Repository navigation
Skip the constraint solver for calls without trait constraints in expression conversion - #21059
Open
TheAngryByrd wants to merge 2 commits into
Open
TheAngryByrd wants to merge 2 commits into
TheAngryByrd wants to merge 2 commits into
Conversation
Contributor
✅ Release notes checked
|
…ression conversion Converting a call of a generic value to FSharpExpr created a constraint solver state and freshened the type parameters even when no type parameter has a trait constraint, so no witness can result. Return no witnesses at once in that case, and reuse the InfoReader of the SymbolEnv for the other calls. Allocation to convert and print 300 calls of a generic function without trait constraints: 82769 bytes per call before, 9625 bytes per call after. The new test fails before the change and passes after it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
TheAngryByrd
force-pushed
the
fcs-witnesses-skip-without-trait-constraints
branch
from
December 2, 2026 04:35
1d93451 to
6823238
Compare
This branch has not been deployed
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.
Description
Converting a call of a generic value to
FSharpExprcreates a constraint solver state and a newInfoReader, and freshens the type parameters. It does this on every call, also when no type parameter has a trait constraint. In that case no witness can result.This PR does two things:
CodegenWitnessesForTyparInstreturns no witnesses at once when no type parameter has aMayResolveMemberconstraint.FSharpExprConvertreuses theInfoReaderof itsSymbolEnvfor the other calls, through a newCodegenWitnessesForTyparInstUsing.CodegenWitnessesForTyparInstkeeps its signature.Fixes #21057
Measurements:
The new test converts and prints 300 calls of a generic function without trait constraints. It allocates 82,769 bytes per call before the change and 9,625 bytes per call after it.
Harness (https://gist.github.com/TheAngryByrd/5cd6633f1a265ca296c978b6e5d28ec8): check a project, convert every implementation file with
FSharpImplementationFileContents, print every expression tree. Median of 6 fresh-process runs, base85903b5f57.41d0560205df7b89The printed trees are identical before and after in every run.
Tools that read the typed tree (for example WebSharper) convert every call of every generic function, so they pay this cost most.
Checklist
ExprTests.fs. I can add a BenchmarkDotNet benchmark undertests/benchmarksif you prefer.🤖 Generated with Claude Code