Skip to content

Fix overcompilation when inheriting inline defs #9730

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
Oct 20, 2020

Conversation

smarter
Copy link
Member

@smarter smarter commented Sep 4, 2020

When the body of an inline def changes, all its callers need to be
recompiled. So when producing an API signature for an inline def to be
sent to Zinc, we need to somehow include that body. So far, this was
done by simply including the toString of the tree in the API
signature, but the API of a class includes its inherited members, and
when calling toString on an inherited inline def, its body ends up
being printed as just TreeUnpickler$LazyReader@123... which is clearly
not what we want, in practice this lead to overcompilation rather than
undercompilation because the string includes the identityHashCode of the
LazyReader which changes at each compilation run.

This commit fixes this by implementing a proper way to hash trees, this
is still not perfect since types aren't included in the hash (see
comments in the code), but that can be addressed at a later point (and
the exact strategy we want to use also depends on how we evolve Zinc).

@smarter
Copy link
Member Author

smarter commented Sep 4, 2020

test performance please

@dottybot
Copy link
Member

dottybot commented Sep 4, 2020

performance test scheduled: 8 job(s) in queue, 1 running.

@smarter smarter force-pushed the tree-hashing branch 3 times, most recently from 1bd2581 to e73a3f4 Compare September 4, 2020 20:05
@dottybot
Copy link
Member

dottybot commented Sep 4, 2020

Performance test finished successfully:

Visit http://dotty-bench.epfl.ch/9730/ to see the changes.

Benchmarks is based on merging with master (1ab71c1)

@smarter
Copy link
Member Author

smarter commented Sep 4, 2020

Performance test finished successfully:

I just realized that -Yforce-sbt-phases is not enabled in the benchmark suite by default so that performance test won't actually show anything: lampepfl/bench#452

@liufengyun
Copy link
Contributor

test performance with #sbt please

@dottybot
Copy link
Member

dottybot commented Sep 4, 2020

performance test scheduled: 8 job(s) in queue, 1 running.

@smarter
Copy link
Member Author

smarter commented Sep 4, 2020

@liufengyun If I understand lampepfl/bench#452 correctly I think we need to test two commits with sbt (master and this PR) otherwise there's going to be some missing points right?

@liufengyun
Copy link
Contributor

test performance with #sbt please: 1ab71c1 d79a1ba

@dottybot
Copy link
Member

dottybot commented Sep 4, 2020

performance test scheduled for 1ab71c1 d79a1ba: 8 job(s) in queue, 1 running.

@dottybot
Copy link
Member

dottybot commented Sep 5, 2020

Performance test finished successfully:

Visit http://dotty-bench.epfl.ch/9730/ to see the changes.

Benchmarks is based on merging with master (1ab71c1)

@bishabosha
Copy link
Member

test performance with #sbt please: 1ab71c1 d79a1ba

@dottybot
Copy link
Member

dottybot commented Sep 7, 2020

performance test scheduled for 1ab71c1 d79a1ba: 4 job(s) in queue, 1 running.

@dottybot
Copy link
Member

dottybot commented Sep 7, 2020

Performance test finished successfully:

Visit http://dotty-bench.epfl.ch/9730/ to see the changes.

Benchmarks is based on merging with master (d11e137)

@bishabosha
Copy link
Member

second test seems to be better performance?

@odersky
Copy link
Contributor

odersky commented Sep 11, 2020

second test seems to be better performance?

I think that's plausible. Computing a tree hash looks faster than converting the tree to a string.

@odersky odersky assigned smarter and unassigned odersky Sep 11, 2020
@smarter smarter assigned bishabosha and unassigned smarter Sep 18, 2020
@smarter smarter added this to the 3.0.0-M1 milestone Sep 28, 2020
@bishabosha bishabosha assigned smarter and unassigned bishabosha Oct 15, 2020
@smarter smarter assigned bishabosha and unassigned smarter Oct 16, 2020
When the body of an inline def changes, all its callers need to be
recompiled. So when producing an API signature for an inline def to be
sent to Zinc, we need to somehow include that body. So far, this was
done by simply including the `toString` of the tree in the API
signature, but the API of a class includes its inherited members, and
when calling `toString` on an inherited inline def, its body ends up
being printed as just `TreeUnpickler$LazyReader@123...` which is clearly
not what we want, in practice this lead to overcompilation rather than
undercompilation because the string includes the identityHashCode of the
LazyReader which changes at each compilation run.

This commit fixes this by implementing a proper way to hash trees, this
is still not perfect since types aren't included in the hash (see
comments in the code), but that can be addressed at a later point (and
the exact strategy we want to use also depends on how we evolve Zinc).
Previously they were warnings, which means we could miss them in the CI.
After the previous commit which turned some warnings into errors, some
tests like tests/pos/tasty-tags-obscure.scala started failing which
revealed the problem. We need to use a custom marker to handle them
because it turns out that zinc upstream doesn't handle them either even
though they're a part of Scala 2 too!
Copy link
Member

@bishabosha bishabosha left a comment

Choose a reason for hiding this comment

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

looks good to me

@smarter smarter merged commit a79145d into scala:master Oct 20, 2020
@smarter smarter deleted the tree-hashing branch October 20, 2020 17:28
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.

5 participants