@@ -177,6 +177,12 @@ _conformsTo(TypeS type, ProtocolS protocol) {
177177 return {type, protocol};
178178}
179179
180+ // Convenience macro to say that a type parameter has default
181+ // Copyable & Escapable requirements.
182+ #define _conformsToDefaults (INDEX ) \
183+ _conformsTo (_typeparam(INDEX), _copyable), \
184+ _conformsTo (_typeparam(INDEX), _escapable)
185+
180186// / A synthesizer which generates a layout constraint requirement.
181187template <class TypeS >
182188struct LayoutConstraintSynthesizer {
@@ -288,8 +294,16 @@ struct CollectGenericParams {
288294 void operator ()(const ConformsToSynthesizer<TypeS, ProtoS> &conf) {
289295 auto type = synthesizeType (SC, conf.Type );
290296 auto protocolType = synthesizeType (SC, conf.Protocol );
291- AddedRequirements.push_back ({RequirementKind::Conformance,
292- type, protocolType});
297+ Requirement req = {RequirementKind::Conformance, type, protocolType};
298+
299+ // If it's an invertible protocol and NoncopyableGenerics is disabled
300+ // then skip the requirement.
301+ if (req.getProtocolDecl ()->getInvertibleProtocolKind ())
302+ if (!(SWIFT_ENABLE_EXPERIMENTAL_NONCOPYABLE_GENERICS ||
303+ SC.Context .LangOpts .hasFeature (Feature::NoncopyableGenerics)))
304+ return ;
305+
306+ AddedRequirements.push_back (req);
293307 }
294308
295309 template <class TypeS >
@@ -310,13 +324,11 @@ synthesizeGenericSignature(SynthesisContext &SC,
310324 CollectGenericParams collector (SC);
311325 list.Params .visit (collector);
312326
313- // FIXME: Change allowInverses to false and add Copyable/Escapable explicitly
314- // to those builtins that need it.
315327 return buildGenericSignature (SC.Context ,
316328 GenericSignature (),
317329 std::move (collector.GenericParamTypes ),
318330 std::move (collector.AddedRequirements ),
319- /* allowInverses=*/ true );
331+ /* allowInverses=*/ false );
320332}
321333
322334// / Build a builtin function declaration.
@@ -716,9 +728,18 @@ namespace {
716728
717729 template <class G >
718730 void addConformanceRequirement (const G &generator, ProtocolDecl *proto) {
731+ assert (proto && " missing protocol" );
719732 Requirement req (RequirementKind::Conformance,
720733 generator.build (*this ),
721734 proto->getDeclaredInterfaceType ());
735+
736+ // If it's an invertible protocol and NoncopyableGenerics is disabled
737+ // then skip the requirement.
738+ if (req.getProtocolDecl ()->getInvertibleProtocolKind ())
739+ if (!(SWIFT_ENABLE_EXPERIMENTAL_NONCOPYABLE_GENERICS ||
740+ Context.LangOpts .hasFeature (Feature::NoncopyableGenerics)))
741+ return ;
742+
722743 addedRequirements.push_back (req);
723744 }
724745
@@ -735,13 +756,11 @@ namespace {
735756 }
736757
737758 FuncDecl *build (Identifier name) {
738- // FIXME: Change allowInverses to false and add Copyable/Escapable
739- // explicitly to those builtins that need it.
740759 auto GenericSig = buildGenericSignature (
741760 Context, GenericSignature (),
742761 std::move (genericParamTypes),
743762 std::move (addedRequirements),
744- /* allowInverses=*/ true );
763+ /* allowInverses=*/ false );
745764 return getBuiltinGenericFunction (name, InterfaceParams,
746765 InterfaceResult,
747766 TheGenericParamList, GenericSig,
@@ -844,12 +863,21 @@ makePackExpansion(const T &object) {
844863// / Create a function with type <T> T -> ().
845864static ValueDecl *getRefCountingOperation (ASTContext &ctx, Identifier id) {
846865 return getBuiltinFunction (ctx, id, _thin,
847- _generics (_unrestricted),
866+ _generics (_unrestricted,
867+ _conformsTo (_typeparam (0 ), _copyable)),
848868 _parameters (_typeparam (0 )),
849869 _void);
850870}
851871
852872static ValueDecl *getLoadOperation (ASTContext &ctx, Identifier id) {
873+ return getBuiltinFunction (ctx, id, _thin,
874+ _generics (_unrestricted,
875+ _conformsTo (_typeparam (0 ), _copyable)),
876+ _parameters (_rawPointer),
877+ _typeparam (0 ));
878+ }
879+
880+ static ValueDecl *getTakeOperation (ASTContext &ctx, Identifier id) {
853881 return getBuiltinFunction (ctx, id, _thin,
854882 _generics (_unrestricted),
855883 _parameters (_rawPointer),
@@ -858,31 +886,33 @@ static ValueDecl *getLoadOperation(ASTContext &ctx, Identifier id) {
858886
859887static ValueDecl *getStoreOperation (ASTContext &ctx, Identifier id) {
860888 return getBuiltinFunction (ctx, id, _thin,
861- _generics (_unrestricted),
889+ _generics (_unrestricted, _conformsToDefaults ( 0 ) ),
862890 _parameters (_owned (_typeparam (0 )),
863891 _rawPointer),
864892 _void);
865893}
866894
867895static ValueDecl *getDestroyOperation (ASTContext &ctx, Identifier id) {
868896 return getBuiltinFunction (ctx, id, _thin,
869- _generics (_unrestricted),
897+ _generics (_unrestricted, _conformsToDefaults ( 0 ) ),
870898 _parameters (_metatype (_typeparam (0 )),
871899 _rawPointer),
872900 _void);
873901}
874902
875903static ValueDecl *getDestroyArrayOperation (ASTContext &ctx, Identifier id) {
876904 return getBuiltinFunction (ctx, id, _thin,
877- _generics (_unrestricted),
905+ _generics (_unrestricted, _conformsToDefaults ( 0 ) ),
878906 _parameters (_metatype (_typeparam (0 )),
879907 _rawPointer,
880908 _word),
881909 _void);
882910}
883911
884912static ValueDecl *getCopyOperation (ASTContext &ctx, Identifier id) {
885- return getBuiltinFunction (ctx, id, _thin, _generics (_unrestricted),
913+ return getBuiltinFunction (ctx, id, _thin,
914+ _generics (_unrestricted,
915+ _conformsTo (_typeparam (0 ), _copyable)),
886916 _parameters (_typeparam (0 )), _typeparam (0 ));
887917}
888918
@@ -894,7 +924,7 @@ static ValueDecl *getAssumeAlignment(ASTContext &ctx, Identifier id) {
894924
895925static ValueDecl *getTransferArrayOperation (ASTContext &ctx, Identifier id) {
896926 return getBuiltinFunction (ctx, id, _thin,
897- _generics (_unrestricted),
927+ _generics (_unrestricted, _conformsToDefaults ( 0 ) ),
898928 _parameters (_metatype (_typeparam (0 )),
899929 _rawPointer,
900930 _rawPointer,
@@ -957,7 +987,9 @@ static ValueDecl *getAllocWithTailElemsOperation(ASTContext &Context,
957987static ValueDecl *getProjectTailElemsOperation (ASTContext &ctx,
958988 Identifier id) {
959989 return getBuiltinFunction (ctx, id, _thin,
960- _generics (_unrestricted, _unrestricted),
990+ _generics (_unrestricted, _unrestricted,
991+ _conformsToDefaults (0 ),
992+ _conformsToDefaults (1 )),
961993 _parameters (_typeparam (0 ),
962994 _metatype (_typeparam (1 ))),
963995 _rawPointer);
@@ -977,7 +1009,9 @@ static ValueDecl *getGepOperation(ASTContext &ctx, Identifier id,
9771009static ValueDecl *getGetTailAddrOperation (ASTContext &ctx, Identifier id,
9781010 Type argType) {
9791011 return getBuiltinFunction (ctx, id, _thin,
980- _generics (_unrestricted, _unrestricted),
1012+ _generics (_unrestricted, _unrestricted,
1013+ _conformsToDefaults (0 ),
1014+ _conformsToDefaults (1 )),
9811015 _parameters (_rawPointer,
9821016 argType,
9831017 _metatype (_typeparam (0 )),
@@ -1170,7 +1204,7 @@ static ValueDecl *getNativeObjectCast(ASTContext &Context, Identifier Id,
11701204static ValueDecl *getCastToBridgeObjectOperation (ASTContext &ctx,
11711205 Identifier id) {
11721206 return getBuiltinFunction (ctx, id, _thin,
1173- _generics (_unrestricted),
1207+ _generics (_unrestricted, _conformsToDefaults ( 0 ) ),
11741208 _parameters (_owned (_typeparam (0 )),
11751209 _word),
11761210 _bridgeObject);
@@ -1182,7 +1216,7 @@ static ValueDecl *getCastFromBridgeObjectOperation(ASTContext &ctx,
11821216 switch (BV) {
11831217 case BuiltinValueKind::CastReferenceFromBridgeObject: {
11841218 return getBuiltinFunction (ctx, id, _thin,
1185- _generics (_unrestricted),
1219+ _generics (_unrestricted, _conformsToDefaults ( 0 ) ),
11861220 _parameters (_owned (_bridgeObject)),
11871221 _typeparam (0 ));
11881222 }
@@ -1212,7 +1246,7 @@ static ValueDecl *getClassifyBridgeObject(ASTContext &C, Identifier Id) {
12121246
12131247static ValueDecl *getValueToBridgeObject (ASTContext &ctx, Identifier id) {
12141248 return getBuiltinFunction (ctx, id, _thin,
1215- _generics (_unrestricted),
1249+ _generics (_unrestricted, _conformsToDefaults ( 0 ) ),
12161250 _parameters (_typeparam (0 )),
12171251 _bridgeObject);
12181252}
@@ -1498,7 +1532,7 @@ static ValueDecl *getCreateAsyncTask(ASTContext &ctx, Identifier id,
14981532
14991533static ValueDecl *getTaskRunInline (ASTContext &ctx, Identifier id) {
15001534 return getBuiltinFunction (
1501- ctx, id, _thin, _generics (_unrestricted),
1535+ ctx, id, _thin, _generics (_unrestricted, _conformsToDefaults ( 0 ) ),
15021536 _parameters (
15031537 _function (_async (_noescape (_thick)), _typeparam (0 ), _parameters ())),
15041538 _typeparam (0 ));
@@ -1521,15 +1555,15 @@ static ValueDecl *getDefaultActorInitDestroy(ASTContext &ctx,
15211555static ValueDecl *getDistributedActorInitializeRemote (ASTContext &ctx,
15221556 Identifier id) {
15231557 return getBuiltinFunction (ctx, id, _thin,
1524- _generics (_unrestricted), // TODO(distributed): restrict to DistributedActor
1558+ _generics (_unrestricted, _conformsToDefaults ( 0 ) ), // TODO(distributed): restrict to DistributedActor
15251559 _parameters (_metatype (_typeparam (0 ))),
15261560 _rawPointer);
15271561}
15281562
15291563static ValueDecl *getResumeContinuationReturning (ASTContext &ctx,
15301564 Identifier id) {
15311565 return getBuiltinFunction (ctx, id, _thin,
1532- _generics (_unrestricted),
1566+ _generics (_unrestricted, _conformsToDefaults ( 0 ) ),
15331567 _parameters (_rawUnsafeContinuation,
15341568 _owned (_typeparam (0 ))),
15351569 _void);
@@ -1575,7 +1609,7 @@ static ValueDecl *getEndAsyncLet(ASTContext &ctx, Identifier id) {
15751609
15761610static ValueDecl *getCreateTaskGroup (ASTContext &ctx, Identifier id) {
15771611 return getBuiltinFunction (ctx, id, _thin,
1578- _generics (_unrestricted),
1612+ _generics (_unrestricted, _conformsToDefaults ( 0 ) ),
15791613 _parameters (_metatype (_typeparam (0 ))),
15801614 _rawPointer);
15811615}
@@ -1613,14 +1647,15 @@ static ValueDecl *getBuildDefaultActorExecutorRef(ASTContext &ctx,
16131647 Identifier id) {
16141648 return getBuiltinFunction (ctx, id, _thin,
16151649 _generics (_unrestricted,
1650+ _conformsToDefaults (0 ),
16161651 _layout (_typeparam (0 ), _classLayout ())),
16171652 _parameters (_typeparam (0 )),
16181653 _executor);
16191654}
16201655
16211656static ValueDecl *getExtractFunctionIsolation (ASTContext &ctx, Identifier id) {
16221657 return getBuiltinFunction (ctx, id, _thin,
1623- _generics (_unrestricted),
1658+ _generics (_unrestricted, _conformsToDefaults ( 0 ) ),
16241659 _parameters (_typeparam (0 )),
16251660 _optional (_existential (_actor)));
16261661}
@@ -1661,7 +1696,7 @@ static ValueDecl *getBuildComplexEqualitySerialExecutorRef(ASTContext &ctx,
16611696static ValueDecl *getAutoDiffCreateLinearMapContext (ASTContext &ctx,
16621697 Identifier id) {
16631698 return getBuiltinFunction (
1664- ctx, id, _thin, _generics (_unrestricted),
1699+ ctx, id, _thin, _generics (_unrestricted, _conformsToDefaults ( 0 )),
16651700 _parameters (_metatype (_typeparam (0 ))), _nativeObject);
16661701}
16671702
@@ -1674,7 +1709,7 @@ static ValueDecl *getAutoDiffProjectTopLevelSubcontext(ASTContext &ctx,
16741709static ValueDecl *getAutoDiffAllocateSubcontext (ASTContext &ctx,
16751710 Identifier id) {
16761711 return getBuiltinFunction (
1677- ctx, id, _thin, _generics (_unrestricted),
1712+ ctx, id, _thin, _generics (_unrestricted, _conformsToDefaults ( 0 ) ),
16781713 _parameters (_nativeObject, _metatype (_typeparam (0 ))), _rawPointer);
16791714}
16801715
@@ -2729,9 +2764,13 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
27292764 case BuiltinValueKind::Load:
27302765 case BuiltinValueKind::LoadRaw:
27312766 case BuiltinValueKind::LoadInvariant:
2732- case BuiltinValueKind::Take:
27332767 if (!Types.empty ()) return nullptr ;
27342768 return getLoadOperation (Context, Id);
2769+
2770+ case BuiltinValueKind::Take:
2771+ if (!Types.empty ()) return nullptr ;
2772+ return getTakeOperation (Context, Id);
2773+
27352774
27362775 case BuiltinValueKind::Destroy:
27372776 if (!Types.empty ()) return nullptr ;
0 commit comments