@@ -110,10 +110,12 @@ LifetimeDependenceInfo LifetimeDependenceInfo::getForParamIndex(
110110 auto indexSubset = IndexSubset::get (ctx, capacity, {index});
111111 if (kind == LifetimeDependenceKind::Scope) {
112112 return LifetimeDependenceInfo{/* inheritLifetimeParamIndices*/ nullptr ,
113- /* scopeLifetimeParamIndices*/ indexSubset};
113+ /* scopeLifetimeParamIndices*/ indexSubset,
114+ /* isImmortal*/ false };
114115 }
115116 return LifetimeDependenceInfo{/* inheritLifetimeParamIndices*/ indexSubset,
116- /* scopeLifetimeParamIndices*/ nullptr };
117+ /* scopeLifetimeParamIndices*/ nullptr ,
118+ /* isImmortal*/ false };
117119}
118120
119121void LifetimeDependenceInfo::getConcatenatedData (
@@ -246,6 +248,18 @@ LifetimeDependenceInfo::fromTypeRepr(AbstractFunctionDecl *afd) {
246248
247249 for (auto specifier : lifetimeDependentRepr->getLifetimeDependencies ()) {
248250 switch (specifier.getSpecifierKind ()) {
251+ case LifetimeDependenceSpecifier::SpecifierKind::Immortal: {
252+ auto immortalParam =
253+ std::find_if (afd->getParameters ()->begin (), afd->getParameters ()->end (), [](ParamDecl *param) {
254+ return strcmp (param->getName ().get (), " immortal" ) == 0 ;
255+ });
256+ if (immortalParam != afd->getParameters ()->end ()) {
257+ diags.diagnose (*immortalParam,
258+ diag::lifetime_dependence_immortal_conflict_name);
259+ }
260+
261+ return LifetimeDependenceInfo (nullptr , nullptr , /* isImmortal*/ true );
262+ }
249263 case LifetimeDependenceSpecifier::SpecifierKind::Named: {
250264 bool foundParamName = false ;
251265 unsigned paramIndex = 0 ;
@@ -315,7 +329,8 @@ LifetimeDependenceInfo::fromTypeRepr(AbstractFunctionDecl *afd) {
315329 : nullptr ,
316330 scopeLifetimeParamIndices.any ()
317331 ? IndexSubset::get (ctx, scopeLifetimeParamIndices)
318- : nullptr );
332+ : nullptr ,
333+ /* isImmortal*/ false );
319334}
320335
321336// This utility is similar to its overloaded version that builds the
@@ -360,18 +375,29 @@ std::optional<LifetimeDependenceInfo> LifetimeDependenceInfo::fromTypeRepr(
360375 };
361376
362377 for (auto specifier : lifetimeDependentRepr->getLifetimeDependencies ()) {
363- assert (specifier.getSpecifierKind () ==
364- LifetimeDependenceSpecifier::SpecifierKind::Ordered);
365- auto index = specifier.getIndex ();
366- if (index > capacity) {
367- diags.diagnose (specifier.getLoc (),
368- diag::lifetime_dependence_invalid_param_index, index);
369- return std::nullopt ;
378+ switch (specifier.getSpecifierKind ()) {
379+ case LifetimeDependenceSpecifier::SpecifierKind::Ordered: {
380+ auto index = specifier.getIndex ();
381+ if (index > capacity) {
382+ diags.diagnose (specifier.getLoc (),
383+ diag::lifetime_dependence_invalid_param_index, index);
384+ return std::nullopt ;
385+ }
386+ auto param = params[index];
387+ auto paramConvention = param.getConvention ();
388+ if (updateLifetimeDependenceInfo (specifier, index, paramConvention)) {
389+ return std::nullopt ;
390+ }
391+ break ;
370392 }
371- auto param = params[index];
372- auto paramConvention = param.getConvention ();
373- if (updateLifetimeDependenceInfo (specifier, index, paramConvention)) {
374- return std::nullopt ;
393+ case LifetimeDependenceSpecifier::SpecifierKind::Immortal: {
394+ return LifetimeDependenceInfo (/* inheritLifetimeParamIndices*/ nullptr ,
395+ /* scopeLifetimeParamIndices*/ nullptr ,
396+ /* isImmortal*/ true );
397+ }
398+ default :
399+ llvm_unreachable (" SIL can only have ordered or immortal lifetime "
400+ " dependence specifier kind" );
375401 }
376402 }
377403
@@ -381,7 +407,8 @@ std::optional<LifetimeDependenceInfo> LifetimeDependenceInfo::fromTypeRepr(
381407 : nullptr ,
382408 scopeLifetimeParamIndices.any ()
383409 ? IndexSubset::get (ctx, scopeLifetimeParamIndices)
384- : nullptr );
410+ : nullptr ,
411+ /* isImmortal*/ false );
385412}
386413
387414std::optional<LifetimeDependenceInfo>
@@ -510,18 +537,6 @@ LifetimeDependenceInfo::get(AbstractFunctionDecl *afd) {
510537 return LifetimeDependenceInfo::infer (afd);
511538}
512539
513- LifetimeDependenceInfo
514- LifetimeDependenceInfo::get (ASTContext &ctx,
515- const SmallBitVector &inheritLifetimeIndices,
516- const SmallBitVector &scopeLifetimeIndices) {
517- return LifetimeDependenceInfo{
518- inheritLifetimeIndices.any ()
519- ? IndexSubset::get (ctx, inheritLifetimeIndices)
520- : nullptr ,
521- scopeLifetimeIndices.any () ? IndexSubset::get (ctx, scopeLifetimeIndices)
522- : nullptr };
523- }
524-
525540std::optional<LifetimeDependenceKind>
526541LifetimeDependenceInfo::getLifetimeDependenceOnParam (unsigned paramIndex) {
527542 if (inheritLifetimeParamIndices) {
0 commit comments