Skip to content

Commit bd0fa0b

Browse files
committed
Eliminate the notion of a "bound signature" for opaque type archetypes.
The refactoring that moved the substitution of the outer environment into an opaque type archeptype into the generic environment eliminated the need for the bound signature entirely, so remove it.
1 parent 9dcb5a5 commit bd0fa0b

File tree

6 files changed

+9
-72
lines changed

6 files changed

+9
-72
lines changed

include/swift/AST/GenericEnvironment.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,10 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
107107
/// This is only useful when lazily populating a generic environment.
108108
Optional<Type> getMappingIfPresent(GenericParamKey key) const;
109109

110-
/// Get the "raw" generic signature, without substituting into opaque
111-
/// type's signature.
112-
GenericSignature getRawGenericSignature() const;
113-
114110
public:
115-
GenericSignature getGenericSignature() const;
111+
GenericSignature getGenericSignature() const {
112+
return SignatureAndKind.getPointer();
113+
}
116114

117115
Kind getKind() const { return SignatureAndKind.getInt(); }
118116

include/swift/AST/Types.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5578,12 +5578,6 @@ class OpaqueTypeArchetypeType final : public ArchetypeType,
55785578
/// Retrieve the set of substitutions applied to the opaque type.
55795579
SubstitutionMap getSubstitutions() const;
55805580

5581-
/// Get the generic signature used to build out this archetype. This is
5582-
/// equivalent to the OpaqueTypeDecl's interface generic signature, with
5583-
/// all of the generic parameters aside from the opaque type's interface
5584-
/// type same-type-constrained to their substitutions for this type.
5585-
GenericSignature getBoundSignature() const;
5586-
55875581
/// Get a generic environment that has this opaque archetype bound within it.
55885582
GenericEnvironment *getGenericEnvironment() const;
55895583

lib/AST/ASTContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4592,7 +4592,7 @@ GenericEnvironment *GenericEnvironment::forOpaqueType(
45924592
size_t bytes = totalSizeToAlloc<OpaqueTypeDecl *, SubstitutionMap, Type>(
45934593
1, 1, numGenericParams);
45944594
void *mem = ctx.Allocate(bytes, alignof(GenericEnvironment), arena);
4595-
auto env = new (mem) GenericEnvironment(GenericSignature(), opaque, subs);
4595+
auto env = new (mem) GenericEnvironment(signature, opaque, subs);
45964596
return env;
45974597
}
45984598

lib/AST/ASTMangler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3314,7 +3314,8 @@ void ASTMangler::appendAnyProtocolConformance(
33143314
conformance.getAbstract());
33153315
appendDependentProtocolConformance(path, genericSig);
33163316
} else if (auto opaqueType = conformingType->getAs<OpaqueTypeArchetypeType>()) {
3317-
GenericSignature opaqueSignature = opaqueType->getBoundSignature();
3317+
GenericSignature opaqueSignature =
3318+
opaqueType->getDecl()->getOpaqueInterfaceGenericSignature();
33183319
ConformanceAccessPath conformanceAccessPath =
33193320
opaqueSignature->getConformanceAccessPath(
33203321
opaqueType->getInterfaceType(),

lib/AST/GenericEnvironment.cpp

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -50,58 +50,6 @@ size_t GenericEnvironment::numTrailingObjects(OverloadToken<Type>) const {
5050
return getGenericParams().size();
5151
}
5252

53-
GenericSignature GenericEnvironment::getRawGenericSignature() const {
54-
switch (getKind()) {
55-
case Kind::Normal:
56-
case Kind::OpenedExistential:
57-
return SignatureAndKind.getPointer();
58-
59-
case Kind::Opaque:
60-
return getOpaqueTypeDecl()->getOpaqueInterfaceGenericSignature();
61-
}
62-
}
63-
64-
GenericSignature GenericEnvironment::getGenericSignature() const {
65-
switch (getKind()) {
66-
case Kind::Normal:
67-
case Kind::OpenedExistential:
68-
return SignatureAndKind.getPointer();
69-
70-
case Kind::Opaque:
71-
if (auto sig = SignatureAndKind.getPointer())
72-
return sig;
73-
74-
// Build signature below.
75-
break;
76-
}
77-
78-
// Create a new opaque archetype.
79-
// It lives in an environment in which the interface generic arguments of the
80-
// decl have all been same-type-bound to the arguments from our substitution
81-
// map.
82-
SmallVector<Requirement, 2> newRequirements;
83-
84-
// Same-type-constrain the arguments in the outer signature to their
85-
// replacements in the substitution map.
86-
auto opaqueDecl = getOpaqueTypeDecl();
87-
auto subs = getOpaqueSubstitutions();
88-
if (auto outerSig = opaqueDecl->getGenericSignature()) {
89-
for (auto outerParam : outerSig.getGenericParams()) {
90-
auto boundType = Type(outerParam).subst(subs);
91-
newRequirements.push_back(
92-
Requirement(RequirementKind::SameType, Type(outerParam), boundType));
93-
}
94-
}
95-
96-
auto signature = buildGenericSignature(
97-
opaqueDecl->getASTContext(),
98-
opaqueDecl->getOpaqueInterfaceGenericSignature(),
99-
/*genericParams=*/{ },
100-
std::move(newRequirements));
101-
SignatureAndKind.setPointer(signature);
102-
return signature;
103-
}
104-
10553
/// Retrieve the array containing the context types associated with the
10654
/// generic parameters, stored in parallel with the generic parameters of the
10755
/// generic signature.
@@ -120,7 +68,7 @@ ArrayRef<Type> GenericEnvironment::getContextTypes() const {
12068

12169
TypeArrayView<GenericTypeParamType>
12270
GenericEnvironment::getGenericParams() const {
123-
return getRawGenericSignature().getGenericParams();
71+
return getGenericSignature().getGenericParams();
12472
}
12573

12674
OpaqueTypeDecl *GenericEnvironment::getOpaqueTypeDecl() const {
@@ -272,7 +220,7 @@ Type TypeBase::mapTypeOutOfContext() {
272220

273221
Type
274222
GenericEnvironment::getOrCreateArchetypeFromInterfaceType(Type depType) {
275-
auto genericSig = getRawGenericSignature();
223+
auto genericSig = getGenericSignature();
276224
LookUpConformanceInSignature conformanceLookupFn(genericSig.getPointer());
277225

278226
auto requirements = genericSig->getLocalRequirements(depType);
@@ -425,7 +373,7 @@ Type GenericEnvironment::mapTypeIntoContext(
425373
}
426374

427375
Type GenericEnvironment::mapTypeIntoContext(Type type) const {
428-
auto sig = getRawGenericSignature();
376+
auto sig = getGenericSignature();
429377
return mapTypeIntoContext(type, LookUpConformanceInSignature(sig.getPointer()));
430378
}
431379

lib/AST/Type.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3320,10 +3320,6 @@ GenericEnvironment *OpaqueTypeArchetypeType::getGenericEnvironment() const {
33203320
return Environment;
33213321
}
33223322

3323-
GenericSignature OpaqueTypeArchetypeType::getBoundSignature() const {
3324-
return getGenericEnvironment()->getGenericSignature();
3325-
}
3326-
33273323
OpaqueTypeDecl *OpaqueTypeArchetypeType::getDecl() const {
33283324
return Environment->getOpaqueTypeDecl();
33293325
}

0 commit comments

Comments
 (0)