| ... | ... | @@ -53,9 +53,6 @@ comptime_break_inst: Zir.Inst.Index = undefined, |
| 53 | 53 | post_hoc_blocks: std.AutoHashMapUnmanaged(Air.Inst.Index, *LabeledBlock) = .empty, |
| 54 | 54 | /// Populated with the last compile error created. |
| 55 | 55 | err: ?*Zcu.ErrorMsg = null, |
| 56 | | /// Set to true when analyzing a func type instruction so that nested generic |
| 57 | | /// function types will emit generic poison instead of a partial type. |
| 58 | | no_partial_func_ty: bool = false, |
| 59 | 56 | |
| 60 | 57 | /// The temporary arena is used for the memory of the `InferredAlloc` values |
| 61 | 58 | /// here so the values can be dropped without any cleanup. |
| ... | ... | @@ -1935,9 +1932,7 @@ pub fn resolveInstAllowNone(sema: *Sema, zir_ref: Zir.Inst.Ref) !Air.Inst.Ref { |
| 1935 | 1932 | pub fn resolveInst(sema: *Sema, zir_ref: Zir.Inst.Ref) !Air.Inst.Ref { |
| 1936 | 1933 | assert(zir_ref != .none); |
| 1937 | 1934 | if (zir_ref.toIndex()) |i| { |
| 1938 | | const inst = sema.inst_map.get(i).?; |
| 1939 | | if (inst == .generic_poison) return error.GenericPoison; |
| 1940 | | return inst; |
| 1935 | return sema.inst_map.get(i).?; |
| 1941 | 1936 | } |
| 1942 | 1937 | // First section of indexes correspond to a set number of constant values. |
| 1943 | 1938 | // We intentionally map the same indexes to the same values between ZIR and AIR. |
| ... | ... | @@ -1997,13 +1992,17 @@ pub fn resolveConstStringIntern( |
| 1997 | 1992 | return sema.sliceToIpString(block, src, val, reason); |
| 1998 | 1993 | } |
| 1999 | 1994 | |
| 2000 | | pub fn resolveType(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.Inst.Ref) !Type { |
| 1995 | fn resolveTypeOrPoison(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.Inst.Ref) !?Type { |
| 2001 | 1996 | const air_inst = try sema.resolveInst(zir_ref); |
| 2002 | 1997 | const ty = try sema.analyzeAsType(block, src, air_inst); |
| 2003 | | if (ty.isGenericPoison()) return error.GenericPoison; |
| 1998 | if (ty.isGenericPoison()) return null; |
| 2004 | 1999 | return ty; |
| 2005 | 2000 | } |
| 2006 | 2001 | |
| 2002 | pub fn resolveType(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.Inst.Ref) !Type { |
| 2003 | return (try sema.resolveTypeOrPoison(block, src, zir_ref)).?; |
| 2004 | } |
| 2005 | |
| 2007 | 2006 | fn resolveDestType( |
| 2008 | 2007 | sema: *Sema, |
| 2009 | 2008 | block: *Block, |
| ... | ... | @@ -2023,24 +2022,21 @@ fn resolveDestType( |
| 2023 | 2022 | .remove_eu => false, |
| 2024 | 2023 | }; |
| 2025 | 2024 | |
| 2026 | | const raw_ty = sema.resolveType(block, src, zir_ref) catch |err| switch (err) { |
| 2027 | | error.GenericPoison => { |
| 2028 | | // Cast builtins use their result type as the destination type, but |
| 2029 | | // it could be an anytype argument, which we can't catch in AstGen. |
| 2030 | | const msg = msg: { |
| 2031 | | const msg = try sema.errMsg(src, "{s} must have a known result type", .{builtin_name}); |
| 2032 | | errdefer msg.destroy(sema.gpa); |
| 2033 | | switch (sema.genericPoisonReason(block, zir_ref)) { |
| 2034 | | .anytype_param => |call_src| try sema.errNote(call_src, msg, "result type is unknown due to anytype parameter", .{}), |
| 2035 | | .anyopaque_ptr => |ptr_src| try sema.errNote(ptr_src, msg, "result type is unknown due to opaque pointer type", .{}), |
| 2036 | | .unknown => {}, |
| 2037 | | } |
| 2038 | | try sema.errNote(src, msg, "use @as to provide explicit result type", .{}); |
| 2039 | | break :msg msg; |
| 2040 | | }; |
| 2041 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 2042 | | }, |
| 2043 | | else => |e| return e, |
| 2025 | const raw_ty = try sema.resolveTypeOrPoison(block, src, zir_ref) orelse { |
| 2026 | // Cast builtins use their result type as the destination type, but |
| 2027 | // it could be an anytype argument, which we can't catch in AstGen. |
| 2028 | const msg = msg: { |
| 2029 | const msg = try sema.errMsg(src, "{s} must have a known result type", .{builtin_name}); |
| 2030 | errdefer msg.destroy(sema.gpa); |
| 2031 | switch (sema.genericPoisonReason(block, zir_ref)) { |
| 2032 | .anytype_param => |call_src| try sema.errNote(call_src, msg, "result type is unknown due to anytype parameter", .{}), |
| 2033 | .anyopaque_ptr => |ptr_src| try sema.errNote(ptr_src, msg, "result type is unknown due to opaque pointer type", .{}), |
| 2034 | .unknown => {}, |
| 2035 | } |
| 2036 | try sema.errNote(src, msg, "use @as to provide explicit result type", .{}); |
| 2037 | break :msg msg; |
| 2038 | }; |
| 2039 | return sema.failWithOwnedErrorMsg(block, msg); |
| 2044 | 2040 | }; |
| 2045 | 2041 | |
| 2046 | 2042 | if (remove_eu and raw_ty.zigTypeTag(zcu) == .error_union) { |
| ... | ... | @@ -2086,9 +2082,7 @@ fn genericPoisonReason(sema: *Sema, block: *Block, ref: Zir.Inst.Ref) GenericPoi |
| 2086 | 2082 | // Either the input type was itself poison, or it was a slice, which we cannot translate |
| 2087 | 2083 | // to an overall result type. |
| 2088 | 2084 | const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 2089 | | const operand_ref = sema.resolveInst(un_node.operand) catch |err| switch (err) { |
| 2090 | | error.GenericPoison => unreachable, // this is a type, not a value |
| 2091 | | }; |
| 2085 | const operand_ref = try sema.resolveInst(un_node.operand); |
| 2092 | 2086 | if (operand_ref == .generic_poison_type) { |
| 2093 | 2087 | // The input was poison -- keep looking. |
| 2094 | 2088 | cur = un_node.operand; |
| ... | ... | @@ -2107,9 +2101,7 @@ fn genericPoisonReason(sema: *Sema, block: *Block, ref: Zir.Inst.Ref) GenericPoi |
| 2107 | 2101 | // There are two cases here: the pointer type may already have been |
| 2108 | 2102 | // generic poison, or it may have been an anyopaque pointer. |
| 2109 | 2103 | const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 2110 | | const operand_ref = sema.resolveInst(un_node.operand) catch |err| switch (err) { |
| 2111 | | error.GenericPoison => unreachable, // this is a type, not a value |
| 2112 | | }; |
| 2104 | const operand_ref = try sema.resolveInst(un_node.operand); |
| 2113 | 2105 | const operand_val = operand_ref.toInterned() orelse return .unknown; |
| 2114 | 2106 | if (operand_val == .generic_poison_type) { |
| 2115 | 2107 | // The pointer was generic poison - keep looking. |
| ... | ... | @@ -2187,7 +2179,6 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) |
| 2187 | 2179 | } |
| 2188 | 2180 | |
| 2189 | 2181 | /// Return the Value corresponding to a given AIR ref, or `null` if it refers to a runtime value. |
| 2190 | | /// Generic poison causes `error.GenericPoison` to be returned. |
| 2191 | 2182 | fn resolveValue(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value { |
| 2192 | 2183 | const zcu = sema.pt.zcu; |
| 2193 | 2184 | assert(inst != .none); |
| ... | ... | @@ -2201,7 +2192,6 @@ fn resolveValue(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value { |
| 2201 | 2192 | |
| 2202 | 2193 | assert(val.getVariable(zcu) == null); |
| 2203 | 2194 | if (val.isPtrRuntimeValue(zcu)) return null; |
| 2204 | | if (val.isGenericPoison()) return error.GenericPoison; |
| 2205 | 2195 | |
| 2206 | 2196 | return val; |
| 2207 | 2197 | } else { |
| ... | ... | @@ -2761,8 +2751,7 @@ fn zirTupleDecl( |
| 2761 | 2751 | .elem_index = @intCast(field_index), |
| 2762 | 2752 | } }); |
| 2763 | 2753 | |
| 2764 | | const uncoerced_field_ty = try sema.resolveInst(zir_field_ty); |
| 2765 | | const field_type = try sema.analyzeAsType(block, type_src, uncoerced_field_ty); |
| 2754 | const field_type = try sema.resolveType(block, type_src, zir_field_ty); |
| 2766 | 2755 | try sema.validateTupleFieldType(block, field_type, type_src); |
| 2767 | 2756 | |
| 2768 | 2757 | field_ty.* = field_type.toIntern(); |
| ... | ... | @@ -4555,10 +4544,7 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 4555 | 4544 | const src = block.nodeOffset(pl_node.src_node); |
| 4556 | 4545 | const extra = sema.code.extraData(Zir.Inst.Bin, pl_node.payload_index).data; |
| 4557 | 4546 | const uncoerced_val = try sema.resolveInst(extra.rhs); |
| 4558 | | const maybe_wrapped_ptr_ty = sema.resolveType(block, LazySrcLoc.unneeded, extra.lhs) catch |err| switch (err) { |
| 4559 | | error.GenericPoison => return uncoerced_val, |
| 4560 | | else => |e| return e, |
| 4561 | | }; |
| 4547 | const maybe_wrapped_ptr_ty = try sema.resolveTypeOrPoison(block, LazySrcLoc.unneeded, extra.lhs) orelse return uncoerced_val; |
| 4562 | 4548 | const ptr_ty = maybe_wrapped_ptr_ty.optEuBaseType(zcu); |
| 4563 | 4549 | assert(ptr_ty.zigTypeTag(zcu) == .pointer); // validated by a previous instruction |
| 4564 | 4550 | const elem_ty = ptr_ty.childType(zcu); |
| ... | ... | @@ -4606,10 +4592,7 @@ fn zirTryOperandTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is_ref: boo |
| 4606 | 4592 | const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 4607 | 4593 | const src = block.nodeOffset(un_node.src_node); |
| 4608 | 4594 | |
| 4609 | | const operand_ty = sema.resolveType(block, src, un_node.operand) catch |err| switch (err) { |
| 4610 | | error.GenericPoison => return .generic_poison_type, |
| 4611 | | else => |e| return e, |
| 4612 | | }; |
| 4595 | const operand_ty = try sema.resolveTypeOrPoison(block, src, un_node.operand) orelse return .generic_poison_type; |
| 4613 | 4596 | |
| 4614 | 4597 | const payload_ty = if (is_ref) ty: { |
| 4615 | 4598 | if (!operand_ty.isSinglePointer(zcu)) { |
| ... | ... | @@ -4656,15 +4639,7 @@ fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 4656 | 4639 | const src = block.tokenOffset(un_tok.src_tok); |
| 4657 | 4640 | // In case of GenericPoison, we don't actually have a type, so this will be |
| 4658 | 4641 | // treated as an untyped address-of operator. |
| 4659 | | const operand_air_inst = sema.resolveInst(un_tok.operand) catch |err| switch (err) { |
| 4660 | | error.GenericPoison => return, |
| 4661 | | else => |e| return e, |
| 4662 | | }; |
| 4663 | | const ty_operand = sema.analyzeAsType(block, src, operand_air_inst) catch |err| switch (err) { |
| 4664 | | error.GenericPoison => return, |
| 4665 | | else => |e| return e, |
| 4666 | | }; |
| 4667 | | if (ty_operand.isGenericPoison()) return; |
| 4642 | const ty_operand = try sema.resolveTypeOrPoison(block, src, un_tok.operand) orelse return; |
| 4668 | 4643 | if (ty_operand.optEuBaseType(zcu).zigTypeTag(zcu) != .pointer) { |
| 4669 | 4644 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 4670 | 4645 | const msg = try sema.errMsg(src, "expected type '{}', found pointer", .{ty_operand.fmt(pt)}); |
| ... | ... | @@ -4696,10 +4671,7 @@ fn zirValidateArrayInitRefTy( |
| 4696 | 4671 | const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 4697 | 4672 | const src = block.nodeOffset(pl_node.src_node); |
| 4698 | 4673 | const extra = sema.code.extraData(Zir.Inst.ArrayInitRefTy, pl_node.payload_index).data; |
| 4699 | | const maybe_wrapped_ptr_ty = sema.resolveType(block, LazySrcLoc.unneeded, extra.ptr_ty) catch |err| switch (err) { |
| 4700 | | error.GenericPoison => return .generic_poison_type, |
| 4701 | | else => |e| return e, |
| 4702 | | }; |
| 4674 | const maybe_wrapped_ptr_ty = try sema.resolveTypeOrPoison(block, LazySrcLoc.unneeded, extra.ptr_ty) orelse return .generic_poison_type; |
| 4703 | 4675 | const ptr_ty = maybe_wrapped_ptr_ty.optEuBaseType(zcu); |
| 4704 | 4676 | assert(ptr_ty.zigTypeTag(zcu) == .pointer); // validated by a previous instruction |
| 4705 | 4677 | switch (zcu.intern_pool.indexToKey(ptr_ty.toIntern())) { |
| ... | ... | @@ -4740,11 +4712,8 @@ fn zirValidateArrayInitTy( |
| 4740 | 4712 | const src = block.nodeOffset(inst_data.src_node); |
| 4741 | 4713 | const ty_src: LazySrcLoc = if (is_result_ty) src else block.src(.{ .node_offset_init_ty = inst_data.src_node }); |
| 4742 | 4714 | const extra = sema.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data; |
| 4743 | | const ty = sema.resolveType(block, ty_src, extra.ty) catch |err| switch (err) { |
| 4744 | | // It's okay for the type to be unknown: this will result in an anonymous array init. |
| 4745 | | error.GenericPoison => return, |
| 4746 | | else => |e| return e, |
| 4747 | | }; |
| 4715 | // It's okay for the type to be poison: this will result in an anonymous array init. |
| 4716 | const ty = try sema.resolveTypeOrPoison(block, ty_src, extra.ty) orelse return; |
| 4748 | 4717 | const arr_ty = if (is_result_ty) ty.optEuBaseType(zcu) else ty; |
| 4749 | 4718 | return sema.validateArrayInitTy(block, src, ty_src, extra.init_count, arr_ty); |
| 4750 | 4719 | } |
| ... | ... | @@ -4803,11 +4772,8 @@ fn zirValidateStructInitTy( |
| 4803 | 4772 | const zcu = pt.zcu; |
| 4804 | 4773 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 4805 | 4774 | const src = block.nodeOffset(inst_data.src_node); |
| 4806 | | const ty = sema.resolveType(block, src, inst_data.operand) catch |err| switch (err) { |
| 4807 | | // It's okay for the type to be unknown: this will result in an anonymous struct init. |
| 4808 | | error.GenericPoison => return, |
| 4809 | | else => |e| return e, |
| 4810 | | }; |
| 4775 | // It's okay for the type to be poison: this will result in an anonymous struct init. |
| 4776 | const ty = try sema.resolveTypeOrPoison(block, src, inst_data.operand) orelse return; |
| 4811 | 4777 | const struct_ty = if (is_result_ty) ty.optEuBaseType(zcu) else ty; |
| 4812 | 4778 | |
| 4813 | 4779 | switch (struct_ty.zigTypeTag(zcu)) { |
| ... | ... | @@ -7043,7 +7009,7 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref |
| 7043 | 7009 | const field_name = try zcu.intern_pool.getOrPutString(gpa, pt.tid, "index", .no_embedded_nulls); |
| 7044 | 7010 | const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, LazySrcLoc.unneeded) catch |err| switch (err) { |
| 7045 | 7011 | error.AnalysisFail => @panic("std.builtin.StackTrace is corrupt"), |
| 7046 | | error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, |
| 7012 | error.ComptimeReturn, error.ComptimeBreak => unreachable, |
| 7047 | 7013 | error.OutOfMemory => |e| return e, |
| 7048 | 7014 | }; |
| 7049 | 7015 | |
| ... | ... | @@ -7668,6 +7634,11 @@ fn analyzeCall( |
| 7668 | 7634 | } |
| 7669 | 7635 | } |
| 7670 | 7636 | |
| 7637 | // This is whether we already know this to be an inline call. |
| 7638 | // If so, then comptime-known arguments are propagated when evaluating generic parameter/return types. |
| 7639 | // We might still learn that this call is inline *after* evaluating the generic return type. |
| 7640 | const early_known_inline = inline_requested or block.isComptime(); |
| 7641 | |
| 7671 | 7642 | // These values are undefined if `func_val == null`. |
| 7672 | 7643 | const fn_nav: InternPool.Nav, const fn_zir: Zir, const fn_tracked_inst: InternPool.TrackedInst.Index, const fn_zir_inst: Zir.Inst.Index, const fn_zir_info: Zir.FnInfo = if (func_val) |f| b: { |
| 7673 | 7644 | const info = ip.indexToKey(f.toIntern()).func; |
| ... | ... | @@ -7746,7 +7717,7 @@ fn analyzeCall( |
| 7746 | 7717 | |
| 7747 | 7718 | const extra = sema.code.extraData(Zir.Inst.Param, param_inst.data.pl_tok.payload_index); |
| 7748 | 7719 | const param_src = generic_block.tokenOffset(param_inst.data.pl_tok.src_tok); |
| 7749 | | const body = sema.code.bodySlice(extra.end, extra.data.body_len); |
| 7720 | const body = sema.code.bodySlice(extra.end, extra.data.type.body_len); |
| 7750 | 7721 | |
| 7751 | 7722 | generic_block.comptime_reason = .{ .reason = .{ |
| 7752 | 7723 | .r = .{ .simple = .function_parameters }, |
| ... | ... | @@ -7777,8 +7748,10 @@ fn analyzeCall( |
| 7777 | 7748 | const param_inst_idx = fn_zir_info.param_body[arg_idx]; |
| 7778 | 7749 | const declared_comptime = if (std.math.cast(u5, arg_idx)) |i| func_ty_info.paramIsComptime(i) else false; |
| 7779 | 7750 | const param_is_comptime = declared_comptime or try arg_ty.comptimeOnlySema(pt); |
| 7780 | | if (param_is_comptime) { |
| 7781 | | if (!try sema.isComptimeKnown(arg.*)) { |
| 7751 | // We allow comptime-known arguments to propagate to generic types not only for comptime |
| 7752 | // parameters, but if the call is known to be inline. |
| 7753 | if (param_is_comptime or early_known_inline) { |
| 7754 | if (param_is_comptime and !try sema.isComptimeKnown(arg.*)) { |
| 7782 | 7755 | assert(!declared_comptime); // `analyzeArg` handles this |
| 7783 | 7756 | const arg_src = args_info.argSrc(block, arg_idx); |
| 7784 | 7757 | const param_ty_src: LazySrcLoc = .{ |
| ... | ... | @@ -8313,14 +8286,7 @@ fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil |
| 8313 | 8286 | const pt = sema.pt; |
| 8314 | 8287 | const zcu = pt.zcu; |
| 8315 | 8288 | const bin = sema.code.instructions.items(.data)[@intFromEnum(inst)].bin; |
| 8316 | | const maybe_wrapped_indexable_ty = sema.resolveType(block, LazySrcLoc.unneeded, bin.lhs) catch |err| switch (err) { |
| 8317 | | // Since this is a ZIR instruction that returns a type, encountering |
| 8318 | | // generic poison should not result in a failed compilation, but the |
| 8319 | | // generic poison type. This prevents unnecessary failures when |
| 8320 | | // constructing types at compile-time. |
| 8321 | | error.GenericPoison => return .generic_poison_type, |
| 8322 | | else => |e| return e, |
| 8323 | | }; |
| 8289 | const maybe_wrapped_indexable_ty = try sema.resolveTypeOrPoison(block, LazySrcLoc.unneeded, bin.lhs) orelse return .generic_poison_type; |
| 8324 | 8290 | const indexable_ty = maybe_wrapped_indexable_ty.optEuBaseType(zcu); |
| 8325 | 8291 | try indexable_ty.resolveFields(pt); |
| 8326 | 8292 | assert(indexable_ty.isIndexable(zcu)); // validated by a previous instruction |
| ... | ... | @@ -8337,10 +8303,7 @@ fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 8337 | 8303 | const pt = sema.pt; |
| 8338 | 8304 | const zcu = pt.zcu; |
| 8339 | 8305 | const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 8340 | | const maybe_wrapped_ptr_ty = sema.resolveType(block, LazySrcLoc.unneeded, un_node.operand) catch |err| switch (err) { |
| 8341 | | error.GenericPoison => return .generic_poison_type, |
| 8342 | | else => |e| return e, |
| 8343 | | }; |
| 8306 | const maybe_wrapped_ptr_ty = try sema.resolveTypeOrPoison(block, LazySrcLoc.unneeded, un_node.operand) orelse return .generic_poison_type; |
| 8344 | 8307 | const ptr_ty = maybe_wrapped_ptr_ty.optEuBaseType(zcu); |
| 8345 | 8308 | assert(ptr_ty.zigTypeTag(zcu) == .pointer); // validated by a previous instruction |
| 8346 | 8309 | const elem_ty = ptr_ty.childType(zcu); |
| ... | ... | @@ -8357,10 +8320,7 @@ fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 8357 | 8320 | const zcu = pt.zcu; |
| 8358 | 8321 | const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 8359 | 8322 | const src = block.nodeOffset(un_node.src_node); |
| 8360 | | const ptr_ty = sema.resolveType(block, src, un_node.operand) catch |err| switch (err) { |
| 8361 | | error.GenericPoison => return .generic_poison_type, |
| 8362 | | else => |e| return e, |
| 8363 | | }; |
| 8323 | const ptr_ty = try sema.resolveTypeOrPoison(block, src, un_node.operand) orelse return .generic_poison_type; |
| 8364 | 8324 | try sema.checkMemOperand(block, src, ptr_ty); |
| 8365 | 8325 | const elem_ty = switch (ptr_ty.ptrSize(zcu)) { |
| 8366 | 8326 | .slice, .many, .c => ptr_ty.childType(zcu), |
| ... | ... | @@ -8373,14 +8333,7 @@ fn zirVecArrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 8373 | 8333 | const pt = sema.pt; |
| 8374 | 8334 | const zcu = pt.zcu; |
| 8375 | 8335 | const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 8376 | | const vec_ty = sema.resolveType(block, LazySrcLoc.unneeded, un_node.operand) catch |err| switch (err) { |
| 8377 | | // Since this is a ZIR instruction that returns a type, encountering |
| 8378 | | // generic poison should not result in a failed compilation, but the |
| 8379 | | // generic poison type. This prevents unnecessary failures when |
| 8380 | | // constructing types at compile-time. |
| 8381 | | error.GenericPoison => return .generic_poison_type, |
| 8382 | | else => |e| return e, |
| 8383 | | }; |
| 8336 | const vec_ty = try sema.resolveTypeOrPoison(block, LazySrcLoc.unneeded, un_node.operand) orelse return .generic_poison_type; |
| 8384 | 8337 | switch (vec_ty.zigTypeTag(zcu)) { |
| 8385 | 8338 | .array, .vector => {}, |
| 8386 | 8339 | else => return sema.fail(block, block.nodeOffset(un_node.src_node), "expected array or vector type, found '{}'", .{vec_ty.fmt(pt)}), |
| ... | ... | @@ -8702,10 +8655,7 @@ fn zirDeclLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index, do_coerce: b |
| 8702 | 8655 | .no_embedded_nulls, |
| 8703 | 8656 | ); |
| 8704 | 8657 | |
| 8705 | | const orig_ty = sema.resolveType(block, src, extra.lhs) catch |err| switch (err) { |
| 8706 | | error.GenericPoison => Type.generic_poison, |
| 8707 | | else => |e| return e, |
| 8708 | | }; |
| 8658 | const orig_ty: Type = try sema.resolveTypeOrPoison(block, src, extra.lhs) orelse .generic_poison; |
| 8709 | 8659 | |
| 8710 | 8660 | const uncoerced_result = res: { |
| 8711 | 8661 | if (orig_ty.toIntern() == .generic_poison_type) { |
| ... | ... | @@ -9232,22 +9182,17 @@ fn zirFunc( |
| 9232 | 9182 | |
| 9233 | 9183 | var extra_index = extra.end; |
| 9234 | 9184 | |
| 9235 | | const ret_ty: Type = switch (extra.data.ret_body_len) { |
| 9185 | const ret_ty: Type = if (extra.data.ret_ty.is_generic) |
| 9186 | .generic_poison |
| 9187 | else switch (extra.data.ret_ty.body_len) { |
| 9236 | 9188 | 0 => Type.void, |
| 9237 | 9189 | 1 => blk: { |
| 9238 | 9190 | const ret_ty_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 9239 | 9191 | extra_index += 1; |
| 9240 | | if (sema.resolveType(block, ret_ty_src, ret_ty_ref)) |ret_ty| { |
| 9241 | | break :blk ret_ty; |
| 9242 | | } else |err| switch (err) { |
| 9243 | | error.GenericPoison => { |
| 9244 | | break :blk Type.generic_poison; |
| 9245 | | }, |
| 9246 | | else => |e| return e, |
| 9247 | | } |
| 9192 | break :blk try sema.resolveType(block, ret_ty_src, ret_ty_ref); |
| 9248 | 9193 | }, |
| 9249 | 9194 | else => blk: { |
| 9250 | | const ret_ty_body = sema.code.bodySlice(extra_index, extra.data.ret_body_len); |
| 9195 | const ret_ty_body = sema.code.bodySlice(extra_index, extra.data.ret_ty.body_len); |
| 9251 | 9196 | extra_index += ret_ty_body.len; |
| 9252 | 9197 | |
| 9253 | 9198 | const ret_ty_val = try sema.resolveGenericBody(block, ret_ty_src, ret_ty_body, inst, Type.type, .{ .simple = .function_ret_ty }); |
| ... | ... | @@ -9319,32 +9264,16 @@ fn resolveGenericBody( |
| 9319 | 9264 | ) !Value { |
| 9320 | 9265 | assert(body.len != 0); |
| 9321 | 9266 | |
| 9322 | | const err = err: { |
| 9323 | | // Make sure any nested param instructions don't clobber our work. |
| 9324 | | const prev_params = block.params; |
| 9325 | | const prev_no_partial_func_type = sema.no_partial_func_ty; |
| 9326 | | block.params = .{}; |
| 9327 | | sema.no_partial_func_ty = true; |
| 9328 | | defer { |
| 9329 | | block.params = prev_params; |
| 9330 | | sema.no_partial_func_ty = prev_no_partial_func_type; |
| 9331 | | } |
| 9332 | | |
| 9333 | | const uncasted = sema.resolveInlineBody(block, body, func_inst) catch |err| break :err err; |
| 9334 | | const result = sema.coerce(block, dest_ty, uncasted, src) catch |err| break :err err; |
| 9335 | | const val = sema.resolveConstDefinedValue(block, src, result, reason) catch |err| break :err err; |
| 9336 | | return val; |
| 9337 | | }; |
| 9338 | | switch (err) { |
| 9339 | | error.GenericPoison => { |
| 9340 | | if (dest_ty.toIntern() == .type_type) { |
| 9341 | | return Value.generic_poison_type; |
| 9342 | | } else { |
| 9343 | | return Value.generic_poison; |
| 9344 | | } |
| 9345 | | }, |
| 9346 | | else => |e| return e, |
| 9267 | // Make sure any nested param instructions don't clobber our work. |
| 9268 | const prev_params = block.params; |
| 9269 | block.params = .{}; |
| 9270 | defer { |
| 9271 | block.params = prev_params; |
| 9347 | 9272 | } |
| 9273 | |
| 9274 | const uncasted = try sema.resolveInlineBody(block, body, func_inst); |
| 9275 | const result = try sema.coerce(block, dest_ty, uncasted, src); |
| 9276 | return sema.resolveConstDefinedValue(block, src, result, reason); |
| 9348 | 9277 | } |
| 9349 | 9278 | |
| 9350 | 9279 | /// Given a library name, examines if the library name should end up in |
| ... | ... | @@ -9593,8 +9522,6 @@ fn funcCommon( |
| 9593 | 9522 | const cc_src = block.src(.{ .node_offset_fn_type_cc = src_node_offset }); |
| 9594 | 9523 | const func_src = block.nodeOffset(src_node_offset); |
| 9595 | 9524 | |
| 9596 | | if (bare_return_type.isGenericPoison() and sema.no_partial_func_ty) return error.GenericPoison; |
| 9597 | | |
| 9598 | 9525 | const ret_ty_requires_comptime = try bare_return_type.comptimeOnlySema(pt); |
| 9599 | 9526 | var is_generic = bare_return_type.isGenericPoison() or ret_ty_requires_comptime; |
| 9600 | 9527 | |
| ... | ... | @@ -9611,9 +9538,6 @@ fn funcCommon( |
| 9611 | 9538 | } }); |
| 9612 | 9539 | const param_ty_comptime = try param_ty.comptimeOnlySema(pt); |
| 9613 | 9540 | const param_ty_generic = param_ty.isGenericPoison(); |
| 9614 | | if (param_ty_generic and sema.no_partial_func_ty) { |
| 9615 | | return error.GenericPoison; |
| 9616 | | } |
| 9617 | 9541 | if (param_is_comptime or param_ty_comptime or param_ty_generic) { |
| 9618 | 9542 | is_generic = true; |
| 9619 | 9543 | } |
| ... | ... | @@ -9962,64 +9886,25 @@ fn zirParam( |
| 9962 | 9886 | const src = block.tokenOffset(inst_data.src_tok); |
| 9963 | 9887 | const extra = sema.code.extraData(Zir.Inst.Param, inst_data.payload_index); |
| 9964 | 9888 | const param_name: Zir.NullTerminatedString = extra.data.name; |
| 9965 | | const body = sema.code.bodySlice(extra.end, extra.data.body_len); |
| 9889 | const body = sema.code.bodySlice(extra.end, extra.data.type.body_len); |
| 9966 | 9890 | |
| 9967 | | const param_ty = param_ty: { |
| 9968 | | const err = err: { |
| 9969 | | // Make sure any nested param instructions don't clobber our work. |
| 9970 | | const prev_params = block.params; |
| 9971 | | const prev_no_partial_func_type = sema.no_partial_func_ty; |
| 9972 | | block.params = .{}; |
| 9973 | | sema.no_partial_func_ty = true; |
| 9974 | | defer { |
| 9975 | | block.params = prev_params; |
| 9976 | | sema.no_partial_func_ty = prev_no_partial_func_type; |
| 9977 | | } |
| 9978 | | |
| 9979 | | if (sema.resolveInlineBody(block, body, inst)) |param_ty_inst| { |
| 9980 | | if (sema.analyzeAsType(block, src, param_ty_inst)) |param_ty| { |
| 9981 | | break :param_ty param_ty; |
| 9982 | | } else |err| break :err err; |
| 9983 | | } else |err| break :err err; |
| 9984 | | }; |
| 9985 | | switch (err) { |
| 9986 | | error.GenericPoison => { |
| 9987 | | // The type is not available until the generic instantiation. |
| 9988 | | // We result the param instruction with a poison value and |
| 9989 | | // insert an anytype parameter. |
| 9990 | | try block.params.append(sema.arena, .{ |
| 9991 | | .ty = .generic_poison_type, |
| 9992 | | .is_comptime = comptime_syntax, |
| 9993 | | .name = param_name, |
| 9994 | | }); |
| 9995 | | sema.inst_map.putAssumeCapacity(inst, .generic_poison); |
| 9996 | | return; |
| 9997 | | }, |
| 9998 | | else => |e| return e, |
| 9891 | const param_ty: Type = if (extra.data.type.is_generic) .generic_poison else ty: { |
| 9892 | // Make sure any nested param instructions don't clobber our work. |
| 9893 | const prev_params = block.params; |
| 9894 | block.params = .{}; |
| 9895 | defer { |
| 9896 | block.params = prev_params; |
| 9999 | 9897 | } |
| 10000 | | }; |
| 10001 | 9898 | |
| 10002 | | const is_comptime = try param_ty.comptimeOnlySema(sema.pt) or comptime_syntax; |
| 9899 | const param_ty_inst = try sema.resolveInlineBody(block, body, inst); |
| 9900 | break :ty try sema.analyzeAsType(block, src, param_ty_inst); |
| 9901 | }; |
| 10003 | 9902 | |
| 10004 | 9903 | try block.params.append(sema.arena, .{ |
| 10005 | 9904 | .ty = param_ty.toIntern(), |
| 10006 | 9905 | .is_comptime = comptime_syntax, |
| 10007 | 9906 | .name = param_name, |
| 10008 | 9907 | }); |
| 10009 | | |
| 10010 | | if (is_comptime) { |
| 10011 | | // If this is a comptime parameter we can add a constant generic_poison |
| 10012 | | // since this is also a generic parameter. |
| 10013 | | sema.inst_map.putAssumeCapacity(inst, .generic_poison); |
| 10014 | | } else { |
| 10015 | | // Otherwise we need a dummy runtime instruction. |
| 10016 | | const result_index: Air.Inst.Index = @enumFromInt(sema.air_instructions.len); |
| 10017 | | try sema.air_instructions.append(sema.gpa, .{ |
| 10018 | | .tag = .alloc, |
| 10019 | | .data = .{ .ty = param_ty }, |
| 10020 | | }); |
| 10021 | | sema.inst_map.putAssumeCapacity(inst, result_index.toRef()); |
| 10022 | | } |
| 10023 | 9908 | } |
| 10024 | 9909 | |
| 10025 | 9910 | fn zirParamAnytype( |
| ... | ... | @@ -10031,14 +9916,11 @@ fn zirParamAnytype( |
| 10031 | 9916 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok; |
| 10032 | 9917 | const param_name: Zir.NullTerminatedString = inst_data.start; |
| 10033 | 9918 | |
| 10034 | | // We are evaluating a generic function without any comptime args provided. |
| 10035 | | |
| 10036 | 9919 | try block.params.append(sema.arena, .{ |
| 10037 | 9920 | .ty = .generic_poison_type, |
| 10038 | 9921 | .is_comptime = comptime_syntax, |
| 10039 | 9922 | .name = param_name, |
| 10040 | 9923 | }); |
| 10041 | | sema.inst_map.putAssumeCapacity(inst, .generic_poison); |
| 10042 | 9924 | } |
| 10043 | 9925 | |
| 10044 | 9926 | fn zirAsNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -10072,24 +9954,11 @@ fn analyzeAs( |
| 10072 | 9954 | const pt = sema.pt; |
| 10073 | 9955 | const zcu = pt.zcu; |
| 10074 | 9956 | const operand = try sema.resolveInst(zir_operand); |
| 10075 | | const operand_air_inst = sema.resolveInst(zir_dest_type) catch |err| switch (err) { |
| 10076 | | error.GenericPoison => return operand, |
| 10077 | | else => |e| return e, |
| 10078 | | }; |
| 10079 | | const dest_ty = sema.analyzeAsType(block, src, operand_air_inst) catch |err| switch (err) { |
| 10080 | | error.GenericPoison => return operand, |
| 10081 | | else => |e| return e, |
| 10082 | | }; |
| 10083 | | const dest_ty_tag = dest_ty.zigTypeTagOrPoison(zcu) catch |err| switch (err) { |
| 10084 | | error.GenericPoison => return operand, |
| 10085 | | }; |
| 10086 | | |
| 10087 | | if (dest_ty_tag == .@"opaque") { |
| 10088 | | return sema.fail(block, src, "cannot cast to opaque type '{}'", .{dest_ty.fmt(pt)}); |
| 10089 | | } |
| 10090 | | |
| 10091 | | if (dest_ty_tag == .noreturn) { |
| 10092 | | return sema.fail(block, src, "cannot cast to noreturn", .{}); |
| 9957 | const dest_ty = try sema.resolveTypeOrPoison(block, src, zir_dest_type) orelse return operand; |
| 9958 | switch (dest_ty.zigTypeTag(zcu)) { |
| 9959 | .@"opaque" => return sema.fail(block, src, "cannot cast to opaque type '{}'", .{dest_ty.fmt(pt)}), |
| 9960 | .noreturn => return sema.fail(block, src, "cannot cast to noreturn", .{}), |
| 9961 | else => {}, |
| 10093 | 9962 | } |
| 10094 | 9963 | |
| 10095 | 9964 | const is_ret = if (zir_dest_type.toIndex()) |ptr_index| |
| ... | ... | @@ -15071,9 +14940,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15071 | 14940 | // and have a tuple, coerce the tuple immediately. |
| 15072 | 14941 | no_coerce: { |
| 15073 | 14942 | if (extra.res_ty == .none) break :no_coerce; |
| 15074 | | const res_ty_inst = try sema.resolveInst(extra.res_ty); |
| 15075 | | const res_ty = try sema.analyzeAsType(block, src, res_ty_inst); |
| 15076 | | if (res_ty.isGenericPoison()) break :no_coerce; |
| 14943 | const res_ty = try sema.resolveTypeOrPoison(block, src, extra.res_ty) orelse break :no_coerce; |
| 15077 | 14944 | if (!uncoerced_lhs_ty.isTuple(zcu)) break :no_coerce; |
| 15078 | 14945 | const lhs_len = uncoerced_lhs_ty.structFieldCount(zcu); |
| 15079 | 14946 | const lhs_dest_ty = switch (res_ty.zigTypeTag(zcu)) { |
| ... | ... | @@ -15313,8 +15180,8 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 15313 | 15180 | const rhs = try sema.resolveInst(extra.rhs); |
| 15314 | 15181 | const lhs_ty = sema.typeOf(lhs); |
| 15315 | 15182 | const rhs_ty = sema.typeOf(rhs); |
| 15316 | | const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(zcu); |
| 15317 | | const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(zcu); |
| 15183 | const lhs_zig_ty_tag = lhs_ty.zigTypeTag(zcu); |
| 15184 | const rhs_zig_ty_tag = rhs_ty.zigTypeTag(zcu); |
| 15318 | 15185 | try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src); |
| 15319 | 15186 | try sema.checkInvalidPtrIntArithmetic(block, src, lhs_ty); |
| 15320 | 15187 | |
| ... | ... | @@ -15479,8 +15346,8 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15479 | 15346 | const rhs = try sema.resolveInst(extra.rhs); |
| 15480 | 15347 | const lhs_ty = sema.typeOf(lhs); |
| 15481 | 15348 | const rhs_ty = sema.typeOf(rhs); |
| 15482 | | const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(zcu); |
| 15483 | | const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(zcu); |
| 15349 | const lhs_zig_ty_tag = lhs_ty.zigTypeTag(zcu); |
| 15350 | const rhs_zig_ty_tag = rhs_ty.zigTypeTag(zcu); |
| 15484 | 15351 | try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src); |
| 15485 | 15352 | try sema.checkInvalidPtrIntArithmetic(block, src, lhs_ty); |
| 15486 | 15353 | |
| ... | ... | @@ -15645,8 +15512,8 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15645 | 15512 | const rhs = try sema.resolveInst(extra.rhs); |
| 15646 | 15513 | const lhs_ty = sema.typeOf(lhs); |
| 15647 | 15514 | const rhs_ty = sema.typeOf(rhs); |
| 15648 | | const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(zcu); |
| 15649 | | const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(zcu); |
| 15515 | const lhs_zig_ty_tag = lhs_ty.zigTypeTag(zcu); |
| 15516 | const rhs_zig_ty_tag = rhs_ty.zigTypeTag(zcu); |
| 15650 | 15517 | try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src); |
| 15651 | 15518 | try sema.checkInvalidPtrIntArithmetic(block, src, lhs_ty); |
| 15652 | 15519 | |
| ... | ... | @@ -15756,8 +15623,8 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15756 | 15623 | const rhs = try sema.resolveInst(extra.rhs); |
| 15757 | 15624 | const lhs_ty = sema.typeOf(lhs); |
| 15758 | 15625 | const rhs_ty = sema.typeOf(rhs); |
| 15759 | | const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(zcu); |
| 15760 | | const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(zcu); |
| 15626 | const lhs_zig_ty_tag = lhs_ty.zigTypeTag(zcu); |
| 15627 | const rhs_zig_ty_tag = rhs_ty.zigTypeTag(zcu); |
| 15761 | 15628 | try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src); |
| 15762 | 15629 | try sema.checkInvalidPtrIntArithmetic(block, src, lhs_ty); |
| 15763 | 15630 | |
| ... | ... | @@ -16000,8 +15867,8 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 16000 | 15867 | const rhs = try sema.resolveInst(extra.rhs); |
| 16001 | 15868 | const lhs_ty = sema.typeOf(lhs); |
| 16002 | 15869 | const rhs_ty = sema.typeOf(rhs); |
| 16003 | | const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(zcu); |
| 16004 | | const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(zcu); |
| 15870 | const lhs_zig_ty_tag = lhs_ty.zigTypeTag(zcu); |
| 15871 | const rhs_zig_ty_tag = rhs_ty.zigTypeTag(zcu); |
| 16005 | 15872 | try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src); |
| 16006 | 15873 | try sema.checkInvalidPtrIntArithmetic(block, src, lhs_ty); |
| 16007 | 15874 | |
| ... | ... | @@ -16186,8 +16053,8 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 16186 | 16053 | const rhs = try sema.resolveInst(extra.rhs); |
| 16187 | 16054 | const lhs_ty = sema.typeOf(lhs); |
| 16188 | 16055 | const rhs_ty = sema.typeOf(rhs); |
| 16189 | | const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(zcu); |
| 16190 | | const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(zcu); |
| 16056 | const lhs_zig_ty_tag = lhs_ty.zigTypeTag(zcu); |
| 16057 | const rhs_zig_ty_tag = rhs_ty.zigTypeTag(zcu); |
| 16191 | 16058 | try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src); |
| 16192 | 16059 | try sema.checkInvalidPtrIntArithmetic(block, src, lhs_ty); |
| 16193 | 16060 | |
| ... | ... | @@ -16282,8 +16149,8 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 16282 | 16149 | const rhs = try sema.resolveInst(extra.rhs); |
| 16283 | 16150 | const lhs_ty = sema.typeOf(lhs); |
| 16284 | 16151 | const rhs_ty = sema.typeOf(rhs); |
| 16285 | | const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(zcu); |
| 16286 | | const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(zcu); |
| 16152 | const lhs_zig_ty_tag = lhs_ty.zigTypeTag(zcu); |
| 16153 | const rhs_zig_ty_tag = rhs_ty.zigTypeTag(zcu); |
| 16287 | 16154 | try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src); |
| 16288 | 16155 | try sema.checkInvalidPtrIntArithmetic(block, src, lhs_ty); |
| 16289 | 16156 | |
| ... | ... | @@ -16623,8 +16490,8 @@ fn analyzeArithmetic( |
| 16623 | 16490 | const zcu = pt.zcu; |
| 16624 | 16491 | const lhs_ty = sema.typeOf(lhs); |
| 16625 | 16492 | const rhs_ty = sema.typeOf(rhs); |
| 16626 | | const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(zcu); |
| 16627 | | const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(zcu); |
| 16493 | const lhs_zig_ty_tag = lhs_ty.zigTypeTag(zcu); |
| 16494 | const rhs_zig_ty_tag = rhs_ty.zigTypeTag(zcu); |
| 16628 | 16495 | try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src); |
| 16629 | 16496 | |
| 16630 | 16497 | if (lhs_zig_ty_tag == .pointer) { |
| ... | ... | @@ -19028,9 +18895,7 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 19028 | 18895 | defer child_block.instructions.deinit(sema.gpa); |
| 19029 | 18896 | |
| 19030 | 18897 | const operand = try sema.resolveInlineBody(&child_block, body, inst); |
| 19031 | | const operand_ty = sema.typeOf(operand); |
| 19032 | | if (operand_ty.isGenericPoison()) return error.GenericPoison; |
| 19033 | | return Air.internedToRef(operand_ty.toIntern()); |
| 18898 | return Air.internedToRef(sema.typeOf(operand).toIntern()); |
| 19034 | 18899 | } |
| 19035 | 18900 | |
| 19036 | 18901 | fn zirTypeofLog2IntType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -20100,7 +19965,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 20100 | 19965 | } |
| 20101 | 19966 | return err; |
| 20102 | 19967 | }; |
| 20103 | | if (ty.isGenericPoison()) return error.GenericPoison; |
| 19968 | assert(!ty.isGenericPoison()); |
| 20104 | 19969 | break :blk ty; |
| 20105 | 19970 | }; |
| 20106 | 19971 | |
| ... | ... | @@ -20252,11 +20117,8 @@ fn zirStructInitEmptyResult(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is |
| 20252 | 20117 | const zcu = pt.zcu; |
| 20253 | 20118 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 20254 | 20119 | const src = block.nodeOffset(inst_data.src_node); |
| 20255 | | const ty_operand = sema.resolveType(block, src, inst_data.operand) catch |err| switch (err) { |
| 20256 | | // Generic poison means this is an untyped anonymous empty struct/array init |
| 20257 | | error.GenericPoison => return .empty_tuple, |
| 20258 | | else => |e| return e, |
| 20259 | | }; |
| 20120 | // Generic poison means this is an untyped anonymous empty struct/array init |
| 20121 | const ty_operand = try sema.resolveTypeOrPoison(block, src, inst_data.operand) orelse return .empty_tuple; |
| 20260 | 20122 | const init_ty = if (is_byref) ty: { |
| 20261 | 20123 | const ptr_ty = ty_operand.optEuBaseType(zcu); |
| 20262 | 20124 | assert(ptr_ty.zigTypeTag(zcu) == .pointer); // validated by a previous instruction |
| ... | ... | @@ -20410,12 +20272,9 @@ fn zirStructInit( |
| 20410 | 20272 | const first_item = sema.code.extraData(Zir.Inst.StructInit.Item, extra.end).data; |
| 20411 | 20273 | const first_field_type_data = zir_datas[@intFromEnum(first_item.field_type)].pl_node; |
| 20412 | 20274 | const first_field_type_extra = sema.code.extraData(Zir.Inst.FieldType, first_field_type_data.payload_index).data; |
| 20413 | | const result_ty = sema.resolveType(block, src, first_field_type_extra.container_type) catch |err| switch (err) { |
| 20414 | | error.GenericPoison => { |
| 20415 | | // The type wasn't actually known, so treat this as an anon struct init. |
| 20416 | | return sema.structInitAnon(block, src, inst, .typed_init, extra.data, extra.end, is_ref); |
| 20417 | | }, |
| 20418 | | else => |e| return e, |
| 20275 | const result_ty = try sema.resolveTypeOrPoison(block, src, first_field_type_extra.container_type) orelse { |
| 20276 | // The type wasn't actually known, so treat this as an anon struct init. |
| 20277 | return sema.structInitAnon(block, src, inst, .typed_init, extra.data, extra.end, is_ref); |
| 20419 | 20278 | }; |
| 20420 | 20279 | const resolved_ty = result_ty.optEuBaseType(zcu); |
| 20421 | 20280 | try resolved_ty.resolveLayout(pt); |
| ... | ... | @@ -20932,12 +20791,9 @@ fn zirArrayInit( |
| 20932 | 20791 | const args = sema.code.refSlice(extra.end, extra.data.operands_len); |
| 20933 | 20792 | assert(args.len >= 2); // array_ty + at least one element |
| 20934 | 20793 | |
| 20935 | | const result_ty = sema.resolveType(block, src, args[0]) catch |err| switch (err) { |
| 20936 | | error.GenericPoison => { |
| 20937 | | // The type wasn't actually known, so treat this as an anon array init. |
| 20938 | | return sema.arrayInitAnon(block, src, args[1..], is_ref); |
| 20939 | | }, |
| 20940 | | else => |e| return e, |
| 20794 | const result_ty = try sema.resolveTypeOrPoison(block, src, args[0]) orelse { |
| 20795 | // The type wasn't actually known, so treat this as an anon array init. |
| 20796 | return sema.arrayInitAnon(block, src, args[1..], is_ref); |
| 20941 | 20797 | }; |
| 20942 | 20798 | const array_ty = result_ty.optEuBaseType(zcu); |
| 20943 | 20799 | const is_tuple = array_ty.zigTypeTag(zcu) == .@"struct"; |
| ... | ... | @@ -21185,14 +21041,7 @@ fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 21185 | 21041 | const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data; |
| 21186 | 21042 | const ty_src = block.nodeOffset(inst_data.src_node); |
| 21187 | 21043 | const field_name_src = block.src(.{ .node_offset_field_name_init = inst_data.src_node }); |
| 21188 | | const wrapped_aggregate_ty = sema.resolveType(block, ty_src, extra.container_type) catch |err| switch (err) { |
| 21189 | | // Since this is a ZIR instruction that returns a type, encountering |
| 21190 | | // generic poison should not result in a failed compilation, but the |
| 21191 | | // generic poison type. This prevents unnecessary failures when |
| 21192 | | // constructing types at compile-time. |
| 21193 | | error.GenericPoison => return .generic_poison_type, |
| 21194 | | else => |e| return e, |
| 21195 | | }; |
| 21044 | const wrapped_aggregate_ty = try sema.resolveTypeOrPoison(block, ty_src, extra.container_type) orelse return .generic_poison_type; |
| 21196 | 21045 | const aggregate_ty = wrapped_aggregate_ty.optEuBaseType(zcu); |
| 21197 | 21046 | const zir_field_name = sema.code.nullTerminatedString(extra.name_start); |
| 21198 | 21047 | const field_name = try ip.getOrPutString(sema.gpa, pt.tid, zir_field_name, .no_embedded_nulls); |
| ... | ... | @@ -24068,7 +23917,7 @@ fn checkNamespaceType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) Com |
| 24068 | 23917 | fn checkIntType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!bool { |
| 24069 | 23918 | const pt = sema.pt; |
| 24070 | 23919 | const zcu = pt.zcu; |
| 24071 | | switch (try ty.zigTypeTagOrPoison(zcu)) { |
| 23920 | switch (ty.zigTypeTag(zcu)) { |
| 24072 | 23921 | .comptime_int => return true, |
| 24073 | 23922 | .int => return false, |
| 24074 | 23923 | else => return sema.fail(block, src, "expected integer type, found '{}'", .{ty.fmt(pt)}), |
| ... | ... | @@ -24083,7 +23932,7 @@ fn checkInvalidPtrIntArithmetic( |
| 24083 | 23932 | ) CompileError!void { |
| 24084 | 23933 | const pt = sema.pt; |
| 24085 | 23934 | const zcu = pt.zcu; |
| 24086 | | switch (try ty.zigTypeTagOrPoison(zcu)) { |
| 23935 | switch (ty.zigTypeTag(zcu)) { |
| 24087 | 23936 | .pointer => switch (ty.ptrSize(zcu)) { |
| 24088 | 23937 | .one, .slice => return, |
| 24089 | 23938 | .many, .c => return sema.failWithInvalidPtrArithmetic(block, src, "pointer-integer", "addition and subtraction"), |
| ... | ... | @@ -24266,7 +24115,7 @@ fn checkAtomicPtrOperand( |
| 24266 | 24115 | }; |
| 24267 | 24116 | |
| 24268 | 24117 | const ptr_ty = sema.typeOf(ptr); |
| 24269 | | const ptr_data = switch (try ptr_ty.zigTypeTagOrPoison(zcu)) { |
| 24118 | const ptr_data = switch (ptr_ty.zigTypeTag(zcu)) { |
| 24270 | 24119 | .pointer => ptr_ty.ptrInfo(zcu), |
| 24271 | 24120 | else => { |
| 24272 | 24121 | const wanted_ptr_ty = try pt.ptrTypeSema(wanted_ptr_data); |
| ... | ... | @@ -24307,11 +24156,11 @@ fn checkIntOrVector( |
| 24307 | 24156 | const pt = sema.pt; |
| 24308 | 24157 | const zcu = pt.zcu; |
| 24309 | 24158 | const operand_ty = sema.typeOf(operand); |
| 24310 | | switch (try operand_ty.zigTypeTagOrPoison(zcu)) { |
| 24159 | switch (operand_ty.zigTypeTag(zcu)) { |
| 24311 | 24160 | .int => return operand_ty, |
| 24312 | 24161 | .vector => { |
| 24313 | 24162 | const elem_ty = operand_ty.childType(zcu); |
| 24314 | | switch (try elem_ty.zigTypeTagOrPoison(zcu)) { |
| 24163 | switch (elem_ty.zigTypeTag(zcu)) { |
| 24315 | 24164 | .int => return elem_ty, |
| 24316 | 24165 | else => return sema.fail(block, operand_src, "expected vector of integers; found vector of '{}'", .{ |
| 24317 | 24166 | elem_ty.fmt(pt), |
| ... | ... | @@ -24332,11 +24181,11 @@ fn checkIntOrVectorAllowComptime( |
| 24332 | 24181 | ) CompileError!Type { |
| 24333 | 24182 | const pt = sema.pt; |
| 24334 | 24183 | const zcu = pt.zcu; |
| 24335 | | switch (try operand_ty.zigTypeTagOrPoison(zcu)) { |
| 24184 | switch (operand_ty.zigTypeTag(zcu)) { |
| 24336 | 24185 | .int, .comptime_int => return operand_ty, |
| 24337 | 24186 | .vector => { |
| 24338 | 24187 | const elem_ty = operand_ty.childType(zcu); |
| 24339 | | switch (try elem_ty.zigTypeTagOrPoison(zcu)) { |
| 24188 | switch (elem_ty.zigTypeTag(zcu)) { |
| 24340 | 24189 | .int, .comptime_int => return elem_ty, |
| 24341 | 24190 | else => return sema.fail(block, operand_src, "expected vector of integers; found vector of '{}'", .{ |
| 24342 | 24191 | elem_ty.fmt(pt), |
| ... | ... | @@ -24406,8 +24255,8 @@ fn checkVectorizableBinaryOperands( |
| 24406 | 24255 | ) CompileError!void { |
| 24407 | 24256 | const pt = sema.pt; |
| 24408 | 24257 | const zcu = pt.zcu; |
| 24409 | | const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(zcu); |
| 24410 | | const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(zcu); |
| 24258 | const lhs_zig_ty_tag = lhs_ty.zigTypeTag(zcu); |
| 24259 | const rhs_zig_ty_tag = rhs_ty.zigTypeTag(zcu); |
| 24411 | 24260 | if (lhs_zig_ty_tag != .vector and rhs_zig_ty_tag != .vector) return; |
| 24412 | 24261 | |
| 24413 | 24262 | const lhs_is_vector = switch (lhs_zig_ty_tag) { |
| ... | ... | @@ -24987,7 +24836,7 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C |
| 24987 | 24836 | const pred_uncoerced = try sema.resolveInst(extra.pred); |
| 24988 | 24837 | const pred_ty = sema.typeOf(pred_uncoerced); |
| 24989 | 24838 | |
| 24990 | | const vec_len_u64 = switch (try pred_ty.zigTypeTagOrPoison(zcu)) { |
| 24839 | const vec_len_u64 = switch (pred_ty.zigTypeTag(zcu)) { |
| 24991 | 24840 | .vector, .array => pred_ty.arrayLen(zcu), |
| 24992 | 24841 | else => return sema.fail(block, pred_src, "expected vector or array, found '{}'", .{pred_ty.fmt(pt)}), |
| 24993 | 24842 | }; |
| ... | ... | @@ -26306,7 +26155,9 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 26306 | 26155 | break :cc .auto; |
| 26307 | 26156 | }; |
| 26308 | 26157 | |
| 26309 | | const ret_ty: Type = if (extra.data.bits.has_ret_ty_body) blk: { |
| 26158 | const ret_ty: Type = if (extra.data.bits.ret_ty_is_generic) |
| 26159 | .generic_poison |
| 26160 | else if (extra.data.bits.has_ret_ty_body) blk: { |
| 26310 | 26161 | const body_len = sema.code.extra[extra_index]; |
| 26311 | 26162 | extra_index += 1; |
| 26312 | 26163 | const body = sema.code.bodySlice(extra_index, body_len); |
| ... | ... | @@ -26318,14 +26169,8 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 26318 | 26169 | } else if (extra.data.bits.has_ret_ty_ref) blk: { |
| 26319 | 26170 | const ret_ty_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 26320 | 26171 | extra_index += 1; |
| 26321 | | const ret_ty_air_ref = sema.resolveInst(ret_ty_ref) catch |err| switch (err) { |
| 26322 | | error.GenericPoison => break :blk Type.generic_poison, |
| 26323 | | else => |e| return e, |
| 26324 | | }; |
| 26325 | | const ret_ty_val = sema.resolveConstDefinedValue(block, ret_src, ret_ty_air_ref, .{ .simple = .function_ret_ty }) catch |err| switch (err) { |
| 26326 | | error.GenericPoison => break :blk Type.generic_poison, |
| 26327 | | else => |e| return e, |
| 26328 | | }; |
| 26172 | const ret_ty_air_ref = try sema.resolveInst(ret_ty_ref); |
| 26173 | const ret_ty_val = try sema.resolveConstDefinedValue(block, ret_src, ret_ty_air_ref, .{ .simple = .function_ret_ty }); |
| 26329 | 26174 | break :blk ret_ty_val.toType(); |
| 26330 | 26175 | } else Type.void; |
| 26331 | 26176 | |
| ... | ... | @@ -27625,7 +27470,7 @@ fn fieldVal( |
| 27625 | 27470 | const val = (try sema.resolveDefinedValue(block, object_src, dereffed_type)).?; |
| 27626 | 27471 | const child_type = val.toType(); |
| 27627 | 27472 | |
| 27628 | | switch (try child_type.zigTypeTagOrPoison(zcu)) { |
| 27473 | switch (child_type.zigTypeTag(zcu)) { |
| 27629 | 27474 | .error_set => { |
| 27630 | 27475 | switch (ip.indexToKey(child_type.toIntern())) { |
| 27631 | 27476 | .error_set_type => |error_set_type| blk: { |
| ... | ... | @@ -35180,7 +35025,7 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void { |
| 35180 | 35025 | if (struct_type.layout == .@"packed") { |
| 35181 | 35026 | sema.backingIntType(struct_type) catch |err| switch (err) { |
| 35182 | 35027 | error.OutOfMemory, error.AnalysisFail => |e| return e, |
| 35183 | | error.ComptimeBreak, error.ComptimeReturn, error.GenericPoison => unreachable, |
| 35028 | error.ComptimeBreak, error.ComptimeReturn => unreachable, |
| 35184 | 35029 | }; |
| 35185 | 35030 | return; |
| 35186 | 35031 | } |
| ... | ... | @@ -35688,7 +35533,7 @@ pub fn resolveStructFieldTypes( |
| 35688 | 35533 | |
| 35689 | 35534 | sema.structFields(struct_type) catch |err| switch (err) { |
| 35690 | 35535 | error.AnalysisFail, error.OutOfMemory => |e| return e, |
| 35691 | | error.ComptimeBreak, error.ComptimeReturn, error.GenericPoison => unreachable, |
| 35536 | error.ComptimeBreak, error.ComptimeReturn => unreachable, |
| 35692 | 35537 | }; |
| 35693 | 35538 | } |
| 35694 | 35539 | |
| ... | ... | @@ -35717,7 +35562,7 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) SemaError!void { |
| 35717 | 35562 | |
| 35718 | 35563 | sema.structFieldInits(struct_type) catch |err| switch (err) { |
| 35719 | 35564 | error.AnalysisFail, error.OutOfMemory => |e| return e, |
| 35720 | | error.ComptimeBreak, error.ComptimeReturn, error.GenericPoison => unreachable, |
| 35565 | error.ComptimeBreak, error.ComptimeReturn => unreachable, |
| 35721 | 35566 | }; |
| 35722 | 35567 | struct_type.setHaveFieldInits(ip); |
| 35723 | 35568 | } |
| ... | ... | @@ -35751,7 +35596,7 @@ pub fn resolveUnionFieldTypes(sema: *Sema, ty: Type, union_type: InternPool.Load |
| 35751 | 35596 | errdefer union_type.setStatus(ip, .none); |
| 35752 | 35597 | sema.unionFields(ty.toIntern(), union_type) catch |err| switch (err) { |
| 35753 | 35598 | error.AnalysisFail, error.OutOfMemory => |e| return e, |
| 35754 | | error.ComptimeBreak, error.ComptimeReturn, error.GenericPoison => unreachable, |
| 35599 | error.ComptimeBreak, error.ComptimeReturn => unreachable, |
| 35755 | 35600 | }; |
| 35756 | 35601 | union_type.setStatus(ip, .have_field_types); |
| 35757 | 35602 | } |
| ... | ... | @@ -36078,9 +35923,6 @@ fn structFields( |
| 36078 | 35923 | const ty_ref = try sema.resolveInlineBody(&block_scope, body, zir_index); |
| 36079 | 35924 | break :ty try sema.analyzeAsType(&block_scope, ty_src, ty_ref); |
| 36080 | 35925 | }; |
| 36081 | | if (field_ty.isGenericPoison()) { |
| 36082 | | return error.GenericPoison; |
| 36083 | | } |
| 36084 | 35926 | |
| 36085 | 35927 | struct_type.field_types.get(ip)[field_i] = field_ty.toIntern(); |
| 36086 | 35928 | |
| ... | ... | @@ -36523,10 +36365,6 @@ fn unionFields( |
| 36523 | 36365 | else |
| 36524 | 36366 | try sema.resolveType(&block_scope, type_src, field_type_ref); |
| 36525 | 36367 | |
| 36526 | | if (field_ty.isGenericPoison()) { |
| 36527 | | return error.GenericPoison; |
| 36528 | | } |
| 36529 | | |
| 36530 | 36368 | if (explicit_tags_seen.len > 0) { |
| 36531 | 36369 | const tag_ty = union_type.tagTypeUnordered(ip); |
| 36532 | 36370 | const tag_info = ip.loadEnumType(tag_ty); |
| ... | ... | @@ -36779,7 +36617,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 36779 | 36617 | .null_type => Value.null, |
| 36780 | 36618 | .undefined_type => Value.undef, |
| 36781 | 36619 | .optional_noreturn_type => try pt.nullValue(ty), |
| 36782 | | .generic_poison_type => error.GenericPoison, |
| 36620 | .generic_poison_type => unreachable, |
| 36783 | 36621 | .empty_tuple_type => Value.empty_tuple, |
| 36784 | 36622 | // values, not types |
| 36785 | 36623 | .undef, |
| ... | ... | @@ -36797,7 +36635,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 36797 | 36635 | .bool_true, |
| 36798 | 36636 | .bool_false, |
| 36799 | 36637 | .empty_tuple, |
| 36800 | | .generic_poison, |
| 36801 | 36638 | // invalid |
| 36802 | 36639 | .none, |
| 36803 | 36640 | => unreachable, |
| ... | ... | @@ -38095,7 +37932,6 @@ fn notePathToComptimeAllocPtr(sema: *Sema, msg: *Zcu.ErrorMsg, src: LazySrcLoc, |
| 38095 | 37932 | ) catch |err| switch (err) { |
| 38096 | 37933 | error.OutOfMemory => |e| return e, |
| 38097 | 37934 | error.AnalysisFail => unreachable, |
| 38098 | | error.GenericPoison => unreachable, |
| 38099 | 37935 | error.ComptimeReturn => unreachable, |
| 38100 | 37936 | error.ComptimeBreak => unreachable, |
| 38101 | 37937 | }; |
| ... | ... | @@ -38410,7 +38246,6 @@ pub fn resolveDeclaredEnum( |
| 38410 | 38246 | zir, |
| 38411 | 38247 | body_end, |
| 38412 | 38248 | ) catch |err| switch (err) { |
| 38413 | | error.GenericPoison => unreachable, |
| 38414 | 38249 | error.ComptimeBreak => unreachable, |
| 38415 | 38250 | error.ComptimeReturn => unreachable, |
| 38416 | 38251 | error.OutOfMemory => |e| return e, |