@@ -177,6 +177,12 @@ _conformsTo(TypeS type, ProtocolS protocol) {
177
177
return {type, protocol};
178
178
}
179
179
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
+
180
186
// / A synthesizer which generates a layout constraint requirement.
181
187
template <class TypeS >
182
188
struct LayoutConstraintSynthesizer {
@@ -288,8 +294,16 @@ struct CollectGenericParams {
288
294
void operator ()(const ConformsToSynthesizer<TypeS, ProtoS> &conf) {
289
295
auto type = synthesizeType (SC, conf.Type );
290
296
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);
293
307
}
294
308
295
309
template <class TypeS >
@@ -310,13 +324,11 @@ synthesizeGenericSignature(SynthesisContext &SC,
310
324
CollectGenericParams collector (SC);
311
325
list.Params .visit (collector);
312
326
313
- // FIXME: Change allowInverses to false and add Copyable/Escapable explicitly
314
- // to those builtins that need it.
315
327
return buildGenericSignature (SC.Context ,
316
328
GenericSignature (),
317
329
std::move (collector.GenericParamTypes ),
318
330
std::move (collector.AddedRequirements ),
319
- /* allowInverses=*/ true );
331
+ /* allowInverses=*/ false );
320
332
}
321
333
322
334
// / Build a builtin function declaration.
@@ -716,9 +728,18 @@ namespace {
716
728
717
729
template <class G >
718
730
void addConformanceRequirement (const G &generator, ProtocolDecl *proto) {
731
+ assert (proto && " missing protocol" );
719
732
Requirement req (RequirementKind::Conformance,
720
733
generator.build (*this ),
721
734
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
+
722
743
addedRequirements.push_back (req);
723
744
}
724
745
@@ -735,13 +756,11 @@ namespace {
735
756
}
736
757
737
758
FuncDecl *build (Identifier name) {
738
- // FIXME: Change allowInverses to false and add Copyable/Escapable
739
- // explicitly to those builtins that need it.
740
759
auto GenericSig = buildGenericSignature (
741
760
Context, GenericSignature (),
742
761
std::move (genericParamTypes),
743
762
std::move (addedRequirements),
744
- /* allowInverses=*/ true );
763
+ /* allowInverses=*/ false );
745
764
return getBuiltinGenericFunction (name, InterfaceParams,
746
765
InterfaceResult,
747
766
TheGenericParamList, GenericSig,
@@ -844,12 +863,21 @@ makePackExpansion(const T &object) {
844
863
// / Create a function with type <T> T -> ().
845
864
static ValueDecl *getRefCountingOperation (ASTContext &ctx, Identifier id) {
846
865
return getBuiltinFunction (ctx, id, _thin,
847
- _generics (_unrestricted),
866
+ _generics (_unrestricted,
867
+ _conformsTo (_typeparam (0 ), _copyable)),
848
868
_parameters (_typeparam (0 )),
849
869
_void);
850
870
}
851
871
852
872
static 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) {
853
881
return getBuiltinFunction (ctx, id, _thin,
854
882
_generics (_unrestricted),
855
883
_parameters (_rawPointer),
@@ -858,31 +886,33 @@ static ValueDecl *getLoadOperation(ASTContext &ctx, Identifier id) {
858
886
859
887
static ValueDecl *getStoreOperation (ASTContext &ctx, Identifier id) {
860
888
return getBuiltinFunction (ctx, id, _thin,
861
- _generics (_unrestricted),
889
+ _generics (_unrestricted, _conformsToDefaults ( 0 ) ),
862
890
_parameters (_owned (_typeparam (0 )),
863
891
_rawPointer),
864
892
_void);
865
893
}
866
894
867
895
static ValueDecl *getDestroyOperation (ASTContext &ctx, Identifier id) {
868
896
return getBuiltinFunction (ctx, id, _thin,
869
- _generics (_unrestricted),
897
+ _generics (_unrestricted, _conformsToDefaults ( 0 ) ),
870
898
_parameters (_metatype (_typeparam (0 )),
871
899
_rawPointer),
872
900
_void);
873
901
}
874
902
875
903
static ValueDecl *getDestroyArrayOperation (ASTContext &ctx, Identifier id) {
876
904
return getBuiltinFunction (ctx, id, _thin,
877
- _generics (_unrestricted),
905
+ _generics (_unrestricted, _conformsToDefaults ( 0 ) ),
878
906
_parameters (_metatype (_typeparam (0 )),
879
907
_rawPointer,
880
908
_word),
881
909
_void);
882
910
}
883
911
884
912
static 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)),
886
916
_parameters (_typeparam (0 )), _typeparam (0 ));
887
917
}
888
918
@@ -894,7 +924,7 @@ static ValueDecl *getAssumeAlignment(ASTContext &ctx, Identifier id) {
894
924
895
925
static ValueDecl *getTransferArrayOperation (ASTContext &ctx, Identifier id) {
896
926
return getBuiltinFunction (ctx, id, _thin,
897
- _generics (_unrestricted),
927
+ _generics (_unrestricted, _conformsToDefaults ( 0 ) ),
898
928
_parameters (_metatype (_typeparam (0 )),
899
929
_rawPointer,
900
930
_rawPointer,
@@ -957,7 +987,9 @@ static ValueDecl *getAllocWithTailElemsOperation(ASTContext &Context,
957
987
static ValueDecl *getProjectTailElemsOperation (ASTContext &ctx,
958
988
Identifier id) {
959
989
return getBuiltinFunction (ctx, id, _thin,
960
- _generics (_unrestricted, _unrestricted),
990
+ _generics (_unrestricted, _unrestricted,
991
+ _conformsToDefaults (0 ),
992
+ _conformsToDefaults (1 )),
961
993
_parameters (_typeparam (0 ),
962
994
_metatype (_typeparam (1 ))),
963
995
_rawPointer);
@@ -977,7 +1009,9 @@ static ValueDecl *getGepOperation(ASTContext &ctx, Identifier id,
977
1009
static ValueDecl *getGetTailAddrOperation (ASTContext &ctx, Identifier id,
978
1010
Type argType) {
979
1011
return getBuiltinFunction (ctx, id, _thin,
980
- _generics (_unrestricted, _unrestricted),
1012
+ _generics (_unrestricted, _unrestricted,
1013
+ _conformsToDefaults (0 ),
1014
+ _conformsToDefaults (1 )),
981
1015
_parameters (_rawPointer,
982
1016
argType,
983
1017
_metatype (_typeparam (0 )),
@@ -1170,7 +1204,7 @@ static ValueDecl *getNativeObjectCast(ASTContext &Context, Identifier Id,
1170
1204
static ValueDecl *getCastToBridgeObjectOperation (ASTContext &ctx,
1171
1205
Identifier id) {
1172
1206
return getBuiltinFunction (ctx, id, _thin,
1173
- _generics (_unrestricted),
1207
+ _generics (_unrestricted, _conformsToDefaults ( 0 ) ),
1174
1208
_parameters (_owned (_typeparam (0 )),
1175
1209
_word),
1176
1210
_bridgeObject);
@@ -1182,7 +1216,7 @@ static ValueDecl *getCastFromBridgeObjectOperation(ASTContext &ctx,
1182
1216
switch (BV) {
1183
1217
case BuiltinValueKind::CastReferenceFromBridgeObject: {
1184
1218
return getBuiltinFunction (ctx, id, _thin,
1185
- _generics (_unrestricted),
1219
+ _generics (_unrestricted, _conformsToDefaults ( 0 ) ),
1186
1220
_parameters (_owned (_bridgeObject)),
1187
1221
_typeparam (0 ));
1188
1222
}
@@ -1212,7 +1246,7 @@ static ValueDecl *getClassifyBridgeObject(ASTContext &C, Identifier Id) {
1212
1246
1213
1247
static ValueDecl *getValueToBridgeObject (ASTContext &ctx, Identifier id) {
1214
1248
return getBuiltinFunction (ctx, id, _thin,
1215
- _generics (_unrestricted),
1249
+ _generics (_unrestricted, _conformsToDefaults ( 0 ) ),
1216
1250
_parameters (_typeparam (0 )),
1217
1251
_bridgeObject);
1218
1252
}
@@ -1498,7 +1532,7 @@ static ValueDecl *getCreateAsyncTask(ASTContext &ctx, Identifier id,
1498
1532
1499
1533
static ValueDecl *getTaskRunInline (ASTContext &ctx, Identifier id) {
1500
1534
return getBuiltinFunction (
1501
- ctx, id, _thin, _generics (_unrestricted),
1535
+ ctx, id, _thin, _generics (_unrestricted, _conformsToDefaults ( 0 ) ),
1502
1536
_parameters (
1503
1537
_function (_async (_noescape (_thick)), _typeparam (0 ), _parameters ())),
1504
1538
_typeparam (0 ));
@@ -1521,15 +1555,15 @@ static ValueDecl *getDefaultActorInitDestroy(ASTContext &ctx,
1521
1555
static ValueDecl *getDistributedActorInitializeRemote (ASTContext &ctx,
1522
1556
Identifier id) {
1523
1557
return getBuiltinFunction (ctx, id, _thin,
1524
- _generics (_unrestricted), // TODO(distributed): restrict to DistributedActor
1558
+ _generics (_unrestricted, _conformsToDefaults ( 0 ) ), // TODO(distributed): restrict to DistributedActor
1525
1559
_parameters (_metatype (_typeparam (0 ))),
1526
1560
_rawPointer);
1527
1561
}
1528
1562
1529
1563
static ValueDecl *getResumeContinuationReturning (ASTContext &ctx,
1530
1564
Identifier id) {
1531
1565
return getBuiltinFunction (ctx, id, _thin,
1532
- _generics (_unrestricted),
1566
+ _generics (_unrestricted, _conformsToDefaults ( 0 ) ),
1533
1567
_parameters (_rawUnsafeContinuation,
1534
1568
_owned (_typeparam (0 ))),
1535
1569
_void);
@@ -1575,7 +1609,7 @@ static ValueDecl *getEndAsyncLet(ASTContext &ctx, Identifier id) {
1575
1609
1576
1610
static ValueDecl *getCreateTaskGroup (ASTContext &ctx, Identifier id) {
1577
1611
return getBuiltinFunction (ctx, id, _thin,
1578
- _generics (_unrestricted),
1612
+ _generics (_unrestricted, _conformsToDefaults ( 0 ) ),
1579
1613
_parameters (_metatype (_typeparam (0 ))),
1580
1614
_rawPointer);
1581
1615
}
@@ -1613,14 +1647,15 @@ static ValueDecl *getBuildDefaultActorExecutorRef(ASTContext &ctx,
1613
1647
Identifier id) {
1614
1648
return getBuiltinFunction (ctx, id, _thin,
1615
1649
_generics (_unrestricted,
1650
+ _conformsToDefaults (0 ),
1616
1651
_layout (_typeparam (0 ), _classLayout ())),
1617
1652
_parameters (_typeparam (0 )),
1618
1653
_executor);
1619
1654
}
1620
1655
1621
1656
static ValueDecl *getExtractFunctionIsolation (ASTContext &ctx, Identifier id) {
1622
1657
return getBuiltinFunction (ctx, id, _thin,
1623
- _generics (_unrestricted),
1658
+ _generics (_unrestricted, _conformsToDefaults ( 0 ) ),
1624
1659
_parameters (_typeparam (0 )),
1625
1660
_optional (_existential (_actor)));
1626
1661
}
@@ -1661,7 +1696,7 @@ static ValueDecl *getBuildComplexEqualitySerialExecutorRef(ASTContext &ctx,
1661
1696
static ValueDecl *getAutoDiffCreateLinearMapContext (ASTContext &ctx,
1662
1697
Identifier id) {
1663
1698
return getBuiltinFunction (
1664
- ctx, id, _thin, _generics (_unrestricted),
1699
+ ctx, id, _thin, _generics (_unrestricted, _conformsToDefaults ( 0 )),
1665
1700
_parameters (_metatype (_typeparam (0 ))), _nativeObject);
1666
1701
}
1667
1702
@@ -1674,7 +1709,7 @@ static ValueDecl *getAutoDiffProjectTopLevelSubcontext(ASTContext &ctx,
1674
1709
static ValueDecl *getAutoDiffAllocateSubcontext (ASTContext &ctx,
1675
1710
Identifier id) {
1676
1711
return getBuiltinFunction (
1677
- ctx, id, _thin, _generics (_unrestricted),
1712
+ ctx, id, _thin, _generics (_unrestricted, _conformsToDefaults ( 0 ) ),
1678
1713
_parameters (_nativeObject, _metatype (_typeparam (0 ))), _rawPointer);
1679
1714
}
1680
1715
@@ -2729,9 +2764,13 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
2729
2764
case BuiltinValueKind::Load:
2730
2765
case BuiltinValueKind::LoadRaw:
2731
2766
case BuiltinValueKind::LoadInvariant:
2732
- case BuiltinValueKind::Take:
2733
2767
if (!Types.empty ()) return nullptr ;
2734
2768
return getLoadOperation (Context, Id);
2769
+
2770
+ case BuiltinValueKind::Take:
2771
+ if (!Types.empty ()) return nullptr ;
2772
+ return getTakeOperation (Context, Id);
2773
+
2735
2774
2736
2775
case BuiltinValueKind::Destroy:
2737
2776
if (!Types.empty ()) return nullptr ;
0 commit comments