Skip to content

Commit 9e8acbe

Browse files
committed
SILGen: ArgEmitter::forward() should return PreparedArguments and not an ArgumentSource
1 parent 17684d0 commit 9e8acbe

File tree

2 files changed

+44
-27
lines changed

2 files changed

+44
-27
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4095,9 +4095,8 @@ class CallSite {
40954095
}
40964096

40974097
/// Take the arguments for special processing, in place of the above.
4098-
ArgumentSource &&forward() && {
4099-
assert(Args.isScalar());
4100-
return std::move(std::move(Args).getSources()[0]);
4098+
PreparedArguments &&forward() && {
4099+
return std::move(Args);
41014100
}
41024101
};
41034102

@@ -4483,6 +4482,12 @@ CallEmission::applyNormalCall(SGFContext C) {
44834482
return firstLevelResult;
44844483
}
44854484

4485+
static void emitPseudoFunctionArguments(SILGenFunction &SGF,
4486+
AbstractionPattern origFnType,
4487+
CanFunctionType substFnType,
4488+
SmallVectorImpl<ManagedValue> &outVals,
4489+
PreparedArguments &&args);
4490+
44864491
CallEmission::FirstLevelApplicationResult
44874492
CallEmission::applyEnumElementConstructor(SGFContext C) {
44884493
FirstLevelApplicationResult firstLevelResult;
@@ -4507,18 +4512,32 @@ CallEmission::applyEnumElementConstructor(SGFContext C) {
45074512
CanType formalResultType = firstLevelResult.formalType.getResult();
45084513

45094514
// Ignore metatype argument
4515+
SmallVector<ManagedValue, 0> metatypeVal;
4516+
emitPseudoFunctionArguments(SGF,
4517+
AbstractionPattern(firstLevelResult.formalType),
4518+
firstLevelResult.formalType, metatypeVal,
4519+
std::move(uncurriedSites[0]).forward());
4520+
assert(metatypeVal.size() == 1);
4521+
45104522
origFormalType = origFormalType.getFunctionResultType();
45114523
claimNextParamClause(firstLevelResult.formalType);
4512-
std::move(uncurriedSites[0]).forward().getAsSingleValue(SGF);
45134524

45144525
// Get the payload argument.
45154526
ArgumentSource payload;
45164527
if (element->hasAssociatedValues()) {
45174528
assert(uncurriedSites.size() == 2);
45184529
SmallVector<ManagedValue, 4> argVals;
45194530
auto resultFnType = cast<FunctionType>(formalResultType);
4520-
auto arg = SGF.prepareEnumPayload(element, resultFnType,
4521-
std::move(uncurriedSites[1]).forward());
4531+
4532+
emitPseudoFunctionArguments(SGF,
4533+
AbstractionPattern(resultFnType),
4534+
resultFnType, argVals,
4535+
std::move(uncurriedSites[1]).forward());
4536+
4537+
auto payloadTy = AnyFunctionType::composeInput(SGF.getASTContext(),
4538+
resultFnType.getParams(),
4539+
/*canonicalVararg*/ true);
4540+
auto arg = RValue(SGF, argVals, payloadTy->getCanonicalType());
45224541
payload = ArgumentSource(element, std::move(arg));
45234542
formalResultType = firstLevelResult.formalType.getResult();
45244543
origFormalType = origFormalType.getFunctionResultType();
@@ -4640,7 +4659,10 @@ CallEmission::applySpecializedEmitter(SpecializedEmitter &specializedEmitter,
46404659

46414660
// We should be able to enforce that these arguments are
46424661
// always still expressions.
4643-
Expr *argument = std::move(uncurriedSites[0]).forward().asKnownExpr();
4662+
PreparedArguments args = std::move(uncurriedSites[0]).forward();
4663+
assert(args.isScalar());
4664+
Expr *argument = std::move(std::move(args).getSources()[0]).asKnownExpr();
4665+
46444666
ManagedValue resultMV =
46454667
emitter(SGF, uncurriedLoc, callee.getSubstitutions(),
46464668
argument, uncurriedContext);
@@ -5982,9 +6004,10 @@ static void collectFakeIndexParameters(SILGenFunction &SGF,
59826004
}
59836005

59846006
static void emitPseudoFunctionArguments(SILGenFunction &SGF,
6007+
AbstractionPattern origFnType,
59856008
CanFunctionType substFnType,
59866009
SmallVectorImpl<ManagedValue> &outVals,
5987-
ArgumentSource &&source) {
6010+
PreparedArguments &&args) {
59886011
auto substParams = substFnType->getParams();
59896012

59906013
SmallVector<SILParameterInfo, 4> substParamTys;
@@ -6002,7 +6025,7 @@ static void emitPseudoFunctionArguments(SILGenFunction &SGF,
60026025
argValues, delayedArgs,
60036026
/*foreign error*/ None, ImportAsMemberStatus());
60046027

6005-
emitter.emitTopLevel(std::move(source), AbstractionPattern(substFnType));
6028+
emitter.emitPreparedArgs(std::move(args), origFnType);
60066029

60076030
// TODO: do something to preserve LValues in the delayed arguments?
60086031
if (!delayedArgs.empty())
@@ -6034,11 +6057,22 @@ SILGenFunction::prepareSubscriptIndices(SubscriptDecl *subscript,
60346057
substFnType = cast<FunctionType>(interfaceType
60356058
->getCanonicalType());
60366059

6060+
6061+
AbstractionPattern origFnType(substFnType);
6062+
6063+
// Prepare the unevaluated index expression.
60376064
auto substParams = substFnType->getParams();
6065+
PreparedArguments args(substParams, /*isScalar=*/true);
6066+
args.addArbitrary(indexExpr);
60386067

6068+
// Now, force it to be evaluated.
60396069
SmallVector<ManagedValue, 4> argValues;
6040-
emitPseudoFunctionArguments(*this, substFnType, argValues, indexExpr);
6070+
emitPseudoFunctionArguments(*this, origFnType, substFnType,
6071+
argValues, std::move(args));
60416072

6073+
// Finally, prepare the evaluated index expression. We might be calling
6074+
// the getter and setter, and it is important to only evaluate the
6075+
// index expression once.
60426076
PreparedArguments result(substParams, /*isScalar=*/false);
60436077

60446078
ArrayRef<ManagedValue> remainingArgs = argValues;
@@ -6055,19 +6089,6 @@ SILGenFunction::prepareSubscriptIndices(SubscriptDecl *subscript,
60556089
return result;
60566090
}
60576091

6058-
RValue
6059-
SILGenFunction::prepareEnumPayload(EnumElementDecl *element,
6060-
CanFunctionType substFnType,
6061-
ArgumentSource &&args) {
6062-
SmallVector<ManagedValue, 4> argValues;
6063-
emitPseudoFunctionArguments(*this, substFnType, argValues, std::move(args));
6064-
6065-
auto payloadTy = AnyFunctionType::composeInput(getASTContext(),
6066-
substFnType.getParams(),
6067-
/*canonicalVararg*/ true);
6068-
return RValue(*this, argValues, payloadTy->getCanonicalType());
6069-
}
6070-
60716092
SILDeclRef SILGenModule::getAccessorDeclRef(AccessorDecl *accessor) {
60726093
return SILDeclRef(accessor, SILDeclRef::Kind::Func)
60736094
.asForeign(requiresForeignEntryPoint(accessor));

lib/SILGen/SILGenFunction.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,10 +1210,6 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
12101210
AccessStrategy strategy,
12111211
Expr *indices);
12121212

1213-
RValue prepareEnumPayload(EnumElementDecl *element,
1214-
CanFunctionType substFnType,
1215-
ArgumentSource &&indexExpr);
1216-
12171213
ArgumentSource prepareAccessorBaseArg(SILLocation loc, ManagedValue base,
12181214
CanType baseFormalType,
12191215
SILDeclRef accessor);

0 commit comments

Comments
 (0)