Skip to content

Commit 575597d

Browse files
committed
AST: Use TypeTransform::transformSubMap() to transform SILFunctionType
1 parent bbea8ec commit 575597d

File tree

2 files changed

+13
-37
lines changed

2 files changed

+13
-37
lines changed

include/swift/AST/TypeTransform.h

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -193,33 +193,21 @@ case TypeKind::Id:
193193

194194
case TypeKind::SILFunction: {
195195
auto fnTy = cast<SILFunctionType>(base);
196-
bool changed = false;
197-
auto updateSubs = [&](SubstitutionMap &subs) -> bool {
198-
// This interface isn't suitable for doing most transformations on
199-
// a substituted SILFunctionType, but it's too hard to come up with
200-
// an assertion that meaningfully captures what restrictions are in
201-
// place. Generally the restriction that you can't naively substitute
202-
// a SILFunctionType using AST mechanisms will have to be good enough.
203-
SmallVector<Type, 4> newReplacements;
204-
for (Type type : subs.getReplacementTypes()) {
205-
auto transformed = doIt(type, TypePosition::Invariant);
206-
newReplacements.push_back(transformed->getCanonicalType());
207-
if (!type->isEqual(transformed))
208-
changed = true;
209-
}
210-
211-
if (changed) {
212-
subs = SubstitutionMap::get(subs.getGenericSignature(),
213-
newReplacements,
214-
subs.getConformances());
215-
}
216-
217-
return changed;
218-
};
219196

220197
if (fnTy->isPolymorphic())
221198
return fnTy;
222199

200+
auto updateSubs = [&](SubstitutionMap &subs) -> bool {
201+
auto newSubs = asDerived().transformSubMap(subs);
202+
if (subs && !newSubs)
203+
return false;
204+
if (subs == newSubs)
205+
return false;
206+
207+
subs = newSubs;
208+
return true;
209+
};
210+
223211
if (auto subs = fnTy->getInvocationSubstitutions()) {
224212
if (updateSubs(subs)) {
225213
return fnTy->withInvocationSubstitutions(subs);
@@ -234,6 +222,8 @@ case TypeKind::Id:
234222
return fnTy;
235223
}
236224

225+
bool changed = false;
226+
237227
SmallVector<SILParameterInfo, 8> transInterfaceParams;
238228
for (SILParameterInfo param : fnTy->getParameters()) {
239229
if (transformSILParameter(pos.flipped(), param, changed))

lib/AST/TypeSubstitution.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -513,20 +513,6 @@ TypeSubstituter::transform(TypeBase *type, TypePosition position) {
513513
return Type(PackType::get(packExpansionTy->getASTContext(), eltTys));
514514
}
515515

516-
if (auto silFnTy = dyn_cast<SILFunctionType>(type)) {
517-
if (silFnTy->isPolymorphic())
518-
return std::nullopt;
519-
if (auto subs = silFnTy->getInvocationSubstitutions()) {
520-
auto newSubs = subs.subst(IFS);
521-
return silFnTy->withInvocationSubstitutions(newSubs);
522-
}
523-
if (auto subs = silFnTy->getPatternSubstitutions()) {
524-
auto newSubs = subs.subst(IFS);
525-
return silFnTy->withPatternSubstitutions(newSubs);
526-
}
527-
return std::nullopt;
528-
}
529-
530516
auto oldLevel = level;
531517
SWIFT_DEFER { level = oldLevel; };
532518

0 commit comments

Comments
 (0)