Skip to content

Fix #2964: Refresh names for anonymous classes #2999

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 7 commits into from
Sep 5, 2017

Conversation

nicolasstucki
Copy link
Contributor

No description provided.


override def phaseName = "liftedClasses"

override def runsAfterGroupsOf: Set[Class[_ <: Phases.Phase]] = Set(classOf[Flatten])
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not really flatten, but RestoreScopes.

@@ -16,6 +17,8 @@ class TransformWildcards extends MiniPhaseTransform with IdentityDenotTransforme

override def phaseName = "transformWildcards"

override def runsAfter: Set[Class[_ <: Phases.Phase]] = Set(classOf[LiftedClasses])
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is there a dependency between those two phases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only checked experimentally. It failed if I put it afterward, therefore I added the explicit runsAfter to make this evident to anyone that tries to reorder phases.

else tree

private def needsRefresh(sym: Symbol)(implicit ctx: Context): Boolean =
sym.isClass && !sym.is(Package) && sym.name.is(UniqueName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have packages with UniqueName?

Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you apply it only to classes, don't we have the same issue with methods that are lifted out?

Copy link
Contributor

Choose a reason for hiding this comment

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

class Foo {
  def ann = {
    def foo() = 1;
  }
}
class Bar {
  def ann = {
    def foo() = 1;
  }
}
public class Foo {
    public void ann() {
    }

    private static int foo$1() {
        return 1;
    }
}

public class Bar {
    public void ann() {
    }

    private static int foo$2() { // <---  same issue
        return 1;
    }
}

/** Renames lifted classes to local numbering scheme */
class LiftedClasses extends MiniPhaseTransform with SymTransformer { thisTransformer =>

override def phaseName = "liftedClasses"
Copy link
Contributor

Choose a reason for hiding this comment

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

renameLifted?

@nicolasstucki
Copy link
Contributor Author

@DarkDimius the requested changes have been made.


/** Refreshes the number of the name based on the full name of the symbol */
private def refreshedName(sym: Symbol)(implicit ctx: Context): Name = {
lazy val rewriteUnique: PartialFunction[Name, Name] = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why lazy?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see, that's a funny way to write recursion 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you know a cleaner way to define recursive partial functions?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would do it with a def

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed it. Though now it will create a new instance of the function each iteration, I guess this should not happen too often.

Copy link
Contributor

@OlivierBlanvillain OlivierBlanvillain left a comment

Choose a reason for hiding this comment

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

LGTM!

@allanrenucci allanrenucci merged commit a0d703b into scala:master Sep 5, 2017
@allanrenucci allanrenucci deleted the fix-#2964 branch December 14, 2017 19:18
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.

4 participants