Skip to content

Commit ae6d3a8

Browse files
committed
Let createSymbol return a symbol
Compute initialization flags of possibly enclosing traits elsewhere (in indexStats). Cleans up the logic and makes the module more understandable.
1 parent 2cacc33 commit ae6d3a8

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

src/dotty/tools/dotc/core/Flags.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,9 @@ object Flags {
525525
/** Either method or lazy */
526526
final val MethodOrLazy = Method | Lazy
527527

528+
/** Either method or lazy or deferred */
529+
final val MethodOrLazyOrDeferred = Method | Lazy | Deferred
530+
528531
/** Labeled `private` or `final` */
529532
final val PrivateOrFinal = Private | Final
530533

src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,9 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) {
371371
}
372372

373373
/** Create symbol of definition node and enter in symAtAddr map
374-
* @return the largest subset of {NoInits, PureInterface} that a
375-
* trait owning this symbol can have as flags.
374+
* @return the created symbol
376375
*/
377-
def createSymbol()(implicit ctx: Context): FlagSet = {
376+
def createSymbol()(implicit ctx: Context): Symbol = {
378377
val start = currentAddr
379378
val tag = readByte()
380379
val end = readEnd()
@@ -434,10 +433,7 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) {
434433
sym.completer.withDecls(newScope)
435434
forkAt(templateStart).indexTemplateParams()(localContext(sym))
436435
}
437-
if (isClass) NoInits
438-
else if (sym.isType || sym.isConstructor || flags.is(Deferred)) NoInitsInterface
439-
else if (tag == VALDEF) EmptyFlags
440-
else NoInits
436+
sym
441437
}
442438

443439
/** Read modifier list into triplet of flags, annotations and a privateWithin
@@ -504,28 +500,33 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) {
504500
(flags, annots.toList, privateWithin)
505501
}
506502

507-
/** Create symbols for a definitions in statement sequence between
503+
/** Create symbols for the definitions in the statement sequence between
508504
* current address and `end`.
509505
* @return the largest subset of {NoInits, PureInterface} that a
510506
* trait owning the indexed statements can have as flags.
511507
*/
512508
def indexStats(end: Addr)(implicit ctx: Context): FlagSet = {
513-
val flagss =
514-
until(end) {
515-
nextByte match {
516-
case VALDEF | DEFDEF | TYPEDEF | TYPEPARAM | PARAM =>
517-
createSymbol()
518-
case IMPORT =>
519-
skipTree()
520-
NoInitsInterface
521-
case PACKAGE =>
522-
processPackage { (pid, end) => implicit ctx => indexStats(end) }
523-
case _ =>
524-
skipTree()
525-
EmptyFlags
526-
}
509+
var initsFlags = NoInitsInterface
510+
while (currentAddr.index < end.index) {
511+
nextByte match {
512+
case VALDEF | DEFDEF | TYPEDEF | TYPEPARAM | PARAM =>
513+
val sym = createSymbol()
514+
if (sym.isTerm && !sym.is(MethodOrLazyOrDeferred))
515+
initsFlags = EmptyFlags
516+
else if (sym.isClass ||
517+
sym.is(Method, butNot = Deferred) && !sym.isConstructor)
518+
initsFlags &= NoInits
519+
case IMPORT =>
520+
skipTree()
521+
case PACKAGE =>
522+
processPackage { (pid, end) => implicit ctx => indexStats(end) }
523+
case _ =>
524+
skipTree()
525+
initsFlags = EmptyFlags
527526
}
528-
(NoInitsInterface /: flagss)(_ & _)
527+
}
528+
assert(currentAddr.index == end.index)
529+
initsFlags
529530
}
530531

531532
/** Process package with given operation `op`. The operation takes as arguments

0 commit comments

Comments
 (0)