diff --git a/compiler/src/dotty/tools/dotc/ast/tpd.scala b/compiler/src/dotty/tools/dotc/ast/tpd.scala index bf954dae459c..ab464cbc8dd5 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -15,6 +15,7 @@ import collection.{immutable, mutable} import util.{Property, SourceFile} import NameKinds.{TempResultName, OuterSelectName} import typer.ConstFold +import dotty.tools.tasty.TastyFormat import scala.annotation.tailrec import scala.collection.mutable.ListBuffer @@ -386,7 +387,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { if (head.isRef(defn.AnyClass)) defn.AnyRefType :: parents else head :: parents } else parents - val cls = newNormalizedClassSymbol(owner, tpnme.ANON_CLASS, Synthetic | Final, parents1, coord = coord) + val cls = newNormalizedClassSymbol(owner, tpnme.ANON_CLASS, Synthetic | Final, parents1, coord = coord, + initTastyVersion = TastyFormat.currentTastyVersion) val constr = newConstructor(cls, Synthetic, Nil, Nil).entered val cdef = ClassDef(cls, DefDef(constr), body(cls)) Block(cdef :: Nil, New(cls.typeRef, Nil)) diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 18dcc4894ed9..d3b858468954 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -50,13 +50,13 @@ class Definitions { newSymbol(owner, name, flags | Permanent, info) private def newPermanentClassSymbol(owner: Symbol, name: TypeName, flags: FlagSet, infoFn: ClassSymbol => Type) = - newClassSymbol(owner, name, flags | Permanent | NoInits | Open, infoFn) + newClassSymbol(owner, name, flags | Permanent | NoInits | Open, infoFn, initTastyVersion = -1) private def enterCompleteClassSymbol(owner: Symbol, name: TypeName, flags: FlagSet, parents: List[TypeRef]): ClassSymbol = enterCompleteClassSymbol(owner, name, flags, parents, newScope(owner.nestingLevel + 1)) private def enterCompleteClassSymbol(owner: Symbol, name: TypeName, flags: FlagSet, parents: List[TypeRef], decls: Scope) = - newCompleteClassSymbol(owner, name, flags | Permanent | NoInits | Open, parents, decls).entered + newCompleteClassSymbol(owner, name, flags | Permanent | NoInits | Open, parents, decls, initTastyVersion = -1).entered private def enterTypeField(cls: ClassSymbol, name: TypeName, flags: FlagSet, scope: MutableScope) = scope.enter(newPermanentSymbol(cls, name, flags, TypeBounds.empty)) @@ -199,16 +199,16 @@ class Definitions { } @tu lazy val RootClass: ClassSymbol = newPackageSymbol( - NoSymbol, nme.ROOT, (root, rootcls) => ctx.base.rootLoader(root)).moduleClass.asClass + NoSymbol, nme.ROOT, (root, rootcls) => ctx.base.rootLoader(root), initTastyVersion = -1).moduleClass.asClass @tu lazy val RootPackage: TermSymbol = newSymbol( NoSymbol, nme.ROOTPKG, PackageCreationFlags, TypeRef(NoPrefix, RootClass)) @tu lazy val EmptyPackageVal: TermSymbol = newPackageSymbol( - RootClass, nme.EMPTY_PACKAGE, (emptypkg, emptycls) => ctx.base.rootLoader(emptypkg)).entered + RootClass, nme.EMPTY_PACKAGE, (emptypkg, emptycls) => ctx.base.rootLoader(emptypkg), initTastyVersion = -1).entered @tu lazy val EmptyPackageClass: ClassSymbol = EmptyPackageVal.moduleClass.asClass /** A package in which we can place all methods and types that are interpreted specially by the compiler */ - @tu lazy val OpsPackageVal: TermSymbol = newCompletePackageSymbol(RootClass, nme.OPS_PACKAGE).entered + @tu lazy val OpsPackageVal: TermSymbol = newCompletePackageSymbol(RootClass, nme.OPS_PACKAGE, initTastyVersion = -1).entered @tu lazy val OpsPackageClass: ClassSymbol = OpsPackageVal.moduleClass.asClass @tu lazy val ScalaPackageVal: TermSymbol = requiredPackage(nme.scala) @@ -446,7 +446,7 @@ class Definitions { Any_toString, Any_##, Any_getClass, Any_isInstanceOf, Any_typeTest, Object_eq, Object_ne) @tu lazy val AnyKindClass: ClassSymbol = { - val cls = newCompleteClassSymbol(ScalaPackageClass, tpnme.AnyKind, AbstractFinal | Permanent, Nil, newScope(0)) + val cls = newCompleteClassSymbol(ScalaPackageClass, tpnme.AnyKind, AbstractFinal | Permanent, Nil, newScope(0), initTastyVersion = -1) if (!ctx.settings.YnoKindPolymorphism.value) // Enable kind-polymorphism by exposing scala.AnyKind cls.entered @@ -1377,7 +1377,8 @@ class Definitions { ), privateWithin = patch.privateWithin, coord = denot.symbol.coord, - assocFile = denot.symbol.associatedFile + assocFile = denot.symbol.associatedFile, + initTastyVersion = denot.tastyVersion ) def makeNonClassSymbol(patch: Symbol) = diff --git a/compiler/src/dotty/tools/dotc/core/Denotations.scala b/compiler/src/dotty/tools/dotc/core/Denotations.scala index 640ba8015be7..e5d9b5b024eb 100644 --- a/compiler/src/dotty/tools/dotc/core/Denotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Denotations.scala @@ -1357,7 +1357,7 @@ object Denotations { */ def missingHook(owner: Symbol, name: Name)(using Context): Symbol = if (owner.is(Package) && name.isTermName) - newCompletePackageSymbol(owner, name.asTermName).entered + newCompletePackageSymbol(owner, name.asTermName, initTastyVersion = -1).entered // AR else NoSymbol diff --git a/compiler/src/dotty/tools/dotc/core/NamerOps.scala b/compiler/src/dotty/tools/dotc/core/NamerOps.scala index dc09edd79781..898c4c206b0b 100644 --- a/compiler/src/dotty/tools/dotc/core/NamerOps.scala +++ b/compiler/src/dotty/tools/dotc/core/NamerOps.scala @@ -138,7 +138,8 @@ object NamerOps: ConstructorCompanionFlags, ConstructorCompanionFlags, constructorCompanionCompleter(cls), coord = cls.coord, - assocFile = cls.assocFile) + assocFile = cls.assocFile, + initTastyVersion = cls.classDenot.tastyVersion) companion.moduleClass.registerCompanion(cls) cls.registerCompanion(companion.moduleClass) companion diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index f63ff1c9013d..14edbf8d3653 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -1935,8 +1935,8 @@ object SymDenotations { def hasTastyVersion: Boolean = myTastyVersion != -1 def tastyVersion: Long = - println("sym id of " + name + " is " + symbol.id) - println("checking hasTastyVersion " + name + " " + hasTastyVersion + " " + System.identityHashCode(this)) +// println("sym id of " + name + " is " + symbol.id) +// println("checking hasTastyVersion " + name + " " + hasTastyVersion + " " + System.identityHashCode(this)) require(hasTastyVersion, s"tasty version of $name not set") myTastyVersion @@ -2661,7 +2661,6 @@ object SymDenotations { initTastyVersion: Long = -1)(using Context): SymDenotation = { val result = if (symbol.isClass) - try println(s"${symbol.name} isClass") catch case _ => () if (initFlags.is(Package)) new PackageClassDenotation(symbol, owner, name, initFlags, initInfo, initPrivateWithin, initTastyVersion) else new ClassDenotation(symbol, owner, name, initFlags, initInfo, initPrivateWithin, initTastyVersion) else new SymDenotation(symbol, owner, name, initFlags, initInfo, initPrivateWithin) diff --git a/compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala b/compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala index 3969a09a69ee..c536fe7ad69c 100644 --- a/compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala +++ b/compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala @@ -51,7 +51,7 @@ object SymbolLoaders { def enterClass( owner: Symbol, name: PreName, completer: SymbolLoader, flags: FlagSet = EmptyFlags, scope: Scope = EmptyScope)(using Context): Symbol = { - val cls = newClassSymbol(owner, name.toTypeName.unmangleClassName.decode, flags, completer, assocFile = completer.sourceFileOrNull) + val cls = newClassSymbol(owner, name.toTypeName.unmangleClassName.decode, flags, completer, assocFile = completer.sourceFileOrNull, initTastyVersion = -1) enterNew(owner, cls, completer, scope) } @@ -63,7 +63,7 @@ object SymbolLoaders { val module = newModuleSymbol( owner, name.toTermName.decode, modFlags, clsFlags, (module, _) => completer.proxy.withDecls(newScope).withSourceModule(module), - assocFile = completer.sourceFileOrNull) + assocFile = completer.sourceFileOrNull, initTastyVersion = -1) enterNew(owner, module, completer, scope) enterNew(owner, module.moduleClass, completer, scope) } @@ -94,7 +94,7 @@ object SymbolLoaders { em"""$owner contains object and package with same name: $pname |one of them needs to be removed from classpath""") newModuleSymbol(owner, pname, PackageCreationFlags, PackageCreationFlags, - completer).entered + completer, initTastyVersion = -1).entered } /** Enter class and module with given `name` into scope of `owner` @@ -390,11 +390,11 @@ abstract class SymbolLoader extends LazyType { self => if (rootDenot.is(ModuleClass)) newClassSymbol( rootDenot.owner, rootDenot.name.stripModuleClassSuffix.asTypeName, Synthetic, - _ => NoType).classDenot + _ => NoType, initTastyVersion = -1).classDenot else newModuleSymbol( rootDenot.owner, rootDenot.name.toTermName, Synthetic, Synthetic, - (module, _) => NoLoader().withDecls(newScope).withSourceModule(module)) + (module, _) => NoLoader().withDecls(newScope).withSourceModule(module), initTastyVersion = -1) .moduleClass.denot.asClass } if (rootDenot.is(ModuleClass)) (linkedDenot, rootDenot) diff --git a/compiler/src/dotty/tools/dotc/core/Symbols.scala b/compiler/src/dotty/tools/dotc/core/Symbols.scala index ea3ff0472ab7..8e6edd5134b5 100644 --- a/compiler/src/dotty/tools/dotc/core/Symbols.scala +++ b/compiler/src/dotty/tools/dotc/core/Symbols.scala @@ -2,36 +2,39 @@ package dotty.tools package dotc package core -import Periods._ -import Names._ -import Scopes._ -import Flags._ -import Decorators._ -import Contexts._ -import Phases._ -import SymDenotations._ -import Denotations._ -import printing.Texts._ +import Periods.* +import Names.* +import Scopes.* +import Flags.* +import Decorators.* +import Contexts.* +import Phases.* +import SymDenotations.* +import Denotations.* +import printing.Texts.* import printing.Printer -import Types._ -import util.Spans._ -import DenotTransformers._ -import StdNames._ -import NameOps._ -import transform.SymUtils._ +import Types.* +import util.Spans.* +import DenotTransformers.* +import StdNames.* +import NameOps.* +import transform.SymUtils.* import NameKinds.LazyImplicitName import ast.tpd -import tpd.{Tree, TreeProvider, TreeOps} +import tpd.{Tree, TreeOps, TreeProvider} import ast.TreeTypeMap import Constants.Constant import Variances.Variance import reporting.Message + import collection.mutable import io.AbstractFile -import util.{SourceFile, NoSource, Property, SourcePosition, SrcPos, EqHashMap} +import util.{EqHashMap, NoSource, Property, SourceFile, SourcePosition, SrcPos} + import scala.annotation.internal.sharable import config.Printers.typr import dotty.tools.dotc.classpath.FileUtils.isScalaBinary +import dotty.tools.tasty.TastyFormat object Symbols { @@ -369,7 +372,7 @@ object Symbols { val d = denot.asClass.tastyVersion newClassSymbol(owner, name.asTypeName, flags, _ => info, privateWithin, coord1, associatedFile1, initTastyVersion = d) else - newSymbol(owner, name, flags, info, privateWithin, coord1, initTastyVersion = -1) // AR + newSymbol(owner, name, flags, info, privateWithin, coord1) } // -------- Printing -------------------------------------------------------- @@ -519,10 +522,9 @@ object Symbols { info: Type, privateWithin: Symbol = NoSymbol, coord: Coord = NoCoord, - nestingLevel: Int = ctx.nestingLevel, - initTastyVersion: Long): Symbol { type ThisName = N } = { + nestingLevel: Int = ctx.nestingLevel): Symbol { type ThisName = N } = { val sym = new Symbol(coord, ctx.base.nextSymId, nestingLevel).asInstanceOf[Symbol { type ThisName = N }] - val denot = SymDenotation(sym, owner, name, flags, info, privateWithin, initTastyVersion) + val denot = SymDenotation(sym, owner, name, flags, info, privateWithin) sym.denot = denot sym } @@ -587,7 +589,8 @@ object Symbols { } def newRefinedClassSymbol(coord: Coord = NoCoord)(using Context): ClassSymbol = - newCompleteClassSymbol(ctx.owner, tpnme.REFINE_CLASS, NonMember, parents = Nil, newScope, coord = coord) + newCompleteClassSymbol(ctx.owner, tpnme.REFINE_CLASS, NonMember, parents = Nil, newScope, coord = coord, + initTastyVersion = TastyFormat.currentTastyVersion) /** Create a module symbol with associated module class * from its non-info fields and a function producing the info @@ -608,7 +611,7 @@ object Symbols { val modclsFlags = clsFlags | ModuleClassCreationFlags val modclsName = name.toTypeName.adjustIfModuleClass(modclsFlags) val module = newSymbol( - owner, name, modFlags | ModuleValCreationFlags, NoCompleter, privateWithin, coord, initTastyVersion = initTastyVersion) + owner, name, modFlags | ModuleValCreationFlags, NoCompleter, privateWithin, coord) val modcls = newClassSymbol( owner, modclsName, modclsFlags, infoFn(module, _), privateWithin, coord, assocFile, initTastyVersion) module.info = @@ -673,8 +676,9 @@ object Symbols { def newPackageSymbol( owner: Symbol, name: TermName, - infoFn: (TermSymbol, ClassSymbol) => LazyType)(using Context): TermSymbol = - newModuleSymbol(owner, name, PackageCreationFlags, PackageCreationFlags, infoFn) + infoFn: (TermSymbol, ClassSymbol) => LazyType, + initTastyVersion: Long)(using Context): TermSymbol = + newModuleSymbol(owner, name, PackageCreationFlags, PackageCreationFlags, infoFn, initTastyVersion = initTastyVersion) /** Create a package symbol with associated package class * from its non-info fields its member scope. */ @@ -683,11 +687,12 @@ object Symbols { name: TermName, modFlags: FlagSet = EmptyFlags, clsFlags: FlagSet = EmptyFlags, - decls: Scope = newScope(0))(using Context): TermSymbol = + decls: Scope = newScope(0), + initTastyVersion: Long)(using Context): TermSymbol = newCompleteModuleSymbol( owner, name, modFlags | PackageCreationFlags, clsFlags | PackageCreationFlags, - Nil, decls) + Nil, decls, initTastyVersion = initTastyVersion) /** Define a new symbol associated with a Bind or pattern wildcard and, by default, make it gadt narrowable. */ def newPatternBoundSymbol( @@ -712,9 +717,9 @@ object Symbols { //if (base.settings.debug.value) throw new Error() val stub = name match { case name: TermName => - newModuleSymbol(normalizedOwner, name, EmptyFlags, EmptyFlags, stubCompleter, assocFile = file) + newModuleSymbol(normalizedOwner, name, EmptyFlags, EmptyFlags, stubCompleter, assocFile = file, initTastyVersion = -1) case name: TypeName => - newClassSymbol(normalizedOwner, name, EmptyFlags, stubCompleter, assocFile = file) + newClassSymbol(normalizedOwner, name, EmptyFlags, stubCompleter, assocFile = file, initTastyVersion = -1) } stub } @@ -801,7 +806,7 @@ object Symbols { def newErrorSymbol(owner: Symbol, name: Name, msg: Message)(using Context): Symbol = { val errType = ErrorType(msg) newSymbol(owner, name, SyntheticArtifact, - if (name.isTypeName) TypeAlias(errType) else errType, initTastyVersion = -1) + if (name.isTypeName) TypeAlias(errType) else errType) } /** Map given symbols, subjecting their attributes to the mappings diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index f6f3d47386e6..3a2d09f5b697 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -61,6 +61,8 @@ class TreeUnpickler(reader: TastyReader, import TreeUnpickler._ import tpd._ + val tastyVersion = (header.majorVersion.toLong << (28 * 2)) | (header.minorVersion.toLong << 28) | header.experimentalVersion.toLong // AR + /** A map from addresses of definition entries to the symbols they define */ private val symAtAddr = new mutable.HashMap[Addr, Symbol] @@ -615,7 +617,6 @@ class TreeUnpickler(reader: TastyReader, def adjustIfModule(completer: LazyType) = if (flags.is(Module)) adjustModuleCompleter(completer, name) else completer val coord = coordAt(start) - val tastyVersion = (header.majorVersion.toLong << (28 * 2)) | (header.minorVersion.toLong << 28) | header.experimentalVersion.toLong val sym = roots.find(root => (root.owner eq ctx.owner) && root.name == name) match { case Some(rootd) => @@ -633,7 +634,7 @@ class TreeUnpickler(reader: TastyReader, if (isClass) newClassSymbol(ctx.owner, name.asTypeName, flags, completer, privateWithin, coord, initTastyVersion = tastyVersion) else - newSymbol(ctx.owner, name, flags, completer, privateWithin, coord, initTastyVersion = tastyVersion) + newSymbol(ctx.owner, name, flags, completer, privateWithin, coord) } val annotOwner = if sym.owner.isClass then newLocalDummy(sym.owner) else sym.owner @@ -1441,6 +1442,7 @@ class TreeUnpickler(reader: TastyReader, else unapply case REFINEDtpt => val refineCls = symAtAddr.getOrElse(start, +// newRefinedClassSymbol(coordAt(start)), tastyVersion).asClass // RM? newRefinedClassSymbol(coordAt(start))).asClass registerSym(start, refineCls) typeAtAddr(start) = refineCls.typeRef diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index 84cf8ba0ce7e..067c96a77d30 100644 --- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -567,8 +567,10 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas .suchThat(_.is(Module)).symbol) else unpickler } + // TODO leave at -1, instead should check is not scala2 before trying to use +// newClassSymbol(owner, name.asTypeName, flags, completer, privateWithin, coord = start, initTastyVersion = -1) newClassSymbol(owner, name.asTypeName, flags, completer, privateWithin, coord = start, initTastyVersion = 0) -// newClassSymbol(owner, name.asTypeName, flags, completer, privateWithin, coord = start) +// newClassSymbol(owner, name.asTypeName, flags, completer, privateWithin, coord = start) // NOTE original version } case VALsym => newSymbol(owner, name.asTermName, flags, localMemberUnpickler, privateWithin, coord = start) @@ -580,7 +582,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas new LocalUnpickler().withModuleClass( owner.info.decls.lookup(name.moduleClassName) .suchThat(_.is(Module)).symbol) - , privateWithin, coord = start, initTastyVersion = 0) + , privateWithin, coord = start) case _ => errorBadSignature("bad symbol tag: " + tag) }) diff --git a/compiler/src/dotty/tools/dotc/transform/SymUtils.scala b/compiler/src/dotty/tools/dotc/transform/SymUtils.scala index 767382a06d9a..7d3b84c2f17f 100644 --- a/compiler/src/dotty/tools/dotc/transform/SymUtils.scala +++ b/compiler/src/dotty/tools/dotc/transform/SymUtils.scala @@ -110,11 +110,12 @@ object SymUtils: /** Is a case class for which mirrors support access to default arguments. */ - def mirrorSupportsDefaultArguments(using Context): Boolean = self.isClass && { - val d = self.asClass.classDenot -// TastyFormat.isVersionCompatible(28, 4, 1, d.tastyMajorVersion, d.tastyMinorVersion, d.tastyExperimentalVersion) - d.tastyMajorVersion == 28 && d.tastyMinorVersion >= 4 - } + def mirrorSupportsDefaultArguments(using Context): Boolean = + !self.is(JavaDefined) && !self.is(Scala2x) && self.isClass && { + val d = self.asClass.classDenot + // TastyFormat.isVersionCompatible(28, 4, 1, d.tastyMajorVersion, d.tastyMinorVersion, d.tastyExperimentalVersion) + d.tastyMajorVersion == 28 && d.tastyMinorVersion >= 4 + } /** Is this an old style implicit conversion? * @param directOnly only consider explicitly written methods diff --git a/compiler/src/dotty/tools/dotc/transform/sjs/JUnitBootstrappers.scala b/compiler/src/dotty/tools/dotc/transform/sjs/JUnitBootstrappers.scala index b911d7dfab96..8332f9409380 100644 --- a/compiler/src/dotty/tools/dotc/transform/sjs/JUnitBootstrappers.scala +++ b/compiler/src/dotty/tools/dotc/transform/sjs/JUnitBootstrappers.scala @@ -14,6 +14,7 @@ import Symbols._ import StdNames._ import Types._ import Decorators.em +import dotty.tools.tasty.TastyFormat import dotty.tools.dotc.transform.MegaPhase._ @@ -156,7 +157,8 @@ class JUnitBootstrappers extends MiniPhase { val moduleSym = newCompleteModuleSymbol(owner, bootstrapperName, Synthetic, Synthetic, List(defn.ObjectType, junitdefn.BootstrapperType), newScope, - coord = testClass.span, assocFile = testClass.assocFile).entered + coord = testClass.span, assocFile = testClass.assocFile, + initTastyVersion = TastyFormat.currentTastyVersion).entered val classSym = moduleSym.moduleClass.asClass val constr = genConstructor(classSym) diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index 04aca960845e..a66061b8d0c7 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -3,38 +3,41 @@ package dotc package typer import backend.sjs.JSDefinitions -import core._ -import ast.{TreeTypeMap, untpd, tpd} -import util.Spans._ -import util.Stats.{record, monitored} -import printing.{Showable, Printer} -import printing.Texts._ -import Contexts._ -import Types._ -import Flags._ +import core.* +import ast.{TreeTypeMap, tpd, untpd} +import util.Spans.* +import util.Stats.{monitored, record} +import printing.{Printer, Showable} +import printing.Texts.* +import Contexts.* +import Types.* +import Flags.* import Mode.ImplicitsEnabled -import NameKinds.{LazyImplicitName, ContextBoundParamName} -import Symbols._ -import Types._ -import Decorators._ -import Names._ -import StdNames._ -import ProtoTypes._ -import ErrorReporting._ +import NameKinds.{ContextBoundParamName, LazyImplicitName} +import Symbols.* +import Types.* +import Decorators.* +import Names.* +import StdNames.* +import ProtoTypes.* +import ErrorReporting.* import Inferencing.{fullyDefinedType, isFullyDefined} import Scopes.newScope -import Typer.BindingPrec, BindingPrec.* -import transform.TypeUtils._ -import Hashable._ +import Typer.BindingPrec +import BindingPrec.* +import transform.TypeUtils.* +import Hashable.* import util.{EqHashMap, Stats} import config.{Config, Feature} import Feature.migrateTo3 import config.Printers.{implicits, implicitsDetailed} +import dotty.tools.tasty.TastyFormat + import collection.mutable -import reporting._ +import reporting.* import transform.Splicer -import annotation.tailrec +import annotation.tailrec import scala.annotation.internal.sharable import scala.annotation.threadUnsafe @@ -1888,7 +1891,8 @@ final class SearchRoot extends SearchHistory: // } val parents = List(defn.ObjectType, defn.SerializableType) - val classSym = newNormalizedClassSymbol(ctx.owner, LazyImplicitName.fresh().toTypeName, Synthetic | Final, parents, coord = span) + val classSym = newNormalizedClassSymbol(ctx.owner, LazyImplicitName.fresh().toTypeName, Synthetic | Final, parents, coord = span, + initTastyVersion = TastyFormat.currentTastyVersion) val vsyms = pruned.map(_._1.symbol) val nsyms = vsyms.map(vsym => newSymbol(classSym, vsym.name, EmptyFlags, vsym.info, coord = span).entered) val vsymMap = (vsyms zip nsyms).toMap diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 85e1591cd0bf..2e160010ba7d 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -211,7 +211,7 @@ class Namer { typer: Typer => if (tree.mods.is(Module)) adjustModuleCompleter(completer, tree.name) else completer - typr.println(i"creating symbol for $tree in ${ctx.mode}") +// typr.println(i"creating symbol for $tree in ${ctx.mode}") // RM /** Create new symbol or redefine existing symbol under lateCompile. */ def createOrRefine[S <: Symbol]( @@ -267,8 +267,8 @@ class Namer { typer: Typer => cls.completer.asInstanceOf[ClassCompleter].init() cls case tree: MemberDef => - if tree.toString.contains("Some") then - println(s"creating symbol for member ${tree.name}") +// if tree.toString.contains("Some") then +// println(s"creating symbol for member ${tree.name}") var flags = checkFlags(tree.mods.flags) val name = checkNoConflict(tree.name, flags.is(Private), tree.span) @@ -309,7 +309,7 @@ class Namer { typer: Typer => case _ => Completer(tree)(cctx) val info = adjustIfModule(completer, tree) val s = createOrRefine[Symbol](tree, name, flags, ctx.owner, _ => info, - (fs, _, pwithin) => newSymbol(ctx.owner, name, fs, info, pwithin, tree.nameSpan, initTastyVersion = currentTastyVersion)) + (fs, _, pwithin) => newSymbol(ctx.owner, name, fs, info, pwithin, tree.nameSpan)) s case tree: Import => @@ -357,9 +357,9 @@ class Namer { typer: Typer => val existingType = pkgOwner.info.decls.lookup(pid.name.toTypeName) if (existingType.exists) { report.error(PkgDuplicateSymbol(existingType), pid.srcPos) - newCompletePackageSymbol(pkgOwner, (pid.name ++ "$_error_").toTermName).entered + newCompletePackageSymbol(pkgOwner, (pid.name ++ "$_error_").toTermName, initTastyVersion = TastyFormat.currentTastyVersion).entered } - else newCompletePackageSymbol(pkgOwner, pid.name.asTermName).entered + else newCompletePackageSymbol(pkgOwner, pid.name.asTermName, initTastyVersion = TastyFormat.currentTastyVersion).entered } } @@ -710,7 +710,8 @@ class Namer { typer: Typer => val className = moduleName.stripModuleClassSuffix.toTypeName val classSym = ctx.effectiveScope.lookup(className) if !classSym.isDefinedInCurrentRun then - val absentClassSymbol = newClassSymbol(ctx.owner, className, EmptyFlags, _ => NoType) + val absentClassSymbol = newClassSymbol(ctx.owner, className, EmptyFlags, _ => NoType, + initTastyVersion = TastyFormat.currentTastyVersion) enterSymbol(absentClassSymbol) for case cdef @ TypeDef(className, _) <- classDef.values do @@ -727,7 +728,8 @@ class Namer { typer: Typer => if needsConstructorProxies(classSym) then classConstructorCompanion(classSym.asClass) else newModuleSymbol( - ctx.owner, moduleName, EmptyFlags, EmptyFlags, (_, _) => NoType) + ctx.owner, moduleName, EmptyFlags, EmptyFlags, (_, _) => NoType, + initTastyVersion = TastyFormat.currentTastyVersion) enterSymbol(companion) end addAbsentCompanions diff --git a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala index 0a6b04fea81e..8d803515a855 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala @@ -18,6 +18,7 @@ import dotty.tools.dotc.quoted.MacroExpansion import dotty.tools.dotc.quoted.PickledQuotes import dotty.tools.dotc.quoted.QuotePatterns import dotty.tools.dotc.quoted.reflect._ +import dotty.tools.tasty.TastyFormat import scala.quoted.runtime.{QuoteUnpickler, QuoteMatching} import scala.quoted.runtime.impl.printers._ @@ -2552,7 +2553,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler dotc.core.Flags.EmptyFlags, parents, selfType.getOrElse(Types.NoType), - dotc.core.Symbols.NoSymbol) + dotc.core.Symbols.NoSymbol, + initTastyVersion = TastyFormat.currentTastyVersion) cls.enter(dotc.core.Symbols.newConstructor(cls, dotc.core.Flags.Synthetic, Nil, Nil)) for sym <- decls(cls) do cls.enter(sym) cls @@ -2567,7 +2569,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler clsFlags | dotc.core.Flags.ModuleClassCreationFlags, parents, dotc.core.Scopes.newScope, - privateWithin) + privateWithin, + initTastyVersion = TastyFormat.currentTastyVersion) val cls = mod.moduleClass.asClass cls.enter(dotc.core.Symbols.newConstructor(cls, dotc.core.Flags.Synthetic, Nil, Nil)) for sym <- decls(cls) do cls.enter(sym) diff --git a/staging/src/scala/quoted/staging/QuoteCompiler.scala b/staging/src/scala/quoted/staging/QuoteCompiler.scala index eee2dacdc5f5..30d3ce149a82 100644 --- a/staging/src/scala/quoted/staging/QuoteCompiler.scala +++ b/staging/src/scala/quoted/staging/QuoteCompiler.scala @@ -20,6 +20,7 @@ import dotty.tools.dotc.transform.{Inlining, Staging, Splicing, PickleQuotes} import dotty.tools.dotc.util.Spans.Span import dotty.tools.dotc.util.{SourceFile, NoSourcePosition} import dotty.tools.io.{Path, VirtualFile} +import dotty.tools.tasty.TastyFormat import scala.quoted.runtime.impl._ @@ -73,7 +74,8 @@ private class QuoteCompiler extends Compiler: // Places the contents of expr in a compilable tree for a class with the following format. // `package __root__ { class ' { def apply: Any = } }` val cls = newCompleteClassSymbol(defn.RootClass, outputClassName, EmptyFlags, - defn.ObjectType :: Nil, newScope, coord = pos, assocFile = assocFile).entered.asClass + defn.ObjectType :: Nil, newScope, coord = pos, assocFile = assocFile, + initTastyVersion = TastyFormat.currentTastyVersion).entered.asClass cls.enter(newDefaultConstructor(cls), EmptyScope) val meth = newSymbol(cls, nme.apply, Method, ExprType(defn.AnyType), coord = pos).entered diff --git a/tasty/src/dotty/tools/tasty/TastyFormat.scala b/tasty/src/dotty/tools/tasty/TastyFormat.scala index d91295f06af5..4c3d25af6524 100644 --- a/tasty/src/dotty/tools/tasty/TastyFormat.scala +++ b/tasty/src/dotty/tools/tasty/TastyFormat.scala @@ -310,6 +310,11 @@ object TastyFormat { */ final val ExperimentalVersion: Int = 1 + // AR ! + val currentTastyVersion: Long = (TastyFormat.MajorVersion.toLong << (28 * 2)) | + (TastyFormat.MinorVersion.toLong << 28) | + TastyFormat.ExperimentalVersion.toLong + /**This method implements a binary relation (`<:<`) between two TASTy versions. * * We label the lhs `file` and rhs `compiler`. diff --git a/tests/pos/i12508c.scala b/tests/pos/i12508c.scala index 4e7bf7b63a10..d8af0a73864a 100644 --- a/tests/pos/i12508c.scala +++ b/tests/pos/i12508c.scala @@ -24,16 +24,16 @@ def test = b = println(1), ) // works -// fun( -// b = println(1), -// a = { -// enum Option2[+X]: -// case Some2(x: X) -// case None2 -// -// import Option2.* -// summon[deriving.Mirror.Of[Some2[Int]]] -// -// if ??? then Option2.Some2(1) else Option2.None2 -// } -// ) // fails \ No newline at end of file + fun( + b = println(1), + a = { + enum Option2[+X]: + case Some2(x: X) + case None2 + + import Option2.* + summon[deriving.Mirror.Of[Some2[Int]]] + + if ??? then Option2.Some2(1) else Option2.None2 + } + ) // fails \ No newline at end of file