authorgravatar for justus@klausecker.deJustus Klausecker <justus@klausecker.de> 2025-08-07 19:42:40+02:00
committergravatar for justus@klausecker.deJustus Klausecker <justus@klausecker.de> 2025-08-12 16:33:57+02:00
log79e5c138c6474713776caf25cbc21923471ff759
treede185dfb6047e9ab3f3723672c35df61fc74611c
parent7756fa66411d88f8e280d6d5e91d809ea536cbff

replace even more aggregate interns


8 files changed, 68 insertions(+), 197 deletions(-)

src/Air/Legalize.zig+3-12
...@@ -941,10 +941,7 @@ fn scalarizeBlockPayload(l: *Legalize, orig_inst: Air.Inst.Index, comptime form:...@@ -941,10 +941,7 @@ fn scalarizeBlockPayload(l: *Legalize, orig_inst: Air.Inst.Index, comptime form:
941 .lhs = Air.internedToRef(try pt.intern(.{ .ptr = .{941 .lhs = Air.internedToRef(try pt.intern(.{ .ptr = .{
942 .ty = (try pt.manyConstPtrType(mask_elem_ty)).toIntern(),942 .ty = (try pt.manyConstPtrType(mask_elem_ty)).toIntern(),
943 .base_addr = .{ .uav = .{943 .base_addr = .{ .uav = .{
944 .val = try pt.intern(.{ .aggregate = .{944 .val = (try pt.aggregateValue(mask_ty, mask_elems)).toIntern(),
945 .ty = mask_ty.toIntern(),
946 .storage = .{ .elems = mask_elems },
947 } }),
948 .orig_ty = (try pt.singleConstPtrType(mask_ty)).toIntern(),945 .orig_ty = (try pt.singleConstPtrType(mask_ty)).toIntern(),
949 } },946 } },
950 .byte_offset = 0,947 .byte_offset = 0,
...@@ -1023,10 +1020,7 @@ fn scalarizeBlockPayload(l: *Legalize, orig_inst: Air.Inst.Index, comptime form:...@@ -1023,10 +1020,7 @@ fn scalarizeBlockPayload(l: *Legalize, orig_inst: Air.Inst.Index, comptime form:
1023 break :operand_b Air.internedToRef(try pt.intern(.{ .ptr = .{1020 break :operand_b Air.internedToRef(try pt.intern(.{ .ptr = .{
1024 .ty = (try pt.manyConstPtrType(elem_ty)).toIntern(),1021 .ty = (try pt.manyConstPtrType(elem_ty)).toIntern(),
1025 .base_addr = .{ .uav = .{1022 .base_addr = .{ .uav = .{
1026 .val = try pt.intern(.{ .aggregate = .{1023 .val = (try pt.aggregateValue(ct_elems_ty, ct_elems.keys())).toIntern(),
1027 .ty = ct_elems_ty.toIntern(),
1028 .storage = .{ .elems = ct_elems.keys() },
1029 } }),
1030 .orig_ty = (try pt.singleConstPtrType(ct_elems_ty)).toIntern(),1024 .orig_ty = (try pt.singleConstPtrType(ct_elems_ty)).toIntern(),
1031 } },1025 } },
1032 .byte_offset = 0,1026 .byte_offset = 0,
...@@ -2550,10 +2544,7 @@ fn floatFromBigIntVal(...@@ -2550,10 +2544,7 @@ fn floatFromBigIntVal(
2550 else => unreachable,2544 else => unreachable,
2551 };2545 };
2552 if (is_vector) {2546 if (is_vector) {
2553 return .fromInterned(try pt.intern(.{ .aggregate = .{2547 return pt.aggregateSplatValue(float_ty, scalar_val);
2554 .ty = float_ty.toIntern(),
2555 .storage = .{ .repeated_elem = scalar_val.toIntern() },
2556 } }));
2557 } else {2548 } else {
2558 return scalar_val;2549 return scalar_val;
2559 }2550 }
src/Sema.zig+1-2
...@@ -14838,8 +14838,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -14838,8 +14838,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1483814838
14839 if (maybe_lhs_val) |lhs_val| {14839 if (maybe_lhs_val) |lhs_val| {
14840 if (maybe_rhs_val) |rhs_val| {14840 if (maybe_rhs_val) |rhs_val| {
14841 const result = try arith.div(sema, block, resolved_type, lhs_val, rhs_val, src, lhs_src, rhs_src, .div);14841 return .fromValue(try arith.div(sema, block, resolved_type, lhs_val, rhs_val, src, lhs_src, rhs_src, .div));
14842 return Air.internedToRef(result.toIntern());
14843 }14842 }
14844 if (allow_div_zero) {14843 if (allow_div_zero) {
14845 if (lhs_val.isUndef(zcu)) return pt.undefRef(resolved_type);14844 if (lhs_val.isUndef(zcu)) return pt.undefRef(resolved_type);
src/Sema/LowerZon.zig+11-34
...@@ -120,10 +120,7 @@ fn lowerExprAnonResTy(self: *LowerZon, node: Zoir.Node.Index) CompileError!Inter...@@ -120,10 +120,7 @@ fn lowerExprAnonResTy(self: *LowerZon, node: Zoir.Node.Index) CompileError!Inter
120 .values = values,120 .values = values,
121 },121 },
122 );122 );
123 return pt.intern(.{ .aggregate = .{123 return (try pt.aggregateValue(.fromInterned(ty), values)).toIntern();
124 .ty = ty,
125 .storage = .{ .elems = values },
126 } });
127 },124 },
128 .struct_literal => |init| {125 .struct_literal => |init| {
129 const elems = try self.sema.arena.alloc(InternPool.Index, init.names.len);126 const elems = try self.sema.arena.alloc(InternPool.Index, init.names.len);
...@@ -205,10 +202,7 @@ fn lowerExprAnonResTy(self: *LowerZon, node: Zoir.Node.Index) CompileError!Inter...@@ -205,10 +202,7 @@ fn lowerExprAnonResTy(self: *LowerZon, node: Zoir.Node.Index) CompileError!Inter
205 try self.sema.declareDependency(.{ .interned = struct_ty });202 try self.sema.declareDependency(.{ .interned = struct_ty });
206 try self.sema.addTypeReferenceEntry(self.nodeSrc(node), struct_ty);203 try self.sema.addTypeReferenceEntry(self.nodeSrc(node), struct_ty);
207204
208 return try pt.intern(.{ .aggregate = .{205 return (try pt.aggregateValue(.fromInterned(struct_ty), elems)).toIntern();
209 .ty = struct_ty,
210 .storage = .{ .elems = elems },
211 } });
212 },206 },
213 }207 }
214}208}
...@@ -638,10 +632,7 @@ fn lowerArray(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool....@@ -638,10 +632,7 @@ fn lowerArray(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool.
638 elems[elems.len - 1] = sentinel.toIntern();632 elems[elems.len - 1] = sentinel.toIntern();
639 }633 }
640634
641 return self.sema.pt.intern(.{ .aggregate = .{635 return (try self.sema.pt.aggregateValue(res_ty, elems)).toIntern();
642 .ty = res_ty.toIntern(),
643 .storage = .{ .elems = elems },
644 } });
645}636}
646637
647fn lowerEnum(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool.Index {638fn lowerEnum(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool.Index {
...@@ -752,10 +743,7 @@ fn lowerTuple(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool....@@ -752,10 +743,7 @@ fn lowerTuple(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool.
752 }743 }
753 }744 }
754745
755 return self.sema.pt.intern(.{ .aggregate = .{746 return (try self.sema.pt.aggregateValue(res_ty, elems)).toIntern();
756 .ty = res_ty.toIntern(),
757 .storage = .{ .elems = elems },
758 } });
759}747}
760748
761fn lowerStruct(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool.Index {749fn lowerStruct(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool.Index {
...@@ -815,12 +803,7 @@ fn lowerStruct(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool...@@ -815,12 +803,7 @@ fn lowerStruct(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool
815 if (value.* == .none) return self.fail(node, "missing field '{f}'", .{name.fmt(ip)});803 if (value.* == .none) return self.fail(node, "missing field '{f}'", .{name.fmt(ip)});
816 }804 }
817805
818 return self.sema.pt.intern(.{ .aggregate = .{806 return (try self.sema.pt.aggregateValue(res_ty, field_values)).toIntern();
819 .ty = res_ty.toIntern(),
820 .storage = .{
821 .elems = field_values,
822 },
823 } });
824}807}
825808
826fn lowerSlice(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool.Index {809fn lowerSlice(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool.Index {
...@@ -867,16 +850,13 @@ fn lowerSlice(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool....@@ -867,16 +850,13 @@ fn lowerSlice(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool.
867 elems[elems.len - 1] = ptr_info.sentinel;850 elems[elems.len - 1] = ptr_info.sentinel;
868 }851 }
869852
870 const array_ty = try self.sema.pt.intern(.{ .array_type = .{853 const array_ty = try self.sema.pt.arrayType(.{
871 .len = elems.len,854 .len = elems.len,
872 .sentinel = ptr_info.sentinel,855 .sentinel = ptr_info.sentinel,
873 .child = ptr_info.child,856 .child = ptr_info.child,
874 } });857 });
875858
876 const array = try self.sema.pt.intern(.{ .aggregate = .{859 const array_val = try self.sema.pt.aggregateValue(array_ty, elems);
877 .ty = array_ty,
878 .storage = .{ .elems = elems },
879 } });
880860
881 const many_item_ptr_type = try self.sema.pt.intern(.{ .ptr_type = .{861 const many_item_ptr_type = try self.sema.pt.intern(.{ .ptr_type = .{
882 .child = ptr_info.child,862 .child = ptr_info.child,
...@@ -894,8 +874,8 @@ fn lowerSlice(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool....@@ -894,8 +874,8 @@ fn lowerSlice(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool.
894 .ty = many_item_ptr_type,874 .ty = many_item_ptr_type,
895 .base_addr = .{875 .base_addr = .{
896 .uav = .{876 .uav = .{
897 .orig_ty = (try self.sema.pt.singleConstPtrType(.fromInterned(array_ty))).toIntern(),877 .orig_ty = (try self.sema.pt.singleConstPtrType(array_ty)).toIntern(),
898 .val = array,878 .val = array_val.toIntern(),
899 },879 },
900 },880 },
901 .byte_offset = 0,881 .byte_offset = 0,
...@@ -994,8 +974,5 @@ fn lowerVector(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool...@@ -994,8 +974,5 @@ fn lowerVector(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool
994 elem.* = try self.lowerExprKnownResTy(elem_nodes.at(@intCast(i)), .fromInterned(vector_info.child));974 elem.* = try self.lowerExprKnownResTy(elem_nodes.at(@intCast(i)), .fromInterned(vector_info.child));
995 }975 }
996976
997 return self.sema.pt.intern(.{ .aggregate = .{977 return (try self.sema.pt.aggregateValue(res_ty, elems)).toIntern();
998 .ty = res_ty.toIntern(),
999 .storage = .{ .elems = elems },
1000 } });
1001}978}
src/Sema/arith.zig+10-30
...@@ -906,12 +906,7 @@ pub fn modRem(...@@ -906,12 +906,7 @@ pub fn modRem(
906 const rhs_elem = try rhs_val.elemValue(pt, elem_idx);906 const rhs_elem = try rhs_val.elemValue(pt, elem_idx);
907 result_elem.* = (try modRemScalar(sema, block, elem_ty, lhs_elem, rhs_elem, lhs_src, rhs_src, op, elem_idx)).toIntern();907 result_elem.* = (try modRemScalar(sema, block, elem_ty, lhs_elem, rhs_elem, lhs_src, rhs_src, op, elem_idx)).toIntern();
908 }908 }
909909 return pt.aggregateValue(ty, elem_vals);
910 const result_val = try pt.intern(.{ .aggregate = .{
911 .ty = ty.toIntern(),
912 .storage = .{ .elems = elem_vals },
913 } });
914 return .fromInterned(result_val);
915 },910 },
916 else => return modRemScalar(sema, block, ty, lhs_val, rhs_val, lhs_src, rhs_src, op, null),911 else => return modRemScalar(sema, block, ty, lhs_val, rhs_val, lhs_src, rhs_src, op, null),
917 }912 }
...@@ -1022,14 +1017,11 @@ pub fn shlWithOverflow(...@@ -1022,14 +1017,11 @@ pub fn shlWithOverflow(
1022 wr.* = elem_result.wrapped_result.toIntern();1017 wr.* = elem_result.wrapped_result.toIntern();
1023 }1018 }
1024 return .{1019 return .{
1025 .overflow_bit = .fromInterned(try pt.intern(.{ .aggregate = .{1020 .overflow_bit = try pt.aggregateValue(try pt.vectorType(.{
1026 .ty = (try pt.vectorType(.{ .len = @intCast(overflow_bits.len), .child = .u1_type })).toIntern(),1021 .len = @intCast(overflow_bits.len),
1027 .storage = .{ .elems = overflow_bits },1022 .child = .u1_type,
1028 } })),1023 }), overflow_bits),
1029 .wrapped_result = .fromInterned(try pt.intern(.{ .aggregate = .{1024 .wrapped_result = try pt.aggregateValue(lhs_ty, wrapped_results),
1030 .ty = lhs_ty.toIntern(),
1031 .storage = .{ .elems = wrapped_results },
1032 } })),
1033 };1025 };
1034 },1026 },
1035 else => unreachable,1027 else => unreachable,
...@@ -1222,10 +1214,7 @@ pub fn truncate(...@@ -1222,10 +1214,7 @@ pub fn truncate(
1222 dest_bits,1214 dest_bits,
1223 )).toIntern();1215 )).toIntern();
1224 }1216 }
1225 return .fromInterned(try pt.intern(.{ .aggregate = .{1217 return pt.aggregateValue(dest_ty, elem_vals);
1226 .ty = dest_ty.toIntern(),
1227 .storage = .{ .elems = elem_vals },
1228 } }));
1229 },1218 },
1230 else => unreachable,1219 else => unreachable,
1231 }1220 }
...@@ -1256,10 +1245,7 @@ pub fn bitwiseNot(sema: *Sema, ty: Type, val: Value) CompileError!Value {...@@ -1256,10 +1245,7 @@ pub fn bitwiseNot(sema: *Sema, ty: Type, val: Value) CompileError!Value {
1256 else1245 else
1257 (try intBitwiseNot(sema, elem_val, elem_ty)).toIntern();1246 (try intBitwiseNot(sema, elem_val, elem_ty)).toIntern();
1258 }1247 }
1259 return .fromInterned(try pt.intern(.{ .aggregate = .{1248 return pt.aggregateValue(ty, elem_vals);
1260 .ty = ty.toIntern(),
1261 .storage = .{ .elems = elem_vals },
1262 } }));
1263 },1249 },
1264 else => unreachable,1250 else => unreachable,
1265 }1251 }
...@@ -1357,10 +1343,7 @@ pub fn bitReverse(sema: *Sema, val: Value, ty: Type) CompileError!Value {...@@ -1357,10 +1343,7 @@ pub fn bitReverse(sema: *Sema, val: Value, ty: Type) CompileError!Value {
1357 else1343 else
1358 (try intBitReverse(sema, elem_val, elem_ty)).toIntern();1344 (try intBitReverse(sema, elem_val, elem_ty)).toIntern();
1359 }1345 }
1360 return .fromInterned(try pt.intern(.{ .aggregate = .{1346 return pt.aggregateValue(ty, elem_vals);
1361 .ty = ty.toIntern(),
1362 .storage = .{ .elems = elem_vals },
1363 } }));
1364 },1347 },
1365 else => unreachable,1348 else => unreachable,
1366 }1349 }
...@@ -1389,10 +1372,7 @@ pub fn byteSwap(sema: *Sema, val: Value, ty: Type) CompileError!Value {...@@ -1389,10 +1372,7 @@ pub fn byteSwap(sema: *Sema, val: Value, ty: Type) CompileError!Value {
1389 else1372 else
1390 (try intByteSwap(sema, elem_val, elem_ty)).toIntern();1373 (try intByteSwap(sema, elem_val, elem_ty)).toIntern();
1391 }1374 }
1392 return .fromInterned(try pt.intern(.{ .aggregate = .{1375 return pt.aggregateValue(ty, elem_vals);
1393 .ty = ty.toIntern(),
1394 .storage = .{ .elems = elem_vals },
1395 } }));
1396 },1376 },
1397 else => unreachable,1377 else => unreachable,
1398 }1378 }
src/Sema/comptime_ptr_access.zig+4-6
...@@ -980,13 +980,14 @@ fn unflattenArray(...@@ -980,13 +980,14 @@ fn unflattenArray(
980 elems: []const InternPool.Index,980 elems: []const InternPool.Index,
981 next_idx: *u64,981 next_idx: *u64,
982) Allocator.Error!Value {982) Allocator.Error!Value {
983 const zcu = sema.pt.zcu;983 const pt = sema.pt;
984 const zcu = pt.zcu;
984 const arena = sema.arena;985 const arena = sema.arena;
985986
986 if (ty.zigTypeTag(zcu) != .array) {987 if (ty.zigTypeTag(zcu) != .array) {
987 const val = Value.fromInterned(elems[@intCast(next_idx.*)]);988 const val = Value.fromInterned(elems[@intCast(next_idx.*)]);
988 next_idx.* += 1;989 next_idx.* += 1;
989 return sema.pt.getCoerced(val, ty);990 return pt.getCoerced(val, ty);
990 }991 }
991992
992 const elem_ty = ty.childType(zcu);993 const elem_ty = ty.childType(zcu);
...@@ -998,10 +999,7 @@ fn unflattenArray(...@@ -998,10 +999,7 @@ fn unflattenArray(
998 // TODO: validate sentinel999 // TODO: validate sentinel
999 _ = try unflattenArray(sema, elem_ty, elems, next_idx);1000 _ = try unflattenArray(sema, elem_ty, elems, next_idx);
1000 }1001 }
1001 return Value.fromInterned(try sema.pt.intern(.{ .aggregate = .{1002 return pt.aggregateValue(ty, buf);
1002 .ty = ty.toIntern(),
1003 .storage = .{ .elems = buf },
1004 } }));
1005}1003}
10061004
1007/// Given a `MutableValue` representing a potentially-nested array, treats `index` as an index into1005/// Given a `MutableValue` representing a potentially-nested array, treats `index` as an index into
src/Type.zig+8-24
...@@ -2490,15 +2490,11 @@ pub fn onePossibleValue(starting_type: Type, pt: Zcu.PerThread) !?Value {...@@ -2490,15 +2490,11 @@ pub fn onePossibleValue(starting_type: Type, pt: Zcu.PerThread) !?Value {
24902490
2491 inline .array_type, .vector_type => |seq_type, seq_tag| {2491 inline .array_type, .vector_type => |seq_type, seq_tag| {
2492 const has_sentinel = seq_tag == .array_type and seq_type.sentinel != .none;2492 const has_sentinel = seq_tag == .array_type and seq_type.sentinel != .none;
2493 if (seq_type.len + @intFromBool(has_sentinel) == 0) return Value.fromInterned(try pt.intern(.{ .aggregate = .{2493 if (seq_type.len + @intFromBool(has_sentinel) == 0) {
2494 .ty = ty.toIntern(),2494 return try pt.aggregateValue(ty, &.{});
2495 .storage = .{ .elems = &.{} },2495 }
2496 } }));
2497 if (try Type.fromInterned(seq_type.child).onePossibleValue(pt)) |opv| {2496 if (try Type.fromInterned(seq_type.child).onePossibleValue(pt)) |opv| {
2498 return Value.fromInterned(try pt.intern(.{ .aggregate = .{2497 return try pt.aggregateSplatValue(ty, opv);
2499 .ty = ty.toIntern(),
2500 .storage = .{ .repeated_elem = opv.toIntern() },
2501 } }));
2502 }2498 }
2503 return null;2499 return null;
2504 },2500 },
...@@ -2567,10 +2563,7 @@ pub fn onePossibleValue(starting_type: Type, pt: Zcu.PerThread) !?Value {...@@ -2567,10 +2563,7 @@ pub fn onePossibleValue(starting_type: Type, pt: Zcu.PerThread) !?Value {
25672563
2568 // In this case the struct has no runtime-known fields and2564 // In this case the struct has no runtime-known fields and
2569 // therefore has one possible value.2565 // therefore has one possible value.
2570 return Value.fromInterned(try pt.intern(.{ .aggregate = .{2566 return try pt.aggregateValue(ty, field_vals);
2571 .ty = ty.toIntern(),
2572 .storage = .{ .elems = field_vals },
2573 } }));
2574 },2567 },
25752568
2576 .tuple_type => |tuple| {2569 .tuple_type => |tuple| {
...@@ -2582,10 +2575,7 @@ pub fn onePossibleValue(starting_type: Type, pt: Zcu.PerThread) !?Value {...@@ -2582,10 +2575,7 @@ pub fn onePossibleValue(starting_type: Type, pt: Zcu.PerThread) !?Value {
2582 // TODO: write something like getCoercedInts to avoid needing to dupe2575 // TODO: write something like getCoercedInts to avoid needing to dupe
2583 const duped_values = try zcu.gpa.dupe(InternPool.Index, tuple.values.get(ip));2576 const duped_values = try zcu.gpa.dupe(InternPool.Index, tuple.values.get(ip));
2584 defer zcu.gpa.free(duped_values);2577 defer zcu.gpa.free(duped_values);
2585 return Value.fromInterned(try pt.intern(.{ .aggregate = .{2578 return try pt.aggregateValue(ty, duped_values);
2586 .ty = ty.toIntern(),
2587 .storage = .{ .elems = duped_values },
2588 } }));
2589 },2579 },
25902580
2591 .union_type => {2581 .union_type => {
...@@ -2957,10 +2947,7 @@ pub fn getParentNamespace(ty: Type, zcu: *Zcu) InternPool.OptionalNamespaceIndex...@@ -2957,10 +2947,7 @@ pub fn getParentNamespace(ty: Type, zcu: *Zcu) InternPool.OptionalNamespaceIndex
2957pub fn minInt(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {2947pub fn minInt(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {
2958 const zcu = pt.zcu;2948 const zcu = pt.zcu;
2959 const scalar = try minIntScalar(ty.scalarType(zcu), pt, dest_ty.scalarType(zcu));2949 const scalar = try minIntScalar(ty.scalarType(zcu), pt, dest_ty.scalarType(zcu));
2960 return if (ty.zigTypeTag(zcu) == .vector) Value.fromInterned(try pt.intern(.{ .aggregate = .{2950 return if (ty.zigTypeTag(zcu) == .vector) pt.aggregateSplatValue(dest_ty, scalar) else scalar;
2961 .ty = dest_ty.toIntern(),
2962 .storage = .{ .repeated_elem = scalar.toIntern() },
2963 } })) else scalar;
2964}2951}
29652952
2966/// Asserts that the type is an integer.2953/// Asserts that the type is an integer.
...@@ -2987,10 +2974,7 @@ pub fn minIntScalar(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {...@@ -2987,10 +2974,7 @@ pub fn minIntScalar(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {
2987pub fn maxInt(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {2974pub fn maxInt(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {
2988 const zcu = pt.zcu;2975 const zcu = pt.zcu;
2989 const scalar = try maxIntScalar(ty.scalarType(zcu), pt, dest_ty.scalarType(zcu));2976 const scalar = try maxIntScalar(ty.scalarType(zcu), pt, dest_ty.scalarType(zcu));
2990 return if (ty.zigTypeTag(zcu) == .vector) Value.fromInterned(try pt.intern(.{ .aggregate = .{2977 return if (ty.zigTypeTag(zcu) == .vector) pt.aggregateSplatValue(dest_ty, scalar) else scalar;
2991 .ty = dest_ty.toIntern(),
2992 .storage = .{ .repeated_elem = scalar.toIntern() },
2993 } })) else scalar;
2994}2978}
29952979
2996/// The returned Value will have type dest_ty.2980/// The returned Value will have type dest_ty.
src/Value.zig+26-77
...@@ -1586,10 +1586,7 @@ pub fn sqrt(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !...@@ -1586,10 +1586,7 @@ pub fn sqrt(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !
1586 const elem_val = try val.elemValue(pt, i);1586 const elem_val = try val.elemValue(pt, i);
1587 scalar.* = (try sqrtScalar(elem_val, scalar_ty, pt)).toIntern();1587 scalar.* = (try sqrtScalar(elem_val, scalar_ty, pt)).toIntern();
1588 }1588 }
1589 return Value.fromInterned(try pt.intern(.{ .aggregate = .{1589 return pt.aggregateValue(float_type, result_data);
1590 .ty = float_type.toIntern(),
1591 .storage = .{ .elems = result_data },
1592 } }));
1593 }1590 }
1594 return sqrtScalar(val, float_type, pt);1591 return sqrtScalar(val, float_type, pt);
1595}1592}
...@@ -1620,10 +1617,7 @@ pub fn sin(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !V...@@ -1620,10 +1617,7 @@ pub fn sin(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !V
1620 const elem_val = try val.elemValue(pt, i);1617 const elem_val = try val.elemValue(pt, i);
1621 scalar.* = (try sinScalar(elem_val, scalar_ty, pt)).toIntern();1618 scalar.* = (try sinScalar(elem_val, scalar_ty, pt)).toIntern();
1622 }1619 }
1623 return Value.fromInterned(try pt.intern(.{ .aggregate = .{1620 return pt.aggregateValue(float_type, result_data);
1624 .ty = float_type.toIntern(),
1625 .storage = .{ .elems = result_data },
1626 } }));
1627 }1621 }
1628 return sinScalar(val, float_type, pt);1622 return sinScalar(val, float_type, pt);
1629}1623}
...@@ -1654,10 +1648,7 @@ pub fn cos(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !V...@@ -1654,10 +1648,7 @@ pub fn cos(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !V
1654 const elem_val = try val.elemValue(pt, i);1648 const elem_val = try val.elemValue(pt, i);
1655 scalar.* = (try cosScalar(elem_val, scalar_ty, pt)).toIntern();1649 scalar.* = (try cosScalar(elem_val, scalar_ty, pt)).toIntern();
1656 }1650 }
1657 return Value.fromInterned(try pt.intern(.{ .aggregate = .{1651 return pt.aggregateValue(float_type, result_data);
1658 .ty = float_type.toIntern(),
1659 .storage = .{ .elems = result_data },
1660 } }));
1661 }1652 }
1662 return cosScalar(val, float_type, pt);1653 return cosScalar(val, float_type, pt);
1663}1654}
...@@ -1688,10 +1679,7 @@ pub fn tan(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !V...@@ -1688,10 +1679,7 @@ pub fn tan(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !V
1688 const elem_val = try val.elemValue(pt, i);1679 const elem_val = try val.elemValue(pt, i);
1689 scalar.* = (try tanScalar(elem_val, scalar_ty, pt)).toIntern();1680 scalar.* = (try tanScalar(elem_val, scalar_ty, pt)).toIntern();
1690 }1681 }
1691 return Value.fromInterned(try pt.intern(.{ .aggregate = .{1682 return pt.aggregateValue(float_type, result_data);
1692 .ty = float_type.toIntern(),
1693 .storage = .{ .elems = result_data },
1694 } }));
1695 }1683 }
1696 return tanScalar(val, float_type, pt);1684 return tanScalar(val, float_type, pt);
1697}1685}
...@@ -1722,10 +1710,7 @@ pub fn exp(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !V...@@ -1722,10 +1710,7 @@ pub fn exp(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !V
1722 const elem_val = try val.elemValue(pt, i);1710 const elem_val = try val.elemValue(pt, i);
1723 scalar.* = (try expScalar(elem_val, scalar_ty, pt)).toIntern();1711 scalar.* = (try expScalar(elem_val, scalar_ty, pt)).toIntern();
1724 }1712 }
1725 return Value.fromInterned(try pt.intern(.{ .aggregate = .{1713 return pt.aggregateValue(float_type, result_data);
1726 .ty = float_type.toIntern(),
1727 .storage = .{ .elems = result_data },
1728 } }));
1729 }1714 }
1730 return expScalar(val, float_type, pt);1715 return expScalar(val, float_type, pt);
1731}1716}
...@@ -1756,10 +1741,7 @@ pub fn exp2(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !...@@ -1756,10 +1741,7 @@ pub fn exp2(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !
1756 const elem_val = try val.elemValue(pt, i);1741 const elem_val = try val.elemValue(pt, i);
1757 scalar.* = (try exp2Scalar(elem_val, scalar_ty, pt)).toIntern();1742 scalar.* = (try exp2Scalar(elem_val, scalar_ty, pt)).toIntern();
1758 }1743 }
1759 return Value.fromInterned(try pt.intern(.{ .aggregate = .{1744 return pt.aggregateValue(float_type, result_data);
1760 .ty = float_type.toIntern(),
1761 .storage = .{ .elems = result_data },
1762 } }));
1763 }1745 }
1764 return exp2Scalar(val, float_type, pt);1746 return exp2Scalar(val, float_type, pt);
1765}1747}
...@@ -1790,10 +1772,7 @@ pub fn log(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !V...@@ -1790,10 +1772,7 @@ pub fn log(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !V
1790 const elem_val = try val.elemValue(pt, i);1772 const elem_val = try val.elemValue(pt, i);
1791 scalar.* = (try logScalar(elem_val, scalar_ty, pt)).toIntern();1773 scalar.* = (try logScalar(elem_val, scalar_ty, pt)).toIntern();
1792 }1774 }
1793 return Value.fromInterned(try pt.intern(.{ .aggregate = .{1775 return pt.aggregateValue(float_type, result_data);
1794 .ty = float_type.toIntern(),
1795 .storage = .{ .elems = result_data },
1796 } }));
1797 }1776 }
1798 return logScalar(val, float_type, pt);1777 return logScalar(val, float_type, pt);
1799}1778}
...@@ -1824,10 +1803,7 @@ pub fn log2(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !...@@ -1824,10 +1803,7 @@ pub fn log2(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !
1824 const elem_val = try val.elemValue(pt, i);1803 const elem_val = try val.elemValue(pt, i);
1825 scalar.* = (try log2Scalar(elem_val, scalar_ty, pt)).toIntern();1804 scalar.* = (try log2Scalar(elem_val, scalar_ty, pt)).toIntern();
1826 }1805 }
1827 return Value.fromInterned(try pt.intern(.{ .aggregate = .{1806 return pt.aggregateValue(float_type, result_data);
1828 .ty = float_type.toIntern(),
1829 .storage = .{ .elems = result_data },
1830 } }));
1831 }1807 }
1832 return log2Scalar(val, float_type, pt);1808 return log2Scalar(val, float_type, pt);
1833}1809}
...@@ -1858,10 +1834,7 @@ pub fn log10(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread)...@@ -1858,10 +1834,7 @@ pub fn log10(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread)
1858 const elem_val = try val.elemValue(pt, i);1834 const elem_val = try val.elemValue(pt, i);
1859 scalar.* = (try log10Scalar(elem_val, scalar_ty, pt)).toIntern();1835 scalar.* = (try log10Scalar(elem_val, scalar_ty, pt)).toIntern();
1860 }1836 }
1861 return Value.fromInterned(try pt.intern(.{ .aggregate = .{1837 return pt.aggregateValue(float_type, result_data);
1862 .ty = float_type.toIntern(),
1863 .storage = .{ .elems = result_data },
1864 } }));
1865 }1838 }
1866 return log10Scalar(val, float_type, pt);1839 return log10Scalar(val, float_type, pt);
1867}1840}
...@@ -1892,10 +1865,7 @@ pub fn abs(val: Value, ty: Type, arena: Allocator, pt: Zcu.PerThread) !Value {...@@ -1892,10 +1865,7 @@ pub fn abs(val: Value, ty: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
1892 const elem_val = try val.elemValue(pt, i);1865 const elem_val = try val.elemValue(pt, i);
1893 scalar.* = (try absScalar(elem_val, scalar_ty, pt, arena)).toIntern();1866 scalar.* = (try absScalar(elem_val, scalar_ty, pt, arena)).toIntern();
1894 }1867 }
1895 return Value.fromInterned(try pt.intern(.{ .aggregate = .{1868 return pt.aggregateValue(ty, result_data);
1896 .ty = ty.toIntern(),
1897 .storage = .{ .elems = result_data },
1898 } }));
1899 }1869 }
1900 return absScalar(val, ty, pt, arena);1870 return absScalar(val, ty, pt, arena);
1901}1871}
...@@ -1945,10 +1915,7 @@ pub fn floor(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread)...@@ -1945,10 +1915,7 @@ pub fn floor(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread)
1945 const elem_val = try val.elemValue(pt, i);1915 const elem_val = try val.elemValue(pt, i);
1946 scalar.* = (try floorScalar(elem_val, scalar_ty, pt)).toIntern();1916 scalar.* = (try floorScalar(elem_val, scalar_ty, pt)).toIntern();
1947 }1917 }
1948 return Value.fromInterned(try pt.intern(.{ .aggregate = .{1918 return pt.aggregateValue(float_type, result_data);
1949 .ty = float_type.toIntern(),
1950 .storage = .{ .elems = result_data },
1951 } }));
1952 }1919 }
1953 return floorScalar(val, float_type, pt);1920 return floorScalar(val, float_type, pt);
1954}1921}
...@@ -1979,10 +1946,7 @@ pub fn ceil(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !...@@ -1979,10 +1946,7 @@ pub fn ceil(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !
1979 const elem_val = try val.elemValue(pt, i);1946 const elem_val = try val.elemValue(pt, i);
1980 scalar.* = (try ceilScalar(elem_val, scalar_ty, pt)).toIntern();1947 scalar.* = (try ceilScalar(elem_val, scalar_ty, pt)).toIntern();
1981 }1948 }
1982 return Value.fromInterned(try pt.intern(.{ .aggregate = .{1949 return pt.aggregateValue(float_type, result_data);
1983 .ty = float_type.toIntern(),
1984 .storage = .{ .elems = result_data },
1985 } }));
1986 }1950 }
1987 return ceilScalar(val, float_type, pt);1951 return ceilScalar(val, float_type, pt);
1988}1952}
...@@ -2013,10 +1977,7 @@ pub fn round(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread)...@@ -2013,10 +1977,7 @@ pub fn round(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread)
2013 const elem_val = try val.elemValue(pt, i);1977 const elem_val = try val.elemValue(pt, i);
2014 scalar.* = (try roundScalar(elem_val, scalar_ty, pt)).toIntern();1978 scalar.* = (try roundScalar(elem_val, scalar_ty, pt)).toIntern();
2015 }1979 }
2016 return Value.fromInterned(try pt.intern(.{ .aggregate = .{1980 return pt.aggregateValue(float_type, result_data);
2017 .ty = float_type.toIntern(),
2018 .storage = .{ .elems = result_data },
2019 } }));
2020 }1981 }
2021 return roundScalar(val, float_type, pt);1982 return roundScalar(val, float_type, pt);
2022}1983}
...@@ -2047,10 +2008,7 @@ pub fn trunc(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread)...@@ -2047,10 +2008,7 @@ pub fn trunc(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread)
2047 const elem_val = try val.elemValue(pt, i);2008 const elem_val = try val.elemValue(pt, i);
2048 scalar.* = (try truncScalar(elem_val, scalar_ty, pt)).toIntern();2009 scalar.* = (try truncScalar(elem_val, scalar_ty, pt)).toIntern();
2049 }2010 }
2050 return Value.fromInterned(try pt.intern(.{ .aggregate = .{2011 return pt.aggregateValue(float_type, result_data);
2051 .ty = float_type.toIntern(),
2052 .storage = .{ .elems = result_data },
2053 } }));
2054 }2012 }
2055 return truncScalar(val, float_type, pt);2013 return truncScalar(val, float_type, pt);
2056}2014}
...@@ -2090,10 +2048,7 @@ pub fn mulAdd(...@@ -2090,10 +2048,7 @@ pub fn mulAdd(
2090 const addend_elem = try addend.elemValue(pt, i);2048 const addend_elem = try addend.elemValue(pt, i);
2091 scalar.* = (try mulAddScalar(scalar_ty, mulend1_elem, mulend2_elem, addend_elem, pt)).toIntern();2049 scalar.* = (try mulAddScalar(scalar_ty, mulend1_elem, mulend2_elem, addend_elem, pt)).toIntern();
2092 }2050 }
2093 return Value.fromInterned(try pt.intern(.{ .aggregate = .{2051 return pt.aggregateValue(float_type, result_data);
2094 .ty = float_type.toIntern(),
2095 .storage = .{ .elems = result_data },
2096 } }));
2097 }2052 }
2098 return mulAddScalar(float_type, mulend1, mulend2, addend, pt);2053 return mulAddScalar(float_type, mulend1, mulend2, addend, pt);
2099}2054}
...@@ -2978,17 +2933,17 @@ pub fn resolveLazy(...@@ -2978,17 +2933,17 @@ pub fn resolveLazy(
2978 }2933 }
2979 if (resolved_elems.len > 0) resolved_elems[i] = resolved_elem;2934 if (resolved_elems.len > 0) resolved_elems[i] = resolved_elem;
2980 }2935 }
2981 return if (resolved_elems.len == 0) val else Value.fromInterned(try pt.intern(.{ .aggregate = .{2936 return if (resolved_elems.len == 0)
2982 .ty = aggregate.ty,2937 val
2983 .storage = .{ .elems = resolved_elems },2938 else
2984 } }));2939 pt.aggregateValue(.fromInterned(aggregate.ty), resolved_elems);
2985 },2940 },
2986 .repeated_elem => |elem| {2941 .repeated_elem => |elem| {
2987 const resolved_elem = (try Value.fromInterned(elem).resolveLazy(arena, pt)).toIntern();2942 const resolved_elem = try Value.fromInterned(elem).resolveLazy(arena, pt);
2988 return if (resolved_elem == elem) val else Value.fromInterned(try pt.intern(.{ .aggregate = .{2943 return if (resolved_elem.toIntern() == elem)
2989 .ty = aggregate.ty,2944 val
2990 .storage = .{ .repeated_elem = resolved_elem },2945 else
2991 } }));2946 pt.aggregateSplatValue(.fromInterned(aggregate.ty), resolved_elem);
2992 },2947 },
2993 },2948 },
2994 .un => |un| {2949 .un => |un| {
...@@ -3205,10 +3160,7 @@ pub fn uninterpret(val: anytype, ty: Type, pt: Zcu.PerThread) error{ OutOfMemory...@@ -3205,10 +3160,7 @@ pub fn uninterpret(val: anytype, ty: Type, pt: Zcu.PerThread) error{ OutOfMemory
3205 const field_ty = ty.fieldType(field_idx, zcu);3160 const field_ty = ty.fieldType(field_idx, zcu);
3206 field_val.* = (try uninterpret(@field(val, field.name), field_ty, pt)).toIntern();3161 field_val.* = (try uninterpret(@field(val, field.name), field_ty, pt)).toIntern();
3207 }3162 }
3208 return .fromInterned(try pt.intern(.{ .aggregate = .{3163 return pt.aggregateValue(ty, &field_vals);
3209 .ty = ty.toIntern(),
3210 .storage = .{ .elems = &field_vals },
3211 } }));
3212 },3164 },
3213 .by_name => {3165 .by_name => {
3214 const struct_obj = zcu.typeToStruct(ty) orelse return error.TypeMismatch;3166 const struct_obj = zcu.typeToStruct(ty) orelse return error.TypeMismatch;
...@@ -3230,10 +3182,7 @@ pub fn uninterpret(val: anytype, ty: Type, pt: Zcu.PerThread) error{ OutOfMemory...@@ -3230,10 +3182,7 @@ pub fn uninterpret(val: anytype, ty: Type, pt: Zcu.PerThread) error{ OutOfMemory
3230 field_val.* = default_init;3182 field_val.* = default_init;
3231 }3183 }
3232 }3184 }
3233 return .fromInterned(try pt.intern(.{ .aggregate = .{3185 return pt.aggregateValue(ty, &field_vals);
3234 .ty = ty.toIntern(),
3235 .storage = .{ .elems = field_vals },
3236 } }));
3237 },3186 },
3238 },3187 },
3239 };3188 };
src/Zcu/PerThread.zig+5-12
...@@ -3327,10 +3327,7 @@ pub fn populateTestFunctions(pt: Zcu.PerThread) Allocator.Error!void {...@@ -3327,10 +3327,7 @@ pub fn populateTestFunctions(pt: Zcu.PerThread) Allocator.Error!void {
3327 .byte_offset = 0,3327 .byte_offset = 0,
3328 } }),3328 } }),
3329 };3329 };
3330 test_fn_val.* = try pt.intern(.{ .aggregate = .{3330 test_fn_val.* = (try pt.aggregateValue(test_fn_ty, &test_fn_fields)).toIntern();
3331 .ty = test_fn_ty.toIntern(),
3332 .storage = .{ .elems = &test_fn_fields },
3333 } });
3334 }3331 }
33353332
3336 const array_ty = try pt.arrayType(.{3333 const array_ty = try pt.arrayType(.{
...@@ -3338,13 +3335,9 @@ pub fn populateTestFunctions(pt: Zcu.PerThread) Allocator.Error!void {...@@ -3338,13 +3335,9 @@ pub fn populateTestFunctions(pt: Zcu.PerThread) Allocator.Error!void {
3338 .child = test_fn_ty.toIntern(),3335 .child = test_fn_ty.toIntern(),
3339 .sentinel = .none,3336 .sentinel = .none,
3340 });3337 });
3341 const array_val = try pt.intern(.{ .aggregate = .{
3342 .ty = array_ty.toIntern(),
3343 .storage = .{ .elems = test_fn_vals },
3344 } });
3345 break :array .{3338 break :array .{
3346 .orig_ty = (try pt.singleConstPtrType(array_ty)).toIntern(),3339 .orig_ty = (try pt.singleConstPtrType(array_ty)).toIntern(),
3347 .val = array_val,3340 .val = (try pt.aggregateValue(array_ty, test_fn_vals)).toIntern(),
3348 };3341 };
3349 };3342 };
33503343
...@@ -3685,15 +3678,15 @@ pub fn aggregateValue(pt: Zcu.PerThread, ty: Type, elems: []const InternPool.Ind...@@ -3685,15 +3678,15 @@ pub fn aggregateValue(pt: Zcu.PerThread, ty: Type, elems: []const InternPool.Ind
3685}3678}
36863679
3687/// Asserts that `ty` is either an array or a vector.3680/// Asserts that `ty` is either an array or a vector.
3688pub fn aggregateSplatValue(pt: Zcu.PerThread, ty: Type, repeated: Value) Allocator.Error!Value {3681pub fn aggregateSplatValue(pt: Zcu.PerThread, ty: Type, repeated_elem: Value) Allocator.Error!Value {
3689 switch (ty.zigTypeTag(pt.zcu)) {3682 switch (ty.zigTypeTag(pt.zcu)) {
3690 .array, .vector => {},3683 .array, .vector => {},
3691 else => unreachable,3684 else => unreachable,
3692 }3685 }
3693 if (repeated.isUndef(pt.zcu)) return pt.undefValue(ty);3686 if (repeated_elem.isUndef(pt.zcu)) return pt.undefValue(ty);
3694 return .fromInterned(try pt.intern(.{ .aggregate = .{3687 return .fromInterned(try pt.intern(.{ .aggregate = .{
3695 .ty = ty.toIntern(),3688 .ty = ty.toIntern(),
3696 .storage = .{ .repeated_elem = repeated.toIntern() },3689 .storage = .{ .repeated_elem = repeated_elem.toIntern() },
3697 } }));3690 } }));
3698}3691}
36993692