@@ -162,6 +162,33 @@ namespace {
162162// / for generics.
163163enum UnrestrictedGenericParam { _unrestricted };
164164
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+
165192// / A synthesizer which generates a generic parameter list.
166193template <class ... ParamS>
167194struct GenericParamListSynthesizer {
@@ -179,6 +206,16 @@ struct CountGenericParameters {
179206 void operator ()(UnrestrictedGenericParam _) const {
180207 Count++;
181208 }
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+ }
182219};
183220
184221} // end anonymous namespace
@@ -240,15 +277,30 @@ struct CollectGenericParams {
240277 }
241278 }
242279
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+ }
244296};
245297
246298} // end anonymous namespace
247299
248300template <class ... ParamsS>
249301static GenericSignature
250302synthesizeGenericSignature (SynthesisContext &SC,
251- GenericParamListSynthesizer<ParamsS...> list) {
303+ const GenericParamListSynthesizer<ParamsS...> & list) {
252304 assert (SC.GenericParams && " synthesizeGenericParamList not called first" );
253305 CollectGenericParams collector (SC);
254306 list.Params .visit (collector);
@@ -1429,6 +1481,15 @@ static ValueDecl *getResumeContinuationThrowing(ASTContext &ctx,
14291481 _void);
14301482}
14311483
1484+ static ValueDecl *getBuildSerialExecutorRef (ASTContext &ctx, Identifier id) {
1485+ // TODO: restrict the generic parameter to the SerialExecutor protocol
1486+ return getBuiltinFunction (ctx, id, _thin,
1487+ _generics (_unrestricted,
1488+ _layout (_typeparam (0 ), _classLayout ())),
1489+ _parameters (_typeparam (0 )),
1490+ _executor);
1491+ }
1492+
14321493static ValueDecl *getAutoDiffCreateLinearMapContext (ASTContext &ctx,
14331494 Identifier id) {
14341495 return getBuiltinFunction (
@@ -2606,6 +2667,9 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
26062667 case BuiltinValueKind::ConvertTaskToJob:
26072668 return getConvertTaskToJob (Context, Id);
26082669
2670+ case BuiltinValueKind::BuildSerialExecutorRef:
2671+ return getBuildSerialExecutorRef (Context, Id);
2672+
26092673 case BuiltinValueKind::PoundAssert:
26102674 return getPoundAssert (Context, Id);
26112675
0 commit comments