authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-08-21 12:48:26+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-08-21 12:53:19+03:00
log20d0018d79c25a0def440040eab2970e7a314130
treee9271c0fefbbfcba4ea4adb4ce182b378b92acc9
parentd48af541c7aa235948621cdbc250d983af303977

Sema: ignore dbg_block instructions when checking for comptimeness

Closes #12514

2 files changed, 20 insertions(+), 5 deletions(-)

src/Sema.zig+5-5
...@@ -3087,7 +3087,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -3087,7 +3087,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
30873087
3088 const candidate = block.instructions.items[search_index];3088 const candidate = block.instructions.items[search_index];
3089 switch (air_tags[candidate]) {3089 switch (air_tags[candidate]) {
3090 .dbg_stmt => continue,3090 .dbg_stmt, .dbg_block_begin, .dbg_block_end => continue,
3091 .store => break candidate,3091 .store => break candidate,
3092 else => break :ct,3092 else => break :ct,
3093 }3093 }
...@@ -3099,7 +3099,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -3099,7 +3099,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
30993099
3100 const candidate = block.instructions.items[search_index];3100 const candidate = block.instructions.items[search_index];
3101 switch (air_tags[candidate]) {3101 switch (air_tags[candidate]) {
3102 .dbg_stmt => continue,3102 .dbg_stmt, .dbg_block_begin, .dbg_block_end => continue,
3103 .alloc => {3103 .alloc => {
3104 if (Air.indexToRef(candidate) != alloc) break :ct;3104 if (Air.indexToRef(candidate) != alloc) break :ct;
3105 break;3105 break;
...@@ -3317,7 +3317,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -3317,7 +3317,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
33173317
3318 const candidate = block.instructions.items[search_index];3318 const candidate = block.instructions.items[search_index];
3319 switch (air_tags[candidate]) {3319 switch (air_tags[candidate]) {
3320 .dbg_stmt => continue,3320 .dbg_stmt, .dbg_block_begin, .dbg_block_end => continue,
3321 .store => break candidate,3321 .store => break candidate,
3322 else => break :ct,3322 else => break :ct,
3323 }3323 }
...@@ -3329,7 +3329,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -3329,7 +3329,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
33293329
3330 const candidate = block.instructions.items[search_index];3330 const candidate = block.instructions.items[search_index];
3331 switch (air_tags[candidate]) {3331 switch (air_tags[candidate]) {
3332 .dbg_stmt => continue,3332 .dbg_stmt, .dbg_block_begin, .dbg_block_end => continue,
3333 .bitcast => break candidate,3333 .bitcast => break candidate,
3334 else => break :ct,3334 else => break :ct,
3335 }3335 }
...@@ -3341,7 +3341,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -3341,7 +3341,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
33413341
3342 const candidate = block.instructions.items[search_index];3342 const candidate = block.instructions.items[search_index];
3343 switch (air_tags[candidate]) {3343 switch (air_tags[candidate]) {
3344 .dbg_stmt => continue,3344 .dbg_stmt, .dbg_block_begin, .dbg_block_end => continue,
3345 .constant => break candidate,3345 .constant => break candidate,
3346 else => break :ct,3346 else => break :ct,
3347 }3347 }
test/behavior/eval.zig+15
...@@ -1310,3 +1310,18 @@ test "repeated value is correctly expanded" {...@@ -1310,3 +1310,18 @@ test "repeated value is correctly expanded" {
1310 } }, res);1310 } }, res);
1311 }1311 }
1312}1312}
1313
1314test "value in if block is comptime known" {
1315 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
1316
1317 const first = blk: {
1318 const s = if (false) "a" else "b";
1319 break :blk "foo" ++ s;
1320 };
1321 const second = blk: {
1322 const S = struct { str: []const u8 };
1323 const s = if (false) S{ .str = "a" } else S{ .str = "b" };
1324 break :blk "foo" ++ s.str;
1325 };
1326 comptime try expect(std.mem.eql(u8, first, second));
1327}