authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-08-19 06:30:54+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-08-19 06:30:54+01:00
log54e48f7b7dec96c8cdd1a0a0491554b118767817
tree0fade2355498d008e8cbe9e7e1d7ac6afdffc8c8
parentc6677be53bd41e7e9a208fb0c1c9135605c761cb
parentde49a9a17352a36a0888b03905f207b0584fc269
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #21128 from mlugg/incremental

incremental: more progress

13 files changed, 251 insertions(+), 524 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+11-143
......@@ -2160,6 +2160,14 @@ pub const Key = union(enum) {
21602160 pub fn resolvedErrorSetUnordered(func: Func, ip: *const InternPool) Index {
21612161 return @atomicLoad(Index, func.resolvedErrorSetPtr(@constCast(ip)), .unordered);
21622162 }
2163
2164 pub fn setResolvedErrorSet(func: Func, ip: *InternPool, ies: Index) void {
2165 const extra_mutex = &ip.getLocal(func.tid).mutate.extra.mutex;
2166 extra_mutex.lock();
2167 defer extra_mutex.unlock();
2168
2169 @atomicStore(Index, func.resolvedErrorSetPtr(ip), ies, .release);
2170 }
21632171 };
21642172
21652173 pub const Int = struct {
......@@ -4403,17 +4411,6 @@ pub const Index = enum(u32) {
44034411 null_type,
44044412 undefined_type,
44054413 enum_literal_type,
4406 atomic_order_type,
4407 atomic_rmw_op_type,
4408 calling_convention_type,
4409 address_space_type,
4410 float_mode_type,
4411 reduce_op_type,
4412 call_modifier_type,
4413 prefetch_options_type,
4414 export_options_type,
4415 extern_options_type,
4416 type_info_type,
44174414 manyptr_u8_type,
44184415 manyptr_const_u8_type,
44194416 manyptr_const_u8_sentinel_0_type,
......@@ -4446,10 +4443,6 @@ pub const Index = enum(u32) {
44464443 four_u8,
44474444 /// `-1` (comptime_int)
44484445 negative_one,
4449 /// `std.builtin.CallingConvention.C`
4450 calling_convention_c,
4451 /// `std.builtin.CallingConvention.Inline`
4452 calling_convention_inline,
44534446 /// `{}`
44544447 void_value,
44554448 /// `unreachable` (noreturn type)
......@@ -4829,17 +4822,6 @@ pub const static_keys = [_]Key{
48294822 .{ .simple_type = .null },
48304823 .{ .simple_type = .undefined },
48314824 .{ .simple_type = .enum_literal },
4832 .{ .simple_type = .atomic_order },
4833 .{ .simple_type = .atomic_rmw_op },
4834 .{ .simple_type = .calling_convention },
4835 .{ .simple_type = .address_space },
4836 .{ .simple_type = .float_mode },
4837 .{ .simple_type = .reduce_op },
4838 .{ .simple_type = .call_modifier },
4839 .{ .simple_type = .prefetch_options },
4840 .{ .simple_type = .export_options },
4841 .{ .simple_type = .extern_options },
4842 .{ .simple_type = .type_info },
48434825
48444826 // [*]u8
48454827 .{ .ptr_type = .{
......@@ -4868,7 +4850,7 @@ pub const static_keys = [_]Key{
48684850 },
48694851 } },
48704852
4871 // comptime_int
4853 // *const comptime_int
48724854 .{ .ptr_type = .{
48734855 .child = .comptime_int_type,
48744856 .flags = .{
......@@ -4959,16 +4941,6 @@ pub const static_keys = [_]Key{
49594941 .ty = .comptime_int_type,
49604942 .storage = .{ .i64 = -1 },
49614943 } },
4962 // calling_convention_c
4963 .{ .enum_tag = .{
4964 .ty = .calling_convention_type,
4965 .int = .one_u8,
4966 } },
4967 // calling_convention_inline
4968 .{ .enum_tag = .{
4969 .ty = .calling_convention_type,
4970 .int = .four_u8,
4971 } },
49724944
49734945 .{ .simple_value = .void },
49744946 .{ .simple_value = .@"unreachable" },
......@@ -5682,18 +5654,6 @@ pub const SimpleType = enum(u32) {
56825654 undefined = @intFromEnum(Index.undefined_type),
56835655 enum_literal = @intFromEnum(Index.enum_literal_type),
56845656
5685 atomic_order = @intFromEnum(Index.atomic_order_type),
5686 atomic_rmw_op = @intFromEnum(Index.atomic_rmw_op_type),
5687 calling_convention = @intFromEnum(Index.calling_convention_type),
5688 address_space = @intFromEnum(Index.address_space_type),
5689 float_mode = @intFromEnum(Index.float_mode_type),
5690 reduce_op = @intFromEnum(Index.reduce_op_type),
5691 call_modifier = @intFromEnum(Index.call_modifier_type),
5692 prefetch_options = @intFromEnum(Index.prefetch_options_type),
5693 export_options = @intFromEnum(Index.export_options_type),
5694 extern_options = @intFromEnum(Index.extern_options_type),
5695 type_info = @intFromEnum(Index.type_info_type),
5696
56975657 adhoc_inferred_error_set = @intFromEnum(Index.adhoc_inferred_error_set_type),
56985658 generic_poison = @intFromEnum(Index.generic_poison_type),
56995659};
......@@ -6273,18 +6233,6 @@ pub fn init(ip: *InternPool, gpa: Allocator, available_threads: usize) !void {
62736233 // Sanity check.
62746234 assert(ip.indexToKey(.bool_true).simple_value == .true);
62756235 assert(ip.indexToKey(.bool_false).simple_value == .false);
6276
6277 const cc_inline = ip.indexToKey(.calling_convention_inline).enum_tag.int;
6278 const cc_c = ip.indexToKey(.calling_convention_c).enum_tag.int;
6279
6280 assert(ip.indexToKey(cc_inline).int.storage.u64 ==
6281 @intFromEnum(std.builtin.CallingConvention.Inline));
6282
6283 assert(ip.indexToKey(cc_c).int.storage.u64 ==
6284 @intFromEnum(std.builtin.CallingConvention.C));
6285
6286 assert(ip.indexToKey(ip.typeOf(cc_inline)).int_type.bits ==
6287 @typeInfo(@typeInfo(std.builtin.CallingConvention).Enum.tag_type).Int.bits);
62886236 }
62896237}
62906238
......@@ -7100,7 +7048,7 @@ fn getOrPutKeyEnsuringAdditionalCapacity(
71007048 const index = entry.acquire();
71017049 if (index == .none) break;
71027050 if (entry.hash != hash) continue;
7103 if (ip.isRemoved(index)) continue;
7051 if (index.unwrap(ip).getTag(ip) == .removed) continue;
71047052 if (ip.indexToKey(index).eql(key, ip)) return .{ .existing = index };
71057053 }
71067054 shard.mutate.map.mutex.lock();
......@@ -9735,14 +9683,6 @@ fn addMap(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, cap: usize) Al
97359683/// Invalidates all references to this index.
97369684pub fn remove(ip: *InternPool, tid: Zcu.PerThread.Id, index: Index) void {
97379685 const unwrapped_index = index.unwrap(ip);
9738 if (@intFromEnum(index) < static_keys.len) {
9739 // The item being removed replaced a special index via `InternPool.resolveBuiltinType`.
9740 // Restore the original item at this index.
9741 assert(static_keys[@intFromEnum(index)] == .simple_type);
9742 const items = ip.getLocalShared(unwrapped_index.tid).items.acquire().view();
9743 @atomicStore(Tag, &items.items(.tag)[unwrapped_index.index], .simple_type, .unordered);
9744 return;
9745 }
97469686
97479687 if (unwrapped_index.tid == tid) {
97489688 const items_len = &ip.getLocal(unwrapped_index.tid).mutate.items.len;
......@@ -10382,17 +10322,7 @@ pub fn isIntegerType(ip: *const InternPool, ty: Index) bool {
1038210322
1038310323/// does not include .enum_literal_type
1038410324pub fn isEnumType(ip: *const InternPool, ty: Index) bool {
10385 return switch (ty) {
10386 .atomic_order_type,
10387 .atomic_rmw_op_type,
10388 .calling_convention_type,
10389 .address_space_type,
10390 .float_mode_type,
10391 .reduce_op_type,
10392 .call_modifier_type,
10393 => true,
10394 else => ip.indexToKey(ty) == .enum_type,
10395 };
10325 return ip.indexToKey(ty) == .enum_type;
1039610326}
1039710327
1039810328pub fn isUnion(ip: *const InternPool, ty: Index) bool {
......@@ -11393,17 +11323,6 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {
1139311323 .null_type,
1139411324 .undefined_type,
1139511325 .enum_literal_type,
11396 .atomic_order_type,
11397 .atomic_rmw_op_type,
11398 .calling_convention_type,
11399 .address_space_type,
11400 .float_mode_type,
11401 .reduce_op_type,
11402 .call_modifier_type,
11403 .prefetch_options_type,
11404 .export_options_type,
11405 .extern_options_type,
11406 .type_info_type,
1140711326 .manyptr_u8_type,
1140811327 .manyptr_const_u8_type,
1140911328 .manyptr_const_u8_sentinel_0_type,
......@@ -11421,7 +11340,6 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {
1142111340 .zero, .one, .negative_one => .comptime_int_type,
1142211341 .zero_usize, .one_usize => .usize_type,
1142311342 .zero_u8, .one_u8, .four_u8 => .u8_type,
11424 .calling_convention_c, .calling_convention_inline => .calling_convention_type,
1142511343 .void_value => .void_type,
1142611344 .unreachable_value => .noreturn_type,
1142711345 .null_value => .null_type,
......@@ -11717,22 +11635,6 @@ pub fn zigTypeTagOrPoison(ip: *const InternPool, index: Index) error{GenericPois
1171711635 .undefined_type => .Undefined,
1171811636 .enum_literal_type => .EnumLiteral,
1171911637
11720 .atomic_order_type,
11721 .atomic_rmw_op_type,
11722 .calling_convention_type,
11723 .address_space_type,
11724 .float_mode_type,
11725 .reduce_op_type,
11726 .call_modifier_type,
11727 => .Enum,
11728
11729 .prefetch_options_type,
11730 .export_options_type,
11731 .extern_options_type,
11732 => .Struct,
11733
11734 .type_info_type => .Union,
11735
1173611638 .manyptr_u8_type,
1173711639 .manyptr_const_u8_type,
1173811640 .manyptr_const_u8_sentinel_0_type,
......@@ -11757,8 +11659,6 @@ pub fn zigTypeTagOrPoison(ip: *const InternPool, index: Index) error{GenericPois
1175711659 .one_u8 => unreachable,
1175811660 .four_u8 => unreachable,
1175911661 .negative_one => unreachable,
11760 .calling_convention_c => unreachable,
11761 .calling_convention_inline => unreachable,
1176211662 .void_value => unreachable,
1176311663 .unreachable_value => unreachable,
1176411664 .null_value => unreachable,
......@@ -12077,34 +11977,6 @@ pub fn unwrapCoercedFunc(ip: *const InternPool, index: Index) Index {
1207711977 };
1207811978}
1207911979
12080/// Having resolved a builtin type to a real struct/union/enum (which is now at `resolverd_index`),
12081/// make `want_index` refer to this type instead. This invalidates `resolved_index`, so must be
12082/// called only when it is guaranteed that no reference to `resolved_index` exists.
12083pub fn resolveBuiltinType(
12084 ip: *InternPool,
12085 tid: Zcu.PerThread.Id,
12086 want_index: Index,
12087 resolved_index: Index,
12088) void {
12089 assert(@intFromEnum(want_index) >= @intFromEnum(Index.first_type));
12090 assert(@intFromEnum(want_index) <= @intFromEnum(Index.last_type));
12091
12092 // Make sure the type isn't already resolved!
12093 assert(ip.indexToKey(want_index) == .simple_type);
12094
12095 // Make sure it's the same kind of type
12096 assert((ip.zigTypeTagOrPoison(want_index) catch unreachable) ==
12097 (ip.zigTypeTagOrPoison(resolved_index) catch unreachable));
12098
12099 // Copy the data
12100 const item = resolved_index.unwrap(ip).getItem(ip);
12101 const unwrapped_index = want_index.unwrap(ip);
12102 var items = ip.getLocalShared(unwrapped_index.tid).items.acquire().view().slice();
12103 items.items(.data)[unwrapped_index.index] = item.data;
12104 @atomicStore(Tag, &items.items(.tag)[unwrapped_index.index], item.tag, .release);
12105 ip.remove(tid, resolved_index);
12106}
12107
1210811980pub fn anonStructFieldTypes(ip: *const InternPool, i: Index) []const Index {
1210911981 return ip.indexToKey(i).anon_struct_type.types;
1211011982}
......@@ -12303,7 +12175,3 @@ pub fn getErrorValue(
1230312175pub fn getErrorValueIfExists(ip: *const InternPool, name: NullTerminatedString) ?Zcu.ErrorInt {
1230412176 return @intFromEnum(ip.global_error_set.getErrorValueIfExists(name) orelse return null);
1230512177}
12306
12307pub fn isRemoved(ip: *const InternPool, ty: Index) bool {
12308 return ty.unwrap(ip).getTag(ip) == .removed;
12309}
src/Sema.zig+55-41
......@@ -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: {
......@@ -32527,6 +32552,7 @@ fn analyzeIsNonErrComptimeOnly(
3252732552 // If the error set is empty, we must return a comptime true or false.
3252832553 // However we want to avoid unnecessarily resolving an inferred error set
3252932554 // in case it is already non-empty.
32555 try mod.maybeUnresolveIes(func_index);
3253032556 switch (ip.funcIesResolvedUnordered(func_index)) {
3253132557 .anyerror_type => break :blk,
3253232558 .none => {},
......@@ -33596,6 +33622,7 @@ fn wrapErrorUnionSet(
3359633622 .inferred_error_set_type => |func_index| ok: {
3359733623 // We carefully do this in an order that avoids unnecessarily
3359833624 // resolving the destination error set type.
33625 try mod.maybeUnresolveIes(func_index);
3359933626 switch (ip.funcIesResolvedUnordered(func_index)) {
3360033627 .anyerror_type => break :ok,
3360133628 .none => if (.ok == try sema.coerceInMemoryAllowedErrorSets(block, dest_err_set_ty, inst_ty, inst_src, inst_src)) {
......@@ -35853,8 +35880,7 @@ fn resolveInferredErrorSet(
3585335880
3585435881 try sema.declareDependency(.{ .interned = func_index }); // resolved IES
3585535882
35856 // TODO: during an incremental update this might not be `.none`, but the
35857 // function might be out-of-date!
35883 try zcu.maybeUnresolveIes(func_index);
3585835884 const resolved_ty = func.resolvedErrorSetUnordered(ip);
3585935885 if (resolved_ty != .none) return resolved_ty;
3586035886
......@@ -36898,17 +36924,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3689836924 .comptime_int_type,
3689936925 .comptime_float_type,
3690036926 .enum_literal_type,
36901 .atomic_order_type,
36902 .atomic_rmw_op_type,
36903 .calling_convention_type,
36904 .address_space_type,
36905 .float_mode_type,
36906 .reduce_op_type,
36907 .call_modifier_type,
36908 .prefetch_options_type,
36909 .export_options_type,
36910 .extern_options_type,
36911 .type_info_type,
3691236927 .manyptr_u8_type,
3691336928 .manyptr_const_u8_type,
3691436929 .manyptr_const_u8_sentinel_0_type,
......@@ -36935,8 +36950,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3693536950 .one_u8,
3693636951 .four_u8,
3693736952 .negative_one,
36938 .calling_convention_c,
36939 .calling_convention_inline,
3694036953 .void_value,
3694136954 .unreachable_value,
3694236955 .null_value,
......@@ -37290,7 +37303,8 @@ pub fn analyzeAsAddressSpace(
3729037303) !std.builtin.AddressSpace {
3729137304 const pt = sema.pt;
3729237305 const mod = pt.zcu;
37293 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);
3729437308 const addrspace_val = try sema.resolveConstDefinedValue(block, src, coerced, .{
3729537309 .needed_comptime_reason = "address space must be comptime-known",
3729637310 });
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.zig+26
......@@ -3468,3 +3468,29 @@ fn formatDependee(data: struct { dependee: InternPool.Dependee, zcu: *Zcu }, com
34683468 },
34693469 }
34703470}
3471
3472/// Given the `InternPool.Index` of a function, set its resolved IES to `.none` if it
3473/// may be outdated. `Sema` should do this before ever loading a resolved IES.
3474pub fn maybeUnresolveIes(zcu: *Zcu, func_index: InternPool.Index) !void {
3475 const unit = AnalUnit.wrap(.{ .func = func_index });
3476 if (zcu.outdated.contains(unit) or zcu.potentially_outdated.contains(unit)) {
3477 // We're consulting the resolved IES now, but the function is outdated, so its
3478 // IES may have changed. We have to assume the IES is outdated and set the resolved
3479 // set back to `.none`.
3480 //
3481 // This will cause `PerThread.analyzeFnBody` to mark the IES as outdated when it's
3482 // eventually hit.
3483 //
3484 // Since the IES needs to be resolved, the function body will now definitely need
3485 // re-analysis (even if the IES turns out to be the same!), so mark it as
3486 // definitely-outdated if it's only PO.
3487 if (zcu.potentially_outdated.fetchSwapRemove(unit)) |kv| {
3488 const gpa = zcu.gpa;
3489 try zcu.outdated.putNoClobber(gpa, unit, kv.value);
3490 if (kv.value == 0) {
3491 try zcu.outdated_ready.put(gpa, unit, {});
3492 }
3493 }
3494 zcu.intern_pool.funcSetIesResolved(func_index, .none);
3495 }
3496}
src/Zcu/PerThread.zig+29-100
......@@ -734,31 +734,25 @@ fn ensureFuncBodyAnalyzedInner(
734734 const func = zcu.funcInfo(func_index);
735735 const anal_unit = AnalUnit.wrap(.{ .func = func_index });
736736
737 // Here's an interesting question: is this function actually valid?
738 // Maybe the signature changed, so we'll end up creating a whole different `func`
739 // in the InternPool, and this one is a waste of time to analyze. Worse, we'd be
740 // analyzing new ZIR with old data, and get bogus errors. They would be unused,
741 // but they would still hang around internally! So, let's detect this case.
742 // For function decls, we must ensure the declaration's `Cau` is up-to-date, and
743 // check if `func_index` was removed by that update.
744 // For function instances, we do that process on the generic owner.
745
746 try pt.ensureCauAnalyzed(cau: {
747 const func_nav = if (func.generic_owner == .none)
748 func.owner_nav
749 else
750 zcu.funcInfo(func.generic_owner).owner_nav;
751
752 break :cau ip.getNav(func_nav).analysis_owner.unwrap().?;
753 });
754
755 if (ip.isRemoved(func_index) or (func.generic_owner != .none and ip.isRemoved(func.generic_owner))) {
756 if (func_outdated) {
757 try zcu.markDependeeOutdated(.marked_po, .{ .interned = func_index }); // IES
737 // Make sure that this function is still owned by the same `Nav`. Otherwise, analyzing
738 // it would be a waste of time in the best case, and could cause codegen to give bogus
739 // results in the worst case.
740
741 if (func.generic_owner == .none) {
742 try pt.ensureCauAnalyzed(ip.getNav(func.owner_nav).analysis_owner.unwrap().?);
743 if (ip.getNav(func.owner_nav).status.resolved.val != func_index) {
744 // This function is no longer referenced! There's no point in re-analyzing it.
745 // Just mark a transitive failure and move on.
746 return error.AnalysisFail;
747 }
748 } else {
749 const go_nav = zcu.funcInfo(func.generic_owner).owner_nav;
750 try pt.ensureCauAnalyzed(ip.getNav(go_nav).analysis_owner.unwrap().?);
751 if (ip.getNav(go_nav).status.resolved.val != func.generic_owner) {
752 // The generic owner is no longer referenced, so this function is also unreferenced.
753 // There's no point in re-analyzing it. Just mark a transitive failure and move on.
754 return error.AnalysisFail;
758755 }
759 ip.removeDependenciesForDepender(gpa, AnalUnit.wrap(.{ .func = func_index }));
760 ip.remove(pt.tid, func_index);
761 @panic("TODO: remove orphaned function from binary");
762756 }
763757
764758 // We'll want to remember what the IES used to be before the update for
......@@ -1108,12 +1102,9 @@ fn semaCau(pt: Zcu.PerThread, cau_index: InternPool.Cau.Index) !SemaCauResult {
11081102 // We are about to re-analyze this `Cau`; drop its depenndencies.
11091103 zcu.intern_pool.removeDependenciesForDepender(gpa, anal_unit);
11101104
1111 const builtin_type_target_index: InternPool.Index = switch (cau.owner.unwrap()) {
1112 .none => ip_index: {
1113 // `comptime` decl -- we will re-analyze its body.
1114 // This declaration has no value so is definitely not a std.builtin type.
1115 break :ip_index .none;
1116 },
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.
11171108 .type => |ty| {
11181109 // This is an incremental update, and this type is being re-analyzed because it is outdated.
11191110 // Create a new type in its place, and mark the old one as outdated so that use sites will
......@@ -1125,53 +1116,7 @@ fn semaCau(pt: Zcu.PerThread, cau_index: InternPool.Cau.Index) !SemaCauResult {
11251116 .invalidate_decl_ref = true,
11261117 };
11271118 },
1128 .nav => |nav| ip_index: {
1129 // Other decl -- we will re-analyze its value.
1130 // This might be a type in `builtin.zig` -- check.
1131 if (file.mod != zcu.std_mod) break :ip_index .none;
1132 // We're in the std module.
1133 const nav_name = ip.getNav(nav).name;
1134 const std_file_imported = try pt.importPkg(zcu.std_mod);
1135 const std_type = Type.fromInterned(zcu.fileRootType(std_file_imported.file_index));
1136 const std_namespace = zcu.namespacePtr(std_type.getNamespace(zcu).unwrap().?);
1137 const builtin_str = try ip.getOrPutString(gpa, pt.tid, "builtin", .no_embedded_nulls);
1138 const builtin_nav = ip.getNav(std_namespace.pub_decls.getKeyAdapted(builtin_str, Zcu.Namespace.NameAdapter{ .zcu = zcu }) orelse break :ip_index .none);
1139 const builtin_namespace = switch (builtin_nav.status) {
1140 .unresolved => break :ip_index .none,
1141 .resolved => |r| Type.fromInterned(r.val).getNamespace(zcu).unwrap().?,
1142 };
1143 if (cau.namespace != builtin_namespace) break :ip_index .none;
1144 // We're in builtin.zig. This could be a builtin we need to add to a specific InternPool index.
1145 for ([_][]const u8{
1146 "AtomicOrder",
1147 "AtomicRmwOp",
1148 "CallingConvention",
1149 "AddressSpace",
1150 "FloatMode",
1151 "ReduceOp",
1152 "CallModifier",
1153 "PrefetchOptions",
1154 "ExportOptions",
1155 "ExternOptions",
1156 "Type",
1157 }, [_]InternPool.Index{
1158 .atomic_order_type,
1159 .atomic_rmw_op_type,
1160 .calling_convention_type,
1161 .address_space_type,
1162 .float_mode_type,
1163 .reduce_op_type,
1164 .call_modifier_type,
1165 .prefetch_options_type,
1166 .export_options_type,
1167 .extern_options_type,
1168 .type_info_type,
1169 }) |type_name, type_ip| {
1170 if (nav_name.eqlSlice(type_name, ip)) break :ip_index type_ip;
1171 }
1172 break :ip_index .none;
1173 },
1174 };
1119 }
11751120
11761121 const is_usingnamespace = switch (cau.owner.unwrap()) {
11771122 .nav => |nav| ip.getNav(nav).is_usingnamespace,
......@@ -1200,7 +1145,6 @@ fn semaCau(pt: Zcu.PerThread, cau_index: InternPool.Cau.Index) !SemaCauResult {
12001145 .fn_ret_ty = Type.void,
12011146 .fn_ret_ty_ies = null,
12021147 .comptime_err_ret_trace = &comptime_err_ret_trace,
1203 .builtin_type_target_index = builtin_type_target_index,
12041148 };
12051149 defer sema.deinit();
12061150
......@@ -1255,9 +1199,6 @@ fn semaCau(pt: Zcu.PerThread, cau_index: InternPool.Cau.Index) !SemaCauResult {
12551199 .type => unreachable, // Handled at top of function.
12561200 };
12571201
1258 // We'll do more work with the Sema. Clear the target type index just in case we analyze any type.
1259 sema.builtin_type_target_index = .none;
1260
12611202 const align_src = block.src(.{ .node_offset_var_decl_align = 0 });
12621203 const section_src = block.src(.{ .node_offset_var_decl_section = 0 });
12631204 const addrspace_src = block.src(.{ .node_offset_var_decl_addrspace = 0 });
......@@ -2072,6 +2013,9 @@ fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index) Zcu.SemaError!
20722013 errdefer _ = zcu.analysis_in_progress.swapRemove(anal_unit);
20732014
20742015 func.setAnalysisState(ip, .analyzed);
2016 if (func.analysisUnordered(ip).inferred_error_set) {
2017 func.setResolvedErrorSet(ip, .none);
2018 }
20752019
20762020 // This is the `Cau` corresponding to the `declaration` instruction which the function or its generic owner originates from.
20772021 const decl_cau = ip.getCau(cau: {
......@@ -2278,7 +2222,7 @@ fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index) Zcu.SemaError!
22782222 else => |e| return e,
22792223 };
22802224 assert(ies.resolved != .none);
2281 ip.funcSetIesResolved(func_index, ies.resolved);
2225 func.setResolvedErrorSet(ip, ies.resolved);
22822226 }
22832227
22842228 assert(zcu.analysis_in_progress.swapRemove(anal_unit));
......@@ -3352,7 +3296,7 @@ pub fn ensureTypeUpToDate(pt: Zcu.PerThread, ty: InternPool.Index, already_updat
33523296 break :o o;
33533297 };
33543298 if (!outdated) return ty;
3355 return pt.recreateStructType(ty, key, struct_obj);
3299 return pt.recreateStructType(key, struct_obj);
33563300 },
33573301 .union_type => |key| {
33583302 const union_obj = ip.loadUnionType(ty);
......@@ -3367,7 +3311,7 @@ pub fn ensureTypeUpToDate(pt: Zcu.PerThread, ty: InternPool.Index, already_updat
33673311 break :o o;
33683312 };
33693313 if (!outdated) return ty;
3370 return pt.recreateUnionType(ty, key, union_obj);
3314 return pt.recreateUnionType(key, union_obj);
33713315 },
33723316 .enum_type => |key| {
33733317 const enum_obj = ip.loadEnumType(ty);
......@@ -3382,7 +3326,7 @@ pub fn ensureTypeUpToDate(pt: Zcu.PerThread, ty: InternPool.Index, already_updat
33823326 break :o o;
33833327 };
33843328 if (!outdated) return ty;
3385 return pt.recreateEnumType(ty, key, enum_obj);
3329 return pt.recreateEnumType(key, enum_obj);
33863330 },
33873331 .opaque_type => {
33883332 assert(!already_updating);
......@@ -3394,7 +3338,6 @@ pub fn ensureTypeUpToDate(pt: Zcu.PerThread, ty: InternPool.Index, already_updat
33943338
33953339fn recreateStructType(
33963340 pt: Zcu.PerThread,
3397 ty: InternPool.Index,
33983341 full_key: InternPool.Key.NamespaceType,
33993342 struct_obj: InternPool.LoadedStructType,
34003343) Zcu.SemaError!InternPool.Index {
......@@ -3409,10 +3352,6 @@ fn recreateStructType(
34093352 .declared => |d| d,
34103353 };
34113354
3412 if (@intFromEnum(ty) <= InternPool.static_len) {
3413 @panic("TODO: recreate resolved builtin type");
3414 }
3415
34163355 const inst_info = key.zir_index.resolveFull(ip) orelse return error.AnalysisFail;
34173356 const file = zcu.fileByIndex(inst_info.file);
34183357 if (file.status != .success_zir) return error.AnalysisFail;
......@@ -3485,7 +3424,6 @@ fn recreateStructType(
34853424
34863425fn recreateUnionType(
34873426 pt: Zcu.PerThread,
3488 ty: InternPool.Index,
34893427 full_key: InternPool.Key.NamespaceType,
34903428 union_obj: InternPool.LoadedUnionType,
34913429) Zcu.SemaError!InternPool.Index {
......@@ -3500,10 +3438,6 @@ fn recreateUnionType(
35003438 .declared => |d| d,
35013439 };
35023440
3503 if (@intFromEnum(ty) <= InternPool.static_len) {
3504 @panic("TODO: recreate resolved builtin type");
3505 }
3506
35073441 const inst_info = key.zir_index.resolveFull(ip) orelse return error.AnalysisFail;
35083442 const file = zcu.fileByIndex(inst_info.file);
35093443 if (file.status != .success_zir) return error.AnalysisFail;
......@@ -3584,7 +3518,6 @@ fn recreateUnionType(
35843518
35853519fn recreateEnumType(
35863520 pt: Zcu.PerThread,
3587 ty: InternPool.Index,
35883521 full_key: InternPool.Key.NamespaceType,
35893522 enum_obj: InternPool.LoadedEnumType,
35903523) Zcu.SemaError!InternPool.Index {
......@@ -3599,10 +3532,6 @@ fn recreateEnumType(
35993532 .declared => |d| d,
36003533 };
36013534
3602 if (@intFromEnum(ty) <= InternPool.static_len) {
3603 @panic("TODO: recreate resolved builtin type");
3604 }
3605
36063535 const inst_info = key.zir_index.resolveFull(ip) orelse return error.AnalysisFail;
36073536 const file = zcu.fileByIndex(inst_info.file);
36083537 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
......@@ -3195,8 +3195,6 @@ pub const Object = struct {
31953195 .one_u8,
31963196 .four_u8,
31973197 .negative_one,
3198 .calling_convention_c,
3199 .calling_convention_inline,
32003198 .void_value,
32013199 .unreachable_value,
32023200 .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");
test/incremental/type_becomes_comptime_only created+39
......@@ -0,0 +1,39 @@
1#target=x86_64-linux
2#update=initial version
3#file=main.zig
4const SomeType = u32;
5const S = struct {
6 x: SomeType,
7 fn foo(_: S) void {}
8};
9pub fn main() void {
10 const s: S = .{ .x = 456 };
11 s.foo();
12}
13#expect_stdout=""
14
15#update=make S comptime-only
16#file=main.zig
17const SomeType = comptime_int;
18const S = struct {
19 x: SomeType,
20 fn foo(_: S) void {}
21};
22pub fn main() void {
23 const s: S = .{ .x = 456 };
24 s.foo();
25}
26#expect_stdout=""
27
28#update=make S runtime again
29#file=main.zig
30const SomeType = u16;
31const S = struct {
32 x: SomeType,
33 fn foo(_: S) void {}
34};
35pub fn main() void {
36 const s: S = .{ .x = 456 };
37 s.foo();
38}
39#expect_stdout=""