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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

Martin521
Copy link
Contributor

@Martin521 Martin521 commented Jun 18, 2025

Description

Fixes #18553.
Breaking change.

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.
So, I propose we leave it like this and call ApplyLineDirectives in the appropriate places in FSAC / the editors.
This will also enable better line directive support in the editors (for some use cases you need the original ranges).
For Ionide / FSAC I found that calling ApplyLineDirectives in a single place (in FSAC's fcsRangeToLspLocation) will most probably be sufficient to support the current functionality.
I don't know what it means for the other editors.
Any thoughts or recommendations here? (@TheAngryByrd @auduchinok @abonie )

List of breaking changes

  • For fsc and fcs users
    • __LINE__ and __SOURCE_FILE__ show original locations now
  • For fcs users only (tooling)
    • AST has original ranges now (ignoring #line directives) (so, also FSharpSymbol points to its original range)

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:

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

@Martin521
Copy link
Contributor Author

Martin521 commented Jun 26, 2025

This is ready for review. See updated PR description.
It introduces no changes for compiler users (except for the hardly used __LINE__ / __SOURCE_FILE__ in combination with #line).
For tooling, see the remarks above.

@Martin521 Martin521 marked this pull request as ready for review June 26, 2025 08:49
@Martin521 Martin521 requested a review from a team as a code owner June 26, 2025 08:49
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