authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-02-26 20:50:45-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-02-26 21:35:30-07:00
log5f3b21a5b6895bd2bfc7144a038a4b7b60313736
treea297b2bea36043bab867eec337303fc1ddab03f1
parentf7143e18e368eb89763e9d813b8b7c9c96dd1bd3

Zir: decouple from InternPool

Note that the correctness of these enum tag values is still protected by the comptime logic at the top of Zcu (currently src/Module.zig).

2 files changed, 92 insertions(+), 91 deletions(-)

src/InternPool.zig+1-1
......@@ -2858,7 +2858,7 @@ pub const static_keys = [_]Key{
28582858/// This is specified with an integer literal and a corresponding comptime
28592859/// assert below to break an unfortunate and arguably incorrect dependency loop
28602860/// when compiling.
2861pub const static_len = 84;
2861pub const static_len = Zir.Inst.Index.static_len;
28622862comptime {
28632863 //@compileLog(static_keys.len);
28642864 assert(static_len == static_keys.len);
src/Zir.zig+91-90
......@@ -19,9 +19,7 @@ const BigIntConst = std.math.big.int.Const;
1919const BigIntMutable = std.math.big.int.Mutable;
2020const Ast = std.zig.Ast;
2121
22const InternPool = @import("InternPool.zig");
2322const Zir = @This();
24const Module = @import("Module.zig");
2523const LazySrcLoc = std.zig.LazySrcLoc;
2624
2725instructions: std.MultiArrayList(Inst).Slice,
......@@ -2093,9 +2091,11 @@ pub const Inst = struct {
20932091 /// ZIR is structured so that the outermost "main" struct of any file
20942092 /// is always at index 0.
20952093 main_struct_inst = 0,
2096 ref_start_index = InternPool.static_len,
2094 ref_start_index = static_len,
20972095 _,
20982096
2097 pub const static_len = 84;
2098
20992099 pub fn toRef(i: Index) Inst.Ref {
21002100 return @enumFromInt(@intFromEnum(Index.ref_start_index) + @intFromEnum(i));
21012101 }
......@@ -2109,7 +2109,7 @@ pub const Inst = struct {
21092109 /// ZIR is structured so that the outermost "main" struct of any file
21102110 /// is always at index 0.
21112111 main_struct_inst = 0,
2112 ref_start_index = InternPool.static_len,
2112 ref_start_index = Index.static_len,
21132113 none = std.math.maxInt(u32),
21142114 _,
21152115
......@@ -2127,97 +2127,98 @@ pub const Inst = struct {
21272127 /// The tag type is specified so that it is safe to bitcast between `[]u32`
21282128 /// and `[]Ref`.
21292129 pub const Ref = enum(u32) {
2130 u0_type = @intFromEnum(InternPool.Index.u0_type),
2131 i0_type = @intFromEnum(InternPool.Index.i0_type),
2132 u1_type = @intFromEnum(InternPool.Index.u1_type),
2133 u8_type = @intFromEnum(InternPool.Index.u8_type),
2134 i8_type = @intFromEnum(InternPool.Index.i8_type),
2135 u16_type = @intFromEnum(InternPool.Index.u16_type),
2136 i16_type = @intFromEnum(InternPool.Index.i16_type),
2137 u29_type = @intFromEnum(InternPool.Index.u29_type),
2138 u32_type = @intFromEnum(InternPool.Index.u32_type),
2139 i32_type = @intFromEnum(InternPool.Index.i32_type),
2140 u64_type = @intFromEnum(InternPool.Index.u64_type),
2141 i64_type = @intFromEnum(InternPool.Index.i64_type),
2142 u80_type = @intFromEnum(InternPool.Index.u80_type),
2143 u128_type = @intFromEnum(InternPool.Index.u128_type),
2144 i128_type = @intFromEnum(InternPool.Index.i128_type),
2145 usize_type = @intFromEnum(InternPool.Index.usize_type),
2146 isize_type = @intFromEnum(InternPool.Index.isize_type),
2147 c_char_type = @intFromEnum(InternPool.Index.c_char_type),
2148 c_short_type = @intFromEnum(InternPool.Index.c_short_type),
2149 c_ushort_type = @intFromEnum(InternPool.Index.c_ushort_type),
2150 c_int_type = @intFromEnum(InternPool.Index.c_int_type),
2151 c_uint_type = @intFromEnum(InternPool.Index.c_uint_type),
2152 c_long_type = @intFromEnum(InternPool.Index.c_long_type),
2153 c_ulong_type = @intFromEnum(InternPool.Index.c_ulong_type),
2154 c_longlong_type = @intFromEnum(InternPool.Index.c_longlong_type),
2155 c_ulonglong_type = @intFromEnum(InternPool.Index.c_ulonglong_type),
2156 c_longdouble_type = @intFromEnum(InternPool.Index.c_longdouble_type),
2157 f16_type = @intFromEnum(InternPool.Index.f16_type),
2158 f32_type = @intFromEnum(InternPool.Index.f32_type),
2159 f64_type = @intFromEnum(InternPool.Index.f64_type),
2160 f80_type = @intFromEnum(InternPool.Index.f80_type),
2161 f128_type = @intFromEnum(InternPool.Index.f128_type),
2162 anyopaque_type = @intFromEnum(InternPool.Index.anyopaque_type),
2163 bool_type = @intFromEnum(InternPool.Index.bool_type),
2164 void_type = @intFromEnum(InternPool.Index.void_type),
2165 type_type = @intFromEnum(InternPool.Index.type_type),
2166 anyerror_type = @intFromEnum(InternPool.Index.anyerror_type),
2167 comptime_int_type = @intFromEnum(InternPool.Index.comptime_int_type),
2168 comptime_float_type = @intFromEnum(InternPool.Index.comptime_float_type),
2169 noreturn_type = @intFromEnum(InternPool.Index.noreturn_type),
2170 anyframe_type = @intFromEnum(InternPool.Index.anyframe_type),
2171 null_type = @intFromEnum(InternPool.Index.null_type),
2172 undefined_type = @intFromEnum(InternPool.Index.undefined_type),
2173 enum_literal_type = @intFromEnum(InternPool.Index.enum_literal_type),
2174 atomic_order_type = @intFromEnum(InternPool.Index.atomic_order_type),
2175 atomic_rmw_op_type = @intFromEnum(InternPool.Index.atomic_rmw_op_type),
2176 calling_convention_type = @intFromEnum(InternPool.Index.calling_convention_type),
2177 address_space_type = @intFromEnum(InternPool.Index.address_space_type),
2178 float_mode_type = @intFromEnum(InternPool.Index.float_mode_type),
2179 reduce_op_type = @intFromEnum(InternPool.Index.reduce_op_type),
2180 call_modifier_type = @intFromEnum(InternPool.Index.call_modifier_type),
2181 prefetch_options_type = @intFromEnum(InternPool.Index.prefetch_options_type),
2182 export_options_type = @intFromEnum(InternPool.Index.export_options_type),
2183 extern_options_type = @intFromEnum(InternPool.Index.extern_options_type),
2184 type_info_type = @intFromEnum(InternPool.Index.type_info_type),
2185 manyptr_u8_type = @intFromEnum(InternPool.Index.manyptr_u8_type),
2186 manyptr_const_u8_type = @intFromEnum(InternPool.Index.manyptr_const_u8_type),
2187 manyptr_const_u8_sentinel_0_type = @intFromEnum(InternPool.Index.manyptr_const_u8_sentinel_0_type),
2188 single_const_pointer_to_comptime_int_type = @intFromEnum(InternPool.Index.single_const_pointer_to_comptime_int_type),
2189 slice_const_u8_type = @intFromEnum(InternPool.Index.slice_const_u8_type),
2190 slice_const_u8_sentinel_0_type = @intFromEnum(InternPool.Index.slice_const_u8_sentinel_0_type),
2191 optional_noreturn_type = @intFromEnum(InternPool.Index.optional_noreturn_type),
2192 anyerror_void_error_union_type = @intFromEnum(InternPool.Index.anyerror_void_error_union_type),
2193 adhoc_inferred_error_set_type = @intFromEnum(InternPool.Index.adhoc_inferred_error_set_type),
2194 generic_poison_type = @intFromEnum(InternPool.Index.generic_poison_type),
2195 empty_struct_type = @intFromEnum(InternPool.Index.empty_struct_type),
2196 undef = @intFromEnum(InternPool.Index.undef),
2197 zero = @intFromEnum(InternPool.Index.zero),
2198 zero_usize = @intFromEnum(InternPool.Index.zero_usize),
2199 zero_u8 = @intFromEnum(InternPool.Index.zero_u8),
2200 one = @intFromEnum(InternPool.Index.one),
2201 one_usize = @intFromEnum(InternPool.Index.one_usize),
2202 one_u8 = @intFromEnum(InternPool.Index.one_u8),
2203 four_u8 = @intFromEnum(InternPool.Index.four_u8),
2204 negative_one = @intFromEnum(InternPool.Index.negative_one),
2205 calling_convention_c = @intFromEnum(InternPool.Index.calling_convention_c),
2206 calling_convention_inline = @intFromEnum(InternPool.Index.calling_convention_inline),
2207 void_value = @intFromEnum(InternPool.Index.void_value),
2208 unreachable_value = @intFromEnum(InternPool.Index.unreachable_value),
2209 null_value = @intFromEnum(InternPool.Index.null_value),
2210 bool_true = @intFromEnum(InternPool.Index.bool_true),
2211 bool_false = @intFromEnum(InternPool.Index.bool_false),
2212 empty_struct = @intFromEnum(InternPool.Index.empty_struct),
2213 generic_poison = @intFromEnum(InternPool.Index.generic_poison),
2130 u0_type,
2131 i0_type,
2132 u1_type,
2133 u8_type,
2134 i8_type,
2135 u16_type,
2136 i16_type,
2137 u29_type,
2138 u32_type,
2139 i32_type,
2140 u64_type,
2141 i64_type,
2142 u80_type,
2143 u128_type,
2144 i128_type,
2145 usize_type,
2146 isize_type,
2147 c_char_type,
2148 c_short_type,
2149 c_ushort_type,
2150 c_int_type,
2151 c_uint_type,
2152 c_long_type,
2153 c_ulong_type,
2154 c_longlong_type,
2155 c_ulonglong_type,
2156 c_longdouble_type,
2157 f16_type,
2158 f32_type,
2159 f64_type,
2160 f80_type,
2161 f128_type,
2162 anyopaque_type,
2163 bool_type,
2164 void_type,
2165 type_type,
2166 anyerror_type,
2167 comptime_int_type,
2168 comptime_float_type,
2169 noreturn_type,
2170 anyframe_type,
2171 null_type,
2172 undefined_type,
2173 enum_literal_type,
2174 atomic_order_type,
2175 atomic_rmw_op_type,
2176 calling_convention_type,
2177 address_space_type,
2178 float_mode_type,
2179 reduce_op_type,
2180 call_modifier_type,
2181 prefetch_options_type,
2182 export_options_type,
2183 extern_options_type,
2184 type_info_type,
2185 manyptr_u8_type,
2186 manyptr_const_u8_type,
2187 manyptr_const_u8_sentinel_0_type,
2188 single_const_pointer_to_comptime_int_type,
2189 slice_const_u8_type,
2190 slice_const_u8_sentinel_0_type,
2191 optional_noreturn_type,
2192 anyerror_void_error_union_type,
2193 adhoc_inferred_error_set_type,
2194 generic_poison_type,
2195 empty_struct_type,
2196 undef,
2197 zero,
2198 zero_usize,
2199 zero_u8,
2200 one,
2201 one_usize,
2202 one_u8,
2203 four_u8,
2204 negative_one,
2205 calling_convention_c,
2206 calling_convention_inline,
2207 void_value,
2208 unreachable_value,
2209 null_value,
2210 bool_true,
2211 bool_false,
2212 empty_struct,
2213 generic_poison,
22142214
22152215 /// This tag is here to match Air and InternPool, however it is unused
22162216 /// for ZIR purposes.
2217 var_args_param_type = @intFromEnum(InternPool.Index.var_args_param_type),
2217 var_args_param_type = std.math.maxInt(u32) - 1,
22182218 /// This Ref does not correspond to any ZIR instruction or constant
22192219 /// value and may instead be used as a sentinel to indicate null.
2220 none = @intFromEnum(InternPool.Index.none),
2220 none = std.math.maxInt(u32),
2221
22212222 _,
22222223
22232224 pub fn toIndex(inst: Ref) ?Index {