Merge pull request #16495 from ziglang/bun

fix recent compiler regressions found when compiling bun
This commit is contained in:
Andrew Kelley 2023-07-22 23:18:47 -07:00 committed by GitHub
commit 1bf16b1723
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 68 additions and 35 deletions

View file

@ -30706,6 +30706,41 @@ fn analyzeIsNonErrComptimeOnly(
const set_ty = ip.errorUnionSet(operand_ty.toIntern()); const set_ty = ip.errorUnionSet(operand_ty.toIntern());
switch (set_ty) { switch (set_ty) {
.anyerror_type => {}, .anyerror_type => {},
.adhoc_inferred_error_set_type => if (sema.fn_ret_ty_ies) |ies| blk: {
// If the error set is empty, we must return a comptime true or false.
// However we want to avoid unnecessarily resolving an inferred error set
// in case it is already non-empty.
switch (ies.resolved) {
.anyerror_type => break :blk,
.none => {},
else => |i| if (ip.indexToKey(i).error_set_type.names.len != 0) break :blk,
}
if (maybe_operand_val != null) break :blk;
// Try to avoid resolving inferred error set if possible.
if (ies.errors.count() != 0) return .none;
switch (ies.resolved) {
.anyerror_type => return .none,
.none => {},
else => switch (ip.indexToKey(ies.resolved).error_set_type.names.len) {
0 => return .bool_true,
else => return .none,
},
}
for (ies.inferred_error_sets.keys()) |other_ies_index| {
if (set_ty == other_ies_index) continue;
const other_resolved =
try sema.resolveInferredErrorSet(block, src, other_ies_index);
if (other_resolved == .anyerror_type) {
ies.resolved = .anyerror_type;
return .none;
}
if (ip.indexToKey(other_resolved).error_set_type.names.len != 0)
return .none;
}
return .bool_true;
},
else => switch (ip.indexToKey(set_ty)) { else => switch (ip.indexToKey(set_ty)) {
.error_set_type => |error_set_type| { .error_set_type => |error_set_type| {
if (error_set_type.names.len == 0) return .bool_true; if (error_set_type.names.len == 0) return .bool_true;
@ -30719,41 +30754,38 @@ fn analyzeIsNonErrComptimeOnly(
.none => {}, .none => {},
else => |i| if (ip.indexToKey(i).error_set_type.names.len != 0) break :blk, else => |i| if (ip.indexToKey(i).error_set_type.names.len != 0) break :blk,
} }
if (maybe_operand_val == null) { if (maybe_operand_val != null) break :blk;
if (sema.fn_ret_ty_ies) |ies| { if (sema.fn_ret_ty_ies) |ies| {
if (set_ty == .adhoc_inferred_error_set_type or if (ies.func == func_index) {
ies.func == func_index) // Try to avoid resolving inferred error set if possible.
{ if (ies.errors.count() != 0) return .none;
// Try to avoid resolving inferred error set if possible. switch (ies.resolved) {
if (ies.errors.count() != 0) return .none; .anyerror_type => return .none,
switch (ies.resolved) { .none => {},
.anyerror_type => return .none, else => switch (ip.indexToKey(ies.resolved).error_set_type.names.len) {
.none => {}, 0 => return .bool_true,
else => switch (ip.indexToKey(ies.resolved).error_set_type.names.len) { else => return .none,
0 => return .bool_true, },
else => return .none, }
}, for (ies.inferred_error_sets.keys()) |other_ies_index| {
} if (set_ty == other_ies_index) continue;
for (ies.inferred_error_sets.keys()) |other_ies_index| { const other_resolved =
if (set_ty == other_ies_index) continue; try sema.resolveInferredErrorSet(block, src, other_ies_index);
const other_resolved = if (other_resolved == .anyerror_type) {
try sema.resolveInferredErrorSet(block, src, other_ies_index); ies.resolved = .anyerror_type;
if (other_resolved == .anyerror_type) { return .none;
ies.resolved = .anyerror_type; }
return .none; if (ip.indexToKey(other_resolved).error_set_type.names.len != 0)
} return .none;
if (ip.indexToKey(other_resolved).error_set_type.names.len != 0)
return .none;
}
return .bool_true;
} }
}
const resolved_ty = try sema.resolveInferredErrorSet(block, src, set_ty);
if (resolved_ty == .anyerror_type)
break :blk;
if (ip.indexToKey(resolved_ty).error_set_type.names.len == 0)
return .bool_true; return .bool_true;
}
} }
const resolved_ty = try sema.resolveInferredErrorSet(block, src, set_ty);
if (resolved_ty == .anyerror_type)
break :blk;
if (ip.indexToKey(resolved_ty).error_set_type.names.len == 0)
return .bool_true;
}, },
else => unreachable, else => unreachable,
}, },

View file

@ -2065,7 +2065,7 @@ pub const Type = struct {
pub fn errorSetIsEmpty(ty: Type, mod: *Module) bool { pub fn errorSetIsEmpty(ty: Type, mod: *Module) bool {
const ip = &mod.intern_pool; const ip = &mod.intern_pool;
return switch (ty.toIntern()) { return switch (ty.toIntern()) {
.anyerror_type => false, .anyerror_type, .adhoc_inferred_error_set_type => false,
else => switch (ip.indexToKey(ty.toIntern())) { else => switch (ip.indexToKey(ty.toIntern())) {
.error_set_type => |error_set_type| error_set_type.names.len == 0, .error_set_type => |error_set_type| error_set_type.names.len == 0,
.inferred_error_set_type => |i| switch (ip.funcIesResolved(i).*) { .inferred_error_set_type => |i| switch (ip.funcIesResolved(i).*) {
@ -2084,6 +2084,7 @@ pub const Type = struct {
const ip = &mod.intern_pool; const ip = &mod.intern_pool;
return switch (ty.toIntern()) { return switch (ty.toIntern()) {
.anyerror_type => true, .anyerror_type => true,
.adhoc_inferred_error_set_type => false,
else => switch (mod.intern_pool.indexToKey(ty.toIntern())) { else => switch (mod.intern_pool.indexToKey(ty.toIntern())) {
.inferred_error_set_type => |i| ip.funcIesResolved(i).* == .anyerror_type, .inferred_error_set_type => |i| ip.funcIesResolved(i).* == .anyerror_type,
else => false, else => false,

View file

@ -483,10 +483,10 @@ pub const Value = struct {
} }
pub fn getFunction(val: Value, mod: *Module) ?InternPool.Key.Func { pub fn getFunction(val: Value, mod: *Module) ?InternPool.Key.Func {
return switch (mod.intern_pool.indexToKey(val.toIntern())) { return if (val.ip_index != .none) switch (mod.intern_pool.indexToKey(val.toIntern())) {
.func => |x| x, .func => |x| x,
else => null, else => null,
}; } else null;
} }
pub fn getExternFunc(val: Value, mod: *Module) ?InternPool.Key.ExternFunc { pub fn getExternFunc(val: Value, mod: *Module) ?InternPool.Key.ExternFunc {