Skip to content

Commit 48c5d14

Browse files
committed
TypeResolution: Derive the generic signature from the generic environment when specified
1 parent f758930 commit 48c5d14

File tree

2 files changed

+16
-26
lines changed

2 files changed

+16
-26
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ TypeResolution::forInterface(DeclContext *dc, TypeResolutionOptions options,
7474
HandlePlaceholderTypeReprFn placeholderHandler) {
7575
TypeResolution result(dc, TypeResolutionStage::Interface, options,
7676
unboundTyOpener, placeholderHandler);
77-
result.genericSig = dc->getGenericSignatureOfContext();
7877
return result;
7978
}
8079

@@ -100,7 +99,6 @@ TypeResolution::forContextual(DeclContext *dc, GenericEnvironment *genericEnv,
10099
TypeResolution TypeResolution::withOptions(TypeResolutionOptions opts) const {
101100
TypeResolution result(dc, stage, opts, unboundTyOpener, placeholderHandler);
102101
result.genericEnv = genericEnv;
103-
result.genericSig = genericSig;
104102
return result;
105103
}
106104

@@ -109,20 +107,14 @@ ASTContext &TypeResolution::getASTContext() const {
109107
}
110108

111109
GenericSignature TypeResolution::getGenericSignature() const {
112-
switch (stage) {
113-
case TypeResolutionStage::Contextual:
114-
return dc->getGenericSignatureOfContext();
115-
116-
case TypeResolutionStage::Interface:
117-
if (genericSig)
118-
return genericSig;
110+
assert(
111+
stage > TypeResolutionStage::Structural &&
112+
"Structural resolution shouldn't require generic signature computation");
119113

120-
return dc->getGenericSignatureOfContext();
114+
if (genericEnv)
115+
return genericEnv->getGenericSignature();
121116

122-
case TypeResolutionStage::Structural:
123-
return GenericSignature();
124-
}
125-
llvm_unreachable("unhandled stage");
117+
return dc->getGenericSignatureOfContext();
126118
}
127119

128120
bool TypeResolution::usesArchetypes() const {
@@ -330,16 +322,17 @@ bool TypeResolution::areSameType(Type type1, Type type2) const {
330322
return false;
331323
}
332324

333-
// If we have a generic signature, canonicalize using it.
334-
if (auto genericSig = getGenericSignature()) {
335-
// If both are type parameters, we can use a cheaper check
336-
// that avoids transforming the type and computing anchors.
337-
if (type1->isTypeParameter() &&
338-
type2->isTypeParameter()) {
339-
return genericSig->areSameTypeParameterInContext(type1, type2);
325+
if (stage == TypeResolutionStage::Interface) {
326+
// If we have a generic signature, canonicalize using it.
327+
if (auto genericSig = getGenericSignature()) {
328+
// If both are type parameters, we can use a cheaper check
329+
// that avoids transforming the type and computing anchors.
330+
if (type1->isTypeParameter() && type2->isTypeParameter()) {
331+
return genericSig->areSameTypeParameterInContext(type1, type2);
332+
}
333+
return genericSig.getCanonicalTypeInContext(type1) ==
334+
genericSig.getCanonicalTypeInContext(type2);
340335
}
341-
return genericSig.getCanonicalTypeInContext(type1) ==
342-
genericSig.getCanonicalTypeInContext(type2);
343336
}
344337

345338
// Otherwise, perform a structural check.

lib/Sema/TypeCheckType.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,6 @@ class TypeResolution {
303303
/// The generic environment used to map to archetypes.
304304
GenericEnvironment *genericEnv;
305305

306-
/// The generic signature to use for type resolution.
307-
GenericSignature genericSig;
308-
309306
TypeResolution(DeclContext *dc, TypeResolutionStage stage,
310307
TypeResolutionOptions options,
311308
OpenUnboundGenericTypeFn unboundTyOpener,

0 commit comments

Comments
 (0)