Skip to content

Commit

Permalink
additional testing and fix class inlines
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinRansom committed May 17, 2024
1 parent 766ca76 commit e97ce1c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Compiler/Optimize/Optimizer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3078,10 +3078,10 @@ and TryOptimizeVal cenv env (vOpt: ValRef option, shouldInline, inlineIfLambda,
let fvs = freeInExpr CollectLocals expr
if fvs.UsesMethodLocalConstructs then
// Discarding lambda for binding because uses protected members --- TBD: Should we warn or error here
None
None (*
elif fvs.FreeLocals |> Seq.exists(fun v -> v.Accessibility.IsPrivate ) then
// Discarding lambda for binding because uses private members --- TBD: Should we warn or error here
None
None *)
else
let exprCopy = CopyExprForInlining cenv inlineIfLambda expr m
Some exprCopy
Expand Down Expand Up @@ -4136,10 +4136,10 @@ and OptimizeBinding cenv isRec env (TBind(vref, expr, spBind)) =
let fvs = freeInExpr CollectLocals body
if fvs.UsesMethodLocalConstructs then
// Discarding lambda for binding because uses protected members
UnknownValue
UnknownValue
elif fvs.FreeLocals.ToArray() |> Seq.fold(fun acc v -> if not acc then v.Accessibility.IsPrivate else acc) false then
// Discarding lambda for binding because uses private members
UnknownValue
UnknownValue
else
ivalue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,59 @@ let main argv =
|> asExe
|> compileAndRun
|> shouldSucceed

[<InlineData(true)>] // RealSig
[<InlineData(false)>] // Regular
[<Theory>]
let ``Inlining field with private class`` (realSig) =
Fsx """
type private FirstType () =
member this.FirstMethod () = ()
type private SecondType () =
member this.SecondMethod () =
let inline callFirstMethod (first: FirstType) =
first.FirstMethod ()
callFirstMethod (FirstType())
printfn $"{(SecondType ()).SecondMethod()}"
"""
|> withOptimize
|> withRealInternalSignature realSig
|> asExe
|> compileAndRun
|> shouldSucceed

[<InlineData(true)>] // RealSig
[<InlineData(false)>] // Regular
[<Theory>]
let ``Inlining deep local functions field with private class`` (realSig) =
Fsx """
type private FirstType () =
member this.FirstMethod () = ()
type private SecondType () =
member this.SecondMethod () =
let inline callFirstMethod (first: FirstType) =
first.FirstMethod ()
let inline callFirstMethodDeeper (first: FirstType) =
callFirstMethod (first)
let inline callFirstMethodMoreDeeper (first: FirstType) =
callFirstMethodDeeper (first)
let inline callFirstMethodMostDeeply (first: FirstType) =
callFirstMethodMoreDeeper (first)
callFirstMethodMostDeeply (FirstType())
printfn $"{(SecondType ()).SecondMethod()}"
"""
|> withOptimize
|> withRealInternalSignature realSig
|> asExe
|> compileAndRun
|> shouldSucceed

0 comments on commit e97ce1c

Please sign in to comment.