@@ -3412,11 +3412,18 @@ Expr *ArgumentSource::findStorageReferenceExprForBorrow() && {
34123412namespace {
34133413
34143414class ArgEmitter {
3415+ public:
3416+ enum Flag {
3417+ IsYield = 0x1 ,
3418+ IsForCoroutine = 0x2 ,
3419+ };
3420+ using OptionSet = OptionSet<Flag>;
3421+
3422+ private:
34153423 SILGenFunction &SGF;
34163424 SILLocation ApplyLoc;
34173425 SILFunctionTypeRepresentation Rep;
3418- bool IsYield;
3419- bool IsForCoroutine;
3426+ OptionSet Options;
34203427 ForeignInfo Foreign;
34213428 ClaimedParamsRef ParamInfos;
34223429 SmallVectorImpl<ManagedValue> &Args;
@@ -3427,13 +3434,11 @@ class ArgEmitter {
34273434
34283435public:
34293436 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,
34333439 SmallVectorImpl<DelayedArgument> &delayedArgs,
34343440 const ForeignInfo &foreign)
3435- : SGF(SGF), ApplyLoc(applyLoc),
3436- Rep (Rep), IsYield(isYield), IsForCoroutine(isForCoroutine),
3441+ : SGF(SGF), ApplyLoc(applyLoc), Rep(Rep), Options(options),
34373442 Foreign (foreign), ParamInfos(paramInfos), Args(args),
34383443 DelayedArguments(delayedArgs) {}
34393444
@@ -3559,7 +3564,7 @@ class ArgEmitter {
35593564 // If we have a guaranteed +0 parameter...
35603565 if (param.isGuaranteedInCaller () || isShared) {
35613566 // And this is a yield, emit a borrowed r-value.
3562- if (IsYield) {
3567+ if (Options. contains (Flag:: IsYield) ) {
35633568 if (tryEmitBorrowed (std::move (arg), loweredSubstArgType,
35643569 loweredSubstParamType, origParamType, paramSlice))
35653570 return ;
@@ -3610,7 +3615,7 @@ class ArgEmitter {
36103615
36113616 // Handle yields of storage reference expressions specially so that we
36123617 // don't emit them as +1 r-values and then expand.
3613- if (IsYield) {
3618+ if (Options. contains (Flag:: IsYield) ) {
36143619 if (auto result = std::move (arg).findStorageReferenceExprForBorrow ()) {
36153620 emitExpandedBorrowed (result, origParamType);
36163621 return ;
@@ -3858,7 +3863,8 @@ class ArgEmitter {
38583863
38593864 auto convertOwnershipConvention = [&](ManagedValue value) {
38603865 return convertOwnershipConventionGivenParamInfo (
3861- SGF, param, origParam, value, loc, IsForCoroutine);
3866+ SGF, param, origParam, value, loc,
3867+ Options.contains (Flag::IsForCoroutine));
38623868 };
38633869
38643870 auto contexts = getRValueEmissionContexts (loweredSubstArgType, param);
@@ -4423,10 +4429,9 @@ void DelayedArgument::emitDefaultArgument(SILGenFunction &SGF,
44234429
44244430 SmallVector<ManagedValue, 4 > loweredArgs;
44254431 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{});
44304435
44314436 emitter.emitSingleArg (ArgumentSource (info.loc , std::move (value)),
44324437 info.origResultType );
@@ -4818,9 +4823,11 @@ class CallSite {
48184823 const ForeignInfo &foreign) && {
48194824 auto params = lowering.claimParams (origFormalType, getParams (), foreign);
48204825
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);
48244831 emitter.emitPreparedArgs (std::move (Args), origFormalType);
48254832 }
48264833
@@ -6069,8 +6076,8 @@ void SILGenFunction::emitYield(SILLocation loc,
60696076 origYield.getConvention ()});
60706077 }
60716078
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),
60746081 yieldArgs, delayedArgs, ForeignInfo{});
60756082
60766083 for (auto i : indices (valueSources)) {
@@ -7077,10 +7084,9 @@ static void emitPseudoFunctionArguments(SILGenFunction &SGF,
70777084 SmallVector<ManagedValue, 4 > argValues;
70787085 SmallVector<DelayedArgument, 2 > delayedArgs;
70797086
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{});
70847090
70857091 emitter.emitPreparedArgs (std::move (args), origFnType);
70867092
@@ -7765,9 +7771,7 @@ SmallVector<ManagedValue, 4> SILGenFunction::emitKeyPathSubscriptOperands(
77657771
77667772 SmallVector<ManagedValue, 4 > argValues;
77677773 SmallVector<DelayedArgument, 2 > delayedArgs;
7768- ArgEmitter emitter (*this , loc, fnType->getRepresentation (),
7769- /* yield*/ false ,
7770- /* isForCoroutine*/ false ,
7774+ ArgEmitter emitter (*this , loc, fnType->getRepresentation (), {},
77717775 ClaimedParamsRef (fnType->getParameters ()), argValues,
77727776 delayedArgs, ForeignInfo{});
77737777
0 commit comments