-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Implement SIP-61 @unroll
annotation
#21693
base: main
Are you sure you want to change the base?
Conversation
@bishabosha some high level comments:
|
Right, I should have noted that the abstract method support should have been dropped - now it is, I will push further commits with more invalidation checks, and see if trait constructor unroll can work |
@lihaoyi there isn't a way to support trait constructor parameters that isn't a rewrite that a user could do manually, so I think this is unexplored territory - e.g. providing default implementations in bytecode for param accessors of traits All the other concerns were addressed in above commits |
Sounds good, let's skip trait params for now. Anyone from the Scala 3 side able to review the code itself and the integration into the scala 3 codebase? |
one implication I guess is that someone might not plan to use or we put in documentation to pre-introduce |
I think forcing At least as currently designed, if code can override an So for For |
CC @lrytz since you're the manager, not sure if you should be reviewing this? |
@Gedochao I thought experimental stuff can go in a patch? - I guess the tasty peculiarity - but that will have experimental flag in the tasty if used |
Ah, if it's behind a flag then it's fine, my bad. |
@Gedochao I added the label back - this would not be correct to backport to 3.5.2 (no block at the tasty level), so it should be in 3.6.0 minimum |
631a6bb
to
4868397
Compare
Just added in the documentation |
I added commit b1c2ec0 which removes the TASTy hack. The commit changes the way forwarders are generated - i.e. they all call the original unrolled method, (rather than "telescoping" and calling the next invisible forwarder). Since we no longer need to resolve calls to Invisible methods, the TASTy hack is no longer needed |
b0ece26
to
aec0618
Compare
6d1fffa
to
a6b757c
Compare
I was talking to @sjrd today, and there is still a problem with |
How about if we leave the synthetic overloads visible. They're meant to be equivalent semantically - it should not matter which one ends up getting called. That's the current manual status quo and it works well enough. |
That would definitely have user-visible consequences. For starters, type inference gets worse as soon as a method has overloads: you don't get expected types, so you don't get lambda param type inference, and implicit conversions may be inserted later or sooner than otherwise. If we need to go that far, it's a language design change compared to the SIP, so we need to go back there. But I don't think we need to do that; if |
A new flag sounds reasonable if it's possible on the implementation side |
b012eee
to
760d3b0
Compare
I added a test in ae4ceba that fails to resolve a forwarder when inlining a transparent inline method, then I fixed the test by introducing a new flag perhaps we can fold the behaviour of |
c42c684
to
ddb9c5a
Compare
Green ci again |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! I didn't look at transform/UnrollDefinitions.scala
in detail.
Is there anything that should be done in MiMa, or in tasty-mima?
tests/run/unroll-traitMethod-integration/UnrollTestPlatformSpecific_3.scala
Outdated
Show resolved
Hide resolved
I'll work on the feedback tonight |
377dde3
to
9cd5b5d
Compare
I've added in b894262 support for If this is acceptable, should it be lifted to a separate PR? |
b894262
to
297c88c
Compare
@lrytz All comments addressed - CI green |
@bishabosha we'll discuss this on this week's Scala Core |
This is planned to be included in 3.7.0. |
@bishabosha ping on that question |
for MiMa, the forwarders should look like ordinary scala methods (except with invisible flag), and will be present in TASTy/bytecode as usual. For tasty-mima - there is the new semantic of the |
I don't think we need anything in tasty-mima. tasty-query ignores the |
@bishabosha Is the git history relevant? Or should it all be squashed to help future |
there is perhaps 3-commit split - the initial commit which is copy-paste the com-lihaoyi/unroll code, commit 2 which is "the rest of the work" and perhaps a third commit which adds the vulpix directive parsing stuff |
I'll let you decompose as you see fit. Then we can merge. |
also copy tests as sbt-scripted tests. Co-authored-by: Jamie Thompson <[email protected]> Co-authored-by: Li Haoyi <[email protected]>
- add documentation page - move before pickling, fix errors due to unpickling select of Invisible definitions and incorrect spans - forwarders now only call the original method. - detect in posttyper which compilation units have unrolled definitions - detect clashes with forwarders and existing definitions - check for illegal uses of @unroll - implementation restriction: no unroll for trait parameters - unlink replaced definitions - check for default parameter - fix invalid pattern in generateFromProduct - sbt-test/scripted: fork when running with unmanaged classpaths - update stdlibExperimentalDefinitions.scala - skip reflection test on scala.js - require final methods, remove special treatment of abstract methods - fix order of printing in test - better error when multiple parameter lists with unroll - Move sbt-scripted tests to vulpix suites
- now invisible members are visible in typer when resolving SELECTin from TASTy. - add sbt-test/tasty-compat test to demonstrate when inline method calls forwarder
- add check files for run/unroll tests - refactorings - test clause interleaving and value class
- add basic support for `//> using target.platform jvm|scala-js` in Vulpix. - if the directive is present, filter out files in compilation that dont match the test platform, also add a suffix to the expected check-file name. - duplicate UnrollTestPlatformSpecific files for jvm and scala-js platforms, deleting the reflection code in scala-js version. - remove directives from compilation tests not listened to by vulpix.
3e17e9c
to
2a04670
Compare
@sjrd I squashed the commits |
Still need to write documentation,Documentation is written also
I am doing this work on behalf of @lihaoyi
The main implementation follows com-lihaoyi/unroll but with some changes:
@unroll
annotation is@experimental
@unroll
Underscore
notEmptyTree
in pattern match default caseThere is one main library addition:
scala.annotation.unroll
, i.e. the@unroll
annotation that appears on parameters,commits are a bit of a mess - a lot of churn
Edit: removed changes:
reuse the symbol when generating the "forwarder" of an abstract method.inferoverride
when overriding trait methods that "appear" abstract in source code, but were actually implemented by the unroll annotationdo not add theInvisible
flag to abstract unrolled methods - this means they can actually still be visible in separately compiled compilation units (because unrolling runs before pickler now)Internal annotationscala.annotation.internal.AbstractUnroll
- marker used to indicate that an unrolled abstract method was abstract in source code (unrolling phase actually provides a default implementation) - this enables downstream implementers to avoid the override flag. (Maybe we shouldn't allow this convenience?)Internal annotationscala.annotation.internal.UnrollForwarder
- marker on any generated forwarder - which is used for special casing TASTy pickling of method calls to the forwardersbecause forwarders get theInvisible
flag, this makes them impossible to select from TASTy normally (viaSELECTin
), (invisible def are filtered out "before typer") so I intercept theSelect
trees to beTERMREFdirect
, and then restore them to Select after TASTY. perhaps someone has a better idea, or we could change the resolution rules forInvisible
? or invent a new TASTy node? (I also tried generating aIdent
tree rather than aSelect
, but this had a type error)fixes #21728