@@ -85,6 +85,27 @@ class ClangTypeInfo {
85
85
void dump (llvm::raw_ostream &os, const clang::ASTContext &ctx) const ;
86
86
};
87
87
88
+ class LifetimeDependenceInfo {
89
+ IndexSubset *copyLifetimeParamIndices;
90
+ IndexSubset *borrowLifetimeParamIndices;
91
+
92
+ public:
93
+ LifetimeDependenceInfo ()
94
+ : copyLifetimeParamIndices(nullptr ), borrowLifetimeParamIndices(nullptr ) {
95
+ }
96
+ LifetimeDependenceInfo (IndexSubset *copyLifetimeParamIndices,
97
+ IndexSubset *borrowLifetimeParamIndices)
98
+ : copyLifetimeParamIndices(copyLifetimeParamIndices),
99
+ borrowLifetimeParamIndices (borrowLifetimeParamIndices) {}
100
+
101
+ operator bool () const { return empty (); }
102
+
103
+ bool empty () const {
104
+ return copyLifetimeParamIndices == nullptr &&
105
+ borrowLifetimeParamIndices == nullptr ;
106
+ }
107
+ };
108
+
88
109
// MARK: - UnexpectedClangTypeError
89
110
// / Potential errors when trying to store a Clang type in an ExtInfo.
90
111
struct UnexpectedClangTypeError {
@@ -369,42 +390,47 @@ class ASTExtInfoBuilder {
369
390
unsigned bits; // Naturally sized for speed.
370
391
371
392
ClangTypeInfo clangTypeInfo;
393
+
372
394
Type globalActor;
373
395
Type thrownError;
374
396
397
+ LifetimeDependenceInfo lifetimeDependenceInfo;
398
+
375
399
using Representation = FunctionTypeRepresentation;
376
400
377
- ASTExtInfoBuilder (
378
- unsigned bits, ClangTypeInfo clangTypeInfo, Type globalActor,
379
- Type thrownError
380
- ) : bits(bits), clangTypeInfo(clangTypeInfo), globalActor(globalActor),
381
- thrownError (thrownError) {}
401
+ ASTExtInfoBuilder (unsigned bits, ClangTypeInfo clangTypeInfo,
402
+ Type globalActor, Type thrownError,
403
+ LifetimeDependenceInfo lifetimeDependenceInfo)
404
+ : bits(bits), clangTypeInfo(clangTypeInfo), globalActor(globalActor),
405
+ thrownError (thrownError),
406
+ lifetimeDependenceInfo(lifetimeDependenceInfo) {}
382
407
383
408
public:
384
409
// / An ExtInfoBuilder for a typical Swift function: @convention(swift),
385
410
// / @escaping, non-throwing, non-differentiable.
386
411
ASTExtInfoBuilder ()
387
412
: ASTExtInfoBuilder(Representation::Swift, false , false , Type(),
388
413
DifferentiabilityKind::NonDifferentiable, nullptr,
389
- Type()) {}
414
+ Type(), LifetimeDependenceInfo() ) {}
390
415
391
416
// Constructor for polymorphic type.
392
417
ASTExtInfoBuilder (Representation rep, bool throws, Type thrownError)
393
418
: ASTExtInfoBuilder(rep, false , throws, thrownError,
394
419
DifferentiabilityKind::NonDifferentiable, nullptr ,
395
- Type ()) {}
420
+ Type (), LifetimeDependenceInfo() ) {}
396
421
397
422
// Constructor with no defaults.
398
423
ASTExtInfoBuilder (Representation rep, bool isNoEscape, bool throws,
399
- Type thrownError,
400
- DifferentiabilityKind diffKind, const clang::Type *type,
401
- Type globalActor )
424
+ Type thrownError, DifferentiabilityKind diffKind,
425
+ const clang::Type *type, Type globalActor ,
426
+ LifetimeDependenceInfo lifetimeDependenceInfo )
402
427
: ASTExtInfoBuilder(
403
428
((unsigned )rep) | (isNoEscape ? NoEscapeMask : 0 ) |
404
429
(throws ? ThrowsMask : 0 ) |
405
430
(((unsigned )diffKind << DifferentiabilityMaskOffset) &
406
431
DifferentiabilityMask),
407
- ClangTypeInfo(type), globalActor, thrownError) {}
432
+ ClangTypeInfo(type), globalActor, thrownError,
433
+ lifetimeDependenceInfo) {}
408
434
409
435
void checkInvariants () const ;
410
436
@@ -444,6 +470,10 @@ class ASTExtInfoBuilder {
444
470
Type getGlobalActor () const { return globalActor; }
445
471
Type getThrownError () const { return thrownError; }
446
472
473
+ LifetimeDependenceInfo getLifetimeDependenceInfo () const {
474
+ return lifetimeDependenceInfo;
475
+ }
476
+
447
477
constexpr bool hasSelfParam () const {
448
478
switch (getSILRepresentation ()) {
449
479
case SILFunctionTypeRepresentation::Thick:
@@ -477,31 +507,31 @@ class ASTExtInfoBuilder {
477
507
return ASTExtInfoBuilder ((bits & ~RepresentationMask) | (unsigned )rep,
478
508
shouldStoreClangType (rep) ? clangTypeInfo
479
509
: ClangTypeInfo (),
480
- globalActor, thrownError);
510
+ globalActor, thrownError, lifetimeDependenceInfo );
481
511
}
482
512
[[nodiscard]]
483
513
ASTExtInfoBuilder withNoEscape (bool noEscape = true ) const {
484
- return ASTExtInfoBuilder (noEscape ? (bits | NoEscapeMask)
485
- : (bits & ~NoEscapeMask),
486
- clangTypeInfo, globalActor, thrownError);
514
+ return ASTExtInfoBuilder (
515
+ noEscape ? (bits | NoEscapeMask) : (bits & ~NoEscapeMask),
516
+ clangTypeInfo, globalActor, thrownError, lifetimeDependenceInfo );
487
517
}
488
518
[[nodiscard]]
489
519
ASTExtInfoBuilder withConcurrent (bool concurrent = true ) const {
490
- return ASTExtInfoBuilder (concurrent ? (bits | SendableMask)
491
- : (bits & ~SendableMask),
492
- clangTypeInfo, globalActor, thrownError);
520
+ return ASTExtInfoBuilder (
521
+ concurrent ? (bits | SendableMask) : (bits & ~SendableMask),
522
+ clangTypeInfo, globalActor, thrownError, lifetimeDependenceInfo );
493
523
}
494
524
[[nodiscard]]
495
525
ASTExtInfoBuilder withAsync (bool async = true ) const {
496
- return ASTExtInfoBuilder (async ? (bits | AsyncMask)
497
- : (bits & ~AsyncMask) ,
498
- clangTypeInfo, globalActor, thrownError );
526
+ return ASTExtInfoBuilder (async ? (bits | AsyncMask) : (bits & ~AsyncMask),
527
+ clangTypeInfo, globalActor, thrownError ,
528
+ lifetimeDependenceInfo );
499
529
}
500
530
[[nodiscard]]
501
531
ASTExtInfoBuilder withThrows (bool throws, Type thrownError) const {
502
532
return ASTExtInfoBuilder (
503
533
throws ? (bits | ThrowsMask) : (bits & ~ThrowsMask), clangTypeInfo,
504
- globalActor, thrownError);
534
+ globalActor, thrownError, lifetimeDependenceInfo );
505
535
}
506
536
[[nodiscard]]
507
537
ASTExtInfoBuilder withThrows () const {
@@ -513,12 +543,12 @@ class ASTExtInfoBuilder {
513
543
return ASTExtInfoBuilder (
514
544
(bits & ~DifferentiabilityMask) |
515
545
((unsigned )differentiability << DifferentiabilityMaskOffset),
516
- clangTypeInfo, globalActor, thrownError);
546
+ clangTypeInfo, globalActor, thrownError, lifetimeDependenceInfo );
517
547
}
518
548
[[nodiscard]]
519
549
ASTExtInfoBuilder withClangFunctionType (const clang::Type *type) const {
520
- return ASTExtInfoBuilder (
521
- bits, ClangTypeInfo (type), globalActor, thrownError);
550
+ return ASTExtInfoBuilder (bits, ClangTypeInfo (type), globalActor,
551
+ thrownError, lifetimeDependenceInfo );
522
552
}
523
553
524
554
// / Put a SIL representation in the ExtInfo.
@@ -532,19 +562,27 @@ class ASTExtInfoBuilder {
532
562
return ASTExtInfoBuilder ((bits & ~RepresentationMask) | (unsigned )rep,
533
563
shouldStoreClangType (rep) ? clangTypeInfo
534
564
: ClangTypeInfo (),
535
- globalActor, thrownError);
565
+ globalActor, thrownError, lifetimeDependenceInfo );
536
566
}
537
567
538
568
[[nodiscard]]
539
569
ASTExtInfoBuilder withGlobalActor (Type globalActor) const {
540
- return ASTExtInfoBuilder (bits, clangTypeInfo, globalActor, thrownError);
570
+ return ASTExtInfoBuilder (bits, clangTypeInfo, globalActor, thrownError,
571
+ lifetimeDependenceInfo);
572
+ }
573
+
574
+ [[nodiscard]] ASTExtInfoBuilder withLifetimeDependenceInfo (
575
+ LifetimeDependenceInfo lifetimeDependenceInfo) const {
576
+ return ASTExtInfoBuilder (bits, clangTypeInfo, globalActor, thrownError,
577
+ lifetimeDependenceInfo);
541
578
}
542
579
543
580
bool isEqualTo (ASTExtInfoBuilder other, bool useClangTypes) const {
544
581
return bits == other.bits &&
545
- (useClangTypes ? (clangTypeInfo == other.clangTypeInfo ) : true ) &&
546
- globalActor.getPointer () == other.globalActor .getPointer () &&
547
- thrownError.getPointer () == other.thrownError .getPointer ();
582
+ (useClangTypes ? (clangTypeInfo == other.clangTypeInfo ) : true ) &&
583
+ globalActor.getPointer () == other.globalActor .getPointer () &&
584
+ thrownError.getPointer () == other.thrownError .getPointer () &&
585
+ lifetimeDependenceInfo == other.lifetimeDependenceInfo ;
548
586
}
549
587
550
588
constexpr std::tuple<unsigned , const void *, const void *, const void *>
@@ -573,8 +611,9 @@ class ASTExtInfo {
573
611
ASTExtInfo (ASTExtInfoBuilder builder) : builder(builder) {}
574
612
575
613
ASTExtInfo (unsigned bits, ClangTypeInfo clangTypeInfo, Type globalActor,
576
- Type thrownError)
577
- : builder(bits, clangTypeInfo, globalActor, thrownError) {
614
+ Type thrownError, LifetimeDependenceInfo lifetimeDependenceInfo)
615
+ : builder(bits, clangTypeInfo, globalActor, thrownError,
616
+ lifetimeDependenceInfo) {
578
617
builder.checkInvariants ();
579
618
};
580
619
@@ -621,6 +660,10 @@ class ASTExtInfo {
621
660
Type getGlobalActor () const { return builder.getGlobalActor (); }
622
661
Type getThrownError () const { return builder.getThrownError (); }
623
662
663
+ LifetimeDependenceInfo getLifetimeDependenceInfo () const {
664
+ return builder.getLifetimeDependenceInfo ();
665
+ }
666
+
624
667
// / Helper method for changing the representation.
625
668
// /
626
669
// / Prefer using \c ASTExtInfoBuilder::withRepresentation for chaining.
@@ -674,6 +717,11 @@ class ASTExtInfo {
674
717
return builder.withGlobalActor (globalActor).build ();
675
718
}
676
719
720
+ [[nodiscard]] ASTExtInfo withLifetimeDependenceInfo (
721
+ LifetimeDependenceInfo lifetimeDependenceInfo) const {
722
+ return builder.withLifetimeDependenceInfo (lifetimeDependenceInfo).build ();
723
+ }
724
+
677
725
bool isEqualTo (ASTExtInfo other, bool useClangTypes) const {
678
726
return builder.isEqualTo (other.builder , useClangTypes);
679
727
}
0 commit comments