[labs/analyzer] Improve module cache invalidation corner cases
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 21.8k
- Forks
- 1.1k
- Avg merge
- 18h 25m
- Merged PRs (30d)
- 2
Description
https://github.com/lit/lit/pull/3333 adds the ability to return cached modules, using a cache invalidation scheme that walks the graph of any previously dereferenced models for dependencies to ensure that they are still valid, based on comparing the ts.SourceFile a given model was created with against the one in the current ts.Program.
There are a couple of cases this invalidation scheme does not cover, which may be important in plugin use cases:
- Type information cached in a module may become invalid based on a change to a different module if we haven't yet dereferenced the model for that module. Since specifically type information comes from the typechecker rather than other models, we don't need to have dereferenced the dependency model to have relied on information from it.
- Related, if an import fails to resolve and later becomes resolvable, we need to know to re-validate a model that depended on it, since the typechecker would have returned
anyfor types it depended on from that module.
There are a few options:
- Walk the entire dependency graph when invalidating; this would eagerly create at least minimal models for all modules in the graph and is thus a performance concern, but likely the most robust.
- Keep a reverse dependency -> dependent graph when parsing a module, and upon updates to a dependency invalidate all dependents. This wouldn't catch filesystem changes unrelated from a dependency module being analyzes however, since it would only invalidate when a given dependency is re-analyzed.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading PR #3333 and the module cache invalidation implementation it introduced. Compare the two uncovered cases against the proposed graph-walking and reverse-dependency approaches, then define tests showing invalidation after an indirect type change and after a previously unresolved import becomes resolvable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100