Skip to content

Optimize Denotation#current #9578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ object Contexts {
final def runId = period.runId
final def phaseId = period.phaseId

final def lastPhaseId = base.phases.length - 1

/** Does current phase use an erased types interpretation? */
final def erasedTypes = phase.erasedTypes

Expand Down
7 changes: 5 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,10 @@ object Denotations {
this match {
case symd: SymDenotation =>
if (stillValid(symd)) return updateValidity()
if (acceptStale(symd)) return symd.currentSymbol.denot.orElse(symd).updateValidity()
if acceptStale(symd) && symd.initial.validFor.firstPhaseId <= ctx.lastPhaseId then
// New run might have fewer phases than old, so symbol might no longer be
// visible at all. TabCompleteTests have examples where this happens.
return symd.currentSymbol.denot.orElse(symd).updateValidity()
case _ =>
}
if (!symbol.exists) return updateValidity()
Expand Down Expand Up @@ -790,7 +793,7 @@ object Denotations {
//println(s"might need new denot for $cur, valid for ${cur.validFor} at $currentPeriod")
// not found, cur points to highest existing variant
val nextTransformerId = ctx.base.nextDenotTransformerId(cur.validFor.lastPhaseId)
if (currentPeriod.lastPhaseId <= nextTransformerId)
if currentPeriod.lastPhaseId <= nextTransformerId then
cur.validFor = Period(currentPeriod.runId, cur.validFor.firstPhaseId, nextTransformerId)
else
var startPid = nextTransformerId + 1
Expand Down
7 changes: 5 additions & 2 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2351,8 +2351,11 @@ object SymDenotations {
if (denot.isOneOf(ValidForeverFlags) || denot.isRefinementClass || denot.isImport) true
else {
val initial = denot.initial
val firstPhaseId = initial.validFor.firstPhaseId.max(typerPhase.id)
if ((initial ne denot) || ctx.phaseId != firstPhaseId)
val firstPhaseId =
initial.validFor.firstPhaseId.max(typerPhase.id)
if firstPhaseId > ctx.lastPhaseId then
false
else if (initial ne denot) || ctx.phaseId != firstPhaseId then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the phases have changed (e.g., adding or removing some phases in the middle), then the periods of denotations will be incorrect in the new run. Therefore, do we need to invalidate all non-permanent denotations in such cases, as the same phaseId does not mean the same phase?

https://github.com/lampepfl/dotty/blob/64a239f62ce8a9528b3a4e2c52349180629ef570/compiler/src/dotty/tools/repl/ReplCompiler.scala#L34-L39

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that looks like a problem. But can phases change like this in the same compiler instance? In that case I don't see how we can re-use any symbols. So it might be better to just start a new compiler instance in that case.

atPhase(firstPhaseId)(stillValidInOwner(initial))
else
stillValidInOwner(denot)
Expand Down