Skip to content

Commit 3f5ae71

Browse files
committed
AST: Clean up mapContextualPackTypeIntoElementContext()
1 parent 50ab7f5 commit 3f5ae71

File tree

1 file changed

+35
-47
lines changed

1 file changed

+35
-47
lines changed

lib/AST/GenericEnvironment.cpp

Lines changed: 35 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -149,53 +149,6 @@ UUID GenericEnvironment::getOpenedElementUUID() const {
149149
return getTrailingObjects<OpenedElementEnvironmentData>()->uuid;
150150
}
151151

152-
namespace {
153-
154-
struct FindOpenedElementParam {
155-
ArrayRef<Type> openedPacks;
156-
ArrayRef<GenericTypeParamType *> packElementParams;
157-
158-
FindOpenedElementParam(const GenericEnvironment *env,
159-
ArrayRef<Type> openedPacks)
160-
: openedPacks(openedPacks),
161-
packElementParams(
162-
env->getGenericSignature().getInnermostGenericParams()) {
163-
assert(openedPacks.size() == packElementParams.size());
164-
}
165-
166-
GenericTypeParamType *operator()(Type packParam) {
167-
for (auto i : indices(openedPacks)) {
168-
if (openedPacks[i]->isEqual(packParam))
169-
return packElementParams[i];
170-
}
171-
llvm_unreachable("parameter was not an opened pack parameter");
172-
}
173-
};
174-
175-
struct FindElementArchetypeForOpenedPackParam {
176-
FindOpenedElementParam findElementParam;
177-
QueryInterfaceTypeSubstitutions getElementArchetype;
178-
179-
FindElementArchetypeForOpenedPackParam(const GenericEnvironment *env,
180-
ArrayRef<Type> openedPacks)
181-
: findElementParam(env, openedPacks), getElementArchetype(env) {}
182-
183-
184-
Type operator()(Type interfaceType) {
185-
assert(interfaceType->isTypeParameter());
186-
if (auto member = interfaceType->getAs<DependentMemberType>()) {
187-
auto baseArchetype = (*this)(member->getBase())
188-
->castTo<ElementArchetypeType>();
189-
return baseArchetype->getNestedType(member->getAssocType())
190-
->castTo<ElementArchetypeType>();
191-
}
192-
assert(interfaceType->is<GenericTypeParamType>());
193-
return getElementArchetype(findElementParam(interfaceType));
194-
}
195-
};
196-
197-
}
198-
199152
void GenericEnvironment::forEachPackElementArchetype(
200153
llvm::function_ref<void(ElementArchetypeType *)> function) const {
201154
auto packElements = getGenericSignature().getInnermostGenericParams();
@@ -652,6 +605,41 @@ Type GenericEnvironment::mapTypeIntoContext(GenericTypeParamType *type) const {
652605
return result;
653606
}
654607

608+
namespace {
609+
610+
struct FindElementArchetypeForOpenedPackParam {
611+
ArrayRef<Type> openedPacks;
612+
ArrayRef<GenericTypeParamType *> packElementParams;
613+
const GenericEnvironment *env;
614+
615+
FindElementArchetypeForOpenedPackParam(const GenericEnvironment *env,
616+
ArrayRef<Type> openedPacks)
617+
: openedPacks(openedPacks),
618+
packElementParams(env->getGenericSignature().getInnermostGenericParams()),
619+
env(env) {}
620+
621+
Type getInterfaceType(Type interfaceType) const {
622+
if (auto member = interfaceType->getAs<DependentMemberType>()) {
623+
return DependentMemberType::get(getInterfaceType(member->getBase()),
624+
member->getAssocType());
625+
}
626+
627+
assert(interfaceType->is<GenericTypeParamType>());
628+
for (auto i : indices(openedPacks)) {
629+
if (openedPacks[i]->isEqual(interfaceType))
630+
return packElementParams[i];
631+
}
632+
633+
llvm_unreachable("parameter was not an opened pack parameter");
634+
}
635+
636+
Type operator()(Type interfaceType) const {
637+
return env->mapTypeIntoContext(getInterfaceType(interfaceType));
638+
}
639+
};
640+
641+
}
642+
655643
/// So this expects a type written with the archetypes of the original generic
656644
/// environment, not 'this', the opened element environment, because it is the
657645
/// original PackArchetypes that become ElementArchetypes. Also this function

0 commit comments

Comments
 (0)