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 {...@@ -366,7 +366,6 @@ const ResultInfo = struct {
366};366};
367367
368const coerced_align_ri: ResultInfo = .{ .rl = .{ .coerced_ty = .u29_type } };368const coerced_align_ri: ResultInfo = .{ .rl = .{ .coerced_ty = .u29_type } };
369const coerced_addrspace_ri: ResultInfo = .{ .rl = .{ .coerced_ty = .address_space_type } };
370const coerced_linksection_ri: ResultInfo = .{ .rl = .{ .coerced_ty = .slice_const_u8_type } };369const coerced_linksection_ri: ResultInfo = .{ .rl = .{ .coerced_ty = .slice_const_u8_type } };
371const coerced_type_ri: ResultInfo = .{ .rl = .{ .coerced_ty = .type_type } };370const coerced_type_ri: ResultInfo = .{ .rl = .{ .coerced_ty = .type_type } };
372const coerced_bool_ri: ResultInfo = .{ .rl = .{ .coerced_ty = .bool_type } };371const coerced_bool_ri: ResultInfo = .{ .rl = .{ .coerced_ty = .bool_type } };
...@@ -1387,7 +1386,7 @@ fn fnProtoExpr(...@@ -1387,7 +1386,7 @@ fn fnProtoExpr(
1387 try expr(1386 try expr(
1388 &block_scope,1387 &block_scope,
1389 scope,1388 scope,
1390 .{ .rl = .{ .coerced_ty = .calling_convention_type } },1389 .{ .rl = .{ .coerced_ty = try block_scope.addBuiltinValue(fn_proto.ast.callconv_expr, .calling_convention) } },
1391 fn_proto.ast.callconv_expr,1390 fn_proto.ast.callconv_expr,
1392 )1391 )
1393 else1392 else
...@@ -3804,7 +3803,8 @@ fn ptrType(...@@ -3804,7 +3803,8 @@ fn ptrType(
3804 gz.astgen.source_line = source_line;3803 gz.astgen.source_line = source_line;
3805 gz.astgen.source_column = source_column;3804 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);
3808 trailing_count += 1;3808 trailing_count += 1;
3809 }3809 }
3810 if (ptr_info.ast.align_node != 0) {3810 if (ptr_info.ast.align_node != 0) {
...@@ -4202,7 +4202,8 @@ fn fnDecl(...@@ -4202,7 +4202,8 @@ fn fnDecl(
4202 var addrspace_gz = decl_gz.makeSubBlock(params_scope);4202 var addrspace_gz = decl_gz.makeSubBlock(params_scope);
4203 defer addrspace_gz.unstack();4203 defer addrspace_gz.unstack();
4204 const addrspace_ref: Zir.Inst.Ref = if (fn_proto.ast.addrspace_expr == 0) .none else inst: {4204 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);
4206 if (addrspace_gz.instructionsSlice().len == 0) {4207 if (addrspace_gz.instructionsSlice().len == 0) {
4207 // In this case we will send a len=0 body which can be encoded more efficiently.4208 // In this case we will send a len=0 body which can be encoded more efficiently.
4208 break :inst inst;4209 break :inst inst;
...@@ -4235,9 +4236,9 @@ fn fnDecl(...@@ -4235,9 +4236,9 @@ fn fnDecl(
4235 );4236 );
4236 }4237 }
4237 const inst = try expr(4238 const inst = try expr(
4238 &decl_gz,4239 &cc_gz,
4239 params_scope,4240 params_scope,
4240 .{ .rl = .{ .coerced_ty = .calling_convention_type } },4241 .{ .rl = .{ .coerced_ty = try cc_gz.addBuiltinValue(fn_proto.ast.callconv_expr, .calling_convention) } },
4241 fn_proto.ast.callconv_expr,4242 fn_proto.ast.callconv_expr,
4242 );4243 );
4243 if (cc_gz.instructionsSlice().len == 0) {4244 if (cc_gz.instructionsSlice().len == 0) {
...@@ -4247,10 +4248,13 @@ fn fnDecl(...@@ -4247,10 +4248,13 @@ fn fnDecl(
4247 _ = try cc_gz.addBreak(.break_inline, @enumFromInt(0), inst);4248 _ = try cc_gz.addBreak(.break_inline, @enumFromInt(0), inst);
4248 break :blk inst;4249 break :blk inst;
4249 } else if (is_extern) {4250 } else if (is_extern) {
4250 // note: https://github.com/ziglang/zig/issues/52694251 const inst = try cc_gz.addBuiltinValue(decl_node, .calling_convention_c);
4251 break :blk .calling_convention_c;4252 _ = try cc_gz.addBreak(.break_inline, @enumFromInt(0), inst);
4253 break :blk inst;
4252 } else if (has_inline_keyword) {4254 } 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;
4254 } else {4258 } else {
4255 break :blk .none;4259 break :blk .none;
4256 }4260 }
...@@ -4525,7 +4529,8 @@ fn globalVarDecl(...@@ -4525,7 +4529,8 @@ fn globalVarDecl(
45254529
4526 var addrspace_gz = linksection_gz.makeSubBlock(scope);4530 var addrspace_gz = linksection_gz.makeSubBlock(scope);
4527 if (var_decl.ast.addrspace_node != 0) {4531 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);
4529 _ = try addrspace_gz.addBreakWithSrcNode(.break_inline, decl_inst, addrspace_inst, node);4534 _ = try addrspace_gz.addBreakWithSrcNode(.break_inline, decl_inst, addrspace_inst, node);
4530 }4535 }
45314536
...@@ -9169,6 +9174,7 @@ fn builtinCall(...@@ -9169,6 +9174,7 @@ fn builtinCall(
9169 // zig fmt: on9174 // zig fmt: on
91709175
9171 .@"export" => {9176 .@"export" => {
9177 const export_options_ty = try gz.addBuiltinValue(node, .export_options);
9172 const node_tags = tree.nodes.items(.tag);9178 const node_tags = tree.nodes.items(.tag);
9173 const node_datas = tree.nodes.items(.data);9179 const node_datas = tree.nodes.items(.data);
9174 // This function causes a Decl to be exported. The first parameter is not an expression,9180 // This function causes a Decl to be exported. The first parameter is not an expression,
...@@ -9192,7 +9198,7 @@ fn builtinCall(...@@ -9192,7 +9198,7 @@ fn builtinCall(
9192 local_val.used = ident_token;9198 local_val.used = ident_token;
9193 _ = try gz.addPlNode(.export_value, node, Zir.Inst.ExportValue{9199 _ = try gz.addPlNode(.export_value, node, Zir.Inst.ExportValue{
9194 .operand = local_val.inst,9200 .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]),
9196 });9202 });
9197 return rvalue(gz, ri, .void_value, node);9203 return rvalue(gz, ri, .void_value, node);
9198 }9204 }
...@@ -9207,7 +9213,7 @@ fn builtinCall(...@@ -9207,7 +9213,7 @@ fn builtinCall(
9207 const loaded = try gz.addUnNode(.load, local_ptr.ptr, node);9213 const loaded = try gz.addUnNode(.load, local_ptr.ptr, node);
9208 _ = try gz.addPlNode(.export_value, node, Zir.Inst.ExportValue{9214 _ = try gz.addPlNode(.export_value, node, Zir.Inst.ExportValue{
9209 .operand = loaded,9215 .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]),
9211 });9217 });
9212 return rvalue(gz, ri, .void_value, node);9218 return rvalue(gz, ri, .void_value, node);
9213 }9219 }
...@@ -9245,7 +9251,7 @@ fn builtinCall(...@@ -9245,7 +9251,7 @@ fn builtinCall(
9245 },9251 },
9246 else => return astgen.failNode(params[0], "symbol to export must identify a declaration", .{}),9252 else => return astgen.failNode(params[0], "symbol to export must identify a declaration", .{}),
9247 }9253 }
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]);
9249 _ = try gz.addPlNode(.@"export", node, Zir.Inst.Export{9255 _ = try gz.addPlNode(.@"export", node, Zir.Inst.Export{
9250 .namespace = namespace,9256 .namespace = namespace,
9251 .decl_name = decl_name,9257 .decl_name = decl_name,
...@@ -9255,7 +9261,8 @@ fn builtinCall(...@@ -9255,7 +9261,8 @@ fn builtinCall(
9255 },9261 },
9256 .@"extern" => {9262 .@"extern" => {
9257 const type_inst = try typeExpr(gz, scope, params[0]);9263 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]);
9259 const result = try gz.addExtendedPayload(.builtin_extern, Zir.Inst.BinNode{9266 const result = try gz.addExtendedPayload(.builtin_extern, Zir.Inst.BinNode{
9260 .node = gz.nodeIndexToRelative(node),9267 .node = gz.nodeIndexToRelative(node),
9261 .lhs = type_inst,9268 .lhs = type_inst,
...@@ -9264,7 +9271,8 @@ fn builtinCall(...@@ -9264,7 +9271,8 @@ fn builtinCall(
9264 return rvalue(gz, ri, result, node);9271 return rvalue(gz, ri, result, node);
9265 },9272 },
9266 .fence => {9273 .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]);
9268 _ = try gz.addExtendedPayload(.fence, Zir.Inst.UnNode{9276 _ = try gz.addExtendedPayload(.fence, Zir.Inst.UnNode{
9269 .node = gz.nodeIndexToRelative(node),9277 .node = gz.nodeIndexToRelative(node),
9270 .operand = order,9278 .operand = order,
...@@ -9272,7 +9280,8 @@ fn builtinCall(...@@ -9272,7 +9280,8 @@ fn builtinCall(
9272 return rvalue(gz, ri, .void_value, node);9280 return rvalue(gz, ri, .void_value, node);
9273 },9281 },
9274 .set_float_mode => {9282 .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]);
9276 _ = try gz.addExtendedPayload(.set_float_mode, Zir.Inst.UnNode{9285 _ = try gz.addExtendedPayload(.set_float_mode, Zir.Inst.UnNode{
9277 .node = gz.nodeIndexToRelative(node),9286 .node = gz.nodeIndexToRelative(node),
9278 .operand = order,9287 .operand = order,
...@@ -9365,7 +9374,8 @@ fn builtinCall(...@@ -9365,7 +9374,8 @@ fn builtinCall(
9365 },9374 },
93669375
9367 .Type => {9376 .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
9370 const gpa = gz.astgen.gpa;9380 const gpa = gz.astgen.gpa;
93719381
...@@ -9502,7 +9512,8 @@ fn builtinCall(...@@ -9502,7 +9512,8 @@ fn builtinCall(
9502 return rvalue(gz, ri, result, node);9512 return rvalue(gz, ri, result, node);
9503 },9513 },
9504 .reduce => {9514 .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]);
9506 const scalar = try expr(gz, scope, .{ .rl = .none }, params[1]);9517 const scalar = try expr(gz, scope, .{ .rl = .none }, params[1]);
9507 const result = try gz.addPlNode(.reduce, node, Zir.Inst.Bin{9518 const result = try gz.addPlNode(.reduce, node, Zir.Inst.Bin{
9508 .lhs = op,9519 .lhs = op,
...@@ -9517,34 +9528,38 @@ fn builtinCall(...@@ -9517,34 +9528,38 @@ fn builtinCall(
9517 .shl_with_overflow => return overflowArithmetic(gz, scope, ri, node, params, .shl_with_overflow),9528 .shl_with_overflow => return overflowArithmetic(gz, scope, ri, node, params, .shl_with_overflow),
95189529
9519 .atomic_load => {9530 .atomic_load => {
9531 const atomic_order_type = try gz.addBuiltinValue(node, .atomic_order);
9520 const result = try gz.addPlNode(.atomic_load, node, Zir.Inst.AtomicLoad{9532 const result = try gz.addPlNode(.atomic_load, node, Zir.Inst.AtomicLoad{
9521 // zig fmt: off9533 // zig fmt: off
9522 .elem_type = try typeExpr(gz, scope, params[0]),9534 .elem_type = try typeExpr(gz, scope, params[0]),
9523 .ptr = try expr (gz, scope, .{ .rl = .none }, params[1]),9535 .ptr = try expr (gz, scope, .{ .rl = .none }, params[1]),
9524 .ordering = try expr (gz, scope, .{ .rl = .{ .coerced_ty = .atomic_order_type } }, params[2]),9536 .ordering = try expr (gz, scope, .{ .rl = .{ .coerced_ty = atomic_order_type } }, params[2]),
9525 // zig fmt: on9537 // zig fmt: on
9526 });9538 });
9527 return rvalue(gz, ri, result, node);9539 return rvalue(gz, ri, result, node);
9528 },9540 },
9529 .atomic_rmw => {9541 .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);
9530 const int_type = try typeExpr(gz, scope, params[0]);9544 const int_type = try typeExpr(gz, scope, params[0]);
9531 const result = try gz.addPlNode(.atomic_rmw, node, Zir.Inst.AtomicRmw{9545 const result = try gz.addPlNode(.atomic_rmw, node, Zir.Inst.AtomicRmw{
9532 // zig fmt: off9546 // zig fmt: off
9533 .ptr = try expr(gz, scope, .{ .rl = .none }, params[1]),9547 .ptr = try expr(gz, scope, .{ .rl = .none }, params[1]),
9534 .operation = try expr(gz, scope, .{ .rl = .{ .coerced_ty = .atomic_rmw_op_type } }, params[2]),9548 .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]),9549 .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]),9550 .ordering = try expr(gz, scope, .{ .rl = .{ .coerced_ty = atomic_order_type } }, params[4]),
9537 // zig fmt: on9551 // zig fmt: on
9538 });9552 });
9539 return rvalue(gz, ri, result, node);9553 return rvalue(gz, ri, result, node);
9540 },9554 },
9541 .atomic_store => {9555 .atomic_store => {
9556 const atomic_order_type = try gz.addBuiltinValue(node, .atomic_order);
9542 const int_type = try typeExpr(gz, scope, params[0]);9557 const int_type = try typeExpr(gz, scope, params[0]);
9543 _ = try gz.addPlNode(.atomic_store, node, Zir.Inst.AtomicStore{9558 _ = try gz.addPlNode(.atomic_store, node, Zir.Inst.AtomicStore{
9544 // zig fmt: off9559 // zig fmt: off
9545 .ptr = try expr(gz, scope, .{ .rl = .none }, params[1]),9560 .ptr = try expr(gz, scope, .{ .rl = .none }, params[1]),
9546 .operand = try expr(gz, scope, .{ .rl = .{ .ty = int_type } }, params[2]),9561 .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]),9562 .ordering = try expr(gz, scope, .{ .rl = .{ .coerced_ty = atomic_order_type } }, params[3]),
9548 // zig fmt: on9563 // zig fmt: on
9549 });9564 });
9550 return rvalue(gz, ri, .void_value, node);9565 return rvalue(gz, ri, .void_value, node);
...@@ -9562,7 +9577,8 @@ fn builtinCall(...@@ -9562,7 +9577,8 @@ fn builtinCall(
9562 return rvalue(gz, ri, result, node);9577 return rvalue(gz, ri, result, node);
9563 },9578 },
9564 .call => {9579 .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]);
9566 const callee = try expr(gz, scope, .{ .rl = .none }, params[1]);9582 const callee = try expr(gz, scope, .{ .rl = .none }, params[1]);
9567 const args = try expr(gz, scope, .{ .rl = .none }, params[2]);9583 const args = try expr(gz, scope, .{ .rl = .none }, params[2]);
9568 const result = try gz.addPlNode(.builtin_call, node, Zir.Inst.BuiltinCall{9584 const result = try gz.addPlNode(.builtin_call, node, Zir.Inst.BuiltinCall{
...@@ -9641,8 +9657,9 @@ fn builtinCall(...@@ -9641,8 +9657,9 @@ fn builtinCall(
9641 return rvalue(gz, ri, result, node);9657 return rvalue(gz, ri, result, node);
9642 },9658 },
9643 .prefetch => {9659 .prefetch => {
9660 const prefetch_options_ty = try gz.addBuiltinValue(node, .prefetch_options);
9644 const ptr = try expr(gz, scope, .{ .rl = .none }, params[0]);9661 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]);
9646 _ = try gz.addExtendedPayload(.prefetch, Zir.Inst.BinNode{9663 _ = try gz.addExtendedPayload(.prefetch, Zir.Inst.BinNode{
9647 .node = gz.nodeIndexToRelative(node),9664 .node = gz.nodeIndexToRelative(node),
9648 .lhs = ptr,9665 .lhs = ptr,
...@@ -9812,14 +9829,15 @@ fn cmpxchg(...@@ -9812,14 +9829,15 @@ fn cmpxchg(
9812 small: u16,9829 small: u16,
9813) InnerError!Zir.Inst.Ref {9830) InnerError!Zir.Inst.Ref {
9814 const int_type = try typeExpr(gz, scope, params[0]);9831 const int_type = try typeExpr(gz, scope, params[0]);
9832 const atomic_order_type = try gz.addBuiltinValue(node, .atomic_order);
9815 const result = try gz.addExtendedPayloadSmall(.cmpxchg, small, Zir.Inst.Cmpxchg{9833 const result = try gz.addExtendedPayloadSmall(.cmpxchg, small, Zir.Inst.Cmpxchg{
9816 // zig fmt: off9834 // zig fmt: off
9817 .node = gz.nodeIndexToRelative(node),9835 .node = gz.nodeIndexToRelative(node),
9818 .ptr = try expr(gz, scope, .{ .rl = .none }, params[1]),9836 .ptr = try expr(gz, scope, .{ .rl = .none }, params[1]),
9819 .expected_value = try expr(gz, scope, .{ .rl = .{ .ty = int_type } }, params[2]),9837 .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]),9838 .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]),9839 .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]),9840 .failure_order = try expr(gz, scope, .{ .rl = .{ .coerced_ty = atomic_order_type } }, params[5]),
9823 // zig fmt: on9841 // zig fmt: on
9824 });9842 });
9825 return rvalue(gz, ri, result, node);9843 return rvalue(gz, ri, result, node);
...@@ -11106,17 +11124,6 @@ fn rvalueInner(...@@ -11106,17 +11124,6 @@ fn rvalueInner(
11106 as_ty | @intFromEnum(Zir.Inst.Ref.null_type),11124 as_ty | @intFromEnum(Zir.Inst.Ref.null_type),
11107 as_ty | @intFromEnum(Zir.Inst.Ref.undefined_type),11125 as_ty | @intFromEnum(Zir.Inst.Ref.undefined_type),
11108 as_ty | @intFromEnum(Zir.Inst.Ref.enum_literal_type),11126 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),
11120 as_ty | @intFromEnum(Zir.Inst.Ref.manyptr_u8_type),11127 as_ty | @intFromEnum(Zir.Inst.Ref.manyptr_u8_type),
11121 as_ty | @intFromEnum(Zir.Inst.Ref.manyptr_const_u8_type),11128 as_ty | @intFromEnum(Zir.Inst.Ref.manyptr_const_u8_type),
11122 as_ty | @intFromEnum(Zir.Inst.Ref.manyptr_const_u8_sentinel_0_type),11129 as_ty | @intFromEnum(Zir.Inst.Ref.manyptr_const_u8_sentinel_0_type),
...@@ -12572,6 +12579,10 @@ const GenZir = struct {...@@ -12572,6 +12579,10 @@ const GenZir = struct {
12572 return new_index;12579 return new_index;
12573 }12580 }
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
12575 fn addExtendedPayload(gz: *GenZir, opcode: Zir.Inst.Extended, extra: anytype) !Zir.Inst.Ref {12586 fn addExtendedPayload(gz: *GenZir, opcode: Zir.Inst.Extended, extra: anytype) !Zir.Inst.Ref {
12576 return addExtendedPayloadSmall(gz, opcode, undefined, extra);12587 return addExtendedPayloadSmall(gz, opcode, undefined, extra);
12577 }12588 }
lib/std/zig/Zir.zig+24-14
...@@ -2055,6 +2055,10 @@ pub const Inst = struct {...@@ -2055,6 +2055,10 @@ pub const Inst = struct {
2055 /// Guaranteed to not have the `ptr_cast` flag.2055 /// Guaranteed to not have the `ptr_cast` flag.
2056 /// Uses the `pl_node` union field with payload `FieldParentPtr`.2056 /// Uses the `pl_node` union field with payload `FieldParentPtr`.
2057 field_parent_ptr,2057 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
2059 pub const InstData = struct {2063 pub const InstData = struct {
2060 opcode: Extended,2064 opcode: Extended,
...@@ -2071,7 +2075,7 @@ pub const Inst = struct {...@@ -2071,7 +2075,7 @@ pub const Inst = struct {
2071 ref_start_index = static_len,2075 ref_start_index = static_len,
2072 _,2076 _,
20732077
2074 pub const static_len = 84;2078 pub const static_len = 71;
20752079
2076 pub fn toRef(i: Index) Inst.Ref {2080 pub fn toRef(i: Index) Inst.Ref {
2077 return @enumFromInt(@intFromEnum(Index.ref_start_index) + @intFromEnum(i));2081 return @enumFromInt(@intFromEnum(Index.ref_start_index) + @intFromEnum(i));
...@@ -2148,17 +2152,6 @@ pub const Inst = struct {...@@ -2148,17 +2152,6 @@ pub const Inst = struct {
2148 null_type,2152 null_type,
2149 undefined_type,2153 undefined_type,
2150 enum_literal_type,2154 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,
2162 manyptr_u8_type,2155 manyptr_u8_type,
2163 manyptr_const_u8_type,2156 manyptr_const_u8_type,
2164 manyptr_const_u8_sentinel_0_type,2157 manyptr_const_u8_sentinel_0_type,
...@@ -2179,8 +2172,6 @@ pub const Inst = struct {...@@ -2179,8 +2172,6 @@ pub const Inst = struct {
2179 one_u8,2172 one_u8,
2180 four_u8,2173 four_u8,
2181 negative_one,2174 negative_one,
2182 calling_convention_c,
2183 calling_convention_inline,
2184 void_value,2175 void_value,
2185 unreachable_value,2176 unreachable_value,
2186 null_value,2177 null_value,
...@@ -3146,6 +3137,24 @@ pub const Inst = struct {...@@ -3146,6 +3137,24 @@ pub const Inst = struct {
3146 }3137 }
3147 };3138 };
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
3149 /// Trailing:3158 /// Trailing:
3150 /// 0. tag_type: Ref, // if has_tag_type3159 /// 0. tag_type: Ref, // if has_tag_type
3151 /// 1. captures_len: u32, // if has_captures_len3160 /// 1. captures_len: u32, // if has_captures_len
...@@ -3977,6 +3986,7 @@ fn findDeclsInner(...@@ -3977,6 +3986,7 @@ fn findDeclsInner(
3977 .restore_err_ret_index,3986 .restore_err_ret_index,
3978 .closure_get,3987 .closure_get,
3979 .field_parent_ptr,3988 .field_parent_ptr,
3989 .builtin_value,
3980 => return,3990 => return,
39813991
3982 // `@TypeOf` has a body.3992 // `@TypeOf` has a body.
src/Air.zig-13
...@@ -938,17 +938,6 @@ pub const Inst = struct {...@@ -938,17 +938,6 @@ pub const Inst = struct {
938 null_type = @intFromEnum(InternPool.Index.null_type),938 null_type = @intFromEnum(InternPool.Index.null_type),
939 undefined_type = @intFromEnum(InternPool.Index.undefined_type),939 undefined_type = @intFromEnum(InternPool.Index.undefined_type),
940 enum_literal_type = @intFromEnum(InternPool.Index.enum_literal_type),940 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),
952 manyptr_u8_type = @intFromEnum(InternPool.Index.manyptr_u8_type),941 manyptr_u8_type = @intFromEnum(InternPool.Index.manyptr_u8_type),
953 manyptr_const_u8_type = @intFromEnum(InternPool.Index.manyptr_const_u8_type),942 manyptr_const_u8_type = @intFromEnum(InternPool.Index.manyptr_const_u8_type),
954 manyptr_const_u8_sentinel_0_type = @intFromEnum(InternPool.Index.manyptr_const_u8_sentinel_0_type),943 manyptr_const_u8_sentinel_0_type = @intFromEnum(InternPool.Index.manyptr_const_u8_sentinel_0_type),
...@@ -969,8 +958,6 @@ pub const Inst = struct {...@@ -969,8 +958,6 @@ pub const Inst = struct {
969 one_u8 = @intFromEnum(InternPool.Index.one_u8),958 one_u8 = @intFromEnum(InternPool.Index.one_u8),
970 four_u8 = @intFromEnum(InternPool.Index.four_u8),959 four_u8 = @intFromEnum(InternPool.Index.four_u8),
971 negative_one = @intFromEnum(InternPool.Index.negative_one),960 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),
974 void_value = @intFromEnum(InternPool.Index.void_value),961 void_value = @intFromEnum(InternPool.Index.void_value),
975 unreachable_value = @intFromEnum(InternPool.Index.unreachable_value),962 unreachable_value = @intFromEnum(InternPool.Index.unreachable_value),
976 null_value = @intFromEnum(InternPool.Index.null_value),963 null_value = @intFromEnum(InternPool.Index.null_value),
src/InternPool.zig+11-143
...@@ -2160,6 +2160,14 @@ pub const Key = union(enum) {...@@ -2160,6 +2160,14 @@ pub const Key = union(enum) {
2160 pub fn resolvedErrorSetUnordered(func: Func, ip: *const InternPool) Index {2160 pub fn resolvedErrorSetUnordered(func: Func, ip: *const InternPool) Index {
2161 return @atomicLoad(Index, func.resolvedErrorSetPtr(@constCast(ip)), .unordered);2161 return @atomicLoad(Index, func.resolvedErrorSetPtr(@constCast(ip)), .unordered);
2162 }2162 }
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 }
2163 };2171 };
21642172
2165 pub const Int = struct {2173 pub const Int = struct {
...@@ -4403,17 +4411,6 @@ pub const Index = enum(u32) {...@@ -4403,17 +4411,6 @@ pub const Index = enum(u32) {
4403 null_type,4411 null_type,
4404 undefined_type,4412 undefined_type,
4405 enum_literal_type,4413 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,
4417 manyptr_u8_type,4414 manyptr_u8_type,
4418 manyptr_const_u8_type,4415 manyptr_const_u8_type,
4419 manyptr_const_u8_sentinel_0_type,4416 manyptr_const_u8_sentinel_0_type,
...@@ -4446,10 +4443,6 @@ pub const Index = enum(u32) {...@@ -4446,10 +4443,6 @@ pub const Index = enum(u32) {
4446 four_u8,4443 four_u8,
4447 /// `-1` (comptime_int)4444 /// `-1` (comptime_int)
4448 negative_one,4445 negative_one,
4449 /// `std.builtin.CallingConvention.C`
4450 calling_convention_c,
4451 /// `std.builtin.CallingConvention.Inline`
4452 calling_convention_inline,
4453 /// `{}`4446 /// `{}`
4454 void_value,4447 void_value,
4455 /// `unreachable` (noreturn type)4448 /// `unreachable` (noreturn type)
...@@ -4829,17 +4822,6 @@ pub const static_keys = [_]Key{...@@ -4829,17 +4822,6 @@ pub const static_keys = [_]Key{
4829 .{ .simple_type = .null },4822 .{ .simple_type = .null },
4830 .{ .simple_type = .undefined },4823 .{ .simple_type = .undefined },
4831 .{ .simple_type = .enum_literal },4824 .{ .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
4844 // [*]u84826 // [*]u8
4845 .{ .ptr_type = .{4827 .{ .ptr_type = .{
...@@ -4868,7 +4850,7 @@ pub const static_keys = [_]Key{...@@ -4868,7 +4850,7 @@ pub const static_keys = [_]Key{
4868 },4850 },
4869 } },4851 } },
48704852
4871 // comptime_int4853 // *const comptime_int
4872 .{ .ptr_type = .{4854 .{ .ptr_type = .{
4873 .child = .comptime_int_type,4855 .child = .comptime_int_type,
4874 .flags = .{4856 .flags = .{
...@@ -4959,16 +4941,6 @@ pub const static_keys = [_]Key{...@@ -4959,16 +4941,6 @@ pub const static_keys = [_]Key{
4959 .ty = .comptime_int_type,4941 .ty = .comptime_int_type,
4960 .storage = .{ .i64 = -1 },4942 .storage = .{ .i64 = -1 },
4961 } },4943 } },
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
4973 .{ .simple_value = .void },4945 .{ .simple_value = .void },
4974 .{ .simple_value = .@"unreachable" },4946 .{ .simple_value = .@"unreachable" },
...@@ -5682,18 +5654,6 @@ pub const SimpleType = enum(u32) {...@@ -5682,18 +5654,6 @@ pub const SimpleType = enum(u32) {
5682 undefined = @intFromEnum(Index.undefined_type),5654 undefined = @intFromEnum(Index.undefined_type),
5683 enum_literal = @intFromEnum(Index.enum_literal_type),5655 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
5697 adhoc_inferred_error_set = @intFromEnum(Index.adhoc_inferred_error_set_type),5657 adhoc_inferred_error_set = @intFromEnum(Index.adhoc_inferred_error_set_type),
5698 generic_poison = @intFromEnum(Index.generic_poison_type),5658 generic_poison = @intFromEnum(Index.generic_poison_type),
5699};5659};
...@@ -6273,18 +6233,6 @@ pub fn init(ip: *InternPool, gpa: Allocator, available_threads: usize) !void {...@@ -6273,18 +6233,6 @@ pub fn init(ip: *InternPool, gpa: Allocator, available_threads: usize) !void {
6273 // Sanity check.6233 // Sanity check.
6274 assert(ip.indexToKey(.bool_true).simple_value == .true);6234 assert(ip.indexToKey(.bool_true).simple_value == .true);
6275 assert(ip.indexToKey(.bool_false).simple_value == .false);6235 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);
6288 }6236 }
6289}6237}
62906238
...@@ -7100,7 +7048,7 @@ fn getOrPutKeyEnsuringAdditionalCapacity(...@@ -7100,7 +7048,7 @@ fn getOrPutKeyEnsuringAdditionalCapacity(
7100 const index = entry.acquire();7048 const index = entry.acquire();
7101 if (index == .none) break;7049 if (index == .none) break;
7102 if (entry.hash != hash) continue;7050 if (entry.hash != hash) continue;
7103 if (ip.isRemoved(index)) continue;7051 if (index.unwrap(ip).getTag(ip) == .removed) continue;
7104 if (ip.indexToKey(index).eql(key, ip)) return .{ .existing = index };7052 if (ip.indexToKey(index).eql(key, ip)) return .{ .existing = index };
7105 }7053 }
7106 shard.mutate.map.mutex.lock();7054 shard.mutate.map.mutex.lock();
...@@ -9735,14 +9683,6 @@ fn addMap(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, cap: usize) Al...@@ -9735,14 +9683,6 @@ fn addMap(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, cap: usize) Al
9735/// Invalidates all references to this index.9683/// Invalidates all references to this index.
9736pub fn remove(ip: *InternPool, tid: Zcu.PerThread.Id, index: Index) void {9684pub fn remove(ip: *InternPool, tid: Zcu.PerThread.Id, index: Index) void {
9737 const unwrapped_index = index.unwrap(ip);9685 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
9747 if (unwrapped_index.tid == tid) {9687 if (unwrapped_index.tid == tid) {
9748 const items_len = &ip.getLocal(unwrapped_index.tid).mutate.items.len;9688 const items_len = &ip.getLocal(unwrapped_index.tid).mutate.items.len;
...@@ -10382,17 +10322,7 @@ pub fn isIntegerType(ip: *const InternPool, ty: Index) bool {...@@ -10382,17 +10322,7 @@ pub fn isIntegerType(ip: *const InternPool, ty: Index) bool {
1038210322
10383/// does not include .enum_literal_type10323/// does not include .enum_literal_type
10384pub fn isEnumType(ip: *const InternPool, ty: Index) bool {10324pub fn isEnumType(ip: *const InternPool, ty: Index) bool {
10385 return switch (ty) {10325 return ip.indexToKey(ty) == .enum_type;
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 };
10396}10326}
1039710327
10398pub fn isUnion(ip: *const InternPool, ty: Index) bool {10328pub fn isUnion(ip: *const InternPool, ty: Index) bool {
...@@ -11393,17 +11323,6 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {...@@ -11393,17 +11323,6 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {
11393 .null_type,11323 .null_type,
11394 .undefined_type,11324 .undefined_type,
11395 .enum_literal_type,11325 .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,
11407 .manyptr_u8_type,11326 .manyptr_u8_type,
11408 .manyptr_const_u8_type,11327 .manyptr_const_u8_type,
11409 .manyptr_const_u8_sentinel_0_type,11328 .manyptr_const_u8_sentinel_0_type,
...@@ -11421,7 +11340,6 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {...@@ -11421,7 +11340,6 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {
11421 .zero, .one, .negative_one => .comptime_int_type,11340 .zero, .one, .negative_one => .comptime_int_type,
11422 .zero_usize, .one_usize => .usize_type,11341 .zero_usize, .one_usize => .usize_type,
11423 .zero_u8, .one_u8, .four_u8 => .u8_type,11342 .zero_u8, .one_u8, .four_u8 => .u8_type,
11424 .calling_convention_c, .calling_convention_inline => .calling_convention_type,
11425 .void_value => .void_type,11343 .void_value => .void_type,
11426 .unreachable_value => .noreturn_type,11344 .unreachable_value => .noreturn_type,
11427 .null_value => .null_type,11345 .null_value => .null_type,
...@@ -11717,22 +11635,6 @@ pub fn zigTypeTagOrPoison(ip: *const InternPool, index: Index) error{GenericPois...@@ -11717,22 +11635,6 @@ pub fn zigTypeTagOrPoison(ip: *const InternPool, index: Index) error{GenericPois
11717 .undefined_type => .Undefined,11635 .undefined_type => .Undefined,
11718 .enum_literal_type => .EnumLiteral,11636 .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
11736 .manyptr_u8_type,11638 .manyptr_u8_type,
11737 .manyptr_const_u8_type,11639 .manyptr_const_u8_type,
11738 .manyptr_const_u8_sentinel_0_type,11640 .manyptr_const_u8_sentinel_0_type,
...@@ -11757,8 +11659,6 @@ pub fn zigTypeTagOrPoison(ip: *const InternPool, index: Index) error{GenericPois...@@ -11757,8 +11659,6 @@ pub fn zigTypeTagOrPoison(ip: *const InternPool, index: Index) error{GenericPois
11757 .one_u8 => unreachable,11659 .one_u8 => unreachable,
11758 .four_u8 => unreachable,11660 .four_u8 => unreachable,
11759 .negative_one => unreachable,11661 .negative_one => unreachable,
11760 .calling_convention_c => unreachable,
11761 .calling_convention_inline => unreachable,
11762 .void_value => unreachable,11662 .void_value => unreachable,
11763 .unreachable_value => unreachable,11663 .unreachable_value => unreachable,
11764 .null_value => unreachable,11664 .null_value => unreachable,
...@@ -12077,34 +11977,6 @@ pub fn unwrapCoercedFunc(ip: *const InternPool, index: Index) Index {...@@ -12077,34 +11977,6 @@ pub fn unwrapCoercedFunc(ip: *const InternPool, index: Index) Index {
12077 };11977 };
12078}11978}
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
12108pub fn anonStructFieldTypes(ip: *const InternPool, i: Index) []const Index {11980pub fn anonStructFieldTypes(ip: *const InternPool, i: Index) []const Index {
12109 return ip.indexToKey(i).anon_struct_type.types;11981 return ip.indexToKey(i).anon_struct_type.types;
12110}11982}
...@@ -12303,7 +12175,3 @@ pub fn getErrorValue(...@@ -12303,7 +12175,3 @@ pub fn getErrorValue(
12303pub fn getErrorValueIfExists(ip: *const InternPool, name: NullTerminatedString) ?Zcu.ErrorInt {12175pub fn getErrorValueIfExists(ip: *const InternPool, name: NullTerminatedString) ?Zcu.ErrorInt {
12304 return @intFromEnum(ip.global_error_set.getErrorValueIfExists(name) orelse return null);12176 return @intFromEnum(ip.global_error_set.getErrorValueIfExists(name) orelse return null);
12305}12177}
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,...@@ -76,10 +76,6 @@ no_partial_func_ty: bool = false,
76/// here so the values can be dropped without any cleanup.76/// here so the values can be dropped without any cleanup.
77unresolved_inferred_allocs: std.AutoArrayHashMapUnmanaged(Air.Inst.Index, InferredAlloc) = .{},77unresolved_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
83/// Links every pointer derived from a base `alloc` back to that `alloc`. Used79/// Links every pointer derived from a base `alloc` back to that `alloc`. Used
84/// to detect comptime-known `const`s.80/// to detect comptime-known `const`s.
85/// TODO: ZIR liveness analysis would allow us to remove elements from this map.81/// TODO: ZIR liveness analysis would allow us to remove elements from this map.
...@@ -1327,6 +1323,7 @@ fn analyzeBodyInner(...@@ -1327,6 +1323,7 @@ fn analyzeBodyInner(
1327 },1323 },
1328 .value_placeholder => unreachable, // never appears in a body1324 .value_placeholder => unreachable, // never appears in a body
1329 .field_parent_ptr => try sema.zirFieldParentPtr(block, extended),1325 .field_parent_ptr => try sema.zirFieldParentPtr(block, extended),
1326 .builtin_value => try sema.zirBuiltinValue(extended),
1330 };1327 };
1331 },1328 },
13321329
...@@ -2712,17 +2709,6 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us...@@ -2712,17 +2709,6 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us
2712 return captures;2709 return captures;
2713}2710}
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
2726fn zirStructDecl(2712fn zirStructDecl(
2727 sema: *Sema,2713 sema: *Sema,
2728 block: *Block,2714 block: *Block,
...@@ -2788,7 +2774,7 @@ fn zirStructDecl(...@@ -2788,7 +2774,7 @@ fn zirStructDecl(
2788 .captures = captures,2774 .captures = captures,
2789 } },2775 } },
2790 };2776 };
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)) {
2792 .existing => |ty| {2778 .existing => |ty| {
2793 const new_ty = try pt.ensureTypeUpToDate(ty, false);2779 const new_ty = try pt.ensureTypeUpToDate(ty, false);
27942780
...@@ -2801,7 +2787,7 @@ fn zirStructDecl(...@@ -2801,7 +2787,7 @@ fn zirStructDecl(
2801 return Air.internedToRef(new_ty);2787 return Air.internedToRef(new_ty);
2802 },2788 },
2803 .wip => |wip| wip,2789 .wip => |wip| wip,
2804 });2790 };
2805 errdefer wip_ty.cancel(ip, pt.tid);2791 errdefer wip_ty.cancel(ip, pt.tid);
28062792
2807 wip_ty.setName(ip, try sema.createTypeName(2793 wip_ty.setName(ip, try sema.createTypeName(
...@@ -3017,7 +3003,7 @@ fn zirEnumDecl(...@@ -3017,7 +3003,7 @@ fn zirEnumDecl(
3017 .captures = captures,3003 .captures = captures,
3018 } },3004 } },
3019 };3005 };
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)) {
3021 .existing => |ty| {3007 .existing => |ty| {
3022 const new_ty = try pt.ensureTypeUpToDate(ty, false);3008 const new_ty = try pt.ensureTypeUpToDate(ty, false);
30233009
...@@ -3030,7 +3016,7 @@ fn zirEnumDecl(...@@ -3030,7 +3016,7 @@ fn zirEnumDecl(
3030 return Air.internedToRef(new_ty);3016 return Air.internedToRef(new_ty);
3031 },3017 },
3032 .wip => |wip| wip,3018 .wip => |wip| wip,
3033 });3019 };
30343020
3035 // Once this is `true`, we will not delete the decl or type even upon failure, since we3021 // Once this is `true`, we will not delete the decl or type even upon failure, since we
3036 // have finished constructing the type and are in the process of analyzing it.3022 // have finished constructing the type and are in the process of analyzing it.
...@@ -3161,7 +3147,7 @@ fn zirUnionDecl(...@@ -3161,7 +3147,7 @@ fn zirUnionDecl(
3161 .captures = captures,3147 .captures = captures,
3162 } },3148 } },
3163 };3149 };
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)) {
3165 .existing => |ty| {3151 .existing => |ty| {
3166 const new_ty = try pt.ensureTypeUpToDate(ty, false);3152 const new_ty = try pt.ensureTypeUpToDate(ty, false);
31673153
...@@ -3174,7 +3160,7 @@ fn zirUnionDecl(...@@ -3174,7 +3160,7 @@ fn zirUnionDecl(
3174 return Air.internedToRef(new_ty);3160 return Air.internedToRef(new_ty);
3175 },3161 },
3176 .wip => |wip| wip,3162 .wip => |wip| wip,
3177 });3163 };
3178 errdefer wip_ty.cancel(ip, pt.tid);3164 errdefer wip_ty.cancel(ip, pt.tid);
31793165
3180 wip_ty.setName(ip, try sema.createTypeName(3166 wip_ty.setName(ip, try sema.createTypeName(
...@@ -3259,7 +3245,6 @@ fn zirOpaqueDecl(...@@ -3259,7 +3245,6 @@ fn zirOpaqueDecl(
3259 .captures = captures,3245 .captures = captures,
3260 } },3246 } },
3261 };3247 };
3262 // No `wrapWipTy` needed as no std.builtin types are opaque.
3263 const wip_ty = switch (try ip.getOpaqueType(gpa, pt.tid, opaque_init)) {3248 const wip_ty = switch (try ip.getOpaqueType(gpa, pt.tid, opaque_init)) {
3264 .existing => |ty| {3249 .existing => |ty| {
3265 // Make sure we update the namespace if the declaration is re-analyzed, to pick3250 // 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...@@ -26179,7 +26164,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
26179 const body = sema.code.bodySlice(extra_index, body_len);26164 const body = sema.code.bodySlice(extra_index, body_len);
26180 extra_index += body.len;26165 extra_index += body.len;
2618126166
26182 const addrspace_ty = Type.fromInterned(.address_space_type);26167 const addrspace_ty = try pt.getBuiltinType("AddressSpace");
26183 const val = try sema.resolveGenericBody(block, addrspace_src, body, inst, addrspace_ty, .{26168 const val = try sema.resolveGenericBody(block, addrspace_src, body, inst, addrspace_ty, .{
26184 .needed_comptime_reason = "addrspace must be comptime-known",26169 .needed_comptime_reason = "addrspace must be comptime-known",
26185 });26170 });
...@@ -26190,7 +26175,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -26190,7 +26175,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
26190 } else if (extra.data.bits.has_addrspace_ref) blk: {26175 } else if (extra.data.bits.has_addrspace_ref) blk: {
26191 const addrspace_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);26176 const addrspace_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
26192 extra_index += 1;26177 extra_index += 1;
26193 const addrspace_ty = Type.fromInterned(.address_space_type);26178 const addrspace_ty = try pt.getBuiltinType("AddressSpace");
26194 const uncoerced_addrspace = sema.resolveInst(addrspace_ref) catch |err| switch (err) {26179 const uncoerced_addrspace = sema.resolveInst(addrspace_ref) catch |err| switch (err) {
26195 error.GenericPoison => break :blk null,26180 error.GenericPoison => break :blk null,
26196 else => |e| return e,26181 else => |e| return e,
...@@ -26255,7 +26240,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -26255,7 +26240,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
26255 } else if (extra.data.bits.has_cc_ref) blk: {26240 } else if (extra.data.bits.has_cc_ref) blk: {
26256 const cc_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);26241 const cc_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
26257 extra_index += 1;26242 extra_index += 1;
26258 const cc_ty = Type.fromInterned(.calling_convention_type);26243 const cc_ty = try pt.getBuiltinType("CallingConvention");
26259 const uncoerced_cc = sema.resolveInst(cc_ref) catch |err| switch (err) {26244 const uncoerced_cc = sema.resolveInst(cc_ref) catch |err| switch (err) {
26260 error.GenericPoison => break :blk null,26245 error.GenericPoison => break :blk null,
26261 else => |e| return e,26246 else => |e| return e,
...@@ -26713,6 +26698,46 @@ fn zirInComptime(...@@ -26713,6 +26698,46 @@ fn zirInComptime(
26713 return if (block.is_comptime) .bool_true else .bool_false;26698 return if (block.is_comptime) .bool_true else .bool_false;
26714}26699}
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
26716fn requireRuntimeBlock(sema: *Sema, block: *Block, src: LazySrcLoc, runtime_src: ?LazySrcLoc) !void {26741fn requireRuntimeBlock(sema: *Sema, block: *Block, src: LazySrcLoc, runtime_src: ?LazySrcLoc) !void {
26717 if (block.is_comptime) {26742 if (block.is_comptime) {
26718 const msg = msg: {26743 const msg = msg: {
...@@ -32527,6 +32552,7 @@ fn analyzeIsNonErrComptimeOnly(...@@ -32527,6 +32552,7 @@ fn analyzeIsNonErrComptimeOnly(
32527 // If the error set is empty, we must return a comptime true or false.32552 // If the error set is empty, we must return a comptime true or false.
32528 // However we want to avoid unnecessarily resolving an inferred error set32553 // However we want to avoid unnecessarily resolving an inferred error set
32529 // in case it is already non-empty.32554 // in case it is already non-empty.
32555 try mod.maybeUnresolveIes(func_index);
32530 switch (ip.funcIesResolvedUnordered(func_index)) {32556 switch (ip.funcIesResolvedUnordered(func_index)) {
32531 .anyerror_type => break :blk,32557 .anyerror_type => break :blk,
32532 .none => {},32558 .none => {},
...@@ -33596,6 +33622,7 @@ fn wrapErrorUnionSet(...@@ -33596,6 +33622,7 @@ fn wrapErrorUnionSet(
33596 .inferred_error_set_type => |func_index| ok: {33622 .inferred_error_set_type => |func_index| ok: {
33597 // We carefully do this in an order that avoids unnecessarily33623 // We carefully do this in an order that avoids unnecessarily
33598 // resolving the destination error set type.33624 // resolving the destination error set type.
33625 try mod.maybeUnresolveIes(func_index);
33599 switch (ip.funcIesResolvedUnordered(func_index)) {33626 switch (ip.funcIesResolvedUnordered(func_index)) {
33600 .anyerror_type => break :ok,33627 .anyerror_type => break :ok,
33601 .none => if (.ok == try sema.coerceInMemoryAllowedErrorSets(block, dest_err_set_ty, inst_ty, inst_src, inst_src)) {33628 .none => if (.ok == try sema.coerceInMemoryAllowedErrorSets(block, dest_err_set_ty, inst_ty, inst_src, inst_src)) {
...@@ -35853,8 +35880,7 @@ fn resolveInferredErrorSet(...@@ -35853,8 +35880,7 @@ fn resolveInferredErrorSet(
3585335880
35854 try sema.declareDependency(.{ .interned = func_index }); // resolved IES35881 try sema.declareDependency(.{ .interned = func_index }); // resolved IES
3585535882
35856 // TODO: during an incremental update this might not be `.none`, but the35883 try zcu.maybeUnresolveIes(func_index);
35857 // function might be out-of-date!
35858 const resolved_ty = func.resolvedErrorSetUnordered(ip);35884 const resolved_ty = func.resolvedErrorSetUnordered(ip);
35859 if (resolved_ty != .none) return resolved_ty;35885 if (resolved_ty != .none) return resolved_ty;
3586035886
...@@ -36898,17 +36924,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -36898,17 +36924,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
36898 .comptime_int_type,36924 .comptime_int_type,
36899 .comptime_float_type,36925 .comptime_float_type,
36900 .enum_literal_type,36926 .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,
36912 .manyptr_u8_type,36927 .manyptr_u8_type,
36913 .manyptr_const_u8_type,36928 .manyptr_const_u8_type,
36914 .manyptr_const_u8_sentinel_0_type,36929 .manyptr_const_u8_sentinel_0_type,
...@@ -36935,8 +36950,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -36935,8 +36950,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
36935 .one_u8,36950 .one_u8,
36936 .four_u8,36951 .four_u8,
36937 .negative_one,36952 .negative_one,
36938 .calling_convention_c,
36939 .calling_convention_inline,
36940 .void_value,36953 .void_value,
36941 .unreachable_value,36954 .unreachable_value,
36942 .null_value,36955 .null_value,
...@@ -37290,7 +37303,8 @@ pub fn analyzeAsAddressSpace(...@@ -37290,7 +37303,8 @@ pub fn analyzeAsAddressSpace(
37290) !std.builtin.AddressSpace {37303) !std.builtin.AddressSpace {
37291 const pt = sema.pt;37304 const pt = sema.pt;
37292 const mod = pt.zcu;37305 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);
37294 const addrspace_val = try sema.resolveConstDefinedValue(block, src, coerced, .{37308 const addrspace_val = try sema.resolveConstDefinedValue(block, src, coerced, .{
37295 .needed_comptime_reason = "address space must be comptime-known",37309 .needed_comptime_reason = "address space must be comptime-known",
37296 });37310 });
src/Type.zig+1-129
...@@ -316,17 +316,6 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error...@@ -316,17 +316,6 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error
316 => try writer.print("@TypeOf({s})", .{@tagName(s)}),316 => try writer.print("@TypeOf({s})", .{@tagName(s)}),
317317
318 .enum_literal => try writer.print("@TypeOf(.{s})", .{@tagName(s)}),318 .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
331 .generic_poison => unreachable,320 .generic_poison => unreachable,
332 },321 },
...@@ -544,16 +533,6 @@ pub fn hasRuntimeBitsAdvanced(...@@ -544,16 +533,6 @@ pub fn hasRuntimeBitsAdvanced(
544 .anyerror,533 .anyerror,
545 .adhoc_inferred_error_set,534 .adhoc_inferred_error_set,
546 .anyopaque,535 .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,
557 => true,536 => true,
558537
559 // These are false because they are comptime-only types.538 // These are false because they are comptime-only types.
...@@ -565,7 +544,6 @@ pub fn hasRuntimeBitsAdvanced(...@@ -565,7 +544,6 @@ pub fn hasRuntimeBitsAdvanced(
565 .null,544 .null,
566 .undefined,545 .undefined,
567 .enum_literal,546 .enum_literal,
568 .type_info,
569 => false,547 => false,
570548
571 .generic_poison => unreachable,549 .generic_poison => unreachable,
...@@ -711,16 +689,6 @@ pub fn hasWellDefinedLayout(ty: Type, mod: *Module) bool {...@@ -711,16 +689,6 @@ pub fn hasWellDefinedLayout(ty: Type, mod: *Module) bool {
711 .anyerror,689 .anyerror,
712 .adhoc_inferred_error_set,690 .adhoc_inferred_error_set,
713 .anyopaque,691 .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,
724 .type,692 .type,
725 .comptime_int,693 .comptime_int,
726 .comptime_float,694 .comptime_float,
...@@ -728,7 +696,6 @@ pub fn hasWellDefinedLayout(ty: Type, mod: *Module) bool {...@@ -728,7 +696,6 @@ pub fn hasWellDefinedLayout(ty: Type, mod: *Module) bool {
728 .null,696 .null,
729 .undefined,697 .undefined,
730 .enum_literal,698 .enum_literal,
731 .type_info,
732 .generic_poison,699 .generic_poison,
733 => false,700 => false,
734 },701 },
...@@ -972,14 +939,6 @@ pub fn abiAlignmentAdvanced(...@@ -972,14 +939,6 @@ pub fn abiAlignmentAdvanced(
972939
973 .simple_type => |t| switch (t) {940 .simple_type => |t| switch (t) {
974 .bool,941 .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,
983 .anyopaque,942 .anyopaque,
984 => return .{ .scalar = .@"1" },943 => return .{ .scalar = .@"1" },
985944
...@@ -987,11 +946,6 @@ pub fn abiAlignmentAdvanced(...@@ -987,11 +946,6 @@ pub fn abiAlignmentAdvanced(
987 .isize,946 .isize,
988 => return .{ .scalar = intAbiAlignment(target.ptrBitWidth(), target, use_llvm) },947 => return .{ .scalar = intAbiAlignment(target.ptrBitWidth(), target, use_llvm) },
989948
990 .export_options,
991 .extern_options,
992 .type_info,
993 => return .{ .scalar = ptrAbiAlignment(target) },
994
995 .c_char => return .{ .scalar = cTypeAlign(target, .char) },949 .c_char => return .{ .scalar = cTypeAlign(target, .char) },
996 .c_short => return .{ .scalar = cTypeAlign(target, .short) },950 .c_short => return .{ .scalar = cTypeAlign(target, .short) },
997 .c_ushort => return .{ .scalar = cTypeAlign(target, .ushort) },951 .c_ushort => return .{ .scalar = cTypeAlign(target, .ushort) },
...@@ -1352,15 +1306,7 @@ pub fn abiSizeAdvanced(...@@ -1352,15 +1306,7 @@ pub fn abiSizeAdvanced(
1352 },1306 },
1353 .func_type => unreachable, // represents machine code; not a pointer1307 .func_type => unreachable, // represents machine code; not a pointer
1354 .simple_type => |t| switch (t) {1308 .simple_type => |t| switch (t) {
1355 .bool,1309 .bool => return .{ .scalar = 1 },
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 },
13641310
1365 .f16 => return .{ .scalar = 2 },1311 .f16 => return .{ .scalar = 2 },
1366 .f32 => return .{ .scalar = 4 },1312 .f32 => return .{ .scalar = 4 },
...@@ -1402,11 +1348,6 @@ pub fn abiSizeAdvanced(...@@ -1402,11 +1348,6 @@ pub fn abiSizeAdvanced(
1402 return .{ .scalar = intAbiSize(bits, target, use_llvm) };1348 return .{ .scalar = intAbiSize(bits, target, use_llvm) };
1403 },1349 },
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,
1410 .noreturn => unreachable,1351 .noreturn => unreachable,
1411 .generic_poison => unreachable,1352 .generic_poison => unreachable,
1412 },1353 },
...@@ -1751,18 +1692,6 @@ pub fn bitSizeAdvanced(...@@ -1751,18 +1692,6 @@ pub fn bitSizeAdvanced(
1751 .undefined => unreachable,1692 .undefined => unreachable,
1752 .enum_literal => unreachable,1693 .enum_literal => unreachable,
1753 .generic_poison => unreachable,1694 .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,
1766 },1695 },
1767 .struct_type => {1696 .struct_type => {
1768 const struct_type = ip.loadStructType(ty.toIntern());1697 const struct_type = ip.loadStructType(ty.toIntern());
...@@ -2565,17 +2494,6 @@ pub fn onePossibleValue(starting_type: Type, pt: Zcu.PerThread) !?Value {...@@ -2565,17 +2494,6 @@ pub fn onePossibleValue(starting_type: Type, pt: Zcu.PerThread) !?Value {
2565 .comptime_int,2494 .comptime_int,
2566 .comptime_float,2495 .comptime_float,
2567 .enum_literal,2496 .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,
2579 .adhoc_inferred_error_set,2497 .adhoc_inferred_error_set,
2580 => return null,2498 => return null,
25812499
...@@ -2782,16 +2700,6 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: Resolve...@@ -2782,16 +2700,6 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: Resolve
2782 .adhoc_inferred_error_set,2700 .adhoc_inferred_error_set,
2783 .noreturn,2701 .noreturn,
2784 .generic_poison,2702 .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,
2795 => false,2703 => false,
27962704
2797 .type,2705 .type,
...@@ -2800,7 +2708,6 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: Resolve...@@ -2800,7 +2708,6 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: Resolve
2800 .null,2708 .null,
2801 .undefined,2709 .undefined,
2802 .enum_literal,2710 .enum_literal,
2803 .type_info,
2804 => true,2711 => true,
2805 },2712 },
2806 .struct_type => {2713 .struct_type => {
...@@ -3534,10 +3441,6 @@ pub fn packedStructFieldPtrInfo(struct_ty: Type, parent_ptr_ty: Type, field_idx:...@@ -3534,10 +3441,6 @@ pub fn packedStructFieldPtrInfo(struct_ty: Type, parent_ptr_ty: Type, field_idx:
3534pub fn resolveLayout(ty: Type, pt: Zcu.PerThread) SemaError!void {3441pub fn resolveLayout(ty: Type, pt: Zcu.PerThread) SemaError!void {
3535 const zcu = pt.zcu;3442 const zcu = pt.zcu;
3536 const ip = &zcu.intern_pool;3443 const ip = &zcu.intern_pool;
3537 switch (ip.indexToKey(ty.toIntern())) {
3538 .simple_type => |simple_type| return resolveSimpleType(simple_type, pt),
3539 else => {},
3540 }
3541 switch (ty.zigTypeTag(zcu)) {3444 switch (ty.zigTypeTag(zcu)) {
3542 .Struct => switch (ip.indexToKey(ty.toIntern())) {3445 .Struct => switch (ip.indexToKey(ty.toIntern())) {
3543 .anon_struct_type => |anon_struct_type| for (0..anon_struct_type.types.len) |i| {3446 .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 {...@@ -3651,8 +3554,6 @@ pub fn resolveFields(ty: Type, pt: Zcu.PerThread) SemaError!void {
3651 .one_u8 => unreachable,3554 .one_u8 => unreachable,
3652 .four_u8 => unreachable,3555 .four_u8 => unreachable,
3653 .negative_one => unreachable,3556 .negative_one => unreachable,
3654 .calling_convention_c => unreachable,
3655 .calling_convention_inline => unreachable,
3656 .void_value => unreachable,3557 .void_value => unreachable,
3657 .unreachable_value => unreachable,3558 .unreachable_value => unreachable,
3658 .null_value => unreachable,3559 .null_value => unreachable,
...@@ -3669,8 +3570,6 @@ pub fn resolveFields(ty: Type, pt: Zcu.PerThread) SemaError!void {...@@ -3669,8 +3570,6 @@ pub fn resolveFields(ty: Type, pt: Zcu.PerThread) SemaError!void {
36693570
3670 .type_union => return ty.resolveUnionInner(pt, .fields),3571 .type_union => return ty.resolveUnionInner(pt, .fields),
36713572
3672 .simple_type => return resolveSimpleType(ip.indexToKey(ty_ip).simple_type, pt),
3673
3674 else => {},3573 else => {},
3675 },3574 },
3676 }3575 }
...@@ -3680,11 +3579,6 @@ pub fn resolveFully(ty: Type, pt: Zcu.PerThread) SemaError!void {...@@ -3680,11 +3579,6 @@ pub fn resolveFully(ty: Type, pt: Zcu.PerThread) SemaError!void {
3680 const zcu = pt.zcu;3579 const zcu = pt.zcu;
3681 const ip = &zcu.intern_pool;3580 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
3688 switch (ty.zigTypeTag(zcu)) {3582 switch (ty.zigTypeTag(zcu)) {
3689 .Type,3583 .Type,
3690 .Void,3584 .Void,
...@@ -3850,28 +3744,6 @@ fn resolveUnionInner(...@@ -3850,28 +3744,6 @@ fn resolveUnionInner(
3850 };3744 };
3851}3745}
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
3875/// Returns the type of a pointer to an element.3747/// Returns the type of a pointer to an element.
3876/// Asserts that the type is a pointer, and that the element type is indexable.3748/// Asserts that the type is a pointer, and that the element type is indexable.
3877/// If the element index is comptime-known, it must be passed in `offset`.3749/// 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...@@ -3468,3 +3468,29 @@ fn formatDependee(data: struct { dependee: InternPool.Dependee, zcu: *Zcu }, com
3468 },3468 },
3469 }3469 }
3470}3470}
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(...@@ -734,31 +734,25 @@ fn ensureFuncBodyAnalyzedInner(
734 const func = zcu.funcInfo(func_index);734 const func = zcu.funcInfo(func_index);
735 const anal_unit = AnalUnit.wrap(.{ .func = func_index });735 const anal_unit = AnalUnit.wrap(.{ .func = func_index });
736736
737 // Here's an interesting question: is this function actually valid?737 // Make sure that this function is still owned by the same `Nav`. Otherwise, analyzing
738 // Maybe the signature changed, so we'll end up creating a whole different `func`738 // it would be a waste of time in the best case, and could cause codegen to give bogus
739 // in the InternPool, and this one is a waste of time to analyze. Worse, we'd be739 // results in the worst case.
740 // analyzing new ZIR with old data, and get bogus errors. They would be unused,740
741 // but they would still hang around internally! So, let's detect this case.741 if (func.generic_owner == .none) {
742 // For function decls, we must ensure the declaration's `Cau` is up-to-date, and742 try pt.ensureCauAnalyzed(ip.getNav(func.owner_nav).analysis_owner.unwrap().?);
743 // check if `func_index` was removed by that update.743 if (ip.getNav(func.owner_nav).status.resolved.val != func_index) {
744 // For function instances, we do that process on the generic owner.744 // This function is no longer referenced! There's no point in re-analyzing it.
745745 // Just mark a transitive failure and move on.
746 try pt.ensureCauAnalyzed(cau: {746 return error.AnalysisFail;
747 const func_nav = if (func.generic_owner == .none)747 }
748 func.owner_nav748 } else {
749 else749 const go_nav = zcu.funcInfo(func.generic_owner).owner_nav;
750 zcu.funcInfo(func.generic_owner).owner_nav;750 try pt.ensureCauAnalyzed(ip.getNav(go_nav).analysis_owner.unwrap().?);
751751 if (ip.getNav(go_nav).status.resolved.val != func.generic_owner) {
752 break :cau ip.getNav(func_nav).analysis_owner.unwrap().?;752 // The generic owner is no longer referenced, so this function is also unreferenced.
753 });753 // There's no point in re-analyzing it. Just mark a transitive failure and move on.
754754 return error.AnalysisFail;
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
758 }755 }
759 ip.removeDependenciesForDepender(gpa, AnalUnit.wrap(.{ .func = func_index }));
760 ip.remove(pt.tid, func_index);
761 @panic("TODO: remove orphaned function from binary");
762 }756 }
763757
764 // We'll want to remember what the IES used to be before the update for758 // 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 {...@@ -1108,12 +1102,9 @@ fn semaCau(pt: Zcu.PerThread, cau_index: InternPool.Cau.Index) !SemaCauResult {
1108 // We are about to re-analyze this `Cau`; drop its depenndencies.1102 // We are about to re-analyze this `Cau`; drop its depenndencies.
1109 zcu.intern_pool.removeDependenciesForDepender(gpa, anal_unit);1103 zcu.intern_pool.removeDependenciesForDepender(gpa, anal_unit);
11101104
1111 const builtin_type_target_index: InternPool.Index = switch (cau.owner.unwrap()) {1105 switch (cau.owner.unwrap()) {
1112 .none => ip_index: {1106 .none => {}, // `comptime` decl -- we will re-analyze its body.
1113 // `comptime` decl -- we will re-analyze its body.1107 .nav => {}, // Other decl -- we will re-analyze its value.
1114 // This declaration has no value so is definitely not a std.builtin type.
1115 break :ip_index .none;
1116 },
1117 .type => |ty| {1108 .type => |ty| {
1118 // This is an incremental update, and this type is being re-analyzed because it is outdated.1109 // This is an incremental update, and this type is being re-analyzed because it is outdated.
1119 // Create a new type in its place, and mark the old one as outdated so that use sites will1110 // 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 {...@@ -1125,53 +1116,7 @@ fn semaCau(pt: Zcu.PerThread, cau_index: InternPool.Cau.Index) !SemaCauResult {
1125 .invalidate_decl_ref = true,1116 .invalidate_decl_ref = true,
1126 };1117 };
1127 },1118 },
1128 .nav => |nav| ip_index: {1119 }
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 };
11751120
1176 const is_usingnamespace = switch (cau.owner.unwrap()) {1121 const is_usingnamespace = switch (cau.owner.unwrap()) {
1177 .nav => |nav| ip.getNav(nav).is_usingnamespace,1122 .nav => |nav| ip.getNav(nav).is_usingnamespace,
...@@ -1200,7 +1145,6 @@ fn semaCau(pt: Zcu.PerThread, cau_index: InternPool.Cau.Index) !SemaCauResult {...@@ -1200,7 +1145,6 @@ fn semaCau(pt: Zcu.PerThread, cau_index: InternPool.Cau.Index) !SemaCauResult {
1200 .fn_ret_ty = Type.void,1145 .fn_ret_ty = Type.void,
1201 .fn_ret_ty_ies = null,1146 .fn_ret_ty_ies = null,
1202 .comptime_err_ret_trace = &comptime_err_ret_trace,1147 .comptime_err_ret_trace = &comptime_err_ret_trace,
1203 .builtin_type_target_index = builtin_type_target_index,
1204 };1148 };
1205 defer sema.deinit();1149 defer sema.deinit();
12061150
...@@ -1255,9 +1199,6 @@ fn semaCau(pt: Zcu.PerThread, cau_index: InternPool.Cau.Index) !SemaCauResult {...@@ -1255,9 +1199,6 @@ fn semaCau(pt: Zcu.PerThread, cau_index: InternPool.Cau.Index) !SemaCauResult {
1255 .type => unreachable, // Handled at top of function.1199 .type => unreachable, // Handled at top of function.
1256 };1200 };
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
1261 const align_src = block.src(.{ .node_offset_var_decl_align = 0 });1202 const align_src = block.src(.{ .node_offset_var_decl_align = 0 });
1262 const section_src = block.src(.{ .node_offset_var_decl_section = 0 });1203 const section_src = block.src(.{ .node_offset_var_decl_section = 0 });
1263 const addrspace_src = block.src(.{ .node_offset_var_decl_addrspace = 0 });1204 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!...@@ -2072,6 +2013,9 @@ fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index) Zcu.SemaError!
2072 errdefer _ = zcu.analysis_in_progress.swapRemove(anal_unit);2013 errdefer _ = zcu.analysis_in_progress.swapRemove(anal_unit);
20732014
2074 func.setAnalysisState(ip, .analyzed);2015 func.setAnalysisState(ip, .analyzed);
2016 if (func.analysisUnordered(ip).inferred_error_set) {
2017 func.setResolvedErrorSet(ip, .none);
2018 }
20752019
2076 // This is the `Cau` corresponding to the `declaration` instruction which the function or its generic owner originates from.2020 // This is the `Cau` corresponding to the `declaration` instruction which the function or its generic owner originates from.
2077 const decl_cau = ip.getCau(cau: {2021 const decl_cau = ip.getCau(cau: {
...@@ -2278,7 +2222,7 @@ fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index) Zcu.SemaError!...@@ -2278,7 +2222,7 @@ fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index) Zcu.SemaError!
2278 else => |e| return e,2222 else => |e| return e,
2279 };2223 };
2280 assert(ies.resolved != .none);2224 assert(ies.resolved != .none);
2281 ip.funcSetIesResolved(func_index, ies.resolved);2225 func.setResolvedErrorSet(ip, ies.resolved);
2282 }2226 }
22832227
2284 assert(zcu.analysis_in_progress.swapRemove(anal_unit));2228 assert(zcu.analysis_in_progress.swapRemove(anal_unit));
...@@ -3352,7 +3296,7 @@ pub fn ensureTypeUpToDate(pt: Zcu.PerThread, ty: InternPool.Index, already_updat...@@ -3352,7 +3296,7 @@ pub fn ensureTypeUpToDate(pt: Zcu.PerThread, ty: InternPool.Index, already_updat
3352 break :o o;3296 break :o o;
3353 };3297 };
3354 if (!outdated) return ty;3298 if (!outdated) return ty;
3355 return pt.recreateStructType(ty, key, struct_obj);3299 return pt.recreateStructType(key, struct_obj);
3356 },3300 },
3357 .union_type => |key| {3301 .union_type => |key| {
3358 const union_obj = ip.loadUnionType(ty);3302 const union_obj = ip.loadUnionType(ty);
...@@ -3367,7 +3311,7 @@ pub fn ensureTypeUpToDate(pt: Zcu.PerThread, ty: InternPool.Index, already_updat...@@ -3367,7 +3311,7 @@ pub fn ensureTypeUpToDate(pt: Zcu.PerThread, ty: InternPool.Index, already_updat
3367 break :o o;3311 break :o o;
3368 };3312 };
3369 if (!outdated) return ty;3313 if (!outdated) return ty;
3370 return pt.recreateUnionType(ty, key, union_obj);3314 return pt.recreateUnionType(key, union_obj);
3371 },3315 },
3372 .enum_type => |key| {3316 .enum_type => |key| {
3373 const enum_obj = ip.loadEnumType(ty);3317 const enum_obj = ip.loadEnumType(ty);
...@@ -3382,7 +3326,7 @@ pub fn ensureTypeUpToDate(pt: Zcu.PerThread, ty: InternPool.Index, already_updat...@@ -3382,7 +3326,7 @@ pub fn ensureTypeUpToDate(pt: Zcu.PerThread, ty: InternPool.Index, already_updat
3382 break :o o;3326 break :o o;
3383 };3327 };
3384 if (!outdated) return ty;3328 if (!outdated) return ty;
3385 return pt.recreateEnumType(ty, key, enum_obj);3329 return pt.recreateEnumType(key, enum_obj);
3386 },3330 },
3387 .opaque_type => {3331 .opaque_type => {
3388 assert(!already_updating);3332 assert(!already_updating);
...@@ -3394,7 +3338,6 @@ pub fn ensureTypeUpToDate(pt: Zcu.PerThread, ty: InternPool.Index, already_updat...@@ -3394,7 +3338,6 @@ pub fn ensureTypeUpToDate(pt: Zcu.PerThread, ty: InternPool.Index, already_updat
33943338
3395fn recreateStructType(3339fn recreateStructType(
3396 pt: Zcu.PerThread,3340 pt: Zcu.PerThread,
3397 ty: InternPool.Index,
3398 full_key: InternPool.Key.NamespaceType,3341 full_key: InternPool.Key.NamespaceType,
3399 struct_obj: InternPool.LoadedStructType,3342 struct_obj: InternPool.LoadedStructType,
3400) Zcu.SemaError!InternPool.Index {3343) Zcu.SemaError!InternPool.Index {
...@@ -3409,10 +3352,6 @@ fn recreateStructType(...@@ -3409,10 +3352,6 @@ fn recreateStructType(
3409 .declared => |d| d,3352 .declared => |d| d,
3410 };3353 };
34113354
3412 if (@intFromEnum(ty) <= InternPool.static_len) {
3413 @panic("TODO: recreate resolved builtin type");
3414 }
3415
3416 const inst_info = key.zir_index.resolveFull(ip) orelse return error.AnalysisFail;3355 const inst_info = key.zir_index.resolveFull(ip) orelse return error.AnalysisFail;
3417 const file = zcu.fileByIndex(inst_info.file);3356 const file = zcu.fileByIndex(inst_info.file);
3418 if (file.status != .success_zir) return error.AnalysisFail;3357 if (file.status != .success_zir) return error.AnalysisFail;
...@@ -3485,7 +3424,6 @@ fn recreateStructType(...@@ -3485,7 +3424,6 @@ fn recreateStructType(
34853424
3486fn recreateUnionType(3425fn recreateUnionType(
3487 pt: Zcu.PerThread,3426 pt: Zcu.PerThread,
3488 ty: InternPool.Index,
3489 full_key: InternPool.Key.NamespaceType,3427 full_key: InternPool.Key.NamespaceType,
3490 union_obj: InternPool.LoadedUnionType,3428 union_obj: InternPool.LoadedUnionType,
3491) Zcu.SemaError!InternPool.Index {3429) Zcu.SemaError!InternPool.Index {
...@@ -3500,10 +3438,6 @@ fn recreateUnionType(...@@ -3500,10 +3438,6 @@ fn recreateUnionType(
3500 .declared => |d| d,3438 .declared => |d| d,
3501 };3439 };
35023440
3503 if (@intFromEnum(ty) <= InternPool.static_len) {
3504 @panic("TODO: recreate resolved builtin type");
3505 }
3506
3507 const inst_info = key.zir_index.resolveFull(ip) orelse return error.AnalysisFail;3441 const inst_info = key.zir_index.resolveFull(ip) orelse return error.AnalysisFail;
3508 const file = zcu.fileByIndex(inst_info.file);3442 const file = zcu.fileByIndex(inst_info.file);
3509 if (file.status != .success_zir) return error.AnalysisFail;3443 if (file.status != .success_zir) return error.AnalysisFail;
...@@ -3584,7 +3518,6 @@ fn recreateUnionType(...@@ -3584,7 +3518,6 @@ fn recreateUnionType(
35843518
3585fn recreateEnumType(3519fn recreateEnumType(
3586 pt: Zcu.PerThread,3520 pt: Zcu.PerThread,
3587 ty: InternPool.Index,
3588 full_key: InternPool.Key.NamespaceType,3521 full_key: InternPool.Key.NamespaceType,
3589 enum_obj: InternPool.LoadedEnumType,3522 enum_obj: InternPool.LoadedEnumType,
3590) Zcu.SemaError!InternPool.Index {3523) Zcu.SemaError!InternPool.Index {
...@@ -3599,10 +3532,6 @@ fn recreateEnumType(...@@ -3599,10 +3532,6 @@ fn recreateEnumType(
3599 .declared => |d| d,3532 .declared => |d| d,
3600 };3533 };
36013534
3602 if (@intFromEnum(ty) <= InternPool.static_len) {
3603 @panic("TODO: recreate resolved builtin type");
3604 }
3605
3606 const inst_info = key.zir_index.resolveFull(ip) orelse return error.AnalysisFail;3535 const inst_info = key.zir_index.resolveFull(ip) orelse return error.AnalysisFail;
3607 const file = zcu.fileByIndex(inst_info.file);3536 const file = zcu.fileByIndex(inst_info.file);
3608 if (file.status != .success_zir) return error.AnalysisFail;3537 if (file.status != .success_zir) return error.AnalysisFail;
src/codegen/c/Type.zig+1-23
...@@ -1389,21 +1389,6 @@ pub const Pool = struct {...@@ -1389,21 +1389,6 @@ pub const Pool = struct {
1389 .anyframe_type,1389 .anyframe_type,
1390 .generic_poison_type,1390 .generic_poison_type,
1391 => unreachable,1391 => 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 ),
1407 .anyerror_type,1392 .anyerror_type,
1408 .anyerror_void_error_union_type,1393 .anyerror_void_error_union_type,
1409 .adhoc_inferred_error_set_type,1394 .adhoc_inferred_error_set_type,
...@@ -1459,8 +1444,6 @@ pub const Pool = struct {...@@ -1459,8 +1444,6 @@ pub const Pool = struct {
1459 .one_u8,1444 .one_u8,
1460 .four_u8,1445 .four_u8,
1461 .negative_one,1446 .negative_one,
1462 .calling_convention_c,
1463 .calling_convention_inline,
1464 .void_value,1447 .void_value,
1465 .unreachable_value,1448 .unreachable_value,
1466 .null_value,1449 .null_value,
...@@ -1471,12 +1454,7 @@ pub const Pool = struct {...@@ -1471,12 +1454,7 @@ pub const Pool = struct {
1471 .none,1454 .none,
1472 => unreachable,1455 => unreachable,
14731456
1474 //.prefetch_options_type,1457 _ => |ip_index| switch (ip.indexToKey(ip_index)) {
1475 //.export_options_type,
1476 //.extern_options_type,
1477 //.type_info_type,
1478 //_,
1479 else => |ip_index| switch (ip.indexToKey(ip_index)) {
1480 .int_type => |int_info| return pool.fromIntInfo(allocator, int_info, mod, kind),1458 .int_type => |int_info| return pool.fromIntInfo(allocator, int_info, mod, kind),
1481 .ptr_type => |ptr_info| switch (ptr_info.flags.size) {1459 .ptr_type => |ptr_info| switch (ptr_info.flags.size) {
1482 .One, .Many, .C => {1460 .One, .Many, .C => {
src/codegen/llvm.zig-2
...@@ -3195,8 +3195,6 @@ pub const Object = struct {...@@ -3195,8 +3195,6 @@ pub const Object = struct {
3195 .one_u8,3195 .one_u8,
3196 .four_u8,3196 .four_u8,
3197 .negative_one,3197 .negative_one,
3198 .calling_convention_c,
3199 .calling_convention_inline,
3200 .void_value,3198 .void_value,
3201 .unreachable_value,3199 .unreachable_value,
3202 .null_value,3200 .null_value,
src/link/Dwarf.zig+1-13
...@@ -2565,19 +2565,7 @@ fn updateType(...@@ -2565,19 +2565,7 @@ fn updateType(
2565 try wip_nav.strp(if (type_index == .generic_poison_type) "anytype" else name);2565 try wip_nav.strp(if (type_index == .generic_poison_type) "anytype" else name);
2566 },2566 },
2567 .anyerror => return, // delay until flush2567 .anyerror => return, // delay until flush
2568 .atomic_order,2568 .adhoc_inferred_error_set => unreachable,
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,
2581 },2569 },
2582 .struct_type,2570 .struct_type,
2583 .union_type,2571 .union_type,
src/print_zir.zig+7
...@@ -615,6 +615,7 @@ const Writer = struct {...@@ -615,6 +615,7 @@ const Writer = struct {
615 .restore_err_ret_index => try self.writeRestoreErrRetIndex(stream, extended),615 .restore_err_ret_index => try self.writeRestoreErrRetIndex(stream, extended),
616 .closure_get => try self.writeClosureGet(stream, extended),616 .closure_get => try self.writeClosureGet(stream, extended),
617 .field_parent_ptr => try self.writeFieldParentPtr(stream, extended),617 .field_parent_ptr => try self.writeFieldParentPtr(stream, extended),
618 .builtin_value => try self.writeBuiltinValue(stream, extended),
618 }619 }
619 }620 }
620621
...@@ -2782,6 +2783,12 @@ const Writer = struct {...@@ -2782,6 +2783,12 @@ const Writer = struct {
2782 try self.writeSrcNode(stream, @bitCast(extended.operand));2783 try self.writeSrcNode(stream, @bitCast(extended.operand));
2783 }2784 }
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
2785 fn writeInstRef(self: *Writer, stream: anytype, ref: Zir.Inst.Ref) !void {2792 fn writeInstRef(self: *Writer, stream: anytype, ref: Zir.Inst.Ref) !void {
2786 if (ref == .none) {2793 if (ref == .none) {
2787 return stream.writeAll(".none");2794 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=""