@@ -3590,7 +3590,8 @@ class DeclDeserializer {
35903590 ctor->setParameters (bodyParams);
35913591
35923592 SmallVector<LifetimeDependenceSpecifier> specifierList;
3593- if (MF.maybeReadLifetimeDependence (specifierList, bodyParams->size ())) {
3593+ if (MF.maybeReadLifetimeDependenceSpecifier (specifierList,
3594+ bodyParams->size ())) {
35943595 auto SelfType = ctor->getDeclaredInterfaceType ();
35953596 auto typeRepr = new (ctx) FixedTypeRepr (SelfType, SourceLoc ());
35963597 auto lifetimeTypeRepr =
@@ -4159,7 +4160,8 @@ class DeclDeserializer {
41594160 ParameterList *paramList = MF.readParameterList ();
41604161 fn->setParameters (paramList);
41614162 SmallVector<LifetimeDependenceSpecifier> specifierList;
4162- if (MF.maybeReadLifetimeDependence (specifierList, paramList->size ())) {
4163+ if (MF.maybeReadLifetimeDependenceSpecifier (specifierList,
4164+ paramList->size ())) {
41634165 auto typeRepr = new (ctx) FixedTypeRepr (resultType, SourceLoc ());
41644166 auto lifetimeTypeRepr =
41654167 LifetimeDependentReturnTypeRepr::create (ctx, typeRepr, specifierList);
@@ -6851,7 +6853,6 @@ detail::function_deserializer::deserialize(ModuleFile &MF,
68516853 isolation = swift::FunctionTypeIsolation::forGlobalActor (globalActorTy.get ());
68526854 }
68536855
6854- // TODO: Handle LifetimeDependenceInfo here.
68556856 auto info = FunctionType::ExtInfoBuilder (
68566857 *representation, noescape, throws, thrownError, *diffKind,
68576858 clangFunctionType, isolation, LifetimeDependenceInfo (),
@@ -6866,6 +6867,7 @@ detail::function_deserializer::deserialize(ModuleFile &MF,
68666867
68676868 SmallVector<AnyFunctionType::Param, 8 > params;
68686869 while (true ) {
6870+ BCOffsetRAII restoreOffset (MF.DeclTypeCursor );
68696871 llvm::BitstreamEntry entry =
68706872 MF.fatalIfUnexpected (MF.DeclTypeCursor .advance (AF_DontPopBlockAtEnd));
68716873 if (entry.Kind != llvm::BitstreamEntry::Record)
@@ -6877,6 +6879,8 @@ detail::function_deserializer::deserialize(ModuleFile &MF,
68776879 if (recordID != decls_block::FUNCTION_PARAM)
68786880 break ;
68796881
6882+ restoreOffset.reset ();
6883+
68806884 IdentifierID labelID;
68816885 IdentifierID internalLabelID;
68826886 TypeID typeID;
@@ -6907,6 +6911,13 @@ detail::function_deserializer::deserialize(ModuleFile &MF,
69076911 MF.getIdentifier (internalLabelID));
69086912 }
69096913
6914+ auto lifetimeDependenceInfo =
6915+ MF.maybeReadLifetimeDependenceInfo (params.size ());
6916+
6917+ if (lifetimeDependenceInfo.has_value ()) {
6918+ info = info.withLifetimeDependenceInfo (*lifetimeDependenceInfo);
6919+ }
6920+
69106921 if (!isGeneric) {
69116922 assert (genericSig.isNull ());
69126923 return FunctionType::get (params, resultTy.get (), info);
@@ -7384,7 +7395,6 @@ Expected<Type> DESERIALIZE_TYPE(SIL_FUNCTION_TYPE)(
73847395 if (erasedIsolation)
73857396 isolation = SILFunctionTypeIsolation::Erased;
73867397
7387- // Handle LifetimeDependenceInfo here.
73887398 auto extInfo =
73897399 SILFunctionType::ExtInfoBuilder (
73907400 *representation, pseudogeneric, noescape, concurrent, async,
@@ -7527,6 +7537,13 @@ Expected<Type> DESERIALIZE_TYPE(SIL_FUNCTION_TYPE)(
75277537 if (!patternSubsOrErr)
75287538 return patternSubsOrErr.takeError ();
75297539
7540+ auto lifetimeDependenceInfo = MF.maybeReadLifetimeDependenceInfo (
7541+ extInfo.hasSelfParam () ? numParams : numParams + 1 );
7542+
7543+ if (lifetimeDependenceInfo.has_value ()) {
7544+ extInfo = extInfo.withLifetimeDependenceInfo (*lifetimeDependenceInfo);
7545+ }
7546+
75307547 return SILFunctionType::get (invocationSig, extInfo, coroutineKind.value (),
75317548 calleeConvention.value (), allParams, allYields,
75327549 allResults, errorResult,
@@ -8687,11 +8704,9 @@ ModuleFile::maybeReadForeignAsyncConvention() {
86878704 errorFlagPolarity);
86888705}
86898706
8690- bool ModuleFile::maybeReadLifetimeDependence (
8691- SmallVectorImpl<LifetimeDependenceSpecifier> &specifierList,
8692- unsigned numParams) {
8707+ bool ModuleFile::maybeReadLifetimeDependenceRecord (
8708+ SmallVectorImpl<uint64_t > &scratch) {
86938709 using namespace decls_block ;
8694- SmallVector<uint64_t , 8 > scratch;
86958710
86968711 BCOffsetRAII restoreOffset (DeclTypeCursor);
86978712
@@ -8711,22 +8726,82 @@ bool ModuleFile::maybeReadLifetimeDependence(
87118726 return false ;
87128727 }
87138728
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;
87158790 ArrayRef<uint64_t > lifetimeDependenceData;
87168791 LifetimeDependenceLayout::readRecord (scratch, hasInheritLifetimeParamIndices,
87178792 hasScopeLifetimeParamIndices,
87188793 lifetimeDependenceData);
87198794
87208795 unsigned startIndex = 0 ;
87218796 auto pushData = [&](LifetimeDependenceKind kind) {
8722- for (unsigned i = 0 ; i < numParams + 1 ; i++) {
8797+ for (unsigned i = 0 ; i < numDeclParams + 1 ; i++) {
87238798 if (lifetimeDependenceData[startIndex + i]) {
87248799 specifierList.push_back (
87258800 LifetimeDependenceSpecifier::getOrderedLifetimeDependenceSpecifier (
87268801 SourceLoc (), kind, i));
87278802 }
87288803 }
8729- startIndex += numParams + 1 ;
8804+ startIndex += numDeclParams + 1 ;
87308805 };
87318806
87328807 if (hasInheritLifetimeParamIndices) {
0 commit comments