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 {
56125612 else => |e| return e,
56135613 };
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
56155627 // If we don't get an error return trace from a caller, create our own.
56165628 if (func.calls_or_awaits_errorable_fn and
56175629 mod.comp.bin_file.options.error_return_tracing and
src/Sema.zig+6
......@@ -82,6 +82,8 @@ is_generic_instantiation: bool = false,
8282/// function types will emit generic poison instead of a partial type.
8383no_partial_func_ty: bool = false,
8484
85unresolved_inferred_allocs: std.AutoHashMapUnmanaged(Air.Inst.Index, void) = .{},
86
8587const std = @import("std");
8688const math = std.math;
8789const mem = std.mem;
......@@ -579,6 +581,7 @@ pub fn deinit(sema: *Sema) void {
579581 }
580582 sema.post_hoc_blocks.deinit(gpa);
581583 }
584 sema.unresolved_inferred_allocs.deinit(gpa);
582585 sema.* = undefined;
583586}
584587
......@@ -3238,6 +3241,7 @@ fn zirAllocExtended(
32383241 );
32393242 try sema.requireFunctionBlock(block, src);
32403243 try block.instructions.append(sema.gpa, Air.refToIndex(result).?);
3244 try sema.unresolved_inferred_allocs.putNoClobber(sema.gpa, Air.refToIndex(result).?, {});
32413245 return result;
32423246}
32433247
......@@ -3414,6 +3418,7 @@ fn zirAllocInferred(
34143418 );
34153419 try sema.requireFunctionBlock(block, src);
34163420 try block.instructions.append(sema.gpa, Air.refToIndex(result).?);
3421 try sema.unresolved_inferred_allocs.putNoClobber(sema.gpa, Air.refToIndex(result).?, {});
34173422 return result;
34183423}
34193424
......@@ -3463,6 +3468,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
34633468 }
34643469 },
34653470 .inferred_alloc => {
3471 assert(sema.unresolved_inferred_allocs.remove(ptr_inst));
34663472 const inferred_alloc = ptr_val.castTag(.inferred_alloc).?;
34673473 const peer_inst_list = inferred_alloc.data.prongs.items(.stored_inst);
34683474 const final_elem_ty = try sema.resolvePeerTypes(block, ty_src, peer_inst_list, .none);
test/behavior.zig+1
......@@ -41,6 +41,7 @@ test {
4141 _ = @import("behavior/bugs/2006.zig");
4242 _ = @import("behavior/bugs/2114.zig");
4343 _ = @import("behavior/bugs/2346.zig");
44 _ = @import("behavior/bugs/2557.zig");
4445 _ = @import("behavior/bugs/2578.zig");
4546 _ = @import("behavior/bugs/2692.zig");
4647 _ = @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}