authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-10-17 15:19:16+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-10-19 01:38:19+03:00
log6582896ee00cd6b05b2f0a1d845b4a77d6bf7c25
treee1b299ed7e33c5fbb18c163c851b3e3804b1ce2f
parent4e134f6dcb02000151c395718eb2c24977100013

Sema: remove unresolved inferred allocs

Closes #2557

4 files changed, 25 insertions(+), 0 deletions(-)

src/Module.zig+12
...@@ -5612,6 +5612,18 @@ pub fn analyzeFnBody(mod: *Module, func: *Fn, arena: Allocator) SemaError!Air {...@@ -5612,6 +5612,18 @@ pub fn analyzeFnBody(mod: *Module, func: *Fn, arena: Allocator) SemaError!Air {
5612 else => |e| return e,5612 else => |e| return e,
5613 };5613 };
56145614
5615 {
5616 var it = sema.unresolved_inferred_allocs.keyIterator();
5617 while (it.next()) |ptr_inst| {
5618 // The lack of a resolve_inferred_alloc means that this instruction
5619 // is unused so it just has to be a no-op.
5620 sema.air_instructions.set(ptr_inst.*, .{
5621 .tag = .alloc,
5622 .data = .{ .ty = Type.initTag(.single_const_pointer_to_comptime_int) },
5623 });
5624 }
5625 }
5626
5615 // If we don't get an error return trace from a caller, create our own.5627 // If we don't get an error return trace from a caller, create our own.
5616 if (func.calls_or_awaits_errorable_fn and5628 if (func.calls_or_awaits_errorable_fn and
5617 mod.comp.bin_file.options.error_return_tracing and5629 mod.comp.bin_file.options.error_return_tracing and
src/Sema.zig+6
...@@ -82,6 +82,8 @@ is_generic_instantiation: bool = false,...@@ -82,6 +82,8 @@ is_generic_instantiation: bool = false,
82/// function types will emit generic poison instead of a partial type.82/// function types will emit generic poison instead of a partial type.
83no_partial_func_ty: bool = false,83no_partial_func_ty: bool = false,
8484
85unresolved_inferred_allocs: std.AutoHashMapUnmanaged(Air.Inst.Index, void) = .{},
86
85const std = @import("std");87const std = @import("std");
86const math = std.math;88const math = std.math;
87const mem = std.mem;89const mem = std.mem;
...@@ -579,6 +581,7 @@ pub fn deinit(sema: *Sema) void {...@@ -579,6 +581,7 @@ pub fn deinit(sema: *Sema) void {
579 }581 }
580 sema.post_hoc_blocks.deinit(gpa);582 sema.post_hoc_blocks.deinit(gpa);
581 }583 }
584 sema.unresolved_inferred_allocs.deinit(gpa);
582 sema.* = undefined;585 sema.* = undefined;
583}586}
584587
...@@ -3238,6 +3241,7 @@ fn zirAllocExtended(...@@ -3238,6 +3241,7 @@ fn zirAllocExtended(
3238 );3241 );
3239 try sema.requireFunctionBlock(block, src);3242 try sema.requireFunctionBlock(block, src);
3240 try block.instructions.append(sema.gpa, Air.refToIndex(result).?);3243 try block.instructions.append(sema.gpa, Air.refToIndex(result).?);
3244 try sema.unresolved_inferred_allocs.putNoClobber(sema.gpa, Air.refToIndex(result).?, {});
3241 return result;3245 return result;
3242}3246}
32433247
...@@ -3414,6 +3418,7 @@ fn zirAllocInferred(...@@ -3414,6 +3418,7 @@ fn zirAllocInferred(
3414 );3418 );
3415 try sema.requireFunctionBlock(block, src);3419 try sema.requireFunctionBlock(block, src);
3416 try block.instructions.append(sema.gpa, Air.refToIndex(result).?);3420 try block.instructions.append(sema.gpa, Air.refToIndex(result).?);
3421 try sema.unresolved_inferred_allocs.putNoClobber(sema.gpa, Air.refToIndex(result).?, {});
3417 return result;3422 return result;
3418}3423}
34193424
...@@ -3463,6 +3468,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -3463,6 +3468,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
3463 }3468 }
3464 },3469 },
3465 .inferred_alloc => {3470 .inferred_alloc => {
3471 assert(sema.unresolved_inferred_allocs.remove(ptr_inst));
3466 const inferred_alloc = ptr_val.castTag(.inferred_alloc).?;3472 const inferred_alloc = ptr_val.castTag(.inferred_alloc).?;
3467 const peer_inst_list = inferred_alloc.data.prongs.items(.stored_inst);3473 const peer_inst_list = inferred_alloc.data.prongs.items(.stored_inst);
3468 const final_elem_ty = try sema.resolvePeerTypes(block, ty_src, peer_inst_list, .none);3474 const final_elem_ty = try sema.resolvePeerTypes(block, ty_src, peer_inst_list, .none);
test/behavior.zig+1
...@@ -41,6 +41,7 @@ test {...@@ -41,6 +41,7 @@ test {
41 _ = @import("behavior/bugs/2006.zig");41 _ = @import("behavior/bugs/2006.zig");
42 _ = @import("behavior/bugs/2114.zig");42 _ = @import("behavior/bugs/2114.zig");
43 _ = @import("behavior/bugs/2346.zig");43 _ = @import("behavior/bugs/2346.zig");
44 _ = @import("behavior/bugs/2557.zig");
44 _ = @import("behavior/bugs/2578.zig");45 _ = @import("behavior/bugs/2578.zig");
45 _ = @import("behavior/bugs/2692.zig");46 _ = @import("behavior/bugs/2692.zig");
46 _ = @import("behavior/bugs/2889.zig");47 _ = @import("behavior/bugs/2889.zig");
test/behavior/bugs/2557.zig created+6
...@@ -0,0 +1,6 @@
1test {
2 var a = if (true) {
3 return;
4 } else true;
5 _ = a;
6}