diff options
author | Dmitry Petrashko <dark@d-d.me> | 2015-11-10 15:58:14 +0100 |
---|---|---|
committer | Dmitry Petrashko <dark@d-d.me> | 2015-11-10 15:58:14 +0100 |
commit | 7cfd3cad248f4b82da61d324c2724e779ddc5fe0 (patch) | |
tree | 9b3bf90ed32e557a6e24ff78d74fba034896d97f | |
parent | f8169b4aac2e80ce7e87fcb20c4da23c99806b04 (diff) | |
parent | 949c48e0f325afa29ebc70e94de17d525b26386e (diff) | |
download | dotty-7cfd3cad248f4b82da61d324c2724e779ddc5fe0.tar.gz dotty-7cfd3cad248f4b82da61d324c2724e779ddc5fe0.tar.bz2 dotty-7cfd3cad248f4b82da61d324c2724e779ddc5fe0.zip |
Merge pull request #928 from dotty-staging/stdlib-definitions
Make Definitions survive recompilation of core definitions.
58 files changed, 756 insertions, 562 deletions
diff --git a/src/dotty/tools/backend/jvm/CollectEntryPoints.scala b/src/dotty/tools/backend/jvm/CollectEntryPoints.scala index 80907fb99..3ed232bc7 100644 --- a/src/dotty/tools/backend/jvm/CollectEntryPoints.scala +++ b/src/dotty/tools/backend/jvm/CollectEntryPoints.scala @@ -49,13 +49,10 @@ class CollectEntryPoints extends MiniPhaseTransform { object CollectEntryPoints{ def isJavaMainMethod(sym: Symbol)(implicit ctx: Context) = { - val d = ctx.definitions - val StringType = d.StringType - (sym.name == nme.main) && (sym.info match { - case r@MethodType(_, List(d.ArrayType(t))) => - (t.widenDealias =:= StringType) && ( - r.resultType.widenDealias =:= d.UnitType) + case r@MethodType(_, List(defn.ArrayOf(t))) => + (t.widenDealias =:= defn.StringType) && ( + r.resultType.widenDealias =:= defn.UnitType) case _ => false }) } diff --git a/src/dotty/tools/backend/jvm/DottyBackendInterface.scala b/src/dotty/tools/backend/jvm/DottyBackendInterface.scala index f92abe906..1498be354 100644 --- a/src/dotty/tools/backend/jvm/DottyBackendInterface.scala +++ b/src/dotty/tools/backend/jvm/DottyBackendInterface.scala @@ -99,9 +99,6 @@ class DottyBackendInterface()(implicit ctx: Context) extends BackendInterface{ val nme_PACKAGE: Name = StdNames.nme.PACKAGE val nme_EQEQ_LOCAL_VAR: Name = StdNames.nme.EQEQ_LOCAL_VAR - val BoxesRunTimeModule = ctx.requiredModule("scala.runtime.BoxesRunTime") - val BoxesRunTimeClass = toDenot(BoxesRunTimeModule).moduleClass.asClass - // require LambdaMetafactory: scalac uses getClassIfDefined, but we need those always. override lazy val LambdaMetaFactory = ctx.requiredClass("java.lang.invoke.LambdaMetafactory") override lazy val MethodHandle = ctx.requiredClass("java.lang.invoke.MethodHandle") @@ -133,17 +130,17 @@ class DottyBackendInterface()(implicit ctx: Context) extends BackendInterface{ } val hashMethodSym: Symbol = NoSymbol // used to dispatch ## on primitives to ScalaRuntime.hash. Should be implemented by a miniphase - val externalEqualsNumNum: Symbol = ctx.requiredMethod(BoxesRunTimeClass, nme.equalsNumNum) - lazy val externalEqualsNumChar: Symbol = ??? // ctx.requiredMethod(BoxesRunTimeClass, nme.equalsNumChar) // this method is private - val externalEqualsNumObject: Symbol = ctx.requiredMethod(BoxesRunTimeClass, nme.equalsNumObject) - val externalEquals: Symbol = BoxesRunTimeClass.info.decl(nme.equals_).suchThat(toDenot(_).info.firstParamTypes.size == 2).symbol + val externalEqualsNumNum: Symbol = defn.BoxesRunTimeModule.requiredMethod(nme.equalsNumNum) + lazy val externalEqualsNumChar: Symbol = ??? // ctx.requiredMethod(BoxesRunTimeTypeRef, nme.equalsNumChar) // this method is private + val externalEqualsNumObject: Symbol = defn.BoxesRunTimeModule.requiredMethod(nme.equalsNumObject) + val externalEquals: Symbol = defn.BoxesRunTimeClass.info.decl(nme.equals_).suchThat(toDenot(_).info.firstParamTypes.size == 2).symbol val MaxFunctionArity: Int = Definitions.MaxFunctionArity - val FunctionClass: Array[Symbol] = defn.FunctionClass.asInstanceOf[Array[Symbol]] - val AbstractFunctionClass: Array[Symbol] = defn.AbstractFunctionClass.asInstanceOf[Array[Symbol]] + val FunctionClass: Array[Symbol] = defn.FunctionClassPerRun() + val AbstractFunctionClass: Array[Symbol] = defn.AbstractFunctionClassPerRun() val PartialFunctionClass: Symbol = defn.PartialFunctionClass val AbstractPartialFunctionClass: Symbol = defn.AbstractPartialFunctionClass val String_valueOf: Symbol = defn.String_valueOf_Object - lazy val Predef_classOf: Symbol = ctx.requiredMethod(toDenot(defn.ScalaPredefModule).moduleClass.asClass, nme.classOf) + lazy val Predef_classOf: Symbol = defn.ScalaPredefModule.requiredMethod(nme.classOf) lazy val AnnotationRetentionAttr = ctx.requiredClass("java.lang.annotation.Retention") lazy val AnnotationRetentionSourceAttr = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("SOURCE") @@ -151,11 +148,10 @@ class DottyBackendInterface()(implicit ctx: Context) extends BackendInterface{ lazy val AnnotationRetentionRuntimeAttr = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("RUNTIME") lazy val JavaAnnotationClass = ctx.requiredClass("java.lang.annotation.Annotation") - - def boxMethods: Map[Symbol, Symbol] = defn.ScalaValueClasses.map{x => + def boxMethods: Map[Symbol, Symbol] = defn.ScalaValueClasses().map{x => // @darkdimius Are you sure this should be a def? (x, Erasure.Boxing.boxMethod(x.asClass)) }.toMap - def unboxMethods: Map[Symbol, Symbol] = defn.ScalaValueClasses.map(x => (x, Erasure.Boxing.unboxMethod(x.asClass))).toMap + def unboxMethods: Map[Symbol, Symbol] = defn.ScalaValueClasses().map(x => (x, Erasure.Boxing.unboxMethod(x.asClass))).toMap private val mkArrayNames: Set[Name] = Set("Byte", "Float", "Char", "Double", "Boolean", "Unit", "Long", "Int", "Short", "Ref").map{ x=> ("new" + x + "Array").toTermName diff --git a/src/dotty/tools/backend/jvm/scalaPrimitives.scala b/src/dotty/tools/backend/jvm/scalaPrimitives.scala index 8e742faf1..0027defa7 100644 --- a/src/dotty/tools/backend/jvm/scalaPrimitives.scala +++ b/src/dotty/tools/backend/jvm/scalaPrimitives.scala @@ -69,7 +69,7 @@ class DottyPrimitives(ctx: Context) { } def elementType: Type = tpe.widenDealias match { - case defn.ArrayType(el) => el + case defn.ArrayOf(el) => el case JavaArrayType(el) => el case _ => ctx.error(s"expected Array $tpe") @@ -79,42 +79,42 @@ class DottyPrimitives(ctx: Context) { code match { case APPLY => - elementType.classSymbol match { - case defn.BooleanClass => ZARRAY_GET - case defn.ByteClass => BARRAY_GET - case defn.ShortClass => SARRAY_GET - case defn.CharClass => CARRAY_GET - case defn.IntClass => IARRAY_GET - case defn.LongClass => LARRAY_GET - case defn.FloatClass => FARRAY_GET - case defn.DoubleClass => DARRAY_GET - case _ => OARRAY_GET + defn.scalaClassName(elementType) match { + case tpnme.Boolean => ZARRAY_GET + case tpnme.Byte => BARRAY_GET + case tpnme.Short => SARRAY_GET + case tpnme.Char => CARRAY_GET + case tpnme.Int => IARRAY_GET + case tpnme.Long => LARRAY_GET + case tpnme.Float => FARRAY_GET + case tpnme.Double => DARRAY_GET + case _ => OARRAY_GET } case UPDATE => - elementType.classSymbol match { - case defn.BooleanClass => ZARRAY_SET - case defn.ByteClass => BARRAY_SET - case defn.ShortClass => SARRAY_SET - case defn.CharClass => CARRAY_SET - case defn.IntClass => IARRAY_SET - case defn.LongClass => LARRAY_SET - case defn.FloatClass => FARRAY_SET - case defn.DoubleClass => DARRAY_SET - case _ => OARRAY_SET + defn.scalaClassName(elementType) match { + case tpnme.Boolean => ZARRAY_SET + case tpnme.Byte => BARRAY_SET + case tpnme.Short => SARRAY_SET + case tpnme.Char => CARRAY_SET + case tpnme.Int => IARRAY_SET + case tpnme.Long => LARRAY_SET + case tpnme.Float => FARRAY_SET + case tpnme.Double => DARRAY_SET + case _ => OARRAY_SET } case LENGTH => - elementType.classSymbol match { - case defn.BooleanClass => ZARRAY_LENGTH - case defn.ByteClass => BARRAY_LENGTH - case defn.ShortClass => SARRAY_LENGTH - case defn.CharClass => CARRAY_LENGTH - case defn.IntClass => IARRAY_LENGTH - case defn.LongClass => LARRAY_LENGTH - case defn.FloatClass => FARRAY_LENGTH - case defn.DoubleClass => DARRAY_LENGTH - case _ => OARRAY_LENGTH + defn.scalaClassName(elementType) match { + case tpnme.Boolean => ZARRAY_LENGTH + case tpnme.Byte => BARRAY_LENGTH + case tpnme.Short => SARRAY_LENGTH + case tpnme.Char => CARRAY_LENGTH + case tpnme.Int => IARRAY_LENGTH + case tpnme.Long => LARRAY_LENGTH + case tpnme.Float => FARRAY_LENGTH + case tpnme.Double => DARRAY_LENGTH + case _ => OARRAY_LENGTH } case _ => diff --git a/src/dotty/tools/dotc/Compiler.scala b/src/dotty/tools/dotc/Compiler.scala index eb8ee8848..42d223fe9 100644 --- a/src/dotty/tools/dotc/Compiler.scala +++ b/src/dotty/tools/dotc/Compiler.scala @@ -5,6 +5,7 @@ import core._ import Contexts._ import Periods._ import Symbols._ +import Types._ import Scopes._ import typer.{FrontEnd, Typer, Mode, ImportInfo, RefChecks} import reporting.{Reporter, ConsoleReporter} @@ -112,8 +113,8 @@ class Compiler { .setMode(Mode.ImplicitsEnabled) .setTyperState(new MutableTyperState(ctx.typerState, rootReporter(ctx), isCommittable = true)) ctx.definitions.init(start) // set context of definitions to start - def addImport(ctx: Context, symf: () => Symbol) = - ctx.fresh.setImportInfo(ImportInfo.rootImport(symf)(ctx)) + def addImport(ctx: Context, refFn: () => TermRef) = + ctx.fresh.setImportInfo(ImportInfo.rootImport(refFn)(ctx)) (start.setRunInfo(new RunInfo(start)) /: defn.RootImportFns)(addImport) } diff --git a/src/dotty/tools/dotc/ast/Desugar.scala b/src/dotty/tools/dotc/ast/Desugar.scala index 33205dfd4..6c914c934 100644 --- a/src/dotty/tools/dotc/ast/Desugar.scala +++ b/src/dotty/tools/dotc/ast/Desugar.scala @@ -323,7 +323,7 @@ object desugar { def anyRef = ref(defn.AnyRefAlias.typeRef) def productConstr(n: Int) = { - val tycon = ref(defn.ProductNClass(n).typeRef) + val tycon = scalaDot((tpnme.Product.toString + n).toTypeName) val targs = constrVparamss.head map (_.tpt) if (targs.isEmpty) tycon else AppliedTypeTree(tycon, targs) } @@ -803,10 +803,10 @@ object desugar { makeBinop(l, op, r) case PostfixOp(t, op) => if ((ctx.mode is Mode.Type) && op == nme.raw.STAR) { - val seqClass = if (ctx.compilationUnit.isJava) defn.ArrayClass else defn.SeqClass + val seqType = if (ctx.compilationUnit.isJava) defn.ArrayType else defn.SeqType Annotated( - New(ref(defn.RepeatedAnnot.typeRef), Nil :: Nil), - AppliedTypeTree(ref(seqClass.typeRef), t)) + New(ref(defn.RepeatedAnnotType), Nil :: Nil), + AppliedTypeTree(ref(seqType), t)) } else { assert(ctx.mode.isExpr || ctx.reporter.hasErrors, ctx.mode) Select(t, op) @@ -818,22 +818,22 @@ object desugar { case Tuple(ts) => if (unboxedPairs) { def PairTypeTree(l: Tree, r: Tree) = - AppliedTypeTree(ref(defn.PairClass.typeRef), l :: r :: Nil) + AppliedTypeTree(ref(defn.PairType), l :: r :: Nil) if (ctx.mode is Mode.Type) ts.reduceRight(PairTypeTree) else if (ts.isEmpty) unitLiteral else ts.reduceRight(Pair(_, _)) } else { val arity = ts.length - def tupleClass = defn.TupleClass(arity) + def tupleTypeRef = defn.TupleType(arity) if (arity > Definitions.MaxTupleArity) { ctx.error(s"tuple too long (max allowed: ${Definitions.MaxTupleArity})", tree.pos) unitLiteral } else if (arity == 1) ts.head - else if (ctx.mode is Mode.Type) AppliedTypeTree(ref(tupleClass.typeRef), ts) + else if (ctx.mode is Mode.Type) AppliedTypeTree(ref(tupleTypeRef), ts) else if (arity == 0) unitLiteral - else Apply(ref(tupleClass.companionModule.valRef), ts) + else Apply(ref(tupleTypeRef.classSymbol.companionModule.valRef), ts) } case WhileDo(cond, body) => // { <label> def while$(): Unit = if (cond) { body; while$() } ; while$() } diff --git a/src/dotty/tools/dotc/ast/TreeInfo.scala b/src/dotty/tools/dotc/ast/TreeInfo.scala index 1266ebbd9..2b0f0aee3 100644 --- a/src/dotty/tools/dotc/ast/TreeInfo.scala +++ b/src/dotty/tools/dotc/ast/TreeInfo.scala @@ -230,7 +230,7 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] => /** Does this CaseDef catch Throwable? */ def catchesThrowable(cdef: CaseDef)(implicit ctx: Context) = - catchesAllOf(cdef, defn.ThrowableClass.typeRef) + catchesAllOf(cdef, defn.ThrowableType) /** Does this CaseDef catch everything of a certain Type? */ def catchesAllOf(cdef: CaseDef, threshold: Type)(implicit ctx: Context) = diff --git a/src/dotty/tools/dotc/ast/tpd.scala b/src/dotty/tools/dotc/ast/tpd.scala index 14a36f398..feeaad49d 100644 --- a/src/dotty/tools/dotc/ast/tpd.scala +++ b/src/dotty/tools/dotc/ast/tpd.scala @@ -2,7 +2,7 @@ package dotty.tools package dotc package ast -import dotty.tools.dotc.transform.ExplicitOuter +import dotty.tools.dotc.transform.{ExplicitOuter, Erasure} import dotty.tools.dotc.typer.ProtoTypes.FunProtoTyped import transform.SymUtils._ import core._ @@ -13,7 +13,6 @@ import config.Printers._ import typer.Mode import collection.mutable import typer.ErrorReporting._ -import transform.Erasure import scala.annotation.tailrec @@ -268,7 +267,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { def AnonClass(parents: List[Type], fns: List[TermSymbol], methNames: List[TermName])(implicit ctx: Context): Block = { val owner = fns.head.owner val parents1 = - if (parents.head.classSymbol.is(Trait)) defn.ObjectClass.typeRef :: parents + if (parents.head.classSymbol.is(Trait)) defn.ObjectType :: parents else parents val cls = ctx.newNormalizedClassSymbol(owner, tpnme.ANON_FUN, Synthetic, parents1, coord = fns.map(_.pos).reduceLeft(_ union _)) @@ -376,7 +375,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { newArr(elemClass.name.toString) else newArr("Ref").appliedToTypeTrees( - TypeTree(defn.ArrayType(elemType)).withPos(typeArg.pos) :: Nil) + TypeTree(defn.ArrayOf(elemType)).withPos(typeArg.pos) :: Nil) } // ------ Creating typed equivalents of trees that exist only in untyped form ------- @@ -778,6 +777,27 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { } else Assign(tree, rhs) + /** A tree in place of this tree that represents the class of type `tp`. + * Contains special handling if the class is a primitive value class + * and invokes a `default` method otherwise. + */ + def clsOf(tp: Type, default: => Tree)(implicit ctx: Context): Tree = { + def TYPE(module: TermSymbol) = + ref(module).select(nme.TYPE_).ensureConforms(tree.tpe).withPos(tree.pos) + defn.scalaClassName(tp) match { + case tpnme.Boolean => TYPE(defn.BoxedBooleanModule) + case tpnme.Byte => TYPE(defn.BoxedByteModule) + case tpnme.Short => TYPE(defn.BoxedShortModule) + case tpnme.Char => TYPE(defn.BoxedCharModule) + case tpnme.Int => TYPE(defn.BoxedIntModule) + case tpnme.Long => TYPE(defn.BoxedLongModule) + case tpnme.Float => TYPE(defn.BoxedFloatModule) + case tpnme.Double => TYPE(defn.BoxedDoubleModule) + case tpnme.Unit => TYPE(defn.BoxedUnitModule) + case _ => default + } + } + // --- Higher order traversal methods ------------------------------- /** Apply `f` to each subtree of this tree */ @@ -843,14 +863,14 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { val defn = ctx.definitions val prefix = args.take(selected.widen.paramTypess.head.size - 1) expectedType match { - case defn.ArrayType(el) => + case defn.ArrayOf(el) => lastParam.tpe match { - case defn.ArrayType(el2) if el2 <:< el => + case defn.ArrayOf(el2) if el2 <:< el => // we have a JavaSeqLiteral with a more precise type // we cannot construct a tree as JavaSeqLiteral infered to precise type // if we add typed than it would be both type-correct and // will pass Ycheck - prefix ::: List(tpd.Typed(lastParam, TypeTree(defn.ArrayType(el)))) + prefix ::: List(tpd.Typed(lastParam, TypeTree(defn.ArrayOf(el)))) case _ => ??? } diff --git a/src/dotty/tools/dotc/ast/untpd.scala b/src/dotty/tools/dotc/ast/untpd.scala index 5db893ff2..28a3cf1ff 100644 --- a/src/dotty/tools/dotc/ast/untpd.scala +++ b/src/dotty/tools/dotc/ast/untpd.scala @@ -201,7 +201,9 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { def ref(tp: NamedType)(implicit ctx: Context): Tree = TypedSplice(tpd.ref(tp)) - def scalaUnit(implicit ctx: Context) = ref(defn.UnitClass.typeRef) + def rootDot(name: Name) = Select(Ident(nme.ROOTPKG), name) + def scalaDot(name: Name) = Select(rootDot(nme.scala_), name) + def scalaUnit = scalaDot(tpnme.Unit) def makeConstructor(tparams: List[TypeDef], vparamss: List[List[ValDef]], rhs: Tree = EmptyTree)(implicit ctx: Context): DefDef = DefDef(nme.CONSTRUCTOR, tparams, vparamss, TypeTree(), rhs) diff --git a/src/dotty/tools/dotc/config/JavaPlatform.scala b/src/dotty/tools/dotc/config/JavaPlatform.scala index 41a9c7113..432a9a0b7 100644 --- a/src/dotty/tools/dotc/config/JavaPlatform.scala +++ b/src/dotty/tools/dotc/config/JavaPlatform.scala @@ -19,13 +19,11 @@ class JavaPlatform extends Platform { } // The given symbol is a method with the right name and signature to be a runnable java program. - def isJavaMainMethod(sym: SymDenotation)(implicit ctx: Context) = { - val dn = defn + def isJavaMainMethod(sym: SymDenotation)(implicit ctx: Context) = (sym.name == nme.main) && (sym.info match { - case t@MethodType(_, dn.ArrayType(el) :: Nil) => el =:= defn.StringType && (t.resultType isRef defn.UnitClass) + case t@MethodType(_, defn.ArrayOf(el) :: Nil) => el =:= defn.StringType && (t.resultType isRef defn.UnitClass) case _ => false }) - } // The given class has a main method. def hasJavaMainMethod(sym: Symbol)(implicit ctx: Context): Boolean = diff --git a/src/dotty/tools/dotc/config/Printers.scala b/src/dotty/tools/dotc/config/Printers.scala index b44a1d2f6..8b9cc45c4 100644 --- a/src/dotty/tools/dotc/config/Printers.scala +++ b/src/dotty/tools/dotc/config/Printers.scala @@ -22,13 +22,13 @@ object Printers { val implicitsDetailed: Printer = noPrinter val subtyping: Printer = noPrinter val unapp: Printer = noPrinter - val completions = noPrinter val gadts = noPrinter val hk = noPrinter val variances = noPrinter val incremental = noPrinter val config = noPrinter val transforms = noPrinter + val completions = noPrinter val cyclicErrors = noPrinter val pickling = noPrinter } diff --git a/src/dotty/tools/dotc/core/Annotations.scala b/src/dotty/tools/dotc/core/Annotations.scala index 6d0fba337..b9c0eca43 100644 --- a/src/dotty/tools/dotc/core/Annotations.scala +++ b/src/dotty/tools/dotc/core/Annotations.scala @@ -91,12 +91,12 @@ object Annotations { def makeChild(sym: Symbol)(implicit ctx: Context) = deferred(defn.ChildAnnot, - implicit ctx => New(defn.ChildAnnot.typeRef.appliedTo(sym.owner.thisType.select(sym.name, sym)), Nil)) + implicit ctx => New(defn.ChildAnnotType.appliedTo(sym.owner.thisType.select(sym.name, sym)), Nil)) } def ThrowsAnnotation(cls: ClassSymbol)(implicit ctx: Context) = { val tref = cls.typeRef - Annotation(defn.ThrowsAnnot.typeRef.appliedTo(tref), Ident(tref)) + Annotation(defn.ThrowsAnnotType.appliedTo(tref), Ident(tref)) } /** A decorator that provides queries for specific annotations diff --git a/src/dotty/tools/dotc/core/Constants.scala b/src/dotty/tools/dotc/core/Constants.scala index 61a23bb9e..e13e07f58 100644 --- a/src/dotty/tools/dotc/core/Constants.scala +++ b/src/dotty/tools/dotc/core/Constants.scala @@ -54,17 +54,17 @@ object Constants { def isAnyVal = UnitTag <= tag && tag <= DoubleTag def tpe(implicit ctx: Context): Type = tag match { - case UnitTag => defn.UnitClass.typeRef - case BooleanTag => defn.BooleanClass.typeRef - case ByteTag => defn.ByteClass.typeRef - case ShortTag => defn.ShortClass.typeRef - case CharTag => defn.CharClass.typeRef - case IntTag => defn.IntClass.typeRef - case LongTag => defn.LongClass.typeRef - case FloatTag => defn.FloatClass.typeRef - case DoubleTag => defn.DoubleClass.typeRef - case StringTag => defn.StringClass.typeRef - case NullTag => defn.NullClass.typeRef + case UnitTag => defn.UnitType + case BooleanTag => defn.BooleanType + case ByteTag => defn.ByteType + case ShortTag => defn.ShortType + case CharTag => defn.CharType + case IntTag => defn.IntType + case LongTag => defn.LongType + case FloatTag => defn.FloatType + case DoubleTag => defn.DoubleType + case StringTag => defn.StringType + case NullTag => defn.NullType case ClazzTag => defn.ClassType(typeValue) case EnumTag => defn.EnumType(symbolValue) } diff --git a/src/dotty/tools/dotc/core/Definitions.scala b/src/dotty/tools/dotc/core/Definitions.scala index 6f322904e..433b8544a 100644 --- a/src/dotty/tools/dotc/core/Definitions.scala +++ b/src/dotty/tools/dotc/core/Definitions.scala @@ -3,7 +3,7 @@ package dotc package core import Types._, Contexts._, Symbols._, Denotations._, SymDenotations._, StdNames._, Names._ -import Flags._, Scopes._, Decorators._, NameOps._, util.Positions._ +import Flags._, Scopes._, Decorators._, NameOps._, util.Positions._, Periods._ import unpickleScala2.Scala2Unpickler.ensureConstructor import scala.annotation.{ switch, meta } import scala.collection.{ mutable, immutable } @@ -15,7 +15,21 @@ object Definitions { val MaxFunctionArity, MaxTupleArity = 22 } -/** A class defining symbols and types of standard definitions */ +/** A class defining symbols and types of standard definitions + * + * Note: There's a much nicer design possible once we have implicit functions. + * The idea is explored to some degree in branch wip-definitions (#929): Instead of a type + * and a separate symbol definition, we produce in one line an implicit function from + * Context to Symbol, and possibly also the corresponding type. This cuts down on all + * the duplication encountered here. + * + * wip-definitions tries to do the same with an implicit conversion from a SymbolPerRun + * type to a symbol type. The problem with that is universal equality. Comparisons will + * not trigger the conversion and will therefore likely return false results. + * + * So the branch is put on hold, until we have implicit functions, which will always + * automatically be dereferenced. + */ class Definitions { import Definitions._ @@ -82,9 +96,9 @@ class Definitions { private def newT1EmptyParamsMethod(cls: ClassSymbol, name: TermName, resultTypeFn: PolyType => Type, flags: FlagSet) = newPolyMethod(cls, name, 1, pt => MethodType(Nil, resultTypeFn(pt)), flags) - private def mkArityArray(name: String, arity: Int, countFrom: Int): Array[ClassSymbol] = { - val arr = new Array[ClassSymbol](arity + 1) - for (i <- countFrom to arity) arr(i) = ctx.requiredClass(name + i) + private def mkArityArray(name: String, arity: Int, countFrom: Int): Array[TypeRef] = { + val arr = new Array[TypeRef](arity + 1) + for (i <- countFrom to arity) arr(i) = ctx.requiredClassRef(name + i) arr } @@ -114,7 +128,8 @@ class Definitions { lazy val JavaLangPackageVal = ctx.requiredPackage("java.lang") // fundamental modules lazy val SysPackage = ctx.requiredModule("scala.sys.package") - def Sys_error = ctx.requiredMethod(SysPackage.moduleClass.asClass, nme.error) + lazy val Sys_errorR = SysPackage.moduleClass.requiredMethodRef(nme.error) + def Sys_error(implicit ctx: Context) = Sys_errorR.symbol /** Note: We cannot have same named methods defined in Object and Any (and AnyVal, for that matter) * because after erasure the Any and AnyVal references get remapped to the Object methods @@ -139,7 +154,9 @@ class Definitions { * } */ lazy val AnyClass: ClassSymbol = completeClass(newCompleteClassSymbol(ScalaPackageClass, tpnme.Any, Abstract, Nil)) + def AnyType = AnyClass.typeRef lazy val AnyValClass: ClassSymbol = completeClass(newCompleteClassSymbol(ScalaPackageClass, tpnme.AnyVal, Abstract, List(AnyClass.typeRef))) + def AnyValType = AnyValClass.typeRef lazy val Any_== = newMethod(AnyClass, nme.EQ, methOfAny(BooleanType), Final) lazy val Any_!= = newMethod(AnyClass, nme.NE, methOfAny(BooleanType), Final) @@ -160,7 +177,10 @@ class Definitions { cls.info = ClassInfo(cls.owner.thisType, cls, AnyClass.typeRef :: Nil, newScope) completeClass(cls) } + def ObjectType = ObjectClass.typeRef + lazy val AnyRefAlias: TypeSymbol = newAliasType(tpnme.AnyRef, ObjectType) + def AnyRefType = AnyRefAlias.typeRef lazy val Object_eq = newMethod(ObjectClass, nme.eq, methOfAnyRef(BooleanType), Final) lazy val Object_ne = newMethod(ObjectClass, nme.ne, methOfAnyRef(BooleanType), Final) @@ -180,7 +200,7 @@ class Definitions { /** Dummy method needed by elimByName */ lazy val dummyApply = newPolyMethod( OpsPackageClass, nme.dummyApply, 1, - pt => MethodType(List(FunctionType(Nil, PolyParam(pt, 0))), PolyParam(pt, 0))) + pt => MethodType(List(FunctionOf(Nil, PolyParam(pt, 0))), PolyParam(pt, 0))) /** Method representing a throw */ lazy val throwMethod = newMethod(OpsPackageClass, nme.THROWkw, @@ -188,90 +208,140 @@ class Definitions { lazy val NothingClass: ClassSymbol = newCompleteClassSymbol( ScalaPackageClass, tpnme.Nothing, AbstractFinal, List(AnyClass.typeRef)) + def NothingType = NothingClass.typeRef lazy val NullClass: ClassSymbol = newCompleteClassSymbol( ScalaPackageClass, tpnme.Null, AbstractFinal, List(ObjectClass.typeRef)) + def NullType = NullClass.typeRef - lazy val ScalaPredefModule = ctx.requiredModule("scala.Predef") + lazy val ScalaPredefModuleRef = ctx.requiredModuleRef("scala.Predef") + def ScalaPredefModule(implicit ctx: Context) = ScalaPredefModuleRef.symbol - lazy val Predef_conforms = ctx.requiredMethod(ScalaPredefModule.moduleClass.asClass, "$conforms") + lazy val Predef_conformsR = ScalaPredefModule.requiredMethodRef("$conforms") + def Predef_conforms(implicit ctx: Context) = Predef_conformsR.symbol - lazy val ScalaRuntimeModule = ctx.requiredModule("scala.runtime.ScalaRunTime") - lazy val ScalaRuntimeClass = ScalaRuntimeModule.moduleClass.asClass + lazy val ScalaRuntimeModuleRef = ctx.requiredModuleRef("scala.runtime.ScalaRunTime") + def ScalaRuntimeModule(implicit ctx: Context) = ScalaRuntimeModuleRef.symbol + def ScalaRuntimeClass(implicit ctx: Context) = ScalaRuntimeModule.moduleClass.asClass - def runtimeMethod(name: PreName) = ctx.requiredMethod(ScalaRuntimeClass, name) + def runtimeMethodRef(name: PreName) = ScalaRuntimeModule.requiredMethodRef(name) + def ScalaRuntime_dropR(implicit ctx: Context) = runtimeMethodRef(nme.drop) + def ScalaRuntime_drop(implicit ctx: Context) = ScalaRuntime_dropR.symbol - lazy val BoxesRunTimeModule = ctx.requiredModule("scala.runtime.BoxesRunTime") - lazy val BoxesRunTimeClass = BoxesRunTimeModule.moduleClass.asClass - lazy val ScalaStaticsModule = ctx.requiredModule("scala.runtime.Statics") - lazy val ScalaStaticsClass = ScalaStaticsModule.moduleClass.asClass + lazy val BoxesRunTimeModuleRef = ctx.requiredModuleRef("scala.runtime.BoxesRunTime") + def BoxesRunTimeModule(implicit ctx: Context) = BoxesRunTimeModuleRef.symbol + def BoxesRunTimeClass(implicit ctx: Context) = BoxesRunTimeModule.moduleClass.asClass + lazy val ScalaStaticsModuleRef = ctx.requiredModuleRef("scala.runtime.Statics") + def ScalaStaticsModule(implicit ctx: Context) = ScalaStaticsModuleRef.symbol + def ScalaStaticsClass(implicit ctx: Context) = ScalaStaticsModule.moduleClass.asClass - def staticsMethod(name: PreName) = ctx.requiredMethod(ScalaStaticsClass, name) + def staticsMethodRef(name: PreName) = ScalaStaticsModule.requiredMethodRef(name) + def staticsMethod(name: PreName) = ScalaStaticsModule.requiredMethod(name) - lazy val DottyPredefModule = ctx.requiredModule("dotty.DottyPredef") - lazy val DottyArraysModule = ctx.requiredModule("dotty.runtime.Arrays") + lazy val DottyPredefModuleRef = ctx.requiredModuleRef("dotty.DottyPredef") + def DottyPredefModule(implicit ctx: Context) = DottyPredefModuleRef.symbol + lazy val DottyArraysModuleRef = ctx.requiredModuleRef("dotty.runtime.Arrays") + def DottyArraysModule(implicit ctx: Context) = DottyArraysModuleRef.symbol - def newRefArrayMethod = ctx.requiredMethod(DottyArraysModule.moduleClass.asClass, "newRefArray") + def newRefArrayMethod(implicit ctx: Context) = DottyArraysModule.requiredMethod("newRefArray") - lazy val NilModule = ctx.requiredModule("scala.collection.immutable.Nil") + lazy val NilModuleRef = ctx.requiredModuleRef("scala.collection.immutable.Nil") + def NilModule(implicit ctx: Context) = NilModuleRef.symbol -// lazy val FunctionClass: ClassSymbol = ctx.requiredClass("scala.Function") lazy val SingletonClass: ClassSymbol = // needed as a synthetic class because Scala 2.x refers to it in classfiles // but does not define it as an explicit class. newCompleteClassSymbol( ScalaPackageClass, tpnme.Singleton, PureInterfaceCreationFlags | Final, List(AnyClass.typeRef), EmptyScope) - lazy val SeqClass: ClassSymbol = ctx.requiredClass("scala.collection.Seq") - lazy val Seq_apply = ctx.requiredMethod(SeqClass, nme.apply) - lazy val Seq_head = ctx.requiredMethod(SeqClass, nme.head) - lazy val ArrayClass: ClassSymbol = ctx.requiredClass("scala.Array") - lazy val Array_apply = ctx.requiredMethod(ArrayClass, nme.apply) - lazy val Array_update = ctx.requiredMethod(ArrayClass, nme.update) - lazy val Array_length = ctx.requiredMethod(ArrayClass, nme.length) - lazy val Array_clone = ctx.requiredMethod(ArrayClass, nme.clone_) - lazy val ArrayConstructor = ctx.requiredMethod(ArrayClass, nme.CONSTRUCTOR) - lazy val traversableDropMethod = ctx.requiredMethod(ScalaRuntimeClass, nme.drop) - lazy val uncheckedStableClass: ClassSymbol = ctx.requiredClass("scala.annotation.unchecked.uncheckedStable") - - lazy val UnitClass = valueClassSymbol("scala.Unit", BoxedUnitClass, java.lang.Void.TYPE, UnitEnc) - lazy val BooleanClass = valueClassSymbol("scala.Boolean", BoxedBooleanClass, java.lang.Boolean.TYPE, BooleanEnc) - lazy val Boolean_! = BooleanClass.requiredMethod(nme.UNARY_!) - lazy val Boolean_&& = BooleanClass.requiredMethod(nme.ZAND) - lazy val Boolean_|| = BooleanClass.requiredMethod(nme.ZOR) - - lazy val ByteClass = valueClassSymbol("scala.Byte", BoxedByteClass, java.lang.Byte.TYPE, ByteEnc) - lazy val ShortClass = valueClassSymbol("scala.Short", BoxedShortClass, java.lang.Short.TYPE, ShortEnc) - lazy val CharClass = valueClassSymbol("scala.Char", BoxedCharClass, java.lang.Character.TYPE, CharEnc) - lazy val IntClass = valueClassSymbol("scala.Int", BoxedIntClass, java.lang.Integer.TYPE, IntEnc) - lazy val Int_- = IntClass.requiredMethod(nme.MINUS, List(IntType)) - lazy val Int_+ = IntClass.requiredMethod(nme.PLUS, List(IntType)) - lazy val Int_/ = IntClass.requiredMethod(nme.DIV, List(IntType)) - lazy val Int_* = IntClass.requiredMethod(nme.MUL, List(IntType)) - lazy val Int_== = IntClass.requiredMethod(nme.EQ, List(IntType)) - lazy val Int_>= = IntClass.requiredMethod(nme.GE, List(IntType)) - lazy val Int_<= = IntClass.requiredMethod(nme.LE, List(IntType)) - lazy val LongClass = valueClassSymbol("scala.Long", BoxedLongClass, java.lang.Long.TYPE, LongEnc) - lazy val Long_XOR_Long = LongClass.info.member(nme.XOR).requiredSymbol( + + lazy val SeqType: TypeRef = ctx.requiredClassRef("scala.collection.Seq") + def SeqClass(implicit ctx: Context) = SeqType.symbol.asClass + + lazy val Seq_applyR = SeqClass.requiredMethodRef(nme.apply) + def Seq_apply(implicit ctx: Context) = Seq_applyR.symbol + lazy val Seq_headR = SeqClass.requiredMethodRef(nme.head) + def Seq_head(implicit ctx: Context) = Seq_headR.symbol + + lazy val ArrayType: TypeRef = ctx.requiredClassRef("scala.Array") + def ArrayClass(implicit ctx: Context) = ArrayType.symbol.asClass + lazy val Array_applyR = ArrayClass.requiredMethodRef(nme.apply) + def Array_apply(implicit ctx: Context) = Array_applyR.symbol + lazy val Array_updateR = ArrayClass.requiredMethodRef(nme.update) + def Array_update(implicit ctx: Context) = Array_updateR.symbol + lazy val Array_lengthR = ArrayClass.requiredMethodRef(nme.length) + def Array_length(implicit ctx: Context) = Array_lengthR.symbol + lazy val Array_cloneR = ArrayClass.requiredMethodRef(nme.clone_) + def Array_clone(implicit ctx: Context) = Array_cloneR.symbol + lazy val ArrayConstructorR = ArrayClass.requiredMethodRef(nme.CONSTRUCTOR) + def ArrayConstructor(implicit ctx: Context) = ArrayConstructorR.symbol + + lazy val UnitType: TypeRef = valueTypeRef("scala.Unit", BoxedUnitType, java.lang.Void.TYPE, UnitEnc) + def UnitClass(implicit ctx: Context) = UnitType.symbol.asClass + lazy val BooleanType = valueTypeRef("scala.Boolean", BoxedBooleanType, java.lang.Boolean.TYPE, BooleanEnc) + def BooleanClass(implicit ctx: Context) = BooleanType.symbol.asClass + lazy val Boolean_notR = BooleanClass.requiredMethodRef(nme.UNARY_!) + def Boolean_! = Boolean_notR.symbol + lazy val Boolean_andR = BooleanClass.requiredMethodRef(nme.ZAND) // ### harmonize required... calls + def Boolean_&& = Boolean_andR.symbol + lazy val Boolean_orR = BooleanClass.requiredMethodRef(nme.ZOR) + def Boolean_|| = Boolean_orR.symbol + + lazy val ByteType: TypeRef = valueTypeRef("scala.Byte", BoxedByteType, java.lang.Byte.TYPE, ByteEnc) + def ByteClass(implicit ctx: Context) = ByteType.symbol.asClass + lazy val ShortType: TypeRef = valueTypeRef("scala.Short", BoxedShortType, java.lang.Short.TYPE, ShortEnc) + def ShortClass(implicit ctx: Context) = ShortType.symbol.asClass + lazy val CharType: TypeRef = valueTypeRef("scala.Char", BoxedCharType, java.lang.Character.TYPE, CharEnc) + def CharClass(implicit ctx: Context) = CharType.symbol.asClass + lazy val IntType: TypeRef = valueTypeRef("scala.Int", BoxedIntType, java.lang.Integer.TYPE, IntEnc) + def IntClass(implicit ctx: Context) = IntType.symbol.asClass + lazy val Int_minusR = IntClass.requiredMethodRef(nme.MINUS, List(IntType)) + def Int_- = Int_minusR.symbol + lazy val Int_plusR = IntClass.requiredMethodRef(nme.PLUS, List(IntType)) + def Int_+ = Int_plusR.symbol + lazy val Int_divR = IntClass.requiredMethodRef(nme.DIV, List(IntType)) + def Int_/ = Int_divR.symbol + lazy val Int_mulR = IntClass.requiredMethodRef(nme.MUL, List(IntType)) + def Int_* = Int_mulR.symbol + lazy val Int_eqR = IntClass.requiredMethodRef(nme.EQ, List(IntType)) + def Int_== = Int_eqR.symbol + lazy val Int_geR = IntClass.requiredMethodRef(nme.GE, List(IntType)) + def Int_>= = Int_geR.symbol + lazy val Int_leR = IntClass.requiredMethodRef(nme.LE, List(IntType)) + def Int_<= = Int_leR.symbol + lazy val LongType: TypeRef = valueTypeRef("scala.Long", BoxedLongType, java.lang.Long.TYPE, LongEnc) + def LongClass(implicit ctx: Context) = LongType.symbol.asClass + lazy val Long_XOR_Long = LongType.member(nme.XOR).requiredSymbol( x => (x is Method) && (x.info.firstParamTypes.head isRef defn.LongClass) ) - lazy val Long_LSR_Int = LongClass.info.member(nme.LSR).requiredSymbol( + lazy val Long_LSR_Int = LongType.member(nme.LSR).requiredSymbol( x => (x is Method) && (x.info.firstParamTypes.head isRef defn.IntClass) ) - lazy val FloatClass = valueClassSymbol("scala.Float", BoxedFloatClass, java.lang.Float.TYPE, FloatEnc) - lazy val DoubleClass = valueClassSymbol("scala.Double", BoxedDoubleClass, java.lang.Double.TYPE, DoubleEnc) - - lazy val BoxedUnitClass = ctx.requiredClass("scala.runtime.BoxedUnit") - - lazy val BoxedUnit_UNIT = BoxedUnitClass.linkedClass.requiredValue("UNIT") - - lazy val BoxedBooleanClass = ctx.requiredClass("java.lang.Boolean") - lazy val BoxedByteClass = ctx.requiredClass("java.lang.Byte") - lazy val BoxedShortClass = ctx.requiredClass("java.lang.Short") - lazy val BoxedCharClass = ctx.requiredClass("java.lang.Character") - lazy val BoxedIntClass = ctx.requiredClass("java.lang.Integer") - lazy val BoxedLongClass = ctx.requiredClass("java.lang.Long") - lazy val BoxedFloatClass = ctx.requiredClass("java.lang.Float") - lazy val BoxedDoubleClass = ctx.requiredClass("java.lang.Double") + lazy val FloatType: TypeRef = valueTypeRef("scala.Float", BoxedFloatType, java.lang.Float.TYPE, FloatEnc) + def FloatClass(implicit ctx: Context) = FloatType.symbol.asClass + lazy val DoubleType: TypeRef = valueTypeRef("scala.Double", BoxedDoubleType, java.lang.Double.TYPE, DoubleEnc) + def DoubleClass(implicit ctx: Context) = DoubleType.symbol.asClass + + lazy val BoxedUnitType: TypeRef = ctx.requiredClassRef("scala.runtime.BoxedUnit") + def BoxedUnitClass(implicit ctx: Context) = BoxedUnitType.symbol.asClass + + def BoxedUnit_UNIT(implicit ctx: Context) = BoxedUnitClass.linkedClass.requiredValue("UNIT") + + lazy val BoxedBooleanType: TypeRef = ctx.requiredClassRef("java.lang.Boolean") + def BoxedBooleanClass(implicit ctx: Context) = BoxedBooleanType.symbol.asClass + lazy val BoxedByteType: TypeRef = ctx.requiredClassRef("java.lang.Byte") + def BoxedByteClass(implicit ctx: Context) = BoxedByteType.symbol.asClass + lazy val BoxedShortType: TypeRef = ctx.requiredClassRef("java.lang.Short") + def BoxedShortClass(implicit ctx: Context) = BoxedShortType.symbol.asClass + lazy val BoxedCharType: TypeRef = ctx.requiredClassRef("java.lang.Character") + def BoxedCharClass(implicit ctx: Context) = BoxedCharType.symbol.asClass + lazy val BoxedIntType: TypeRef = ctx.requiredClassRef("java.lang.Integer") + def BoxedIntClass(implicit ctx: Context) = BoxedIntType.symbol.asClass + lazy val BoxedLongType: TypeRef = ctx.requiredClassRef("java.lang.Long") + def BoxedLongClass(implicit ctx: Context) = BoxedLongType.symbol.asClass + lazy val BoxedFloatType: TypeRef = ctx.requiredClassRef("java.lang.Float") + def BoxedFloatClass(implicit ctx: Context) = BoxedFloatType.symbol.asClass + lazy val BoxedDoubleType: TypeRef = ctx.requiredClassRef("java.lang.Double") + def BoxedDoubleClass(implicit ctx: Context) = BoxedDoubleType.symbol.asClass lazy val BoxedBooleanModule = ctx.requiredModule("java.lang.Boolean") lazy val BoxedByteModule = ctx.requiredModule("java.lang.Byte") @@ -281,7 +351,7 @@ class Definitions { lazy val BoxedLongModule = ctx.requiredModule("java.lang.Long") lazy val BoxedFloatModule = ctx.requiredModule("java.lang.Float") lazy val BoxedDoubleModule = ctx.requiredModule("java.lang.Double") - lazy val BoxedVoidModule = ctx.requiredModule("java.lang.Void") + lazy val BoxedUnitModule = ctx.requiredModule("java.lang.Void") lazy val ByNameParamClass2x = specialPolyClass(tpnme.BYNAME_PARAM_CLASS, Covariant, AnyType) lazy val EqualsPatternClass = specialPolyClass(tpnme.EQUALS_PATTERN, EmptyFlags, AnyType) @@ -289,8 +359,9 @@ class Definitions { lazy val RepeatedParamClass = specialPolyClass(tpnme.REPEATED_PARAM_CLASS, Covariant, ObjectType, SeqType) // fundamental classes - lazy val StringClass = ctx.requiredClass("java.lang.String") - lazy val StringModule = StringClass.linkedClass + lazy val StringClass = ctx.requiredClass("java.lang.String") + def StringType: Type = StringClass.typeRef + lazy val StringModule = StringClass.linkedClass lazy val String_+ = newMethod(StringClass, nme.raw.PLUS, methOfAny(StringType), Final) lazy val String_valueOf_Object = StringModule.info.member(nme.valueOf).suchThat(_.info.firstParamTypes match { @@ -298,71 +369,117 @@ class Definitions { case _ => false }).symbol - // in scalac modified to have Any as parrent - - lazy val SerializableClass = ctx.requiredClass("scala.Serializable") lazy val JavaCloneableClass = ctx.requiredClass("java.lang.Cloneable") - lazy val StringBuilderClass = ctx.requiredClass("scala.collection.mutable.StringBuilder") - lazy val NullPointerExceptionClass = ctx.requiredClass(jnme.NPException) - lazy val MatchErrorClass = ctx.requiredClass("scala.MatchError") - lazy val MatchErrorType = MatchErrorClass.typeRef - - lazy val StringAddClass = ctx.requiredClass("scala.runtime.StringAdd") - - lazy val StringAdd_+ = StringAddClass.requiredMethod(nme.raw.PLUS) - - lazy val PairClass = ctx.requiredClass("dotty.Pair") - lazy val PartialFunctionClass = ctx.requiredClass("scala.PartialFunction") - lazy val AbstractPartialFunctionClass = ctx.requiredClass("scala.runtime.AbstractPartialFunction") - lazy val SymbolClass = ctx.requiredClass("scala.Symbol") - lazy val ClassClass = ctx.requiredClass("java.lang.Class") - lazy val DynamicClass = ctx.requiredClass("scala.Dynamic") - lazy val OptionClass = ctx.requiredClass("scala.Option") - lazy val BoxedNumberClass = ctx.requiredClass("java.lang.Number") - lazy val ThrowableClass = ctx.requiredClass("java.lang.Throwable") - lazy val ClassCastExceptionClass = ctx.requiredClass("java.lang.ClassCastException") - lazy val JavaSerializableClass = ctx.requiredClass("java.lang.Serializable") - lazy val ComparableClass = ctx.requiredClass("java.lang.Comparable") - lazy val ProductClass = ctx.requiredClass("scala.Product") - lazy val Product_canEqual = ProductClass.requiredMethod(nme.canEqual_) - lazy val Product_productArity = ProductClass.requiredMethod(nme.productArity) - lazy val Product_productPrefix = ProductClass.requiredMethod(nme.productPrefix) - lazy val LanguageModuleClass = ctx.requiredModule("dotty.language").moduleClass.asClass - lazy val NonLocalReturnControlClass = ctx.requiredClass("scala.runtime.NonLocalReturnControl") + lazy val NullPointerExceptionClass = ctx.requiredClass("java.lang.NullPointerException") + lazy val ClassClass = ctx.requiredClass("java.lang.Class") + lazy val BoxedNumberClass = ctx.requiredClass("java.lang.Number") + lazy val ThrowableClass = ctx.requiredClass("java.lang.Throwable") + lazy val ClassCastExceptionClass = ctx.requiredClass("java.lang.ClassCastException") + lazy val JavaSerializableClass = ctx.requiredClass("java.lang.Serializable") + lazy val ComparableClass = ctx.requiredClass("java.lang.Comparable") + + // in scalac modified to have Any as parent + + lazy val SerializableType: TypeRef = ctx.requiredClassRef("scala.Serializable") + def SerializableClass(implicit ctx: Context) = SerializableType.symbol.asClass + lazy val StringBuilderType: TypeRef = ctx.requiredClassRef("scala.collection.mutable.StringBuilder") + def StringBuilderClass(implicit ctx: Context) = StringBuilderType.symbol.asClass + lazy val MatchErrorType: TypeRef = ctx.requiredClassRef("scala.MatchError") + def MatchErrorClass(implicit ctx: Context) = MatchErrorType.symbol.asClass + + lazy val StringAddType: TypeRef = ctx.requiredClassRef("scala.runtime.StringAdd") + def StringAddClass(implicit ctx: Context) = StringAddType.symbol.asClass + + lazy val StringAdd_plusR = StringAddClass.requiredMethodRef(nme.raw.PLUS) + def StringAdd_+(implicit ctx: Context) = StringAdd_plusR.symbol + + lazy val PairType: TypeRef = ctx.requiredClassRef("dotty.Pair") + def PairClass(implicit ctx: Context) = PairType.symbol.asClass + lazy val PartialFunctionType: TypeRef = ctx.requiredClassRef("scala.PartialFunction") + def PartialFunctionClass(implicit ctx: Context) = PartialFunctionType.symbol.asClass + lazy val AbstractPartialFunctionType: TypeRef = ctx.requiredClassRef("scala.runtime.AbstractPartialFunction") + def AbstractPartialFunctionClass(implicit ctx: Context) = AbstractPartialFunctionType.symbol.asClass + lazy val SymbolType: TypeRef = ctx.requiredClassRef("scala.Symbol") + def SymbolClass(implicit ctx: Context) = SymbolType.symbol.asClass + lazy val DynamicType: TypeRef = ctx.requiredClassRef("scala.Dynamic") + def DynamicClass(implicit ctx: Context) = DynamicType.symbol.asClass + lazy val OptionType: TypeRef = ctx.requiredClassRef("scala.Option") + def OptionClass(implicit ctx: Context) = OptionType.symbol.asClass + lazy val ProductType: TypeRef = ctx.requiredClassRef("scala.Product") + def ProductClass(implicit ctx: Context) = ProductType.symbol.asClass + lazy val Product_canEqualR = ProductClass.requiredMethodRef(nme.canEqual_) + def Product_canEqual(implicit ctx: Context) = Product_canEqualR.symbol + lazy val Product_productArityR = ProductClass.requiredMethodRef(nme.productArity) + def Product_productArity(implicit ctx: Context) = Product_productArityR.symbol + lazy val Product_productPrefixR = ProductClass.requiredMethodRef(nme.productPrefix) + def Product_productPrefix(implicit ctx: Context) = Product_productPrefixR.symbol + lazy val LanguageModuleRef = ctx.requiredModule("dotty.language") + def LanguageModuleClass(implicit ctx: Context) = LanguageModuleRef.symbol.moduleClass.asClass + lazy val NonLocalReturnControlType: TypeRef = ctx.requiredClassRef("scala.runtime.NonLocalReturnControl") // Annotation base classes - lazy val AnnotationClass = ctx.requiredClass("scala.annotation.Annotation") - lazy val ClassfileAnnotationClass = ctx.requiredClass("scala.annotation.ClassfileAnnotation") - lazy val StaticAnnotationClass = ctx.requiredClass("scala.annotation.StaticAnnotation") - lazy val TailrecAnnotationClass = ctx.requiredClass("scala.annotation.tailrec") - lazy val RemoteAnnot = ctx.requiredClass("scala.remote") - lazy val SerialVersionUIDAnnot = ctx.requiredClass("scala.SerialVersionUID") - lazy val TransientAnnot = ctx.requiredClass("scala.transient") - lazy val NativeAnnot = ctx.requiredClass("scala.native") - lazy val ScalaStrictFPAnnot = ctx.requiredClass("scala.annotation.strictfp") + lazy val AnnotationType = ctx.requiredClassRef("scala.annotation.Annotation") + def AnnotationClass(implicit ctx: Context) = AnnotationType.symbol.asClass + lazy val ClassfileAnnotationType = ctx.requiredClassRef("scala.annotation.ClassfileAnnotation") + def ClassfileAnnotationClass(implicit ctx: Context) = ClassfileAnnotationType.symbol.asClass + lazy val StaticAnnotationType = ctx.requiredClassRef("scala.annotation.StaticAnnotation") + def StaticAnnotationClass(implicit ctx: Context) = StaticAnnotationType.symbol.asClass // Annotation classes - lazy val AliasAnnot = ctx.requiredClass("dotty.annotation.internal.Alias") - lazy val ChildAnnot = ctx.requiredClass("dotty.annotation.internal.Child") - lazy val RepeatedAnnot = ctx.requiredClass("dotty.annotation.internal.Repeated") - lazy val InvariantBetweenClass = ctx.requiredClass("dotty.annotation.internal.InvariantBetween") - lazy val CovariantBetweenClass = ctx.requiredClass("dotty.annotation.internal.CovariantBetween") - lazy val ContravariantBetweenClass = ctx.requiredClass("dotty.annotation.internal.ContravariantBetween") - lazy val ScalaSignatureAnnot = ctx.requiredClass("scala.reflect.ScalaSignature") - lazy val ScalaLongSignatureAnnot = ctx.requiredClass("scala.reflect.ScalaLongSignature") - lazy val TASTYSignatureAnnot = ctx.requiredClass("scala.annotation.internal.TASTYSignature") - lazy val TASTYLongSignatureAnnot = ctx.requiredClass("scala.annotation.internal.TASTYLongSignature") - lazy val DeprecatedAnnot = ctx.requiredClass("scala.deprecated") - lazy val MigrationAnnot = ctx.requiredClass("scala.annotation.migration") - lazy val AnnotationDefaultAnnot = ctx.requiredClass("dotty.annotation.internal.AnnotationDefault") - lazy val ThrowsAnnot = ctx.requiredClass("scala.throws") - lazy val UncheckedAnnot = ctx.requiredClass("scala.unchecked") - lazy val UncheckedStableAnnot = ctx.requiredClass("scala.annotation.unchecked.uncheckedStable") - lazy val UncheckedVarianceAnnot = ctx.requiredClass("scala.annotation.unchecked.uncheckedVariance") - lazy val VolatileAnnot = ctx.requiredClass("scala.volatile") - lazy val FieldMetaAnnot = ctx.requiredClass("scala.annotation.meta.field") - lazy val GetterMetaAnnot = ctx.requiredClass("scala.annotation.meta.getter") - lazy val SetterMetaAnnot = ctx.requiredClass("scala.annotation.meta.setter") + lazy val AliasAnnotType = ctx.requiredClassRef("dotty.annotation.internal.Alias") + def AliasAnnot(implicit ctx: Context) = AliasAnnotType.symbol.asClass + lazy val AnnotationDefaultAnnotType = ctx.requiredClassRef("dotty.annotation.internal.AnnotationDefault") + def AnnotationDefaultAnnot(implicit ctx: Context) = AnnotationDefaultAnnotType.symbol.asClass + lazy val ChildAnnotType = ctx.requiredClassRef("dotty.annotation.internal.Child") + def ChildAnnot(implicit ctx: Context) = ChildAnnotType.symbol.asClass + lazy val CovariantBetweenAnnotType = ctx.requiredClassRef("dotty.annotation.internal.CovariantBetween") + def CovariantBetweenAnnot(implicit ctx: Context) = CovariantBetweenAnnotType.symbol.asClass + lazy val ContravariantBetweenAnnotType = ctx.requiredClassRef("dotty.annotation.internal.ContravariantBetween") + def ContravariantBetweenAnnot(implicit ctx: Context) = ContravariantBetweenAnnotType.symbol.asClass + lazy val DeprecatedAnnotType = ctx.requiredClassRef("scala.deprecated") + def DeprecatedAnnot(implicit ctx: Context) = DeprecatedAnnotType.symbol.asClass + lazy val InvariantBetweenAnnotType = ctx.requiredClassRef("dotty.annotation.internal.InvariantBetween") + def InvariantBetweenAnnot(implicit ctx: Context) = InvariantBetweenAnnotType.symbol.asClass + lazy val MigrationAnnotType = ctx.requiredClassRef("scala.annotation.migration") + def MigrationAnnot(implicit ctx: Context) = MigrationAnnotType.symbol.asClass + lazy val NativeAnnotType = ctx.requiredClassRef("scala.native") + def NativeAnnot(implicit ctx: Context) = NativeAnnotType.symbol.asClass + lazy val RemoteAnnotType = ctx.requiredClassRef("scala.remote") + def RemoteAnnot(implicit ctx: Context) = RemoteAnnotType.symbol.asClass + lazy val RepeatedAnnotType = ctx.requiredClassRef("dotty.annotation.internal.Repeated") + def RepeatedAnnot(implicit ctx: Context) = RepeatedAnnotType.symbol.asClass + lazy val ScalaSignatureAnnotType = ctx.requiredClassRef("scala.reflect.ScalaSignature") + def ScalaSignatureAnnot(implicit ctx: Context) = ScalaSignatureAnnotType.symbol.asClass + lazy val ScalaLongSignatureAnnotType = ctx.requiredClassRef("scala.reflect.ScalaLongSignature") + def ScalaLongSignatureAnnot(implicit ctx: Context) = ScalaLongSignatureAnnotType.symbol.asClass + lazy val ScalaStrictFPAnnotType = ctx.requiredClassRef("scala.annotation.strictfp") + def ScalaStrictFPAnnot(implicit ctx: Context) = ScalaStrictFPAnnotType.symbol.asClass + lazy val SerialVersionUIDAnnotType = ctx.requiredClassRef("scala.SerialVersionUID") + def SerialVersionUIDAnnot(implicit ctx: Context) = SerialVersionUIDAnnotType.symbol.asClass + lazy val TASTYSignatureAnnotType = ctx.requiredClassRef("scala.annotation.internal.TASTYSignature") + def TASTYSignatureAnnot(implicit ctx: Context) = TASTYSignatureAnnotType.symbol.asClass + lazy val TASTYLongSignatureAnnotType = ctx.requiredClassRef("scala.annotation.internal.TASTYLongSignature") + def TASTYLongSignatureAnnot(implicit ctx: Context) = TASTYLongSignatureAnnotType.symbol.asClass + lazy val TailrecAnnotType = ctx.requiredClassRef("scala.annotation.tailrec") + def TailrecAnnot(implicit ctx: Context) = TailrecAnnotType.symbol.asClass + lazy val ThrowsAnnotType = ctx.requiredClassRef("scala.throws") + def ThrowsAnnot(implicit ctx: Context) = ThrowsAnnotType.symbol.asClass + lazy val TransientAnnotType = ctx.requiredClassRef("scala.transient") + def TransientAnnot(implicit ctx: Context) = TransientAnnotType.symbol.asClass + lazy val UncheckedAnnotType = ctx.requiredClassRef("scala.unchecked") + def UncheckedAnnot(implicit ctx: Context) = UncheckedAnnotType.symbol.asClass + lazy val UncheckedStableAnnotType = ctx.requiredClassRef("scala.annotation.unchecked.uncheckedStable") + def UncheckedStableAnnot(implicit ctx: Context) = UncheckedStableAnnotType.symbol.asClass + lazy val UncheckedVarianceAnnotType = ctx.requiredClassRef("scala.annotation.unchecked.uncheckedVariance") + def UncheckedVarianceAnnot(implicit ctx: Context) = UncheckedVarianceAnnotType.symbol.asClass + lazy val VolatileAnnotType = ctx.requiredClassRef("scala.volatile") + def VolatileAnnot(implicit ctx: Context) = VolatileAnnotType.symbol.asClass + lazy val FieldMetaAnnotType = ctx.requiredClassRef("scala.annotation.meta.field") + def FieldMetaAnnot(implicit ctx: Context) = FieldMetaAnnotType.symbol.asClass + lazy val GetterMetaAnnotType = ctx.requiredClassRef("scala.annotation.meta.getter") + def GetterMetaAnnot(implicit ctx: Context) = GetterMetaAnnotType.symbol.asClass + lazy val SetterMetaAnnotType = ctx.requiredClassRef("scala.annotation.meta.setter") + def SetterMetaAnnot(implicit ctx: Context) = SetterMetaAnnotType.symbol.asClass // convenient one-parameter method types def methOfAny(tp: Type) = MethodType(List(AnyType), tp) @@ -370,29 +487,9 @@ class Definitions { def methOfAnyRef(tp: Type) = MethodType(List(ObjectType), tp) // Derived types - def AnyType: Type = AnyClass.typeRef - def AnyValType: Type = AnyValClass.typeRef - def ObjectType: Type = ObjectClass.typeRef - def AnyRefType: Type = AnyRefAlias.typeRef - def NothingType: Type = NothingClass.typeRef - def NullType: Type = NullClass.typeRef - def SeqType: Type = SeqClass.typeRef - - def UnitType: Type = UnitClass.typeRef - def BooleanType: Type = BooleanClass.typeRef - def ByteType: Type = ByteClass.typeRef - def ShortType: Type = ShortClass.typeRef - def CharType: Type = CharClass.typeRef - def IntType: Type = IntClass.typeRef - def LongType: Type = LongClass.typeRef - def FloatType: Type = FloatClass.typeRef - def DoubleType: Type = DoubleClass.typeRef - def PairType: Type = PairClass.typeRef - def StringType: Type = StringClass.typeRef + def RepeatedParamType = RepeatedParamClass.typeRef def ThrowableType = ThrowableClass.typeRef - def OptionType = OptionClass.typeRef - def VolatileAnnotType = VolatileAnnot.typeRef def ClassType(arg: Type)(implicit ctx: Context) = { val ctype = ClassClass.typeRef @@ -407,40 +504,52 @@ class Definitions { // - .linkedClass: the ClassSymbol of the enumeration (class E) sym.owner.linkedClass.typeRef - object FunctionType { + object FunctionOf { def apply(args: List[Type], resultType: Type)(implicit ctx: Context) = - FunctionClass(args.length).typeRef.appliedTo(args ::: resultType :: Nil) + FunctionType(args.length).appliedTo(args ::: resultType :: Nil) def unapply(ft: Type)(implicit ctx: Context)/*: Option[(List[Type], Type)]*/ = { // -language:keepUnions difference: unapply needs result type because inferred type // is Some[(List[Type], Type)] | None, which is not a legal unapply type. val tsym = ft.typeSymbol lazy val targs = ft.argInfos - if ((FunctionClasses contains tsym) && - (targs.length - 1 <= MaxFunctionArity) && - (FunctionClass(targs.length - 1) == tsym)) Some(targs.init, targs.last) + val numArgs = targs.length - 1 + if (numArgs >= 0 && numArgs <= MaxFunctionArity && + (FunctionType(numArgs).symbol == tsym)) Some(targs.init, targs.last) else None } } - object ArrayType { + object ArrayOf { def apply(elem: Type)(implicit ctx: Context) = if (ctx.erasedTypes) JavaArrayType(elem) - else ArrayClass.typeRef.appliedTo(elem :: Nil) + else ArrayType.appliedTo(elem :: Nil) def unapply(tp: Type)(implicit ctx: Context): Option[Type] = tp.dealias match { - case at: RefinedType if (at isRef ArrayClass) && at.argInfos.length == 1 => Some(at.argInfos.head) + case at: RefinedType if (at isRef ArrayType.symbol) && at.argInfos.length == 1 => Some(at.argInfos.head) case _ => None } } - object MultiArrayType { + /** An extractor for multi-dimensional arrays. + * Note that this will also extract the high bound if an + * element type is a wildcard. E.g. + * + * Array[_ <: Array[_ <: Number]] + * + * would match + * + * MultiArrayOf(<Number>, 2) + */ + object MultiArrayOf { def apply(elem: Type, ndims: Int)(implicit ctx: Context): Type = - if (ndims == 0) elem else ArrayType(apply(elem, ndims - 1)) + if (ndims == 0) elem else ArrayOf(apply(elem, ndims - 1)) def unapply(tp: Type)(implicit ctx: Context): Option[(Type, Int)] = tp match { - case ArrayType(elemtp) => - elemtp match { - case MultiArrayType(finalElemTp, n) => Some(finalElemTp, n + 1) + case ArrayOf(elemtp) => + def recur(elemtp: Type): Option[(Type, Int)] = elemtp.dealias match { + case TypeBounds(lo, hi) => recur(hi) + case MultiArrayOf(finalElemTp, n) => Some(finalElemTp, n + 1) case _ => Some(elemtp, 1) } + recur(elemtp) case _ => None } @@ -448,43 +557,71 @@ class Definitions { // ----- Symbol sets --------------------------------------------------- - lazy val AbstractFunctionClass = mkArityArray("scala.runtime.AbstractFunction", MaxFunctionArity, 0) - lazy val FunctionClass = mkArityArray("scala.Function", MaxFunctionArity, 0) - lazy val Function0_apply = FunctionClass(0).requiredMethod(nme.apply) + lazy val AbstractFunctionType = mkArityArray("scala.runtime.AbstractFunction", MaxFunctionArity, 0) + val AbstractFunctionClassPerRun = new PerRun[Array[Symbol]](implicit ctx => AbstractFunctionType.map(_.symbol.asClass)) + def AbstractFunctionClass(n: Int)(implicit ctx: Context) = AbstractFunctionClassPerRun()(ctx)(n) + lazy val FunctionType = mkArityArray("scala.Function", MaxFunctionArity, 0) + def FunctionClassPerRun = new PerRun[Array[Symbol]](implicit ctx => FunctionType.map(_.symbol.asClass)) + def FunctionClass(n: Int)(implicit ctx: Context) = FunctionClassPerRun()(ctx)(n) + lazy val Function0_applyR = FunctionType(0).symbol.requiredMethodRef(nme.apply) + def Function0_apply(implicit ctx: Context) = Function0_applyR.symbol - lazy val TupleClass = mkArityArray("scala.Tuple", MaxTupleArity, 2) - lazy val ProductNClass = mkArityArray("scala.Product", MaxTupleArity, 0) + lazy val TupleType = mkArityArray("scala.Tuple", MaxTupleArity, 2) + lazy val ProductNType = mkArityArray("scala.Product", MaxTupleArity, 0) - lazy val FunctionClasses: Set[Symbol] = FunctionClass.toSet - lazy val TupleClasses: Set[Symbol] = TupleClass.toSet - lazy val ProductClasses: Set[Symbol] = ProductNClass.toSet + private lazy val FunctionTypes: Set[TypeRef] = FunctionType.toSet + private lazy val TupleTypes: Set[TypeRef] = TupleType.toSet + private lazy val ProductTypes: Set[TypeRef] = ProductNType.toSet - /** `Modules whose members are in the default namespace and their module classes */ - lazy val UnqualifiedOwners = RootImports.toSet ++ RootImports.map(_.moduleClass) + /** If `cls` is a class in the scala package, its name, otherwise EmptyTypeName */ + def scalaClassName(cls: Symbol)(implicit ctx: Context): TypeName = + if (cls.isClass && cls.owner == ScalaPackageClass) cls.asClass.name else EmptyTypeName - lazy val PhantomClasses = Set[Symbol](AnyClass, AnyValClass, NullClass, NothingClass) + /** If type `ref` refers to a class in the scala package, its name, otherwise EmptyTypeName */ + def scalaClassName(ref: Type)(implicit ctx: Context): TypeName = scalaClassName(ref.classSymbol) + + private def isVarArityClass(cls: Symbol, prefix: Name) = { + val name = scalaClassName(cls) + name.startsWith(prefix) && name.drop(prefix.length).forall(_.isDigit) + } - lazy val isPolymorphicAfterErasure = Set[Symbol](Any_isInstanceOf, Any_asInstanceOf, newRefArrayMethod) + def isFunctionClass(cls: Symbol) = isVarArityClass(cls, tpnme.Function) + def isAbstractFunctionClass(cls: Symbol) = isVarArityClass(cls, tpnme.AbstractFunction) + def isTupleClass(cls: Symbol) = isVarArityClass(cls, tpnme.Tuple) + def isProductClass(cls: Symbol) = isVarArityClass(cls, tpnme.Product) - val RootImportFns = List[() => Symbol](() => JavaLangPackageVal, () => ScalaPackageVal, () => ScalaPredefModule, () => DottyPredefModule) + val RootImportFns = List[() => TermRef]( + () => JavaLangPackageVal.termRef, + () => ScalaPackageVal.termRef, + () => ScalaPredefModuleRef, + () => DottyPredefModuleRef) - lazy val RootImports = RootImportFns.map(_()) + lazy val RootImportTypes = RootImportFns.map(_()) + + /** `Modules whose members are in the default namespace and their module classes */ + lazy val UnqualifiedOwnerTypes: Set[NamedType] = + RootImportTypes.toSet[NamedType] ++ RootImportTypes.map(_.symbol.moduleClass.typeRef) + + lazy val PhantomClasses = Set[Symbol](AnyClass, AnyValClass, NullClass, NothingClass) + + def isPolymorphicAfterErasure(sym: Symbol) = + (sym eq Any_isInstanceOf) || (sym eq Any_asInstanceOf) || (sym eq newRefArrayMethod) def isTupleType(tp: Type)(implicit ctx: Context) = { val arity = tp.dealias.argInfos.length - arity <= MaxTupleArity && (tp isRef TupleClass(arity)) + arity <= MaxTupleArity && TupleType(arity) != null && (tp isRef TupleType(arity).symbol) } def tupleType(elems: List[Type]) = { - TupleClass(elems.size).typeRef.appliedTo(elems) + TupleType(elems.size).appliedTo(elems) } def isProductSubType(tp: Type)(implicit ctx: Context) = - (tp derivesFrom ProductClass) && tp.baseClasses.exists(ProductClasses contains _) + (tp derivesFrom ProductType.symbol) && tp.baseClasses.exists(isProductClass) def isFunctionType(tp: Type)(implicit ctx: Context) = { val arity = functionArity(tp) - 0 <= arity && arity <= MaxFunctionArity && (tp isRef FunctionClass(arity)) + 0 <= arity && arity <= MaxFunctionArity && (tp isRef FunctionType(arity).symbol) } def functionArity(tp: Type)(implicit ctx: Context) = tp.dealias.argInfos.length - 1 @@ -556,54 +693,49 @@ class Definitions { // ----- primitive value class machinery ------------------------------------------ - lazy val ScalaNumericValueClassList = List( - ByteClass, - ShortClass, - CharClass, - IntClass, - LongClass, - FloatClass, - DoubleClass) - - lazy val ScalaNumericValueClasses: collection.Set[Symbol] = ScalaNumericValueClassList.toSet - lazy val ScalaValueClasses: collection.Set[Symbol] = ScalaNumericValueClasses + UnitClass + BooleanClass - - lazy val ScalaBoxedClasses = ScalaValueClasses map boxedClass - - private[this] val _boxedClass = mutable.Map[Symbol, Symbol]() - private[this] val _unboxedClass = mutable.Map[Symbol, Symbol]() - - private[this] val _javaTypeToValueClass = mutable.Map[Class[_], Symbol]() - private[this] val _valueClassToJavaType = mutable.Map[Symbol, Class[_]]() - private[this] val _valueClassEnc = mutable.Map[Symbol, Int]() - - val boxedClass: collection.Map[Symbol, Symbol] = _boxedClass - val unboxedClass: collection.Map[Symbol, Symbol] = _boxedClass - val javaTypeToValueClass: collection.Map[Class[_], Symbol] = _javaTypeToValueClass - val valueClassToJavaType: collection.Map[Symbol, Class[_]] = _valueClassToJavaType - val valueClassEnc: collection.Map[Symbol, Int] = _valueClassEnc - - private def valueClassSymbol(name: String, boxed: ClassSymbol, jtype: Class[_], enc: Int): ClassSymbol = { - val vcls = ctx.requiredClass(name) - _unboxedClass(boxed) = vcls - _boxedClass(vcls) = boxed - _javaTypeToValueClass(jtype) = vcls - _valueClassToJavaType(vcls) = jtype - _valueClassEnc(vcls) = enc - vcls + /** This class would also be obviated by the implicit function type design */ + class PerRun[T](generate: Context => T) { + private var current: RunId = NoRunId + private var cached: T = _ + def apply()(implicit ctx: Context): T = { + if (current != ctx.runId) { + cached = generate(ctx) + current = ctx.runId + } + cached + } } - /** The classes for which a Ref type exists. */ - lazy val refClassKeys: collection.Set[Symbol] = ScalaNumericValueClasses + BooleanClass + ObjectClass + lazy val ScalaNumericValueTypeList = List( + ByteType, ShortType, CharType, IntType, LongType, FloatType, DoubleType) + + private lazy val ScalaNumericValueTypes: collection.Set[TypeRef] = ScalaNumericValueTypeList.toSet + private lazy val ScalaValueTypes: collection.Set[TypeRef] = ScalaNumericValueTypes + UnitType + BooleanType + private lazy val ScalaBoxedTypes = ScalaValueTypes map (t => boxedTypes(t.name)) - lazy val refClass: Map[Symbol, Symbol] = - refClassKeys.map(rc => rc -> ctx.requiredClass(s"scala.runtime.${rc.name}Ref")).toMap + val ScalaNumericValueClasses = new PerRun[collection.Set[Symbol]](implicit ctx => ScalaNumericValueTypes.map(_.symbol)) + val ScalaValueClasses = new PerRun[collection.Set[Symbol]](implicit ctx => ScalaValueTypes.map(_.symbol)) + val ScalaBoxedClasses = new PerRun[collection.Set[Symbol]](implicit ctx => ScalaBoxedTypes.map(_.symbol)) - lazy val volatileRefClass: Map[Symbol, Symbol] = - refClassKeys.map(rc => rc -> ctx.requiredClass(s"scala.runtime.Volatile${rc.name}Ref")).toMap + private val boxedTypes = mutable.Map[TypeName, TypeRef]() + private val valueTypeEnc = mutable.Map[TypeName, PrimitiveClassEnc]() - lazy val boxedRefClasses: collection.Set[Symbol] = - refClassKeys.flatMap(k => Set(refClass(k), volatileRefClass(k))) +// private val unboxedTypeRef = mutable.Map[TypeName, TypeRef]() +// private val javaTypeToValueTypeRef = mutable.Map[Class[_], TypeRef]() +// private val valueTypeNameToJavaType = mutable.Map[TypeName, Class[_]]() + + private def valueTypeRef(name: String, boxed: TypeRef, jtype: Class[_], enc: Int): TypeRef = { + val vcls = ctx.requiredClassRef(name) + boxedTypes(vcls.name) = boxed + valueTypeEnc(vcls.name) = enc +// unboxedTypeRef(boxed.name) = vcls +// javaTypeToValueTypeRef(jtype) = vcls +// valueTypeNameToJavaType(vcls.name) = jtype + vcls + } + + /** The type of the boxed class corresponding to primitive value type `tp`. */ + def boxedType(tp: Type)(implicit ctx: Context): TypeRef = boxedTypes(scalaClassName(tp)) def wrapArrayMethodName(elemtp: Type): TermName = { val cls = elemtp.classSymbol @@ -612,6 +744,8 @@ class Definitions { else nme.genericWrapArray } + type PrimitiveClassEnc = Int + val ByteEnc = 2 val ShortEnc = ByteEnc * 3 val CharEnc = 5 @@ -622,8 +756,10 @@ class Definitions { val BooleanEnc = 17 val UnitEnc = 19 - def isValueSubClass(cls1: Symbol, cls2: Symbol)(implicit ctx: Context) = - valueClassEnc(cls2) % valueClassEnc(cls1) == 0 + def isValueSubType(tref1: TypeRef, tref2: TypeRef)(implicit ctx: Context) = + valueTypeEnc(tref2.name) % valueTypeEnc(tref1.name) == 0 + def isValueSubClass(sym1: Symbol, sym2: Symbol) = + valueTypeEnc(sym2.asClass.name) % valueTypeEnc(sym1.asClass.name) == 0 // ----- Initialization --------------------------------------------------- @@ -645,13 +781,13 @@ class Definitions { lazy val syntheticCoreMethods = AnyMethods ++ ObjectMethods ++ List(String_+) private[this] var _isInitialized = false - def isInitialized = _isInitialized + private def isInitialized = _isInitialized def init(implicit ctx: Context) = { this.ctx = ctx if (!_isInitialized) { // force initialization of every symbol that is synthesized or hijacked by the compiler - val forced = syntheticCoreClasses ++ syntheticCoreMethods ++ ScalaValueClasses + val forced = syntheticCoreClasses ++ syntheticCoreMethods ++ ScalaValueClasses() _isInitialized = true } } diff --git a/src/dotty/tools/dotc/core/Denotations.scala b/src/dotty/tools/dotc/core/Denotations.scala index 65df55a9d..666908fab 100644 --- a/src/dotty/tools/dotc/core/Denotations.scala +++ b/src/dotty/tools/dotc/core/Denotations.scala @@ -207,14 +207,20 @@ object Denotations { def requiredMethod(name: PreName)(implicit ctx: Context): TermSymbol = info.member(name.toTermName).requiredSymbol(_ is Method).asTerm + def requiredMethodRef(name: PreName)(implicit ctx: Context): TermRef = + requiredMethod(name).termRef def requiredMethod(name: PreName, argTypes: List[Type])(implicit ctx: Context): TermSymbol = info.member(name.toTermName).requiredSymbol(x=> (x is Method) && x.info.paramTypess == List(argTypes) ).asTerm + def requiredMethodRef(name: PreName, argTypes: List[Type])(implicit ctx: Context): TermRef = + requiredMethod(name, argTypes).termRef def requiredValue(name: PreName)(implicit ctx: Context): TermSymbol = info.member(name.toTermName).requiredSymbol(_.info.isParameterless).asTerm + def requiredValueRef(name: PreName)(implicit ctx: Context): TermRef = + requiredValue(name).termRef def requiredClass(name: PreName)(implicit ctx: Context): ClassSymbol = info.member(name.toTypeName).requiredSymbol(_.isClass).asClass diff --git a/src/dotty/tools/dotc/core/Scopes.scala b/src/dotty/tools/dotc/core/Scopes.scala index ad9ba4201..3daa8117e 100644 --- a/src/dotty/tools/dotc/core/Scopes.scala +++ b/src/dotty/tools/dotc/core/Scopes.scala @@ -142,6 +142,8 @@ object Scopes { def openForMutations: MutableScope = unsupported("openForMutations") final def toText(printer: Printer): Text = printer.toText(this) + + def checkConsistent()(implicit ctx: Context) = () } /** A subclass of Scope that defines methods for entering and @@ -240,6 +242,7 @@ object Scopes { else { hashTable = new Array[ScopeEntry](tableSize) enterAllInHash(lastEntry) + // checkConsistent() // DEBUG } private def enterAllInHash(e: ScopeEntry, n: Int = 0)(implicit ctx: Context): Unit = { @@ -378,6 +381,17 @@ object Scopes { } override def openForMutations: MutableScope = this + + /** Check that all symbols in this scope are in their correct hashtable buckets. */ + override def checkConsistent()(implicit ctx: Context) = { + var e = lastEntry + while (e != null) { + var e1 = lookupEntry(e.name) + while (e1 != e && e1 != null) e1 = lookupNextEntry(e1) + assert(e1 == e, s"PANIC: Entry ${e.name} is badly linked") + e = e.prev + } + } } /** Create a new scope */ diff --git a/src/dotty/tools/dotc/core/StdNames.scala b/src/dotty/tools/dotc/core/StdNames.scala index 7c73d95da..e8cddd3d4 100644 --- a/src/dotty/tools/dotc/core/StdNames.scala +++ b/src/dotty/tools/dotc/core/StdNames.scala @@ -176,19 +176,22 @@ object StdNames { final val LAMBDA_ARG_PREFIX: N = "hk$" final val LAMBDA_ARG_PREFIXhead: Char = LAMBDA_ARG_PREFIX.head - final val Any: N = "Any" - final val AnyVal: N = "AnyVal" - final val ExprApi: N = "ExprApi" - final val Mirror: N = "Mirror" - final val Nothing: N = "Nothing" - final val Null: N = "Null" - final val Object: N = "Object" - final val PartialFunction: N = "PartialFunction" - final val PrefixType: N = "PrefixType" - final val Product: N = "Product" - final val Serializable: N = "Serializable" - final val Singleton: N = "Singleton" - final val Throwable: N = "Throwable" + final val AbstractFunction: N = "AbstractFunction" + final val Any: N = "Any" + final val AnyVal: N = "AnyVal" + final val ExprApi: N = "ExprApi" + final val Function: N = "Function" + final val Mirror: N = "Mirror" + final val Nothing: N = "Nothing" + final val Null: N = "Null" + final val Object: N = "Object" + final val PartialFunction: N = "PartialFunction" + final val PrefixType: N = "PrefixType" + final val Product: N = "Product" + final val Serializable: N = "Serializable" + final val Singleton: N = "Singleton" + final val Throwable: N = "Throwable" + final val Tuple: N = "Tuple" final val ClassfileAnnotation: N = "ClassfileAnnotation" final val ClassManifest: N = "ClassManifest" diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index 20d674b86..5d079640f 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -163,6 +163,11 @@ object SymDenotations { } private def completeFrom(completer: LazyType)(implicit ctx: Context): Unit = { + if (completions ne noPrinter) { + completions.println(i"${" " * indent}completing ${if (isType) "type" else "val"} $name") + indent += 1 + } + indent += 1 if (myFlags is Touched) throw CyclicReference(this) myFlags |= Touched @@ -173,6 +178,11 @@ object SymDenotations { completions.println(s"error while completing ${this.debugString}") throw ex } + finally + if (completions ne noPrinter) { + indent -= 1 + completions.println(i"${" " * indent}completed $name in $owner") + } // completions.println(s"completed ${this.debugString}") } @@ -417,10 +427,12 @@ object SymDenotations { name.toTermName == nme.EVT2U /** Is symbol a primitive value class? */ - def isPrimitiveValueClass(implicit ctx: Context) = defn.ScalaValueClasses contains symbol + def isPrimitiveValueClass(implicit ctx: Context) = + maybeOwner == defn.ScalaPackageClass && defn.ScalaValueClasses().contains(symbol) /** Is symbol a primitive numeric value class? */ - def isNumericValueClass(implicit ctx: Context) = defn.ScalaNumericValueClasses contains symbol + def isNumericValueClass(implicit ctx: Context) = + maybeOwner == defn.ScalaPackageClass && defn.ScalaNumericValueClasses().contains(symbol) /** Is symbol a phantom class for which no runtime representation exists? */ def isPhantomClass(implicit ctx: Context) = defn.PhantomClasses contains symbol @@ -1870,4 +1882,6 @@ object SymDenotations { } private val AccessorOrLabel = Accessor | Label + + @sharable private var indent = 0 // for completions printing } diff --git a/src/dotty/tools/dotc/core/Symbols.scala b/src/dotty/tools/dotc/core/Symbols.scala index 100f87a54..e33f9651e 100644 --- a/src/dotty/tools/dotc/core/Symbols.scala +++ b/src/dotty/tools/dotc/core/Symbols.scala @@ -339,9 +339,13 @@ trait Symbols { this: Context => def requiredPackage(path: PreName): TermSymbol = base.staticRef(path.toTermName).requiredSymbol(_ is Package).asTerm + def requiredPackageRef(path: PreName): TermRef = requiredPackage(path).termRef + def requiredClass(path: PreName): ClassSymbol = base.staticRef(path.toTypeName).requiredSymbol(_.isClass).asClass + def requiredClassRef(path: PreName): TypeRef = requiredClass(path).typeRef + /** Get ClassSymbol if class is either defined in current compilation run * or present on classpath. * Returns NoSymbol otherwise. */ @@ -351,8 +355,7 @@ trait Symbols { this: Context => def requiredModule(path: PreName): TermSymbol = base.staticRef(path.toTermName).requiredSymbol(_ is Module).asTerm - def requiredMethod(cls: ClassSymbol, name: PreName): TermSymbol = - cls.info.member(name.toTermName).requiredSymbol(_ is Method).asTerm + def requiredModuleRef(path: PreName): TermRef = requiredModule(path).termRef } object Symbols { diff --git a/src/dotty/tools/dotc/core/TypeApplications.scala b/src/dotty/tools/dotc/core/TypeApplications.scala index 7274c1f70..2631e9964 100644 --- a/src/dotty/tools/dotc/core/TypeApplications.scala +++ b/src/dotty/tools/dotc/core/TypeApplications.scala @@ -444,7 +444,7 @@ class TypeApplications(val self: Type) extends AnyVal { /** The element type of a sequence or array */ def elemType(implicit ctx: Context): Type = self match { - case defn.ArrayType(elemtp) => elemtp + case defn.ArrayOf(elemtp) => elemtp case JavaArrayType(elemtp) => elemtp case _ => firstBaseArgInfo(defn.SeqClass) } diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala index 684e9cbfd..2045de3ce 100644 --- a/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/src/dotty/tools/dotc/core/TypeComparer.scala @@ -808,7 +808,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { /** The greatest lower bound of a list types */ final def glb(tps: List[Type]): Type = - (defn.AnyType /: tps)(glb) + ((defn.AnyType: Type) /: tps)(glb) /** The least upper bound of two types * @note We do not admit singleton types in or-types as lubs. @@ -837,7 +837,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { /** The least upper bound of a list of types */ final def lub(tps: List[Type]): Type = - (defn.NothingType /: tps)(lub) + ((defn.NothingType: Type) /: tps)(lub) /** Merge `t1` into `tp2` if t1 is a subtype of some &-summand of tp2. */ diff --git a/src/dotty/tools/dotc/core/TypeErasure.scala b/src/dotty/tools/dotc/core/TypeErasure.scala index 35c24ff5a..8f116c85f 100644 --- a/src/dotty/tools/dotc/core/TypeErasure.scala +++ b/src/dotty/tools/dotc/core/TypeErasure.scala @@ -176,7 +176,7 @@ object TypeErasure { else if (sym.isConstructor) outer.addParam(sym.owner.asClass, erase(tp)(erasureCtx)) else erase.eraseInfo(tp, sym)(erasureCtx) match { case einfo: MethodType if sym.isGetter && einfo.resultType.isRef(defn.UnitClass) => - MethodType(Nil, defn.BoxedUnitClass.typeRef) + MethodType(Nil, defn.BoxedUnitType) case einfo => einfo } @@ -360,7 +360,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean else classParents.mapConserve(eraseTypeRef) match { case tr :: trs1 => assert(!tr.classSymbol.is(Trait), cls) - val tr1 = if (cls is Trait) defn.ObjectClass.typeRef else tr + val tr1 = if (cls is Trait) defn.ObjectType else tr tr1 :: trs1.filterNot(_ isRef defn.ObjectClass) case nil => nil } @@ -375,7 +375,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean } private def eraseArray(tp: RefinedType)(implicit ctx: Context) = { - val defn.ArrayType(elemtp) = tp + val defn.ArrayOf(elemtp) = tp def arrayErasure(tpToErase: Type) = erasureFn(isJava, semiEraseVCs = false, isConstructor, wildcardOK)(tpToErase) if (elemtp derivesFrom defn.NullClass) JavaArrayType(defn.ObjectType) @@ -456,14 +456,14 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean if (erasedVCRef.exists) return sigName(erasedVCRef) } normalizeClass(sym.asClass).fullName.asTypeName - case defn.ArrayType(elem) => + case defn.ArrayOf(elem) => sigName(this(tp)) case JavaArrayType(elem) => sigName(elem) ++ "[]" case tp: TermRef => sigName(tp.widen) case ExprType(rt) => - sigName(defn.FunctionType(Nil, rt)) + sigName(defn.FunctionOf(Nil, rt)) case tp: TypeProxy => sigName(tp.underlying) case ErrorType | WildcardType => diff --git a/src/dotty/tools/dotc/core/TypeOps.scala b/src/dotty/tools/dotc/core/TypeOps.scala index aa643256c..4cfc52909 100644 --- a/src/dotty/tools/dotc/core/TypeOps.scala +++ b/src/dotty/tools/dotc/core/TypeOps.scala @@ -481,7 +481,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object. formals = formals.updated(name, tp1.typeParamNamed(name)) normalizeToRef(tp1) case ErrorType => - defn.AnyClass.typeRef + defn.AnyType case AnnotatedType(_, tpe) => normalizeToRef(tpe) case _ => diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index bfff1a448..4ccbd4b4c 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -607,9 +607,9 @@ object Types { /** Is this type a primitive value type which can be widened to the primitive value type `that`? */ def isValueSubType(that: Type)(implicit ctx: Context) = widen match { - case self: TypeRef if defn.ScalaValueClasses contains self.symbol => + case self: TypeRef if self.symbol.isPrimitiveValueClass => that.widenExpr match { - case that: TypeRef if defn.ScalaValueClasses contains that.symbol => + case that: TypeRef if that.symbol.isPrimitiveValueClass => defn.isValueSubClass(self.symbol, that.symbol) case _ => false @@ -746,7 +746,8 @@ object Types { */ final def dealias(implicit ctx: Context): Type = this match { case tp: TypeRef => - tp.info match { + if (tp.symbol.isClass) tp + else tp.info match { case TypeAlias(tp) => tp.dealias case _ => tp } @@ -964,7 +965,7 @@ object Types { /** The first parent of this type, AnyRef if list of parents is empty */ def firstParent(implicit ctx: Context): TypeRef = parents match { case p :: _ => p - case _ => defn.AnyClass.typeRef + case _ => defn.AnyType } /** the self type of the underlying classtype */ @@ -1101,7 +1102,7 @@ object Types { def toFunctionType(dropLast: Int = 0)(implicit ctx: Context): Type = this match { case mt @ MethodType(_, formals) if !mt.isDependent || ctx.mode.is(Mode.AllowDependentFunctions) => val formals1 = if (dropLast == 0) formals else formals dropRight dropLast - defn.FunctionType( + defn.FunctionOf( formals1 mapConserve (_.underlyingIfRepeated(mt.isJava)), mt.resultType) } @@ -1387,7 +1388,7 @@ object Types { (lastSymbol.infoOrCompleter == ErrorType || sym.owner.derivesFrom(lastSymbol.owner) && sym.owner != lastSymbol.owner ), - s"data race? overwriting symbol of ${this.show} / $this / ${this.getClass} / ${lastSymbol.id} / ${sym.id} / ${sym.owner} / ${lastSymbol.owner} / ${ctx.phase}") + s"data race? overwriting symbol of ${this.show} / $this / ${this.getClass} / ${lastSymbol.id} / ${sym.id} / ${sym.owner} / ${lastSymbol.owner} / ${ctx.phase} at run ${ctx.runId}") protected def sig: Signature = Signature.NotAMethod @@ -3258,7 +3259,7 @@ object Types { val ex = new CyclicReference(denot) if (!(ctx.mode is typer.Mode.CheckCyclic)) { cyclicErrors.println(ex.getMessage) - for (elem <- ex.getStackTrace take 50) + for (elem <- ex.getStackTrace take 200) cyclicErrors.println(elem.toString) } ex diff --git a/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala b/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala index b948efebb..9ea24324b 100644 --- a/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala +++ b/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala @@ -104,7 +104,7 @@ class ClassfileParser( /** Parse parents for Java classes. For Scala, return AnyRef, since the real type will be unpickled. * Updates the read pointer of 'in'. */ def parseParents: List[Type] = { - val superType = if (isAnnotation) { in.nextChar; defn.AnnotationClass.typeRef } + val superType = if (isAnnotation) { in.nextChar; defn.AnnotationType } else pool.getSuperClass(in.nextChar).typeRef val ifaceCount = in.nextChar var ifaces = for (i <- (0 until ifaceCount).toList) yield pool.getSuperClass(in.nextChar).typeRef @@ -115,7 +115,7 @@ class ClassfileParser( // is found. If we treat constant subtyping specially, we might be able // to do something there. But in any case, the until should be more efficient. - if (isAnnotation) ifaces = defn.ClassfileAnnotationClass.typeRef :: ifaces + if (isAnnotation) ifaces = defn.ClassfileAnnotationType :: ifaces superType :: ifaces } @@ -324,7 +324,7 @@ class ClassfileParser( if (elemtp.typeSymbol.isAbstractType && !(elemtp.derivesFrom(defn.ObjectClass))) { elemtp = AndType(elemtp, defn.ObjectType) } - defn.ArrayType(elemtp) + defn.ArrayOf(elemtp) case '(' => // we need a method symbol. given in line 486 by calling getType(methodSym, ..) val paramtypes = new ListBuffer[Type]() @@ -614,7 +614,7 @@ class ClassfileParser( addConstr(paramTypes) if (paramTypes.nonEmpty) paramTypes.last match { - case defn.ArrayType(elemtp) => + case defn.ArrayOf(elemtp) => addConstr(paramTypes.init :+ defn.RepeatedParamType.appliedTo(elemtp)) case _ => } diff --git a/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index 9269109ad..709270994 100644 --- a/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -99,17 +99,21 @@ object Scala2Unpickler { case TempPolyType(tps, cinfo) => (tps, cinfo) case cinfo => (Nil, cinfo) } + val ost = + if ((selfInfo eq NoType) && (denot is ModuleClass)) + denot.owner.thisType select denot.sourceModule + else selfInfo + + denot.info = ClassInfo(denot.owner.thisType, denot.classSymbol, Nil, decls, ost) // first rough info to avoid CyclicReferences var parentRefs = ctx.normalizeToClassRefs(parents, cls, decls) - if (parentRefs.isEmpty) parentRefs = defn.ObjectClass.typeRef :: Nil + if (parentRefs.isEmpty) parentRefs = defn.ObjectType :: Nil for (tparam <- tparams) { val tsym = decls.lookup(tparam.name) if (tsym.exists) tsym.setFlag(TypeParam) else denot.enter(tparam, decls) } - val ost = - if ((selfInfo eq NoType) && (denot is ModuleClass)) - denot.owner.thisType select denot.sourceModule - else selfInfo + denot.info = ClassInfo( + denot.owner.thisType, denot.classSymbol, parentRefs, decls, ost) // more refined infowith parents if (!(denot.flagsUNSAFE is JavaModule)) ensureConstructor(denot.symbol.asClass, decls) val scalacCompanion = denot.classSymbol.scalacLinkedClass @@ -140,7 +144,7 @@ object Scala2Unpickler { decls1 } - denot.info = ClassInfo( + denot.info = ClassInfo( // final info denot.owner.thisType, denot.classSymbol, parentRefs, declsInRightOrder, ost) } } @@ -379,6 +383,9 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas if (sym.exists || owner.ne(defn.ObjectClass)) sym else declIn(defn.AnyClass) } + def slowSearch(name: Name): Symbol = + owner.info.decls.find(_.name == name).getOrElse(NoSymbol) + def nestedObjectSymbol: Symbol = { // If the owner is overloaded (i.e. a method), it's not possible to select the // right member, so return NoSymbol. This can only happen when unpickling a tree. @@ -410,13 +417,16 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas fromName(name.toTermName.expandedName(owner)) orElse { // (3) Try as a nested object symbol. nestedObjectSymbol orElse { - // // (4) Call the mirror's "missing" hook. + // (4) Call the mirror's "missing" hook. adjust(ctx.base.missingHook(owner, name)) orElse { // println(owner.info.decls.toList.map(_.debugString).mkString("\n ")) // !!! DEBUG // } // (5) Create a stub symbol to defer hard failure a little longer. - println(i"***** missing reference, looking for $name in $owner") - println(i"decls = ${owner.info.decls}") + System.err.println(i"***** missing reference, looking for $name in $owner") + System.err.println(i"decls = ${owner.info.decls}") + owner.info.decls.checkConsistent() + if (slowSearch(name).exists) + System.err.println(i"**** slow search found: ${slowSearch(name)}") new Exception().printStackTrace() ctx.newStubSymbol(owner, name, source) } @@ -852,7 +862,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas val end = readNat() + readIndex // array elements are trees representing instances of scala.annotation.Annotation SeqLiteral( - defn.SeqType.appliedTo(defn.AnnotationClass.typeRef :: Nil), + defn.SeqType.appliedTo(defn.AnnotationType :: Nil), until(end, () => readClassfileAnnotArg(readNat()))) } diff --git a/src/dotty/tools/dotc/parsing/JavaParsers.scala b/src/dotty/tools/dotc/parsing/JavaParsers.scala index 52bcdb965..be7822cdc 100644 --- a/src/dotty/tools/dotc/parsing/JavaParsers.scala +++ b/src/dotty/tools/dotc/parsing/JavaParsers.scala @@ -92,12 +92,10 @@ object JavaParsers { // --------- tree building ----------------------------- - def rootId(name: Name) = Select(Ident(nme.ROOTPKG), name) - def scalaDot(name: Name) = Select(Ident(nme.scala_), name) def scalaAnnotationDot(name: Name) = Select(scalaDot(nme.annotation), name) def javaDot(name: Name): Tree = - Select(rootId(nme.java), name) + Select(rootDot(nme.java), name) def javaLangDot(name: Name): Tree = Select(javaDot(nme.lang), name) diff --git a/src/dotty/tools/dotc/parsing/SymbolicXMLBuilder.scala b/src/dotty/tools/dotc/parsing/SymbolicXMLBuilder.scala index 46d2a450e..20b655a19 100644 --- a/src/dotty/tools/dotc/parsing/SymbolicXMLBuilder.scala +++ b/src/dotty/tools/dotc/parsing/SymbolicXMLBuilder.scala @@ -70,7 +70,7 @@ class SymbolicXMLBuilder(parser: Parser, preserveWS: Boolean)(implicit ctx: Cont private def const(x: Any) = Literal(Constant(x)) private def wild = Ident(nme.WILDCARD) private def wildStar = Ident(tpnme.WILDCARD_STAR) - private def _scala(name: Name) = Select(Select(Ident(nme.ROOTPKG), nme.scala_), name) + private def _scala(name: Name) = scalaDot(name) private def _scala_xml(name: Name) = Select(_scala(_xml), name) private def _scala_xml_Comment = _scala_xml(_Comment) diff --git a/src/dotty/tools/dotc/printing/PlainPrinter.scala b/src/dotty/tools/dotc/printing/PlainPrinter.scala index 5daef9fb8..8b2d68570 100644 --- a/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -245,10 +245,10 @@ class PlainPrinter(_ctx: Context) extends Printer { } } - protected def isOmittablePrefix(sym: Symbol) = - (defn.UnqualifiedOwners contains sym) || isEmptyPrefix(sym) + protected def isOmittablePrefix(sym: Symbol): Boolean = + defn.UnqualifiedOwnerTypes.exists(_.symbol == sym) || isEmptyPrefix(sym) - protected def isEmptyPrefix(sym: Symbol) = + protected def isEmptyPrefix(sym: Symbol): Boolean = sym.isEffectiveRoot || sym.isAnonymousClass || sym.name.isReplWrapperName /** String representation of a definition's type following its name, diff --git a/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/src/dotty/tools/dotc/printing/RefinedPrinter.scala index d50b551fa..7065976dc 100644 --- a/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -115,8 +115,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { val cls = tycon.typeSymbol if (cls.typeParams.length == args.length) { if (tycon.isRepeatedParam) return toTextLocal(args.head) ~ "*" - if (defn.FunctionClasses contains cls) return toTextFunction(args) - if (defn.TupleClasses contains cls) return toTextTuple(args) + if (defn.isFunctionClass(cls)) return toTextFunction(args) + if (defn.isTupleClass(cls)) return toTextTuple(args) } return (toTextLocal(tycon) ~ "[" ~ Text(args map argText, ", ") ~ "]").close } diff --git a/src/dotty/tools/dotc/transform/AugmentScala2Traits.scala b/src/dotty/tools/dotc/transform/AugmentScala2Traits.scala index 779f0d647..9c01aaa9a 100644 --- a/src/dotty/tools/dotc/transform/AugmentScala2Traits.scala +++ b/src/dotty/tools/dotc/transform/AugmentScala2Traits.scala @@ -53,7 +53,7 @@ class AugmentScala2Traits extends MiniPhaseTransform with IdentityDenotTransform owner = mixin.owner, name = mixin.name.implClassName, flags = Abstract | Scala2x, - parents = defn.ObjectClass.typeRef :: Nil, + parents = defn.ObjectType :: Nil, assocFile = mixin.assocFile).enteredAfter(thisTransform) def implMethod(meth: TermSymbol): Symbol = { diff --git a/src/dotty/tools/dotc/transform/CapturedVars.scala b/src/dotty/tools/dotc/transform/CapturedVars.scala index 0f1a60282..cd05589c3 100644 --- a/src/dotty/tools/dotc/transform/CapturedVars.scala +++ b/src/dotty/tools/dotc/transform/CapturedVars.scala @@ -24,9 +24,30 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisTransfo val phaseName: String = "capturedVars" val treeTransform = new Transform(Set()) + private class RefInfo(implicit ctx: Context) { + /** The classes for which a Ref type exists. */ + val refClassKeys: collection.Set[Symbol] = + defn.ScalaNumericValueClasses() + defn.BooleanClass + defn.ObjectClass + + val refClass: Map[Symbol, Symbol] = + refClassKeys.map(rc => rc -> ctx.requiredClass(s"scala.runtime.${rc.name}Ref")).toMap + + val volatileRefClass: Map[Symbol, Symbol] = + refClassKeys.map(rc => rc -> ctx.requiredClass(s"scala.runtime.Volatile${rc.name}Ref")).toMap + + val boxedRefClasses: collection.Set[Symbol] = + refClassKeys.flatMap(k => Set(refClass(k), volatileRefClass(k))) + } + class Transform(captured: collection.Set[Symbol]) extends TreeTransform { def phase = thisTransform + private var myRefInfo: RefInfo = null + private def refInfo(implicit ctx: Context) = { + if (myRefInfo == null) myRefInfo = new RefInfo() + myRefInfo + } + private class CollectCaptured(implicit ctx: Context) extends EnclosingMethodTraverser { private val captured = mutable.HashSet[Symbol]() def traverse(enclMeth: Symbol, tree: Tree)(implicit ctx: Context) = tree match { @@ -54,16 +75,19 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisTransfo /** The {Volatile|}{Int|Double|...|Object}Ref class corresponding to the class `cls`, * depending on whether the reference should be @volatile */ - def refCls(cls: Symbol, isVolatile: Boolean)(implicit ctx: Context): Symbol = { - val refMap = if (isVolatile) defn.volatileRefClass else defn.refClass - refMap.getOrElse(cls, refMap(defn.ObjectClass)) + def refClass(cls: Symbol, isVolatile: Boolean)(implicit ctx: Context): Symbol = { + val refMap = if (isVolatile) refInfo.volatileRefClass else refInfo.refClass + if (cls.isClass) { + refMap.getOrElse(cls, refMap(defn.ObjectClass)) + } + else refMap(defn.ObjectClass) } override def prepareForValDef(vdef: ValDef)(implicit ctx: Context) = { val sym = vdef.symbol if (captured contains sym) { val newd = sym.denot(ctx.withPhase(thisTransform)).copySymDenotation( - info = refCls(sym.info.classSymbol, sym.hasAnnotation(defn.VolatileAnnot)).typeRef, + info = refClass(sym.info.classSymbol, sym.hasAnnotation(defn.VolatileAnnot)).typeRef, initFlags = sym.flags &~ Mutable) newd.removeAnnotation(defn.VolatileAnnot) newd.installAfter(thisTransform) @@ -113,7 +137,7 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisTransfo case TypeApply(Select(qual, nme.asInstanceOf_), _) => val Select(_, nme.elem) = qual recur(qual) - case Select(_, nme.elem) if defn.boxedRefClasses.contains(lhs.symbol.maybeOwner) => + case Select(_, nme.elem) if refInfo.boxedRefClasses.contains(lhs.symbol.maybeOwner) => val tempDef = transformFollowing(SyntheticValDef(ctx.freshName("ev$").toTermName, tree.rhs)) transformFollowing(Block(tempDef :: Nil, cpy.Assign(tree)(lhs, ref(tempDef.symbol)))) case _ => diff --git a/src/dotty/tools/dotc/transform/ClassOf.scala b/src/dotty/tools/dotc/transform/ClassOf.scala index 4d6bf2dc9..51a68f903 100644 --- a/src/dotty/tools/dotc/transform/ClassOf.scala +++ b/src/dotty/tools/dotc/transform/ClassOf.scala @@ -5,7 +5,7 @@ import ast.tpd import core.Constants.Constant import core.Contexts.Context import core.StdNames.nme -import core.Symbols.TermSymbol +import core.Symbols.{defn,TermSymbol} import core.TypeErasure import TreeTransforms.{MiniPhaseTransform, TransformerInfo, TreeTransform} @@ -24,30 +24,14 @@ class ClassOf extends MiniPhaseTransform { private var classOfMethod: TermSymbol = _ override def prepareForUnit(tree: tpd.Tree)(implicit ctx: Context): TreeTransform = { - val predefModule = ctx.definitions.ScalaPredefModule - classOfMethod = ctx.requiredMethod(predefModule.moduleClass.asClass, nme.classOf) + classOfMethod = defn.ScalaPredefModule.requiredMethod(nme.classOf) this } - override def transformTypeApply(tree: TypeApply)(implicit ctx: Context, info: TransformerInfo): Tree = { + override def transformTypeApply(tree: TypeApply)(implicit ctx: Context, info: TransformerInfo): Tree = if (tree.symbol eq classOfMethod) { - val tp = tree.args.head.tpe - val defn = ctx.definitions - val claz = tp.classSymbol - - def TYPE(module: TermSymbol) = ref(module).select(nme.TYPE_).ensureConforms(tree.tpe) - claz match { - case defn.BooleanClass => TYPE(defn.BoxedBooleanModule) - case defn.ByteClass => TYPE(defn.BoxedByteModule) - case defn.ShortClass => TYPE(defn.BoxedShortModule) - case defn.CharClass => TYPE(defn.BoxedCharModule) - case defn.IntClass => TYPE(defn.BoxedIntModule) - case defn.LongClass => TYPE(defn.BoxedLongModule) - case defn.FloatClass => TYPE(defn.BoxedFloatModule) - case defn.DoubleClass => TYPE(defn.BoxedDoubleModule) - case defn.UnitClass => TYPE(defn.BoxedVoidModule) - case _ => Literal(Constant(TypeErasure.erasure(tp))) - } - } else tree - } + val targ = tree.args.head.tpe + tree.clsOf(targ, Literal(Constant(TypeErasure.erasure(targ)))) + } + else tree } diff --git a/src/dotty/tools/dotc/transform/ClassTags.scala b/src/dotty/tools/dotc/transform/ClassTags.scala index 9d8abae93..8fd25f785 100644 --- a/src/dotty/tools/dotc/transform/ClassTags.scala +++ b/src/dotty/tools/dotc/transform/ClassTags.scala @@ -31,9 +31,8 @@ class ClassTags extends MiniPhaseTransform with IdentityDenotTransformer { thisT override def prepareForUnit(tree: tpd.Tree)(implicit ctx: Context): TreeTransform = { - val predefClass = defn.DottyPredefModule.moduleClass.asClass - classTagCache = ctx.requiredMethod(predefClass, nme.classTag) - typeTagCache = ctx.requiredMethod(predefClass, nme.typeTag) + classTagCache = defn.DottyPredefModule.requiredMethod(nme.classTag) + typeTagCache = defn.DottyPredefModule.requiredMethod(nme.typeTag) scala2ClassTagModule = ctx.requiredModule("scala.reflect.ClassTag") this } @@ -45,20 +44,24 @@ class ClassTags extends MiniPhaseTransform with IdentityDenotTransformer { thisT val tp = tree.args.head.tpe val defn = ctx.definitions val (elemType, ndims) = tp match { - case defn.MultiArrayType(elem, ndims) => (elem, ndims) + case defn.MultiArrayOf(elem, ndims) => (elem, ndims) case _ => (tp, 0) } val claz = tp.classSymbol val elemClaz = elemType.classSymbol assert(!claz.isPrimitiveValueClass) // should be inserted by typer - val elemTag = if (defn.ScalaValueClasses.contains(elemClaz) || elemClaz == defn.NothingClass || elemClaz == defn.NullClass) + val elemTag = + if (elemClaz.isPrimitiveValueClass || elemClaz == defn.NothingClass || elemClaz == defn.NullClass) ref(defn.DottyPredefModule).select(s"${elemClaz.name}ClassTag".toTermName) - else if (ValueClasses.isDerivedValueClass(elemClaz)) ref(claz.companionModule) - else if (elemClaz eq defn.AnyClass) ref(scala2ClassTagModule).select(nme.Any) + else if (ValueClasses.isDerivedValueClass(elemClaz)) + ref(claz.companionModule) + else if (elemClaz eq defn.AnyClass) + ref(scala2ClassTagModule).select(nme.Any) else { val erazedTp = TypeErasure.erasure(elemType).classSymbol.typeRef - ref(scala2ClassTagModule).select(nme.apply).appliedToType(erazedTp).appliedTo(Literal(Constant(erazedTp))) + ref(scala2ClassTagModule).select(nme.apply) + .appliedToType(erazedTp).appliedTo(Literal(Constant(erazedTp))) } (1 to ndims).foldLeft(elemTag)((arr, level) => Select(arr, nme.wrap).ensureApplied).ensureConforms(tree.tpe) } else tree diff --git a/src/dotty/tools/dotc/transform/ElimByName.scala b/src/dotty/tools/dotc/transform/ElimByName.scala index 2d0ecaf99..b65a46249 100644 --- a/src/dotty/tools/dotc/transform/ElimByName.scala +++ b/src/dotty/tools/dotc/transform/ElimByName.scala @@ -120,7 +120,7 @@ class ElimByName extends MiniPhaseTransform with InfoTransformer { thisTransform else tree def transformInfo(tp: Type, sym: Symbol)(implicit ctx: Context): Type = tp match { - case ExprType(rt) if exprBecomesFunction(sym) => defn.FunctionType(Nil, rt) + case ExprType(rt) if exprBecomesFunction(sym) => defn.FunctionOf(Nil, rt) case _ => tp } diff --git a/src/dotty/tools/dotc/transform/ElimRepeated.scala b/src/dotty/tools/dotc/transform/ElimRepeated.scala index 9563a7ed0..98abbb26d 100644 --- a/src/dotty/tools/dotc/transform/ElimRepeated.scala +++ b/src/dotty/tools/dotc/transform/ElimRepeated.scala @@ -81,7 +81,7 @@ class ElimRepeated extends MiniPhaseTransform with InfoTransformer with Annotati .select(nme.seqToArray) .appliedToType(elemType) .appliedTo(tree, Literal(Constant(elemClass.typeRef))) - .ensureConforms(defn.ArrayType(elemType)) + .ensureConforms(defn.ArrayOf(elemType)) // Because of phantomclasses, the Java array's type might not conform to the return type } diff --git a/src/dotty/tools/dotc/transform/Erasure.scala b/src/dotty/tools/dotc/transform/Erasure.scala index a414c6399..1b9b898f2 100644 --- a/src/dotty/tools/dotc/transform/Erasure.scala +++ b/src/dotty/tools/dotc/transform/Erasure.scala @@ -119,10 +119,10 @@ object Erasure extends TypeTestsCasts{ object Boxing { def isUnbox(sym: Symbol)(implicit ctx: Context) = - sym.name == nme.unbox && (defn.ScalaValueClasses contains sym.owner.linkedClass) + sym.name == nme.unbox && sym.owner.linkedClass.isPrimitiveValueClass def isBox(sym: Symbol)(implicit ctx: Context) = - sym.name == nme.box && (defn.ScalaValueClasses contains sym.owner.linkedClass) + sym.name == nme.box && sym.owner.linkedClass.isPrimitiveValueClass def boxMethod(cls: ClassSymbol)(implicit ctx: Context) = cls.linkedClass.info.member(nme.box).symbol @@ -138,7 +138,7 @@ object Erasure extends TypeTestsCasts{ */ private def safelyRemovableUnboxArg(tree: Tree)(implicit ctx: Context): Tree = tree match { case Apply(fn, arg :: Nil) - if isUnbox(fn.symbol) && (defn.ScalaBoxedClasses contains arg.tpe.widen.typeSymbol) => + if isUnbox(fn.symbol) && defn.ScalaBoxedClasses().contains(arg.tpe.widen.typeSymbol) => arg case _ => EmptyTree @@ -218,7 +218,7 @@ object Erasure extends TypeTestsCasts{ case (JavaArrayType(treeElem), JavaArrayType(ptElem)) if treeElem.widen.isPrimitiveValueType && !ptElem.isPrimitiveValueType => // See SI-2386 for one example of when this might be necessary. - cast(ref(defn.runtimeMethod(nme.toObjectArray)).appliedTo(tree), pt) + cast(ref(defn.runtimeMethodRef(nme.toObjectArray)).appliedTo(tree), pt) case (_, ErasedValueType(cls, _)) => ref(u2evt(cls)).appliedTo(tree) case _ => @@ -388,10 +388,10 @@ object Erasure extends TypeTestsCasts{ } private def runtimeCallWithProtoArgs(name: Name, pt: Type, args: Tree*)(implicit ctx: Context): Tree = { - val meth = defn.runtimeMethod(name) - val followingParams = meth.info.firstParamTypes.drop(args.length) + val meth = defn.runtimeMethodRef(name) + val followingParams = meth.symbol.info.firstParamTypes.drop(args.length) val followingArgs = protoArgs(pt).zipWithConserve(followingParams)(typedExpr).asInstanceOf[List[tpd.Tree]] - ref(defn.runtimeMethod(name)).appliedToArgs(args.toList ++ followingArgs) + ref(meth).appliedToArgs(args.toList ++ followingArgs) } private def protoArgs(pt: Type): List[untpd.Tree] = pt match { diff --git a/src/dotty/tools/dotc/transform/ExtensionMethods.scala b/src/dotty/tools/dotc/transform/ExtensionMethods.scala index 087e15c71..90e105ee7 100644 --- a/src/dotty/tools/dotc/transform/ExtensionMethods.scala +++ b/src/dotty/tools/dotc/transform/ExtensionMethods.scala @@ -76,9 +76,8 @@ class ExtensionMethods extends MiniPhaseTransform with DenotTransformer with Ful val underlyingCls = underlying.classSymbol val underlyingClsName = - if (defn.ScalaNumericValueClasses.contains(underlyingCls) || - underlyingCls == defn.BooleanClass) underlyingCls.name else nme.Object - + if (underlyingCls.isNumericValueClass || underlyingCls == defn.BooleanClass) underlyingCls.name + else nme.Object val syp = ctx.requiredClass(s"dotty.runtime.vc.VC${underlyingClsName}Companion").asClass @@ -98,9 +97,9 @@ class ExtensionMethods extends MiniPhaseTransform with DenotTransformer with Ful moduleClassSym } case ref: SymDenotation - if isMethodWithExtension(ref) && ref.hasAnnotation(defn.TailrecAnnotationClass) => + if isMethodWithExtension(ref) && ref.hasAnnotation(defn.TailrecAnnot) => val ref1 = ref.copySymDenotation() - ref1.removeAnnotation(defn.TailrecAnnotationClass) + ref1.removeAnnotation(defn.TailrecAnnot) ref1 case _ => ref diff --git a/src/dotty/tools/dotc/transform/FirstTransform.scala b/src/dotty/tools/dotc/transform/FirstTransform.scala index aecc1b86f..3b629f9b6 100644 --- a/src/dotty/tools/dotc/transform/FirstTransform.scala +++ b/src/dotty/tools/dotc/transform/FirstTransform.scala @@ -71,7 +71,7 @@ class FirstTransform extends MiniPhaseTransform with IdentityDenotTransformer wi def newCompanion(name: TermName, forClass: Symbol): Thicket = { val modul = ctx.newCompleteModuleSymbol(ctx.owner, name, Synthetic, Synthetic, - defn.ObjectClass.typeRef :: Nil, Scopes.newScope) + defn.ObjectType :: Nil, Scopes.newScope) val mc = modul.moduleClass if (ctx.owner.isClass) modul.enteredAfter(thisTransformer) ctx.synthesizeCompanionMethod(nme.COMPANION_CLASS_METHOD, forClass, mc).enteredAfter(thisTransformer) @@ -100,7 +100,7 @@ class FirstTransform extends MiniPhaseTransform with IdentityDenotTransformer wi if (ddef.symbol.hasAnnotation(defn.NativeAnnot)) { ddef.symbol.resetFlag(Deferred) DefDef(ddef.symbol.asTerm, - _ => ref(defn.Sys_error).withPos(ddef.pos) + _ => ref(defn.Sys_errorR).withPos(ddef.pos) .appliedTo(Literal(Constant("native method stub")))) } else ddef } diff --git a/src/dotty/tools/dotc/transform/GetClass.scala b/src/dotty/tools/dotc/transform/GetClass.scala index 4d8c8ae40..9d182382d 100644 --- a/src/dotty/tools/dotc/transform/GetClass.scala +++ b/src/dotty/tools/dotc/transform/GetClass.scala @@ -4,7 +4,6 @@ package transform import ast.tpd import core.Contexts.Context import core.StdNames.nme -import core.Symbols.TermSymbol import core.Phases.Phase import TreeTransforms.{MiniPhaseTransform, TransformerInfo} @@ -24,25 +23,8 @@ class GetClass extends MiniPhaseTransform { override def transformApply(tree: Apply)(implicit ctx: Context, info: TransformerInfo): Tree = { import ast.Trees._ - tree match { - case Apply(Select(qual, nme.getClass_), Nil) => - val defn = ctx.definitions - val claz = qual.tpe.widen.classSymbol - - def TYPE(module: TermSymbol) = ref(module).select(nme.TYPE_).ensureConforms(tree.tpe) - claz match { - case defn.BooleanClass => TYPE(defn.BoxedBooleanModule) - case defn.ByteClass => TYPE(defn.BoxedByteModule) - case defn.ShortClass => TYPE(defn.BoxedShortModule) - case defn.CharClass => TYPE(defn.BoxedCharModule) - case defn.IntClass => TYPE(defn.BoxedIntModule) - case defn.LongClass => TYPE(defn.BoxedLongModule) - case defn.FloatClass => TYPE(defn.BoxedFloatModule) - case defn.DoubleClass => TYPE(defn.BoxedDoubleModule) - case defn.UnitClass => TYPE(defn.BoxedVoidModule) - case _ => tree - } + case Apply(Select(qual, nme.getClass_), Nil) => tree.clsOf(qual.tpe.widen, tree) case _ => tree } } diff --git a/src/dotty/tools/dotc/transform/InterceptedMethods.scala b/src/dotty/tools/dotc/transform/InterceptedMethods.scala index ff354a54c..ffb4ae756 100644 --- a/src/dotty/tools/dotc/transform/InterceptedMethods.scala +++ b/src/dotty/tools/dotc/transform/InterceptedMethods.scala @@ -51,7 +51,7 @@ class InterceptedMethods extends MiniPhaseTransform { /** perform context-dependant initialization */ override def prepareForUnit(tree: Tree)(implicit ctx: Context) = { this.Any_## = defn.Any_## - primitiveGetClassMethods = Set[Symbol]() ++ defn.ScalaValueClasses.map(x => x.requiredMethod(nme.getClass_)) + primitiveGetClassMethods = Set[Symbol]() ++ defn.ScalaValueClasses().map(x => x.requiredMethod(nme.getClass_)) this } @@ -86,7 +86,7 @@ class InterceptedMethods extends MiniPhaseTransform { def alt2 = defn.ScalaRuntimeModule.info.member(nme.hash_) .suchThat(_.info.firstParamTypes.head.typeSymbol == defn.AnyClass) - Ident((if (defn.ScalaNumericValueClasses contains s) alt1 else alt2).termRef) + Ident((if (s.isNumericValueClass) alt1 else alt2).termRef) .appliedTo(tree) } } diff --git a/src/dotty/tools/dotc/transform/NonLocalReturns.scala b/src/dotty/tools/dotc/transform/NonLocalReturns.scala index 1f18a7318..7680e283e 100644 --- a/src/dotty/tools/dotc/transform/NonLocalReturns.scala +++ b/src/dotty/tools/dotc/transform/NonLocalReturns.scala @@ -29,7 +29,7 @@ class NonLocalReturns extends MiniPhaseTransform { thisTransformer => /** The type of a non-local return expression with given argument type */ private def nonLocalReturnExceptionType(argtype: Type)(implicit ctx: Context) = - defn.NonLocalReturnControlClass.typeRef.appliedTo(argtype) + defn.NonLocalReturnControlType.appliedTo(argtype) /** A hashmap from method symbols to non-local return keys */ private val nonLocalReturnKeys = mutable.Map[Symbol, TermSymbol]() @@ -50,7 +50,7 @@ class NonLocalReturns extends MiniPhaseTransform { thisTransformer => private def nonLocalReturnThrow(expr: Tree, meth: Symbol)(implicit ctx: Context) = Throw( New( - defn.NonLocalReturnControlClass.typeRef, + defn.NonLocalReturnControlType, ref(nonLocalReturnKey(meth)) :: expr.ensureConforms(defn.ObjectType) :: Nil)) /** Transform (body, key) to: @@ -68,7 +68,7 @@ class NonLocalReturns extends MiniPhaseTransform { thisTransformer => */ private def nonLocalReturnTry(body: Tree, key: TermSymbol, meth: Symbol)(implicit ctx: Context) = { val keyDef = ValDef(key, New(defn.ObjectType, Nil)) - val nonLocalReturnControl = defn.NonLocalReturnControlClass.typeRef + val nonLocalReturnControl = defn.NonLocalReturnControlType val ex = ctx.newSymbol(meth, nme.ex, EmptyFlags, nonLocalReturnControl, coord = body.pos) val pat = BindTyped(ex, nonLocalReturnControl) val rhs = If( diff --git a/src/dotty/tools/dotc/transform/PatternMatcher.scala b/src/dotty/tools/dotc/transform/PatternMatcher.scala index 2df7a9825..5b4d42683 100644 --- a/src/dotty/tools/dotc/transform/PatternMatcher.scala +++ b/src/dotty/tools/dotc/transform/PatternMatcher.scala @@ -134,7 +134,7 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans // for name-based matching, but this was an expedient route for the basics. def drop(tgt: Tree)(n: Int): Tree = { def callDirect = tgt.select(nme.drop).appliedTo(Literal(Constant(n))) - def callRuntime = ref(defn.traversableDropMethod).appliedTo(tgt, Literal(Constant(n))) + def callRuntime = ref(defn.ScalaRuntime_drop).appliedTo(tgt, Literal(Constant(n))) def needsRuntime = !(tgt.tpe derivesFrom defn.SeqClass) /*typeOfMemberNamedDrop(tgt.tpe) == NoType*/ @@ -755,7 +755,7 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans def expectedWide = expectedTp.widen def isAnyRef = testedWide <:< defn.AnyRefType def isAsExpected = testedWide <:< expectedTp - def isExpectedPrimitiveType = isAsExpected && defn.ScalaValueClasses.contains(expectedTp.classSymbol) + def isExpectedPrimitiveType = isAsExpected && expectedTp.classSymbol.isPrimitiveValueClass def isExpectedReferenceType = isAsExpected && (expectedTp <:< defn.AnyRefType) def mkNullTest = nonNullTest(testedBinder) def mkOuterTest = outerTest(testedBinder, expectedTp) diff --git a/src/dotty/tools/dotc/transform/SyntheticMethods.scala b/src/dotty/tools/dotc/transform/SyntheticMethods.scala index fa931a379..a496f80ce 100644 --- a/src/dotty/tools/dotc/transform/SyntheticMethods.scala +++ b/src/dotty/tools/dotc/transform/SyntheticMethods.scala @@ -77,7 +77,7 @@ class SyntheticMethods(thisTransformer: DenotTransformer) { coord = clazz.coord).enteredAfter(thisTransformer).asTerm def forwardToRuntime(vrefss: List[List[Tree]]): Tree = - ref(defn.runtimeMethod("_" + sym.name.toString)).appliedToArgs(This(clazz) :: vrefss.head) + ref(defn.runtimeMethodRef("_" + sym.name.toString)).appliedToArgs(This(clazz) :: vrefss.head) def syntheticRHS(implicit ctx: Context): List[List[Tree]] => Tree = synthetic.name match { case nme.hashCode_ if isDerivedValueClass(clazz) => vrefss => valueHashCodeBody @@ -161,20 +161,17 @@ class SyntheticMethods(thisTransformer: DenotTransformer) { } /** The hashCode implementation for given symbol `sym`. */ - def hashImpl(sym: Symbol)(implicit ctx: Context): Tree = { - val d = defn - import d._ - sym.info.finalResultType.typeSymbol match { - case UnitClass | NullClass => Literal(Constant(0)) - case BooleanClass => If(ref(sym), Literal(Constant(1231)), Literal(Constant(1237))) - case IntClass => ref(sym) - case ShortClass | ByteClass | CharClass => ref(sym).select(nme.toInt) - case LongClass => ref(staticsMethod("longHash")).appliedTo(ref(sym)) - case DoubleClass => ref(staticsMethod("doubleHash")).appliedTo(ref(sym)) - case FloatClass => ref(staticsMethod("floatHash")).appliedTo(ref(sym)) - case _ => ref(staticsMethod("anyHash")).appliedTo(ref(sym)) + def hashImpl(sym: Symbol)(implicit ctx: Context): Tree = + defn.scalaClassName(sym.info.finalResultType) match { + case tpnme.Unit | tpnme.Null => Literal(Constant(0)) + case tpnme.Boolean => If(ref(sym), Literal(Constant(1231)), Literal(Constant(1237))) + case tpnme.Int => ref(sym) + case tpnme.Short | tpnme.Byte | tpnme.Char => ref(sym).select(nme.toInt) + case tpnme.Long => ref(defn.staticsMethod("longHash")).appliedTo(ref(sym)) + case tpnme.Double => ref(defn.staticsMethod("doubleHash")).appliedTo(ref(sym)) + case tpnme.Float => ref(defn.staticsMethod("floatHash")).appliedTo(ref(sym)) + case _ => ref(defn.staticsMethod("anyHash")).appliedTo(ref(sym)) } - } /** The class * diff --git a/src/dotty/tools/dotc/transform/TailRec.scala b/src/dotty/tools/dotc/transform/TailRec.scala index fdfb95e99..58fe7a6c9 100644 --- a/src/dotty/tools/dotc/transform/TailRec.scala +++ b/src/dotty/tools/dotc/transform/TailRec.scala @@ -85,7 +85,7 @@ class TailRec extends MiniPhaseTransform with DenotTransformer with FullParamete tree match { case dd@DefDef(name, tparams, vparamss0, tpt, _) if (sym.isEffectivelyFinal) && !((sym is Flags.Accessor) || (dd.rhs eq EmptyTree) || (sym is Flags.Label)) => - val mandatory = sym.hasAnnotation(defn.TailrecAnnotationClass) + val mandatory = sym.hasAnnotation(defn.TailrecAnnot) atGroupEnd { implicit ctx: Context => cpy.DefDef(dd)(rhs = { @@ -121,10 +121,10 @@ class TailRec extends MiniPhaseTransform with DenotTransformer with FullParamete } }) } - case d: DefDef if d.symbol.hasAnnotation(defn.TailrecAnnotationClass) => + case d: DefDef if d.symbol.hasAnnotation(defn.TailrecAnnot) => ctx.error("TailRec optimisation not applicable, method is neither private nor final so can be overridden", d.pos) d - case d if d.symbol.hasAnnotation(defn.TailrecAnnotationClass) => + case d if d.symbol.hasAnnotation(defn.TailrecAnnot) => ctx.error("TailRec optimisation not applicable, not a method", d.pos) d case _ => tree diff --git a/src/dotty/tools/dotc/transform/TreeChecker.scala b/src/dotty/tools/dotc/transform/TreeChecker.scala index 1f47b4486..0ee709539 100644 --- a/src/dotty/tools/dotc/transform/TreeChecker.scala +++ b/src/dotty/tools/dotc/transform/TreeChecker.scala @@ -23,6 +23,7 @@ import ast.{tpd, untpd} import util.SourcePosition import collection.mutable import ProtoTypes._ +import config.Printers import java.lang.AssertionError import scala.util.control.NonFatal @@ -79,7 +80,7 @@ class TreeChecker extends Phase with SymTransformer { val sym = symd.symbol if (sym.isClass && !sym.isAbsent) { - val validSuperclass = defn.ScalaValueClasses.contains(sym) || defn.syntheticCoreClasses.contains(sym) || + val validSuperclass = sym.isPrimitiveValueClass || defn.syntheticCoreClasses.contains(sym) || (sym eq defn.ObjectClass) || (sym is NoSuperClass) || (sym.asClass.superClass.exists) if (!validSuperclass) printError(s"$sym has no superclass set") @@ -124,7 +125,10 @@ class TreeChecker extends Phase with SymTransformer { catch { case NonFatal(ex) => implicit val ctx: Context = checkingCtx - ctx.println(i"*** error while checking after phase ${checkingCtx.phase.prev} ***") + ctx.println(i"*** error while checking ${ctx.compilationUnit} after phase ${checkingCtx.phase.prev} ***") + ctx.println(ex.toString) + ctx.println(ex.getStackTrace.take(30).deep.mkString("\n")) + ctx.println("<<<") throw ex } } diff --git a/src/dotty/tools/dotc/transform/TypeTestsCasts.scala b/src/dotty/tools/dotc/transform/TypeTestsCasts.scala index b2d45b661..c57d6fd1a 100644 --- a/src/dotty/tools/dotc/transform/TypeTestsCasts.scala +++ b/src/dotty/tools/dotc/transform/TypeTestsCasts.scala @@ -50,7 +50,7 @@ trait TypeTestsCasts { Literal(Constant(true)) withPos tree.pos else if (argCls.isPrimitiveValueClass) if (qualCls.isPrimitiveValueClass) Literal(Constant(qualCls == argCls)) withPos tree.pos - else transformIsInstanceOf(expr, defn.boxedClass(argCls).typeRef) + else transformIsInstanceOf(expr, defn.boxedType(argCls.typeRef)) else argType.dealias match { case _: SingletonType => val cmpOp = if (argType derivesFrom defn.AnyValClass) defn.Any_equals else defn.Object_eq @@ -68,9 +68,9 @@ trait TypeTestsCasts { } } } - case defn.MultiArrayType(elem, ndims) if isUnboundedGeneric(elem) => + case defn.MultiArrayOf(elem, ndims) if isUnboundedGeneric(elem) => def isArrayTest(arg: Tree) = - ref(defn.runtimeMethod(nme.isArray)).appliedTo(arg, Literal(Constant(ndims))) + ref(defn.runtimeMethodRef(nme.isArray)).appliedTo(arg, Literal(Constant(ndims))) if (ndims == 1) isArrayTest(qual) else evalOnce(qual) { qual1 => derivedTree(qual1, defn.Any_isInstanceOf, qual1.tpe) and isArrayTest(qual1) diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala index 87bed8895..64047cc1e 100644 --- a/src/dotty/tools/dotc/typer/Applications.scala +++ b/src/dotty/tools/dotc/typer/Applications.scala @@ -949,7 +949,7 @@ trait Applications extends Compatibility { self: Typer => /** The shape of given tree as a type; cannot handle named arguments. */ def typeShape(tree: untpd.Tree): Type = tree match { case untpd.Function(args, body) => - defn.FunctionType(args map Function.const(defn.AnyType), typeShape(body)) + defn.FunctionOf(args map Function.const(defn.AnyType), typeShape(body)) case _ => defn.NothingType } @@ -1068,7 +1068,7 @@ trait Applications extends Compatibility { self: Typer => val alts1 = alts filter pt.isMatchedBy resolveOverloaded(alts1, pt1, targs) - case defn.FunctionType(args, resultType) => + case defn.FunctionOf(args, resultType) => narrowByTypes(alts, args, resultType) case pt => @@ -1102,8 +1102,8 @@ trait Applications extends Compatibility { self: Typer => } val clss = numericClasses(ts, Set()) if (clss.size > 1) { - val lub = defn.ScalaNumericValueClassList.find(lubCls => - clss.forall(defn.isValueSubClass(_, lubCls))).get.typeRef + val lub = defn.ScalaNumericValueTypeList.find(lubTpe => + clss.forall(cls => defn.isValueSubType(cls.typeRef, lubTpe))).get ts.mapConserve(adapt(_, lub)) } else ts diff --git a/src/dotty/tools/dotc/typer/Checking.scala b/src/dotty/tools/dotc/typer/Checking.scala index 3dc7b67df..9dfe46232 100644 --- a/src/dotty/tools/dotc/typer/Checking.scala +++ b/src/dotty/tools/dotc/typer/Checking.scala @@ -310,7 +310,7 @@ trait Checking { /** Check that `tp` is a class type with a stable prefix. Also, if `traitReq` is * true check that `tp` is a trait. * Stability checking is disabled in phases after RefChecks. - * @return `tp` itself if it is a class or trait ref, ObjectClass.typeRef if not. + * @return `tp` itself if it is a class or trait ref, ObjectType if not. */ def checkClassTypeWithStablePrefix(tp: Type, pos: Position, traitReq: Boolean)(implicit ctx: Context): Type = tp.underlyingClassRef(refinementOK = false) match { @@ -320,7 +320,7 @@ trait Checking { tp case _ => ctx.error(d"$tp is not a class type", pos) - defn.ObjectClass.typeRef + defn.ObjectType } /** Check that a non-implicit parameter making up the first parameter section of an diff --git a/src/dotty/tools/dotc/typer/FrontEnd.scala b/src/dotty/tools/dotc/typer/FrontEnd.scala index e8a0adf19..eee8744a5 100644 --- a/src/dotty/tools/dotc/typer/FrontEnd.scala +++ b/src/dotty/tools/dotc/typer/FrontEnd.scala @@ -4,17 +4,20 @@ package typer import core._ import Phases._ import Contexts._ +import Symbols._ import dotty.tools.dotc.parsing.JavaParsers.JavaParser import parsing.Parsers.Parser import config.Printers._ import util.Stats._ import scala.util.control.NonFatal +import ast.Trees._ import util.FreshNameCreator class FrontEnd extends Phase { override def phaseName = "frontend" override def isTyper = true + import ast.tpd def monitor(doing: String)(body: => Unit)(implicit ctx: Context) = try body @@ -47,6 +50,16 @@ class FrontEnd extends Phase { record("retainedTypedTrees", unit.tpdTree.treeSize) } + private def firstTopLevelDef(trees: List[tpd.Tree])(implicit ctx: Context): Symbol = trees match { + case PackageDef(_, defs) :: _ => firstTopLevelDef(defs) + case Import(_, _) :: defs => firstTopLevelDef(defs) + case (tree @ TypeDef(_, _)) :: _ => tree.symbol + case _ => NoSymbol + } + + private def discardAfterTyper(unit: CompilationUnit)(implicit ctx: Context) = + unit.isJava || firstTopLevelDef(unit.tpdTree :: Nil).isPrimitiveValueClass + override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = { val unitContexts = for (unit <- units) yield ctx.fresh.setCompilationUnit(unit).setFreshNames(new FreshNameCreator.Default) @@ -55,7 +68,7 @@ class FrontEnd extends Phase { unitContexts foreach (enterSyms(_)) unitContexts foreach (typeCheck(_)) record("totalTrees", ast.Trees.ntrees) - unitContexts.map(_.compilationUnit).filter(!_.isJava) + unitContexts.map(_.compilationUnit).filterNot(discardAfterTyper) } override def run(implicit ctx: Context): Unit = { diff --git a/src/dotty/tools/dotc/typer/ImportInfo.scala b/src/dotty/tools/dotc/typer/ImportInfo.scala index fe999b561..2ca90311f 100644 --- a/src/dotty/tools/dotc/typer/ImportInfo.scala +++ b/src/dotty/tools/dotc/typer/ImportInfo.scala @@ -11,9 +11,9 @@ import Decorators.StringInterpolators object ImportInfo { /** The import info for a root import from given symbol `sym` */ - def rootImport(sym: () => Symbol)(implicit ctx: Context) = { + def rootImport(refFn: () => TermRef)(implicit ctx: Context) = { val selectors = untpd.Ident(nme.WILDCARD) :: Nil - def expr = tpd.Ident(sym().valRef) + def expr = tpd.Ident(refFn()) def imp = tpd.Import(expr, selectors) new ImportInfo(imp.symbol, selectors, isRootImport = true) } @@ -101,7 +101,7 @@ class ImportInfo(symf: => Symbol, val selectors: List[untpd.Tree], val isRootImp case Pair(_, Ident(nme.WILDCARD)) => true case _ => false } - if ((defn.RootImports contains sym) && hasMaskingSelector) sym else NoSymbol + if ((defn.RootImportTypes exists (_.symbol == sym)) && hasMaskingSelector) sym else NoSymbol } override def toString = { diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index 3c491fa7a..999efff09 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -579,7 +579,7 @@ class Namer { typer: Typer => val pt = checkClassTypeWithStablePrefix(ptype, parent.pos, traitReq = parent ne parents.head) if (pt.derivesFrom(cls)) { ctx.error(i"cyclic inheritance: $cls extends itself", parent.pos) - defn.ObjectClass.typeRef + defn.ObjectType } else pt } diff --git a/src/dotty/tools/dotc/typer/ProtoTypes.scala b/src/dotty/tools/dotc/typer/ProtoTypes.scala index 2b19d9db3..db196f0c2 100644 --- a/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -370,7 +370,7 @@ object ProtoTypes { if (pt.isInstanceOf[ApplyingProto]) mt.derivedMethodType(mt.paramNames, mt.paramTypes, rt) else { - val ft = defn.FunctionType(mt.paramTypes, rt) + val ft = defn.FunctionOf(mt.paramTypes, rt) if (mt.paramTypes.nonEmpty || ft <:< pt) ft else rt } } diff --git a/src/dotty/tools/dotc/typer/ReTyper.scala b/src/dotty/tools/dotc/typer/ReTyper.scala index f4e4f52b9..49718fd00 100644 --- a/src/dotty/tools/dotc/typer/ReTyper.scala +++ b/src/dotty/tools/dotc/typer/ReTyper.scala @@ -10,6 +10,7 @@ import typer.ProtoTypes._ import ast.{tpd, untpd} import ast.Trees._ import scala.util.control.NonFatal +import config.Printers /** A version of Typer that keeps all symbols defined and referenced in a * previously typed tree. @@ -91,7 +92,7 @@ class ReTyper extends Typer { try super.typedUnadapted(tree, pt) catch { case NonFatal(ex) => - println(i"exception while typing $tree of class ${tree.getClass} # ${tree.uniqueId}") + Printers.transforms.println(i"exception while typing $tree of class ${tree.getClass} # ${tree.uniqueId}") throw ex } diff --git a/src/dotty/tools/dotc/typer/TypeAssigner.scala b/src/dotty/tools/dotc/typer/TypeAssigner.scala index 25030012c..af5fdd428 100644 --- a/src/dotty/tools/dotc/typer/TypeAssigner.scala +++ b/src/dotty/tools/dotc/typer/TypeAssigner.scala @@ -350,7 +350,7 @@ trait TypeAssigner { def assignType(tree: untpd.SeqLiteral, elems: List[Tree])(implicit ctx: Context) = tree match { case tree: JavaSeqLiteral => - tree.withType(defn.ArrayType(ctx.typeComparer.lub(elems.tpes).widen)) + tree.withType(defn.ArrayOf(ctx.typeComparer.lub(elems.tpes).widen)) case _ => val ownType = if (ctx.erasedTypes) defn.SeqType diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index c621d96c4..10bca44bf 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -373,7 +373,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit def regularTyped(isWildcard: Boolean) = { val tpt1 = if (untpd.isWildcardStarArg(tree)) - TypeTree(defn.SeqClass.typeRef.appliedTo(pt :: Nil)) + TypeTree(defn.SeqType.appliedTo(pt :: Nil)) else checkSimpleKinded(typedType(tree.tpt)) val expr1 = @@ -891,7 +891,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit } def typedAnnotation(annot: untpd.Tree)(implicit ctx: Context): Tree = track("typedAnnotation") { - typed(annot, defn.AnnotationClass.typeRef) + typed(annot, defn.AnnotationType) } def typedValDef(vdef: untpd.ValDef, sym: Symbol)(implicit ctx: Context) = track("typedValDef") { @@ -1034,7 +1034,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit } def typedAnnotated(tree: untpd.Annotated, pt: Type)(implicit ctx: Context): Tree = track("typedAnnotated") { - val annot1 = typedExpr(tree.annot, defn.AnnotationClass.typeRef) + val annot1 = typedExpr(tree.annot, defn.AnnotationType) val arg1 = typed(tree.arg, pt) if (ctx.mode is Mode.Type) assignType(cpy.Annotated(tree)(annot1, arg1), annot1, arg1) diff --git a/src/dotty/tools/io/ClassPath.scala b/src/dotty/tools/io/ClassPath.scala index 0d1402430..e30eca492 100644 --- a/src/dotty/tools/io/ClassPath.scala +++ b/src/dotty/tools/io/ClassPath.scala @@ -25,13 +25,16 @@ import language.postfixOps * @author Stepan Koltsov */ object ClassPath { + /** Expand single path entry */ private def expandS(pattern: String): List[String] = { val wildSuffix = File.separator + "*" /** Get all subdirectories, jars, zips out of a directory. */ - def lsDir(dir: Directory, filt: String => Boolean = _ => true) = - dir.list filter (x => filt(x.name) && (x.isDirectory || isJarOrZip(x))) map (_.path) toList + def lsDir(dir: Directory, filt: String => Boolean = _ => true) = { + val files = synchronized(dir.list) + files filter (x => filt(x.name) && (x.isDirectory || isJarOrZip(x))) map (_.path) toList + } def basedir(s: String) = if (s contains File.separator) s.substring(0, s.lastIndexOf(File.separator)) diff --git a/test/dotc/scala-collections.whitelist b/test/dotc/scala-collections.whitelist index 76fa64c8e..59388ac78 100644 --- a/test/dotc/scala-collections.whitelist +++ b/test/dotc/scala-collections.whitelist @@ -1,47 +1,30 @@ -# no sig for NoType -# no sig for ErasedValueType(class RichShort,NoType) -# no sig for TypeRef(TermRef(ThisType(TypeRef(NoPrefix,scala)),runtime),RichShort) -# failure while taking result signture of (x: Short)runtime.RichShort: runtime.RichShort -# cannot take signature of (x: Short)runtime.RichShort -# exception occurred while typechecking ./scala-scala/src/library/scala/runtime/RichByte.scala -# -#./scala-scala/src/library/scala/runtime/RichBoolean.scala -#./scala-scala/src/library/scala/runtime/RichByte.scala -#./scala-scala/src/library/scala/runtime/RichChar.scala -#./scala-scala/src/library/scala/runtime/RichDouble.scala -#./scala-scala/src/library/scala/runtime/RichException.scala -#./scala-scala/src/library/scala/runtime/RichFloat.scala -#./scala-scala/src/library/scala/runtime/RichInt.scala -#./scala-scala/src/library/scala/runtime/RichLong.scala -#./scala-scala/src/library/scala/runtime/RichShort.scala - - - -# -# no sig for NoType -# no sig for ErasedValueType(class RichShort,NoType) -# no sig for TypeRef(TermRef(ThisType(TypeRef(NoPrefix,scala)),runtime),RichShort) -# failure while taking result signture of (x: Short)runtime.RichShort: runtime.RichShort -# cannot take signature of (x: Short)runtime.RichShort -# exception occurred while typechecking ./scala-scala/src/library/scala/Array.scala -# -#./scala-scala/src/library/scala/Array.scala -#./scala-scala/src/library/scala/NotImplementedError.scala +./scala-scala/src/library/scala/runtime/RichBoolean.scala +./scala-scala/src/library/scala/runtime/RichByte.scala +./scala-scala/src/library/scala/runtime/RichChar.scala +./scala-scala/src/library/scala/runtime/RichDouble.scala +./scala-scala/src/library/scala/runtime/RichException.scala +./scala-scala/src/library/scala/runtime/RichFloat.scala +./scala-scala/src/library/scala/runtime/RichInt.scala +./scala-scala/src/library/scala/runtime/RichLong.scala +./scala-scala/src/library/scala/runtime/RichShort.scala + +./scala-scala/src/library/scala/Array.scala +./scala-scala/src/library/scala/NotImplementedError.scala ./scala-scala/src/library/scala/AnyValCompanion.scala -# Does not pass refchecks: -# method getClass of type ()Class[_ <: AnyVal] cannot override final member method getClass in class Any +# AnyVal is a synthesized class in Dotty, cannot be compiled from source. #./scala-scala/src/library/scala/AnyVal.scala -#./scala-scala/src/library/scala/Boolean.scala -#./scala-scala/src/library/scala/Byte.scala -#./scala-scala/src/library/scala/Char.scala -#./scala-scala/src/library/scala/Double.scala -#./scala-scala/src/library/scala/Float.scala -#./scala-scala/src/library/scala/Int.scala -#./scala-scala/src/library/scala/Long.scala -#./scala-scala/src/library/scala/Short.scala -#./scala-scala/src/library/scala/Unit.scala + +./scala-scala/src/library/scala/Boolean.scala +./scala-scala/src/library/scala/Byte.scala +./scala-scala/src/library/scala/Char.scala +./scala-scala/src/library/scala/Double.scala +./scala-scala/src/library/scala/Float.scala +./scala-scala/src/library/scala/Int.scala +./scala-scala/src/library/scala/Long.scala +./scala-scala/src/library/scala/Short.scala +./scala-scala/src/library/scala/Unit.scala ./scala-scala/src/library/scala/Cloneable.scala ./scala-scala/src/library/scala/DelayedInit.scala @@ -52,38 +35,34 @@ ./scala-scala/src/library/scala/Mutable.scala ./scala-scala/src/library/scala/NotNull.scala -# https://github.com/lampepfl/dotty/issues/911 ./scala-scala/src/library/scala/Option.scala ./scala-scala/src/library/scala/PartialFunction.scala ./scala-scala/src/library/scala/Predef.scala -# Causes data races #907 -# java.lang.AssertionError: assertion failed: data race? overwriting symbol of Product1 / TypeRef(ThisType(TypeRef(NoPrefix,scala)),Product1) / class dotty.tools.dotc.core.Types$CachedTypeRef / 190 / 4820 / module class scala / module class scala / frontend, took 2.154 sec -#./scala-scala/src/library/scala/Product.scala -#./scala-scala/src/library/scala/Product1.scala -#./scala-scala/src/library/scala/Product10.scala -#./scala-scala/src/library/scala/Product11.scala -#./scala-scala/src/library/scala/Product12.scala -#./scala-scala/src/library/scala/Product13.scala -#./scala-scala/src/library/scala/Product14.scala -#./scala-scala/src/library/scala/Product15.scala -#./scala-scala/src/library/scala/Product16.scala -#./scala-scala/src/library/scala/Product17.scala -#./scala-scala/src/library/scala/Product18.scala -#./scala-scala/src/library/scala/Product19.scala -#./scala-scala/src/library/scala/Product2.scala -#./scala-scala/src/library/scala/Product20.scala -#./scala-scala/src/library/scala/Product21.scala -#./scala-scala/src/library/scala/Product22.scala -#./scala-scala/src/library/scala/Product3.scala -#./scala-scala/src/library/scala/Product4.scala -#./scala-scala/src/library/scala/Product5.scala -#./scala-scala/src/library/scala/Product6.scala -#./scala-scala/src/library/scala/Product7.scala -#./scala-scala/src/library/scala/Product8.scala -#./scala-scala/src/library/scala/Product9.scala - +./scala-scala/src/library/scala/Product.scala +./scala-scala/src/library/scala/Product1.scala +./scala-scala/src/library/scala/Product10.scala +./scala-scala/src/library/scala/Product11.scala +./scala-scala/src/library/scala/Product12.scala +./scala-scala/src/library/scala/Product13.scala +./scala-scala/src/library/scala/Product14.scala +./scala-scala/src/library/scala/Product15.scala +./scala-scala/src/library/scala/Product16.scala +./scala-scala/src/library/scala/Product17.scala +./scala-scala/src/library/scala/Product18.scala +./scala-scala/src/library/scala/Product19.scala +./scala-scala/src/library/scala/Product2.scala +./scala-scala/src/library/scala/Product20.scala +./scala-scala/src/library/scala/Product21.scala +./scala-scala/src/library/scala/Product22.scala +./scala-scala/src/library/scala/Product3.scala +./scala-scala/src/library/scala/Product4.scala +./scala-scala/src/library/scala/Product5.scala +./scala-scala/src/library/scala/Product6.scala +./scala-scala/src/library/scala/Product7.scala +./scala-scala/src/library/scala/Product8.scala +./scala-scala/src/library/scala/Product9.scala ./scala-scala/src/library/scala/Proxy.scala ./scala-scala/src/library/scala/SerialVersionUID.scala @@ -156,3 +135,9 @@ ./scala-scala/src/library/scala/transient.scala ./scala-scala/src/library/scala/unchecked.scala ./scala-scala/src/library/scala/volatile.scala + +# cyclic reference +./scala-scala/src/library/scala/collection/GenSeq.scala +./scala-scala/src/library/scala/collection/GenSeqLike.scala + + diff --git a/tests/pos/lazyValsSepComp.scala b/tests/pos/lazyValsSepComp.scala index 337447280..1a7e37020 100644 --- a/tests/pos/lazyValsSepComp.scala +++ b/tests/pos/lazyValsSepComp.scala @@ -12,5 +12,5 @@ import dotty.tools.dotc.core.Contexts._ object Foo { val definitions: Definitions = null def defn = definitions - def go = defn.FunctionClass(0) + def go = defn.FunctionType(0) } |