aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCody Tapscott <topolarity@tapscott.me>2022-10-30 12:25:49 -0700
committerCody Tapscott <topolarity@tapscott.me>2022-10-30 12:38:08 -0700
commitca332f57f712c3b4570ca42bc503824022115142 (patch)
tree4485ea7741ecbfe501eeb2916290d7c911bfffe0 /src
parent2f732deb3d15752d4977f04b38718e6896460e69 (diff)
downloadzig-ca332f57f712c3b4570ca42bc503824022115142.tar.gz
zig-ca332f57f712c3b4570ca42bc503824022115142.zip
stage2: Make `x and false`/`x or true` comptime-known
Same as preceding change, but for stage2.
Diffstat (limited to 'src')
-rw-r--r--src/Sema.zig23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index a73c1eedcb..34b22f5073 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -15932,12 +15932,10 @@ fn zirBoolBr(
const gpa = sema.gpa;
if (try sema.resolveDefinedValue(parent_block, lhs_src, lhs)) |lhs_val| {
- if (lhs_val.toBool() == is_bool_or) {
- if (is_bool_or) {
- return Air.Inst.Ref.bool_true;
- } else {
- return Air.Inst.Ref.bool_false;
- }
+ if (is_bool_or and lhs_val.toBool()) {
+ return Air.Inst.Ref.bool_true;
+ } else if (!is_bool_or and !lhs_val.toBool()) {
+ return Air.Inst.Ref.bool_false;
}
// comptime-known left-hand side. No need for a block here; the result
// is simply the rhs expression. Here we rely on there only being 1
@@ -15977,7 +15975,18 @@ fn zirBoolBr(
_ = try rhs_block.addBr(block_inst, rhs_result);
}
- return finishCondBr(sema, parent_block, &child_block, &then_block, &else_block, lhs, block_inst);
+ const result = finishCondBr(sema, parent_block, &child_block, &then_block, &else_block, lhs, block_inst);
+ if (!sema.typeOf(rhs_result).isNoReturn()) {
+ if (try sema.resolveDefinedValue(rhs_block, sema.src, rhs_result)) |rhs_val| {
+ if (is_bool_or and rhs_val.toBool()) {
+ return Air.Inst.Ref.bool_true;
+ } else if (!is_bool_or and !rhs_val.toBool()) {
+ return Air.Inst.Ref.bool_false;
+ }
+ }
+ }
+
+ return result;
}
fn finishCondBr(