Skip to content

Transparent Compiler: check a single file using only its dependency subgraph - #20889

Open
nojaf wants to merge 6 commits into
dotnet:mainfrom
nojaf:tc-dependency-subgraph
Open

nojaf wants to merge 6 commits into
dotnet:mainfrom
nojaf:tc-dependency-subgraph

Conversation

@nojaf

@nojaf nojaf commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #20850

When the Transparent Compiler checks a single file, it type checks every file before it, including files the checked file does not depend on. Tools that only need the typed tree of one file (Telplin generating a signature for one file, analyzers, code generators) pay for the whole project.

The snapshot overload of FSharpChecker.ParseAndCheckFileInProject takes a new optional ?checkDependenciesOnly. When it is set, the file's dependency graph is trimmed with Graph.subGraphFor, the line that was commented out in ComputeDependencyGraphForFile, so only the checked file and its transitive dependencies are type checked. The full check stays the default, and the BackgroundCompiler ignores the flag.

What a caller gets:

  • The typed tree, tcEnv and the checked file's own diagnostics are the same as with a full check. Even in a full check, each file is checked against the state of its graph dependencies only, so the subgraph only skips the files that were never needed.
  • The partial assembly signature and DependencyFiles only cover the file and its dependencies.
  • These results bypass the ParseAndCheckFileInProject cache, so a later full ParseAndCheckFileInProject, TryGetRecentCheckResultsForFile or GetCachedCheckFileResult never gets them. The per-file TcIntermediate cache is shared between both modes, which is safe because every file in the subgraph starts from the same input state in both.
  • FSharp.Core uses a linear graph, so it still checks every prior file.

subGraphFor now uses a HashSet instead of Array.contains.

Measurement

A synthetic project of 30 independent files (750 declarations each), plus a Last.fs that uses only F01. A new checker for each check, Release build:

File checked Time
F02.fs, all prior files 390–410 ms
Last.fs, all prior files 1930–1940 ms
Last.fs, dependencies only 340–430 ms

Tests

  • We don't check files that are not depended on now uses the new mode, and its commented-out assertion (check "FileSecond.fs" []) is enabled.
  • A full check after a dependencies-only check type checks only the skipped file, and the signature is unchanged.
  • The two modes report the same diagnostics for a file with a type error.
  • A dependency through a .fsi, and a checked file with its own .fsi.
  • A dependencies-only result is not returned by TryGetRecentCheckResultsForFile.
  • A direct unit test for Graph.subGraphFor.

Not in this PR

The skipped Files that are not depended on don't invalidate cache tests still fail. TcIntermediate is keyed on all prior files (FileKey(index)), so editing an unrelated earlier file still invalidates the checked file. Keying it on the file's dependencies is what the original design did, and it was removed when signature-file support went in (0101@0a35243). That is a separate change.

Question for maintainers

Was there a reason, beyond the missing "complete vs minimal" request type, that the subgraph was disabled in that commit?

Checklist

  • Test cases added
  • Performance benchmarks added in case of performance changes
  • Release notes entry updated

When the Transparent Compiler checks a single file, it type checks every
file before it, even files the checked file does not depend on. Tools
that only need the typed tree of one file, such as signature generators
and analyzers, pay for the whole project.

The snapshot overload of FSharpChecker.ParseAndCheckFileInProject takes
a new optional ?checkDependenciesOnly. When set, the dependency graph is
trimmed with Graph.subGraphFor to the checked file and its transitive
dependencies. The typed tree of the file is the same as with a full
check. The partial assembly signature and DependencyFiles only cover the
file and its dependencies, so these results bypass the
ParseAndCheckFileInProject cache and are never served to later full
requests. The BackgroundCompiler ignores the flag. The full check stays
the default.

subGraphFor now uses a HashSet lookup instead of Array.contains.

Re-enables the assertion in "We don't check files that are not depended
on" and adds tests for signature parity, diagnostics parity, signature
files, and the cache bypass.

dotnet#20850
@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

✅ Release notes checked


✅ Found changes and release notes in following paths:

Change path Release notes path Description
`src/Compiler` docs/release-notes/.FSharp.Compiler.Service/11.0.200.md

@nojaf nojaf changed the title TC: opt-in check of a file's dependency subgraph only Transparent Compiler: check a single file using only its dependency subgraph Oct 30, 2026
@nojaf
nojaf marked this pull request as ready for review October 30, 2026 12:28
@nojaf
nojaf requested a review from a team as a code owner October 30, 2026 12:28

@T-Gro T-Gro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 🕵️ LGTM

@github-project-automation github-project-automation Bot moved this from New to In Progress in F# Compiler and Tooling Nov 2, 2026
@T-Gro T-Gro added the AI-reviewed PR reviewed by AI review council label Nov 2, 2026
@T-Gro
T-Gro self-requested a review November 2, 2026 12:32
nojaf added 4 commits November 2, 2026 20:55
The conflict resolution in merge 54ec285 took main's signature and
dropped the parameter, while the body and callers still use it, so
TransparentCompiler.fs no longer compiled.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI-reviewed PR reviewed by AI review council Transparent-Compiler

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

Transparent Compiler: check a single file using only its dependency subgraph

2 participants