Skip to content

Optimizer: fix accessing captured values when skipping inlining - #20089

Merged
T-Gro merged 1 commit into
dotnet:mainfrom
auduchinok:optimizer-noInline-accessCaptured
Aug 12, 2026
Merged

Optimizer: fix accessing captured values when skipping inlining#20089
T-Gro merged 1 commit into
dotnet:mainfrom
auduchinok:optimizer-noInline-accessCaptured

Conversation

@auduchinok

@auduchinok auduchinok commented Jul 28, 2026

Copy link
Copy Markdown
Member

Fixes the captured values repro from #20063.

let f () =
    let x = 42
    let inline g y = x + int y
    g 1uy

printfn "%A (expected 43)" (f ())
let f2 () =
    let xs = [ 1; 2; 3 ]
    let inline g y = xs |> List.map (fun v -> v + int y) |> List.sum
    g 1uy

printfn "%A (expected 9)" (f2 ())

@auduchinok
auduchinok requested a review from a team as a code owner July 28, 2026 14:43
@auduchinok auduchinok added the NO_RELEASE_NOTES Label for pull requests which signals, that user opted-out of providing release notes label Jul 28, 2026
@github-actions github-actions Bot added AI-Tooling-Check-Scanned-Clean Tooling check: diff analyzed, no interesting infrastructure files ⚠️ Affects-Compiler-Output Tooling check: PR touches IL emission or codegen labels Jul 28, 2026
@github-actions

This comment has been minimized.

@github-project-automation github-project-automation Bot moved this from New to In Progress in F# Compiler and Tooling Aug 3, 2026
@T-Gro
T-Gro enabled auto-merge (squash) August 3, 2026 19:10
auto-merge was automatically disabled August 10, 2026 10:12

Head branch was pushed to by a user without write access

@auduchinok
auduchinok force-pushed the optimizer-noInline-accessCaptured branch from 6f53591 to ae4fe1b Compare August 10, 2026 10:12
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Release notes required, but author opted out

Warning

Author opted out of release notes, check is disabled for this pull request.
cc @dotnet/fsharp-team-msft

@auduchinok

Copy link
Copy Markdown
Member Author

This is ready.

@github-actions

Copy link
Copy Markdown
Contributor

🔍 Tooling Safety Check — Affects-Compiler-Output
Affects-Compiler-Output: modifies Optimizer.fs (IL output)

Generated by PR Tooling Safety Check · opus46 5.7M ·

@T-Gro

T-Gro commented Aug 19, 2026

Copy link
Copy Markdown
Member

/backport to release/10.0.4xx

Resurfaced as #20297 against SDK 10.0.400 — AccessViolationException when an inline function is applied inside a nested closure in a Debug build. That branch has #19548 but not this fix. The cherry-pick applies cleanly, the repro passes with it, and the DebugInlineAsCall suite is green there (79/79). #20299 adds a regression test for that callsite shape and is worth taking along.

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/10.0.4xx (link to workflow run)

@T-Gro

T-Gro commented Aug 21, 2026

Copy link
Copy Markdown
Member

/backport to release/dev18.9

@T-Gro

T-Gro commented Aug 21, 2026

Copy link
Copy Markdown
Member

/backport to release/dev18.10

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/dev18.9 (link to workflow run)

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/dev18.10 (link to workflow run)

@github-actions

Copy link
Copy Markdown
Contributor

@T-Gro an error occurred while backporting to release/dev18.10. See the workflow output for details.

@github-actions

Copy link
Copy Markdown
Contributor

@T-Gro an error occurred while backporting to release/dev18.9. See the workflow output for details.

@T-Gro

T-Gro commented Aug 24, 2026

Copy link
Copy Markdown
Member

/backport to release/dev18.9

@T-Gro

T-Gro commented Aug 24, 2026

Copy link
Copy Markdown
Member

/backport to release/dev18.10

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/dev18.9 (link to workflow run)

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/dev18.10 (link to workflow run)

T-Gro added a commit that referenced this pull request Aug 24, 2026
…20299)

* Test: debug-inline capture of a local function from a nested-closure callsite

Regression coverage for #20297. The reduced repro keeps the reported
shape - a captured local function, a callsite inside a nested closure,
and '>>' composition - and crashes with AccessViolationException on
release/10.0.4xx, where <addEnum>__debug@N is emitted as a two-argument
static method that does 'ldarg.0; ldfld tee' against the string
parameter. It passes once #20089 is present.

SRTP 30-38 all call the inline function directly from the enclosing
method, so none of them cover a callsite inside a closure.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* Minimize SRTP 39 debug-inline capture repro test

Address review feedback: strip printfn and addName noise from the repro so the emitted-IL baseline is easier to follow. The minimized source keeps all essential ingredients (inline function whose body is a lambda capturing an outer local 'tee', used first-class inside a nested closure via >>) and the SRTP 'int value'/ExplicitDynamic aspect, so <addEnum>__debug@N still reaches the captured local through a closure field.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <copilot@github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

⚠️ Affects-Compiler-Output Tooling check: PR touches IL emission or codegen AI-Tooling-Check-Scanned-Clean Tooling check: diff analyzed, no interesting infrastructure files NO_RELEASE_NOTES Label for pull requests which signals, that user opted-out of providing release notes

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants