Skip to content

Commit

Permalink
Update tasty reader for existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bishabosha committed Feb 15, 2021
1 parent 00b1e81 commit 9e83a60
Show file tree
Hide file tree
Showing 10 changed files with 328 additions and 113 deletions.
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 = "3.0.0-M3" // TASTy version 26.1
val scala3Compiler = "org.scala-lang" % "scala3-compiler_3.0.0-M3" % supportedTASTyRelease
val supportedTASTyRelease = "3.0.0-M4-bin-20210214-80befc3-NIGHTLY" // TASTy version 28.0.1
val scala3Compiler = "org.scala-lang" % "scala3-compiler_3.0.0-M4" % supportedTASTyRelease
}

/** Settings needed to compile with Dotty,
Expand Down
46 changes: 33 additions & 13 deletions src/compiler/scala/tools/nsc/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,9 @@ class TreeUnpickler[Tasty <: TastyUniverse](
def skipParams(): Unit =
while ({
val tag = nextByte
tag == PARAM || tag == TYPEPARAM || tag == PARAMEND
tag == PARAM || tag == TYPEPARAM || tag == EMPTYCLAUSE || tag == SPLITCLAUSE
}) skipTree()

def skipTypeParams(): Unit =
while (nextByte === TYPEPARAM) skipTree()

/** Record all directly nested definitions and templates in current tree
* as `OwnerTree`s in `buf`.
* A complication concerns member definitions. These are lexically nested in a
Expand Down Expand Up @@ -704,12 +701,26 @@ class TreeUnpickler[Tasty <: TastyUniverse](

ctx.log(s"$symAddr completing ${showSym(sym)} in scope ${showSym(ctx.owner)}")

def readParamss(implicit ctx: Context): List[List[NoCycle/*ValDef*/]] = nextByte match {
case PARAM | PARAMEND =>
readParams[NoCycle](PARAM) ::
(if (nextByte == PARAMEND) { readByte(); readParamss } else Nil)
def readParamss(skipTypeParams: Boolean)(implicit ctx: Context): List[List[NoCycle]] = {
def readRest() = {
if (nextByte == SPLITCLAUSE) readByte()
readParamss(skipTypeParams)
}

def emptyTypeParams() = {
while (nextByte === TYPEPARAM) skipTree()
Nil
}

case _ => Nil
nextByte match {
case PARAM => readParams[NoCycle](PARAM) :: readRest()
case TYPEPARAM =>
val typarams =
if (skipTypeParams) emptyTypeParams() else readParams[NoCycle](TYPEPARAM)
typarams :: readRest()
case EMPTYCLAUSE => readByte(); Nil :: readRest()
case _ => Nil
}
}

def checkUnsupportedFlags(unsupported: TastyFlagSet)(implicit ctx: Context): Unit = {
Expand All @@ -723,16 +734,25 @@ class TreeUnpickler[Tasty <: TastyUniverse](
val isMacro = repr.originalFlagSet.is(Erased | Macro)
checkUnsupportedFlags(repr.tastyOnlyFlags &~ (Extension | Exported | Infix | optFlag(isMacro)(Erased)))
val isCtor = sym.isConstructor
val typeParams = {
val paramDefss = readParamss(skipTypeParams=isCtor)(localCtx) // TODO: this can mix type and term parameters, must skip type params if ctor
val typeParams: List[Symbol] = {
if (isCtor) {
skipTypeParams()
// skipTypeParams()
sym.owner.typeParams
}
else {
readParams[NoCycle](TYPEPARAM)(localCtx).map(symFromNoCycle)
// readParams[NoCycle](TYPEPARAM)(localCtx).map(symFromNoCycle)

// TODO: Handle extension methods with multiple param lists
val first = paramDefss.take(1).flatten.map(symFromNoCycle)
if (first.headOption.exists(_.isType)) first else Nil
}
}
val vparamss = readParamss(localCtx)
val vparamss: List[List[NoCycle]] = {
// TODO: Handle extension methods with multiple param lists
val droppedClauses = if (typeParams.isEmpty) 0 else 1
paramDefss.drop(droppedClauses).ensuring(_.flatten.forall(nc => symFromNoCycle(nc).isTerm))
}
val tpt = readTpt()(localCtx)
if (isMacro) {
val impl = tpd.Macro(readTerm()(ctx.addMode(ReadMacro)))
Expand Down
20 changes: 12 additions & 8 deletions src/compiler/scala/tools/nsc/tasty/bridge/SymbolOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,29 @@ trait SymbolOps { self: TastyUniverse =>

implicit final class SymbolDecorator(val sym: Symbol) {

def isScala3Macro: Boolean = repr.originalFlagSet.is(Inline | Macro)
def isScala3Inline: Boolean = repr.originalFlagSet.is(Inline)
def isScala2Macro: Boolean = repr.originalFlagSet.is(Erased | Macro)
def isScala3Macro(implicit ctx: Context): Boolean = repr.originalFlagSet.is(Inline | Macro)
def isScala3Inline(implicit ctx: Context): Boolean = repr.originalFlagSet.is(Inline)
def isScala2Macro(implicit ctx: Context): Boolean = repr.originalFlagSet.is(Erased | Macro)

def isPureMixinCtor: Boolean = isMixinCtor && repr.originalFlagSet.is(Stable)
def isPureMixinCtor(implicit ctx: Context): Boolean = isMixinCtor && repr.originalFlagSet.is(Stable)
def isMixinCtor: Boolean = u.nme.MIXIN_CONSTRUCTOR == sym.name && sym.owner.isTrait

def isTraitParamAccessor: Boolean = sym.owner.isTrait && repr.originalFlagSet.is(FieldAccessor|ParamSetter)
def isTraitParamAccessor(implicit ctx: Context): Boolean = sym.owner.isTrait && repr.originalFlagSet.is(FieldAccessor|ParamSetter)

def isParamGetter: Boolean =
def isParamGetter(implicit ctx: Context): Boolean =
sym.isMethod && sym.repr.originalFlagSet.is(FlagSets.FieldAccessorFlags)

/** A computed property that should only be called on a symbol which is known to have been initialised by the
* Tasty Unpickler and is not yet completed.
*
* @todo adapt callsites and type so that this property is more safe to call (barring mutation from uncontrolled code)
*/
def repr: TastyRepr = {
require(sym.rawInfo.isInstanceOf[TastyRepr], s"Expected ${u.typeOf[TastyRepr]}, is ${u.showRaw(sym.rawInfo)} ")
def repr(implicit ctx: Context): TastyRepr = {
require(sym.rawInfo.isInstanceOf[TastyRepr], {
val raw = u.showRaw(sym.rawInfo)
val tastyRepr = u.typeOf[TastyRepr]
s"${showSym(sym)} is already completed. Expected $tastyRepr, is $raw. in ${ctx.source}"
})
sym.rawInfo.asInstanceOf[TastyRepr]
}

Expand Down

0 comments on commit 9e83a60

Please sign in to comment.