-
Notifications
You must be signed in to change notification settings - Fork 1.1k
#9268 Port genMatch from scala-js/GenJSCode (WIP, do not merge) #9297
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
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! ☀️
|
||
val defaultLabelSym = cases | ||
.collectFirst { | ||
case CaseDef(Ident(nme.WILDCARD), EmptyTree, body @ Labeled(_, rhs)) |
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.
As I said on the issue. You can scrap everything that takes care of Labeled
things. In scalac we have to reverse-engineer LabelDef
definitions and jumps to them, but not in Dotty, because the Labeled
blocks are correctly compiled to the Scala.js IR once and for all in case Labeled(bind, expr) =>
.
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.
Thanks for the explanation, but I'm still too much of a newbie to understand what exactly I can remove. Is there any documentation about this?
Can I remove the whole defaultLabelSym
value? What shall I do where it is used, e.g.
case app @ Apply(_, Nil) if app.symbol == defaultLabelSym =>
genJumpToElseClause
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.
Yes, you can remove it. Basically you can consider that defaultLabelSym
is always NoSymbol
. That means that if app.symbol == defaultLabelSym
is basically if false
, and that consequently you can remove that case
entirely.
From there, you'll figure that genJumpToElseClause
is dead code, and hence optElseClauseLabel
will never be assigned to a Some
. You can therefore replace it by None
and remove dead code from there as well.
The domino effect of this strategy will cause a lot of code to be removed.
val op = | ||
if (isInt(genSelector) && isInt(uniqueAlt)) js.BinaryOp.Int_== | ||
else js.BinaryOp.=== |
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.
This is what would cause a ===
to be emitted instead of the correct Int_==
. The ===
case should be used only when we are switching on String
s (including null
values). In scalac, patmat makes sure that only primitive Int
s or java.lang.String
s can be left in Match
and leave the back-end. That test therefore uses ===
only for strings in scalac. Apparently in dotty other kinds of numeric types survive here, like Char
s. Either the back-end should convert them to ints, or PatMat should convert them to Ints.
In any case, here we should end up using ===
only for String
s and null
. Everything should use Int_==
.
It turns out the issues raised by this PR come from the fact that the pattern matcher does not force switch matches to operate on Ints. Instead it can leave (a mix of) Chars, Bytes, Shorts and Ints. scalac does force switch matches coming out of the PatMat phase to operate on Ints, potentially adapting the scrutinee and alternatives to Int. I have submitted an alternative PR #9411 that deals with this problem. |
Closing since #9411 got merged. |
This is a copy of the
genMatch
method and its dependencies fromGenJSCode
with minor modifications to make it compile.Some remarks / open issues:
genMatchEnd
method (https://github.com/devkat/dotty/blob/scalajs-tests/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala#L3559) used to take aLabelDef
which has params. I have no idea how to handle this withLabeled
(see FIXME on line 3572).var
etc.) since I'm not familiar enough with the coding guidelines yet and I don't know how much optimization already went into the code.