-
Notifications
You must be signed in to change notification settings - Fork 326
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
Support pattern matching on constants #3641
Support pattern matching on constants #3641
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.
Awesome! I can't wait to use it 😃
.../runtime/src/main/java/org/enso/interpreter/node/controlflow/caseexpr/LiteralBranchNode.java
Outdated
Show resolved
Hide resolved
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.
Great work in a really fast time!
Object state, | ||
Text target, | ||
@Cached("build()") ToJavaStringNode toJavaStringNode) { | ||
if (textProfile.profile(literal.equals(toJavaStringNode.execute(target)))) |
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.
Converting Text
to String
just to do equals
? I guess we could benefit from a switch to TruffleStrings then and use EqualsNode which would compare the values without converting to String
.
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.
Yeah, this is the only ugly part in this PR, I admit.
Thanks for the suggestion, I wasn't entirely sure what is the proper way to deal with this.
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.
On the other hand, we use similar technique already with ExpectStringNode
, ExpectTextNode
(and ToJavaStringNode
) in various places.
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.
So I think that with a comparison of normalized strings this is no longer an option.
.../runtime/src/main/java/org/enso/interpreter/node/controlflow/caseexpr/LiteralBranchNode.java
Outdated
Show resolved
Hide resolved
engine/runtime/src/test/scala/org/enso/compiler/test/codegen/AstToIrTest.scala
Show resolved
Hide resolved
b12eaf3
to
2c8c8bb
Compare
This change adds support for matching on constants by: 1) extending parser to allow literals in patterns 2) generate branch node for literals
Added tests for matching on literals that are deeply nested. Turned out the initial setup was wrong but was able to reuse the existing logic. Addressed the first of the comments in PR
Split LiteralBranchNode into comparing strings and numeric values. That way we can ensure that LHS is a String and avoid casting.
2c8c8bb
to
275b43f
Compare
cf00ecc
to
abeccec
Compare
Pull Request Description
This change adds support for matching on constants by:
Related to https://www.pivotaltracker.com/story/show/182743559
Checklist
Please include the following checklist in your PR:
Scala,
Java,
and
Rust
style guides.
./run ide build
and./run ide watch
.