Skip to content

Commit e5e7134

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

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 =
@@ -4098,7 +4099,7 @@ and OptimizeDecisionTreeTarget cenv env _m (TTarget(vs, expr, flags)) =
40984099
let env = BindInternalValsToUnknown cenv vs env
40994100
let exprR, einfo = OptimizeExpr cenv env expr
41004101
let exprR, einfo = ConsiderSplitToMethod cenv.settings.abstractBigTargets cenv.settings.bigTargetSize cenv env (exprR, einfo)
4101-
let evalueR = AbstractExprInfoByVars (vs, []) einfo.Info
4102+
let evalueR = AbstractExprInfoByVars cenv (vs, []) einfo.Info
41024103
TTarget(vs, exprR, flags),
41034104
{ TotalSize=einfo.TotalSize
41044105
FunctionSize=einfo.FunctionSize
@@ -4382,7 +4383,7 @@ and OptimizeModuleExprWithSig cenv env mty def =
43824383

43834384
elimModuleDefn def
43844385

4385-
let info = AbstractAndRemapModulInfo g rpi info
4386+
let info = AbstractAndRemapModulInfo g cenv rpi info
43864387

43874388
def, info
43884389

@@ -4455,14 +4456,14 @@ and OptimizeImplFileInternal cenv env isIncrementalFragment hidden implFile =
44554456
// This optimizes and builds minfo ignoring the signature
44564457
let (defR, minfo), (_env, _bindInfosColl) = OptimizeModuleContents cenv (env, []) contents
44574458
let hidden = ComputeImplementationHidingInfoAtAssemblyBoundary defR hidden
4458-
let minfo = AbstractLazyModulInfoByHiding false hidden minfo
4459+
let minfo = AbstractLazyModulInfoByHiding false cenv hidden minfo
44594460
let env = BindValsInModuleOrNamespace cenv minfo env
44604461
env, defR, minfo, hidden
44614462
else
44624463
// This optimizes and builds minfo w.r.t. the signature
44634464
let mexprR, minfo = OptimizeModuleExprWithSig cenv env signature contents
44644465
let hidden = ComputeSignatureHidingInfoAtAssemblyBoundary signature hidden
4465-
let minfoExternal = AbstractLazyModulInfoByHiding true hidden minfo
4466+
let minfoExternal = AbstractLazyModulInfoByHiding true cenv hidden minfo
44664467
let env = BindValsInModuleOrNamespace cenv minfo env
44674468
env, mexprR, minfoExternal, hidden
44684469

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)