Skip to content

Commit 03f3a0c

Browse files
authored
Merge pull request #10940 from DougGregor/se-0157-recursive-constraints
2 parents 1e38b4b + afbdbae commit 03f3a0c

File tree

9 files changed

+10
-73
lines changed

9 files changed

+10
-73
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,8 +1666,6 @@ ERROR(requires_generic_param_made_equal_to_concrete,none,
16661666
(Type))
16671667
ERROR(recursive_type_reference,none,
16681668
"%0 %1 references itself", (DescriptiveDeclKind, Identifier))
1669-
ERROR(recursive_requirement_reference,none,
1670-
"type may not reference itself as a requirement",())
16711669
ERROR(recursive_same_type_constraint,none,
16721670
"same-type constraint %0 == %1 is recursive", (Type, Type))
16731671
ERROR(recursive_superclass_constraint,none,

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,6 @@ class GenericSignatureBuilder {
417417
template<typename F>
418418
void visitPotentialArchetypes(F f);
419419

420-
void markPotentialArchetypeRecursive(PotentialArchetype *pa,
421-
ProtocolDecl *proto,
422-
const RequirementSource *source);
423-
424420
public:
425421
/// Construct a new generic signature builder.
426422
///
@@ -1332,32 +1328,28 @@ class GenericSignatureBuilder::PotentialArchetype {
13321328
/// that share a name.
13331329
llvm::MapVector<Identifier, StoredNestedType> NestedTypes;
13341330

1335-
/// \brief Recursively conforms to itself.
1336-
unsigned IsRecursive : 1;
1337-
13381331
/// \brief Construct a new potential archetype for an unresolved
13391332
/// associated type.
13401333
PotentialArchetype(PotentialArchetype *parent, Identifier name);
13411334

13421335
/// \brief Construct a new potential archetype for an associated type.
13431336
PotentialArchetype(PotentialArchetype *parent, AssociatedTypeDecl *assocType)
1344-
: parentOrBuilder(parent), identifier(assocType), IsRecursive(false)
1337+
: parentOrBuilder(parent), identifier(assocType)
13451338
{
13461339
assert(parent != nullptr && "Not an associated type?");
13471340
}
13481341

13491342
/// \brief Construct a new potential archetype for a concrete declaration.
13501343
PotentialArchetype(PotentialArchetype *parent, TypeDecl *concreteDecl)
1351-
: parentOrBuilder(parent), identifier(concreteDecl), IsRecursive(false)
1344+
: parentOrBuilder(parent), identifier(concreteDecl)
13521345
{
13531346
assert(parent != nullptr && "Not an associated type?");
13541347
}
13551348

13561349
/// \brief Construct a new potential archetype for a generic parameter.
13571350
PotentialArchetype(GenericSignatureBuilder *builder,
13581351
GenericParamKey genericParam)
1359-
: parentOrBuilder(builder), identifier(genericParam),
1360-
IsRecursive(false)
1352+
: parentOrBuilder(builder), identifier(genericParam)
13611353
{
13621354
}
13631355

@@ -1600,9 +1592,6 @@ class GenericSignatureBuilder::PotentialArchetype {
16001592
return Type();
16011593
}
16021594

1603-
void setIsRecursive() { IsRecursive = true; }
1604-
bool isRecursive() const { return IsRecursive; }
1605-
16061595
LLVM_ATTRIBUTE_DEPRECATED(
16071596
void dump() const,
16081597
"only for use within the debugger");

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,6 @@ namespace swift {
206206
/// Should we use \c ASTScope-based resolution for unqualified name lookup?
207207
bool EnableASTScopeLookup = false;
208208

209-
/// Enable SE-0157: Recursive Protocol Constraints.
210-
bool EnableRecursiveConstraints = false;
211-
212209
/// Whether to use the import as member inference system
213210
///
214211
/// When importing a global, try to infer whether we can import it as a

include/swift/Option/FrontendOptions.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,6 @@ def disable_target_os_checking :
109109
def enable_astscope_lookup : Flag<["-"], "enable-astscope-lookup">,
110110
HelpText<"Enable ASTScope-based unqualified name lookup">;
111111

112-
def enable_recursive_constraints : Flag<["-"], "enable-recursive-constraints">,
113-
HelpText<"Enable SE-0157: Recursive Protocol Constraints">;
114-
115112
def print_clang_stats : Flag<["-"], "print-clang-stats">,
116113
HelpText<"Print Clang importer statistics">;
117114

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3357,28 +3357,6 @@ ConstraintResult GenericSignatureBuilder::addSameTypeRequirementDirect(
33573357
}
33583358
}
33593359

3360-
// Local function to mark the given associated type as recursive,
3361-
// diagnosing it if this is the first such occurrence.
3362-
void GenericSignatureBuilder::markPotentialArchetypeRecursive(
3363-
PotentialArchetype *pa, ProtocolDecl *proto, const RequirementSource *source) {
3364-
if (pa->isRecursive())
3365-
return;
3366-
pa->setIsRecursive();
3367-
3368-
pa->addConformance(proto, source, *this);
3369-
if (!pa->getParent())
3370-
return;
3371-
3372-
auto assocType = pa->getResolvedAssociatedType();
3373-
if (!assocType || assocType->isInvalid())
3374-
return;
3375-
3376-
Diags.diagnose(assocType->getLoc(), diag::recursive_requirement_reference);
3377-
3378-
// Silence downstream errors referencing this associated type.
3379-
assocType->setInvalid();
3380-
}
3381-
33823360
ConstraintResult GenericSignatureBuilder::addInheritedRequirements(
33833361
TypeDecl *decl,
33843362
UnresolvedType type,
@@ -3429,26 +3407,6 @@ ConstraintResult GenericSignatureBuilder::addInheritedRequirements(
34293407
getFloatingSource(typeRepr, /*forInferred=*/true));
34303408
}
34313409

3432-
if (!decl->getASTContext().LangOpts.EnableRecursiveConstraints) {
3433-
// Check for direct recursion.
3434-
if (auto assocType = dyn_cast<AssociatedTypeDecl>(decl)) {
3435-
auto proto = assocType->getProtocol();
3436-
if (auto inheritedProto = inheritedType->getAs<ProtocolType>()) {
3437-
if (inheritedProto->getDecl() == proto ||
3438-
inheritedProto->getDecl()->inheritsFrom(proto)) {
3439-
auto source = getFloatingSource(typeRepr, /*forInferred=*/false);
3440-
if (auto resolved = resolve(type, source)) {
3441-
if (auto pa = resolved->getPotentialArchetype()) {
3442-
markPotentialArchetypeRecursive(pa, proto,
3443-
source.getSource(pa));
3444-
return ConstraintResult::Conflicting;
3445-
}
3446-
}
3447-
}
3448-
}
3449-
}
3450-
}
3451-
34523410
return addTypeRequirement(type, inheritedType,
34533411
getFloatingSource(typeRepr,
34543412
/*forInferred=*/false),

lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,8 +1007,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
10071007
}
10081008

10091009
Opts.EnableASTScopeLookup |= Args.hasArg(OPT_enable_astscope_lookup);
1010-
Opts.EnableRecursiveConstraints |=
1011-
Args.hasArg(OPT_enable_recursive_constraints);
10121010
Opts.DebugConstraintSolver |= Args.hasArg(OPT_debug_constraints);
10131011
Opts.EnableConstraintPropagation |= Args.hasArg(OPT_propagate_constraints);
10141012
Opts.IterativeTypeChecker |= Args.hasArg(OPT_iterative_type_checker);

test/Generics/same_type_constraints.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ extension Dictionary {
154154

155155
// rdar://problem/19245317
156156
protocol P {
157-
associatedtype T: P // expected-error{{type may not reference itself as a requirement}}
157+
associatedtype T: P
158158
}
159159

160160
struct S<A: P> {

test/decl/protocol/recursive_requirement.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// -----
44

55
protocol Foo {
6-
associatedtype Bar : Foo // expected-error{{type may not reference itself as a requirement}}
6+
associatedtype Bar : Foo
77
}
88

99
struct Oroborous : Foo {
@@ -13,7 +13,7 @@ struct Oroborous : Foo {
1313
// -----
1414

1515
protocol P {
16-
associatedtype A : P // expected-error{{type may not reference itself as a requirement}}
16+
associatedtype A : P
1717
}
1818

1919
struct X<T: P> {
@@ -26,7 +26,7 @@ func f<T : P>(_ z: T) {
2626
// -----
2727

2828
protocol PP2 {
29-
associatedtype A : P2 = Self // expected-error{{type may not reference itself as a requirement}}
29+
associatedtype A : P2 = Self
3030
}
3131

3232
protocol P2 : PP2 {
@@ -41,13 +41,13 @@ struct Y2 : P2 {
4141
}
4242

4343
func f<T : P2>(_ z: T) {
44-
_ = X2<T.A>() // expected-error{{type 'T.A' does not conform to protocol 'P2'}}
44+
_ = X2<T.A>()
4545
}
4646

4747
// -----
4848

4949
protocol P3 {
50-
associatedtype A: P4 = Self // expected-error{{type may not reference itself as a requirement}}
50+
associatedtype A: P4 = Self
5151
}
5252

5353
protocol P4 : P3 {}

test/decl/protocol/recursive_requirement_ok.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -enable-recursive-constraints
1+
// RUN: %target-typecheck-verify-swift
22

33
protocol P {
44
associatedtype Assoc : P

0 commit comments

Comments
 (0)