Skip to content

Commit

Permalink
remove newClassSymbol tastyVersion default argument
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneFlesselle committed Oct 31, 2023
1 parent 62dce94 commit 256b000
Show file tree
Hide file tree
Showing 17 changed files with 137 additions and 106 deletions.
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
15 changes: 8 additions & 7 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) =
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/core/NamerOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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)
Expand Down
67 changes: 36 additions & 31 deletions compiler/src/dotty/tools/dotc/core/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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 --------------------------------------------------------
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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 =
Expand Down Expand Up @@ -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.
*/
Expand All @@ -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(
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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) =>
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
})
Expand Down
11 changes: 6 additions & 5 deletions compiler/src/dotty/tools/dotc/transform/SymUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Symbols._
import StdNames._
import Types._
import Decorators.em
import dotty.tools.tasty.TastyFormat

import dotty.tools.dotc.transform.MegaPhase._

Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 256b000

Please sign in to comment.