@@ -98,36 +98,48 @@ struct LoweredParamGenerator {
9898 ParamDecl *paramDecl = nullptr ;
9999 bool isNoImplicitCopy = false ;
100100 LifetimeAnnotation lifetimeAnnotation = LifetimeAnnotation::None;
101+ bool isImplicitParameter = false ;
101102
102103 void configureParamData (ParamDecl *paramDecl, bool isNoImplicitCopy,
103104 LifetimeAnnotation lifetimeAnnotation) {
104105 this ->paramDecl = paramDecl;
105106 this ->isNoImplicitCopy = isNoImplicitCopy;
106107 this ->lifetimeAnnotation = lifetimeAnnotation;
108+ this ->isImplicitParameter = false ;
107109 }
110+
111+ void configureParamDataForImplicitParam () { isImplicitParameter = true ; }
112+
108113 void resetParamData () {
109114 configureParamData (nullptr , false , LifetimeAnnotation::None);
110115 }
111116
112117 ManagedValue claimNext () {
113118 auto parameterInfo = parameterTypes.claimNext ();
114119
115- // We should only be called without a param decl when pulling
116- // pack parameters out for multiple formal parameters (or a single
117- // formal parameter pack).
120+ // We should only be called without a param decl when pulling pack
121+ // parameters out for multiple formal parameters (or a single formal
122+ // parameter pack) or if we have an implicit parameter.
123+ //
118124 // TODO: preserve the parameters captured by the pack into the SIL
119125 // representation.
120- bool isFormalParameterPack = (paramDecl == nullptr );
126+ bool isFormalParameterPack = (paramDecl == nullptr ) && !isImplicitParameter ;
121127 assert (!isFormalParameterPack || parameterInfo.isPack ());
122128
123129 auto paramType =
124130 SGF.F .mapTypeIntoContext (SGF.getSILType (parameterInfo, fnTy));
125131 ManagedValue mv = SGF.B .createInputFunctionArgument (
126132 paramType, paramDecl, isNoImplicitCopy, lifetimeAnnotation,
127- /* isClosureCapture*/ false , isFormalParameterPack);
133+ /* isClosureCapture*/ false , isFormalParameterPack, isImplicitParameter );
128134 return mv;
129135 }
130136
137+ std::optional<SILParameterInfo> peek () const {
138+ if (isFinished ())
139+ return {};
140+ return parameterTypes.get ();
141+ }
142+
131143 bool isFinished () const {
132144 return parameterTypes.isFinished ();
133145 }
@@ -655,6 +667,17 @@ class ArgumentInitHelper {
655667 /* ignore final*/ false );
656668 }
657669
670+ // Go through all of our implicit SIL parameters and emit them. These do not
671+ // exist in the AST and always appear in between the results and the
672+ // explicit parameters.
673+ while (auto param = loweredParams.peek ()) {
674+ if (!param->hasOption (SILParameterInfo::ImplicitLeading))
675+ break ;
676+ loweredParams.configureParamDataForImplicitParam ();
677+ loweredParams.advance ();
678+ loweredParams.resetParamData ();
679+ }
680+
658681 // Emit each of the function's explicit parameters in order.
659682 if (paramList) {
660683 for (auto *param : *paramList)
0 commit comments