Fix degraded codegen for inner recursive functions under realsig#19882
Open
T-Gro wants to merge 4 commits into
Open
Fix degraded codegen for inner recursive functions under realsig#19882T-Gro wants to merge 4 commits into
T-Gro wants to merge 4 commits into
Conversation
Two codegen bugs fixed: 1. TLR (Top-Level Routing) was disabled under --realsig+ via a blanket short-circuit in InnerLambdasToTopLevelFuncs, causing inner recursive functions to be emitted as closure classes instead of static methods. This produced ~23× perf regression for struct mutual recursion (#17607). Fix: Remove the realsig band-aid. Instead, add a moduleCloc field to IlxGenEnv that always points to the enclosing non-generic module class. TLR-lifted vals (IsCompiledAsTopLevel && !IsMemberOrModuleBinding) are routed to moduleCloc, preventing them from inheriting class typars of a generic enclosing type. 2. Constrained inline generics, when inlined into closures, attached their constraints to the closure class's type params. The Specialize<T> override (from FSharpTypeFunc) must be unconstrained to match its base signature. When constraints leaked, the JIT threw TypeLoadException (#14492). Fix: In EraseClosures CASE 1, strip constraints from both the Specialize override method-typars (CASE 1b) and the later closure class-typars (CASE 1a) at the CASE 1 head. Rewrite stripILGenericParamConstraints via mkILSimpleTypar to be future-proof (clears all constraint fields including CustomAttrsStored which carries IsUnmanagedAttribute). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…sent HOF - verifyILContains now throws on mismatch instead of silently returning CompilationResult.Failure (which callers were ignoring with |> ignore). - Unify checkILPresent/checkILNotPresent via shared checkILFragments HOF. - Expose verifyILPresent in Compiler.fs (symmetric with verifyILNotPresent). - Fix TypeTests.fs assertions exposed by the silent-failure fix. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
New test files: - Regression_TLR_MutualInnerRec_StructuralAssertions.fs: 20 tests covering TLR scenarios (generic class, nested module, three-way rec, quotation, value rec) and constraint stripping (IL shape, ILVerify, >5 params CASE 2a, combined TLR+constraint). All run under both realsig on/off. - Regression_Specialize_ConstraintVerification.fs: 14 tests exercising each ILGenericParameterDef field stripped by mkILSimpleTypar (struct, not struct, unmanaged, new(), interface, comparison, combined) via ILVerify + run. - 4 new IL-baseline source files (mutual rec, captured env, generic, Point2D) with Off/On .il.bsl pairs confirming realsig parity. Regenerated baselines: - TestFunction06, TestFunction23: closures replaced by static methods - Match01: clo@4 closure removed (TLR fires under realsig+) - Unmanaged: virtual DirectInvoke → static func@3 Note: Match01 and TestFunction23 .net472.bsl baselines need TEST_UPDATE_BSL=1 regeneration on Windows CI (macOS cannot target net472). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ix (#14492) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
❗ Release notes required
Warning No PR link found in some release notes, please consider adding it.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #17607 and #14492.
Under
--realsig+(default since .NET 9), inner recursive functions were not lifted to static methods by TLR, producing closure allocations and losingtail.calls — causing up to 23× perf regression for struct-heavy mutual recursion.Additionally, constrained inline generics inlined into closures could leak type parameter constraints onto the
Specialize<T>override, causingTypeLoadExceptionat runtime.Note:
.net472.bslbaselines for Match01 and TestFunction23 needTEST_UPDATE_BSL=1regeneration on Windows CI.