From bbbf4e7d43a6fc03fe85b4cd849d587bdfc55aa5 Mon Sep 17 00:00:00 2001 From: Kavon Farvardin Date: Sat, 28 Oct 2023 15:31:44 -0700 Subject: [PATCH] [Sema] drop half-baked redundancy checking for now We already don't diagnose all redundant requirements. Because inverses can be written in both inheritance and where clauses, but they're not treated uniformly in the implementation, it's a bit annoying to try and account for the redundancies in both places; `checkInheritanceClause` will go over the same "requirements" that we'll also check again in `swift::rewriting::expandDefaultRequirements`. --- include/swift/AST/DiagnosticsSema.def | 4 ---- lib/Sema/TypeCheckDecl.cpp | 14 +------------- test/Generics/inverse_protocols_errors.swift | 6 ------ test/Parse/inverses.swift | 13 ++++++++++--- 4 files changed, 11 insertions(+), 26 deletions(-) diff --git a/include/swift/AST/DiagnosticsSema.def b/include/swift/AST/DiagnosticsSema.def index 6fcd04f2914..5223bb5ccdb 100644 --- a/include/swift/AST/DiagnosticsSema.def +++ b/include/swift/AST/DiagnosticsSema.def @@ -2399,10 +2399,6 @@ ERROR(inferred_opaque_type,none, // Inverse Constraints ERROR(inverse_type_not_invertible,none, "type %0 is not invertible", (Type)) -ERROR(inverse_duplicate,none, - "duplicate inverse constraint", ()) -NOTE(inverse_duplicate_previous,none, - "previous inverse constraint here", ()) // Extensions ERROR(non_nominal_extension,none, diff --git a/lib/Sema/TypeCheckDecl.cpp b/lib/Sema/TypeCheckDecl.cpp index dd566b7381a..b4f613ee295 100644 --- a/lib/Sema/TypeCheckDecl.cpp +++ b/lib/Sema/TypeCheckDecl.cpp @@ -952,21 +952,9 @@ bool HasNoncopyableAnnotationRequest::evaluate(Evaluator &evaluator, TypeDecl *d // The set of defaults all types start with. auto defaults = InvertibleProtocolSet::full(); - std::map lastInverse; - // Does correctness checking after inspecting the inheritance clause. - // TODO: we can probably move this to `checkInheritanceClause` instead. auto foundInverse = [&](SourceLoc loc, InvertibleProtocolKind kind) { - // do we still have this default? - if (defaults.contains(kind)) { - defaults.remove(kind); - lastInverse.insert({kind, loc}); - return; - } - - // diagnose duplicate inverses - ctx.Diags.diagnose(loc, diag::inverse_duplicate); - ctx.Diags.diagnose(lastInverse[kind], diag::inverse_duplicate_previous); + defaults.remove(kind); }; // Check the inheritance clause for inverses. diff --git a/test/Generics/inverse_protocols_errors.swift b/test/Generics/inverse_protocols_errors.swift index 63162128a34..bd2b8cb638c 100644 --- a/test/Generics/inverse_protocols_errors.swift +++ b/test/Generics/inverse_protocols_errors.swift @@ -41,9 +41,3 @@ struct NCThinger: ~Copyable, Hello { // expected-note@-3 {{add 'inout' for a mutable reference}} // expected-note@-4 {{add 'consuming' to take the value from the caller}} } - -struct ExtraNoncopyStruct: ~Copyable, ~Copyable {} -// expected-error@-1 {{duplicate inverse constraint}} -// expected-note@-2 {{previous inverse constraint here}} - -protocol ExtraNoncopyProto: ~Copyable, ~Copyable {} diff --git a/test/Parse/inverses.swift b/test/Parse/inverses.swift index 517671fee83..83aa610df03 100644 --- a/test/Parse/inverses.swift +++ b/test/Parse/inverses.swift @@ -24,10 +24,17 @@ func blah(_ t: borrowing T) where T: ~Copyable, func foo(x: borrowing T) {} -struct Buurap {} +struct Buurap where T: ~Copyable {} -protocol Foo: ~Copyable // expected-note {{previous inverse constraint here}} - where Self: ~Copyable { // expected-error {{duplicate inverse constraint}} +struct ExtraNoncopyStruct: ~Copyable, ~Copyable {} +struct ExtraNoncopyEnum: ~Copyable, ~Copyable {} +protocol ExtraNoncopyProto: ~Copyable, ~Copyable {} + +protocol Foo: ~Copyable + where Self: ~Copyable { + + associatedtype Touch : ~Copyable, + ~Copyable func test(_ t: T) where T: ~Self // expected-error {{type 'Self' is not invertible}} }