| ... | @@ -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; |
| ... | @@ -5830,8 +5830,6 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -5830,8 +5830,6 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 5830 | const src = block.nodeOffset(inst_data.src_node); | 5830 | const src = block.nodeOffset(inst_data.src_node); |
| 5831 | const msg_inst = try sema.resolveInst(inst_data.operand); | 5831 | const msg_inst = try sema.resolveInst(inst_data.operand); |
| 5832 | | 5832 | |
| 5833 | // `panicWithMsg` would perform this coercion for us, but we can get a better | | |
| 5834 | // source location if we do it here. | | |
| 5835 | const coerced_msg = try sema.coerce(block, Type.slice_const_u8, msg_inst, block.builtinCallArgSrc(inst_data.src_node, 0)); | 5833 | const coerced_msg = try sema.coerce(block, Type.slice_const_u8, msg_inst, block.builtinCallArgSrc(inst_data.src_node, 0)); |
| 5836 | | 5834 | |
| 5837 | if (block.is_comptime) { | 5835 | if (block.is_comptime) { |
| ... | @@ -5844,7 +5842,7 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -5844,7 +5842,7 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 5844 | sema.branch_hint = .cold; | 5842 | sema.branch_hint = .cold; |
| 5845 | } | 5843 | } |
| 5846 | | 5844 | |
| 5847 | try sema.panicWithMsg(block, src, coerced_msg, .@"@panic"); | 5845 | try callPanic(sema, block, src, .explicit_call, coerced_msg, .@"@panic"); |
| 5848 | } | 5846 | } |
| 5849 | | 5847 | |
| 5850 | fn zirTrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 5848 | fn zirTrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| ... | @@ -7325,6 +7323,31 @@ fn callBuiltin( | ... | @@ -7325,6 +7323,31 @@ fn callBuiltin( |
| 7325 | ); | 7323 | ); |
| 7326 | } | 7324 | } |
| 7327 | | 7325 | |
| | 7326 | const PanicCauseTag = @typeInfo(std.builtin.PanicCause).@"union".tag_type.?; |
| | 7327 | |
| | 7328 | fn callPanic( |
| | 7329 | sema: *Sema, |
| | 7330 | block: *Block, |
| | 7331 | call_src: LazySrcLoc, |
| | 7332 | tag: PanicCauseTag, |
| | 7333 | payload: Air.Inst.Ref, |
| | 7334 | call_operation: CallOperation, |
| | 7335 | ) !void { |
| | 7336 | const pt = sema.pt; |
| | 7337 | if (!pt.zcu.backendSupportsFeature(.panic_fn)) { |
| | 7338 | _ = try block.addNoOp(.trap); |
| | 7339 | return; |
| | 7340 | } |
| | 7341 | const panic_cause_ty = try pt.getBuiltinType("PanicCause"); |
| | 7342 | const panic_cause = try block.addUnionInit(panic_cause_ty, @intFromEnum(tag), payload); |
| | 7343 | const panic_fn = try pt.getBuiltin("panic"); |
| | 7344 | const err_return_trace = try sema.getErrorReturnTrace(block); |
| | 7345 | const opt_usize_ty = try pt.optionalType(.usize_type); |
| | 7346 | const null_usize = try pt.nullValue(opt_usize_ty); |
| | 7347 | const args: [3]Air.Inst.Ref = .{ panic_cause, err_return_trace, Air.internedToRef(null_usize) }; |
| | 7348 | try sema.callBuiltin(block, call_src, panic_fn, .auto, &args, call_operation); |
| | 7349 | } |
| | 7350 | |
| 7328 | const CallOperation = enum { | 7351 | const CallOperation = enum { |
| 7329 | call, | 7352 | call, |
| 7330 | @"@call", | 7353 | @"@call", |
| ... | @@ -9327,7 +9350,7 @@ fn analyzeErrUnionPayload( | ... | @@ -9327,7 +9350,7 @@ fn analyzeErrUnionPayload( |
| 9327 | if (safety_check and block.wantSafety() and | 9350 | if (safety_check and block.wantSafety() and |
| 9328 | !err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) | 9351 | !err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) |
| 9329 | { | 9352 | { |
| 9330 | try sema.panicUnwrapError(block, src, operand, .unwrap_errunion_err, .is_non_err); | 9353 | try sema.addSafetyCheckUnwrapError(block, src, operand, .unwrap_errunion_err, .is_non_err); |
| 9331 | } | 9354 | } |
| 9332 | | 9355 | |
| 9333 | return block.addTyOp(.unwrap_errunion_payload, payload_ty, operand); | 9356 | return block.addTyOp(.unwrap_errunion_payload, payload_ty, operand); |
| ... | @@ -9411,7 +9434,7 @@ fn analyzeErrUnionPayloadPtr( | ... | @@ -9411,7 +9434,7 @@ fn analyzeErrUnionPayloadPtr( |
| 9411 | if (safety_check and block.wantSafety() and | 9434 | if (safety_check and block.wantSafety() and |
| 9412 | !err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) | 9435 | !err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) |
| 9413 | { | 9436 | { |
| 9414 | try sema.panicUnwrapError(block, src, operand, .unwrap_errunion_err_ptr, .is_non_err_ptr); | 9437 | try sema.addSafetyCheckUnwrapError(block, src, operand, .unwrap_errunion_err_ptr, .is_non_err_ptr); |
| 9415 | } | 9438 | } |
| 9416 | | 9439 | |
| 9417 | if (initializing) { | 9440 | if (initializing) { |
| ... | @@ -14190,7 +14213,6 @@ fn maybeErrorUnwrap( | ... | @@ -14190,7 +14213,6 @@ fn maybeErrorUnwrap( |
| 14190 | ) !bool { | 14213 | ) !bool { |
| 14191 | const pt = sema.pt; | 14214 | const pt = sema.pt; |
| 14192 | const zcu = pt.zcu; | 14215 | const zcu = pt.zcu; |
| 14193 | if (!zcu.backendSupportsFeature(.panic_unwrap_error)) return false; | | |
| 14194 | | 14216 | |
| 14195 | const tags = sema.code.instructions.items(.tag); | 14217 | const tags = sema.code.instructions.items(.tag); |
| 14196 | for (body) |inst| { | 14218 | for (body) |inst| { |
| ... | @@ -14223,25 +14245,13 @@ fn maybeErrorUnwrap( | ... | @@ -14223,25 +14245,13 @@ fn maybeErrorUnwrap( |
| 14223 | .as_node => try sema.zirAsNode(block, inst), | 14245 | .as_node => try sema.zirAsNode(block, inst), |
| 14224 | .field_val => try sema.zirFieldVal(block, inst), | 14246 | .field_val => try sema.zirFieldVal(block, inst), |
| 14225 | .@"unreachable" => { | 14247 | .@"unreachable" => { |
| 14226 | if (!zcu.comp.formatted_panics) { | 14248 | try callPanic(sema, block, operand_src, .unwrap_error, operand, .@"safety check"); |
| 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; | 14249 | return true; |
| 14236 | }, | 14250 | }, |
| 14237 | .panic => { | 14251 | .panic => { |
| 14238 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 14252 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 14239 | const msg_inst = try sema.resolveInst(inst_data.operand); | 14253 | const msg_inst = try sema.resolveInst(inst_data.operand); |
| 14240 | | 14254 | try callPanic(sema, block, operand_src, .explicit_call, msg_inst, .@"@panic"); |
| 14241 | const panic_fn = try pt.getBuiltin("panic"); | | |
| 14242 | const err_return_trace = try sema.getErrorReturnTrace(block); | | |
| 14243 | 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"); | | |
| 14245 | return true; | 14255 | return true; |
| 14246 | }, | 14256 | }, |
| 14247 | else => unreachable, | 14257 | else => unreachable, |
| ... | @@ -17388,9 +17398,6 @@ fn analyzeArithmetic( | ... | @@ -17388,9 +17398,6 @@ fn analyzeArithmetic( |
| 17388 | | 17398 | |
| 17389 | if (block.wantSafety() and want_safety and scalar_tag == .int) { | 17399 | if (block.wantSafety() and want_safety and scalar_tag == .int) { |
| 17390 | if (zcu.backendSupportsFeature(.safety_checked_instructions)) { | 17400 | if (zcu.backendSupportsFeature(.safety_checked_instructions)) { |
| 17391 | if (air_tag != air_tag_safe) { | | |
| 17392 | _ = try sema.preparePanicId(block, src, .integer_overflow); | | |
| 17393 | } | | |
| 17394 | return block.addBinOp(air_tag_safe, casted_lhs, casted_rhs); | 17401 | return block.addBinOp(air_tag_safe, casted_lhs, casted_rhs); |
| 17395 | } else { | 17402 | } else { |
| 17396 | const maybe_op_ov: ?Air.Inst.Tag = switch (air_tag) { | 17403 | const maybe_op_ov: ?Air.Inst.Tag = switch (air_tag) { |
| ... | @@ -18319,29 +18326,14 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18319,29 +18326,14 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18319 | .undefined, | 18326 | .undefined, |
| 18320 | .null, | 18327 | .null, |
| 18321 | .enum_literal, | 18328 | .enum_literal, |
| 18322 | => |type_info_tag| return Air.internedToRef((try pt.intern(.{ .un = .{ | 18329 | => |type_info_tag| return Air.internedToRef((try pt.internUnion(.{ |
| 18323 | .ty = type_info_ty.toIntern(), | 18330 | .ty = type_info_ty.toIntern(), |
| 18324 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(type_info_tag))).toIntern(), | 18331 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(type_info_tag))).toIntern(), |
| 18325 | .val = .void_value, | 18332 | .val = .void_value, |
| 18326 | } }))), | 18333 | }))), |
| 18327 | .@"fn" => { | 18334 | .@"fn" => { |
| 18328 | const fn_info_nav = try sema.namespaceLookup( | 18335 | const fn_info_ty = try getInnerType(sema, block, src, type_info_ty, "Fn"); |
| 18329 | block, | 18336 | const param_info_ty = try getInnerType(sema, block, src, fn_info_ty, "Param"); |
| 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 | | | |
| 18337 | const param_info_nav = try sema.namespaceLookup( | | |
| 18338 | block, | | |
| 18339 | src, | | |
| 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 | | 18337 | |
| 18346 | const func_ty_info = zcu.typeToFunc(ty).?; | 18338 | const func_ty_info = zcu.typeToFunc(ty).?; |
| 18347 | const param_vals = try sema.arena.alloc(InternPool.Index, func_ty_info.param_types.len); | 18339 | const param_vals = try sema.arena.alloc(InternPool.Index, func_ty_info.param_types.len); |
| ... | @@ -18425,25 +18417,17 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18425,25 +18417,17 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18425 | // args: []const Fn.Param, | 18417 | // args: []const Fn.Param, |
| 18426 | args_val, | 18418 | args_val, |
| 18427 | }; | 18419 | }; |
| 18428 | return Air.internedToRef((try pt.intern(.{ .un = .{ | 18420 | return Air.internedToRef((try pt.internUnion(.{ |
| 18429 | .ty = type_info_ty.toIntern(), | 18421 | .ty = type_info_ty.toIntern(), |
| 18430 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.@"fn"))).toIntern(), | 18422 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.@"fn"))).toIntern(), |
| 18431 | .val = try pt.intern(.{ .aggregate = .{ | 18423 | .val = try pt.intern(.{ .aggregate = .{ |
| 18432 | .ty = fn_info_ty.toIntern(), | 18424 | .ty = fn_info_ty.toIntern(), |
| 18433 | .storage = .{ .elems = &field_values }, | 18425 | .storage = .{ .elems = &field_values }, |
| 18434 | } }), | 18426 | } }), |
| 18435 | } }))); | 18427 | }))); |
| 18436 | }, | 18428 | }, |
| 18437 | .int => { | 18429 | .int => { |
| 18438 | const int_info_nav = try sema.namespaceLookup( | 18430 | const int_info_ty = try getInnerType(sema, block, src, type_info_ty, "Int"); |
| 18439 | block, | | |
| 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"); | 18431 | const signedness_ty = try pt.getBuiltinType("Signedness"); |
| 18448 | const info = ty.intInfo(zcu); | 18432 | const info = ty.intInfo(zcu); |
| 18449 | const field_values = .{ | 18433 | const field_values = .{ |
| ... | @@ -18452,37 +18436,30 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18452,37 +18436,30 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18452 | // bits: u16, | 18436 | // bits: u16, |
| 18453 | (try pt.intValue(Type.u16, info.bits)).toIntern(), | 18437 | (try pt.intValue(Type.u16, info.bits)).toIntern(), |
| 18454 | }; | 18438 | }; |
| 18455 | return Air.internedToRef((try pt.intern(.{ .un = .{ | 18439 | return Air.internedToRef((try pt.internUnion(.{ |
| 18456 | .ty = type_info_ty.toIntern(), | 18440 | .ty = type_info_ty.toIntern(), |
| 18457 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.int))).toIntern(), | 18441 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.int))).toIntern(), |
| 18458 | .val = try pt.intern(.{ .aggregate = .{ | 18442 | .val = try pt.intern(.{ .aggregate = .{ |
| 18459 | .ty = int_info_ty.toIntern(), | 18443 | .ty = int_info_ty.toIntern(), |
| 18460 | .storage = .{ .elems = &field_values }, | 18444 | .storage = .{ .elems = &field_values }, |
| 18461 | } }), | 18445 | } }), |
| 18462 | } }))); | 18446 | }))); |
| 18463 | }, | 18447 | }, |
| 18464 | .float => { | 18448 | .float => { |
| 18465 | const float_info_nav = try sema.namespaceLookup( | 18449 | const float_info_ty = try getInnerType(sema, block, src, type_info_ty, "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 | | 18450 | |
| 18474 | const field_vals = .{ | 18451 | const field_vals = .{ |
| 18475 | // bits: u16, | 18452 | // bits: u16, |
| 18476 | (try pt.intValue(Type.u16, ty.bitSize(zcu))).toIntern(), | 18453 | (try pt.intValue(Type.u16, ty.bitSize(zcu))).toIntern(), |
| 18477 | }; | 18454 | }; |
| 18478 | return Air.internedToRef((try pt.intern(.{ .un = .{ | 18455 | return Air.internedToRef((try pt.internUnion(.{ |
| 18479 | .ty = type_info_ty.toIntern(), | 18456 | .ty = type_info_ty.toIntern(), |
| 18480 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.float))).toIntern(), | 18457 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.float))).toIntern(), |
| 18481 | .val = try pt.intern(.{ .aggregate = .{ | 18458 | .val = try pt.intern(.{ .aggregate = .{ |
| 18482 | .ty = float_info_ty.toIntern(), | 18459 | .ty = float_info_ty.toIntern(), |
| 18483 | .storage = .{ .elems = &field_vals }, | 18460 | .storage = .{ .elems = &field_vals }, |
| 18484 | } }), | 18461 | } }), |
| 18485 | } }))); | 18462 | }))); |
| 18486 | }, | 18463 | }, |
| 18487 | .pointer => { | 18464 | .pointer => { |
| 18488 | const info = ty.ptrInfo(zcu); | 18465 | const info = ty.ptrInfo(zcu); |
| ... | @@ -18492,26 +18469,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18492,26 +18469,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18492 | try Type.fromInterned(info.child).lazyAbiAlignment(pt); | 18469 | try Type.fromInterned(info.child).lazyAbiAlignment(pt); |
| 18493 | | 18470 | |
| 18494 | const addrspace_ty = try pt.getBuiltinType("AddressSpace"); | 18471 | const addrspace_ty = try pt.getBuiltinType("AddressSpace"); |
| 18495 | const pointer_ty = t: { | 18472 | const pointer_ty = try getInnerType(sema, block, src, type_info_ty, "Pointer"); |
| 18496 | const nav = try sema.namespaceLookup( | 18473 | const ptr_size_ty = try getInnerType(sema, block, src, pointer_ty, "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 | | 18474 | |
| 18516 | const field_values = .{ | 18475 | const field_values = .{ |
| 18517 | // size: Size, | 18476 | // size: Size, |
| ... | @@ -18534,26 +18493,17 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18534,26 +18493,17 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18534 | else => Value.fromInterned(info.sentinel), | 18493 | else => Value.fromInterned(info.sentinel), |
| 18535 | })).toIntern(), | 18494 | })).toIntern(), |
| 18536 | }; | 18495 | }; |
| 18537 | return Air.internedToRef((try pt.intern(.{ .un = .{ | 18496 | return Air.internedToRef((try pt.internUnion(.{ |
| 18538 | .ty = type_info_ty.toIntern(), | 18497 | .ty = type_info_ty.toIntern(), |
| 18539 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.pointer))).toIntern(), | 18498 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.pointer))).toIntern(), |
| 18540 | .val = try pt.intern(.{ .aggregate = .{ | 18499 | .val = try pt.intern(.{ .aggregate = .{ |
| 18541 | .ty = pointer_ty.toIntern(), | 18500 | .ty = pointer_ty.toIntern(), |
| 18542 | .storage = .{ .elems = &field_values }, | 18501 | .storage = .{ .elems = &field_values }, |
| 18543 | } }), | 18502 | } }), |
| 18544 | } }))); | 18503 | }))); |
| 18545 | }, | 18504 | }, |
| 18546 | .array => { | 18505 | .array => { |
| 18547 | const array_field_ty = t: { | 18506 | const array_field_ty = try getInnerType(sema, block, src, type_info_ty, "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 | | 18507 | |
| 18558 | const info = ty.arrayInfo(zcu); | 18508 | const info = ty.arrayInfo(zcu); |
| 18559 | const field_values = .{ | 18509 | const field_values = .{ |
| ... | @@ -18564,26 +18514,17 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18564,26 +18514,17 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18564 | // sentinel: ?*const anyopaque, | 18514 | // sentinel: ?*const anyopaque, |
| 18565 | (try sema.optRefValue(info.sentinel)).toIntern(), | 18515 | (try sema.optRefValue(info.sentinel)).toIntern(), |
| 18566 | }; | 18516 | }; |
| 18567 | return Air.internedToRef((try pt.intern(.{ .un = .{ | 18517 | return Air.internedToRef((try pt.internUnion(.{ |
| 18568 | .ty = type_info_ty.toIntern(), | 18518 | .ty = type_info_ty.toIntern(), |
| 18569 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.array))).toIntern(), | 18519 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.array))).toIntern(), |
| 18570 | .val = try pt.intern(.{ .aggregate = .{ | 18520 | .val = try pt.intern(.{ .aggregate = .{ |
| 18571 | .ty = array_field_ty.toIntern(), | 18521 | .ty = array_field_ty.toIntern(), |
| 18572 | .storage = .{ .elems = &field_values }, | 18522 | .storage = .{ .elems = &field_values }, |
| 18573 | } }), | 18523 | } }), |
| 18574 | } }))); | 18524 | }))); |
| 18575 | }, | 18525 | }, |
| 18576 | .vector => { | 18526 | .vector => { |
| 18577 | const vector_field_ty = t: { | 18527 | const vector_field_ty = try getInnerType(sema, block, src, type_info_ty, "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 | | 18528 | |
| 18588 | const info = ty.arrayInfo(zcu); | 18529 | const info = ty.arrayInfo(zcu); |
| 18589 | const field_values = .{ | 18530 | const field_values = .{ |
| ... | @@ -18592,52 +18533,34 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18592,52 +18533,34 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18592 | // child: type, | 18533 | // child: type, |
| 18593 | info.elem_type.toIntern(), | 18534 | info.elem_type.toIntern(), |
| 18594 | }; | 18535 | }; |
| 18595 | return Air.internedToRef((try pt.intern(.{ .un = .{ | 18536 | return Air.internedToRef((try pt.internUnion(.{ |
| 18596 | .ty = type_info_ty.toIntern(), | 18537 | .ty = type_info_ty.toIntern(), |
| 18597 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.vector))).toIntern(), | 18538 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.vector))).toIntern(), |
| 18598 | .val = try pt.intern(.{ .aggregate = .{ | 18539 | .val = try pt.intern(.{ .aggregate = .{ |
| 18599 | .ty = vector_field_ty.toIntern(), | 18540 | .ty = vector_field_ty.toIntern(), |
| 18600 | .storage = .{ .elems = &field_values }, | 18541 | .storage = .{ .elems = &field_values }, |
| 18601 | } }), | 18542 | } }), |
| 18602 | } }))); | 18543 | }))); |
| 18603 | }, | 18544 | }, |
| 18604 | .optional => { | 18545 | .optional => { |
| 18605 | const optional_field_ty = t: { | 18546 | const optional_field_ty = try getInnerType(sema, block, src, type_info_ty, "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 | | 18547 | |
| 18616 | const field_values = .{ | 18548 | const field_values = .{ |
| 18617 | // child: type, | 18549 | // child: type, |
| 18618 | ty.optionalChild(zcu).toIntern(), | 18550 | ty.optionalChild(zcu).toIntern(), |
| 18619 | }; | 18551 | }; |
| 18620 | return Air.internedToRef((try pt.intern(.{ .un = .{ | 18552 | return Air.internedToRef((try pt.internUnion(.{ |
| 18621 | .ty = type_info_ty.toIntern(), | 18553 | .ty = type_info_ty.toIntern(), |
| 18622 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.optional))).toIntern(), | 18554 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.optional))).toIntern(), |
| 18623 | .val = try pt.intern(.{ .aggregate = .{ | 18555 | .val = try pt.intern(.{ .aggregate = .{ |
| 18624 | .ty = optional_field_ty.toIntern(), | 18556 | .ty = optional_field_ty.toIntern(), |
| 18625 | .storage = .{ .elems = &field_values }, | 18557 | .storage = .{ .elems = &field_values }, |
| 18626 | } }), | 18558 | } }), |
| 18627 | } }))); | 18559 | }))); |
| 18628 | }, | 18560 | }, |
| 18629 | .error_set => { | 18561 | .error_set => { |
| 18630 | // Get the Error type | 18562 | // Get the Error type |
| 18631 | const error_field_ty = t: { | 18563 | const error_field_ty = try getInnerType(sema, block, src, type_info_ty, "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 | | 18564 | |
| 18642 | // Build our list of Error values | 18565 | // Build our list of Error values |
| 18643 | // Optional value is only null if anyerror | 18566 | // Optional value is only null if anyerror |
| ... | @@ -18726,23 +18649,14 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18726,23 +18649,14 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18726 | } }); | 18649 | } }); |
| 18727 | | 18650 | |
| 18728 | // Construct Type{ .error_set = errors_val } | 18651 | // Construct Type{ .error_set = errors_val } |
| 18729 | return Air.internedToRef((try pt.intern(.{ .un = .{ | 18652 | return Air.internedToRef((try pt.internUnion(.{ |
| 18730 | .ty = type_info_ty.toIntern(), | 18653 | .ty = type_info_ty.toIntern(), |
| 18731 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.error_set))).toIntern(), | 18654 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.error_set))).toIntern(), |
| 18732 | .val = errors_val, | 18655 | .val = errors_val, |
| 18733 | } }))); | 18656 | }))); |
| 18734 | }, | 18657 | }, |
| 18735 | .error_union => { | 18658 | .error_union => { |
| 18736 | const error_union_field_ty = t: { | 18659 | const error_union_field_ty = try getInnerType(sema, block, src, type_info_ty, "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 | | 18660 | |
| 18747 | const field_values = .{ | 18661 | const field_values = .{ |
| 18748 | // error_set: type, | 18662 | // error_set: type, |
| ... | @@ -18750,28 +18664,19 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18750,28 +18664,19 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18750 | // payload: type, | 18664 | // payload: type, |
| 18751 | ty.errorUnionPayload(zcu).toIntern(), | 18665 | ty.errorUnionPayload(zcu).toIntern(), |
| 18752 | }; | 18666 | }; |
| 18753 | return Air.internedToRef((try pt.intern(.{ .un = .{ | 18667 | return Air.internedToRef((try pt.internUnion(.{ |
| 18754 | .ty = type_info_ty.toIntern(), | 18668 | .ty = type_info_ty.toIntern(), |
| 18755 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.error_union))).toIntern(), | 18669 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.error_union))).toIntern(), |
| 18756 | .val = try pt.intern(.{ .aggregate = .{ | 18670 | .val = try pt.intern(.{ .aggregate = .{ |
| 18757 | .ty = error_union_field_ty.toIntern(), | 18671 | .ty = error_union_field_ty.toIntern(), |
| 18758 | .storage = .{ .elems = &field_values }, | 18672 | .storage = .{ .elems = &field_values }, |
| 18759 | } }), | 18673 | } }), |
| 18760 | } }))); | 18674 | }))); |
| 18761 | }, | 18675 | }, |
| 18762 | .@"enum" => { | 18676 | .@"enum" => { |
| 18763 | const is_exhaustive = Value.makeBool(ip.loadEnumType(ty.toIntern()).tag_mode != .nonexhaustive); | 18677 | const is_exhaustive = Value.makeBool(ip.loadEnumType(ty.toIntern()).tag_mode != .nonexhaustive); |
| 18764 | | 18678 | |
| 18765 | const enum_field_ty = t: { | 18679 | const enum_field_ty = try getInnerType(sema, block, src, type_info_ty, "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 | | 18680 | |
| 18776 | const enum_field_vals = try sema.arena.alloc(InternPool.Index, ip.loadEnumType(ty.toIntern()).names.len); | 18681 | 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| { | 18682 | for (enum_field_vals, 0..) |*field_val, tag_index| { |
| ... | @@ -18858,16 +18763,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18858,16 +18763,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18858 | | 18763 | |
| 18859 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ip.loadEnumType(ty.toIntern()).namespace.toOptional()); | 18764 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ip.loadEnumType(ty.toIntern()).namespace.toOptional()); |
| 18860 | | 18765 | |
| 18861 | const type_enum_ty = t: { | 18766 | const type_enum_ty = try getInnerType(sema, block, src, type_info_ty, "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 | | 18767 | |
| 18872 | const field_values = .{ | 18768 | const field_values = .{ |
| 18873 | // tag_type: type, | 18769 | // tag_type: type, |
| ... | @@ -18879,37 +18775,18 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18879,37 +18775,18 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18879 | // is_exhaustive: bool, | 18775 | // is_exhaustive: bool, |
| 18880 | is_exhaustive.toIntern(), | 18776 | is_exhaustive.toIntern(), |
| 18881 | }; | 18777 | }; |
| 18882 | return Air.internedToRef((try pt.intern(.{ .un = .{ | 18778 | return Air.internedToRef((try pt.internUnion(.{ |
| 18883 | .ty = type_info_ty.toIntern(), | 18779 | .ty = type_info_ty.toIntern(), |
| 18884 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.@"enum"))).toIntern(), | 18780 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.@"enum"))).toIntern(), |
| 18885 | .val = try pt.intern(.{ .aggregate = .{ | 18781 | .val = try pt.intern(.{ .aggregate = .{ |
| 18886 | .ty = type_enum_ty.toIntern(), | 18782 | .ty = type_enum_ty.toIntern(), |
| 18887 | .storage = .{ .elems = &field_values }, | 18783 | .storage = .{ .elems = &field_values }, |
| 18888 | } }), | 18784 | } }), |
| 18889 | } }))); | 18785 | }))); |
| 18890 | }, | 18786 | }, |
| 18891 | .@"union" => { | 18787 | .@"union" => { |
| 18892 | const type_union_ty = t: { | 18788 | const type_union_ty = try getInnerType(sema, block, src, type_info_ty, "Union"); |
| 18893 | const nav = try sema.namespaceLookup( | 18789 | const union_field_ty = try getInnerType(sema, block, src, type_info_ty, "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 | | 18790 | |
| 18914 | try ty.resolveLayout(pt); // Getting alignment requires type layout | 18791 | try ty.resolveLayout(pt); // Getting alignment requires type layout |
| 18915 | const union_obj = zcu.typeToUnion(ty).?; | 18792 | const union_obj = zcu.typeToUnion(ty).?; |
| ... | @@ -19004,16 +18881,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -19004,16 +18881,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, | 18881 | .val = if (ty.unionTagType(zcu)) |tag_ty| tag_ty.toIntern() else .none, |
| 19005 | } }); | 18882 | } }); |
| 19006 | | 18883 | |
| 19007 | const container_layout_ty = t: { | 18884 | const container_layout_ty = try getBuiltinInnerType(sema, block, src, "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 | | 18885 | |
| 19018 | const field_values = .{ | 18886 | const field_values = .{ |
| 19019 | // layout: ContainerLayout, | 18887 | // layout: ContainerLayout, |
| ... | @@ -19026,37 +18894,18 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -19026,37 +18894,18 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 19026 | // decls: []const Declaration, | 18894 | // decls: []const Declaration, |
| 19027 | decls_val, | 18895 | decls_val, |
| 19028 | }; | 18896 | }; |
| 19029 | return Air.internedToRef((try pt.intern(.{ .un = .{ | 18897 | return Air.internedToRef((try pt.internUnion(.{ |
| 19030 | .ty = type_info_ty.toIntern(), | 18898 | .ty = type_info_ty.toIntern(), |
| 19031 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.@"union"))).toIntern(), | 18899 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.@"union"))).toIntern(), |
| 19032 | .val = try pt.intern(.{ .aggregate = .{ | 18900 | .val = try pt.intern(.{ .aggregate = .{ |
| 19033 | .ty = type_union_ty.toIntern(), | 18901 | .ty = type_union_ty.toIntern(), |
| 19034 | .storage = .{ .elems = &field_values }, | 18902 | .storage = .{ .elems = &field_values }, |
| 19035 | } }), | 18903 | } }), |
| 19036 | } }))); | 18904 | }))); |
| 19037 | }, | 18905 | }, |
| 19038 | .@"struct" => { | 18906 | .@"struct" => { |
| 19039 | const type_struct_ty = t: { | 18907 | const type_struct_ty = try getInnerType(sema, block, src, type_info_ty, "Struct"); |
| 19040 | const nav = try sema.namespaceLookup( | 18908 | const struct_field_ty = try getInnerType(sema, block, src, type_info_ty, "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 | | 18909 | |
| 19061 | try ty.resolveLayout(pt); // Getting alignment requires type layout | 18910 | try ty.resolveLayout(pt); // Getting alignment requires type layout |
| 19062 | | 18911 | |
| ... | @@ -19233,16 +19082,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -19233,16 +19082,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 19233 | } else .none, | 19082 | } else .none, |
| 19234 | } }); | 19083 | } }); |
| 19235 | | 19084 | |
| 19236 | const container_layout_ty = t: { | 19085 | const container_layout_ty = try getInnerType(sema, block, src, type_info_ty, "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 | | 19086 | |
| 19247 | const layout = ty.containerLayout(zcu); | 19087 | const layout = ty.containerLayout(zcu); |
| 19248 | | 19088 | |
| ... | @@ -19258,26 +19098,17 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -19258,26 +19098,17 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 19258 | // is_tuple: bool, | 19098 | // is_tuple: bool, |
| 19259 | Value.makeBool(ty.isTuple(zcu)).toIntern(), | 19099 | Value.makeBool(ty.isTuple(zcu)).toIntern(), |
| 19260 | }; | 19100 | }; |
| 19261 | return Air.internedToRef((try pt.intern(.{ .un = .{ | 19101 | return Air.internedToRef((try pt.internUnion(.{ |
| 19262 | .ty = type_info_ty.toIntern(), | 19102 | .ty = type_info_ty.toIntern(), |
| 19263 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.@"struct"))).toIntern(), | 19103 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.@"struct"))).toIntern(), |
| 19264 | .val = try pt.intern(.{ .aggregate = .{ | 19104 | .val = try pt.intern(.{ .aggregate = .{ |
| 19265 | .ty = type_struct_ty.toIntern(), | 19105 | .ty = type_struct_ty.toIntern(), |
| 19266 | .storage = .{ .elems = &field_values }, | 19106 | .storage = .{ .elems = &field_values }, |
| 19267 | } }), | 19107 | } }), |
| 19268 | } }))); | 19108 | }))); |
| 19269 | }, | 19109 | }, |
| 19270 | .@"opaque" => { | 19110 | .@"opaque" => { |
| 19271 | const type_opaque_ty = t: { | 19111 | const type_opaque_ty = try getInnerType(sema, block, src, type_info_ty, "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 | | 19112 | |
| 19282 | try ty.resolveFields(pt); | 19113 | try ty.resolveFields(pt); |
| 19283 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespace(zcu)); | 19114 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespace(zcu)); |
| ... | @@ -19286,14 +19117,14 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -19286,14 +19117,14 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 19286 | // decls: []const Declaration, | 19117 | // decls: []const Declaration, |
| 19287 | decls_val, | 19118 | decls_val, |
| 19288 | }; | 19119 | }; |
| 19289 | return Air.internedToRef((try pt.intern(.{ .un = .{ | 19120 | return Air.internedToRef((try pt.internUnion(.{ |
| 19290 | .ty = type_info_ty.toIntern(), | 19121 | .ty = type_info_ty.toIntern(), |
| 19291 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.@"opaque"))).toIntern(), | 19122 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.@"opaque"))).toIntern(), |
| 19292 | .val = try pt.intern(.{ .aggregate = .{ | 19123 | .val = try pt.intern(.{ .aggregate = .{ |
| 19293 | .ty = type_opaque_ty.toIntern(), | 19124 | .ty = type_opaque_ty.toIntern(), |
| 19294 | .storage = .{ .elems = &field_values }, | 19125 | .storage = .{ .elems = &field_values }, |
| 19295 | } }), | 19126 | } }), |
| 19296 | } }))); | 19127 | }))); |
| 19297 | }, | 19128 | }, |
| 19298 | .frame => return sema.failWithUseOfAsync(block, src), | 19129 | .frame => return sema.failWithUseOfAsync(block, src), |
| 19299 | .@"anyframe" => return sema.failWithUseOfAsync(block, src), | 19130 | .@"anyframe" => return sema.failWithUseOfAsync(block, src), |
| ... | @@ -19309,19 +19140,9 @@ fn typeInfoDecls( | ... | @@ -19309,19 +19140,9 @@ fn typeInfoDecls( |
| 19309 | ) CompileError!InternPool.Index { | 19140 | ) CompileError!InternPool.Index { |
| 19310 | const pt = sema.pt; | 19141 | const pt = sema.pt; |
| 19311 | const zcu = pt.zcu; | 19142 | const zcu = pt.zcu; |
| 19312 | const ip = &zcu.intern_pool; | | |
| 19313 | const gpa = sema.gpa; | 19143 | const gpa = sema.gpa; |
| 19314 | | 19144 | |
| 19315 | const declaration_ty = t: { | 19145 | const declaration_ty = try getInnerType(sema, block, src, type_info_ty, "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 | | 19146 | |
| 19326 | var decl_vals = std.ArrayList(InternPool.Index).init(gpa); | 19147 | var decl_vals = std.ArrayList(InternPool.Index).init(gpa); |
| 19327 | defer decl_vals.deinit(); | 19148 | defer decl_vals.deinit(); |
| ... | @@ -20809,11 +20630,11 @@ fn unionInit( | ... | @@ -20809,11 +20630,11 @@ fn unionInit( |
| 20809 | if (try sema.resolveValue(init)) |init_val| { | 20630 | if (try sema.resolveValue(init)) |init_val| { |
| 20810 | const tag_ty = union_ty.unionTagTypeHypothetical(zcu); | 20631 | const tag_ty = union_ty.unionTagTypeHypothetical(zcu); |
| 20811 | const tag_val = try pt.enumValueFieldIndex(tag_ty, field_index); | 20632 | const tag_val = try pt.enumValueFieldIndex(tag_ty, field_index); |
| 20812 | return Air.internedToRef((try pt.intern(.{ .un = .{ | 20633 | return Air.internedToRef((try pt.internUnion(.{ |
| 20813 | .ty = union_ty.toIntern(), | 20634 | .ty = union_ty.toIntern(), |
| 20814 | .tag = tag_val.toIntern(), | 20635 | .tag = tag_val.toIntern(), |
| 20815 | .val = init_val.toIntern(), | 20636 | .val = init_val.toIntern(), |
| 20816 | } }))); | 20637 | }))); |
| 20817 | } | 20638 | } |
| 20818 | | 20639 | |
| 20819 | try sema.requireRuntimeBlock(block, init_src, null); | 20640 | try sema.requireRuntimeBlock(block, init_src, null); |
| ... | @@ -20949,11 +20770,11 @@ fn zirStructInit( | ... | @@ -20949,11 +20770,11 @@ fn zirStructInit( |
| 20949 | const init_inst = try sema.coerce(block, field_ty, uncoerced_init_inst, field_src); | 20770 | const init_inst = try sema.coerce(block, field_ty, uncoerced_init_inst, field_src); |
| 20950 | | 20771 | |
| 20951 | if (try sema.resolveValue(init_inst)) |val| { | 20772 | if (try sema.resolveValue(init_inst)) |val| { |
| 20952 | const struct_val = Value.fromInterned(try pt.intern(.{ .un = .{ | 20773 | const struct_val = Value.fromInterned(try pt.internUnion(.{ |
| 20953 | .ty = resolved_ty.toIntern(), | 20774 | .ty = resolved_ty.toIntern(), |
| 20954 | .tag = tag_val.toIntern(), | 20775 | .tag = tag_val.toIntern(), |
| 20955 | .val = val.toIntern(), | 20776 | .val = val.toIntern(), |
| 20956 | } })); | 20777 | })); |
| 20957 | const final_val_inst = try sema.coerce(block, result_ty, Air.internedToRef(struct_val.toIntern()), src); | 20778 | 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)).?; | 20779 | const final_val = (try sema.resolveValue(final_val_inst)).?; |
| 20959 | return sema.addConstantMaybeRef(final_val.toIntern(), is_ref); | 20780 | return sema.addConstantMaybeRef(final_val.toIntern(), is_ref); |
| ... | @@ -21869,11 +21690,20 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -21869,11 +21690,20 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 21869 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); | 21690 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 21870 | const src = block.nodeOffset(inst_data.src_node); | 21691 | const src = block.nodeOffset(inst_data.src_node); |
| 21871 | const operand = try sema.resolveInst(inst_data.operand); | 21692 | const operand = try sema.resolveInst(inst_data.operand); |
| | 21693 | return analyzeTagName(sema, block, src, operand_src, operand); |
| | 21694 | } |
| | 21695 | |
| | 21696 | fn analyzeTagName( |
| | 21697 | sema: *Sema, |
| | 21698 | block: *Block, |
| | 21699 | src: LazySrcLoc, |
| | 21700 | operand_src: LazySrcLoc, |
| | 21701 | operand: Air.Inst.Ref, |
| | 21702 | ) CompileError!Air.Inst.Ref { |
| 21872 | const operand_ty = sema.typeOf(operand); | 21703 | const operand_ty = sema.typeOf(operand); |
| 21873 | const pt = sema.pt; | 21704 | const pt = sema.pt; |
| 21874 | const zcu = pt.zcu; | 21705 | const zcu = pt.zcu; |
| 21875 | const ip = &zcu.intern_pool; | 21706 | const ip = &zcu.intern_pool; |
| 21876 | | | |
| 21877 | try operand_ty.resolveLayout(pt); | 21707 | try operand_ty.resolveLayout(pt); |
| 21878 | const enum_ty = switch (operand_ty.zigTypeTag(zcu)) { | 21708 | const enum_ty = switch (operand_ty.zigTypeTag(zcu)) { |
| 21879 | .enum_literal => { | 21709 | .enum_literal => { |
| ... | @@ -27840,7 +27670,7 @@ fn explainWhyTypeIsNotPacked( | ... | @@ -27840,7 +27670,7 @@ fn explainWhyTypeIsNotPacked( |
| 27840 | } | 27670 | } |
| 27841 | } | 27671 | } |
| 27842 | | 27672 | |
| 27843 | fn prepareSimplePanic(sema: *Sema, block: *Block, src: LazySrcLoc) !void { | 27673 | fn preparePanic(sema: *Sema, block: *Block, src: LazySrcLoc) !void { |
| 27844 | const pt = sema.pt; | 27674 | const pt = sema.pt; |
| 27845 | const zcu = pt.zcu; | 27675 | const zcu = pt.zcu; |
| 27846 | | 27676 | |
| ... | @@ -27871,33 +27701,12 @@ fn prepareSimplePanic(sema: *Sema, block: *Block, src: LazySrcLoc) !void { | ... | @@ -27871,33 +27701,12 @@ fn prepareSimplePanic(sema: *Sema, block: *Block, src: LazySrcLoc) !void { |
| 27871 | .val = .none, | 27701 | .val = .none, |
| 27872 | } }); | 27702 | } }); |
| 27873 | } | 27703 | } |
| 27874 | } | | |
| 27875 | | | |
| 27876 | /// Backends depend on panic decls being available when lowering safety-checked | | |
| 27877 | /// instructions. This function ensures the panic function will be available to | | |
| 27878 | /// be called during that time. | | |
| 27879 | fn preparePanicId(sema: *Sema, block: *Block, src: LazySrcLoc, panic_id: Zcu.PanicId) !InternPool.Nav.Index { | | |
| 27880 | const pt = sema.pt; | | |
| 27881 | const zcu = pt.zcu; | | |
| 27882 | const gpa = sema.gpa; | | |
| 27883 | if (zcu.panic_messages[@intFromEnum(panic_id)].unwrap()) |x| return x; | | |
| 27884 | | | |
| 27885 | try sema.prepareSimplePanic(block, src); | | |
| 27886 | | 27704 | |
| 27887 | const panic_messages_ty = try pt.getBuiltinType("panic_messages"); | 27705 | if (zcu.panic_cause_type == .none) { |
| 27888 | const msg_nav_index = (sema.namespaceLookup( | 27706 | const panic_cause_ty = try pt.getBuiltinType("PanicCause"); |
| 27889 | block, | 27707 | try panic_cause_ty.resolveFields(pt); |
| 27890 | LazySrcLoc.unneeded, | 27708 | zcu.panic_cause_type = panic_cause_ty.toIntern(); |
| 27891 | panic_messages_ty.getNamespaceIndex(zcu), | 27709 | } |
| 27892 | try zcu.intern_pool.getOrPutString(gpa, pt.tid, @tagName(panic_id), .no_embedded_nulls), | | |
| 27893 | ) catch |err| switch (err) { | | |
| 27894 | error.AnalysisFail => @panic("std.builtin.panic_messages is corrupt"), | | |
| 27895 | error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, | | |
| 27896 | error.OutOfMemory => |e| return e, | | |
| 27897 | }).?; | | |
| 27898 | try sema.ensureNavResolved(src, msg_nav_index); | | |
| 27899 | zcu.panic_messages[@intFromEnum(panic_id)] = msg_nav_index.toOptional(); | | |
| 27900 | return msg_nav_index; | | |
| 27901 | } | 27710 | } |
| 27902 | | 27711 | |
| 27903 | fn addSafetyCheck( | 27712 | fn addSafetyCheck( |
| ... | @@ -27905,7 +27714,7 @@ fn addSafetyCheck( | ... | @@ -27905,7 +27714,7 @@ fn addSafetyCheck( |
| 27905 | parent_block: *Block, | 27714 | parent_block: *Block, |
| 27906 | src: LazySrcLoc, | 27715 | src: LazySrcLoc, |
| 27907 | ok: Air.Inst.Ref, | 27716 | ok: Air.Inst.Ref, |
| 27908 | panic_id: Zcu.PanicId, | 27717 | panic_cause_tag: PanicCauseTag, |
| 27909 | ) !void { | 27718 | ) !void { |
| 27910 | const gpa = sema.gpa; | 27719 | const gpa = sema.gpa; |
| 27911 | assert(!parent_block.is_comptime); | 27720 | assert(!parent_block.is_comptime); |
| ... | @@ -27923,7 +27732,7 @@ fn addSafetyCheck( | ... | @@ -27923,7 +27732,7 @@ fn addSafetyCheck( |
| 27923 | | 27732 | |
| 27924 | defer fail_block.instructions.deinit(gpa); | 27733 | defer fail_block.instructions.deinit(gpa); |
| 27925 | | 27734 | |
| 27926 | try sema.safetyPanic(&fail_block, src, panic_id); | 27735 | try sema.safetyPanic(&fail_block, src, panic_cause_tag); |
| 27927 | try sema.addSafetyCheckExtra(parent_block, ok, &fail_block); | 27736 | try sema.addSafetyCheckExtra(parent_block, ok, &fail_block); |
| 27928 | } | 27737 | } |
| 27929 | | 27738 | |
| ... | @@ -27992,30 +27801,7 @@ fn addSafetyCheckExtra( | ... | @@ -27992,30 +27801,7 @@ fn addSafetyCheckExtra( |
| 27992 | parent_block.instructions.appendAssumeCapacity(block_inst); | 27801 | parent_block.instructions.appendAssumeCapacity(block_inst); |
| 27993 | } | 27802 | } |
| 27994 | | 27803 | |
| 27995 | fn panicWithMsg(sema: *Sema, block: *Block, src: LazySrcLoc, msg_inst: Air.Inst.Ref, operation: CallOperation) !void { | 27804 | fn addSafetyCheckUnwrapError( |
| 27996 | const pt = sema.pt; | | |
| 27997 | const zcu = pt.zcu; | | |
| 27998 | | | |
| 27999 | if (!zcu.backendSupportsFeature(.panic_fn)) { | | |
| 28000 | _ = try block.addNoOp(.trap); | | |
| 28001 | return; | | |
| 28002 | } | | |
| 28003 | | | |
| 28004 | try sema.prepareSimplePanic(block, src); | | |
| 28005 | | | |
| 28006 | const panic_func = zcu.funcInfo(zcu.panic_func_index); | | |
| 28007 | const panic_fn = try sema.analyzeNavVal(block, src, panic_func.owner_nav); | | |
| 28008 | const null_stack_trace = Air.internedToRef(zcu.null_stack_trace); | | |
| 28009 | | | |
| 28010 | const opt_usize_ty = try pt.optionalType(.usize_type); | | |
| 28011 | const null_ret_addr = Air.internedToRef((try pt.intern(.{ .opt = .{ | | |
| 28012 | .ty = opt_usize_ty.toIntern(), | | |
| 28013 | .val = .none, | | |
| 28014 | } }))); | | |
| 28015 | try sema.callBuiltin(block, src, panic_fn, .auto, &.{ msg_inst, null_stack_trace, null_ret_addr }, operation); | | |
| 28016 | } | | |
| 28017 | | | |
| 28018 | fn panicUnwrapError( | | |
| 28019 | sema: *Sema, | 27805 | sema: *Sema, |
| 28020 | parent_block: *Block, | 27806 | parent_block: *Block, |
| 28021 | src: LazySrcLoc, | 27807 | src: LazySrcLoc, |
| ... | @@ -28023,12 +27809,8 @@ fn panicUnwrapError( | ... | @@ -28023,12 +27809,8 @@ fn panicUnwrapError( |
| 28023 | unwrap_err_tag: Air.Inst.Tag, | 27809 | unwrap_err_tag: Air.Inst.Tag, |
| 28024 | is_non_err_tag: Air.Inst.Tag, | 27810 | is_non_err_tag: Air.Inst.Tag, |
| 28025 | ) !void { | 27811 | ) !void { |
| 28026 | const pt = sema.pt; | | |
| 28027 | assert(!parent_block.is_comptime); | 27812 | assert(!parent_block.is_comptime); |
| 28028 | const ok = try parent_block.addUnOp(is_non_err_tag, operand); | 27813 | 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; | 27814 | const gpa = sema.gpa; |
| 28033 | | 27815 | |
| 28034 | var fail_block: Block = .{ | 27816 | var fail_block: Block = .{ |
| ... | @@ -28044,21 +27826,13 @@ fn panicUnwrapError( | ... | @@ -28044,21 +27826,13 @@ fn panicUnwrapError( |
| 28044 | | 27826 | |
| 28045 | defer fail_block.instructions.deinit(gpa); | 27827 | defer fail_block.instructions.deinit(gpa); |
| 28046 | | 27828 | |
| 28047 | { | 27829 | const err = try fail_block.addTyOp(unwrap_err_tag, Type.anyerror, operand); |
| 28048 | if (!pt.zcu.backendSupportsFeature(.panic_unwrap_error)) { | 27830 | try callPanic(sema, &fail_block, src, .unwrap_error, err, .@"safety check"); |
| 28049 | _ = try fail_block.addNoOp(.trap); | 27831 | |
| 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); | 27832 | try sema.addSafetyCheckExtra(parent_block, ok, &fail_block); |
| 28059 | } | 27833 | } |
| 28060 | | 27834 | |
| 28061 | fn panicIndexOutOfBounds( | 27835 | fn addSafetyCheckIndexOob( |
| 28062 | sema: *Sema, | 27836 | sema: *Sema, |
| 28063 | parent_block: *Block, | 27837 | parent_block: *Block, |
| 28064 | src: LazySrcLoc, | 27838 | src: LazySrcLoc, |
| ... | @@ -28067,14 +27841,71 @@ fn panicIndexOutOfBounds( | ... | @@ -28067,14 +27841,71 @@ fn panicIndexOutOfBounds( |
| 28067 | cmp_op: Air.Inst.Tag, | 27841 | cmp_op: Air.Inst.Tag, |
| 28068 | ) !void { | 27842 | ) !void { |
| 28069 | assert(!parent_block.is_comptime); | 27843 | assert(!parent_block.is_comptime); |
| | 27844 | const gpa = sema.gpa; |
| 28070 | const ok = try parent_block.addBinOp(cmp_op, index, len); | 27845 | const ok = try parent_block.addBinOp(cmp_op, index, len); |
| 28071 | if (!sema.pt.zcu.comp.formatted_panics) { | 27846 | |
| 28072 | return sema.addSafetyCheck(parent_block, src, ok, .index_out_of_bounds); | 27847 | var fail_block: Block = .{ |
| | 27848 | .parent = parent_block, |
| | 27849 | .sema = sema, |
| | 27850 | .namespace = parent_block.namespace, |
| | 27851 | .instructions = .{}, |
| | 27852 | .inlining = parent_block.inlining, |
| | 27853 | .is_comptime = false, |
| | 27854 | .src_base_inst = parent_block.src_base_inst, |
| | 27855 | .type_name_ctx = parent_block.type_name_ctx, |
| | 27856 | }; |
| | 27857 | |
| | 27858 | defer fail_block.instructions.deinit(gpa); |
| | 27859 | |
| | 27860 | const oob_ty = try getBuiltinInnerType(sema, &fail_block, src, "PanicCause", "IndexOutOfBounds"); |
| | 27861 | comptime { |
| | 27862 | const fields = @typeInfo(std.builtin.PanicCause.IndexOutOfBounds).@"struct".fields; |
| | 27863 | assert(std.mem.eql(u8, fields[0].name, "index")); |
| | 27864 | assert(std.mem.eql(u8, fields[1].name, "len")); |
| | 27865 | assert(fields.len == 2); |
| 28073 | } | 27866 | } |
| 28074 | try sema.safetyCheckFormatted(parent_block, src, ok, "panicOutOfBounds", &.{ index, len }); | 27867 | const panic_cause_payload = try fail_block.addAggregateInit(oob_ty, &.{ index, len }); |
| | 27868 | try callPanic(sema, &fail_block, src, .index_out_of_bounds, panic_cause_payload, .@"safety check"); |
| | 27869 | try sema.addSafetyCheckExtra(parent_block, ok, &fail_block); |
| 28075 | } | 27870 | } |
| 28076 | | 27871 | |
| 28077 | fn panicInactiveUnionField( | 27872 | fn addSafetyCheckStartGreaterThanEnd( |
| | 27873 | sema: *Sema, |
| | 27874 | parent_block: *Block, |
| | 27875 | src: LazySrcLoc, |
| | 27876 | start: Air.Inst.Ref, |
| | 27877 | end: Air.Inst.Ref, |
| | 27878 | ) !void { |
| | 27879 | assert(!parent_block.is_comptime); |
| | 27880 | const gpa = sema.gpa; |
| | 27881 | const ok = try parent_block.addBinOp(.cmp_lte, start, end); |
| | 27882 | |
| | 27883 | var fail_block: Block = .{ |
| | 27884 | .parent = parent_block, |
| | 27885 | .sema = sema, |
| | 27886 | .namespace = parent_block.namespace, |
| | 27887 | .instructions = .{}, |
| | 27888 | .inlining = parent_block.inlining, |
| | 27889 | .is_comptime = false, |
| | 27890 | .src_base_inst = parent_block.src_base_inst, |
| | 27891 | .type_name_ctx = parent_block.type_name_ctx, |
| | 27892 | }; |
| | 27893 | |
| | 27894 | defer fail_block.instructions.deinit(gpa); |
| | 27895 | |
| | 27896 | const oob_ty = try getBuiltinInnerType(sema, &fail_block, src, "PanicCause", "StartIndexGreaterThanEnd"); |
| | 27897 | comptime { |
| | 27898 | const fields = @typeInfo(std.builtin.PanicCause.StartIndexGreaterThanEnd).@"struct".fields; |
| | 27899 | assert(std.mem.eql(u8, fields[0].name, "start")); |
| | 27900 | assert(std.mem.eql(u8, fields[1].name, "end")); |
| | 27901 | assert(fields.len == 2); |
| | 27902 | } |
| | 27903 | const panic_cause_payload = try fail_block.addAggregateInit(oob_ty, &.{ start, end }); |
| | 27904 | try callPanic(sema, &fail_block, src, .start_index_greater_than_end, panic_cause_payload, .@"safety check"); |
| | 27905 | try sema.addSafetyCheckExtra(parent_block, ok, &fail_block); |
| | 27906 | } |
| | 27907 | |
| | 27908 | fn addSafetyCheckInactiveUnionField( |
| 28078 | sema: *Sema, | 27909 | sema: *Sema, |
| 28079 | parent_block: *Block, | 27910 | parent_block: *Block, |
| 28080 | src: LazySrcLoc, | 27911 | src: LazySrcLoc, |
| ... | @@ -28082,14 +27913,39 @@ fn panicInactiveUnionField( | ... | @@ -28082,14 +27913,39 @@ fn panicInactiveUnionField( |
| 28082 | wanted_tag: Air.Inst.Ref, | 27913 | wanted_tag: Air.Inst.Ref, |
| 28083 | ) !void { | 27914 | ) !void { |
| 28084 | assert(!parent_block.is_comptime); | 27915 | assert(!parent_block.is_comptime); |
| | 27916 | const gpa = sema.gpa; |
| 28085 | const ok = try parent_block.addBinOp(.cmp_eq, active_tag, wanted_tag); | 27917 | const ok = try parent_block.addBinOp(.cmp_eq, active_tag, wanted_tag); |
| 28086 | if (!sema.pt.zcu.comp.formatted_panics) { | 27918 | |
| 28087 | return sema.addSafetyCheck(parent_block, src, ok, .inactive_union_field); | 27919 | var fail_block: Block = .{ |
| 28088 | } | 27920 | .parent = parent_block, |
| 28089 | try sema.safetyCheckFormatted(parent_block, src, ok, "panicInactiveUnionField", &.{ active_tag, wanted_tag }); | 27921 | .sema = sema, |
| | 27922 | .namespace = parent_block.namespace, |
| | 27923 | .instructions = .{}, |
| | 27924 | .inlining = parent_block.inlining, |
| | 27925 | .is_comptime = false, |
| | 27926 | .src_base_inst = parent_block.src_base_inst, |
| | 27927 | .type_name_ctx = parent_block.type_name_ctx, |
| | 27928 | }; |
| | 27929 | |
| | 27930 | defer fail_block.instructions.deinit(gpa); |
| | 27931 | |
| | 27932 | const payload_ty = try getBuiltinInnerType(sema, &fail_block, src, "PanicCause", "InactiveUnionField"); |
| | 27933 | comptime { |
| | 27934 | const fields = @typeInfo(std.builtin.PanicCause.InactiveUnionField).@"struct".fields; |
| | 27935 | assert(std.mem.eql(u8, fields[0].name, "active")); |
| | 27936 | assert(std.mem.eql(u8, fields[1].name, "accessed")); |
| | 27937 | assert(fields.len == 2); |
| | 27938 | } |
| | 27939 | // TODO: before merging the branch, check how many safety checks end up being emitted |
| | 27940 | // for union field accesses and avoid extraneous ones. |
| | 27941 | const active_str = try analyzeTagName(sema, &fail_block, src, src, active_tag); |
| | 27942 | const accessed_str = try analyzeTagName(sema, &fail_block, src, src, wanted_tag); |
| | 27943 | const panic_cause_payload = try fail_block.addAggregateInit(payload_ty, &.{ active_str, accessed_str }); |
| | 27944 | try callPanic(sema, &fail_block, src, .inactive_union_field, panic_cause_payload, .@"safety check"); |
| | 27945 | try sema.addSafetyCheckExtra(parent_block, ok, &fail_block); |
| 28090 | } | 27946 | } |
| 28091 | | 27947 | |
| 28092 | fn panicSentinelMismatch( | 27948 | fn addSafetyCheckSentinelMismatch( |
| 28093 | sema: *Sema, | 27949 | sema: *Sema, |
| 28094 | parent_block: *Block, | 27950 | parent_block: *Block, |
| 28095 | src: LazySrcLoc, | 27951 | src: LazySrcLoc, |
| ... | @@ -28099,6 +27955,7 @@ fn panicSentinelMismatch( | ... | @@ -28099,6 +27955,7 @@ fn panicSentinelMismatch( |
| 28099 | sentinel_index: Air.Inst.Ref, | 27955 | sentinel_index: Air.Inst.Ref, |
| 28100 | ) !void { | 27956 | ) !void { |
| 28101 | assert(!parent_block.is_comptime); | 27957 | assert(!parent_block.is_comptime); |
| | 27958 | const gpa = sema.gpa; |
| 28102 | const pt = sema.pt; | 27959 | const pt = sema.pt; |
| 28103 | const zcu = pt.zcu; | 27960 | const zcu = pt.zcu; |
| 28104 | const expected_sentinel_val = maybe_sentinel orelse return; | 27961 | const expected_sentinel_val = maybe_sentinel orelse return; |
| ... | @@ -28114,8 +27971,7 @@ fn panicSentinelMismatch( | ... | @@ -28114,8 +27971,7 @@ fn panicSentinelMismatch( |
| 28114 | }; | 27971 | }; |
| 28115 | | 27972 | |
| 28116 | const ok = if (sentinel_ty.zigTypeTag(zcu) == .vector) ok: { | 27973 | const ok = if (sentinel_ty.zigTypeTag(zcu) == .vector) ok: { |
| 28117 | const eql = | 27974 | 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(.{ | 27975 | break :ok try parent_block.addInst(.{ |
| 28120 | .tag = .reduce, | 27976 | .tag = .reduce, |
| 28121 | .data = .{ .reduce = .{ | 27977 | .data = .{ .reduce = .{ |
| ... | @@ -28128,25 +27984,6 @@ fn panicSentinelMismatch( | ... | @@ -28128,25 +27984,6 @@ fn panicSentinelMismatch( |
| 28128 | break :ok try parent_block.addBinOp(.cmp_eq, expected_sentinel, actual_sentinel); | 27984 | break :ok try parent_block.addBinOp(.cmp_eq, expected_sentinel, actual_sentinel); |
| 28129 | }; | 27985 | }; |
| 28130 | | 27986 | |
| 28131 | if (!pt.zcu.comp.formatted_panics) { | | |
| 28132 | return sema.addSafetyCheck(parent_block, src, ok, .sentinel_mismatch); | | |
| 28133 | } | | |
| 28134 | try sema.safetyCheckFormatted(parent_block, src, ok, "panicSentinelMismatch", &.{ expected_sentinel, actual_sentinel }); | | |
| 28135 | } | | |
| 28136 | | | |
| 28137 | fn safetyCheckFormatted( | | |
| 28138 | sema: *Sema, | | |
| 28139 | parent_block: *Block, | | |
| 28140 | src: LazySrcLoc, | | |
| 28141 | ok: Air.Inst.Ref, | | |
| 28142 | func: []const u8, | | |
| 28143 | args: []const Air.Inst.Ref, | | |
| 28144 | ) CompileError!void { | | |
| 28145 | const pt = sema.pt; | | |
| 28146 | const zcu = pt.zcu; | | |
| 28147 | assert(zcu.comp.formatted_panics); | | |
| 28148 | const gpa = sema.gpa; | | |
| 28149 | | | |
| 28150 | var fail_block: Block = .{ | 27987 | var fail_block: Block = .{ |
| 28151 | .parent = parent_block, | 27988 | .parent = parent_block, |
| 28152 | .sema = sema, | 27989 | .sema = sema, |
| ... | @@ -28160,20 +27997,29 @@ fn safetyCheckFormatted( | ... | @@ -28160,20 +27997,29 @@ fn safetyCheckFormatted( |
| 28160 | | 27997 | |
| 28161 | defer fail_block.instructions.deinit(gpa); | 27998 | defer fail_block.instructions.deinit(gpa); |
| 28162 | | 27999 | |
| 28163 | if (!zcu.backendSupportsFeature(.safety_check_formatted)) { | 28000 | // A different PanicCause tag must be used depending on what payload type it can be fit into. |
| 28164 | _ = try fail_block.addNoOp(.trap); | 28001 | // If it cannot fit into any, the "other" tag can be used, which does not try to carry the |
| | 28002 | // sentinel value data. |
| | 28003 | |
| | 28004 | if (sentinel_ty.isUnsignedInt(zcu) and sentinel_ty.intInfo(zcu).bits <= Type.usize.intInfo(zcu).bits) { |
| | 28005 | const mm_ty = try getBuiltinInnerType(sema, &fail_block, src, "PanicCause", "SentinelMismatchUsize"); |
| | 28006 | comptime { |
| | 28007 | const fields = @typeInfo(std.builtin.PanicCause.SentinelMismatchUsize).@"struct".fields; |
| | 28008 | assert(std.mem.eql(u8, fields[0].name, "expected")); |
| | 28009 | assert(std.mem.eql(u8, fields[1].name, "found")); |
| | 28010 | assert(fields.len == 2); |
| | 28011 | } |
| | 28012 | const panic_cause_payload = &fail_block.addAggregateInit(mm_ty, &.{ expected_sentinel, actual_sentinel }); |
| | 28013 | try callPanic(sema, &fail_block, src, .sentinel_mismatch_usize, panic_cause_payload, .@"safety check"); |
| 28165 | } else { | 28014 | } else { |
| 28166 | const panic_fn = try pt.getBuiltin(func); | 28015 | try callPanic(sema, &fail_block, src, .sentinel_mismatch_other, .void_value, .@"safety check"); |
| 28167 | try sema.callBuiltin(&fail_block, src, panic_fn, .auto, args, .@"safety check"); | | |
| 28168 | } | 28016 | } |
| 28169 | try sema.addSafetyCheckExtra(parent_block, ok, &fail_block); | 28017 | try sema.addSafetyCheckExtra(parent_block, ok, &fail_block); |
| 28170 | } | 28018 | } |
| 28171 | | 28019 | |
| 28172 | /// This does not set `sema.branch_hint`. | 28020 | /// This does not set `sema.branch_hint`. |
| 28173 | fn safetyPanic(sema: *Sema, block: *Block, src: LazySrcLoc, panic_id: Zcu.PanicId) CompileError!void { | 28021 | fn safetyPanic(sema: *Sema, block: *Block, src: LazySrcLoc, panic_cause_tag: PanicCauseTag) CompileError!void { |
| 28174 | const msg_nav_index = try sema.preparePanicId(block, src, panic_id); | 28022 | try callPanic(sema, block, src, panic_cause_tag, .void_value, .@"safety check"); |
| 28175 | const msg_inst = try sema.analyzeNavVal(block, src, msg_nav_index); | | |
| 28176 | try sema.panicWithMsg(block, src, msg_inst, .@"safety check"); | | |
| 28177 | } | 28023 | } |
| 28178 | | 28024 | |
| 28179 | fn emitBackwardBranch(sema: *Sema, block: *Block, src: LazySrcLoc) !void { | 28025 | fn emitBackwardBranch(sema: *Sema, block: *Block, src: LazySrcLoc) !void { |
| ... | @@ -29229,7 +29075,7 @@ fn unionFieldPtr( | ... | @@ -29229,7 +29075,7 @@ fn unionFieldPtr( |
| 29229 | // TODO would it be better if get_union_tag supported pointers to unions? | 29075 | // 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); | 29076 | 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); | 29077 | 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); | 29078 | try sema.addSafetyCheckInactiveUnionField(block, src, active_tag, wanted_tag); |
| 29233 | } | 29079 | } |
| 29234 | if (field_ty.zigTypeTag(zcu) == .noreturn) { | 29080 | if (field_ty.zigTypeTag(zcu) == .noreturn) { |
| 29235 | _ = try block.addNoOp(.unreach); | 29081 | _ = try block.addNoOp(.unreach); |
| ... | @@ -29304,7 +29150,7 @@ fn unionFieldVal( | ... | @@ -29304,7 +29150,7 @@ fn unionFieldVal( |
| 29304 | const wanted_tag_val = try pt.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index); | 29150 | 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()); | 29151 | 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); | 29152 | 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); | 29153 | try sema.addSafetyCheckInactiveUnionField(block, src, active_tag, wanted_tag); |
| 29308 | } | 29154 | } |
| 29309 | if (field_ty.zigTypeTag(zcu) == .noreturn) { | 29155 | if (field_ty.zigTypeTag(zcu) == .noreturn) { |
| 29310 | _ = try block.addNoOp(.unreach); | 29156 | _ = try block.addNoOp(.unreach); |
| ... | @@ -29668,11 +29514,11 @@ fn elemValArray( | ... | @@ -29668,11 +29514,11 @@ fn elemValArray( |
| 29668 | | 29514 | |
| 29669 | const runtime_src = if (maybe_undef_array_val != null) elem_index_src else array_src; | 29515 | const runtime_src = if (maybe_undef_array_val != null) elem_index_src else array_src; |
| 29670 | if (oob_safety and block.wantSafety()) { | 29516 | if (oob_safety and block.wantSafety()) { |
| 29671 | // Runtime check is only needed if unable to comptime check | 29517 | // Runtime check is only needed if unable to comptime check. |
| 29672 | if (maybe_index_val == null) { | 29518 | if (maybe_index_val == null) { |
| 29673 | const len_inst = try pt.intRef(Type.usize, array_len); | 29519 | 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; | 29520 | 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); | 29521 | try sema.addSafetyCheckIndexOob(block, src, elem_index, len_inst, cmp_op); |
| 29676 | } | 29522 | } |
| 29677 | } | 29523 | } |
| 29678 | | 29524 | |
| ... | @@ -29740,7 +29586,7 @@ fn elemPtrArray( | ... | @@ -29740,7 +29586,7 @@ fn elemPtrArray( |
| 29740 | if (oob_safety and block.wantSafety() and offset == null) { | 29586 | if (oob_safety and block.wantSafety() and offset == null) { |
| 29741 | const len_inst = try pt.intRef(Type.usize, array_len); | 29587 | 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; | 29588 | 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); | 29589 | try sema.addSafetyCheckIndexOob(block, src, elem_index, len_inst, cmp_op); |
| 29744 | } | 29590 | } |
| 29745 | | 29591 | |
| 29746 | return block.addPtrElemPtr(array_ptr, elem_index, elem_ptr_ty); | 29592 | return block.addPtrElemPtr(array_ptr, elem_index, elem_ptr_ty); |
| ... | @@ -29799,7 +29645,7 @@ fn elemValSlice( | ... | @@ -29799,7 +29645,7 @@ fn elemValSlice( |
| 29799 | else | 29645 | else |
| 29800 | try block.addTyOp(.slice_len, Type.usize, slice); | 29646 | try block.addTyOp(.slice_len, Type.usize, slice); |
| 29801 | const cmp_op: Air.Inst.Tag = if (slice_sent) .cmp_lte else .cmp_lt; | 29647 | 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); | 29648 | try sema.addSafetyCheckIndexOob(block, src, elem_index, len_inst, cmp_op); |
| 29803 | } | 29649 | } |
| 29804 | return block.addBinOp(.slice_elem_val, slice, elem_index); | 29650 | return block.addBinOp(.slice_elem_val, slice, elem_index); |
| 29805 | } | 29651 | } |
| ... | @@ -29859,7 +29705,7 @@ fn elemPtrSlice( | ... | @@ -29859,7 +29705,7 @@ fn elemPtrSlice( |
| 29859 | break :len try block.addTyOp(.slice_len, Type.usize, slice); | 29705 | break :len try block.addTyOp(.slice_len, Type.usize, slice); |
| 29860 | }; | 29706 | }; |
| 29861 | const cmp_op: Air.Inst.Tag = if (slice_sent) .cmp_lte else .cmp_lt; | 29707 | 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); | 29708 | try sema.addSafetyCheckIndexOob(block, src, elem_index, len_inst, cmp_op); |
| 29863 | } | 29709 | } |
| 29864 | return block.addSliceElemPtr(slice, elem_index, elem_ptr_ty); | 29710 | return block.addSliceElemPtr(slice, elem_index, elem_ptr_ty); |
| 29865 | } | 29711 | } |
| ... | @@ -33666,12 +33512,7 @@ fn analyzeSlice( | ... | @@ -33666,12 +33512,7 @@ fn analyzeSlice( |
| 33666 | // requirement: start <= end | 33512 | // requirement: start <= end |
| 33667 | assert(!block.is_comptime); | 33513 | assert(!block.is_comptime); |
| 33668 | try sema.requireRuntimeBlock(block, src, runtime_src.?); | 33514 | try sema.requireRuntimeBlock(block, src, runtime_src.?); |
| 33669 | const ok = try block.addBinOp(.cmp_lte, start, end); | 33515 | try sema.addSafetyCheckStartGreaterThanEnd(block, src, start, end); |
| 33670 | if (!pt.zcu.comp.formatted_panics) { | | |
| 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 | } | 33516 | } |
| 33676 | const new_len = if (by_length) | 33517 | const new_len = if (by_length) |
| 33677 | try sema.coerce(block, Type.usize, uncasted_end_opt, end_src) | 33518 | try sema.coerce(block, Type.usize, uncasted_end_opt, end_src) |
| ... | @@ -33726,11 +33567,11 @@ fn analyzeSlice( | ... | @@ -33726,11 +33567,11 @@ fn analyzeSlice( |
| 33726 | else | 33567 | else |
| 33727 | end; | 33568 | end; |
| 33728 | | 33569 | |
| 33729 | try sema.panicIndexOutOfBounds(block, src, actual_end, actual_len, .cmp_lte); | 33570 | try sema.addSafetyCheckIndexOob(block, src, actual_end, actual_len, .cmp_lte); |
| 33730 | } | 33571 | } |
| 33731 | | 33572 | |
| 33732 | // requirement: result[new_len] == slice_sentinel | 33573 | // requirement: result[new_len] == slice_sentinel |
| 33733 | try sema.panicSentinelMismatch(block, src, slice_sentinel, elem_ty, result, new_len); | 33574 | try sema.addSafetyCheckSentinelMismatch(block, src, slice_sentinel, elem_ty, result, new_len); |
| 33734 | } | 33575 | } |
| 33735 | return result; | 33576 | return result; |
| 33736 | }; | 33577 | }; |
| ... | @@ -33789,11 +33630,11 @@ fn analyzeSlice( | ... | @@ -33789,11 +33630,11 @@ fn analyzeSlice( |
| 33789 | try sema.analyzeArithmetic(block, .add, end, .one, src, end_src, end_src, true) | 33630 | try sema.analyzeArithmetic(block, .add, end, .one, src, end_src, end_src, true) |
| 33790 | else | 33631 | else |
| 33791 | end; | 33632 | end; |
| 33792 | try sema.panicIndexOutOfBounds(block, src, actual_end, len_inst, .cmp_lte); | 33633 | try sema.addSafetyCheckIndexOob(block, src, actual_end, len_inst, .cmp_lte); |
| 33793 | } | 33634 | } |
| 33794 | | 33635 | |
| 33795 | // requirement: start <= end | 33636 | // requirement: start <= end |
| 33796 | try sema.panicIndexOutOfBounds(block, src, start, end, .cmp_lte); | 33637 | try sema.addSafetyCheckIndexOob(block, src, start, end, .cmp_lte); |
| 33797 | } | 33638 | } |
| 33798 | const result = try block.addInst(.{ | 33639 | const result = try block.addInst(.{ |
| 33799 | .tag = .slice, | 33640 | .tag = .slice, |
| ... | @@ -33807,7 +33648,7 @@ fn analyzeSlice( | ... | @@ -33807,7 +33648,7 @@ fn analyzeSlice( |
| 33807 | }); | 33648 | }); |
| 33808 | if (block.wantSafety()) { | 33649 | if (block.wantSafety()) { |
| 33809 | // requirement: result[new_len] == slice_sentinel | 33650 | // requirement: result[new_len] == slice_sentinel |
| 33810 | try sema.panicSentinelMismatch(block, src, slice_sentinel, elem_ty, result, new_len); | 33651 | try sema.addSafetyCheckSentinelMismatch(block, src, slice_sentinel, elem_ty, result, new_len); |
| 33811 | } | 33652 | } |
| 33812 | return result; | 33653 | return result; |
| 33813 | } | 33654 | } |
| ... | @@ -37688,11 +37529,11 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -37688,11 +37529,11 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37688 | const only_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[0]); | 37529 | const only_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[0]); |
| 37689 | const val_val = (try sema.typeHasOnePossibleValue(only_field_ty)) orelse | 37530 | const val_val = (try sema.typeHasOnePossibleValue(only_field_ty)) orelse |
| 37690 | return null; | 37531 | return null; |
| 37691 | const only = try pt.intern(.{ .un = .{ | 37532 | const only = try pt.internUnion(.{ |
| 37692 | .ty = ty.toIntern(), | 37533 | .ty = ty.toIntern(), |
| 37693 | .tag = tag_val.toIntern(), | 37534 | .tag = tag_val.toIntern(), |
| 37694 | .val = val_val.toIntern(), | 37535 | .val = val_val.toIntern(), |
| 37695 | } }); | 37536 | }); |
| 37696 | return Value.fromInterned(only); | 37537 | return Value.fromInterned(only); |
| 37697 | }, | 37538 | }, |
| 37698 | | 37539 | |
| ... | @@ -38849,7 +38690,7 @@ fn analyzeUnreachable(sema: *Sema, block: *Block, src: LazySrcLoc, safety_check: | ... | @@ -38849,7 +38690,7 @@ fn analyzeUnreachable(sema: *Sema, block: *Block, src: LazySrcLoc, safety_check: |
| 38849 | sema.branch_hint = .cold; | 38690 | sema.branch_hint = .cold; |
| 38850 | } | 38691 | } |
| 38851 | | 38692 | |
| 38852 | try sema.safetyPanic(block, src, .unreach); | 38693 | try sema.safetyPanic(block, src, .reached_unreachable); |
| 38853 | } else { | 38694 | } else { |
| 38854 | _ = try block.addNoOp(.unreach); | 38695 | _ = try block.addNoOp(.unreach); |
| 38855 | } | 38696 | } |
| ... | @@ -39123,3 +38964,36 @@ const loadComptimePtr = @import("Sema/comptime_ptr_access.zig").loadComptimePtr; | ... | @@ -39123,3 +38964,36 @@ const loadComptimePtr = @import("Sema/comptime_ptr_access.zig").loadComptimePtr; |
| 39123 | const ComptimeLoadResult = @import("Sema/comptime_ptr_access.zig").ComptimeLoadResult; | 38964 | const ComptimeLoadResult = @import("Sema/comptime_ptr_access.zig").ComptimeLoadResult; |
| 39124 | const storeComptimePtr = @import("Sema/comptime_ptr_access.zig").storeComptimePtr; | 38965 | const storeComptimePtr = @import("Sema/comptime_ptr_access.zig").storeComptimePtr; |
| 39125 | const ComptimeStoreResult = @import("Sema/comptime_ptr_access.zig").ComptimeStoreResult; | 38966 | const ComptimeStoreResult = @import("Sema/comptime_ptr_access.zig").ComptimeStoreResult; |
| | 38967 | |
| | 38968 | /// Convenience function that looks 2 levels deep into `std.builtin`. |
| | 38969 | fn getBuiltinInnerType( |
| | 38970 | sema: *Sema, |
| | 38971 | block: *Block, |
| | 38972 | src: LazySrcLoc, |
| | 38973 | outer_name: []const u8, |
| | 38974 | inner_name: []const u8, |
| | 38975 | ) !Type { |
| | 38976 | const outer_ty = try sema.pt.getBuiltinType(outer_name); |
| | 38977 | return getInnerType(sema, block, src, outer_ty, inner_name); |
| | 38978 | } |
| | 38979 | |
| | 38980 | fn getInnerType( |
| | 38981 | sema: *Sema, |
| | 38982 | block: *Block, |
| | 38983 | src: LazySrcLoc, |
| | 38984 | outer_ty: Type, |
| | 38985 | inner_name: []const u8, |
| | 38986 | ) !Type { |
| | 38987 | const pt = sema.pt; |
| | 38988 | const zcu = pt.zcu; |
| | 38989 | const ip = &zcu.intern_pool; |
| | 38990 | const gpa = sema.gpa; |
| | 38991 | const nav = try sema.namespaceLookup( |
| | 38992 | block, |
| | 38993 | src, |
| | 38994 | outer_ty.getNamespaceIndex(zcu), |
| | 38995 | try ip.getOrPutString(gpa, pt.tid, inner_name, .no_embedded_nulls), |
| | 38996 | ) orelse return sema.fail(block, src, "std.builtin missing {s}", .{inner_name}); |
| | 38997 | try sema.ensureNavResolved(src, nav); |
| | 38998 | return Type.fromInterned(ip.getNav(nav).status.resolved.val); |
| | 38999 | } |