@@ -85,6 +85,27 @@ class ClangTypeInfo {
8585 void dump (llvm::raw_ostream &os, const clang::ASTContext &ctx) const ;
8686};
8787
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+
88109// MARK: - UnexpectedClangTypeError
89110// / Potential errors when trying to store a Clang type in an ExtInfo.
90111struct UnexpectedClangTypeError {
@@ -369,42 +390,47 @@ class ASTExtInfoBuilder {
369390 unsigned bits; // Naturally sized for speed.
370391
371392 ClangTypeInfo clangTypeInfo;
393+
372394 Type globalActor;
373395 Type thrownError;
374396
397+ LifetimeDependenceInfo lifetimeDependenceInfo;
398+
375399 using Representation = FunctionTypeRepresentation;
376400
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) {}
382407
383408public:
384409 // / An ExtInfoBuilder for a typical Swift function: @convention(swift),
385410 // / @escaping, non-throwing, non-differentiable.
386411 ASTExtInfoBuilder ()
387412 : ASTExtInfoBuilder(Representation::Swift, false , false , Type(),
388413 DifferentiabilityKind::NonDifferentiable, nullptr,
389- Type()) {}
414+ Type(), LifetimeDependenceInfo() ) {}
390415
391416 // Constructor for polymorphic type.
392417 ASTExtInfoBuilder (Representation rep, bool throws, Type thrownError)
393418 : ASTExtInfoBuilder(rep, false , throws, thrownError,
394419 DifferentiabilityKind::NonDifferentiable, nullptr ,
395- Type ()) {}
420+ Type (), LifetimeDependenceInfo() ) {}
396421
397422 // Constructor with no defaults.
398423 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 )
402427 : ASTExtInfoBuilder(
403428 ((unsigned )rep) | (isNoEscape ? NoEscapeMask : 0 ) |
404429 (throws ? ThrowsMask : 0 ) |
405430 (((unsigned )diffKind << DifferentiabilityMaskOffset) &
406431 DifferentiabilityMask),
407- ClangTypeInfo(type), globalActor, thrownError) {}
432+ ClangTypeInfo(type), globalActor, thrownError,
433+ lifetimeDependenceInfo) {}
408434
409435 void checkInvariants () const ;
410436
@@ -444,6 +470,10 @@ class ASTExtInfoBuilder {
444470 Type getGlobalActor () const { return globalActor; }
445471 Type getThrownError () const { return thrownError; }
446472
473+ LifetimeDependenceInfo getLifetimeDependenceInfo () const {
474+ return lifetimeDependenceInfo;
475+ }
476+
447477 constexpr bool hasSelfParam () const {
448478 switch (getSILRepresentation ()) {
449479 case SILFunctionTypeRepresentation::Thick:
@@ -477,31 +507,31 @@ class ASTExtInfoBuilder {
477507 return ASTExtInfoBuilder ((bits & ~RepresentationMask) | (unsigned )rep,
478508 shouldStoreClangType (rep) ? clangTypeInfo
479509 : ClangTypeInfo (),
480- globalActor, thrownError);
510+ globalActor, thrownError, lifetimeDependenceInfo );
481511 }
482512 [[nodiscard]]
483513 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 );
487517 }
488518 [[nodiscard]]
489519 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 );
493523 }
494524 [[nodiscard]]
495525 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 );
499529 }
500530 [[nodiscard]]
501531 ASTExtInfoBuilder withThrows (bool throws, Type thrownError) const {
502532 return ASTExtInfoBuilder (
503533 throws ? (bits | ThrowsMask) : (bits & ~ThrowsMask), clangTypeInfo,
504- globalActor, thrownError);
534+ globalActor, thrownError, lifetimeDependenceInfo );
505535 }
506536 [[nodiscard]]
507537 ASTExtInfoBuilder withThrows () const {
@@ -513,12 +543,12 @@ class ASTExtInfoBuilder {
513543 return ASTExtInfoBuilder (
514544 (bits & ~DifferentiabilityMask) |
515545 ((unsigned )differentiability << DifferentiabilityMaskOffset),
516- clangTypeInfo, globalActor, thrownError);
546+ clangTypeInfo, globalActor, thrownError, lifetimeDependenceInfo );
517547 }
518548 [[nodiscard]]
519549 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 );
522552 }
523553
524554 // / Put a SIL representation in the ExtInfo.
@@ -532,19 +562,27 @@ class ASTExtInfoBuilder {
532562 return ASTExtInfoBuilder ((bits & ~RepresentationMask) | (unsigned )rep,
533563 shouldStoreClangType (rep) ? clangTypeInfo
534564 : ClangTypeInfo (),
535- globalActor, thrownError);
565+ globalActor, thrownError, lifetimeDependenceInfo );
536566 }
537567
538568 [[nodiscard]]
539569 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);
541578 }
542579
543580 bool isEqualTo (ASTExtInfoBuilder other, bool useClangTypes) const {
544581 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 ;
548586 }
549587
550588 constexpr std::tuple<unsigned , const void *, const void *, const void *>
@@ -573,8 +611,9 @@ class ASTExtInfo {
573611 ASTExtInfo (ASTExtInfoBuilder builder) : builder(builder) {}
574612
575613 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) {
578617 builder.checkInvariants ();
579618 };
580619
@@ -621,6 +660,10 @@ class ASTExtInfo {
621660 Type getGlobalActor () const { return builder.getGlobalActor (); }
622661 Type getThrownError () const { return builder.getThrownError (); }
623662
663+ LifetimeDependenceInfo getLifetimeDependenceInfo () const {
664+ return builder.getLifetimeDependenceInfo ();
665+ }
666+
624667 // / Helper method for changing the representation.
625668 // /
626669 // / Prefer using \c ASTExtInfoBuilder::withRepresentation for chaining.
@@ -674,6 +717,11 @@ class ASTExtInfo {
674717 return builder.withGlobalActor (globalActor).build ();
675718 }
676719
720+ [[nodiscard]] ASTExtInfo withLifetimeDependenceInfo (
721+ LifetimeDependenceInfo lifetimeDependenceInfo) const {
722+ return builder.withLifetimeDependenceInfo (lifetimeDependenceInfo).build ();
723+ }
724+
677725 bool isEqualTo (ASTExtInfo other, bool useClangTypes) const {
678726 return builder.isEqualTo (other.builder , useClangTypes);
679727 }
0 commit comments