Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

FSharpChecker.CompileWithTypeCheckResults: give tools the type check result of a compile (related to #17260) #21062

Backlog

Description

@TheAngryByrd

Is your feature request related to a problem? Please describe.

A tool that compiles a project and also needs its type check result (symbol uses, AssemblyContents, AssemblySignature) runs the type check twice: once inside FSharpChecker.Compile and once in ParseAndCheckProject. WebSharper is an example: it translates F# to JavaScript and runs its own check next to the compile. Related: #17260 asks to reuse type check results between runs. This is the same idea inside one process.

Describe the solution you'd like

member CompileWithTypeCheckResults:
    argv: string[] * onTypeChecked: (FSharpCheckProjectResults -> unit) * ?userOpName: string ->
        Async<FSharpDiagnostic[] * exn option>

It compiles like Compile and calls onTypeChecked with the compile's own type check result, after type checking and before optimization and code generation. The result has no diagnostics, because a check with errors stops the compile before the call. The hook is an AsyncLocal in fsc.fs, so other Compile calls are not affected. My patch is 123 lines in 6 files (fsc.fs/.fsi, service.fs/.fsi, ParseAndCheckInputs.fs/.fsi).

Measurements (base 9cd6167a72 and 85903b5f57; harness: https://gist.github.com/TheAngryByrd/5cd6633f1a265ca296c978b6e5d28ec8)

Compile, then ParseAndCheckProject and read symbol uses and AssemblyContents, against one CompileWithTypeCheckResults. Median of 6 alternating fresh-process runs. The machine was shared with other work, so the CPU numbers are rough. Treat them as a direction, not a result.

Project CPU, compile plus check CPU, one call with results
Giraffe 41d05602 14.7 s 11.0 s
FsToolkit.ErrorHandling 05df7b89 26.9 s 21.2 s
  • The typed trees and the output dlls are equal in every run.
  • The symbol uses are equal on Giraffe (8,089 uses). On FsToolkit (27,584 uses) 13 entries differ in IsFromDefinition. The cause is the check order. The stock sequential check records the implicit open of the namespace first. The compile path checks in graph mode, and records the binding first. With --parallelcompilation- there are 0 differences.
  • Collecting the real symbol uses in the compile path costs about +0.2 s (Giraffe) and +1.0 s (FsToolkit) of CPU.

Describe alternatives you've considered

Run the check twice, as tools do now. A cache of check results between runs (#17260) is a larger design and does not remove the second check inside one process.

Additional context

The typed tree is shared with the optimizer. The optimizer writes Val.val_logical_name and the compiler-generated flag (Optimizer.fs TryOptimizeVal), and replaces the module type of a module with a signature (Optimizer.fs). A reader that reads after the hook returns can see changed data. A synchronous reader that finishes before the hook returns does not. The XML doc of the API says so. Details: dotnet-websharper/core#1707.

I have a branch and can open a PR if you want this.

🤖 Generated with Claude Code

Activity

  1. added this to the Backlog milestone on Dec 2, 2026
  2. TheAngryByrd commented on Dec 2, 2026

    @TheAngryByrd
    ContributorAuthor

    The patch is on a branch, so you can see what I mean: https://github.com/TheAngryByrd/visualfsharp/tree/fcs-compile-with-typecheck-results (commit 63e5fd092d, 123 lines in 6 files, base 9cd6167a72). It has no tests yet. I will add tests and open a PR if you want this API.

    Automated comment from Claude, posted for Jimmy Byrd.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions