-
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
Fix #5054: Remove the dead code generated by the Labeled-based pattern matcher #5056
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! ☀️
def test(s: String): Int =
matchResult1[Int]:
{
case val x1: String = s
if "Hello".==(x1) then return[matchResult1] 1 else ()
return[matchResult1] 2
} I see that you added a special case in the backend to not generate code if the else part if the Also I think it would be good to add a bytecode test, that make sure that no @Test def labeledBlock = {
val source =
"""class Test {
| def test(s: String) = s match {
| case "Hello" => 1
| case _ => 2
| }
|}
""".stripMargin
checkBCode(source) { dir =>
val clsIn = dir.lookupName("Test.class", directory = false)
val clsNode = loadClassNode(clsIn.input)
val method = getMethod(clsNode, "test")
val throwMatchError = instructionsFromMethod(method).exists {
case Op(Opcodes.ATHROW) => true
case _ => false
}
assertFalse(throwMatchError)
}
} |
I'm afraid not. dotty internals do not like that. In dotty a |
I have added the test, thanks! As well as a few other tests for switches. |
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.
LGTM. Although, this would benefit from some documentation.
You should push your backend changes to sharing-backend
and update the submodule to track the new HEAD
@@ -597,6 +603,16 @@ object PatternMatcher { | |||
plan | |||
} | |||
} | |||
override def apply(plan: SeqPlan): Plan = { |
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.
You should update the doc comment of def inlineVars
saying that it drops unreachable branch as well
If the head of a `SeqPlan` cannot fall through, the tail is unreachable and can be removed.
…hes. This removes the last nop's generating by the `Labeled`-based pattern matcher.
* Switch with alternatives * Switch with guards * No `throw` in a match with `case _ =>`
7baec35
to
6e08649
Compare
Updated. Rebased on master and addressed @allanrenucci's comments. |
After this PR, the tree after patmat is
and the bytecode is
The only difference wrt. the previous implementation is now the useless
goto 19
at offset 16. But that should be trivial for a peephole optimizer to get rid of.