authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-08-18 17:57:28+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-08-18 18:10:59+01:00
logde49a9a17352a36a0888b03905f207b0584fc269
treeebda829424b7df833084bc0f8275815d42a6eeec
parenta239d8d4e2c0e5a7f3eb4b9973f869afdb3bbe05
signaturelock-open Commit is signed but in an unrecognized format.

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.

11 files changed, 152 insertions(+), 492 deletions(-)

lib/std/zig/AstGen.zig+57-46
......@@ -366,7 +366,6 @@ const ResultInfo = struct {
366366};
367367
368368const coerced_align_ri: ResultInfo = .{ .rl = .{ .coerced_ty = .u29_type } };
369const coerced_addrspace_ri: ResultInfo = .{ .rl = .{ .coerced_ty = .address_space_type } };
370369const coerced_linksection_ri: ResultInfo = .{ .rl = .{ .coerced_ty = .slice_const_u8_type } };
371370const coerced_type_ri: ResultInfo = .{ .rl = .{ .coerced_ty = .type_type } };
372371const coerced_bool_ri: ResultInfo = .{ .rl = .{ .coerced_ty = .bool_type } };
......@@ -1387,7 +1386,7 @@ fn fnProtoExpr(
13871386 try expr(
13881387 &block_scope,
13891388 scope,
1390 .{ .rl = .{ .coerced_ty = .calling_convention_type } },
1389 .{ .rl = .{ .coerced_ty = try block_scope.addBuiltinValue(fn_proto.ast.callconv_expr, .calling_convention) } },
13911390 fn_proto.ast.callconv_expr,
13921391 )
13931392 else
......@@ -3804,7 +3803,8 @@ fn ptrType(
38043803 gz.astgen.source_line = source_line;
38053804 gz.astgen.source_column = source_column;
38063805
3807 addrspace_ref = try expr(gz, scope, coerced_addrspace_ri, ptr_info.ast.addrspace_node);
3806 const addrspace_ty = try gz.addBuiltinValue(ptr_info.ast.addrspace_node, .address_space);
3807 addrspace_ref = try expr(gz, scope, .{ .rl = .{ .coerced_ty = addrspace_ty } }, ptr_info.ast.addrspace_node);
38083808 trailing_count += 1;
38093809 }
38103810 if (ptr_info.ast.align_node != 0) {
......@@ -4202,7 +4202,8 @@ fn fnDecl(
42024202 var addrspace_gz = decl_gz.makeSubBlock(params_scope);
42034203 defer addrspace_gz.unstack();
42044204 const addrspace_ref: Zir.Inst.Ref = if (fn_proto.ast.addrspace_expr == 0) .none else inst: {
4205 const inst = try expr(&decl_gz, params_scope, coerced_addrspace_ri, fn_proto.ast.addrspace_expr);
4205 const addrspace_ty = try decl_gz.addBuiltinValue(fn_proto.ast.addrspace_expr, .address_space);
4206 const inst = try expr(&decl_gz, params_scope, .{ .rl = .{ .coerced_ty = addrspace_ty } }, fn_proto.ast.addrspace_expr);
42064207 if (addrspace_gz.instructionsSlice().len == 0) {
42074208 // In this case we will send a len=0 body which can be encoded more efficiently.
42084209 break :inst inst;
......@@ -4235,9 +4236,9 @@ fn fnDecl(
42354236 );
42364237 }
42374238 const inst = try expr(
4238 &decl_gz,
4239 &cc_gz,
42394240 params_scope,
4240 .{ .rl = .{ .coerced_ty = .calling_convention_type } },
4241 .{ .rl = .{ .coerced_ty = try cc_gz.addBuiltinValue(fn_proto.ast.callconv_expr, .calling_convention) } },
42414242 fn_proto.ast.callconv_expr,
42424243 );
42434244 if (cc_gz.instructionsSlice().len == 0) {
......@@ -4247,10 +4248,13 @@ fn fnDecl(
42474248 _ = try cc_gz.addBreak(.break_inline, @enumFromInt(0), inst);
42484249 break :blk inst;
42494250 } else if (is_extern) {
4250 // note: https://github.com/ziglang/zig/issues/5269
4251 break :blk .calling_convention_c;
4251 const inst = try cc_gz.addBuiltinValue(decl_node, .calling_convention_c);
4252 _ = try cc_gz.addBreak(.break_inline, @enumFromInt(0), inst);
4253 break :blk inst;
42524254 } else if (has_inline_keyword) {
4253 break :blk .calling_convention_inline;
4255 const inst = try cc_gz.addBuiltinValue(decl_node, .calling_convention_inline);
4256 _ = try cc_gz.addBreak(.break_inline, @enumFromInt(0), inst);
4257 break :blk inst;
42544258 } else {
42554259 break :blk .none;
42564260 }
......@@ -4525,7 +4529,8 @@ fn globalVarDecl(
45254529
45264530 var addrspace_gz = linksection_gz.makeSubBlock(scope);
45274531 if (var_decl.ast.addrspace_node != 0) {
4528 const addrspace_inst = try fullBodyExpr(&addrspace_gz, &addrspace_gz.base, coerced_addrspace_ri, var_decl.ast.addrspace_node);
4532 const addrspace_ty = try addrspace_gz.addBuiltinValue(var_decl.ast.addrspace_node, .address_space);
4533 const addrspace_inst = try fullBodyExpr(&addrspace_gz, &addrspace_gz.base, .{ .rl = .{ .coerced_ty = addrspace_ty } }, var_decl.ast.addrspace_node);
45294534 _ = try addrspace_gz.addBreakWithSrcNode(.break_inline, decl_inst, addrspace_inst, node);
45304535 }
45314536
......@@ -9169,6 +9174,7 @@ fn builtinCall(
91699174 // zig fmt: on
91709175
91719176 .@"export" => {
9177 const export_options_ty = try gz.addBuiltinValue(node, .export_options);
91729178 const node_tags = tree.nodes.items(.tag);
91739179 const node_datas = tree.nodes.items(.data);
91749180 // This function causes a Decl to be exported. The first parameter is not an expression,
......@@ -9192,7 +9198,7 @@ fn builtinCall(
91929198 local_val.used = ident_token;
91939199 _ = try gz.addPlNode(.export_value, node, Zir.Inst.ExportValue{
91949200 .operand = local_val.inst,
9195 .options = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = .export_options_type } }, params[1]),
9201 .options = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = export_options_ty } }, params[1]),
91969202 });
91979203 return rvalue(gz, ri, .void_value, node);
91989204 }
......@@ -9207,7 +9213,7 @@ fn builtinCall(
92079213 const loaded = try gz.addUnNode(.load, local_ptr.ptr, node);
92089214 _ = try gz.addPlNode(.export_value, node, Zir.Inst.ExportValue{
92099215 .operand = loaded,
9210 .options = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = .export_options_type } }, params[1]),
9216 .options = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = export_options_ty } }, params[1]),
92119217 });
92129218 return rvalue(gz, ri, .void_value, node);
92139219 }
......@@ -9245,7 +9251,7 @@ fn builtinCall(
92459251 },
92469252 else => return astgen.failNode(params[0], "symbol to export must identify a declaration", .{}),
92479253 }
9248 const options = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = .export_options_type } }, params[1]);
9254 const options = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = export_options_ty } }, params[1]);
92499255 _ = try gz.addPlNode(.@"export", node, Zir.Inst.Export{
92509256 .namespace = namespace,
92519257 .decl_name = decl_name,
......@@ -9255,7 +9261,8 @@ fn builtinCall(
92559261 },
92569262 .@"extern" => {
92579263 const type_inst = try typeExpr(gz, scope, params[0]);
9258 const options = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = .extern_options_type } }, params[1]);
9264 const extern_options_ty = try gz.addBuiltinValue(node, .extern_options);
9265 const options = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = extern_options_ty } }, params[1]);
92599266 const result = try gz.addExtendedPayload(.builtin_extern, Zir.Inst.BinNode{
92609267 .node = gz.nodeIndexToRelative(node),
92619268 .lhs = type_inst,
......@@ -9264,7 +9271,8 @@ fn builtinCall(
92649271 return rvalue(gz, ri, result, node);
92659272 },
92669273 .fence => {
9267 const order = try expr(gz, scope, .{ .rl = .{ .coerced_ty = .atomic_order_type } }, params[0]);
9274 const atomic_order_ty = try gz.addBuiltinValue(node, .atomic_order);
9275 const order = try expr(gz, scope, .{ .rl = .{ .coerced_ty = atomic_order_ty } }, params[0]);
92689276 _ = try gz.addExtendedPayload(.fence, Zir.Inst.UnNode{
92699277 .node = gz.nodeIndexToRelative(node),
92709278 .operand = order,
......@@ -9272,7 +9280,8 @@ fn builtinCall(
92729280 return rvalue(gz, ri, .void_value, node);
92739281 },
92749282 .set_float_mode => {
9275 const order = try expr(gz, scope, .{ .rl = .{ .coerced_ty = .float_mode_type } }, params[0]);
9283 const float_mode_ty = try gz.addBuiltinValue(node, .float_mode);
9284 const order = try expr(gz, scope, .{ .rl = .{ .coerced_ty = float_mode_ty } }, params[0]);
92769285 _ = try gz.addExtendedPayload(.set_float_mode, Zir.Inst.UnNode{
92779286 .node = gz.nodeIndexToRelative(node),
92789287 .operand = order,
......@@ -9365,7 +9374,8 @@ fn builtinCall(
93659374 },
93669375
93679376 .Type => {
9368 const operand = try expr(gz, scope, .{ .rl = .{ .coerced_ty = .type_info_type } }, params[0]);
9377 const type_info_ty = try gz.addBuiltinValue(node, .type_info);
9378 const operand = try expr(gz, scope, .{ .rl = .{ .coerced_ty = type_info_ty } }, params[0]);
93699379
93709380 const gpa = gz.astgen.gpa;
93719381
......@@ -9502,7 +9512,8 @@ fn builtinCall(
95029512 return rvalue(gz, ri, result, node);
95039513 },
95049514 .reduce => {
9505 const op = try expr(gz, scope, .{ .rl = .{ .coerced_ty = .reduce_op_type } }, params[0]);
9515 const reduce_op_ty = try gz.addBuiltinValue(node, .reduce_op);
9516 const op = try expr(gz, scope, .{ .rl = .{ .coerced_ty = reduce_op_ty } }, params[0]);
95069517 const scalar = try expr(gz, scope, .{ .rl = .none }, params[1]);
95079518 const result = try gz.addPlNode(.reduce, node, Zir.Inst.Bin{
95089519 .lhs = op,
......@@ -9517,34 +9528,38 @@ fn builtinCall(
95179528 .shl_with_overflow => return overflowArithmetic(gz, scope, ri, node, params, .shl_with_overflow),
95189529
95199530 .atomic_load => {
9531 const atomic_order_type = try gz.addBuiltinValue(node, .atomic_order);
95209532 const result = try gz.addPlNode(.atomic_load, node, Zir.Inst.AtomicLoad{
95219533 // zig fmt: off
9522 .elem_type = try typeExpr(gz, scope, params[0]),
9523 .ptr = try expr (gz, scope, .{ .rl = .none }, params[1]),
9524 .ordering = try expr (gz, scope, .{ .rl = .{ .coerced_ty = .atomic_order_type } }, params[2]),
9534 .elem_type = try typeExpr(gz, scope, params[0]),
9535 .ptr = try expr (gz, scope, .{ .rl = .none }, params[1]),
9536 .ordering = try expr (gz, scope, .{ .rl = .{ .coerced_ty = atomic_order_type } }, params[2]),
95259537 // zig fmt: on
95269538 });
95279539 return rvalue(gz, ri, result, node);
95289540 },
95299541 .atomic_rmw => {
9542 const atomic_order_type = try gz.addBuiltinValue(node, .atomic_order);
9543 const atomic_rmw_op_type = try gz.addBuiltinValue(node, .atomic_rmw_op);
95309544 const int_type = try typeExpr(gz, scope, params[0]);
95319545 const result = try gz.addPlNode(.atomic_rmw, node, Zir.Inst.AtomicRmw{
95329546 // zig fmt: off
9533 .ptr = try expr(gz, scope, .{ .rl = .none }, params[1]),
9534 .operation = try expr(gz, scope, .{ .rl = .{ .coerced_ty = .atomic_rmw_op_type } }, params[2]),
9535 .operand = try expr(gz, scope, .{ .rl = .{ .ty = int_type } }, params[3]),
9536 .ordering = try expr(gz, scope, .{ .rl = .{ .coerced_ty = .atomic_order_type } }, params[4]),
9547 .ptr = try expr(gz, scope, .{ .rl = .none }, params[1]),
9548 .operation = try expr(gz, scope, .{ .rl = .{ .coerced_ty = atomic_rmw_op_type } }, params[2]),
9549 .operand = try expr(gz, scope, .{ .rl = .{ .ty = int_type } }, params[3]),
9550 .ordering = try expr(gz, scope, .{ .rl = .{ .coerced_ty = atomic_order_type } }, params[4]),
95379551 // zig fmt: on
95389552 });
95399553 return rvalue(gz, ri, result, node);
95409554 },
95419555 .atomic_store => {
9556 const atomic_order_type = try gz.addBuiltinValue(node, .atomic_order);
95429557 const int_type = try typeExpr(gz, scope, params[0]);
95439558 _ = try gz.addPlNode(.atomic_store, node, Zir.Inst.AtomicStore{
95449559 // zig fmt: off
9545 .ptr = try expr(gz, scope, .{ .rl = .none }, params[1]),
9546 .operand = try expr(gz, scope, .{ .rl = .{ .ty = int_type } }, params[2]),
9547 .ordering = try expr(gz, scope, .{ .rl = .{ .coerced_ty = .atomic_order_type } }, params[3]),
9560 .ptr = try expr(gz, scope, .{ .rl = .none }, params[1]),
9561 .operand = try expr(gz, scope, .{ .rl = .{ .ty = int_type } }, params[2]),
9562 .ordering = try expr(gz, scope, .{ .rl = .{ .coerced_ty = atomic_order_type } }, params[3]),
95489563 // zig fmt: on
95499564 });
95509565 return rvalue(gz, ri, .void_value, node);
......@@ -9562,7 +9577,8 @@ fn builtinCall(
95629577 return rvalue(gz, ri, result, node);
95639578 },
95649579 .call => {
9565 const modifier = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = .call_modifier_type } }, params[0]);
9580 const call_modifier_ty = try gz.addBuiltinValue(node, .call_modifier);
9581 const modifier = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = call_modifier_ty } }, params[0]);
95669582 const callee = try expr(gz, scope, .{ .rl = .none }, params[1]);
95679583 const args = try expr(gz, scope, .{ .rl = .none }, params[2]);
95689584 const result = try gz.addPlNode(.builtin_call, node, Zir.Inst.BuiltinCall{
......@@ -9641,8 +9657,9 @@ fn builtinCall(
96419657 return rvalue(gz, ri, result, node);
96429658 },
96439659 .prefetch => {
9660 const prefetch_options_ty = try gz.addBuiltinValue(node, .prefetch_options);
96449661 const ptr = try expr(gz, scope, .{ .rl = .none }, params[0]);
9645 const options = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = .prefetch_options_type } }, params[1]);
9662 const options = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = prefetch_options_ty } }, params[1]);
96469663 _ = try gz.addExtendedPayload(.prefetch, Zir.Inst.BinNode{
96479664 .node = gz.nodeIndexToRelative(node),
96489665 .lhs = ptr,
......@@ -9812,14 +9829,15 @@ fn cmpxchg(
98129829 small: u16,
98139830) InnerError!Zir.Inst.Ref {
98149831 const int_type = try typeExpr(gz, scope, params[0]);
9832 const atomic_order_type = try gz.addBuiltinValue(node, .atomic_order);
98159833 const result = try gz.addExtendedPayloadSmall(.cmpxchg, small, Zir.Inst.Cmpxchg{
98169834 // zig fmt: off
98179835 .node = gz.nodeIndexToRelative(node),
9818 .ptr = try expr(gz, scope, .{ .rl = .none }, params[1]),
9819 .expected_value = try expr(gz, scope, .{ .rl = .{ .ty = int_type } }, params[2]),
9820 .new_value = try expr(gz, scope, .{ .rl = .{ .coerced_ty = int_type } }, params[3]),
9821 .success_order = try expr(gz, scope, .{ .rl = .{ .coerced_ty = .atomic_order_type } }, params[4]),
9822 .failure_order = try expr(gz, scope, .{ .rl = .{ .coerced_ty = .atomic_order_type } }, params[5]),
9836 .ptr = try expr(gz, scope, .{ .rl = .none }, params[1]),
9837 .expected_value = try expr(gz, scope, .{ .rl = .{ .ty = int_type } }, params[2]),
9838 .new_value = try expr(gz, scope, .{ .rl = .{ .coerced_ty = int_type } }, params[3]),
9839 .success_order = try expr(gz, scope, .{ .rl = .{ .coerced_ty = atomic_order_type } }, params[4]),
9840 .failure_order = try expr(gz, scope, .{ .rl = .{ .coerced_ty = atomic_order_type } }, params[5]),
98239841 // zig fmt: on
98249842 });
98259843 return rvalue(gz, ri, result, node);
......@@ -11106,17 +11124,6 @@ fn rvalueInner(
1110611124 as_ty | @intFromEnum(Zir.Inst.Ref.null_type),
1110711125 as_ty | @intFromEnum(Zir.Inst.Ref.undefined_type),
1110811126 as_ty | @intFromEnum(Zir.Inst.Ref.enum_literal_type),
11109 as_ty | @intFromEnum(Zir.Inst.Ref.atomic_order_type),
11110 as_ty | @intFromEnum(Zir.Inst.Ref.atomic_rmw_op_type),
11111 as_ty | @intFromEnum(Zir.Inst.Ref.calling_convention_type),
11112 as_ty | @intFromEnum(Zir.Inst.Ref.address_space_type),
11113 as_ty | @intFromEnum(Zir.Inst.Ref.float_mode_type),
11114 as_ty | @intFromEnum(Zir.Inst.Ref.reduce_op_type),
11115 as_ty | @intFromEnum(Zir.Inst.Ref.call_modifier_type),
11116 as_ty | @intFromEnum(Zir.Inst.Ref.prefetch_options_type),
11117 as_ty | @intFromEnum(Zir.Inst.Ref.export_options_type),
11118 as_ty | @intFromEnum(Zir.Inst.Ref.extern_options_type),
11119 as_ty | @intFromEnum(Zir.Inst.Ref.type_info_type),
1112011127 as_ty | @intFromEnum(Zir.Inst.Ref.manyptr_u8_type),
1112111128 as_ty | @intFromEnum(Zir.Inst.Ref.manyptr_const_u8_type),
1112211129 as_ty | @intFromEnum(Zir.Inst.Ref.manyptr_const_u8_sentinel_0_type),
......@@ -12572,6 +12579,10 @@ const GenZir = struct {
1257212579 return new_index;
1257312580 }
1257412581
12582 fn addBuiltinValue(gz: *GenZir, src_node: Ast.Node.Index, val: Zir.Inst.BuiltinValue) !Zir.Inst.Ref {
12583 return addExtendedNodeSmall(gz, .builtin_value, src_node, @intFromEnum(val));
12584 }
12585
1257512586 fn addExtendedPayload(gz: *GenZir, opcode: Zir.Inst.Extended, extra: anytype) !Zir.Inst.Ref {
1257612587 return addExtendedPayloadSmall(gz, opcode, undefined, extra);
1257712588 }
lib/std/zig/Zir.zig+24-14
......@@ -2055,6 +2055,10 @@ pub const Inst = struct {
20552055 /// Guaranteed to not have the `ptr_cast` flag.
20562056 /// Uses the `pl_node` union field with payload `FieldParentPtr`.
20572057 field_parent_ptr,
2058 /// Get a type or value from `std.builtin`.
2059 /// `operand` is `src_node: i32`.
2060 /// `small` is an `Inst.BuiltinValue`.
2061 builtin_value,
20582062
20592063 pub const InstData = struct {
20602064 opcode: Extended,
......@@ -2071,7 +2075,7 @@ pub const Inst = struct {
20712075 ref_start_index = static_len,
20722076 _,
20732077
2074 pub const static_len = 84;
2078 pub const static_len = 71;
20752079
20762080 pub fn toRef(i: Index) Inst.Ref {
20772081 return @enumFromInt(@intFromEnum(Index.ref_start_index) + @intFromEnum(i));
......@@ -2148,17 +2152,6 @@ pub const Inst = struct {
21482152 null_type,
21492153 undefined_type,
21502154 enum_literal_type,
2151 atomic_order_type,
2152 atomic_rmw_op_type,
2153 calling_convention_type,
2154 address_space_type,
2155 float_mode_type,
2156 reduce_op_type,
2157 call_modifier_type,
2158 prefetch_options_type,
2159 export_options_type,
2160 extern_options_type,
2161 type_info_type,
21622155 manyptr_u8_type,
21632156 manyptr_const_u8_type,
21642157 manyptr_const_u8_sentinel_0_type,
......@@ -2179,8 +2172,6 @@ pub const Inst = struct {
21792172 one_u8,
21802173 four_u8,
21812174 negative_one,
2182 calling_convention_c,
2183 calling_convention_inline,
21842175 void_value,
21852176 unreachable_value,
21862177 null_value,
......@@ -3146,6 +3137,24 @@ pub const Inst = struct {
31463137 }
31473138 };
31483139
3140 pub const BuiltinValue = enum(u16) {
3141 // Types
3142 atomic_order,
3143 atomic_rmw_op,
3144 calling_convention,
3145 address_space,
3146 float_mode,
3147 reduce_op,
3148 call_modifier,
3149 prefetch_options,
3150 export_options,
3151 extern_options,
3152 type_info,
3153 // Values
3154 calling_convention_c,
3155 calling_convention_inline,
3156 };
3157
31493158 /// Trailing:
31503159 /// 0. tag_type: Ref, // if has_tag_type
31513160 /// 1. captures_len: u32, // if has_captures_len
......@@ -3977,6 +3986,7 @@ fn findDeclsInner(
39773986 .restore_err_ret_index,
39783987 .closure_get,
39793988 .field_parent_ptr,
3989 .builtin_value,
39803990 => return,
39813991
39823992 // `@TypeOf` has a body.
src/Air.zig-13
......@@ -938,17 +938,6 @@ pub const Inst = struct {
938938 null_type = @intFromEnum(InternPool.Index.null_type),
939939 undefined_type = @intFromEnum(InternPool.Index.undefined_type),
940940 enum_literal_type = @intFromEnum(InternPool.Index.enum_literal_type),
941 atomic_order_type = @intFromEnum(InternPool.Index.atomic_order_type),
942 atomic_rmw_op_type = @intFromEnum(InternPool.Index.atomic_rmw_op_type),
943 calling_convention_type = @intFromEnum(InternPool.Index.calling_convention_type),
944 address_space_type = @intFromEnum(InternPool.Index.address_space_type),
945 float_mode_type = @intFromEnum(InternPool.Index.float_mode_type),
946 reduce_op_type = @intFromEnum(InternPool.Index.reduce_op_type),
947 call_modifier_type = @intFromEnum(InternPool.Index.call_modifier_type),
948 prefetch_options_type = @intFromEnum(InternPool.Index.prefetch_options_type),
949 export_options_type = @intFromEnum(InternPool.Index.export_options_type),
950 extern_options_type = @intFromEnum(InternPool.Index.extern_options_type),
951 type_info_type = @intFromEnum(InternPool.Index.type_info_type),
952941 manyptr_u8_type = @intFromEnum(InternPool.Index.manyptr_u8_type),
953942 manyptr_const_u8_type = @intFromEnum(InternPool.Index.manyptr_const_u8_type),
954943 manyptr_const_u8_sentinel_0_type = @intFromEnum(InternPool.Index.manyptr_const_u8_sentinel_0_type),
......@@ -969,8 +958,6 @@ pub const Inst = struct {
969958 one_u8 = @intFromEnum(InternPool.Index.one_u8),
970959 four_u8 = @intFromEnum(InternPool.Index.four_u8),
971960 negative_one = @intFromEnum(InternPool.Index.negative_one),
972 calling_convention_c = @intFromEnum(InternPool.Index.calling_convention_c),
973 calling_convention_inline = @intFromEnum(InternPool.Index.calling_convention_inline),
974961 void_value = @intFromEnum(InternPool.Index.void_value),
975962 unreachable_value = @intFromEnum(InternPool.Index.unreachable_value),
976963 null_value = @intFromEnum(InternPool.Index.null_value),
src/InternPool.zig+2-138
......@@ -4411,17 +4411,6 @@ pub const Index = enum(u32) {
44114411 null_type,
44124412 undefined_type,
44134413 enum_literal_type,
4414 atomic_order_type,
4415 atomic_rmw_op_type,
4416 calling_convention_type,
4417 address_space_type,
4418 float_mode_type,
4419 reduce_op_type,
4420 call_modifier_type,
4421 prefetch_options_type,
4422 export_options_type,
4423 extern_options_type,
4424 type_info_type,
44254414 manyptr_u8_type,
44264415 manyptr_const_u8_type,
44274416 manyptr_const_u8_sentinel_0_type,
......@@ -4454,10 +4443,6 @@ pub const Index = enum(u32) {
44544443 four_u8,
44554444 /// `-1` (comptime_int)
44564445 negative_one,
4457 /// `std.builtin.CallingConvention.C`
4458 calling_convention_c,
4459 /// `std.builtin.CallingConvention.Inline`
4460 calling_convention_inline,
44614446 /// `{}`
44624447 void_value,
44634448 /// `unreachable` (noreturn type)
......@@ -4837,17 +4822,6 @@ pub const static_keys = [_]Key{
48374822 .{ .simple_type = .null },
48384823 .{ .simple_type = .undefined },
48394824 .{ .simple_type = .enum_literal },
4840 .{ .simple_type = .atomic_order },
4841 .{ .simple_type = .atomic_rmw_op },
4842 .{ .simple_type = .calling_convention },
4843 .{ .simple_type = .address_space },
4844 .{ .simple_type = .float_mode },
4845 .{ .simple_type = .reduce_op },
4846 .{ .simple_type = .call_modifier },
4847 .{ .simple_type = .prefetch_options },
4848 .{ .simple_type = .export_options },
4849 .{ .simple_type = .extern_options },
4850 .{ .simple_type = .type_info },
48514825
48524826 // [*]u8
48534827 .{ .ptr_type = .{
......@@ -4876,7 +4850,7 @@ pub const static_keys = [_]Key{
48764850 },
48774851 } },
48784852
4879 // comptime_int
4853 // *const comptime_int
48804854 .{ .ptr_type = .{
48814855 .child = .comptime_int_type,
48824856 .flags = .{
......@@ -4967,16 +4941,6 @@ pub const static_keys = [_]Key{
49674941 .ty = .comptime_int_type,
49684942 .storage = .{ .i64 = -1 },
49694943 } },
4970 // calling_convention_c
4971 .{ .enum_tag = .{
4972 .ty = .calling_convention_type,
4973 .int = .one_u8,
4974 } },
4975 // calling_convention_inline
4976 .{ .enum_tag = .{
4977 .ty = .calling_convention_type,
4978 .int = .four_u8,
4979 } },
49804944
49814945 .{ .simple_value = .void },
49824946 .{ .simple_value = .@"unreachable" },
......@@ -5690,18 +5654,6 @@ pub const SimpleType = enum(u32) {
56905654 undefined = @intFromEnum(Index.undefined_type),
56915655 enum_literal = @intFromEnum(Index.enum_literal_type),
56925656
5693 atomic_order = @intFromEnum(Index.atomic_order_type),
5694 atomic_rmw_op = @intFromEnum(Index.atomic_rmw_op_type),
5695 calling_convention = @intFromEnum(Index.calling_convention_type),
5696 address_space = @intFromEnum(Index.address_space_type),
5697 float_mode = @intFromEnum(Index.float_mode_type),
5698 reduce_op = @intFromEnum(Index.reduce_op_type),
5699 call_modifier = @intFromEnum(Index.call_modifier_type),
5700 prefetch_options = @intFromEnum(Index.prefetch_options_type),
5701 export_options = @intFromEnum(Index.export_options_type),
5702 extern_options = @intFromEnum(Index.extern_options_type),
5703 type_info = @intFromEnum(Index.type_info_type),
5704
57055657 adhoc_inferred_error_set = @intFromEnum(Index.adhoc_inferred_error_set_type),
57065658 generic_poison = @intFromEnum(Index.generic_poison_type),
57075659};
......@@ -6281,18 +6233,6 @@ pub fn init(ip: *InternPool, gpa: Allocator, available_threads: usize) !void {
62816233 // Sanity check.
62826234 assert(ip.indexToKey(.bool_true).simple_value == .true);
62836235 assert(ip.indexToKey(.bool_false).simple_value == .false);
6284
6285 const cc_inline = ip.indexToKey(.calling_convention_inline).enum_tag.int;
6286 const cc_c = ip.indexToKey(.calling_convention_c).enum_tag.int;
6287
6288 assert(ip.indexToKey(cc_inline).int.storage.u64 ==
6289 @intFromEnum(std.builtin.CallingConvention.Inline));
6290
6291 assert(ip.indexToKey(cc_c).int.storage.u64 ==
6292 @intFromEnum(std.builtin.CallingConvention.C));
6293
6294 assert(ip.indexToKey(ip.typeOf(cc_inline)).int_type.bits ==
6295 @typeInfo(@typeInfo(std.builtin.CallingConvention).Enum.tag_type).Int.bits);
62966236 }
62976237}
62986238
......@@ -9743,14 +9683,6 @@ fn addMap(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, cap: usize) Al
97439683/// Invalidates all references to this index.
97449684pub fn remove(ip: *InternPool, tid: Zcu.PerThread.Id, index: Index) void {
97459685 const unwrapped_index = index.unwrap(ip);
9746 if (@intFromEnum(index) < static_keys.len) {
9747 // The item being removed replaced a special index via `InternPool.resolveBuiltinType`.
9748 // Restore the original item at this index.
9749 assert(static_keys[@intFromEnum(index)] == .simple_type);
9750 const items = ip.getLocalShared(unwrapped_index.tid).items.acquire().view();
9751 @atomicStore(Tag, &items.items(.tag)[unwrapped_index.index], .simple_type, .unordered);
9752 return;
9753 }
97549686
97559687 if (unwrapped_index.tid == tid) {
97569688 const items_len = &ip.getLocal(unwrapped_index.tid).mutate.items.len;
......@@ -10390,17 +10322,7 @@ pub fn isIntegerType(ip: *const InternPool, ty: Index) bool {
1039010322
1039110323/// does not include .enum_literal_type
1039210324pub fn isEnumType(ip: *const InternPool, ty: Index) bool {
10393 return switch (ty) {
10394 .atomic_order_type,
10395 .atomic_rmw_op_type,
10396 .calling_convention_type,
10397 .address_space_type,
10398 .float_mode_type,
10399 .reduce_op_type,
10400 .call_modifier_type,
10401 => true,
10402 else => ip.indexToKey(ty) == .enum_type,
10403 };
10325 return ip.indexToKey(ty) == .enum_type;
1040410326}
1040510327
1040610328pub fn isUnion(ip: *const InternPool, ty: Index) bool {
......@@ -11401,17 +11323,6 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {
1140111323 .null_type,
1140211324 .undefined_type,
1140311325 .enum_literal_type,
11404 .atomic_order_type,
11405 .atomic_rmw_op_type,
11406 .calling_convention_type,
11407 .address_space_type,
11408 .float_mode_type,
11409 .reduce_op_type,
11410 .call_modifier_type,
11411 .prefetch_options_type,
11412 .export_options_type,
11413 .extern_options_type,
11414 .type_info_type,
1141511326 .manyptr_u8_type,
1141611327 .manyptr_const_u8_type,
1141711328 .manyptr_const_u8_sentinel_0_type,
......@@ -11429,7 +11340,6 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {
1142911340 .zero, .one, .negative_one => .comptime_int_type,
1143011341 .zero_usize, .one_usize => .usize_type,
1143111342 .zero_u8, .one_u8, .four_u8 => .u8_type,
11432 .calling_convention_c, .calling_convention_inline => .calling_convention_type,
1143311343 .void_value => .void_type,
1143411344 .unreachable_value => .noreturn_type,
1143511345 .null_value => .null_type,
......@@ -11725,22 +11635,6 @@ pub fn zigTypeTagOrPoison(ip: *const InternPool, index: Index) error{GenericPois
1172511635 .undefined_type => .Undefined,
1172611636 .enum_literal_type => .EnumLiteral,
1172711637
11728 .atomic_order_type,
11729 .atomic_rmw_op_type,
11730 .calling_convention_type,
11731 .address_space_type,
11732 .float_mode_type,
11733 .reduce_op_type,
11734 .call_modifier_type,
11735 => .Enum,
11736
11737 .prefetch_options_type,
11738 .export_options_type,
11739 .extern_options_type,
11740 => .Struct,
11741
11742 .type_info_type => .Union,
11743
1174411638 .manyptr_u8_type,
1174511639 .manyptr_const_u8_type,
1174611640 .manyptr_const_u8_sentinel_0_type,
......@@ -11765,8 +11659,6 @@ pub fn zigTypeTagOrPoison(ip: *const InternPool, index: Index) error{GenericPois
1176511659 .one_u8 => unreachable,
1176611660 .four_u8 => unreachable,
1176711661 .negative_one => unreachable,
11768 .calling_convention_c => unreachable,
11769 .calling_convention_inline => unreachable,
1177011662 .void_value => unreachable,
1177111663 .unreachable_value => unreachable,
1177211664 .null_value => unreachable,
......@@ -12085,34 +11977,6 @@ pub fn unwrapCoercedFunc(ip: *const InternPool, index: Index) Index {
1208511977 };
1208611978}
1208711979
12088/// Having resolved a builtin type to a real struct/union/enum (which is now at `resolverd_index`),
12089/// make `want_index` refer to this type instead. This invalidates `resolved_index`, so must be
12090/// called only when it is guaranteed that no reference to `resolved_index` exists.
12091pub fn resolveBuiltinType(
12092 ip: *InternPool,
12093 tid: Zcu.PerThread.Id,
12094 want_index: Index,
12095 resolved_index: Index,
12096) void {
12097 assert(@intFromEnum(want_index) >= @intFromEnum(Index.first_type));
12098 assert(@intFromEnum(want_index) <= @intFromEnum(Index.last_type));
12099
12100 // Make sure the type isn't already resolved!
12101 assert(ip.indexToKey(want_index) == .simple_type);
12102
12103 // Make sure it's the same kind of type
12104 assert((ip.zigTypeTagOrPoison(want_index) catch unreachable) ==
12105 (ip.zigTypeTagOrPoison(resolved_index) catch unreachable));
12106
12107 // Copy the data
12108 const item = resolved_index.unwrap(ip).getItem(ip);
12109 const unwrapped_index = want_index.unwrap(ip);
12110 var items = ip.getLocalShared(unwrapped_index.tid).items.acquire().view().slice();
12111 items.items(.data)[unwrapped_index.index] = item.data;
12112 @atomicStore(Tag, &items.items(.tag)[unwrapped_index.index], item.tag, .release);
12113 ip.remove(tid, resolved_index);
12114}
12115
1211611980pub fn anonStructFieldTypes(ip: *const InternPool, i: Index) []const Index {
1211711981 return ip.indexToKey(i).anon_struct_type.types;
1211811982}
src/Sema.zig+52-39
......@@ -76,10 +76,6 @@ no_partial_func_ty: bool = false,
7676/// here so the values can be dropped without any cleanup.
7777unresolved_inferred_allocs: std.AutoArrayHashMapUnmanaged(Air.Inst.Index, InferredAlloc) = .{},
7878
79/// While analyzing a type which has a special InternPool index, this is set to the index at which
80/// the struct/enum/union type created should be placed. Otherwise, it is `.none`.
81builtin_type_target_index: InternPool.Index = .none,
82
8379/// Links every pointer derived from a base `alloc` back to that `alloc`. Used
8480/// to detect comptime-known `const`s.
8581/// TODO: ZIR liveness analysis would allow us to remove elements from this map.
......@@ -1327,6 +1323,7 @@ fn analyzeBodyInner(
13271323 },
13281324 .value_placeholder => unreachable, // never appears in a body
13291325 .field_parent_ptr => try sema.zirFieldParentPtr(block, extended),
1326 .builtin_value => try sema.zirBuiltinValue(extended),
13301327 };
13311328 },
13321329
......@@ -2712,17 +2709,6 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us
27122709 return captures;
27132710}
27142711
2715/// Given an `InternPool.WipNamespaceType` or `InternPool.WipEnumType`, apply
2716/// `sema.builtin_type_target_index` to it if necessary.
2717fn wrapWipTy(sema: *Sema, wip_ty: anytype) @TypeOf(wip_ty) {
2718 const pt = sema.pt;
2719 if (sema.builtin_type_target_index == .none) return wip_ty;
2720 var new = wip_ty;
2721 new.index = sema.builtin_type_target_index;
2722 pt.zcu.intern_pool.resolveBuiltinType(pt.tid, new.index, wip_ty.index);
2723 return new;
2724}
2725
27262712fn zirStructDecl(
27272713 sema: *Sema,
27282714 block: *Block,
......@@ -2788,7 +2774,7 @@ fn zirStructDecl(
27882774 .captures = captures,
27892775 } },
27902776 };
2791 const wip_ty = sema.wrapWipTy(switch (try ip.getStructType(gpa, pt.tid, struct_init, false)) {
2777 const wip_ty = switch (try ip.getStructType(gpa, pt.tid, struct_init, false)) {
27922778 .existing => |ty| {
27932779 const new_ty = try pt.ensureTypeUpToDate(ty, false);
27942780
......@@ -2801,7 +2787,7 @@ fn zirStructDecl(
28012787 return Air.internedToRef(new_ty);
28022788 },
28032789 .wip => |wip| wip,
2804 });
2790 };
28052791 errdefer wip_ty.cancel(ip, pt.tid);
28062792
28072793 wip_ty.setName(ip, try sema.createTypeName(
......@@ -3017,7 +3003,7 @@ fn zirEnumDecl(
30173003 .captures = captures,
30183004 } },
30193005 };
3020 const wip_ty = sema.wrapWipTy(switch (try ip.getEnumType(gpa, pt.tid, enum_init, false)) {
3006 const wip_ty = switch (try ip.getEnumType(gpa, pt.tid, enum_init, false)) {
30213007 .existing => |ty| {
30223008 const new_ty = try pt.ensureTypeUpToDate(ty, false);
30233009
......@@ -3030,7 +3016,7 @@ fn zirEnumDecl(
30303016 return Air.internedToRef(new_ty);
30313017 },
30323018 .wip => |wip| wip,
3033 });
3019 };
30343020
30353021 // Once this is `true`, we will not delete the decl or type even upon failure, since we
30363022 // have finished constructing the type and are in the process of analyzing it.
......@@ -3161,7 +3147,7 @@ fn zirUnionDecl(
31613147 .captures = captures,
31623148 } },
31633149 };
3164 const wip_ty = sema.wrapWipTy(switch (try ip.getUnionType(gpa, pt.tid, union_init, false)) {
3150 const wip_ty = switch (try ip.getUnionType(gpa, pt.tid, union_init, false)) {
31653151 .existing => |ty| {
31663152 const new_ty = try pt.ensureTypeUpToDate(ty, false);
31673153
......@@ -3174,7 +3160,7 @@ fn zirUnionDecl(
31743160 return Air.internedToRef(new_ty);
31753161 },
31763162 .wip => |wip| wip,
3177 });
3163 };
31783164 errdefer wip_ty.cancel(ip, pt.tid);
31793165
31803166 wip_ty.setName(ip, try sema.createTypeName(
......@@ -3259,7 +3245,6 @@ fn zirOpaqueDecl(
32593245 .captures = captures,
32603246 } },
32613247 };
3262 // No `wrapWipTy` needed as no std.builtin types are opaque.
32633248 const wip_ty = switch (try ip.getOpaqueType(gpa, pt.tid, opaque_init)) {
32643249 .existing => |ty| {
32653250 // Make sure we update the namespace if the declaration is re-analyzed, to pick
......@@ -26179,7 +26164,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2617926164 const body = sema.code.bodySlice(extra_index, body_len);
2618026165 extra_index += body.len;
2618126166
26182 const addrspace_ty = Type.fromInterned(.address_space_type);
26167 const addrspace_ty = try pt.getBuiltinType("AddressSpace");
2618326168 const val = try sema.resolveGenericBody(block, addrspace_src, body, inst, addrspace_ty, .{
2618426169 .needed_comptime_reason = "addrspace must be comptime-known",
2618526170 });
......@@ -26190,7 +26175,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2619026175 } else if (extra.data.bits.has_addrspace_ref) blk: {
2619126176 const addrspace_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
2619226177 extra_index += 1;
26193 const addrspace_ty = Type.fromInterned(.address_space_type);
26178 const addrspace_ty = try pt.getBuiltinType("AddressSpace");
2619426179 const uncoerced_addrspace = sema.resolveInst(addrspace_ref) catch |err| switch (err) {
2619526180 error.GenericPoison => break :blk null,
2619626181 else => |e| return e,
......@@ -26255,7 +26240,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2625526240 } else if (extra.data.bits.has_cc_ref) blk: {
2625626241 const cc_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
2625726242 extra_index += 1;
26258 const cc_ty = Type.fromInterned(.calling_convention_type);
26243 const cc_ty = try pt.getBuiltinType("CallingConvention");
2625926244 const uncoerced_cc = sema.resolveInst(cc_ref) catch |err| switch (err) {
2626026245 error.GenericPoison => break :blk null,
2626126246 else => |e| return e,
......@@ -26713,6 +26698,46 @@ fn zirInComptime(
2671326698 return if (block.is_comptime) .bool_true else .bool_false;
2671426699}
2671526700
26701fn zirBuiltinValue(sema: *Sema, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
26702 const pt = sema.pt;
26703 const value: Zir.Inst.BuiltinValue = @enumFromInt(extended.small);
26704 const type_name = switch (value) {
26705 .atomic_order => "AtomicOrder",
26706 .atomic_rmw_op => "AtomicRmwOp",
26707 .calling_convention => "CallingConvention",
26708 .address_space => "AddressSpace",
26709 .float_mode => "FloatMode",
26710 .reduce_op => "ReduceOp",
26711 .call_modifier => "CallModifier",
26712 .prefetch_options => "PrefetchOptions",
26713 .export_options => "ExportOptions",
26714 .extern_options => "ExternOptions",
26715 .type_info => "Type",
26716
26717 // Values are handled here.
26718 .calling_convention_c => {
26719 const callconv_ty = try pt.getBuiltinType("CallingConvention");
26720 comptime assert(@intFromEnum(std.builtin.CallingConvention.C) == 1);
26721 const val = try pt.intern(.{ .enum_tag = .{
26722 .ty = callconv_ty.toIntern(),
26723 .int = .one_u8,
26724 } });
26725 return Air.internedToRef(val);
26726 },
26727 .calling_convention_inline => {
26728 const callconv_ty = try pt.getBuiltinType("CallingConvention");
26729 comptime assert(@intFromEnum(std.builtin.CallingConvention.Inline) == 4);
26730 const val = try pt.intern(.{ .enum_tag = .{
26731 .ty = callconv_ty.toIntern(),
26732 .int = .four_u8,
26733 } });
26734 return Air.internedToRef(val);
26735 },
26736 };
26737 const ty = try pt.getBuiltinType(type_name);
26738 return Air.internedToRef(ty.toIntern());
26739}
26740
2671626741fn requireRuntimeBlock(sema: *Sema, block: *Block, src: LazySrcLoc, runtime_src: ?LazySrcLoc) !void {
2671726742 if (block.is_comptime) {
2671826743 const msg = msg: {
......@@ -36899,17 +36924,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3689936924 .comptime_int_type,
3690036925 .comptime_float_type,
3690136926 .enum_literal_type,
36902 .atomic_order_type,
36903 .atomic_rmw_op_type,
36904 .calling_convention_type,
36905 .address_space_type,
36906 .float_mode_type,
36907 .reduce_op_type,
36908 .call_modifier_type,
36909 .prefetch_options_type,
36910 .export_options_type,
36911 .extern_options_type,
36912 .type_info_type,
3691336927 .manyptr_u8_type,
3691436928 .manyptr_const_u8_type,
3691536929 .manyptr_const_u8_sentinel_0_type,
......@@ -36936,8 +36950,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3693636950 .one_u8,
3693736951 .four_u8,
3693836952 .negative_one,
36939 .calling_convention_c,
36940 .calling_convention_inline,
3694136953 .void_value,
3694236954 .unreachable_value,
3694336955 .null_value,
......@@ -37291,7 +37303,8 @@ pub fn analyzeAsAddressSpace(
3729137303) !std.builtin.AddressSpace {
3729237304 const pt = sema.pt;
3729337305 const mod = pt.zcu;
37294 const coerced = try sema.coerce(block, Type.fromInterned(.address_space_type), air_ref, src);
37306 const addrspace_ty = try pt.getBuiltinType("AddressSpace");
37307 const coerced = try sema.coerce(block, addrspace_ty, air_ref, src);
3729537308 const addrspace_val = try sema.resolveConstDefinedValue(block, src, coerced, .{
3729637309 .needed_comptime_reason = "address space must be comptime-known",
3729737310 });
src/Type.zig+1-129
......@@ -316,17 +316,6 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error
316316 => try writer.print("@TypeOf({s})", .{@tagName(s)}),
317317
318318 .enum_literal => try writer.print("@TypeOf(.{s})", .{@tagName(s)}),
319 .atomic_order => try writer.writeAll("std.builtin.AtomicOrder"),
320 .atomic_rmw_op => try writer.writeAll("std.builtin.AtomicRmwOp"),
321 .calling_convention => try writer.writeAll("std.builtin.CallingConvention"),
322 .address_space => try writer.writeAll("std.builtin.AddressSpace"),
323 .float_mode => try writer.writeAll("std.builtin.FloatMode"),
324 .reduce_op => try writer.writeAll("std.builtin.ReduceOp"),
325 .call_modifier => try writer.writeAll("std.builtin.CallModifier"),
326 .prefetch_options => try writer.writeAll("std.builtin.PrefetchOptions"),
327 .export_options => try writer.writeAll("std.builtin.ExportOptions"),
328 .extern_options => try writer.writeAll("std.builtin.ExternOptions"),
329 .type_info => try writer.writeAll("std.builtin.Type"),
330319
331320 .generic_poison => unreachable,
332321 },
......@@ -544,16 +533,6 @@ pub fn hasRuntimeBitsAdvanced(
544533 .anyerror,
545534 .adhoc_inferred_error_set,
546535 .anyopaque,
547 .atomic_order,
548 .atomic_rmw_op,
549 .calling_convention,
550 .address_space,
551 .float_mode,
552 .reduce_op,
553 .call_modifier,
554 .prefetch_options,
555 .export_options,
556 .extern_options,
557536 => true,
558537
559538 // These are false because they are comptime-only types.
......@@ -565,7 +544,6 @@ pub fn hasRuntimeBitsAdvanced(
565544 .null,
566545 .undefined,
567546 .enum_literal,
568 .type_info,
569547 => false,
570548
571549 .generic_poison => unreachable,
......@@ -711,16 +689,6 @@ pub fn hasWellDefinedLayout(ty: Type, mod: *Module) bool {
711689 .anyerror,
712690 .adhoc_inferred_error_set,
713691 .anyopaque,
714 .atomic_order,
715 .atomic_rmw_op,
716 .calling_convention,
717 .address_space,
718 .float_mode,
719 .reduce_op,
720 .call_modifier,
721 .prefetch_options,
722 .export_options,
723 .extern_options,
724692 .type,
725693 .comptime_int,
726694 .comptime_float,
......@@ -728,7 +696,6 @@ pub fn hasWellDefinedLayout(ty: Type, mod: *Module) bool {
728696 .null,
729697 .undefined,
730698 .enum_literal,
731 .type_info,
732699 .generic_poison,
733700 => false,
734701 },
......@@ -972,14 +939,6 @@ pub fn abiAlignmentAdvanced(
972939
973940 .simple_type => |t| switch (t) {
974941 .bool,
975 .atomic_order,
976 .atomic_rmw_op,
977 .calling_convention,
978 .address_space,
979 .float_mode,
980 .reduce_op,
981 .call_modifier,
982 .prefetch_options,
983942 .anyopaque,
984943 => return .{ .scalar = .@"1" },
985944
......@@ -987,11 +946,6 @@ pub fn abiAlignmentAdvanced(
987946 .isize,
988947 => return .{ .scalar = intAbiAlignment(target.ptrBitWidth(), target, use_llvm) },
989948
990 .export_options,
991 .extern_options,
992 .type_info,
993 => return .{ .scalar = ptrAbiAlignment(target) },
994
995949 .c_char => return .{ .scalar = cTypeAlign(target, .char) },
996950 .c_short => return .{ .scalar = cTypeAlign(target, .short) },
997951 .c_ushort => return .{ .scalar = cTypeAlign(target, .ushort) },
......@@ -1352,15 +1306,7 @@ pub fn abiSizeAdvanced(
13521306 },
13531307 .func_type => unreachable, // represents machine code; not a pointer
13541308 .simple_type => |t| switch (t) {
1355 .bool,
1356 .atomic_order,
1357 .atomic_rmw_op,
1358 .calling_convention,
1359 .address_space,
1360 .float_mode,
1361 .reduce_op,
1362 .call_modifier,
1363 => return .{ .scalar = 1 },
1309 .bool => return .{ .scalar = 1 },
13641310
13651311 .f16 => return .{ .scalar = 2 },
13661312 .f32 => return .{ .scalar = 4 },
......@@ -1402,11 +1348,6 @@ pub fn abiSizeAdvanced(
14021348 return .{ .scalar = intAbiSize(bits, target, use_llvm) };
14031349 },
14041350
1405 .prefetch_options => unreachable, // missing call to resolveTypeFields
1406 .export_options => unreachable, // missing call to resolveTypeFields
1407 .extern_options => unreachable, // missing call to resolveTypeFields
1408
1409 .type_info => unreachable,
14101351 .noreturn => unreachable,
14111352 .generic_poison => unreachable,
14121353 },
......@@ -1751,18 +1692,6 @@ pub fn bitSizeAdvanced(
17511692 .undefined => unreachable,
17521693 .enum_literal => unreachable,
17531694 .generic_poison => unreachable,
1754
1755 .atomic_order => unreachable,
1756 .atomic_rmw_op => unreachable,
1757 .calling_convention => unreachable,
1758 .address_space => unreachable,
1759 .float_mode => unreachable,
1760 .reduce_op => unreachable,
1761 .call_modifier => unreachable,
1762 .prefetch_options => unreachable,
1763 .export_options => unreachable,
1764 .extern_options => unreachable,
1765 .type_info => unreachable,
17661695 },
17671696 .struct_type => {
17681697 const struct_type = ip.loadStructType(ty.toIntern());
......@@ -2565,17 +2494,6 @@ pub fn onePossibleValue(starting_type: Type, pt: Zcu.PerThread) !?Value {
25652494 .comptime_int,
25662495 .comptime_float,
25672496 .enum_literal,
2568 .atomic_order,
2569 .atomic_rmw_op,
2570 .calling_convention,
2571 .address_space,
2572 .float_mode,
2573 .reduce_op,
2574 .call_modifier,
2575 .prefetch_options,
2576 .export_options,
2577 .extern_options,
2578 .type_info,
25792497 .adhoc_inferred_error_set,
25802498 => return null,
25812499
......@@ -2782,16 +2700,6 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: Resolve
27822700 .adhoc_inferred_error_set,
27832701 .noreturn,
27842702 .generic_poison,
2785 .atomic_order,
2786 .atomic_rmw_op,
2787 .calling_convention,
2788 .address_space,
2789 .float_mode,
2790 .reduce_op,
2791 .call_modifier,
2792 .prefetch_options,
2793 .export_options,
2794 .extern_options,
27952703 => false,
27962704
27972705 .type,
......@@ -2800,7 +2708,6 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: Resolve
28002708 .null,
28012709 .undefined,
28022710 .enum_literal,
2803 .type_info,
28042711 => true,
28052712 },
28062713 .struct_type => {
......@@ -3534,10 +3441,6 @@ pub fn packedStructFieldPtrInfo(struct_ty: Type, parent_ptr_ty: Type, field_idx:
35343441pub fn resolveLayout(ty: Type, pt: Zcu.PerThread) SemaError!void {
35353442 const zcu = pt.zcu;
35363443 const ip = &zcu.intern_pool;
3537 switch (ip.indexToKey(ty.toIntern())) {
3538 .simple_type => |simple_type| return resolveSimpleType(simple_type, pt),
3539 else => {},
3540 }
35413444 switch (ty.zigTypeTag(zcu)) {
35423445 .Struct => switch (ip.indexToKey(ty.toIntern())) {
35433446 .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 {
36513554 .one_u8 => unreachable,
36523555 .four_u8 => unreachable,
36533556 .negative_one => unreachable,
3654 .calling_convention_c => unreachable,
3655 .calling_convention_inline => unreachable,
36563557 .void_value => unreachable,
36573558 .unreachable_value => unreachable,
36583559 .null_value => unreachable,
......@@ -3669,8 +3570,6 @@ pub fn resolveFields(ty: Type, pt: Zcu.PerThread) SemaError!void {
36693570
36703571 .type_union => return ty.resolveUnionInner(pt, .fields),
36713572
3672 .simple_type => return resolveSimpleType(ip.indexToKey(ty_ip).simple_type, pt),
3673
36743573 else => {},
36753574 },
36763575 }
......@@ -3680,11 +3579,6 @@ pub fn resolveFully(ty: Type, pt: Zcu.PerThread) SemaError!void {
36803579 const zcu = pt.zcu;
36813580 const ip = &zcu.intern_pool;
36823581
3683 switch (ip.indexToKey(ty.toIntern())) {
3684 .simple_type => |simple_type| return resolveSimpleType(simple_type, pt),
3685 else => {},
3686 }
3687
36883582 switch (ty.zigTypeTag(zcu)) {
36893583 .Type,
36903584 .Void,
......@@ -3850,28 +3744,6 @@ fn resolveUnionInner(
38503744 };
38513745}
38523746
3853/// Fully resolves a simple type. This is usually a nop, but for builtin types with
3854/// special InternPool indices (such as std.builtin.Type) it will analyze and fully
3855/// resolve the type.
3856fn resolveSimpleType(simple_type: InternPool.SimpleType, pt: Zcu.PerThread) Allocator.Error!void {
3857 const builtin_type_name: []const u8 = switch (simple_type) {
3858 .atomic_order => "AtomicOrder",
3859 .atomic_rmw_op => "AtomicRmwOp",
3860 .calling_convention => "CallingConvention",
3861 .address_space => "AddressSpace",
3862 .float_mode => "FloatMode",
3863 .reduce_op => "ReduceOp",
3864 .call_modifier => "CallModifer",
3865 .prefetch_options => "PrefetchOptions",
3866 .export_options => "ExportOptions",
3867 .extern_options => "ExternOptions",
3868 .type_info => "Type",
3869 else => return,
3870 };
3871 // This will fully resolve the type.
3872 _ = try pt.getBuiltinType(builtin_type_name);
3873}
3874
38753747/// Returns the type of a pointer to an element.
38763748/// Asserts that the type is a pointer, and that the element type is indexable.
38773749/// If the element index is comptime-known, it must be passed in `offset`.
src/Zcu/PerThread.zig+7-75
......@@ -1102,12 +1102,9 @@ fn semaCau(pt: Zcu.PerThread, cau_index: InternPool.Cau.Index) !SemaCauResult {
11021102 // We are about to re-analyze this `Cau`; drop its depenndencies.
11031103 zcu.intern_pool.removeDependenciesForDepender(gpa, anal_unit);
11041104
1105 const builtin_type_target_index: InternPool.Index = switch (cau.owner.unwrap()) {
1106 .none => ip_index: {
1107 // `comptime` decl -- we will re-analyze its body.
1108 // This declaration has no value so is definitely not a std.builtin type.
1109 break :ip_index .none;
1110 },
1105 switch (cau.owner.unwrap()) {
1106 .none => {}, // `comptime` decl -- we will re-analyze its body.
1107 .nav => {}, // Other decl -- we will re-analyze its value.
11111108 .type => |ty| {
11121109 // This is an incremental update, and this type is being re-analyzed because it is outdated.
11131110 // Create a new type in its place, and mark the old one as outdated so that use sites will
......@@ -1119,53 +1116,7 @@ fn semaCau(pt: Zcu.PerThread, cau_index: InternPool.Cau.Index) !SemaCauResult {
11191116 .invalidate_decl_ref = true,
11201117 };
11211118 },
1122 .nav => |nav| ip_index: {
1123 // Other decl -- we will re-analyze its value.
1124 // This might be a type in `builtin.zig` -- check.
1125 if (file.mod != zcu.std_mod) break :ip_index .none;
1126 // We're in the std module.
1127 const nav_name = ip.getNav(nav).name;
1128 const std_file_imported = try pt.importPkg(zcu.std_mod);
1129 const std_type = Type.fromInterned(zcu.fileRootType(std_file_imported.file_index));
1130 const std_namespace = zcu.namespacePtr(std_type.getNamespace(zcu).unwrap().?);
1131 const builtin_str = try ip.getOrPutString(gpa, pt.tid, "builtin", .no_embedded_nulls);
1132 const builtin_nav = ip.getNav(std_namespace.pub_decls.getKeyAdapted(builtin_str, Zcu.Namespace.NameAdapter{ .zcu = zcu }) orelse break :ip_index .none);
1133 const builtin_namespace = switch (builtin_nav.status) {
1134 .unresolved => break :ip_index .none,
1135 .resolved => |r| Type.fromInterned(r.val).getNamespace(zcu).unwrap().?,
1136 };
1137 if (cau.namespace != builtin_namespace) break :ip_index .none;
1138 // We're in builtin.zig. This could be a builtin we need to add to a specific InternPool index.
1139 for ([_][]const u8{
1140 "AtomicOrder",
1141 "AtomicRmwOp",
1142 "CallingConvention",
1143 "AddressSpace",
1144 "FloatMode",
1145 "ReduceOp",
1146 "CallModifier",
1147 "PrefetchOptions",
1148 "ExportOptions",
1149 "ExternOptions",
1150 "Type",
1151 }, [_]InternPool.Index{
1152 .atomic_order_type,
1153 .atomic_rmw_op_type,
1154 .calling_convention_type,
1155 .address_space_type,
1156 .float_mode_type,
1157 .reduce_op_type,
1158 .call_modifier_type,
1159 .prefetch_options_type,
1160 .export_options_type,
1161 .extern_options_type,
1162 .type_info_type,
1163 }) |type_name, type_ip| {
1164 if (nav_name.eqlSlice(type_name, ip)) break :ip_index type_ip;
1165 }
1166 break :ip_index .none;
1167 },
1168 };
1119 }
11691120
11701121 const is_usingnamespace = switch (cau.owner.unwrap()) {
11711122 .nav => |nav| ip.getNav(nav).is_usingnamespace,
......@@ -1194,7 +1145,6 @@ fn semaCau(pt: Zcu.PerThread, cau_index: InternPool.Cau.Index) !SemaCauResult {
11941145 .fn_ret_ty = Type.void,
11951146 .fn_ret_ty_ies = null,
11961147 .comptime_err_ret_trace = &comptime_err_ret_trace,
1197 .builtin_type_target_index = builtin_type_target_index,
11981148 };
11991149 defer sema.deinit();
12001150
......@@ -1249,9 +1199,6 @@ fn semaCau(pt: Zcu.PerThread, cau_index: InternPool.Cau.Index) !SemaCauResult {
12491199 .type => unreachable, // Handled at top of function.
12501200 };
12511201
1252 // We'll do more work with the Sema. Clear the target type index just in case we analyze any type.
1253 sema.builtin_type_target_index = .none;
1254
12551202 const align_src = block.src(.{ .node_offset_var_decl_align = 0 });
12561203 const section_src = block.src(.{ .node_offset_var_decl_section = 0 });
12571204 const addrspace_src = block.src(.{ .node_offset_var_decl_addrspace = 0 });
......@@ -3349,7 +3296,7 @@ pub fn ensureTypeUpToDate(pt: Zcu.PerThread, ty: InternPool.Index, already_updat
33493296 break :o o;
33503297 };
33513298 if (!outdated) return ty;
3352 return pt.recreateStructType(ty, key, struct_obj);
3299 return pt.recreateStructType(key, struct_obj);
33533300 },
33543301 .union_type => |key| {
33553302 const union_obj = ip.loadUnionType(ty);
......@@ -3364,7 +3311,7 @@ pub fn ensureTypeUpToDate(pt: Zcu.PerThread, ty: InternPool.Index, already_updat
33643311 break :o o;
33653312 };
33663313 if (!outdated) return ty;
3367 return pt.recreateUnionType(ty, key, union_obj);
3314 return pt.recreateUnionType(key, union_obj);
33683315 },
33693316 .enum_type => |key| {
33703317 const enum_obj = ip.loadEnumType(ty);
......@@ -3379,7 +3326,7 @@ pub fn ensureTypeUpToDate(pt: Zcu.PerThread, ty: InternPool.Index, already_updat
33793326 break :o o;
33803327 };
33813328 if (!outdated) return ty;
3382 return pt.recreateEnumType(ty, key, enum_obj);
3329 return pt.recreateEnumType(key, enum_obj);
33833330 },
33843331 .opaque_type => {
33853332 assert(!already_updating);
......@@ -3391,7 +3338,6 @@ pub fn ensureTypeUpToDate(pt: Zcu.PerThread, ty: InternPool.Index, already_updat
33913338
33923339fn recreateStructType(
33933340 pt: Zcu.PerThread,
3394 ty: InternPool.Index,
33953341 full_key: InternPool.Key.NamespaceType,
33963342 struct_obj: InternPool.LoadedStructType,
33973343) Zcu.SemaError!InternPool.Index {
......@@ -3406,10 +3352,6 @@ fn recreateStructType(
34063352 .declared => |d| d,
34073353 };
34083354
3409 if (@intFromEnum(ty) <= InternPool.static_len) {
3410 @panic("TODO: recreate resolved builtin type");
3411 }
3412
34133355 const inst_info = key.zir_index.resolveFull(ip) orelse return error.AnalysisFail;
34143356 const file = zcu.fileByIndex(inst_info.file);
34153357 if (file.status != .success_zir) return error.AnalysisFail;
......@@ -3482,7 +3424,6 @@ fn recreateStructType(
34823424
34833425fn recreateUnionType(
34843426 pt: Zcu.PerThread,
3485 ty: InternPool.Index,
34863427 full_key: InternPool.Key.NamespaceType,
34873428 union_obj: InternPool.LoadedUnionType,
34883429) Zcu.SemaError!InternPool.Index {
......@@ -3497,10 +3438,6 @@ fn recreateUnionType(
34973438 .declared => |d| d,
34983439 };
34993440
3500 if (@intFromEnum(ty) <= InternPool.static_len) {
3501 @panic("TODO: recreate resolved builtin type");
3502 }
3503
35043441 const inst_info = key.zir_index.resolveFull(ip) orelse return error.AnalysisFail;
35053442 const file = zcu.fileByIndex(inst_info.file);
35063443 if (file.status != .success_zir) return error.AnalysisFail;
......@@ -3581,7 +3518,6 @@ fn recreateUnionType(
35813518
35823519fn recreateEnumType(
35833520 pt: Zcu.PerThread,
3584 ty: InternPool.Index,
35853521 full_key: InternPool.Key.NamespaceType,
35863522 enum_obj: InternPool.LoadedEnumType,
35873523) Zcu.SemaError!InternPool.Index {
......@@ -3596,10 +3532,6 @@ fn recreateEnumType(
35963532 .declared => |d| d,
35973533 };
35983534
3599 if (@intFromEnum(ty) <= InternPool.static_len) {
3600 @panic("TODO: recreate resolved builtin type");
3601 }
3602
36033535 const inst_info = key.zir_index.resolveFull(ip) orelse return error.AnalysisFail;
36043536 const file = zcu.fileByIndex(inst_info.file);
36053537 if (file.status != .success_zir) return error.AnalysisFail;
src/codegen/c/Type.zig+1-23
......@@ -1389,21 +1389,6 @@ pub const Pool = struct {
13891389 .anyframe_type,
13901390 .generic_poison_type,
13911391 => unreachable,
1392 .atomic_order_type,
1393 .atomic_rmw_op_type,
1394 .calling_convention_type,
1395 .address_space_type,
1396 .float_mode_type,
1397 .reduce_op_type,
1398 .call_modifier_type,
1399 => |ip_index| return pool.fromType(
1400 allocator,
1401 scratch,
1402 Type.fromInterned(ip.loadEnumType(ip_index).tag_ty),
1403 pt,
1404 mod,
1405 kind,
1406 ),
14071392 .anyerror_type,
14081393 .anyerror_void_error_union_type,
14091394 .adhoc_inferred_error_set_type,
......@@ -1459,8 +1444,6 @@ pub const Pool = struct {
14591444 .one_u8,
14601445 .four_u8,
14611446 .negative_one,
1462 .calling_convention_c,
1463 .calling_convention_inline,
14641447 .void_value,
14651448 .unreachable_value,
14661449 .null_value,
......@@ -1471,12 +1454,7 @@ pub const Pool = struct {
14711454 .none,
14721455 => unreachable,
14731456
1474 //.prefetch_options_type,
1475 //.export_options_type,
1476 //.extern_options_type,
1477 //.type_info_type,
1478 //_,
1479 else => |ip_index| switch (ip.indexToKey(ip_index)) {
1457 _ => |ip_index| switch (ip.indexToKey(ip_index)) {
14801458 .int_type => |int_info| return pool.fromIntInfo(allocator, int_info, mod, kind),
14811459 .ptr_type => |ptr_info| switch (ptr_info.flags.size) {
14821460 .One, .Many, .C => {
src/codegen/llvm.zig-2
......@@ -3194,8 +3194,6 @@ pub const Object = struct {
31943194 .one_u8,
31953195 .four_u8,
31963196 .negative_one,
3197 .calling_convention_c,
3198 .calling_convention_inline,
31993197 .void_value,
32003198 .unreachable_value,
32013199 .null_value,
src/link/Dwarf.zig+1-13
......@@ -2565,19 +2565,7 @@ fn updateType(
25652565 try wip_nav.strp(if (type_index == .generic_poison_type) "anytype" else name);
25662566 },
25672567 .anyerror => return, // delay until flush
2568 .atomic_order,
2569 .atomic_rmw_op,
2570 .calling_convention,
2571 .address_space,
2572 .float_mode,
2573 .reduce_op,
2574 .call_modifier,
2575 .prefetch_options,
2576 .export_options,
2577 .extern_options,
2578 .type_info,
2579 .adhoc_inferred_error_set,
2580 => unreachable,
2568 .adhoc_inferred_error_set => unreachable,
25812569 },
25822570 .struct_type,
25832571 .union_type,
src/print_zir.zig+7
......@@ -615,6 +615,7 @@ const Writer = struct {
615615 .restore_err_ret_index => try self.writeRestoreErrRetIndex(stream, extended),
616616 .closure_get => try self.writeClosureGet(stream, extended),
617617 .field_parent_ptr => try self.writeFieldParentPtr(stream, extended),
618 .builtin_value => try self.writeBuiltinValue(stream, extended),
618619 }
619620 }
620621
......@@ -2782,6 +2783,12 @@ const Writer = struct {
27822783 try self.writeSrcNode(stream, @bitCast(extended.operand));
27832784 }
27842785
2786 fn writeBuiltinValue(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
2787 const val: Zir.Inst.BuiltinValue = @enumFromInt(extended.small);
2788 try stream.print("{s})) ", .{@tagName(val)});
2789 try self.writeSrcNode(stream, @bitCast(extended.operand));
2790 }
2791
27852792 fn writeInstRef(self: *Writer, stream: anytype, ref: Zir.Inst.Ref) !void {
27862793 if (ref == .none) {
27872794 return stream.writeAll(".none");