aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/tasty/NameBuffer.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-10-13 11:44:07 +0200
committerMartin Odersky <odersky@gmail.com>2016-10-13 11:48:57 +0200
commit189629f9cf9e24abfc3479d3f067448fe380b965 (patch)
tree0ad92a123bd954781f6f51838c03bb1858b72c41 /src/dotty/tools/dotc/core/tasty/NameBuffer.scala
parent9ef03414b78622ce181d300c1bf7f607fe4ddea8 (diff)
downloaddotty-189629f9cf9e24abfc3479d3f067448fe380b965.tar.gz
dotty-189629f9cf9e24abfc3479d3f067448fe380b965.tar.bz2
dotty-189629f9cf9e24abfc3479d3f067448fe380b965.zip
Fix #1544: Allow long signatures in names
Fixes #1544 by making the length field use 1 or 2 bytes, depending on the number of parameters in a signature.
Diffstat (limited to 'src/dotty/tools/dotc/core/tasty/NameBuffer.scala')
-rw-r--r--src/dotty/tools/dotc/core/tasty/NameBuffer.scala18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/dotty/tools/dotc/core/tasty/NameBuffer.scala b/src/dotty/tools/dotc/core/tasty/NameBuffer.scala
index 69fd63805..3ff7298ce 100644
--- a/src/dotty/tools/dotc/core/tasty/NameBuffer.scala
+++ b/src/dotty/tools/dotc/core/tasty/NameBuffer.scala
@@ -12,6 +12,7 @@ import TastyName._
import TastyFormat._
class NameBuffer extends TastyBuffer(10000) {
+ import NameBuffer._
private val nameRefs = new mutable.LinkedHashMap[TastyName, NameRef]
@@ -40,13 +41,12 @@ class NameBuffer extends TastyBuffer(10000) {
nameIndex(name)
}
- private def withLength(op: => Unit): Unit = {
+ private def withLength(op: => Unit, lengthWidth: Int = 1): Unit = {
val lengthAddr = currentAddr
- writeByte(0)
+ for (i <- 0 until lengthWidth) writeByte(0)
op
val length = currentAddr.index - lengthAddr.index - 1
- assert(length < 128)
- putNat(lengthAddr, length, 1)
+ putNat(lengthAddr, length, lengthWidth)
}
def writeNameRef(ref: NameRef) = writeNat(ref.index)
@@ -64,7 +64,9 @@ class NameBuffer extends TastyBuffer(10000) {
withLength { writeNameRef(qualified); writeNameRef(selector) }
case Signed(original, params, result) =>
writeByte(SIGNED)
- withLength { writeNameRef(original); writeNameRef(result); params.foreach(writeNameRef) }
+ withLength(
+ { writeNameRef(original); writeNameRef(result); params.foreach(writeNameRef) },
+ if ((params.length + 2) * maxIndexWidth <= maxNumInByte) 1 else 2)
case Expanded(prefix, original) =>
writeByte(EXPANDED)
withLength { writeNameRef(prefix); writeNameRef(original) }
@@ -91,3 +93,9 @@ class NameBuffer extends TastyBuffer(10000) {
}
}
}
+
+object NameBuffer {
+ private val maxIndexWidth = 3 // allows name indices up to 2^21.
+ private val payloadBitsPerByte = 7 // determined by nat encoding in TastyBuffer
+ private val maxNumInByte = (1 << payloadBitsPerByte) - 1
+}