Skip to content

Commit 009398b

Browse files
authored
Merge pull request #1588 from dotty-staging/fix-#1502
Fix #1544: Allow long signatures in names
2 parents 171f4aa + 189629f commit 009398b

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/dotty/tools/dotc/core/tasty/NameBuffer.scala

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import TastyName._
1212
import TastyFormat._
1313

1414
class NameBuffer extends TastyBuffer(10000) {
15+
import NameBuffer._
1516

1617
private val nameRefs = new mutable.LinkedHashMap[TastyName, NameRef]
1718

@@ -40,13 +41,12 @@ class NameBuffer extends TastyBuffer(10000) {
4041
nameIndex(name)
4142
}
4243

43-
private def withLength(op: => Unit): Unit = {
44+
private def withLength(op: => Unit, lengthWidth: Int = 1): Unit = {
4445
val lengthAddr = currentAddr
45-
writeByte(0)
46+
for (i <- 0 until lengthWidth) writeByte(0)
4647
op
4748
val length = currentAddr.index - lengthAddr.index - 1
48-
assert(length < 128)
49-
putNat(lengthAddr, length, 1)
49+
putNat(lengthAddr, length, lengthWidth)
5050
}
5151

5252
def writeNameRef(ref: NameRef) = writeNat(ref.index)
@@ -64,7 +64,9 @@ class NameBuffer extends TastyBuffer(10000) {
6464
withLength { writeNameRef(qualified); writeNameRef(selector) }
6565
case Signed(original, params, result) =>
6666
writeByte(SIGNED)
67-
withLength { writeNameRef(original); writeNameRef(result); params.foreach(writeNameRef) }
67+
withLength(
68+
{ writeNameRef(original); writeNameRef(result); params.foreach(writeNameRef) },
69+
if ((params.length + 2) * maxIndexWidth <= maxNumInByte) 1 else 2)
6870
case Expanded(prefix, original) =>
6971
writeByte(EXPANDED)
7072
withLength { writeNameRef(prefix); writeNameRef(original) }
@@ -91,3 +93,9 @@ class NameBuffer extends TastyBuffer(10000) {
9193
}
9294
}
9395
}
96+
97+
object NameBuffer {
98+
private val maxIndexWidth = 3 // allows name indices up to 2^21.
99+
private val payloadBitsPerByte = 7 // determined by nat encoding in TastyBuffer
100+
private val maxNumInByte = (1 << payloadBitsPerByte) - 1
101+
}

tests/pos/i1544.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object Foo {
2+
def foo(p1: Int, p2: Int, p3: Int, p4: Int, p5: Int, p6: Int, p7: Int, p8: Int, p9: Int, p10: Int, p11: Int, p12: Int, p13: Int, p14: Int, p15: Int, p16: Int, p17: Int, p18: Int, p19: Int, p20: Int, p21: Int, p22: Int, p23: Int, p24: Int, p25: Int, p26: Int, p27: Int, p28: Int, p29: Int, p30: Int, p31: Int, p32: Int, p33: Int, p34: Int, p35: Int, p36: Int, p37: Int, p38: Int, p39: Int, p40: Int, p41: Int, p42: Int, p43: Int, p44: Int, p45: Int, p46: Int, p47: Int, p48: Int, p49: Int, p50: Int, p51: Int, p52: Int, p53: Int, p54: Int, p55: Int, p56: Int, p57: Int, p58: Int, p59: Int, p60: Int, p61: Int, p62: Int, p63: Int, p64: Int, p65: Int, p66: Int, p67: Int, p68: Int, p69: Int, p70: Int, p71: Int, p72: Int, p73: Int, p74: Int, p75: Int, p76: Int, p77: Int, p78: Int, p79: Int, p80: Int, p81: Int, p82: Int, p83: Int, p84: Int, p85: Int, p86: Int, p87: Int, p88: Int, p89: Int, p90: Int, p91: Int, p92: Int, p93: Int, p94: Int, p95: Int, p96: Int, p97: Int, p98: Int, p99: Int, p100: Int, p101: Int, p102: Int, p103: Int, p104: Int, p105: Int, p106: Int, p107: Int, p108: Int, p109: Int): Int = 42
3+
foo(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109)
4+
}

0 commit comments

Comments
 (0)