Uh oh!
There was an error while loading. Please reload this page.
Unify let, let!, use, use!LetOrUse AST representation. - #18825
Conversation
Ensure that regular let/use bindings (isComputed=false) are matched before let!/use! bindings (isComputed=true) to prevent computation expressions from being treated as regular bindings.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
T-Gro
left a comment
There was a problem hiding this comment.
Since this changes the public API, I think this deserves some form of impact analysis for this change, and some guidance around the change.
https://github.com/search?q=LetOrUseBang+language%3AF%23&type=code&l=F%23
8ddf826 to
596202bCompareUh oh!
There was an error while loading. Please reload this page.
596202b to
b1ed90bCompare
T-Gro
left a comment
There was a problem hiding this comment.
Please consider writing a footnote on migration towards AST users.
Can be a footnote inside the release-notes file, pointed to from the main release notes entry.
# Conflicts: # tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_netstandard2.0.bsl # tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_netstandard2.0.bsl
Head branch was pushed to by a user without write access
edgarfgp
commented
Aug 11, 2025
Done :) |
Uh oh!
There was an error while loading. Please reload this page.
| let isUse = ($1 = "use") | ||
| mkLetExpression(true, mKeyword, None, m, $8, None, Some(pat, $4, $7, mEquals, isUse)) } | ||
| mkLetExpression(true, None, m, $8, None, Some(pat, $4, $7, mKeyword, mEquals, isUse)) } |
There was a problem hiding this comment.
@edgarfgp It seems the separate rules should not be needed anymore for the computed variants of the bindings too. Could you try unifying them with the the normal ones?
nojaf
commented
Nov 14, 2025
I know I'm too late to all of this, but is would have been so useful if Now I need to check two things to ensure opt {let!abc= def ()and! foo =()()}are indeed |
Description
This PR unifies the AST representation for binding expressions by consolidating
SynExpr.LetOrUseandSynExpr.LetOrUseBanginto a singleSynExpr.LetOrUsenode. This change simplifies the AST structure and makes it more consistent for tools working with syntax trees.Key Changes
Removed:
SynExpr.LetOrUseBangcase has been completely removedExtended:
SynExpr.LetOrUsenow includes two additional boolean flags:isFromSource: Indicates whether the binding originates from user-written code (true) vs compiler-generated (false)isComputed: Distinguishes computation expression bindings (let!/use!= true) from regular bindings (let/use= false)Before and After AST Structure
Before (Two Separate Cases)
After (Unified Single Case)
Example 1: Computation Expression with
let!andand!Before AST:
After AST:
Example 2: Regular
letBindingBefore AST:
After AST:
Example 3:
use!in Computation ExpressionBefore AST:
After AST:
Complete AST Flags Mapping
(isRec, isUse, isFromSource, isComputed)let x = 42LetOrUse(false, false, true, false)let rec f x = ...LetOrUse(true, false, true, false)use file = ...LetOrUse(false, true, true, false)let! x = asyncOp()LetOrUse(false, false, true, true)use! r = getResource()LetOrUse(false, true, true, true)let! a = opA() and! b = opB()LetOrUse(false, false, true, true)LetOrUse(false, false, false, false)LetOrUse(false, false, false, true)Understanding the Boolean Flags
isFromSourcetrue: User-written code that appears in the source filefalse: Compiler-generated during transformations (pattern match compilation, CE desugaring, etc.)isComputedtrue: Computation expression binding (let!oruse!)false: Regular binding (letoruse)Migration Guidance for Ecosystem AST Users
1. Pattern Matching Updates
Before:
After:
2. Construction Updates
Before:
After:
3. Common Migration Patterns
Checking for computation expressions:
Extracting pattern and expression from let!:
Processing and! bindings:
Breaking Changes
This is a breaking change for any code that pattern matches on or constructs
SynExprvalues. All tools and libraries that work with the AST will need to be updated, including:Checklist