From f8cf708753bdc494c4ec5c6e64f0da8cd2783895 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Thu, 3 Jul 2025 18:13:23 -0400 Subject: [PATCH 1/2] RequirementMachine: Increase default type differences limit to 13000 Fixes rdar://154684522. --- include/swift/Basic/LangOptions.h | 2 +- test/Generics/infinite_concrete_type.swift | 39 ++++++++++++++++++- .../{non_confluent.swift => non_fcrs.swift} | 33 ---------------- test/Generics/rdar90402519.swift | 4 +- 4 files changed, 41 insertions(+), 37 deletions(-) rename test/Generics/{non_confluent.swift => non_fcrs.swift} (78%) diff --git a/include/swift/Basic/LangOptions.h b/include/swift/Basic/LangOptions.h index f1896d42383f7..34122f38225be 100644 --- a/include/swift/Basic/LangOptions.h +++ b/include/swift/Basic/LangOptions.h @@ -590,7 +590,7 @@ namespace swift { /// Maximum number of "type difference" structures for the requirement machine /// property map algorithm. - unsigned RequirementMachineMaxTypeDifferences = 4000; + unsigned RequirementMachineMaxTypeDifferences = 13000; /// Maximum number of attempts to make when splitting concrete equivalence /// classes. diff --git a/test/Generics/infinite_concrete_type.swift b/test/Generics/infinite_concrete_type.swift index 02c22b2cf20d6..02b271fb02ff1 100644 --- a/test/Generics/infinite_concrete_type.swift +++ b/test/Generics/infinite_concrete_type.swift @@ -3,7 +3,7 @@ class G {} protocol P1 { // expected-error {{cannot build rewrite system for protocol; concrete type difference limit exceeded}} -// expected-note@-1 {{failed rewrite rule is [P1:B].[superclass: G>>>>>>>>>>>>] => [P1:B]}} +// expected-note@-1 {{failed rewrite rule is [P1:B].[superclass: G>>>>>>>>>>>>>>>>>>>>>] => [P1:B]}} associatedtype A where A == G associatedtype B where B == G } @@ -19,3 +19,40 @@ func useP2(_: T) { _ = T.A.self _ = T.B.self } + +protocol P3 { + associatedtype T : P3 +} + +struct S : P3 { + typealias T = S> +} + +protocol P4Base { + associatedtype T : P3 + associatedtype U : P3 +} + +protocol P4 : P4Base where T == S { +// expected-error@-1 {{cannot build rewrite system for protocol; rule length limit exceeded}} +// expected-note@-2 {{failed rewrite rule is [P4:T].[P3:T].[P3:T].[P3:T].[P3:T].[P3:T].[P3:T].[P3:T].[P3:T].[P3:T].[P3:T].[P3:T].[P3:T].[P3:T].[concrete: S>>>>>>>>>>>>>] => [P4:T].[P3:T].[P3:T].[P3:T].[P3:T].[P3:T].[P3:T].[P3:T].[P3:T].[P3:T].[P3:T].[P3:T].[P3:T].[P3:T]}} +} + +protocol Exponential { +// expected-error@-1 {{cannot build rewrite system for protocol; concrete type size limit exceeded}} +// expected-note@-2 {{failed rewrite rule is }} + associatedtype A where A == (A, A) +} + +class Base {} + +class Derived : Base<(T, U)> {} + +protocol TooManyDifferences { +// expected-error@-1 {{cannot build rewrite system for protocol; concrete type difference limit exceeded}} +// expected-note@-2 {{failed rewrite rule is }} + associatedtype A1 where A1: Derived, A2: Base, A1 == A2 + associatedtype A2 + associatedtype B + associatedtype C +} \ No newline at end of file diff --git a/test/Generics/non_confluent.swift b/test/Generics/non_fcrs.swift similarity index 78% rename from test/Generics/non_confluent.swift rename to test/Generics/non_fcrs.swift index 547c40fccca10..19767c1f2e9b9 100644 --- a/test/Generics/non_confluent.swift +++ b/test/Generics/non_fcrs.swift @@ -39,39 +39,6 @@ extension P1 where Self : P2 {} // expected-error@-1 {{cannot build rewrite system for generic signature; rule length limit exceeded}} // expected-note@-2 {{failed rewrite rule is τ_0_0.[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P2] => τ_0_0.[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T]}} -struct S : P1 { - typealias T = S> -} - -protocol P3Base { - associatedtype T : P1 - associatedtype U : P1 -} - -protocol P3 : P3Base where T == S { -// expected-error@-1 {{cannot build rewrite system for protocol; rule length limit exceeded}} -// expected-note@-2 {{failed rewrite rule is [P3:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[concrete: S>>>>>>>>>>>>>] => [P3:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T].[P1:T]}} -} - -protocol Exponential { -// expected-error@-1 {{cannot build rewrite system for protocol; concrete type size limit exceeded}} -// expected-note@-2 {{failed rewrite rule is }} - associatedtype A where A == (A, A) -} - -class Base {} - -class Derived : Base<(T, U)> {} - -protocol TooManyDifferences { -// expected-error@-1 {{cannot build rewrite system for protocol; concrete type difference limit exceeded}} -// expected-note@-2 {{failed rewrite rule is }} - associatedtype A1 where A1: Derived, A2: Base, A1 == A2 - associatedtype A2 - associatedtype B - associatedtype C -} - protocol M0 { // expected-error@-1 {{cannot build rewrite system for protocol; rule length limit exceeded}} // expected-note@-2 {{failed rewrite rule is }} diff --git a/test/Generics/rdar90402519.swift b/test/Generics/rdar90402519.swift index 7be346ec4d044..efee103dd5917 100644 --- a/test/Generics/rdar90402519.swift +++ b/test/Generics/rdar90402519.swift @@ -23,5 +23,5 @@ protocol P1 : P0 where C == G1 { } protocol P2 : P1 where C == G2 {} -// expected-error@-1 {{cannot build rewrite system for protocol; concrete type difference limit exceeded}} -// expected-note@-2 {{failed rewrite rule is [P2:I].[concrete: G>>>>>>>>>>>>>>>>>>>>>>>>> : Escapable] => [P2:I]}} +// expected-error@-1 {{cannot build rewrite system for protocol; concrete type nesting limit exceeded}} +// expected-note@-2 {{failed rewrite rule is [P2:I].[concrete: G>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] => [P2:I]}} From c5d8ae5b00c9400121efbf6e596a89c17c8a1de5 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sun, 6 Jul 2025 11:22:55 -0400 Subject: [PATCH 2/2] Sema: Remove unused variable --- lib/Sema/TypeCheckMacros.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Sema/TypeCheckMacros.cpp b/lib/Sema/TypeCheckMacros.cpp index 73b8bb1c93b59..3afe3d97e9bdf 100644 --- a/lib/Sema/TypeCheckMacros.cpp +++ b/lib/Sema/TypeCheckMacros.cpp @@ -1893,7 +1893,6 @@ std::optional ExpandBodyMacroRequest::evaluate(Evaluator &evaluator, AnyFunctionRef fn) const { auto *dc = fn.getAsDeclContext(); - auto &ctx = dc->getASTContext(); std::optional bufferID; fn.forEachAttachedMacro( MacroRole::Body,