| ... | @@ -222,6 +222,11 @@ pub const Key = union(enum) { | ... | @@ -222,6 +222,11 @@ pub const Key = union(enum) { |
| 222 | /// A comptime function call with a memoized result. | 222 | /// A comptime function call with a memoized result. |
| 223 | memoized_call: Key.MemoizedCall, | 223 | memoized_call: Key.MemoizedCall, |
| 224 | | 224 | |
| | 225 | pub const TypeValue = struct { |
| | 226 | ty: Index, |
| | 227 | val: Index, |
| | 228 | }; |
| | 229 | |
| 225 | pub const IntType = std.builtin.Type.Int; | 230 | pub const IntType = std.builtin.Type.Int; |
| 226 | | 231 | |
| 227 | pub const ErrorUnionType = struct { | 232 | pub const ErrorUnionType = struct { |
| ... | @@ -1372,7 +1377,7 @@ pub const Index = enum(u32) { | ... | @@ -1372,7 +1377,7 @@ pub const Index = enum(u32) { |
| 1372 | }, | 1377 | }, |
| 1373 | | 1378 | |
| 1374 | undef: DataIsIndex, | 1379 | undef: DataIsIndex, |
| 1375 | runtime_value: DataIsIndex, | 1380 | runtime_value: struct { data: *Tag.TypeValue }, |
| 1376 | simple_value: struct { data: SimpleValue }, | 1381 | simple_value: struct { data: SimpleValue }, |
| 1377 | ptr_decl: struct { data: *PtrDecl }, | 1382 | ptr_decl: struct { data: *PtrDecl }, |
| 1378 | ptr_mut_decl: struct { data: *PtrMutDecl }, | 1383 | ptr_mut_decl: struct { data: *PtrMutDecl }, |
| ... | @@ -1383,7 +1388,7 @@ pub const Index = enum(u32) { | ... | @@ -1383,7 +1388,7 @@ pub const Index = enum(u32) { |
| 1383 | ptr_elem: struct { data: *PtrBaseIndex }, | 1388 | ptr_elem: struct { data: *PtrBaseIndex }, |
| 1384 | ptr_field: struct { data: *PtrBaseIndex }, | 1389 | ptr_field: struct { data: *PtrBaseIndex }, |
| 1385 | ptr_slice: struct { data: *PtrSlice }, | 1390 | ptr_slice: struct { data: *PtrSlice }, |
| 1386 | opt_payload: struct { data: *TypeValue }, | 1391 | opt_payload: struct { data: *Tag.TypeValue }, |
| 1387 | opt_null: DataIsIndex, | 1392 | opt_null: DataIsIndex, |
| 1388 | int_u8: struct { data: u8 }, | 1393 | int_u8: struct { data: u8 }, |
| 1389 | int_u16: struct { data: u16 }, | 1394 | int_u16: struct { data: u16 }, |
| ... | @@ -1399,7 +1404,7 @@ pub const Index = enum(u32) { | ... | @@ -1399,7 +1404,7 @@ pub const Index = enum(u32) { |
| 1399 | int_lazy_size: struct { data: *IntLazy }, | 1404 | int_lazy_size: struct { data: *IntLazy }, |
| 1400 | error_set_error: struct { data: *Key.Error }, | 1405 | error_set_error: struct { data: *Key.Error }, |
| 1401 | error_union_error: struct { data: *Key.Error }, | 1406 | error_union_error: struct { data: *Key.Error }, |
| 1402 | error_union_payload: struct { data: *TypeValue }, | 1407 | error_union_payload: struct { data: *Tag.TypeValue }, |
| 1403 | enum_literal: struct { data: NullTerminatedString }, | 1408 | enum_literal: struct { data: NullTerminatedString }, |
| 1404 | enum_tag: struct { data: *Key.EnumTag }, | 1409 | enum_tag: struct { data: *Key.EnumTag }, |
| 1405 | float_f16: struct { data: f16 }, | 1410 | float_f16: struct { data: f16 }, |
| ... | @@ -1410,7 +1415,7 @@ pub const Index = enum(u32) { | ... | @@ -1410,7 +1415,7 @@ pub const Index = enum(u32) { |
| 1410 | float_c_longdouble_f80: struct { data: *Float80 }, | 1415 | float_c_longdouble_f80: struct { data: *Float80 }, |
| 1411 | float_c_longdouble_f128: struct { data: *Float128 }, | 1416 | float_c_longdouble_f128: struct { data: *Float128 }, |
| 1412 | float_comptime_float: struct { data: *Float128 }, | 1417 | float_comptime_float: struct { data: *Float128 }, |
| 1413 | variable: struct { data: *Variable }, | 1418 | variable: struct { data: *Tag.Variable }, |
| 1414 | extern_func: struct { data: *Key.ExternFunc }, | 1419 | extern_func: struct { data: *Key.ExternFunc }, |
| 1415 | func: struct { data: *Key.Func }, | 1420 | func: struct { data: *Key.Func }, |
| 1416 | only_possible_value: DataIsIndex, | 1421 | only_possible_value: DataIsIndex, |
| ... | @@ -1769,7 +1774,7 @@ pub const Tag = enum(u8) { | ... | @@ -1769,7 +1774,7 @@ pub const Tag = enum(u8) { |
| 1769 | undef, | 1774 | undef, |
| 1770 | /// A wrapper for values which are comptime-known but should | 1775 | /// A wrapper for values which are comptime-known but should |
| 1771 | /// semantically be runtime-known. | 1776 | /// semantically be runtime-known. |
| 1772 | /// `data` is `Index` of the value. | 1777 | /// data is extra index of `TypeValue`. |
| 1773 | runtime_value, | 1778 | runtime_value, |
| 1774 | /// A value that can be represented with only an enum tag. | 1779 | /// A value that can be represented with only an enum tag. |
| 1775 | /// data is SimpleValue enum value. | 1780 | /// data is SimpleValue enum value. |
| ... | @@ -1924,8 +1929,117 @@ pub const Tag = enum(u8) { | ... | @@ -1924,8 +1929,117 @@ pub const Tag = enum(u8) { |
| 1924 | /// data is extra index to `Key.MemoizedDecl` | 1929 | /// data is extra index to `Key.MemoizedDecl` |
| 1925 | memoized_decl, | 1930 | memoized_decl, |
| 1926 | /// A memoized comptime function call result. | 1931 | /// A memoized comptime function call result. |
| 1927 | /// data is extra index to `MemoizedFunc` | 1932 | /// data is extra index to `MemoizedCall` |
| 1928 | memoized_call, | 1933 | memoized_call, |
| | 1934 | |
| | 1935 | const ErrorUnionType = Key.ErrorUnionType; |
| | 1936 | const OpaqueType = Key.OpaqueType; |
| | 1937 | const TypeValue = Key.TypeValue; |
| | 1938 | const Error = Key.Error; |
| | 1939 | const EnumTag = Key.EnumTag; |
| | 1940 | const ExternFunc = Key.ExternFunc; |
| | 1941 | const Func = Key.Func; |
| | 1942 | const Union = Key.Union; |
| | 1943 | const MemoizedDecl = Key.MemoizedDecl; |
| | 1944 | |
| | 1945 | fn Payload(comptime tag: Tag) type { |
| | 1946 | return switch (tag) { |
| | 1947 | .type_int_signed => unreachable, |
| | 1948 | .type_int_unsigned => unreachable, |
| | 1949 | .type_array_big => Array, |
| | 1950 | .type_array_small => Vector, |
| | 1951 | .type_vector => Vector, |
| | 1952 | .type_pointer => Pointer, |
| | 1953 | .type_slice => unreachable, |
| | 1954 | .type_optional => unreachable, |
| | 1955 | .type_anyframe => unreachable, |
| | 1956 | .type_error_union => ErrorUnionType, |
| | 1957 | .type_error_set => ErrorSet, |
| | 1958 | .type_inferred_error_set => unreachable, |
| | 1959 | .type_enum_auto => EnumAuto, |
| | 1960 | .type_enum_explicit => EnumExplicit, |
| | 1961 | .type_enum_nonexhaustive => EnumExplicit, |
| | 1962 | .simple_type => unreachable, |
| | 1963 | .type_opaque => OpaqueType, |
| | 1964 | .type_struct => unreachable, |
| | 1965 | .type_struct_ns => unreachable, |
| | 1966 | .type_struct_anon => TypeStructAnon, |
| | 1967 | .type_tuple_anon => TypeStructAnon, |
| | 1968 | .type_union_tagged => unreachable, |
| | 1969 | .type_union_untagged => unreachable, |
| | 1970 | .type_union_safety => unreachable, |
| | 1971 | .type_function => TypeFunction, |
| | 1972 | |
| | 1973 | .undef => unreachable, |
| | 1974 | .runtime_value => TypeValue, |
| | 1975 | .simple_value => unreachable, |
| | 1976 | .ptr_decl => PtrDecl, |
| | 1977 | .ptr_mut_decl => PtrMutDecl, |
| | 1978 | .ptr_comptime_field => PtrComptimeField, |
| | 1979 | .ptr_int => PtrBase, |
| | 1980 | .ptr_eu_payload => PtrBase, |
| | 1981 | .ptr_opt_payload => PtrBase, |
| | 1982 | .ptr_elem => PtrBaseIndex, |
| | 1983 | .ptr_field => PtrBaseIndex, |
| | 1984 | .ptr_slice => PtrSlice, |
| | 1985 | .opt_payload => TypeValue, |
| | 1986 | .opt_null => unreachable, |
| | 1987 | .int_u8 => unreachable, |
| | 1988 | .int_u16 => unreachable, |
| | 1989 | .int_u32 => unreachable, |
| | 1990 | .int_i32 => unreachable, |
| | 1991 | .int_usize => unreachable, |
| | 1992 | .int_comptime_int_u32 => unreachable, |
| | 1993 | .int_comptime_int_i32 => unreachable, |
| | 1994 | .int_small => IntSmall, |
| | 1995 | .int_positive => unreachable, |
| | 1996 | .int_negative => unreachable, |
| | 1997 | .int_lazy_align => IntLazy, |
| | 1998 | .int_lazy_size => IntLazy, |
| | 1999 | .error_set_error => Error, |
| | 2000 | .error_union_error => Error, |
| | 2001 | .error_union_payload => TypeValue, |
| | 2002 | .enum_literal => unreachable, |
| | 2003 | .enum_tag => EnumTag, |
| | 2004 | .float_f16 => unreachable, |
| | 2005 | .float_f32 => unreachable, |
| | 2006 | .float_f64 => unreachable, |
| | 2007 | .float_f80 => unreachable, |
| | 2008 | .float_f128 => unreachable, |
| | 2009 | .float_c_longdouble_f80 => unreachable, |
| | 2010 | .float_c_longdouble_f128 => unreachable, |
| | 2011 | .float_comptime_float => unreachable, |
| | 2012 | .variable => Variable, |
| | 2013 | .extern_func => ExternFunc, |
| | 2014 | .func => Func, |
| | 2015 | .only_possible_value => unreachable, |
| | 2016 | .union_value => Union, |
| | 2017 | .bytes => Bytes, |
| | 2018 | .aggregate => Aggregate, |
| | 2019 | .repeated => Repeated, |
| | 2020 | .memoized_decl => MemoizedDecl, |
| | 2021 | .memoized_call => MemoizedCall, |
| | 2022 | }; |
| | 2023 | } |
| | 2024 | |
| | 2025 | pub const Variable = struct { |
| | 2026 | ty: Index, |
| | 2027 | /// May be `none`. |
| | 2028 | init: Index, |
| | 2029 | decl: Module.Decl.Index, |
| | 2030 | /// Library name if specified. |
| | 2031 | /// For example `extern "c" var stderrp = ...` would have 'c' as library name. |
| | 2032 | lib_name: OptionalNullTerminatedString, |
| | 2033 | flags: Flags, |
| | 2034 | |
| | 2035 | pub const Flags = packed struct(u32) { |
| | 2036 | is_extern: bool, |
| | 2037 | is_const: bool, |
| | 2038 | is_threadlocal: bool, |
| | 2039 | is_weak_linkage: bool, |
| | 2040 | _: u28 = 0, |
| | 2041 | }; |
| | 2042 | }; |
| 1929 | }; | 2043 | }; |
| 1930 | | 2044 | |
| 1931 | /// Trailing: | 2045 | /// Trailing: |
| ... | @@ -2137,11 +2251,6 @@ pub const Array = struct { | ... | @@ -2137,11 +2251,6 @@ pub const Array = struct { |
| 2137 | } | 2251 | } |
| 2138 | }; | 2252 | }; |
| 2139 | | 2253 | |
| 2140 | pub const TypeValue = struct { | | |
| 2141 | ty: Index, | | |
| 2142 | val: Index, | | |
| 2143 | }; | | |
| 2144 | | | |
| 2145 | /// Trailing: | 2254 | /// Trailing: |
| 2146 | /// 0. field name: NullTerminatedString for each fields_len; declaration order | 2255 | /// 0. field name: NullTerminatedString for each fields_len; declaration order |
| 2147 | /// 1. tag value: Index for each fields_len; declaration order | 2256 | /// 1. tag value: Index for each fields_len; declaration order |
| ... | @@ -2190,25 +2299,6 @@ pub const PackedU64 = packed struct(u64) { | ... | @@ -2190,25 +2299,6 @@ pub const PackedU64 = packed struct(u64) { |
| 2190 | } | 2299 | } |
| 2191 | }; | 2300 | }; |
| 2192 | | 2301 | |
| 2193 | pub const Variable = struct { | | |
| 2194 | /// This is a value if has_init is true, otherwise a type. | | |
| 2195 | init: Index, | | |
| 2196 | decl: Module.Decl.Index, | | |
| 2197 | /// Library name if specified. | | |
| 2198 | /// For example `extern "c" var stderrp = ...` would have 'c' as library name. | | |
| 2199 | lib_name: OptionalNullTerminatedString, | | |
| 2200 | flags: Flags, | | |
| 2201 | | | |
| 2202 | pub const Flags = packed struct(u32) { | | |
| 2203 | has_init: bool, | | |
| 2204 | is_extern: bool, | | |
| 2205 | is_const: bool, | | |
| 2206 | is_threadlocal: bool, | | |
| 2207 | is_weak_linkage: bool, | | |
| 2208 | _: u27 = 0, | | |
| 2209 | }; | | |
| 2210 | }; | | |
| 2211 | | | |
| 2212 | pub const PtrDecl = struct { | 2302 | pub const PtrDecl = struct { |
| 2213 | ty: Index, | 2303 | ty: Index, |
| 2214 | decl: Module.Decl.Index, | 2304 | decl: Module.Decl.Index, |
| ... | @@ -2569,19 +2659,13 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { | ... | @@ -2569,19 +2659,13 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { |
| 2569 | .type_function => .{ .func_type = ip.indexToKeyFuncType(data) }, | 2659 | .type_function => .{ .func_type = ip.indexToKeyFuncType(data) }, |
| 2570 | | 2660 | |
| 2571 | .undef => .{ .undef = @intToEnum(Index, data) }, | 2661 | .undef => .{ .undef = @intToEnum(Index, data) }, |
| 2572 | .runtime_value => { | 2662 | .runtime_value => .{ .runtime_value = ip.extraData(Tag.TypeValue, data) }, |
| 2573 | const val = @intToEnum(Index, data); | | |
| 2574 | return .{ .runtime_value = .{ | | |
| 2575 | .ty = ip.typeOf(val), | | |
| 2576 | .val = val, | | |
| 2577 | } }; | | |
| 2578 | }, | | |
| 2579 | .opt_null => .{ .opt = .{ | 2663 | .opt_null => .{ .opt = .{ |
| 2580 | .ty = @intToEnum(Index, data), | 2664 | .ty = @intToEnum(Index, data), |
| 2581 | .val = .none, | 2665 | .val = .none, |
| 2582 | } }, | 2666 | } }, |
| 2583 | .opt_payload => { | 2667 | .opt_payload => { |
| 2584 | const extra = ip.extraData(TypeValue, data); | 2668 | const extra = ip.extraData(Tag.TypeValue, data); |
| 2585 | return .{ .opt = .{ | 2669 | return .{ .opt = .{ |
| 2586 | .ty = extra.ty, | 2670 | .ty = extra.ty, |
| 2587 | .val = extra.val, | 2671 | .val = extra.val, |
| ... | @@ -2806,10 +2890,10 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { | ... | @@ -2806,10 +2890,10 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { |
| 2806 | .storage = .{ .f128 = ip.extraData(Float128, data).get() }, | 2890 | .storage = .{ .f128 = ip.extraData(Float128, data).get() }, |
| 2807 | } }, | 2891 | } }, |
| 2808 | .variable => { | 2892 | .variable => { |
| 2809 | const extra = ip.extraData(Variable, data); | 2893 | const extra = ip.extraData(Tag.Variable, data); |
| 2810 | return .{ .variable = .{ | 2894 | return .{ .variable = .{ |
| 2811 | .ty = if (extra.flags.has_init) ip.typeOf(extra.init) else extra.init, | 2895 | .ty = extra.ty, |
| 2812 | .init = if (extra.flags.has_init) extra.init else .none, | 2896 | .init = extra.init, |
| 2813 | .decl = extra.decl, | 2897 | .decl = extra.decl, |
| 2814 | .lib_name = extra.lib_name, | 2898 | .lib_name = extra.lib_name, |
| 2815 | .is_extern = extra.flags.is_extern, | 2899 | .is_extern = extra.flags.is_extern, |
| ... | @@ -2887,7 +2971,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { | ... | @@ -2887,7 +2971,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { |
| 2887 | } }; | 2971 | } }; |
| 2888 | }, | 2972 | }, |
| 2889 | .error_union_payload => { | 2973 | .error_union_payload => { |
| 2890 | const extra = ip.extraData(TypeValue, data); | 2974 | const extra = ip.extraData(Tag.TypeValue, data); |
| 2891 | return .{ .error_union = .{ | 2975 | return .{ .error_union = .{ |
| 2892 | .ty = extra.ty, | 2976 | .ty = extra.ty, |
| 2893 | .val = .{ .payload = extra.val }, | 2977 | .val = .{ .payload = extra.val }, |
| ... | @@ -3124,7 +3208,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { | ... | @@ -3124,7 +3208,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 3124 | assert(runtime_value.ty == ip.typeOf(runtime_value.val)); | 3208 | assert(runtime_value.ty == ip.typeOf(runtime_value.val)); |
| 3125 | ip.items.appendAssumeCapacity(.{ | 3209 | ip.items.appendAssumeCapacity(.{ |
| 3126 | .tag = .runtime_value, | 3210 | .tag = .runtime_value, |
| 3127 | .data = @enumToInt(runtime_value.val), | 3211 | .data = try ip.addExtra(gpa, runtime_value), |
| 3128 | }); | 3212 | }); |
| 3129 | }, | 3213 | }, |
| 3130 | | 3214 | |
| ... | @@ -3266,12 +3350,12 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { | ... | @@ -3266,12 +3350,12 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 3266 | if (has_init) assert(variable.ty == ip.typeOf(variable.init)); | 3350 | if (has_init) assert(variable.ty == ip.typeOf(variable.init)); |
| 3267 | ip.items.appendAssumeCapacity(.{ | 3351 | ip.items.appendAssumeCapacity(.{ |
| 3268 | .tag = .variable, | 3352 | .tag = .variable, |
| 3269 | .data = try ip.addExtra(gpa, Variable{ | 3353 | .data = try ip.addExtra(gpa, Tag.Variable{ |
| 3270 | .init = if (has_init) variable.init else variable.ty, | 3354 | .ty = variable.ty, |
| | 3355 | .init = variable.init, |
| 3271 | .decl = variable.decl, | 3356 | .decl = variable.decl, |
| 3272 | .lib_name = variable.lib_name, | 3357 | .lib_name = variable.lib_name, |
| 3273 | .flags = .{ | 3358 | .flags = .{ |
| 3274 | .has_init = has_init, | | |
| 3275 | .is_extern = variable.is_extern, | 3359 | .is_extern = variable.is_extern, |
| 3276 | .is_const = variable.is_const, | 3360 | .is_const = variable.is_const, |
| 3277 | .is_threadlocal = variable.is_threadlocal, | 3361 | .is_threadlocal = variable.is_threadlocal, |
| ... | @@ -3431,7 +3515,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { | ... | @@ -3431,7 +3515,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 3431 | .data = @enumToInt(opt.ty), | 3515 | .data = @enumToInt(opt.ty), |
| 3432 | } else .{ | 3516 | } else .{ |
| 3433 | .tag = .opt_payload, | 3517 | .tag = .opt_payload, |
| 3434 | .data = try ip.addExtra(gpa, TypeValue{ | 3518 | .data = try ip.addExtra(gpa, Tag.TypeValue{ |
| 3435 | .ty = opt.ty, | 3519 | .ty = opt.ty, |
| 3436 | .val = opt.val, | 3520 | .val = opt.val, |
| 3437 | }), | 3521 | }), |
| ... | @@ -3642,7 +3726,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { | ... | @@ -3642,7 +3726,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 3642 | }, | 3726 | }, |
| 3643 | .payload => |payload| .{ | 3727 | .payload => |payload| .{ |
| 3644 | .tag = .error_union_payload, | 3728 | .tag = .error_union_payload, |
| 3645 | .data = try ip.addExtra(gpa, TypeValue{ | 3729 | .data = try ip.addExtra(gpa, Tag.TypeValue{ |
| 3646 | .ty = error_union.ty, | 3730 | .ty = error_union.ty, |
| 3647 | .val = payload, | 3731 | .val = payload, |
| 3648 | }), | 3732 | }), |
| ... | @@ -4222,7 +4306,7 @@ fn addExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 { | ... | @@ -4222,7 +4306,7 @@ fn addExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 { |
| 4222 | TypeFunction.Flags => @bitCast(u32, @field(extra, field.name)), | 4306 | TypeFunction.Flags => @bitCast(u32, @field(extra, field.name)), |
| 4223 | Pointer.PackedOffset => @bitCast(u32, @field(extra, field.name)), | 4307 | Pointer.PackedOffset => @bitCast(u32, @field(extra, field.name)), |
| 4224 | Pointer.VectorIndex => @enumToInt(@field(extra, field.name)), | 4308 | Pointer.VectorIndex => @enumToInt(@field(extra, field.name)), |
| 4225 | Variable.Flags => @bitCast(u32, @field(extra, field.name)), | 4309 | Tag.Variable.Flags => @bitCast(u32, @field(extra, field.name)), |
| 4226 | else => @compileError("bad field type: " ++ @typeName(field.type)), | 4310 | else => @compileError("bad field type: " ++ @typeName(field.type)), |
| 4227 | }); | 4311 | }); |
| 4228 | } | 4312 | } |
| ... | @@ -4290,7 +4374,7 @@ fn extraDataTrail(ip: InternPool, comptime T: type, index: usize) struct { data: | ... | @@ -4290,7 +4374,7 @@ fn extraDataTrail(ip: InternPool, comptime T: type, index: usize) struct { data: |
| 4290 | TypeFunction.Flags => @bitCast(TypeFunction.Flags, int32), | 4374 | TypeFunction.Flags => @bitCast(TypeFunction.Flags, int32), |
| 4291 | Pointer.PackedOffset => @bitCast(Pointer.PackedOffset, int32), | 4375 | Pointer.PackedOffset => @bitCast(Pointer.PackedOffset, int32), |
| 4292 | Pointer.VectorIndex => @intToEnum(Pointer.VectorIndex, int32), | 4376 | Pointer.VectorIndex => @intToEnum(Pointer.VectorIndex, int32), |
| 4293 | Variable.Flags => @bitCast(Variable.Flags, int32), | 4377 | Tag.Variable.Flags => @bitCast(Tag.Variable.Flags, int32), |
| 4294 | else => @compileError("bad field type: " ++ @typeName(field.type)), | 4378 | else => @compileError("bad field type: " ++ @typeName(field.type)), |
| 4295 | }; | 4379 | }; |
| 4296 | } | 4380 | } |
| ... | @@ -4737,7 +4821,7 @@ pub fn isAggregateType(ip: InternPool, ty: Index) bool { | ... | @@ -4737,7 +4821,7 @@ pub fn isAggregateType(ip: InternPool, ty: Index) bool { |
| 4737 | /// The is only legal because the initializer is not part of the hash. | 4821 | /// The is only legal because the initializer is not part of the hash. |
| 4738 | pub fn mutateVarInit(ip: *InternPool, index: Index, init_index: Index) void { | 4822 | pub fn mutateVarInit(ip: *InternPool, index: Index, init_index: Index) void { |
| 4739 | assert(ip.items.items(.tag)[@enumToInt(index)] == .variable); | 4823 | assert(ip.items.items(.tag)[@enumToInt(index)] == .variable); |
| 4740 | const field_index = inline for (@typeInfo(Variable).Struct.fields, 0..) |field, field_index| { | 4824 | const field_index = inline for (@typeInfo(Tag.Variable).Struct.fields, 0..) |field, field_index| { |
| 4741 | if (comptime std.mem.eql(u8, field.name, "init")) break field_index; | 4825 | if (comptime std.mem.eql(u8, field.name, "init")) break field_index; |
| 4742 | } else unreachable; | 4826 | } else unreachable; |
| 4743 | ip.extra.items[ip.items.items(.data)[@enumToInt(index)] + field_index] = @enumToInt(init_index); | 4827 | ip.extra.items[ip.items.items(.data)[@enumToInt(index)] + field_index] = @enumToInt(init_index); |
| ... | @@ -4847,7 +4931,7 @@ fn dumpFallible(ip: InternPool, arena: Allocator) anyerror!void { | ... | @@ -4847,7 +4931,7 @@ fn dumpFallible(ip: InternPool, arena: Allocator) anyerror!void { |
| 4847 | }, | 4931 | }, |
| 4848 | | 4932 | |
| 4849 | .undef => 0, | 4933 | .undef => 0, |
| 4850 | .runtime_value => 0, | 4934 | .runtime_value => @sizeOf(Tag.TypeValue), |
| 4851 | .simple_type => 0, | 4935 | .simple_type => 0, |
| 4852 | .simple_value => 0, | 4936 | .simple_value => 0, |
| 4853 | .ptr_decl => @sizeOf(PtrDecl), | 4937 | .ptr_decl => @sizeOf(PtrDecl), |
| ... | @@ -4860,7 +4944,7 @@ fn dumpFallible(ip: InternPool, arena: Allocator) anyerror!void { | ... | @@ -4860,7 +4944,7 @@ fn dumpFallible(ip: InternPool, arena: Allocator) anyerror!void { |
| 4860 | .ptr_field => @sizeOf(PtrBaseIndex), | 4944 | .ptr_field => @sizeOf(PtrBaseIndex), |
| 4861 | .ptr_slice => @sizeOf(PtrSlice), | 4945 | .ptr_slice => @sizeOf(PtrSlice), |
| 4862 | .opt_null => 0, | 4946 | .opt_null => 0, |
| 4863 | .opt_payload => @sizeOf(TypeValue), | 4947 | .opt_payload => @sizeOf(Tag.TypeValue), |
| 4864 | .int_u8 => 0, | 4948 | .int_u8 => 0, |
| 4865 | .int_u16 => 0, | 4949 | .int_u16 => 0, |
| 4866 | .int_u32 => 0, | 4950 | .int_u32 => 0, |
| ... | @@ -4880,7 +4964,7 @@ fn dumpFallible(ip: InternPool, arena: Allocator) anyerror!void { | ... | @@ -4880,7 +4964,7 @@ fn dumpFallible(ip: InternPool, arena: Allocator) anyerror!void { |
| 4880 | .int_lazy_align, .int_lazy_size => @sizeOf(IntLazy), | 4964 | .int_lazy_align, .int_lazy_size => @sizeOf(IntLazy), |
| 4881 | | 4965 | |
| 4882 | .error_set_error, .error_union_error => @sizeOf(Key.Error), | 4966 | .error_set_error, .error_union_error => @sizeOf(Key.Error), |
| 4883 | .error_union_payload => @sizeOf(TypeValue), | 4967 | .error_union_payload => @sizeOf(Tag.TypeValue), |
| 4884 | .enum_literal => 0, | 4968 | .enum_literal => 0, |
| 4885 | .enum_tag => @sizeOf(Key.EnumTag), | 4969 | .enum_tag => @sizeOf(Key.EnumTag), |
| 4886 | | 4970 | |
| ... | @@ -4905,7 +4989,7 @@ fn dumpFallible(ip: InternPool, arena: Allocator) anyerror!void { | ... | @@ -4905,7 +4989,7 @@ fn dumpFallible(ip: InternPool, arena: Allocator) anyerror!void { |
| 4905 | .float_c_longdouble_f80 => @sizeOf(Float80), | 4989 | .float_c_longdouble_f80 => @sizeOf(Float80), |
| 4906 | .float_c_longdouble_f128 => @sizeOf(Float128), | 4990 | .float_c_longdouble_f128 => @sizeOf(Float128), |
| 4907 | .float_comptime_float => @sizeOf(Float128), | 4991 | .float_comptime_float => @sizeOf(Float128), |
| 4908 | .variable => @sizeOf(Variable) + @sizeOf(Module.Decl), | 4992 | .variable => @sizeOf(Tag.Variable) + @sizeOf(Module.Decl), |
| 4909 | .extern_func => @sizeOf(Key.ExternFunc) + @sizeOf(Module.Decl), | 4993 | .extern_func => @sizeOf(Key.ExternFunc) + @sizeOf(Module.Decl), |
| 4910 | .func => @sizeOf(Key.Func) + @sizeOf(Module.Fn) + @sizeOf(Module.Decl), | 4994 | .func => @sizeOf(Key.Func) + @sizeOf(Module.Fn) + @sizeOf(Module.Decl), |
| 4911 | .only_possible_value => 0, | 4995 | .only_possible_value => 0, |
| ... | @@ -5179,6 +5263,7 @@ pub fn typeOf(ip: InternPool, index: Index) Index { | ... | @@ -5179,6 +5263,7 @@ pub fn typeOf(ip: InternPool, index: Index) Index { |
| 5179 | .generic_poison_type, | 5263 | .generic_poison_type, |
| 5180 | .empty_struct_type, | 5264 | .empty_struct_type, |
| 5181 | => .type_type, | 5265 | => .type_type, |
| | 5266 | |
| 5182 | .undef => .undefined_type, | 5267 | .undef => .undefined_type, |
| 5183 | .zero, .one, .negative_one => .comptime_int_type, | 5268 | .zero, .one, .negative_one => .comptime_int_type, |
| 5184 | .zero_usize, .one_usize => .usize_type, | 5269 | .zero_usize, .one_usize => .usize_type, |
| ... | @@ -5190,8 +5275,109 @@ pub fn typeOf(ip: InternPool, index: Index) Index { | ... | @@ -5190,8 +5275,109 @@ pub fn typeOf(ip: InternPool, index: Index) Index { |
| 5190 | .bool_true, .bool_false => .bool_type, | 5275 | .bool_true, .bool_false => .bool_type, |
| 5191 | .empty_struct => .empty_struct_type, | 5276 | .empty_struct => .empty_struct_type, |
| 5192 | .generic_poison => .generic_poison_type, | 5277 | .generic_poison => .generic_poison_type, |
| 5193 | .var_args_param_type, .none => unreachable, | 5278 | |
| 5194 | _ => ip.indexToKey(index).typeOf(), | 5279 | // This optimization on tags is needed so that indexToKey can call |
| | 5280 | // typeOf without being recursive. |
| | 5281 | _ => switch (ip.items.items(.tag)[@enumToInt(index)]) { |
| | 5282 | .type_int_signed, |
| | 5283 | .type_int_unsigned, |
| | 5284 | .type_array_big, |
| | 5285 | .type_array_small, |
| | 5286 | .type_vector, |
| | 5287 | .type_pointer, |
| | 5288 | .type_slice, |
| | 5289 | .type_optional, |
| | 5290 | .type_anyframe, |
| | 5291 | .type_error_union, |
| | 5292 | .type_error_set, |
| | 5293 | .type_inferred_error_set, |
| | 5294 | .type_enum_auto, |
| | 5295 | .type_enum_explicit, |
| | 5296 | .type_enum_nonexhaustive, |
| | 5297 | .simple_type, |
| | 5298 | .type_opaque, |
| | 5299 | .type_struct, |
| | 5300 | .type_struct_ns, |
| | 5301 | .type_struct_anon, |
| | 5302 | .type_tuple_anon, |
| | 5303 | .type_union_tagged, |
| | 5304 | .type_union_untagged, |
| | 5305 | .type_union_safety, |
| | 5306 | .type_function, |
| | 5307 | => .type_type, |
| | 5308 | |
| | 5309 | .undef, |
| | 5310 | .opt_null, |
| | 5311 | .only_possible_value, |
| | 5312 | => @intToEnum(Index, ip.items.items(.data)[@enumToInt(index)]), |
| | 5313 | |
| | 5314 | .simple_value => unreachable, // handled via Index above |
| | 5315 | |
| | 5316 | inline .ptr_decl, |
| | 5317 | .ptr_mut_decl, |
| | 5318 | .ptr_comptime_field, |
| | 5319 | .ptr_int, |
| | 5320 | .ptr_eu_payload, |
| | 5321 | .ptr_opt_payload, |
| | 5322 | .ptr_elem, |
| | 5323 | .ptr_field, |
| | 5324 | .ptr_slice, |
| | 5325 | .opt_payload, |
| | 5326 | .error_union_payload, |
| | 5327 | .runtime_value, |
| | 5328 | .int_small, |
| | 5329 | .int_lazy_align, |
| | 5330 | .int_lazy_size, |
| | 5331 | .error_set_error, |
| | 5332 | .error_union_error, |
| | 5333 | .enum_tag, |
| | 5334 | .variable, |
| | 5335 | .extern_func, |
| | 5336 | .func, |
| | 5337 | .union_value, |
| | 5338 | .bytes, |
| | 5339 | .aggregate, |
| | 5340 | .repeated, |
| | 5341 | => |t| { |
| | 5342 | const extra_index = ip.items.items(.data)[@enumToInt(index)]; |
| | 5343 | const field_index = std.meta.fieldIndex(t.Payload(), "ty").?; |
| | 5344 | return @intToEnum(Index, ip.extra.items[extra_index + field_index]); |
| | 5345 | }, |
| | 5346 | |
| | 5347 | .int_u8 => .u8_type, |
| | 5348 | .int_u16 => .u16_type, |
| | 5349 | .int_u32 => .u32_type, |
| | 5350 | .int_i32 => .i32_type, |
| | 5351 | .int_usize => .usize_type, |
| | 5352 | |
| | 5353 | .int_comptime_int_u32, |
| | 5354 | .int_comptime_int_i32, |
| | 5355 | => .comptime_int_type, |
| | 5356 | |
| | 5357 | // Note these are stored in limbs data, not extra data. |
| | 5358 | .int_positive, |
| | 5359 | .int_negative, |
| | 5360 | => ip.limbData(Int, ip.items.items(.data)[@enumToInt(index)]).ty, |
| | 5361 | |
| | 5362 | .enum_literal => .enum_literal_type, |
| | 5363 | .float_f16 => .f16_type, |
| | 5364 | .float_f32 => .f32_type, |
| | 5365 | .float_f64 => .f64_type, |
| | 5366 | .float_f80 => .f80_type, |
| | 5367 | .float_f128 => .f128_type, |
| | 5368 | |
| | 5369 | .float_c_longdouble_f80, |
| | 5370 | .float_c_longdouble_f128, |
| | 5371 | => .c_longdouble_type, |
| | 5372 | |
| | 5373 | .float_comptime_float => .comptime_float_type, |
| | 5374 | |
| | 5375 | .memoized_decl => unreachable, |
| | 5376 | .memoized_call => unreachable, |
| | 5377 | }, |
| | 5378 | |
| | 5379 | .var_args_param_type => unreachable, |
| | 5380 | .none => unreachable, |
| 5195 | }; | 5381 | }; |
| 5196 | } | 5382 | } |
| 5197 | | 5383 | |