Skip to content

Commit 62dce94

Browse files
tmp before removing initTastyVersion param from newSymbol factory method
1 parent d015fb1 commit 62dce94

File tree

5 files changed

+96
-34
lines changed

5 files changed

+96
-34
lines changed

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1935,7 +1935,9 @@ object SymDenotations {
19351935
def hasTastyVersion: Boolean = myTastyVersion != -1
19361936

19371937
def tastyVersion: Long =
1938-
require(hasTastyVersion)
1938+
println("sym id of " + name + " is " + symbol.id)
1939+
println("checking hasTastyVersion " + name + " " + hasTastyVersion + " " + System.identityHashCode(this))
1940+
require(hasTastyVersion, s"tasty version of $name not set")
19391941
myTastyVersion
19401942

19411943
def tastyMajorVersion: Int = (tastyVersion >>> (28 * 2)).toInt
@@ -2659,6 +2661,7 @@ object SymDenotations {
26592661
initTastyVersion: Long = -1)(using Context): SymDenotation = {
26602662
val result =
26612663
if (symbol.isClass)
2664+
try println(s"${symbol.name} isClass") catch case _ => ()
26622665
if (initFlags.is(Package)) new PackageClassDenotation(symbol, owner, name, initFlags, initInfo, initPrivateWithin, initTastyVersion)
26632666
else new ClassDenotation(symbol, owner, name, initFlags, initInfo, initPrivateWithin, initTastyVersion)
26642667
else new SymDenotation(symbol, owner, name, initFlags, initInfo, initPrivateWithin)

compiler/src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,10 @@ object Symbols {
366366
val associatedFile1 = if (associatedFile == null) owner.associatedFile else associatedFile
367367

368368
if isClass then
369-
newClassSymbol(owner, name.asTypeName, flags, _ => info, privateWithin, coord1, associatedFile1)
369+
val d = denot.asClass.tastyVersion
370+
newClassSymbol(owner, name.asTypeName, flags, _ => info, privateWithin, coord1, associatedFile1, initTastyVersion = d)
370371
else
371-
newSymbol(owner, name, flags, info, privateWithin, coord1)
372+
newSymbol(owner, name, flags, info, privateWithin, coord1, initTastyVersion = -1) // AR
372373
}
373374

374375
// -------- Printing --------------------------------------------------------
@@ -519,7 +520,7 @@ object Symbols {
519520
privateWithin: Symbol = NoSymbol,
520521
coord: Coord = NoCoord,
521522
nestingLevel: Int = ctx.nestingLevel,
522-
initTastyVersion: Long = -1): Symbol { type ThisName = N } = {
523+
initTastyVersion: Long): Symbol { type ThisName = N } = {
523524
val sym = new Symbol(coord, ctx.base.nextSymId, nestingLevel).asInstanceOf[Symbol { type ThisName = N }]
524525
val denot = SymDenotation(sym, owner, name, flags, info, privateWithin, initTastyVersion)
525526
sym.denot = denot
@@ -537,7 +538,7 @@ object Symbols {
537538
privateWithin: Symbol = NoSymbol,
538539
coord: Coord = NoCoord,
539540
assocFile: AbstractFile | Null = null,
540-
initTastyVersion: Long = -1)(using Context): ClassSymbol
541+
initTastyVersion: Long)(using Context): ClassSymbol
541542
= {
542543
val cls = new ClassSymbol(coord, assocFile, ctx.base.nextSymId, ctx.nestingLevel)
543544
val denot = SymDenotation(cls, owner, name, flags, infoFn(cls), privateWithin, initTastyVersion)
@@ -555,11 +556,12 @@ object Symbols {
555556
selfInfo: Type = NoType,
556557
privateWithin: Symbol = NoSymbol,
557558
coord: Coord = NoCoord,
558-
assocFile: AbstractFile | Null = null)(using Context): ClassSymbol =
559+
assocFile: AbstractFile | Null = null,
560+
initTastyVersion: Long)(using Context): ClassSymbol =
559561
newClassSymbol(
560562
owner, name, flags,
561563
ClassInfo(owner.thisType, _, parents, decls, selfInfo),
562-
privateWithin, coord, assocFile)
564+
privateWithin, coord, assocFile, initTastyVersion)
563565

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

586589
def newRefinedClassSymbol(coord: Coord = NoCoord)(using Context): ClassSymbol =
@@ -598,15 +601,16 @@ object Symbols {
598601
infoFn: (TermSymbol, ClassSymbol) => Type, // typically a ModuleClassCompleterWithDecls
599602
privateWithin: Symbol = NoSymbol,
600603
coord: Coord = NoCoord,
601-
assocFile: AbstractFile | Null = null)(using Context): TermSymbol
604+
assocFile: AbstractFile | Null = null,
605+
initTastyVersion: Long)(using Context): TermSymbol
602606
= {
603607
val base = owner.thisType
604608
val modclsFlags = clsFlags | ModuleClassCreationFlags
605609
val modclsName = name.toTypeName.adjustIfModuleClass(modclsFlags)
606610
val module = newSymbol(
607-
owner, name, modFlags | ModuleValCreationFlags, NoCompleter, privateWithin, coord)
611+
owner, name, modFlags | ModuleValCreationFlags, NoCompleter, privateWithin, coord, initTastyVersion = initTastyVersion)
608612
val modcls = newClassSymbol(
609-
owner, modclsName, modclsFlags, infoFn(module, _), privateWithin, coord, assocFile)
613+
owner, modclsName, modclsFlags, infoFn(module, _), privateWithin, coord, assocFile, initTastyVersion)
610614
module.info =
611615
if (modcls.isCompleted) TypeRef(owner.thisType, modcls)
612616
else new ModuleCompleter(modcls)
@@ -627,12 +631,13 @@ object Symbols {
627631
decls: Scope,
628632
privateWithin: Symbol = NoSymbol,
629633
coord: Coord = NoCoord,
630-
assocFile: AbstractFile | Null = null)(using Context): TermSymbol =
634+
assocFile: AbstractFile | Null = null,
635+
initTastyVersion: Long)(using Context): TermSymbol =
631636
newModuleSymbol(
632637
owner, name, modFlags, clsFlags,
633638
(module, modcls) => ClassInfo(
634639
owner.thisType, modcls, parents, decls, TermRef(owner.thisType, module)),
635-
privateWithin, coord, assocFile)
640+
privateWithin, coord, assocFile, initTastyVersion)
636641

637642
/** Same as `newCompleteModuleSymbol` except that `parents` can be a list of arbitrary
638643
* types which get normalized into type refs and parameter bindings.
@@ -646,18 +651,20 @@ object Symbols {
646651
decls: Scope,
647652
privateWithin: Symbol = NoSymbol,
648653
coord: Coord = NoCoord,
649-
assocFile: AbstractFile | Null = null)(using Context): TermSymbol = {
654+
assocFile: AbstractFile | Null = null,
655+
initTastyVersion: Long)(using Context): TermSymbol = {
650656
def completer(module: Symbol) = new LazyType {
651657
def complete(denot: SymDenotation)(using Context): Unit = {
652658
val cls = denot.asClass.classSymbol
653659
val decls = newScope
654660
denot.info = ClassInfo(owner.thisType, cls, parentTypes.map(_.dealias), decls, TermRef(owner.thisType, module))
661+
// TODO? set tastyVersion
655662
}
656663
}
657664
newModuleSymbol(
658665
owner, name, modFlags, clsFlags,
659666
(module, modcls) => completer(module),
660-
privateWithin, coord, assocFile)
667+
privateWithin, coord, assocFile, initTastyVersion)
661668
}
662669

663670
/** Create a package symbol with associated package class
@@ -794,7 +801,7 @@ object Symbols {
794801
def newErrorSymbol(owner: Symbol, name: Name, msg: Message)(using Context): Symbol = {
795802
val errType = ErrorType(msg)
796803
newSymbol(owner, name, SyntheticArtifact,
797-
if (name.isTypeName) TypeAlias(errType) else errType)
804+
if (name.isTypeName) TypeAlias(errType) else errType, initTastyVersion = -1)
798805
}
799806

800807
/** Map given symbols, subjecting their attributes to the mappings

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
498498

499499
denot.setPrivateWithin(privateWithin)
500500
denot.info = completer
501+
denot.tastyVersion = 0
501502
denot.symbol
502503
}
503504

@@ -549,6 +550,8 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
549550
if (flags.is(TypeParam)) flags1 |= owner.typeParamCreationFlags
550551
newSymbol(owner, name1, flags1, localMemberUnpickler, privateWithin, coord = start)
551552
case CLASSsym =>
553+
// println(s"name: $name")
554+
552555
if (isClassRoot)
553556
completeRoot(
554557
classRoot, rootClassUnpickler(start, classRoot.symbol, NoSymbol, infoRef), privateWithin)
@@ -564,7 +567,8 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
564567
.suchThat(_.is(Module)).symbol)
565568
else unpickler
566569
}
567-
newClassSymbol(owner, name.asTypeName, flags, completer, privateWithin, coord = start)
570+
newClassSymbol(owner, name.asTypeName, flags, completer, privateWithin, coord = start, initTastyVersion = 0)
571+
// newClassSymbol(owner, name.asTypeName, flags, completer, privateWithin, coord = start)
568572
}
569573
case VALsym =>
570574
newSymbol(owner, name.asTermName, flags, localMemberUnpickler, privateWithin, coord = start)
@@ -576,7 +580,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
576580
new LocalUnpickler().withModuleClass(
577581
owner.info.decls.lookup(name.moduleClassName)
578582
.suchThat(_.is(Module)).symbol)
579-
, privateWithin, coord = start)
583+
, privateWithin, coord = start, initTastyVersion = 0)
580584
case _ =>
581585
errorBadSignature("bad symbol tag: " + tag)
582586
})

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,26 +237,39 @@ class Namer { typer: Typer =>
237237
prev.flags = flags1
238238
prev.info = infoFn(prev.asInstanceOf[S])
239239
prev.setPrivateWithin(privateWithin)
240+
val tastyVersion = (TastyFormat.MajorVersion.toLong << (28 * 2))
241+
| (TastyFormat.MinorVersion.toLong << 28)
242+
| TastyFormat.ExperimentalVersion.toLong
243+
if prev.isClass then prev.asClass.classDenot.tastyVersion = tastyVersion
240244
prev
241245
}
242246
else symFn(flags1, infoFn, privateWithin)
243247
recordSym(sym, tree)
244248
}
245249

246-
tree match {
250+
// TODO Move
251+
val currentTastyVersion = (TastyFormat.MajorVersion.toLong << (28 * 2))
252+
| (TastyFormat.MinorVersion.toLong << 28)
253+
| TastyFormat.ExperimentalVersion.toLong
254+
255+
// if tree.className.contains("Some") then
256+
// println(i"creating symbol for ${tree.className}")
257+
val res = tree match {
247258
case tree: TypeDef if tree.isClassDef =>
259+
// if tree.toString.contains("Some") then
260+
// println(s"creating symbol for class ${tree.name}")
248261
val flags = checkFlags(tree.mods.flags)
249262
val name = checkNoConflict(tree.name, flags.is(Private), tree.span).asTypeName
250-
val tastyVersion = (TastyFormat.MajorVersion.toLong << (28 * 2))
251-
| (TastyFormat.MinorVersion.toLong << 28)
252-
| TastyFormat.ExperimentalVersion.toLong
253263
val cls =
254264
createOrRefine[ClassSymbol](tree, name, flags, ctx.owner,
255265
cls => adjustIfModule(new ClassCompleter(cls, tree)(ctx), tree),
256-
newClassSymbol(ctx.owner, name, _, _, _, tree.nameSpan, ctx.source.file, tastyVersion))
266+
newClassSymbol(ctx.owner, name, _, _, _, tree.nameSpan, ctx.source.file, currentTastyVersion))
257267
cls.completer.asInstanceOf[ClassCompleter].init()
258268
cls
259269
case tree: MemberDef =>
270+
if tree.toString.contains("Some") then
271+
println(s"creating symbol for member ${tree.name}")
272+
260273
var flags = checkFlags(tree.mods.flags)
261274
val name = checkNoConflict(tree.name, flags.is(Private), tree.span)
262275
tree match
@@ -295,13 +308,21 @@ class Namer { typer: Typer =>
295308
case tree: TypeDef => TypeDefCompleter(tree)(cctx)
296309
case _ => Completer(tree)(cctx)
297310
val info = adjustIfModule(completer, tree)
298-
createOrRefine[Symbol](tree, name, flags, ctx.owner, _ => info,
299-
(fs, _, pwithin) => newSymbol(ctx.owner, name, fs, info, pwithin, tree.nameSpan))
311+
val s = createOrRefine[Symbol](tree, name, flags, ctx.owner, _ => info,
312+
(fs, _, pwithin) => newSymbol(ctx.owner, name, fs, info, pwithin, tree.nameSpan, initTastyVersion = currentTastyVersion))
313+
314+
s
300315
case tree: Import =>
316+
// if tree.toString.contains("Some") then
317+
// println(s"creating symbol for import ${tree.className}")
301318
recordSym(newImportSymbol(ctx.owner, Completer(tree)(ctx), tree.span), tree)
302319
case _ =>
320+
// if tree.toString.contains("Some") then
321+
// println(s"creating symbol for _ ${tree.className}")
303322
NoSymbol
304323
}
324+
// println(s"creating symbol $res")
325+
res
305326
}
306327

307328
/** If `sym` exists, enter it in effective scope. Check that

tests/pos/i12508c.scala

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,39 @@
1-
def fun(a: Any, b: Any = 2): Any = ???
1+
//def fun(a: Any, b: Any = 2): Any = ???
2+
def fun(a: Any, b: Any): Any = ???
23

34
def test =
5+
6+
// val a1 = {
7+
// enum Option1[+X]:
8+
// case Some1(x: X)
9+
// case None1
10+
// if ??? then Option1.Some1(1) else Option1.None1
11+
// }
12+
// fun(
13+
// b = println(1),
14+
// a = a1
15+
// ) // works
16+
417
fun(
5-
b = println(1),
618
a = {
7-
enum Option[+X]:
8-
case Some(x: X)
9-
case None
10-
if ??? then Option.Some(1) else Option.None
11-
}
12-
)
19+
enum Option3[+X]:
20+
case Some3(x: X)
21+
case None3
22+
if ??? then Option3.Some3(1) else Option3.None3
23+
},
24+
b = println(1),
25+
) // works
26+
27+
// fun(
28+
// b = println(1),
29+
// a = {
30+
// enum Option2[+X]:
31+
// case Some2(x: X)
32+
// case None2
33+
//
34+
// import Option2.*
35+
// summon[deriving.Mirror.Of[Some2[Int]]]
36+
//
37+
// if ??? then Option2.Some2(1) else Option2.None2
38+
// }
39+
// ) // fails

0 commit comments

Comments
 (0)