mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 02:44:43 +01:00
compiler: avoid unreasonable eval branch quotas
Using `@FieldType` (#21702).
This commit is contained in:
parent
2319d62f21
commit
0b786059b5
3 changed files with 11 additions and 16 deletions
|
|
@ -12243,7 +12243,7 @@ const PackedCallingConvention = packed struct(u18) {
|
|||
std.builtin.CallingConvention.RiscvInterruptOptions => .{
|
||||
.tag = tag,
|
||||
.incoming_stack_alignment = .fromByteUnits(pl.incoming_stack_alignment orelse 0),
|
||||
.extra = @intFromEnum(pl.level),
|
||||
.extra = @intFromEnum(pl.mode),
|
||||
},
|
||||
else => comptime unreachable,
|
||||
},
|
||||
|
|
@ -12251,12 +12251,11 @@ const PackedCallingConvention = packed struct(u18) {
|
|||
}
|
||||
|
||||
fn unpack(cc: PackedCallingConvention) std.builtin.CallingConvention {
|
||||
@setEvalBranchQuota(400_000);
|
||||
return switch (cc.tag) {
|
||||
inline else => |tag| @unionInit(
|
||||
std.builtin.CallingConvention,
|
||||
@tagName(tag),
|
||||
switch (std.meta.FieldType(std.builtin.CallingConvention, tag)) {
|
||||
switch (@FieldType(std.builtin.CallingConvention, @tagName(tag))) {
|
||||
void => {},
|
||||
std.builtin.CallingConvention.CommonOptions => .{
|
||||
.incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(),
|
||||
|
|
@ -12275,7 +12274,7 @@ const PackedCallingConvention = packed struct(u18) {
|
|||
},
|
||||
std.builtin.CallingConvention.RiscvInterruptOptions => .{
|
||||
.incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(),
|
||||
.level = @enumFromInt(cc.extra),
|
||||
.mode = @enumFromInt(cc.extra),
|
||||
},
|
||||
else => comptime unreachable,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -31348,7 +31348,7 @@ fn callconvCoerceAllowed(
|
|||
if (src_data.mode != dest_data.mode) return false;
|
||||
},
|
||||
std.builtin.CallingConvention.RiscvInterruptOptions => {
|
||||
if (src_data.level != dest_data.level) return false;
|
||||
if (src_data.mode != dest_data.mode) return false;
|
||||
},
|
||||
else => comptime unreachable,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4495,8 +4495,6 @@ pub fn resolveLazy(
|
|||
/// This is useful for accessing `std.builtin` structures received from comptime logic.
|
||||
/// `val` must be fully resolved.
|
||||
pub fn interpret(val: Value, comptime T: type, pt: Zcu.PerThread) error{ OutOfMemory, UndefinedValue, TypeMismatch }!T {
|
||||
@setEvalBranchQuota(400_000);
|
||||
|
||||
const zcu = pt.zcu;
|
||||
const ip = &zcu.intern_pool;
|
||||
const ty = val.typeOf(zcu);
|
||||
|
|
@ -4552,13 +4550,13 @@ pub fn interpret(val: Value, comptime T: type, pt: Zcu.PerThread) error{ OutOfMe
|
|||
if (union_obj.field_types.len != @"union".fields.len) return error.TypeMismatch;
|
||||
const tag_val = val.unionTag(zcu) orelse return error.TypeMismatch;
|
||||
const tag = try tag_val.interpret(@"union".tag_type.?, pt);
|
||||
switch (tag) {
|
||||
inline else => |tag_comptime| {
|
||||
const Payload = std.meta.FieldType(T, tag_comptime);
|
||||
const payload = try val.unionValue(zcu).interpret(Payload, pt);
|
||||
return @unionInit(T, @tagName(tag_comptime), payload);
|
||||
},
|
||||
}
|
||||
return switch (tag) {
|
||||
inline else => |tag_comptime| @unionInit(
|
||||
T,
|
||||
@tagName(tag_comptime),
|
||||
try val.unionValue(zcu).interpret(@FieldType(T, @tagName(tag_comptime)), pt),
|
||||
),
|
||||
};
|
||||
},
|
||||
|
||||
.@"struct" => |@"struct"| {
|
||||
|
|
@ -4577,8 +4575,6 @@ pub fn interpret(val: Value, comptime T: type, pt: Zcu.PerThread) error{ OutOfMe
|
|||
/// within the compilation. This is useful for passing `std.builtin` structures in the compiler back to the compilation.
|
||||
/// This is the inverse of `interpret`.
|
||||
pub fn uninterpret(val: anytype, ty: Type, pt: Zcu.PerThread) error{ OutOfMemory, TypeMismatch }!Value {
|
||||
@setEvalBranchQuota(400_000);
|
||||
|
||||
const T = @TypeOf(val);
|
||||
|
||||
const zcu = pt.zcu;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue