aboutsummaryrefslogtreecommitdiff
path: root/src/Zcu/PerThread.zig
diff options
context:
space:
mode:
authorMatthew Lugg <mlugg@mlugg.co.uk>2025-11-12 23:14:02 +0000
committerGitHub <noreply@github.com>2025-11-12 23:14:02 +0000
commit181b25ce4fcebc32f6fdc7498148c0f5e131dda9 (patch)
treef5cfe981b1b158e8bac17cc3a3bc909ffb7b1aa1 /src/Zcu/PerThread.zig
parentdfd7b7f2337d84ce660253a37079489f7780b055 (diff)
parent532aa3c5758f110eb7cf0992eb394088ab563899 (diff)
downloadzig-181b25ce4fcebc32f6fdc7498148c0f5e131dda9.tar.gz
zig-181b25ce4fcebc32f6fdc7498148c0f5e131dda9.zip
Merge pull request #25772 from mlugg/kill-dead-code
compiler: rewrite some legalizations, and remove a bunch of dead code
Diffstat (limited to 'src/Zcu/PerThread.zig')
-rw-r--r--src/Zcu/PerThread.zig26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/Zcu/PerThread.zig b/src/Zcu/PerThread.zig
index 20aaa3d3c2..41b5a32f6e 100644
--- a/src/Zcu/PerThread.zig
+++ b/src/Zcu/PerThread.zig
@@ -3512,7 +3512,6 @@ pub fn ptrType(pt: Zcu.PerThread, info: InternPool.Key.PtrType) Allocator.Error!
canon_info.packed_offset.host_size = 0;
}
},
- .runtime => {},
_ => assert(@intFromEnum(info.flags.vector_index) < info.packed_offset.host_size),
}
@@ -3663,21 +3662,40 @@ pub fn intRef(pt: Zcu.PerThread, ty: Type, x: anytype) Allocator.Error!Air.Inst.
}
pub fn intValue_big(pt: Zcu.PerThread, ty: Type, x: BigIntConst) Allocator.Error!Value {
- return Value.fromInterned(try pt.intern(.{ .int = .{
+ if (ty.toIntern() != .comptime_int_type) {
+ const int_info = ty.intInfo(pt.zcu);
+ assert(x.fitsInTwosComp(int_info.signedness, int_info.bits));
+ }
+ return .fromInterned(try pt.intern(.{ .int = .{
.ty = ty.toIntern(),
.storage = .{ .big_int = x },
} }));
}
pub fn intValue_u64(pt: Zcu.PerThread, ty: Type, x: u64) Allocator.Error!Value {
- return Value.fromInterned(try pt.intern(.{ .int = .{
+ if (ty.toIntern() != .comptime_int_type and x != 0) {
+ const int_info = ty.intInfo(pt.zcu);
+ const unsigned_bits = int_info.bits - @intFromBool(int_info.signedness == .signed);
+ assert(unsigned_bits >= std.math.log2(x) + 1);
+ }
+ return .fromInterned(try pt.intern(.{ .int = .{
.ty = ty.toIntern(),
.storage = .{ .u64 = x },
} }));
}
pub fn intValue_i64(pt: Zcu.PerThread, ty: Type, x: i64) Allocator.Error!Value {
- return Value.fromInterned(try pt.intern(.{ .int = .{
+ if (ty.toIntern() != .comptime_int_type and x != 0) {
+ const int_info = ty.intInfo(pt.zcu);
+ const unsigned_bits = int_info.bits - @intFromBool(int_info.signedness == .signed);
+ if (x > 0) {
+ assert(unsigned_bits >= std.math.log2(x) + 1);
+ } else {
+ assert(int_info.signedness == .signed);
+ assert(unsigned_bits >= std.math.log2_int_ceil(u64, @abs(x)));
+ }
+ }
+ return .fromInterned(try pt.intern(.{ .int = .{
.ty = ty.toIntern(),
.storage = .{ .i64 = x },
} }));