mir_build: Clarify parts of if-condition lowering - #161861
Conversation
The existing name doesn't give a good intuition for what's actually happening, which is that we lower a (possibly complex) boolean condition and then proceed if it's true or break if it's false. This commit also directly exposes the arguments struct to callers, since it makes the call sites more self-documenting.
This convention is a little less intuitive for simple if-expressions, but is easier to follow when dealing with complex nested conditions or with other if-like constructs.
|
Some changes occurred in match lowering cc @Nadrieril |
|
r? @tiif rustbot has assigned @tiif. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
cc @dianne and @dingxiangfei2009 in case they have opinions on the code being touched here. |
|
That's a huge improvement for me, I also found these bits hard to follow. I also appreciate the comments added. r? me @bors r+ |
mir_build: Clarify parts of if-condition lowering I've been looking at this condition-lowering code a lot, and I noticed that some parts are hard to follow due to how functions and variables are named. In particular, the function name `then_else_break` doesn't give much useful intuition for the fact that it lowers an `if` condition (or similar), and then proceeds if the condition was true or breaks if the condition was false. Similarly, I was finding it hard to keep track of the two destinations selected after evaluating a condition, especially when dealing with complex subconditions like `||` or `!`, or looking at different callers. So this PR tries to establish a convention of always using `(true_block, false_block)` to refer to the condition's outcome paths, which can then be manipulated as appropriate by calling code. There should be no observable change to compiler behaviour.
mir_build: Clarify parts of if-condition lowering I've been looking at this condition-lowering code a lot, and I noticed that some parts are hard to follow due to how functions and variables are named. In particular, the function name `then_else_break` doesn't give much useful intuition for the fact that it lowers an `if` condition (or similar), and then proceeds if the condition was true or breaks if the condition was false. Similarly, I was finding it hard to keep track of the two destinations selected after evaluating a condition, especially when dealing with complex subconditions like `||` or `!`, or looking at different callers. So this PR tries to establish a convention of always using `(true_block, false_block)` to refer to the condition's outcome paths, which can then be manipulated as appropriate by calling code. There should be no observable change to compiler behaviour.
mir_build: Clarify parts of if-condition lowering I've been looking at this condition-lowering code a lot, and I noticed that some parts are hard to follow due to how functions and variables are named. In particular, the function name `then_else_break` doesn't give much useful intuition for the fact that it lowers an `if` condition (or similar), and then proceeds if the condition was true or breaks if the condition was false. Similarly, I was finding it hard to keep track of the two destinations selected after evaluating a condition, especially when dealing with complex subconditions like `||` or `!`, or looking at different callers. So this PR tries to establish a convention of always using `(true_block, false_block)` to refer to the condition's outcome paths, which can then be manipulated as appropriate by calling code. There should be no observable change to compiler behaviour.
mir_build: Clarify parts of if-condition lowering I've been looking at this condition-lowering code a lot, and I noticed that some parts are hard to follow due to how functions and variables are named. In particular, the function name `then_else_break` doesn't give much useful intuition for the fact that it lowers an `if` condition (or similar), and then proceeds if the condition was true or breaks if the condition was false. Similarly, I was finding it hard to keep track of the two destinations selected after evaluating a condition, especially when dealing with complex subconditions like `||` or `!`, or looking at different callers. So this PR tries to establish a convention of always using `(true_block, false_block)` to refer to the condition's outcome paths, which can then be manipulated as appropriate by calling code. There should be no observable change to compiler behaviour.
mir_build: Clarify parts of if-condition lowering I've been looking at this condition-lowering code a lot, and I noticed that some parts are hard to follow due to how functions and variables are named. In particular, the function name `then_else_break` doesn't give much useful intuition for the fact that it lowers an `if` condition (or similar), and then proceeds if the condition was true or breaks if the condition was false. Similarly, I was finding it hard to keep track of the two destinations selected after evaluating a condition, especially when dealing with complex subconditions like `||` or `!`, or looking at different callers. So this PR tries to establish a convention of always using `(true_block, false_block)` to refer to the condition's outcome paths, which can then be manipulated as appropriate by calling code. There should be no observable change to compiler behaviour.
mir_build: Clarify parts of if-condition lowering I've been looking at this condition-lowering code a lot, and I noticed that some parts are hard to follow due to how functions and variables are named. In particular, the function name `then_else_break` doesn't give much useful intuition for the fact that it lowers an `if` condition (or similar), and then proceeds if the condition was true or breaks if the condition was false. Similarly, I was finding it hard to keep track of the two destinations selected after evaluating a condition, especially when dealing with complex subconditions like `||` or `!`, or looking at different callers. So this PR tries to establish a convention of always using `(true_block, false_block)` to refer to the condition's outcome paths, which can then be manipulated as appropriate by calling code. There should be no observable change to compiler behaviour.
mir_build: Clarify parts of if-condition lowering I've been looking at this condition-lowering code a lot, and I noticed that some parts are hard to follow due to how functions and variables are named. In particular, the function name `then_else_break` doesn't give much useful intuition for the fact that it lowers an `if` condition (or similar), and then proceeds if the condition was true or breaks if the condition was false. Similarly, I was finding it hard to keep track of the two destinations selected after evaluating a condition, especially when dealing with complex subconditions like `||` or `!`, or looking at different callers. So this PR tries to establish a convention of always using `(true_block, false_block)` to refer to the condition's outcome paths, which can then be manipulated as appropriate by calling code. There should be no observable change to compiler behaviour.
mir_build: Clarify parts of if-condition lowering I've been looking at this condition-lowering code a lot, and I noticed that some parts are hard to follow due to how functions and variables are named. In particular, the function name `then_else_break` doesn't give much useful intuition for the fact that it lowers an `if` condition (or similar), and then proceeds if the condition was true or breaks if the condition was false. Similarly, I was finding it hard to keep track of the two destinations selected after evaluating a condition, especially when dealing with complex subconditions like `||` or `!`, or looking at different callers. So this PR tries to establish a convention of always using `(true_block, false_block)` to refer to the condition's outcome paths, which can then be manipulated as appropriate by calling code. There should be no observable change to compiler behaviour.
mir_build: Clarify parts of if-condition lowering I've been looking at this condition-lowering code a lot, and I noticed that some parts are hard to follow due to how functions and variables are named. In particular, the function name `then_else_break` doesn't give much useful intuition for the fact that it lowers an `if` condition (or similar), and then proceeds if the condition was true or breaks if the condition was false. Similarly, I was finding it hard to keep track of the two destinations selected after evaluating a condition, especially when dealing with complex subconditions like `||` or `!`, or looking at different callers. So this PR tries to establish a convention of always using `(true_block, false_block)` to refer to the condition's outcome paths, which can then be manipulated as appropriate by calling code. There should be no observable change to compiler behaviour.
…uwer Rollup of 16 pull requests Successful merges: - #137720 (support `#[target_feature(enable = ...)]` on `#[naked]` functions) - #160534 (stabilize smart pointer map functions) - #160551 (mir_build: Clearly distinguish or/refutable/irrefutable patterns during match lowering) - #160989 (Make sin, cos, exp, exp2, log, log2, log10 generic) - #161861 (mir_build: Clarify parts of if-condition lowering) - #161929 (explicitly track inherent const generic args kind) - #162040 (bootstrap: stage0 to cbae9b4) - #162063 (Switch dist-aarch64-linux to EC2 and update dist-x86_64-linux) - #161353 (Add test for parallel compiler reproducible build) - #161937 (A series of Polonius Alpha refactors) - #162051 (`rustc_feature` cleanups) - #162055 (remove `_{style}` recovery for diagnostic structs) - #162075 (Move track_caller on closures gating to attribute parsing) - #162079 (std: implement `File::fsync` for Hermit) - #162097 (Deduplicate `InstrumentFnAttr`) - #162115 (fix typo in feature documentation)
Rollup merge of #161861 - Zalathar:if-then, r=Nadrieril mir_build: Clarify parts of if-condition lowering I've been looking at this condition-lowering code a lot, and I noticed that some parts are hard to follow due to how functions and variables are named. In particular, the function name `then_else_break` doesn't give much useful intuition for the fact that it lowers an `if` condition (or similar), and then proceeds if the condition was true or breaks if the condition was false. Similarly, I was finding it hard to keep track of the two destinations selected after evaluating a condition, especially when dealing with complex subconditions like `||` or `!`, or looking at different callers. So this PR tries to establish a convention of always using `(true_block, false_block)` to refer to the condition's outcome paths, which can then be manipulated as appropriate by calling code. There should be no observable change to compiler behaviour.
|
Finished benchmarking commit (9b66008): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up. @rustbot label: -S-waiting-on-perf -perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (secondary -2.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesThis perf run didn't have relevant results for this metric. Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: missing data |
…uwer Rollup of 16 pull requests Successful merges: - rust-lang/rust#137720 (support `#[target_feature(enable = ...)]` on `#[naked]` functions) - rust-lang/rust#160534 (stabilize smart pointer map functions) - rust-lang/rust#160551 (mir_build: Clearly distinguish or/refutable/irrefutable patterns during match lowering) - rust-lang/rust#160989 (Make sin, cos, exp, exp2, log, log2, log10 generic) - rust-lang/rust#161861 (mir_build: Clarify parts of if-condition lowering) - rust-lang/rust#161929 (explicitly track inherent const generic args kind) - rust-lang/rust#162040 (bootstrap: stage0 to cbae9b4cae2b108f6a3d18cfe6075714bb739463) - rust-lang/rust#162063 (Switch dist-aarch64-linux to EC2 and update dist-x86_64-linux) - rust-lang/rust#161353 (Add test for parallel compiler reproducible build) - rust-lang/rust#161937 (A series of Polonius Alpha refactors) - rust-lang/rust#162051 (`rustc_feature` cleanups) - rust-lang/rust#162055 (remove `_{style}` recovery for diagnostic structs) - rust-lang/rust#162075 (Move track_caller on closures gating to attribute parsing) - rust-lang/rust#162079 (std: implement `File::fsync` for Hermit) - rust-lang/rust#162097 (Deduplicate `InstrumentFnAttr`) - rust-lang/rust#162115 (fix typo in feature documentation)
…uwer Rollup of 16 pull requests Successful merges: - rust-lang/rust#137720 (support `#[target_feature(enable = ...)]` on `#[naked]` functions) - rust-lang/rust#160534 (stabilize smart pointer map functions) - rust-lang/rust#160551 (mir_build: Clearly distinguish or/refutable/irrefutable patterns during match lowering) - rust-lang/rust#160989 (Make sin, cos, exp, exp2, log, log2, log10 generic) - rust-lang/rust#161861 (mir_build: Clarify parts of if-condition lowering) - rust-lang/rust#161929 (explicitly track inherent const generic args kind) - rust-lang/rust#162040 (bootstrap: stage0 to cbae9b4cae2b108f6a3d18cfe6075714bb739463) - rust-lang/rust#162063 (Switch dist-aarch64-linux to EC2 and update dist-x86_64-linux) - rust-lang/rust#161353 (Add test for parallel compiler reproducible build) - rust-lang/rust#161937 (A series of Polonius Alpha refactors) - rust-lang/rust#162051 (`rustc_feature` cleanups) - rust-lang/rust#162055 (remove `_{style}` recovery for diagnostic structs) - rust-lang/rust#162075 (Move track_caller on closures gating to attribute parsing) - rust-lang/rust#162079 (std: implement `File::fsync` for Hermit) - rust-lang/rust#162097 (Deduplicate `InstrumentFnAttr`) - rust-lang/rust#162115 (fix typo in feature documentation)
…uwer Rollup of 16 pull requests Successful merges: - rust-lang/rust#137720 (support `#[target_feature(enable = ...)]` on `#[naked]` functions) - rust-lang/rust#160534 (stabilize smart pointer map functions) - rust-lang/rust#160551 (mir_build: Clearly distinguish or/refutable/irrefutable patterns during match lowering) - rust-lang/rust#160989 (Make sin, cos, exp, exp2, log, log2, log10 generic) - rust-lang/rust#161861 (mir_build: Clarify parts of if-condition lowering) - rust-lang/rust#161929 (explicitly track inherent const generic args kind) - rust-lang/rust#162040 (bootstrap: stage0 to cbae9b4cae2b108f6a3d18cfe6075714bb739463) - rust-lang/rust#162063 (Switch dist-aarch64-linux to EC2 and update dist-x86_64-linux) - rust-lang/rust#161353 (Add test for parallel compiler reproducible build) - rust-lang/rust#161937 (A series of Polonius Alpha refactors) - rust-lang/rust#162051 (`rustc_feature` cleanups) - rust-lang/rust#162055 (remove `_{style}` recovery for diagnostic structs) - rust-lang/rust#162075 (Move track_caller on closures gating to attribute parsing) - rust-lang/rust#162079 (std: implement `File::fsync` for Hermit) - rust-lang/rust#162097 (Deduplicate `InstrumentFnAttr`) - rust-lang/rust#162115 (fix typo in feature documentation)
I've been looking at this condition-lowering code a lot, and I noticed that some parts are hard to follow due to how functions and variables are named.
In particular, the function name
then_else_breakdoesn't give much useful intuition for the fact that it lowers anifcondition (or similar), and then proceeds if the condition was true or breaks if the condition was false.Similarly, I was finding it hard to keep track of the two destinations selected after evaluating a condition, especially when dealing with complex subconditions like
||or!, or looking at different callers. So this PR tries to establish a convention of always using(true_block, false_block)to refer to the condition's outcome paths, which can then be manipulated as appropriate by calling code.There should be no observable change to compiler behaviour.