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