Skip to content

Commit 2f762d3

Browse files
committed
Fix16105
1 parent 096ac34 commit 2f762d3

File tree

54 files changed

+466
-114
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+466
-114
lines changed

docs/release-notes/.FSharp.Compiler.Service/8.0.300.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* `[<CliEvent>]` member should not produce property symbol. ([Issue #16640](https://github.com/dotnet/fsharp/issues/16640), [PR #16658](https://github.com/dotnet/fsharp/pull/16658))
1212
* Fix discriminated union initialization. ([#PR 16661](https://github.com/dotnet/fsharp/pull/16661))
1313
* Allow calling method with both Optional and ParamArray. ([#PR 16688](https://github.com/dotnet/fsharp/pull/16688), [suggestions #1120](https://github.com/fsharp/fslang-suggestions/issues/1120))
14+
* Fix16105 - Release inline optimization leads to MethodAccessException if used with assembly:InternalsVisibleTo attribute. ([Issue #16105](https://github.com/dotnet/fsharp/issues/16105), ([#PR 16737](https://github.com/dotnet/fsharp/pull/16737))
1415

1516
### Added
1617

docs/release-notes/.VisualStudio/17.10.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* Show signature help mid-pipeline in more scenarios. ([PR #16462](https://github.com/dotnet/fsharp/pull/16462))
44
* Various unneeded parentheses code fix improvements. ([PR #16578](https://github.com/dotnet/fsharp/pull/16578), [PR #16666](https://github.com/dotnet/fsharp/pull/16666))
5+
* Fix16105 - Release inline optimization leads to MethodAccessException if used with assembly:InternalsVisibleTo attribute. ([Issue #16105](https://github.com/dotnet/fsharp/issues/16105), ([#PR 16737](https://github.com/dotnet/fsharp/pull/16737))
56

67
### Changed
78

src/Compiler/Optimize/Optimizer.fs

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ let rec IsPartialExprVal x =
496496
| TupleValue args | RecdValue (_, args) | UnionCaseValue (_, args) -> Array.exists IsPartialExprVal args
497497
| ConstValue _ | CurriedLambdaValue _ | ConstExprValue _ -> false
498498
| ValValue (_, a)
499-
| SizeValue(_, a) -> IsPartialExprVal a
499+
| SizeValue (_, a) -> IsPartialExprVal a
500500

501501
let CheckInlineValueIsComplete (v: Val) res =
502502
if v.MustInline && IsPartialExprVal res then
@@ -690,10 +690,25 @@ let GetInfoForVal cenv env m (vref: ValRef) =
690690
GetInfoForLocalValue cenv env vref.binding m
691691
else
692692
GetInfoForNonLocalVal cenv env vref
693+
res
693694

695+
let GetInfoForValWithCheck cenv env m (vref: ValRef) =
696+
let res = GetInfoForVal cenv env m vref
694697
check vref res |> ignore
695698
res
696699

700+
let IsPartialExpr cenv env m x =
701+
let rec isPartialExpression x =
702+
match x with
703+
| Expr.App (func, _, _, args, _) -> func :: args |> Seq.exists isPartialExpression
704+
| Expr.Lambda (_, _, _, _, expr, _, _) -> expr |> isPartialExpression
705+
| Expr.Let (TBind (_,expr,_), body, _, _) -> expr :: [body] |> List.exists isPartialExpression
706+
| Expr.LetRec (bindings, body, _, _) -> body :: (bindings |> List.map (fun (TBind (_,expr,_)) -> expr)) |> List.exists isPartialExpression
707+
| Expr.Sequential (expr1, expr2, _, _) -> [expr1; expr2] |> Seq.exists isPartialExpression
708+
| Expr.Val (vr, _, _) when not vr.IsLocalRef -> ((GetInfoForVal cenv env m vr).ValExprInfo) |> IsPartialExprVal
709+
| _ -> false
710+
isPartialExpression x
711+
697712
//-------------------------------------------------------------------------
698713
// Try to get information about values of particular types
699714
//-------------------------------------------------------------------------
@@ -3062,11 +3077,14 @@ and TryOptimizeVal cenv env (vOpt: ValRef option, mustInline, inlineIfLambda, va
30623077
failwith "tuple, union and record values cannot be marked 'inline'"
30633078

30643079
| UnknownValue when mustInline ->
3065-
warning(Error(FSComp.SR.optValueMarkedInlineHasUnexpectedValue(), m)); None
3080+
warning(Error(FSComp.SR.optValueMarkedInlineHasUnexpectedValue(), m))
3081+
None
30663082

30673083
| _ when mustInline ->
3068-
warning(Error(FSComp.SR.optValueMarkedInlineCouldNotBeInlined(), m)); None
3069-
| _ -> None
3084+
warning(Error(FSComp.SR.optValueMarkedInlineCouldNotBeInlined(), m))
3085+
None
3086+
3087+
| _ -> None
30703088

30713089
and TryOptimizeValInfo cenv env m vinfo =
30723090
if vinfo.HasEffect then None else TryOptimizeVal cenv env (None, false, false, vinfo.Info, m)
@@ -3089,7 +3107,7 @@ and OptimizeVal cenv env expr (v: ValRef, m) =
30893107

30903108
let g = cenv.g
30913109

3092-
let valInfoForVal = GetInfoForVal cenv env m v
3110+
let valInfoForVal = GetInfoForValWithCheck cenv env m v
30933111

30943112
match TryOptimizeVal cenv env (Some v, v.MustInline, v.InlineIfLambda, valInfoForVal.ValExprInfo, m) with
30953113
| Some e ->
@@ -3402,15 +3420,15 @@ and TryInlineApplication cenv env finfo (tyargs: TType list, args: Expr list, m)
34023420
| _ -> false
34033421
| _ -> false
34043422
| _ -> false
3405-
| _ -> false
3423+
| _ -> false
34063424

34073425
if isValFromLazyExtensions then None else
34083426

34093427
let isSecureMethod =
34103428
match finfo.Info with
34113429
| ValValue(vref, _) ->
34123430
vref.Attribs |> List.exists (fun a -> (IsSecurityAttribute g cenv.amap cenv.casApplied a m) || (IsSecurityCriticalAttribute g a))
3413-
| _ -> false
3431+
| _ -> false
34143432

34153433
if isSecureMethod then None else
34163434

@@ -3421,6 +3439,13 @@ and TryInlineApplication cenv env finfo (tyargs: TType list, args: Expr list, m)
34213439

34223440
if isGetHashCode then None else
34233441

3442+
let isApplicationPartialExpr =
3443+
match finfo.Info with
3444+
| ValValue (_, CurriedLambdaValue (_, _, _, expr, _) ) -> IsPartialExpr cenv env m expr
3445+
| _ -> false
3446+
3447+
if isApplicationPartialExpr then None else
3448+
34243449
// Inlining lambda
34253450
let f2R = CopyExprForInlining cenv false f2 m
34263451

@@ -3597,8 +3622,8 @@ and OptimizeApplication cenv env (f0, f0ty, tyargs, args, m) =
35973622
// This includes recursive calls to the function being defined (in which case we get a non-critical, closed-world tailcall).
35983623
// Note we also have to check the argument count to ensure this is a direct call (or a partial application).
35993624
let doesNotMakeCriticalTailcall =
3600-
vref.MakesNoCriticalTailcalls ||
3601-
(let valInfoForVal = GetInfoForVal cenv env m vref in valInfoForVal.ValMakesNoCriticalTailcalls) ||
3625+
vref.MakesNoCriticalTailcalls ||
3626+
(let valInfoForVal = GetInfoForValWithCheck cenv env m vref in valInfoForVal.ValMakesNoCriticalTailcalls) ||
36023627
(match env.functionVal with | None -> false | Some (v, _) -> valEq vref.Deref v)
36033628
if doesNotMakeCriticalTailcall then
36043629
let numArgs = otherArgs.Length + newArgs.Length

tests/AheadOfTime/Trimming/check.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function CheckTrim($root, $tfm, $outputfile, $expected_len) {
3939
# error NETSDK1124: Trimming assemblies requires .NET Core 3.0 or higher.
4040

4141
# Check net7.0 trimmed assemblies
42-
CheckTrim -root "SelfContained_Trimming_Test" -tfm "net8.0" -outputfile "FSharp.Core.dll" -expected_len 287232
42+
CheckTrim -root "SelfContained_Trimming_Test" -tfm "net8.0" -outputfile "FSharp.Core.dll" -expected_len 303104
4343

4444
# Check net7.0 trimmed assemblies
45-
CheckTrim -root "StaticLinkedFSharpCore_Trimming_Test" -tfm "net8.0" -outputfile "StaticLinkedFSharpCore_Trimming_Test.dll" -expected_len 8821248
45+
CheckTrim -root "StaticLinkedFSharpCore_Trimming_Test" -tfm "net8.0" -outputfile "StaticLinkedFSharpCore_Trimming_Test.dll" -expected_len 8839680

tests/FSharp.Compiler.ComponentTests/Debugger/PortablePdbs.fs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ module Baz =
7474
Line 16, Col 20, Line 16, Col 22
7575
Line 21, Col 20, Line 21, Col 22
7676
]
77-
VerifyDocuments [
78-
Path.Combine(Environment.CurrentDirectory, "test.fs")
79-
]
77+
VerifyDocuments [ "test.fs" ]
8078
]
8179

8280
[<Fact>]
@@ -100,9 +98,4 @@ module M =
10098
|> withPortablePdb
10199
|> compile
102100
|> shouldSucceed
103-
|> verifyPdb [
104-
VerifyDocuments [
105-
Path.Combine(Environment.CurrentDirectory, "test.fsi")
106-
Path.Combine(Environment.CurrentDirectory, "test.fs")
107-
]
108-
]
101+
|> verifyPdb [ VerifyDocuments [ "test.fsi"; "test.fs" ] ]

0 commit comments

Comments
 (0)