| ... | @@ -1904,8 +1904,9 @@ fn resolveDefinedValue( | ... | @@ -1904,8 +1904,9 @@ fn resolveDefinedValue( |
| 1904 | src: LazySrcLoc, | 1904 | src: LazySrcLoc, |
| 1905 | air_ref: Air.Inst.Ref, | 1905 | air_ref: Air.Inst.Ref, |
| 1906 | ) CompileError!?Value { | 1906 | ) CompileError!?Value { |
| | 1907 | const mod = sema.mod; |
| 1907 | if (try sema.resolveMaybeUndefVal(air_ref)) |val| { | 1908 | if (try sema.resolveMaybeUndefVal(air_ref)) |val| { |
| 1908 | if (val.isUndef()) { | 1909 | if (val.isUndef(mod)) { |
| 1909 | if (block.is_typeof) return null; | 1910 | if (block.is_typeof) return null; |
| 1910 | return sema.failWithUseOfUndef(block, src); | 1911 | return sema.failWithUseOfUndef(block, src); |
| 1911 | } | 1912 | } |
| ... | @@ -4333,7 +4334,7 @@ fn validateUnionInit( | ... | @@ -4333,7 +4334,7 @@ fn validateUnionInit( |
| 4333 | | 4334 | |
| 4334 | const tag_ty = union_ty.unionTagTypeHypothetical(mod); | 4335 | const tag_ty = union_ty.unionTagTypeHypothetical(mod); |
| 4335 | const enum_field_index = @intCast(u32, tag_ty.enumFieldIndex(field_name, mod).?); | 4336 | const enum_field_index = @intCast(u32, tag_ty.enumFieldIndex(field_name, mod).?); |
| 4336 | const tag_val = try Value.Tag.enum_field_index.create(sema.arena, enum_field_index); | 4337 | const tag_val = try mod.enumValueFieldIndex(tag_ty, enum_field_index); |
| 4337 | | 4338 | |
| 4338 | if (init_val) |val| { | 4339 | if (init_val) |val| { |
| 4339 | // Our task is to delete all the `field_ptr` and `store` instructions, and insert | 4340 | // Our task is to delete all the `field_ptr` and `store` instructions, and insert |
| ... | @@ -4832,7 +4833,7 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -4832,7 +4833,7 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 4832 | | 4833 | |
| 4833 | const elem_ty = operand_ty.elemType2(mod); | 4834 | const elem_ty = operand_ty.elemType2(mod); |
| 4834 | if (try sema.resolveMaybeUndefVal(operand)) |val| { | 4835 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 4835 | if (val.isUndef()) { | 4836 | if (val.isUndef(mod)) { |
| 4836 | return sema.fail(block, src, "cannot dereference undefined value", .{}); | 4837 | return sema.fail(block, src, "cannot dereference undefined value", .{}); |
| 4837 | } | 4838 | } |
| 4838 | } else if (!(try sema.validateRunTimeType(elem_ty, false))) { | 4839 | } else if (!(try sema.validateRunTimeType(elem_ty, false))) { |
| ... | @@ -6194,15 +6195,16 @@ fn lookupInNamespace( | ... | @@ -6194,15 +6195,16 @@ fn lookupInNamespace( |
| 6194 | } | 6195 | } |
| 6195 | | 6196 | |
| 6196 | fn funcDeclSrc(sema: *Sema, func_inst: Air.Inst.Ref) !?*Decl { | 6197 | fn funcDeclSrc(sema: *Sema, func_inst: Air.Inst.Ref) !?*Decl { |
| | 6198 | const mod = sema.mod; |
| 6197 | const func_val = (try sema.resolveMaybeUndefVal(func_inst)) orelse return null; | 6199 | const func_val = (try sema.resolveMaybeUndefVal(func_inst)) orelse return null; |
| 6198 | if (func_val.isUndef()) return null; | 6200 | if (func_val.isUndef(mod)) return null; |
| 6199 | const owner_decl_index = switch (func_val.tag()) { | 6201 | const owner_decl_index = switch (func_val.tag()) { |
| 6200 | .extern_fn => func_val.castTag(.extern_fn).?.data.owner_decl, | 6202 | .extern_fn => func_val.castTag(.extern_fn).?.data.owner_decl, |
| 6201 | .function => func_val.castTag(.function).?.data.owner_decl, | 6203 | .function => func_val.castTag(.function).?.data.owner_decl, |
| 6202 | .decl_ref => sema.mod.declPtr(func_val.castTag(.decl_ref).?.data).val.castTag(.function).?.data.owner_decl, | 6204 | .decl_ref => mod.declPtr(func_val.castTag(.decl_ref).?.data).val.castTag(.function).?.data.owner_decl, |
| 6203 | else => return null, | 6205 | else => return null, |
| 6204 | }; | 6206 | }; |
| 6205 | return sema.mod.declPtr(owner_decl_index); | 6207 | return mod.declPtr(owner_decl_index); |
| 6206 | } | 6208 | } |
| 6207 | | 6209 | |
| 6208 | pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref { | 6210 | pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref { |
| ... | @@ -8106,7 +8108,7 @@ fn zirErrorToInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat | ... | @@ -8106,7 +8108,7 @@ fn zirErrorToInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 8106 | const operand = try sema.coerce(block, Type.anyerror, uncasted_operand, operand_src); | 8108 | const operand = try sema.coerce(block, Type.anyerror, uncasted_operand, operand_src); |
| 8107 | | 8109 | |
| 8108 | if (try sema.resolveMaybeUndefVal(operand)) |val| { | 8110 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 8109 | if (val.isUndef()) { | 8111 | if (val.isUndef(mod)) { |
| 8110 | return sema.addConstUndef(Type.err_int); | 8112 | return sema.addConstUndef(Type.err_int); |
| 8111 | } | 8113 | } |
| 8112 | switch (val.tag()) { | 8114 | switch (val.tag()) { |
| ... | @@ -8326,7 +8328,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -8326,7 +8328,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 8326 | }; | 8328 | }; |
| 8327 | return sema.failWithOwnedErrorMsg(msg); | 8329 | return sema.failWithOwnedErrorMsg(msg); |
| 8328 | } | 8330 | } |
| 8329 | if (int_val.isUndef()) { | 8331 | if (int_val.isUndef(mod)) { |
| 8330 | return sema.failWithUseOfUndef(block, operand_src); | 8332 | return sema.failWithUseOfUndef(block, operand_src); |
| 8331 | } | 8333 | } |
| 8332 | if (!(try sema.enumHasInt(dest_ty, int_val))) { | 8334 | if (!(try sema.enumHasInt(dest_ty, int_val))) { |
| ... | @@ -11472,7 +11474,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -11472,7 +11474,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 11472 | if (f != null) continue; | 11474 | if (f != null) continue; |
| 11473 | cases_len += 1; | 11475 | cases_len += 1; |
| 11474 | | 11476 | |
| 11475 | const item_val = try Value.Tag.enum_field_index.create(sema.arena, @intCast(u32, i)); | 11477 | const item_val = try mod.enumValueFieldIndex(operand_ty, @intCast(u32, i)); |
| 11476 | const item_ref = try sema.addConstant(operand_ty, item_val); | 11478 | const item_ref = try sema.addConstant(operand_ty, item_val); |
| 11477 | case_block.inline_case_capture = item_ref; | 11479 | case_block.inline_case_capture = item_ref; |
| 11478 | | 11480 | |
| ... | @@ -12208,7 +12210,7 @@ fn zirShl( | ... | @@ -12208,7 +12210,7 @@ fn zirShl( |
| 12208 | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(rhs); | 12210 | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(rhs); |
| 12209 | | 12211 | |
| 12210 | if (maybe_rhs_val) |rhs_val| { | 12212 | if (maybe_rhs_val) |rhs_val| { |
| 12211 | if (rhs_val.isUndef()) { | 12213 | if (rhs_val.isUndef(mod)) { |
| 12212 | return sema.addConstUndef(sema.typeOf(lhs)); | 12214 | return sema.addConstUndef(sema.typeOf(lhs)); |
| 12213 | } | 12215 | } |
| 12214 | // If rhs is 0, return lhs without doing any calculations. | 12216 | // If rhs is 0, return lhs without doing any calculations. |
| ... | @@ -12255,7 +12257,7 @@ fn zirShl( | ... | @@ -12255,7 +12257,7 @@ fn zirShl( |
| 12255 | } | 12257 | } |
| 12256 | | 12258 | |
| 12257 | const runtime_src = if (maybe_lhs_val) |lhs_val| rs: { | 12259 | const runtime_src = if (maybe_lhs_val) |lhs_val| rs: { |
| 12258 | if (lhs_val.isUndef()) return sema.addConstUndef(lhs_ty); | 12260 | if (lhs_val.isUndef(mod)) return sema.addConstUndef(lhs_ty); |
| 12259 | const rhs_val = maybe_rhs_val orelse { | 12261 | const rhs_val = maybe_rhs_val orelse { |
| 12260 | if (scalar_ty.zigTypeTag(mod) == .ComptimeInt) { | 12262 | if (scalar_ty.zigTypeTag(mod) == .ComptimeInt) { |
| 12261 | return sema.fail(block, src, "LHS of shift must be a fixed-width integer type, or RHS must be comptime-known", .{}); | 12263 | return sema.fail(block, src, "LHS of shift must be a fixed-width integer type, or RHS must be comptime-known", .{}); |
| ... | @@ -12389,7 +12391,7 @@ fn zirShr( | ... | @@ -12389,7 +12391,7 @@ fn zirShr( |
| 12389 | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(rhs); | 12391 | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(rhs); |
| 12390 | | 12392 | |
| 12391 | const runtime_src = if (maybe_rhs_val) |rhs_val| rs: { | 12393 | const runtime_src = if (maybe_rhs_val) |rhs_val| rs: { |
| 12392 | if (rhs_val.isUndef()) { | 12394 | if (rhs_val.isUndef(mod)) { |
| 12393 | return sema.addConstUndef(lhs_ty); | 12395 | return sema.addConstUndef(lhs_ty); |
| 12394 | } | 12396 | } |
| 12395 | // If rhs is 0, return lhs without doing any calculations. | 12397 | // If rhs is 0, return lhs without doing any calculations. |
| ... | @@ -12434,7 +12436,7 @@ fn zirShr( | ... | @@ -12434,7 +12436,7 @@ fn zirShr( |
| 12434 | }); | 12436 | }); |
| 12435 | } | 12437 | } |
| 12436 | if (maybe_lhs_val) |lhs_val| { | 12438 | if (maybe_lhs_val) |lhs_val| { |
| 12437 | if (lhs_val.isUndef()) { | 12439 | if (lhs_val.isUndef(mod)) { |
| 12438 | return sema.addConstUndef(lhs_ty); | 12440 | return sema.addConstUndef(lhs_ty); |
| 12439 | } | 12441 | } |
| 12440 | if (air_tag == .shr_exact) { | 12442 | if (air_tag == .shr_exact) { |
| ... | @@ -12578,7 +12580,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -12578,7 +12580,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 12578 | } | 12580 | } |
| 12579 | | 12581 | |
| 12580 | if (try sema.resolveMaybeUndefVal(operand)) |val| { | 12582 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 12581 | if (val.isUndef()) { | 12583 | if (val.isUndef(mod)) { |
| 12582 | return sema.addConstUndef(operand_type); | 12584 | return sema.addConstUndef(operand_type); |
| 12583 | } else if (operand_type.zigTypeTag(mod) == .Vector) { | 12585 | } else if (operand_type.zigTypeTag(mod) == .Vector) { |
| 12584 | const vec_len = try sema.usizeCast(block, operand_src, operand_type.vectorLen(mod)); | 12586 | const vec_len = try sema.usizeCast(block, operand_src, operand_type.vectorLen(mod)); |
| ... | @@ -13154,7 +13156,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -13154,7 +13156,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 13154 | if (rhs_scalar_ty.isAnyFloat()) { | 13156 | if (rhs_scalar_ty.isAnyFloat()) { |
| 13155 | // We handle float negation here to ensure negative zero is represented in the bits. | 13157 | // We handle float negation here to ensure negative zero is represented in the bits. |
| 13156 | if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| { | 13158 | if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| { |
| 13157 | if (rhs_val.isUndef()) return sema.addConstUndef(rhs_ty); | 13159 | if (rhs_val.isUndef(mod)) return sema.addConstUndef(rhs_ty); |
| 13158 | return sema.addConstant(rhs_ty, try rhs_val.floatNeg(rhs_ty, sema.arena, sema.mod)); | 13160 | return sema.addConstant(rhs_ty, try rhs_val.floatNeg(rhs_ty, sema.arena, sema.mod)); |
| 13159 | } | 13161 | } |
| 13160 | try sema.requireRuntimeBlock(block, src, null); | 13162 | try sema.requireRuntimeBlock(block, src, null); |
| ... | @@ -13297,7 +13299,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins | ... | @@ -13297,7 +13299,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 13297 | switch (scalar_tag) { | 13299 | switch (scalar_tag) { |
| 13298 | .Int, .ComptimeInt, .ComptimeFloat => { | 13300 | .Int, .ComptimeInt, .ComptimeFloat => { |
| 13299 | if (maybe_lhs_val) |lhs_val| { | 13301 | if (maybe_lhs_val) |lhs_val| { |
| 13300 | if (!lhs_val.isUndef()) { | 13302 | if (!lhs_val.isUndef(mod)) { |
| 13301 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { | 13303 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 13302 | const scalar_zero = switch (scalar_tag) { | 13304 | const scalar_zero = switch (scalar_tag) { |
| 13303 | .ComptimeFloat, .Float => try mod.floatValue(resolved_type.scalarType(mod), 0), | 13305 | .ComptimeFloat, .Float => try mod.floatValue(resolved_type.scalarType(mod), 0), |
| ... | @@ -13312,7 +13314,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins | ... | @@ -13312,7 +13314,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 13312 | } | 13314 | } |
| 13313 | } | 13315 | } |
| 13314 | if (maybe_rhs_val) |rhs_val| { | 13316 | if (maybe_rhs_val) |rhs_val| { |
| 13315 | if (rhs_val.isUndef()) { | 13317 | if (rhs_val.isUndef(mod)) { |
| 13316 | return sema.failWithUseOfUndef(block, rhs_src); | 13318 | return sema.failWithUseOfUndef(block, rhs_src); |
| 13317 | } | 13319 | } |
| 13318 | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) { | 13320 | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) { |
| ... | @@ -13326,7 +13328,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins | ... | @@ -13326,7 +13328,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 13326 | | 13328 | |
| 13327 | const runtime_src = rs: { | 13329 | const runtime_src = rs: { |
| 13328 | if (maybe_lhs_val) |lhs_val| { | 13330 | if (maybe_lhs_val) |lhs_val| { |
| 13329 | if (lhs_val.isUndef()) { | 13331 | if (lhs_val.isUndef(mod)) { |
| 13330 | if (lhs_scalar_ty.isSignedInt(mod) and rhs_scalar_ty.isSignedInt(mod)) { | 13332 | if (lhs_scalar_ty.isSignedInt(mod) and rhs_scalar_ty.isSignedInt(mod)) { |
| 13331 | if (maybe_rhs_val) |rhs_val| { | 13333 | if (maybe_rhs_val) |rhs_val| { |
| 13332 | if (try sema.compareAll(rhs_val, .neq, try mod.intValue(resolved_type, -1), resolved_type)) { | 13334 | if (try sema.compareAll(rhs_val, .neq, try mod.intValue(resolved_type, -1), resolved_type)) { |
| ... | @@ -13434,7 +13436,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13434,7 +13436,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13434 | // If the lhs is undefined, compile error because there is a possible | 13436 | // If the lhs is undefined, compile error because there is a possible |
| 13435 | // value for which the division would result in a remainder. | 13437 | // value for which the division would result in a remainder. |
| 13436 | if (maybe_lhs_val) |lhs_val| { | 13438 | if (maybe_lhs_val) |lhs_val| { |
| 13437 | if (lhs_val.isUndef()) { | 13439 | if (lhs_val.isUndef(mod)) { |
| 13438 | return sema.failWithUseOfUndef(block, rhs_src); | 13440 | return sema.failWithUseOfUndef(block, rhs_src); |
| 13439 | } else { | 13441 | } else { |
| 13440 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { | 13442 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| ... | @@ -13451,7 +13453,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13451,7 +13453,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13451 | } | 13453 | } |
| 13452 | } | 13454 | } |
| 13453 | if (maybe_rhs_val) |rhs_val| { | 13455 | if (maybe_rhs_val) |rhs_val| { |
| 13454 | if (rhs_val.isUndef()) { | 13456 | if (rhs_val.isUndef(mod)) { |
| 13455 | return sema.failWithUseOfUndef(block, rhs_src); | 13457 | return sema.failWithUseOfUndef(block, rhs_src); |
| 13456 | } | 13458 | } |
| 13457 | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) { | 13459 | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) { |
| ... | @@ -13611,7 +13613,7 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13611,7 +13613,7 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13611 | // value (zero) for which the division would be illegal behavior. | 13613 | // value (zero) for which the division would be illegal behavior. |
| 13612 | // If the lhs is undefined, result is undefined. | 13614 | // If the lhs is undefined, result is undefined. |
| 13613 | if (maybe_lhs_val) |lhs_val| { | 13615 | if (maybe_lhs_val) |lhs_val| { |
| 13614 | if (!lhs_val.isUndef()) { | 13616 | if (!lhs_val.isUndef(mod)) { |
| 13615 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { | 13617 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 13616 | const scalar_zero = switch (scalar_tag) { | 13618 | const scalar_zero = switch (scalar_tag) { |
| 13617 | .ComptimeFloat, .Float => try mod.floatValue(resolved_type.scalarType(mod), 0), | 13619 | .ComptimeFloat, .Float => try mod.floatValue(resolved_type.scalarType(mod), 0), |
| ... | @@ -13626,7 +13628,7 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13626,7 +13628,7 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13626 | } | 13628 | } |
| 13627 | } | 13629 | } |
| 13628 | if (maybe_rhs_val) |rhs_val| { | 13630 | if (maybe_rhs_val) |rhs_val| { |
| 13629 | if (rhs_val.isUndef()) { | 13631 | if (rhs_val.isUndef(mod)) { |
| 13630 | return sema.failWithUseOfUndef(block, rhs_src); | 13632 | return sema.failWithUseOfUndef(block, rhs_src); |
| 13631 | } | 13633 | } |
| 13632 | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) { | 13634 | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) { |
| ... | @@ -13635,7 +13637,7 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13635,7 +13637,7 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13635 | // TODO: if the RHS is one, return the LHS directly | 13637 | // TODO: if the RHS is one, return the LHS directly |
| 13636 | } | 13638 | } |
| 13637 | if (maybe_lhs_val) |lhs_val| { | 13639 | if (maybe_lhs_val) |lhs_val| { |
| 13638 | if (lhs_val.isUndef()) { | 13640 | if (lhs_val.isUndef(mod)) { |
| 13639 | if (lhs_scalar_ty.isSignedInt(mod) and rhs_scalar_ty.isSignedInt(mod)) { | 13641 | if (lhs_scalar_ty.isSignedInt(mod) and rhs_scalar_ty.isSignedInt(mod)) { |
| 13640 | if (maybe_rhs_val) |rhs_val| { | 13642 | if (maybe_rhs_val) |rhs_val| { |
| 13641 | if (try sema.compareAll(rhs_val, .neq, try mod.intValue(resolved_type, -1), resolved_type)) { | 13643 | if (try sema.compareAll(rhs_val, .neq, try mod.intValue(resolved_type, -1), resolved_type)) { |
| ... | @@ -13732,7 +13734,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13732,7 +13734,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13732 | // value (zero) for which the division would be illegal behavior. | 13734 | // value (zero) for which the division would be illegal behavior. |
| 13733 | // If the lhs is undefined, result is undefined. | 13735 | // If the lhs is undefined, result is undefined. |
| 13734 | if (maybe_lhs_val) |lhs_val| { | 13736 | if (maybe_lhs_val) |lhs_val| { |
| 13735 | if (!lhs_val.isUndef()) { | 13737 | if (!lhs_val.isUndef(mod)) { |
| 13736 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { | 13738 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 13737 | const scalar_zero = switch (scalar_tag) { | 13739 | const scalar_zero = switch (scalar_tag) { |
| 13738 | .ComptimeFloat, .Float => try mod.floatValue(resolved_type.scalarType(mod), 0), | 13740 | .ComptimeFloat, .Float => try mod.floatValue(resolved_type.scalarType(mod), 0), |
| ... | @@ -13747,7 +13749,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13747,7 +13749,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13747 | } | 13749 | } |
| 13748 | } | 13750 | } |
| 13749 | if (maybe_rhs_val) |rhs_val| { | 13751 | if (maybe_rhs_val) |rhs_val| { |
| 13750 | if (rhs_val.isUndef()) { | 13752 | if (rhs_val.isUndef(mod)) { |
| 13751 | return sema.failWithUseOfUndef(block, rhs_src); | 13753 | return sema.failWithUseOfUndef(block, rhs_src); |
| 13752 | } | 13754 | } |
| 13753 | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) { | 13755 | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) { |
| ... | @@ -13755,7 +13757,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13755,7 +13757,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13755 | } | 13757 | } |
| 13756 | } | 13758 | } |
| 13757 | if (maybe_lhs_val) |lhs_val| { | 13759 | if (maybe_lhs_val) |lhs_val| { |
| 13758 | if (lhs_val.isUndef()) { | 13760 | if (lhs_val.isUndef(mod)) { |
| 13759 | if (lhs_scalar_ty.isSignedInt(mod) and rhs_scalar_ty.isSignedInt(mod)) { | 13761 | if (lhs_scalar_ty.isSignedInt(mod) and rhs_scalar_ty.isSignedInt(mod)) { |
| 13760 | if (maybe_rhs_val) |rhs_val| { | 13762 | if (maybe_rhs_val) |rhs_val| { |
| 13761 | if (try sema.compareAll(rhs_val, .neq, try mod.intValue(resolved_type, -1), resolved_type)) { | 13763 | if (try sema.compareAll(rhs_val, .neq, try mod.intValue(resolved_type, -1), resolved_type)) { |
| ... | @@ -13977,7 +13979,7 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -13977,7 +13979,7 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 13977 | // then emit a compile error saying you have to pick one. | 13979 | // then emit a compile error saying you have to pick one. |
| 13978 | if (is_int) { | 13980 | if (is_int) { |
| 13979 | if (maybe_lhs_val) |lhs_val| { | 13981 | if (maybe_lhs_val) |lhs_val| { |
| 13980 | if (lhs_val.isUndef()) { | 13982 | if (lhs_val.isUndef(mod)) { |
| 13981 | return sema.failWithUseOfUndef(block, lhs_src); | 13983 | return sema.failWithUseOfUndef(block, lhs_src); |
| 13982 | } | 13984 | } |
| 13983 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { | 13985 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| ... | @@ -13995,7 +13997,7 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -13995,7 +13997,7 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 13995 | return sema.failWithModRemNegative(block, lhs_src, lhs_ty, rhs_ty); | 13997 | return sema.failWithModRemNegative(block, lhs_src, lhs_ty, rhs_ty); |
| 13996 | } | 13998 | } |
| 13997 | if (maybe_rhs_val) |rhs_val| { | 13999 | if (maybe_rhs_val) |rhs_val| { |
| 13998 | if (rhs_val.isUndef()) { | 14000 | if (rhs_val.isUndef(mod)) { |
| 13999 | return sema.failWithUseOfUndef(block, rhs_src); | 14001 | return sema.failWithUseOfUndef(block, rhs_src); |
| 14000 | } | 14002 | } |
| 14001 | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) { | 14003 | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) { |
| ... | @@ -14024,7 +14026,7 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -14024,7 +14026,7 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 14024 | } | 14026 | } |
| 14025 | // float operands | 14027 | // float operands |
| 14026 | if (maybe_rhs_val) |rhs_val| { | 14028 | if (maybe_rhs_val) |rhs_val| { |
| 14027 | if (rhs_val.isUndef()) { | 14029 | if (rhs_val.isUndef(mod)) { |
| 14028 | return sema.failWithUseOfUndef(block, rhs_src); | 14030 | return sema.failWithUseOfUndef(block, rhs_src); |
| 14029 | } | 14031 | } |
| 14030 | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) { | 14032 | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) { |
| ... | @@ -14034,7 +14036,7 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -14034,7 +14036,7 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 14034 | return sema.failWithModRemNegative(block, rhs_src, lhs_ty, rhs_ty); | 14036 | return sema.failWithModRemNegative(block, rhs_src, lhs_ty, rhs_ty); |
| 14035 | } | 14037 | } |
| 14036 | if (maybe_lhs_val) |lhs_val| { | 14038 | if (maybe_lhs_val) |lhs_val| { |
| 14037 | if (lhs_val.isUndef() or !(try lhs_val.compareAllWithZeroAdvanced(.gte, sema))) { | 14039 | if (lhs_val.isUndef(mod) or !(try lhs_val.compareAllWithZeroAdvanced(.gte, sema))) { |
| 14038 | return sema.failWithModRemNegative(block, lhs_src, lhs_ty, rhs_ty); | 14040 | return sema.failWithModRemNegative(block, lhs_src, lhs_ty, rhs_ty); |
| 14039 | } | 14041 | } |
| 14040 | return sema.addConstant( | 14042 | return sema.addConstant( |
| ... | @@ -14155,12 +14157,12 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins | ... | @@ -14155,12 +14157,12 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 14155 | // If the lhs is undefined, result is undefined. | 14157 | // If the lhs is undefined, result is undefined. |
| 14156 | if (is_int) { | 14158 | if (is_int) { |
| 14157 | if (maybe_lhs_val) |lhs_val| { | 14159 | if (maybe_lhs_val) |lhs_val| { |
| 14158 | if (lhs_val.isUndef()) { | 14160 | if (lhs_val.isUndef(mod)) { |
| 14159 | return sema.failWithUseOfUndef(block, lhs_src); | 14161 | return sema.failWithUseOfUndef(block, lhs_src); |
| 14160 | } | 14162 | } |
| 14161 | } | 14163 | } |
| 14162 | if (maybe_rhs_val) |rhs_val| { | 14164 | if (maybe_rhs_val) |rhs_val| { |
| 14163 | if (rhs_val.isUndef()) { | 14165 | if (rhs_val.isUndef(mod)) { |
| 14164 | return sema.failWithUseOfUndef(block, rhs_src); | 14166 | return sema.failWithUseOfUndef(block, rhs_src); |
| 14165 | } | 14167 | } |
| 14166 | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) { | 14168 | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) { |
| ... | @@ -14179,7 +14181,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins | ... | @@ -14179,7 +14181,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 14179 | } | 14181 | } |
| 14180 | // float operands | 14182 | // float operands |
| 14181 | if (maybe_rhs_val) |rhs_val| { | 14183 | if (maybe_rhs_val) |rhs_val| { |
| 14182 | if (rhs_val.isUndef()) { | 14184 | if (rhs_val.isUndef(mod)) { |
| 14183 | return sema.failWithUseOfUndef(block, rhs_src); | 14185 | return sema.failWithUseOfUndef(block, rhs_src); |
| 14184 | } | 14186 | } |
| 14185 | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) { | 14187 | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) { |
| ... | @@ -14187,7 +14189,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins | ... | @@ -14187,7 +14189,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 14187 | } | 14189 | } |
| 14188 | } | 14190 | } |
| 14189 | if (maybe_lhs_val) |lhs_val| { | 14191 | if (maybe_lhs_val) |lhs_val| { |
| 14190 | if (lhs_val.isUndef()) { | 14192 | if (lhs_val.isUndef(mod)) { |
| 14191 | return sema.addConstUndef(resolved_type); | 14193 | return sema.addConstUndef(resolved_type); |
| 14192 | } | 14194 | } |
| 14193 | if (maybe_rhs_val) |rhs_val| { | 14195 | if (maybe_rhs_val) |rhs_val| { |
| ... | @@ -14257,12 +14259,12 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins | ... | @@ -14257,12 +14259,12 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 14257 | // If the lhs is undefined, result is undefined. | 14259 | // If the lhs is undefined, result is undefined. |
| 14258 | if (is_int) { | 14260 | if (is_int) { |
| 14259 | if (maybe_lhs_val) |lhs_val| { | 14261 | if (maybe_lhs_val) |lhs_val| { |
| 14260 | if (lhs_val.isUndef()) { | 14262 | if (lhs_val.isUndef(mod)) { |
| 14261 | return sema.failWithUseOfUndef(block, lhs_src); | 14263 | return sema.failWithUseOfUndef(block, lhs_src); |
| 14262 | } | 14264 | } |
| 14263 | } | 14265 | } |
| 14264 | if (maybe_rhs_val) |rhs_val| { | 14266 | if (maybe_rhs_val) |rhs_val| { |
| 14265 | if (rhs_val.isUndef()) { | 14267 | if (rhs_val.isUndef(mod)) { |
| 14266 | return sema.failWithUseOfUndef(block, rhs_src); | 14268 | return sema.failWithUseOfUndef(block, rhs_src); |
| 14267 | } | 14269 | } |
| 14268 | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) { | 14270 | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) { |
| ... | @@ -14281,7 +14283,7 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins | ... | @@ -14281,7 +14283,7 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 14281 | } | 14283 | } |
| 14282 | // float operands | 14284 | // float operands |
| 14283 | if (maybe_rhs_val) |rhs_val| { | 14285 | if (maybe_rhs_val) |rhs_val| { |
| 14284 | if (rhs_val.isUndef()) { | 14286 | if (rhs_val.isUndef(mod)) { |
| 14285 | return sema.failWithUseOfUndef(block, rhs_src); | 14287 | return sema.failWithUseOfUndef(block, rhs_src); |
| 14286 | } | 14288 | } |
| 14287 | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) { | 14289 | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) { |
| ... | @@ -14289,7 +14291,7 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins | ... | @@ -14289,7 +14291,7 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 14289 | } | 14291 | } |
| 14290 | } | 14292 | } |
| 14291 | if (maybe_lhs_val) |lhs_val| { | 14293 | if (maybe_lhs_val) |lhs_val| { |
| 14292 | if (lhs_val.isUndef()) { | 14294 | if (lhs_val.isUndef(mod)) { |
| 14293 | return sema.addConstUndef(resolved_type); | 14295 | return sema.addConstUndef(resolved_type); |
| 14294 | } | 14296 | } |
| 14295 | if (maybe_rhs_val) |rhs_val| { | 14297 | if (maybe_rhs_val) |rhs_val| { |
| ... | @@ -14372,18 +14374,18 @@ fn zirOverflowArithmetic( | ... | @@ -14372,18 +14374,18 @@ fn zirOverflowArithmetic( |
| 14372 | // to the result, even if it is undefined.. | 14374 | // to the result, even if it is undefined.. |
| 14373 | // Otherwise, if either of the argument is undefined, undefined is returned. | 14375 | // Otherwise, if either of the argument is undefined, undefined is returned. |
| 14374 | if (maybe_lhs_val) |lhs_val| { | 14376 | if (maybe_lhs_val) |lhs_val| { |
| 14375 | if (!lhs_val.isUndef() and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema))) { | 14377 | if (!lhs_val.isUndef(mod) and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema))) { |
| 14376 | break :result .{ .overflow_bit = try maybeRepeated(sema, dest_ty, zero), .inst = rhs }; | 14378 | break :result .{ .overflow_bit = try maybeRepeated(sema, dest_ty, zero), .inst = rhs }; |
| 14377 | } | 14379 | } |
| 14378 | } | 14380 | } |
| 14379 | if (maybe_rhs_val) |rhs_val| { | 14381 | if (maybe_rhs_val) |rhs_val| { |
| 14380 | if (!rhs_val.isUndef() and (try rhs_val.compareAllWithZeroAdvanced(.eq, sema))) { | 14382 | if (!rhs_val.isUndef(mod) and (try rhs_val.compareAllWithZeroAdvanced(.eq, sema))) { |
| 14381 | break :result .{ .overflow_bit = try maybeRepeated(sema, dest_ty, zero), .inst = lhs }; | 14383 | break :result .{ .overflow_bit = try maybeRepeated(sema, dest_ty, zero), .inst = lhs }; |
| 14382 | } | 14384 | } |
| 14383 | } | 14385 | } |
| 14384 | if (maybe_lhs_val) |lhs_val| { | 14386 | if (maybe_lhs_val) |lhs_val| { |
| 14385 | if (maybe_rhs_val) |rhs_val| { | 14387 | if (maybe_rhs_val) |rhs_val| { |
| 14386 | if (lhs_val.isUndef() or rhs_val.isUndef()) { | 14388 | if (lhs_val.isUndef(mod) or rhs_val.isUndef(mod)) { |
| 14387 | break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef }; | 14389 | break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef }; |
| 14388 | } | 14390 | } |
| 14389 | | 14391 | |
| ... | @@ -14396,12 +14398,12 @@ fn zirOverflowArithmetic( | ... | @@ -14396,12 +14398,12 @@ fn zirOverflowArithmetic( |
| 14396 | // If the rhs is zero, then the result is lhs and no overflow occured. | 14398 | // If the rhs is zero, then the result is lhs and no overflow occured. |
| 14397 | // Otherwise, if either result is undefined, both results are undefined. | 14399 | // Otherwise, if either result is undefined, both results are undefined. |
| 14398 | if (maybe_rhs_val) |rhs_val| { | 14400 | if (maybe_rhs_val) |rhs_val| { |
| 14399 | if (rhs_val.isUndef()) { | 14401 | if (rhs_val.isUndef(mod)) { |
| 14400 | break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef }; | 14402 | break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef }; |
| 14401 | } else if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { | 14403 | } else if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 14402 | break :result .{ .overflow_bit = try maybeRepeated(sema, dest_ty, zero), .inst = lhs }; | 14404 | break :result .{ .overflow_bit = try maybeRepeated(sema, dest_ty, zero), .inst = lhs }; |
| 14403 | } else if (maybe_lhs_val) |lhs_val| { | 14405 | } else if (maybe_lhs_val) |lhs_val| { |
| 14404 | if (lhs_val.isUndef()) { | 14406 | if (lhs_val.isUndef(mod)) { |
| 14405 | break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef }; | 14407 | break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef }; |
| 14406 | } | 14408 | } |
| 14407 | | 14409 | |
| ... | @@ -14416,7 +14418,7 @@ fn zirOverflowArithmetic( | ... | @@ -14416,7 +14418,7 @@ fn zirOverflowArithmetic( |
| 14416 | // Otherwise, if either of the arguments is undefined, both results are undefined. | 14418 | // Otherwise, if either of the arguments is undefined, both results are undefined. |
| 14417 | const scalar_one = try mod.intValue(dest_ty.scalarType(mod), 1); | 14419 | const scalar_one = try mod.intValue(dest_ty.scalarType(mod), 1); |
| 14418 | if (maybe_lhs_val) |lhs_val| { | 14420 | if (maybe_lhs_val) |lhs_val| { |
| 14419 | if (!lhs_val.isUndef()) { | 14421 | if (!lhs_val.isUndef(mod)) { |
| 14420 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { | 14422 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 14421 | break :result .{ .overflow_bit = try maybeRepeated(sema, dest_ty, zero), .inst = lhs }; | 14423 | break :result .{ .overflow_bit = try maybeRepeated(sema, dest_ty, zero), .inst = lhs }; |
| 14422 | } else if (try sema.compareAll(lhs_val, .eq, try maybeRepeated(sema, dest_ty, scalar_one), dest_ty)) { | 14424 | } else if (try sema.compareAll(lhs_val, .eq, try maybeRepeated(sema, dest_ty, scalar_one), dest_ty)) { |
| ... | @@ -14426,7 +14428,7 @@ fn zirOverflowArithmetic( | ... | @@ -14426,7 +14428,7 @@ fn zirOverflowArithmetic( |
| 14426 | } | 14428 | } |
| 14427 | | 14429 | |
| 14428 | if (maybe_rhs_val) |rhs_val| { | 14430 | if (maybe_rhs_val) |rhs_val| { |
| 14429 | if (!rhs_val.isUndef()) { | 14431 | if (!rhs_val.isUndef(mod)) { |
| 14430 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { | 14432 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 14431 | break :result .{ .overflow_bit = try maybeRepeated(sema, dest_ty, zero), .inst = rhs }; | 14433 | break :result .{ .overflow_bit = try maybeRepeated(sema, dest_ty, zero), .inst = rhs }; |
| 14432 | } else if (try sema.compareAll(rhs_val, .eq, try maybeRepeated(sema, dest_ty, scalar_one), dest_ty)) { | 14434 | } else if (try sema.compareAll(rhs_val, .eq, try maybeRepeated(sema, dest_ty, scalar_one), dest_ty)) { |
| ... | @@ -14437,7 +14439,7 @@ fn zirOverflowArithmetic( | ... | @@ -14437,7 +14439,7 @@ fn zirOverflowArithmetic( |
| 14437 | | 14439 | |
| 14438 | if (maybe_lhs_val) |lhs_val| { | 14440 | if (maybe_lhs_val) |lhs_val| { |
| 14439 | if (maybe_rhs_val) |rhs_val| { | 14441 | if (maybe_rhs_val) |rhs_val| { |
| 14440 | if (lhs_val.isUndef() or rhs_val.isUndef()) { | 14442 | if (lhs_val.isUndef(mod) or rhs_val.isUndef(mod)) { |
| 14441 | break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef }; | 14443 | break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef }; |
| 14442 | } | 14444 | } |
| 14443 | | 14445 | |
| ... | @@ -14451,18 +14453,18 @@ fn zirOverflowArithmetic( | ... | @@ -14451,18 +14453,18 @@ fn zirOverflowArithmetic( |
| 14451 | // If rhs is zero, the result is lhs (even if undefined) and no overflow occurred. | 14453 | // If rhs is zero, the result is lhs (even if undefined) and no overflow occurred. |
| 14452 | // Oterhwise if either of the arguments is undefined, both results are undefined. | 14454 | // Oterhwise if either of the arguments is undefined, both results are undefined. |
| 14453 | if (maybe_lhs_val) |lhs_val| { | 14455 | if (maybe_lhs_val) |lhs_val| { |
| 14454 | if (!lhs_val.isUndef() and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema))) { | 14456 | if (!lhs_val.isUndef(mod) and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema))) { |
| 14455 | break :result .{ .overflow_bit = try maybeRepeated(sema, dest_ty, zero), .inst = lhs }; | 14457 | break :result .{ .overflow_bit = try maybeRepeated(sema, dest_ty, zero), .inst = lhs }; |
| 14456 | } | 14458 | } |
| 14457 | } | 14459 | } |
| 14458 | if (maybe_rhs_val) |rhs_val| { | 14460 | if (maybe_rhs_val) |rhs_val| { |
| 14459 | if (!rhs_val.isUndef() and (try rhs_val.compareAllWithZeroAdvanced(.eq, sema))) { | 14461 | if (!rhs_val.isUndef(mod) and (try rhs_val.compareAllWithZeroAdvanced(.eq, sema))) { |
| 14460 | break :result .{ .overflow_bit = try maybeRepeated(sema, dest_ty, zero), .inst = lhs }; | 14462 | break :result .{ .overflow_bit = try maybeRepeated(sema, dest_ty, zero), .inst = lhs }; |
| 14461 | } | 14463 | } |
| 14462 | } | 14464 | } |
| 14463 | if (maybe_lhs_val) |lhs_val| { | 14465 | if (maybe_lhs_val) |lhs_val| { |
| 14464 | if (maybe_rhs_val) |rhs_val| { | 14466 | if (maybe_rhs_val) |rhs_val| { |
| 14465 | if (lhs_val.isUndef() or rhs_val.isUndef()) { | 14467 | if (lhs_val.isUndef(mod) or rhs_val.isUndef(mod)) { |
| 14466 | break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef }; | 14468 | break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef }; |
| 14467 | } | 14469 | } |
| 14468 | | 14470 | |
| ... | @@ -14606,12 +14608,12 @@ fn analyzeArithmetic( | ... | @@ -14606,12 +14608,12 @@ fn analyzeArithmetic( |
| 14606 | // overflow (max_int), causing illegal behavior. | 14608 | // overflow (max_int), causing illegal behavior. |
| 14607 | // For floats: either operand being undef makes the result undef. | 14609 | // For floats: either operand being undef makes the result undef. |
| 14608 | if (maybe_lhs_val) |lhs_val| { | 14610 | if (maybe_lhs_val) |lhs_val| { |
| 14609 | if (!lhs_val.isUndef() and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema))) { | 14611 | if (!lhs_val.isUndef(mod) and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema))) { |
| 14610 | return casted_rhs; | 14612 | return casted_rhs; |
| 14611 | } | 14613 | } |
| 14612 | } | 14614 | } |
| 14613 | if (maybe_rhs_val) |rhs_val| { | 14615 | if (maybe_rhs_val) |rhs_val| { |
| 14614 | if (rhs_val.isUndef()) { | 14616 | if (rhs_val.isUndef(mod)) { |
| 14615 | if (is_int) { | 14617 | if (is_int) { |
| 14616 | return sema.failWithUseOfUndef(block, rhs_src); | 14618 | return sema.failWithUseOfUndef(block, rhs_src); |
| 14617 | } else { | 14619 | } else { |
| ... | @@ -14624,7 +14626,7 @@ fn analyzeArithmetic( | ... | @@ -14624,7 +14626,7 @@ fn analyzeArithmetic( |
| 14624 | } | 14626 | } |
| 14625 | const air_tag: Air.Inst.Tag = if (block.float_mode == .Optimized) .add_optimized else .add; | 14627 | const air_tag: Air.Inst.Tag = if (block.float_mode == .Optimized) .add_optimized else .add; |
| 14626 | if (maybe_lhs_val) |lhs_val| { | 14628 | if (maybe_lhs_val) |lhs_val| { |
| 14627 | if (lhs_val.isUndef()) { | 14629 | if (lhs_val.isUndef(mod)) { |
| 14628 | if (is_int) { | 14630 | if (is_int) { |
| 14629 | return sema.failWithUseOfUndef(block, lhs_src); | 14631 | return sema.failWithUseOfUndef(block, lhs_src); |
| 14630 | } else { | 14632 | } else { |
| ... | @@ -14653,13 +14655,13 @@ fn analyzeArithmetic( | ... | @@ -14653,13 +14655,13 @@ fn analyzeArithmetic( |
| 14653 | // If either of the operands are zero, the other operand is returned. | 14655 | // If either of the operands are zero, the other operand is returned. |
| 14654 | // If either of the operands are undefined, the result is undefined. | 14656 | // If either of the operands are undefined, the result is undefined. |
| 14655 | if (maybe_lhs_val) |lhs_val| { | 14657 | if (maybe_lhs_val) |lhs_val| { |
| 14656 | if (!lhs_val.isUndef() and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema))) { | 14658 | if (!lhs_val.isUndef(mod) and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema))) { |
| 14657 | return casted_rhs; | 14659 | return casted_rhs; |
| 14658 | } | 14660 | } |
| 14659 | } | 14661 | } |
| 14660 | const air_tag: Air.Inst.Tag = if (block.float_mode == .Optimized) .addwrap_optimized else .addwrap; | 14662 | const air_tag: Air.Inst.Tag = if (block.float_mode == .Optimized) .addwrap_optimized else .addwrap; |
| 14661 | if (maybe_rhs_val) |rhs_val| { | 14663 | if (maybe_rhs_val) |rhs_val| { |
| 14662 | if (rhs_val.isUndef()) { | 14664 | if (rhs_val.isUndef(mod)) { |
| 14663 | return sema.addConstUndef(resolved_type); | 14665 | return sema.addConstUndef(resolved_type); |
| 14664 | } | 14666 | } |
| 14665 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { | 14667 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| ... | @@ -14678,12 +14680,12 @@ fn analyzeArithmetic( | ... | @@ -14678,12 +14680,12 @@ fn analyzeArithmetic( |
| 14678 | // If either of the operands are zero, then the other operand is returned. | 14680 | // If either of the operands are zero, then the other operand is returned. |
| 14679 | // If either of the operands are undefined, the result is undefined. | 14681 | // If either of the operands are undefined, the result is undefined. |
| 14680 | if (maybe_lhs_val) |lhs_val| { | 14682 | if (maybe_lhs_val) |lhs_val| { |
| 14681 | if (!lhs_val.isUndef() and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema))) { | 14683 | if (!lhs_val.isUndef(mod) and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema))) { |
| 14682 | return casted_rhs; | 14684 | return casted_rhs; |
| 14683 | } | 14685 | } |
| 14684 | } | 14686 | } |
| 14685 | if (maybe_rhs_val) |rhs_val| { | 14687 | if (maybe_rhs_val) |rhs_val| { |
| 14686 | if (rhs_val.isUndef()) { | 14688 | if (rhs_val.isUndef(mod)) { |
| 14687 | return sema.addConstUndef(resolved_type); | 14689 | return sema.addConstUndef(resolved_type); |
| 14688 | } | 14690 | } |
| 14689 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { | 14691 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| ... | @@ -14708,7 +14710,7 @@ fn analyzeArithmetic( | ... | @@ -14708,7 +14710,7 @@ fn analyzeArithmetic( |
| 14708 | // overflow, causing illegal behavior. | 14710 | // overflow, causing illegal behavior. |
| 14709 | // For floats: either operand being undef makes the result undef. | 14711 | // For floats: either operand being undef makes the result undef. |
| 14710 | if (maybe_rhs_val) |rhs_val| { | 14712 | if (maybe_rhs_val) |rhs_val| { |
| 14711 | if (rhs_val.isUndef()) { | 14713 | if (rhs_val.isUndef(mod)) { |
| 14712 | if (is_int) { | 14714 | if (is_int) { |
| 14713 | return sema.failWithUseOfUndef(block, rhs_src); | 14715 | return sema.failWithUseOfUndef(block, rhs_src); |
| 14714 | } else { | 14716 | } else { |
| ... | @@ -14721,7 +14723,7 @@ fn analyzeArithmetic( | ... | @@ -14721,7 +14723,7 @@ fn analyzeArithmetic( |
| 14721 | } | 14723 | } |
| 14722 | const air_tag: Air.Inst.Tag = if (block.float_mode == .Optimized) .sub_optimized else .sub; | 14724 | const air_tag: Air.Inst.Tag = if (block.float_mode == .Optimized) .sub_optimized else .sub; |
| 14723 | if (maybe_lhs_val) |lhs_val| { | 14725 | if (maybe_lhs_val) |lhs_val| { |
| 14724 | if (lhs_val.isUndef()) { | 14726 | if (lhs_val.isUndef(mod)) { |
| 14725 | if (is_int) { | 14727 | if (is_int) { |
| 14726 | return sema.failWithUseOfUndef(block, lhs_src); | 14728 | return sema.failWithUseOfUndef(block, lhs_src); |
| 14727 | } else { | 14729 | } else { |
| ... | @@ -14750,7 +14752,7 @@ fn analyzeArithmetic( | ... | @@ -14750,7 +14752,7 @@ fn analyzeArithmetic( |
| 14750 | // If the RHS is zero, then the other operand is returned, even if it is undefined. | 14752 | // If the RHS is zero, then the other operand is returned, even if it is undefined. |
| 14751 | // If either of the operands are undefined, the result is undefined. | 14753 | // If either of the operands are undefined, the result is undefined. |
| 14752 | if (maybe_rhs_val) |rhs_val| { | 14754 | if (maybe_rhs_val) |rhs_val| { |
| 14753 | if (rhs_val.isUndef()) { | 14755 | if (rhs_val.isUndef(mod)) { |
| 14754 | return sema.addConstUndef(resolved_type); | 14756 | return sema.addConstUndef(resolved_type); |
| 14755 | } | 14757 | } |
| 14756 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { | 14758 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| ... | @@ -14759,7 +14761,7 @@ fn analyzeArithmetic( | ... | @@ -14759,7 +14761,7 @@ fn analyzeArithmetic( |
| 14759 | } | 14761 | } |
| 14760 | const air_tag: Air.Inst.Tag = if (block.float_mode == .Optimized) .subwrap_optimized else .subwrap; | 14762 | const air_tag: Air.Inst.Tag = if (block.float_mode == .Optimized) .subwrap_optimized else .subwrap; |
| 14761 | if (maybe_lhs_val) |lhs_val| { | 14763 | if (maybe_lhs_val) |lhs_val| { |
| 14762 | if (lhs_val.isUndef()) { | 14764 | if (lhs_val.isUndef(mod)) { |
| 14763 | return sema.addConstUndef(resolved_type); | 14765 | return sema.addConstUndef(resolved_type); |
| 14764 | } | 14766 | } |
| 14765 | if (maybe_rhs_val) |rhs_val| { | 14767 | if (maybe_rhs_val) |rhs_val| { |
| ... | @@ -14775,7 +14777,7 @@ fn analyzeArithmetic( | ... | @@ -14775,7 +14777,7 @@ fn analyzeArithmetic( |
| 14775 | // If the RHS is zero, result is LHS. | 14777 | // If the RHS is zero, result is LHS. |
| 14776 | // If either of the operands are undefined, result is undefined. | 14778 | // If either of the operands are undefined, result is undefined. |
| 14777 | if (maybe_rhs_val) |rhs_val| { | 14779 | if (maybe_rhs_val) |rhs_val| { |
| 14778 | if (rhs_val.isUndef()) { | 14780 | if (rhs_val.isUndef(mod)) { |
| 14779 | return sema.addConstUndef(resolved_type); | 14781 | return sema.addConstUndef(resolved_type); |
| 14780 | } | 14782 | } |
| 14781 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { | 14783 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| ... | @@ -14783,7 +14785,7 @@ fn analyzeArithmetic( | ... | @@ -14783,7 +14785,7 @@ fn analyzeArithmetic( |
| 14783 | } | 14785 | } |
| 14784 | } | 14786 | } |
| 14785 | if (maybe_lhs_val) |lhs_val| { | 14787 | if (maybe_lhs_val) |lhs_val| { |
| 14786 | if (lhs_val.isUndef()) { | 14788 | if (lhs_val.isUndef(mod)) { |
| 14787 | return sema.addConstUndef(resolved_type); | 14789 | return sema.addConstUndef(resolved_type); |
| 14788 | } | 14790 | } |
| 14789 | if (maybe_rhs_val) |rhs_val| { | 14791 | if (maybe_rhs_val) |rhs_val| { |
| ... | @@ -14814,7 +14816,7 @@ fn analyzeArithmetic( | ... | @@ -14814,7 +14816,7 @@ fn analyzeArithmetic( |
| 14814 | else => unreachable, | 14816 | else => unreachable, |
| 14815 | }; | 14817 | }; |
| 14816 | if (maybe_lhs_val) |lhs_val| { | 14818 | if (maybe_lhs_val) |lhs_val| { |
| 14817 | if (!lhs_val.isUndef()) { | 14819 | if (!lhs_val.isUndef(mod)) { |
| 14818 | if (lhs_val.isNan(mod)) { | 14820 | if (lhs_val.isNan(mod)) { |
| 14819 | return sema.addConstant(resolved_type, lhs_val); | 14821 | return sema.addConstant(resolved_type, lhs_val); |
| 14820 | } | 14822 | } |
| ... | @@ -14844,7 +14846,7 @@ fn analyzeArithmetic( | ... | @@ -14844,7 +14846,7 @@ fn analyzeArithmetic( |
| 14844 | } | 14846 | } |
| 14845 | const air_tag: Air.Inst.Tag = if (block.float_mode == .Optimized) .mul_optimized else .mul; | 14847 | const air_tag: Air.Inst.Tag = if (block.float_mode == .Optimized) .mul_optimized else .mul; |
| 14846 | if (maybe_rhs_val) |rhs_val| { | 14848 | if (maybe_rhs_val) |rhs_val| { |
| 14847 | if (rhs_val.isUndef()) { | 14849 | if (rhs_val.isUndef(mod)) { |
| 14848 | if (is_int) { | 14850 | if (is_int) { |
| 14849 | return sema.failWithUseOfUndef(block, rhs_src); | 14851 | return sema.failWithUseOfUndef(block, rhs_src); |
| 14850 | } else { | 14852 | } else { |
| ... | @@ -14874,7 +14876,7 @@ fn analyzeArithmetic( | ... | @@ -14874,7 +14876,7 @@ fn analyzeArithmetic( |
| 14874 | return casted_lhs; | 14876 | return casted_lhs; |
| 14875 | } | 14877 | } |
| 14876 | if (maybe_lhs_val) |lhs_val| { | 14878 | if (maybe_lhs_val) |lhs_val| { |
| 14877 | if (lhs_val.isUndef()) { | 14879 | if (lhs_val.isUndef(mod)) { |
| 14878 | if (is_int) { | 14880 | if (is_int) { |
| 14879 | return sema.failWithUseOfUndef(block, lhs_src); | 14881 | return sema.failWithUseOfUndef(block, lhs_src); |
| 14880 | } else { | 14882 | } else { |
| ... | @@ -14908,7 +14910,7 @@ fn analyzeArithmetic( | ... | @@ -14908,7 +14910,7 @@ fn analyzeArithmetic( |
| 14908 | else => unreachable, | 14910 | else => unreachable, |
| 14909 | }; | 14911 | }; |
| 14910 | if (maybe_lhs_val) |lhs_val| { | 14912 | if (maybe_lhs_val) |lhs_val| { |
| 14911 | if (!lhs_val.isUndef()) { | 14913 | if (!lhs_val.isUndef(mod)) { |
| 14912 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { | 14914 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 14913 | const zero_val = if (is_vector) b: { | 14915 | const zero_val = if (is_vector) b: { |
| 14914 | break :b try Value.Tag.repeated.create(sema.arena, scalar_zero); | 14916 | break :b try Value.Tag.repeated.create(sema.arena, scalar_zero); |
| ... | @@ -14922,7 +14924,7 @@ fn analyzeArithmetic( | ... | @@ -14922,7 +14924,7 @@ fn analyzeArithmetic( |
| 14922 | } | 14924 | } |
| 14923 | const air_tag: Air.Inst.Tag = if (block.float_mode == .Optimized) .mulwrap_optimized else .mulwrap; | 14925 | const air_tag: Air.Inst.Tag = if (block.float_mode == .Optimized) .mulwrap_optimized else .mulwrap; |
| 14924 | if (maybe_rhs_val) |rhs_val| { | 14926 | if (maybe_rhs_val) |rhs_val| { |
| 14925 | if (rhs_val.isUndef()) { | 14927 | if (rhs_val.isUndef(mod)) { |
| 14926 | return sema.addConstUndef(resolved_type); | 14928 | return sema.addConstUndef(resolved_type); |
| 14927 | } | 14929 | } |
| 14928 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { | 14930 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| ... | @@ -14935,7 +14937,7 @@ fn analyzeArithmetic( | ... | @@ -14935,7 +14937,7 @@ fn analyzeArithmetic( |
| 14935 | return casted_lhs; | 14937 | return casted_lhs; |
| 14936 | } | 14938 | } |
| 14937 | if (maybe_lhs_val) |lhs_val| { | 14939 | if (maybe_lhs_val) |lhs_val| { |
| 14938 | if (lhs_val.isUndef()) { | 14940 | if (lhs_val.isUndef(mod)) { |
| 14939 | return sema.addConstUndef(resolved_type); | 14941 | return sema.addConstUndef(resolved_type); |
| 14940 | } | 14942 | } |
| 14941 | return sema.addConstant( | 14943 | return sema.addConstant( |
| ... | @@ -14956,7 +14958,7 @@ fn analyzeArithmetic( | ... | @@ -14956,7 +14958,7 @@ fn analyzeArithmetic( |
| 14956 | else => unreachable, | 14958 | else => unreachable, |
| 14957 | }; | 14959 | }; |
| 14958 | if (maybe_lhs_val) |lhs_val| { | 14960 | if (maybe_lhs_val) |lhs_val| { |
| 14959 | if (!lhs_val.isUndef()) { | 14961 | if (!lhs_val.isUndef(mod)) { |
| 14960 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { | 14962 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 14961 | const zero_val = if (is_vector) b: { | 14963 | const zero_val = if (is_vector) b: { |
| 14962 | break :b try Value.Tag.repeated.create(sema.arena, scalar_zero); | 14964 | break :b try Value.Tag.repeated.create(sema.arena, scalar_zero); |
| ... | @@ -14969,7 +14971,7 @@ fn analyzeArithmetic( | ... | @@ -14969,7 +14971,7 @@ fn analyzeArithmetic( |
| 14969 | } | 14971 | } |
| 14970 | } | 14972 | } |
| 14971 | if (maybe_rhs_val) |rhs_val| { | 14973 | if (maybe_rhs_val) |rhs_val| { |
| 14972 | if (rhs_val.isUndef()) { | 14974 | if (rhs_val.isUndef(mod)) { |
| 14973 | return sema.addConstUndef(resolved_type); | 14975 | return sema.addConstUndef(resolved_type); |
| 14974 | } | 14976 | } |
| 14975 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { | 14977 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| ... | @@ -14982,7 +14984,7 @@ fn analyzeArithmetic( | ... | @@ -14982,7 +14984,7 @@ fn analyzeArithmetic( |
| 14982 | return casted_lhs; | 14984 | return casted_lhs; |
| 14983 | } | 14985 | } |
| 14984 | if (maybe_lhs_val) |lhs_val| { | 14986 | if (maybe_lhs_val) |lhs_val| { |
| 14985 | if (lhs_val.isUndef()) { | 14987 | if (lhs_val.isUndef(mod)) { |
| 14986 | return sema.addConstUndef(resolved_type); | 14988 | return sema.addConstUndef(resolved_type); |
| 14987 | } | 14989 | } |
| 14988 | | 14990 | |
| ... | @@ -15100,7 +15102,7 @@ fn analyzePtrArithmetic( | ... | @@ -15100,7 +15102,7 @@ fn analyzePtrArithmetic( |
| 15100 | const runtime_src = rs: { | 15102 | const runtime_src = rs: { |
| 15101 | if (opt_ptr_val) |ptr_val| { | 15103 | if (opt_ptr_val) |ptr_val| { |
| 15102 | if (opt_off_val) |offset_val| { | 15104 | if (opt_off_val) |offset_val| { |
| 15103 | if (ptr_val.isUndef()) return sema.addConstUndef(new_ptr_ty); | 15105 | if (ptr_val.isUndef(mod)) return sema.addConstUndef(new_ptr_ty); |
| 15104 | | 15106 | |
| 15105 | const offset_int = try sema.usizeCast(block, offset_src, offset_val.toUnsignedInt(mod)); | 15107 | const offset_int = try sema.usizeCast(block, offset_src, offset_val.toUnsignedInt(mod)); |
| 15106 | if (offset_int == 0) return ptr; | 15108 | if (offset_int == 0) return ptr; |
| ... | @@ -15363,7 +15365,7 @@ fn zirCmpEq( | ... | @@ -15363,7 +15365,7 @@ fn zirCmpEq( |
| 15363 | const runtime_src: LazySrcLoc = src: { | 15365 | const runtime_src: LazySrcLoc = src: { |
| 15364 | if (try sema.resolveMaybeUndefVal(lhs)) |lval| { | 15366 | if (try sema.resolveMaybeUndefVal(lhs)) |lval| { |
| 15365 | if (try sema.resolveMaybeUndefVal(rhs)) |rval| { | 15367 | if (try sema.resolveMaybeUndefVal(rhs)) |rval| { |
| 15366 | if (lval.isUndef() or rval.isUndef()) { | 15368 | if (lval.isUndef(mod) or rval.isUndef(mod)) { |
| 15367 | return sema.addConstUndef(Type.bool); | 15369 | return sema.addConstUndef(Type.bool); |
| 15368 | } | 15370 | } |
| 15369 | // TODO optimisation opportunity: evaluate if mem.eql is faster with the names, | 15371 | // TODO optimisation opportunity: evaluate if mem.eql is faster with the names, |
| ... | @@ -15425,7 +15427,7 @@ fn analyzeCmpUnionTag( | ... | @@ -15425,7 +15427,7 @@ fn analyzeCmpUnionTag( |
| 15425 | const coerced_union = try sema.coerce(block, union_tag_ty, un, un_src); | 15427 | const coerced_union = try sema.coerce(block, union_tag_ty, un, un_src); |
| 15426 | | 15428 | |
| 15427 | if (try sema.resolveMaybeUndefVal(coerced_tag)) |enum_val| { | 15429 | if (try sema.resolveMaybeUndefVal(coerced_tag)) |enum_val| { |
| 15428 | if (enum_val.isUndef()) return sema.addConstUndef(Type.bool); | 15430 | if (enum_val.isUndef(mod)) return sema.addConstUndef(Type.bool); |
| 15429 | const field_ty = union_ty.unionFieldType(enum_val, sema.mod); | 15431 | const field_ty = union_ty.unionFieldType(enum_val, sema.mod); |
| 15430 | if (field_ty.zigTypeTag(mod) == .NoReturn) { | 15432 | if (field_ty.zigTypeTag(mod) == .NoReturn) { |
| 15431 | return Air.Inst.Ref.bool_false; | 15433 | return Air.Inst.Ref.bool_false; |
| ... | @@ -15527,9 +15529,9 @@ fn cmpSelf( | ... | @@ -15527,9 +15529,9 @@ fn cmpSelf( |
| 15527 | const resolved_type = sema.typeOf(casted_lhs); | 15529 | const resolved_type = sema.typeOf(casted_lhs); |
| 15528 | const runtime_src: LazySrcLoc = src: { | 15530 | const runtime_src: LazySrcLoc = src: { |
| 15529 | if (try sema.resolveMaybeUndefVal(casted_lhs)) |lhs_val| { | 15531 | if (try sema.resolveMaybeUndefVal(casted_lhs)) |lhs_val| { |
| 15530 | if (lhs_val.isUndef()) return sema.addConstUndef(Type.bool); | 15532 | if (lhs_val.isUndef(mod)) return sema.addConstUndef(Type.bool); |
| 15531 | if (try sema.resolveMaybeUndefVal(casted_rhs)) |rhs_val| { | 15533 | if (try sema.resolveMaybeUndefVal(casted_rhs)) |rhs_val| { |
| 15532 | if (rhs_val.isUndef()) return sema.addConstUndef(Type.bool); | 15534 | if (rhs_val.isUndef(mod)) return sema.addConstUndef(Type.bool); |
| 15533 | | 15535 | |
| 15534 | if (resolved_type.zigTypeTag(mod) == .Vector) { | 15536 | if (resolved_type.zigTypeTag(mod) == .Vector) { |
| 15535 | const result_ty = try mod.vectorType(.{ | 15537 | const result_ty = try mod.vectorType(.{ |
| ... | @@ -15557,7 +15559,7 @@ fn cmpSelf( | ... | @@ -15557,7 +15559,7 @@ fn cmpSelf( |
| 15557 | // bool eq/neq more efficiently. | 15559 | // bool eq/neq more efficiently. |
| 15558 | if (resolved_type.zigTypeTag(mod) == .Bool) { | 15560 | if (resolved_type.zigTypeTag(mod) == .Bool) { |
| 15559 | if (try sema.resolveMaybeUndefVal(casted_rhs)) |rhs_val| { | 15561 | if (try sema.resolveMaybeUndefVal(casted_rhs)) |rhs_val| { |
| 15560 | if (rhs_val.isUndef()) return sema.addConstUndef(Type.bool); | 15562 | if (rhs_val.isUndef(mod)) return sema.addConstUndef(Type.bool); |
| 15561 | return sema.runtimeBoolCmp(block, src, op, casted_lhs, rhs_val.toBool(mod), lhs_src); | 15563 | return sema.runtimeBoolCmp(block, src, op, casted_lhs, rhs_val.toBool(mod), lhs_src); |
| 15562 | } | 15564 | } |
| 15563 | } | 15565 | } |
| ... | @@ -15892,68 +15894,69 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -15892,68 +15894,69 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15892 | const src = inst_data.src(); | 15894 | const src = inst_data.src(); |
| 15893 | const ty = try sema.resolveType(block, src, inst_data.operand); | 15895 | const ty = try sema.resolveType(block, src, inst_data.operand); |
| 15894 | const type_info_ty = try sema.getBuiltinType("Type"); | 15896 | const type_info_ty = try sema.getBuiltinType("Type"); |
| | 15897 | const type_info_tag_ty = type_info_ty.unionTagType(mod).?; |
| 15895 | | 15898 | |
| 15896 | switch (ty.zigTypeTag(mod)) { | 15899 | switch (ty.zigTypeTag(mod)) { |
| 15897 | .Type => return sema.addConstant( | 15900 | .Type => return sema.addConstant( |
| 15898 | type_info_ty, | 15901 | type_info_ty, |
| 15899 | try Value.Tag.@"union".create(sema.arena, .{ | 15902 | try Value.Tag.@"union".create(sema.arena, .{ |
| 15900 | .tag = try Value.Tag.enum_field_index.create(sema.arena, @enumToInt(std.builtin.TypeId.Type)), | 15903 | .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Type)), |
| 15901 | .val = Value.void, | 15904 | .val = Value.void, |
| 15902 | }), | 15905 | }), |
| 15903 | ), | 15906 | ), |
| 15904 | .Void => return sema.addConstant( | 15907 | .Void => return sema.addConstant( |
| 15905 | type_info_ty, | 15908 | type_info_ty, |
| 15906 | try Value.Tag.@"union".create(sema.arena, .{ | 15909 | try Value.Tag.@"union".create(sema.arena, .{ |
| 15907 | .tag = try Value.Tag.enum_field_index.create(sema.arena, @enumToInt(std.builtin.TypeId.Void)), | 15910 | .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Void)), |
| 15908 | .val = Value.void, | 15911 | .val = Value.void, |
| 15909 | }), | 15912 | }), |
| 15910 | ), | 15913 | ), |
| 15911 | .Bool => return sema.addConstant( | 15914 | .Bool => return sema.addConstant( |
| 15912 | type_info_ty, | 15915 | type_info_ty, |
| 15913 | try Value.Tag.@"union".create(sema.arena, .{ | 15916 | try Value.Tag.@"union".create(sema.arena, .{ |
| 15914 | .tag = try Value.Tag.enum_field_index.create(sema.arena, @enumToInt(std.builtin.TypeId.Bool)), | 15917 | .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Bool)), |
| 15915 | .val = Value.void, | 15918 | .val = Value.void, |
| 15916 | }), | 15919 | }), |
| 15917 | ), | 15920 | ), |
| 15918 | .NoReturn => return sema.addConstant( | 15921 | .NoReturn => return sema.addConstant( |
| 15919 | type_info_ty, | 15922 | type_info_ty, |
| 15920 | try Value.Tag.@"union".create(sema.arena, .{ | 15923 | try Value.Tag.@"union".create(sema.arena, .{ |
| 15921 | .tag = try Value.Tag.enum_field_index.create(sema.arena, @enumToInt(std.builtin.TypeId.NoReturn)), | 15924 | .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.NoReturn)), |
| 15922 | .val = Value.void, | 15925 | .val = Value.void, |
| 15923 | }), | 15926 | }), |
| 15924 | ), | 15927 | ), |
| 15925 | .ComptimeFloat => return sema.addConstant( | 15928 | .ComptimeFloat => return sema.addConstant( |
| 15926 | type_info_ty, | 15929 | type_info_ty, |
| 15927 | try Value.Tag.@"union".create(sema.arena, .{ | 15930 | try Value.Tag.@"union".create(sema.arena, .{ |
| 15928 | .tag = try Value.Tag.enum_field_index.create(sema.arena, @enumToInt(std.builtin.TypeId.ComptimeFloat)), | 15931 | .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.ComptimeFloat)), |
| 15929 | .val = Value.void, | 15932 | .val = Value.void, |
| 15930 | }), | 15933 | }), |
| 15931 | ), | 15934 | ), |
| 15932 | .ComptimeInt => return sema.addConstant( | 15935 | .ComptimeInt => return sema.addConstant( |
| 15933 | type_info_ty, | 15936 | type_info_ty, |
| 15934 | try Value.Tag.@"union".create(sema.arena, .{ | 15937 | try Value.Tag.@"union".create(sema.arena, .{ |
| 15935 | .tag = try Value.Tag.enum_field_index.create(sema.arena, @enumToInt(std.builtin.TypeId.ComptimeInt)), | 15938 | .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.ComptimeInt)), |
| 15936 | .val = Value.void, | 15939 | .val = Value.void, |
| 15937 | }), | 15940 | }), |
| 15938 | ), | 15941 | ), |
| 15939 | .Undefined => return sema.addConstant( | 15942 | .Undefined => return sema.addConstant( |
| 15940 | type_info_ty, | 15943 | type_info_ty, |
| 15941 | try Value.Tag.@"union".create(sema.arena, .{ | 15944 | try Value.Tag.@"union".create(sema.arena, .{ |
| 15942 | .tag = try Value.Tag.enum_field_index.create(sema.arena, @enumToInt(std.builtin.TypeId.Undefined)), | 15945 | .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Undefined)), |
| 15943 | .val = Value.void, | 15946 | .val = Value.void, |
| 15944 | }), | 15947 | }), |
| 15945 | ), | 15948 | ), |
| 15946 | .Null => return sema.addConstant( | 15949 | .Null => return sema.addConstant( |
| 15947 | type_info_ty, | 15950 | type_info_ty, |
| 15948 | try Value.Tag.@"union".create(sema.arena, .{ | 15951 | try Value.Tag.@"union".create(sema.arena, .{ |
| 15949 | .tag = try Value.Tag.enum_field_index.create(sema.arena, @enumToInt(std.builtin.TypeId.Null)), | 15952 | .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Null)), |
| 15950 | .val = Value.void, | 15953 | .val = Value.void, |
| 15951 | }), | 15954 | }), |
| 15952 | ), | 15955 | ), |
| 15953 | .EnumLiteral => return sema.addConstant( | 15956 | .EnumLiteral => return sema.addConstant( |
| 15954 | type_info_ty, | 15957 | type_info_ty, |
| 15955 | try Value.Tag.@"union".create(sema.arena, .{ | 15958 | try Value.Tag.@"union".create(sema.arena, .{ |
| 15956 | .tag = try Value.Tag.enum_field_index.create(sema.arena, @enumToInt(std.builtin.TypeId.EnumLiteral)), | 15959 | .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.EnumLiteral)), |
| 15957 | .val = Value.void, | 15960 | .val = Value.void, |
| 15958 | }), | 15961 | }), |
| 15959 | ), | 15962 | ), |
| ... | @@ -16040,10 +16043,12 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16040,10 +16043,12 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16040 | else | 16043 | else |
| 16041 | Value.null; | 16044 | Value.null; |
| 16042 | | 16045 | |
| | 16046 | const callconv_ty = try sema.getBuiltinType("CallingConvention"); |
| | 16047 | |
| 16043 | const field_values = try sema.arena.create([6]Value); | 16048 | const field_values = try sema.arena.create([6]Value); |
| 16044 | field_values.* = .{ | 16049 | field_values.* = .{ |
| 16045 | // calling_convention: CallingConvention, | 16050 | // calling_convention: CallingConvention, |
| 16046 | try Value.Tag.enum_field_index.create(sema.arena, @enumToInt(info.cc)), | 16051 | try mod.enumValueFieldIndex(callconv_ty, @enumToInt(info.cc)), |
| 16047 | // alignment: comptime_int, | 16052 | // alignment: comptime_int, |
| 16048 | try mod.intValue(Type.comptime_int, ty.abiAlignment(mod)), | 16053 | try mod.intValue(Type.comptime_int, ty.abiAlignment(mod)), |
| 16049 | // is_generic: bool, | 16054 | // is_generic: bool, |
| ... | @@ -16059,26 +16064,24 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16059,26 +16064,24 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16059 | return sema.addConstant( | 16064 | return sema.addConstant( |
| 16060 | type_info_ty, | 16065 | type_info_ty, |
| 16061 | try Value.Tag.@"union".create(sema.arena, .{ | 16066 | try Value.Tag.@"union".create(sema.arena, .{ |
| 16062 | .tag = try Value.Tag.enum_field_index.create(sema.arena, @enumToInt(std.builtin.TypeId.Fn)), | 16067 | .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Fn)), |
| 16063 | .val = try Value.Tag.aggregate.create(sema.arena, field_values), | 16068 | .val = try Value.Tag.aggregate.create(sema.arena, field_values), |
| 16064 | }), | 16069 | }), |
| 16065 | ); | 16070 | ); |
| 16066 | }, | 16071 | }, |
| 16067 | .Int => { | 16072 | .Int => { |
| | 16073 | const signedness_ty = try sema.getBuiltinType("Signedness"); |
| 16068 | const info = ty.intInfo(mod); | 16074 | const info = ty.intInfo(mod); |
| 16069 | const field_values = try sema.arena.alloc(Value, 2); | 16075 | const field_values = try sema.arena.alloc(Value, 2); |
| 16070 | // signedness: Signedness, | 16076 | // signedness: Signedness, |
| 16071 | field_values[0] = try Value.Tag.enum_field_index.create( | 16077 | field_values[0] = try mod.enumValueFieldIndex(signedness_ty, @enumToInt(info.signedness)); |
| 16072 | sema.arena, | | |
| 16073 | @enumToInt(info.signedness), | | |
| 16074 | ); | | |
| 16075 | // bits: u16, | 16078 | // bits: u16, |
| 16076 | field_values[1] = try mod.intValue(Type.u16, info.bits); | 16079 | field_values[1] = try mod.intValue(Type.u16, info.bits); |
| 16077 | | 16080 | |
| 16078 | return sema.addConstant( | 16081 | return sema.addConstant( |
| 16079 | type_info_ty, | 16082 | type_info_ty, |
| 16080 | try Value.Tag.@"union".create(sema.arena, .{ | 16083 | try Value.Tag.@"union".create(sema.arena, .{ |
| 16081 | .tag = try Value.Tag.enum_field_index.create(sema.arena, @enumToInt(std.builtin.TypeId.Int)), | 16084 | .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Int)), |
| 16082 | .val = try Value.Tag.aggregate.create(sema.arena, field_values), | 16085 | .val = try Value.Tag.aggregate.create(sema.arena, field_values), |
| 16083 | }), | 16086 | }), |
| 16084 | ); | 16087 | ); |
| ... | @@ -16091,7 +16094,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16091,7 +16094,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16091 | return sema.addConstant( | 16094 | return sema.addConstant( |
| 16092 | type_info_ty, | 16095 | type_info_ty, |
| 16093 | try Value.Tag.@"union".create(sema.arena, .{ | 16096 | try Value.Tag.@"union".create(sema.arena, .{ |
| 16094 | .tag = try Value.Tag.enum_field_index.create(sema.arena, @enumToInt(std.builtin.TypeId.Float)), | 16097 | .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Float)), |
| 16095 | .val = try Value.Tag.aggregate.create(sema.arena, field_values), | 16098 | .val = try Value.Tag.aggregate.create(sema.arena, field_values), |
| 16096 | }), | 16099 | }), |
| 16097 | ); | 16100 | ); |
| ... | @@ -16103,10 +16106,13 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16103,10 +16106,13 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16103 | else | 16106 | else |
| 16104 | try info.pointee_type.lazyAbiAlignment(mod, sema.arena); | 16107 | try info.pointee_type.lazyAbiAlignment(mod, sema.arena); |
| 16105 | | 16108 | |
| | 16109 | const addrspace_ty = try sema.getBuiltinType("AddressSpace"); |
| | 16110 | const ptr_size_ty = try sema.getBuiltinType("PtrSize"); |
| | 16111 | |
| 16106 | const field_values = try sema.arena.create([8]Value); | 16112 | const field_values = try sema.arena.create([8]Value); |
| 16107 | field_values.* = .{ | 16113 | field_values.* = .{ |
| 16108 | // size: Size, | 16114 | // size: Size, |
| 16109 | try Value.Tag.enum_field_index.create(sema.arena, @enumToInt(info.size)), | 16115 | try mod.enumValueFieldIndex(ptr_size_ty, @enumToInt(info.size)), |
| 16110 | // is_const: bool, | 16116 | // is_const: bool, |
| 16111 | Value.makeBool(!info.mutable), | 16117 | Value.makeBool(!info.mutable), |
| 16112 | // is_volatile: bool, | 16118 | // is_volatile: bool, |
| ... | @@ -16114,7 +16120,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16114,7 +16120,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16114 | // alignment: comptime_int, | 16120 | // alignment: comptime_int, |
| 16115 | alignment, | 16121 | alignment, |
| 16116 | // address_space: AddressSpace | 16122 | // address_space: AddressSpace |
| 16117 | try Value.Tag.enum_field_index.create(sema.arena, @enumToInt(info.@"addrspace")), | 16123 | try mod.enumValueFieldIndex(addrspace_ty, @enumToInt(info.@"addrspace")), |
| 16118 | // child: type, | 16124 | // child: type, |
| 16119 | try Value.Tag.ty.create(sema.arena, info.pointee_type), | 16125 | try Value.Tag.ty.create(sema.arena, info.pointee_type), |
| 16120 | // is_allowzero: bool, | 16126 | // is_allowzero: bool, |
| ... | @@ -16126,7 +16132,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16126,7 +16132,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16126 | return sema.addConstant( | 16132 | return sema.addConstant( |
| 16127 | type_info_ty, | 16133 | type_info_ty, |
| 16128 | try Value.Tag.@"union".create(sema.arena, .{ | 16134 | try Value.Tag.@"union".create(sema.arena, .{ |
| 16129 | .tag = try Value.Tag.enum_field_index.create(sema.arena, @enumToInt(std.builtin.TypeId.Pointer)), | 16135 | .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Pointer)), |
| 16130 | .val = try Value.Tag.aggregate.create(sema.arena, field_values), | 16136 | .val = try Value.Tag.aggregate.create(sema.arena, field_values), |
| 16131 | }), | 16137 | }), |
| 16132 | ); | 16138 | ); |
| ... | @@ -16144,7 +16150,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16144,7 +16150,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16144 | return sema.addConstant( | 16150 | return sema.addConstant( |
| 16145 | type_info_ty, | 16151 | type_info_ty, |
| 16146 | try Value.Tag.@"union".create(sema.arena, .{ | 16152 | try Value.Tag.@"union".create(sema.arena, .{ |
| 16147 | .tag = try Value.Tag.enum_field_index.create(sema.arena, @enumToInt(std.builtin.TypeId.Array)), | 16153 | .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Array)), |
| 16148 | .val = try Value.Tag.aggregate.create(sema.arena, field_values), | 16154 | .val = try Value.Tag.aggregate.create(sema.arena, field_values), |
| 16149 | }), | 16155 | }), |
| 16150 | ); | 16156 | ); |
| ... | @@ -16160,7 +16166,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16160,7 +16166,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16160 | return sema.addConstant( | 16166 | return sema.addConstant( |
| 16161 | type_info_ty, | 16167 | type_info_ty, |
| 16162 | try Value.Tag.@"union".create(sema.arena, .{ | 16168 | try Value.Tag.@"union".create(sema.arena, .{ |
| 16163 | .tag = try Value.Tag.enum_field_index.create(sema.arena, @enumToInt(std.builtin.TypeId.Vector)), | 16169 | .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Vector)), |
| 16164 | .val = try Value.Tag.aggregate.create(sema.arena, field_values), | 16170 | .val = try Value.Tag.aggregate.create(sema.arena, field_values), |
| 16165 | }), | 16171 | }), |
| 16166 | ); | 16172 | ); |
| ... | @@ -16173,7 +16179,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16173,7 +16179,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16173 | return sema.addConstant( | 16179 | return sema.addConstant( |
| 16174 | type_info_ty, | 16180 | type_info_ty, |
| 16175 | try Value.Tag.@"union".create(sema.arena, .{ | 16181 | try Value.Tag.@"union".create(sema.arena, .{ |
| 16176 | .tag = try Value.Tag.enum_field_index.create(sema.arena, @enumToInt(std.builtin.TypeId.Optional)), | 16182 | .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Optional)), |
| 16177 | .val = try Value.Tag.aggregate.create(sema.arena, field_values), | 16183 | .val = try Value.Tag.aggregate.create(sema.arena, field_values), |
| 16178 | }), | 16184 | }), |
| 16179 | ); | 16185 | ); |
| ... | @@ -16263,7 +16269,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16263,7 +16269,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16263 | return sema.addConstant( | 16269 | return sema.addConstant( |
| 16264 | type_info_ty, | 16270 | type_info_ty, |
| 16265 | try Value.Tag.@"union".create(sema.arena, .{ | 16271 | try Value.Tag.@"union".create(sema.arena, .{ |
| 16266 | .tag = try Value.Tag.enum_field_index.create(sema.arena, @enumToInt(std.builtin.TypeId.ErrorSet)), | 16272 | .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.ErrorSet)), |
| 16267 | .val = errors_val, | 16273 | .val = errors_val, |
| 16268 | }), | 16274 | }), |
| 16269 | ); | 16275 | ); |
| ... | @@ -16278,7 +16284,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16278,7 +16284,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16278 | return sema.addConstant( | 16284 | return sema.addConstant( |
| 16279 | type_info_ty, | 16285 | type_info_ty, |
| 16280 | try Value.Tag.@"union".create(sema.arena, .{ | 16286 | try Value.Tag.@"union".create(sema.arena, .{ |
| 16281 | .tag = try Value.Tag.enum_field_index.create(sema.arena, @enumToInt(std.builtin.TypeId.ErrorUnion)), | 16287 | .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.ErrorUnion)), |
| 16282 | .val = try Value.Tag.aggregate.create(sema.arena, field_values), | 16288 | .val = try Value.Tag.aggregate.create(sema.arena, field_values), |
| 16283 | }), | 16289 | }), |
| 16284 | ); | 16290 | ); |
| ... | @@ -16365,7 +16371,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16365,7 +16371,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16365 | return sema.addConstant( | 16371 | return sema.addConstant( |
| 16366 | type_info_ty, | 16372 | type_info_ty, |
| 16367 | try Value.Tag.@"union".create(sema.arena, .{ | 16373 | try Value.Tag.@"union".create(sema.arena, .{ |
| 16368 | .tag = try Value.Tag.enum_field_index.create(sema.arena, @enumToInt(std.builtin.TypeId.Enum)), | 16374 | .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Enum)), |
| 16369 | .val = try Value.Tag.aggregate.create(sema.arena, field_values), | 16375 | .val = try Value.Tag.aggregate.create(sema.arena, field_values), |
| 16370 | }), | 16376 | }), |
| 16371 | ); | 16377 | ); |
| ... | @@ -16454,13 +16460,12 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16454,13 +16460,12 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16454 | break :v try Value.Tag.opt_payload.create(sema.arena, ty_val); | 16460 | break :v try Value.Tag.opt_payload.create(sema.arena, ty_val); |
| 16455 | } else Value.null; | 16461 | } else Value.null; |
| 16456 | | 16462 | |
| | 16463 | const container_layout_ty = try sema.getBuiltinType("TmpContainerLayoutAlias"); |
| | 16464 | |
| 16457 | const field_values = try sema.arena.create([4]Value); | 16465 | const field_values = try sema.arena.create([4]Value); |
| 16458 | field_values.* = .{ | 16466 | field_values.* = .{ |
| 16459 | // layout: ContainerLayout, | 16467 | // layout: ContainerLayout, |
| 16460 | try Value.Tag.enum_field_index.create( | 16468 | try mod.enumValueFieldIndex(container_layout_ty, @enumToInt(layout)), |
| 16461 | sema.arena, | | |
| 16462 | @enumToInt(layout), | | |
| 16463 | ), | | |
| 16464 | | 16469 | |
| 16465 | // tag_type: ?type, | 16470 | // tag_type: ?type, |
| 16466 | enum_tag_ty_val, | 16471 | enum_tag_ty_val, |
| ... | @@ -16473,7 +16478,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16473,7 +16478,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16473 | return sema.addConstant( | 16478 | return sema.addConstant( |
| 16474 | type_info_ty, | 16479 | type_info_ty, |
| 16475 | try Value.Tag.@"union".create(sema.arena, .{ | 16480 | try Value.Tag.@"union".create(sema.arena, .{ |
| 16476 | .tag = try Value.Tag.enum_field_index.create(sema.arena, @enumToInt(std.builtin.TypeId.Union)), | 16481 | .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Union)), |
| 16477 | .val = try Value.Tag.aggregate.create(sema.arena, field_values), | 16482 | .val = try Value.Tag.aggregate.create(sema.arena, field_values), |
| 16478 | }), | 16483 | }), |
| 16479 | ); | 16484 | ); |
| ... | @@ -16625,13 +16630,12 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16625,13 +16630,12 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16625 | } | 16630 | } |
| 16626 | }; | 16631 | }; |
| 16627 | | 16632 | |
| | 16633 | const container_layout_ty = try sema.getBuiltinType("TmpContainerLayoutAlias"); |
| | 16634 | |
| 16628 | const field_values = try sema.arena.create([5]Value); | 16635 | const field_values = try sema.arena.create([5]Value); |
| 16629 | field_values.* = .{ | 16636 | field_values.* = .{ |
| 16630 | // layout: ContainerLayout, | 16637 | // layout: ContainerLayout, |
| 16631 | try Value.Tag.enum_field_index.create( | 16638 | try mod.enumValueFieldIndex(container_layout_ty, @enumToInt(layout)), |
| 16632 | sema.arena, | | |
| 16633 | @enumToInt(layout), | | |
| 16634 | ), | | |
| 16635 | // backing_integer: ?type, | 16639 | // backing_integer: ?type, |
| 16636 | backing_integer_val, | 16640 | backing_integer_val, |
| 16637 | // fields: []const StructField, | 16641 | // fields: []const StructField, |
| ... | @@ -16645,7 +16649,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16645,7 +16649,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16645 | return sema.addConstant( | 16649 | return sema.addConstant( |
| 16646 | type_info_ty, | 16650 | type_info_ty, |
| 16647 | try Value.Tag.@"union".create(sema.arena, .{ | 16651 | try Value.Tag.@"union".create(sema.arena, .{ |
| 16648 | .tag = try Value.Tag.enum_field_index.create(sema.arena, @enumToInt(std.builtin.TypeId.Struct)), | 16652 | .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Struct)), |
| 16649 | .val = try Value.Tag.aggregate.create(sema.arena, field_values), | 16653 | .val = try Value.Tag.aggregate.create(sema.arena, field_values), |
| 16650 | }), | 16654 | }), |
| 16651 | ); | 16655 | ); |
| ... | @@ -16665,7 +16669,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16665,7 +16669,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16665 | return sema.addConstant( | 16669 | return sema.addConstant( |
| 16666 | type_info_ty, | 16670 | type_info_ty, |
| 16667 | try Value.Tag.@"union".create(sema.arena, .{ | 16671 | try Value.Tag.@"union".create(sema.arena, .{ |
| 16668 | .tag = try Value.Tag.enum_field_index.create(sema.arena, @enumToInt(std.builtin.TypeId.Opaque)), | 16672 | .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Opaque)), |
| 16669 | .val = try Value.Tag.aggregate.create(sema.arena, field_values), | 16673 | .val = try Value.Tag.aggregate.create(sema.arena, field_values), |
| 16670 | }), | 16674 | }), |
| 16671 | ); | 16675 | ); |
| ... | @@ -16912,7 +16916,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -16912,7 +16916,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 16912 | | 16916 | |
| 16913 | const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src); | 16917 | const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src); |
| 16914 | if (try sema.resolveMaybeUndefVal(operand)) |val| { | 16918 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 16915 | return if (val.isUndef()) | 16919 | return if (val.isUndef(mod)) |
| 16916 | sema.addConstUndef(Type.bool) | 16920 | sema.addConstUndef(Type.bool) |
| 16917 | else if (val.toBool(mod)) | 16921 | else if (val.toBool(mod)) |
| 16918 | Air.Inst.Ref.bool_false | 16922 | Air.Inst.Ref.bool_false |
| ... | @@ -17879,7 +17883,7 @@ fn unionInit( | ... | @@ -17879,7 +17883,7 @@ fn unionInit( |
| 17879 | if (try sema.resolveMaybeUndefVal(init)) |init_val| { | 17883 | if (try sema.resolveMaybeUndefVal(init)) |init_val| { |
| 17880 | const tag_ty = union_ty.unionTagTypeHypothetical(mod); | 17884 | const tag_ty = union_ty.unionTagTypeHypothetical(mod); |
| 17881 | const enum_field_index = @intCast(u32, tag_ty.enumFieldIndex(field_name, mod).?); | 17885 | const enum_field_index = @intCast(u32, tag_ty.enumFieldIndex(field_name, mod).?); |
| 17882 | const tag_val = try Value.Tag.enum_field_index.create(sema.arena, enum_field_index); | 17886 | const tag_val = try mod.enumValueFieldIndex(tag_ty, enum_field_index); |
| 17883 | return sema.addConstant(union_ty, try Value.Tag.@"union".create(sema.arena, .{ | 17887 | return sema.addConstant(union_ty, try Value.Tag.@"union".create(sema.arena, .{ |
| 17884 | .tag = tag_val, | 17888 | .tag = tag_val, |
| 17885 | .val = init_val, | 17889 | .val = init_val, |
| ... | @@ -17980,7 +17984,7 @@ fn zirStructInit( | ... | @@ -17980,7 +17984,7 @@ fn zirStructInit( |
| 17980 | const field_index = try sema.unionFieldIndex(block, resolved_ty, field_name, field_src); | 17984 | const field_index = try sema.unionFieldIndex(block, resolved_ty, field_name, field_src); |
| 17981 | const tag_ty = resolved_ty.unionTagTypeHypothetical(mod); | 17985 | const tag_ty = resolved_ty.unionTagTypeHypothetical(mod); |
| 17982 | const enum_field_index = @intCast(u32, tag_ty.enumFieldIndex(field_name, mod).?); | 17986 | const enum_field_index = @intCast(u32, tag_ty.enumFieldIndex(field_name, mod).?); |
| 17983 | const tag_val = try Value.Tag.enum_field_index.create(sema.arena, enum_field_index); | 17987 | const tag_val = try mod.enumValueFieldIndex(tag_ty, enum_field_index); |
| 17984 | | 17988 | |
| 17985 | const init_inst = try sema.resolveInst(item.data.init); | 17989 | const init_inst = try sema.resolveInst(item.data.init); |
| 17986 | if (try sema.resolveMaybeUndefVal(init_inst)) |val| { | 17990 | if (try sema.resolveMaybeUndefVal(init_inst)) |val| { |
| ... | @@ -18614,7 +18618,7 @@ fn zirBoolToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -18614,7 +18618,7 @@ fn zirBoolToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 18614 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 18618 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 18615 | const operand = try sema.resolveInst(inst_data.operand); | 18619 | const operand = try sema.resolveInst(inst_data.operand); |
| 18616 | if (try sema.resolveMaybeUndefVal(operand)) |val| { | 18620 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 18617 | if (val.isUndef()) return sema.addConstUndef(Type.u1); | 18621 | if (val.isUndef(mod)) return sema.addConstUndef(Type.u1); |
| 18618 | if (val.toBool(mod)) return sema.addConstant(Type.u1, try mod.intValue(Type.u1, 1)); | 18622 | if (val.toBool(mod)) return sema.addConstant(Type.u1, try mod.intValue(Type.u1, 1)); |
| 18619 | return sema.addConstant(Type.u1, try mod.intValue(Type.u1, 0)); | 18623 | return sema.addConstant(Type.u1, try mod.intValue(Type.u1, 0)); |
| 18620 | } | 18624 | } |
| ... | @@ -18673,7 +18677,7 @@ fn zirUnaryMath( | ... | @@ -18673,7 +18677,7 @@ fn zirUnaryMath( |
| 18673 | .child = scalar_ty.ip_index, | 18677 | .child = scalar_ty.ip_index, |
| 18674 | }); | 18678 | }); |
| 18675 | if (try sema.resolveMaybeUndefVal(operand)) |val| { | 18679 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 18676 | if (val.isUndef()) | 18680 | if (val.isUndef(mod)) |
| 18677 | return sema.addConstUndef(result_ty); | 18681 | return sema.addConstUndef(result_ty); |
| 18678 | | 18682 | |
| 18679 | const elems = try sema.arena.alloc(Value, vec_len); | 18683 | const elems = try sema.arena.alloc(Value, vec_len); |
| ... | @@ -18692,7 +18696,7 @@ fn zirUnaryMath( | ... | @@ -18692,7 +18696,7 @@ fn zirUnaryMath( |
| 18692 | }, | 18696 | }, |
| 18693 | .ComptimeFloat, .Float => { | 18697 | .ComptimeFloat, .Float => { |
| 18694 | if (try sema.resolveMaybeUndefVal(operand)) |operand_val| { | 18698 | if (try sema.resolveMaybeUndefVal(operand)) |operand_val| { |
| 18695 | if (operand_val.isUndef()) | 18699 | if (operand_val.isUndef(mod)) |
| 18696 | return sema.addConstUndef(operand_ty); | 18700 | return sema.addConstUndef(operand_ty); |
| 18697 | const result_val = try eval(operand_val, operand_ty, sema.arena, sema.mod); | 18701 | const result_val = try eval(operand_val, operand_ty, sema.arena, sema.mod); |
| 18698 | return sema.addConstant(operand_ty, result_val); | 18702 | return sema.addConstant(operand_ty, result_val); |
| ... | @@ -18809,7 +18813,7 @@ fn zirReify( | ... | @@ -18809,7 +18813,7 @@ fn zirReify( |
| 18809 | const signedness_val = struct_val[0]; | 18813 | const signedness_val = struct_val[0]; |
| 18810 | const bits_val = struct_val[1]; | 18814 | const bits_val = struct_val[1]; |
| 18811 | | 18815 | |
| 18812 | const signedness = signedness_val.toEnum(std.builtin.Signedness); | 18816 | const signedness = mod.toEnum(std.builtin.Signedness, signedness_val); |
| 18813 | const bits = @intCast(u16, bits_val.toUnsignedInt(mod)); | 18817 | const bits = @intCast(u16, bits_val.toUnsignedInt(mod)); |
| 18814 | const ty = try mod.intType(signedness, bits); | 18818 | const ty = try mod.intType(signedness, bits); |
| 18815 | return sema.addType(ty); | 18819 | return sema.addType(ty); |
| ... | @@ -18874,7 +18878,7 @@ fn zirReify( | ... | @@ -18874,7 +18878,7 @@ fn zirReify( |
| 18874 | break :t elem_ty; | 18878 | break :t elem_ty; |
| 18875 | }; | 18879 | }; |
| 18876 | | 18880 | |
| 18877 | const ptr_size = size_val.toEnum(std.builtin.Type.Pointer.Size); | 18881 | const ptr_size = mod.toEnum(std.builtin.Type.Pointer.Size, size_val); |
| 18878 | | 18882 | |
| 18879 | var actual_sentinel: ?Value = null; | 18883 | var actual_sentinel: ?Value = null; |
| 18880 | if (!sentinel_val.isNull(mod)) { | 18884 | if (!sentinel_val.isNull(mod)) { |
| ... | @@ -18927,7 +18931,7 @@ fn zirReify( | ... | @@ -18927,7 +18931,7 @@ fn zirReify( |
| 18927 | .mutable = !is_const_val.toBool(mod), | 18931 | .mutable = !is_const_val.toBool(mod), |
| 18928 | .@"volatile" = is_volatile_val.toBool(mod), | 18932 | .@"volatile" = is_volatile_val.toBool(mod), |
| 18929 | .@"align" = abi_align, | 18933 | .@"align" = abi_align, |
| 18930 | .@"addrspace" = address_space_val.toEnum(std.builtin.AddressSpace), | 18934 | .@"addrspace" = mod.toEnum(std.builtin.AddressSpace, address_space_val), |
| 18931 | .pointee_type = try elem_ty.copy(sema.arena), | 18935 | .pointee_type = try elem_ty.copy(sema.arena), |
| 18932 | .@"allowzero" = is_allowzero_val.toBool(mod), | 18936 | .@"allowzero" = is_allowzero_val.toBool(mod), |
| 18933 | .sentinel = actual_sentinel, | 18937 | .sentinel = actual_sentinel, |
| ... | @@ -19033,7 +19037,7 @@ fn zirReify( | ... | @@ -19033,7 +19037,7 @@ fn zirReify( |
| 19033 | const is_tuple_val = struct_val[4]; | 19037 | const is_tuple_val = struct_val[4]; |
| 19034 | assert(struct_val.len == 5); | 19038 | assert(struct_val.len == 5); |
| 19035 | | 19039 | |
| 19036 | const layout = layout_val.toEnum(std.builtin.Type.ContainerLayout); | 19040 | const layout = mod.toEnum(std.builtin.Type.ContainerLayout, layout_val); |
| 19037 | | 19041 | |
| 19038 | // Decls | 19042 | // Decls |
| 19039 | if (decls_val.sliceLen(mod) > 0) { | 19043 | if (decls_val.sliceLen(mod) > 0) { |
| ... | @@ -19208,7 +19212,7 @@ fn zirReify( | ... | @@ -19208,7 +19212,7 @@ fn zirReify( |
| 19208 | if (decls_val.sliceLen(mod) > 0) { | 19212 | if (decls_val.sliceLen(mod) > 0) { |
| 19209 | return sema.fail(block, src, "reified unions must have no decls", .{}); | 19213 | return sema.fail(block, src, "reified unions must have no decls", .{}); |
| 19210 | } | 19214 | } |
| 19211 | const layout = layout_val.toEnum(std.builtin.Type.ContainerLayout); | 19215 | const layout = mod.toEnum(std.builtin.Type.ContainerLayout, layout_val); |
| 19212 | | 19216 | |
| 19213 | var new_decl_arena = std.heap.ArenaAllocator.init(gpa); | 19217 | var new_decl_arena = std.heap.ArenaAllocator.init(gpa); |
| 19214 | errdefer new_decl_arena.deinit(); | 19218 | errdefer new_decl_arena.deinit(); |
| ... | @@ -19309,7 +19313,7 @@ fn zirReify( | ... | @@ -19309,7 +19313,7 @@ fn zirReify( |
| 19309 | } | 19313 | } |
| 19310 | | 19314 | |
| 19311 | if (explicit_enum_info) |tag_info| { | 19315 | if (explicit_enum_info) |tag_info| { |
| 19312 | const enum_index = tag_info.nameIndex(mod.intern_pool, field_name_ip) orelse { | 19316 | const enum_index = tag_info.nameIndex(&mod.intern_pool, field_name_ip) orelse { |
| 19313 | const msg = msg: { | 19317 | const msg = msg: { |
| 19314 | const msg = try sema.errMsg(block, src, "no field named '{s}' in enum '{}'", .{ field_name, union_obj.tag_ty.fmt(mod) }); | 19318 | const msg = try sema.errMsg(block, src, "no field named '{s}' in enum '{}'", .{ field_name, union_obj.tag_ty.fmt(mod) }); |
| 19315 | errdefer msg.destroy(gpa); | 19319 | errdefer msg.destroy(gpa); |
| ... | @@ -19402,7 +19406,7 @@ fn zirReify( | ... | @@ -19402,7 +19406,7 @@ fn zirReify( |
| 19402 | const struct_val: []const Value = union_val.val.castTag(.aggregate).?.data; | 19406 | const struct_val: []const Value = union_val.val.castTag(.aggregate).?.data; |
| 19403 | // TODO use reflection instead of magic numbers here | 19407 | // TODO use reflection instead of magic numbers here |
| 19404 | // calling_convention: CallingConvention, | 19408 | // calling_convention: CallingConvention, |
| 19405 | const cc = struct_val[0].toEnum(std.builtin.CallingConvention); | 19409 | const cc = mod.toEnum(std.builtin.CallingConvention, struct_val[0]); |
| 19406 | // alignment: comptime_int, | 19410 | // alignment: comptime_int, |
| 19407 | const alignment_val = struct_val[1]; | 19411 | const alignment_val = struct_val[1]; |
| 19408 | // is_generic: bool, | 19412 | // is_generic: bool, |
| ... | @@ -20180,7 +20184,7 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -20180,7 +20184,7 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 20180 | } | 20184 | } |
| 20181 | | 20185 | |
| 20182 | if (try sema.resolveMaybeUndefVal(ptr)) |operand_val| { | 20186 | if (try sema.resolveMaybeUndefVal(ptr)) |operand_val| { |
| 20183 | if (!dest_ty.ptrAllowsZero(mod) and operand_val.isUndef()) { | 20187 | if (!dest_ty.ptrAllowsZero(mod) and operand_val.isUndef(mod)) { |
| 20184 | return sema.failWithUseOfUndef(block, operand_src); | 20188 | return sema.failWithUseOfUndef(block, operand_src); |
| 20185 | } | 20189 | } |
| 20186 | if (!dest_ty.ptrAllowsZero(mod) and operand_val.isNull(mod)) { | 20190 | if (!dest_ty.ptrAllowsZero(mod) and operand_val.isNull(mod)) { |
| ... | @@ -20315,7 +20319,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -20315,7 +20319,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 20315 | } | 20319 | } |
| 20316 | | 20320 | |
| 20317 | if (try sema.resolveMaybeUndefValIntable(operand)) |val| { | 20321 | if (try sema.resolveMaybeUndefValIntable(operand)) |val| { |
| 20318 | if (val.isUndef()) return sema.addConstUndef(dest_ty); | 20322 | if (val.isUndef(mod)) return sema.addConstUndef(dest_ty); |
| 20319 | if (!is_vector) { | 20323 | if (!is_vector) { |
| 20320 | return sema.addConstant( | 20324 | return sema.addConstant( |
| 20321 | dest_ty, | 20325 | dest_ty, |
| ... | @@ -20419,7 +20423,7 @@ fn zirBitCount( | ... | @@ -20419,7 +20423,7 @@ fn zirBitCount( |
| 20419 | .child = result_scalar_ty.ip_index, | 20423 | .child = result_scalar_ty.ip_index, |
| 20420 | }); | 20424 | }); |
| 20421 | if (try sema.resolveMaybeUndefVal(operand)) |val| { | 20425 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 20422 | if (val.isUndef()) return sema.addConstUndef(result_ty); | 20426 | if (val.isUndef(mod)) return sema.addConstUndef(result_ty); |
| 20423 | | 20427 | |
| 20424 | const elems = try sema.arena.alloc(Value, vec_len); | 20428 | const elems = try sema.arena.alloc(Value, vec_len); |
| 20425 | const scalar_ty = operand_ty.scalarType(mod); | 20429 | const scalar_ty = operand_ty.scalarType(mod); |
| ... | @@ -20439,7 +20443,7 @@ fn zirBitCount( | ... | @@ -20439,7 +20443,7 @@ fn zirBitCount( |
| 20439 | }, | 20443 | }, |
| 20440 | .Int => { | 20444 | .Int => { |
| 20441 | if (try sema.resolveMaybeUndefVal(operand)) |val| { | 20445 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 20442 | if (val.isUndef()) return sema.addConstUndef(result_scalar_ty); | 20446 | if (val.isUndef(mod)) return sema.addConstUndef(result_scalar_ty); |
| 20443 | try sema.resolveLazyValue(val); | 20447 | try sema.resolveLazyValue(val); |
| 20444 | return sema.addIntUnsigned(result_scalar_ty, comptimeOp(val, operand_ty, mod)); | 20448 | return sema.addIntUnsigned(result_scalar_ty, comptimeOp(val, operand_ty, mod)); |
| 20445 | } else { | 20449 | } else { |
| ... | @@ -20476,7 +20480,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -20476,7 +20480,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 20476 | switch (operand_ty.zigTypeTag(mod)) { | 20480 | switch (operand_ty.zigTypeTag(mod)) { |
| 20477 | .Int => { | 20481 | .Int => { |
| 20478 | const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| { | 20482 | const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 20479 | if (val.isUndef()) return sema.addConstUndef(operand_ty); | 20483 | if (val.isUndef(mod)) return sema.addConstUndef(operand_ty); |
| 20480 | const result_val = try val.byteSwap(operand_ty, mod, sema.arena); | 20484 | const result_val = try val.byteSwap(operand_ty, mod, sema.arena); |
| 20481 | return sema.addConstant(operand_ty, result_val); | 20485 | return sema.addConstant(operand_ty, result_val); |
| 20482 | } else operand_src; | 20486 | } else operand_src; |
| ... | @@ -20486,7 +20490,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -20486,7 +20490,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 20486 | }, | 20490 | }, |
| 20487 | .Vector => { | 20491 | .Vector => { |
| 20488 | const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| { | 20492 | const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 20489 | if (val.isUndef()) | 20493 | if (val.isUndef(mod)) |
| 20490 | return sema.addConstUndef(operand_ty); | 20494 | return sema.addConstUndef(operand_ty); |
| 20491 | | 20495 | |
| 20492 | const vec_len = operand_ty.vectorLen(mod); | 20496 | const vec_len = operand_ty.vectorLen(mod); |
| ... | @@ -20524,7 +20528,7 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -20524,7 +20528,7 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 20524 | switch (operand_ty.zigTypeTag(mod)) { | 20528 | switch (operand_ty.zigTypeTag(mod)) { |
| 20525 | .Int => { | 20529 | .Int => { |
| 20526 | const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| { | 20530 | const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 20527 | if (val.isUndef()) return sema.addConstUndef(operand_ty); | 20531 | if (val.isUndef(mod)) return sema.addConstUndef(operand_ty); |
| 20528 | const result_val = try val.bitReverse(operand_ty, mod, sema.arena); | 20532 | const result_val = try val.bitReverse(operand_ty, mod, sema.arena); |
| 20529 | return sema.addConstant(operand_ty, result_val); | 20533 | return sema.addConstant(operand_ty, result_val); |
| 20530 | } else operand_src; | 20534 | } else operand_src; |
| ... | @@ -20534,7 +20538,7 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -20534,7 +20538,7 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 20534 | }, | 20538 | }, |
| 20535 | .Vector => { | 20539 | .Vector => { |
| 20536 | const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| { | 20540 | const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 20537 | if (val.isUndef()) | 20541 | if (val.isUndef(mod)) |
| 20538 | return sema.addConstUndef(operand_ty); | 20542 | return sema.addConstUndef(operand_ty); |
| 20539 | | 20543 | |
| 20540 | const vec_len = operand_ty.vectorLen(mod); | 20544 | const vec_len = operand_ty.vectorLen(mod); |
| ... | @@ -21072,7 +21076,7 @@ fn resolveExportOptions( | ... | @@ -21072,7 +21076,7 @@ fn resolveExportOptions( |
| 21072 | | 21076 | |
| 21073 | const linkage_operand = try sema.fieldVal(block, src, options, "linkage", linkage_src); | 21077 | const linkage_operand = try sema.fieldVal(block, src, options, "linkage", linkage_src); |
| 21074 | const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_operand, "linkage of exported value must be comptime-known"); | 21078 | const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_operand, "linkage of exported value must be comptime-known"); |
| 21075 | const linkage = linkage_val.toEnum(std.builtin.GlobalLinkage); | 21079 | const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val); |
| 21076 | | 21080 | |
| 21077 | const section_operand = try sema.fieldVal(block, src, options, "section", section_src); | 21081 | const section_operand = try sema.fieldVal(block, src, options, "section", section_src); |
| 21078 | const section_opt_val = try sema.resolveConstValue(block, section_src, section_operand, "linksection of exported value must be comptime-known"); | 21082 | const section_opt_val = try sema.resolveConstValue(block, section_src, section_operand, "linksection of exported value must be comptime-known"); |
| ... | @@ -21084,7 +21088,7 @@ fn resolveExportOptions( | ... | @@ -21084,7 +21088,7 @@ fn resolveExportOptions( |
| 21084 | | 21088 | |
| 21085 | const visibility_operand = try sema.fieldVal(block, src, options, "visibility", visibility_src); | 21089 | const visibility_operand = try sema.fieldVal(block, src, options, "visibility", visibility_src); |
| 21086 | const visibility_val = try sema.resolveConstValue(block, visibility_src, visibility_operand, "visibility of exported value must be comptime-known"); | 21090 | const visibility_val = try sema.resolveConstValue(block, visibility_src, visibility_operand, "visibility of exported value must be comptime-known"); |
| 21087 | const visibility = visibility_val.toEnum(std.builtin.SymbolVisibility); | 21091 | const visibility = mod.toEnum(std.builtin.SymbolVisibility, visibility_val); |
| 21088 | | 21092 | |
| 21089 | if (name.len < 1) { | 21093 | if (name.len < 1) { |
| 21090 | return sema.fail(block, name_src, "exported symbol name cannot be empty", .{}); | 21094 | return sema.fail(block, name_src, "exported symbol name cannot be empty", .{}); |
| ... | @@ -21112,11 +21116,12 @@ fn resolveBuiltinEnum( | ... | @@ -21112,11 +21116,12 @@ fn resolveBuiltinEnum( |
| 21112 | comptime name: []const u8, | 21116 | comptime name: []const u8, |
| 21113 | reason: []const u8, | 21117 | reason: []const u8, |
| 21114 | ) CompileError!@field(std.builtin, name) { | 21118 | ) CompileError!@field(std.builtin, name) { |
| | 21119 | const mod = sema.mod; |
| 21115 | const ty = try sema.getBuiltinType(name); | 21120 | const ty = try sema.getBuiltinType(name); |
| 21116 | const air_ref = try sema.resolveInst(zir_ref); | 21121 | const air_ref = try sema.resolveInst(zir_ref); |
| 21117 | const coerced = try sema.coerce(block, ty, air_ref, src); | 21122 | const coerced = try sema.coerce(block, ty, air_ref, src); |
| 21118 | const val = try sema.resolveConstValue(block, src, coerced, reason); | 21123 | const val = try sema.resolveConstValue(block, src, coerced, reason); |
| 21119 | return val.toEnum(@field(std.builtin, name)); | 21124 | return mod.toEnum(@field(std.builtin, name), val); |
| 21120 | } | 21125 | } |
| 21121 | | 21126 | |
| 21122 | fn resolveAtomicOrder( | 21127 | fn resolveAtomicOrder( |
| ... | @@ -21198,7 +21203,7 @@ fn zirCmpxchg( | ... | @@ -21198,7 +21203,7 @@ fn zirCmpxchg( |
| 21198 | const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: { | 21203 | const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: { |
| 21199 | if (try sema.resolveMaybeUndefVal(expected_value)) |expected_val| { | 21204 | if (try sema.resolveMaybeUndefVal(expected_value)) |expected_val| { |
| 21200 | if (try sema.resolveMaybeUndefVal(new_value)) |new_val| { | 21205 | if (try sema.resolveMaybeUndefVal(new_value)) |new_val| { |
| 21201 | if (expected_val.isUndef() or new_val.isUndef()) { | 21206 | if (expected_val.isUndef(mod) or new_val.isUndef(mod)) { |
| 21202 | // TODO: this should probably cause the memory stored at the pointer | 21207 | // TODO: this should probably cause the memory stored at the pointer |
| 21203 | // to become undef as well | 21208 | // to become undef as well |
| 21204 | return sema.addConstUndef(result_ty); | 21209 | return sema.addConstUndef(result_ty); |
| ... | @@ -21248,7 +21253,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I | ... | @@ -21248,7 +21253,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 21248 | .child = scalar_ty.ip_index, | 21253 | .child = scalar_ty.ip_index, |
| 21249 | }); | 21254 | }); |
| 21250 | if (try sema.resolveMaybeUndefVal(scalar)) |scalar_val| { | 21255 | if (try sema.resolveMaybeUndefVal(scalar)) |scalar_val| { |
| 21251 | if (scalar_val.isUndef()) return sema.addConstUndef(vector_ty); | 21256 | if (scalar_val.isUndef(mod)) return sema.addConstUndef(vector_ty); |
| 21252 | | 21257 | |
| 21253 | return sema.addConstant( | 21258 | return sema.addConstant( |
| 21254 | vector_ty, | 21259 | vector_ty, |
| ... | @@ -21300,7 +21305,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -21300,7 +21305,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 21300 | } | 21305 | } |
| 21301 | | 21306 | |
| 21302 | if (try sema.resolveMaybeUndefVal(operand)) |operand_val| { | 21307 | if (try sema.resolveMaybeUndefVal(operand)) |operand_val| { |
| 21303 | if (operand_val.isUndef()) return sema.addConstUndef(scalar_ty); | 21308 | if (operand_val.isUndef(mod)) return sema.addConstUndef(scalar_ty); |
| 21304 | | 21309 | |
| 21305 | var accum: Value = try operand_val.elemValue(mod, 0); | 21310 | var accum: Value = try operand_val.elemValue(mod, 0); |
| 21306 | var i: u32 = 1; | 21311 | var i: u32 = 1; |
| ... | @@ -21420,7 +21425,7 @@ fn analyzeShuffle( | ... | @@ -21420,7 +21425,7 @@ fn analyzeShuffle( |
| 21420 | var i: usize = 0; | 21425 | var i: usize = 0; |
| 21421 | while (i < mask_len) : (i += 1) { | 21426 | while (i < mask_len) : (i += 1) { |
| 21422 | const elem = try mask.elemValue(sema.mod, i); | 21427 | const elem = try mask.elemValue(sema.mod, i); |
| 21423 | if (elem.isUndef()) continue; | 21428 | if (elem.isUndef(mod)) continue; |
| 21424 | const int = elem.toSignedInt(mod); | 21429 | const int = elem.toSignedInt(mod); |
| 21425 | var unsigned: u32 = undefined; | 21430 | var unsigned: u32 = undefined; |
| 21426 | var chosen: u32 = undefined; | 21431 | var chosen: u32 = undefined; |
| ... | @@ -21458,7 +21463,7 @@ fn analyzeShuffle( | ... | @@ -21458,7 +21463,7 @@ fn analyzeShuffle( |
| 21458 | i = 0; | 21463 | i = 0; |
| 21459 | while (i < mask_len) : (i += 1) { | 21464 | while (i < mask_len) : (i += 1) { |
| 21460 | const mask_elem_val = try mask.elemValue(sema.mod, i); | 21465 | const mask_elem_val = try mask.elemValue(sema.mod, i); |
| 21461 | if (mask_elem_val.isUndef()) { | 21466 | if (mask_elem_val.isUndef(mod)) { |
| 21462 | values[i] = Value.undef; | 21467 | values[i] = Value.undef; |
| 21463 | continue; | 21468 | continue; |
| 21464 | } | 21469 | } |
| ... | @@ -21559,13 +21564,13 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C | ... | @@ -21559,13 +21564,13 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C |
| 21559 | const maybe_b = try sema.resolveMaybeUndefVal(b); | 21564 | const maybe_b = try sema.resolveMaybeUndefVal(b); |
| 21560 | | 21565 | |
| 21561 | const runtime_src = if (maybe_pred) |pred_val| rs: { | 21566 | const runtime_src = if (maybe_pred) |pred_val| rs: { |
| 21562 | if (pred_val.isUndef()) return sema.addConstUndef(vec_ty); | 21567 | if (pred_val.isUndef(mod)) return sema.addConstUndef(vec_ty); |
| 21563 | | 21568 | |
| 21564 | if (maybe_a) |a_val| { | 21569 | if (maybe_a) |a_val| { |
| 21565 | if (a_val.isUndef()) return sema.addConstUndef(vec_ty); | 21570 | if (a_val.isUndef(mod)) return sema.addConstUndef(vec_ty); |
| 21566 | | 21571 | |
| 21567 | if (maybe_b) |b_val| { | 21572 | if (maybe_b) |b_val| { |
| 21568 | if (b_val.isUndef()) return sema.addConstUndef(vec_ty); | 21573 | if (b_val.isUndef(mod)) return sema.addConstUndef(vec_ty); |
| 21569 | | 21574 | |
| 21570 | const elems = try sema.gpa.alloc(Value, vec_len); | 21575 | const elems = try sema.gpa.alloc(Value, vec_len); |
| 21571 | for (elems, 0..) |*elem, i| { | 21576 | for (elems, 0..) |*elem, i| { |
| ... | @@ -21587,16 +21592,16 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C | ... | @@ -21587,16 +21592,16 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C |
| 21587 | } | 21592 | } |
| 21588 | } else { | 21593 | } else { |
| 21589 | if (maybe_b) |b_val| { | 21594 | if (maybe_b) |b_val| { |
| 21590 | if (b_val.isUndef()) return sema.addConstUndef(vec_ty); | 21595 | if (b_val.isUndef(mod)) return sema.addConstUndef(vec_ty); |
| 21591 | } | 21596 | } |
| 21592 | break :rs a_src; | 21597 | break :rs a_src; |
| 21593 | } | 21598 | } |
| 21594 | } else rs: { | 21599 | } else rs: { |
| 21595 | if (maybe_a) |a_val| { | 21600 | if (maybe_a) |a_val| { |
| 21596 | if (a_val.isUndef()) return sema.addConstUndef(vec_ty); | 21601 | if (a_val.isUndef(mod)) return sema.addConstUndef(vec_ty); |
| 21597 | } | 21602 | } |
| 21598 | if (maybe_b) |b_val| { | 21603 | if (maybe_b) |b_val| { |
| 21599 | if (b_val.isUndef()) return sema.addConstUndef(vec_ty); | 21604 | if (b_val.isUndef(mod)) return sema.addConstUndef(vec_ty); |
| 21600 | } | 21605 | } |
| 21601 | break :rs pred_src; | 21606 | break :rs pred_src; |
| 21602 | }; | 21607 | }; |
| ... | @@ -21803,10 +21808,10 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -21803,10 +21808,10 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 21803 | | 21808 | |
| 21804 | const runtime_src = if (maybe_mulend1) |mulend1_val| rs: { | 21809 | const runtime_src = if (maybe_mulend1) |mulend1_val| rs: { |
| 21805 | if (maybe_mulend2) |mulend2_val| { | 21810 | if (maybe_mulend2) |mulend2_val| { |
| 21806 | if (mulend2_val.isUndef()) return sema.addConstUndef(ty); | 21811 | if (mulend2_val.isUndef(mod)) return sema.addConstUndef(ty); |
| 21807 | | 21812 | |
| 21808 | if (maybe_addend) |addend_val| { | 21813 | if (maybe_addend) |addend_val| { |
| 21809 | if (addend_val.isUndef()) return sema.addConstUndef(ty); | 21814 | if (addend_val.isUndef(mod)) return sema.addConstUndef(ty); |
| 21810 | const result_val = try Value.mulAdd(ty, mulend1_val, mulend2_val, addend_val, sema.arena, sema.mod); | 21815 | const result_val = try Value.mulAdd(ty, mulend1_val, mulend2_val, addend_val, sema.arena, sema.mod); |
| 21811 | return sema.addConstant(ty, result_val); | 21816 | return sema.addConstant(ty, result_val); |
| 21812 | } else { | 21817 | } else { |
| ... | @@ -21814,16 +21819,16 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -21814,16 +21819,16 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 21814 | } | 21819 | } |
| 21815 | } else { | 21820 | } else { |
| 21816 | if (maybe_addend) |addend_val| { | 21821 | if (maybe_addend) |addend_val| { |
| 21817 | if (addend_val.isUndef()) return sema.addConstUndef(ty); | 21822 | if (addend_val.isUndef(mod)) return sema.addConstUndef(ty); |
| 21818 | } | 21823 | } |
| 21819 | break :rs mulend2_src; | 21824 | break :rs mulend2_src; |
| 21820 | } | 21825 | } |
| 21821 | } else rs: { | 21826 | } else rs: { |
| 21822 | if (maybe_mulend2) |mulend2_val| { | 21827 | if (maybe_mulend2) |mulend2_val| { |
| 21823 | if (mulend2_val.isUndef()) return sema.addConstUndef(ty); | 21828 | if (mulend2_val.isUndef(mod)) return sema.addConstUndef(ty); |
| 21824 | } | 21829 | } |
| 21825 | if (maybe_addend) |addend_val| { | 21830 | if (maybe_addend) |addend_val| { |
| 21826 | if (addend_val.isUndef()) return sema.addConstUndef(ty); | 21831 | if (addend_val.isUndef(mod)) return sema.addConstUndef(ty); |
| 21827 | } | 21832 | } |
| 21828 | break :rs mulend1_src; | 21833 | break :rs mulend1_src; |
| 21829 | }; | 21834 | }; |
| ... | @@ -21859,7 +21864,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -21859,7 +21864,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 21859 | const air_ref = try sema.resolveInst(extra.modifier); | 21864 | const air_ref = try sema.resolveInst(extra.modifier); |
| 21860 | const modifier_ref = try sema.coerce(block, modifier_ty, air_ref, modifier_src); | 21865 | const modifier_ref = try sema.coerce(block, modifier_ty, air_ref, modifier_src); |
| 21861 | const modifier_val = try sema.resolveConstValue(block, modifier_src, modifier_ref, "call modifier must be comptime-known"); | 21866 | const modifier_val = try sema.resolveConstValue(block, modifier_src, modifier_ref, "call modifier must be comptime-known"); |
| 21862 | var modifier = modifier_val.toEnum(std.builtin.CallModifier); | 21867 | var modifier = mod.toEnum(std.builtin.CallModifier, modifier_val); |
| 21863 | switch (modifier) { | 21868 | switch (modifier) { |
| 21864 | // These can be upgraded to comptime or nosuspend calls. | 21869 | // These can be upgraded to comptime or nosuspend calls. |
| 21865 | .auto, .never_tail, .no_async => { | 21870 | .auto, .never_tail, .no_async => { |
| ... | @@ -22111,8 +22116,8 @@ fn analyzeMinMax( | ... | @@ -22111,8 +22116,8 @@ fn analyzeMinMax( |
| 22111 | | 22116 | |
| 22112 | runtime_known.unset(operand_idx); | 22117 | runtime_known.unset(operand_idx); |
| 22113 | | 22118 | |
| 22114 | if (cur_val.isUndef()) continue; // result is also undef | 22119 | if (cur_val.isUndef(mod)) continue; // result is also undef |
| 22115 | if (operand_val.isUndef()) { | 22120 | if (operand_val.isUndef(mod)) { |
| 22116 | cur_minmax = try sema.addConstUndef(simd_op.result_ty); | 22121 | cur_minmax = try sema.addConstUndef(simd_op.result_ty); |
| 22117 | continue; | 22122 | continue; |
| 22118 | } | 22123 | } |
| ... | @@ -22165,7 +22170,7 @@ fn analyzeMinMax( | ... | @@ -22165,7 +22170,7 @@ fn analyzeMinMax( |
| 22165 | var cur_max: Value = cur_min; | 22170 | var cur_max: Value = cur_min; |
| 22166 | for (1..len) |idx| { | 22171 | for (1..len) |idx| { |
| 22167 | const elem_val = try val.elemValue(mod, idx); | 22172 | const elem_val = try val.elemValue(mod, idx); |
| 22168 | if (elem_val.isUndef()) break :blk orig_ty; // can't refine undef | 22173 | if (elem_val.isUndef(mod)) break :blk orig_ty; // can't refine undef |
| 22169 | if (Value.order(elem_val, cur_min, mod).compare(.lt)) cur_min = elem_val; | 22174 | if (Value.order(elem_val, cur_min, mod).compare(.lt)) cur_min = elem_val; |
| 22170 | if (Value.order(elem_val, cur_max, mod).compare(.gt)) cur_max = elem_val; | 22175 | if (Value.order(elem_val, cur_max, mod).compare(.gt)) cur_max = elem_val; |
| 22171 | } | 22176 | } |
| ... | @@ -22177,7 +22182,7 @@ fn analyzeMinMax( | ... | @@ -22177,7 +22182,7 @@ fn analyzeMinMax( |
| 22177 | }); | 22182 | }); |
| 22178 | } else blk: { | 22183 | } else blk: { |
| 22179 | if (orig_ty.isAnyFloat()) break :blk orig_ty; // can't refine floats | 22184 | if (orig_ty.isAnyFloat()) break :blk orig_ty; // can't refine floats |
| 22180 | if (val.isUndef()) break :blk orig_ty; // can't refine undef | 22185 | if (val.isUndef(mod)) break :blk orig_ty; // can't refine undef |
| 22181 | break :blk try mod.intFittingRange(val, val); | 22186 | break :blk try mod.intFittingRange(val, val); |
| 22182 | }; | 22187 | }; |
| 22183 | | 22188 | |
| ... | @@ -22205,7 +22210,7 @@ fn analyzeMinMax( | ... | @@ -22205,7 +22210,7 @@ fn analyzeMinMax( |
| 22205 | // If the comptime-known part is undef we can avoid emitting actual instructions later | 22210 | // If the comptime-known part is undef we can avoid emitting actual instructions later |
| 22206 | const known_undef = if (cur_minmax) |operand| blk: { | 22211 | const known_undef = if (cur_minmax) |operand| blk: { |
| 22207 | const val = (try sema.resolveMaybeUndefVal(operand)).?; | 22212 | const val = (try sema.resolveMaybeUndefVal(operand)).?; |
| 22208 | break :blk val.isUndef(); | 22213 | break :blk val.isUndef(mod); |
| 22209 | } else false; | 22214 | } else false; |
| 22210 | | 22215 | |
| 22211 | if (cur_minmax == null) { | 22216 | if (cur_minmax == null) { |
| ... | @@ -22749,7 +22754,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -22749,7 +22754,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 22749 | if (val.isGenericPoison()) { | 22754 | if (val.isGenericPoison()) { |
| 22750 | break :blk null; | 22755 | break :blk null; |
| 22751 | } | 22756 | } |
| 22752 | break :blk val.toEnum(std.builtin.AddressSpace); | 22757 | break :blk mod.toEnum(std.builtin.AddressSpace, val); |
| 22753 | } else if (extra.data.bits.has_addrspace_ref) blk: { | 22758 | } else if (extra.data.bits.has_addrspace_ref) blk: { |
| 22754 | const addrspace_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]); | 22759 | const addrspace_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]); |
| 22755 | extra_index += 1; | 22760 | extra_index += 1; |
| ... | @@ -22759,7 +22764,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -22759,7 +22764,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 22759 | }, | 22764 | }, |
| 22760 | else => |e| return e, | 22765 | else => |e| return e, |
| 22761 | }; | 22766 | }; |
| 22762 | break :blk addrspace_tv.val.toEnum(std.builtin.AddressSpace); | 22767 | break :blk mod.toEnum(std.builtin.AddressSpace, addrspace_tv.val); |
| 22763 | } else target_util.defaultAddressSpace(target, .function); | 22768 | } else target_util.defaultAddressSpace(target, .function); |
| 22764 | | 22769 | |
| 22765 | const @"linksection": FuncLinkSection = if (extra.data.bits.has_section_body) blk: { | 22770 | const @"linksection": FuncLinkSection = if (extra.data.bits.has_section_body) blk: { |
| ... | @@ -22797,7 +22802,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -22797,7 +22802,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 22797 | if (val.isGenericPoison()) { | 22802 | if (val.isGenericPoison()) { |
| 22798 | break :blk null; | 22803 | break :blk null; |
| 22799 | } | 22804 | } |
| 22800 | break :blk val.toEnum(std.builtin.CallingConvention); | 22805 | break :blk mod.toEnum(std.builtin.CallingConvention, val); |
| 22801 | } else if (extra.data.bits.has_cc_ref) blk: { | 22806 | } else if (extra.data.bits.has_cc_ref) blk: { |
| 22802 | const cc_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]); | 22807 | const cc_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]); |
| 22803 | extra_index += 1; | 22808 | extra_index += 1; |
| ... | @@ -22807,7 +22812,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -22807,7 +22812,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 22807 | }, | 22812 | }, |
| 22808 | else => |e| return e, | 22813 | else => |e| return e, |
| 22809 | }; | 22814 | }; |
| 22810 | break :blk cc_tv.val.toEnum(std.builtin.CallingConvention); | 22815 | break :blk mod.toEnum(std.builtin.CallingConvention, cc_tv.val); |
| 22811 | } else if (sema.owner_decl.is_exported and has_body) | 22816 | } else if (sema.owner_decl.is_exported and has_body) |
| 22812 | .C | 22817 | .C |
| 22813 | else | 22818 | else |
| ... | @@ -22994,9 +22999,9 @@ fn resolvePrefetchOptions( | ... | @@ -22994,9 +22999,9 @@ fn resolvePrefetchOptions( |
| 22994 | const cache_val = try sema.resolveConstValue(block, cache_src, cache, "prefetch cache must be comptime-known"); | 22999 | const cache_val = try sema.resolveConstValue(block, cache_src, cache, "prefetch cache must be comptime-known"); |
| 22995 | | 23000 | |
| 22996 | return std.builtin.PrefetchOptions{ | 23001 | return std.builtin.PrefetchOptions{ |
| 22997 | .rw = rw_val.toEnum(std.builtin.PrefetchOptions.Rw), | 23002 | .rw = mod.toEnum(std.builtin.PrefetchOptions.Rw, rw_val), |
| 22998 | .locality = @intCast(u2, locality_val.toUnsignedInt(mod)), | 23003 | .locality = @intCast(u2, locality_val.toUnsignedInt(mod)), |
| 22999 | .cache = cache_val.toEnum(std.builtin.PrefetchOptions.Cache), | 23004 | .cache = mod.toEnum(std.builtin.PrefetchOptions.Cache, cache_val), |
| 23000 | }; | 23005 | }; |
| 23001 | } | 23006 | } |
| 23002 | | 23007 | |
| ... | @@ -23059,7 +23064,7 @@ fn resolveExternOptions( | ... | @@ -23059,7 +23064,7 @@ fn resolveExternOptions( |
| 23059 | | 23064 | |
| 23060 | const linkage_ref = try sema.fieldVal(block, src, options, "linkage", linkage_src); | 23065 | const linkage_ref = try sema.fieldVal(block, src, options, "linkage", linkage_src); |
| 23061 | const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_ref, "linkage of the extern symbol must be comptime-known"); | 23066 | const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_ref, "linkage of the extern symbol must be comptime-known"); |
| 23062 | const linkage = linkage_val.toEnum(std.builtin.GlobalLinkage); | 23067 | const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val); |
| 23063 | | 23068 | |
| 23064 | const is_thread_local = try sema.fieldVal(block, src, options, "is_thread_local", thread_local_src); | 23069 | const is_thread_local = try sema.fieldVal(block, src, options, "is_thread_local", thread_local_src); |
| 23065 | const is_thread_local_val = try sema.resolveConstValue(block, thread_local_src, is_thread_local, "threadlocality of the extern symbol must be comptime-known"); | 23070 | const is_thread_local_val = try sema.resolveConstValue(block, thread_local_src, is_thread_local, "threadlocality of the extern symbol must be comptime-known"); |
| ... | @@ -24140,7 +24145,7 @@ fn fieldVal( | ... | @@ -24140,7 +24145,7 @@ fn fieldVal( |
| 24140 | const field_index = @intCast(u32, field_index_usize); | 24145 | const field_index = @intCast(u32, field_index_usize); |
| 24141 | return sema.addConstant( | 24146 | return sema.addConstant( |
| 24142 | enum_ty, | 24147 | enum_ty, |
| 24143 | try Value.Tag.enum_field_index.create(sema.arena, field_index), | 24148 | try mod.enumValueFieldIndex(enum_ty, field_index), |
| 24144 | ); | 24149 | ); |
| 24145 | } | 24150 | } |
| 24146 | } | 24151 | } |
| ... | @@ -24155,8 +24160,8 @@ fn fieldVal( | ... | @@ -24155,8 +24160,8 @@ fn fieldVal( |
| 24155 | const field_index_usize = child_type.enumFieldIndex(field_name, mod) orelse | 24160 | const field_index_usize = child_type.enumFieldIndex(field_name, mod) orelse |
| 24156 | return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name); | 24161 | return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name); |
| 24157 | const field_index = @intCast(u32, field_index_usize); | 24162 | const field_index = @intCast(u32, field_index_usize); |
| 24158 | const enum_val = try Value.Tag.enum_field_index.create(arena, field_index); | 24163 | const enum_val = try mod.enumValueFieldIndex(child_type, field_index); |
| 24159 | return sema.addConstant(try child_type.copy(arena), enum_val); | 24164 | return sema.addConstant(child_type, enum_val); |
| 24160 | }, | 24165 | }, |
| 24161 | .Struct, .Opaque => { | 24166 | .Struct, .Opaque => { |
| 24162 | if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| { | 24167 | if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| { |
| ... | @@ -24355,8 +24360,8 @@ fn fieldPtr( | ... | @@ -24355,8 +24360,8 @@ fn fieldPtr( |
| 24355 | var anon_decl = try block.startAnonDecl(); | 24360 | var anon_decl = try block.startAnonDecl(); |
| 24356 | defer anon_decl.deinit(); | 24361 | defer anon_decl.deinit(); |
| 24357 | return sema.analyzeDeclRef(try anon_decl.finish( | 24362 | return sema.analyzeDeclRef(try anon_decl.finish( |
| 24358 | try enum_ty.copy(anon_decl.arena()), | 24363 | enum_ty, |
| 24359 | try Value.Tag.enum_field_index.create(anon_decl.arena(), field_index_u32), | 24364 | try mod.enumValueFieldIndex(enum_ty, field_index_u32), |
| 24360 | 0, // default alignment | 24365 | 0, // default alignment |
| 24361 | )); | 24366 | )); |
| 24362 | } | 24367 | } |
| ... | @@ -24376,8 +24381,8 @@ fn fieldPtr( | ... | @@ -24376,8 +24381,8 @@ fn fieldPtr( |
| 24376 | var anon_decl = try block.startAnonDecl(); | 24381 | var anon_decl = try block.startAnonDecl(); |
| 24377 | defer anon_decl.deinit(); | 24382 | defer anon_decl.deinit(); |
| 24378 | return sema.analyzeDeclRef(try anon_decl.finish( | 24383 | return sema.analyzeDeclRef(try anon_decl.finish( |
| 24379 | try child_type.copy(anon_decl.arena()), | 24384 | child_type, |
| 24380 | try Value.Tag.enum_field_index.create(anon_decl.arena(), field_index_u32), | 24385 | try mod.enumValueFieldIndex(child_type, field_index_u32), |
| 24381 | 0, // default alignment | 24386 | 0, // default alignment |
| 24382 | )); | 24387 | )); |
| 24383 | }, | 24388 | }, |
| ... | @@ -24850,7 +24855,7 @@ fn structFieldVal( | ... | @@ -24850,7 +24855,7 @@ fn structFieldVal( |
| 24850 | } | 24855 | } |
| 24851 | | 24856 | |
| 24852 | if (try sema.resolveMaybeUndefVal(struct_byval)) |struct_val| { | 24857 | if (try sema.resolveMaybeUndefVal(struct_byval)) |struct_val| { |
| 24853 | if (struct_val.isUndef()) return sema.addConstUndef(field.ty); | 24858 | if (struct_val.isUndef(mod)) return sema.addConstUndef(field.ty); |
| 24854 | if ((try sema.typeHasOnePossibleValue(field.ty))) |opv| { | 24859 | if ((try sema.typeHasOnePossibleValue(field.ty))) |opv| { |
| 24855 | return sema.addConstant(field.ty, opv); | 24860 | return sema.addConstant(field.ty, opv); |
| 24856 | } | 24861 | } |
| ... | @@ -24922,7 +24927,7 @@ fn tupleFieldValByIndex( | ... | @@ -24922,7 +24927,7 @@ fn tupleFieldValByIndex( |
| 24922 | } | 24927 | } |
| 24923 | | 24928 | |
| 24924 | if (try sema.resolveMaybeUndefVal(tuple_byval)) |tuple_val| { | 24929 | if (try sema.resolveMaybeUndefVal(tuple_byval)) |tuple_val| { |
| 24925 | if (tuple_val.isUndef()) return sema.addConstUndef(field_ty); | 24930 | if (tuple_val.isUndef(mod)) return sema.addConstUndef(field_ty); |
| 24926 | if ((try sema.typeHasOnePossibleValue(field_ty))) |opv| { | 24931 | if ((try sema.typeHasOnePossibleValue(field_ty))) |opv| { |
| 24927 | return sema.addConstant(field_ty, opv); | 24932 | return sema.addConstant(field_ty, opv); |
| 24928 | } | 24933 | } |
| ... | @@ -24983,19 +24988,15 @@ fn unionFieldPtr( | ... | @@ -24983,19 +24988,15 @@ fn unionFieldPtr( |
| 24983 | .Auto => if (!initializing) { | 24988 | .Auto => if (!initializing) { |
| 24984 | const union_val = (try sema.pointerDeref(block, src, union_ptr_val, union_ptr_ty)) orelse | 24989 | const union_val = (try sema.pointerDeref(block, src, union_ptr_val, union_ptr_ty)) orelse |
| 24985 | break :ct; | 24990 | break :ct; |
| 24986 | if (union_val.isUndef()) { | 24991 | if (union_val.isUndef(mod)) { |
| 24987 | return sema.failWithUseOfUndef(block, src); | 24992 | return sema.failWithUseOfUndef(block, src); |
| 24988 | } | 24993 | } |
| 24989 | const tag_and_val = union_val.castTag(.@"union").?.data; | 24994 | const tag_and_val = union_val.castTag(.@"union").?.data; |
| 24990 | var field_tag_buf: Value.Payload.U32 = .{ | 24995 | const field_tag = try mod.enumValueFieldIndex(union_obj.tag_ty, enum_field_index); |
| 24991 | .base = .{ .tag = .enum_field_index }, | | |
| 24992 | .data = enum_field_index, | | |
| 24993 | }; | | |
| 24994 | const field_tag = Value.initPayload(&field_tag_buf.base); | | |
| 24995 | const tag_matches = tag_and_val.tag.eql(field_tag, union_obj.tag_ty, mod); | 24996 | const tag_matches = tag_and_val.tag.eql(field_tag, union_obj.tag_ty, mod); |
| 24996 | if (!tag_matches) { | 24997 | if (!tag_matches) { |
| 24997 | const msg = msg: { | 24998 | const msg = msg: { |
| 24998 | const active_index = tag_and_val.tag.castTag(.enum_field_index).?.data; | 24999 | const active_index = union_obj.tag_ty.enumTagFieldIndex(tag_and_val.tag, mod).?; |
| 24999 | const active_field_name = union_obj.tag_ty.enumFieldName(active_index, mod); | 25000 | const active_field_name = union_obj.tag_ty.enumFieldName(active_index, mod); |
| 25000 | const msg = try sema.errMsg(block, src, "access of union field '{s}' while field '{s}' is active", .{ field_name, active_field_name }); | 25001 | const msg = try sema.errMsg(block, src, "access of union field '{s}' while field '{s}' is active", .{ field_name, active_field_name }); |
| 25001 | errdefer msg.destroy(sema.gpa); | 25002 | errdefer msg.destroy(sema.gpa); |
| ... | @@ -25021,7 +25022,7 @@ fn unionFieldPtr( | ... | @@ -25021,7 +25022,7 @@ fn unionFieldPtr( |
| 25021 | if (!initializing and union_obj.layout == .Auto and block.wantSafety() and | 25022 | if (!initializing and union_obj.layout == .Auto and block.wantSafety() and |
| 25022 | union_ty.unionTagTypeSafety(mod) != null and union_obj.fields.count() > 1) | 25023 | union_ty.unionTagTypeSafety(mod) != null and union_obj.fields.count() > 1) |
| 25023 | { | 25024 | { |
| 25024 | const wanted_tag_val = try Value.Tag.enum_field_index.create(sema.arena, enum_field_index); | 25025 | const wanted_tag_val = try mod.enumValueFieldIndex(union_obj.tag_ty, enum_field_index); |
| 25025 | const wanted_tag = try sema.addConstant(union_obj.tag_ty, wanted_tag_val); | 25026 | const wanted_tag = try sema.addConstant(union_obj.tag_ty, wanted_tag_val); |
| 25026 | // TODO would it be better if get_union_tag supported pointers to unions? | 25027 | // TODO would it be better if get_union_tag supported pointers to unions? |
| 25027 | const union_val = try block.addTyOp(.load, union_ty, union_ptr); | 25028 | const union_val = try block.addTyOp(.load, union_ty, union_ptr); |
| ... | @@ -25054,14 +25055,10 @@ fn unionFieldVal( | ... | @@ -25054,14 +25055,10 @@ fn unionFieldVal( |
| 25054 | const enum_field_index = @intCast(u32, union_obj.tag_ty.enumFieldIndex(field_name, mod).?); | 25055 | const enum_field_index = @intCast(u32, union_obj.tag_ty.enumFieldIndex(field_name, mod).?); |
| 25055 | | 25056 | |
| 25056 | if (try sema.resolveMaybeUndefVal(union_byval)) |union_val| { | 25057 | if (try sema.resolveMaybeUndefVal(union_byval)) |union_val| { |
| 25057 | if (union_val.isUndef()) return sema.addConstUndef(field.ty); | 25058 | if (union_val.isUndef(mod)) return sema.addConstUndef(field.ty); |
| 25058 | | 25059 | |
| 25059 | const tag_and_val = union_val.castTag(.@"union").?.data; | 25060 | const tag_and_val = union_val.castTag(.@"union").?.data; |
| 25060 | var field_tag_buf: Value.Payload.U32 = .{ | 25061 | const field_tag = try mod.enumValueFieldIndex(union_obj.tag_ty, enum_field_index); |
| 25061 | .base = .{ .tag = .enum_field_index }, | | |
| 25062 | .data = enum_field_index, | | |
| 25063 | }; | | |
| 25064 | const field_tag = Value.initPayload(&field_tag_buf.base); | | |
| 25065 | const tag_matches = tag_and_val.tag.eql(field_tag, union_obj.tag_ty, mod); | 25062 | const tag_matches = tag_and_val.tag.eql(field_tag, union_obj.tag_ty, mod); |
| 25066 | switch (union_obj.layout) { | 25063 | switch (union_obj.layout) { |
| 25067 | .Auto => { | 25064 | .Auto => { |
| ... | @@ -25069,7 +25066,7 @@ fn unionFieldVal( | ... | @@ -25069,7 +25066,7 @@ fn unionFieldVal( |
| 25069 | return sema.addConstant(field.ty, tag_and_val.val); | 25066 | return sema.addConstant(field.ty, tag_and_val.val); |
| 25070 | } else { | 25067 | } else { |
| 25071 | const msg = msg: { | 25068 | const msg = msg: { |
| 25072 | const active_index = tag_and_val.tag.castTag(.enum_field_index).?.data; | 25069 | const active_index = union_obj.tag_ty.enumTagFieldIndex(tag_and_val.tag, mod).?; |
| 25073 | const active_field_name = union_obj.tag_ty.enumFieldName(active_index, mod); | 25070 | const active_field_name = union_obj.tag_ty.enumFieldName(active_index, mod); |
| 25074 | const msg = try sema.errMsg(block, src, "access of union field '{s}' while field '{s}' is active", .{ field_name, active_field_name }); | 25071 | const msg = try sema.errMsg(block, src, "access of union field '{s}' while field '{s}' is active", .{ field_name, active_field_name }); |
| 25075 | errdefer msg.destroy(sema.gpa); | 25072 | errdefer msg.destroy(sema.gpa); |
| ... | @@ -25096,7 +25093,7 @@ fn unionFieldVal( | ... | @@ -25096,7 +25093,7 @@ fn unionFieldVal( |
| 25096 | if (union_obj.layout == .Auto and block.wantSafety() and | 25093 | if (union_obj.layout == .Auto and block.wantSafety() and |
| 25097 | union_ty.unionTagTypeSafety(mod) != null and union_obj.fields.count() > 1) | 25094 | union_ty.unionTagTypeSafety(mod) != null and union_obj.fields.count() > 1) |
| 25098 | { | 25095 | { |
| 25099 | const wanted_tag_val = try Value.Tag.enum_field_index.create(sema.arena, enum_field_index); | 25096 | const wanted_tag_val = try mod.enumValueFieldIndex(union_obj.tag_ty, enum_field_index); |
| 25100 | const wanted_tag = try sema.addConstant(union_obj.tag_ty, wanted_tag_val); | 25097 | const wanted_tag = try sema.addConstant(union_obj.tag_ty, wanted_tag_val); |
| 25101 | const active_tag = try block.addTyOp(.get_union_tag, union_obj.tag_ty, union_byval); | 25098 | const active_tag = try block.addTyOp(.get_union_tag, union_obj.tag_ty, union_byval); |
| 25102 | try sema.panicInactiveUnionField(block, active_tag, wanted_tag); | 25099 | try sema.panicInactiveUnionField(block, active_tag, wanted_tag); |
| ... | @@ -25364,7 +25361,7 @@ fn tupleField( | ... | @@ -25364,7 +25361,7 @@ fn tupleField( |
| 25364 | } | 25361 | } |
| 25365 | | 25362 | |
| 25366 | if (try sema.resolveMaybeUndefVal(tuple)) |tuple_val| { | 25363 | if (try sema.resolveMaybeUndefVal(tuple)) |tuple_val| { |
| 25367 | if (tuple_val.isUndef()) return sema.addConstUndef(field_ty); | 25364 | if (tuple_val.isUndef(mod)) return sema.addConstUndef(field_ty); |
| 25368 | return sema.addConstant(field_ty, try tuple_val.fieldValue(tuple_ty, mod, field_index)); | 25365 | return sema.addConstant(field_ty, try tuple_val.fieldValue(tuple_ty, mod, field_index)); |
| 25369 | } | 25366 | } |
| 25370 | | 25367 | |
| ... | @@ -25412,7 +25409,7 @@ fn elemValArray( | ... | @@ -25412,7 +25409,7 @@ fn elemValArray( |
| 25412 | } | 25409 | } |
| 25413 | } | 25410 | } |
| 25414 | if (maybe_undef_array_val) |array_val| { | 25411 | if (maybe_undef_array_val) |array_val| { |
| 25415 | if (array_val.isUndef()) { | 25412 | if (array_val.isUndef(mod)) { |
| 25416 | return sema.addConstUndef(elem_ty); | 25413 | return sema.addConstUndef(elem_ty); |
| 25417 | } | 25414 | } |
| 25418 | if (maybe_index_val) |index_val| { | 25415 | if (maybe_index_val) |index_val| { |
| ... | @@ -25473,7 +25470,7 @@ fn elemPtrArray( | ... | @@ -25473,7 +25470,7 @@ fn elemPtrArray( |
| 25473 | const elem_ptr_ty = try sema.elemPtrType(array_ptr_ty, offset); | 25470 | const elem_ptr_ty = try sema.elemPtrType(array_ptr_ty, offset); |
| 25474 | | 25471 | |
| 25475 | if (maybe_undef_array_ptr_val) |array_ptr_val| { | 25472 | if (maybe_undef_array_ptr_val) |array_ptr_val| { |
| 25476 | if (array_ptr_val.isUndef()) { | 25473 | if (array_ptr_val.isUndef(mod)) { |
| 25477 | return sema.addConstUndef(elem_ptr_ty); | 25474 | return sema.addConstUndef(elem_ptr_ty); |
| 25478 | } | 25475 | } |
| 25479 | if (offset) |index| { | 25476 | if (offset) |index| { |
| ... | @@ -25580,7 +25577,7 @@ fn elemPtrSlice( | ... | @@ -25580,7 +25577,7 @@ fn elemPtrSlice( |
| 25580 | const elem_ptr_ty = try sema.elemPtrType(slice_ty, offset); | 25577 | const elem_ptr_ty = try sema.elemPtrType(slice_ty, offset); |
| 25581 | | 25578 | |
| 25582 | if (maybe_undef_slice_val) |slice_val| { | 25579 | if (maybe_undef_slice_val) |slice_val| { |
| 25583 | if (slice_val.isUndef()) { | 25580 | if (slice_val.isUndef(mod)) { |
| 25584 | return sema.addConstUndef(elem_ptr_ty); | 25581 | return sema.addConstUndef(elem_ptr_ty); |
| 25585 | } | 25582 | } |
| 25586 | const slice_len = slice_val.sliceLen(mod); | 25583 | const slice_len = slice_val.sliceLen(mod); |
| ... | @@ -25605,7 +25602,7 @@ fn elemPtrSlice( | ... | @@ -25605,7 +25602,7 @@ fn elemPtrSlice( |
| 25605 | if (oob_safety and block.wantSafety()) { | 25602 | if (oob_safety and block.wantSafety()) { |
| 25606 | const len_inst = len: { | 25603 | const len_inst = len: { |
| 25607 | if (maybe_undef_slice_val) |slice_val| | 25604 | if (maybe_undef_slice_val) |slice_val| |
| 25608 | if (!slice_val.isUndef()) | 25605 | if (!slice_val.isUndef(mod)) |
| 25609 | break :len try sema.addIntUnsigned(Type.usize, slice_val.sliceLen(mod)); | 25606 | break :len try sema.addIntUnsigned(Type.usize, slice_val.sliceLen(mod)); |
| 25610 | break :len try block.addTyOp(.slice_len, Type.usize, slice); | 25607 | break :len try block.addTyOp(.slice_len, Type.usize, slice); |
| 25611 | }; | 25608 | }; |
| ... | @@ -25681,7 +25678,6 @@ fn coerceExtra( | ... | @@ -25681,7 +25678,6 @@ fn coerceExtra( |
| 25681 | if (dest_ty.eql(inst_ty, mod)) | 25678 | if (dest_ty.eql(inst_ty, mod)) |
| 25682 | return inst; | 25679 | return inst; |
| 25683 | | 25680 | |
| 25684 | const arena = sema.arena; | | |
| 25685 | const maybe_inst_val = try sema.resolveMaybeUndefVal(inst); | 25681 | const maybe_inst_val = try sema.resolveMaybeUndefVal(inst); |
| 25686 | | 25682 | |
| 25687 | var in_memory_result = try sema.coerceInMemoryAllowed(block, dest_ty, inst_ty, false, target, dest_ty_src, inst_src); | 25683 | var in_memory_result = try sema.coerceInMemoryAllowed(block, dest_ty, inst_ty, false, target, dest_ty_src, inst_src); |
| ... | @@ -26175,7 +26171,7 @@ fn coerceExtra( | ... | @@ -26175,7 +26171,7 @@ fn coerceExtra( |
| 26175 | }; | 26171 | }; |
| 26176 | return sema.addConstant( | 26172 | return sema.addConstant( |
| 26177 | dest_ty, | 26173 | dest_ty, |
| 26178 | try Value.Tag.enum_field_index.create(arena, @intCast(u32, field_index)), | 26174 | try mod.enumValueFieldIndex(dest_ty, @intCast(u32, field_index)), |
| 26179 | ); | 26175 | ); |
| 26180 | }, | 26176 | }, |
| 26181 | .Union => blk: { | 26177 | .Union => blk: { |
| ... | @@ -27858,8 +27854,9 @@ fn beginComptimePtrMutation( | ... | @@ -27858,8 +27854,9 @@ fn beginComptimePtrMutation( |
| 27858 | }, | 27854 | }, |
| 27859 | .Union => { | 27855 | .Union => { |
| 27860 | const payload = try arena.create(Value.Payload.Union); | 27856 | const payload = try arena.create(Value.Payload.Union); |
| | 27857 | const tag_ty = parent.ty.unionTagTypeHypothetical(mod); |
| 27861 | payload.* = .{ .data = .{ | 27858 | payload.* = .{ .data = .{ |
| 27862 | .tag = try Value.Tag.enum_field_index.create(arena, field_index), | 27859 | .tag = try mod.enumValueFieldIndex(tag_ty, field_index), |
| 27863 | .val = Value.undef, | 27860 | .val = Value.undef, |
| 27864 | } }; | 27861 | } }; |
| 27865 | | 27862 | |
| ... | @@ -27934,11 +27931,10 @@ fn beginComptimePtrMutation( | ... | @@ -27934,11 +27931,10 @@ fn beginComptimePtrMutation( |
| 27934 | | 27931 | |
| 27935 | .@"union" => { | 27932 | .@"union" => { |
| 27936 | // We need to set the active field of the union. | 27933 | // We need to set the active field of the union. |
| 27937 | const arena = parent.beginArena(sema.mod); | 27934 | const union_tag_ty = field_ptr.container_ty.unionTagTypeHypothetical(mod); |
| 27938 | defer parent.finishArena(sema.mod); | | |
| 27939 | | 27935 | |
| 27940 | const payload = &val_ptr.castTag(.@"union").?.data; | 27936 | const payload = &val_ptr.castTag(.@"union").?.data; |
| 27941 | payload.tag = try Value.Tag.enum_field_index.create(arena, field_index); | 27937 | payload.tag = try mod.enumValueFieldIndex(union_tag_ty, field_index); |
| 27942 | | 27938 | |
| 27943 | return beginComptimePtrMutationInner( | 27939 | return beginComptimePtrMutationInner( |
| 27944 | sema, | 27940 | sema, |
| ... | @@ -28575,7 +28571,7 @@ fn coerceCompatiblePtrs( | ... | @@ -28575,7 +28571,7 @@ fn coerceCompatiblePtrs( |
| 28575 | const mod = sema.mod; | 28571 | const mod = sema.mod; |
| 28576 | const inst_ty = sema.typeOf(inst); | 28572 | const inst_ty = sema.typeOf(inst); |
| 28577 | if (try sema.resolveMaybeUndefVal(inst)) |val| { | 28573 | if (try sema.resolveMaybeUndefVal(inst)) |val| { |
| 28578 | if (!val.isUndef() and val.isNull(mod) and !dest_ty.isAllowzeroPtr(mod)) { | 28574 | if (!val.isUndef(mod) and val.isNull(mod) and !dest_ty.isAllowzeroPtr(mod)) { |
| 28579 | return sema.fail(block, inst_src, "null pointer casted to type '{}'", .{dest_ty.fmt(sema.mod)}); | 28575 | return sema.fail(block, inst_src, "null pointer casted to type '{}'", .{dest_ty.fmt(sema.mod)}); |
| 28580 | } | 28576 | } |
| 28581 | // The comptime Value representation is compatible with both types. | 28577 | // The comptime Value representation is compatible with both types. |
| ... | @@ -29426,7 +29422,7 @@ fn analyzeSlicePtr( | ... | @@ -29426,7 +29422,7 @@ fn analyzeSlicePtr( |
| 29426 | const buf = try sema.arena.create(Type.SlicePtrFieldTypeBuffer); | 29422 | const buf = try sema.arena.create(Type.SlicePtrFieldTypeBuffer); |
| 29427 | const result_ty = slice_ty.slicePtrFieldType(buf, mod); | 29423 | const result_ty = slice_ty.slicePtrFieldType(buf, mod); |
| 29428 | if (try sema.resolveMaybeUndefVal(slice)) |val| { | 29424 | if (try sema.resolveMaybeUndefVal(slice)) |val| { |
| 29429 | if (val.isUndef()) return sema.addConstUndef(result_ty); | 29425 | if (val.isUndef(mod)) return sema.addConstUndef(result_ty); |
| 29430 | return sema.addConstant(result_ty, val.slicePtr()); | 29426 | return sema.addConstant(result_ty, val.slicePtr()); |
| 29431 | } | 29427 | } |
| 29432 | try sema.requireRuntimeBlock(block, slice_src, null); | 29428 | try sema.requireRuntimeBlock(block, slice_src, null); |
| ... | @@ -29439,8 +29435,9 @@ fn analyzeSliceLen( | ... | @@ -29439,8 +29435,9 @@ fn analyzeSliceLen( |
| 29439 | src: LazySrcLoc, | 29435 | src: LazySrcLoc, |
| 29440 | slice_inst: Air.Inst.Ref, | 29436 | slice_inst: Air.Inst.Ref, |
| 29441 | ) CompileError!Air.Inst.Ref { | 29437 | ) CompileError!Air.Inst.Ref { |
| | 29438 | const mod = sema.mod; |
| 29442 | if (try sema.resolveMaybeUndefVal(slice_inst)) |slice_val| { | 29439 | if (try sema.resolveMaybeUndefVal(slice_inst)) |slice_val| { |
| 29443 | if (slice_val.isUndef()) { | 29440 | if (slice_val.isUndef(mod)) { |
| 29444 | return sema.addConstUndef(Type.usize); | 29441 | return sema.addConstUndef(Type.usize); |
| 29445 | } | 29442 | } |
| 29446 | return sema.addIntUnsigned(Type.usize, slice_val.sliceLen(sema.mod)); | 29443 | return sema.addIntUnsigned(Type.usize, slice_val.sliceLen(sema.mod)); |
| ... | @@ -29459,7 +29456,7 @@ fn analyzeIsNull( | ... | @@ -29459,7 +29456,7 @@ fn analyzeIsNull( |
| 29459 | const mod = sema.mod; | 29456 | const mod = sema.mod; |
| 29460 | const result_ty = Type.bool; | 29457 | const result_ty = Type.bool; |
| 29461 | if (try sema.resolveMaybeUndefVal(operand)) |opt_val| { | 29458 | if (try sema.resolveMaybeUndefVal(operand)) |opt_val| { |
| 29462 | if (opt_val.isUndef()) { | 29459 | if (opt_val.isUndef(mod)) { |
| 29463 | return sema.addConstUndef(result_ty); | 29460 | return sema.addConstUndef(result_ty); |
| 29464 | } | 29461 | } |
| 29465 | const is_null = opt_val.isNull(mod); | 29462 | const is_null = opt_val.isNull(mod); |
| ... | @@ -29588,7 +29585,7 @@ fn analyzeIsNonErrComptimeOnly( | ... | @@ -29588,7 +29585,7 @@ fn analyzeIsNonErrComptimeOnly( |
| 29588 | } | 29585 | } |
| 29589 | | 29586 | |
| 29590 | if (maybe_operand_val) |err_union| { | 29587 | if (maybe_operand_val) |err_union| { |
| 29591 | if (err_union.isUndef()) { | 29588 | if (err_union.isUndef(mod)) { |
| 29592 | return sema.addConstUndef(Type.bool); | 29589 | return sema.addConstUndef(Type.bool); |
| 29593 | } | 29590 | } |
| 29594 | if (err_union.getError() == null) { | 29591 | if (err_union.getError() == null) { |
| ... | @@ -29768,7 +29765,7 @@ fn analyzeSlice( | ... | @@ -29768,7 +29765,7 @@ fn analyzeSlice( |
| 29768 | } else try sema.coerce(block, Type.usize, uncasted_end_opt, end_src); | 29765 | } else try sema.coerce(block, Type.usize, uncasted_end_opt, end_src); |
| 29769 | if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| { | 29766 | if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| { |
| 29770 | if (try sema.resolveMaybeUndefVal(ptr_or_slice)) |slice_val| { | 29767 | if (try sema.resolveMaybeUndefVal(ptr_or_slice)) |slice_val| { |
| 29771 | if (slice_val.isUndef()) { | 29768 | if (slice_val.isUndef(mod)) { |
| 29772 | return sema.fail(block, src, "slice of undefined", .{}); | 29769 | return sema.fail(block, src, "slice of undefined", .{}); |
| 29773 | } | 29770 | } |
| 29774 | const has_sentinel = slice_ty.sentinel(mod) != null; | 29771 | const has_sentinel = slice_ty.sentinel(mod) != null; |
| ... | @@ -29948,7 +29945,7 @@ fn analyzeSlice( | ... | @@ -29948,7 +29945,7 @@ fn analyzeSlice( |
| 29948 | return result; | 29945 | return result; |
| 29949 | }; | 29946 | }; |
| 29950 | | 29947 | |
| 29951 | if (!new_ptr_val.isUndef()) { | 29948 | if (!new_ptr_val.isUndef(mod)) { |
| 29952 | return sema.addConstant(return_ty, new_ptr_val); | 29949 | return sema.addConstant(return_ty, new_ptr_val); |
| 29953 | } | 29950 | } |
| 29954 | | 29951 | |
| ... | @@ -30069,19 +30066,19 @@ fn cmpNumeric( | ... | @@ -30069,19 +30066,19 @@ fn cmpNumeric( |
| 30069 | if (try sema.resolveMaybeUndefVal(lhs)) |lhs_val| { | 30066 | if (try sema.resolveMaybeUndefVal(lhs)) |lhs_val| { |
| 30070 | if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| { | 30067 | if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| { |
| 30071 | // Compare ints: const vs. undefined (or vice versa) | 30068 | // Compare ints: const vs. undefined (or vice versa) |
| 30072 | if (!lhs_val.isUndef() and (lhs_ty.isInt(mod) or lhs_ty_tag == .ComptimeInt) and rhs_ty.isInt(mod) and rhs_val.isUndef()) { | 30069 | if (!lhs_val.isUndef(mod) and (lhs_ty.isInt(mod) or lhs_ty_tag == .ComptimeInt) and rhs_ty.isInt(mod) and rhs_val.isUndef(mod)) { |
| 30073 | try sema.resolveLazyValue(lhs_val); | 30070 | try sema.resolveLazyValue(lhs_val); |
| 30074 | if (try sema.compareIntsOnlyPossibleResult(lhs_val, op, rhs_ty)) |res| { | 30071 | if (try sema.compareIntsOnlyPossibleResult(lhs_val, op, rhs_ty)) |res| { |
| 30075 | return if (res) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false; | 30072 | return if (res) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false; |
| 30076 | } | 30073 | } |
| 30077 | } else if (!rhs_val.isUndef() and (rhs_ty.isInt(mod) or rhs_ty_tag == .ComptimeInt) and lhs_ty.isInt(mod) and lhs_val.isUndef()) { | 30074 | } else if (!rhs_val.isUndef(mod) and (rhs_ty.isInt(mod) or rhs_ty_tag == .ComptimeInt) and lhs_ty.isInt(mod) and lhs_val.isUndef(mod)) { |
| 30078 | try sema.resolveLazyValue(rhs_val); | 30075 | try sema.resolveLazyValue(rhs_val); |
| 30079 | if (try sema.compareIntsOnlyPossibleResult(rhs_val, op.reverse(), lhs_ty)) |res| { | 30076 | if (try sema.compareIntsOnlyPossibleResult(rhs_val, op.reverse(), lhs_ty)) |res| { |
| 30080 | return if (res) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false; | 30077 | return if (res) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false; |
| 30081 | } | 30078 | } |
| 30082 | } | 30079 | } |
| 30083 | | 30080 | |
| 30084 | if (lhs_val.isUndef() or rhs_val.isUndef()) { | 30081 | if (lhs_val.isUndef(mod) or rhs_val.isUndef(mod)) { |
| 30085 | return sema.addConstUndef(Type.bool); | 30082 | return sema.addConstUndef(Type.bool); |
| 30086 | } | 30083 | } |
| 30087 | if (lhs_val.isNan(mod) or rhs_val.isNan(mod)) { | 30084 | if (lhs_val.isNan(mod) or rhs_val.isNan(mod)) { |
| ... | @@ -30097,7 +30094,7 @@ fn cmpNumeric( | ... | @@ -30097,7 +30094,7 @@ fn cmpNumeric( |
| 30097 | return Air.Inst.Ref.bool_false; | 30094 | return Air.Inst.Ref.bool_false; |
| 30098 | } | 30095 | } |
| 30099 | } else { | 30096 | } else { |
| 30100 | if (!lhs_val.isUndef() and (lhs_ty.isInt(mod) or lhs_ty_tag == .ComptimeInt) and rhs_ty.isInt(mod)) { | 30097 | if (!lhs_val.isUndef(mod) and (lhs_ty.isInt(mod) or lhs_ty_tag == .ComptimeInt) and rhs_ty.isInt(mod)) { |
| 30101 | // Compare ints: const vs. var | 30098 | // Compare ints: const vs. var |
| 30102 | try sema.resolveLazyValue(lhs_val); | 30099 | try sema.resolveLazyValue(lhs_val); |
| 30103 | if (try sema.compareIntsOnlyPossibleResult(lhs_val, op, rhs_ty)) |res| { | 30100 | if (try sema.compareIntsOnlyPossibleResult(lhs_val, op, rhs_ty)) |res| { |
| ... | @@ -30108,7 +30105,7 @@ fn cmpNumeric( | ... | @@ -30108,7 +30105,7 @@ fn cmpNumeric( |
| 30108 | } | 30105 | } |
| 30109 | } else { | 30106 | } else { |
| 30110 | if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| { | 30107 | if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| { |
| 30111 | if (!rhs_val.isUndef() and (rhs_ty.isInt(mod) or rhs_ty_tag == .ComptimeInt) and lhs_ty.isInt(mod)) { | 30108 | if (!rhs_val.isUndef(mod) and (rhs_ty.isInt(mod) or rhs_ty_tag == .ComptimeInt) and lhs_ty.isInt(mod)) { |
| 30112 | // Compare ints: var vs. const | 30109 | // Compare ints: var vs. const |
| 30113 | try sema.resolveLazyValue(rhs_val); | 30110 | try sema.resolveLazyValue(rhs_val); |
| 30114 | if (try sema.compareIntsOnlyPossibleResult(rhs_val, op.reverse(), lhs_ty)) |res| { | 30111 | if (try sema.compareIntsOnlyPossibleResult(rhs_val, op.reverse(), lhs_ty)) |res| { |
| ... | @@ -30177,7 +30174,7 @@ fn cmpNumeric( | ... | @@ -30177,7 +30174,7 @@ fn cmpNumeric( |
| 30177 | var lhs_bits: usize = undefined; | 30174 | var lhs_bits: usize = undefined; |
| 30178 | if (try sema.resolveMaybeUndefVal(lhs)) |lhs_val| { | 30175 | if (try sema.resolveMaybeUndefVal(lhs)) |lhs_val| { |
| 30179 | try sema.resolveLazyValue(lhs_val); | 30176 | try sema.resolveLazyValue(lhs_val); |
| 30180 | if (lhs_val.isUndef()) | 30177 | if (lhs_val.isUndef(mod)) |
| 30181 | return sema.addConstUndef(Type.bool); | 30178 | return sema.addConstUndef(Type.bool); |
| 30182 | if (lhs_val.isNan(mod)) switch (op) { | 30179 | if (lhs_val.isNan(mod)) switch (op) { |
| 30183 | .neq => return Air.Inst.Ref.bool_true, | 30180 | .neq => return Air.Inst.Ref.bool_true, |
| ... | @@ -30236,7 +30233,7 @@ fn cmpNumeric( | ... | @@ -30236,7 +30233,7 @@ fn cmpNumeric( |
| 30236 | var rhs_bits: usize = undefined; | 30233 | var rhs_bits: usize = undefined; |
| 30237 | if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| { | 30234 | if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| { |
| 30238 | try sema.resolveLazyValue(rhs_val); | 30235 | try sema.resolveLazyValue(rhs_val); |
| 30239 | if (rhs_val.isUndef()) | 30236 | if (rhs_val.isUndef(mod)) |
| 30240 | return sema.addConstUndef(Type.bool); | 30237 | return sema.addConstUndef(Type.bool); |
| 30241 | if (rhs_val.isNan(mod)) switch (op) { | 30238 | if (rhs_val.isNan(mod)) switch (op) { |
| 30242 | .neq => return Air.Inst.Ref.bool_true, | 30239 | .neq => return Air.Inst.Ref.bool_true, |
| ... | @@ -30441,7 +30438,7 @@ fn cmpVector( | ... | @@ -30441,7 +30438,7 @@ fn cmpVector( |
| 30441 | const runtime_src: LazySrcLoc = src: { | 30438 | const runtime_src: LazySrcLoc = src: { |
| 30442 | if (try sema.resolveMaybeUndefVal(casted_lhs)) |lhs_val| { | 30439 | if (try sema.resolveMaybeUndefVal(casted_lhs)) |lhs_val| { |
| 30443 | if (try sema.resolveMaybeUndefVal(casted_rhs)) |rhs_val| { | 30440 | if (try sema.resolveMaybeUndefVal(casted_rhs)) |rhs_val| { |
| 30444 | if (lhs_val.isUndef() or rhs_val.isUndef()) { | 30441 | if (lhs_val.isUndef(mod) or rhs_val.isUndef(mod)) { |
| 30445 | return sema.addConstUndef(result_ty); | 30442 | return sema.addConstUndef(result_ty); |
| 30446 | } | 30443 | } |
| 30447 | const cmp_val = try sema.compareVector(lhs_val, op, rhs_val, resolved_ty); | 30444 | const cmp_val = try sema.compareVector(lhs_val, op, rhs_val, resolved_ty); |
| ... | @@ -30558,11 +30555,12 @@ fn unionToTag( | ... | @@ -30558,11 +30555,12 @@ fn unionToTag( |
| 30558 | un: Air.Inst.Ref, | 30555 | un: Air.Inst.Ref, |
| 30559 | un_src: LazySrcLoc, | 30556 | un_src: LazySrcLoc, |
| 30560 | ) !Air.Inst.Ref { | 30557 | ) !Air.Inst.Ref { |
| | 30558 | const mod = sema.mod; |
| 30561 | if ((try sema.typeHasOnePossibleValue(enum_ty))) |opv| { | 30559 | if ((try sema.typeHasOnePossibleValue(enum_ty))) |opv| { |
| 30562 | return sema.addConstant(enum_ty, opv); | 30560 | return sema.addConstant(enum_ty, opv); |
| 30563 | } | 30561 | } |
| 30564 | if (try sema.resolveMaybeUndefVal(un)) |un_val| { | 30562 | if (try sema.resolveMaybeUndefVal(un)) |un_val| { |
| 30565 | return sema.addConstant(enum_ty, un_val.unionTag()); | 30563 | return sema.addConstant(enum_ty, un_val.unionTag(mod)); |
| 30566 | } | 30564 | } |
| 30567 | try sema.requireRuntimeBlock(block, un_src, null); | 30565 | try sema.requireRuntimeBlock(block, un_src, null); |
| 30568 | return block.addTyOp(.get_union_tag, enum_ty, un); | 30566 | return block.addTyOp(.get_union_tag, enum_ty, un); |
| ... | @@ -31718,6 +31716,7 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { | ... | @@ -31718,6 +31716,7 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { |
| 31718 | .enum_type => |enum_type| try sema.resolveTypeRequiresComptime(enum_type.tag_ty.toType()), | 31716 | .enum_type => |enum_type| try sema.resolveTypeRequiresComptime(enum_type.tag_ty.toType()), |
| 31719 | | 31717 | |
| 31720 | // values, not types | 31718 | // values, not types |
| | 31719 | .undef => unreachable, |
| 31721 | .un => unreachable, | 31720 | .un => unreachable, |
| 31722 | .simple_value => unreachable, | 31721 | .simple_value => unreachable, |
| 31723 | .extern_func => unreachable, | 31722 | .extern_func => unreachable, |
| ... | @@ -31845,6 +31844,7 @@ pub fn resolveTypeFields(sema: *Sema, ty: Type) CompileError!Type { | ... | @@ -31845,6 +31844,7 @@ pub fn resolveTypeFields(sema: *Sema, ty: Type) CompileError!Type { |
| 31845 | .none => return ty, | 31844 | .none => return ty, |
| 31846 | | 31845 | |
| 31847 | .u1_type, | 31846 | .u1_type, |
| | 31847 | .u5_type, |
| 31848 | .u8_type, | 31848 | .u8_type, |
| 31849 | .i8_type, | 31849 | .i8_type, |
| 31850 | .u16_type, | 31850 | .u16_type, |
| ... | @@ -31904,6 +31904,8 @@ pub fn resolveTypeFields(sema: *Sema, ty: Type) CompileError!Type { | ... | @@ -31904,6 +31904,8 @@ pub fn resolveTypeFields(sema: *Sema, ty: Type) CompileError!Type { |
| 31904 | .zero_u8 => unreachable, | 31904 | .zero_u8 => unreachable, |
| 31905 | .one => unreachable, | 31905 | .one => unreachable, |
| 31906 | .one_usize => unreachable, | 31906 | .one_usize => unreachable, |
| | 31907 | .one_u5 => unreachable, |
| | 31908 | .four_u5 => unreachable, |
| 31907 | .negative_one => unreachable, | 31909 | .negative_one => unreachable, |
| 31908 | .calling_convention_c => unreachable, | 31910 | .calling_convention_c => unreachable, |
| 31909 | .calling_convention_inline => unreachable, | 31911 | .calling_convention_inline => unreachable, |
| ... | @@ -32720,7 +32722,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { | ... | @@ -32720,7 +32722,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 32720 | } | 32722 | } |
| 32721 | | 32723 | |
| 32722 | if (explicit_enum_info) |tag_info| { | 32724 | if (explicit_enum_info) |tag_info| { |
| 32723 | const enum_index = tag_info.nameIndex(mod.intern_pool, field_name_ip) orelse { | 32725 | const enum_index = tag_info.nameIndex(&mod.intern_pool, field_name_ip) orelse { |
| 32724 | const msg = msg: { | 32726 | const msg = msg: { |
| 32725 | const ty_src = mod.fieldSrcLoc(union_obj.owner_decl, .{ | 32727 | const ty_src = mod.fieldSrcLoc(union_obj.owner_decl, .{ |
| 32726 | .index = field_i, | 32728 | .index = field_i, |
| ... | @@ -33186,19 +33188,30 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -33186,19 +33188,30 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 33186 | .opaque_type => null, | 33188 | .opaque_type => null, |
| 33187 | .enum_type => |enum_type| switch (enum_type.tag_mode) { | 33189 | .enum_type => |enum_type| switch (enum_type.tag_mode) { |
| 33188 | .nonexhaustive => { | 33190 | .nonexhaustive => { |
| 33189 | if (enum_type.tag_ty != .comptime_int_type and | 33191 | if (enum_type.tag_ty == .comptime_int_type) return null; |
| 33190 | !(try sema.typeHasRuntimeBits(enum_type.tag_ty.toType()))) | 33192 | |
| 33191 | { | 33193 | if (try sema.typeHasOnePossibleValue(enum_type.tag_ty.toType())) |int_opv| { |
| 33192 | return Value.enum_field_0; | 33194 | const only = try mod.intern(.{ .enum_tag = .{ |
| 33193 | } else { | 33195 | .ty = ty.ip_index, |
| 33194 | return null; | 33196 | .int = int_opv.ip_index, |
| | 33197 | } }); |
| | 33198 | return only.toValue(); |
| 33195 | } | 33199 | } |
| | 33200 | |
| | 33201 | return null; |
| 33196 | }, | 33202 | }, |
| 33197 | .auto, .explicit => switch (enum_type.names.len) { | 33203 | .auto, .explicit => switch (enum_type.names.len) { |
| 33198 | 0 => return Value.@"unreachable", | 33204 | 0 => return Value.@"unreachable", |
| 33199 | 1 => { | 33205 | 1 => { |
| 33200 | if (enum_type.values.len == 0) { | 33206 | if (enum_type.values.len == 0) { |
| 33201 | return Value.enum_field_0; // auto-numbered | 33207 | const only = try mod.intern(.{ .enum_tag = .{ |
| | 33208 | .ty = ty.ip_index, |
| | 33209 | .int = try mod.intern(.{ .int = .{ |
| | 33210 | .ty = enum_type.tag_ty, |
| | 33211 | .storage = .{ .u64 = 0 }, |
| | 33212 | } }), |
| | 33213 | } }); |
| | 33214 | return only.toValue(); |
| 33202 | } else { | 33215 | } else { |
| 33203 | return enum_type.values[0].toValue(); | 33216 | return enum_type.values[0].toValue(); |
| 33204 | } | 33217 | } |
| ... | @@ -33208,6 +33221,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -33208,6 +33221,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 33208 | }, | 33221 | }, |
| 33209 | | 33222 | |
| 33210 | // values, not types | 33223 | // values, not types |
| | 33224 | .undef => unreachable, |
| 33211 | .un => unreachable, | 33225 | .un => unreachable, |
| 33212 | .simple_value => unreachable, | 33226 | .simple_value => unreachable, |
| 33213 | .extern_func => unreachable, | 33227 | .extern_func => unreachable, |
| ... | @@ -33397,8 +33411,9 @@ pub fn analyzeAddressSpace( | ... | @@ -33397,8 +33411,9 @@ pub fn analyzeAddressSpace( |
| 33397 | zir_ref: Zir.Inst.Ref, | 33411 | zir_ref: Zir.Inst.Ref, |
| 33398 | ctx: AddressSpaceContext, | 33412 | ctx: AddressSpaceContext, |
| 33399 | ) !std.builtin.AddressSpace { | 33413 | ) !std.builtin.AddressSpace { |
| | 33414 | const mod = sema.mod; |
| 33400 | const addrspace_tv = try sema.resolveInstConst(block, src, zir_ref, "addresspace must be comptime-known"); | 33415 | const addrspace_tv = try sema.resolveInstConst(block, src, zir_ref, "addresspace must be comptime-known"); |
| 33401 | const address_space = addrspace_tv.val.toEnum(std.builtin.AddressSpace); | 33416 | const address_space = mod.toEnum(std.builtin.AddressSpace, addrspace_tv.val); |
| 33402 | const target = sema.mod.getTarget(); | 33417 | const target = sema.mod.getTarget(); |
| 33403 | const arch = target.cpu.arch; | 33418 | const arch = target.cpu.arch; |
| 33404 | | 33419 | |
| ... | @@ -33766,6 +33781,7 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { | ... | @@ -33766,6 +33781,7 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { |
| 33766 | .enum_type => |enum_type| try sema.typeRequiresComptime(enum_type.tag_ty.toType()), | 33781 | .enum_type => |enum_type| try sema.typeRequiresComptime(enum_type.tag_ty.toType()), |
| 33767 | | 33782 | |
| 33768 | // values, not types | 33783 | // values, not types |
| | 33784 | .undef => unreachable, |
| 33769 | .un => unreachable, | 33785 | .un => unreachable, |
| 33770 | .simple_value => unreachable, | 33786 | .simple_value => unreachable, |
| 33771 | .extern_func => unreachable, | 33787 | .extern_func => unreachable, |
| ... | @@ -33921,9 +33937,9 @@ fn numberAddWrapScalar( | ... | @@ -33921,9 +33937,9 @@ fn numberAddWrapScalar( |
| 33921 | rhs: Value, | 33937 | rhs: Value, |
| 33922 | ty: Type, | 33938 | ty: Type, |
| 33923 | ) !Value { | 33939 | ) !Value { |
| 33924 | if (lhs.isUndef() or rhs.isUndef()) return Value.undef; | | |
| 33925 | | | |
| 33926 | const mod = sema.mod; | 33940 | const mod = sema.mod; |
| | 33941 | if (lhs.isUndef(mod) or rhs.isUndef(mod)) return Value.undef; |
| | 33942 | |
| 33927 | if (ty.zigTypeTag(mod) == .ComptimeInt) { | 33943 | if (ty.zigTypeTag(mod) == .ComptimeInt) { |
| 33928 | return sema.intAdd(lhs, rhs, ty); | 33944 | return sema.intAdd(lhs, rhs, ty); |
| 33929 | } | 33945 | } |
| ... | @@ -33975,9 +33991,9 @@ fn numberSubWrapScalar( | ... | @@ -33975,9 +33991,9 @@ fn numberSubWrapScalar( |
| 33975 | rhs: Value, | 33991 | rhs: Value, |
| 33976 | ty: Type, | 33992 | ty: Type, |
| 33977 | ) !Value { | 33993 | ) !Value { |
| 33978 | if (lhs.isUndef() or rhs.isUndef()) return Value.undef; | | |
| 33979 | | | |
| 33980 | const mod = sema.mod; | 33994 | const mod = sema.mod; |
| | 33995 | if (lhs.isUndef(mod) or rhs.isUndef(mod)) return Value.undef; |
| | 33996 | |
| 33981 | if (ty.zigTypeTag(mod) == .ComptimeInt) { | 33997 | if (ty.zigTypeTag(mod) == .ComptimeInt) { |
| 33982 | return sema.intSub(lhs, rhs, ty); | 33998 | return sema.intSub(lhs, rhs, ty); |
| 33983 | } | 33999 | } |
| ... | @@ -34222,17 +34238,12 @@ fn enumHasInt(sema: *Sema, ty: Type, int: Value) CompileError!bool { | ... | @@ -34222,17 +34238,12 @@ fn enumHasInt(sema: *Sema, ty: Type, int: Value) CompileError!bool { |
| 34222 | const mod = sema.mod; | 34238 | const mod = sema.mod; |
| 34223 | const enum_type = mod.intern_pool.indexToKey(ty.ip_index).enum_type; | 34239 | const enum_type = mod.intern_pool.indexToKey(ty.ip_index).enum_type; |
| 34224 | assert(enum_type.tag_mode != .nonexhaustive); | 34240 | assert(enum_type.tag_mode != .nonexhaustive); |
| 34225 | if (enum_type.values.len == 0) { | | |
| 34226 | // auto-numbered | | |
| 34227 | return sema.intInRange(enum_type.tag_ty.toType(), int, enum_type.names.len); | | |
| 34228 | } | | |
| 34229 | | | |
| 34230 | // The `tagValueIndex` function call below relies on the type being the integer tag type. | 34241 | // The `tagValueIndex` function call below relies on the type being the integer tag type. |
| 34231 | // `getCoerced` assumes the value will fit the new type. | 34242 | // `getCoerced` assumes the value will fit the new type. |
| 34232 | if (!(try sema.intFitsInType(int, enum_type.tag_ty.toType(), null))) return false; | 34243 | if (!(try sema.intFitsInType(int, enum_type.tag_ty.toType(), null))) return false; |
| 34233 | const int_coerced = try mod.intern_pool.getCoerced(sema.gpa, int.ip_index, enum_type.tag_ty); | 34244 | const int_coerced = try mod.intern_pool.getCoerced(sema.gpa, int.ip_index, enum_type.tag_ty); |
| 34234 | | 34245 | |
| 34235 | return enum_type.tagValueIndex(mod.intern_pool, int_coerced) != null; | 34246 | return enum_type.tagValueIndex(&mod.intern_pool, int_coerced) != null; |
| 34236 | } | 34247 | } |
| 34237 | | 34248 | |
| 34238 | fn intAddWithOverflow( | 34249 | fn intAddWithOverflow( |