-
Notifications
You must be signed in to change notification settings - Fork 826
Eenable LanguageFeature.UnmanagedConstraintCsharpInterop for F# 10.0 #18737
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The feature UnmanagedConstraintCsharpInterop generates invalid IL in the Specialize method. Add a test to verify the exact reported issue by compiling and running. For debugging this, also add a test which will verifyIL of that piece of code. Make sure to run the tests with previewVersion language feature, otherwise it will not kick in. |
Co-authored-by: T-Gro <[email protected]>
…erop - Add test that reproduces the original lambda issue reported in #17509 - Add test that verifies the invalid IL generation in Specialize method - Tests show that when UnmanagedConstraintCsharpInterop is enabled with preview version, it generates modreq constraint in the Specialize method IL which causes TypeLoadException - This demonstrates the root cause of the issue: invalid IL generation in lambda constraints Co-authored-by: T-Gro <[email protected]>
... I've added the requested tests to reproduce issue #17509. The tests now demonstrate the exact problem: when The key issue is in the generated IL: .method public strict virtual instance object Specialize<valuetype (class [runtime]System.ValueType modreq([runtime]System.Runtime.InteropServices.UnmanagedType)) T>() cil managed The Tests added in commit 9f670d0:
Both tests run with previewVersion as requested. The tests now clearly show the root cause of the issue. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
tests/FSharp.Compiler.ComponentTests/Conformance/Constraints/Unmanaged.fs
Outdated
Show resolved
Hide resolved
tests/FSharp.Compiler.ComponentTests/Conformance/Constraints/Unmanaged.fs
Outdated
Show resolved
Hide resolved
tests/FSharp.Compiler.ComponentTests/Conformance/Constraints/Unmanaged.fs
Outdated
Show resolved
Hide resolved
tests/FSharp.Compiler.ComponentTests/Conformance/Constraints/Unmanaged.fs
Outdated
Show resolved
Hide resolved
…and IL verification Co-authored-by: T-Gro <[email protected]>
/run fantomas |
🔧 CLI Command Report
✅ Command succeeded, no changes needed. |
Summary
Re-enables the
UnmanagedConstraintCsharpInterop
language feature for F#109.0 to fix a TypeLoadException that occurs when using unmanaged constraints in lambda expressions.Problem
Runtime Error:
Solution
Well, copilot tried many times to hack it around by disabling bunch of closure related codegen in IlxGen, but it only kept making things worse.
The (human discovered) solution makes sure the right closure generation style is picked (there are two main forms, well documented in comments in IL generation and closure lowering).
The function isCompiledOrWitnessPassingConstraint asks "Which constraints actually get compiled to .NET constraints?" Unmanaged constraints absolutely DO compile to IL (modreq(System.Runtime.InteropServices.UnmanagedType)), so they belong in this list alongside:
class constraints
struct constraints
new() constraints
base type constraints