| ... | @@ -2141,7 +2141,7 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) | ... | @@ -2141,7 +2141,7 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) |
| 2141 | const addrs_ptr = try err_trace_block.addTy(.alloc, try pt.singleMutPtrType(addr_arr_ty)); | 2141 | const addrs_ptr = try err_trace_block.addTy(.alloc, try pt.singleMutPtrType(addr_arr_ty)); |
| 2142 | | 2142 | |
| 2143 | // var st: StackTrace = undefined; | 2143 | // var st: StackTrace = undefined; |
| 2144 | const stack_trace_ty = try pt.getBuiltinType("StackTrace"); | 2144 | const stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 2145 | try stack_trace_ty.resolveFields(pt); | 2145 | try stack_trace_ty.resolveFields(pt); |
| 2146 | const st_ptr = try err_trace_block.addTy(.alloc, try pt.singleMutPtrType(stack_trace_ty)); | 2146 | const st_ptr = try err_trace_block.addTy(.alloc, try pt.singleMutPtrType(stack_trace_ty)); |
| 2147 | | 2147 | |
| ... | @@ -4854,11 +4854,11 @@ fn validateUnionInit( | ... | @@ -4854,11 +4854,11 @@ fn validateUnionInit( |
| 4854 | } | 4854 | } |
| 4855 | block.instructions.shrinkRetainingCapacity(block_index); | 4855 | block.instructions.shrinkRetainingCapacity(block_index); |
| 4856 | | 4856 | |
| 4857 | const union_val = try pt.intern(.{ .un = .{ | 4857 | const union_val = try pt.internUnion(.{ |
| 4858 | .ty = union_ty.toIntern(), | 4858 | .ty = union_ty.toIntern(), |
| 4859 | .tag = tag_val.toIntern(), | 4859 | .tag = tag_val.toIntern(), |
| 4860 | .val = val.toIntern(), | 4860 | .val = val.toIntern(), |
| 4861 | } }); | 4861 | }); |
| 4862 | const union_init = Air.internedToRef(union_val); | 4862 | const union_init = Air.internedToRef(union_val); |
| 4863 | try sema.storePtr2(block, init_src, union_ptr, init_src, union_init, init_src, .store); | 4863 | try sema.storePtr2(block, init_src, union_ptr, init_src, union_init, init_src, .store); |
| 4864 | return; | 4864 | return; |
| ... | @@ -5703,27 +5703,7 @@ fn addStrLit(sema: *Sema, string: InternPool.String, len: u64) CompileError!Air. | ... | @@ -5703,27 +5703,7 @@ fn addStrLit(sema: *Sema, string: InternPool.String, len: u64) CompileError!Air. |
| 5703 | } | 5703 | } |
| 5704 | | 5704 | |
| 5705 | fn uavRef(sema: *Sema, val: InternPool.Index) CompileError!Air.Inst.Ref { | 5705 | fn uavRef(sema: *Sema, val: InternPool.Index) CompileError!Air.Inst.Ref { |
| 5706 | return Air.internedToRef(try sema.refValue(val)); | 5706 | return Air.internedToRef(try sema.pt.refValue(val)); |
| 5707 | } | | |
| 5708 | | | |
| 5709 | fn refValue(sema: *Sema, val: InternPool.Index) CompileError!InternPool.Index { | | |
| 5710 | const pt = sema.pt; | | |
| 5711 | const ptr_ty = (try pt.ptrTypeSema(.{ | | |
| 5712 | .child = pt.zcu.intern_pool.typeOf(val), | | |
| 5713 | .flags = .{ | | |
| 5714 | .alignment = .none, | | |
| 5715 | .is_const = true, | | |
| 5716 | .address_space = .generic, | | |
| 5717 | }, | | |
| 5718 | })).toIntern(); | | |
| 5719 | return pt.intern(.{ .ptr = .{ | | |
| 5720 | .ty = ptr_ty, | | |
| 5721 | .base_addr = .{ .uav = .{ | | |
| 5722 | .val = val, | | |
| 5723 | .orig_ty = ptr_ty, | | |
| 5724 | } }, | | |
| 5725 | .byte_offset = 0, | | |
| 5726 | } }); | | |
| 5727 | } | 5707 | } |
| 5728 | | 5708 | |
| 5729 | fn zirInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 5709 | fn zirInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | @@ -6965,7 +6945,7 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref | ... | @@ -6965,7 +6945,7 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref |
| 6965 | | 6945 | |
| 6966 | if (!block.ownerModule().error_tracing) return .none; | 6946 | if (!block.ownerModule().error_tracing) return .none; |
| 6967 | | 6947 | |
| 6968 | const stack_trace_ty = try pt.getBuiltinType("StackTrace"); | 6948 | const stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 6969 | try stack_trace_ty.resolveFields(pt); | 6949 | try stack_trace_ty.resolveFields(pt); |
| 6970 | const field_name = try zcu.intern_pool.getOrPutString(gpa, pt.tid, "index", .no_embedded_nulls); | 6950 | const field_name = try zcu.intern_pool.getOrPutString(gpa, pt.tid, "index", .no_embedded_nulls); |
| 6971 | const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, LazySrcLoc.unneeded) catch |err| switch (err) { | 6951 | const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, LazySrcLoc.unneeded) catch |err| switch (err) { |
| ... | @@ -7007,7 +6987,7 @@ fn popErrorReturnTrace( | ... | @@ -7007,7 +6987,7 @@ fn popErrorReturnTrace( |
| 7007 | // AstGen determined this result does not go to an error-handling expr (try/catch/return etc.), or | 6987 | // AstGen determined this result does not go to an error-handling expr (try/catch/return etc.), or |
| 7008 | // the result is comptime-known to be a non-error. Either way, pop unconditionally. | 6988 | // the result is comptime-known to be a non-error. Either way, pop unconditionally. |
| 7009 | | 6989 | |
| 7010 | const stack_trace_ty = try pt.getBuiltinType("StackTrace"); | 6990 | const stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 7011 | try stack_trace_ty.resolveFields(pt); | 6991 | try stack_trace_ty.resolveFields(pt); |
| 7012 | const ptr_stack_trace_ty = try pt.singleMutPtrType(stack_trace_ty); | 6992 | const ptr_stack_trace_ty = try pt.singleMutPtrType(stack_trace_ty); |
| 7013 | const err_return_trace = try block.addTy(.err_return_trace, ptr_stack_trace_ty); | 6993 | const err_return_trace = try block.addTy(.err_return_trace, ptr_stack_trace_ty); |
| ... | @@ -7033,7 +7013,7 @@ fn popErrorReturnTrace( | ... | @@ -7033,7 +7013,7 @@ fn popErrorReturnTrace( |
| 7033 | defer then_block.instructions.deinit(gpa); | 7013 | defer then_block.instructions.deinit(gpa); |
| 7034 | | 7014 | |
| 7035 | // If non-error, then pop the error return trace by restoring the index. | 7015 | // If non-error, then pop the error return trace by restoring the index. |
| 7036 | const stack_trace_ty = try pt.getBuiltinType("StackTrace"); | 7016 | const stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 7037 | try stack_trace_ty.resolveFields(pt); | 7017 | try stack_trace_ty.resolveFields(pt); |
| 7038 | const ptr_stack_trace_ty = try pt.singleMutPtrType(stack_trace_ty); | 7018 | const ptr_stack_trace_ty = try pt.singleMutPtrType(stack_trace_ty); |
| 7039 | const err_return_trace = try then_block.addTy(.err_return_trace, ptr_stack_trace_ty); | 7019 | const err_return_trace = try then_block.addTy(.err_return_trace, ptr_stack_trace_ty); |
| ... | @@ -7176,7 +7156,7 @@ fn zirCall( | ... | @@ -7176,7 +7156,7 @@ fn zirCall( |
| 7176 | // If any input is an error-type, we might need to pop any trace it generated. Otherwise, we only | 7156 | // If any input is an error-type, we might need to pop any trace it generated. Otherwise, we only |
| 7177 | // need to clean-up our own trace if we were passed to a non-error-handling expression. | 7157 | // need to clean-up our own trace if we were passed to a non-error-handling expression. |
| 7178 | if (input_is_error or (pop_error_return_trace and return_ty.isError(zcu))) { | 7158 | if (input_is_error or (pop_error_return_trace and return_ty.isError(zcu))) { |
| 7179 | const stack_trace_ty = try pt.getBuiltinType("StackTrace"); | 7159 | const stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 7180 | try stack_trace_ty.resolveFields(pt); | 7160 | try stack_trace_ty.resolveFields(pt); |
| 7181 | const field_name = try zcu.intern_pool.getOrPutString(sema.gpa, pt.tid, "index", .no_embedded_nulls); | 7161 | const field_name = try zcu.intern_pool.getOrPutString(sema.gpa, pt.tid, "index", .no_embedded_nulls); |
| 7182 | const field_index = try sema.structFieldIndex(block, stack_trace_ty, field_name, call_src); | 7162 | const field_index = try sema.structFieldIndex(block, stack_trace_ty, field_name, call_src); |
| ... | @@ -9327,7 +9307,7 @@ fn analyzeErrUnionPayload( | ... | @@ -9327,7 +9307,7 @@ fn analyzeErrUnionPayload( |
| 9327 | if (safety_check and block.wantSafety() and | 9307 | if (safety_check and block.wantSafety() and |
| 9328 | !err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) | 9308 | !err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) |
| 9329 | { | 9309 | { |
| 9330 | try sema.panicUnwrapError(block, src, operand, .unwrap_errunion_err, .is_non_err); | 9310 | try sema.addSafetyCheckUnwrapError(block, src, operand, .unwrap_errunion_err, .is_non_err); |
| 9331 | } | 9311 | } |
| 9332 | | 9312 | |
| 9333 | return block.addTyOp(.unwrap_errunion_payload, payload_ty, operand); | 9313 | return block.addTyOp(.unwrap_errunion_payload, payload_ty, operand); |
| ... | @@ -9411,7 +9391,7 @@ fn analyzeErrUnionPayloadPtr( | ... | @@ -9411,7 +9391,7 @@ fn analyzeErrUnionPayloadPtr( |
| 9411 | if (safety_check and block.wantSafety() and | 9391 | if (safety_check and block.wantSafety() and |
| 9412 | !err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) | 9392 | !err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) |
| 9413 | { | 9393 | { |
| 9414 | try sema.panicUnwrapError(block, src, operand, .unwrap_errunion_err_ptr, .is_non_err_ptr); | 9394 | try sema.addSafetyCheckUnwrapError(block, src, operand, .unwrap_errunion_err_ptr, .is_non_err_ptr); |
| 9415 | } | 9395 | } |
| 9416 | | 9396 | |
| 9417 | if (initializing) { | 9397 | if (initializing) { |
| ... | @@ -10231,7 +10211,7 @@ fn finishFunc( | ... | @@ -10231,7 +10211,7 @@ fn finishFunc( |
| 10231 | if (!final_is_generic and sema.wantErrorReturnTracing(return_type)) { | 10211 | if (!final_is_generic and sema.wantErrorReturnTracing(return_type)) { |
| 10232 | // Make sure that StackTrace's fields are resolved so that the backend can | 10212 | // Make sure that StackTrace's fields are resolved so that the backend can |
| 10233 | // lower this fn type. | 10213 | // lower this fn type. |
| 10234 | const unresolved_stack_trace_ty = try pt.getBuiltinType("StackTrace"); | 10214 | const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 10235 | try unresolved_stack_trace_ty.resolveFields(pt); | 10215 | try unresolved_stack_trace_ty.resolveFields(pt); |
| 10236 | } | 10216 | } |
| 10237 | | 10217 | |
| ... | @@ -14190,7 +14170,6 @@ fn maybeErrorUnwrap( | ... | @@ -14190,7 +14170,6 @@ fn maybeErrorUnwrap( |
| 14190 | ) !bool { | 14170 | ) !bool { |
| 14191 | const pt = sema.pt; | 14171 | const pt = sema.pt; |
| 14192 | const zcu = pt.zcu; | 14172 | const zcu = pt.zcu; |
| 14193 | if (!zcu.backendSupportsFeature(.panic_unwrap_error)) return false; | | |
| 14194 | | 14173 | |
| 14195 | const tags = sema.code.instructions.items(.tag); | 14174 | const tags = sema.code.instructions.items(.tag); |
| 14196 | for (body) |inst| { | 14175 | for (body) |inst| { |
| ... | @@ -14223,25 +14202,17 @@ fn maybeErrorUnwrap( | ... | @@ -14223,25 +14202,17 @@ fn maybeErrorUnwrap( |
| 14223 | .as_node => try sema.zirAsNode(block, inst), | 14202 | .as_node => try sema.zirAsNode(block, inst), |
| 14224 | .field_val => try sema.zirFieldVal(block, inst), | 14203 | .field_val => try sema.zirFieldVal(block, inst), |
| 14225 | .@"unreachable" => { | 14204 | .@"unreachable" => { |
| 14226 | if (!zcu.comp.formatted_panics) { | 14205 | try safetyPanicUnwrapError(sema, block, operand_src, operand); |
| 14227 | try sema.safetyPanic(block, operand_src, .unwrap_error); | | |
| 14228 | return true; | | |
| 14229 | } | | |
| 14230 | | | |
| 14231 | const panic_fn = try pt.getBuiltin("panicUnwrapError"); | | |
| 14232 | const err_return_trace = try sema.getErrorReturnTrace(block); | | |
| 14233 | const args: [2]Air.Inst.Ref = .{ err_return_trace, operand }; | | |
| 14234 | try sema.callBuiltin(block, operand_src, panic_fn, .auto, &args, .@"safety check"); | | |
| 14235 | return true; | 14206 | return true; |
| 14236 | }, | 14207 | }, |
| 14237 | .panic => { | 14208 | .panic => { |
| 14238 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 14209 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 14239 | const msg_inst = try sema.resolveInst(inst_data.operand); | 14210 | const msg_inst = try sema.resolveInst(inst_data.operand); |
| 14240 | | 14211 | |
| 14241 | const panic_fn = try pt.getBuiltin("panic"); | 14212 | const panic_fn = try getPanicInnerFn(sema, block, operand_src, "call"); |
| 14242 | const err_return_trace = try sema.getErrorReturnTrace(block); | 14213 | const err_return_trace = try sema.getErrorReturnTrace(block); |
| 14243 | const args: [3]Air.Inst.Ref = .{ msg_inst, err_return_trace, .null_value }; | 14214 | const args: [3]Air.Inst.Ref = .{ msg_inst, err_return_trace, .null_value }; |
| 14244 | try sema.callBuiltin(block, operand_src, panic_fn, .auto, &args, .@"safety check"); | 14215 | try sema.callBuiltin(block, operand_src, Air.internedToRef(panic_fn), .auto, &args, .@"safety check"); |
| 14245 | return true; | 14216 | return true; |
| 14246 | }, | 14217 | }, |
| 14247 | else => unreachable, | 14218 | else => unreachable, |
| ... | @@ -18275,7 +18246,7 @@ fn zirBuiltinSrc( | ... | @@ -18275,7 +18246,7 @@ fn zirBuiltinSrc( |
| 18275 | } }); | 18246 | } }); |
| 18276 | }; | 18247 | }; |
| 18277 | | 18248 | |
| 18278 | const src_loc_ty = try pt.getBuiltinType("SourceLocation"); | 18249 | const src_loc_ty = try sema.getBuiltinType("SourceLocation"); |
| 18279 | const fields = .{ | 18250 | const fields = .{ |
| 18280 | // module: [:0]const u8, | 18251 | // module: [:0]const u8, |
| 18281 | module_name_val, | 18252 | module_name_val, |
| ... | @@ -18302,7 +18273,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18302,7 +18273,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18302 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 18273 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 18303 | const src = block.nodeOffset(inst_data.src_node); | 18274 | const src = block.nodeOffset(inst_data.src_node); |
| 18304 | const ty = try sema.resolveType(block, src, inst_data.operand); | 18275 | const ty = try sema.resolveType(block, src, inst_data.operand); |
| 18305 | const type_info_ty = try pt.getBuiltinType("Type"); | 18276 | const type_info_ty = try sema.getBuiltinType("Type"); |
| 18306 | const type_info_tag_ty = type_info_ty.unionTagType(zcu).?; | 18277 | const type_info_tag_ty = type_info_ty.unionTagType(zcu).?; |
| 18307 | | 18278 | |
| 18308 | if (ty.typeDeclInst(zcu)) |type_decl_inst| { | 18279 | if (ty.typeDeclInst(zcu)) |type_decl_inst| { |
| ... | @@ -18319,29 +18290,11 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18319,29 +18290,11 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18319 | .undefined, | 18290 | .undefined, |
| 18320 | .null, | 18291 | .null, |
| 18321 | .enum_literal, | 18292 | .enum_literal, |
| 18322 | => |type_info_tag| return Air.internedToRef((try pt.intern(.{ .un = .{ | 18293 | => |type_info_tag| return unionInitFromEnumTag(sema, block, src, type_info_ty, @intFromEnum(type_info_tag), .void_value), |
| 18323 | .ty = type_info_ty.toIntern(), | | |
| 18324 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(type_info_tag))).toIntern(), | | |
| 18325 | .val = .void_value, | | |
| 18326 | } }))), | | |
| 18327 | .@"fn" => { | | |
| 18328 | const fn_info_nav = try sema.namespaceLookup( | | |
| 18329 | block, | | |
| 18330 | src, | | |
| 18331 | type_info_ty.getNamespaceIndex(zcu), | | |
| 18332 | try ip.getOrPutString(gpa, pt.tid, "Fn", .no_embedded_nulls), | | |
| 18333 | ) orelse @panic("std.builtin.Type is corrupt"); | | |
| 18334 | try sema.ensureNavResolved(src, fn_info_nav); | | |
| 18335 | const fn_info_ty = Type.fromInterned(ip.getNav(fn_info_nav).status.resolved.val); | | |
| 18336 | | 18294 | |
| 18337 | const param_info_nav = try sema.namespaceLookup( | 18295 | .@"fn" => { |
| 18338 | block, | 18296 | const fn_info_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "Fn"); |
| 18339 | src, | 18297 | const param_info_ty = try getBuiltinInnerType(sema, block, src, fn_info_ty, "Type.Fn", "Param"); |
| 18340 | fn_info_ty.getNamespaceIndex(zcu), | | |
| 18341 | try ip.getOrPutString(gpa, pt.tid, "Param", .no_embedded_nulls), | | |
| 18342 | ) orelse @panic("std.builtin.Type is corrupt"); | | |
| 18343 | try sema.ensureNavResolved(src, param_info_nav); | | |
| 18344 | const param_info_ty = Type.fromInterned(ip.getNav(param_info_nav).status.resolved.val); | | |
| 18345 | | 18298 | |
| 18346 | const func_ty_info = zcu.typeToFunc(ty).?; | 18299 | const func_ty_info = zcu.typeToFunc(ty).?; |
| 18347 | const param_vals = try sema.arena.alloc(InternPool.Index, func_ty_info.param_types.len); | 18300 | const param_vals = try sema.arena.alloc(InternPool.Index, func_ty_info.param_types.len); |
| ... | @@ -18411,7 +18364,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18411,7 +18364,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18411 | func_ty_info.return_type, | 18364 | func_ty_info.return_type, |
| 18412 | } }); | 18365 | } }); |
| 18413 | | 18366 | |
| 18414 | const callconv_ty = try pt.getBuiltinType("CallingConvention"); | 18367 | const callconv_ty = try sema.getBuiltinType("CallingConvention"); |
| 18415 | | 18368 | |
| 18416 | const field_values = .{ | 18369 | const field_values = .{ |
| 18417 | // calling_convention: CallingConvention, | 18370 | // calling_convention: CallingConvention, |
| ... | @@ -18425,26 +18378,18 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18425,26 +18378,18 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18425 | // args: []const Fn.Param, | 18378 | // args: []const Fn.Param, |
| 18426 | args_val, | 18379 | args_val, |
| 18427 | }; | 18380 | }; |
| 18428 | return Air.internedToRef((try pt.intern(.{ .un = .{ | 18381 | return Air.internedToRef((try pt.internUnion(.{ |
| 18429 | .ty = type_info_ty.toIntern(), | 18382 | .ty = type_info_ty.toIntern(), |
| 18430 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.@"fn"))).toIntern(), | 18383 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.@"fn"))).toIntern(), |
| 18431 | .val = try pt.intern(.{ .aggregate = .{ | 18384 | .val = try pt.intern(.{ .aggregate = .{ |
| 18432 | .ty = fn_info_ty.toIntern(), | 18385 | .ty = fn_info_ty.toIntern(), |
| 18433 | .storage = .{ .elems = &field_values }, | 18386 | .storage = .{ .elems = &field_values }, |
| 18434 | } }), | 18387 | } }), |
| 18435 | } }))); | 18388 | }))); |
| 18436 | }, | 18389 | }, |
| 18437 | .int => { | 18390 | .int => { |
| 18438 | const int_info_nav = try sema.namespaceLookup( | 18391 | const int_info_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "Int"); |
| 18439 | block, | 18392 | const signedness_ty = try sema.getBuiltinType("Signedness"); |
| 18440 | src, | | |
| 18441 | type_info_ty.getNamespaceIndex(zcu), | | |
| 18442 | try ip.getOrPutString(gpa, pt.tid, "Int", .no_embedded_nulls), | | |
| 18443 | ) orelse @panic("std.builtin.Type is corrupt"); | | |
| 18444 | try sema.ensureNavResolved(src, int_info_nav); | | |
| 18445 | const int_info_ty = Type.fromInterned(ip.getNav(int_info_nav).status.resolved.val); | | |
| 18446 | | | |
| 18447 | const signedness_ty = try pt.getBuiltinType("Signedness"); | | |
| 18448 | const info = ty.intInfo(zcu); | 18393 | const info = ty.intInfo(zcu); |
| 18449 | const field_values = .{ | 18394 | const field_values = .{ |
| 18450 | // signedness: Signedness, | 18395 | // signedness: Signedness, |
| ... | @@ -18452,37 +18397,30 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18452,37 +18397,30 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18452 | // bits: u16, | 18397 | // bits: u16, |
| 18453 | (try pt.intValue(Type.u16, info.bits)).toIntern(), | 18398 | (try pt.intValue(Type.u16, info.bits)).toIntern(), |
| 18454 | }; | 18399 | }; |
| 18455 | return Air.internedToRef((try pt.intern(.{ .un = .{ | 18400 | return Air.internedToRef((try pt.internUnion(.{ |
| 18456 | .ty = type_info_ty.toIntern(), | 18401 | .ty = type_info_ty.toIntern(), |
| 18457 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.int))).toIntern(), | 18402 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.int))).toIntern(), |
| 18458 | .val = try pt.intern(.{ .aggregate = .{ | 18403 | .val = try pt.intern(.{ .aggregate = .{ |
| 18459 | .ty = int_info_ty.toIntern(), | 18404 | .ty = int_info_ty.toIntern(), |
| 18460 | .storage = .{ .elems = &field_values }, | 18405 | .storage = .{ .elems = &field_values }, |
| 18461 | } }), | 18406 | } }), |
| 18462 | } }))); | 18407 | }))); |
| 18463 | }, | 18408 | }, |
| 18464 | .float => { | 18409 | .float => { |
| 18465 | const float_info_nav = try sema.namespaceLookup( | 18410 | const float_info_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "Float"); |
| 18466 | block, | | |
| 18467 | src, | | |
| 18468 | type_info_ty.getNamespaceIndex(zcu), | | |
| 18469 | try ip.getOrPutString(gpa, pt.tid, "Float", .no_embedded_nulls), | | |
| 18470 | ) orelse @panic("std.builtin.Type is corrupt"); | | |
| 18471 | try sema.ensureNavResolved(src, float_info_nav); | | |
| 18472 | const float_info_ty = Type.fromInterned(ip.getNav(float_info_nav).status.resolved.val); | | |
| 18473 | | 18411 | |
| 18474 | const field_vals = .{ | 18412 | const field_vals = .{ |
| 18475 | // bits: u16, | 18413 | // bits: u16, |
| 18476 | (try pt.intValue(Type.u16, ty.bitSize(zcu))).toIntern(), | 18414 | (try pt.intValue(Type.u16, ty.bitSize(zcu))).toIntern(), |
| 18477 | }; | 18415 | }; |
| 18478 | return Air.internedToRef((try pt.intern(.{ .un = .{ | 18416 | return Air.internedToRef((try pt.internUnion(.{ |
| 18479 | .ty = type_info_ty.toIntern(), | 18417 | .ty = type_info_ty.toIntern(), |
| 18480 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.float))).toIntern(), | 18418 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.float))).toIntern(), |
| 18481 | .val = try pt.intern(.{ .aggregate = .{ | 18419 | .val = try pt.intern(.{ .aggregate = .{ |
| 18482 | .ty = float_info_ty.toIntern(), | 18420 | .ty = float_info_ty.toIntern(), |
| 18483 | .storage = .{ .elems = &field_vals }, | 18421 | .storage = .{ .elems = &field_vals }, |
| 18484 | } }), | 18422 | } }), |
| 18485 | } }))); | 18423 | }))); |
| 18486 | }, | 18424 | }, |
| 18487 | .pointer => { | 18425 | .pointer => { |
| 18488 | const info = ty.ptrInfo(zcu); | 18426 | const info = ty.ptrInfo(zcu); |
| ... | @@ -18491,27 +18429,9 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18491,27 +18429,9 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18491 | else | 18429 | else |
| 18492 | try Type.fromInterned(info.child).lazyAbiAlignment(pt); | 18430 | try Type.fromInterned(info.child).lazyAbiAlignment(pt); |
| 18493 | | 18431 | |
| 18494 | const addrspace_ty = try pt.getBuiltinType("AddressSpace"); | 18432 | const addrspace_ty = try sema.getBuiltinType("AddressSpace"); |
| 18495 | const pointer_ty = t: { | 18433 | const pointer_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "Pointer"); |
| 18496 | const nav = try sema.namespaceLookup( | 18434 | const ptr_size_ty = try getBuiltinInnerType(sema, block, src, pointer_ty, "Type.Pointer", "Size"); |
| 18497 | block, | | |
| 18498 | src, | | |
| 18499 | (try pt.getBuiltinType("Type")).getNamespaceIndex(zcu), | | |
| 18500 | try ip.getOrPutString(gpa, pt.tid, "Pointer", .no_embedded_nulls), | | |
| 18501 | ) orelse @panic("std.builtin.Type is corrupt"); | | |
| 18502 | try sema.ensureNavResolved(src, nav); | | |
| 18503 | break :t Type.fromInterned(ip.getNav(nav).status.resolved.val); | | |
| 18504 | }; | | |
| 18505 | const ptr_size_ty = t: { | | |
| 18506 | const nav = try sema.namespaceLookup( | | |
| 18507 | block, | | |
| 18508 | src, | | |
| 18509 | pointer_ty.getNamespaceIndex(zcu), | | |
| 18510 | try ip.getOrPutString(gpa, pt.tid, "Size", .no_embedded_nulls), | | |
| 18511 | ) orelse @panic("std.builtin.Type is corrupt"); | | |
| 18512 | try sema.ensureNavResolved(src, nav); | | |
| 18513 | break :t Type.fromInterned(ip.getNav(nav).status.resolved.val); | | |
| 18514 | }; | | |
| 18515 | | 18435 | |
| 18516 | const field_values = .{ | 18436 | const field_values = .{ |
| 18517 | // size: Size, | 18437 | // size: Size, |
| ... | @@ -18534,26 +18454,17 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18534,26 +18454,17 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18534 | else => Value.fromInterned(info.sentinel), | 18454 | else => Value.fromInterned(info.sentinel), |
| 18535 | })).toIntern(), | 18455 | })).toIntern(), |
| 18536 | }; | 18456 | }; |
| 18537 | return Air.internedToRef((try pt.intern(.{ .un = .{ | 18457 | return Air.internedToRef((try pt.internUnion(.{ |
| 18538 | .ty = type_info_ty.toIntern(), | 18458 | .ty = type_info_ty.toIntern(), |
| 18539 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.pointer))).toIntern(), | 18459 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.pointer))).toIntern(), |
| 18540 | .val = try pt.intern(.{ .aggregate = .{ | 18460 | .val = try pt.intern(.{ .aggregate = .{ |
| 18541 | .ty = pointer_ty.toIntern(), | 18461 | .ty = pointer_ty.toIntern(), |
| 18542 | .storage = .{ .elems = &field_values }, | 18462 | .storage = .{ .elems = &field_values }, |
| 18543 | } }), | 18463 | } }), |
| 18544 | } }))); | 18464 | }))); |
| 18545 | }, | 18465 | }, |
| 18546 | .array => { | 18466 | .array => { |
| 18547 | const array_field_ty = t: { | 18467 | const array_field_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "Array"); |
| 18548 | const nav = try sema.namespaceLookup( | | |
| 18549 | block, | | |
| 18550 | src, | | |
| 18551 | type_info_ty.getNamespaceIndex(zcu), | | |
| 18552 | try ip.getOrPutString(gpa, pt.tid, "Array", .no_embedded_nulls), | | |
| 18553 | ) orelse @panic("std.builtin.Type is corrupt"); | | |
| 18554 | try sema.ensureNavResolved(src, nav); | | |
| 18555 | break :t Type.fromInterned(ip.getNav(nav).status.resolved.val); | | |
| 18556 | }; | | |
| 18557 | | 18468 | |
| 18558 | const info = ty.arrayInfo(zcu); | 18469 | const info = ty.arrayInfo(zcu); |
| 18559 | const field_values = .{ | 18470 | const field_values = .{ |
| ... | @@ -18564,26 +18475,17 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18564,26 +18475,17 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18564 | // sentinel: ?*const anyopaque, | 18475 | // sentinel: ?*const anyopaque, |
| 18565 | (try sema.optRefValue(info.sentinel)).toIntern(), | 18476 | (try sema.optRefValue(info.sentinel)).toIntern(), |
| 18566 | }; | 18477 | }; |
| 18567 | return Air.internedToRef((try pt.intern(.{ .un = .{ | 18478 | return Air.internedToRef((try pt.internUnion(.{ |
| 18568 | .ty = type_info_ty.toIntern(), | 18479 | .ty = type_info_ty.toIntern(), |
| 18569 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.array))).toIntern(), | 18480 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.array))).toIntern(), |
| 18570 | .val = try pt.intern(.{ .aggregate = .{ | 18481 | .val = try pt.intern(.{ .aggregate = .{ |
| 18571 | .ty = array_field_ty.toIntern(), | 18482 | .ty = array_field_ty.toIntern(), |
| 18572 | .storage = .{ .elems = &field_values }, | 18483 | .storage = .{ .elems = &field_values }, |
| 18573 | } }), | 18484 | } }), |
| 18574 | } }))); | 18485 | }))); |
| 18575 | }, | 18486 | }, |
| 18576 | .vector => { | 18487 | .vector => { |
| 18577 | const vector_field_ty = t: { | 18488 | const vector_field_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "Vector"); |
| 18578 | const nav = try sema.namespaceLookup( | | |
| 18579 | block, | | |
| 18580 | src, | | |
| 18581 | type_info_ty.getNamespaceIndex(zcu), | | |
| 18582 | try ip.getOrPutString(gpa, pt.tid, "Vector", .no_embedded_nulls), | | |
| 18583 | ) orelse @panic("std.builtin.Type is corrupt"); | | |
| 18584 | try sema.ensureNavResolved(src, nav); | | |
| 18585 | break :t Type.fromInterned(ip.getNav(nav).status.resolved.val); | | |
| 18586 | }; | | |
| 18587 | | 18489 | |
| 18588 | const info = ty.arrayInfo(zcu); | 18490 | const info = ty.arrayInfo(zcu); |
| 18589 | const field_values = .{ | 18491 | const field_values = .{ |
| ... | @@ -18592,52 +18494,34 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18592,52 +18494,34 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18592 | // child: type, | 18494 | // child: type, |
| 18593 | info.elem_type.toIntern(), | 18495 | info.elem_type.toIntern(), |
| 18594 | }; | 18496 | }; |
| 18595 | return Air.internedToRef((try pt.intern(.{ .un = .{ | 18497 | return Air.internedToRef((try pt.internUnion(.{ |
| 18596 | .ty = type_info_ty.toIntern(), | 18498 | .ty = type_info_ty.toIntern(), |
| 18597 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.vector))).toIntern(), | 18499 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.vector))).toIntern(), |
| 18598 | .val = try pt.intern(.{ .aggregate = .{ | 18500 | .val = try pt.intern(.{ .aggregate = .{ |
| 18599 | .ty = vector_field_ty.toIntern(), | 18501 | .ty = vector_field_ty.toIntern(), |
| 18600 | .storage = .{ .elems = &field_values }, | 18502 | .storage = .{ .elems = &field_values }, |
| 18601 | } }), | 18503 | } }), |
| 18602 | } }))); | 18504 | }))); |
| 18603 | }, | 18505 | }, |
| 18604 | .optional => { | 18506 | .optional => { |
| 18605 | const optional_field_ty = t: { | 18507 | const optional_field_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "Optional"); |
| 18606 | const nav = try sema.namespaceLookup( | | |
| 18607 | block, | | |
| 18608 | src, | | |
| 18609 | type_info_ty.getNamespaceIndex(zcu), | | |
| 18610 | try ip.getOrPutString(gpa, pt.tid, "Optional", .no_embedded_nulls), | | |
| 18611 | ) orelse @panic("std.builtin.Type is corrupt"); | | |
| 18612 | try sema.ensureNavResolved(src, nav); | | |
| 18613 | break :t Type.fromInterned(ip.getNav(nav).status.resolved.val); | | |
| 18614 | }; | | |
| 18615 | | 18508 | |
| 18616 | const field_values = .{ | 18509 | const field_values = .{ |
| 18617 | // child: type, | 18510 | // child: type, |
| 18618 | ty.optionalChild(zcu).toIntern(), | 18511 | ty.optionalChild(zcu).toIntern(), |
| 18619 | }; | 18512 | }; |
| 18620 | return Air.internedToRef((try pt.intern(.{ .un = .{ | 18513 | return Air.internedToRef((try pt.internUnion(.{ |
| 18621 | .ty = type_info_ty.toIntern(), | 18514 | .ty = type_info_ty.toIntern(), |
| 18622 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.optional))).toIntern(), | 18515 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.optional))).toIntern(), |
| 18623 | .val = try pt.intern(.{ .aggregate = .{ | 18516 | .val = try pt.intern(.{ .aggregate = .{ |
| 18624 | .ty = optional_field_ty.toIntern(), | 18517 | .ty = optional_field_ty.toIntern(), |
| 18625 | .storage = .{ .elems = &field_values }, | 18518 | .storage = .{ .elems = &field_values }, |
| 18626 | } }), | 18519 | } }), |
| 18627 | } }))); | 18520 | }))); |
| 18628 | }, | 18521 | }, |
| 18629 | .error_set => { | 18522 | .error_set => { |
| 18630 | // Get the Error type | 18523 | // Get the Error type |
| 18631 | const error_field_ty = t: { | 18524 | const error_field_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "Error"); |
| 18632 | const nav = try sema.namespaceLookup( | | |
| 18633 | block, | | |
| 18634 | src, | | |
| 18635 | type_info_ty.getNamespaceIndex(zcu), | | |
| 18636 | try ip.getOrPutString(gpa, pt.tid, "Error", .no_embedded_nulls), | | |
| 18637 | ) orelse @panic("std.builtin.Type is corrupt"); | | |
| 18638 | try sema.ensureNavResolved(src, nav); | | |
| 18639 | break :t Type.fromInterned(ip.getNav(nav).status.resolved.val); | | |
| 18640 | }; | | |
| 18641 | | 18525 | |
| 18642 | // Build our list of Error values | 18526 | // Build our list of Error values |
| 18643 | // Optional value is only null if anyerror | 18527 | // Optional value is only null if anyerror |
| ... | @@ -18726,23 +18610,14 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18726,23 +18610,14 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18726 | } }); | 18610 | } }); |
| 18727 | | 18611 | |
| 18728 | // Construct Type{ .error_set = errors_val } | 18612 | // Construct Type{ .error_set = errors_val } |
| 18729 | return Air.internedToRef((try pt.intern(.{ .un = .{ | 18613 | return Air.internedToRef((try pt.internUnion(.{ |
| 18730 | .ty = type_info_ty.toIntern(), | 18614 | .ty = type_info_ty.toIntern(), |
| 18731 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.error_set))).toIntern(), | 18615 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.error_set))).toIntern(), |
| 18732 | .val = errors_val, | 18616 | .val = errors_val, |
| 18733 | } }))); | 18617 | }))); |
| 18734 | }, | 18618 | }, |
| 18735 | .error_union => { | 18619 | .error_union => { |
| 18736 | const error_union_field_ty = t: { | 18620 | const error_union_field_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "ErrorUnion"); |
| 18737 | const nav = try sema.namespaceLookup( | | |
| 18738 | block, | | |
| 18739 | src, | | |
| 18740 | type_info_ty.getNamespaceIndex(zcu), | | |
| 18741 | try ip.getOrPutString(gpa, pt.tid, "ErrorUnion", .no_embedded_nulls), | | |
| 18742 | ) orelse @panic("std.builtin.Type is corrupt"); | | |
| 18743 | try sema.ensureNavResolved(src, nav); | | |
| 18744 | break :t Type.fromInterned(ip.getNav(nav).status.resolved.val); | | |
| 18745 | }; | | |
| 18746 | | 18621 | |
| 18747 | const field_values = .{ | 18622 | const field_values = .{ |
| 18748 | // error_set: type, | 18623 | // error_set: type, |
| ... | @@ -18750,28 +18625,19 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18750,28 +18625,19 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18750 | // payload: type, | 18625 | // payload: type, |
| 18751 | ty.errorUnionPayload(zcu).toIntern(), | 18626 | ty.errorUnionPayload(zcu).toIntern(), |
| 18752 | }; | 18627 | }; |
| 18753 | return Air.internedToRef((try pt.intern(.{ .un = .{ | 18628 | return Air.internedToRef((try pt.internUnion(.{ |
| 18754 | .ty = type_info_ty.toIntern(), | 18629 | .ty = type_info_ty.toIntern(), |
| 18755 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.error_union))).toIntern(), | 18630 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.error_union))).toIntern(), |
| 18756 | .val = try pt.intern(.{ .aggregate = .{ | 18631 | .val = try pt.intern(.{ .aggregate = .{ |
| 18757 | .ty = error_union_field_ty.toIntern(), | 18632 | .ty = error_union_field_ty.toIntern(), |
| 18758 | .storage = .{ .elems = &field_values }, | 18633 | .storage = .{ .elems = &field_values }, |
| 18759 | } }), | 18634 | } }), |
| 18760 | } }))); | 18635 | }))); |
| 18761 | }, | 18636 | }, |
| 18762 | .@"enum" => { | 18637 | .@"enum" => { |
| 18763 | const is_exhaustive = Value.makeBool(ip.loadEnumType(ty.toIntern()).tag_mode != .nonexhaustive); | 18638 | const is_exhaustive = Value.makeBool(ip.loadEnumType(ty.toIntern()).tag_mode != .nonexhaustive); |
| 18764 | | 18639 | |
| 18765 | const enum_field_ty = t: { | 18640 | const enum_field_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "EnumField"); |
| 18766 | const nav = try sema.namespaceLookup( | | |
| 18767 | block, | | |
| 18768 | src, | | |
| 18769 | type_info_ty.getNamespaceIndex(zcu), | | |
| 18770 | try ip.getOrPutString(gpa, pt.tid, "EnumField", .no_embedded_nulls), | | |
| 18771 | ) orelse @panic("std.builtin.Type is corrupt"); | | |
| 18772 | try sema.ensureNavResolved(src, nav); | | |
| 18773 | break :t Type.fromInterned(ip.getNav(nav).status.resolved.val); | | |
| 18774 | }; | | |
| 18775 | | 18641 | |
| 18776 | const enum_field_vals = try sema.arena.alloc(InternPool.Index, ip.loadEnumType(ty.toIntern()).names.len); | 18642 | const enum_field_vals = try sema.arena.alloc(InternPool.Index, ip.loadEnumType(ty.toIntern()).names.len); |
| 18777 | for (enum_field_vals, 0..) |*field_val, tag_index| { | 18643 | for (enum_field_vals, 0..) |*field_val, tag_index| { |
| ... | @@ -18858,16 +18724,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18858,16 +18724,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18858 | | 18724 | |
| 18859 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ip.loadEnumType(ty.toIntern()).namespace.toOptional()); | 18725 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ip.loadEnumType(ty.toIntern()).namespace.toOptional()); |
| 18860 | | 18726 | |
| 18861 | const type_enum_ty = t: { | 18727 | const type_enum_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "Enum"); |
| 18862 | const nav = try sema.namespaceLookup( | | |
| 18863 | block, | | |
| 18864 | src, | | |
| 18865 | type_info_ty.getNamespaceIndex(zcu), | | |
| 18866 | try ip.getOrPutString(gpa, pt.tid, "Enum", .no_embedded_nulls), | | |
| 18867 | ) orelse @panic("std.builtin.Type is corrupt"); | | |
| 18868 | try sema.ensureNavResolved(src, nav); | | |
| 18869 | break :t Type.fromInterned(ip.getNav(nav).status.resolved.val); | | |
| 18870 | }; | | |
| 18871 | | 18728 | |
| 18872 | const field_values = .{ | 18729 | const field_values = .{ |
| 18873 | // tag_type: type, | 18730 | // tag_type: type, |
| ... | @@ -18879,37 +18736,18 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18879,37 +18736,18 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18879 | // is_exhaustive: bool, | 18736 | // is_exhaustive: bool, |
| 18880 | is_exhaustive.toIntern(), | 18737 | is_exhaustive.toIntern(), |
| 18881 | }; | 18738 | }; |
| 18882 | return Air.internedToRef((try pt.intern(.{ .un = .{ | 18739 | return Air.internedToRef((try pt.internUnion(.{ |
| 18883 | .ty = type_info_ty.toIntern(), | 18740 | .ty = type_info_ty.toIntern(), |
| 18884 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.@"enum"))).toIntern(), | 18741 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.@"enum"))).toIntern(), |
| 18885 | .val = try pt.intern(.{ .aggregate = .{ | 18742 | .val = try pt.intern(.{ .aggregate = .{ |
| 18886 | .ty = type_enum_ty.toIntern(), | 18743 | .ty = type_enum_ty.toIntern(), |
| 18887 | .storage = .{ .elems = &field_values }, | 18744 | .storage = .{ .elems = &field_values }, |
| 18888 | } }), | 18745 | } }), |
| 18889 | } }))); | 18746 | }))); |
| 18890 | }, | 18747 | }, |
| 18891 | .@"union" => { | 18748 | .@"union" => { |
| 18892 | const type_union_ty = t: { | 18749 | const type_union_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "Union"); |
| 18893 | const nav = try sema.namespaceLookup( | 18750 | const union_field_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "UnionField"); |
| 18894 | block, | | |
| 18895 | src, | | |
| 18896 | type_info_ty.getNamespaceIndex(zcu), | | |
| 18897 | try ip.getOrPutString(gpa, pt.tid, "Union", .no_embedded_nulls), | | |
| 18898 | ) orelse @panic("std.builtin.Type is corrupt"); | | |
| 18899 | try sema.ensureNavResolved(src, nav); | | |
| 18900 | break :t Type.fromInterned(ip.getNav(nav).status.resolved.val); | | |
| 18901 | }; | | |
| 18902 | | | |
| 18903 | const union_field_ty = t: { | | |
| 18904 | const nav = try sema.namespaceLookup( | | |
| 18905 | block, | | |
| 18906 | src, | | |
| 18907 | type_info_ty.getNamespaceIndex(zcu), | | |
| 18908 | try ip.getOrPutString(gpa, pt.tid, "UnionField", .no_embedded_nulls), | | |
| 18909 | ) orelse @panic("std.builtin.Type is corrupt"); | | |
| 18910 | try sema.ensureNavResolved(src, nav); | | |
| 18911 | break :t Type.fromInterned(ip.getNav(nav).status.resolved.val); | | |
| 18912 | }; | | |
| 18913 | | 18751 | |
| 18914 | try ty.resolveLayout(pt); // Getting alignment requires type layout | 18752 | try ty.resolveLayout(pt); // Getting alignment requires type layout |
| 18915 | const union_obj = zcu.typeToUnion(ty).?; | 18753 | const union_obj = zcu.typeToUnion(ty).?; |
| ... | @@ -19004,16 +18842,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -19004,16 +18842,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 19004 | .val = if (ty.unionTagType(zcu)) |tag_ty| tag_ty.toIntern() else .none, | 18842 | .val = if (ty.unionTagType(zcu)) |tag_ty| tag_ty.toIntern() else .none, |
| 19005 | } }); | 18843 | } }); |
| 19006 | | 18844 | |
| 19007 | const container_layout_ty = t: { | 18845 | const container_layout_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "ContainerLayout"); |
| 19008 | const nav = try sema.namespaceLookup( | | |
| 19009 | block, | | |
| 19010 | src, | | |
| 19011 | (try pt.getBuiltinType("Type")).getNamespaceIndex(zcu), | | |
| 19012 | try ip.getOrPutString(gpa, pt.tid, "ContainerLayout", .no_embedded_nulls), | | |
| 19013 | ) orelse @panic("std.builtin.Type is corrupt"); | | |
| 19014 | try sema.ensureNavResolved(src, nav); | | |
| 19015 | break :t Type.fromInterned(ip.getNav(nav).status.resolved.val); | | |
| 19016 | }; | | |
| 19017 | | 18846 | |
| 19018 | const field_values = .{ | 18847 | const field_values = .{ |
| 19019 | // layout: ContainerLayout, | 18848 | // layout: ContainerLayout, |
| ... | @@ -19026,37 +18855,18 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -19026,37 +18855,18 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 19026 | // decls: []const Declaration, | 18855 | // decls: []const Declaration, |
| 19027 | decls_val, | 18856 | decls_val, |
| 19028 | }; | 18857 | }; |
| 19029 | return Air.internedToRef((try pt.intern(.{ .un = .{ | 18858 | return Air.internedToRef((try pt.internUnion(.{ |
| 19030 | .ty = type_info_ty.toIntern(), | 18859 | .ty = type_info_ty.toIntern(), |
| 19031 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.@"union"))).toIntern(), | 18860 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.@"union"))).toIntern(), |
| 19032 | .val = try pt.intern(.{ .aggregate = .{ | 18861 | .val = try pt.intern(.{ .aggregate = .{ |
| 19033 | .ty = type_union_ty.toIntern(), | 18862 | .ty = type_union_ty.toIntern(), |
| 19034 | .storage = .{ .elems = &field_values }, | 18863 | .storage = .{ .elems = &field_values }, |
| 19035 | } }), | 18864 | } }), |
| 19036 | } }))); | 18865 | }))); |
| 19037 | }, | 18866 | }, |
| 19038 | .@"struct" => { | 18867 | .@"struct" => { |
| 19039 | const type_struct_ty = t: { | 18868 | const type_struct_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "Struct"); |
| 19040 | const nav = try sema.namespaceLookup( | 18869 | const struct_field_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "StructField"); |
| 19041 | block, | | |
| 19042 | src, | | |
| 19043 | type_info_ty.getNamespaceIndex(zcu), | | |
| 19044 | try ip.getOrPutString(gpa, pt.tid, "Struct", .no_embedded_nulls), | | |
| 19045 | ) orelse @panic("std.builtin.Type is corrupt"); | | |
| 19046 | try sema.ensureNavResolved(src, nav); | | |
| 19047 | break :t Type.fromInterned(ip.getNav(nav).status.resolved.val); | | |
| 19048 | }; | | |
| 19049 | | | |
| 19050 | const struct_field_ty = t: { | | |
| 19051 | const nav = try sema.namespaceLookup( | | |
| 19052 | block, | | |
| 19053 | src, | | |
| 19054 | type_info_ty.getNamespaceIndex(zcu), | | |
| 19055 | try ip.getOrPutString(gpa, pt.tid, "StructField", .no_embedded_nulls), | | |
| 19056 | ) orelse @panic("std.builtin.Type is corrupt"); | | |
| 19057 | try sema.ensureNavResolved(src, nav); | | |
| 19058 | break :t Type.fromInterned(ip.getNav(nav).status.resolved.val); | | |
| 19059 | }; | | |
| 19060 | | 18870 | |
| 19061 | try ty.resolveLayout(pt); // Getting alignment requires type layout | 18871 | try ty.resolveLayout(pt); // Getting alignment requires type layout |
| 19062 | | 18872 | |
| ... | @@ -19233,16 +19043,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -19233,16 +19043,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 19233 | } else .none, | 19043 | } else .none, |
| 19234 | } }); | 19044 | } }); |
| 19235 | | 19045 | |
| 19236 | const container_layout_ty = t: { | 19046 | const container_layout_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "ContainerLayout"); |
| 19237 | const nav = try sema.namespaceLookup( | | |
| 19238 | block, | | |
| 19239 | src, | | |
| 19240 | (try pt.getBuiltinType("Type")).getNamespaceIndex(zcu), | | |
| 19241 | try ip.getOrPutString(gpa, pt.tid, "ContainerLayout", .no_embedded_nulls), | | |
| 19242 | ) orelse @panic("std.builtin.Type is corrupt"); | | |
| 19243 | try sema.ensureNavResolved(src, nav); | | |
| 19244 | break :t Type.fromInterned(ip.getNav(nav).status.resolved.val); | | |
| 19245 | }; | | |
| 19246 | | 19047 | |
| 19247 | const layout = ty.containerLayout(zcu); | 19048 | const layout = ty.containerLayout(zcu); |
| 19248 | | 19049 | |
| ... | @@ -19258,26 +19059,17 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -19258,26 +19059,17 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 19258 | // is_tuple: bool, | 19059 | // is_tuple: bool, |
| 19259 | Value.makeBool(ty.isTuple(zcu)).toIntern(), | 19060 | Value.makeBool(ty.isTuple(zcu)).toIntern(), |
| 19260 | }; | 19061 | }; |
| 19261 | return Air.internedToRef((try pt.intern(.{ .un = .{ | 19062 | return Air.internedToRef((try pt.internUnion(.{ |
| 19262 | .ty = type_info_ty.toIntern(), | 19063 | .ty = type_info_ty.toIntern(), |
| 19263 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.@"struct"))).toIntern(), | 19064 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.@"struct"))).toIntern(), |
| 19264 | .val = try pt.intern(.{ .aggregate = .{ | 19065 | .val = try pt.intern(.{ .aggregate = .{ |
| 19265 | .ty = type_struct_ty.toIntern(), | 19066 | .ty = type_struct_ty.toIntern(), |
| 19266 | .storage = .{ .elems = &field_values }, | 19067 | .storage = .{ .elems = &field_values }, |
| 19267 | } }), | 19068 | } }), |
| 19268 | } }))); | 19069 | }))); |
| 19269 | }, | 19070 | }, |
| 19270 | .@"opaque" => { | 19071 | .@"opaque" => { |
| 19271 | const type_opaque_ty = t: { | 19072 | const type_opaque_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "Opaque"); |
| 19272 | const nav = try sema.namespaceLookup( | | |
| 19273 | block, | | |
| 19274 | src, | | |
| 19275 | type_info_ty.getNamespaceIndex(zcu), | | |
| 19276 | try ip.getOrPutString(gpa, pt.tid, "Opaque", .no_embedded_nulls), | | |
| 19277 | ) orelse @panic("std.builtin.Type is corrupt"); | | |
| 19278 | try sema.ensureNavResolved(src, nav); | | |
| 19279 | break :t Type.fromInterned(ip.getNav(nav).status.resolved.val); | | |
| 19280 | }; | | |
| 19281 | | 19073 | |
| 19282 | try ty.resolveFields(pt); | 19074 | try ty.resolveFields(pt); |
| 19283 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespace(zcu)); | 19075 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespace(zcu)); |
| ... | @@ -19286,14 +19078,14 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -19286,14 +19078,14 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 19286 | // decls: []const Declaration, | 19078 | // decls: []const Declaration, |
| 19287 | decls_val, | 19079 | decls_val, |
| 19288 | }; | 19080 | }; |
| 19289 | return Air.internedToRef((try pt.intern(.{ .un = .{ | 19081 | return Air.internedToRef((try pt.internUnion(.{ |
| 19290 | .ty = type_info_ty.toIntern(), | 19082 | .ty = type_info_ty.toIntern(), |
| 19291 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.@"opaque"))).toIntern(), | 19083 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.@"opaque"))).toIntern(), |
| 19292 | .val = try pt.intern(.{ .aggregate = .{ | 19084 | .val = try pt.intern(.{ .aggregate = .{ |
| 19293 | .ty = type_opaque_ty.toIntern(), | 19085 | .ty = type_opaque_ty.toIntern(), |
| 19294 | .storage = .{ .elems = &field_values }, | 19086 | .storage = .{ .elems = &field_values }, |
| 19295 | } }), | 19087 | } }), |
| 19296 | } }))); | 19088 | }))); |
| 19297 | }, | 19089 | }, |
| 19298 | .frame => return sema.failWithUseOfAsync(block, src), | 19090 | .frame => return sema.failWithUseOfAsync(block, src), |
| 19299 | .@"anyframe" => return sema.failWithUseOfAsync(block, src), | 19091 | .@"anyframe" => return sema.failWithUseOfAsync(block, src), |
| ... | @@ -19309,19 +19101,9 @@ fn typeInfoDecls( | ... | @@ -19309,19 +19101,9 @@ fn typeInfoDecls( |
| 19309 | ) CompileError!InternPool.Index { | 19101 | ) CompileError!InternPool.Index { |
| 19310 | const pt = sema.pt; | 19102 | const pt = sema.pt; |
| 19311 | const zcu = pt.zcu; | 19103 | const zcu = pt.zcu; |
| 19312 | const ip = &zcu.intern_pool; | | |
| 19313 | const gpa = sema.gpa; | 19104 | const gpa = sema.gpa; |
| 19314 | | 19105 | |
| 19315 | const declaration_ty = t: { | 19106 | const declaration_ty = try getBuiltinInnerType(sema, block, src, type_info_ty, "Type", "Declaration"); |
| 19316 | const nav = try sema.namespaceLookup( | | |
| 19317 | block, | | |
| 19318 | src, | | |
| 19319 | type_info_ty.getNamespaceIndex(zcu), | | |
| 19320 | try ip.getOrPutString(gpa, pt.tid, "Declaration", .no_embedded_nulls), | | |
| 19321 | ) orelse @panic("std.builtin.Type is corrupt"); | | |
| 19322 | try sema.ensureNavResolved(src, nav); | | |
| 19323 | break :t Type.fromInterned(ip.getNav(nav).status.resolved.val); | | |
| 19324 | }; | | |
| 19325 | | 19107 | |
| 19326 | var decl_vals = std.ArrayList(InternPool.Index).init(gpa); | 19108 | var decl_vals = std.ArrayList(InternPool.Index).init(gpa); |
| 19327 | defer decl_vals.deinit(); | 19109 | defer decl_vals.deinit(); |
| ... | @@ -20265,11 +20047,11 @@ fn retWithErrTracing( | ... | @@ -20265,11 +20047,11 @@ fn retWithErrTracing( |
| 20265 | else => true, | 20047 | else => true, |
| 20266 | }; | 20048 | }; |
| 20267 | const gpa = sema.gpa; | 20049 | const gpa = sema.gpa; |
| 20268 | const stack_trace_ty = try pt.getBuiltinType("StackTrace"); | 20050 | const stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 20269 | try stack_trace_ty.resolveFields(pt); | 20051 | try stack_trace_ty.resolveFields(pt); |
| 20270 | const ptr_stack_trace_ty = try pt.singleMutPtrType(stack_trace_ty); | 20052 | const ptr_stack_trace_ty = try pt.singleMutPtrType(stack_trace_ty); |
| 20271 | const err_return_trace = try block.addTy(.err_return_trace, ptr_stack_trace_ty); | 20053 | const err_return_trace = try block.addTy(.err_return_trace, ptr_stack_trace_ty); |
| 20272 | const return_err_fn = try pt.getBuiltin("returnError"); | 20054 | const return_err_fn = try sema.getBuiltin("returnError"); |
| 20273 | const args: [1]Air.Inst.Ref = .{err_return_trace}; | 20055 | const args: [1]Air.Inst.Ref = .{err_return_trace}; |
| 20274 | | 20056 | |
| 20275 | if (!need_check) { | 20057 | if (!need_check) { |
| ... | @@ -20805,19 +20587,32 @@ fn unionInit( | ... | @@ -20805,19 +20587,32 @@ fn unionInit( |
| 20805 | const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_src); | 20587 | const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_src); |
| 20806 | const field_ty = Type.fromInterned(zcu.typeToUnion(union_ty).?.field_types.get(ip)[field_index]); | 20588 | const field_ty = Type.fromInterned(zcu.typeToUnion(union_ty).?.field_types.get(ip)[field_index]); |
| 20807 | const init = try sema.coerce(block, field_ty, uncasted_init, init_src); | 20589 | const init = try sema.coerce(block, field_ty, uncasted_init, init_src); |
| | 20590 | _ = union_ty_src; |
| | 20591 | return unionInitFromEnumTag(sema, block, init_src, union_ty, field_index, init); |
| | 20592 | } |
| | 20593 | |
| | 20594 | fn unionInitFromEnumTag( |
| | 20595 | sema: *Sema, |
| | 20596 | block: *Block, |
| | 20597 | init_src: LazySrcLoc, |
| | 20598 | union_ty: Type, |
| | 20599 | field_index: u32, |
| | 20600 | init: Air.Inst.Ref, |
| | 20601 | ) !Air.Inst.Ref { |
| | 20602 | const pt = sema.pt; |
| | 20603 | const zcu = pt.zcu; |
| 20808 | | 20604 | |
| 20809 | if (try sema.resolveValue(init)) |init_val| { | 20605 | if (try sema.resolveValue(init)) |init_val| { |
| 20810 | const tag_ty = union_ty.unionTagTypeHypothetical(zcu); | 20606 | const tag_ty = union_ty.unionTagTypeHypothetical(zcu); |
| 20811 | const tag_val = try pt.enumValueFieldIndex(tag_ty, field_index); | 20607 | const tag_val = try pt.enumValueFieldIndex(tag_ty, field_index); |
| 20812 | return Air.internedToRef((try pt.intern(.{ .un = .{ | 20608 | return Air.internedToRef((try pt.internUnion(.{ |
| 20813 | .ty = union_ty.toIntern(), | 20609 | .ty = union_ty.toIntern(), |
| 20814 | .tag = tag_val.toIntern(), | 20610 | .tag = tag_val.toIntern(), |
| 20815 | .val = init_val.toIntern(), | 20611 | .val = init_val.toIntern(), |
| 20816 | } }))); | 20612 | }))); |
| 20817 | } | 20613 | } |
| 20818 | | 20614 | |
| 20819 | try sema.requireRuntimeBlock(block, init_src, null); | 20615 | try sema.requireRuntimeBlock(block, init_src, null); |
| 20820 | _ = union_ty_src; | | |
| 20821 | return block.addUnionInit(union_ty, field_index, init); | 20616 | return block.addUnionInit(union_ty, field_index, init); |
| 20822 | } | 20617 | } |
| 20823 | | 20618 | |
| ... | @@ -20949,11 +20744,11 @@ fn zirStructInit( | ... | @@ -20949,11 +20744,11 @@ fn zirStructInit( |
| 20949 | const init_inst = try sema.coerce(block, field_ty, uncoerced_init_inst, field_src); | 20744 | const init_inst = try sema.coerce(block, field_ty, uncoerced_init_inst, field_src); |
| 20950 | | 20745 | |
| 20951 | if (try sema.resolveValue(init_inst)) |val| { | 20746 | if (try sema.resolveValue(init_inst)) |val| { |
| 20952 | const struct_val = Value.fromInterned(try pt.intern(.{ .un = .{ | 20747 | const struct_val = Value.fromInterned(try pt.internUnion(.{ |
| 20953 | .ty = resolved_ty.toIntern(), | 20748 | .ty = resolved_ty.toIntern(), |
| 20954 | .tag = tag_val.toIntern(), | 20749 | .tag = tag_val.toIntern(), |
| 20955 | .val = val.toIntern(), | 20750 | .val = val.toIntern(), |
| 20956 | } })); | 20751 | })); |
| 20957 | const final_val_inst = try sema.coerce(block, result_ty, Air.internedToRef(struct_val.toIntern()), src); | 20752 | const final_val_inst = try sema.coerce(block, result_ty, Air.internedToRef(struct_val.toIntern()), src); |
| 20958 | const final_val = (try sema.resolveValue(final_val_inst)).?; | 20753 | const final_val = (try sema.resolveValue(final_val_inst)).?; |
| 20959 | return sema.addConstantMaybeRef(final_val.toIntern(), is_ref); | 20754 | return sema.addConstantMaybeRef(final_val.toIntern(), is_ref); |
| ... | @@ -21660,7 +21455,7 @@ fn getErrorReturnTrace(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref { | ... | @@ -21660,7 +21455,7 @@ fn getErrorReturnTrace(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref { |
| 21660 | const pt = sema.pt; | 21455 | const pt = sema.pt; |
| 21661 | const zcu = pt.zcu; | 21456 | const zcu = pt.zcu; |
| 21662 | const ip = &zcu.intern_pool; | 21457 | const ip = &zcu.intern_pool; |
| 21663 | const stack_trace_ty = try pt.getBuiltinType("StackTrace"); | 21458 | const stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 21664 | try stack_trace_ty.resolveFields(pt); | 21459 | try stack_trace_ty.resolveFields(pt); |
| 21665 | const ptr_stack_trace_ty = try pt.singleMutPtrType(stack_trace_ty); | 21460 | const ptr_stack_trace_ty = try pt.singleMutPtrType(stack_trace_ty); |
| 21666 | const opt_ptr_stack_trace_ty = try pt.optionalType(ptr_stack_trace_ty.toIntern()); | 21461 | const opt_ptr_stack_trace_ty = try pt.optionalType(ptr_stack_trace_ty.toIntern()); |
| ... | @@ -21873,7 +21668,6 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -21873,7 +21668,6 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 21873 | const pt = sema.pt; | 21668 | const pt = sema.pt; |
| 21874 | const zcu = pt.zcu; | 21669 | const zcu = pt.zcu; |
| 21875 | const ip = &zcu.intern_pool; | 21670 | const ip = &zcu.intern_pool; |
| 21876 | | | |
| 21877 | try operand_ty.resolveLayout(pt); | 21671 | try operand_ty.resolveLayout(pt); |
| 21878 | const enum_ty = switch (operand_ty.zigTypeTag(zcu)) { | 21672 | const enum_ty = switch (operand_ty.zigTypeTag(zcu)) { |
| 21879 | .enum_literal => { | 21673 | .enum_literal => { |
| ... | @@ -21950,7 +21744,7 @@ fn zirReify( | ... | @@ -21950,7 +21744,7 @@ fn zirReify( |
| 21950 | }, | 21744 | }, |
| 21951 | }, | 21745 | }, |
| 21952 | }; | 21746 | }; |
| 21953 | const type_info_ty = try pt.getBuiltinType("Type"); | 21747 | const type_info_ty = try sema.getBuiltinType("Type"); |
| 21954 | const uncasted_operand = try sema.resolveInst(extra.operand); | 21748 | const uncasted_operand = try sema.resolveInst(extra.operand); |
| 21955 | const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src); | 21749 | const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src); |
| 21956 | const val = try sema.resolveConstDefinedValue(block, operand_src, type_info, .{ | 21750 | const val = try sema.resolveConstDefinedValue(block, operand_src, type_info, .{ |
| ... | @@ -23152,7 +22946,7 @@ fn reifyStruct( | ... | @@ -23152,7 +22946,7 @@ fn reifyStruct( |
| 23152 | | 22946 | |
| 23153 | fn resolveVaListRef(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.Inst.Ref) CompileError!Air.Inst.Ref { | 22947 | fn resolveVaListRef(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.Inst.Ref) CompileError!Air.Inst.Ref { |
| 23154 | const pt = sema.pt; | 22948 | const pt = sema.pt; |
| 23155 | const va_list_ty = try pt.getBuiltinType("VaList"); | 22949 | const va_list_ty = try sema.getBuiltinType("VaList"); |
| 23156 | const va_list_ptr = try pt.singleMutPtrType(va_list_ty); | 22950 | const va_list_ptr = try pt.singleMutPtrType(va_list_ty); |
| 23157 | | 22951 | |
| 23158 | const inst = try sema.resolveInst(zir_ref); | 22952 | const inst = try sema.resolveInst(zir_ref); |
| ... | @@ -23191,7 +22985,7 @@ fn zirCVaCopy(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) | ... | @@ -23191,7 +22985,7 @@ fn zirCVaCopy(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) |
| 23191 | const va_list_src = block.builtinCallArgSrc(extra.node, 0); | 22985 | const va_list_src = block.builtinCallArgSrc(extra.node, 0); |
| 23192 | | 22986 | |
| 23193 | const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.operand); | 22987 | const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.operand); |
| 23194 | const va_list_ty = try sema.pt.getBuiltinType("VaList"); | 22988 | const va_list_ty = try sema.getBuiltinType("VaList"); |
| 23195 | | 22989 | |
| 23196 | try sema.requireRuntimeBlock(block, src, null); | 22990 | try sema.requireRuntimeBlock(block, src, null); |
| 23197 | return block.addTyOp(.c_va_copy, va_list_ty, va_list_ref); | 22991 | return block.addTyOp(.c_va_copy, va_list_ty, va_list_ref); |
| ... | @@ -23211,7 +23005,7 @@ fn zirCVaEnd(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C | ... | @@ -23211,7 +23005,7 @@ fn zirCVaEnd(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C |
| 23211 | fn zirCVaStart(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { | 23005 | fn zirCVaStart(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { |
| 23212 | const src = block.nodeOffset(@bitCast(extended.operand)); | 23006 | const src = block.nodeOffset(@bitCast(extended.operand)); |
| 23213 | | 23007 | |
| 23214 | const va_list_ty = try sema.pt.getBuiltinType("VaList"); | 23008 | const va_list_ty = try sema.getBuiltinType("VaList"); |
| 23215 | try sema.requireRuntimeBlock(block, src, null); | 23009 | try sema.requireRuntimeBlock(block, src, null); |
| 23216 | return block.addInst(.{ | 23010 | return block.addInst(.{ |
| 23217 | .tag = .c_va_start, | 23011 | .tag = .c_va_start, |
| ... | @@ -24823,7 +24617,7 @@ fn resolveExportOptions( | ... | @@ -24823,7 +24617,7 @@ fn resolveExportOptions( |
| 24823 | const zcu = pt.zcu; | 24617 | const zcu = pt.zcu; |
| 24824 | const gpa = sema.gpa; | 24618 | const gpa = sema.gpa; |
| 24825 | const ip = &zcu.intern_pool; | 24619 | const ip = &zcu.intern_pool; |
| 24826 | const export_options_ty = try pt.getBuiltinType("ExportOptions"); | 24620 | const export_options_ty = try sema.getBuiltinType("ExportOptions"); |
| 24827 | const air_ref = try sema.resolveInst(zir_ref); | 24621 | const air_ref = try sema.resolveInst(zir_ref); |
| 24828 | const options = try sema.coerce(block, export_options_ty, air_ref, src); | 24622 | const options = try sema.coerce(block, export_options_ty, air_ref, src); |
| 24829 | | 24623 | |
| ... | @@ -24887,7 +24681,7 @@ fn resolveBuiltinEnum( | ... | @@ -24887,7 +24681,7 @@ fn resolveBuiltinEnum( |
| 24887 | reason: NeededComptimeReason, | 24681 | reason: NeededComptimeReason, |
| 24888 | ) CompileError!@field(std.builtin, name) { | 24682 | ) CompileError!@field(std.builtin, name) { |
| 24889 | const pt = sema.pt; | 24683 | const pt = sema.pt; |
| 24890 | const ty = try pt.getBuiltinType(name); | 24684 | const ty = try sema.getBuiltinType(name); |
| 24891 | const air_ref = try sema.resolveInst(zir_ref); | 24685 | const air_ref = try sema.resolveInst(zir_ref); |
| 24892 | const coerced = try sema.coerce(block, ty, air_ref, src); | 24686 | const coerced = try sema.coerce(block, ty, air_ref, src); |
| 24893 | const val = try sema.resolveConstDefinedValue(block, src, coerced, reason); | 24687 | const val = try sema.resolveConstDefinedValue(block, src, coerced, reason); |
| ... | @@ -25656,7 +25450,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -25656,7 +25450,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 25656 | const extra = sema.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data; | 25450 | const extra = sema.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data; |
| 25657 | const func = try sema.resolveInst(extra.callee); | 25451 | const func = try sema.resolveInst(extra.callee); |
| 25658 | | 25452 | |
| 25659 | const modifier_ty = try pt.getBuiltinType("CallModifier"); | 25453 | const modifier_ty = try sema.getBuiltinType("CallModifier"); |
| 25660 | const air_ref = try sema.resolveInst(extra.modifier); | 25454 | const air_ref = try sema.resolveInst(extra.modifier); |
| 25661 | const modifier_ref = try sema.coerce(block, modifier_ty, air_ref, modifier_src); | 25455 | const modifier_ref = try sema.coerce(block, modifier_ty, air_ref, modifier_src); |
| 25662 | const modifier_val = try sema.resolveConstDefinedValue(block, modifier_src, modifier_ref, .{ | 25456 | const modifier_val = try sema.resolveConstDefinedValue(block, modifier_src, modifier_ref, .{ |
| ... | @@ -26782,7 +26576,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -26782,7 +26576,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 26782 | const body = sema.code.bodySlice(extra_index, body_len); | 26576 | const body = sema.code.bodySlice(extra_index, body_len); |
| 26783 | extra_index += body.len; | 26577 | extra_index += body.len; |
| 26784 | | 26578 | |
| 26785 | const addrspace_ty = try pt.getBuiltinType("AddressSpace"); | 26579 | const addrspace_ty = try sema.getBuiltinType("AddressSpace"); |
| 26786 | const val = try sema.resolveGenericBody(block, addrspace_src, body, inst, addrspace_ty, .{ | 26580 | const val = try sema.resolveGenericBody(block, addrspace_src, body, inst, addrspace_ty, .{ |
| 26787 | .needed_comptime_reason = "addrspace must be comptime-known", | 26581 | .needed_comptime_reason = "addrspace must be comptime-known", |
| 26788 | }); | 26582 | }); |
| ... | @@ -26793,7 +26587,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -26793,7 +26587,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 26793 | } else if (extra.data.bits.has_addrspace_ref) blk: { | 26587 | } else if (extra.data.bits.has_addrspace_ref) blk: { |
| 26794 | const addrspace_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); | 26588 | const addrspace_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 26795 | extra_index += 1; | 26589 | extra_index += 1; |
| 26796 | const addrspace_ty = try pt.getBuiltinType("AddressSpace"); | 26590 | const addrspace_ty = try sema.getBuiltinType("AddressSpace"); |
| 26797 | const uncoerced_addrspace = sema.resolveInst(addrspace_ref) catch |err| switch (err) { | 26591 | const uncoerced_addrspace = sema.resolveInst(addrspace_ref) catch |err| switch (err) { |
| 26798 | error.GenericPoison => break :blk null, | 26592 | error.GenericPoison => break :blk null, |
| 26799 | else => |e| return e, | 26593 | else => |e| return e, |
| ... | @@ -26847,7 +26641,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -26847,7 +26641,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 26847 | const body = sema.code.bodySlice(extra_index, body_len); | 26641 | const body = sema.code.bodySlice(extra_index, body_len); |
| 26848 | extra_index += body.len; | 26642 | extra_index += body.len; |
| 26849 | | 26643 | |
| 26850 | const cc_ty = try pt.getBuiltinType("CallingConvention"); | 26644 | const cc_ty = try sema.getBuiltinType("CallingConvention"); |
| 26851 | const val = try sema.resolveGenericBody(block, cc_src, body, inst, cc_ty, .{ | 26645 | const val = try sema.resolveGenericBody(block, cc_src, body, inst, cc_ty, .{ |
| 26852 | .needed_comptime_reason = "calling convention must be comptime-known", | 26646 | .needed_comptime_reason = "calling convention must be comptime-known", |
| 26853 | }); | 26647 | }); |
| ... | @@ -26858,7 +26652,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -26858,7 +26652,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 26858 | } else if (extra.data.bits.has_cc_ref) blk: { | 26652 | } else if (extra.data.bits.has_cc_ref) blk: { |
| 26859 | const cc_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); | 26653 | const cc_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 26860 | extra_index += 1; | 26654 | extra_index += 1; |
| 26861 | const cc_ty = try pt.getBuiltinType("CallingConvention"); | 26655 | const cc_ty = try sema.getBuiltinType("CallingConvention"); |
| 26862 | const uncoerced_cc = sema.resolveInst(cc_ref) catch |err| switch (err) { | 26656 | const uncoerced_cc = sema.resolveInst(cc_ref) catch |err| switch (err) { |
| 26863 | error.GenericPoison => break :blk null, | 26657 | error.GenericPoison => break :blk null, |
| 26864 | else => |e| return e, | 26658 | else => |e| return e, |
| ... | @@ -27075,7 +26869,7 @@ fn resolvePrefetchOptions( | ... | @@ -27075,7 +26869,7 @@ fn resolvePrefetchOptions( |
| 27075 | const zcu = pt.zcu; | 26869 | const zcu = pt.zcu; |
| 27076 | const gpa = sema.gpa; | 26870 | const gpa = sema.gpa; |
| 27077 | const ip = &zcu.intern_pool; | 26871 | const ip = &zcu.intern_pool; |
| 27078 | const options_ty = try pt.getBuiltinType("PrefetchOptions"); | 26872 | const options_ty = try sema.getBuiltinType("PrefetchOptions"); |
| 27079 | const options = try sema.coerce(block, options_ty, try sema.resolveInst(zir_ref), src); | 26873 | const options = try sema.coerce(block, options_ty, try sema.resolveInst(zir_ref), src); |
| 27080 | | 26874 | |
| 27081 | const rw_src = block.src(.{ .init_field_rw = src.offset.node_offset_builtin_call_arg.builtin_call_node }); | 26875 | const rw_src = block.src(.{ .init_field_rw = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| ... | @@ -27148,7 +26942,7 @@ fn resolveExternOptions( | ... | @@ -27148,7 +26942,7 @@ fn resolveExternOptions( |
| 27148 | const gpa = sema.gpa; | 26942 | const gpa = sema.gpa; |
| 27149 | const ip = &zcu.intern_pool; | 26943 | const ip = &zcu.intern_pool; |
| 27150 | const options_inst = try sema.resolveInst(zir_ref); | 26944 | const options_inst = try sema.resolveInst(zir_ref); |
| 27151 | const extern_options_ty = try pt.getBuiltinType("ExternOptions"); | 26945 | const extern_options_ty = try sema.getBuiltinType("ExternOptions"); |
| 27152 | const options = try sema.coerce(block, extern_options_ty, options_inst, src); | 26946 | const options = try sema.coerce(block, extern_options_ty, options_inst, src); |
| 27153 | | 26947 | |
| 27154 | const name_src = block.src(.{ .init_field_name = src.offset.node_offset_builtin_call_arg.builtin_call_node }); | 26948 | const name_src = block.src(.{ .init_field_name = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| ... | @@ -27335,7 +27129,7 @@ fn zirBuiltinValue(sema: *Sema, extended: Zir.Inst.Extended.InstData) CompileErr | ... | @@ -27335,7 +27129,7 @@ fn zirBuiltinValue(sema: *Sema, extended: Zir.Inst.Extended.InstData) CompileErr |
| 27335 | | 27129 | |
| 27336 | // Values are handled here. | 27130 | // Values are handled here. |
| 27337 | .calling_convention_c => { | 27131 | .calling_convention_c => { |
| 27338 | const callconv_ty = try pt.getBuiltinType("CallingConvention"); | 27132 | const callconv_ty = try sema.getBuiltinType("CallingConvention"); |
| 27339 | comptime assert(@intFromEnum(std.builtin.CallingConvention.C) == 1); | 27133 | comptime assert(@intFromEnum(std.builtin.CallingConvention.C) == 1); |
| 27340 | const val = try pt.intern(.{ .enum_tag = .{ | 27134 | const val = try pt.intern(.{ .enum_tag = .{ |
| 27341 | .ty = callconv_ty.toIntern(), | 27135 | .ty = callconv_ty.toIntern(), |
| ... | @@ -27344,7 +27138,7 @@ fn zirBuiltinValue(sema: *Sema, extended: Zir.Inst.Extended.InstData) CompileErr | ... | @@ -27344,7 +27138,7 @@ fn zirBuiltinValue(sema: *Sema, extended: Zir.Inst.Extended.InstData) CompileErr |
| 27344 | return Air.internedToRef(val); | 27138 | return Air.internedToRef(val); |
| 27345 | }, | 27139 | }, |
| 27346 | .calling_convention_inline => { | 27140 | .calling_convention_inline => { |
| 27347 | const callconv_ty = try pt.getBuiltinType("CallingConvention"); | 27141 | const callconv_ty = try sema.getBuiltinType("CallingConvention"); |
| 27348 | comptime assert(@intFromEnum(std.builtin.CallingConvention.Inline) == 4); | 27142 | comptime assert(@intFromEnum(std.builtin.CallingConvention.Inline) == 4); |
| 27349 | const val = try pt.intern(.{ .enum_tag = .{ | 27143 | const val = try pt.intern(.{ .enum_tag = .{ |
| 27350 | .ty = callconv_ty.toIntern(), | 27144 | .ty = callconv_ty.toIntern(), |
| ... | @@ -27353,7 +27147,7 @@ fn zirBuiltinValue(sema: *Sema, extended: Zir.Inst.Extended.InstData) CompileErr | ... | @@ -27353,7 +27147,7 @@ fn zirBuiltinValue(sema: *Sema, extended: Zir.Inst.Extended.InstData) CompileErr |
| 27353 | return Air.internedToRef(val); | 27147 | return Air.internedToRef(val); |
| 27354 | }, | 27148 | }, |
| 27355 | }; | 27149 | }; |
| 27356 | const ty = try pt.getBuiltinType(type_name); | 27150 | const ty = try sema.getBuiltinType(type_name); |
| 27357 | return Air.internedToRef(ty.toIntern()); | 27151 | return Air.internedToRef(ty.toIntern()); |
| 27358 | } | 27152 | } |
| 27359 | | 27153 | |
| ... | @@ -27392,7 +27186,7 @@ fn zirBranchHint(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat | ... | @@ -27392,7 +27186,7 @@ fn zirBranchHint(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 27392 | const uncoerced_hint = try sema.resolveInst(extra.operand); | 27186 | const uncoerced_hint = try sema.resolveInst(extra.operand); |
| 27393 | const operand_src = block.builtinCallArgSrc(extra.node, 0); | 27187 | const operand_src = block.builtinCallArgSrc(extra.node, 0); |
| 27394 | | 27188 | |
| 27395 | const hint_ty = try pt.getBuiltinType("BranchHint"); | 27189 | const hint_ty = try sema.getBuiltinType("BranchHint"); |
| 27396 | const coerced_hint = try sema.coerce(block, hint_ty, uncoerced_hint, operand_src); | 27190 | const coerced_hint = try sema.coerce(block, hint_ty, uncoerced_hint, operand_src); |
| 27397 | const hint_val = try sema.resolveConstDefinedValue(block, operand_src, coerced_hint, .{ | 27191 | const hint_val = try sema.resolveConstDefinedValue(block, operand_src, coerced_hint, .{ |
| 27398 | .needed_comptime_reason = "operand to '@branchHint' must be comptime-known", | 27192 | .needed_comptime_reason = "operand to '@branchHint' must be comptime-known", |
| ... | @@ -27845,18 +27639,14 @@ fn prepareSimplePanic(sema: *Sema, block: *Block, src: LazySrcLoc) !void { | ... | @@ -27845,18 +27639,14 @@ fn prepareSimplePanic(sema: *Sema, block: *Block, src: LazySrcLoc) !void { |
| 27845 | const zcu = pt.zcu; | 27639 | const zcu = pt.zcu; |
| 27846 | | 27640 | |
| 27847 | if (zcu.panic_func_index == .none) { | 27641 | if (zcu.panic_func_index == .none) { |
| 27848 | const fn_ref = try sema.analyzeNavVal(block, src, try pt.getBuiltinNav("panic")); | 27642 | zcu.panic_func_index = try sema.getPanicInnerFn(block, src, "call"); |
| 27849 | const fn_val = try sema.resolveConstValue(block, src, fn_ref, .{ | 27643 | // Here, function body analysis must be queued up so that backends can |
| 27850 | .needed_comptime_reason = "panic handler must be comptime-known", | 27644 | // make calls to this function. |
| 27851 | }); | 27645 | try zcu.ensureFuncBodyAnalysisQueued(zcu.panic_func_index); |
| 27852 | assert(fn_val.typeOf(zcu).zigTypeTag(zcu) == .@"fn"); | | |
| 27853 | assert(try fn_val.typeOf(zcu).fnHasRuntimeBitsSema(pt)); | | |
| 27854 | try zcu.ensureFuncBodyAnalysisQueued(fn_val.toIntern()); | | |
| 27855 | zcu.panic_func_index = fn_val.toIntern(); | | |
| 27856 | } | 27646 | } |
| 27857 | | 27647 | |
| 27858 | if (zcu.null_stack_trace == .none) { | 27648 | if (zcu.null_stack_trace == .none) { |
| 27859 | const stack_trace_ty = try pt.getBuiltinType("StackTrace"); | 27649 | const stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 27860 | try stack_trace_ty.resolveFields(pt); | 27650 | try stack_trace_ty.resolveFields(pt); |
| 27861 | const target = zcu.getTarget(); | 27651 | const target = zcu.getTarget(); |
| 27862 | const ptr_stack_trace_ty = try pt.ptrTypeSema(.{ | 27652 | const ptr_stack_trace_ty = try pt.ptrTypeSema(.{ |
| ... | @@ -27884,14 +27674,15 @@ fn preparePanicId(sema: *Sema, block: *Block, src: LazySrcLoc, panic_id: Zcu.Pan | ... | @@ -27884,14 +27674,15 @@ fn preparePanicId(sema: *Sema, block: *Block, src: LazySrcLoc, panic_id: Zcu.Pan |
| 27884 | | 27674 | |
| 27885 | try sema.prepareSimplePanic(block, src); | 27675 | try sema.prepareSimplePanic(block, src); |
| 27886 | | 27676 | |
| 27887 | const panic_messages_ty = try pt.getBuiltinType("panic_messages"); | 27677 | const panic_ty = try sema.getBuiltinType("Panic"); |
| | 27678 | const panic_messages_ty = try sema.getBuiltinInnerType(block, src, panic_ty, "Panic", "messages"); |
| 27888 | const msg_nav_index = (sema.namespaceLookup( | 27679 | const msg_nav_index = (sema.namespaceLookup( |
| 27889 | block, | 27680 | block, |
| 27890 | LazySrcLoc.unneeded, | 27681 | LazySrcLoc.unneeded, |
| 27891 | panic_messages_ty.getNamespaceIndex(zcu), | 27682 | panic_messages_ty.getNamespaceIndex(zcu), |
| 27892 | try zcu.intern_pool.getOrPutString(gpa, pt.tid, @tagName(panic_id), .no_embedded_nulls), | 27683 | try zcu.intern_pool.getOrPutString(gpa, pt.tid, @tagName(panic_id), .no_embedded_nulls), |
| 27893 | ) catch |err| switch (err) { | 27684 | ) catch |err| switch (err) { |
| 27894 | error.AnalysisFail => @panic("std.builtin.panic_messages is corrupt"), | 27685 | error.AnalysisFail => return error.AnalysisFail, |
| 27895 | error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, | 27686 | error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, |
| 27896 | error.OutOfMemory => |e| return e, | 27687 | error.OutOfMemory => |e| return e, |
| 27897 | }).?; | 27688 | }).?; |
| ... | @@ -28015,7 +27806,7 @@ fn panicWithMsg(sema: *Sema, block: *Block, src: LazySrcLoc, msg_inst: Air.Inst. | ... | @@ -28015,7 +27806,7 @@ fn panicWithMsg(sema: *Sema, block: *Block, src: LazySrcLoc, msg_inst: Air.Inst. |
| 28015 | try sema.callBuiltin(block, src, panic_fn, .auto, &.{ msg_inst, null_stack_trace, null_ret_addr }, operation); | 27806 | try sema.callBuiltin(block, src, panic_fn, .auto, &.{ msg_inst, null_stack_trace, null_ret_addr }, operation); |
| 28016 | } | 27807 | } |
| 28017 | | 27808 | |
| 28018 | fn panicUnwrapError( | 27809 | fn addSafetyCheckUnwrapError( |
| 28019 | sema: *Sema, | 27810 | sema: *Sema, |
| 28020 | parent_block: *Block, | 27811 | parent_block: *Block, |
| 28021 | src: LazySrcLoc, | 27812 | src: LazySrcLoc, |
| ... | @@ -28023,12 +27814,8 @@ fn panicUnwrapError( | ... | @@ -28023,12 +27814,8 @@ fn panicUnwrapError( |
| 28023 | unwrap_err_tag: Air.Inst.Tag, | 27814 | unwrap_err_tag: Air.Inst.Tag, |
| 28024 | is_non_err_tag: Air.Inst.Tag, | 27815 | is_non_err_tag: Air.Inst.Tag, |
| 28025 | ) !void { | 27816 | ) !void { |
| 28026 | const pt = sema.pt; | | |
| 28027 | assert(!parent_block.is_comptime); | 27817 | assert(!parent_block.is_comptime); |
| 28028 | const ok = try parent_block.addUnOp(is_non_err_tag, operand); | 27818 | const ok = try parent_block.addUnOp(is_non_err_tag, operand); |
| 28029 | if (!pt.zcu.comp.formatted_panics) { | | |
| 28030 | return sema.addSafetyCheck(parent_block, src, ok, .unwrap_error); | | |
| 28031 | } | | |
| 28032 | const gpa = sema.gpa; | 27819 | const gpa = sema.gpa; |
| 28033 | | 27820 | |
| 28034 | var fail_block: Block = .{ | 27821 | var fail_block: Block = .{ |
| ... | @@ -28044,21 +27831,26 @@ fn panicUnwrapError( | ... | @@ -28044,21 +27831,26 @@ fn panicUnwrapError( |
| 28044 | | 27831 | |
| 28045 | defer fail_block.instructions.deinit(gpa); | 27832 | defer fail_block.instructions.deinit(gpa); |
| 28046 | | 27833 | |
| 28047 | { | 27834 | const err = try fail_block.addTyOp(unwrap_err_tag, Type.anyerror, operand); |
| 28048 | if (!pt.zcu.backendSupportsFeature(.panic_unwrap_error)) { | 27835 | try safetyPanicUnwrapError(sema, &fail_block, src, err); |
| 28049 | _ = try fail_block.addNoOp(.trap); | 27836 | |
| 28050 | } else { | | |
| 28051 | const panic_fn = try sema.pt.getBuiltin("panicUnwrapError"); | | |
| 28052 | const err = try fail_block.addTyOp(unwrap_err_tag, Type.anyerror, operand); | | |
| 28053 | const err_return_trace = try sema.getErrorReturnTrace(&fail_block); | | |
| 28054 | const args: [2]Air.Inst.Ref = .{ err_return_trace, err }; | | |
| 28055 | try sema.callBuiltin(&fail_block, src, panic_fn, .auto, &args, .@"safety check"); | | |
| 28056 | } | | |
| 28057 | } | | |
| 28058 | try sema.addSafetyCheckExtra(parent_block, ok, &fail_block); | 27837 | try sema.addSafetyCheckExtra(parent_block, ok, &fail_block); |
| 28059 | } | 27838 | } |
| 28060 | | 27839 | |
| 28061 | fn panicIndexOutOfBounds( | 27840 | fn safetyPanicUnwrapError(sema: *Sema, block: *Block, src: LazySrcLoc, err: Air.Inst.Ref) !void { |
| | 27841 | const pt = sema.pt; |
| | 27842 | const zcu = pt.zcu; |
| | 27843 | if (!zcu.backendSupportsFeature(.panic_fn)) { |
| | 27844 | _ = try block.addNoOp(.trap); |
| | 27845 | } else { |
| | 27846 | const panic_fn = try getPanicInnerFn(sema, block, src, "unwrapError"); |
| | 27847 | const err_return_trace = try sema.getErrorReturnTrace(block); |
| | 27848 | const args: [2]Air.Inst.Ref = .{ err_return_trace, err }; |
| | 27849 | try sema.callBuiltin(block, src, Air.internedToRef(panic_fn), .auto, &args, .@"safety check"); |
| | 27850 | } |
| | 27851 | } |
| | 27852 | |
| | 27853 | fn addSafetyCheckIndexOob( |
| 28062 | sema: *Sema, | 27854 | sema: *Sema, |
| 28063 | parent_block: *Block, | 27855 | parent_block: *Block, |
| 28064 | src: LazySrcLoc, | 27856 | src: LazySrcLoc, |
| ... | @@ -28068,13 +27860,10 @@ fn panicIndexOutOfBounds( | ... | @@ -28068,13 +27860,10 @@ fn panicIndexOutOfBounds( |
| 28068 | ) !void { | 27860 | ) !void { |
| 28069 | assert(!parent_block.is_comptime); | 27861 | assert(!parent_block.is_comptime); |
| 28070 | const ok = try parent_block.addBinOp(cmp_op, index, len); | 27862 | const ok = try parent_block.addBinOp(cmp_op, index, len); |
| 28071 | if (!sema.pt.zcu.comp.formatted_panics) { | 27863 | return addSafetyCheckCall(sema, parent_block, src, ok, "outOfBounds", &.{ index, len }); |
| 28072 | return sema.addSafetyCheck(parent_block, src, ok, .index_out_of_bounds); | | |
| 28073 | } | | |
| 28074 | try sema.safetyCheckFormatted(parent_block, src, ok, "panicOutOfBounds", &.{ index, len }); | | |
| 28075 | } | 27864 | } |
| 28076 | | 27865 | |
| 28077 | fn panicInactiveUnionField( | 27866 | fn addSafetyCheckInactiveUnionField( |
| 28078 | sema: *Sema, | 27867 | sema: *Sema, |
| 28079 | parent_block: *Block, | 27868 | parent_block: *Block, |
| 28080 | src: LazySrcLoc, | 27869 | src: LazySrcLoc, |
| ... | @@ -28083,13 +27872,10 @@ fn panicInactiveUnionField( | ... | @@ -28083,13 +27872,10 @@ fn panicInactiveUnionField( |
| 28083 | ) !void { | 27872 | ) !void { |
| 28084 | assert(!parent_block.is_comptime); | 27873 | assert(!parent_block.is_comptime); |
| 28085 | const ok = try parent_block.addBinOp(.cmp_eq, active_tag, wanted_tag); | 27874 | const ok = try parent_block.addBinOp(.cmp_eq, active_tag, wanted_tag); |
| 28086 | if (!sema.pt.zcu.comp.formatted_panics) { | 27875 | return addSafetyCheckCall(sema, parent_block, src, ok, "inactiveUnionField", &.{ active_tag, wanted_tag }); |
| 28087 | return sema.addSafetyCheck(parent_block, src, ok, .inactive_union_field); | | |
| 28088 | } | | |
| 28089 | try sema.safetyCheckFormatted(parent_block, src, ok, "panicInactiveUnionField", &.{ active_tag, wanted_tag }); | | |
| 28090 | } | 27876 | } |
| 28091 | | 27877 | |
| 28092 | fn panicSentinelMismatch( | 27878 | fn addSafetyCheckSentinelMismatch( |
| 28093 | sema: *Sema, | 27879 | sema: *Sema, |
| 28094 | parent_block: *Block, | 27880 | parent_block: *Block, |
| 28095 | src: LazySrcLoc, | 27881 | src: LazySrcLoc, |
| ... | @@ -28114,8 +27900,7 @@ fn panicSentinelMismatch( | ... | @@ -28114,8 +27900,7 @@ fn panicSentinelMismatch( |
| 28114 | }; | 27900 | }; |
| 28115 | | 27901 | |
| 28116 | const ok = if (sentinel_ty.zigTypeTag(zcu) == .vector) ok: { | 27902 | const ok = if (sentinel_ty.zigTypeTag(zcu) == .vector) ok: { |
| 28117 | const eql = | 27903 | const eql = try parent_block.addCmpVector(expected_sentinel, actual_sentinel, .eq); |
| 28118 | try parent_block.addCmpVector(expected_sentinel, actual_sentinel, .eq); | | |
| 28119 | break :ok try parent_block.addInst(.{ | 27904 | break :ok try parent_block.addInst(.{ |
| 28120 | .tag = .reduce, | 27905 | .tag = .reduce, |
| 28121 | .data = .{ .reduce = .{ | 27906 | .data = .{ .reduce = .{ |
| ... | @@ -28128,24 +27913,23 @@ fn panicSentinelMismatch( | ... | @@ -28128,24 +27913,23 @@ fn panicSentinelMismatch( |
| 28128 | break :ok try parent_block.addBinOp(.cmp_eq, expected_sentinel, actual_sentinel); | 27913 | break :ok try parent_block.addBinOp(.cmp_eq, expected_sentinel, actual_sentinel); |
| 28129 | }; | 27914 | }; |
| 28130 | | 27915 | |
| 28131 | if (!pt.zcu.comp.formatted_panics) { | 27916 | return addSafetyCheckCall(sema, parent_block, src, ok, "sentinelMismatch", &.{ |
| 28132 | return sema.addSafetyCheck(parent_block, src, ok, .sentinel_mismatch); | 27917 | expected_sentinel, actual_sentinel, |
| 28133 | } | 27918 | }); |
| 28134 | try sema.safetyCheckFormatted(parent_block, src, ok, "panicSentinelMismatch", &.{ expected_sentinel, actual_sentinel }); | | |
| 28135 | } | 27919 | } |
| 28136 | | 27920 | |
| 28137 | fn safetyCheckFormatted( | 27921 | fn addSafetyCheckCall( |
| 28138 | sema: *Sema, | 27922 | sema: *Sema, |
| 28139 | parent_block: *Block, | 27923 | parent_block: *Block, |
| 28140 | src: LazySrcLoc, | 27924 | src: LazySrcLoc, |
| 28141 | ok: Air.Inst.Ref, | 27925 | ok: Air.Inst.Ref, |
| 28142 | func: []const u8, | 27926 | func_name: []const u8, |
| 28143 | args: []const Air.Inst.Ref, | 27927 | args: []const Air.Inst.Ref, |
| 28144 | ) CompileError!void { | 27928 | ) !void { |
| | 27929 | assert(!parent_block.is_comptime); |
| | 27930 | const gpa = sema.gpa; |
| 28145 | const pt = sema.pt; | 27931 | const pt = sema.pt; |
| 28146 | const zcu = pt.zcu; | 27932 | const zcu = pt.zcu; |
| 28147 | assert(zcu.comp.formatted_panics); | | |
| 28148 | const gpa = sema.gpa; | | |
| 28149 | | 27933 | |
| 28150 | var fail_block: Block = .{ | 27934 | var fail_block: Block = .{ |
| 28151 | .parent = parent_block, | 27935 | .parent = parent_block, |
| ... | @@ -28160,12 +27944,13 @@ fn safetyCheckFormatted( | ... | @@ -28160,12 +27944,13 @@ fn safetyCheckFormatted( |
| 28160 | | 27944 | |
| 28161 | defer fail_block.instructions.deinit(gpa); | 27945 | defer fail_block.instructions.deinit(gpa); |
| 28162 | | 27946 | |
| 28163 | if (!zcu.backendSupportsFeature(.safety_check_formatted)) { | 27947 | if (!zcu.backendSupportsFeature(.panic_fn)) { |
| 28164 | _ = try fail_block.addNoOp(.trap); | 27948 | _ = try fail_block.addNoOp(.trap); |
| 28165 | } else { | 27949 | } else { |
| 28166 | const panic_fn = try pt.getBuiltin(func); | 27950 | const panic_fn = try getPanicInnerFn(sema, &fail_block, src, func_name); |
| 28167 | try sema.callBuiltin(&fail_block, src, panic_fn, .auto, args, .@"safety check"); | 27951 | try sema.callBuiltin(&fail_block, src, Air.internedToRef(panic_fn), .auto, args, .@"safety check"); |
| 28168 | } | 27952 | } |
| | 27953 | |
| 28169 | try sema.addSafetyCheckExtra(parent_block, ok, &fail_block); | 27954 | try sema.addSafetyCheckExtra(parent_block, ok, &fail_block); |
| 28170 | } | 27955 | } |
| 28171 | | 27956 | |
| ... | @@ -29229,7 +29014,7 @@ fn unionFieldPtr( | ... | @@ -29229,7 +29014,7 @@ fn unionFieldPtr( |
| 29229 | // TODO would it be better if get_union_tag supported pointers to unions? | 29014 | // TODO would it be better if get_union_tag supported pointers to unions? |
| 29230 | const union_val = try block.addTyOp(.load, union_ty, union_ptr); | 29015 | const union_val = try block.addTyOp(.load, union_ty, union_ptr); |
| 29231 | const active_tag = try block.addTyOp(.get_union_tag, Type.fromInterned(union_obj.enum_tag_ty), union_val); | 29016 | const active_tag = try block.addTyOp(.get_union_tag, Type.fromInterned(union_obj.enum_tag_ty), union_val); |
| 29232 | try sema.panicInactiveUnionField(block, src, active_tag, wanted_tag); | 29017 | try sema.addSafetyCheckInactiveUnionField(block, src, active_tag, wanted_tag); |
| 29233 | } | 29018 | } |
| 29234 | if (field_ty.zigTypeTag(zcu) == .noreturn) { | 29019 | if (field_ty.zigTypeTag(zcu) == .noreturn) { |
| 29235 | _ = try block.addNoOp(.unreach); | 29020 | _ = try block.addNoOp(.unreach); |
| ... | @@ -29304,7 +29089,7 @@ fn unionFieldVal( | ... | @@ -29304,7 +29089,7 @@ fn unionFieldVal( |
| 29304 | const wanted_tag_val = try pt.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index); | 29089 | const wanted_tag_val = try pt.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index); |
| 29305 | const wanted_tag = Air.internedToRef(wanted_tag_val.toIntern()); | 29090 | const wanted_tag = Air.internedToRef(wanted_tag_val.toIntern()); |
| 29306 | const active_tag = try block.addTyOp(.get_union_tag, Type.fromInterned(union_obj.enum_tag_ty), union_byval); | 29091 | const active_tag = try block.addTyOp(.get_union_tag, Type.fromInterned(union_obj.enum_tag_ty), union_byval); |
| 29307 | try sema.panicInactiveUnionField(block, src, active_tag, wanted_tag); | 29092 | try sema.addSafetyCheckInactiveUnionField(block, src, active_tag, wanted_tag); |
| 29308 | } | 29093 | } |
| 29309 | if (field_ty.zigTypeTag(zcu) == .noreturn) { | 29094 | if (field_ty.zigTypeTag(zcu) == .noreturn) { |
| 29310 | _ = try block.addNoOp(.unreach); | 29095 | _ = try block.addNoOp(.unreach); |
| ... | @@ -29668,11 +29453,11 @@ fn elemValArray( | ... | @@ -29668,11 +29453,11 @@ fn elemValArray( |
| 29668 | | 29453 | |
| 29669 | const runtime_src = if (maybe_undef_array_val != null) elem_index_src else array_src; | 29454 | const runtime_src = if (maybe_undef_array_val != null) elem_index_src else array_src; |
| 29670 | if (oob_safety and block.wantSafety()) { | 29455 | if (oob_safety and block.wantSafety()) { |
| 29671 | // Runtime check is only needed if unable to comptime check | 29456 | // Runtime check is only needed if unable to comptime check. |
| 29672 | if (maybe_index_val == null) { | 29457 | if (maybe_index_val == null) { |
| 29673 | const len_inst = try pt.intRef(Type.usize, array_len); | 29458 | const len_inst = try pt.intRef(Type.usize, array_len); |
| 29674 | const cmp_op: Air.Inst.Tag = if (array_sent != null) .cmp_lte else .cmp_lt; | 29459 | const cmp_op: Air.Inst.Tag = if (array_sent != null) .cmp_lte else .cmp_lt; |
| 29675 | try sema.panicIndexOutOfBounds(block, src, elem_index, len_inst, cmp_op); | 29460 | try sema.addSafetyCheckIndexOob(block, src, elem_index, len_inst, cmp_op); |
| 29676 | } | 29461 | } |
| 29677 | } | 29462 | } |
| 29678 | | 29463 | |
| ... | @@ -29740,7 +29525,7 @@ fn elemPtrArray( | ... | @@ -29740,7 +29525,7 @@ fn elemPtrArray( |
| 29740 | if (oob_safety and block.wantSafety() and offset == null) { | 29525 | if (oob_safety and block.wantSafety() and offset == null) { |
| 29741 | const len_inst = try pt.intRef(Type.usize, array_len); | 29526 | const len_inst = try pt.intRef(Type.usize, array_len); |
| 29742 | const cmp_op: Air.Inst.Tag = if (array_sent) .cmp_lte else .cmp_lt; | 29527 | const cmp_op: Air.Inst.Tag = if (array_sent) .cmp_lte else .cmp_lt; |
| 29743 | try sema.panicIndexOutOfBounds(block, src, elem_index, len_inst, cmp_op); | 29528 | try sema.addSafetyCheckIndexOob(block, src, elem_index, len_inst, cmp_op); |
| 29744 | } | 29529 | } |
| 29745 | | 29530 | |
| 29746 | return block.addPtrElemPtr(array_ptr, elem_index, elem_ptr_ty); | 29531 | return block.addPtrElemPtr(array_ptr, elem_index, elem_ptr_ty); |
| ... | @@ -29799,7 +29584,7 @@ fn elemValSlice( | ... | @@ -29799,7 +29584,7 @@ fn elemValSlice( |
| 29799 | else | 29584 | else |
| 29800 | try block.addTyOp(.slice_len, Type.usize, slice); | 29585 | try block.addTyOp(.slice_len, Type.usize, slice); |
| 29801 | const cmp_op: Air.Inst.Tag = if (slice_sent) .cmp_lte else .cmp_lt; | 29586 | const cmp_op: Air.Inst.Tag = if (slice_sent) .cmp_lte else .cmp_lt; |
| 29802 | try sema.panicIndexOutOfBounds(block, src, elem_index, len_inst, cmp_op); | 29587 | try sema.addSafetyCheckIndexOob(block, src, elem_index, len_inst, cmp_op); |
| 29803 | } | 29588 | } |
| 29804 | return block.addBinOp(.slice_elem_val, slice, elem_index); | 29589 | return block.addBinOp(.slice_elem_val, slice, elem_index); |
| 29805 | } | 29590 | } |
| ... | @@ -29859,7 +29644,7 @@ fn elemPtrSlice( | ... | @@ -29859,7 +29644,7 @@ fn elemPtrSlice( |
| 29859 | break :len try block.addTyOp(.slice_len, Type.usize, slice); | 29644 | break :len try block.addTyOp(.slice_len, Type.usize, slice); |
| 29860 | }; | 29645 | }; |
| 29861 | const cmp_op: Air.Inst.Tag = if (slice_sent) .cmp_lte else .cmp_lt; | 29646 | const cmp_op: Air.Inst.Tag = if (slice_sent) .cmp_lte else .cmp_lt; |
| 29862 | try sema.panicIndexOutOfBounds(block, src, elem_index, len_inst, cmp_op); | 29647 | try sema.addSafetyCheckIndexOob(block, src, elem_index, len_inst, cmp_op); |
| 29863 | } | 29648 | } |
| 29864 | return block.addSliceElemPtr(slice, elem_index, elem_ptr_ty); | 29649 | return block.addSliceElemPtr(slice, elem_index, elem_ptr_ty); |
| 29865 | } | 29650 | } |
| ... | @@ -32891,7 +32676,7 @@ fn optRefValue(sema: *Sema, opt_val: ?Value) !Value { | ... | @@ -32891,7 +32676,7 @@ fn optRefValue(sema: *Sema, opt_val: ?Value) !Value { |
| 32891 | return Value.fromInterned(try pt.intern(.{ .opt = .{ | 32676 | return Value.fromInterned(try pt.intern(.{ .opt = .{ |
| 32892 | .ty = (try pt.optionalType(ptr_anyopaque_ty.toIntern())).toIntern(), | 32677 | .ty = (try pt.optionalType(ptr_anyopaque_ty.toIntern())).toIntern(), |
| 32893 | .val = if (opt_val) |val| (try pt.getCoerced( | 32678 | .val = if (opt_val) |val| (try pt.getCoerced( |
| 32894 | Value.fromInterned(try sema.refValue(val.toIntern())), | 32679 | Value.fromInterned(try pt.refValue(val.toIntern())), |
| 32895 | ptr_anyopaque_ty, | 32680 | ptr_anyopaque_ty, |
| 32896 | )).toIntern() else .none, | 32681 | )).toIntern() else .none, |
| 32897 | } })); | 32682 | } })); |
| ... | @@ -33667,11 +33452,7 @@ fn analyzeSlice( | ... | @@ -33667,11 +33452,7 @@ fn analyzeSlice( |
| 33667 | assert(!block.is_comptime); | 33452 | assert(!block.is_comptime); |
| 33668 | try sema.requireRuntimeBlock(block, src, runtime_src.?); | 33453 | try sema.requireRuntimeBlock(block, src, runtime_src.?); |
| 33669 | const ok = try block.addBinOp(.cmp_lte, start, end); | 33454 | const ok = try block.addBinOp(.cmp_lte, start, end); |
| 33670 | if (!pt.zcu.comp.formatted_panics) { | 33455 | try sema.addSafetyCheckCall(block, src, ok, "startGreaterThanEnd", &.{ start, end }); |
| 33671 | try sema.addSafetyCheck(block, src, ok, .start_index_greater_than_end); | | |
| 33672 | } else { | | |
| 33673 | try sema.safetyCheckFormatted(block, src, ok, "panicStartGreaterThanEnd", &.{ start, end }); | | |
| 33674 | } | | |
| 33675 | } | 33456 | } |
| 33676 | const new_len = if (by_length) | 33457 | const new_len = if (by_length) |
| 33677 | try sema.coerce(block, Type.usize, uncasted_end_opt, end_src) | 33458 | try sema.coerce(block, Type.usize, uncasted_end_opt, end_src) |
| ... | @@ -33726,11 +33507,11 @@ fn analyzeSlice( | ... | @@ -33726,11 +33507,11 @@ fn analyzeSlice( |
| 33726 | else | 33507 | else |
| 33727 | end; | 33508 | end; |
| 33728 | | 33509 | |
| 33729 | try sema.panicIndexOutOfBounds(block, src, actual_end, actual_len, .cmp_lte); | 33510 | try sema.addSafetyCheckIndexOob(block, src, actual_end, actual_len, .cmp_lte); |
| 33730 | } | 33511 | } |
| 33731 | | 33512 | |
| 33732 | // requirement: result[new_len] == slice_sentinel | 33513 | // requirement: result[new_len] == slice_sentinel |
| 33733 | try sema.panicSentinelMismatch(block, src, slice_sentinel, elem_ty, result, new_len); | 33514 | try sema.addSafetyCheckSentinelMismatch(block, src, slice_sentinel, elem_ty, result, new_len); |
| 33734 | } | 33515 | } |
| 33735 | return result; | 33516 | return result; |
| 33736 | }; | 33517 | }; |
| ... | @@ -33789,11 +33570,11 @@ fn analyzeSlice( | ... | @@ -33789,11 +33570,11 @@ fn analyzeSlice( |
| 33789 | try sema.analyzeArithmetic(block, .add, end, .one, src, end_src, end_src, true) | 33570 | try sema.analyzeArithmetic(block, .add, end, .one, src, end_src, end_src, true) |
| 33790 | else | 33571 | else |
| 33791 | end; | 33572 | end; |
| 33792 | try sema.panicIndexOutOfBounds(block, src, actual_end, len_inst, .cmp_lte); | 33573 | try sema.addSafetyCheckIndexOob(block, src, actual_end, len_inst, .cmp_lte); |
| 33793 | } | 33574 | } |
| 33794 | | 33575 | |
| 33795 | // requirement: start <= end | 33576 | // requirement: start <= end |
| 33796 | try sema.panicIndexOutOfBounds(block, src, start, end, .cmp_lte); | 33577 | try sema.addSafetyCheckIndexOob(block, src, start, end, .cmp_lte); |
| 33797 | } | 33578 | } |
| 33798 | const result = try block.addInst(.{ | 33579 | const result = try block.addInst(.{ |
| 33799 | .tag = .slice, | 33580 | .tag = .slice, |
| ... | @@ -33807,7 +33588,7 @@ fn analyzeSlice( | ... | @@ -33807,7 +33588,7 @@ fn analyzeSlice( |
| 33807 | }); | 33588 | }); |
| 33808 | if (block.wantSafety()) { | 33589 | if (block.wantSafety()) { |
| 33809 | // requirement: result[new_len] == slice_sentinel | 33590 | // requirement: result[new_len] == slice_sentinel |
| 33810 | try sema.panicSentinelMismatch(block, src, slice_sentinel, elem_ty, result, new_len); | 33591 | try sema.addSafetyCheckSentinelMismatch(block, src, slice_sentinel, elem_ty, result, new_len); |
| 33811 | } | 33592 | } |
| 33812 | return result; | 33593 | return result; |
| 33813 | } | 33594 | } |
| ... | @@ -35820,7 +35601,7 @@ pub fn resolveFnTypes(sema: *Sema, fn_ty: Type) CompileError!void { | ... | @@ -35820,7 +35601,7 @@ pub fn resolveFnTypes(sema: *Sema, fn_ty: Type) CompileError!void { |
| 35820 | Type.fromInterned(fn_ty_info.return_type).isError(zcu)) | 35601 | Type.fromInterned(fn_ty_info.return_type).isError(zcu)) |
| 35821 | { | 35602 | { |
| 35822 | // Ensure the type exists so that backends can assume that. | 35603 | // Ensure the type exists so that backends can assume that. |
| 35823 | _ = try pt.getBuiltinType("StackTrace"); | 35604 | _ = try sema.getBuiltinType("StackTrace"); |
| 35824 | } | 35605 | } |
| 35825 | | 35606 | |
| 35826 | for (0..fn_ty_info.param_types.len) |i| { | 35607 | for (0..fn_ty_info.param_types.len) |i| { |
| ... | @@ -37688,11 +37469,11 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -37688,11 +37469,11 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37688 | const only_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[0]); | 37469 | const only_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[0]); |
| 37689 | const val_val = (try sema.typeHasOnePossibleValue(only_field_ty)) orelse | 37470 | const val_val = (try sema.typeHasOnePossibleValue(only_field_ty)) orelse |
| 37690 | return null; | 37471 | return null; |
| 37691 | const only = try pt.intern(.{ .un = .{ | 37472 | const only = try pt.internUnion(.{ |
| 37692 | .ty = ty.toIntern(), | 37473 | .ty = ty.toIntern(), |
| 37693 | .tag = tag_val.toIntern(), | 37474 | .tag = tag_val.toIntern(), |
| 37694 | .val = val_val.toIntern(), | 37475 | .val = val_val.toIntern(), |
| 37695 | } }); | 37476 | }); |
| 37696 | return Value.fromInterned(only); | 37477 | return Value.fromInterned(only); |
| 37697 | }, | 37478 | }, |
| 37698 | | 37479 | |
| ... | @@ -37866,7 +37647,7 @@ pub fn analyzeAsAddressSpace( | ... | @@ -37866,7 +37647,7 @@ pub fn analyzeAsAddressSpace( |
| 37866 | ) !std.builtin.AddressSpace { | 37647 | ) !std.builtin.AddressSpace { |
| 37867 | const pt = sema.pt; | 37648 | const pt = sema.pt; |
| 37868 | const zcu = pt.zcu; | 37649 | const zcu = pt.zcu; |
| 37869 | const addrspace_ty = try pt.getBuiltinType("AddressSpace"); | 37650 | const addrspace_ty = try sema.getBuiltinType("AddressSpace"); |
| 37870 | const coerced = try sema.coerce(block, addrspace_ty, air_ref, src); | 37651 | const coerced = try sema.coerce(block, addrspace_ty, air_ref, src); |
| 37871 | const addrspace_val = try sema.resolveConstDefinedValue(block, src, coerced, .{ | 37652 | const addrspace_val = try sema.resolveConstDefinedValue(block, src, coerced, .{ |
| 37872 | .needed_comptime_reason = "address space must be comptime-known", | 37653 | .needed_comptime_reason = "address space must be comptime-known", |
| ... | @@ -38849,7 +38630,7 @@ fn analyzeUnreachable(sema: *Sema, block: *Block, src: LazySrcLoc, safety_check: | ... | @@ -38849,7 +38630,7 @@ fn analyzeUnreachable(sema: *Sema, block: *Block, src: LazySrcLoc, safety_check: |
| 38849 | sema.branch_hint = .cold; | 38630 | sema.branch_hint = .cold; |
| 38850 | } | 38631 | } |
| 38851 | | 38632 | |
| 38852 | try sema.safetyPanic(block, src, .unreach); | 38633 | try sema.safetyPanic(block, src, .reached_unreachable); |
| 38853 | } else { | 38634 | } else { |
| 38854 | _ = try block.addNoOp(.unreach); | 38635 | _ = try block.addNoOp(.unreach); |
| 38855 | } | 38636 | } |
| ... | @@ -39123,3 +38904,70 @@ const loadComptimePtr = @import("Sema/comptime_ptr_access.zig").loadComptimePtr; | ... | @@ -39123,3 +38904,70 @@ const loadComptimePtr = @import("Sema/comptime_ptr_access.zig").loadComptimePtr; |
| 39123 | const ComptimeLoadResult = @import("Sema/comptime_ptr_access.zig").ComptimeLoadResult; | 38904 | const ComptimeLoadResult = @import("Sema/comptime_ptr_access.zig").ComptimeLoadResult; |
| 39124 | const storeComptimePtr = @import("Sema/comptime_ptr_access.zig").storeComptimePtr; | 38905 | const storeComptimePtr = @import("Sema/comptime_ptr_access.zig").storeComptimePtr; |
| 39125 | const ComptimeStoreResult = @import("Sema/comptime_ptr_access.zig").ComptimeStoreResult; | 38906 | const ComptimeStoreResult = @import("Sema/comptime_ptr_access.zig").ComptimeStoreResult; |
| | 38907 | |
| | 38908 | fn getPanicInnerFn( |
| | 38909 | sema: *Sema, |
| | 38910 | block: *Block, |
| | 38911 | src: LazySrcLoc, |
| | 38912 | inner_name: []const u8, |
| | 38913 | ) !InternPool.Index { |
| | 38914 | const gpa = sema.gpa; |
| | 38915 | const pt = sema.pt; |
| | 38916 | const zcu = pt.zcu; |
| | 38917 | const ip = &zcu.intern_pool; |
| | 38918 | const outer_ty = try sema.getBuiltinType("Panic"); |
| | 38919 | const inner_name_ip = try ip.getOrPutString(gpa, pt.tid, inner_name, .no_embedded_nulls); |
| | 38920 | const opt_fn_ref = try namespaceLookupVal(sema, block, src, outer_ty.getNamespaceIndex(zcu), inner_name_ip); |
| | 38921 | const fn_ref = opt_fn_ref orelse return sema.fail(block, src, "std.builtin.Panic missing {s}", .{inner_name}); |
| | 38922 | const fn_val = try sema.resolveConstValue(block, src, fn_ref, .{ |
| | 38923 | .needed_comptime_reason = "panic handler must be comptime-known", |
| | 38924 | }); |
| | 38925 | if (fn_val.typeOf(zcu).zigTypeTag(zcu) != .@"fn") { |
| | 38926 | return sema.fail(block, src, "std.builtin.Panic.{s} is not a function", .{inner_name}); |
| | 38927 | } |
| | 38928 | // Better not to queue up function body analysis because the function might be generic, and |
| | 38929 | // the semantic analysis for the call will already queue if necessary. |
| | 38930 | return fn_val.toIntern(); |
| | 38931 | } |
| | 38932 | |
| | 38933 | fn getBuiltinType(sema: *Sema, name: []const u8) SemaError!Type { |
| | 38934 | const pt = sema.pt; |
| | 38935 | const ty_inst = try sema.getBuiltin(name); |
| | 38936 | const ty = Type.fromInterned(ty_inst.toInterned() orelse @panic("std.builtin is corrupt")); |
| | 38937 | try ty.resolveFully(pt); |
| | 38938 | return ty; |
| | 38939 | } |
| | 38940 | |
| | 38941 | fn getBuiltinInnerType( |
| | 38942 | sema: *Sema, |
| | 38943 | block: *Block, |
| | 38944 | src: LazySrcLoc, |
| | 38945 | outer_ty: Type, |
| | 38946 | /// Relative to "std.builtin". |
| | 38947 | compile_error_parent_name: []const u8, |
| | 38948 | inner_name: []const u8, |
| | 38949 | ) !Type { |
| | 38950 | const pt = sema.pt; |
| | 38951 | const zcu = pt.zcu; |
| | 38952 | const ip = &zcu.intern_pool; |
| | 38953 | const gpa = sema.gpa; |
| | 38954 | const inner_name_ip = try ip.getOrPutString(gpa, pt.tid, inner_name, .no_embedded_nulls); |
| | 38955 | const opt_nav = try sema.namespaceLookup(block, src, outer_ty.getNamespaceIndex(zcu), inner_name_ip); |
| | 38956 | const nav = opt_nav orelse return sema.fail(block, src, "std.builtin.{s} missing {s}", .{ |
| | 38957 | compile_error_parent_name, inner_name, |
| | 38958 | }); |
| | 38959 | try sema.ensureNavResolved(src, nav); |
| | 38960 | const val = Value.fromInterned(ip.getNav(nav).status.resolved.val); |
| | 38961 | const ty = val.toType(); |
| | 38962 | try ty.resolveFully(pt); |
| | 38963 | return ty; |
| | 38964 | } |
| | 38965 | |
| | 38966 | fn getBuiltin(sema: *Sema, name: []const u8) SemaError!Air.Inst.Ref { |
| | 38967 | const pt = sema.pt; |
| | 38968 | const zcu = pt.zcu; |
| | 38969 | const ip = &zcu.intern_pool; |
| | 38970 | const nav = try pt.getBuiltinNav(name); |
| | 38971 | try pt.ensureCauAnalyzed(ip.getNav(nav).analysis_owner.unwrap().?); |
| | 38972 | return Air.internedToRef(ip.getNav(nav).status.resolved.val); |
| | 38973 | } |