Skip to content

[Sdk 2] Compiler does not fail if FSharp.Core is not referenced #3340

Closed

Description

@0x53A

Note: No paket this time, really just these two files. =)

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net461</TargetFramework>
    <DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
  </PropertyGroup>
  
  <ItemGroup>
    <Compile Include="Library.fs" />
  </ItemGroup>
  
</Project>
namespace fsharp_test

module Say =
    let hello name =
        let r = Result.Ok name
        printfn "Hello %s" (match r with Ok n -> n | Error x -> x)

Expected

I would expect the project to fail with an actionable error message.

Actual

image

image

Note how the generated package does not have a reference against FSharp.Core!

The compiler (not the SDK!) just picked any available FSharp.Core from the environment.

This will cause lot's of issues at runtime.

/cc @forki, ref fsprojects/Paket#2528 (comment)

Activity

  1. 0x53A commented on Jul 16, 2017

    @0x53A
    ContributorAuthor

    I created a detailed build log, this is the relevant part:

    Using "Fsc" task from assembly "C:\Program Files\dotnet\sdk\2.1.0-preview1-006784\FSharp\FSharp.Build.dll".
           Task "Fsc"
             C:\Program Files\dotnet\sdk\2.1.0-preview1-006784\FSharp\RunFsc.cmd -o:obj\Debug\net461\fsharp-test.dll
             -g
             --debug:portable
             --noframework
             --define:TRACE
             --define:DEBUG
             --define:NET461
             --optimize-
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\mscorlib.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Core.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Data.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Drawing.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.IO.Compression.FileSystem.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Numerics.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Runtime.Serialization.dll
             -r:C:\Users\lr\.nuget\packages\system.valuetuple\4.3.1\lib\netstandard1.0\System.ValueTuple.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Xml.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Xml.Linq.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Collections.Concurrent.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Collections.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.ComponentModel.Annotations.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.ComponentModel.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.ComponentModel.EventBasedAsync.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Diagnostics.Contracts.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Diagnostics.Debug.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Diagnostics.Tools.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Diagnostics.Tracing.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Dynamic.Runtime.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Globalization.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.IO.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Linq.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Linq.Expressions.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Linq.Parallel.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Linq.Queryable.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Net.NetworkInformation.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Net.Primitives.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Net.Requests.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Net.WebHeaderCollection.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.ObjectModel.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Reflection.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Reflection.Emit.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Reflection.Emit.ILGeneration.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Reflection.Emit.Lightweight.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Reflection.Extensions.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Reflection.Primitives.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Resources.ResourceManager.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Runtime.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Runtime.Extensions.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Runtime.Handles.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Runtime.InteropServices.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Runtime.InteropServices.WindowsRuntime.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Runtime.Numerics.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Runtime.Serialization.Json.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Runtime.Serialization.Primitives.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Runtime.Serialization.Xml.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Security.Principal.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.ServiceModel.Duplex.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.ServiceModel.Http.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.ServiceModel.NetTcp.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.ServiceModel.Primitives.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.ServiceModel.Security.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Text.Encoding.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Text.Encoding.Extensions.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Text.RegularExpressions.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Threading.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Threading.Tasks.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Threading.Tasks.Parallel.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Threading.Timer.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Xml.ReaderWriter.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Xml.XDocument.dll
             -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Xml.XmlSerializer.dll
             --target:library
             --warn:3
             --warnaserror:76
             --fullpaths
             --flaterrors
             --subsystemversion:6.00
             --highentropyva+
             --targetprofile:mscorlib
             --simpleresolution
             --nocopyfsharpcore
             Library.fs
             C:\Users\lr\AppData\Local\Temp\.NETFramework,Version=v4.6.1.AssemblyAttributes.fs
             
             Microsoft (R) F# Compiler version 4.1
             Copyright (c) Microsoft Corporation. All Rights Reserved.
           Done executing task "Fsc".
         1>Done building target "CoreCompile" in project "fsharp-test.fsproj".
    

    Note how there is no reference to FSharp.Core.

    I always thought --noframework disabled this magic stuff, is there a second switch to disable magic FSharp.Core resolution?

  2. KevinRansom commented on Jul 17, 2017

    @KevinRansom
    Contributor

    @0x53A

    The compiler is always going to find an FSharp.Core.dll. With or without SDK magic. The Compiler has always had a last port of call where it looks in the directory containing the compiler binaries to load an FSharp.Core. And we ship an FSharp.Core.dll alongside the compiler.

    The behavior is needed for the command line compile scenario: fsc program.fs and fsi scripts and the interactive fsi session, as well as, I expect, most apps that rely on the FCS.

    Kevin

  3. forki commented on Jul 17, 2017

    @forki
    Contributor

    fsc program.fs and fsi are completely different things than sdk and pack.

  4. KevinRansom commented on Jul 17, 2017

    @KevinRansom
    Contributor

    How is that relevant?

  5. 0x53A commented on Jul 17, 2017

    @0x53A
    ContributorAuthor

    @KevinRansom and that's great when you call the compiler manually - but not so great when the compiler gets called from the sdk.

    Similar to --noframework, there needs to be a switch to disable this magic resolution ( I call it magic because it is not obvious from the user's point of view).


    My concern is that if we enable DisableImplicitFSharpCoreReference by default in paket, then we end up with a lot of broken packages that do not reference FSharp.Core at all.

    My second concern is that if we do not enable DisableImplicitFSharpCoreReference by default in paket, then we end up with a lot of packages that reference a wrong version of FSharp.Core.

  6. KevinRansom commented on Jul 17, 2017

    @KevinRansom
    Contributor

    0x53a.

    We already have a switch it's called --simpleresolution, however, even that does this fallback behavior, and always has. I am reluctant to add yet another compiler switch
    e.g. --reallyreallytrulysimpledonothingmagicatall
    because I know that at some point someone will add code to make it do magic. Changing the current behavior will break some existing project, and

    What we can do is this:

    Add something to the SDK targets, that verifies that there is an FSharp.Core referenced in the msbuild target and fail if it doesn't find it.

    Then when you build using an SDK target with the disabled flag. If there isn't a manual reference the sdk build will fail with an error.

    If you like the idea open an issue, and we will look at how to solve it.

    How does that sound?

    Kevin

  7. forki commented on Jul 17, 2017

    @forki
    Contributor

    What's wrong with this issue here?
    Doing it in the sdk is OK too

  8. 0x53A commented on Jul 17, 2017

    @0x53A
    ContributorAuthor

    I think the existing flags all have more or less well defined behaviour and are orthogonal:

    (someone please correct me if I am wrong)

    • --simpleresolution: don't manually resolve assembly identities like "System.ValueTuple" to the GAC or special folders, expect that the user passes the full path.

    • --noframework: don't automatically reference the latest installed .net framework, expect that the user passes all facades manually.

    So a new switch --noimplicitfsharpcore would, in my opinion, be completely unrelated to the existing switches.

  9. KevinRansom commented on Jul 17, 2017

    @KevinRansom
    Contributor

    I'm okay with, building this into the SDK especially since you have the same issue with System.ValueTuple and perhaps any other framework assembly that holds types that may migrate to other contract assemblies eventually, that we may auto-reference.

    And perhaps one day we can clean up all of the compiler referencing to a simple model. That is at least my hope ...

  10. 0x53A commented on Jul 17, 2017

    @0x53A
    ContributorAuthor

    I'm okay with, building this into the SDK

    A check in the SDK would be better than nothing, and even if I can convince you to add the new fsc arg, it's probably easier to modify the sdk than to modify the compiler with regard to 15.3. =)

    But that just feels a bit like a bandaid.

    especially since you have the same issue with System.ValueTuple

    Afaik the compiler does have special knowledge about a few types (e.g. it knows that System.Tuple moved from FSharp.Core to the mscorlib), but (again afaik) FSharp.Core is (with --noframework) the only thing that gets automatically referenced.

    namespace testx
    
    module Say =
        let hello name =
            let x = System.ValueTuple<int,int>(1, 2)
            printfn "Hello %s" name
    
    <Project Sdk="Microsoft.NET.Sdk">
    
      <PropertyGroup>
        <TargetFramework>net461</TargetFramework>
        <DisableImplicitSystemValueTupleReference>true</DisableImplicitSystemValueTupleReference>
      </PropertyGroup>
    
      <ItemGroup>
        <Compile Include="Library.fs" />
      </ItemGroup>
    
    </Project>
    
    Microsoft (R)-Buildmodul, Version 15.3.406.54721 für .NET Core
    Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.
    
    C:\temp\testx\Library.fs(5,24): error FS0039: Der Wert, Konstruktor, Namespace oder Typ "ValueTuple" ist nicht definiert. Vielleicht möchten Sie eine der folgenden Bezeichnungen verwenden:�   ValueType [C:\temp\testx\testx.fsproj]
    
    Fehler beim Buildvorgang.
    
    C:\temp\testx\Library.fs(5,24): error FS0039: Der Wert, Konstruktor, Namespace oder Typ "ValueTuple" ist nicht definiert. Vielleicht möchten Sie eine der folgenden Bezeichnungen verwenden:�   ValueType [C:\temp\testx\testx.fsproj]
        0 Warnung(en)
        1 Fehler
    
    Verstrichene Zeit 00:00:01.65
    

    (Sorry for the german, The value, constructor, namespace or type "ValueTuple" is not defined.)

  11. KevinRansom commented on Jul 17, 2017

    @KevinRansom
    Contributor

    @0x53A everything about how the compiler resolves types is a band aid. I want to move to the model that nothing is resolved magically. However, we are a long way away from being able to do that ... Until then enforcing requirements in the build system is what we have.

  12. dsyme commented on Jul 18, 2017

    @dsyme
    Contributor

    I always thought --noframework disabled this magic stuff, is there a second switch to disable magic FSharp.Core resolution?

    I thought this was the case as well. It would be worth checking previous versions of F# to see if this was the case and if something has changed here. (Specifically, I thought the compiler complained if you gave it an explicit "mscorlib.dll" without an explicit "FSharp.Core")

    Certainly I would have no problem with --noframework having this behaviour. The whole point of --noframework is to turn off all the auto-referencing that is necessary for the current implementation of the F# scripting model, i.e. it is designed to get you to the simple world that @KevinRansom mentions.

  13. added this to the 16.0 milestone on Jul 30, 2018
  14. modified the milestones: 16.0, Unknown on Aug 25, 2018
  15. dsyme commented on Aug 24, 2021

    @dsyme
    Contributor

    Closing out this old issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions