@@ -3412,11 +3412,18 @@ Expr *ArgumentSource::findStorageReferenceExprForBorrow() && {
3412
3412
namespace {
3413
3413
3414
3414
class ArgEmitter {
3415
+ public:
3416
+ enum Flag {
3417
+ IsYield = 0x1 ,
3418
+ IsForCoroutine = 0x2 ,
3419
+ };
3420
+ using OptionSet = OptionSet<Flag>;
3421
+
3422
+ private:
3415
3423
SILGenFunction &SGF;
3416
3424
SILLocation ApplyLoc;
3417
3425
SILFunctionTypeRepresentation Rep;
3418
- bool IsYield;
3419
- bool IsForCoroutine;
3426
+ OptionSet Options;
3420
3427
ForeignInfo Foreign;
3421
3428
ClaimedParamsRef ParamInfos;
3422
3429
SmallVectorImpl<ManagedValue> &Args;
@@ -3427,13 +3434,11 @@ class ArgEmitter {
3427
3434
3428
3435
public:
3429
3436
ArgEmitter (SILGenFunction &SGF, SILLocation applyLoc,
3430
- SILFunctionTypeRepresentation Rep,
3431
- bool isYield, bool isForCoroutine, ClaimedParamsRef paramInfos,
3432
- SmallVectorImpl<ManagedValue> &args,
3437
+ SILFunctionTypeRepresentation Rep, OptionSet options,
3438
+ ClaimedParamsRef paramInfos, SmallVectorImpl<ManagedValue> &args,
3433
3439
SmallVectorImpl<DelayedArgument> &delayedArgs,
3434
3440
const ForeignInfo &foreign)
3435
- : SGF(SGF), ApplyLoc(applyLoc),
3436
- Rep (Rep), IsYield(isYield), IsForCoroutine(isForCoroutine),
3441
+ : SGF(SGF), ApplyLoc(applyLoc), Rep(Rep), Options(options),
3437
3442
Foreign (foreign), ParamInfos(paramInfos), Args(args),
3438
3443
DelayedArguments(delayedArgs) {}
3439
3444
@@ -3559,7 +3564,7 @@ class ArgEmitter {
3559
3564
// If we have a guaranteed +0 parameter...
3560
3565
if (param.isGuaranteedInCaller () || isShared) {
3561
3566
// And this is a yield, emit a borrowed r-value.
3562
- if (IsYield) {
3567
+ if (Options. contains (Flag:: IsYield) ) {
3563
3568
if (tryEmitBorrowed (std::move (arg), loweredSubstArgType,
3564
3569
loweredSubstParamType, origParamType, paramSlice))
3565
3570
return ;
@@ -3610,7 +3615,7 @@ class ArgEmitter {
3610
3615
3611
3616
// Handle yields of storage reference expressions specially so that we
3612
3617
// don't emit them as +1 r-values and then expand.
3613
- if (IsYield) {
3618
+ if (Options. contains (Flag:: IsYield) ) {
3614
3619
if (auto result = std::move (arg).findStorageReferenceExprForBorrow ()) {
3615
3620
emitExpandedBorrowed (result, origParamType);
3616
3621
return ;
@@ -3858,7 +3863,8 @@ class ArgEmitter {
3858
3863
3859
3864
auto convertOwnershipConvention = [&](ManagedValue value) {
3860
3865
return convertOwnershipConventionGivenParamInfo (
3861
- SGF, param, origParam, value, loc, IsForCoroutine);
3866
+ SGF, param, origParam, value, loc,
3867
+ Options.contains (Flag::IsForCoroutine));
3862
3868
};
3863
3869
3864
3870
auto contexts = getRValueEmissionContexts (loweredSubstArgType, param);
@@ -4423,10 +4429,9 @@ void DelayedArgument::emitDefaultArgument(SILGenFunction &SGF,
4423
4429
4424
4430
SmallVector<ManagedValue, 4 > loweredArgs;
4425
4431
SmallVector<DelayedArgument, 4 > delayedArgs;
4426
- auto emitter = ArgEmitter (SGF, info.loc , info.functionRepresentation ,
4427
- /* yield*/ false , /* coroutine*/ false ,
4428
- info.paramsToEmit , loweredArgs,
4429
- delayedArgs, ForeignInfo{});
4432
+ auto emitter =
4433
+ ArgEmitter (SGF, info.loc , info.functionRepresentation , {},
4434
+ info.paramsToEmit , loweredArgs, delayedArgs, ForeignInfo{});
4430
4435
4431
4436
emitter.emitSingleArg (ArgumentSource (info.loc , std::move (value)),
4432
4437
info.origResultType );
@@ -4818,9 +4823,11 @@ class CallSite {
4818
4823
const ForeignInfo &foreign) && {
4819
4824
auto params = lowering.claimParams (origFormalType, getParams (), foreign);
4820
4825
4821
- ArgEmitter emitter (SGF, Loc, lowering.Rep , /* yield*/ false ,
4822
- /* isForCoroutine*/ substFnType->isCoroutine (), params,
4823
- args, delayedArgs, foreign);
4826
+ ArgEmitter::OptionSet options;
4827
+ if (substFnType->isCoroutine ())
4828
+ options |= ArgEmitter::IsForCoroutine;
4829
+ ArgEmitter emitter (SGF, Loc, lowering.Rep , options, params, args,
4830
+ delayedArgs, foreign);
4824
4831
emitter.emitPreparedArgs (std::move (Args), origFormalType);
4825
4832
}
4826
4833
@@ -6069,8 +6076,8 @@ void SILGenFunction::emitYield(SILLocation loc,
6069
6076
origYield.getConvention ()});
6070
6077
}
6071
6078
6072
- ArgEmitter emitter (*this , loc, fnType->getRepresentation (), /* yield */ true ,
6073
- /* isForCoroutine */ false , ClaimedParamsRef (substYieldTys),
6079
+ ArgEmitter emitter (*this , loc, fnType->getRepresentation (),
6080
+ ArgEmitter::IsYield , ClaimedParamsRef (substYieldTys),
6074
6081
yieldArgs, delayedArgs, ForeignInfo{});
6075
6082
6076
6083
for (auto i : indices (valueSources)) {
@@ -7077,10 +7084,9 @@ static void emitPseudoFunctionArguments(SILGenFunction &SGF,
7077
7084
SmallVector<ManagedValue, 4 > argValues;
7078
7085
SmallVector<DelayedArgument, 2 > delayedArgs;
7079
7086
7080
- ArgEmitter emitter (SGF, applyLoc, SILFunctionTypeRepresentation::Thin,
7081
- /* yield*/ false ,
7082
- /* isForCoroutine*/ false , ClaimedParamsRef (substParamTys),
7083
- argValues, delayedArgs, ForeignInfo{});
7087
+ ArgEmitter emitter (SGF, applyLoc, SILFunctionTypeRepresentation::Thin, {},
7088
+ ClaimedParamsRef (substParamTys), argValues, delayedArgs,
7089
+ ForeignInfo{});
7084
7090
7085
7091
emitter.emitPreparedArgs (std::move (args), origFnType);
7086
7092
@@ -7765,9 +7771,7 @@ SmallVector<ManagedValue, 4> SILGenFunction::emitKeyPathSubscriptOperands(
7765
7771
7766
7772
SmallVector<ManagedValue, 4 > argValues;
7767
7773
SmallVector<DelayedArgument, 2 > delayedArgs;
7768
- ArgEmitter emitter (*this , loc, fnType->getRepresentation (),
7769
- /* yield*/ false ,
7770
- /* isForCoroutine*/ false ,
7774
+ ArgEmitter emitter (*this , loc, fnType->getRepresentation (), {},
7771
7775
ClaimedParamsRef (fnType->getParameters ()), argValues,
7772
7776
delayedArgs, ForeignInfo{});
7773
7777
0 commit comments