Skip to content

Commit 209bfd0

Browse files
committed
Break argument checking out of a lambda and add comments
1 parent 1347929 commit 209bfd0

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -924,28 +924,32 @@ SILInstruction *SILCombiner::createApplyWithConcreteType(
924924
});
925925
}
926926

927-
bool canUpdateArgs, madeUpdate;
928-
std::tie(canUpdateArgs, madeUpdate) = [&]() {
929-
auto substTy =
930-
Apply.getCallee()
931-
->getType()
932-
.substGenericArgs(Apply.getModule(), NewCallSubs,
933-
Apply.getFunction()->getTypeExpansionContext())
934-
.getAs<SILFunctionType>();
935-
SILFunctionConventions conv(substTy,
936-
SILModuleConventions(Apply.getModule()));
937-
bool canUpdate = true;
938-
// Keep track of weather we made any updates at all. Otherwise, we will
939-
// have an infinite loop.
940-
bool madeUpdate = false;
941-
for (unsigned index = 0; index < conv.getNumSILArguments(); ++index) {
942-
canUpdate &= conv.getSILArgumentType(index) == NewArgs[index]->getType();
943-
madeUpdate |=
944-
NewArgs[index]->getType() != Apply.getArgument(index)->getType();
945-
}
946-
return std::make_tuple(canUpdate, madeUpdate);
947-
}();
927+
// We need to make sure that we can a) update Apply to use the new args and b)
928+
// at least one argument has changed. If no arguments have changed, we need
929+
// to return nullptr. Otherwise, we will have an infinite loop.
930+
auto substTy =
931+
Apply.getCallee()
932+
->getType()
933+
.substGenericArgs(Apply.getModule(), NewCallSubs,
934+
Apply.getFunction()->getTypeExpansionContext())
935+
.getAs<SILFunctionType>();
936+
SILFunctionConventions conv(substTy,
937+
SILModuleConventions(Apply.getModule()));
938+
bool canUpdateArgs = true;
939+
bool madeUpdate = false;
940+
for (unsigned index = 0; index < conv.getNumSILArguments(); ++index) {
941+
// Make sure that *all* the arguments in both the new substitution function
942+
// and our vector of new arguments have the same type.
943+
canUpdateArgs &=
944+
conv.getSILArgumentType(index) == NewArgs[index]->getType();
945+
// Make sure that we have changed at least one argument.
946+
madeUpdate |=
947+
NewArgs[index]->getType() != Apply.getArgument(index)->getType();
948+
}
948949

950+
// If we can't update the args (because of a type mismatch) or the args don't
951+
// change, bail out by removing the instructions we've added and returning
952+
// nullptr.
949953
if (!canUpdateArgs || !madeUpdate) {
950954
// Remove any new instructions created while attempting to optimize this
951955
// apply. Since the apply was never rewritten, if they aren't removed here,

0 commit comments

Comments
 (0)