Skip to content

support Dotty 0.24.0-RC1 #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions project/DottySupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import sbt.librarymanagement.{
* Settings to support validation of TastyUnpickler against the release of dotty with the matching TASTy version
*/
object TastySupport {
val supportedTASTyRelease = "0.23.0-RC1" // TASTy version 20
val dottyCompiler = "ch.epfl.lamp" % "dotty-compiler_0.23" % supportedTASTyRelease
val supportedTASTyRelease = "0.24.0-RC1" // TASTy version 22
val dottyCompiler = "ch.epfl.lamp" % "dotty-compiler_0.24" % supportedTASTyRelease
}

/** Settings needed to compile with Dotty,
Expand Down
12 changes: 7 additions & 5 deletions src/compiler/scala/tools/nsc/tasty/TastyUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ class TastyUnpickler[Tasty <: TastyUniverse](reader: TastyReader)(implicit tasty
debugName(SimpleName(new String(bytes.slice(start.index, start.index + length), "UTF-8")))
case tag @ (QUALIFIED | EXPANDED | EXPANDPREFIX) =>
val sep = tag match {
case QUALIFIED => TastyName.PathSep
case EXPANDED => TastyName.ExpandedSep
case EXPANDPREFIX => TastyName.ExpandPrefixSep
case QUALIFIED => PathSep
case EXPANDED => ExpandedSep
case EXPANDPREFIX => ExpandPrefixSep
}
debugName(QualifiedName(readName(), sep, readName().asSimpleName))
case UNIQUE =>
Expand All @@ -90,10 +90,12 @@ class TastyUnpickler[Tasty <: TastyUniverse](reader: TastyReader)(implicit tasty
debugName(SignedName(original, sig))
case OBJECTCLASS =>
debugName(ObjectName(readName()))
case BODYRETAINER =>
debugName(SuffixName(readName(), BodyRetainerSuffix))
case INLINEACCESSOR | SUPERACCESSOR =>
val prefix = tag match {
case INLINEACCESSOR => TastyName.InlinePrefix
case SUPERACCESSOR => TastyName.SuperPrefix
case INLINEACCESSOR => InlinePrefix
case SUPERACCESSOR => SuperPrefix
}
debugName(PrefixName(prefix, readName()))
case _ =>
Expand Down
65 changes: 42 additions & 23 deletions src/compiler/scala/tools/nsc/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,35 @@ class TreeUnpickler[Tasty <: TastyUniverse](

// ------ Reading types -----------------------------------------------------

/** Read names in an interleaved sequence of (parameter) names and types/bounds */
def readParamNames(end: Addr): List[TastyName] =
until(end) {
val name = readTastyName()
skipTree()
name
/** Read names in an interleaved sequence of types/bounds and (parameter) names,
* possibly followed by a sequence of modifiers.
*/
def readParamNamesAndMods(end: Addr): (List[TastyName], TastyFlagSet) = {
val names =
collectWhile(currentAddr != end && !isModifierTag(nextByte)) {
skipTree()
readTastyName()
}
var mods = EmptyTastyFlags
while (currentAddr != end) { // avoid boxing the mods
readByte() match {
case IMPLICIT => mods |= Implicit
case ERASED => mods |= Erased
case GIVEN => mods |= Given
}
}
(names, mods)
}

/** Read types or bounds in an interleaved sequence of (parameter) names and types/bounds */
def readParamTypes[T <: Type](end: Addr)(implicit ctx: Context): List[T] =
until(end) { readNat(); readType().asInstanceOf[T] }
/** Read `n` parameter types or bounds which are interleaved with names */
def readParamTypes[T <: Type](n: Int)(implicit ctx: Context): List[T] = {
if (n == 0) Nil
else {
val t = readType().asInstanceOf[T]
readNat() // skip name
t :: readParamTypes(n - 1)
}
}

/** Read reference to definition and return symbol created at that definition */
def readSymRef()(implicit ctx: Context): Symbol = symbolAt(readAddr())
Expand Down Expand Up @@ -264,15 +282,15 @@ class TreeUnpickler[Tasty <: TastyUniverse](
val end = readEnd()

def readMethodic[N <: TastyName]
(companion: LambdaTypeCompanion[N], nameMap: TastyName => N)(implicit ctx: Context): Type = {
(companionOp: TastyFlagSet => LambdaTypeCompanion[N], nameMap: TastyName => N)(implicit ctx: Context): Type = {
val result = typeAtAddr.getOrElse(start, {
val nameReader = fork
nameReader.skipTree() // skip result
val paramReader = nameReader.fork
val paramNames: List[N] = map(nameReader.readParamNames(end), nameMap)
companion(paramNames)(
val (paramNames, mods) = nameReader.readParamNamesAndMods(end)
companionOp(mods)(paramNames.map(nameMap))(
pt => typeAtAddr(start) = pt,
() => paramReader.readParamTypes(end),
() => paramReader.readParamTypes(paramNames.length),
() => readType()
).tap(typeAtAddr(start) = _)
})
Expand Down Expand Up @@ -313,11 +331,16 @@ class TreeUnpickler[Tasty <: TastyUniverse](
case ORtype => unionIsUnsupported
case SUPERtype => defn.SuperType(readType(), readType())
case MATCHtype => matchTypeIsUnsupported
case POLYtype => readMethodic(PolyType, _.toTypeName)
case METHODtype => readMethodic(MethodType, id)
case ERASEDMETHODtype | ERASEDGIVENMETHODtype => erasedRefinementIsUnsupported
case IMPLICITMETHODtype | GIVENMETHODtype => readMethodic(ImplicitMethodType, id)
case TYPELAMBDAtype => readMethodic(HKTypeLambda, _.toTypeName)
case POLYtype => readMethodic(Function.const(PolyType), _.toTypeName)
case METHODtype =>
def companion(mods0: TastyFlagSet) = {
var mods = EmptyTastyFlags
if (mods0.is(Erased)) erasedRefinementIsUnsupported[Unit]
if (mods0.isOneOf(Given | Implicit)) mods |= Implicit
methodTypeCompanion(mods)
}
readMethodic(companion, id)
case TYPELAMBDAtype => readMethodic(Function.const(HKTypeLambda), _.toTypeName)
case PARAMtype => // reference to a type parameter within a LambdaType
readTypeRef().typeParams(readNat()).ref
}
Expand Down Expand Up @@ -398,9 +421,6 @@ class TreeUnpickler[Tasty <: TastyUniverse](
}
}
else if (isParamTag(tag)) flags |= Param
if (name.isDefaultName || flags.is(Param) && owner.isMethod && owner.is(DefaultParameterized)) {
flags |= DefaultParameterized
}
flags
}

Expand Down Expand Up @@ -570,8 +590,7 @@ class TreeUnpickler[Tasty <: TastyUniverse](
case CASEaccessor => addFlag(CaseAccessor)
case COVARIANT => addFlag(Covariant)
case CONTRAVARIANT => addFlag(Contravariant)
case SCALA2X => addFlag(Scala2x)
case DEFAULTparameterized => addFlag(DefaultParameterized)
case HASDEFAULT => addFlag(HasDefault)
case STABLE => addFlag(Stable)
case EXTENSION => addFlag(Extension)
case GIVEN => addFlag(Implicit)
Expand Down
31 changes: 15 additions & 16 deletions src/compiler/scala/tools/nsc/tasty/bridge/FlagOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ trait FlagOps { self: TastyUniverse =>

object FlagSets {
val TastyOnlyFlags: TastyFlagSet = (
Erased | Internal | Inline | InlineProxy | Opaque | Scala2x | Extension | Given | Exported | Macro | Enum
| Open | ParamAlias
Erased | Internal | Inline | InlineProxy | Opaque | Extension | Given | Exported | Macro | Enum | Open
| ParamAlias
)
val TermParamOrAccessor: TastyFlagSet = Param | ParamSetter
val ObjectCreationFlags: TastyFlagSet = Object | Lazy | Final | Stable
Expand Down Expand Up @@ -54,7 +54,7 @@ trait FlagOps { self: TastyUniverse =>
if (tflags.is(CaseAccessor)) flags |= Flag.CASEACCESSOR
if (tflags.is(Covariant)) flags |= Flag.COVARIANT
if (tflags.is(Contravariant)) flags |= Flag.CONTRAVARIANT
if (tflags.is(DefaultParameterized)) flags |= Flag.DEFAULTPARAM
if (tflags.is(HasDefault)) flags |= Flag.DEFAULTPARAM
if (tflags.is(Stable)) flags |= Flag.STABLE
if (tflags.is(ParamSetter)) flags |= Flag.PARAMACCESSOR
if (tflags.is(Param)) flags |= Flag.PARAM
Expand All @@ -68,19 +68,18 @@ trait FlagOps { self: TastyUniverse =>
if (!tflags) "EmptyTastyFlags"
else (tflags).toSingletonSets.map { f =>
(f: @unchecked) match {
case Erased => "erased"
case Internal => "<internal>"
case Inline => "inline"
case InlineProxy => "<inlineproxy>"
case Opaque => "opaque"
case Scala2x => "<scala2x>"
case Extension => "<extension>"
case Given => "given"
case Exported => "<exported>"
case Macro => "<tastymacro>"
case Enum => "enum"
case Open => "open"
case ParamAlias => "<paramalias>"
case Erased => "erased"
case Internal => "<internal>"
case Inline => "inline"
case InlineProxy => "<inlineproxy>"
case Opaque => "opaque"
case Extension => "<extension>"
case Given => "given"
case Exported => "<exported>"
case Macro => "<tastymacro>"
case Enum => "enum"
case Open => "open"
case ParamAlias => "<paramalias>"
}
} mkString(" | ")
}
Expand Down
5 changes: 2 additions & 3 deletions src/compiler/scala/tools/nsc/tasty/bridge/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ trait TypeOps { self: TastyUniverse =>
new PolyTypeLambda(params)(registerCallback, paramInfosOp, resultTypeOp)
}

abstract class MethodTypeCompanion(defaultFlags: TastyFlagSet) extends TermLambdaCompanion { self =>
final class MethodTypeCompanion(defaultFlags: TastyFlagSet) extends TermLambdaCompanion { self =>
def factory(params: List[TastyName])(registerCallback: Type => Unit,
paramInfosOp: () => List[Type], resultTypeOp: () => Type)(implicit ctx: Context): LambdaType =
new MethodTermLambda(params, defaultFlags)(registerCallback, paramInfosOp, resultTypeOp)
Expand Down Expand Up @@ -371,8 +371,7 @@ trait TypeOps { self: TastyUniverse =>

}

object MethodType extends MethodTypeCompanion(EmptyTastyFlags)
object ImplicitMethodType extends MethodTypeCompanion(Implicit)
def methodTypeCompanion(initialFlags: TastyFlagSet): MethodTypeCompanion = new MethodTypeCompanion(initialFlags)

abstract class TermLambdaCompanion
extends LambdaTypeCompanion[TastyName]
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/scala/tools/tasty/Signature.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ object Signature {

type ParamSig[T] = Either[Int, T]

def merge[T](sb: StringBuilder, sig: Signature[T]): StringBuilder = sig.mergeShow(sb)

def apply[T](params: List[ParamSig[T]], result: T): MethodSignature[T] = new MethodSignature(params, result)

case class MethodSignature[T] private[Signature](params: List[ParamSig[T]], result: T) extends Signature[T] {
Expand Down
10 changes: 4 additions & 6 deletions src/compiler/scala/tools/tasty/TastyFlags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ object TastyFlags {
final val CaseAccessor = FieldAccessor.next
final val Covariant = CaseAccessor.next
final val Contravariant = Covariant.next
final val DefaultParameterized = Contravariant.next
final val Stable = DefaultParameterized.next
final val HasDefault = Contravariant.next
final val Stable = HasDefault.next
final val ParamSetter = Stable.next
final val Param = ParamSetter.next
final val Deferred = Param.next
Expand All @@ -51,8 +51,7 @@ object TastyFlags {
final val Inline = Internal.next
final val InlineProxy = Inline.next
final val Opaque = InlineProxy.next
final val Scala2x = Opaque.next
final val Extension = Scala2x.next
final val Extension = Opaque.next
final val Given = Extension.next
final val Exported = Given.next
final val Macro = Exported.next
Expand Down Expand Up @@ -118,7 +117,7 @@ object TastyFlags {
case CaseAccessor => "CaseAccessor"
case Covariant => "Covariant"
case Contravariant => "Contravariant"
case DefaultParameterized => "DefaultParameterized"
case HasDefault => "HasDefault"
case Stable => "Stable"
case ParamSetter => "ParamSetter"
case Param => "Param"
Expand All @@ -129,7 +128,6 @@ object TastyFlags {
case Inline => "Inline"
case InlineProxy => "InlineProxy"
case Opaque => "Opaque"
case Scala2x => "Scala2x"
case Extension => "Extension"
case Given => "Given"
case Exported => "Exported"
Expand Down
66 changes: 23 additions & 43 deletions src/compiler/scala/tools/tasty/TastyFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,38 @@ package scala.tools.tasty
object TastyFormat {

final val header: Array[Int] = Array(0x5C, 0xA1, 0xAB, 0x1F)
val MajorVersion: Int = 20
val MajorVersion: Int = 22
val MinorVersion: Int = 0

/** Tags used to serialize names */
class NameTags {
final val UTF8 = 1 // A simple name in UTF8 encoding.
final val UTF8 = 1 // A simple name in UTF8 encoding.

final val QUALIFIED = 2 // A fully qualified name `<prefix>.<suffix>`.
final val QUALIFIED = 2 // A fully qualified name `<prefix>.<suffix>`.

final val EXPANDED = 3 // An expanded name `<prefix>$$<suffix>`,
// used by Scala-2 for private names.
final val EXPANDED = 3 // An expanded name `<prefix>$$<suffix>`,
// used by Scala-2 for private names.

final val EXPANDPREFIX = 4 // An expansion prefix `<prefix>$<suffix>`,
// used by Scala-2 for private names.
final val EXPANDPREFIX = 4 // An expansion prefix `<prefix>$<suffix>`,
// used by Scala-2 for private names.

final val UNIQUE = 10 // A unique name `<name>$<num>` where `<num>`
// is used only once for each `<name>`.
final val UNIQUE = 10 // A unique name `<name>$<num>` where `<num>`
// is used only once for each `<name>`.

final val DEFAULTGETTER = 11 // The name `<meth-name>$default$<param-num>`
// of a default getter that returns a default argument.
final val DEFAULTGETTER = 11 // The name `<meth-name>$default$<param-num>`
// of a default getter that returns a default argument.

final val SUPERACCESSOR = 20 // The name of a super accessor `super$name` created by SuperAccesors.
final val SUPERACCESSOR = 20 // The name of a super accessor `super$name` created by SuperAccesors.

final val INLINEACCESSOR = 21 // The name of an inline accessor `inline$name`
final val INLINEACCESSOR = 21 // The name of an inline accessor `inline$name`

final val OBJECTCLASS = 23 // The name of an object class (or: module class) `<name>$`.
final val BODYRETAINER = 22 // The name of a synthetic method that retains the runtime
// body of an inline method

final val SIGNED = 63 // A pair of a name and a signature, used to identify
// possibly overloaded methods.
final val OBJECTCLASS = 23 // The name of an object class (or: module class) `<name>$`.

final val SIGNED = 63 // A pair of a name and a signature, used to identify
// possibly overloaded methods.
}
object NameTags extends NameTags

Expand Down Expand Up @@ -83,8 +86,7 @@ object TastyFormat {
final val CASEaccessor = 27
final val COVARIANT = 28
final val CONTRAVARIANT = 29
final val SCALA2X = 30
final val DEFAULTparameterized = 31
final val HASDEFAULT = 31
final val STABLE = 32
final val MACRO = 33
final val ERASED = 34
Expand Down Expand Up @@ -196,23 +198,10 @@ object TastyFormat {
final val TYPEREFin = 175

final val METHODtype = 180
final val ERASEDMETHODtype = 181
final val GIVENMETHODtype = 182
final val ERASEDGIVENMETHODtype = 183
final val IMPLICITMETHODtype = 184

final val MATCHtype = 190
final val MATCHtpt = 191

def methodTypeTag(isContextual: Boolean, isImplicit: Boolean, isErased: Boolean): Int = {
val implicitOffset =
if (isContextual) 2
else if (isImplicit) { assert(!isErased); 4 }
else 0
val erasedOffset = if (isErased) 1 else 0
METHODtype + erasedOffset + implicitOffset
}

final val HOLE = 255

final val firstNatTreeTag = SHAREDterm
Expand Down Expand Up @@ -260,8 +249,7 @@ object TastyFormat {
| CASEaccessor
| COVARIANT
| CONTRAVARIANT
| SCALA2X
| DEFAULTparameterized
| HASDEFAULT
| STABLE
| EXTENSION
| PARAMsetter
Expand Down Expand Up @@ -321,8 +309,7 @@ object TastyFormat {
case CASEaccessor => "CASEaccessor"
case COVARIANT => "COVARIANT"
case CONTRAVARIANT => "CONTRAVARIANT"
case SCALA2X => "SCALA2X"
case DEFAULTparameterized => "DEFAULTparameterized"
case HASDEFAULT => "HASDEFAULT"
case STABLE => "STABLE"
case EXTENSION => "EXTENSION"
case GIVEN => "GIVEN"
Expand Down Expand Up @@ -416,10 +403,6 @@ object TastyFormat {
case BYNAMEtpt => "BYNAMEtpt"
case POLYtype => "POLYtype"
case METHODtype => "METHODtype"
case ERASEDMETHODtype => "ERASEDMETHODtype"
case GIVENMETHODtype => "GIVENMETHODtype"
case ERASEDGIVENMETHODtype => "ERASEDGIVENMETHODtype"
case IMPLICITMETHODtype => "IMPLICITMETHODtype"
case TYPELAMBDAtype => "TYPELAMBDAtype"
case LAMBDAtpt => "LAMBDAtpt"
case MATCHtype => "MATCHtype"
Expand All @@ -438,10 +421,7 @@ object TastyFormat {
case VALDEF | DEFDEF | TYPEDEF | TYPEPARAM | PARAM | NAMEDARG | RETURN | BIND |
SELFDEF | REFINEDtype | TERMREFin | TYPEREFin | HOLE => 1
case RENAMED | PARAMtype => 2
case POLYtype | TYPELAMBDAtype |
METHODtype | ERASEDMETHODtype |
GIVENMETHODtype | ERASEDGIVENMETHODtype |
IMPLICITMETHODtype => -1
case POLYtype | TYPELAMBDAtype | METHODtype => -1
case _ => 0
}
}
Loading