Skip to content

Fix #2869: Have constructors run after group of Memoize #2870

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 4 commits into from
Jul 15, 2017

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Jul 14, 2017

As explained in the code comment, the two get too entangled otherwise
which leads to parameters being stored as class fields when they should not.

This was the most obvious source of memory leaks in the IDE. Once this is fixed
we can check whether there are others.

@odersky odersky force-pushed the fix-param-captures branch from 8ade44c to 16d0421 Compare July 14, 2017 13:53
@@ -0,0 +1,4 @@
class MT(sf: MT => String) {
// `s` is retained as a field, but `sf` should not be.
Copy link
Member

Choose a reason for hiding this comment

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

To actually test this, I suggest making a run test and using Java reflection like https://github.com/lampepfl/dotty/blob/master/tests/run/paramForwarding.scala#L46

As explained in the code comment, the two get too entangled otherwise
which leads to parameters being stored as class fields when they should not.
@odersky odersky force-pushed the fix-param-captures branch from 16d0421 to c637535 Compare July 14, 2017 15:18
@odersky
Copy link
Contributor Author

odersky commented Jul 14, 2017

@smarter Ready for review once tests have passed.

@odersky odersky changed the title Fix #2859: Avoid unnecessary parameter stores [WIP] Fix #2869: Have constructors run after group of Memoize Jul 14, 2017
// `s` is retained as a field, but `sf` should not be.
val s = sf(this)
}
object Test extends App {
Copy link
Member

@smarter smarter Jul 14, 2017

Choose a reason for hiding this comment

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

I think we've deprecated/discouraged the use of App

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 but I am not sure why? I hate to write all these main methods.

Copy link
Member

Choose a reason for hiding this comment

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

See #559

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am still not sure why we use LegacyApp instead of App now. They seem to be equivalent.

Copy link
Member

Choose a reason for hiding this comment

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

/cc @DarkDimius do you remember why LegacyApp had to be introduced?

It turns out with the fix to Constructors we don't generate the
a value for the intermediate field anymore. This seems great!
(scalac does generate the field, but it looks redundant)
Copy link
Member

@smarter smarter left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM, nice improvement!

// This test is done in the right-hand side of a value definition. If Memoize
// was in the same group as Constructors, the test on the rhs ident would be
// performed before the rhs undergoes the owner change. This would lead
// to more symbls being retained as parameters. Test case is
Copy link
Member

Choose a reason for hiding this comment

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

typo: symbls -> symbols

// performed before the rhs undergoes the owner change. This would lead
// to more symbls being retained as parameters. Test case is
//
// dotc tests/pos/captuing.scala -Xprint:constr
Copy link
Member

Choose a reason for hiding this comment

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

typo: captuing -> capturing

@@ -79,8 +93,7 @@ class Constructors extends MiniPhaseTransform with IdentityDenotTransformer { th
}

override def transformValDef(tree: tpd.ValDef)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = {
if (mightBeDropped(tree.symbol))
(if (isWildcardStarArg(tree.rhs)) retainedPrivateVals else seenPrivateVals) += tree.symbol
Copy link
Member

Choose a reason for hiding this comment

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

Why was this condition dropped?

Copy link
Contributor Author

@odersky odersky Jul 14, 2017

Choose a reason for hiding this comment

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

It is (probably) dead code. The test looks non-sensical to me. I fail to see how a definition of a class member can end up as something like this:

 val xs = y: _*

Even if it did, why would it make a difference? I put in an assert to flag the condition, but it never triggered in all our tests.

@smarter
Copy link
Member

smarter commented Jul 14, 2017

Do we really need to split the group of phases in two? Perhaps we could move Constructors to the next group of phase instead? /cc @DarkDimius

I verified experimentally that LamdaLift and Constructors cannot run in the same group.
@odersky
Copy link
Contributor Author

odersky commented Jul 14, 2017

Do we really need to split the group of phases in two? Perhaps we could move Constructors to the next group of phase instead?

Unfortunately no. See last commit.

@smarter
Copy link
Member

smarter commented Jul 14, 2017

OK. I assume that this will have a non-trivial impact on performance but it should be worth it anyway.

@odersky
Copy link
Contributor Author

odersky commented Jul 14, 2017

I think the win of not having to store all these parameters might well be stronger than the loss of having an extra phase. If we only had benchmarks that worked...

@odersky odersky merged commit b12326c into scala:master Jul 15, 2017
@allanrenucci allanrenucci deleted the fix-param-captures branch December 14, 2017 19:20
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