-
Notifications
You must be signed in to change notification settings - Fork 847
Support SkipLocalsinit #11267
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
Support SkipLocalsinit #11267
Changes from all commits
63eaf15
f1bae10
14f15ef
3afe0f4
1d1774f
5d8d0ec
7f7ca30
1843f83
0c646f3
bd82a2f
abffd5a
9479c37
fb4253e
6c12df2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. | ||
|
|
||
| namespace FSharp.Compiler.ComponentTests.EmittedIL | ||
|
|
||
| open Xunit | ||
| open FSharp.Test.Utilities.Compiler | ||
|
|
||
| #if NETCOREAPP | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That should be good testing wise, I'll see what we can do with the x-framework IL validation.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be great if you could pass TFM to |
||
| module ``SkipLocalsInit`` = | ||
| [<Fact>] | ||
| let ``Init in function and closure not emitted when applied on function``() = | ||
| FSharp """ | ||
| module SkipLocalsInit | ||
| [<System.Runtime.CompilerServices.SkipLocalsInitAttribute>] | ||
| let x () = | ||
| [||] |> Array.filter (fun x -> let y = "".Length in y + y = x) |> ignore | ||
| """ | ||
| |> compile | ||
| |> shouldSucceed | ||
| |> verifyIL [""" | ||
| .method public static void x() cil managed | ||
| { | ||
| .custom instance void [runtime]System.Runtime.CompilerServices.SkipLocalsInitAttribute::.ctor() = ( 01 00 00 00 ) | ||
| .maxstack 4 | ||
| .locals (int32[] V_0) | ||
| """ | ||
|
|
||
| """ | ||
| .method public strict virtual instance bool | ||
| Invoke(int32 x) cil managed | ||
| { | ||
| .maxstack 6 | ||
| .locals (int32 V_0)"""] | ||
|
|
||
| [<Fact>] | ||
| let ``Init in static method not emitted when applied on class``() = | ||
| FSharp """ | ||
| module SkipLocalsInit | ||
| [<System.Runtime.CompilerServices.SkipLocalsInitAttribute>] | ||
| type X () = | ||
| static member Y () = | ||
| let x = "ssa".Length | ||
| x + x | ||
| """ | ||
| |> compile | ||
| |> shouldSucceed | ||
| |> verifyIL [""" | ||
| .custom instance void [runtime]System.Runtime.CompilerServices.SkipLocalsInitAttribute::.ctor() = ( 01 00 00 00 ) | ||
| .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) | ||
| """ | ||
|
|
||
| """ | ||
| .method public static int32 Y() cil managed | ||
| { | ||
| .maxstack 4 | ||
| .locals (int32 V_0)"""] | ||
|
|
||
| [<Fact>] | ||
| let ``Init in static method and function not emitted when applied on module``() = | ||
| FSharp """ | ||
| [<System.Runtime.CompilerServices.SkipLocalsInitAttribute>] | ||
| module SkipLocalsInit | ||
| let x () = | ||
| let x = "ssa".Length | ||
| x + x | ||
| type X () = | ||
| static member Y () = | ||
| let x = "ssa".Length | ||
| x + x | ||
| """ | ||
| |> compile | ||
| |> shouldSucceed | ||
| |> verifyIL [""" | ||
| .custom instance void [runtime]System.Runtime.CompilerServices.SkipLocalsInitAttribute::.ctor() = ( 01 00 00 00 ) | ||
| .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) | ||
| """ | ||
|
|
||
| """ | ||
| .method public static int32 x() cil managed | ||
| { | ||
| .maxstack 4 | ||
| .locals (int32 V_0) | ||
| """ | ||
|
|
||
| """ | ||
| .method public static int32 Y() cil managed | ||
| { | ||
| .maxstack 4 | ||
| .locals (int32 V_0)"""] | ||
|
|
||
| [<Fact>] | ||
| let ``Init in method and closure not emitted when applied on method``() = | ||
| FSharp """ | ||
| module SkipLocalsInit | ||
| type X () = | ||
| [<System.Runtime.CompilerServices.SkipLocalsInitAttribute>] | ||
| member _.Y () = | ||
| [||] |> Array.filter (fun x -> let y = "".Length in y + y = x) |> ignore | ||
| let x = "ssa".Length | ||
| x + x | ||
| """ | ||
| |> compile | ||
| |> shouldSucceed | ||
| |> verifyIL [""" | ||
| .method public hidebysig instance int32 | ||
| Y() cil managed | ||
| { | ||
| .custom instance void [runtime]System.Runtime.CompilerServices.SkipLocalsInitAttribute::.ctor() = ( 01 00 00 00 ) | ||
| .maxstack 4 | ||
| .locals (int32[] V_0, | ||
| int32 V_1) | ||
| """ | ||
|
|
||
| """ | ||
| .method public strict virtual instance bool | ||
| Invoke(int32 x) cil managed | ||
| { | ||
| .maxstack 6 | ||
| .locals (int32 V_0) | ||
| """] | ||
| #endif | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not quite sure if this shouldn't be
tryFindSysAttrib. Attributes above use both find and try find and I can't tell what the deciding factor is. It does not throw even on net472, so I guess it's fine?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine. You can check to see if you can deref it. If you can't, then it couldn't find it.