| ... | ... | @@ -428,7 +428,7 @@ pub const Block = struct { |
| 428 | 428 | } }); |
| 429 | 429 | } |
| 430 | 430 | |
| 431 | | fn nodeOffset(block: Block, node_offset: i32) LazySrcLoc { |
| 431 | pub fn nodeOffset(block: Block, node_offset: i32) LazySrcLoc { |
| 432 | 432 | return block.src(LazySrcLoc.Offset.nodeOffset(node_offset)); |
| 433 | 433 | } |
| 434 | 434 | |
| ... | ... | @@ -2149,7 +2149,7 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) |
| 2149 | 2149 | const addrs_ptr = try err_trace_block.addTy(.alloc, try pt.singleMutPtrType(addr_arr_ty)); |
| 2150 | 2150 | |
| 2151 | 2151 | // var st: StackTrace = undefined; |
| 2152 | | const stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 2152 | const stack_trace_ty = try sema.getBuiltinType(block.nodeOffset(0), .StackTrace); |
| 2153 | 2153 | try stack_trace_ty.resolveFields(pt); |
| 2154 | 2154 | const st_ptr = try err_trace_block.addTy(.alloc, try pt.singleMutPtrType(stack_trace_ty)); |
| 2155 | 2155 | |
| ... | ... | @@ -6600,6 +6600,7 @@ fn zirDisableInstrumentation(sema: *Sema) CompileError!void { |
| 6600 | 6600 | .nav_val, |
| 6601 | 6601 | .nav_ty, |
| 6602 | 6602 | .type, |
| 6603 | .memoized_state, |
| 6603 | 6604 | => return, // does nothing outside a function |
| 6604 | 6605 | }; |
| 6605 | 6606 | ip.funcSetDisableInstrumentation(func); |
| ... | ... | @@ -6609,7 +6610,7 @@ fn zirDisableInstrumentation(sema: *Sema) CompileError!void { |
| 6609 | 6610 | fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { |
| 6610 | 6611 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 6611 | 6612 | const src = block.builtinCallArgSrc(extra.node, 0); |
| 6612 | | block.float_mode = try sema.resolveBuiltinEnum(block, src, extra.operand, "FloatMode", .{ .simple = .operand_setFloatMode }); |
| 6613 | block.float_mode = try sema.resolveBuiltinEnum(block, src, extra.operand, .FloatMode, .{ .simple = .operand_setFloatMode }); |
| 6613 | 6614 | } |
| 6614 | 6615 | |
| 6615 | 6616 | fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| ... | ... | @@ -6917,7 +6918,7 @@ fn lookupInNamespace( |
| 6917 | 6918 | |
| 6918 | 6919 | ignore_self: { |
| 6919 | 6920 | const skip_nav = switch (sema.owner.unwrap()) { |
| 6920 | | .@"comptime", .type, .func => break :ignore_self, |
| 6921 | .@"comptime", .type, .func, .memoized_state => break :ignore_self, |
| 6921 | 6922 | .nav_ty, .nav_val => |nav| nav, |
| 6922 | 6923 | }; |
| 6923 | 6924 | var i: usize = 0; |
| ... | ... | @@ -6990,7 +6991,7 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref |
| 6990 | 6991 | |
| 6991 | 6992 | if (!block.ownerModule().error_tracing) return .none; |
| 6992 | 6993 | |
| 6993 | | const stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 6994 | const stack_trace_ty = try sema.getBuiltinType(block.nodeOffset(0), .StackTrace); |
| 6994 | 6995 | try stack_trace_ty.resolveFields(pt); |
| 6995 | 6996 | const field_name = try zcu.intern_pool.getOrPutString(gpa, pt.tid, "index", .no_embedded_nulls); |
| 6996 | 6997 | const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, LazySrcLoc.unneeded) catch |err| switch (err) { |
| ... | ... | @@ -7032,7 +7033,7 @@ fn popErrorReturnTrace( |
| 7032 | 7033 | // AstGen determined this result does not go to an error-handling expr (try/catch/return etc.), or |
| 7033 | 7034 | // the result is comptime-known to be a non-error. Either way, pop unconditionally. |
| 7034 | 7035 | |
| 7035 | | const stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 7036 | const stack_trace_ty = try sema.getBuiltinType(src, .StackTrace); |
| 7036 | 7037 | try stack_trace_ty.resolveFields(pt); |
| 7037 | 7038 | const ptr_stack_trace_ty = try pt.singleMutPtrType(stack_trace_ty); |
| 7038 | 7039 | const err_return_trace = try block.addTy(.err_return_trace, ptr_stack_trace_ty); |
| ... | ... | @@ -7058,7 +7059,7 @@ fn popErrorReturnTrace( |
| 7058 | 7059 | defer then_block.instructions.deinit(gpa); |
| 7059 | 7060 | |
| 7060 | 7061 | // If non-error, then pop the error return trace by restoring the index. |
| 7061 | | const stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 7062 | const stack_trace_ty = try sema.getBuiltinType(src, .StackTrace); |
| 7062 | 7063 | try stack_trace_ty.resolveFields(pt); |
| 7063 | 7064 | const ptr_stack_trace_ty = try pt.singleMutPtrType(stack_trace_ty); |
| 7064 | 7065 | const err_return_trace = try then_block.addTy(.err_return_trace, ptr_stack_trace_ty); |
| ... | ... | @@ -7178,7 +7179,7 @@ fn zirCall( |
| 7178 | 7179 | const call_inst = try sema.analyzeCall(block, func, func_ty, callee_src, call_src, modifier, ensure_result_used, args_info, call_dbg_node, .call); |
| 7179 | 7180 | |
| 7180 | 7181 | switch (sema.owner.unwrap()) { |
| 7181 | | .@"comptime", .type, .nav_ty, .nav_val => input_is_error = false, |
| 7182 | .@"comptime", .type, .memoized_state, .nav_ty, .nav_val => input_is_error = false, |
| 7182 | 7183 | .func => |owner_func| if (!zcu.intern_pool.funcAnalysisUnordered(owner_func).calls_or_awaits_errorable_fn) { |
| 7183 | 7184 | // No errorable fn actually called; we have no error return trace |
| 7184 | 7185 | input_is_error = false; |
| ... | ... | @@ -7201,7 +7202,7 @@ fn zirCall( |
| 7201 | 7202 | // If any input is an error-type, we might need to pop any trace it generated. Otherwise, we only |
| 7202 | 7203 | // need to clean-up our own trace if we were passed to a non-error-handling expression. |
| 7203 | 7204 | if (input_is_error or (pop_error_return_trace and return_ty.isError(zcu))) { |
| 7204 | | const stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 7205 | const stack_trace_ty = try sema.getBuiltinType(call_src, .StackTrace); |
| 7205 | 7206 | try stack_trace_ty.resolveFields(pt); |
| 7206 | 7207 | const field_name = try zcu.intern_pool.getOrPutString(sema.gpa, pt.tid, "index", .no_embedded_nulls); |
| 7207 | 7208 | const field_index = try sema.structFieldIndex(block, stack_trace_ty, field_name, call_src); |
| ... | ... | @@ -8091,7 +8092,7 @@ fn analyzeCall( |
| 8091 | 8092 | if (call_dbg_node) |some| try sema.zirDbgStmt(block, some); |
| 8092 | 8093 | |
| 8093 | 8094 | switch (sema.owner.unwrap()) { |
| 8094 | | .@"comptime", .nav_ty, .nav_val, .type => {}, |
| 8095 | .@"comptime", .nav_ty, .nav_val, .type, .memoized_state => {}, |
| 8095 | 8096 | .func => |owner_func| if (Type.fromInterned(func_ty_info.return_type).isError(zcu)) { |
| 8096 | 8097 | ip.funcSetCallsOrAwaitsErrorableFn(owner_func); |
| 8097 | 8098 | }, |
| ... | ... | @@ -8557,7 +8558,7 @@ fn instantiateGenericCall( |
| 8557 | 8558 | if (call_dbg_node) |some| try sema.zirDbgStmt(block, some); |
| 8558 | 8559 | |
| 8559 | 8560 | switch (sema.owner.unwrap()) { |
| 8560 | | .@"comptime", .nav_ty, .nav_val, .type => {}, |
| 8561 | .@"comptime", .nav_ty, .nav_val, .type, .memoized_state => {}, |
| 8561 | 8562 | .func => |owner_func| if (Type.fromInterned(func_ty_info.return_type).isError(zcu)) { |
| 8562 | 8563 | ip.funcSetCallsOrAwaitsErrorableFn(owner_func); |
| 8563 | 8564 | }, |
| ... | ... | @@ -9537,6 +9538,7 @@ fn zirFunc( |
| 9537 | 9538 | const extra = sema.code.extraData(Zir.Inst.Func, inst_data.payload_index); |
| 9538 | 9539 | const target = zcu.getTarget(); |
| 9539 | 9540 | const ret_ty_src = block.src(.{ .node_offset_fn_type_ret_ty = inst_data.src_node }); |
| 9541 | const src = block.nodeOffset(inst_data.src_node); |
| 9540 | 9542 | |
| 9541 | 9543 | var extra_index = extra.end; |
| 9542 | 9544 | |
| ... | ... | @@ -9588,7 +9590,7 @@ fn zirFunc( |
| 9588 | 9590 | // error by trying to evaluate `std.builtin.CallingConvention.c`, so for consistency, |
| 9589 | 9591 | // let's eval that now and just get the transitive error. (It's guaranteed to error |
| 9590 | 9592 | // because it does the exact `cCallingConvention` call we just did.) |
| 9591 | | const cc_type = try sema.getBuiltinType("CallingConvention"); |
| 9593 | const cc_type = try sema.getBuiltinType(src, .CallingConvention); |
| 9592 | 9594 | _ = try sema.namespaceLookupVal( |
| 9593 | 9595 | block, |
| 9594 | 9596 | LazySrcLoc.unneeded, |
| ... | ... | @@ -10302,7 +10304,7 @@ fn finishFunc( |
| 10302 | 10304 | if (!final_is_generic and sema.wantErrorReturnTracing(return_type)) { |
| 10303 | 10305 | // Make sure that StackTrace's fields are resolved so that the backend can |
| 10304 | 10306 | // lower this fn type. |
| 10305 | | const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 10307 | const unresolved_stack_trace_ty = try sema.getBuiltinType(block.nodeOffset(0), .StackTrace); |
| 10306 | 10308 | try unresolved_stack_trace_ty.resolveFields(pt); |
| 10307 | 10309 | } |
| 10308 | 10310 | |
| ... | ... | @@ -14283,7 +14285,7 @@ fn maybeErrorUnwrap( |
| 14283 | 14285 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 14284 | 14286 | const msg_inst = try sema.resolveInst(inst_data.operand); |
| 14285 | 14287 | |
| 14286 | | const panic_fn = try getPanicInnerFn(sema, block, operand_src, "call"); |
| 14288 | const panic_fn = try getBuiltin(sema, operand_src, .@"Panic.call"); |
| 14287 | 14289 | const err_return_trace = try sema.getErrorReturnTrace(block); |
| 14288 | 14290 | const args: [3]Air.Inst.Ref = .{ msg_inst, err_return_trace, .null_value }; |
| 14289 | 14291 | try sema.callBuiltin(block, operand_src, Air.internedToRef(panic_fn), .auto, &args, .@"safety check"); |
| ... | ... | @@ -17477,7 +17479,7 @@ fn analyzeArithmetic( |
| 17477 | 17479 | if (block.wantSafety() and want_safety and scalar_tag == .int) { |
| 17478 | 17480 | if (zcu.backendSupportsFeature(.safety_checked_instructions)) { |
| 17479 | 17481 | if (air_tag != air_tag_safe) { |
| 17480 | | _ = try sema.preparePanicId(block, src, .integer_overflow); |
| 17482 | _ = try sema.preparePanicId(src, .integer_overflow); |
| 17481 | 17483 | } |
| 17482 | 17484 | return block.addBinOp(air_tag_safe, casted_lhs, casted_rhs); |
| 17483 | 17485 | } else { |
| ... | ... | @@ -18381,7 +18383,7 @@ fn zirBuiltinSrc( |
| 18381 | 18383 | } }); |
| 18382 | 18384 | }; |
| 18383 | 18385 | |
| 18384 | | const src_loc_ty = try sema.getBuiltinType("SourceLocation"); |
| 18386 | const src_loc_ty = try sema.getBuiltinType(block.nodeOffset(0), .SourceLocation); |
| 18385 | 18387 | const fields = .{ |
| 18386 | 18388 | // module: [:0]const u8, |
| 18387 | 18389 | module_name_val, |
| ... | ... | @@ -18408,7 +18410,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18408 | 18410 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 18409 | 18411 | const src = block.nodeOffset(inst_data.src_node); |
| 18410 | 18412 | const ty = try sema.resolveType(block, src, inst_data.operand); |
| 18411 | | const type_info_ty = try sema.getBuiltinType("Type"); |
| 18413 | const type_info_ty = try sema.getBuiltinType(src, .Type); |
| 18412 | 18414 | const type_info_tag_ty = type_info_ty.unionTagType(zcu).?; |
| 18413 | 18415 | |
| 18414 | 18416 | if (ty.typeDeclInst(zcu)) |type_decl_inst| { |
| ... | ... | @@ -18428,8 +18430,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18428 | 18430 | => |type_info_tag| return unionInitFromEnumTag(sema, block, src, type_info_ty, @intFromEnum(type_info_tag), .void_value), |
| 18429 | 18431 | |
| 18430 | 18432 | .@"fn" => { |
| 18431 | | const fn_info_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "Fn"); |
| 18432 | | const param_info_ty = try getBuiltinInnerType(sema, block, src, fn_info_ty, "Type.Fn", "Param"); |
| 18433 | const fn_info_ty = try sema.getBuiltinType(src, .@"Type.Fn"); |
| 18434 | const param_info_ty = try sema.getBuiltinType(src, .@"Type.Fn.Param"); |
| 18433 | 18435 | |
| 18434 | 18436 | const func_ty_info = zcu.typeToFunc(ty).?; |
| 18435 | 18437 | const param_vals = try sema.arena.alloc(InternPool.Index, func_ty_info.param_types.len); |
| ... | ... | @@ -18499,7 +18501,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18499 | 18501 | func_ty_info.return_type, |
| 18500 | 18502 | } }); |
| 18501 | 18503 | |
| 18502 | | const callconv_ty = try sema.getBuiltinType("CallingConvention"); |
| 18504 | const callconv_ty = try sema.getBuiltinType(src, .CallingConvention); |
| 18503 | 18505 | const callconv_val = Value.uninterpret(func_ty_info.cc, callconv_ty, pt) catch |err| switch (err) { |
| 18504 | 18506 | error.TypeMismatch => @panic("std.builtin is corrupt"), |
| 18505 | 18507 | error.OutOfMemory => |e| return e, |
| ... | ... | @@ -18527,8 +18529,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18527 | 18529 | }))); |
| 18528 | 18530 | }, |
| 18529 | 18531 | .int => { |
| 18530 | | const int_info_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "Int"); |
| 18531 | | const signedness_ty = try sema.getBuiltinType("Signedness"); |
| 18532 | const int_info_ty = try sema.getBuiltinType(src, .@"Type.Int"); |
| 18533 | const signedness_ty = try sema.getBuiltinType(src, .Signedness); |
| 18532 | 18534 | const info = ty.intInfo(zcu); |
| 18533 | 18535 | const field_values = .{ |
| 18534 | 18536 | // signedness: Signedness, |
| ... | ... | @@ -18546,7 +18548,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18546 | 18548 | }))); |
| 18547 | 18549 | }, |
| 18548 | 18550 | .float => { |
| 18549 | | const float_info_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "Float"); |
| 18551 | const float_info_ty = try sema.getBuiltinType(src, .@"Type.Float"); |
| 18550 | 18552 | |
| 18551 | 18553 | const field_vals = .{ |
| 18552 | 18554 | // bits: u16, |
| ... | ... | @@ -18568,9 +18570,9 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18568 | 18570 | else |
| 18569 | 18571 | try Type.fromInterned(info.child).lazyAbiAlignment(pt); |
| 18570 | 18572 | |
| 18571 | | const addrspace_ty = try sema.getBuiltinType("AddressSpace"); |
| 18572 | | const pointer_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "Pointer"); |
| 18573 | | const ptr_size_ty = try getBuiltinInnerType(sema, block, src, pointer_ty, "Type.Pointer", "Size"); |
| 18573 | const addrspace_ty = try sema.getBuiltinType(src, .AddressSpace); |
| 18574 | const pointer_ty = try sema.getBuiltinType(src, .@"Type.Pointer"); |
| 18575 | const ptr_size_ty = try sema.getBuiltinType(src, .@"Type.Pointer.Size"); |
| 18574 | 18576 | |
| 18575 | 18577 | const field_values = .{ |
| 18576 | 18578 | // size: Size, |
| ... | ... | @@ -18603,7 +18605,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18603 | 18605 | }))); |
| 18604 | 18606 | }, |
| 18605 | 18607 | .array => { |
| 18606 | | const array_field_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "Array"); |
| 18608 | const array_field_ty = try sema.getBuiltinType(src, .@"Type.Array"); |
| 18607 | 18609 | |
| 18608 | 18610 | const info = ty.arrayInfo(zcu); |
| 18609 | 18611 | const field_values = .{ |
| ... | ... | @@ -18624,7 +18626,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18624 | 18626 | }))); |
| 18625 | 18627 | }, |
| 18626 | 18628 | .vector => { |
| 18627 | | const vector_field_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "Vector"); |
| 18629 | const vector_field_ty = try sema.getBuiltinType(src, .@"Type.Vector"); |
| 18628 | 18630 | |
| 18629 | 18631 | const info = ty.arrayInfo(zcu); |
| 18630 | 18632 | const field_values = .{ |
| ... | ... | @@ -18643,7 +18645,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18643 | 18645 | }))); |
| 18644 | 18646 | }, |
| 18645 | 18647 | .optional => { |
| 18646 | | const optional_field_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "Optional"); |
| 18648 | const optional_field_ty = try sema.getBuiltinType(src, .@"Type.Optional"); |
| 18647 | 18649 | |
| 18648 | 18650 | const field_values = .{ |
| 18649 | 18651 | // child: type, |
| ... | ... | @@ -18660,7 +18662,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18660 | 18662 | }, |
| 18661 | 18663 | .error_set => { |
| 18662 | 18664 | // Get the Error type |
| 18663 | | const error_field_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "Error"); |
| 18665 | const error_field_ty = try sema.getBuiltinType(src, .@"Type.Error"); |
| 18664 | 18666 | |
| 18665 | 18667 | // Build our list of Error values |
| 18666 | 18668 | // Optional value is only null if anyerror |
| ... | ... | @@ -18756,7 +18758,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18756 | 18758 | }))); |
| 18757 | 18759 | }, |
| 18758 | 18760 | .error_union => { |
| 18759 | | const error_union_field_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "ErrorUnion"); |
| 18761 | const error_union_field_ty = try sema.getBuiltinType(src, .@"Type.ErrorUnion"); |
| 18760 | 18762 | |
| 18761 | 18763 | const field_values = .{ |
| 18762 | 18764 | // error_set: type, |
| ... | ... | @@ -18776,7 +18778,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18776 | 18778 | .@"enum" => { |
| 18777 | 18779 | const is_exhaustive = Value.makeBool(ip.loadEnumType(ty.toIntern()).tag_mode != .nonexhaustive); |
| 18778 | 18780 | |
| 18779 | | const enum_field_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "EnumField"); |
| 18781 | const enum_field_ty = try sema.getBuiltinType(src, .@"Type.EnumField"); |
| 18780 | 18782 | |
| 18781 | 18783 | const enum_field_vals = try sema.arena.alloc(InternPool.Index, ip.loadEnumType(ty.toIntern()).names.len); |
| 18782 | 18784 | for (enum_field_vals, 0..) |*field_val, tag_index| { |
| ... | ... | @@ -18861,9 +18863,9 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18861 | 18863 | } }); |
| 18862 | 18864 | }; |
| 18863 | 18865 | |
| 18864 | | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ip.loadEnumType(ty.toIntern()).namespace.toOptional()); |
| 18866 | const decls_val = try sema.typeInfoDecls(block, src, ip.loadEnumType(ty.toIntern()).namespace.toOptional()); |
| 18865 | 18867 | |
| 18866 | | const type_enum_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "Enum"); |
| 18868 | const type_enum_ty = try sema.getBuiltinType(src, .@"Type.Enum"); |
| 18867 | 18869 | |
| 18868 | 18870 | const field_values = .{ |
| 18869 | 18871 | // tag_type: type, |
| ... | ... | @@ -18885,8 +18887,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18885 | 18887 | }))); |
| 18886 | 18888 | }, |
| 18887 | 18889 | .@"union" => { |
| 18888 | | const type_union_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "Union"); |
| 18889 | | const union_field_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "UnionField"); |
| 18890 | const type_union_ty = try sema.getBuiltinType(src, .@"Type.Union"); |
| 18891 | const union_field_ty = try sema.getBuiltinType(src, .@"Type.UnionField"); |
| 18890 | 18892 | |
| 18891 | 18893 | try ty.resolveLayout(pt); // Getting alignment requires type layout |
| 18892 | 18894 | const union_obj = zcu.typeToUnion(ty).?; |
| ... | ... | @@ -18974,14 +18976,14 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18974 | 18976 | } }); |
| 18975 | 18977 | }; |
| 18976 | 18978 | |
| 18977 | | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespaceIndex(zcu).toOptional()); |
| 18979 | const decls_val = try sema.typeInfoDecls(block, src, ty.getNamespaceIndex(zcu).toOptional()); |
| 18978 | 18980 | |
| 18979 | 18981 | const enum_tag_ty_val = try pt.intern(.{ .opt = .{ |
| 18980 | 18982 | .ty = (try pt.optionalType(.type_type)).toIntern(), |
| 18981 | 18983 | .val = if (ty.unionTagType(zcu)) |tag_ty| tag_ty.toIntern() else .none, |
| 18982 | 18984 | } }); |
| 18983 | 18985 | |
| 18984 | | const container_layout_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "ContainerLayout"); |
| 18986 | const container_layout_ty = try sema.getBuiltinType(src, .@"Type.ContainerLayout"); |
| 18985 | 18987 | |
| 18986 | 18988 | const field_values = .{ |
| 18987 | 18989 | // layout: ContainerLayout, |
| ... | ... | @@ -19004,8 +19006,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 19004 | 19006 | }))); |
| 19005 | 19007 | }, |
| 19006 | 19008 | .@"struct" => { |
| 19007 | | const type_struct_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "Struct"); |
| 19008 | | const struct_field_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "StructField"); |
| 19009 | const type_struct_ty = try sema.getBuiltinType(src, .@"Type.Struct"); |
| 19010 | const struct_field_ty = try sema.getBuiltinType(src, .@"Type.StructField"); |
| 19009 | 19011 | |
| 19010 | 19012 | try ty.resolveLayout(pt); // Getting alignment requires type layout |
| 19011 | 19013 | |
| ... | ... | @@ -19169,7 +19171,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 19169 | 19171 | } }); |
| 19170 | 19172 | }; |
| 19171 | 19173 | |
| 19172 | | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespace(zcu)); |
| 19174 | const decls_val = try sema.typeInfoDecls(block, src, ty.getNamespace(zcu)); |
| 19173 | 19175 | |
| 19174 | 19176 | const backing_integer_val = try pt.intern(.{ .opt = .{ |
| 19175 | 19177 | .ty = (try pt.optionalType(.type_type)).toIntern(), |
| ... | ... | @@ -19179,7 +19181,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 19179 | 19181 | } else .none, |
| 19180 | 19182 | } }); |
| 19181 | 19183 | |
| 19182 | | const container_layout_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "ContainerLayout"); |
| 19184 | const container_layout_ty = try sema.getBuiltinType(src, .@"Type.ContainerLayout"); |
| 19183 | 19185 | |
| 19184 | 19186 | const layout = ty.containerLayout(zcu); |
| 19185 | 19187 | |
| ... | ... | @@ -19205,10 +19207,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 19205 | 19207 | }))); |
| 19206 | 19208 | }, |
| 19207 | 19209 | .@"opaque" => { |
| 19208 | | const type_opaque_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "Opaque"); |
| 19210 | const type_opaque_ty = try sema.getBuiltinType(src, .@"Type.Opaque"); |
| 19209 | 19211 | |
| 19210 | 19212 | try ty.resolveFields(pt); |
| 19211 | | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespace(zcu)); |
| 19213 | const decls_val = try sema.typeInfoDecls(block, src, ty.getNamespace(zcu)); |
| 19212 | 19214 | |
| 19213 | 19215 | const field_values = .{ |
| 19214 | 19216 | // decls: []const Declaration, |
| ... | ... | @@ -19232,14 +19234,13 @@ fn typeInfoDecls( |
| 19232 | 19234 | sema: *Sema, |
| 19233 | 19235 | block: *Block, |
| 19234 | 19236 | src: LazySrcLoc, |
| 19235 | | type_info_ty: Type, |
| 19236 | 19237 | opt_namespace: InternPool.OptionalNamespaceIndex, |
| 19237 | 19238 | ) CompileError!InternPool.Index { |
| 19238 | 19239 | const pt = sema.pt; |
| 19239 | 19240 | const zcu = pt.zcu; |
| 19240 | 19241 | const gpa = sema.gpa; |
| 19241 | 19242 | |
| 19242 | | const declaration_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "Declaration"); |
| 19243 | const declaration_ty = try sema.getBuiltinType(src, .@"Type.Declaration"); |
| 19243 | 19244 | |
| 19244 | 19245 | var decl_vals = std.ArrayList(InternPool.Index).init(gpa); |
| 19245 | 19246 | defer decl_vals.deinit(); |
| ... | ... | @@ -20181,11 +20182,11 @@ fn retWithErrTracing( |
| 20181 | 20182 | else => true, |
| 20182 | 20183 | }; |
| 20183 | 20184 | const gpa = sema.gpa; |
| 20184 | | const stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 20185 | const stack_trace_ty = try sema.getBuiltinType(src, .StackTrace); |
| 20185 | 20186 | try stack_trace_ty.resolveFields(pt); |
| 20186 | 20187 | const ptr_stack_trace_ty = try pt.singleMutPtrType(stack_trace_ty); |
| 20187 | 20188 | const err_return_trace = try block.addTy(.err_return_trace, ptr_stack_trace_ty); |
| 20188 | | const return_err_fn = try sema.getBuiltin("returnError"); |
| 20189 | const return_err_fn = Air.internedToRef(try sema.getBuiltin(src, .returnError)); |
| 20189 | 20190 | const args: [1]Air.Inst.Ref = .{err_return_trace}; |
| 20190 | 20191 | |
| 20191 | 20192 | if (!need_check) { |
| ... | ... | @@ -21607,7 +21608,7 @@ fn getErrorReturnTrace(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref { |
| 21607 | 21608 | const pt = sema.pt; |
| 21608 | 21609 | const zcu = pt.zcu; |
| 21609 | 21610 | const ip = &zcu.intern_pool; |
| 21610 | | const stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 21611 | const stack_trace_ty = try sema.getBuiltinType(block.nodeOffset(0), .StackTrace); |
| 21611 | 21612 | try stack_trace_ty.resolveFields(pt); |
| 21612 | 21613 | const ptr_stack_trace_ty = try pt.singleMutPtrType(stack_trace_ty); |
| 21613 | 21614 | const opt_ptr_stack_trace_ty = try pt.optionalType(ptr_stack_trace_ty.toIntern()); |
| ... | ... | @@ -21616,7 +21617,7 @@ fn getErrorReturnTrace(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref { |
| 21616 | 21617 | .func => |func| if (ip.funcAnalysisUnordered(func).calls_or_awaits_errorable_fn and block.ownerModule().error_tracing) { |
| 21617 | 21618 | return block.addTy(.err_return_trace, opt_ptr_stack_trace_ty); |
| 21618 | 21619 | }, |
| 21619 | | .@"comptime", .nav_ty, .nav_val, .type => {}, |
| 21620 | .@"comptime", .nav_ty, .nav_val, .type, .memoized_state => {}, |
| 21620 | 21621 | } |
| 21621 | 21622 | return Air.internedToRef(try pt.intern(.{ .opt = .{ |
| 21622 | 21623 | .ty = opt_ptr_stack_trace_ty.toIntern(), |
| ... | ... | @@ -21896,7 +21897,7 @@ fn zirReify( |
| 21896 | 21897 | }, |
| 21897 | 21898 | }, |
| 21898 | 21899 | }; |
| 21899 | | const type_info_ty = try sema.getBuiltinType("Type"); |
| 21900 | const type_info_ty = try sema.getBuiltinType(src, .Type); |
| 21900 | 21901 | const uncasted_operand = try sema.resolveInst(extra.operand); |
| 21901 | 21902 | const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src); |
| 21902 | 21903 | const val = try sema.resolveConstDefinedValue(block, operand_src, type_info, .{ .simple = .operand_Type }); |
| ... | ... | @@ -23156,7 +23157,7 @@ fn reifyStruct( |
| 23156 | 23157 | |
| 23157 | 23158 | fn resolveVaListRef(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.Inst.Ref) CompileError!Air.Inst.Ref { |
| 23158 | 23159 | const pt = sema.pt; |
| 23159 | | const va_list_ty = try sema.getBuiltinType("VaList"); |
| 23160 | const va_list_ty = try sema.getBuiltinType(src, .VaList); |
| 23160 | 23161 | const va_list_ptr = try pt.singleMutPtrType(va_list_ty); |
| 23161 | 23162 | |
| 23162 | 23163 | const inst = try sema.resolveInst(zir_ref); |
| ... | ... | @@ -23195,7 +23196,7 @@ fn zirCVaCopy(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) |
| 23195 | 23196 | const va_list_src = block.builtinCallArgSrc(extra.node, 0); |
| 23196 | 23197 | |
| 23197 | 23198 | const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.operand); |
| 23198 | | const va_list_ty = try sema.getBuiltinType("VaList"); |
| 23199 | const va_list_ty = try sema.getBuiltinType(src, .VaList); |
| 23199 | 23200 | |
| 23200 | 23201 | try sema.requireRuntimeBlock(block, src, null); |
| 23201 | 23202 | return block.addTyOp(.c_va_copy, va_list_ty, va_list_ref); |
| ... | ... | @@ -23215,7 +23216,7 @@ fn zirCVaEnd(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C |
| 23215 | 23216 | fn zirCVaStart(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { |
| 23216 | 23217 | const src = block.nodeOffset(@bitCast(extended.operand)); |
| 23217 | 23218 | |
| 23218 | | const va_list_ty = try sema.getBuiltinType("VaList"); |
| 23219 | const va_list_ty = try sema.getBuiltinType(src, .VaList); |
| 23219 | 23220 | try sema.requireRuntimeBlock(block, src, null); |
| 23220 | 23221 | return block.addInst(.{ |
| 23221 | 23222 | .tag = .c_va_start, |
| ... | ... | @@ -24821,7 +24822,7 @@ fn resolveExportOptions( |
| 24821 | 24822 | const zcu = pt.zcu; |
| 24822 | 24823 | const gpa = sema.gpa; |
| 24823 | 24824 | const ip = &zcu.intern_pool; |
| 24824 | | const export_options_ty = try sema.getBuiltinType("ExportOptions"); |
| 24825 | const export_options_ty = try sema.getBuiltinType(src, .ExportOptions); |
| 24825 | 24826 | const air_ref = try sema.resolveInst(zir_ref); |
| 24826 | 24827 | const options = try sema.coerce(block, export_options_ty, air_ref, src); |
| 24827 | 24828 | |
| ... | ... | @@ -24871,15 +24872,15 @@ fn resolveBuiltinEnum( |
| 24871 | 24872 | block: *Block, |
| 24872 | 24873 | src: LazySrcLoc, |
| 24873 | 24874 | zir_ref: Zir.Inst.Ref, |
| 24874 | | comptime name: []const u8, |
| 24875 | comptime name: Zcu.BuiltinDecl, |
| 24875 | 24876 | reason: ComptimeReason, |
| 24876 | | ) CompileError!@field(std.builtin, name) { |
| 24877 | ) CompileError!@field(std.builtin, @tagName(name)) { |
| 24877 | 24878 | const pt = sema.pt; |
| 24878 | | const ty = try sema.getBuiltinType(name); |
| 24879 | const ty = try sema.getBuiltinType(src, name); |
| 24879 | 24880 | const air_ref = try sema.resolveInst(zir_ref); |
| 24880 | 24881 | const coerced = try sema.coerce(block, ty, air_ref, src); |
| 24881 | 24882 | const val = try sema.resolveConstDefinedValue(block, src, coerced, reason); |
| 24882 | | return pt.zcu.toEnum(@field(std.builtin, name), val); |
| 24883 | return pt.zcu.toEnum(@field(std.builtin, @tagName(name)), val); |
| 24883 | 24884 | } |
| 24884 | 24885 | |
| 24885 | 24886 | fn resolveAtomicOrder( |
| ... | ... | @@ -24889,7 +24890,7 @@ fn resolveAtomicOrder( |
| 24889 | 24890 | zir_ref: Zir.Inst.Ref, |
| 24890 | 24891 | reason: ComptimeReason, |
| 24891 | 24892 | ) CompileError!std.builtin.AtomicOrder { |
| 24892 | | return sema.resolveBuiltinEnum(block, src, zir_ref, "AtomicOrder", reason); |
| 24893 | return sema.resolveBuiltinEnum(block, src, zir_ref, .AtomicOrder, reason); |
| 24893 | 24894 | } |
| 24894 | 24895 | |
| 24895 | 24896 | fn resolveAtomicRmwOp( |
| ... | ... | @@ -24898,7 +24899,7 @@ fn resolveAtomicRmwOp( |
| 24898 | 24899 | src: LazySrcLoc, |
| 24899 | 24900 | zir_ref: Zir.Inst.Ref, |
| 24900 | 24901 | ) CompileError!std.builtin.AtomicRmwOp { |
| 24901 | | return sema.resolveBuiltinEnum(block, src, zir_ref, "AtomicRmwOp", .{ .simple = .operand_atomicRmw_operation }); |
| 24902 | return sema.resolveBuiltinEnum(block, src, zir_ref, .AtomicRmwOp, .{ .simple = .operand_atomicRmw_operation }); |
| 24902 | 24903 | } |
| 24903 | 24904 | |
| 24904 | 24905 | fn zirCmpxchg( |
| ... | ... | @@ -25078,7 +25079,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 25078 | 25079 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 25079 | 25080 | const op_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 25080 | 25081 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 25081 | | const operation = try sema.resolveBuiltinEnum(block, op_src, extra.lhs, "ReduceOp", .{ .simple = .operand_reduce_operation }); |
| 25082 | const operation = try sema.resolveBuiltinEnum(block, op_src, extra.lhs, .ReduceOp, .{ .simple = .operand_reduce_operation }); |
| 25082 | 25083 | const operand = try sema.resolveInst(extra.rhs); |
| 25083 | 25084 | const operand_ty = sema.typeOf(operand); |
| 25084 | 25085 | const pt = sema.pt; |
| ... | ... | @@ -25668,7 +25669,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 25668 | 25669 | const extra = sema.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data; |
| 25669 | 25670 | const func = try sema.resolveInst(extra.callee); |
| 25670 | 25671 | |
| 25671 | | const modifier_ty = try sema.getBuiltinType("CallModifier"); |
| 25672 | const modifier_ty = try sema.getBuiltinType(call_src, .CallModifier); |
| 25672 | 25673 | const air_ref = try sema.resolveInst(extra.modifier); |
| 25673 | 25674 | const modifier_ref = try sema.coerce(block, modifier_ty, air_ref, modifier_src); |
| 25674 | 25675 | const modifier_val = try sema.resolveConstDefinedValue(block, modifier_src, modifier_ref, .{ .simple = .call_modifier }); |
| ... | ... | @@ -26630,13 +26631,13 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 26630 | 26631 | const body = sema.code.bodySlice(extra_index, body_len); |
| 26631 | 26632 | extra_index += body.len; |
| 26632 | 26633 | |
| 26633 | | const cc_ty = try sema.getBuiltinType("CallingConvention"); |
| 26634 | const cc_ty = try sema.getBuiltinType(cc_src, .CallingConvention); |
| 26634 | 26635 | const val = try sema.resolveGenericBody(block, cc_src, body, inst, cc_ty, .{ .simple = .@"callconv" }); |
| 26635 | 26636 | break :blk try sema.analyzeValueAsCallconv(block, cc_src, val); |
| 26636 | 26637 | } else if (extra.data.bits.has_cc_ref) blk: { |
| 26637 | 26638 | const cc_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 26638 | 26639 | extra_index += 1; |
| 26639 | | const cc_ty = try sema.getBuiltinType("CallingConvention"); |
| 26640 | const cc_ty = try sema.getBuiltinType(cc_src, .CallingConvention); |
| 26640 | 26641 | const uncoerced_cc = try sema.resolveInst(cc_ref); |
| 26641 | 26642 | const coerced_cc = try sema.coerce(block, cc_ty, uncoerced_cc, cc_src); |
| 26642 | 26643 | const cc_val = try sema.resolveConstDefinedValue(block, cc_src, coerced_cc, .{ .simple = .@"callconv" }); |
| ... | ... | @@ -26656,7 +26657,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 26656 | 26657 | // error by trying to evaluate `std.builtin.CallingConvention.c`, so for consistency, |
| 26657 | 26658 | // let's eval that now and just get the transitive error. (It's guaranteed to error |
| 26658 | 26659 | // because it does the exact `cCallingConvention` call we just did.) |
| 26659 | | const cc_type = try sema.getBuiltinType("CallingConvention"); |
| 26660 | const cc_type = try sema.getBuiltinType(cc_src, .CallingConvention); |
| 26660 | 26661 | _ = try sema.namespaceLookupVal( |
| 26661 | 26662 | block, |
| 26662 | 26663 | LazySrcLoc.unneeded, |
| ... | ... | @@ -26834,7 +26835,7 @@ fn resolvePrefetchOptions( |
| 26834 | 26835 | const zcu = pt.zcu; |
| 26835 | 26836 | const gpa = sema.gpa; |
| 26836 | 26837 | const ip = &zcu.intern_pool; |
| 26837 | | const options_ty = try sema.getBuiltinType("PrefetchOptions"); |
| 26838 | const options_ty = try sema.getBuiltinType(src, .PrefetchOptions); |
| 26838 | 26839 | const options = try sema.coerce(block, options_ty, try sema.resolveInst(zir_ref), src); |
| 26839 | 26840 | |
| 26840 | 26841 | const rw_src = block.src(.{ .init_field_rw = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| ... | ... | @@ -26902,7 +26903,7 @@ fn resolveExternOptions( |
| 26902 | 26903 | const gpa = sema.gpa; |
| 26903 | 26904 | const ip = &zcu.intern_pool; |
| 26904 | 26905 | const options_inst = try sema.resolveInst(zir_ref); |
| 26905 | | const extern_options_ty = try sema.getBuiltinType("ExternOptions"); |
| 26906 | const extern_options_ty = try sema.getBuiltinType(src, .ExternOptions); |
| 26906 | 26907 | const options = try sema.coerce(block, extern_options_ty, options_inst, src); |
| 26907 | 26908 | |
| 26908 | 26909 | const name_src = block.src(.{ .init_field_name = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| ... | ... | @@ -27004,6 +27005,7 @@ fn zirBuiltinExtern( |
| 27004 | 27005 | .zir_index = switch (sema.owner.unwrap()) { |
| 27005 | 27006 | .@"comptime" => |cu| ip.getComptimeUnit(cu).zir_index, |
| 27006 | 27007 | .type => |owner_ty| Type.fromInterned(owner_ty).typeDeclInst(zcu).?, |
| 27008 | .memoized_state => unreachable, |
| 27007 | 27009 | .nav_ty, .nav_val => |nav| ip.getNav(nav).analysis.?.zir_index, |
| 27008 | 27010 | .func => |func| zir_index: { |
| 27009 | 27011 | const func_info = zcu.funcInfo(func); |
| ... | ... | @@ -27081,23 +27083,25 @@ fn zirBuiltinValue(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD |
| 27081 | 27083 | const src = block.nodeOffset(@bitCast(extended.operand)); |
| 27082 | 27084 | const value: Zir.Inst.BuiltinValue = @enumFromInt(extended.small); |
| 27083 | 27085 | |
| 27084 | | const type_name = switch (value) { |
| 27085 | | .atomic_order => "AtomicOrder", |
| 27086 | | .atomic_rmw_op => "AtomicRmwOp", |
| 27087 | | .calling_convention => "CallingConvention", |
| 27088 | | .address_space => "AddressSpace", |
| 27089 | | .float_mode => "FloatMode", |
| 27090 | | .reduce_op => "ReduceOp", |
| 27091 | | .call_modifier => "CallModifier", |
| 27092 | | .prefetch_options => "PrefetchOptions", |
| 27093 | | .export_options => "ExportOptions", |
| 27094 | | .extern_options => "ExternOptions", |
| 27095 | | .type_info => "Type", |
| 27096 | | .branch_hint => "BranchHint", |
| 27086 | const ty = switch (value) { |
| 27087 | // zig fmt: off |
| 27088 | .atomic_order => try sema.getBuiltinType(src, .AtomicOrder), |
| 27089 | .atomic_rmw_op => try sema.getBuiltinType(src, .AtomicRmwOp), |
| 27090 | .calling_convention => try sema.getBuiltinType(src, .CallingConvention), |
| 27091 | .address_space => try sema.getBuiltinType(src, .AddressSpace), |
| 27092 | .float_mode => try sema.getBuiltinType(src, .FloatMode), |
| 27093 | .reduce_op => try sema.getBuiltinType(src, .ReduceOp), |
| 27094 | .call_modifier => try sema.getBuiltinType(src, .CallModifier), |
| 27095 | .prefetch_options => try sema.getBuiltinType(src, .PrefetchOptions), |
| 27096 | .export_options => try sema.getBuiltinType(src, .ExportOptions), |
| 27097 | .extern_options => try sema.getBuiltinType(src, .ExternOptions), |
| 27098 | .type_info => try sema.getBuiltinType(src, .Type), |
| 27099 | .branch_hint => try sema.getBuiltinType(src, .BranchHint), |
| 27100 | // zig fmt: on |
| 27097 | 27101 | |
| 27098 | 27102 | // Values are handled here. |
| 27099 | 27103 | .calling_convention_c => { |
| 27100 | | const callconv_ty = try sema.getBuiltinType("CallingConvention"); |
| 27104 | const callconv_ty = try sema.getBuiltinType(src, .CallingConvention); |
| 27101 | 27105 | return try sema.namespaceLookupVal( |
| 27102 | 27106 | block, |
| 27103 | 27107 | src, |
| ... | ... | @@ -27107,7 +27111,7 @@ fn zirBuiltinValue(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD |
| 27107 | 27111 | }, |
| 27108 | 27112 | .calling_convention_inline => { |
| 27109 | 27113 | comptime assert(@typeInfo(std.builtin.CallingConvention.Tag).@"enum".tag_type == u8); |
| 27110 | | const callconv_ty = try sema.getBuiltinType("CallingConvention"); |
| 27114 | const callconv_ty = try sema.getBuiltinType(src, .CallingConvention); |
| 27111 | 27115 | const callconv_tag_ty = callconv_ty.unionTagType(zcu) orelse @panic("std.builtin is corrupt"); |
| 27112 | 27116 | const inline_tag_val = try pt.enumValue( |
| 27113 | 27117 | callconv_tag_ty, |
| ... | ... | @@ -27119,7 +27123,6 @@ fn zirBuiltinValue(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD |
| 27119 | 27123 | return sema.coerce(block, callconv_ty, Air.internedToRef(inline_tag_val.toIntern()), src); |
| 27120 | 27124 | }, |
| 27121 | 27125 | }; |
| 27122 | | const ty = try sema.getBuiltinType(type_name); |
| 27123 | 27126 | return Air.internedToRef(ty.toIntern()); |
| 27124 | 27127 | } |
| 27125 | 27128 | |
| ... | ... | @@ -27158,7 +27161,7 @@ fn zirBranchHint(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 27158 | 27161 | const uncoerced_hint = try sema.resolveInst(extra.operand); |
| 27159 | 27162 | const operand_src = block.builtinCallArgSrc(extra.node, 0); |
| 27160 | 27163 | |
| 27161 | | const hint_ty = try sema.getBuiltinType("BranchHint"); |
| 27164 | const hint_ty = try sema.getBuiltinType(operand_src, .BranchHint); |
| 27162 | 27165 | const coerced_hint = try sema.coerce(block, hint_ty, uncoerced_hint, operand_src); |
| 27163 | 27166 | const hint_val = try sema.resolveConstDefinedValue(block, operand_src, coerced_hint, .{ .simple = .operand_branchHint }); |
| 27164 | 27167 | |
| ... | ... | @@ -27603,61 +27606,19 @@ fn explainWhyTypeIsNotPacked( |
| 27603 | 27606 | } |
| 27604 | 27607 | } |
| 27605 | 27608 | |
| 27606 | | fn prepareSimplePanic(sema: *Sema, block: *Block, src: LazySrcLoc) !void { |
| 27607 | | const pt = sema.pt; |
| 27608 | | const zcu = pt.zcu; |
| 27609 | | |
| 27610 | | if (zcu.panic_func_index == .none) { |
| 27611 | | zcu.panic_func_index = try sema.getPanicInnerFn(block, src, "call"); |
| 27612 | | // Here, function body analysis must be queued up so that backends can |
| 27613 | | // make calls to this function. |
| 27614 | | try zcu.ensureFuncBodyAnalysisQueued(zcu.panic_func_index); |
| 27615 | | } |
| 27616 | | |
| 27617 | | if (zcu.null_stack_trace == .none) { |
| 27618 | | const stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 27619 | | try stack_trace_ty.resolveFields(pt); |
| 27620 | | const target = zcu.getTarget(); |
| 27621 | | const ptr_stack_trace_ty = try pt.ptrTypeSema(.{ |
| 27622 | | .child = stack_trace_ty.toIntern(), |
| 27623 | | .flags = .{ |
| 27624 | | .address_space = target_util.defaultAddressSpace(target, .global_constant), |
| 27625 | | }, |
| 27626 | | }); |
| 27627 | | const opt_ptr_stack_trace_ty = try pt.optionalType(ptr_stack_trace_ty.toIntern()); |
| 27628 | | zcu.null_stack_trace = try pt.intern(.{ .opt = .{ |
| 27629 | | .ty = opt_ptr_stack_trace_ty.toIntern(), |
| 27630 | | .val = .none, |
| 27631 | | } }); |
| 27632 | | } |
| 27633 | | } |
| 27634 | | |
| 27635 | 27609 | /// Backends depend on panic decls being available when lowering safety-checked |
| 27636 | 27610 | /// instructions. This function ensures the panic function will be available to |
| 27637 | 27611 | /// be called during that time. |
| 27638 | | fn preparePanicId(sema: *Sema, block: *Block, src: LazySrcLoc, panic_id: Zcu.PanicId) !InternPool.Nav.Index { |
| 27639 | | const pt = sema.pt; |
| 27640 | | const zcu = pt.zcu; |
| 27641 | | const gpa = sema.gpa; |
| 27642 | | if (zcu.panic_messages[@intFromEnum(panic_id)].unwrap()) |x| return x; |
| 27643 | | |
| 27644 | | try sema.prepareSimplePanic(block, src); |
| 27645 | | |
| 27646 | | const panic_ty = try sema.getBuiltinType("Panic"); |
| 27647 | | const panic_messages_ty = try sema.getBuiltinInnerType(block, src, panic_ty, "Panic", "messages"); |
| 27648 | | const msg_nav_index = (sema.namespaceLookup( |
| 27649 | | block, |
| 27650 | | LazySrcLoc.unneeded, |
| 27651 | | panic_messages_ty.getNamespaceIndex(zcu), |
| 27652 | | try zcu.intern_pool.getOrPutString(gpa, pt.tid, @tagName(panic_id), .no_embedded_nulls), |
| 27653 | | ) catch |err| switch (err) { |
| 27654 | | error.AnalysisFail => return error.AnalysisFail, |
| 27655 | | error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, |
| 27656 | | error.OutOfMemory => |e| return e, |
| 27657 | | }).?; |
| 27658 | | try sema.ensureNavResolved(src, msg_nav_index, .fully); |
| 27659 | | zcu.panic_messages[@intFromEnum(panic_id)] = msg_nav_index.toOptional(); |
| 27660 | | return msg_nav_index; |
| 27612 | fn preparePanicId(sema: *Sema, src: LazySrcLoc, panic_id: Zcu.PanicId) !InternPool.Index { |
| 27613 | const zcu = sema.pt.zcu; |
| 27614 | try sema.ensureMemoizedStateResolved(src, .panic); |
| 27615 | try zcu.ensureFuncBodyAnalysisQueued(zcu.builtin_decl_values.@"Panic.call"); |
| 27616 | switch (panic_id) { |
| 27617 | inline else => |ct_panic_id| { |
| 27618 | const name = "Panic.messages." ++ @tagName(ct_panic_id); |
| 27619 | return @field(zcu.builtin_decl_values, name); |
| 27620 | }, |
| 27621 | } |
| 27661 | 27622 | } |
| 27662 | 27623 | |
| 27663 | 27624 | fn addSafetyCheck( |
| ... | ... | @@ -27761,10 +27722,10 @@ fn panicWithMsg(sema: *Sema, block: *Block, src: LazySrcLoc, msg_inst: Air.Inst. |
| 27761 | 27722 | return; |
| 27762 | 27723 | } |
| 27763 | 27724 | |
| 27764 | | try sema.prepareSimplePanic(block, src); |
| 27725 | try sema.ensureMemoizedStateResolved(src, .panic); |
| 27726 | try zcu.ensureFuncBodyAnalysisQueued(zcu.builtin_decl_values.@"Panic.call"); |
| 27765 | 27727 | |
| 27766 | | const panic_func = zcu.funcInfo(zcu.panic_func_index); |
| 27767 | | const panic_fn = try sema.analyzeNavVal(block, src, panic_func.owner_nav); |
| 27728 | const panic_fn = Air.internedToRef(zcu.builtin_decl_values.@"Panic.call"); |
| 27768 | 27729 | const null_stack_trace = Air.internedToRef(zcu.null_stack_trace); |
| 27769 | 27730 | |
| 27770 | 27731 | const opt_usize_ty = try pt.optionalType(.usize_type); |
| ... | ... | @@ -27812,7 +27773,7 @@ fn safetyPanicUnwrapError(sema: *Sema, block: *Block, src: LazySrcLoc, err: Air. |
| 27812 | 27773 | if (!zcu.backendSupportsFeature(.panic_fn)) { |
| 27813 | 27774 | _ = try block.addNoOp(.trap); |
| 27814 | 27775 | } else { |
| 27815 | | const panic_fn = try getPanicInnerFn(sema, block, src, "unwrapError"); |
| 27776 | const panic_fn = try getBuiltin(sema, src, .@"Panic.unwrapError"); |
| 27816 | 27777 | const err_return_trace = try sema.getErrorReturnTrace(block); |
| 27817 | 27778 | const args: [2]Air.Inst.Ref = .{ err_return_trace, err }; |
| 27818 | 27779 | try sema.callBuiltin(block, src, Air.internedToRef(panic_fn), .auto, &args, .@"safety check"); |
| ... | ... | @@ -27829,7 +27790,7 @@ fn addSafetyCheckIndexOob( |
| 27829 | 27790 | ) !void { |
| 27830 | 27791 | assert(!parent_block.isComptime()); |
| 27831 | 27792 | const ok = try parent_block.addBinOp(cmp_op, index, len); |
| 27832 | | return addSafetyCheckCall(sema, parent_block, src, ok, "outOfBounds", &.{ index, len }); |
| 27793 | return addSafetyCheckCall(sema, parent_block, src, ok, .@"Panic.outOfBounds", &.{ index, len }); |
| 27833 | 27794 | } |
| 27834 | 27795 | |
| 27835 | 27796 | fn addSafetyCheckInactiveUnionField( |
| ... | ... | @@ -27841,7 +27802,7 @@ fn addSafetyCheckInactiveUnionField( |
| 27841 | 27802 | ) !void { |
| 27842 | 27803 | assert(!parent_block.isComptime()); |
| 27843 | 27804 | const ok = try parent_block.addBinOp(.cmp_eq, active_tag, wanted_tag); |
| 27844 | | return addSafetyCheckCall(sema, parent_block, src, ok, "inactiveUnionField", &.{ active_tag, wanted_tag }); |
| 27805 | return addSafetyCheckCall(sema, parent_block, src, ok, .@"Panic.inactiveUnionField", &.{ active_tag, wanted_tag }); |
| 27845 | 27806 | } |
| 27846 | 27807 | |
| 27847 | 27808 | fn addSafetyCheckSentinelMismatch( |
| ... | ... | @@ -27882,7 +27843,7 @@ fn addSafetyCheckSentinelMismatch( |
| 27882 | 27843 | break :ok try parent_block.addBinOp(.cmp_eq, expected_sentinel, actual_sentinel); |
| 27883 | 27844 | }; |
| 27884 | 27845 | |
| 27885 | | return addSafetyCheckCall(sema, parent_block, src, ok, "sentinelMismatch", &.{ |
| 27846 | return addSafetyCheckCall(sema, parent_block, src, ok, .@"Panic.sentinelMismatch", &.{ |
| 27886 | 27847 | expected_sentinel, actual_sentinel, |
| 27887 | 27848 | }); |
| 27888 | 27849 | } |
| ... | ... | @@ -27892,7 +27853,7 @@ fn addSafetyCheckCall( |
| 27892 | 27853 | parent_block: *Block, |
| 27893 | 27854 | src: LazySrcLoc, |
| 27894 | 27855 | ok: Air.Inst.Ref, |
| 27895 | | func_name: []const u8, |
| 27856 | comptime func_decl: Zcu.BuiltinDecl, |
| 27896 | 27857 | args: []const Air.Inst.Ref, |
| 27897 | 27858 | ) !void { |
| 27898 | 27859 | assert(!parent_block.isComptime()); |
| ... | ... | @@ -27916,7 +27877,7 @@ fn addSafetyCheckCall( |
| 27916 | 27877 | if (!zcu.backendSupportsFeature(.panic_fn)) { |
| 27917 | 27878 | _ = try fail_block.addNoOp(.trap); |
| 27918 | 27879 | } else { |
| 27919 | | const panic_fn = try getPanicInnerFn(sema, &fail_block, src, func_name); |
| 27880 | const panic_fn = try getBuiltin(sema, src, func_decl); |
| 27920 | 27881 | try sema.callBuiltin(&fail_block, src, Air.internedToRef(panic_fn), .auto, args, .@"safety check"); |
| 27921 | 27882 | } |
| 27922 | 27883 | |
| ... | ... | @@ -27925,9 +27886,8 @@ fn addSafetyCheckCall( |
| 27925 | 27886 | |
| 27926 | 27887 | /// This does not set `sema.branch_hint`. |
| 27927 | 27888 | fn safetyPanic(sema: *Sema, block: *Block, src: LazySrcLoc, panic_id: Zcu.PanicId) CompileError!void { |
| 27928 | | const msg_nav_index = try sema.preparePanicId(block, src, panic_id); |
| 27929 | | const msg_inst = try sema.analyzeNavVal(block, src, msg_nav_index); |
| 27930 | | try sema.panicWithMsg(block, src, msg_inst, .@"safety check"); |
| 27889 | const msg_val = try sema.preparePanicId(src, panic_id); |
| 27890 | try sema.panicWithMsg(block, src, Air.internedToRef(msg_val), .@"safety check"); |
| 27931 | 27891 | } |
| 27932 | 27892 | |
| 27933 | 27893 | fn emitBackwardBranch(sema: *Sema, block: *Block, src: LazySrcLoc) !void { |
| ... | ... | @@ -32524,6 +32484,19 @@ fn addTypeReferenceEntry( |
| 32524 | 32484 | try zcu.addTypeReference(sema.owner, referenced_type, src); |
| 32525 | 32485 | } |
| 32526 | 32486 | |
| 32487 | fn ensureMemoizedStateResolved(sema: *Sema, src: LazySrcLoc, stage: InternPool.MemoizedStateStage) SemaError!void { |
| 32488 | const pt = sema.pt; |
| 32489 | |
| 32490 | const unit: AnalUnit = .wrap(.{ .memoized_state = stage }); |
| 32491 | try sema.addReferenceEntry(src, unit); |
| 32492 | try sema.declareDependency(.{ .memoized_state = stage }); |
| 32493 | |
| 32494 | if (pt.zcu.analysis_in_progress.contains(unit)) { |
| 32495 | return sema.failWithOwnedErrorMsg(null, try sema.errMsg(src, "dependency loop detected", .{})); |
| 32496 | } |
| 32497 | try pt.ensureMemoizedStateUpToDate(stage); |
| 32498 | } |
| 32499 | |
| 32527 | 32500 | pub fn ensureNavResolved(sema: *Sema, src: LazySrcLoc, nav_index: InternPool.Nav.Index, kind: enum { type, fully }) CompileError!void { |
| 32528 | 32501 | const pt = sema.pt; |
| 32529 | 32502 | const zcu = pt.zcu; |
| ... | ... | @@ -33373,7 +33346,7 @@ fn analyzeSlice( |
| 33373 | 33346 | assert(!block.isComptime()); |
| 33374 | 33347 | try sema.requireRuntimeBlock(block, src, runtime_src.?); |
| 33375 | 33348 | const ok = try block.addBinOp(.cmp_lte, start, end); |
| 33376 | | try sema.addSafetyCheckCall(block, src, ok, "startGreaterThanEnd", &.{ start, end }); |
| 33349 | try sema.addSafetyCheckCall(block, src, ok, .@"Panic.startGreaterThanEnd", &.{ start, end }); |
| 33377 | 33350 | } |
| 33378 | 33351 | const new_len = if (by_length) |
| 33379 | 33352 | try sema.coerce(block, Type.usize, uncasted_end_opt, end_src) |
| ... | ... | @@ -35493,7 +35466,7 @@ pub fn resolveIes(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError!void |
| 35493 | 35466 | } |
| 35494 | 35467 | } |
| 35495 | 35468 | |
| 35496 | | pub fn resolveFnTypes(sema: *Sema, fn_ty: Type) CompileError!void { |
| 35469 | pub fn resolveFnTypes(sema: *Sema, fn_ty: Type, src: LazySrcLoc) CompileError!void { |
| 35497 | 35470 | const pt = sema.pt; |
| 35498 | 35471 | const zcu = pt.zcu; |
| 35499 | 35472 | const ip = &zcu.intern_pool; |
| ... | ... | @@ -35505,7 +35478,7 @@ pub fn resolveFnTypes(sema: *Sema, fn_ty: Type) CompileError!void { |
| 35505 | 35478 | Type.fromInterned(fn_ty_info.return_type).isError(zcu)) |
| 35506 | 35479 | { |
| 35507 | 35480 | // Ensure the type exists so that backends can assume that. |
| 35508 | | _ = try sema.getBuiltinType("StackTrace"); |
| 35481 | _ = try sema.getBuiltinType(src, .StackTrace); |
| 35509 | 35482 | } |
| 35510 | 35483 | |
| 35511 | 35484 | for (0..fn_ty_info.param_types.len) |i| { |
| ... | ... | @@ -37550,7 +37523,7 @@ pub fn analyzeAsAddressSpace( |
| 37550 | 37523 | ) !std.builtin.AddressSpace { |
| 37551 | 37524 | const pt = sema.pt; |
| 37552 | 37525 | const zcu = pt.zcu; |
| 37553 | | const addrspace_ty = try sema.getBuiltinType("AddressSpace"); |
| 37526 | const addrspace_ty = try sema.getBuiltinType(src, .AddressSpace); |
| 37554 | 37527 | const coerced = try sema.coerce(block, addrspace_ty, air_ref, src); |
| 37555 | 37528 | const addrspace_val = try sema.resolveConstDefinedValue(block, src, coerced, .{ .simple = .@"addrspace" }); |
| 37556 | 37529 | const address_space = zcu.toEnum(std.builtin.AddressSpace, addrspace_val); |
| ... | ... | @@ -38747,69 +38720,15 @@ const ComptimeLoadResult = @import("Sema/comptime_ptr_access.zig").ComptimeLoadR |
| 38747 | 38720 | const storeComptimePtr = @import("Sema/comptime_ptr_access.zig").storeComptimePtr; |
| 38748 | 38721 | const ComptimeStoreResult = @import("Sema/comptime_ptr_access.zig").ComptimeStoreResult; |
| 38749 | 38722 | |
| 38750 | | fn getPanicInnerFn( |
| 38751 | | sema: *Sema, |
| 38752 | | block: *Block, |
| 38753 | | src: LazySrcLoc, |
| 38754 | | inner_name: []const u8, |
| 38755 | | ) !InternPool.Index { |
| 38756 | | const gpa = sema.gpa; |
| 38757 | | const pt = sema.pt; |
| 38758 | | const zcu = pt.zcu; |
| 38759 | | const ip = &zcu.intern_pool; |
| 38760 | | const outer_ty = try sema.getBuiltinType("Panic"); |
| 38761 | | const inner_name_ip = try ip.getOrPutString(gpa, pt.tid, inner_name, .no_embedded_nulls); |
| 38762 | | const opt_fn_ref = try namespaceLookupVal(sema, block, src, outer_ty.getNamespaceIndex(zcu), inner_name_ip); |
| 38763 | | const fn_ref = opt_fn_ref orelse return sema.fail(block, src, "std.builtin.Panic missing {s}", .{inner_name}); |
| 38764 | | const fn_val = try sema.resolveConstValue(block, src, fn_ref, .{ .simple = .panic_handler }); |
| 38765 | | if (fn_val.typeOf(zcu).zigTypeTag(zcu) != .@"fn") { |
| 38766 | | return sema.fail(block, src, "std.builtin.Panic.{s} is not a function", .{inner_name}); |
| 38767 | | } |
| 38768 | | // Better not to queue up function body analysis because the function might be generic, and |
| 38769 | | // the semantic analysis for the call will already queue if necessary. |
| 38770 | | return fn_val.toIntern(); |
| 38771 | | } |
| 38772 | | |
| 38773 | | fn getBuiltinType(sema: *Sema, name: []const u8) SemaError!Type { |
| 38774 | | const pt = sema.pt; |
| 38775 | | const ty_inst = try sema.getBuiltin(name); |
| 38776 | | const ty = Type.fromInterned(ty_inst.toInterned() orelse @panic("std.builtin is corrupt")); |
| 38777 | | try ty.resolveFully(pt); |
| 38778 | | return ty; |
| 38779 | | } |
| 38780 | | |
| 38781 | | fn getBuiltinInnerType( |
| 38782 | | sema: *Sema, |
| 38783 | | block: *Block, |
| 38784 | | src: LazySrcLoc, |
| 38785 | | outer_ty: Type, |
| 38786 | | /// Relative to "std.builtin". |
| 38787 | | compile_error_parent_name: []const u8, |
| 38788 | | inner_name: []const u8, |
| 38789 | | ) !Type { |
| 38790 | | const pt = sema.pt; |
| 38791 | | const zcu = pt.zcu; |
| 38792 | | const ip = &zcu.intern_pool; |
| 38793 | | const gpa = sema.gpa; |
| 38794 | | const inner_name_ip = try ip.getOrPutString(gpa, pt.tid, inner_name, .no_embedded_nulls); |
| 38795 | | const opt_nav = try sema.namespaceLookup(block, src, outer_ty.getNamespaceIndex(zcu), inner_name_ip); |
| 38796 | | const nav = opt_nav orelse return sema.fail(block, src, "std.builtin.{s} missing {s}", .{ |
| 38797 | | compile_error_parent_name, inner_name, |
| 38798 | | }); |
| 38799 | | try sema.ensureNavResolved(src, nav, .fully); |
| 38800 | | const val = Value.fromInterned(ip.getNav(nav).status.fully_resolved.val); |
| 38801 | | const ty = val.toType(); |
| 38802 | | try ty.resolveFully(pt); |
| 38803 | | return ty; |
| 38723 | pub fn getBuiltinType(sema: *Sema, src: LazySrcLoc, comptime decl: Zcu.BuiltinDecl) SemaError!Type { |
| 38724 | comptime assert(decl.kind() == .type); |
| 38725 | try sema.ensureMemoizedStateResolved(src, decl.stage()); |
| 38726 | return .fromInterned(@field(sema.pt.zcu.builtin_decl_values, @tagName(decl))); |
| 38804 | 38727 | } |
| 38805 | | |
| 38806 | | fn getBuiltin(sema: *Sema, name: []const u8) SemaError!Air.Inst.Ref { |
| 38807 | | const pt = sema.pt; |
| 38808 | | const zcu = pt.zcu; |
| 38809 | | const ip = &zcu.intern_pool; |
| 38810 | | const nav = try pt.getBuiltinNav(name); |
| 38811 | | try pt.ensureNavValUpToDate(nav); |
| 38812 | | return Air.internedToRef(ip.getNav(nav).status.fully_resolved.val); |
| 38728 | pub fn getBuiltin(sema: *Sema, src: LazySrcLoc, comptime decl: Zcu.BuiltinDecl) SemaError!InternPool.Index { |
| 38729 | comptime assert(decl.kind() != .type); |
| 38730 | try sema.ensureMemoizedStateResolved(src, decl.stage()); |
| 38731 | return @field(sema.pt.zcu.builtin_decl_values, @tagName(decl)); |
| 38813 | 38732 | } |
| 38814 | 38733 | |
| 38815 | 38734 | pub const NavPtrModifiers = struct { |
| ... | ... | @@ -38877,3 +38796,77 @@ pub fn resolveNavPtrModifiers( |
| 38877 | 38796 | .@"addrspace" = @"addrspace", |
| 38878 | 38797 | }; |
| 38879 | 38798 | } |
| 38799 | |
| 38800 | pub fn analyzeMemoizedState(sema: *Sema, block: *Block, src: LazySrcLoc, builtin_namespace: InternPool.NamespaceIndex, stage: InternPool.MemoizedStateStage) CompileError!bool { |
| 38801 | const pt = sema.pt; |
| 38802 | const zcu = pt.zcu; |
| 38803 | const ip = &zcu.intern_pool; |
| 38804 | const gpa = zcu.gpa; |
| 38805 | |
| 38806 | var any_changed = false; |
| 38807 | |
| 38808 | inline for (comptime std.enums.values(Zcu.BuiltinDecl)) |builtin_decl| { |
| 38809 | if (stage == comptime builtin_decl.stage()) { |
| 38810 | const parent_ns: Zcu.Namespace.Index, const parent_name: []const u8, const name: []const u8 = switch (comptime builtin_decl.access()) { |
| 38811 | .direct => |name| .{ builtin_namespace, "std.builtin", name }, |
| 38812 | .nested => |nested| access: { |
| 38813 | const parent_ty: Type = .fromInterned(@field(zcu.builtin_decl_values, @tagName(nested[0]))); |
| 38814 | const parent_ns = parent_ty.getNamespace(zcu).unwrap() orelse { |
| 38815 | return sema.fail(block, src, "std.builtin.{s} is not a container type", .{@tagName(nested[0])}); |
| 38816 | }; |
| 38817 | break :access .{ parent_ns, "std.builtin." ++ @tagName(nested[0]), nested[1] }; |
| 38818 | }, |
| 38819 | }; |
| 38820 | |
| 38821 | const name_nts = try ip.getOrPutString(gpa, pt.tid, name, .no_embedded_nulls); |
| 38822 | const result = try sema.namespaceLookupVal(block, src, parent_ns, name_nts) orelse |
| 38823 | return sema.fail(block, src, "{s} missing {s}", .{ parent_name, name }); |
| 38824 | |
| 38825 | const val = try sema.resolveConstDefinedValue(block, src, result, null); |
| 38826 | |
| 38827 | switch (builtin_decl.kind()) { |
| 38828 | .type => if (val.typeOf(zcu).zigTypeTag(zcu) != .type) { |
| 38829 | return sema.fail(block, src, "{s}.{s} is not a type", .{ parent_name, name }); |
| 38830 | } else { |
| 38831 | try val.toType().resolveFully(pt); |
| 38832 | }, |
| 38833 | .func => if (val.typeOf(zcu).zigTypeTag(zcu) != .@"fn") { |
| 38834 | return sema.fail(block, src, "{s}.{s} is not a function", .{ parent_name, name }); |
| 38835 | }, |
| 38836 | .string => { |
| 38837 | const ty = val.typeOf(zcu); |
| 38838 | if (!ty.isSinglePointer(zcu) or |
| 38839 | !ty.isConstPtr(zcu) or |
| 38840 | ty.childType(zcu).zigTypeTag(zcu) != .array or |
| 38841 | ty.childType(zcu).childType(zcu).toIntern() != .u8_type) |
| 38842 | { |
| 38843 | return sema.fail(block, src, "{s}.{s} is not a valid string", .{ parent_name, name }); |
| 38844 | } |
| 38845 | }, |
| 38846 | } |
| 38847 | |
| 38848 | const prev = @field(zcu.builtin_decl_values, @tagName(builtin_decl)); |
| 38849 | if (val.toIntern() != prev) { |
| 38850 | @field(zcu.builtin_decl_values, @tagName(builtin_decl)) = val.toIntern(); |
| 38851 | any_changed = true; |
| 38852 | } |
| 38853 | } |
| 38854 | } |
| 38855 | |
| 38856 | if (stage == .panic) { |
| 38857 | // We use `getBuiltinType` because this is from an earlier stage. |
| 38858 | const stack_trace_ty = try sema.getBuiltinType(src, .StackTrace); |
| 38859 | const ptr_stack_trace_ty = try pt.singleMutPtrType(stack_trace_ty); |
| 38860 | const opt_ptr_stack_trace_ty = try pt.optionalType(ptr_stack_trace_ty.toIntern()); |
| 38861 | const null_stack_trace = try pt.intern(.{ .opt = .{ |
| 38862 | .ty = opt_ptr_stack_trace_ty.toIntern(), |
| 38863 | .val = .none, |
| 38864 | } }); |
| 38865 | if (null_stack_trace != zcu.null_stack_trace) { |
| 38866 | zcu.null_stack_trace = null_stack_trace; |
| 38867 | any_changed = true; |
| 38868 | } |
| 38869 | } |
| 38870 | |
| 38871 | return any_changed; |
| 38872 | } |