@@ -3605,7 +3605,8 @@ class DeclDeserializer {
3605
3605
ctor->setParameters (bodyParams);
3606
3606
3607
3607
SmallVector<LifetimeDependenceSpecifier> specifierList;
3608
- if (MF.maybeReadLifetimeDependence (specifierList, bodyParams->size ())) {
3608
+ if (MF.maybeReadLifetimeDependenceSpecifier (specifierList,
3609
+ bodyParams->size ())) {
3609
3610
auto SelfType = ctor->getDeclaredInterfaceType ();
3610
3611
auto typeRepr = new (ctx) FixedTypeRepr (SelfType, SourceLoc ());
3611
3612
auto lifetimeTypeRepr =
@@ -4174,7 +4175,8 @@ class DeclDeserializer {
4174
4175
ParameterList *paramList = MF.readParameterList ();
4175
4176
fn->setParameters (paramList);
4176
4177
SmallVector<LifetimeDependenceSpecifier> specifierList;
4177
- if (MF.maybeReadLifetimeDependence (specifierList, paramList->size ())) {
4178
+ if (MF.maybeReadLifetimeDependenceSpecifier (specifierList,
4179
+ paramList->size ())) {
4178
4180
auto typeRepr = new (ctx) FixedTypeRepr (resultType, SourceLoc ());
4179
4181
auto lifetimeTypeRepr =
4180
4182
LifetimeDependentReturnTypeRepr::create (ctx, typeRepr, specifierList);
@@ -6849,7 +6851,6 @@ detail::function_deserializer::deserialize(ModuleFile &MF,
6849
6851
isolation = swift::FunctionTypeIsolation::forGlobalActor (globalActorTy.get ());
6850
6852
}
6851
6853
6852
- // TODO: Handle LifetimeDependenceInfo here.
6853
6854
auto info = FunctionType::ExtInfoBuilder (
6854
6855
*representation, noescape, throws, thrownError, *diffKind,
6855
6856
clangFunctionType, isolation, LifetimeDependenceInfo (),
@@ -6905,6 +6906,12 @@ detail::function_deserializer::deserialize(ModuleFile &MF,
6905
6906
MF.getIdentifier (internalLabelID));
6906
6907
}
6907
6908
6909
+ auto lifetimeDependenceInfo = MF.maybeReadLifetimeDependenceInfo (params.size ());
6910
+
6911
+ if (lifetimeDependenceInfo.has_value ()) {
6912
+ info = info.withLifetimeDependenceInfo (*lifetimeDependenceInfo);
6913
+ }
6914
+
6908
6915
if (!isGeneric) {
6909
6916
assert (genericSig.isNull ());
6910
6917
return FunctionType::get (params, resultTy.get (), info);
@@ -7382,7 +7389,6 @@ Expected<Type> DESERIALIZE_TYPE(SIL_FUNCTION_TYPE)(
7382
7389
if (erasedIsolation)
7383
7390
isolation = SILFunctionTypeIsolation::Erased;
7384
7391
7385
- // Handle LifetimeDependenceInfo here.
7386
7392
auto extInfo =
7387
7393
SILFunctionType::ExtInfoBuilder (
7388
7394
*representation, pseudogeneric, noescape, concurrent, async,
@@ -7525,6 +7531,13 @@ Expected<Type> DESERIALIZE_TYPE(SIL_FUNCTION_TYPE)(
7525
7531
if (!patternSubsOrErr)
7526
7532
return patternSubsOrErr.takeError ();
7527
7533
7534
+ auto lifetimeDependenceInfo = MF.maybeReadLifetimeDependenceInfo (
7535
+ extInfo.hasSelfParam () ? numParams : numParams + 1 );
7536
+
7537
+ if (lifetimeDependenceInfo.has_value ()) {
7538
+ extInfo = extInfo.withLifetimeDependenceInfo (*lifetimeDependenceInfo);
7539
+ }
7540
+
7528
7541
return SILFunctionType::get (invocationSig, extInfo, coroutineKind.value (),
7529
7542
calleeConvention.value (), allParams, allYields,
7530
7543
allResults, errorResult,
@@ -8685,11 +8698,9 @@ ModuleFile::maybeReadForeignAsyncConvention() {
8685
8698
errorFlagPolarity);
8686
8699
}
8687
8700
8688
- bool ModuleFile::maybeReadLifetimeDependence (
8689
- SmallVectorImpl<LifetimeDependenceSpecifier> &specifierList,
8690
- unsigned numParams) {
8701
+ bool ModuleFile::maybeReadLifetimeDependenceRecord (
8702
+ SmallVectorImpl<uint64_t > &scratch) {
8691
8703
using namespace decls_block ;
8692
- SmallVector<uint64_t , 8 > scratch;
8693
8704
8694
8705
BCOffsetRAII restoreOffset (DeclTypeCursor);
8695
8706
@@ -8709,22 +8720,82 @@ bool ModuleFile::maybeReadLifetimeDependence(
8709
8720
return false ;
8710
8721
}
8711
8722
8712
- bool hasInheritLifetimeParamIndices, hasScopeLifetimeParamIndices;
8723
+ return true ;
8724
+ }
8725
+
8726
+ std::optional<LifetimeDependenceInfo>
8727
+ ModuleFile::maybeReadLifetimeDependenceInfo (unsigned numParams) {
8728
+ using namespace decls_block ;
8729
+
8730
+ SmallVector<uint64_t , 8 > scratch;
8731
+ if (!maybeReadLifetimeDependenceRecord (scratch)) {
8732
+ return std::nullopt;
8733
+ }
8734
+
8735
+ bool hasInheritLifetimeParamIndices;
8736
+ bool hasScopeLifetimeParamIndices;
8737
+ ArrayRef<uint64_t > lifetimeDependenceData;
8738
+ LifetimeDependenceLayout::readRecord (scratch, hasInheritLifetimeParamIndices,
8739
+ hasScopeLifetimeParamIndices,
8740
+ lifetimeDependenceData);
8741
+
8742
+ SmallBitVector inheritLifetimeParamIndices (numParams, false );
8743
+ SmallBitVector scopeLifetimeParamIndices (numParams, false );
8744
+
8745
+ unsigned startIndex = 0 ;
8746
+ auto pushData = [&](SmallBitVector &bits) {
8747
+ for (unsigned i = 0 ; i < numParams; i++) {
8748
+ if (lifetimeDependenceData[startIndex + i]) {
8749
+ bits.set (i);
8750
+ }
8751
+ }
8752
+ startIndex += numParams;
8753
+ };
8754
+
8755
+ if (hasInheritLifetimeParamIndices) {
8756
+ pushData (inheritLifetimeParamIndices);
8757
+ }
8758
+ if (hasScopeLifetimeParamIndices) {
8759
+ pushData (scopeLifetimeParamIndices);
8760
+ }
8761
+
8762
+ ASTContext &ctx = getContext ();
8763
+ return LifetimeDependenceInfo (
8764
+ hasInheritLifetimeParamIndices
8765
+ ? IndexSubset::get (ctx, inheritLifetimeParamIndices)
8766
+ : nullptr ,
8767
+ hasScopeLifetimeParamIndices
8768
+ ? IndexSubset::get (ctx, scopeLifetimeParamIndices)
8769
+ : nullptr );
8770
+ }
8771
+
8772
+ bool ModuleFile::maybeReadLifetimeDependenceSpecifier (
8773
+ SmallVectorImpl<LifetimeDependenceSpecifier> &specifierList,
8774
+ unsigned numDeclParams) {
8775
+ using namespace decls_block ;
8776
+
8777
+ SmallVector<uint64_t , 8 > scratch;
8778
+ if (!maybeReadLifetimeDependenceRecord (scratch)) {
8779
+ return false ;
8780
+ }
8781
+
8782
+ bool hasInheritLifetimeParamIndices;
8783
+ bool hasScopeLifetimeParamIndices;
8713
8784
ArrayRef<uint64_t > lifetimeDependenceData;
8714
8785
LifetimeDependenceLayout::readRecord (scratch, hasInheritLifetimeParamIndices,
8715
8786
hasScopeLifetimeParamIndices,
8716
8787
lifetimeDependenceData);
8717
8788
8718
8789
unsigned startIndex = 0 ;
8719
8790
auto pushData = [&](LifetimeDependenceKind kind) {
8720
- for (unsigned i = 0 ; i < numParams + 1 ; i++) {
8791
+ for (unsigned i = 0 ; i < numDeclParams + 1 ; i++) {
8721
8792
if (lifetimeDependenceData[startIndex + i]) {
8722
8793
specifierList.push_back (
8723
8794
LifetimeDependenceSpecifier::getOrderedLifetimeDependenceSpecifier (
8724
8795
SourceLoc (), kind, i));
8725
8796
}
8726
8797
}
8727
- startIndex += numParams + 1 ;
8798
+ startIndex += numDeclParams + 1 ;
8728
8799
};
8729
8800
8730
8801
if (hasInheritLifetimeParamIndices) {
0 commit comments