Skip to content

Commit 326696f

Browse files
Performance tweaks for completion flags checking
1 parent 47b3b08 commit 326696f

File tree

2 files changed

+8
-25
lines changed

2 files changed

+8
-25
lines changed

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

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,7 @@ object Flags {
406406
/** A denotation that is valid in all run-ids */
407407
val (Permanent @ _, _, _) = newFlags(61, "<permanent>")
408408

409-
/** Denotation is being loaded. If `Completing` is not set,
410-
* this means this denotation was loaded from an external file.
411-
*/
409+
/** Denotation is being loaded */
412410
val (Loading @ _, _, _) = newFlags(62, "<loading>")
413411

414412
// --------- Combined Flag Sets and Conjunctions ----------------------
@@ -456,19 +454,6 @@ object Flags {
456454
val AfterLoadFlags: FlagSet = commonFlags(
457455
FromStartFlags, Opaque, AccessFlags, Final, AccessorOrSealed, LazyOrTrait, SelfName, JavaDefined)
458456

459-
/** Flags that are not mutated during completion when a certain
460-
* condition is satisfied
461-
*/
462-
object ConditionallyImmutableFlags {
463-
val flagsAndConditions: List[(Flag, (given Contexts.Context) => SymDenotations.SymDenotation => Boolean)] = List(
464-
Deferred -> { denot => denot.is(Opaque) && denot.isType }
465-
)
466-
467-
val flags: FlagSet = flagsAndConditions.map(_._1)
468-
.foldLeft(EmptyFlags) { (accum, next) => accum | next }
469-
}
470-
471-
472457
/** A value that's unstable unless complemented with a Stable flag */
473458
val UnstableValueFlags: FlagSet = Mutable | Method
474459

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,11 @@ object SymDenotations {
161161
private[dotc] final def flagsUNSAFE: FlagSet = myFlags
162162

163163
private def setMyFlags(flags: FlagSet) =
164-
lazy val immutableFlags = if myInfo.isInstanceOf[SymbolLoader] then AfterLoadFlags else FromStartFlags
165-
lazy val changedImmutableFlags = (myFlags ^ flags) & immutableFlags
166-
if myFlags.is(Touched, butNot = Loading) then assert(changedImmutableFlags.isEmpty,
167-
s"Illegal mutation of flags ${changedImmutableFlags.flagsString} on completion of $this")
164+
if myFlags.is(Touched, butNot = Loading) then
165+
val immutableFlags = if myInfo.isInstanceOf[SymbolLoader] then AfterLoadFlags else FromStartFlags
166+
val changedImmutableFlags = (myFlags ^ flags) & immutableFlags
167+
assert(changedImmutableFlags.isEmpty,
168+
s"Illegal mutation of flags ${changedImmutableFlags.flagsString} on completion of $this")
168169
myFlags = flags
169170

170171
final def startedLoading() =
@@ -204,11 +205,8 @@ object SymDenotations {
204205
else AfterLoadFlags
205206
val mutableFlagsBeingQueried = fs &~ immutableFlags
206207

207-
mutableFlagsBeingQueried.isEmpty || ( // All flags are immutable wrt completion
208-
mutableFlagsBeingQueried <= ConditionallyImmutableFlags.flags && // All the mutable flags being queried are not mutated during completion under certain conditions
209-
ConditionallyImmutableFlags.flagsAndConditions.forall { case (flag, condition) =>
210-
(flag & mutableFlagsBeingQueried).isEmpty || !condition(this)
211-
}
208+
mutableFlagsBeingQueried.isEmpty || (
209+
mutableFlagsBeingQueried <= Deferred && !(is(Opaque) && isType)
212210
)
213211

214212

0 commit comments

Comments
 (0)