Skip to content

Commit

Permalink
tmp before removing initTastyVersion param from newSymbol factory method
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneFlesselle committed Oct 31, 2023
1 parent d015fb1 commit 62dce94
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 34 deletions.
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1935,7 +1935,9 @@ object SymDenotations {
def hasTastyVersion: Boolean = myTastyVersion != -1

def tastyVersion: Long =
require(hasTastyVersion)
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

def tastyMajorVersion: Int = (tastyVersion >>> (28 * 2)).toInt
Expand Down Expand Up @@ -2659,6 +2661,7 @@ 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
39 changes: 23 additions & 16 deletions compiler/src/dotty/tools/dotc/core/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,10 @@ object Symbols {
val associatedFile1 = if (associatedFile == null) owner.associatedFile else associatedFile

if isClass then
newClassSymbol(owner, name.asTypeName, flags, _ => info, privateWithin, coord1, associatedFile1)
val d = denot.asClass.tastyVersion
newClassSymbol(owner, name.asTypeName, flags, _ => info, privateWithin, coord1, associatedFile1, initTastyVersion = d)
else
newSymbol(owner, name, flags, info, privateWithin, coord1)
newSymbol(owner, name, flags, info, privateWithin, coord1, initTastyVersion = -1) // AR
}

// -------- Printing --------------------------------------------------------
Expand Down Expand Up @@ -519,7 +520,7 @@ object Symbols {
privateWithin: Symbol = NoSymbol,
coord: Coord = NoCoord,
nestingLevel: Int = ctx.nestingLevel,
initTastyVersion: Long = -1): Symbol { type ThisName = N } = {
initTastyVersion: Long): 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)
sym.denot = denot
Expand All @@ -537,7 +538,7 @@ object Symbols {
privateWithin: Symbol = NoSymbol,
coord: Coord = NoCoord,
assocFile: AbstractFile | Null = null,
initTastyVersion: Long = -1)(using Context): ClassSymbol
initTastyVersion: Long)(using Context): ClassSymbol
= {
val cls = new ClassSymbol(coord, assocFile, ctx.base.nextSymId, ctx.nestingLevel)
val denot = SymDenotation(cls, owner, name, flags, infoFn(cls), privateWithin, initTastyVersion)
Expand All @@ -555,11 +556,12 @@ object Symbols {
selfInfo: Type = NoType,
privateWithin: Symbol = NoSymbol,
coord: Coord = NoCoord,
assocFile: AbstractFile | Null = null)(using Context): ClassSymbol =
assocFile: AbstractFile | Null = null,
initTastyVersion: Long)(using Context): ClassSymbol =
newClassSymbol(
owner, name, flags,
ClassInfo(owner.thisType, _, parents, decls, selfInfo),
privateWithin, coord, assocFile)
privateWithin, coord, assocFile, initTastyVersion)

/** Same as `newCompleteClassSymbol` except that `parents` can be a list of arbitrary
* types which get normalized into type refs and parameter bindings.
Expand All @@ -572,15 +574,16 @@ object Symbols {
selfInfo: Type = NoType,
privateWithin: Symbol = NoSymbol,
coord: Coord = NoCoord,
assocFile: AbstractFile | Null = null)(using Context): ClassSymbol = {
assocFile: AbstractFile | Null = null,
initTastyVersion: Long)(using Context): ClassSymbol = {
def completer = new LazyType {
def complete(denot: SymDenotation)(using Context): Unit = {
val cls = denot.asClass.classSymbol
val decls = newScope
denot.info = ClassInfo(owner.thisType, cls, parentTypes.map(_.dealias), decls, selfInfo)
}
}
newClassSymbol(owner, name, flags, completer, privateWithin, coord, assocFile)
newClassSymbol(owner, name, flags, completer, privateWithin, coord, assocFile, initTastyVersion)
}

def newRefinedClassSymbol(coord: Coord = NoCoord)(using Context): ClassSymbol =
Expand All @@ -598,15 +601,16 @@ object Symbols {
infoFn: (TermSymbol, ClassSymbol) => Type, // typically a ModuleClassCompleterWithDecls
privateWithin: Symbol = NoSymbol,
coord: Coord = NoCoord,
assocFile: AbstractFile | Null = null)(using Context): TermSymbol
assocFile: AbstractFile | Null = null,
initTastyVersion: Long)(using Context): TermSymbol
= {
val base = owner.thisType
val modclsFlags = clsFlags | ModuleClassCreationFlags
val modclsName = name.toTypeName.adjustIfModuleClass(modclsFlags)
val module = newSymbol(
owner, name, modFlags | ModuleValCreationFlags, NoCompleter, privateWithin, coord)
owner, name, modFlags | ModuleValCreationFlags, NoCompleter, privateWithin, coord, initTastyVersion = initTastyVersion)
val modcls = newClassSymbol(
owner, modclsName, modclsFlags, infoFn(module, _), privateWithin, coord, assocFile)
owner, modclsName, modclsFlags, infoFn(module, _), privateWithin, coord, assocFile, initTastyVersion)
module.info =
if (modcls.isCompleted) TypeRef(owner.thisType, modcls)
else new ModuleCompleter(modcls)
Expand All @@ -627,12 +631,13 @@ object Symbols {
decls: Scope,
privateWithin: Symbol = NoSymbol,
coord: Coord = NoCoord,
assocFile: AbstractFile | Null = null)(using Context): TermSymbol =
assocFile: AbstractFile | Null = null,
initTastyVersion: Long)(using Context): TermSymbol =
newModuleSymbol(
owner, name, modFlags, clsFlags,
(module, modcls) => ClassInfo(
owner.thisType, modcls, parents, decls, TermRef(owner.thisType, module)),
privateWithin, coord, assocFile)
privateWithin, coord, assocFile, initTastyVersion)

/** Same as `newCompleteModuleSymbol` except that `parents` can be a list of arbitrary
* types which get normalized into type refs and parameter bindings.
Expand All @@ -646,18 +651,20 @@ object Symbols {
decls: Scope,
privateWithin: Symbol = NoSymbol,
coord: Coord = NoCoord,
assocFile: AbstractFile | Null = null)(using Context): TermSymbol = {
assocFile: AbstractFile | Null = null,
initTastyVersion: Long)(using Context): TermSymbol = {
def completer(module: Symbol) = new LazyType {
def complete(denot: SymDenotation)(using Context): Unit = {
val cls = denot.asClass.classSymbol
val decls = newScope
denot.info = ClassInfo(owner.thisType, cls, parentTypes.map(_.dealias), decls, TermRef(owner.thisType, module))
// TODO? set tastyVersion
}
}
newModuleSymbol(
owner, name, modFlags, clsFlags,
(module, modcls) => completer(module),
privateWithin, coord, assocFile)
privateWithin, coord, assocFile, initTastyVersion)
}

/** Create a package symbol with associated package class
Expand Down Expand Up @@ -794,7 +801,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)
if (name.isTypeName) TypeAlias(errType) else errType, initTastyVersion = -1)
}

/** Map given symbols, subjecting their attributes to the mappings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas

denot.setPrivateWithin(privateWithin)
denot.info = completer
denot.tastyVersion = 0
denot.symbol
}

Expand Down Expand Up @@ -549,6 +550,8 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
if (flags.is(TypeParam)) flags1 |= owner.typeParamCreationFlags
newSymbol(owner, name1, flags1, localMemberUnpickler, privateWithin, coord = start)
case CLASSsym =>
// println(s"name: $name")

if (isClassRoot)
completeRoot(
classRoot, rootClassUnpickler(start, classRoot.symbol, NoSymbol, infoRef), privateWithin)
Expand All @@ -564,7 +567,8 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
.suchThat(_.is(Module)).symbol)
else unpickler
}
newClassSymbol(owner, name.asTypeName, flags, completer, privateWithin, coord = start)
newClassSymbol(owner, name.asTypeName, flags, completer, privateWithin, coord = start, initTastyVersion = 0)
// newClassSymbol(owner, name.asTypeName, flags, completer, privateWithin, coord = start)
}
case VALsym =>
newSymbol(owner, name.asTermName, flags, localMemberUnpickler, privateWithin, coord = start)
Expand All @@ -576,7 +580,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)
, privateWithin, coord = start, initTastyVersion = 0)
case _ =>
errorBadSignature("bad symbol tag: " + tag)
})
Expand Down
35 changes: 28 additions & 7 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -237,26 +237,39 @@ class Namer { typer: Typer =>
prev.flags = flags1
prev.info = infoFn(prev.asInstanceOf[S])
prev.setPrivateWithin(privateWithin)
val tastyVersion = (TastyFormat.MajorVersion.toLong << (28 * 2))
| (TastyFormat.MinorVersion.toLong << 28)
| TastyFormat.ExperimentalVersion.toLong
if prev.isClass then prev.asClass.classDenot.tastyVersion = tastyVersion
prev
}
else symFn(flags1, infoFn, privateWithin)
recordSym(sym, tree)
}

tree match {
// TODO Move
val currentTastyVersion = (TastyFormat.MajorVersion.toLong << (28 * 2))
| (TastyFormat.MinorVersion.toLong << 28)
| TastyFormat.ExperimentalVersion.toLong

// if tree.className.contains("Some") then
// println(i"creating symbol for ${tree.className}")
val res = tree match {
case tree: TypeDef if tree.isClassDef =>
// if tree.toString.contains("Some") then
// println(s"creating symbol for class ${tree.name}")
val flags = checkFlags(tree.mods.flags)
val name = checkNoConflict(tree.name, flags.is(Private), tree.span).asTypeName
val tastyVersion = (TastyFormat.MajorVersion.toLong << (28 * 2))
| (TastyFormat.MinorVersion.toLong << 28)
| TastyFormat.ExperimentalVersion.toLong
val cls =
createOrRefine[ClassSymbol](tree, name, flags, ctx.owner,
cls => adjustIfModule(new ClassCompleter(cls, tree)(ctx), tree),
newClassSymbol(ctx.owner, name, _, _, _, tree.nameSpan, ctx.source.file, tastyVersion))
newClassSymbol(ctx.owner, name, _, _, _, tree.nameSpan, ctx.source.file, currentTastyVersion))
cls.completer.asInstanceOf[ClassCompleter].init()
cls
case tree: MemberDef =>
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)
tree match
Expand Down Expand Up @@ -295,13 +308,21 @@ class Namer { typer: Typer =>
case tree: TypeDef => TypeDefCompleter(tree)(cctx)
case _ => Completer(tree)(cctx)
val info = adjustIfModule(completer, tree)
createOrRefine[Symbol](tree, name, flags, ctx.owner, _ => info,
(fs, _, pwithin) => newSymbol(ctx.owner, name, fs, info, pwithin, tree.nameSpan))
val s = createOrRefine[Symbol](tree, name, flags, ctx.owner, _ => info,
(fs, _, pwithin) => newSymbol(ctx.owner, name, fs, info, pwithin, tree.nameSpan, initTastyVersion = currentTastyVersion))

s
case tree: Import =>
// if tree.toString.contains("Some") then
// println(s"creating symbol for import ${tree.className}")
recordSym(newImportSymbol(ctx.owner, Completer(tree)(ctx), tree.span), tree)
case _ =>
// if tree.toString.contains("Some") then
// println(s"creating symbol for _ ${tree.className}")
NoSymbol
}
// println(s"creating symbol $res")
res
}

/** If `sym` exists, enter it in effective scope. Check that
Expand Down
43 changes: 35 additions & 8 deletions tests/pos/i12508c.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
def fun(a: Any, b: Any = 2): Any = ???
//def fun(a: Any, b: Any = 2): Any = ???
def fun(a: Any, b: Any): Any = ???

def test =

// val a1 = {
// enum Option1[+X]:
// case Some1(x: X)
// case None1
// if ??? then Option1.Some1(1) else Option1.None1
// }
// fun(
// b = println(1),
// a = a1
// ) // works

fun(
b = println(1),
a = {
enum Option[+X]:
case Some(x: X)
case None
if ??? then Option.Some(1) else Option.None
}
)
enum Option3[+X]:
case Some3(x: X)
case None3
if ??? then Option3.Some3(1) else Option3.None3
},
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

0 comments on commit 62dce94

Please sign in to comment.