authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-10-15 20:22:38+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-10-19 19:21:17+01:00
log0b786059b5c2549acc8824857a5bdc3b13956272
treeb24f5733d98e93c286980748594f7e5d3d675a6c
parent2319d62f21e4cdcf4575d1512cb8058dd03fd6b4
signaturelock-open Commit is signed but in an unrecognized format.

compiler: avoid unreasonable eval branch quotas

Using `@FieldType` (#21702).

3 files changed, 11 insertions(+), 16 deletions(-)

src/InternPool.zig+3-4
......@@ -12243,7 +12243,7 @@ const PackedCallingConvention = packed struct(u18) {
1224312243 std.builtin.CallingConvention.RiscvInterruptOptions => .{
1224412244 .tag = tag,
1224512245 .incoming_stack_alignment = .fromByteUnits(pl.incoming_stack_alignment orelse 0),
12246 .extra = @intFromEnum(pl.level),
12246 .extra = @intFromEnum(pl.mode),
1224712247 },
1224812248 else => comptime unreachable,
1224912249 },
......@@ -12251,12 +12251,11 @@ const PackedCallingConvention = packed struct(u18) {
1225112251 }
1225212252
1225312253 fn unpack(cc: PackedCallingConvention) std.builtin.CallingConvention {
12254 @setEvalBranchQuota(400_000);
1225512254 return switch (cc.tag) {
1225612255 inline else => |tag| @unionInit(
1225712256 std.builtin.CallingConvention,
1225812257 @tagName(tag),
12259 switch (std.meta.FieldType(std.builtin.CallingConvention, tag)) {
12258 switch (@FieldType(std.builtin.CallingConvention, @tagName(tag))) {
1226012259 void => {},
1226112260 std.builtin.CallingConvention.CommonOptions => .{
1226212261 .incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(),
......@@ -12275,7 +12274,7 @@ const PackedCallingConvention = packed struct(u18) {
1227512274 },
1227612275 std.builtin.CallingConvention.RiscvInterruptOptions => .{
1227712276 .incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(),
12278 .level = @enumFromInt(cc.extra),
12277 .mode = @enumFromInt(cc.extra),
1227912278 },
1228012279 else => comptime unreachable,
1228112280 },
src/Sema.zig+1-1
......@@ -31348,7 +31348,7 @@ fn callconvCoerceAllowed(
3134831348 if (src_data.mode != dest_data.mode) return false;
3134931349 },
3135031350 std.builtin.CallingConvention.RiscvInterruptOptions => {
31351 if (src_data.level != dest_data.level) return false;
31351 if (src_data.mode != dest_data.mode) return false;
3135231352 },
3135331353 else => comptime unreachable,
3135431354 }
src/Value.zig+7-11
......@@ -4495,8 +4495,6 @@ pub fn resolveLazy(
44954495/// This is useful for accessing `std.builtin` structures received from comptime logic.
44964496/// `val` must be fully resolved.
44974497pub fn interpret(val: Value, comptime T: type, pt: Zcu.PerThread) error{ OutOfMemory, UndefinedValue, TypeMismatch }!T {
4498 @setEvalBranchQuota(400_000);
4499
45004498 const zcu = pt.zcu;
45014499 const ip = &zcu.intern_pool;
45024500 const ty = val.typeOf(zcu);
......@@ -4552,13 +4550,13 @@ pub fn interpret(val: Value, comptime T: type, pt: Zcu.PerThread) error{ OutOfMe
45524550 if (union_obj.field_types.len != @"union".fields.len) return error.TypeMismatch;
45534551 const tag_val = val.unionTag(zcu) orelse return error.TypeMismatch;
45544552 const tag = try tag_val.interpret(@"union".tag_type.?, pt);
4555 switch (tag) {
4556 inline else => |tag_comptime| {
4557 const Payload = std.meta.FieldType(T, tag_comptime);
4558 const payload = try val.unionValue(zcu).interpret(Payload, pt);
4559 return @unionInit(T, @tagName(tag_comptime), payload);
4560 },
4561 }
4553 return switch (tag) {
4554 inline else => |tag_comptime| @unionInit(
4555 T,
4556 @tagName(tag_comptime),
4557 try val.unionValue(zcu).interpret(@FieldType(T, @tagName(tag_comptime)), pt),
4558 ),
4559 };
45624560 },
45634561
45644562 .@"struct" => |@"struct"| {
......@@ -4577,8 +4575,6 @@ pub fn interpret(val: Value, comptime T: type, pt: Zcu.PerThread) error{ OutOfMe
45774575/// within the compilation. This is useful for passing `std.builtin` structures in the compiler back to the compilation.
45784576/// This is the inverse of `interpret`.
45794577pub fn uninterpret(val: anytype, ty: Type, pt: Zcu.PerThread) error{ OutOfMemory, TypeMismatch }!Value {
4580 @setEvalBranchQuota(400_000);
4581
45824578 const T = @TypeOf(val);
45834579
45844580 const zcu = pt.zcu;