Skip to content

Some FSharp.Core constructs don't run on CoreRT #4954

@zpodlovics

Description

@zpodlovics

I am experimenting with porting some of the F# testsuite cases to CoreRT (dotnet/corert#2057 (comment), dotnet/corert#5827) However right now some of the Core F# modules does not support code paths without dynamic code generation. For example the F# test suite written in a style that contains lot's of printf and sprintf code (egrep -r "printf" tests/|wc -l will found more than 10k cases). Earlier I intentionally avoided printf in the code bases that may also used in fully static compilation (Mono Full AOT). Due the large number of usage everywhere (eg.: testsuite) rewrite the existing printf/sprintf usage to System.String.Format and System.Console.WriteLine would be a huge waste of time.

Please note, some earlier test cases was carefully designed and intentionally avoided this issue by factoring out the printing functionality to the beginning of the test code:

let failures = ref []

let report_failure (s : string) = 
    stderr.Write" NO: "
    stderr.WriteLine s
    failures := !failures @ [s]

let test (s : string) b = 
    stderr.Write(s)
    if b then stderr.WriteLine " OK"
    else report_failure (s)

Is there any earlier Printf module version that could be used for this purpose - but without dynamic code generation (performance does not matter in this case)?

By dynamic code generation I mean code snippets like this:

        | 'A' ->
            let mi = typeof<ObjectPrinter>.GetMethod("GenericToString", NonPublicStatics)
            let mi = mi.MakeGenericMethod(ty)
            mi.Invoke(null, [| box spec |])

https://github.com/Microsoft/visualfsharp/blob/master/src/fsharp/FSharp.Core/printf.fs#L1170

Repro steps

printf.zip

cd printf
dotnet publish -c Release -r linux-x64
./bin/Release/netcoreapp2.0/linux-x64/publish/printf

Expected behavior

Core modules should also work without dynamic code generation path (as a fallback option).

Actual behavior

Due the dynamic code generation the Printf module does not work with CoreRT.

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.FSharp.Core.PrintfImpl.PrintfBuilder`3.buildPlainFinal(Object[], Type[]) + 0xbd
   at Microsoft.FSharp.Core.PrintfImpl.PrintfBuilder`3.Build[T](String) + 0x61
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey, Func`2) + 0x83
   at Microsoft.FSharp.Core.PrintfImpl.Cache`4.Get(PrintfFormat`4) + 0x65
   at Microsoft.FSharp.Core.PrintfModule.PrintFormatToTextWriterThen[TResult, T](FSharpFunc`2, TextWriter, PrintfFormat`4) + 0x21
   at Program.main(String[]) + 0x3a
   at printf!<BaseAddress>+0x209f83

Aborted

Known workarounds

Rewrite everything to System.Console.WriteLine and System.String.Format or write Printf module without dynamic codegen.

Related information

  • Operating system: Ubuntu 16.04
  • .NET Runtime, CoreCLR or Mono Version:
ii  dotnet-host                                                 2.1.0-rc1-1                                                 amd64        Microsoft .NET Core Host - 2.1.0 Release Candidate 1
ii  dotnet-hostfxr-1.1.0                                        1.1.0-1                                                     amd64        Microsoft .NET Core 1.1.3 - Host FX Resolver 1.1.0
ii  dotnet-hostfxr-2.0.5                                        2.0.5-1                                                     amd64        Microsoft .NET Core Host FX Resolver - 2.0.5 2.0.5
ii  dotnet-hostfxr-2.0.6                                        2.0.6-1                                                     amd64        Microsoft .NET Core Host FX Resolver - 2.0.6 2.0.6
ii  dotnet-hostfxr-2.1.0-rc1                                    2.1.0-rc1-1                                                 amd64        Microsoft .NET Core Host FX Resolver - 2.1.0 Release Candidate 1 2.1.0-rc1
ii  dotnet-runtime-2.0.5                                        2.0.5-1                                                     amd64        Microsoft .NET Core Runtime - 2.0.5 Microsoft.NETCore.App 2.0.5
ii  dotnet-runtime-2.0.6                                        2.0.6-1                                                     amd64        Microsoft .NET Core Runtime - 2.0.6 Microsoft.NETCore.App 2.0.6
ii  dotnet-runtime-2.1.0-rc1                                    2.1.0-rc1-1                                                 amd64        Microsoft .NET Core Runtime - 2.1.0 Release Candidate 1 Microsoft.NETCore.App 2.1.0-rc1
ii  dotnet-runtime-deps-2.1.0-rc1                               2.1.0-rc1-1                                                 amd64        dotnet-runtime-deps-2.1.0-rc1 2.1.0-rc1
ii  dotnet-sdk-2.1.4                                            2.1.4-1                                                     amd64        Microsoft .NET Core SDK - 2.1.4
ii  dotnet-sharedframework-microsoft.netcore.app-1.1.8          1.1.8-1                                                     amd64        Microsoft .NET Core 1.1.8 - Runtime Microsoft.NETCore.App 1.1.8

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions