Skip to content

Commit 2e4ad65

Browse files
committed
[NFC] Change forEachFunctionParam to only ignore the final orig parameter
and not also drop a subst parameter. This turned out to be more convenient for certain clients (e.g. SILGenPoly) than requiring the full subst param list to be passed in. These clients want to process the subst param list separately, and dropping self early can be convenient for that. The only fundamental reason we need this flag is for working with the orig type, so just use it for that; clients that need to use this feature can reasonably be expected to cooperate.
1 parent 2172c0a commit 2e4ad65

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

include/swift/SIL/AbstractionPatternGenerators.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class FunctionParamGenerator {
8181
public:
8282
FunctionParamGenerator(AbstractionPattern origFunctionType,
8383
AnyFunctionType::CanParamArrayRef substParams,
84-
bool ignoreFinalParam);
84+
bool ignoreFinalOrigParam);
8585

8686
/// Is the traversal finished? If so, none of the getters below
8787
/// are allowed to be called.

lib/SIL/IR/AbstractionPattern.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ unsigned AbstractionPattern::getNumFunctionParams() const {
12031203

12041204
void AbstractionPattern::
12051205
forEachFunctionParam(AnyFunctionType::CanParamArrayRef substParams,
1206-
bool ignoreFinalParam,
1206+
bool ignoreFinalOrigParam,
12071207
llvm::function_ref<void(unsigned origParamIndex,
12081208
unsigned substParamIndex,
12091209
ParameterTypeFlags origFlags,
@@ -1216,7 +1216,7 @@ forEachFunctionParam(AnyFunctionType::CanParamArrayRef substParams,
12161216
AbstractionPattern origExpansionType,
12171217
AnyFunctionType::CanParamArrayRef substParams)>
12181218
handleExpansion) const {
1219-
FunctionParamGenerator generator(*this, substParams, ignoreFinalParam);
1219+
FunctionParamGenerator generator(*this, substParams, ignoreFinalOrigParam);
12201220

12211221
for (; !generator.isFinished(); generator.advance()) {
12221222
if (generator.isPackExpansion()) {
@@ -1239,7 +1239,7 @@ forEachFunctionParam(AnyFunctionType::CanParamArrayRef substParams,
12391239
FunctionParamGenerator::FunctionParamGenerator(
12401240
AbstractionPattern origFunctionType,
12411241
AnyFunctionType::CanParamArrayRef substParams,
1242-
bool ignoreFinalParam)
1242+
bool ignoreFinalOrigParam)
12431243
: origFunctionType(origFunctionType), allSubstParams(substParams) {
12441244
origFunctionTypeIsOpaque =
12451245
(origFunctionType.isTypeParameterOrOpaqueArchetype() ||
@@ -1249,11 +1249,8 @@ FunctionParamGenerator::FunctionParamGenerator(
12491249
numOrigParams = allSubstParams.size();
12501250
} else {
12511251
numOrigParams = origFunctionType.getNumFunctionParams();
1252-
}
1253-
1254-
if (ignoreFinalParam) {
1255-
allSubstParams = allSubstParams.drop_back();
1256-
numOrigParams--;
1252+
if (ignoreFinalOrigParam)
1253+
numOrigParams--;
12571254
}
12581255

12591256
if (!isFinished()) loadParameter();

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1569,7 +1569,8 @@ class DestructureInputs {
15691569
maybeAddForeignParameters();
15701570

15711571
// Process all the non-self parameters.
1572-
origType.forEachFunctionParam(params, hasSelf,
1572+
origType.forEachFunctionParam(params.drop_back(hasSelf ? 1 : 0),
1573+
/*ignore final orig param*/ hasSelf,
15731574
[&](unsigned origParamIndex, unsigned substParamIndex,
15741575
ParameterTypeFlags origFlags,
15751576
AbstractionPattern origParamType,

0 commit comments

Comments
 (0)