authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-13 16:48:24-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-13 16:50:27-07:00
loge83cf6a4542b34e7fd64028a3b1b89dacdc2e166
treeed192b102e4ca13145623216b0e808d7f1fd6059
parentb109daacddf54dbe4ffcbef9041443f2759511e3

Sema: detect and skip over elided instructions

It would be better if AstGen would actually omit these instructions rather than only marking them as elided, but that can be solved separately.

3 files changed, 9 insertions(+), 0 deletions(-)

BRANCH_TODO+2
......@@ -65,3 +65,5 @@
6565
6666 * in SwitchProng resolve, make sure AST tree gets loaded.
6767 It will be unloaded if using cached ZIR.
68
69 * make AstGen smart enough to omit elided store_to_block_ptr instructions
src/Sema.zig+5
......@@ -1461,6 +1461,11 @@ fn zirStoreToBlockPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) In
14611461 defer tracy.end();
14621462
14631463 const bin_inst = sema.code.instructions.items(.data)[inst].bin;
1464 if (bin_inst.lhs == .none) {
1465 // This is an elided instruction, but AstGen was not smart enough
1466 // to omit it.
1467 return;
1468 }
14641469 const ptr = try sema.resolveInst(bin_inst.lhs);
14651470 const value = try sema.resolveInst(bin_inst.rhs);
14661471 const ptr_ty = try sema.mod.simplePtrType(sema.arena, value.ty, true, .One);
src/Zir.zig+2
......@@ -484,6 +484,8 @@ pub const Inst = struct {
484484 /// Same as `store` but the type of the value being stored will be used to infer
485485 /// the block type. The LHS is the pointer to store to.
486486 /// Uses the `bin` union field.
487 /// If the pointer is none, it means this instruction has been elided in
488 /// AstGen, but AstGen was unable to actually omit it from the ZIR code.
487489 store_to_block_ptr,
488490 /// Same as `store` but the type of the value being stored will be used to infer
489491 /// the pointer type.