diff options
Diffstat (limited to 'src/dotty/tools/dotc/core')
-rw-r--r-- | src/dotty/tools/dotc/core/Definitions.scala | 8 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Denotations.scala | 35 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Flags.scala | 3 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Scopes.scala | 4 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/SymDenotations.scala | 87 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/SymbolLoaders.scala | 4 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/TypeOps.scala | 4 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/pickling/ClassfileParser.scala | 8 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/pickling/UnPickler.scala | 4 |
9 files changed, 92 insertions, 65 deletions
diff --git a/src/dotty/tools/dotc/core/Definitions.scala b/src/dotty/tools/dotc/core/Definitions.scala index b5ec98343..8c6e8d72c 100644 --- a/src/dotty/tools/dotc/core/Definitions.scala +++ b/src/dotty/tools/dotc/core/Definitions.scala @@ -37,8 +37,8 @@ class Definitions(implicit ctx: Context) { newTypeParam(cls, suffix.toTypeName.expandedName(cls), ExpandedName, scope) private def specialPolyClass(name: TypeName, paramFlags: FlagSet, parentConstrs: Type*): ClassSymbol = { - val completer = new LazyType { - def complete(denot: SymDenotation): Unit = { + val completer = new LazyType with CompleteInCreationContext { + def completeInCreationContext(denot: SymDenotation): Unit = { val cls = denot.asClass.classSymbol val paramDecls = newScope val typeParam = newSyntheticTypeParam(cls, paramDecls, paramFlags) @@ -368,8 +368,8 @@ class Definitions(implicit ctx: Context) { case 1 => EmptyFlags } - val completer = new LazyType { - def complete(denot: SymDenotation): Unit = { + val completer = new LazyType with CompleteInCreationContext { + def completeInCreationContext(denot: SymDenotation): Unit = { val cls = denot.asClass.classSymbol val paramDecls = newScope for ((v, i) <- vcs.zipWithIndex) diff --git a/src/dotty/tools/dotc/core/Denotations.scala b/src/dotty/tools/dotc/core/Denotations.scala index bc7545abd..2ad193970 100644 --- a/src/dotty/tools/dotc/core/Denotations.scala +++ b/src/dotty/tools/dotc/core/Denotations.scala @@ -98,7 +98,12 @@ object Denotations { def symbol: Symbol /** The type info of the denotation, exists only for non-overloaded denotations */ - def info: Type + def info(implicit ctx: Context): Type + + /** The type info, or, if this is a SymDenotation where the symbol + * is not yet completed, the completer + */ + def infoOrCompleter: Type /** The period during which this denotation is valid. */ def validFor: Period @@ -315,7 +320,8 @@ object Denotations { */ case class MultiDenotation(denot1: Denotation, denot2: Denotation) extends Denotation { final def symbol: Symbol = NoSymbol - final def info = multiHasNot("info") + final def infoOrCompleter = multiHasNot("info") + final def info(implicit ctx: Context) = infoOrCompleter final def validFor = denot1.validFor & denot2.validFor final def isType = false def signature(implicit ctx: Context) = multiHasNot("signature") @@ -356,7 +362,6 @@ object Denotations { def hasUniqueSym: Boolean protected def newLikeThis(symbol: Symbol, info: Type): SingleDenotation - def isType = info.isInstanceOf[TypeType] final def signature(implicit ctx: Context): Signature = { if (isType) Signature.NotAMethod // don't force info if this is a type SymDenotation else info match { @@ -371,7 +376,7 @@ object Denotations { } } - def derivedSingleDenotation(symbol: Symbol, info: Type): SingleDenotation = + def derivedSingleDenotation(symbol: Symbol, info: Type)(implicit ctx: Context): SingleDenotation = if ((symbol eq this.symbol) && (info eq this.info)) this else newLikeThis(symbol, info) @@ -535,7 +540,7 @@ object Denotations { override def toString = if (symbol == NoSymbol) symbol.toString - else s"<SingleDenotation of type $info>" + else s"<SingleDenotation of type $infoOrCompleter>" // ------ PreDenotation ops ---------------------------------------------- @@ -571,10 +576,16 @@ object Denotations { } } + abstract class NonSymSingleDenotation extends SingleDenotation { + def infoOrCompleter: Type + def info(implicit ctx: Context) = infoOrCompleter + def isType = infoOrCompleter.isInstanceOf[TypeType] + } + class UniqueRefDenotation( val symbol: Symbol, - val info: Type, - initValidFor: Period) extends SingleDenotation { + val infoOrCompleter: Type, + initValidFor: Period) extends NonSymSingleDenotation { validFor = initValidFor override def hasUniqueSym: Boolean = true protected def newLikeThis(s: Symbol, i: Type): SingleDenotation = new UniqueRefDenotation(s, i, validFor) @@ -582,18 +593,18 @@ object Denotations { class JointRefDenotation( val symbol: Symbol, - val info: Type, - initValidFor: Period) extends SingleDenotation { + val infoOrCompleter: Type, + initValidFor: Period) extends NonSymSingleDenotation { validFor = initValidFor override def hasUniqueSym = false protected def newLikeThis(s: Symbol, i: Type): SingleDenotation = new JointRefDenotation(s, i, validFor) } - class ErrorDenotation(implicit ctx: Context) extends SingleDenotation { + class ErrorDenotation(implicit ctx: Context) extends NonSymSingleDenotation { override def exists = false override def hasUniqueSym = false - val symbol = NoSymbol - val info = NoType + def symbol = NoSymbol + def infoOrCompleter = NoType validFor = Period.allInRun(ctx.runId) protected def newLikeThis(s: Symbol, i: Type): SingleDenotation = this } diff --git a/src/dotty/tools/dotc/core/Flags.scala b/src/dotty/tools/dotc/core/Flags.scala index d7d30f438..ab17c7176 100644 --- a/src/dotty/tools/dotc/core/Flags.scala +++ b/src/dotty/tools/dotc/core/Flags.scala @@ -175,6 +175,9 @@ object Flags { /** The empty flag set */ final val EmptyFlags = FlagSet(0) + /** The undefined flag set */ + final val UndefinedFlags = FlagSet(~KINDFLAGS) + // Available flags: /** Labeled with `private` modifier */ diff --git a/src/dotty/tools/dotc/core/Scopes.scala b/src/dotty/tools/dotc/core/Scopes.scala index cdc596e2b..a20433b1f 100644 --- a/src/dotty/tools/dotc/core/Scopes.scala +++ b/src/dotty/tools/dotc/core/Scopes.scala @@ -344,8 +344,8 @@ object Scopes { def scopeTransform(owner: Symbol)(op: => MutableScope): MutableScope = op val selectAll: SymDenotation => Boolean = alwaysTrue - val selectPrivate: SymDenotation => Boolean = d => (d is Flags.Private) - val selectNonPrivate: SymDenotation => Boolean = d => !(d is Flags.Private) + val selectPrivate: SymDenotation => Boolean = d => (d.flagsUNSAFE is Flags.Private) + val selectNonPrivate: SymDenotation => Boolean = d => !(d.flagsUNSAFE is Flags.Private) /** The empty scope (immutable). */ diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index 7b9d4cd48..3169efea0 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -71,7 +71,7 @@ object SymDenotations { def owner: Symbol = ownerIfExists /** The flag set */ - final def flags: FlagSet = { ensureCompleted(); myFlags } + final def flags(implicit ctx: Context): FlagSet = { ensureCompleted(); myFlags } /** The flag set without forcing symbol completion. * Should be used only for printing. @@ -92,42 +92,45 @@ object SymDenotations { final def resetFlag(flags: FlagSet): Unit = { myFlags &~= flags } /** Has this denotation one of the flags in `fs` set? */ - final def is(fs: FlagSet) = { + final def is(fs: FlagSet)(implicit ctx: Context) = { (if (fs <= FromStartFlags) myFlags else flags) is fs } /** Has this denotation one of the flags in `fs` set, whereas none of the flags * in `butNot` are set? */ - final def is(fs: FlagSet, butNot: FlagSet) = + final def is(fs: FlagSet, butNot: FlagSet)(implicit ctx: Context) = (if (fs <= FromStartFlags && butNot <= FromStartFlags) myFlags else flags) is (fs, butNot) /** Has this denotation all of the flags in `fs` set? */ - final def is(fs: FlagConjunction) = + final def is(fs: FlagConjunction)(implicit ctx: Context) = (if (fs <= FromStartFlags) myFlags else flags) is fs /** Has this denotation all of the flags in `fs` set, whereas none of the flags * in `butNot` are set? */ - final def is(fs: FlagConjunction, butNot: FlagSet) = + final def is(fs: FlagConjunction, butNot: FlagSet)(implicit ctx: Context) = (if (fs <= FromStartFlags && butNot <= FromStartFlags) myFlags else flags) is (fs, butNot) /** The type info. * The info is an instance of TypeType iff this is a type denotation * Uncompleted denotations set myInfo to a LazyType. */ - final def info: Type = myInfo match { + final def info(implicit ctx: Context): Type = myInfo match { case myInfo: LazyType => completeFrom(myInfo); info case _ => myInfo } + /** The type info, or, if symbol is not yet completed, the completer */ + final def infoOrCompleter = myInfo + /** Optionally, the info if it is completed */ final def unforcedInfo: Option[Type] = myInfo match { case myInfo: LazyType => None case _ => Some(myInfo) } - private def completeFrom(completer: LazyType): Unit = { + private def completeFrom(completer: LazyType)(implicit ctx: Context): Unit = { if (myFlags is Touched) throw new CyclicReference(this) myFlags |= Touched @@ -151,19 +154,19 @@ object SymDenotations { } /** The name, except if this is a module class, strip the module class suffix */ - def effectiveName = + def effectiveName(implicit ctx: Context) = if (this is ModuleClass) name.stripModuleClassSuffix else name /** The privateWithin boundary, NoSymbol if no boundary is given. */ - final def privateWithin: Symbol = { ensureCompleted(); myPrivateWithin } + final def privateWithin(implicit ctx: Context): Symbol = { ensureCompleted(); myPrivateWithin } /** Set privateWithin. */ protected[core] final def privateWithin_=(sym: Symbol): Unit = myPrivateWithin = sym /** The annotations of this denotation */ - final def annotations: List[Annotation] = { + final def annotations(implicit ctx: Context): List[Annotation] = { ensureCompleted(); myAnnotations } @@ -195,7 +198,7 @@ object SymDenotations { final def completer: LazyType = myInfo.asInstanceOf[LazyType] /** Make sure this denotation is completed */ - final def ensureCompleted(): Unit = info + final def ensureCompleted()(implicit ctx: Context): Unit = info /** The symbols defined in this class or object. */ @@ -221,7 +224,7 @@ object SymDenotations { // ------ Names ---------------------------------------------- /** The name with which the denoting symbol was created */ - final def originalName = { + final def originalName(implicit ctx: Context) = { val d = initial.asSymDenotation if (d is ExpandedName) d.name.unexpandedName() else d.name // !!!DEBUG, was: effectiveName } @@ -292,10 +295,10 @@ object SymDenotations { } /** Is this symbol an abstract type? */ - final def isAbstractType = isType && (this is Deferred) + final def isAbstractType(implicit ctx: Context) = isType && (this is Deferred) /** Is this symbol an alias type? */ - final def isAliasType = isAbstractOrAliasType && !(this is Deferred) + final def isAliasType(implicit ctx: Context) = isAbstractOrAliasType && !(this is Deferred) /** Is this symbol an abstract or alias type? */ final def isAbstractOrAliasType = isType & !isClass @@ -346,13 +349,13 @@ object SymDenotations { } /** Is this a user defined "def" method? Excluded are accessors. */ - final def isSourceMethod = this is (Method, butNot = Accessor) + final def isSourceMethod(implicit ctx: Context) = this is (Method, butNot = Accessor) /** Is this a setter? */ - final def isGetter = (this is Accessor) && !originalName.isSetterName + final def isGetter(implicit ctx: Context) = (this is Accessor) && !originalName.isSetterName /** Is this a setter? */ - final def isSetter = (this is Accessor) && originalName.isSetterName + final def isSetter(implicit ctx: Context) = (this is Accessor) && originalName.isSetterName /** is this the constructor of a class? */ final def isClassConstructor = name == nme.CONSTRUCTOR @@ -679,18 +682,18 @@ object SymDenotations { /** The variance of this type parameter or type member as an Int, with * +1 = Covariant, -1 = Contravariant, 0 = Nonvariant, or not a type parameter */ - final def variance: Int = + final def variance(implicit ctx: Context): Int = if (this is Covariant) 1 else if (this is Contravariant) -1 else 0 override def toString = { val kindString = - if (this is ModuleClass) "module class" + if (myFlags is ModuleClass) "module class" else if (isClass) "class" else if (isType) "type" - else if (this is Module) "module" - else if (this is Method) "method" + else if (myFlags is Module) "module" + else if (myFlags is Method) "method" else "val" s"$kindString $name" } @@ -706,13 +709,17 @@ object SymDenotations { symbol: Symbol = this.symbol, owner: Symbol = this.owner, name: Name = this.name, - initFlags: FlagSet = this.flags, - info: Type = this.info, - privateWithin: Symbol = this.privateWithin, - annotations: List[Annotation] = this.annotations)(implicit ctx: Context) = - { - val d = ctx.SymDenotation(symbol, owner, name, initFlags, info, privateWithin) - d.annotations = annotations + initFlags: FlagSet = UndefinedFlags, + info: Type = null, + privateWithin: Symbol = null, + annotations: List[Annotation] = null)(implicit ctx: Context) = + { // simulate default parameters, while also passing implicit context ctx to the default values + val initFlags1 = if (initFlags != UndefinedFlags) initFlags else this.flags + val info1 = if (info != null) info else this.info + val privateWithin1 = if (privateWithin != null) privateWithin else this.privateWithin + val annotations1 = if (annotations != null) annotations else this.annotations + val d = ctx.SymDenotation(symbol, owner, name, initFlags1, info1, privateWithin1) + d.annotations = annotations1 d } } @@ -751,7 +758,7 @@ object SymDenotations { myTypeParams } - private def myClassParents: List[TypeRef] = info match { + private def myClassParents(implicit ctx: Context): List[TypeRef] = info match { case classInfo: ClassInfo => classInfo.myClassParents case _ => Nil } @@ -1194,7 +1201,7 @@ object SymDenotations { with ((TermSymbol, ClassSymbol) => LazyType) { self => /** Sets all missing fields of given denotation */ - def complete(denot: SymDenotation): Unit + def complete(denot: SymDenotation)(implicit ctx: Context): Unit def apply(sym: Symbol) = this def apply(module: TermSymbol, modcls: ClassSymbol) = this @@ -1207,7 +1214,7 @@ object SymDenotations { * but provides fresh slots for scope/sourceModule/moduleClass */ def proxy: LazyType = new LazyType { - override def complete(denot: SymDenotation) = self.complete(denot) + override def complete(denot: SymDenotation)(implicit ctx: Context) = self.complete(denot) } def decls: Scope = myDecls @@ -1219,11 +1226,17 @@ object SymDenotations { def withModuleClass(moduleClass: => Symbol): this.type = { myModuleClassFn = () => moduleClass; this } } + trait CompleteInCreationContext extends LazyType { + def completeInCreationContext(denot: SymDenotation): Unit + final override def complete(denot: SymDenotation)(implicit ctx: Context) = + completeInCreationContext(denot) + } + val NoSymbolFn = () => NoSymbol /** A missing completer */ class NoCompleter extends LazyType { - def complete(denot: SymDenotation): Unit = unsupported("complete") + def complete(denot: SymDenotation)(implicit ctx: Context): Unit = unsupported("complete") } /** A lazy type for modules that points to the module class. @@ -1232,8 +1245,8 @@ object SymDenotations { * module class, followed by copying the relevant fields to the module. */ class ModuleCompleter(override val moduleClass: ClassSymbol)(implicit cctx: CondensedContext) - extends LazyType { - def complete(denot: SymDenotation): Unit = { + extends LazyType with CompleteInCreationContext { + def completeInCreationContext(denot: SymDenotation): Unit = { val from = moduleClass.denot.asClass denot.setFlag(from.flags.toTermFlags & RetainedModuleValFlags) denot.annotations = from.annotations filter (_.appliesToModule) @@ -1247,9 +1260,9 @@ object SymDenotations { } /** A completer for missing references */ - class StubInfo()(implicit cctx: CondensedContext) extends LazyType { + class StubInfo()(implicit cctx: CondensedContext) extends LazyType with CompleteInCreationContext { - def initializeToDefaults(denot: SymDenotation) = { + def initializeToDefaults(denot: SymDenotation)(implicit ctx: Context) = { denot.info = denot match { case denot: ClassDenotation => ClassInfo(denot.owner.thisType, denot.classSymbol, Nil, EmptyScope) @@ -1259,7 +1272,7 @@ object SymDenotations { denot.privateWithin = NoSymbol } - def complete(denot: SymDenotation): Unit = { + def completeInCreationContext(denot: SymDenotation): Unit = { val sym = denot.symbol val file = sym.associatedFile val (location, src) = diff --git a/src/dotty/tools/dotc/core/SymbolLoaders.scala b/src/dotty/tools/dotc/core/SymbolLoaders.scala index d88e84ff7..d1eb2872c 100644 --- a/src/dotty/tools/dotc/core/SymbolLoaders.scala +++ b/src/dotty/tools/dotc/core/SymbolLoaders.scala @@ -173,7 +173,7 @@ class SymbolLoaders { /** A lazy type that completes itself by calling parameter doComplete. * Any linked modules/classes or module classes are also initialized. */ -abstract class SymbolLoader extends LazyType { +abstract class SymbolLoader extends LazyType with CompleteInCreationContext { implicit val cctx: CondensedContext /** Load source or class file for `root`, return */ @@ -186,7 +186,7 @@ abstract class SymbolLoader extends LazyType { */ def description: String - override def complete(root: SymDenotation): Unit = { + override def completeInCreationContext(root: SymDenotation): Unit = { def signalError(ex: Exception): Unit = { if (cctx.debug) ex.printStackTrace() val msg = ex.getMessage() diff --git a/src/dotty/tools/dotc/core/TypeOps.scala b/src/dotty/tools/dotc/core/TypeOps.scala index 4e0a857a3..deb906417 100644 --- a/src/dotty/tools/dotc/core/TypeOps.scala +++ b/src/dotty/tools/dotc/core/TypeOps.scala @@ -87,8 +87,8 @@ trait TypeOps { this: Context => } private def enterArgBinding(formal: Symbol, info: Type, cls: ClassSymbol, decls: Scope) = { - val lazyInfo = new LazyType { // needed so we do not force `formal`. - def complete(denot: SymDenotation): Unit = { + val lazyInfo = new LazyType with CompleteInCreationContext { // needed so we do not force `formal`. + def completeInCreationContext(denot: SymDenotation): Unit = { denot setFlag formal.flags & RetainedTypeArgFlags denot.info = info } diff --git a/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala b/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala index 5edddc396..8745593f4 100644 --- a/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala +++ b/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala @@ -163,9 +163,9 @@ class ClassfileParser( skipAttributes } - val memberCompleter = new LazyType { + val memberCompleter = new LazyType with CompleteInCreationContext { - def complete(denot: SymDenotation): Unit = { + def completeInCreationContext(denot: SymDenotation): Unit = { val oldbp = in.bp try { in.bp = denot.symbol.coord.toIndex @@ -337,8 +337,8 @@ class ClassfileParser( var tparams = classTParams - def typeParamCompleter(start: Int) = new LazyType { - def complete(denot: SymDenotation): Unit = { + def typeParamCompleter(start: Int) = new LazyType with CompleteInCreationContext { + def completeInCreationContext(denot: SymDenotation): Unit = { val savedIndex = index try { index = start diff --git a/src/dotty/tools/dotc/core/pickling/UnPickler.scala b/src/dotty/tools/dotc/core/pickling/UnPickler.scala index 17d4e874a..706eb477e 100644 --- a/src/dotty/tools/dotc/core/pickling/UnPickler.scala +++ b/src/dotty/tools/dotc/core/pickling/UnPickler.scala @@ -490,7 +490,7 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot: }) } - class LocalUnpickler extends LazyType { + class LocalUnpickler extends LazyType with CompleteInCreationContext { def parseToCompletion(denot: SymDenotation) = { val tag = readByte() val end = readNat() + readIndex @@ -533,7 +533,7 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot: // println(s"unpickled ${denot.debugString}, info = ${denot.info}") !!! DEBUG } def startCoord(denot: SymDenotation): Coord = denot.symbol.coord - def complete(denot: SymDenotation): Unit = try { + def completeInCreationContext(denot: SymDenotation): Unit = try { atReadPos(startCoord(denot).toIndex, () => parseToCompletion(denot)) } catch { case ex: RuntimeException => handleRuntimeException(ex) |