Skip to content

Revive function specialization #10452

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 3 commits into from
Nov 25, 2020
Merged

Conversation

liufengyun
Copy link
Contributor

Revive function specialization

Supersede #9846

@liufengyun
Copy link
Contributor Author

liufengyun commented Nov 23, 2020

test performance please: 640886a b80fe59 67dbbfa

@liufengyun
Copy link
Contributor Author

@Duhemm @felixmulder Thanks for your work on function specialization. To keep history simpler, are you OK with squash the commits to 3: one for each author?

@dottybot
Copy link
Member

performance test scheduled for 640886a b80fe59 67dbbfa: 1 job(s) in queue, 0 running.

@Duhemm
Copy link
Contributor

Duhemm commented Nov 23, 2020

@Duhemm @felixmulder Thanks for your work on function specialization. To keep history simpler, are you OK with squash the commits to 3: one for each author?

Thank you for taking this to the finish line! Yes, please squash all my commits the way you feel is the cleanest 👍

@scala scala deleted a comment from dottybot Nov 23, 2020
@dottybot
Copy link
Member

Performance test finished successfully:

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

Benchmarks is based on merging with master (31566b7)

@felixm-stripe
Copy link

Go for it 👍

@liufengyun
Copy link
Contributor Author

@smarter Could you have another look? If you find it OK, I can squash the experiment commits.

Note: from the benchmark result http://dotty-bench.epfl.ch/10452/, the regression in scalap is caused by the code in 1b16557.

@liufengyun liufengyun requested a review from smarter November 24, 2020 09:21
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, thanks for your work on this!

@liufengyun liufengyun force-pushed the fun-spec2 branch 2 times, most recently from 73f6a0b to bee8aa8 Compare November 24, 2020 20:58
felixmulder and others added 3 commits November 25, 2020 07:30
Add phases and initial replacement for super

Replace all existing combinations of Function1 with specialized version

Do transformations on symbol level too

Refactor transformations to be more idiomatic

Add dispatch to specialized applys

Add forwarding method for generic case

Don't specialize Function1 tree when invalid to

Write test to check for specialized apply

Remove `DispatchToSpecializedApply` phase

SpecializeFunction1: don't roll over parents, use mapConserve

Rewrite to handle all specialized functions

Don't remove parents not being specialized

Add plain function tests to NameOps and Definitions

Rewrite `SpecializeFunctions` from `DenotTransformer` to `InfoTransformer`

Add `MiniPhaseTransform` to add specialized methods to FunctionN

Add synthetic bridge when compiling FunctionN

Fix ordering of specialized names and type parameterized apply

Add parent types explicitly when specializing

When a class directly extends a specialized function class, we need to
replace the parent with the specialized interface. In other cases we don't
replace it, even if the parent of a parent has a specialized apply - the
symbols would propagate anyway.

Make `ThisName` recursive on `self.ThisName`

Make sure specialized functions get the correct name
Fix compilation errors

Don't change parents in `specializeFunctions`

Cleanup

Move type to JVM tag conversion to Definitions

Add more tests for function specialization

Pass by name should not introduce boxing

Cleanup

No specialization for Function3

Adapt to recent changes in transformers and phases

Address review comments

Optimize phase `SpecializeFunctions`

 - Stop immediately if the type doesn't derive from `Function{0,1,2}`
 - We don't need to check if any of the parents derives from
   `Function{0,1,2}`, we can just check if the type derives from it.
- Fix isPlainFunctionClass

Previous implementation is incorrect, as scala.Function1$ would qualify.

- Create the symbol at the next phase

Create the symbol at the next phase, so that it is a valid member of the
corresponding function for all valid periods of its SymDenotations.
Otherwise, the valid period will offset by 1, which causes a stale symbol
in compiling stdlib.

- Handle abstract apply and multiple applys

- Don't specialize abstract apply

- Fast specialization

We avoid going through InfoTransformer, which will cause all symbols to be checked.
The reason why it works is that the specialized base classes, i.e. Function0-2
already have all the relevant definitions.

- Use StringBuilder instead of StringBuffer (thanks @smarter)

StringBuffer is synchronized thus is slower.
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.

7 participants