@@ -4105,6 +4105,13 @@ class DeclDeserializer {
41054105
41064106 ParameterList *paramList = MF.readParameterList ();
41074107 fn->setParameters (paramList);
4108+ SmallVector<LifetimeDependenceSpecifier> specifierList;
4109+ if (MF.maybeReadLifetimeDependence (specifierList, paramList->size ())) {
4110+ auto typeRepr = new (ctx) FixedTypeRepr (resultType, SourceLoc ());
4111+ auto lifetimeTypeRepr =
4112+ LifetimeDependentReturnTypeRepr::create (ctx, typeRepr, specifierList);
4113+ fn->setDeserializedResultTypeLoc (TypeLoc (lifetimeTypeRepr, resultType));
4114+ }
41084115
41094116 if (auto errorConvention = MF.maybeReadForeignErrorConvention ())
41104117 fn->setForeignErrorConvention (*errorConvention);
@@ -8548,3 +8555,58 @@ ModuleFile::maybeReadForeignAsyncConvention() {
85488555 completionHandlerErrorFlagParamIndex,
85498556 errorFlagPolarity);
85508557}
8558+
8559+ bool ModuleFile::maybeReadLifetimeDependence (
8560+ SmallVectorImpl<LifetimeDependenceSpecifier> &specifierList,
8561+ unsigned numParams) {
8562+ using namespace decls_block ;
8563+ SmallVector<uint64_t , 8 > scratch;
8564+
8565+ BCOffsetRAII restoreOffset (DeclTypeCursor);
8566+
8567+ llvm::BitstreamEntry next =
8568+ fatalIfUnexpected (DeclTypeCursor.advance (AF_DontPopBlockAtEnd));
8569+ if (next.Kind != llvm::BitstreamEntry::Record)
8570+ return false ;
8571+
8572+ unsigned recKind =
8573+ fatalIfUnexpected (DeclTypeCursor.readRecord (next.ID , scratch));
8574+ switch (recKind) {
8575+ case LIFETIME_DEPENDENCE:
8576+ restoreOffset.reset ();
8577+ break ;
8578+
8579+ default :
8580+ return false ;
8581+ }
8582+
8583+ bool hasInheritLifetimeParamIndices, hasBorrowLifetimeParamIndices,
8584+ hasMutateLifetimeParamIndices;
8585+ ArrayRef<uint64_t > lifetimeDependenceData;
8586+ LifetimeDependenceLayout::readRecord (
8587+ scratch, hasInheritLifetimeParamIndices, hasBorrowLifetimeParamIndices,
8588+ hasMutateLifetimeParamIndices, lifetimeDependenceData);
8589+
8590+ unsigned startIndex = 0 ;
8591+ auto pushData = [&](LifetimeDependenceKind kind) {
8592+ for (unsigned i = 0 ; i < numParams + 1 ; i++) {
8593+ if (lifetimeDependenceData[startIndex + i]) {
8594+ specifierList.push_back (
8595+ LifetimeDependenceSpecifier::getOrderedLifetimeDependenceSpecifier (
8596+ SourceLoc (), kind, i));
8597+ }
8598+ }
8599+ startIndex += numParams + 1 ;
8600+ };
8601+
8602+ if (hasInheritLifetimeParamIndices) {
8603+ pushData (LifetimeDependenceKind::Consume);
8604+ }
8605+ if (hasBorrowLifetimeParamIndices) {
8606+ pushData (LifetimeDependenceKind::Borrow);
8607+ }
8608+ if (hasMutateLifetimeParamIndices) {
8609+ pushData (LifetimeDependenceKind::Mutate);
8610+ }
8611+ return true ;
8612+ }
0 commit comments