| author | |
| committer | |
| log | 447a30299073ce88b7b26d18d060a345beac5276 |
| tree | 40f114a446af38e91a88cce5c91481c0b3a97cce |
| parent | b61d0debd6d6018203945ae67dc54d474fbc74de |
This was a special type tag used for hacky stuff in Semantic Analysis.
Move the hacky stuff to use a dedicated `Air.Inst.Ref` instead.
This way, `var_args_param` is not involved in the type system or intern
pool.4 files changed, 34 insertions(+), 42 deletions(-)
src/Sema.zig+29-22| ... | ... | @@ -1767,7 +1767,9 @@ pub fn resolveConstString( |
| 1767 | 1767 | } |
| 1768 | 1768 | |
| 1769 | 1769 | pub fn resolveType(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.Inst.Ref) !Type { |
| 1770 | assert(zir_ref != .var_args_param); | |
| 1770 | 1771 | const air_inst = try sema.resolveInst(zir_ref); |
| 1772 | assert(air_inst != .var_args_param); | |
| 1771 | 1773 | const ty = try sema.analyzeAsType(block, src, air_inst); |
| 1772 | 1774 | if (ty.tag() == .generic_poison) return error.GenericPoison; |
| 1773 | 1775 | return ty; |
| ... | ... | @@ -6329,12 +6331,6 @@ fn zirCall( |
| 6329 | 6331 | const arg_end = sema.code.extra[extra.end + extra_index]; |
| 6330 | 6332 | defer arg_start = arg_end; |
| 6331 | 6333 | |
| 6332 | const param_ty = if (arg_index >= fn_params_len or | |
| 6333 | func_ty_info.param_types[arg_index].tag() == .generic_poison) | |
| 6334 | Type.initTag(.var_args_param) | |
| 6335 | else | |
| 6336 | func_ty_info.param_types[arg_index]; | |
| 6337 | ||
| 6338 | 6334 | // Generate args to comptime params in comptime block. |
| 6339 | 6335 | defer block.is_comptime = parent_comptime; |
| 6340 | 6336 | if (arg_index < fn_params_len and func_ty_info.comptime_params[arg_index]) { |
| ... | ... | @@ -6342,8 +6338,15 @@ fn zirCall( |
| 6342 | 6338 | // TODO set comptime_reason |
| 6343 | 6339 | } |
| 6344 | 6340 | |
| 6345 | const param_ty_inst = try sema.addType(param_ty); | |
| 6346 | sema.inst_map.putAssumeCapacity(inst, param_ty_inst); | |
| 6341 | sema.inst_map.putAssumeCapacity(inst, inst: { | |
| 6342 | if (arg_index >= fn_params_len) | |
| 6343 | break :inst Air.Inst.Ref.var_args_param; | |
| 6344 | ||
| 6345 | if (func_ty_info.param_types[arg_index].tag() == .generic_poison) | |
| 6346 | break :inst Air.Inst.Ref.generic_poison_type; | |
| 6347 | ||
| 6348 | break :inst try sema.addType(func_ty_info.param_types[arg_index]); | |
| 6349 | }); | |
| 6347 | 6350 | |
| 6348 | 6351 | const resolved = try sema.resolveBody(block, args_body[arg_start..arg_end], inst); |
| 6349 | 6352 | const resolved_ty = sema.typeOf(resolved); |
| ... | ... | @@ -9401,16 +9404,19 @@ fn analyzeAs( |
| 9401 | 9404 | zir_operand: Zir.Inst.Ref, |
| 9402 | 9405 | no_cast_to_comptime_int: bool, |
| 9403 | 9406 | ) CompileError!Air.Inst.Ref { |
| 9404 | const is_ret = if (Zir.refToIndex(zir_dest_type)) |ptr_index| | |
| 9405 | sema.code.instructions.items(.tag)[ptr_index] == .ret_type | |
| 9406 | else | |
| 9407 | false; | |
| 9408 | const dest_ty = try sema.resolveType(block, src, zir_dest_type); | |
| 9409 | 9407 | const operand = try sema.resolveInst(zir_operand); |
| 9410 | if (dest_ty.tag() == .var_args_param) return operand; | |
| 9408 | if (zir_dest_type == .var_args_param) return operand; | |
| 9409 | const dest_ty = sema.resolveType(block, src, zir_dest_type) catch |err| switch (err) { | |
| 9410 | error.GenericPoison => return operand, | |
| 9411 | else => |e| return e, | |
| 9412 | }; | |
| 9411 | 9413 | if (dest_ty.zigTypeTag() == .NoReturn) { |
| 9412 | 9414 | return sema.fail(block, src, "cannot cast to noreturn", .{}); |
| 9413 | 9415 | } |
| 9416 | const is_ret = if (Zir.refToIndex(zir_dest_type)) |ptr_index| | |
| 9417 | sema.code.instructions.items(.tag)[ptr_index] == .ret_type | |
| 9418 | else | |
| 9419 | false; | |
| 9414 | 9420 | return sema.coerceExtra(block, dest_ty, operand, src, .{ .is_ret = is_ret, .no_cast_to_comptime_int = no_cast_to_comptime_int }) catch |err| switch (err) { |
| 9415 | 9421 | error.NotCoercible => unreachable, |
| 9416 | 9422 | else => |e| return e, |
| ... | ... | @@ -18300,8 +18306,14 @@ fn zirFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 18300 | 18306 | const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data; |
| 18301 | 18307 | const ty_src = inst_data.src(); |
| 18302 | 18308 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; |
| 18303 | const aggregate_ty = try sema.resolveType(block, ty_src, extra.container_type); | |
| 18304 | if (aggregate_ty.tag() == .var_args_param) return sema.addType(aggregate_ty); | |
| 18309 | const aggregate_ty = sema.resolveType(block, ty_src, extra.container_type) catch |err| switch (err) { | |
| 18310 | // Since this is a ZIR instruction that returns a type, encountering | |
| 18311 | // generic poison should not result in a failed compilation, but the | |
| 18312 | // generic poison type. This prevents unnecessary failures when | |
| 18313 | // constructing types at compile-time. | |
| 18314 | error.GenericPoison => return Air.Inst.Ref.generic_poison_type, | |
| 18315 | else => |e| return e, | |
| 18316 | }; | |
| 18305 | 18317 | const field_name = sema.code.nullTerminatedString(extra.name_start); |
| 18306 | 18318 | return sema.fieldType(block, aggregate_ty, field_name, field_name_src, ty_src); |
| 18307 | 18319 | } |
| ... | ... | @@ -24253,8 +24265,7 @@ fn fieldCallBind( |
| 24253 | 24265 | const first_param_type = decl_type.fnParamType(0); |
| 24254 | 24266 | const first_param_tag = first_param_type.tag(); |
| 24255 | 24267 | // zig fmt: off |
| 24256 | if (first_param_tag == .var_args_param or | |
| 24257 | first_param_tag == .generic_poison or ( | |
| 24268 | if (first_param_tag == .generic_poison or ( | |
| 24258 | 24269 | first_param_type.zigTypeTag() == .Pointer and |
| 24259 | 24270 | (first_param_type.ptrSize() == .One or |
| 24260 | 24271 | first_param_type.ptrSize() == .C) and |
| ... | ... | @@ -25405,7 +25416,6 @@ fn coerceExtra( |
| 25405 | 25416 | opts: CoerceOpts, |
| 25406 | 25417 | ) CoersionError!Air.Inst.Ref { |
| 25407 | 25418 | switch (dest_ty_unresolved.tag()) { |
| 25408 | .var_args_param => return sema.coerceVarArgParam(block, inst, inst_src), | |
| 25409 | 25419 | .generic_poison => return inst, |
| 25410 | 25420 | else => {}, |
| 25411 | 25421 | } |
| ... | ... | @@ -31269,7 +31279,6 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { |
| 31269 | 31279 | .function, |
| 31270 | 31280 | => true, |
| 31271 | 31281 | |
| 31272 | .var_args_param => unreachable, | |
| 31273 | 31282 | .inferred_alloc_mut => unreachable, |
| 31274 | 31283 | .inferred_alloc_const => unreachable, |
| 31275 | 31284 | .bound_fn => unreachable, |
| ... | ... | @@ -32634,7 +32643,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 32634 | 32643 | .anyerror_void_error_union, |
| 32635 | 32644 | .error_set_inferred, |
| 32636 | 32645 | .@"opaque", |
| 32637 | .var_args_param, | |
| 32638 | 32646 | .manyptr_u8, |
| 32639 | 32647 | .manyptr_const_u8, |
| 32640 | 32648 | .manyptr_const_u8_sentinel_0, |
| ... | ... | @@ -33298,7 +33306,6 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { |
| 33298 | 33306 | .function, |
| 33299 | 33307 | => true, |
| 33300 | 33308 | |
| 33301 | .var_args_param => unreachable, | |
| 33302 | 33309 | .inferred_alloc_mut => unreachable, |
| 33303 | 33310 | .inferred_alloc_const => unreachable, |
| 33304 | 33311 | .bound_fn => unreachable, |
src/Zir.zig+5| ... | ... | @@ -2163,6 +2163,10 @@ pub const Inst = struct { |
| 2163 | 2163 | /// Used for generic parameters where the type and value |
| 2164 | 2164 | /// is not known until generic function instantiation. |
| 2165 | 2165 | generic_poison, |
| 2166 | /// This is a special type for variadic parameters of a function call. | |
| 2167 | /// Casts to it will validate that the type can be passed to a c | |
| 2168 | /// calling convention function. | |
| 2169 | var_args_param, | |
| 2166 | 2170 | |
| 2167 | 2171 | _, |
| 2168 | 2172 | |
| ... | ... | @@ -2474,6 +2478,7 @@ pub const Inst = struct { |
| 2474 | 2478 | .ty = Type.initTag(.generic_poison), |
| 2475 | 2479 | .val = Value.initTag(.generic_poison), |
| 2476 | 2480 | }, |
| 2481 | .var_args_param = undefined, | |
| 2477 | 2482 | }); |
| 2478 | 2483 | }; |
| 2479 | 2484 |
src/print_air.zig-1| ... | ... | @@ -369,7 +369,6 @@ const Writer = struct { |
| 369 | 369 | .inferred_alloc_const => try s.writeAll("(inferred_alloc_const)"), |
| 370 | 370 | .inferred_alloc_mut => try s.writeAll("(inferred_alloc_mut)"), |
| 371 | 371 | .generic_poison => try s.writeAll("(generic_poison)"), |
| 372 | .var_args_param => try s.writeAll("(var_args_param)"), | |
| 373 | 372 | .bound_fn => try s.writeAll("(bound_fn)"), |
| 374 | 373 | else => try ty.print(s, w.module), |
| 375 | 374 | } |
src/type.zig-19| ... | ... | @@ -158,7 +158,6 @@ pub const Type = extern union { |
| 158 | 158 | => return .Union, |
| 159 | 159 | |
| 160 | 160 | .bound_fn => unreachable, |
| 161 | .var_args_param => unreachable, // can be any type | |
| 162 | 161 | } |
| 163 | 162 | } |
| 164 | 163 | |
| ... | ... | @@ -935,7 +934,6 @@ pub const Type = extern union { |
| 935 | 934 | .type_info => unreachable, // needed to resolve the type before now |
| 936 | 935 | |
| 937 | 936 | .bound_fn => unreachable, |
| 938 | .var_args_param => unreachable, // can be any type | |
| 939 | 937 | } |
| 940 | 938 | } |
| 941 | 939 | |
| ... | ... | @@ -1245,7 +1243,6 @@ pub const Type = extern union { |
| 1245 | 1243 | .type_info => unreachable, // needed to resolve the type before now |
| 1246 | 1244 | |
| 1247 | 1245 | .bound_fn => unreachable, |
| 1248 | .var_args_param => unreachable, // can be any type | |
| 1249 | 1246 | } |
| 1250 | 1247 | } |
| 1251 | 1248 | |
| ... | ... | @@ -1335,7 +1332,6 @@ pub const Type = extern union { |
| 1335 | 1332 | .anyerror_void_error_union, |
| 1336 | 1333 | .inferred_alloc_const, |
| 1337 | 1334 | .inferred_alloc_mut, |
| 1338 | .var_args_param, | |
| 1339 | 1335 | .empty_struct_literal, |
| 1340 | 1336 | .manyptr_u8, |
| 1341 | 1337 | .manyptr_const_u8, |
| ... | ... | @@ -1617,7 +1613,6 @@ pub const Type = extern union { |
| 1617 | 1613 | .comptime_int, |
| 1618 | 1614 | .comptime_float, |
| 1619 | 1615 | .noreturn, |
| 1620 | .var_args_param, | |
| 1621 | 1616 | .bound_fn, |
| 1622 | 1617 | => return writer.writeAll(@tagName(t)), |
| 1623 | 1618 | |
| ... | ... | @@ -1954,7 +1949,6 @@ pub const Type = extern union { |
| 1954 | 1949 | .inferred_alloc_const => unreachable, |
| 1955 | 1950 | .inferred_alloc_mut => unreachable, |
| 1956 | 1951 | .generic_poison => unreachable, |
| 1957 | .var_args_param => unreachable, | |
| 1958 | 1952 | .bound_fn => unreachable, |
| 1959 | 1953 | |
| 1960 | 1954 | // TODO get rid of these Type.Tag values. |
| ... | ... | @@ -2595,7 +2589,6 @@ pub const Type = extern union { |
| 2595 | 2589 | |
| 2596 | 2590 | .inferred_alloc_const => unreachable, |
| 2597 | 2591 | .inferred_alloc_mut => unreachable, |
| 2598 | .var_args_param => unreachable, | |
| 2599 | 2592 | .generic_poison => unreachable, |
| 2600 | 2593 | } |
| 2601 | 2594 | } |
| ... | ... | @@ -2708,7 +2701,6 @@ pub const Type = extern union { |
| 2708 | 2701 | .enum_nonexhaustive, |
| 2709 | 2702 | => !ty.cast(Payload.EnumFull).?.data.tag_ty_inferred, |
| 2710 | 2703 | |
| 2711 | .var_args_param => unreachable, | |
| 2712 | 2704 | .inferred_alloc_mut => unreachable, |
| 2713 | 2705 | .inferred_alloc_const => unreachable, |
| 2714 | 2706 | .bound_fn => unreachable, |
| ... | ... | @@ -3190,7 +3182,6 @@ pub const Type = extern union { |
| 3190 | 3182 | .noreturn, |
| 3191 | 3183 | .inferred_alloc_const, |
| 3192 | 3184 | .inferred_alloc_mut, |
| 3193 | .var_args_param, | |
| 3194 | 3185 | .bound_fn, |
| 3195 | 3186 | => unreachable, |
| 3196 | 3187 | |
| ... | ... | @@ -3295,7 +3286,6 @@ pub const Type = extern union { |
| 3295 | 3286 | .noreturn => unreachable, |
| 3296 | 3287 | .inferred_alloc_const => unreachable, |
| 3297 | 3288 | .inferred_alloc_mut => unreachable, |
| 3298 | .var_args_param => unreachable, | |
| 3299 | 3289 | .generic_poison => unreachable, |
| 3300 | 3290 | .modifier => unreachable, // missing call to resolveTypeFields |
| 3301 | 3291 | .prefetch_options => unreachable, // missing call to resolveTypeFields |
| ... | ... | @@ -3639,7 +3629,6 @@ pub const Type = extern union { |
| 3639 | 3629 | .inferred_alloc_const => unreachable, |
| 3640 | 3630 | .inferred_alloc_mut => unreachable, |
| 3641 | 3631 | .@"opaque" => unreachable, |
| 3642 | .var_args_param => unreachable, | |
| 3643 | 3632 | .generic_poison => unreachable, |
| 3644 | 3633 | .bound_fn => unreachable, |
| 3645 | 3634 | |
| ... | ... | @@ -4172,8 +4161,6 @@ pub const Type = extern union { |
| 4172 | 4161 | .single_const_pointer_to_comptime_int => Type.initTag(.comptime_int), |
| 4173 | 4162 | .pointer => ty.castTag(.pointer).?.data.pointee_type, |
| 4174 | 4163 | |
| 4175 | .var_args_param => ty, | |
| 4176 | ||
| 4177 | 4164 | else => unreachable, |
| 4178 | 4165 | }; |
| 4179 | 4166 | } |
| ... | ... | @@ -5032,7 +5019,6 @@ pub const Type = extern union { |
| 5032 | 5019 | .anyerror_void_error_union, |
| 5033 | 5020 | .error_set_inferred, |
| 5034 | 5021 | .@"opaque", |
| 5035 | .var_args_param, | |
| 5036 | 5022 | .manyptr_u8, |
| 5037 | 5023 | .manyptr_const_u8, |
| 5038 | 5024 | .manyptr_const_u8_sentinel_0, |
| ... | ... | @@ -5257,7 +5243,6 @@ pub const Type = extern union { |
| 5257 | 5243 | .function, |
| 5258 | 5244 | => true, |
| 5259 | 5245 | |
| 5260 | .var_args_param => unreachable, | |
| 5261 | 5246 | .inferred_alloc_mut => unreachable, |
| 5262 | 5247 | .inferred_alloc_const => unreachable, |
| 5263 | 5248 | .bound_fn => unreachable, |
| ... | ... | @@ -6088,9 +6073,6 @@ pub const Type = extern union { |
| 6088 | 6073 | const_slice_u8_sentinel_0, |
| 6089 | 6074 | anyerror_void_error_union, |
| 6090 | 6075 | generic_poison, |
| 6091 | /// This is a special type for variadic parameters of a function call. | |
| 6092 | /// Casts to it will validate that the type can be passed to a c calling convention function. | |
| 6093 | var_args_param, | |
| 6094 | 6076 | /// Same as `empty_struct` except it has an empty namespace. |
| 6095 | 6077 | empty_struct_literal, |
| 6096 | 6078 | /// This is a special value that tracks a set of types that have been stored |
| ... | ... | @@ -6201,7 +6183,6 @@ pub const Type = extern union { |
| 6201 | 6183 | .generic_poison, |
| 6202 | 6184 | .inferred_alloc_const, |
| 6203 | 6185 | .inferred_alloc_mut, |
| 6204 | .var_args_param, | |
| 6205 | 6186 | .empty_struct_literal, |
| 6206 | 6187 | .manyptr_u8, |
| 6207 | 6188 | .manyptr_const_u8, |