Skip to content

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

Merged
merged 10 commits into from
Apr 28, 2017

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Apr 20, 2017

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:

ByNameClosures
HoistSuperArgs
ElimByName

@@ -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
Copy link
Contributor

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.

@DarkDimius
Copy link
Contributor

Drop InSuperCall flag

This PR is awesome!

@odersky odersky changed the title [WIP] Rework ElimByName Rework ElimByName and combine with new phase HoistSuperArgs Apr 21, 2017
@DarkDimius DarkDimius self-assigned this Apr 26, 2017
Copy link
Contributor

@DarkDimius DarkDimius left a 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) */
Copy link
Contributor

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) =
Copy link
Contributor

Choose a reason for hiding this comment

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

can be private

Copy link
Contributor Author

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))
Copy link
Contributor

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)
Copy link
Contributor

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?

odersky added 10 commits April 28, 2017 15:51
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.
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.

2 participants