@@ -162,6 +162,33 @@ namespace {
162
162
// / for generics.
163
163
enum UnrestrictedGenericParam { _unrestricted };
164
164
165
+ // / A synthesizer which generates a conformance requirement.
166
+ template <class TypeS , class ProtocolS >
167
+ struct ConformsToSynthesizer {
168
+ TypeS Type;
169
+ ProtocolS Protocol;
170
+ };
171
+ template <class TypeS , class ProtocolS >
172
+ constexpr ConformsToSynthesizer<TypeS, ProtocolS>
173
+ _conformsTo (TypeS type, ProtocolS protocol) {
174
+ return {type, protocol};
175
+ }
176
+
177
+ // / A synthesizer which generates a layout constraint requirement.
178
+ template <class TypeS >
179
+ struct LayoutConstraintSynthesizer {
180
+ TypeS Type;
181
+ LayoutConstraint Constraint;
182
+ };
183
+ template <class TypeS >
184
+ LayoutConstraintSynthesizer<TypeS>
185
+ _layout (TypeS type, LayoutConstraint constraint) {
186
+ return {type, constraint};
187
+ }
188
+ static LayoutConstraint _classLayout () {
189
+ return LayoutConstraint::getLayoutConstraint (LayoutConstraintKind::Class);
190
+ }
191
+
165
192
// / A synthesizer which generates a generic parameter list.
166
193
template <class ... ParamS>
167
194
struct GenericParamListSynthesizer {
@@ -179,6 +206,16 @@ struct CountGenericParameters {
179
206
void operator ()(UnrestrictedGenericParam _) const {
180
207
Count++;
181
208
}
209
+
210
+ template <class TypeS , class ProtoS >
211
+ void operator ()(const ConformsToSynthesizer<TypeS, ProtoS> &_) const {
212
+ // not a parameter
213
+ }
214
+
215
+ template <class TypeS >
216
+ void operator ()(const LayoutConstraintSynthesizer<TypeS> &_) const {
217
+ // not a parameter
218
+ }
182
219
};
183
220
184
221
} // end anonymous namespace
@@ -240,15 +277,30 @@ struct CollectGenericParams {
240
277
}
241
278
}
242
279
243
- void operator ()(UnrestrictedGenericParam _) const {}
280
+ void operator ()(UnrestrictedGenericParam _) {}
281
+
282
+ template <class TypeS , class ProtoS >
283
+ void operator ()(const ConformsToSynthesizer<TypeS, ProtoS> &conf) {
284
+ auto type = synthesizeType (SC, conf.Type );
285
+ auto protocolType = synthesizeType (SC, conf.Protocol );
286
+ AddedRequirements.push_back ({RequirementKind::Conformance,
287
+ type, protocolType});
288
+ }
289
+
290
+ template <class TypeS >
291
+ void operator ()(const LayoutConstraintSynthesizer<TypeS> &req) {
292
+ auto type = synthesizeType (SC, req.Type );
293
+ AddedRequirements.push_back ({RequirementKind::Layout,
294
+ type, req.Constraint });
295
+ }
244
296
};
245
297
246
298
} // end anonymous namespace
247
299
248
300
template <class ... ParamsS>
249
301
static GenericSignature
250
302
synthesizeGenericSignature (SynthesisContext &SC,
251
- GenericParamListSynthesizer<ParamsS...> list) {
303
+ const GenericParamListSynthesizer<ParamsS...> & list) {
252
304
assert (SC.GenericParams && " synthesizeGenericParamList not called first" );
253
305
CollectGenericParams collector (SC);
254
306
list.Params .visit (collector);
0 commit comments