zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit e83cf6a4542b34e7fd64028a3b1b89dacdc2e166 (tree)
parent b109daacddf54dbe4ffcbef9041443f2759511e3
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Thu, 13 May 2021 16:48:24 -0700

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.

Diffstat:
MBRANCH_TODO | 2++
Msrc/Sema.zig | 5+++++
Msrc/Zir.zig | 2++
3 files changed, 9 insertions(+), 0 deletions(-)

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