@@ -110,10 +110,12 @@ LifetimeDependenceInfo LifetimeDependenceInfo::getForParamIndex(
110
110
auto indexSubset = IndexSubset::get (ctx, capacity, {index });
111
111
if (kind == LifetimeDependenceKind::Scope) {
112
112
return LifetimeDependenceInfo{/* inheritLifetimeParamIndices*/ nullptr ,
113
- /* scopeLifetimeParamIndices*/ indexSubset};
113
+ /* scopeLifetimeParamIndices*/ indexSubset,
114
+ /* isImmortal*/ false };
114
115
}
115
116
return LifetimeDependenceInfo{/* inheritLifetimeParamIndices*/ indexSubset,
116
- /* scopeLifetimeParamIndices*/ nullptr };
117
+ /* scopeLifetimeParamIndices*/ nullptr ,
118
+ /* isImmortal*/ false };
117
119
}
118
120
119
121
void LifetimeDependenceInfo::getConcatenatedData (
@@ -246,6 +248,18 @@ LifetimeDependenceInfo::fromTypeRepr(AbstractFunctionDecl *afd) {
246
248
247
249
for (auto specifier : lifetimeDependentRepr->getLifetimeDependencies ()) {
248
250
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
+ }
249
263
case LifetimeDependenceSpecifier::SpecifierKind::Named: {
250
264
bool foundParamName = false ;
251
265
unsigned paramIndex = 0 ;
@@ -315,7 +329,8 @@ LifetimeDependenceInfo::fromTypeRepr(AbstractFunctionDecl *afd) {
315
329
: nullptr ,
316
330
scopeLifetimeParamIndices.any ()
317
331
? IndexSubset::get (ctx, scopeLifetimeParamIndices)
318
- : nullptr );
332
+ : nullptr ,
333
+ /* isImmortal*/ false );
319
334
}
320
335
321
336
// This utility is similar to its overloaded version that builds the
@@ -360,18 +375,29 @@ std::optional<LifetimeDependenceInfo> LifetimeDependenceInfo::fromTypeRepr(
360
375
};
361
376
362
377
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 ;
370
392
}
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" );
375
401
}
376
402
}
377
403
@@ -381,7 +407,8 @@ std::optional<LifetimeDependenceInfo> LifetimeDependenceInfo::fromTypeRepr(
381
407
: nullptr ,
382
408
scopeLifetimeParamIndices.any ()
383
409
? IndexSubset::get (ctx, scopeLifetimeParamIndices)
384
- : nullptr );
410
+ : nullptr ,
411
+ /* isImmortal*/ false );
385
412
}
386
413
387
414
std::optional<LifetimeDependenceInfo>
@@ -510,18 +537,6 @@ LifetimeDependenceInfo::get(AbstractFunctionDecl *afd) {
510
537
return LifetimeDependenceInfo::infer (afd);
511
538
}
512
539
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
-
525
540
std::optional<LifetimeDependenceKind>
526
541
LifetimeDependenceInfo::getLifetimeDependenceOnParam (unsigned paramIndex) {
527
542
if (inheritLifetimeParamIndices) {
0 commit comments