-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Rework ElimByName and combine with new phase HoistSuperArgs #2282
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
Conversation
tests/neg/tailcall/t1672b.scala
Outdated
@@ -46,7 +46,7 @@ object Test1772B { | |||
else 1 + (try { | |||
throw new RuntimeException | |||
} catch { | |||
case _: Throwable => bar(i - 1) // old-error | |||
case _: Throwable => bar(i - 1) // error |
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 was this test affected? It doesn't seem to have anything to do with by-name changes.
This PR is awesome! |
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.
Minor suggestions, otherwise LGTM.
abstract class TransformByNameApply extends MiniPhaseTransform { thisTransformer: DenotTransformer => | ||
import ast.tpd._ | ||
|
||
/** The info of the tree's symbol at phase Nullarify (i.e. before transformation) */ |
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.
nullarify phase doesn't exist anymore
tree.symbol.denot(ctx.withPhase(thisTransformer)) | ||
|
||
/** If denotation had an ExprType before, it now gets a function type */ | ||
protected def exprBecomesFunction(symd: SymDenotation)(implicit ctx: Context) = |
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 be private
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.
No it's used in elimByName
|
||
override def mkClosure(arg: Tree, argType: Type)(implicit ctx: Context): Tree = { | ||
val meth = ctx.newSymbol( | ||
ctx.owner, nme.ANON_FUN, Synthetic | Method, MethodType(Nil, Nil, argType)) |
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'd prefer to give it more informative name that indicates that it originated from by-name param.
Helps when reading bytecode.
case tp: NamedType | ||
if (tp.symbol.owner == cls || tp.symbol.owner == constr) && | ||
tp.symbol.is(ParamOrAccessor) => | ||
val mappedSym = origParams.zip(paramSyms).toMap.apply(tp.symbol) |
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.
maybe extract origParams.zip(paramSyms).toMap
to a lazy val inside this TTM?
changeOwner already does this.
- Make it use changeOwnerAfter - Factor out TransformByNameApply as a common base trait between it and ElimByName
Used to fail in backend when reference of closure was to a static method. The test case failing is 2127.scala
Hoist complex supercall arguments out of the class they appear in. This avoids a lot of complexity later on in other transformation phases.
and special handling involved in it. Require the phases that used ti to be after phase HoistInSuperCall instead.
Do the necessary changes to combine HoistSuperArgs and ByNameClosures. Also, polishings.
Also hoist complex arguments out of this-calls of secondary constructors.
2ee4db6
to
b14969c
Compare
We split ElimByName so that we can create the necessary closures before a new phase that hoists supercall arguments out of the call. New sequence of phases: