F# using lazy keyword raises trimming warnings on publish.
Discussed in https://github.com/dotnet/fsharp/discussions/17323
Originally posted by @abklearnhere June 18, 2024 F# using lazy keyword raises trimming warnings on publish. For example,
let f23 () = let z = lazy (12345) in z.Force()
[<EntryPoint>]
let main _ =
f23() |> System.Console.WriteLine
0
I am creating an F#, .NET 8 (SDK 8.0.302) console app and publish as a single file with AOT, trimming. I run dotnet publish command as below:
dotnet publish -c Release -r win-x64 --self-contained true -p:PublishAot=true -p:PublishTrimmed=true -p:ReflectionFree=false -o ./publish
This results in warning:
D:\a_work\1\s\src\FSharp.Core\prim-types.fs(7159): Trim analysis warning IL2091: Microsoft.FSharp.Control.LazyExtensions.Create<T>(FSharpFunc`2<Unit,!!0>): 'T' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in 'System.Lazy`1'. The generic parameter 'T' of 'Micros oft.FSharp.Control.LazyExtensions.Create<T>(FSharpFunc`2<Unit,!!0>)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
The warning appears regardless of -p:ReflectionFree being false or true. The fsproj file has following settings:
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<IsAotCompatible>true</IsAotCompatible>
<PublishAot>true</PublishAot>
<PublishTrimmed>true</PublishTrimmed>
<TrimmerSingleWarn>false</TrimmerSingleWarn>
ReflectionFree doesn't affect pretty much anything outside printing.
@KevinRansom another instance of trimmning + annotations.