Skip to content

Fix FS0192 Iterate2D from ReflectedDefinition over a recursive value - #20488

Open
T-Gro wants to merge 5 commits into
mainfrom
fix/issue-20379
Open

Fix FS0192 Iterate2D from ReflectedDefinition over a recursive value#20488
T-Gro wants to merge 5 commits into
mainfrom
fix/issue-20379

Conversation

@T-Gro

@T-Gro T-Gro commented Sep 8, 2026

Copy link
Copy Markdown
Member

Fixes #20379

A [<ReflectedDefinition(true)>] parameter that auto-quotes an argument capturing a not-yet-generalized use of an inferred generically-recursive function triggered internal error FS0192 "Iterate2D". The auto-quoted (Expr.WithValue) copy now keeps a fresh link to the recursive-value use, so it receives the same inferred type arguments that are applied at the letrec point as the executable expression.

Copilot and others added 5 commits September 8, 2026 10:58
…ric recursion ICE)

Adds three failing ComponentTests proving the FS0192 'internal error: Iterate2D'
crash when [<ReflectedDefinition(true)>] on a parameter is used from an inferred
generically-recursive function. No compiler source changed; a later sprint fixes it.
Includes red-evidence-sprint01.txt showing all three tests failing with Iterate2D.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A [<ReflectedDefinition(true)>] parameter auto-quotes its argument via
Expr.WithValue (mkCallLiftValueWithDefn), which copies the argument with
copyExpr. copyExpr inlines Expr.Link fixup nodes at copy time, so a use of an
inferred generically-recursive function captured in the argument was snapshotted
before AdjustAndForgetUsesOfRecValue inserted the generalized type arguments at
the letrec point. The detached snapshot kept zero type arguments while the value
had formal typars, so GetWitnessArgs' Iterate2D zip failed with FS0192.

The auto-quote copy now uses copyExprKeepingRecursiveValLinks, which keeps a
fresh Expr.Link pointing at the original recursive-use fixup node (only for
values still in their letrec scope) so the quoted copy receives the same
inferred type arguments as the executable expression. Both Quote true and
Quote false conversions are unaffected for non-recursive uses, and FS1230 for
inner generic functions in quotations still fires.

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

Broaden regression coverage for the FS0192 (Iterate2D) fix: mutual recursion,
nested lambdas/captures/shadowing, static and instance attributed methods,
cross-assembly attributed API, single-evaluation of the auto-quoted argument,
controls (false-attribute/nonrecursive/ordinary/explicit-quotation/monomorphic/
explicit-generic), and preservation of FS1230 for inner generic functions.

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

Expert-review hardening: isRecursiveValFixupLink now matches only the
exact fixup shape Expr.App(Expr.Val _, _, _, [], _) with empty value args,
matching what AdjustAndForgetUsesOfRecValue accepts. Strictly more precise;
no behavior change for the sole Remap.Empty/CloneAll auto-quote caller.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The isRecursiveValFixupLink predicate over-matched monomorphic recursive
data values (lazy-initialized 'let rec'). Such a value's shared fixup node
is re-mutated to a lazy 'Force' by EliminateInitializationGraphs, so keeping
a link to it leaked a 'Force(ValueWithName ...)' node into the auto-quoted
(WithValue) definition. Only function-valued recursive bindings benefit from
link preservation and are bound as lambdas (never lazy-morphed), so restrict
the predicate to values whose ValReprInfo has curried arguments.

Adds a monomorphic-recursive-data-value regression test asserting no lazy
Force leaks into the captured quotation. Also removes a stray committed
red-evidence log artifact.

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

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

❗ Release notes required

You can open this PR in browser to add release notes: open in github.dev


✅ 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/11.0.100.md No current pull request URL (#20488) found, please consider adding it

@github-actions github-actions Bot added the AI-Tooling-Check-Bypassed Tooling check: non-fork PR, not diff-analyzed label Sep 8, 2026
@T-Gro
T-Gro requested a review from abonie September 9, 2026 08:24
@T-Gro T-Gro added the AI-reviewed PR reviewed by AI review council label Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI-reviewed PR reviewed by AI review council AI-Tooling-Check-Bypassed Tooling check: non-fork PR, not diff-analyzed

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

internal error Iterate2D with ReflectedDefinition and recursion

1 participant