<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/113950>113950</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Reduce `Decl`'s dependency on `DeclContext`/other Decls.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            erichkeane
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          erichkeane
      </td>
    </tr>
</table>

<pre>
    One of the outcomes of the llvm-dev talk by @zygoloid is that it got me thinking about ways to improve template instantiation time.  One such problem is that we rebuild every `Decl` every time, particularly `VarDecl` thanks to its link to its `DeclContext` and other `Decl`s, instead of being able ot use them like we do with some `Stmt` nodes.

There are three steps to this:
1- Remove the dependency on `DeclContext` for `Decl` types where this doesn't matter.  From a quick look, it seems that various `FunctionDecl` types probably still need the link, as does `VarDecl`s at the global state, so moving this out of `Decl` and reproducing the `DeclContext` references in each place it is needed (plus conditionally NOT referencing it in the `VarDecl` case) is likely a great first step.

2- Replace the `DeclContext::decls` implementation/storage.  Currently this is done by using a linked-list as a part of `Decl`, which obviously causes a dependency on the "next" declaration, so we could only re-use the 'last' declarations. Instead, we could perhaps have some sort of storage on `DeclContext` itself to do this relationship.

3- Update instantiation of various `Decl` types to re-use the node if none of its children change.  `VarDecl` in the "parent is a function decl" case is probably a great first step that ends up saving us a bit, but other types likely assume they always need to be rebuilt.  This part is likely a long-tail, but we can enable it via 1 and 2.

FILING this as an issue so that someone someday will work on this. I don't really have time short-term, so if someone is wanting to take this one, please feel free!
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEVU-P27gO_zTKhUiQyOlkcsihr0UeCjy0QF9377TFxNrIklekk_V--gVlZ5qgA-xlPOORyR9_fyhk9udIdDAf_mOspeyb9kIYyVhrPnxe4CBtyoef7xd1cuPhWyRIJ5CWIA3SpI74_ncI127p6AqC4QL1CGa7_ns8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