From 01d19a8d3cdd52ad50f45bfb8666b56ccf8d3a22 Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Tue, 30 Aug 2022 14:40:48 +0300 Subject: Sema: do not emit generic poison for non generic parameters Closes #12679 --- src/Sema.zig | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Sema.zig b/src/Sema.zig index 823ae9baf2..bf147a7cb4 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -8195,8 +8195,22 @@ fn zirParam( .is_comptime = comptime_syntax, .name = param_name, }); - const result = try sema.addConstant(param_ty, Value.initTag(.generic_poison)); - try sema.inst_map.putNoClobber(sema.gpa, inst, result); + + if (is_comptime) { + // If this is a comptime parameter we can add a constant generic_poison + // since this is also a generic parameter. + const result = try sema.addConstant(param_ty, Value.initTag(.generic_poison)); + try sema.inst_map.putNoClobber(sema.gpa, inst, result); + } else { + // Otherwise we need a dummy runtime instruction. + const result_index = @intCast(Air.Inst.Index, sema.air_instructions.len); + try sema.air_instructions.append(sema.gpa, .{ + .tag = .alloc, + .data = .{ .ty = param_ty }, + }); + const result = Air.indexToRef(result_index); + try sema.inst_map.putNoClobber(sema.gpa, inst, result); + } } fn zirParamAnytype( -- cgit v1.2.3