From 05c81d5063cec2b1fc7990476c4846622d68f70a Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Wed, 26 Aug 2026 17:22:49 +0200 Subject: [PATCH 1/2] Inline TryD to remove closure allocations in the constraint solver Make `TryD` inline with `[]` on the always-evaluated `f` argument so the `f`/`g` lambda closures are no longer allocated at each call site (hottest: SolveTypeEqualsType via SolveTypeEqualsTypeKeepAbbrevsWithCxsln). `IgnoreFailedMemberConstraintResolution` is made inline so its non-literal `f1` propagates as a lambda, keeping InlineIfLambda satisfied without FS3517. Pure inline refactor: byte-identical compiler output (deterministic self-compile SHA-256 match); no behavior change. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- src/Compiler/Checking/ConstraintSolver.fs | 2 +- src/Compiler/Facilities/DiagnosticsLogger.fs | 2 +- src/Compiler/Facilities/DiagnosticsLogger.fsi | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Compiler/Checking/ConstraintSolver.fs b/src/Compiler/Checking/ConstraintSolver.fs index 838a534f2a2..fcdfa301dd0 100644 --- a/src/Compiler/Checking/ConstraintSolver.fs +++ b/src/Compiler/Checking/ConstraintSolver.fs @@ -589,7 +589,7 @@ exception NonRigidTypar of displayEnv: DisplayEnv * string option * range * TTyp exception AbortForFailedMemberConstraintResolution /// This is used internally in method overload resolution -let IgnoreFailedMemberConstraintResolution f1 f2 = +let inline IgnoreFailedMemberConstraintResolution ([] f1) f2 = TryD f1 (function diff --git a/src/Compiler/Facilities/DiagnosticsLogger.fs b/src/Compiler/Facilities/DiagnosticsLogger.fs index 77351b7dd89..8f1689f2cf7 100644 --- a/src/Compiler/Facilities/DiagnosticsLogger.fs +++ b/src/Compiler/Facilities/DiagnosticsLogger.fs @@ -747,7 +747,7 @@ let rec Iterate2D f xs ys = /// Keep the warnings, propagate the error to the exception continuation. [] -let TryD f g = +let inline TryD ([] f) g = match f () with | ErrorResult(warns, err) -> trackErrors { diff --git a/src/Compiler/Facilities/DiagnosticsLogger.fsi b/src/Compiler/Facilities/DiagnosticsLogger.fsi index 66377aac861..1d148e65c05 100644 --- a/src/Compiler/Facilities/DiagnosticsLogger.fsi +++ b/src/Compiler/Facilities/DiagnosticsLogger.fsi @@ -408,7 +408,7 @@ val IterateIdxD: f: (int -> 'T -> OperationResult) -> xs: 'T list -> Opera /// Stop on first error. Accumulate warnings and continue. val Iterate2D: f: ('T -> 'b -> OperationResult) -> xs: 'T list -> ys: 'b list -> OperationResult -val TryD: f: (unit -> OperationResult<'T>) -> g: (exn -> OperationResult<'T>) -> OperationResult<'T> +val inline TryD: f: (unit -> OperationResult<'T>) -> g: (exn -> OperationResult<'T>) -> OperationResult<'T> val RepeatWhileD: nDeep: int -> body: (int -> OperationResult) -> OperationResult From d1a44af1662b40e3a074f5d928a50841d3ff9df1 Mon Sep 17 00:00:00 2001 From: Copilot Date: Fri, 28 Aug 2026 07:59:04 +0200 Subject: [PATCH 2/2] Add release notes entry for constraint-solver TryD inlining (#20367) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- docs/release-notes/.FSharp.Compiler.Service/11.0.100.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md b/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md index 562632e460d..e1dc6d20e5c 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md +++ b/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md @@ -187,6 +187,7 @@ * IL: cache the ILTypeRef of a type def ([PR #20259](https://github.com/dotnet/fsharp/pull/20259)) * IL: use empty tables for members when possible ([PR #20249](https://github.com/dotnet/fsharp/pull/20249)) * Make Entity's adhoc members list lazy ([PR #20286](https://github.com/dotnet/fsharp/pull/20286/changes)) +* Constraint solver: `TryD` is now `inline` with `[]` on its always-run continuation, so the argument closures are no longer allocated at the (very hot) constraint-solver call sites; `IgnoreFailedMemberConstraintResolution` is `inline` so its forwarded continuation stays a literal. ([PR #20367](https://github.com/dotnet/fsharp/pull/20367)) ### Changed * The `--warnaserror` option now ignores unrecognized diagnostic identifiers in warning lists while still applying recognized F# warning codes. ([PR #20246](https://github.com/dotnet/fsharp/pull/20246))