@@ -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 (),
@@ -6866,6 +6867,7 @@ detail::function_deserializer::deserialize(ModuleFile &MF,
6866
6867
6867
6868
SmallVector<AnyFunctionType::Param, 8 > params;
6868
6869
while (true ) {
6870
+ BCOffsetRAII restoreOffset (MF.DeclTypeCursor );
6869
6871
llvm::BitstreamEntry entry =
6870
6872
MF.fatalIfUnexpected (MF.DeclTypeCursor .advance (AF_DontPopBlockAtEnd));
6871
6873
if (entry.Kind != llvm::BitstreamEntry::Record)
@@ -6877,6 +6879,8 @@ detail::function_deserializer::deserialize(ModuleFile &MF,
6877
6879
if (recordID != decls_block::FUNCTION_PARAM)
6878
6880
break ;
6879
6881
6882
+ restoreOffset.reset ();
6883
+
6880
6884
IdentifierID labelID;
6881
6885
IdentifierID internalLabelID;
6882
6886
TypeID typeID;
@@ -6907,6 +6911,13 @@ detail::function_deserializer::deserialize(ModuleFile &MF,
6907
6911
MF.getIdentifier (internalLabelID));
6908
6912
}
6909
6913
6914
+ auto lifetimeDependenceInfo =
6915
+ MF.maybeReadLifetimeDependenceInfo (params.size ());
6916
+
6917
+ if (lifetimeDependenceInfo.has_value ()) {
6918
+ info = info.withLifetimeDependenceInfo (*lifetimeDependenceInfo);
6919
+ }
6920
+
6910
6921
if (!isGeneric) {
6911
6922
assert (genericSig.isNull ());
6912
6923
return FunctionType::get (params, resultTy.get (), info);
@@ -7384,7 +7395,6 @@ Expected<Type> DESERIALIZE_TYPE(SIL_FUNCTION_TYPE)(
7384
7395
if (erasedIsolation)
7385
7396
isolation = SILFunctionTypeIsolation::Erased;
7386
7397
7387
- // Handle LifetimeDependenceInfo here.
7388
7398
auto extInfo =
7389
7399
SILFunctionType::ExtInfoBuilder (
7390
7400
*representation, pseudogeneric, noescape, concurrent, async,
@@ -7527,6 +7537,13 @@ Expected<Type> DESERIALIZE_TYPE(SIL_FUNCTION_TYPE)(
7527
7537
if (!patternSubsOrErr)
7528
7538
return patternSubsOrErr.takeError ();
7529
7539
7540
+ auto lifetimeDependenceInfo = MF.maybeReadLifetimeDependenceInfo (
7541
+ extInfo.hasSelfParam () ? numParams : numParams + 1 );
7542
+
7543
+ if (lifetimeDependenceInfo.has_value ()) {
7544
+ extInfo = extInfo.withLifetimeDependenceInfo (*lifetimeDependenceInfo);
7545
+ }
7546
+
7530
7547
return SILFunctionType::get (invocationSig, extInfo, coroutineKind.value (),
7531
7548
calleeConvention.value (), allParams, allYields,
7532
7549
allResults, errorResult,
@@ -8687,11 +8704,9 @@ ModuleFile::maybeReadForeignAsyncConvention() {
8687
8704
errorFlagPolarity);
8688
8705
}
8689
8706
8690
- bool ModuleFile::maybeReadLifetimeDependence (
8691
- SmallVectorImpl<LifetimeDependenceSpecifier> &specifierList,
8692
- unsigned numParams) {
8707
+ bool ModuleFile::maybeReadLifetimeDependenceRecord (
8708
+ SmallVectorImpl<uint64_t > &scratch) {
8693
8709
using namespace decls_block ;
8694
- SmallVector<uint64_t , 8 > scratch;
8695
8710
8696
8711
BCOffsetRAII restoreOffset (DeclTypeCursor);
8697
8712
@@ -8711,22 +8726,82 @@ bool ModuleFile::maybeReadLifetimeDependence(
8711
8726
return false ;
8712
8727
}
8713
8728
8714
- bool hasInheritLifetimeParamIndices, hasScopeLifetimeParamIndices;
8729
+ return true ;
8730
+ }
8731
+
8732
+ std::optional<LifetimeDependenceInfo>
8733
+ ModuleFile::maybeReadLifetimeDependenceInfo (unsigned numParams) {
8734
+ using namespace decls_block ;
8735
+
8736
+ SmallVector<uint64_t , 8 > scratch;
8737
+ if (!maybeReadLifetimeDependenceRecord (scratch)) {
8738
+ return std::nullopt;
8739
+ }
8740
+
8741
+ bool hasInheritLifetimeParamIndices;
8742
+ bool hasScopeLifetimeParamIndices;
8743
+ ArrayRef<uint64_t > lifetimeDependenceData;
8744
+ LifetimeDependenceLayout::readRecord (scratch, hasInheritLifetimeParamIndices,
8745
+ hasScopeLifetimeParamIndices,
8746
+ lifetimeDependenceData);
8747
+
8748
+ SmallBitVector inheritLifetimeParamIndices (numParams, false );
8749
+ SmallBitVector scopeLifetimeParamIndices (numParams, false );
8750
+
8751
+ unsigned startIndex = 0 ;
8752
+ auto pushData = [&](SmallBitVector &bits) {
8753
+ for (unsigned i = 0 ; i < numParams; i++) {
8754
+ if (lifetimeDependenceData[startIndex + i]) {
8755
+ bits.set (i);
8756
+ }
8757
+ }
8758
+ startIndex += numParams;
8759
+ };
8760
+
8761
+ if (hasInheritLifetimeParamIndices) {
8762
+ pushData (inheritLifetimeParamIndices);
8763
+ }
8764
+ if (hasScopeLifetimeParamIndices) {
8765
+ pushData (scopeLifetimeParamIndices);
8766
+ }
8767
+
8768
+ ASTContext &ctx = getContext ();
8769
+ return LifetimeDependenceInfo (
8770
+ hasInheritLifetimeParamIndices
8771
+ ? IndexSubset::get (ctx, inheritLifetimeParamIndices)
8772
+ : nullptr ,
8773
+ hasScopeLifetimeParamIndices
8774
+ ? IndexSubset::get (ctx, scopeLifetimeParamIndices)
8775
+ : nullptr );
8776
+ }
8777
+
8778
+ bool ModuleFile::maybeReadLifetimeDependenceSpecifier (
8779
+ SmallVectorImpl<LifetimeDependenceSpecifier> &specifierList,
8780
+ unsigned numDeclParams) {
8781
+ using namespace decls_block ;
8782
+
8783
+ SmallVector<uint64_t , 8 > scratch;
8784
+ if (!maybeReadLifetimeDependenceRecord (scratch)) {
8785
+ return false ;
8786
+ }
8787
+
8788
+ bool hasInheritLifetimeParamIndices;
8789
+ bool hasScopeLifetimeParamIndices;
8715
8790
ArrayRef<uint64_t > lifetimeDependenceData;
8716
8791
LifetimeDependenceLayout::readRecord (scratch, hasInheritLifetimeParamIndices,
8717
8792
hasScopeLifetimeParamIndices,
8718
8793
lifetimeDependenceData);
8719
8794
8720
8795
unsigned startIndex = 0 ;
8721
8796
auto pushData = [&](LifetimeDependenceKind kind) {
8722
- for (unsigned i = 0 ; i < numParams + 1 ; i++) {
8797
+ for (unsigned i = 0 ; i < numDeclParams + 1 ; i++) {
8723
8798
if (lifetimeDependenceData[startIndex + i]) {
8724
8799
specifierList.push_back (
8725
8800
LifetimeDependenceSpecifier::getOrderedLifetimeDependenceSpecifier (
8726
8801
SourceLoc (), kind, i));
8727
8802
}
8728
8803
}
8729
- startIndex += numParams + 1 ;
8804
+ startIndex += numDeclParams + 1 ;
8730
8805
};
8731
8806
8732
8807
if (hasInheritLifetimeParamIndices) {
0 commit comments