Skip to content
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

Keep language imports around longer #14364

Merged
merged 4 commits into from
Jan 28, 2022
Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Jan 26, 2022

Some phases might need to know what language imports are active. Concretely, under
explicit nulls, the exhaustivity checks for patterns need to know that. We therefore
keep language imports until phase PruneErasedDefs. Other imports are dropped in
FirstTransform, as before.

The handling of statements in MegaPhase was changed so that imports now are visible
in the context for transforming the following statements.

Update: Now, MacroTransform has the same changes, and in fact all of MegaPhase, MacroTransform and TreeMapWithImplicits use the same inline method for treating statement lists.

Fixes #14346

Some phases might need to know what language imports are active. Concretely, uner
explicit nulls, the exhaustivity checks for patterns need to know that. We therefore
keep language imports until phase PruneErasedDefs. Other imports are dropped in
FirstTransform, as before.

The handling of statements in MegaPhase was changed so that imports now are visible
in the context for transforming the following statements.

Fixes scala#14346
@odersky
Copy link
Contributor Author

odersky commented Jan 26, 2022

test performance please

@dottybot
Copy link
Member

performance test scheduled: 4 job(s) in queue, 1 running.

@dottybot
Copy link
Member

Performance test finished successfully:

Visit https://dotty-bench.epfl.ch/14364/ to see the changes.

Benchmarks is based on merging with master (8ae2962)

@odersky
Copy link
Contributor Author

odersky commented Jan 27, 2022

test performance please

@dottybot
Copy link
Member

performance test scheduled: 2 job(s) in queue, 1 running.

compiler/src/dotty/tools/dotc/transform/MegaPhase.scala Outdated Show resolved Hide resolved
@@ -54,10 +56,18 @@ class PruneErasedDefs extends MiniPhase with SymTransformer { thisTransform =>
checkErasedInExperimental(tree.symbol)
tree

override def transformOther(tree: Tree)(using Context): Tree = tree match
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought about making a separate miniphase for this but it's probably not worth the overhead of boilerplate. If we want to move the dropping of imports, we can easily split it out into a separate miniphase later.

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 was my thinking also.

@dottybot
Copy link
Member

Performance test finished successfully:

Visit https://dotty-bench.epfl.ch/14364/ to see the changes.

Benchmarks is based on merging with master (8ae2962)

Copy link
Member

@noti0na1 noti0na1 left a comment

Choose a reason for hiding this comment

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

LGTM, I tested #13976 based on this PR, and it works without sticky-key .

def transformStat(stat: Tree)(using Context): Tree = stat match {
case _: Import | _: DefTree => transformTree(stat, start)
case Thicket(stats) => cpy.Thicket(stat)(stats.mapConserve(transformStat))
case _ => transformTree(stat, start)(using ctx.exprContext(stat, exprOwner))
}

def restContext(tree: Tree)(using Context): Context = tree match
Copy link
Member

Choose a reason for hiding this comment

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

Could we add this for MacroTransform as well? I need the import information in PostTyper to fix #14319.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, let's do that.

Todo: We have very similar and involved operations now sor handling statements
in tpd.TreeMapWithPreciseStatContexts and MegaPhase. Can we factor out the common logic?
But we should not create any closures doing so, to keep things fast.
Use a single "mapStatements" implementation in three TreeMapWithImplicits,
MacroTransform, and MegaPhase.
@odersky
Copy link
Contributor Author

odersky commented Jan 28, 2022

test performance please

@dottybot
Copy link
Member

performance test scheduled: 1 job(s) in queue, 0 running.

@dottybot
Copy link
Member

Performance test finished successfully:

Visit https://dotty-bench.epfl.ch/14364/ to see the changes.

Benchmarks is based on merging with master (f955f8b)

Copy link
Contributor

@olhotak olhotak left a comment

Choose a reason for hiding this comment

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

LGTM

@odersky odersky merged commit d871d35 into scala:master Jan 28, 2022
@odersky odersky deleted the fix-14346 branch January 28, 2022 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

make language imports available after Typer
4 participants