@@ -414,48 +414,6 @@ LifetimeDependenceInfo::fromLifetimeAttribute(AbstractFunctionDecl *afd) {
414414}
415415
416416std::optional<LifetimeDependenceInfo>
417- LifetimeDependenceInfo::fromDependsOn (AbstractFunctionDecl *afd,
418- TypeRepr *targetTypeRepr, Type targetType,
419- unsigned targetIndex) {
420- auto *dc = afd->getDeclContext ();
421- auto &ctx = dc->getASTContext ();
422- auto &diags = ctx.Diags ;
423-
424- auto *lifetimeDependentRepr =
425- dyn_cast_or_null<LifetimeDependentTypeRepr>(targetTypeRepr);
426- if (!lifetimeDependentRepr) {
427- return std::nullopt ;
428- }
429-
430- if (targetType->isEscapable ()) {
431- diags.diagnose (targetTypeRepr->getLoc (),
432- diag::lifetime_dependence_invalid_type);
433- return std::nullopt ;
434- }
435-
436- auto capacity = afd->hasImplicitSelfDecl ()
437- ? (afd->getParameters ()->size () + 1 )
438- : afd->getParameters ()->size ();
439-
440- SmallBitVector inheritIndices (capacity);
441- SmallBitVector scopeIndices (capacity);
442- bool isImmortal = false ;
443- bool hasError = false ;
444-
445- for (auto entry : lifetimeDependentRepr->getLifetimeDependencies ()) {
446- hasError |= populateLifetimeDependence (afd, entry, inheritIndices,
447- scopeIndices, isImmortal);
448- }
449-
450- if (hasError) {
451- return std::nullopt ;
452- }
453- return LifetimeDependenceInfo (
454- inheritIndices.any () ? IndexSubset::get (ctx, inheritIndices) : nullptr ,
455- scopeIndices.any () ? IndexSubset::get (ctx, scopeIndices) : nullptr ,
456- targetIndex, isImmortal);
457- }
458-
459417// This utility is similar to its overloaded version that builds the
460418// LifetimeDependenceInfo from the swift decl. Reason for duplicated code is
461419// the apis on type and ownership is different in SIL compared to Sema.
@@ -735,38 +693,12 @@ LifetimeDependenceInfo::get(AbstractFunctionDecl *afd) {
735693 return LifetimeDependenceInfo::fromLifetimeAttribute (afd);
736694 }
737695
738- SmallVector<LifetimeDependenceInfo> lifetimeDependencies;
739-
740- for (unsigned targetIndex : indices (*afd->getParameters ())) {
741- auto *param = (*afd->getParameters ())[targetIndex];
742- auto paramType =
743- afd->mapTypeIntoContext (param->toFunctionParam ().getParameterType ());
744- if (auto result = LifetimeDependenceInfo::fromDependsOn (
745- afd, param->getTypeRepr (), paramType, targetIndex)) {
746- lifetimeDependencies.push_back (*result);
747- }
748- }
749-
750- std::optional<LifetimeDependenceInfo> resultDependence;
751-
752- if (auto *lifetimeTypeRepr = dyn_cast_or_null<LifetimeDependentTypeRepr>(
753- afd->getResultTypeRepr ())) {
754- resultDependence = LifetimeDependenceInfo::fromDependsOn (
755- afd, lifetimeTypeRepr, getResultOrYield (afd),
756- afd->hasImplicitSelfDecl () ? afd->getParameters ()->size () + 1
757- : afd->getParameters ()->size ());
758- } else {
759- resultDependence = LifetimeDependenceInfo::infer (afd);
760- }
761-
762- if (resultDependence.has_value ()) {
763- lifetimeDependencies.push_back (*resultDependence);
764- }
765-
766- if (lifetimeDependencies.empty ()) {
696+ SmallVector<LifetimeDependenceInfo, 1 > lifetimeDependencies;
697+ auto resultDependence = LifetimeDependenceInfo::infer (afd);
698+ if (!resultDependence.has_value ()) {
767699 return std::nullopt ;
768700 }
769-
701+ lifetimeDependencies. push_back (*resultDependence);
770702 return afd->getASTContext ().AllocateCopy (lifetimeDependencies);
771703}
772704
0 commit comments