aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-05-07 12:53:14 -0700
committerAndrew Kelley <andrew@ziglang.org>2023-06-10 20:42:29 -0700
commit4c3c605e5f53c91430efac821ce1b863cbb5bf06 (patch)
tree14ec529e00b720650b3531c6defa9fc3c03e73f0 /src/Sema.zig
parentc1ca16d779a3f3201a5a35a88eff188290b2091a (diff)
downloadzig-4c3c605e5f53c91430efac821ce1b863cbb5bf06.tar.gz
zig-4c3c605e5f53c91430efac821ce1b863cbb5bf06.zip
InternPool: add getCoercedInt to avoid copy in Sema
Diffstat (limited to 'src/Sema.zig')
-rw-r--r--src/Sema.zig15
1 files changed, 1 insertions, 14 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index e92c626691..dc5bb1cdea 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -25957,20 +25957,7 @@ fn coerceExtra(
if (!opts.report_err) return error.NotCoercible;
return sema.fail(block, inst_src, "type '{}' cannot represent integer value '{}'", .{ dest_ty.fmt(sema.mod), val.fmtValue(inst_ty, sema.mod) });
}
- const key = mod.intern_pool.indexToKey(val.ip_index);
- // If the int is represented as a bigint, copy it so we can safely pass it to `mod.intern`
- const int_storage: InternPool.Key.Int.Storage = switch (key.int.storage) {
- .u64 => |x| .{ .u64 = x },
- .i64 => |x| .{ .i64 = x },
- .big_int => |big_int| .{ .big_int = .{
- .limbs = try sema.arena.dupe(std.math.big.Limb, big_int.limbs),
- .positive = big_int.positive,
- } },
- };
- const new_val = try mod.intern(.{ .int = .{
- .ty = dest_ty.ip_index,
- .storage = int_storage,
- } });
+ const new_val = try mod.intern_pool.getCoercedInt(sema.gpa, val.ip_index, dest_ty.ip_index);
return try sema.addConstant(dest_ty, new_val.toValue());
}
if (dest_ty.zigTypeTag(mod) == .ComptimeInt) {