Skip to content

Commit db6d3e0

Browse files
committed
AST: Refactor MapLocalArchetypesOutOfContext to handle member types
1 parent d2c0efe commit db6d3e0

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

include/swift/AST/LocalArchetypeRequirementCollector.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ struct MapLocalArchetypesOutOfContext {
5050
ArrayRef<GenericEnvironment *> capturedEnvs)
5151
: baseGenericSig(baseGenericSig), capturedEnvs(capturedEnvs) {}
5252

53+
Type getInterfaceType(Type interfaceTy, GenericEnvironment *genericEnv) const;
5354
Type operator()(SubstitutableType *type) const;
5455
};
5556

lib/AST/LocalArchetypeRequirementCollector.cpp

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -157,27 +157,17 @@ GenericSignature swift::buildGenericSignatureWithCapturedEnvironments(
157157
/*allowInverses=*/false);
158158
}
159159

160-
Type MapLocalArchetypesOutOfContext::operator()(SubstitutableType *type) const {
161-
auto *archetypeTy = cast<ArchetypeType>(type);
160+
Type MapLocalArchetypesOutOfContext::getInterfaceType(
161+
Type interfaceTy, GenericEnvironment *genericEnv) const {
162162

163-
// Primary archetypes just map out of context.
164-
if (isa<PrimaryArchetypeType>(archetypeTy) ||
165-
isa<PackArchetypeType>(archetypeTy)) {
166-
return archetypeTy->getInterfaceType();
163+
if (auto *dmt = interfaceTy->getAs<DependentMemberType>()) {
164+
auto newBase = getInterfaceType(dmt->getBase(), genericEnv);
165+
return DependentMemberType::get(newBase, dmt->getAssocType());
167166
}
168167

169-
assert(isa<LocalArchetypeType>(archetypeTy));
170-
171-
// Handle dependent member types recursively in the usual way.
172-
if (!archetypeTy->isRoot())
173-
return Type();
174-
175-
// Root local archetypes change depth.
176-
auto *genericEnv = archetypeTy->getGenericEnvironment();
177-
auto rootParam = archetypeTy->getInterfaceType()
178-
->castTo<GenericTypeParamType>();
179-
assert(!rootParam->isParameterPack());
180-
assert(rootParam->getDepth() == genericEnv->getGenericSignature()->getMaxDepth());
168+
auto rootParam = interfaceTy->castTo<GenericTypeParamType>();
169+
ASSERT(!rootParam->isParameterPack());
170+
ASSERT(rootParam->getDepth() == genericEnv->getGenericSignature()->getMaxDepth());
181171

182172
// The new depth is determined by counting how many captured environments
183173
// precede this one.
@@ -192,7 +182,25 @@ Type MapLocalArchetypesOutOfContext::operator()(SubstitutableType *type) const {
192182
++depth;
193183
}
194184

195-
llvm_unreachable("Fell off the end");
185+
llvm::errs() << "Fell off the end:\n";
186+
interfaceTy->dump(llvm::errs());
187+
abort();
188+
}
189+
190+
Type MapLocalArchetypesOutOfContext::operator()(SubstitutableType *type) const {
191+
auto *archetypeTy = cast<ArchetypeType>(type);
192+
193+
// Primary archetypes just map out of context.
194+
if (isa<PrimaryArchetypeType>(archetypeTy) ||
195+
isa<PackArchetypeType>(archetypeTy)) {
196+
return archetypeTy->getInterfaceType();
197+
}
198+
199+
ASSERT(isa<LocalArchetypeType>(archetypeTy));
200+
201+
// Root local archetypes change depth.
202+
auto *genericEnv = archetypeTy->getGenericEnvironment();
203+
return getInterfaceType(archetypeTy->getInterfaceType(), genericEnv);
196204
}
197205

198206
static Type mapIntoLocalContext(GenericTypeParamType *param, unsigned baseDepth,

0 commit comments

Comments
 (0)