-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #4939: Add rewrite type match
construct.
#4962
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
Conversation
# Conflicts: # tests/run/TupleImpl.scala
We should print the type symbol, not the class symbol, as otherwise abstract and alias types that are annotated with @showAsInline do not print correctly.
A PoC how generic tuples can be implemented - no limit of 22 - generic operations are possible - fully backwards compatible with Scala-2 tuples - specializes for small tuple sizes, yielding optimized code
... to reflect the fact that empty blocks in inline code are now optimized away.
... since they are inlined themselves. Also, fleshed out tuple PoC.
- also, introduce `rewrite` as a modifier for match expressions and conditionals. - keep `transparent` for methods that are not erased, and don't inline by themselves, yet can be inlined from rewritten code.
Also implements rewrite matches and rewrite ifs. Keeps transparent as a separate modifier with meaning: "inline if called from a rewrite context".
erased can only override erased, non-erased can only override non-erased.
These types are injected as parents of Tuple1,...,Tuple22, but are eliminated again at erasure. To support them properly before full dotty bootstrap we needed a @`rewrite` annotation that erases the annotated method (unlike `@forceInline`, which generates code).
And replace Tuple.scala with a Scala 2 implementation and a Scala 3 implementation. The Scala 2 implementaion of Tuple.scala is not strictly necessary but could be useful if non-version-specific library sources end up referencing scala.Tuple.
Erased code does not keep full Inlined trees. The previous version converted the Inlined tree back to the call, but this can expose leaks (since calls are not traversed for references). We now keep the Inlined node, so that its call part can be subsequently simplified.
With the Scala 2/3 split, we don't need it anymore.
Does not rely anymore on `deep`, which is dropped in Scala 2.14.
Was erased to Object before, but this loses precision and breaks binary compatibility with Scala 2.
Currently, this is not exploited but some rewrites might become more effective that way in the future.
There's a difference to be made between projections of instance creations in a preceding val on the one hand and instance creations in a def or directly written creations on the other hand.
Currently only unapplys that return a tuple are supported.
- no nested rewrites - calls to rewrite unapplys only in rewrite code
This is a first attempt to allow matching directly on types.
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.
Hello, and thank you for opening this PR! 🎉
All contributors have signed the CLA, thank you! ❤️
Commit Messages
We want to keep history, but for that to actually be useful we have
some rules on how to format our commit messages (relevant xkcd).
Please stick to these guidelines for commit messages:
- Separate subject from body with a blank line
- When fixing an issue, start your commit message with
Fix #<ISSUE-NBR>:
- Limit the subject line to 72 characters
- Capitalize the subject line
- Do not end the subject line with a period
- Use the imperative mood in the subject line ("Add" instead of "Added")
- Wrap the body at 80 characters
- Use the body to explain what and why vs. how
adapted from https://chris.beams.io/posts/git-commit
Have an awesome day! ☀️
rewrite type match
construct.rewrite type match
construct.
(Changed the title, guess this fixes #4939 not #4949). |
This is based on #4938. Only the last two commits are new.
I am not quite sure about this one yet. I think #4940 is more important, so I would put this one on hold until #4940 is decided.