Skip to content

Commit 80c1656

Browse files
authored
Merge pull request #17201 from vzarytovskii/fix-inlining-regression
Fix inlining regression
2 parents bdd55fc + 77c9637 commit 80c1656

File tree

4 files changed

+88
-16
lines changed

4 files changed

+88
-16
lines changed

eng/Versions.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<!-- F# Version components -->
1515
<FSMajorVersion>8</FSMajorVersion>
1616
<FSMinorVersion>0</FSMinorVersion>
17-
<FSBuildVersion>300</FSBuildVersion>
17+
<FSBuildVersion>301</FSBuildVersion>
1818
<FSRevisionVersion>0</FSRevisionVersion>
1919
<!-- -->
2020
<!-- F# Language version -->

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"xcopy-msbuild": "17.8.1-2"
1515
},
1616
"native-tools": {
17-
"perl": "5.38.0.1"
17+
"perl": "5.38.2.2"
1818
},
1919
"msbuild-sdks": {
2020
"Microsoft.DotNet.Arcade.Sdk": "8.0.0-beta.24204.3",

src/Compiler/Optimize/Optimizer.fs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2356,15 +2356,7 @@ let rec OptimizeExpr cenv (env: IncrementalOptimizationEnv) expr =
23562356
OptimizeConst cenv env expr (c, m, ty)
23572357

23582358
| Expr.Val (v, _vFlags, m) ->
2359-
if not (v.Accessibility.IsPrivate) then
2360-
OptimizeVal cenv env expr (v, m)
2361-
else
2362-
expr,
2363-
{ TotalSize = 10
2364-
FunctionSize = 1
2365-
HasEffect = false
2366-
MightMakeCriticalTailcall=false
2367-
Info=UnknownValue }
2359+
OptimizeVal cenv env expr (v, m)
23682360

23692361

23702362
| Expr.Quote (ast, splices, isFromQueryExpression, m, ty) ->
@@ -3082,9 +3074,6 @@ and TryOptimizeVal cenv env (vOpt: ValRef option, shouldInline, inlineIfLambda,
30823074
let fvs = freeInExpr CollectLocals expr
30833075
if fvs.UsesMethodLocalConstructs then
30843076
// Discarding lambda for binding because uses protected members --- TBD: Should we warn or error here
3085-
None
3086-
elif fvs.FreeLocals |> Seq.exists(fun v -> v.Accessibility.IsPrivate ) then
3087-
// Discarding lambda for binding because uses private members --- TBD: Should we warn or error here
30883077
None
30893078
else
30903079
let exprCopy = CopyExprForInlining cenv inlineIfLambda expr m
@@ -4123,10 +4112,10 @@ and OptimizeBinding cenv isRec env (TBind(vref, expr, spBind)) =
41234112
let fvs = freeInExpr CollectLocals body
41244113
if fvs.UsesMethodLocalConstructs then
41254114
// Discarding lambda for binding because uses protected members
4126-
UnknownValue
4115+
UnknownValue
41274116
elif fvs.FreeLocals.ToArray() |> Seq.fold(fun acc v -> if not acc then v.Accessibility.IsPrivate else acc) false then
41284117
// Discarding lambda for binding because uses private members
4129-
UnknownValue
4118+
UnknownValue
41304119
else
41314120
ivalue
41324121

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

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ module Inlining =
1616
|> ignoreWarnings
1717
|> verifyILBaseline
1818

19+
let withRealInternalSignature realSig compilation =
20+
compilation
21+
|> withOptions [if realSig then "--realsig+" else "--realsig-" ]
22+
1923
// SOURCE=Match01.fs SCFLAGS="-a --optimize+" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd Match01.dll" # Match01.fs
2024
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"Match01_RealInternalSignatureOn.fs"|])>]
2125
let ``Match01_RealInternalSignatureOn_fs`` compilation =
@@ -139,3 +143,82 @@ let found = data |> List.contains nan
139143
}"""]
140144
#endif
141145

146+
[<InlineData(true)>] // RealSig
147+
[<InlineData(false)>] // Regular
148+
[<Theory>]
149+
let ``Inlining field with private module`` (realSig) =
150+
Fsx """
151+
module private PrivateModule =
152+
let moduleValue = 1
153+
154+
let inline getModuleValue () =
155+
moduleValue
156+
157+
[<EntryPoint>]
158+
let main argv =
159+
// [FS1118] Failed to inline the value 'getModuleValue' marked 'inline', perhaps because a recursive value was marked 'inline'
160+
// (fixed by making PrivateModule internal instead of private)
161+
PrivateModule.getModuleValue () |> ignore
162+
0
163+
"""
164+
|> withOptimize
165+
|> withRealInternalSignature realSig
166+
|> asExe
167+
|> compileAndRun
168+
|> shouldSucceed
169+
170+
[<InlineData(true)>] // RealSig
171+
[<InlineData(false)>] // Regular
172+
[<Theory>]
173+
let ``Inlining field with private class`` (realSig) =
174+
Fsx """
175+
type private FirstType () =
176+
member this.FirstMethod () = ()
177+
178+
type private SecondType () =
179+
member this.SecondMethod () =
180+
let inline callFirstMethod (first: FirstType) =
181+
first.FirstMethod ()
182+
183+
callFirstMethod (FirstType())
184+
185+
printfn $"{(SecondType ()).SecondMethod()}"
186+
"""
187+
|> withOptimize
188+
|> withRealInternalSignature realSig
189+
|> asExe
190+
|> compileAndRun
191+
|> shouldSucceed
192+
193+
[<InlineData(true)>] // RealSig
194+
[<InlineData(false)>] // Regular
195+
[<Theory>]
196+
let ``Inlining deep local functions field with private class`` (realSig) =
197+
Fsx """
198+
type private FirstType () =
199+
member this.FirstMethod () = ()
200+
201+
type private SecondType () =
202+
member this.SecondMethod () =
203+
let inline callFirstMethod (first: FirstType) =
204+
first.FirstMethod ()
205+
206+
let inline callFirstMethodDeeper (first: FirstType) =
207+
callFirstMethod (first)
208+
209+
let inline callFirstMethodMoreDeeper (first: FirstType) =
210+
callFirstMethodDeeper (first)
211+
212+
let inline callFirstMethodMostDeeply (first: FirstType) =
213+
callFirstMethodMoreDeeper (first)
214+
215+
callFirstMethodMostDeeply (FirstType())
216+
217+
printfn $"{(SecondType ()).SecondMethod()}"
218+
"""
219+
|> withOptimize
220+
|> withRealInternalSignature realSig
221+
|> asExe
222+
|> compileAndRun
223+
|> shouldSucceed
224+

0 commit comments

Comments
 (0)