authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-22 23:18:47-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-07-22 23:18:47-07:00
log1bf16b1723445ba307ca556dc050d6d13bb0ebff
tree88c1eddc872ff02e0e3d0ac0a2b93a0a66a602c1
parent1ae839cd248c9eee8a9ff0643d7b80628f5f5533
parentc804abc7f6948a14e806104dd5ded6cabc5665be
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #16495 from ziglang/bun

fix recent compiler regressions found when compiling bun

3 files changed, 67 insertions(+), 34 deletions(-)

src/Sema.zig+63-31
...@@ -30706,6 +30706,41 @@ fn analyzeIsNonErrComptimeOnly(...@@ -30706,6 +30706,41 @@ fn analyzeIsNonErrComptimeOnly(
30706 const set_ty = ip.errorUnionSet(operand_ty.toIntern());30706 const set_ty = ip.errorUnionSet(operand_ty.toIntern());
30707 switch (set_ty) {30707 switch (set_ty) {
30708 .anyerror_type => {},30708 .anyerror_type => {},
30709 .adhoc_inferred_error_set_type => if (sema.fn_ret_ty_ies) |ies| blk: {
30710 // If the error set is empty, we must return a comptime true or false.
30711 // However we want to avoid unnecessarily resolving an inferred error set
30712 // in case it is already non-empty.
30713 switch (ies.resolved) {
30714 .anyerror_type => break :blk,
30715 .none => {},
30716 else => |i| if (ip.indexToKey(i).error_set_type.names.len != 0) break :blk,
30717 }
30718
30719 if (maybe_operand_val != null) break :blk;
30720
30721 // Try to avoid resolving inferred error set if possible.
30722 if (ies.errors.count() != 0) return .none;
30723 switch (ies.resolved) {
30724 .anyerror_type => return .none,
30725 .none => {},
30726 else => switch (ip.indexToKey(ies.resolved).error_set_type.names.len) {
30727 0 => return .bool_true,
30728 else => return .none,
30729 },
30730 }
30731 for (ies.inferred_error_sets.keys()) |other_ies_index| {
30732 if (set_ty == other_ies_index) continue;
30733 const other_resolved =
30734 try sema.resolveInferredErrorSet(block, src, other_ies_index);
30735 if (other_resolved == .anyerror_type) {
30736 ies.resolved = .anyerror_type;
30737 return .none;
30738 }
30739 if (ip.indexToKey(other_resolved).error_set_type.names.len != 0)
30740 return .none;
30741 }
30742 return .bool_true;
30743 },
30709 else => switch (ip.indexToKey(set_ty)) {30744 else => switch (ip.indexToKey(set_ty)) {
30710 .error_set_type => |error_set_type| {30745 .error_set_type => |error_set_type| {
30711 if (error_set_type.names.len == 0) return .bool_true;30746 if (error_set_type.names.len == 0) return .bool_true;
...@@ -30719,41 +30754,38 @@ fn analyzeIsNonErrComptimeOnly(...@@ -30719,41 +30754,38 @@ fn analyzeIsNonErrComptimeOnly(
30719 .none => {},30754 .none => {},
30720 else => |i| if (ip.indexToKey(i).error_set_type.names.len != 0) break :blk,30755 else => |i| if (ip.indexToKey(i).error_set_type.names.len != 0) break :blk,
30721 }30756 }
30722 if (maybe_operand_val == null) {30757 if (maybe_operand_val != null) break :blk;
30723 if (sema.fn_ret_ty_ies) |ies| {30758 if (sema.fn_ret_ty_ies) |ies| {
30724 if (set_ty == .adhoc_inferred_error_set_type or30759 if (ies.func == func_index) {
30725 ies.func == func_index)30760 // Try to avoid resolving inferred error set if possible.
30726 {30761 if (ies.errors.count() != 0) return .none;
30727 // Try to avoid resolving inferred error set if possible.30762 switch (ies.resolved) {
30728 if (ies.errors.count() != 0) return .none;30763 .anyerror_type => return .none,
30729 switch (ies.resolved) {30764 .none => {},
30730 .anyerror_type => return .none,30765 else => switch (ip.indexToKey(ies.resolved).error_set_type.names.len) {
30731 .none => {},30766 0 => return .bool_true,
30732 else => switch (ip.indexToKey(ies.resolved).error_set_type.names.len) {30767 else => return .none,
30733 0 => return .bool_true,30768 },
30734 else => return .none,30769 }
30735 },30770 for (ies.inferred_error_sets.keys()) |other_ies_index| {
30736 }30771 if (set_ty == other_ies_index) continue;
30737 for (ies.inferred_error_sets.keys()) |other_ies_index| {30772 const other_resolved =
30738 if (set_ty == other_ies_index) continue;30773 try sema.resolveInferredErrorSet(block, src, other_ies_index);
30739 const other_resolved =30774 if (other_resolved == .anyerror_type) {
30740 try sema.resolveInferredErrorSet(block, src, other_ies_index);30775 ies.resolved = .anyerror_type;
30741 if (other_resolved == .anyerror_type) {30776 return .none;
30742 ies.resolved = .anyerror_type;
30743 return .none;
30744 }
30745 if (ip.indexToKey(other_resolved).error_set_type.names.len != 0)
30746 return .none;
30747 }30777 }
30748 return .bool_true;30778 if (ip.indexToKey(other_resolved).error_set_type.names.len != 0)
30779 return .none;
30749 }30780 }
30750 }
30751 const resolved_ty = try sema.resolveInferredErrorSet(block, src, set_ty);
30752 if (resolved_ty == .anyerror_type)
30753 break :blk;
30754 if (ip.indexToKey(resolved_ty).error_set_type.names.len == 0)
30755 return .bool_true;30781 return .bool_true;
30782 }
30756 }30783 }
30784 const resolved_ty = try sema.resolveInferredErrorSet(block, src, set_ty);
30785 if (resolved_ty == .anyerror_type)
30786 break :blk;
30787 if (ip.indexToKey(resolved_ty).error_set_type.names.len == 0)
30788 return .bool_true;
30757 },30789 },
30758 else => unreachable,30790 else => unreachable,
30759 },30791 },
src/type.zig+2-1
...@@ -2065,7 +2065,7 @@ pub const Type = struct {...@@ -2065,7 +2065,7 @@ pub const Type = struct {
2065 pub fn errorSetIsEmpty(ty: Type, mod: *Module) bool {2065 pub fn errorSetIsEmpty(ty: Type, mod: *Module) bool {
2066 const ip = &mod.intern_pool;2066 const ip = &mod.intern_pool;
2067 return switch (ty.toIntern()) {2067 return switch (ty.toIntern()) {
2068 .anyerror_type => false,2068 .anyerror_type, .adhoc_inferred_error_set_type => false,
2069 else => switch (ip.indexToKey(ty.toIntern())) {2069 else => switch (ip.indexToKey(ty.toIntern())) {
2070 .error_set_type => |error_set_type| error_set_type.names.len == 0,2070 .error_set_type => |error_set_type| error_set_type.names.len == 0,
2071 .inferred_error_set_type => |i| switch (ip.funcIesResolved(i).*) {2071 .inferred_error_set_type => |i| switch (ip.funcIesResolved(i).*) {
...@@ -2084,6 +2084,7 @@ pub const Type = struct {...@@ -2084,6 +2084,7 @@ pub const Type = struct {
2084 const ip = &mod.intern_pool;2084 const ip = &mod.intern_pool;
2085 return switch (ty.toIntern()) {2085 return switch (ty.toIntern()) {
2086 .anyerror_type => true,2086 .anyerror_type => true,
2087 .adhoc_inferred_error_set_type => false,
2087 else => switch (mod.intern_pool.indexToKey(ty.toIntern())) {2088 else => switch (mod.intern_pool.indexToKey(ty.toIntern())) {
2088 .inferred_error_set_type => |i| ip.funcIesResolved(i).* == .anyerror_type,2089 .inferred_error_set_type => |i| ip.funcIesResolved(i).* == .anyerror_type,
2089 else => false,2090 else => false,
src/value.zig+2-2
...@@ -483,10 +483,10 @@ pub const Value = struct {...@@ -483,10 +483,10 @@ pub const Value = struct {
483 }483 }
484484
485 pub fn getFunction(val: Value, mod: *Module) ?InternPool.Key.Func {485 pub fn getFunction(val: Value, mod: *Module) ?InternPool.Key.Func {
486 return switch (mod.intern_pool.indexToKey(val.toIntern())) {486 return if (val.ip_index != .none) switch (mod.intern_pool.indexToKey(val.toIntern())) {
487 .func => |x| x,487 .func => |x| x,
488 else => null,488 else => null,
489 };489 } else null;
490 }490 }
491491
492 pub fn getExternFunc(val: Value, mod: *Module) ?InternPool.Key.ExternFunc {492 pub fn getExternFunc(val: Value, mod: *Module) ?InternPool.Key.ExternFunc {