Skip to content

Commit fab3771

Browse files
committed
Sema: Clean up named opaque result type generic signature construction
We were building the signature twice, and adding the 'where' clause twice each time. The GSB magically uniqued them, whereas the Requirement Machine is not so forgiving.
1 parent 4e89f73 commit fab3771

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

lib/Sema/TypeCheckGeneric.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ OpaqueResultTypeRequest::evaluate(Evaluator &evaluator,
122122
originatingDC->getParentModule(),
123123
outerGenericSignature.getPointer(),
124124
genericParams,
125-
WhereClauseOwner(originatingDC, genericParams),
125+
WhereClauseOwner(),
126126
/*addedRequirements=*/{},
127127
/*inferenceSources=*/{},
128128
/*allowConcreteGenericParams=*/false};
@@ -208,6 +208,9 @@ OpaqueResultTypeRequest::evaluate(Evaluator &evaluator,
208208
opaqueDecl->copyFormalAccessFrom(originatingDecl);
209209
if (auto originatingSig = originatingDC->getGenericSignatureOfContext()) {
210210
opaqueDecl->setGenericSignature(originatingSig);
211+
} else {
212+
// Avoid kicking off GenericSignatureRequest for the OpaqueTypeDecl.
213+
opaqueDecl->setGenericSignature(GenericSignature());
211214
}
212215

213216
// Resolving in the context of `opaqueDecl` allows type resolution to create
@@ -572,6 +575,8 @@ static unsigned getExtendedTypeGenericDepth(ExtensionDecl *ext) {
572575
GenericSignature
573576
GenericSignatureRequest::evaluate(Evaluator &evaluator,
574577
GenericContext *GC) const {
578+
assert(!isa<OpaqueTypeDecl>(GC));
579+
575580
auto &ctx = GC->getASTContext();
576581

577582
// The signature of a Protocol is trivial (Self: TheProtocol) so let's compute

lib/Serialization/Deserialization.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -3567,6 +3567,8 @@ class DeclDeserializer {
35673567
auto genericSig = MF.getGenericSignature(genericSigID);
35683568
if (genericSig)
35693569
opaqueDecl->setGenericSignature(genericSig);
3570+
else
3571+
opaqueDecl->setGenericSignature(GenericSignature());
35703572
if (underlyingTypeSubsID) {
35713573
auto subMapOrError = MF.getSubstitutionMapChecked(underlyingTypeSubsID);
35723574
if (!subMapOrError)

test/type/opaque_return_named.swift

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -enable-experimental-named-opaque-types -disable-availability-checking
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-named-opaque-types -disable-availability-checking -requirement-machine-protocol-signatures=on -requirement-machine-inferred-signatures=on
22

33
// Tests for experimental extensions to opaque return type support.
44

@@ -133,14 +133,10 @@ struct Generic<T: P1 & Equatable & DefaultInitializable>
133133
}
134134
}
135135

136-
// FIXME: expected-warning@+2{{redundant same-type constraint 'C.Element' == 'T.A'}}
137-
// FIXME: expected-note@+1{{previous same-type constraint 'C.Element' == 'T.A' written here}}
138136
func sameTypeParams() -> <C: Collection where C.Element == T.A> C {
139137
[ T.A(), T.A() ]
140138
}
141139

142-
// FIXME: expected-warning@+2{{redundant same-type constraint 'C.Element' == 'T.A'}}
143-
// FIXME: expected-note@+1{{previous same-type constraint 'C.Element' == 'T.A' written here}}
144140
func sameTypeParamsBad() -> <C: Collection where C.Element == T.A> C {
145141
[ T() ] // expected-error{{cannot convert value of type 'T' to expected element type 'T.A'}}
146142
}

0 commit comments

Comments
 (0)