Skip to content

Commit ba6888f

Browse files
committed
Inline NoDynamicInvocation functions
1 parent a8491d1 commit ba6888f

4 files changed

Lines changed: 26 additions & 3 deletions

File tree

src/Compiler/Optimize/Optimizer.fs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2341,6 +2341,17 @@ let inline IsStateMachineExpr g overallExpr =
23412341
isReturnsResumableCodeTy g valRef.TauType
23422342
| _ -> false
23432343

2344+
let shouldForceInlineMembersInDebug (g: TcGlobals) (tcref: EntityRef) =
2345+
match g.fslibForceInlineModules.TryGetValue tcref.LogicalName with
2346+
| true, modRef -> tyconRefEq g tcref modRef
2347+
| _ -> false
2348+
2349+
let shouldForceInlineInDebug (g: TcGlobals) (vref: ValRef) : bool =
2350+
ValHasWellKnownAttribute g WellKnownValAttributes.NoDynamicInvocationAttribute_True vref.Deref ||
2351+
ValHasWellKnownAttribute g WellKnownValAttributes.NoDynamicInvocationAttribute_False vref.Deref ||
2352+
2353+
vref.HasDeclaringEntity && shouldForceInlineMembersInDebug g vref.DeclaringEntity
2354+
23442355
/// Optimize/analyze an expression
23452356
let rec OptimizeExpr cenv (env: IncrementalOptimizationEnv) expr =
23462357
cenv.stackGuard.Guard <| fun () ->
@@ -3432,7 +3443,7 @@ and TryInlineApplication cenv env finfo (valExpr: Expr) (tyargs: TType list, arg
34323443
let g = cenv.g
34333444

34343445
match cenv.settings.inlineNamedFunctions, stripExpr valExpr with
3435-
| false, Expr.Val(vref, _, _) when vref.ShouldInline ->
3446+
| false, Expr.Val(vref, _, _) when vref.ShouldInline && not (shouldForceInlineInDebug cenv.g vref) ->
34363447
let origFinfo = GetInfoForValWithCheck cenv env m vref
34373448
match stripValue origFinfo.ValExprInfo with
34383449
| CurriedLambdaValue(origLambdaId, _, _, origLambda, origLambdaTy) when not (Zset.contains origLambdaId env.dontInline) ->

src/Compiler/TypedTree/TcGlobals.fs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,15 @@ type TcGlobals(
646646

647647
yield nleref.LastItemMangledName, ERefNonLocal nleref ]
648648

649+
let v_FSharpCoreForceInlineModules =
650+
dict [ for nleref in [ fslib_MFIntrinsicOperators_nleref
651+
fslib_MFOperators_nleref
652+
fslib_MFOperatorIntrinsics_nleref
653+
fslib_MFOperatorsChecked_nleref
654+
fslib_MFNativePtrModule_nleref ] do
655+
656+
yield nleref.LastItemMangledName, ERefNonLocal nleref ]
657+
649658
let tryDecodeTupleTy tupInfo l =
650659
match l with
651660
| [t1;t2;t3;t4;t5;t6;t7;markerTy] ->
@@ -1133,6 +1142,8 @@ type TcGlobals(
11331142
// better the job we do of mapping from provided expressions back to FSharp.Core F# functions and values.
11341143
member _.knownFSharpCoreModules = v_knownFSharpCoreModules
11351144

1145+
member _.fslibForceInlineModules = v_FSharpCoreForceInlineModules
1146+
11361147
member _.compilingFSharpCore = compilingFSharpCore
11371148

11381149
member _.useReflectionFreeCodeGen = useReflectionFreeCodeGen

src/Compiler/TypedTree/TcGlobals.fsi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,8 @@ type internal TcGlobals =
698698

699699
member knownFSharpCoreModules: System.Collections.Generic.IDictionary<string, TypedTree.EntityRef>
700700

701+
member fslibForceInlineModules: System.Collections.Generic.IDictionary<string, TypedTree.EntityRef>
702+
701703
member knownIntrinsics:
702704
System.Collections.Concurrent.ConcurrentDictionary<string * string option * string * int, TypedTree.ValRef>
703705

tests/FSharp.Compiler.ComponentTests/EmittedIL/DebugInlineAsCall.fs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ let main _ =
158158
|> withNoOptimize
159159
|> asExe
160160
|> compileAndRun
161-
|> verifyILContains ["call bool [FSharp.Core]Microsoft.FSharp.Core.Operators::Not(bool)"]
162-
|> shouldSucceed
161+
|> verifyILNotPresent ["call bool [FSharp.Core]Microsoft.FSharp.Core.Operators::Not(bool)"]
163162

164163
[<Fact>]
165164
let ``Call 10 - Different assembly`` () =

0 commit comments

Comments
 (0)