Skip to content

Refactor #line processing - keep the original positions in the AST #18699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Martin521
Copy link
Contributor

Description

Fixes #18553.
Breaking change.
Work in Progress.

This PR is non-breaking for two of the three #line use cases mentioned in #18553.
It keeps the original ranges in the AST, stores the #line directives in a table and provides a method range.ApplyLineDirectives(). This method is applied in the following places

  • construction of runtime diagnostics in pattern match compilation
  • emitting debug information in quotation translation
  • creating IL source markers (debug information)
  • formatting fsc compiler diagnostics (CompilerDiagnostics.FormatDiagnosticLocation)
  • creating service diagnostics (FSharpDiagnostics.CreateFromException)

This should make sure that all debugging information (in .pdb) and all diagnostics stay unchanged.

The third use case, symbol positions for IDE editors, is more tricky. FSharpSymbol has no range field or property that I could apply the transformation to, but just contains (and makes public) the AST items with their original ranges.
I am considering different options here, this is still work in progress. One option is to leave calling ApplyLineDirectives to the user (e.g. FSAC). (To possibly offer both positions to the IDE using PositionLink.)
I am still trying to find my way through FSAC and LSP protocol. I am assuming now that the target location (rather than the original) is needed only for the various go-to requests and some naviation items.
Any thoughts or recommendations here? (@TheAngryByrd @auduchinok @abonie )

List of breaking changes

  • AST has original ranges now (ignoring #line directives)
  • __LINE__ and __SOURCE_FILE__ show original locations now
  • Symbols t.b.d.

Checklist

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

Copy link
Contributor

github-actions bot commented Jun 18, 2025

❗ Release notes required


✅ Found changes and release notes in following paths:

Warning

No PR link found in some release notes, please consider adding it.

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/10.0.100.md No current pull request URL (#18699) found, please consider adding it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: New
Development

Successfully merging this pull request may close these issues.

Keep original line information in AST ranges, add separate mechanism for #line directives
1 participant