Skip to content

Commit bc6a38c

Browse files
authored
Merge pull request #41733 from slavapestov/reenable-minimal-canonical-type
Reenable calls to getMinimalCanonicalType() in re-declaration checking
2 parents e6d8912 + 21def03 commit bc6a38c

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

lib/AST/ASTContext.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5201,7 +5201,8 @@ ASTContext::getOpenedArchetypeSignature(Type type, GenericSignature parentSig) {
52015201
type = existential->getConstraintType();
52025202

52035203
const CanType constraint = type->getCanonicalType();
5204-
assert(!constraint->hasTypeParameter() && "This only works with archetypes");
5204+
assert(parentSig || !constraint->hasTypeParameter() &&
5205+
"Interface type here requires a parent signature");
52055206

52065207
// The opened archetype signature for a protocol type is identical
52075208
// to the protocol's own canonical generic signature if there aren't any
@@ -5216,11 +5217,13 @@ ASTContext::getOpenedArchetypeSignature(Type type, GenericSignature parentSig) {
52165217
// generic parameters. This ensures that we keep e.g. generic superclass
52175218
// existentials contained in a well-formed generic context.
52185219
auto canParentSig = parentSig.getCanonicalSignature();
5219-
auto found = getImpl().ExistentialSignatures.find({constraint, canParentSig.getPointer()});
5220+
auto key = std::make_pair(constraint, canParentSig.getPointer());
5221+
auto found = getImpl().ExistentialSignatures.find(key);
52205222
if (found != getImpl().ExistentialSignatures.end())
52215223
return found->second;
52225224

5223-
auto genericParam = OpenedArchetypeType::getSelfInterfaceTypeFromContext(canParentSig, type->getASTContext())
5225+
auto genericParam = OpenedArchetypeType::getSelfInterfaceTypeFromContext(
5226+
canParentSig, type->getASTContext())
52245227
->castTo<GenericTypeParamType>();
52255228
Requirement requirement(RequirementKind::Conformance, genericParam,
52265229
constraint);
@@ -5231,7 +5234,7 @@ ASTContext::getOpenedArchetypeSignature(Type type, GenericSignature parentSig) {
52315234
CanGenericSignature canGenericSig(genericSig);
52325235

52335236
auto result = getImpl().ExistentialSignatures.insert(
5234-
std::make_pair(std::make_pair(constraint, canParentSig.getPointer()), canGenericSig));
5237+
std::make_pair(key, canGenericSig));
52355238
assert(result.second);
52365239
(void) result;
52375240

lib/AST/Decl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2926,7 +2926,7 @@ CanType ValueDecl::getOverloadSignatureType() const {
29262926
/*topLevelFunction=*/true, isMethod,
29272927
/*isInitializer=*/isa<ConstructorDecl>(afd),
29282928
getNumCurryLevels())
2929-
->getCanonicalType();
2929+
->getMinimalCanonicalType(afd);
29302930
}
29312931

29322932
if (isa<AbstractStorageDecl>(this)) {
@@ -2942,7 +2942,7 @@ CanType ValueDecl::getOverloadSignatureType() const {
29422942
/*topLevelFunction=*/true,
29432943
/*isMethod=*/false,
29442944
/*isInitializer=*/false, getNumCurryLevels())
2945-
->getCanonicalType();
2945+
->getMinimalCanonicalType(cast<SubscriptDecl>(this));
29462946
}
29472947

29482948
// We want to curry the default signature type with the 'self' type of the
@@ -2957,7 +2957,7 @@ CanType ValueDecl::getOverloadSignatureType() const {
29572957
auto mappedType = mapSignatureFunctionType(
29582958
getASTContext(), getInterfaceType(), /*topLevelFunction=*/false,
29592959
/*isMethod=*/false, /*isInitializer=*/false, getNumCurryLevels());
2960-
return mappedType->getCanonicalType();
2960+
return mappedType->getMinimalCanonicalType(getDeclContext());
29612961
}
29622962

29632963
// Note: If you add more cases to this function, you should update the

test/type/subclass_composition.swift

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,30 +46,29 @@ struct Unrelated {}
4646

4747
//
4848
// If a class conforms to a protocol concretely, the resulting protocol
49-
// composition type should be equivalent to the class type.
50-
//
51-
// FIXME: Disabled for now.
49+
// composition type should be equivalent to the class type for redeclaration
50+
// checking purposes.
5251
//
5352

54-
func alreadyConforms<T>(_: Base<T>) {} // expected-note {{'alreadyConforms' previously declared here}}
55-
func alreadyConforms<T>(_: Base<T> & P1) {} // FIXME e/xpected-error {{invalid redeclaration of 'alreadyConforms'}} expected-note {{'alreadyConforms' previously declared here}}
53+
func alreadyConforms<T>(_: Base<T>) {} // expected-note 3 {{'alreadyConforms' previously declared here}}
54+
func alreadyConforms<T>(_: Base<T> & P1) {} // expected-error {{invalid redeclaration of 'alreadyConforms'}}
5655
func alreadyConforms<T>(_: Base<T> & AnyObject) {} // expected-error {{invalid redeclaration of 'alreadyConforms'}}
5756
func alreadyConforms<T>(_: Base<T> & P1 & AnyObject) {} // expected-error {{invalid redeclaration of 'alreadyConforms'}}
5857

59-
func alreadyConformsMeta<T>(_: Base<T>.Type) {} // expected-note {{'alreadyConformsMeta' previously declared here}}
60-
func alreadyConformsMeta<T>(_: (Base<T> & P1).Type) {} // FIXME e/xpected-error {{invalid redeclaration of 'alreadyConformsMeta'}} expected-note {{'alreadyConformsMeta' previously declared here}}
61-
func alreadyConformsMeta<T>(_: (Base<T> & P1).Protocol) {} // FIXME e/xpected-error {{invalid redeclaration of 'alreadyConformsMeta'}} expected-note 3 {{'alreadyConformsMeta' previously declared here}}
58+
func alreadyConformsMeta<T>(_: Base<T>.Type) {} // expected-note 7 {{'alreadyConformsMeta' previously declared here}}
59+
func alreadyConformsMeta<T>(_: (Base<T> & P1).Type) {} // expected-error {{invalid redeclaration of 'alreadyConformsMeta'}}
60+
func alreadyConformsMeta<T>(_: (Base<T> & P1).Protocol) {} // expected-error {{invalid redeclaration of 'alreadyConformsMeta'}}
6261
func alreadyConformsMeta<T>(_: (any Base<T> & P1).Type) {} // expected-error {{invalid redeclaration of 'alreadyConformsMeta'}}
6362
func alreadyConformsMeta<T>(_: (Base<T> & AnyObject).Type) {} // expected-error {{invalid redeclaration of 'alreadyConformsMeta'}}
6463
func alreadyConformsMeta<T>(_: (Base<T> & P1 & AnyObject).Type) {} // expected-error {{invalid redeclaration of 'alreadyConformsMeta'}}
6564
func alreadyConformsMeta<T>(_: (Base<T> & P1 & AnyObject).Protocol) {} // expected-error {{invalid redeclaration of 'alreadyConformsMeta'}}
6665
func alreadyConformsMeta<T>(_: (any Base<T> & P1 & AnyObject).Type) {} // expected-error {{invalid redeclaration of 'alreadyConformsMeta'}}
6766

68-
func alreadyConforms(_: P3) {} // e/xpected-note {{'alreadyConforms' previously declared here}}
69-
func alreadyConforms(_: P3 & AnyObject) {} // FIXME e/xpected-error {{invalid redeclaration of 'alreadyConforms'}}
67+
func alreadyConforms(_: P3) {} // expected-note {{'alreadyConforms' previously declared here}}
68+
func alreadyConforms(_: P3 & AnyObject) {} // expected-error {{invalid redeclaration of 'alreadyConforms'}}
7069

71-
func alreadyConformsMeta(_: P3.Type) {} // FIXME e/xpected-note {{'alreadyConformsMeta' previously declared here}}
72-
func alreadyConformsMeta(_: (P3 & AnyObject).Type) {} // FIXME ex/pected-error {{invalid redeclaration of 'alreadyConformsMeta'}}
70+
func alreadyConformsMeta(_: P3.Type) {} // expected-note {{'alreadyConformsMeta' previously declared here}}
71+
func alreadyConformsMeta(_: (P3 & AnyObject).Type) {} // expected-error {{invalid redeclaration of 'alreadyConformsMeta'}}
7372

7473
// SE-0156 stipulates that a composition can contain multiple classes, as long
7574
// as they are all the same.

0 commit comments

Comments
 (0)