Skip to content

Commit 9fc9f21

Browse files
committed
Scala2Unpickler: set privateWithin at symbol creation time
Second step towards making `privateWithin` force less.
1 parent f648faa commit 9fc9f21

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

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

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
468468
//if (isModuleRoot) println(s"moduleRoot of $moduleRoot found at $readIndex, flags = ${flags.flagsString}") // !!! DEBUG
469469
//if (isModuleClassRoot) println(s"moduleClassRoot of $moduleClassRoot found at $readIndex, flags = ${flags.flagsString}") // !!! DEBUG
470470

471-
def completeRoot(denot: ClassDenotation, completer: LazyType): Symbol = {
471+
def completeRoot(denot: ClassDenotation, completer: LazyType, privateWithin: Symbol): Symbol = {
472472
denot.setFlag(flags)
473473
denot.resetFlag(Touched) // allow one more completion
474474

@@ -479,6 +479,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
479479
if (owner == defn.ScalaPackageClass && ((name eq tpnme.Serializable) || (name eq tpnme.Product)))
480480
denot.setFlag(NoInits)
481481

482+
denot.privateWithin = privateWithin
482483
denot.info = completer
483484
denot.symbol
484485
}
@@ -497,24 +498,32 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
497498
sym
498499
}
499500

501+
val (privateWithin, infoRef) = {
502+
val ref = readNat()
503+
if (!isSymbolRef(ref))
504+
(NoSymbol, ref)
505+
else {
506+
val pw = at(ref, () => readSymbol())
507+
(pw, readNat())
508+
}
509+
}
510+
500511
finishSym(tag match {
501512
case TYPEsym | ALIASsym =>
502513
var name1 = name.asTypeName
503514
var flags1 = flags
504515
if (flags.is(TypeParam)) flags1 |= owner.typeParamCreationFlags
505-
ctx.newSymbol(owner, name1, flags1, localMemberUnpickler, coord = start)
516+
ctx.newSymbol(owner, name1, flags1, localMemberUnpickler, privateWithin, coord = start)
506517
case CLASSsym =>
507-
var infoRef = readNat()
508-
if (isSymbolRef(infoRef)) infoRef = readNat()
509518
if (isClassRoot)
510519
completeRoot(
511-
classRoot, rootClassUnpickler(start, classRoot.symbol, NoSymbol, infoRef))
520+
classRoot, rootClassUnpickler(start, classRoot.symbol, NoSymbol, infoRef), privateWithin)
512521
else if (isModuleClassRoot)
513522
completeRoot(
514-
moduleClassRoot, rootClassUnpickler(start, moduleClassRoot.symbol, moduleClassRoot.sourceModule, infoRef))
523+
moduleClassRoot, rootClassUnpickler(start, moduleClassRoot.symbol, moduleClassRoot.sourceModule, infoRef), privateWithin)
515524
else if (name == tpnme.REFINE_CLASS)
516525
// create a type alias instead
517-
ctx.newSymbol(owner, name, flags, localMemberUnpickler, coord = start)
526+
ctx.newSymbol(owner, name, flags, localMemberUnpickler, privateWithin, coord = start)
518527
else {
519528
def completer(cls: Symbol) = {
520529
val unpickler = new ClassUnpickler(infoRef) withDecls symScope(cls)
@@ -524,10 +533,10 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
524533
.suchThat(_.is(Module)).symbol)
525534
else unpickler
526535
}
527-
ctx.newClassSymbol(owner, name.asTypeName, flags, completer, coord = start)
536+
ctx.newClassSymbol(owner, name.asTypeName, flags, completer, privateWithin, coord = start)
528537
}
529538
case VALsym =>
530-
ctx.newSymbol(owner, name.asTermName, flags, localMemberUnpickler, coord = start)
539+
ctx.newSymbol(owner, name.asTermName, flags, localMemberUnpickler, privateWithin, coord = start)
531540
case MODULEsym =>
532541
if (isModuleRoot) {
533542
moduleRoot setFlag flags
@@ -536,7 +545,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
536545
new LocalUnpickler() withModuleClass(implicit ctx =>
537546
owner.info.decls.lookup(name.moduleClassName)
538547
.suchThat(_.is(Module)).symbol)
539-
, coord = start)
548+
, privateWithin, coord = start)
540549
case _ =>
541550
errorBadSignature("bad symbol tag: " + tag)
542551
})
@@ -552,16 +561,13 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
552561
val unusedNameref = readNat()
553562
val unusedOwnerref = readNat()
554563
val unusedFlags = readLongNat()
564+
555565
var inforef = readNat()
556-
denot.privateWithin =
557-
if (!isSymbolRef(inforef)) NoSymbol
558-
else {
559-
val pw = at(inforef, () => readSymbol())
560-
inforef = readNat()
561-
pw
562-
}
566+
if (isSymbolRef(inforef)) inforef = readNat()
567+
563568
// println("reading type for " + denot) // !!! DEBUG
564569
val tp = at(inforef, () => readType()(ctx))
570+
565571
denot match {
566572
case denot: ClassDenotation =>
567573
val selfInfo = if (atEnd) NoType else readTypeRef()

0 commit comments

Comments
 (0)