Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NativeAOT FSharp issue #70999

Closed
kant2002 opened this issue Jun 20, 2022 · 3 comments
Closed

NativeAOT FSharp issue #70999

kant2002 opened this issue Jun 20, 2022 · 3 comments
Labels
area-NativeAOT-coreclr tracking-external-issue The issue is caused by external problem (e.g. OS) - nothing we can do to fix it directly

Comments

@kant2002
Copy link
Contributor

Not sure if I again on the unsupported territory or not, but let's pretend not.

Get code from this PR JamesRandall/fsharp-wolfenstein#7 and add

diff --git a/desktop/FSharpWolfenstein.Desktop.fsproj b/desktop/FSharpWolfenstein.Desktop.fsproj
index 74c5450..a7114eb 100644
--- a/desktop/FSharpWolfenstein.Desktop.fsproj
+++ b/desktop/FSharpWolfenstein.Desktop.fsproj
@@ -2,9 +2,11 @@

     <PropertyGroup>
         <OutputType>Exe</OutputType>
-        <TargetFramework>net6.0</TargetFramework>
+        <TargetFramework>net7.0</TargetFramework>
         <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
         <PublishAot Condition="'$(TargetFramework)' == 'net7.0'">true</PublishAot>
+        <IlcTrimMetadata>true</IlcTrimMetadata>
+        <TrimmerDefaultAction>link</TrimmerDefaultAction>
     </PropertyGroup>

     <ItemGroup>

Publish with dotnet publish -c Release --self-contained.
Mostly application works, but some diagnostic information triggers

Unhandled Exception: System.Collections.Generic.KeyNotFoundException: An index satisfying the predicate was not found in the collection.
   at Microsoft.FSharp.Collections.ArrayModule.loop@596-36[T, TResult](FSharpFunc`2, T[], Int32) + 0x9e
   at Microsoft.FSharp.Reflection.Impl.getUnionCaseTyp(Type, Int32, BindingFlags) + 0x3e
   at Microsoft.FSharp.Reflection.Impl.fieldsPropsOfUnionCase(Type, Int32, BindingFlags) + 0x143
   at Microsoft.FSharp.Reflection.FSharpValue.GetUnionFields(Object, Type, FSharpOption`1) + 0x6f
   at Microsoft.FSharp.Text.StructuredPrintfImpl.ReflectUtils.Value.GetValueInfoOfObject$cont@525(BindingFlags, Object, Type, Unit) + 0x57
   at Microsoft.FSharp.Text.StructuredPrintfImpl.Display.ObjectGraphFormatter.objL(Display.ShowMode, Int32, Display.Precedence, Object, Type) + 0x3f
   at Microsoft.FSharp.Text.StructuredPrintfImpl.Display.Format@1515.Invoke(Int32, Display.Precedence, Tuple`2) + 0x3a
   at Microsoft.FSharp.Text.StructuredPrintfImpl.Display.ObjectGraphFormatter.Format[a](Display.ShowMode, a, Type) + 0x83
   at Microsoft.FSharp.Text.StructuredPrintfImpl.Display.anyToStringForPrintf[T](FormatOptions, BindingFlags, T, Type) + 0x5c
   at Microsoft.FSharp.Core.PrintfImpl.ObjectPrinter.GenericToStringCore[T](T, FormatOptions, BindingFlags) + 0x47
   at Microsoft.FSharp.Core.PrintfImpl.OneStepWithArg@508-1.Invoke(A) + 0x37
   at System.Text.ValueStringBuilder.AppendFormatHelper(IFormatProvider, String, ParamsArray) + 0x644
   at System.String.FormatHelper(IFormatProvider, String, ParamsArray) + 0xae
   at Microsoft.FSharp.Core.PrintfImpl.InterpolandToString@924.Invoke(Object) + 0x75
   at Microsoft.FSharp.Core.PrintfImpl.PrintfEnv`3.RunSteps(Object[], Type[], PrintfImpl.Step[]) + 0xb4
   at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThen[T](PrintfFormat`4) + 0x6a
   at App.AI.preProcess(Model.Game, Model.Enemy) + 0x110
   at App.AI.applyAi(Double, Model.Game, Model.GameObject) + 0x5b
   at App.Update.updatedGameObjects@254.Invoke(Int32, Model.GameObject) + 0x95
   at Microsoft.FSharp.Primitives.Basics.List.mapiToFreshConsTail[a, b](FSharpList`1, OptimizedClosures.FSharpFunc`3, FSharpList`1, Int32) + 0x5c
   at Microsoft.FSharp.Primitives.Basics.List.mapi[T, TResult](FSharpFunc`2, FSharpList`1) + 0xb1
   at App.Update.updateEnemies@251(Double, Model.WallRenderingResult, Model.Game, Boolean) + 0x67
   at App.Update.updateFrame(Model.Game, Double, Model.WallRenderingResult) + 0x295
   at Program.render(Double) + 0x4a
   at Program.main@198-1.Invoke(Double) + 0x9
   at Silk.NET.Windowing.Internals.ViewImplementationBase.DoRender() + 0x16e
   at Silk.NET.Windowing.Internals.ViewImplementationBase.Run(Action) + 0x15
   at Silk.NET.Windowing.WindowExtensions.Run(IView) + 0x61
   at Program.main(String[]) + 0x149
   at FSharpWolfenstein.Desktop!<BaseAddress>+0x462583

Which seems to be from this line

https://github.com/JamesRandall/fsharp-wolfenstein/blob/4032d6e3157dd3ca99a26ab617be2f983700a3e9/browser/src/CrossPlatform/AI.fs#L278

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jun 20, 2022
@jkotas
Copy link
Member

jkotas commented Jun 20, 2022

Printf in FSharp is known to use a ton of reflection that is not compatible with trimming. Duplicate of fsharp/fslang-suggestions#919 .

@jkotas jkotas closed this as completed Jun 20, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Jun 20, 2022
@jkotas jkotas added the tracking-external-issue The issue is caused by external problem (e.g. OS) - nothing we can do to fix it directly label Jun 20, 2022
@kant2002
Copy link
Contributor Author

Just FYI that's slightly different pattern, but I will go report that pattern there too.

@ghost ghost locked as resolved and limited conversation to collaborators Jul 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-NativeAOT-coreclr tracking-external-issue The issue is caused by external problem (e.g. OS) - nothing we can do to fix it directly
Projects
None yet
Development

No branches or pull requests

2 participants