Fix invalid IL for generative methods declared with System.Void return type#523
Open
Thorium wants to merge 1 commit into
Open
Fix invalid IL for generative methods declared with System.Void return type#523Thorium wants to merge 1 commit into
Thorium wants to merge 1 commit into
Conversation
…n type The unit-return fix from fsprojects#518 emits I_ldnull before I_ret whenever the return type is unit-like, but its retUnit check also matched ILType.Void. A ProvidedMethod declared with returnType = typeof<System.Void> then got a stray null pushed onto the stack of a void-returning method, which is invalid IL: the JIT throws InvalidProgramException on first invocation. Split the check: void keeps the empty-stack behavior with no ldnull, while only a genuine FSharp.Core Unit return pushes the boxed unit null. Adds a generative regression test that declares a System.Void-returning method and invokes it from the loaded assembly (fails with InvalidProgramException before this fix). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Member
Author
|
This is a low-priority issue compared to 520 and 522, which are solving real production issues. |
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.
Problem
The unit-return fix from #518 emits
I_ldnullbeforeI_retwhenever the method's return type is unit-like:The check also matches
ILType.Void, so aProvidedMethoddeclared withreturnType = typeof<System.Void>(whichtransTypemaps toILType.Void) gets a stray null pushed onto the stack of a void-returning method. That is invalid IL — the stack must be empty atretin a void method — and the JIT throwsInvalidProgramExceptionthe first time the method is invoked:(The equivalent lambda path in
CodeGenerator.emitLambdaalready gets this right: it emitsI_ldnullonly for the FSharp.CoreUnitreturn type, not for void.)Fix
Split the check:
retVoidkeeps the empty-stack behavior with noldnull; only a genuine FSharp.CoreUnitreturn pushes the boxed unit valuenull.Testing
System.Void-returning method and invoking it from the loaded assembly — fails withInvalidProgramExceptionbefore the fix, passes after.🤖 Generated with Claude Code