Skip to content

Fix phase of context for denotation transformer #89

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 1 commit into from
Mar 24, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 7 additions & 2 deletions src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ object Contexts {
final def withMode(mode: Mode): Context =
if (mode != this.mode) fresh.withNewMode(mode) else this

def withPhase(phase: PhaseId): Context =
if (this.phaseId == phaseId) this else fresh.withPhase(phase)
def withPhase(phase: Phase): Context =
withPhase(phase.id)

final def addMode(mode: Mode): Context = withMode(this.mode | mode)
final def maskMode(mode: Mode): Context = withMode(this.mode & mode)
final def retractMode(mode: Mode): Context = withMode(this.mode &~ mode)
Expand Down Expand Up @@ -324,8 +329,8 @@ object Contexts {

def withProperty(prop: (String, Any)): this.type = withMoreProperties(moreProperties + prop)

def withPhase(pid: PhaseId): this.type = withPeriod(Period(runId, pid))
def withPhase(phase: Phase): this.type = withPhase(phase.id)
override def withPhase(pid: PhaseId): this.type = withPeriod(Period(runId, pid))
override def withPhase(phase: Phase): this.type = withPhase(phase.id)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why would you want to override this? IIUC the superclass implementation does the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. The second withPhase(phase: Phase) in class FreshContext can be deleted.

Copy link
Contributor

Choose a reason for hiding this comment

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

This override is required, as otherwise returning type will be Context, and not FreshContext.

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed. But that means, and I just realize that, that withPhase mutates the underlying object depending on its runtime type. @odersky I think this is a very bad idea. The methods should have a different name. (IMHO, the with methods of FreshContext should rather be called set)


def withSetting[T](setting: Setting[T], value: T): this.type =
withSettings(setting.updateIn(sstate, value))
Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ object Denotations {
val transformer = ctx.denotTransformers(nextTranformerId)
//println(s"transforming with $transformer")
if (currentPeriod.lastPhaseId > transformer.id)
next = transformer.transform(cur).syncWithParents
next = transformer.transform(cur)(ctx.withPhase(startPid)).syncWithParents
if (next eq cur)
startPid = cur.validFor.firstPhaseId
else {
Expand Down