@@ -104,7 +104,9 @@ LifetimeDependenceInfo LifetimeDependenceInfo::getForParamIndex(
104104 AbstractFunctionDecl *afd, unsigned index, LifetimeDependenceKind kind) {
105105 auto *dc = afd->getDeclContext ();
106106 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 ();
108110 auto indexSubset = IndexSubset::get (ctx, capacity, {index});
109111 if (kind == LifetimeDependenceKind::Scope) {
110112 return LifetimeDependenceInfo{/* inheritLifetimeParamIndices*/ nullptr ,
@@ -176,7 +178,9 @@ LifetimeDependenceInfo::fromTypeRepr(AbstractFunctionDecl *afd, Type resultType,
176178 auto &ctx = dc->getASTContext ();
177179 auto *mod = afd->getModuleContext ();
178180 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 ();
180184 auto lifetimeDependentRepr =
181185 cast<LifetimeDependentReturnTypeRepr>(afd->getResultTypeRepr ());
182186
@@ -252,7 +256,7 @@ LifetimeDependenceInfo::fromTypeRepr(AbstractFunctionDecl *afd, Type resultType,
252256 for (auto *param : *afd->getParameters ()) {
253257 if (param->getParameterName () == specifier.getName ()) {
254258 if (updateLifetimeDependenceInfo (
255- specifier, paramIndex + 1 ,
259+ specifier, paramIndex,
256260 afd->mapTypeIntoContext (
257261 param->toFunctionParam ().getParameterType ()),
258262 param->getValueOwnership ())) {
@@ -278,17 +282,14 @@ LifetimeDependenceInfo::fromTypeRepr(AbstractFunctionDecl *afd, Type resultType,
278282 diag::lifetime_dependence_invalid_param_index, index);
279283 return std::nullopt ;
280284 }
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 ;
290291 }
291- LLVM_FALLTHROUGH ;
292+ break ;
292293 }
293294 case LifetimeDependenceSpecifier::SpecifierKind::Self: {
294295 if (!afd->hasImplicitSelfDecl ()) {
@@ -302,7 +303,7 @@ LifetimeDependenceInfo::fromTypeRepr(AbstractFunctionDecl *afd, Type resultType,
302303 return std::nullopt ;
303304 }
304305 if (updateLifetimeDependenceInfo (
305- specifier, /* selfIndex*/ 0 ,
306+ specifier, /* selfIndex */ afd-> getParameters ()-> size () ,
306307 afd->getImplicitSelfDecl ()->getTypeInContext (),
307308 afd->getImplicitSelfDecl ()->getValueOwnership ())) {
308309 return std::nullopt ;
@@ -326,11 +327,10 @@ LifetimeDependenceInfo::fromTypeRepr(AbstractFunctionDecl *afd, Type resultType,
326327// apis on type and ownership is different in SIL compared to Sema.
327328std::optional<LifetimeDependenceInfo> LifetimeDependenceInfo::fromTypeRepr (
328329 LifetimeDependentReturnTypeRepr *lifetimeDependentRepr,
329- SmallVectorImpl<SILParameterInfo> ¶ms, bool hasSelfParam,
330- DeclContext *dc) {
330+ SmallVectorImpl<SILParameterInfo> ¶ms, DeclContext *dc) {
331331 auto &ctx = dc->getASTContext ();
332332 auto &diags = ctx.Diags ;
333- auto capacity = hasSelfParam ? params.size () : params. size () + 1 ;
333+ auto capacity = params.size (); // SIL parameters include self
334334
335335 SmallBitVector inheritLifetimeParamIndices (capacity);
336336 SmallBitVector scopeLifetimeParamIndices (capacity);
@@ -367,17 +367,12 @@ std::optional<LifetimeDependenceInfo> LifetimeDependenceInfo::fromTypeRepr(
367367 assert (specifier.getSpecifierKind () ==
368368 LifetimeDependenceSpecifier::SpecifierKind::Ordered);
369369 auto index = specifier.getIndex ();
370- if (index > params. size () ) {
370+ if (index > capacity ) {
371371 diags.diagnose (specifier.getLoc (),
372372 diag::lifetime_dependence_invalid_param_index, index);
373373 return std::nullopt ;
374374 }
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];
381376 auto paramConvention = param.getConvention ();
382377 if (updateLifetimeDependenceInfo (specifier, index, paramConvention)) {
383378 return std::nullopt ;
@@ -451,7 +446,8 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
451446 diag::lifetime_dependence_invalid_self_ownership);
452447 return std::nullopt ;
453448 }
454- return LifetimeDependenceInfo::getForParamIndex (afd, /* selfIndex*/ 0 , kind);
449+ return LifetimeDependenceInfo::getForParamIndex (
450+ afd, /* selfIndex*/ afd->getParameters ()->size (), kind);
455451 }
456452
457453 LifetimeDependenceInfo lifetimeDependenceInfo;
@@ -493,7 +489,7 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
493489 }
494490 candidateParam = param;
495491 lifetimeDependenceInfo =
496- LifetimeDependenceInfo::getForParamIndex (afd, paramIndex + 1 , lifetimeKind);
492+ LifetimeDependenceInfo::getForParamIndex (afd, paramIndex, lifetimeKind);
497493 }
498494
499495 if (!candidateParam && !hasParamError) {
0 commit comments