@@ -98,36 +98,48 @@ struct LoweredParamGenerator {
98
98
ParamDecl *paramDecl = nullptr ;
99
99
bool isNoImplicitCopy = false ;
100
100
LifetimeAnnotation lifetimeAnnotation = LifetimeAnnotation::None;
101
+ bool isImplicitParameter = false ;
101
102
102
103
void configureParamData (ParamDecl *paramDecl, bool isNoImplicitCopy,
103
104
LifetimeAnnotation lifetimeAnnotation) {
104
105
this ->paramDecl = paramDecl;
105
106
this ->isNoImplicitCopy = isNoImplicitCopy;
106
107
this ->lifetimeAnnotation = lifetimeAnnotation;
108
+ this ->isImplicitParameter = false ;
107
109
}
110
+
111
+ void configureParamDataForImplicitParam () { isImplicitParameter = true ; }
112
+
108
113
void resetParamData () {
109
114
configureParamData (nullptr , false , LifetimeAnnotation::None);
110
115
}
111
116
112
117
ManagedValue claimNext () {
113
118
auto parameterInfo = parameterTypes.claimNext ();
114
119
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
+ //
118
124
// TODO: preserve the parameters captured by the pack into the SIL
119
125
// representation.
120
- bool isFormalParameterPack = (paramDecl == nullptr );
126
+ bool isFormalParameterPack = (paramDecl == nullptr ) && !isImplicitParameter ;
121
127
assert (!isFormalParameterPack || parameterInfo.isPack ());
122
128
123
129
auto paramType =
124
130
SGF.F .mapTypeIntoContext (SGF.getSILType (parameterInfo, fnTy));
125
131
ManagedValue mv = SGF.B .createInputFunctionArgument (
126
132
paramType, paramDecl, isNoImplicitCopy, lifetimeAnnotation,
127
- /* isClosureCapture*/ false , isFormalParameterPack);
133
+ /* isClosureCapture*/ false , isFormalParameterPack, isImplicitParameter );
128
134
return mv;
129
135
}
130
136
137
+ std::optional<SILParameterInfo> peek () const {
138
+ if (isFinished ())
139
+ return {};
140
+ return parameterTypes.get ();
141
+ }
142
+
131
143
bool isFinished () const {
132
144
return parameterTypes.isFinished ();
133
145
}
@@ -655,6 +667,17 @@ class ArgumentInitHelper {
655
667
/* ignore final*/ false );
656
668
}
657
669
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
+
658
681
// Emit each of the function's explicit parameters in order.
659
682
if (paramList) {
660
683
for (auto *param : *paramList)
0 commit comments