-
Notifications
You must be signed in to change notification settings - Fork 790
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add attribute to prevent fsc inlining but allow JIT inlining (#14235)
* Add attribute to prevent fsc inlining but allow JIT inlining * Work around IL checker shortcomings * Update surface area * Rename NoFscInliningAttribute
- Loading branch information
Showing
7 changed files
with
153 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
113 changes: 113 additions & 0 deletions
113
tests/FSharp.Compiler.ComponentTests/EmittedIL/NoCompilerInlining.fs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// 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.Compiler | ||
|
||
module ``NoCompilerInlining`` = | ||
[<Fact>] | ||
let ``Function marked with NoCompilerInlining is not inlined by the compiler``() = | ||
FSharp """ | ||
module NoCompilerInlining | ||
let functionInlined () = 3 | ||
[<NoCompilerInliningAttribute>] | ||
let functionNotInlined () = 3 | ||
let x () = functionInlined () + functionNotInlined () | ||
""" | ||
|> compile | ||
|> shouldSucceed | ||
|> verifyIL [""" | ||
.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 functionInlined() cil managed | ||
{ | ||
.maxstack 8 | ||
IL_0000: ldc.i4.3 | ||
IL_0001: ret | ||
}""" | ||
|
||
""" | ||
.method public static int32 functionNotInlined() cil managed | ||
{ | ||
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) | ||
.maxstack 8 | ||
IL_0000: ldc.i4.3 | ||
IL_0001: ret | ||
}""" | ||
|
||
""" | ||
.method public static int32 x() cil managed | ||
{ | ||
.maxstack 8 | ||
IL_0000: ldc.i4.3 | ||
IL_0001: call int32 NoCompilerInlining::functionNotInlined() | ||
IL_0006: add | ||
IL_0007: ret | ||
}"""] | ||
|
||
[<Fact>] | ||
let ``Value marked with NoCompilerInlining is not inlined by the compiler``() = | ||
FSharp """ | ||
module NoCompilerInlining | ||
let valueInlined = 3 | ||
[<NoCompilerInliningAttribute>] | ||
let valueNotInlined = 3 | ||
let x () = valueInlined + valueNotInlined | ||
""" | ||
|> compile | ||
|> shouldSucceed | ||
|> verifyIL [""" | ||
get_valueInlined() cil managed | ||
{ | ||
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) | ||
.custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) | ||
.maxstack 8 | ||
IL_0000: ldc.i4.3 | ||
IL_0001: ret | ||
}""" | ||
|
||
""" | ||
get_valueNotInlined() cil managed | ||
{ | ||
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) | ||
.custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) | ||
.maxstack 8 | ||
IL_0000: ldc.i4.3 | ||
IL_0001: ret | ||
}""" | ||
|
||
""" | ||
.method public static int32 x() cil managed | ||
{ | ||
.maxstack 8 | ||
IL_0000: ldc.i4.3 | ||
IL_0001: call int32 NoCompilerInlining::get_valueNotInlined() | ||
IL_0006: add | ||
IL_0007: ret | ||
}""" | ||
|
||
""" | ||
.property int32 valueInlined() | ||
{ | ||
.get int32 NoCompilerInlining::get_valueInlined() | ||
}""" | ||
|
||
""" | ||
.property int32 valueNotInlined() | ||
{ | ||
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) | ||
.get int32 NoCompilerInlining::get_valueNotInlined() | ||
} | ||
"""] |
This file contains 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
This file contains 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