Rust: Improve CFG for let expressions#18007
Conversation
|
Do we want to support this? Using When I was looking at CFG inconsistencies in the projects we have on DCA the Rust compiler was the only project using this syntax. |
Oh, I had no idea that this was experimental. Given the simplicity of supporting it, I think we should do it. |
The Rust compiler complains about it by default. There's an issue tracking the feature here. But yes, if it is simple then it won't hurt to support. And it should fix quite a few CFG inconsistencies on the Rust compiler. |
5478237 to
74b5ebe
Compare
| false | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Here's another example that I think results in a dead-end. As far as I recall, when I looked at the Rust code base, this pattern of starting with let and then having some conditions was by far the most common.
| fn test_and_if_let3(a: bool, b: Option<i64>, c: bool) -> bool { | |
| if let Some(d) = b && c && c { | |
| d > 0 | |
| } else { | |
| false | |
| } | |
| } | |
There was a problem hiding this comment.
Let's perhaps do that in a follow-up PR?
There was a problem hiding this comment.
I don't think there's much value in adding partial support for let expressions without handling that (most common) case as well.
Is that change orthogonal to the one in this PR? If yes, then doing it in a follow up PR seems fine, otherwise I think I'd be easier to review the changes together.
There was a problem hiding this comment.
Yes, it's orthogonal to this PR; this PR merely improves CFG splitting a bit (see example in the PR description).
| } | ||
|
|
||
| fn test_and_if_let2(a: bool, b: i64, c: bool) -> bool { | ||
| if a && let d = b && c{ |
There was a problem hiding this comment.
| if a && let d = b && c{ | |
| if a && let d = b && c { |
Example:
CFG before:
CFG after: