Skip to content

Commit 06b4c09

Browse files
committed
Don't check accessibility for non-inlined functions
1 parent 3b97534 commit 06b4c09

2 files changed

Lines changed: 48 additions & 15 deletions

File tree

src/Compiler/Optimize/Optimizer.fs

Lines changed: 16 additions & 15 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,7 @@ 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) -> check cenv vref (abstractValInfo e) )) }
14101411

14111412
and abstractLazyModulInfo (ss: LazyModuleInfo) =
14121413
ss.Force() |> abstractModulInfo |> notlazy
@@ -1425,7 +1426,7 @@ let AbstractOptimizationInfoToEssentials =
14251426
abstractLazyModulInfo
14261427

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

14901491
abstractExprInfo ivalue
14911492

@@ -1525,9 +1526,9 @@ let RemapOptimizationInfo g tmenv =
15251526
remapLazyModulInfo
15261527

15271528
/// Hide information when a value is no longer visible
1528-
let AbstractAndRemapModulInfo g (repackage, hidden) info =
1529+
let AbstractAndRemapModulInfo g (cenv: cenv) (repackage, hidden) info =
15291530
let mrpi = mkRepackageRemapping repackage
1530-
let info = info |> AbstractLazyModulInfoByHiding false hidden
1531+
let info = info |> AbstractLazyModulInfoByHiding false cenv hidden
15311532
let info = info |> RemapOptimizationInfo g mrpi
15321533
info
15331534

@@ -2850,7 +2851,7 @@ and OptimizeLetRec cenv env (binds, bodyExpr, m) =
28502851
let fvs = List.fold (fun acc x -> unionFreeVars acc (fst x |> freeInBindingRhs CollectLocals)) fvs0 bindsR
28512852
SplitValuesByIsUsedOrHasEffect cenv (fun () -> fvs.FreeLocals) bindsR
28522853
// Trim out any optimization info that involves escaping values
2853-
let evalueR = AbstractExprInfoByVars (vs, []) einfo.Info
2854+
let evalueR = AbstractExprInfoByVars cenv (vs, []) einfo.Info
28542855
// REVIEW: size of constructing new closures - should probably add #freevars + #recfixups here
28552856
let bodyExprR = Expr.LetRec (bindsRR, bodyExprR, m, Construct.NewFreeVarsCache())
28562857
let info = CombineValueInfos (einfo :: bindinfos) evalueR
@@ -2926,7 +2927,7 @@ and OptimizeLinearExpr cenv env expr contf =
29262927
Info = UnknownValue }
29272928
else
29282929
// 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
2930+
let evalueR = AbstractExprInfoByVars cenv ([bindR.Var], []) bodyInfo.Info
29302931

29312932
// Preserve the debug points for eliminated bindings that have debug points.
29322933
let bodyR =
@@ -4101,7 +4102,7 @@ and OptimizeDecisionTreeTarget cenv env _m (TTarget(vs, expr, flags)) =
41014102
let env = BindInternalValsToUnknown cenv vs env
41024103
let exprR, einfo = OptimizeExpr cenv env expr
41034104
let exprR, einfo = ConsiderSplitToMethod cenv.settings.abstractBigTargets cenv.settings.bigTargetSize cenv env (exprR, einfo)
4104-
let evalueR = AbstractExprInfoByVars (vs, []) einfo.Info
4105+
let evalueR = AbstractExprInfoByVars cenv (vs, []) einfo.Info
41054106
TTarget(vs, exprR, flags),
41064107
{ TotalSize=einfo.TotalSize
41074108
FunctionSize=einfo.FunctionSize
@@ -4385,7 +4386,7 @@ and OptimizeModuleExprWithSig cenv env mty def =
43854386

43864387
elimModuleDefn def
43874388

4388-
let info = AbstractAndRemapModulInfo g rpi info
4389+
let info = AbstractAndRemapModulInfo g cenv rpi info
43894390

43904391
def, info
43914392

@@ -4458,14 +4459,14 @@ and OptimizeImplFileInternal cenv env isIncrementalFragment hidden implFile =
44584459
// This optimizes and builds minfo ignoring the signature
44594460
let (defR, minfo), (_env, _bindInfosColl) = OptimizeModuleContents cenv (env, []) contents
44604461
let hidden = ComputeImplementationHidingInfoAtAssemblyBoundary defR hidden
4461-
let minfo = AbstractLazyModulInfoByHiding false hidden minfo
4462+
let minfo = AbstractLazyModulInfoByHiding false cenv hidden minfo
44624463
let env = BindValsInModuleOrNamespace cenv minfo env
44634464
env, defR, minfo, hidden
44644465
else
44654466
// This optimizes and builds minfo w.r.t. the signature
44664467
let mexprR, minfo = OptimizeModuleExprWithSig cenv env signature contents
44674468
let hidden = ComputeSignatureHidingInfoAtAssemblyBoundary signature hidden
4468-
let minfoExternal = AbstractLazyModulInfoByHiding true hidden minfo
4469+
let minfoExternal = AbstractLazyModulInfoByHiding true cenv hidden minfo
44694470
let env = BindValsInModuleOrNamespace cenv minfo env
44704471
env, mexprR, minfoExternal, hidden
44714472

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,3 +661,35 @@ let main _ =
661661
|> compileAndRun
662662
|> verifyILContains ["call int32 Test::'<op_PlusPlus>__debug@5'(int32,"]
663663
|> shouldSucceed
664+
665+
[<Fact>]
666+
let ``Accessibility 01`` () =
667+
FSharp """
668+
module Module
669+
670+
let inline internal fInternal () = ()
671+
let inline f () = fInternal ()
672+
"""
673+
|> withDebug
674+
|> withNoOptimize
675+
|> asLibrary
676+
|> compile
677+
|> shouldSucceed
678+
679+
[<Fact>]
680+
let ``Accessibility 02`` () =
681+
FSharp """
682+
module Module
683+
684+
type T() =
685+
member inline internal this.InternalMethod() =
686+
()
687+
688+
member inline this.Method() =
689+
this.InternalMethod()
690+
"""
691+
|> withDebug
692+
|> withNoOptimize
693+
|> asLibrary
694+
|> compile
695+
|> shouldSucceed

0 commit comments

Comments
 (0)