-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Topic/info transforms #72
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
Changes from all commits
12679e9
62419a0
6ceeb08
4c20b7e
7b15b38
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package dotty.tools.dotc | ||
package core | ||
|
||
import Periods._ | ||
import SymDenotations._ | ||
import Contexts._ | ||
import Types._ | ||
import Denotations._ | ||
import Phases._ | ||
import java.lang.AssertionError | ||
import dotty.tools.dotc.util.DotClass | ||
|
||
object DenotTransformers { | ||
|
||
/** A transformer group contains a sequence of transformers, | ||
* ordered by the phase where they apply. Transformers are added | ||
* to a group via `install`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This documentation is outdated. |
||
*/ | ||
|
||
/** A transformer transforms denotations at a given phase */ | ||
trait DenotTransformer extends Phase { | ||
|
||
/** The last phase during which the transformed denotations are valid */ | ||
def lastPhaseId(implicit ctx: Context) = ctx.nextTransformerId(id + 1) | ||
|
||
/** The validity period of the transformer in the given context */ | ||
def validFor(implicit ctx: Context): Period = | ||
Period(ctx.runId, id, lastPhaseId) | ||
|
||
/** The transformation method */ | ||
def transform(ref: SingleDenotation)(implicit ctx: Context): SingleDenotation | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ import Symbols._ | |
import Types._ | ||
import Periods._ | ||
import Flags._ | ||
import Transformers._ | ||
import DenotTransformers._ | ||
import Decorators._ | ||
import transform.Erasure | ||
import printing.Texts._ | ||
|
@@ -192,6 +192,9 @@ object Denotations { | |
def requiredValue(name: PreName)(implicit ctx: Context): TermSymbol = | ||
info.member(name.toTermName).requiredSymbol(_.info.isParameterless).asTerm | ||
|
||
def requiredClass(name: PreName)(implicit ctx: Context): ClassSymbol = | ||
info.member(name.toTypeName).requiredSymbol(_.isClass).asClass | ||
|
||
/** The denotation that has a type matching `targetType` when seen | ||
* as a member of type `site`, `NoDenotation` if none exists. | ||
*/ | ||
|
@@ -387,7 +390,6 @@ object Denotations { | |
if ((symbol eq this.symbol) && (info eq this.info)) this | ||
else newLikeThis(symbol, info) | ||
|
||
|
||
def orElse(that: => SingleDenotation) = if (this.exists) this else that | ||
|
||
def altsWith(p: Symbol => Boolean): List[SingleDenotation] = | ||
|
@@ -515,8 +517,8 @@ object Denotations { | |
} else { | ||
// not found, cur points to highest existing variant | ||
var startPid = cur.validFor.lastPhaseId + 1 | ||
val transformers = ctx.transformersFor(cur) | ||
val transformer = transformers.nextTransformer(startPid) | ||
val transformer = ctx.phases(startPid - 1).asInstanceOf[DenotTransformer] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If first phase doesn't implement DenotTransformer this line throws exception |
||
//println(s"transforming with $transformer") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lingering debug statement There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd say leave it in, it's still relatively new code, so we might want to resurrect it at some point. |
||
next = transformer.transform(cur).syncWithParents | ||
if (next eq cur) | ||
startPid = cur.validFor.firstPhaseId | ||
|
@@ -525,20 +527,23 @@ object Denotations { | |
case next: ClassDenotation => next.resetFlag(Frozen) | ||
case _ => | ||
} | ||
next.nextInRun = cur.nextInRun | ||
cur.nextInRun = next | ||
cur = next | ||
} | ||
cur.validFor = Period( | ||
currentPeriod.runId, startPid, transformer.lastPhaseId) | ||
//println(s"new denot: $cur, valid for ${cur.validFor}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lingering debug |
||
} | ||
} else { | ||
// currentPeriod < valid; in this case a version must exist | ||
// currentPeriod < end of valid; in this case a version must exist | ||
// but to be defensive we check for infinite loop anyway | ||
var cnt = 0 | ||
while (!(cur.validFor contains currentPeriod)) { | ||
//println(s"searching: $cur at $currentPeriod, valid for ${cur.validFor}") | ||
cur = cur.nextInRun | ||
cnt += 1 | ||
assert(cnt <= MaxPossiblePhaseId, "seems to be a loop in Denotations") | ||
assert(cnt <= MaxPossiblePhaseId, s"seems to be a loop in Denotations for $this, currentPeriod = $currentPeriod") | ||
} | ||
} | ||
cur | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love the fact that
changeOwner
is exposed onTree
, rather than onSymbol
. We have some terrible bugs inscalac
whereby speculative typechecking (e.g names/defaults) changes the owner of a symbol before bailing out, which breaks the immutability ofTrees
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this work? Does this create new symbols for deftrees whose owners need to be changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I found: https://github.com/odersky/dotty/blob/topic/info-transforms/src/dotty/tools/dotc/ast/tpd.scala#L350