@@ -104,7 +104,9 @@ LifetimeDependenceInfo LifetimeDependenceInfo::getForParamIndex(
104
104
AbstractFunctionDecl *afd, unsigned index, LifetimeDependenceKind kind) {
105
105
auto *dc = afd->getDeclContext ();
106
106
auto &ctx = dc->getASTContext ();
107
- unsigned capacity = afd->getParameters ()->size () + 1 ;
107
+ unsigned capacity = afd->hasImplicitSelfDecl ()
108
+ ? (afd->getParameters ()->size () + 1 )
109
+ : afd->getParameters ()->size ();
108
110
auto indexSubset = IndexSubset::get (ctx, capacity, {index });
109
111
if (kind == LifetimeDependenceKind::Scope) {
110
112
return LifetimeDependenceInfo{/* inheritLifetimeParamIndices*/ nullptr ,
@@ -176,7 +178,9 @@ LifetimeDependenceInfo::fromTypeRepr(AbstractFunctionDecl *afd, Type resultType,
176
178
auto &ctx = dc->getASTContext ();
177
179
auto *mod = afd->getModuleContext ();
178
180
auto &diags = ctx.Diags ;
179
- auto capacity = afd->getParameters ()->size () + 1 ;
181
+ auto capacity = afd->hasImplicitSelfDecl ()
182
+ ? (afd->getParameters ()->size () + 1 )
183
+ : afd->getParameters ()->size ();
180
184
auto lifetimeDependentRepr =
181
185
cast<LifetimeDependentReturnTypeRepr>(afd->getResultTypeRepr ());
182
186
@@ -252,7 +256,7 @@ LifetimeDependenceInfo::fromTypeRepr(AbstractFunctionDecl *afd, Type resultType,
252
256
for (auto *param : *afd->getParameters ()) {
253
257
if (param->getParameterName () == specifier.getName ()) {
254
258
if (updateLifetimeDependenceInfo (
255
- specifier, paramIndex + 1 ,
259
+ specifier, paramIndex,
256
260
afd->mapTypeIntoContext (
257
261
param->toFunctionParam ().getParameterType ()),
258
262
param->getValueOwnership ())) {
@@ -278,17 +282,14 @@ LifetimeDependenceInfo::fromTypeRepr(AbstractFunctionDecl *afd, Type resultType,
278
282
diag::lifetime_dependence_invalid_param_index, index );
279
283
return std::nullopt;
280
284
}
281
- if (index != 0 ) {
282
- auto param = afd->getParameters ()->get (index - 1 );
283
- auto ownership = param->getValueOwnership ();
284
- auto type = afd->mapTypeIntoContext (
285
- param->toFunctionParam ().getParameterType ());
286
- if (updateLifetimeDependenceInfo (specifier, index , type, ownership)) {
287
- return std::nullopt;
288
- }
289
- break ;
285
+ auto param = afd->getParameters ()->get (index );
286
+ auto ownership = param->getValueOwnership ();
287
+ auto type =
288
+ afd->mapTypeIntoContext (param->toFunctionParam ().getParameterType ());
289
+ if (updateLifetimeDependenceInfo (specifier, index , type, ownership)) {
290
+ return std::nullopt;
290
291
}
291
- LLVM_FALLTHROUGH ;
292
+ break ;
292
293
}
293
294
case LifetimeDependenceSpecifier::SpecifierKind::Self: {
294
295
if (!afd->hasImplicitSelfDecl ()) {
@@ -302,7 +303,7 @@ LifetimeDependenceInfo::fromTypeRepr(AbstractFunctionDecl *afd, Type resultType,
302
303
return std::nullopt;
303
304
}
304
305
if (updateLifetimeDependenceInfo (
305
- specifier, /* selfIndex*/ 0 ,
306
+ specifier, /* selfIndex */ afd-> getParameters ()-> size () ,
306
307
afd->getImplicitSelfDecl ()->getTypeInContext (),
307
308
afd->getImplicitSelfDecl ()->getValueOwnership ())) {
308
309
return std::nullopt;
@@ -326,11 +327,10 @@ LifetimeDependenceInfo::fromTypeRepr(AbstractFunctionDecl *afd, Type resultType,
326
327
// apis on type and ownership is different in SIL compared to Sema.
327
328
std::optional<LifetimeDependenceInfo> LifetimeDependenceInfo::fromTypeRepr (
328
329
LifetimeDependentReturnTypeRepr *lifetimeDependentRepr,
329
- SmallVectorImpl<SILParameterInfo> ¶ms, bool hasSelfParam,
330
- DeclContext *dc) {
330
+ SmallVectorImpl<SILParameterInfo> ¶ms, DeclContext *dc) {
331
331
auto &ctx = dc->getASTContext ();
332
332
auto &diags = ctx.Diags ;
333
- auto capacity = hasSelfParam ? params.size () : params. size () + 1 ;
333
+ auto capacity = params.size (); // SIL parameters include self
334
334
335
335
SmallBitVector inheritLifetimeParamIndices (capacity);
336
336
SmallBitVector scopeLifetimeParamIndices (capacity);
@@ -367,17 +367,12 @@ std::optional<LifetimeDependenceInfo> LifetimeDependenceInfo::fromTypeRepr(
367
367
assert (specifier.getSpecifierKind () ==
368
368
LifetimeDependenceSpecifier::SpecifierKind::Ordered);
369
369
auto index = specifier.getIndex ();
370
- if (index > params. size () ) {
370
+ if (index > capacity ) {
371
371
diags.diagnose (specifier.getLoc (),
372
372
diag::lifetime_dependence_invalid_param_index, index );
373
373
return std::nullopt;
374
374
}
375
- if (index == 0 && !hasSelfParam) {
376
- diags.diagnose (specifier.getLoc (),
377
- diag::lifetime_dependence_invalid_self_in_static);
378
- return std::nullopt;
379
- }
380
- auto param = index == 0 ? params.back () : params[index - 1 ];
375
+ auto param = params[index ];
381
376
auto paramConvention = param.getConvention ();
382
377
if (updateLifetimeDependenceInfo (specifier, index , paramConvention)) {
383
378
return std::nullopt;
@@ -451,7 +446,8 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
451
446
diag::lifetime_dependence_invalid_self_ownership);
452
447
return std::nullopt;
453
448
}
454
- return LifetimeDependenceInfo::getForParamIndex (afd, /* selfIndex*/ 0 , kind);
449
+ return LifetimeDependenceInfo::getForParamIndex (
450
+ afd, /* selfIndex*/ afd->getParameters ()->size (), kind);
455
451
}
456
452
457
453
LifetimeDependenceInfo lifetimeDependenceInfo;
@@ -493,7 +489,7 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
493
489
}
494
490
candidateParam = param;
495
491
lifetimeDependenceInfo =
496
- LifetimeDependenceInfo::getForParamIndex (afd, paramIndex + 1 , lifetimeKind);
492
+ LifetimeDependenceInfo::getForParamIndex (afd, paramIndex, lifetimeKind);
497
493
}
498
494
499
495
if (!candidateParam && !hasParamError) {
0 commit comments