Repository: apple/swift
File: lib/AST/LifetimeDependence.cpp (C++)

Code before:

    if (implicitSelfParam && paramOrResultIndex == implicitSelfParam->index)
      return implicitSelfParam->typeInContext;

    return parameterInfos[paramOrResultIndex].typeInContext;
  }

private:
  static auto collectLifetimeEntries(DeclAttributes const &attrs) {
    decltype(lifetimeEntries) lifetimeEntries;
    for (auto attr : attrs.getAttributes<LifetimeAttr>()) {
      lifetimeEntries.push_back(attr->getLifetimeEntry());
    }
    return lifetimeEntries;
  }

  static auto collectParameterInfo(ParameterList const *params,
                                   DeclContext *DC) {
    decltype(parameterInfos) parameterInfos;
    for (auto paramAndIndex : enumerate(*params)) {
      const ParamDecl *param = paramAndIndex.value();
      parameterInfos.push_back(
        {param->toFunctionParam(), (unsigned)paramAndIndex.index(),
         param->getLoc(),
         DC->mapTypeIntoEnvironment(param->getInterfaceType())});
    }
    return parameterInfos;
  }

public:
  LifetimeDependenceChecker(AbstractFunctionDecl *afd)
      : lifetimeEntries(collectLifetimeEntries(afd->getAttrs())),
        parameterInfos(collectParameterInfo(afd->getParameters(), afd)),
        afd(afd),
        ctx(afd->getDeclContext()->getASTContext()),
        sourceFile(afd->getParentSourceFile()),
        escapableDecl(
          ctx.getProtocol(
            swift::getKnownProtocolKind(InvertibleProtocolKind::Escapable))),
        genericEnv(afd->getGenericEnvironment()),
        resultIndex(getResultIndex(afd)),
        resultInterfaceType(getResultOrYieldInterface(afd)),
        resultTy(afd->mapTypeIntoEnvironment(resultInterfaceType)),
        returnLoc(getReturnLoc(afd)),
        implicitSelfParam(getSelfParamInfo(afd)),
        depBuilder(/*sourceIndexCap*/ resultIndex),
        isImplicit(afd->isImplicit()),
        isInit(isa<ConstructorDecl>(afd)),
        hasUnsafeNonEscapableResult(
          afd->getAttrs().hasAttribute<UnsafeNonEscapableResultAttr>()) {}


Review comment (suggestion):
```suggestion
    for (auto [index, param] : enumerate(*params)) {
      parameterInfos.push_back(
        {param->toFunctionParam(), (unsigned)index,
         param->getLoc(),
         DC->mapTypeIntoEnvironment(param->getInterfaceType())});
    }
```

Code after:
      return resultTy;

    if (implicitSelfParam && paramOrResultIndex == implicitSelfParam->index)
      return implicitSelfParam->typeInContext;

    return parameterInfos[paramOrResultIndex].typeInContext;
  }

private:
  static auto collectLifetimeEntries(DeclAttributes const &attrs) {
    decltype(lifetimeEntries) lifetimeEntries;
    for (auto attr : attrs.getAttributes<LifetimeAttr>()) {
      lifetimeEntries.push_back(attr->getLifetimeEntry());
    }
    return lifetimeEntries;
  }

  static auto collectParameterInfo(ParameterList const *params,
                                   DeclContext *DC) {
    decltype(parameterInfos) parameterInfos;
    for (auto [index, param] : enumerate(*params)) {
      parameterInfos.push_back(
        {param->toFunctionParam(), (unsigned)index, param->getLoc(),
         DC->mapTypeIntoEnvironment(param->getInterfaceType())});
    }
    return parameterInfos;
  }

public:
  LifetimeDependenceChecker(AbstractFunctionDecl *afd)
      : lifetimeEntries(collectLifetimeEntries(afd->getAttrs())),
        parameterInfos(collectParameterInfo(afd->getParameters(), afd)),
        afd(afd),
        ctx(afd->getDeclContext()->getASTContext()),
        sourceFile(afd->getParentSourceFile()),
        escapableDecl(
          ctx.getProtocol(
            swift::getKnownProtocolKind(InvertibleProtocolKind::Escapable))),
        genericEnv(afd->getGenericEnvironment()),
        resultIndex(getResultIndex(afd)),
        resultInterfaceType(getResultOrYieldInterface(afd)),
        resultTy(afd->mapTypeIntoEnvironment(resultInterfaceType)),
        returnLoc(getReturnLoc(afd)),
        implicitSelfParam(getSelfParamInfo(afd)),
        depBuilder(/*sourceIndexCap*/ resultIndex),
        isImplicit(afd->isImplicit()),
        isInit(isa<ConstructorDecl>(afd)),
        hasUnsafeNonEscapableResult(
          afd->getAttrs().hasAttribute<UnsafeNonEscapableResultAttr>()) {}

  std::optional<llvm::ArrayRef<LifetimeDependenceInfo>>