Better manage Program options lifetimes - #64519
Open
Jake Bailey (jakebailey) wants to merge 5 commits into
Open
Jake Bailey (jakebailey) wants to merge 5 commits into
Jake Bailey (jakebailey) wants to merge 5 commits into
Conversation
Cloned programs share inclusion records, but diagnostics derived from those records can refer to a particular program's files. Caching them on the shared records lets later generations reuse diagnostics from an old program and prolong the lifetime of its source files. Keep derived diagnostics with their program and make the shared payloads explicit so the reusable records cannot hide arbitrary owners.
Resolver registrations survive the request that creates them. Retaining that request's context in their factory can send later callbacks through an already canceled context and keep request-scoped state alive. Pass the current construction request's context when creating a resolver instead of retaining it in the reusable factory.
Shared program data must not retain factory closures or hosts from an older generation. In particular, project-reference mappings outlive the construction callbacks that populate them. Keep those lifetimes in separate types while preserving the flat ProgramOptions literal used by callers. Only reusable configuration and the current hosts belong to the finished program; construction factories and mapper-building state do not.
Reusable program data must not retain a resolver that keeps its creating host and snapshot alive. Retain only host-free resolution data, and bind lazy queries to the current program host. Package lookups can populate caches after construction, so each program needs its own package-json cache table. Construction-only resolution caches do not need to survive in completed programs.
Jake Bailey (jakebailey)
requested review from
Andrew Branch (andrewbranch)
and
a balanced review from Copilot
September 29, 2026 03:31
Copilot started reviewing on behalf of
Jake Bailey (jakebailey)
September 29, 2026 03:32
View session
Contributor
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
Broad cross-cutting lifetime and cache-ownership changes warrant final human validation despite strong targeted tests.
Review effort: Balanced
Findings: None
What changed in this PR
Splits program configuration, hosts, and factories to prevent cloned programs from retaining prior program generations and associated runtime state.
Changes:
- Separates reusable program and module-resolution data from generation-specific hosts and factories.
- Makes diagnostic caches program-local and project-reference mapping host-independent.
- Adds lifetime, cache-isolation, context, and project-reference regression tests.
| File | Description |
|---|---|
tsc/internal/testutil/testutil.go |
Adds retained-data type validation. |
tsc/internal/project/snapshot.go |
Passes context to resolver factories. |
tsc/internal/project/snapshot_test.go |
Tests collection of old generations. |
tsc/internal/project/project.go |
Uses current build context for resolvers. |
tsc/internal/packagejson/cache.go |
Adds cache cloning. |
tsc/internal/module/types.go |
Exposes reusable resolution data. |
tsc/internal/module/staticresolver.go |
Delegates resolution-data access. |
tsc/internal/module/staticresolver_test.go |
Updates internal resolver tests. |
tsc/internal/module/resolver.go |
Separates resolver data from runtime caches. |
tsc/internal/module/resolver_test.go |
Tests cache and data isolation. |
tsc/internal/module/cache.go |
Defines cloneable resolution data. |
tsc/internal/compiler/projectreferenceparser.go |
Builds host-free reference mappings. |
tsc/internal/compiler/projectreferencefilemapper.go |
Splits persistent mapping from builder state. |
tsc/internal/compiler/projectreferencedtsfakinghost.go |
Rebinds mappings to current hosts. |
tsc/internal/compiler/program.go |
Separates program options and clone lifetimes. |
tsc/internal/compiler/program_test.go |
Tests ownership and cloning behavior. |
tsc/internal/compiler/processingDiagnostic.go |
Makes diagnostic payloads data-only. |
tsc/internal/compiler/includeprocessor.go |
Separates shared include data from caches. |
tsc/internal/compiler/filesparser.go |
Produces reusable include data. |
tsc/internal/compiler/fileloader.go |
Avoids retaining complete program options. |
tsc/internal/compiler/fileInclude.go |
Moves diagnostic caching onto programs. |
tsc/internal/compiler/emitHost.go |
Removes obsolete resolver delegation. |
tsc/internal/api/session.go |
Defers resolver context selection. |
tsc/internal/api/session_module_resolution_test.go |
Tests current-context propagation and cleanup. |
tsc/internal/api/module_resolution.go |
Uses per-construction callback contexts. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
The collection test intermittently exceeds its deadline under concurrent coverage runs, even after multiple completed GC cycles. Keep the deterministic ownership and cache-isolation checks without making CI depend on collection timing.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is intended to replace #64466 with something that prevents us from making this mistake in the future.
ProgramOptionsis split into three pieces:ProgramConfig- data only bits like the compiler options,SingleThreaded, etc, that can be carried between programs as they are reused.ProgramHosts- hosts likeCompilerHostandTracingthat are specific to a program but should not be carried over as new programs have different contexts.ProgramFactories- funcs to create checker pools or module resolvers which are only called on constructionSplitting these up allows us to only persist the right ones over time and discard them when no longer needed, making it harder to accidentally retain old state.
Additionally, this PR fixes diags that are kept alive between programs (which can end up referencing old data), and tweaks the module resolver so it too has a data holding value that can be carried between.
Fixes #64465
Closes #64466