Skip to content

Commit ea48847

Browse files
committed
AST: WhereClauseOwner never visit the obsolete 'where' clause inside a GenericParamList
Otherwise, we'll end up visiting it twice in InferredGenericSignatureRequest. The GSB uniques requirements seen this way, whereas the Requirement Machine does not, leading to redundant requirement diagnostics.
1 parent fab3771 commit ea48847

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

lib/AST/TypeCheckRequests.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -340,28 +340,26 @@ void RequirementSignatureRequest::cacheResult(RequirementSignature value) const
340340
// Requirement computation.
341341
//----------------------------------------------------------------------------//
342342

343-
WhereClauseOwner::WhereClauseOwner(GenericContext *genCtx): dc(genCtx) {
344-
if (const auto whereClause = genCtx->getTrailingWhereClause())
345-
source = whereClause;
346-
else
347-
source = genCtx->getGenericParams();
348-
}
343+
WhereClauseOwner::WhereClauseOwner(GenericContext *genCtx)
344+
: dc(genCtx),
345+
source(genCtx->getTrailingWhereClause()) {}
349346

350347
WhereClauseOwner::WhereClauseOwner(AssociatedTypeDecl *atd)
351348
: dc(atd->getInnermostDeclContext()),
352349
source(atd->getTrailingWhereClause()) {}
353350

354351
SourceLoc WhereClauseOwner::getLoc() const {
355-
if (auto where = source.dyn_cast<TrailingWhereClause *>())
356-
return where->getWhereLoc();
357-
358-
if (auto attr = source.dyn_cast<SpecializeAttr *>())
352+
if (auto genericParams = source.dyn_cast<GenericParamList *>()) {
353+
return genericParams->getWhereLoc();
354+
} else if (auto attr = source.dyn_cast<SpecializeAttr *>()) {
359355
return attr->getLocation();
360-
361-
if (auto attr = source.dyn_cast<DifferentiableAttr *>())
356+
} else if (auto attr = source.dyn_cast<DifferentiableAttr *>()) {
362357
return attr->getLocation();
358+
} else if (auto where = source.dyn_cast<TrailingWhereClause *>()) {
359+
return where->getWhereLoc();
360+
}
363361

364-
return source.get<GenericParamList *>()->getWhereLoc();
362+
return SourceLoc();
365363
}
366364

367365
void swift::simple_display(llvm::raw_ostream &out,

test/IDE/annotation.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ class SubCls : MyCls, Prot {
8181
var protocolProperty2 = 0
8282
}
8383

84-
// CHECK: func <Func>genFn</Func><<GenericTypeParam>T</GenericTypeParam> : <Protocol@64:10>Prot</Protocol> where <GenericTypeParam@85:12>T</GenericTypeParam>.<AssociatedType@65:18>Blarg</AssociatedType> : <Protocol@71:10>Prot2</Protocol>>(_ <Param>p</Param> : <GenericTypeParam@85:12>T</GenericTypeParam>) -> <iStruct@>Int</iStruct> {}{{$}}
85-
func genFn<T : Prot where T.Blarg : Prot2>(_ p : T) -> Int {}
84+
// CHECK: func <Func>genFn</Func><<GenericTypeParam>T</GenericTypeParam> : <Protocol@64:10>Prot</Protocol>>(_ <Param>p</Param> : <GenericTypeParam@85:12>T</GenericTypeParam>) -> <iStruct@>Int</iStruct> where <GenericTypeParam@85:12>T</GenericTypeParam>.<AssociatedType@65:18>Blarg</AssociatedType> : <Protocol@71:10>Prot2</Protocol> {}{{$}}
85+
func genFn<T : Prot>(_ p : T) -> Int where T.Blarg : Prot2 {}
8686

8787
func test(_ x: Int) {
8888
// CHECK: <Func@[[@LINE-3]]:6>genFn</Func>(<Class@[[@LINE-11]]:7>SubCls</Class>())

test/Parse/deprecated_where.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 -swift-version 4
1+
// RUN: %target-typecheck-verify-swift -swift-version 4 -requirement-machine-protocol-signatures=on -requirement-machine-inferred-signatures=on
22

33
protocol Mashable { }
44
protocol Womparable { }

test/type/protocol_composition.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 -swift-version 4 -requirement-machine-protocol-signatures=verify -requirement-machine-inferred-signatures=verify
1+
// RUN: %target-typecheck-verify-swift -swift-version 4 -requirement-machine-protocol-signatures=on -requirement-machine-inferred-signatures=on
22

33
func canonical_empty_protocol() -> Any {
44
return 1

0 commit comments

Comments
 (0)