diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2024-05-02 01:59:38 +0100 |
|---|---|---|
| committer | Matthew Lugg <mlugg@mlugg.co.uk> | 2024-05-04 22:03:56 +0100 |
| commit | db890dbae72bc31e50d4ec641f2afce683df772d (patch) | |
| tree | b1b3f0b3f9f921cfd1ac365446becb235151a970 /src/Sema.zig | |
| parent | 5bbb2f966a4d29c7003767255515b7c69a2f1178 (diff) | |
| download | zig-db890dbae72bc31e50d4ec641f2afce683df772d.tar.gz zig-db890dbae72bc31e50d4ec641f2afce683df772d.zip | |
InternPool: eliminate `var_args_param_type`
This was a "fake" type used to handle C varargs parameters, much like
generic poison. In fact, it is treated identically to generic poison in
all cases other than one (the final coercion of a call argument), which
is trivially special-cased. Thus, it makes sense to remove this special
tag and instead use `generic_poison_type` in its place. This fixes
several bugs in Sema related to missing handling of this tag.
Resolves: #19781
Diffstat (limited to 'src/Sema.zig')
| -rw-r--r-- | src/Sema.zig | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index 74cea620e3..86d3378aee 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -1901,7 +1901,6 @@ pub fn resolveConstStringIntern( pub fn resolveType(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.Inst.Ref) !Type { const air_inst = try sema.resolveInst(zir_ref); - assert(air_inst != .var_args_param_type); const ty = try sema.analyzeAsType(block, src, air_inst); if (ty.isGenericPoison()) return error.GenericPoison; return ty; @@ -4572,12 +4571,10 @@ fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr const src = un_tok.src(); // In case of GenericPoison, we don't actually have a type, so this will be // treated as an untyped address-of operator. - if (un_tok.operand == .var_args_param_type) return; const operand_air_inst = sema.resolveInst(un_tok.operand) catch |err| switch (err) { error.GenericPoison => return, else => |e| return e, }; - if (operand_air_inst == .var_args_param_type) return; const ty_operand = sema.analyzeAsType(block, src, operand_air_inst) catch |err| switch (err) { error.GenericPoison => return, else => |e| return e, @@ -7363,7 +7360,7 @@ const CallArgsInfo = union(enum) { } /// Analyzes the arg at `arg_index` and coerces it to `param_ty`. - /// `param_ty` may be `generic_poison` or `var_args_param`. + /// `param_ty` may be `generic_poison`. A value of `null` indicates a varargs parameter. /// `func_ty_info` may be the type before instantiation, even if a generic /// instantiation has been partially completed. fn analyzeArg( @@ -7371,16 +7368,16 @@ const CallArgsInfo = union(enum) { sema: *Sema, block: *Block, arg_index: usize, - param_ty: Type, + maybe_param_ty: ?Type, func_ty_info: InternPool.Key.FuncType, func_inst: Air.Inst.Ref, ) CompileError!Air.Inst.Ref { const mod = sema.mod; const param_count = func_ty_info.param_types.len; - switch (param_ty.toIntern()) { - .generic_poison_type, .var_args_param_type => {}, + if (maybe_param_ty) |param_ty| switch (param_ty.toIntern()) { + .generic_poison_type => {}, else => try sema.queueFullTypeResolution(param_ty), - } + }; const uncoerced_arg: Air.Inst.Ref = switch (cai) { inline .resolved, .call_builtin => |resolved| resolved.args[arg_index], .zir_call => |zir_call| arg_val: { @@ -7409,7 +7406,8 @@ const CallArgsInfo = union(enum) { // TODO set comptime_reason } // Give the arg its result type - sema.inst_map.putAssumeCapacity(zir_call.call_inst, Air.internedToRef(param_ty.toIntern())); + const provide_param_ty = if (maybe_param_ty) |t| t else Type.generic_poison; + sema.inst_map.putAssumeCapacity(zir_call.call_inst, Air.internedToRef(provide_param_ty.toIntern())); // Resolve the arg! const uncoerced_arg = try sema.resolveInlineBody(block, arg_body, zir_call.call_inst); @@ -7426,9 +7424,11 @@ const CallArgsInfo = union(enum) { break :arg_val uncoerced_arg; }, }; + const param_ty = maybe_param_ty orelse { + return sema.coerceVarArgParam(block, uncoerced_arg, cai.argSrc(block, arg_index)); + }; switch (param_ty.toIntern()) { .generic_poison_type => return uncoerced_arg, - .var_args_param_type => return sema.coerceVarArgParam(block, uncoerced_arg, cai.argSrc(block, arg_index)), else => return sema.coerceExtra( block, param_ty, @@ -7970,10 +7970,10 @@ fn analyzeCall( const args = try sema.arena.alloc(Air.Inst.Ref, args_info.count()); for (args, 0..) |*arg_out, arg_idx| { // Non-generic, so param types are already resolved - const param_ty = if (arg_idx < func_ty_info.param_types.len) ty: { + const param_ty: ?Type = if (arg_idx < func_ty_info.param_types.len) ty: { break :ty Type.fromInterned(func_ty_info.param_types.get(ip)[arg_idx]); - } else Type.fromInterned(InternPool.Index.var_args_param_type); - assert(!param_ty.isGenericPoison()); + } else null; + if (param_ty) |t| assert(!t.isGenericPoison()); arg_out.* = try args_info.analyzeArg(sema, block, arg_idx, param_ty, func_ty_info, func); try sema.validateRuntimeValue(block, args_info.argSrc(block, arg_idx), arg_out.*); if (sema.typeOf(arg_out.*).zigTypeTag(mod) == .NoReturn) { @@ -10226,12 +10226,10 @@ fn analyzeAs( ) CompileError!Air.Inst.Ref { const mod = sema.mod; const operand = try sema.resolveInst(zir_operand); - if (zir_dest_type == .var_args_param_type) return operand; const operand_air_inst = sema.resolveInst(zir_dest_type) catch |err| switch (err) { error.GenericPoison => return operand, else => |e| return e, }; - if (operand_air_inst == .var_args_param_type) return operand; const dest_ty = sema.analyzeAsType(block, src, operand_air_inst) catch |err| switch (err) { error.GenericPoison => return operand, else => |e| return e, @@ -35664,8 +35662,6 @@ pub fn resolveTypeFields(sema: *Sema, ty: Type) CompileError!void { const ty_ip = ty.toIntern(); switch (ty_ip) { - .var_args_param_type => unreachable, - .none => unreachable, .u0_type, @@ -37184,7 +37180,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { .empty_struct, .generic_poison, // invalid - .var_args_param_type, .none, => unreachable, |
