Skip to content

Commit 5cc1c28

Browse files
committed
Don't check accessibility for non-inlined functions
1 parent e74b105 commit 5cc1c28

2 files changed

Lines changed: 53 additions & 17 deletions

File tree

src/Compiler/Optimize/Optimizer.fs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,9 @@ let CheckInlineValueIsComplete (v: Val) res =
506506
errorR(Error(FSComp.SR.optValueMarkedInlineButIncomplete(v.DisplayName), v.Range))
507507
//System.Diagnostics.Debug.Assert(false, sprintf "Break for incomplete inline value %s" v.DisplayName)
508508

509-
let check (vref: ValRef) (res: ValInfo) =
510-
CheckInlineValueIsComplete vref.Deref res.ValExprInfo
509+
let check (cenv: cenv) (vref: ValRef) (res: ValInfo) =
510+
if cenv.settings.inlineNamedFunctions then
511+
CheckInlineValueIsComplete vref.Deref res.ValExprInfo
511512
(vref, res)
512513

513514
//-------------------------------------------------------------------------
@@ -697,7 +698,7 @@ let GetInfoForVal cenv env m (vref: ValRef) =
697698

698699
let GetInfoForValWithCheck cenv env m (vref: ValRef) =
699700
let res = GetInfoForVal cenv env m vref
700-
check vref res |> ignore
701+
check cenv vref res |> ignore
701702
res
702703

703704
let IsPartialExpr cenv env m x =
@@ -1331,7 +1332,7 @@ let CombineValueInfos einfos res =
13311332
let CombineValueInfosUnknown einfos = CombineValueInfos einfos UnknownValue
13321333

13331334
/// Hide information because of a signature
1334-
let AbstractLazyModulInfoByHiding isAssemblyBoundary mhi =
1335+
let AbstractLazyModulInfoByHiding isAssemblyBoundary (cenv: cenv) mhi =
13351336

13361337
// The freevars and FreeTyvars can indicate if the non-public (hidden) items have been used.
13371338
// Under those checks, the further hidden* checks may be subsumed (meaning, not required anymore).
@@ -1406,7 +1407,8 @@ let AbstractLazyModulInfoByHiding isAssemblyBoundary mhi =
14061407
ValInfos =
14071408
ValInfos(ss.ValInfos.Entries
14081409
|> Seq.filter (fun (vref, _) -> not (hiddenVal vref.Deref))
1409-
|> Seq.map (fun (vref, e) -> check (* "its implementation uses a binding hidden by a signature" m *) vref (abstractValInfo e) )) }
1410+
|> Seq.map (fun (vref, e) ->
1411+
check cenv (* "its implementation uses a binding hidden by a signature" m *) vref (abstractValInfo e) )) }
14101412

14111413
and abstractLazyModulInfo (ss: LazyModuleInfo) =
14121414
ss.Force() |> abstractModulInfo |> notlazy
@@ -1425,7 +1427,7 @@ let AbstractOptimizationInfoToEssentials =
14251427
abstractLazyModulInfo
14261428

14271429
/// Hide information because of a "let ... in ..." or "let rec ... in ... "
1428-
let AbstractExprInfoByVars (boundVars: Val list, boundTyVars) ivalue =
1430+
let AbstractExprInfoByVars (cenv: cenv) (boundVars: Val list, boundTyVars) ivalue =
14291431
// Module and member bindings can be skipped when checking abstraction, since abstraction of these values has already been done when
14301432
// we hit the end of the module and called AbstractLazyModulInfoByHiding. If we don't skip these then we end up quadratically retraversing
14311433
// the inferred optimization data, i.e. at each binding all the way up a sequences of 'lets' in a module.
@@ -1485,7 +1487,7 @@ let AbstractExprInfoByVars (boundVars: Val list, boundTyVars) ivalue =
14851487
let rec abstractModulInfo ss =
14861488
{ ModuleOrNamespaceInfos = ss.ModuleOrNamespaceInfos |> NameMap.map (InterruptibleLazy.force >> abstractModulInfo >> notlazy)
14871489
ValInfos = ss.ValInfos.Map (fun (vref, e) ->
1488-
check vref (abstractValInfo e) ) }
1490+
check cenv vref (abstractValInfo e)) }
14891491

14901492
abstractExprInfo ivalue
14911493

@@ -1525,9 +1527,9 @@ let RemapOptimizationInfo g tmenv =
15251527
remapLazyModulInfo
15261528

15271529
/// Hide information when a value is no longer visible
1528-
let AbstractAndRemapModulInfo g (repackage, hidden) info =
1530+
let AbstractAndRemapModulInfo g (cenv: cenv) (repackage, hidden) info =
15291531
let mrpi = mkRepackageRemapping repackage
1530-
let info = info |> AbstractLazyModulInfoByHiding false hidden
1532+
let info = info |> AbstractLazyModulInfoByHiding false cenv hidden
15311533
let info = info |> RemapOptimizationInfo g mrpi
15321534
info
15331535

@@ -2850,7 +2852,7 @@ and OptimizeLetRec cenv env (binds, bodyExpr, m) =
28502852
let fvs = List.fold (fun acc x -> unionFreeVars acc (fst x |> freeInBindingRhs CollectLocals)) fvs0 bindsR
28512853
SplitValuesByIsUsedOrHasEffect cenv (fun () -> fvs.FreeLocals) bindsR
28522854
// Trim out any optimization info that involves escaping values
2853-
let evalueR = AbstractExprInfoByVars (vs, []) einfo.Info
2855+
let evalueR = AbstractExprInfoByVars cenv (vs, []) einfo.Info
28542856
// REVIEW: size of constructing new closures - should probably add #freevars + #recfixups here
28552857
let bodyExprR = Expr.LetRec (bindsRR, bodyExprR, m, Construct.NewFreeVarsCache())
28562858
let info = CombineValueInfos (einfo :: bindinfos) evalueR
@@ -2926,7 +2928,7 @@ and OptimizeLinearExpr cenv env expr contf =
29262928
Info = UnknownValue }
29272929
else
29282930
// On the way back up: Trim out any optimization info that involves escaping values on the way back up
2929-
let evalueR = AbstractExprInfoByVars ([bindR.Var], []) bodyInfo.Info
2931+
let evalueR = AbstractExprInfoByVars cenv ([bindR.Var], []) bodyInfo.Info
29302932

29312933
// Preserve the debug points for eliminated bindings that have debug points.
29322934
let bodyR =
@@ -3461,7 +3463,8 @@ and TryInlineApplication cenv env finfo (valExpr: Expr) (tyargs: TType list, arg
34613463
hasNoTraits || (not allTyargsAreConcrete && vref.ValReprInfo.IsSome)
34623464

34633465
if canCallDirectly then
3464-
Some(mkApps g ((exprForValRef m vref, vref.Type), [tyargs], argsR, m), info)
3466+
let resultExpr = mkApps g ((exprForValRef m vref, vref.Type), [tyargs], argsR, m)
3467+
Some(resultExpr, info)
34653468
else
34663469
let f2R = CopyExprForInlining cenv true origLambda m
34673470
let specLambda = MakeApplicationAndBetaReduce g (f2R, origLambdaTy, [tyargs], [], m)
@@ -3495,7 +3498,8 @@ and TryInlineApplication cenv env finfo (valExpr: Expr) (tyargs: TType list, arg
34953498
ParentNone)
34963499

34973500
let callExpr = mkApps g ((exprForVal m debugVal, specLambdaTy), [], argsR, m)
3498-
Some(mkCompGenLet m debugVal specLambdaR callExpr, info)
3501+
let resultExpr = mkCompGenLet m debugVal specLambdaR callExpr
3502+
Some(resultExpr, info)
34993503

35003504
| _ -> None
35013505
| _ ->
@@ -4098,7 +4102,7 @@ and OptimizeDecisionTreeTarget cenv env _m (TTarget(vs, expr, flags)) =
40984102
let env = BindInternalValsToUnknown cenv vs env
40994103
let exprR, einfo = OptimizeExpr cenv env expr
41004104
let exprR, einfo = ConsiderSplitToMethod cenv.settings.abstractBigTargets cenv.settings.bigTargetSize cenv env (exprR, einfo)
4101-
let evalueR = AbstractExprInfoByVars (vs, []) einfo.Info
4105+
let evalueR = AbstractExprInfoByVars cenv (vs, []) einfo.Info
41024106
TTarget(vs, exprR, flags),
41034107
{ TotalSize=einfo.TotalSize
41044108
FunctionSize=einfo.FunctionSize
@@ -4382,7 +4386,7 @@ and OptimizeModuleExprWithSig cenv env mty def =
43824386

43834387
elimModuleDefn def
43844388

4385-
let info = AbstractAndRemapModulInfo g rpi info
4389+
let info = AbstractAndRemapModulInfo g cenv rpi info
43864390

43874391
def, info
43884392

@@ -4455,14 +4459,14 @@ and OptimizeImplFileInternal cenv env isIncrementalFragment hidden implFile =
44554459
// This optimizes and builds minfo ignoring the signature
44564460
let (defR, minfo), (_env, _bindInfosColl) = OptimizeModuleContents cenv (env, []) contents
44574461
let hidden = ComputeImplementationHidingInfoAtAssemblyBoundary defR hidden
4458-
let minfo = AbstractLazyModulInfoByHiding false hidden minfo
4462+
let minfo = AbstractLazyModulInfoByHiding false cenv hidden minfo
44594463
let env = BindValsInModuleOrNamespace cenv minfo env
44604464
env, defR, minfo, hidden
44614465
else
44624466
// This optimizes and builds minfo w.r.t. the signature
44634467
let mexprR, minfo = OptimizeModuleExprWithSig cenv env signature contents
44644468
let hidden = ComputeSignatureHidingInfoAtAssemblyBoundary signature hidden
4465-
let minfoExternal = AbstractLazyModulInfoByHiding true hidden minfo
4469+
let minfoExternal = AbstractLazyModulInfoByHiding true cenv hidden minfo
44664470
let env = BindValsInModuleOrNamespace cenv minfo env
44674471
env, mexprR, minfoExternal, hidden
44684472

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,3 +606,35 @@ let main _ =
606606
|> compileAndRun
607607
|> verifyILContains ["call int32 Test::'<op_PlusPlus>__debug@5'(int32,"]
608608
|> shouldSucceed
609+
610+
[<Fact>]
611+
let ``Accessibility 01`` () =
612+
FSharp """
613+
module Module
614+
615+
let inline internal fInternal () = ()
616+
let inline f () = fInternal ()
617+
"""
618+
|> withDebug
619+
|> withNoOptimize
620+
|> asLibrary
621+
|> compile
622+
|> shouldSucceed
623+
624+
[<Fact>]
625+
let ``Accessibility 02`` () =
626+
FSharp """
627+
module Module
628+
629+
type T() =
630+
member inline internal this.InternalMethod() =
631+
()
632+
633+
member inline this.Method() =
634+
this.InternalMethod()
635+
"""
636+
|> withDebug
637+
|> withNoOptimize
638+
|> asLibrary
639+
|> compile
640+
|> shouldSucceed

0 commit comments

Comments
 (0)