-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Rust ref pattern #18754
Rust ref pattern #18754
Conversation
341c62f
to
be6ac13
Compare
To do this we: * Let SSA writes target the name inside identifier patterns instead of the pattern itself * Include relevant names in the data flow graph * Add a store step from a identifier patterns with `ref` into the contained name. So we have an edge `ref a` -> `a` that stores in the reference content type.
be6ac13
to
7476aea
Compare
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.
Overall LGTM, some minor things. As we discussed offline, there are a few CFG issues to look into follow-up. Also, remember DCA :-)
@@ -658,7 +662,11 @@ module PatternTrees { | |||
} | |||
|
|||
override predicate succ(AstNode pred, AstNode succ, Completion c) { | |||
// Edge from succesful subpattern to name | |||
super.succ(pred, succ, c) and c.(MatchCompletion).succeeded() |
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.
I think I prefer for this to be more explicit, i.e.
last(this.getPat(), pred, c) and
first(this.getName(), succ) and
c.(MatchCompletion).succeeded()
then we should also change StandardPostOrderTree
to just PostOrderTree
.
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.
True, that is clearer.
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.
DCA doesn't look too happy; probably a bad join somewhere.
I've fixed a very bad cartesian product. DCA went from 😭 to 😐. A few things went up and down by tiny amounts, which I don't think matters. We should be good to merge. |
This PR aims to add support for
ref
in patterns.For a
let
statement these two lines are equivalent:So we'd like their effect to be the same. For a pattern like
Some(ref a)
the introduced variablea
is a reference and should have the content of the matched value stored in the reference content type.The cleanest way to do this is to add a new store edge from
ref a
(identity pattern) ->a
(name) in the data flow graph. But, currently the name nodes in the AST are not really considered everywhere from the CFG to the data flow library.Hence this PR:
ref
into the contained name. So we have an edgeref a
->a
that stores in the reference content type. For identifier patterns without aref
we add a normal value preserving step, that maintains current behavior.Here are some diagrams depicting the change in the CFG.
Example 1
Here there is a new
map
node before themut map
node.Before
After
Example 2
This shows that the PR also makes a change regarding splitting, in that it is no longer done for identifier patterns.
Before
After