-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand non-transparent macros after Typer #9984
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
Expand non-transparent macros after Typer #9984
Conversation
af0ed15
to
4da92f1
Compare
1a94a4c
to
f1afb7c
Compare
f42cdcc
to
8043ce0
Compare
8043ce0
to
64e5eab
Compare
64e5eab
to
6535013
Compare
9954554
to
3b874d9
Compare
4199f34
to
0c61b36
Compare
performance test scheduled: 9 job(s) in queue, 1 running. |
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.
Can we try without overriding typer and test performance again?
@@ -272,6 +276,8 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase | |||
checkNoConstructorProxy(tree) | |||
transformSelect(tree, Nil) | |||
case tree: Apply => | |||
if tree.symbol.is(Inline) && !Inliner.inInlineMethod then |
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.
Why is this needed here? Don't we get to an Ident or Select eventually, which sets needsInlining
. Also, why do we handle Apply
here but not TypeApply
. If this is in fact needed for some reason it would be good to add a comment.
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.
It is redundant. I removed it.
@@ -329,6 +338,8 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase | |||
) | |||
} | |||
case tree: ValDef => | |||
if tree.symbol.is(Inline, butNot = Param) then |
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.
Would this be triggered by
inline val x = 2
? Those things are extremely common, so we should avoid running the inliner just for these.
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.
Yes, then we would need to check that the RHS of an inline val
is a constant after the Inlining
phase. I try to fit it into another phase.
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.
That would cause many more traversals, so yes, good to do this somewhere else.
@@ -1235,8 +1254,14 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) { | |||
super.ensureAccessible(tpe, superAccess, pos) | |||
} | |||
|
|||
override def typed(tree: untpd.Tree, pt: Type = WildcardType)(using Context): Tree = |
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.
In fact, it might be better to do this test only in typedApply and typedTypeApply. Concentrating everything in typed
is more elegant but might have performance implications. I am also nervous about making calls to typed
more megamorphic.
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 moved the logic back to typedApply
, typedTypeApply
, typedIdent
and typedSelect
. I kept the rest of the refactoring which avoids the duplication of the code that is now in needsInlining
.
Performance test finished successfully: Visit http://dotty-bench.epfl.ch/9984/ to see the changes. Benchmarks is based on merging with master (a63b1d1) |
test performance with #quotes please |
performance test scheduled: 1 job(s) in queue, 0 running. |
Performance test finished successfully: Visit http://dotty-bench.epfl.ch/9984/ to see the changes. Benchmarks is based on merging with master (16bf86f) |
Those are checked by the Ident or Select of their function parts
To avoid running the phase
981defd
to
bdf2482
Compare
@liufengyun could you have a look at the new commits? |
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.
LGTM
@nicolasstucki It seems like this is working for me out of the box! I don't need to modify anything. Say I make a typing mistake on purpose: inline def q = quote {
query[SanePerson] // hello
}
inline def name(p: SanePerson) = p.name
inline def qq = quote {
q.map(p => name(p.name)) // purposely making a typing mistake
} Why does the macro even run if there was an error on a previous phase? |
The technical change
transparent inline
definitions in typerinline
after typer.Sematic changes
inline given
transparent inline given f: T = ...
: does the same as all inline definition did beforetransparent inline given f: T = (...): T
can be used to emulate the previous versioninline given
inline given f: T = ...
: if an error is emitted during the inlining then the error is reported to the user.scala.compiletime.testing.{typeChecks, typeCheckErrors}
must be used directly or inside atransparent inline