@@ -431,13 +431,26 @@ createGenericParam(ASTContext &ctx, const char *name, unsigned index) {
431
431
432
432
// / Create a generic parameter list with multiple generic parameters.
433
433
static GenericParamList *getGenericParams (ASTContext &ctx,
434
- unsigned numParameters) {
434
+ unsigned numParameters,
435
+ bool isAnyObject) {
435
436
assert (numParameters <= llvm::array_lengthof (GenericParamNames));
436
437
437
438
SmallVector<GenericTypeParamDecl*, 2 > genericParams;
438
439
for (unsigned i = 0 ; i != numParameters; ++i)
439
440
genericParams.push_back (createGenericParam (ctx, GenericParamNames[i], i));
440
441
442
+
443
+ if (isAnyObject) {
444
+ CanType ao = ctx.getAnyObjectType ();
445
+ SmallVector<RequirementRepr, 1 > req;
446
+ req.push_back (RequirementRepr::getTypeConstraint (TypeLoc::withoutLoc (genericParams[0 ]->getInterfaceType ()), SourceLoc (),
447
+ TypeLoc::withoutLoc (ao)));
448
+
449
+ auto paramList = GenericParamList::create (ctx, SourceLoc (), genericParams,
450
+ SourceLoc (), req, SourceLoc ());
451
+ return paramList;
452
+ }
453
+
441
454
auto paramList = GenericParamList::create (ctx, SourceLoc (), genericParams,
442
455
SourceLoc ());
443
456
return paramList;
@@ -460,9 +473,10 @@ namespace {
460
473
SmallVector<Requirement, 2 > addedRequirements;
461
474
462
475
public:
463
- BuiltinFunctionBuilder (ASTContext &ctx, unsigned numGenericParams = 1 )
476
+ BuiltinFunctionBuilder (ASTContext &ctx, unsigned numGenericParams = 1 ,
477
+ bool isAnyObject = false )
464
478
: Context(ctx) {
465
- TheGenericParamList = getGenericParams (ctx, numGenericParams);
479
+ TheGenericParamList = getGenericParams (ctx, numGenericParams, isAnyObject );
466
480
for (auto gp : TheGenericParamList->getParams ()) {
467
481
genericParamTypes.push_back (
468
482
gp->getDeclaredInterfaceType ()->castTo <GenericTypeParamType>());
@@ -645,6 +659,14 @@ static ValueDecl *getIsUniqueOperation(ASTContext &Context, Identifier Id) {
645
659
return builder.build (Id);
646
660
}
647
661
662
+ static ValueDecl *getEndCOWMutation (ASTContext &Context, Identifier Id) {
663
+ // <T> (@inout T) -> ()
664
+ BuiltinFunctionBuilder builder (Context);
665
+ builder.addParameter (makeGenericParam (), ValueOwnership::InOut);
666
+ builder.setResult (makeConcrete (TupleType::getEmpty (Context)));
667
+ return builder.build (Id);
668
+ }
669
+
648
670
static ValueDecl *getBindMemoryOperation (ASTContext &Context, Identifier Id) {
649
671
BuiltinFunctionBuilder builder (Context);
650
672
builder.addParameter (makeConcrete (Context.TheRawPointerType ));
@@ -908,6 +930,16 @@ static ValueDecl *getValueToBridgeObject(ASTContext &C, Identifier Id) {
908
930
return builder.build (Id);
909
931
}
910
932
933
+ static ValueDecl *getCOWBufferForReading (ASTContext &C, Identifier Id) {
934
+ // <T : AnyObject> T -> T
935
+ //
936
+ BuiltinFunctionBuilder builder (C, 1 , true );
937
+ auto T = makeGenericParam ();
938
+ builder.addParameter (T);
939
+ builder.setResult (T);
940
+ return builder.build (Id);
941
+ }
942
+
911
943
static ValueDecl *getUnsafeGuaranteed (ASTContext &C, Identifier Id) {
912
944
// <T : AnyObject> T -> (T, Int8Ty)
913
945
//
@@ -2249,9 +2281,16 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
2249
2281
2250
2282
case BuiltinValueKind::IsUnique:
2251
2283
case BuiltinValueKind::IsUnique_native:
2284
+ case BuiltinValueKind::BeginCOWMutation:
2285
+ case BuiltinValueKind::BeginCOWMutation_native:
2252
2286
if (!Types.empty ()) return nullptr ;
2287
+ // BeginCOWMutation has the same signature as IsUnique.
2253
2288
return getIsUniqueOperation (Context, Id);
2254
2289
2290
+ case BuiltinValueKind::EndCOWMutation:
2291
+ if (!Types.empty ()) return nullptr ;
2292
+ return getEndCOWMutation (Context, Id);
2293
+
2255
2294
case BuiltinValueKind::BindMemory:
2256
2295
if (!Types.empty ()) return nullptr ;
2257
2296
return getBindMemoryOperation (Context, Id);
@@ -2380,6 +2419,10 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
2380
2419
if (!Types.empty ())
2381
2420
return nullptr ;
2382
2421
return getValueToBridgeObject (Context, Id);
2422
+
2423
+ case BuiltinValueKind::COWBufferForReading:
2424
+ return getCOWBufferForReading (Context, Id);
2425
+
2383
2426
case BuiltinValueKind::UnsafeGuaranteed:
2384
2427
return getUnsafeGuaranteed (Context, Id);
2385
2428
0 commit comments