Skip to content

Commit b83085b

Browse files
committed
[NFC] IRGen: Extracted function.
1 parent 3f6bd9d commit b83085b

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

lib/IRGen/Outlining.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,25 @@
3232
using namespace swift;
3333
using namespace irgen;
3434

35+
static GenericEnvironment *digOutGenericEnvironment(CanType loweredType) {
36+
// Find a non-local, non-opaque archetype in the type and pull out
37+
// its generic environment.
38+
// TODO: we ought to be able to usefully minimize this
39+
40+
GenericEnvironment *env = nullptr;
41+
loweredType.findIf([&env](CanType t) -> bool {
42+
if (auto arch = dyn_cast<ArchetypeType>(t)) {
43+
if (!isa<PrimaryArchetypeType>(arch) && !isa<PackArchetypeType>(arch))
44+
return false;
45+
env = arch->getGenericEnvironment();
46+
return true;
47+
}
48+
return false;
49+
});
50+
51+
return env;
52+
}
53+
3554
OutliningMetadataCollector::OutliningMetadataCollector(
3655
SILType T, IRGenFunction &IGF, LayoutIsNeeded_t needsLayout,
3756
DeinitIsNeeded_t needsDeinitTypes)
@@ -141,21 +160,8 @@ irgen::getTypeAndGenericSignatureForManglingOutlineFunction(SILType type) {
141160
auto loweredType = type.getASTType();
142161
if (!loweredType->hasArchetype()) return {loweredType, nullptr};
143162

144-
// Find a non-local, non-opaque archetype in the type and pull out
145-
// its generic environment.
146-
// TODO: we ought to be able to usefully minimize this
163+
GenericEnvironment *env = digOutGenericEnvironment(loweredType);
147164

148-
GenericEnvironment *env = nullptr;
149-
loweredType.findIf([&env](CanType t) -> bool {
150-
if (auto arch = dyn_cast<ArchetypeType>(t)) {
151-
if (!isa<PrimaryArchetypeType>(arch) &&
152-
!isa<PackArchetypeType>(arch))
153-
return false;
154-
env = arch->getGenericEnvironment();
155-
return true;
156-
}
157-
return false;
158-
});
159165
assert(env && "has archetype but no archetype?!");
160166
return {loweredType->mapTypeOutOfContext()->getCanonicalType(),
161167
env->getGenericSignature().getCanonicalSignature()};

0 commit comments

Comments
 (0)