| ... | ... | @@ -15154,13 +15154,10 @@ fn addDivIntOverflowSafety( |
| 15154 | 15154 | const elem_val = try lhs_val.elemValue(pt, elem_idx); |
| 15155 | 15155 | elem_ok.* = if (elem_val.eqlScalarNum(min_int_scalar, zcu)) .bool_false else .bool_true; |
| 15156 | 15156 | } |
| 15157 | | break :ok Air.internedToRef(try pt.intern(.{ .aggregate = .{ |
| 15158 | | .ty = (try pt.vectorType(.{ |
| 15159 | | .len = vec_len, |
| 15160 | | .child = .bool_type, |
| 15161 | | })).toIntern(), |
| 15162 | | .storage = .{ .elems = elems_ok }, |
| 15163 | | } })); |
| 15157 | break :ok .fromValue(try pt.aggregateValue(try pt.vectorType(.{ |
| 15158 | .len = vec_len, |
| 15159 | .child = .bool_type, |
| 15160 | }), elems_ok)); |
| 15164 | 15161 | } else ok: { |
| 15165 | 15162 | // The operand isn't comptime-known; add a runtime comparison. |
| 15166 | 15163 | const min_int_ref = Air.internedToRef(min_int.toIntern()); |
| ... | ... | @@ -15175,13 +15172,10 @@ fn addDivIntOverflowSafety( |
| 15175 | 15172 | const elem_val = try rhs_val.elemValue(pt, elem_idx); |
| 15176 | 15173 | elem_ok.* = if (elem_val.eqlScalarNum(neg_one_scalar, zcu)) .bool_false else .bool_true; |
| 15177 | 15174 | } |
| 15178 | | break :ok Air.internedToRef(try pt.intern(.{ .aggregate = .{ |
| 15179 | | .ty = (try pt.vectorType(.{ |
| 15180 | | .len = vec_len, |
| 15181 | | .child = .bool_type, |
| 15182 | | })).toIntern(), |
| 15183 | | .storage = .{ .elems = elems_ok }, |
| 15184 | | } })); |
| 15175 | break :ok .fromValue(try pt.aggregateValue(try pt.vectorType(.{ |
| 15176 | .len = vec_len, |
| 15177 | .child = .bool_type, |
| 15178 | }), elems_ok)); |
| 15185 | 15179 | } else ok: { |
| 15186 | 15180 | // The operand isn't comptime-known; add a runtime comparison. |
| 15187 | 15181 | const neg_one_ref = Air.internedToRef(neg_one.toIntern()); |
| ... | ... | @@ -19057,10 +19051,7 @@ fn arrayInitEmpty(sema: *Sema, block: *Block, src: LazySrcLoc, obj_ty: Type) Com |
| 19057 | 19051 | return sema.fail(block, src, "expected {d} vector elements; found 0", .{arr_len}); |
| 19058 | 19052 | } |
| 19059 | 19053 | } |
| 19060 | | return Air.internedToRef((try pt.intern(.{ .aggregate = .{ |
| 19061 | | .ty = obj_ty.toIntern(), |
| 19062 | | .storage = .{ .elems = &.{} }, |
| 19063 | | } }))); |
| 19054 | return .fromValue(try pt.aggregateValue(obj_ty, &.{})); |
| 19064 | 19055 | } |
| 19065 | 19056 | |
| 19066 | 19057 | fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -23478,40 +23469,23 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 23478 | 23469 | } |
| 23479 | 23470 | |
| 23480 | 23471 | // We also need this case because `[0:s]T` is not OPV. |
| 23481 | | if (len == 0) { |
| 23482 | | const empty_aggregate = try pt.intern(.{ .aggregate = .{ |
| 23483 | | .ty = dest_ty.toIntern(), |
| 23484 | | .storage = .{ .elems = &.{} }, |
| 23485 | | } }); |
| 23486 | | return Air.internedToRef(empty_aggregate); |
| 23487 | | } |
| 23472 | if (len == 0) return .fromValue(try pt.aggregateValue(dest_ty, &.{})); |
| 23488 | 23473 | |
| 23489 | 23474 | const maybe_sentinel = dest_ty.sentinel(zcu); |
| 23490 | 23475 | |
| 23491 | 23476 | if (try sema.resolveValue(scalar)) |scalar_val| { |
| 23492 | | if (scalar_val.isUndef(zcu) and maybe_sentinel == null) { |
| 23493 | | return pt.undefRef(dest_ty); |
| 23477 | full: { |
| 23478 | if (dest_ty.zigTypeTag(zcu) == .vector) break :full; |
| 23479 | const sentinel = maybe_sentinel orelse break :full; |
| 23480 | if (sentinel.toIntern() == scalar_val.toIntern()) break :full; |
| 23481 | // This is a array with non-zero length and a sentinel which does not match the element. |
| 23482 | // We have to use the full `elems` representation. |
| 23483 | const elems = try sema.arena.alloc(InternPool.Index, len + 1); |
| 23484 | @memset(elems[0..len], scalar_val.toIntern()); |
| 23485 | elems[len] = sentinel.toIntern(); |
| 23486 | return .fromValue(try pt.aggregateValue(dest_ty, elems)); |
| 23494 | 23487 | } |
| 23495 | | // TODO: I didn't want to put `.aggregate` on a separate line here; `zig fmt` bugs have forced my hand |
| 23496 | | return Air.internedToRef(try pt.intern(.{ |
| 23497 | | .aggregate = .{ |
| 23498 | | .ty = dest_ty.toIntern(), |
| 23499 | | .storage = s: { |
| 23500 | | full: { |
| 23501 | | if (dest_ty.zigTypeTag(zcu) == .vector) break :full; |
| 23502 | | const sentinel = maybe_sentinel orelse break :full; |
| 23503 | | if (sentinel.toIntern() == scalar_val.toIntern()) break :full; |
| 23504 | | // This is a array with non-zero length and a sentinel which does not match the element. |
| 23505 | | // We have to use the full `elems` representation. |
| 23506 | | const elems = try sema.arena.alloc(InternPool.Index, len + 1); |
| 23507 | | @memset(elems[0..len], scalar_val.toIntern()); |
| 23508 | | elems[len] = sentinel.toIntern(); |
| 23509 | | break :s .{ .elems = elems }; |
| 23510 | | } |
| 23511 | | break :s .{ .repeated_elem = scalar_val.toIntern() }; |
| 23512 | | }, |
| 23513 | | }, |
| 23514 | | })); |
| 23488 | return .fromValue(try pt.aggregateSplatValue(dest_ty, scalar_val)); |
| 23515 | 23489 | } |
| 23516 | 23490 | |
| 23517 | 23491 | try sema.requireRuntimeBlock(block, src, scalar_src); |
| ... | ... | @@ -35923,11 +35897,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 35923 | 35897 | => switch (ip.indexToKey(ty.toIntern())) { |
| 35924 | 35898 | inline .array_type, .vector_type => |seq_type, seq_tag| { |
| 35925 | 35899 | const has_sentinel = seq_tag == .array_type and seq_type.sentinel != .none; |
| 35926 | | if (seq_type.len + @intFromBool(has_sentinel) == 0) return Value.fromInterned(try pt.intern(.{ .aggregate = .{ |
| 35927 | | .ty = ty.toIntern(), |
| 35928 | | .storage = .{ .elems = &.{} }, |
| 35929 | | } })); |
| 35930 | | |
| 35900 | if (seq_type.len + @intFromBool(has_sentinel) == 0) return try pt.aggregateValue(ty, &.{}); |
| 35931 | 35901 | if (try sema.typeHasOnePossibleValue(.fromInterned(seq_type.child))) |opv| { |
| 35932 | 35902 | return try pt.aggregateSplatValue(ty, opv); |
| 35933 | 35903 | } |
| ... | ... | @@ -35944,10 +35914,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 35944 | 35914 | if (struct_type.field_types.len == 0) { |
| 35945 | 35915 | // In this case the struct has no fields at all and |
| 35946 | 35916 | // therefore has one possible value. |
| 35947 | | return Value.fromInterned(try pt.intern(.{ .aggregate = .{ |
| 35948 | | .ty = ty.toIntern(), |
| 35949 | | .storage = .{ .elems = &.{} }, |
| 35950 | | } })); |
| 35917 | return try pt.aggregateValue(ty, &.{}); |
| 35951 | 35918 | } |
| 35952 | 35919 | |
| 35953 | 35920 | const field_vals = try sema.arena.alloc( |