diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2024-08-18 17:57:28 +0100 |
|---|---|---|
| committer | mlugg <mlugg@mlugg.co.uk> | 2024-08-18 18:10:59 +0100 |
| commit | de49a9a17352a36a0888b03905f207b0584fc269 (patch) | |
| tree | ebda829424b7df833084bc0f8275815d42a6eeec /src/Type.zig | |
| parent | a239d8d4e2c0e5a7f3eb4b9973f869afdb3bbe05 (diff) | |
| download | zig-de49a9a17352a36a0888b03905f207b0584fc269.tar.gz zig-de49a9a17352a36a0888b03905f207b0584fc269.zip | |
Zir: add instructions to fetch std.builtin types
This replaces the constant `Zir.Inst.Ref` tags (and the analagous tags
in `Air.Inst.Ref`, `InternPool.Index`) referring to types in
`std.builtin` with a ZIR instruction `extended(builtin_type(...))` which
instructs Sema to fetch such a type, effectively as if it were a
shorthand for the ZIR for `@import("std").builtin.xyz`.
Previously, this was achieved through constant tags in `Ref`. The
analagous `InternPool` indices began as `simple_type` values, and were
later rewritten to the correct type information. This system was kind of
brittle, and more importantly, isn't compatible with incremental
compilation of std, since incremental compilation relies on the ability
to recreate types at different indices when they change. Replacing the
old system with this instruction slightly increases the size of ZIR, but
it simplifies logic and allows incremental compilation to work correctly
on the standard library.
This shouldn't have a significant impact on ZIR size or compiler
performance, but I will take measurements in the PR to confirm this.
Diffstat (limited to 'src/Type.zig')
| -rw-r--r-- | src/Type.zig | 130 |
1 files changed, 1 insertions, 129 deletions
diff --git a/src/Type.zig b/src/Type.zig index c113e0734e..0a37e5a6f5 100644 --- a/src/Type.zig +++ b/src/Type.zig @@ -316,17 +316,6 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error => try writer.print("@TypeOf({s})", .{@tagName(s)}), .enum_literal => try writer.print("@TypeOf(.{s})", .{@tagName(s)}), - .atomic_order => try writer.writeAll("std.builtin.AtomicOrder"), - .atomic_rmw_op => try writer.writeAll("std.builtin.AtomicRmwOp"), - .calling_convention => try writer.writeAll("std.builtin.CallingConvention"), - .address_space => try writer.writeAll("std.builtin.AddressSpace"), - .float_mode => try writer.writeAll("std.builtin.FloatMode"), - .reduce_op => try writer.writeAll("std.builtin.ReduceOp"), - .call_modifier => try writer.writeAll("std.builtin.CallModifier"), - .prefetch_options => try writer.writeAll("std.builtin.PrefetchOptions"), - .export_options => try writer.writeAll("std.builtin.ExportOptions"), - .extern_options => try writer.writeAll("std.builtin.ExternOptions"), - .type_info => try writer.writeAll("std.builtin.Type"), .generic_poison => unreachable, }, @@ -544,16 +533,6 @@ pub fn hasRuntimeBitsAdvanced( .anyerror, .adhoc_inferred_error_set, .anyopaque, - .atomic_order, - .atomic_rmw_op, - .calling_convention, - .address_space, - .float_mode, - .reduce_op, - .call_modifier, - .prefetch_options, - .export_options, - .extern_options, => true, // These are false because they are comptime-only types. @@ -565,7 +544,6 @@ pub fn hasRuntimeBitsAdvanced( .null, .undefined, .enum_literal, - .type_info, => false, .generic_poison => unreachable, @@ -711,16 +689,6 @@ pub fn hasWellDefinedLayout(ty: Type, mod: *Module) bool { .anyerror, .adhoc_inferred_error_set, .anyopaque, - .atomic_order, - .atomic_rmw_op, - .calling_convention, - .address_space, - .float_mode, - .reduce_op, - .call_modifier, - .prefetch_options, - .export_options, - .extern_options, .type, .comptime_int, .comptime_float, @@ -728,7 +696,6 @@ pub fn hasWellDefinedLayout(ty: Type, mod: *Module) bool { .null, .undefined, .enum_literal, - .type_info, .generic_poison, => false, }, @@ -972,14 +939,6 @@ pub fn abiAlignmentAdvanced( .simple_type => |t| switch (t) { .bool, - .atomic_order, - .atomic_rmw_op, - .calling_convention, - .address_space, - .float_mode, - .reduce_op, - .call_modifier, - .prefetch_options, .anyopaque, => return .{ .scalar = .@"1" }, @@ -987,11 +946,6 @@ pub fn abiAlignmentAdvanced( .isize, => return .{ .scalar = intAbiAlignment(target.ptrBitWidth(), target, use_llvm) }, - .export_options, - .extern_options, - .type_info, - => return .{ .scalar = ptrAbiAlignment(target) }, - .c_char => return .{ .scalar = cTypeAlign(target, .char) }, .c_short => return .{ .scalar = cTypeAlign(target, .short) }, .c_ushort => return .{ .scalar = cTypeAlign(target, .ushort) }, @@ -1352,15 +1306,7 @@ pub fn abiSizeAdvanced( }, .func_type => unreachable, // represents machine code; not a pointer .simple_type => |t| switch (t) { - .bool, - .atomic_order, - .atomic_rmw_op, - .calling_convention, - .address_space, - .float_mode, - .reduce_op, - .call_modifier, - => return .{ .scalar = 1 }, + .bool => return .{ .scalar = 1 }, .f16 => return .{ .scalar = 2 }, .f32 => return .{ .scalar = 4 }, @@ -1402,11 +1348,6 @@ pub fn abiSizeAdvanced( return .{ .scalar = intAbiSize(bits, target, use_llvm) }; }, - .prefetch_options => unreachable, // missing call to resolveTypeFields - .export_options => unreachable, // missing call to resolveTypeFields - .extern_options => unreachable, // missing call to resolveTypeFields - - .type_info => unreachable, .noreturn => unreachable, .generic_poison => unreachable, }, @@ -1751,18 +1692,6 @@ pub fn bitSizeAdvanced( .undefined => unreachable, .enum_literal => unreachable, .generic_poison => unreachable, - - .atomic_order => unreachable, - .atomic_rmw_op => unreachable, - .calling_convention => unreachable, - .address_space => unreachable, - .float_mode => unreachable, - .reduce_op => unreachable, - .call_modifier => unreachable, - .prefetch_options => unreachable, - .export_options => unreachable, - .extern_options => unreachable, - .type_info => unreachable, }, .struct_type => { const struct_type = ip.loadStructType(ty.toIntern()); @@ -2565,17 +2494,6 @@ pub fn onePossibleValue(starting_type: Type, pt: Zcu.PerThread) !?Value { .comptime_int, .comptime_float, .enum_literal, - .atomic_order, - .atomic_rmw_op, - .calling_convention, - .address_space, - .float_mode, - .reduce_op, - .call_modifier, - .prefetch_options, - .export_options, - .extern_options, - .type_info, .adhoc_inferred_error_set, => return null, @@ -2782,16 +2700,6 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: Resolve .adhoc_inferred_error_set, .noreturn, .generic_poison, - .atomic_order, - .atomic_rmw_op, - .calling_convention, - .address_space, - .float_mode, - .reduce_op, - .call_modifier, - .prefetch_options, - .export_options, - .extern_options, => false, .type, @@ -2800,7 +2708,6 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: Resolve .null, .undefined, .enum_literal, - .type_info, => true, }, .struct_type => { @@ -3534,10 +3441,6 @@ pub fn packedStructFieldPtrInfo(struct_ty: Type, parent_ptr_ty: Type, field_idx: pub fn resolveLayout(ty: Type, pt: Zcu.PerThread) SemaError!void { const zcu = pt.zcu; const ip = &zcu.intern_pool; - switch (ip.indexToKey(ty.toIntern())) { - .simple_type => |simple_type| return resolveSimpleType(simple_type, pt), - else => {}, - } switch (ty.zigTypeTag(zcu)) { .Struct => switch (ip.indexToKey(ty.toIntern())) { .anon_struct_type => |anon_struct_type| for (0..anon_struct_type.types.len) |i| { @@ -3651,8 +3554,6 @@ pub fn resolveFields(ty: Type, pt: Zcu.PerThread) SemaError!void { .one_u8 => unreachable, .four_u8 => unreachable, .negative_one => unreachable, - .calling_convention_c => unreachable, - .calling_convention_inline => unreachable, .void_value => unreachable, .unreachable_value => unreachable, .null_value => unreachable, @@ -3669,8 +3570,6 @@ pub fn resolveFields(ty: Type, pt: Zcu.PerThread) SemaError!void { .type_union => return ty.resolveUnionInner(pt, .fields), - .simple_type => return resolveSimpleType(ip.indexToKey(ty_ip).simple_type, pt), - else => {}, }, } @@ -3680,11 +3579,6 @@ pub fn resolveFully(ty: Type, pt: Zcu.PerThread) SemaError!void { const zcu = pt.zcu; const ip = &zcu.intern_pool; - switch (ip.indexToKey(ty.toIntern())) { - .simple_type => |simple_type| return resolveSimpleType(simple_type, pt), - else => {}, - } - switch (ty.zigTypeTag(zcu)) { .Type, .Void, @@ -3850,28 +3744,6 @@ fn resolveUnionInner( }; } -/// Fully resolves a simple type. This is usually a nop, but for builtin types with -/// special InternPool indices (such as std.builtin.Type) it will analyze and fully -/// resolve the type. -fn resolveSimpleType(simple_type: InternPool.SimpleType, pt: Zcu.PerThread) Allocator.Error!void { - const builtin_type_name: []const u8 = switch (simple_type) { - .atomic_order => "AtomicOrder", - .atomic_rmw_op => "AtomicRmwOp", - .calling_convention => "CallingConvention", - .address_space => "AddressSpace", - .float_mode => "FloatMode", - .reduce_op => "ReduceOp", - .call_modifier => "CallModifer", - .prefetch_options => "PrefetchOptions", - .export_options => "ExportOptions", - .extern_options => "ExternOptions", - .type_info => "Type", - else => return, - }; - // This will fully resolve the type. - _ = try pt.getBuiltinType(builtin_type_name); -} - /// Returns the type of a pointer to an element. /// Asserts that the type is a pointer, and that the element type is indexable. /// If the element index is comptime-known, it must be passed in `offset`. |
