Skip to content

Commit cb3bf10

Browse files
committed
[SILGen] Eliminate SubstitutionList from SILGenFunction::emitApply().
1 parent 9a0e57f commit cb3bf10

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3707,7 +3707,7 @@ CallEmission::applyNormalCall(SGFContext C) {
37073707
// Emit the uncurried call.
37083708
firstLevelResult.value = SGF.emitApply(
37093709
std::move(resultPlan), std::move(argScope), uncurriedLoc.getValue(), mv,
3710-
callee.getSubstitutions().toList(), uncurriedArgs, calleeTypeInfo, options,
3710+
callee.getSubstitutions(), uncurriedArgs, calleeTypeInfo, options,
37113711
uncurriedContext);
37123712
firstLevelResult.foreignSelf = calleeTypeInfo.foreignSelf;
37133713
return firstLevelResult;
@@ -4096,7 +4096,7 @@ CallEmission CallEmission::forApplyExpr(SILGenFunction &SGF, Expr *e) {
40964096
/// formal type.
40974097
RValue SILGenFunction::emitApply(ResultPlanPtr &&resultPlan,
40984098
ArgumentScope &&argScope, SILLocation loc,
4099-
ManagedValue fn, SubstitutionList subs,
4099+
ManagedValue fn, SubstitutionMap subs,
41004100
ArrayRef<ManagedValue> args,
41014101
const CalleeTypeInfo &calleeTypeInfo,
41024102
ApplyOptions options, SGFContext evalContext) {
@@ -4162,9 +4162,12 @@ RValue SILGenFunction::emitApply(ResultPlanPtr &&resultPlan,
41624162
loc.decodeDebugLoc(SGM.M.getASTContext().SourceMgr);
41634163
auto genericSig =
41644164
fn.getType().castTo<SILFunctionType>()->getGenericSignature();
4165-
auto subMap = genericSig->getSubstitutionMap(subs);
4165+
if (genericSig != subs.getGenericSignature()) {
4166+
subs = genericSig->getSubstitutionMap(subs.toList());
4167+
}
4168+
41664169
SILValue rawDirectResult = emitRawApply(
4167-
*this, loc, fn, subMap, args, substFnType, options, indirectResultAddrs);
4170+
*this, loc, fn, subs, args, substFnType, options, indirectResultAddrs);
41684171

41694172
// Pop the argument scope.
41704173
argScope.pop();
@@ -4456,13 +4459,13 @@ SILGenFunction::emitApplyOfLibraryIntrinsic(SILLocation loc,
44564459

44574460
SILFunctionConventions silConv(calleeTypeInfo.substFnType, getModule());
44584461
llvm::SmallVector<ManagedValue, 8> finalArgs;
4459-
convertOwnershipConventionsGivenParamInfos(*this, silConv.getParameters(), args, loc, finalArgs);
4462+
convertOwnershipConventionsGivenParamInfos(*this, silConv.getParameters(),
4463+
args, loc, finalArgs);
44604464

44614465
ResultPlanPtr resultPlan =
44624466
ResultPlanBuilder::computeResultPlan(*this, calleeTypeInfo, loc, ctx);
44634467
ArgumentScope argScope(*this, loc);
4464-
return emitApply(std::move(resultPlan), std::move(argScope), loc, mv,
4465-
subMap.toList(),
4468+
return emitApply(std::move(resultPlan), std::move(argScope), loc, mv, subMap,
44664469
finalArgs, calleeTypeInfo, ApplyOptions::None, ctx);
44674470
}
44684471

lib/SILGen/SILGenBridging.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,7 @@ emitBridgeObjectiveCToNative(SILGenFunction &SGF,
236236
ArgumentScope argScope(SGF, loc);
237237
RValue result =
238238
SGF.emitApply(std::move(resultPlan), std::move(argScope), loc,
239-
ManagedValue::forUnmanaged(witnessRef),
240-
subs.toList(),
239+
ManagedValue::forUnmanaged(witnessRef), subs,
241240
{objcValue, ManagedValue::forUnmanaged(metatypeValue)},
242241
calleeTypeInfo, ApplyOptions::None, context);
243242
return std::move(result).getAsSingleValue(SGF, loc);
@@ -1780,7 +1779,7 @@ void SILGenFunction::emitForeignToNativeThunk(SILDeclRef thunk) {
17801779
ArgumentScope argScope(*this, fd);
17811780
ManagedValue resultMV =
17821781
emitApply(std::move(resultPlan), std::move(argScope), fd,
1783-
ManagedValue::forUnmanaged(fn), subs.toList(), args,
1782+
ManagedValue::forUnmanaged(fn), subs, args,
17841783
calleeTypeInfo, ApplyOptions::None, context)
17851784
.getAsSingleValue(*this, fd);
17861785

lib/SILGen/SILGenExpr.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2649,7 +2649,7 @@ SILGenFunction::emitApplyOfDefaultArgGenerator(SILLocation loc,
26492649
ResultPlanBuilder::computeResultPlan(*this, calleeTypeInfo, loc, C);
26502650
ArgumentScope argScope(*this, loc);
26512651
return emitApply(std::move(resultPtr), std::move(argScope), loc, fnRef,
2652-
subs.toList(), {}, calleeTypeInfo, ApplyOptions::None, C);
2652+
subs, {}, calleeTypeInfo, ApplyOptions::None, C);
26532653
}
26542654

26552655
RValue SILGenFunction::emitApplyOfStoredPropertyInitializer(
@@ -2672,7 +2672,7 @@ RValue SILGenFunction::emitApplyOfStoredPropertyInitializer(
26722672
ResultPlanBuilder::computeResultPlan(*this, calleeTypeInfo, loc, C);
26732673
ArgumentScope argScope(*this, loc);
26742674
return emitApply(std::move(resultPlan), std::move(argScope), loc, fnRef,
2675-
subs.toList(), {}, calleeTypeInfo, ApplyOptions::None, C);
2675+
subs, {}, calleeTypeInfo, ApplyOptions::None, C);
26762676
}
26772677

26782678
static void emitTupleShuffleExprInto(RValueEmitter &emitter,
@@ -3550,7 +3550,7 @@ getOrCreateKeyPathEqualsAndHash(SILGenModule &SGM,
35503550
isEqual = subSGF
35513551
.emitApply(std::move(equalsResultPlan), std::move(argScope),
35523552
loc, ManagedValue::forUnmanaged(equalsWitness),
3553-
equatableSub.toList(),
3553+
equatableSub,
35543554
{lhsArg, rhsArg, metatyValue},
35553555
equalsInfo, ApplyOptions::None, SGFContext())
35563556
.getUnmanagedSingleValue(subSGF, loc);
@@ -3664,7 +3664,7 @@ getOrCreateKeyPathEqualsAndHash(SILGenModule &SGM,
36643664
auto hashWitness = subSGF.B.createWitnessMethod(loc,
36653665
formalTy, hashable,
36663666
hashRef, hashTy);
3667-
3667+
36683668
auto hashSubstTy = hashTy.castTo<SILFunctionType>()
36693669
->substGenericArgs(SGM.M, hashableSubsMap);
36703670
auto hashInfo = CalleeTypeInfo(hashSubstTy,
@@ -3690,7 +3690,7 @@ getOrCreateKeyPathEqualsAndHash(SILGenModule &SGM,
36903690
subSGF
36913691
.emitApply(std::move(hashResultPlan), std::move(argScope), loc,
36923692
ManagedValue::forUnmanaged(hashWitness),
3693-
hashableSubsMap.toList(),
3693+
hashableSubsMap,
36943694
{arg}, hashInfo, ApplyOptions::None, SGFContext())
36953695
.getUnmanagedSingleValue(subSGF, loc);
36963696
}

lib/SILGen/SILGenFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,7 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
12971297
/// result does need to be turned back into something matching a
12981298
/// formal type.
12991299
RValue emitApply(ResultPlanPtr &&resultPlan, ArgumentScope &&argScope,
1300-
SILLocation loc, ManagedValue fn, SubstitutionList subs,
1300+
SILLocation loc, ManagedValue fn, SubstitutionMap subs,
13011301
ArrayRef<ManagedValue> args,
13021302
const CalleeTypeInfo &calleeTypeInfo, ApplyOptions options,
13031303
SGFContext evalContext);

0 commit comments

Comments
 (0)