Giter Site home page Giter Site logo

Comments (12)

KevinRansom avatar KevinRansom commented on May 14, 2024

I have talked this over with Don and we agree that this is an issue with the type provider. the compiler does what it is told and the type provider has told it to use fsharp.core.dll. I considered remapping the references in the compiler, but that sort of magic does not really belong in the compiler.

What is needed is providedtypes.fs needs a new set of helpers which will make types, methodinfos, generic types etc only from the set of assemblies passed to the type provider by the compiler. I notice that there is a bunch of code in the TP for handling assembly resolution failure and so loading stuff randomly from the compiling machine. None of that will work well for portable libraries, and will work even worse if we re-host the compiler on coreclr, also when we are doing multi-targeting, I.e. using FSharp 4.0 to compile an F# 3.1 or F# 3.0 application, the only runtime difference is the set of target assemblies.

@ovatsus as maintainer of the TypeProviders starter pack, would you like to start a thread on how to solve this. I will help make sure the solution will work for the cross platform scenario.

from fsharp.

ovatsus avatar ovatsus commented on May 14, 2024

This is very tricky business, unfortunately, with assembly mismatches all over.
FSharp.Data is the only TP lib I know of that tries to support portable, and it's really hard. First approach was to build a mechanism to fix up all the types, that breaks in NetCore because there's issues with mscorlib. I started trying another approach but I'm stuck: fsprojects/FSharp.Data#672

from fsharp.

KevinRansom avatar KevinRansom commented on May 14, 2024

I agree it ain't easy. So the type provider must only use types from the reference set for quotations and provided types. If the type can't be loaded from there then it is a missing type error. If you use LoadFrom and then GetType() and MakeGenericType etc. Type Forwarders and binding redirects should not be honored.

Remapping is possible but ultimately a hack, and the compiler doesn't really know about profiles, it just knows about the set of assemblies that it gets from the command line and the source code being compiled. If I had the bandwidth I would look at this, since it is an important issue, and one that is only going to get more important.

from fsharp.

latkin avatar latkin commented on May 14, 2024

What is our guidance to TP authors/consumers, then? If our position is that this is an issue with the TP, how do they fix their issue?

If there is no good way to "fix" this, I guess we just advise folks that it's unsupported to down-target when using type providers (i.e. type providers are not forward-compatible).

from fsharp.

dsyme avatar dsyme commented on May 14, 2024

It is definitely possible to fix this in type providers, and most likely it is possible to have some very general machinery in ProvidedTypes.fs that fixes this in most cases for most type providers. It feels like we need to iterate towards some additions to ProvidedTypes.fs (in the Type Provider Starter Pack) which get us what we need....

from fsharp.

latkin avatar latkin commented on May 14, 2024

Can you elaborate on how this can be fixed in TPs, so that @ctaggart and co. can make appropriate adjustments? If the TP was built entirely using 3.1 toolchain, what mechanism do we offer to prevent vFuture toolchain from adding bogus new references?

from fsharp.

dmitry-a-morozov avatar dmitry-a-morozov commented on May 14, 2024

I made an attempt to fix the problem.

I realized that I use AssemblyQualifiedName for types from FSharp.Core.
https://github.com/fsprojects/FSharp.Data.SqlClient/blob/104ca6be317dd752817b1272eacdeb69e5d7bb63/src/SqlClient/DesignTime.fs#L165
That's fixed

Also per @KevinRansom suggestion I changed assembly resolution logic from
https://github.com/fsprojects/FSharp.Data.SqlClient/blob/master/src/SqlClient/SqlProgrammabilityProvider.fs#L36
to
https://github.com/fsprojects/FSharp.Data.SqlClient/blob/38ba3b625c424aa69a7075100ad147adc4f60479/src/SqlClient/SqlProgrammabilityProvider.fs#L60

But the problem is not gone.

To experiment I added a console app as test projects that targets .NET 4.0 + FSharp.Core 4.3.0.0.
https://github.com/fsprojects/FSharp.Data.SqlClient/tree/master/src/SqlClient.Tests/SqlClient.Tests.NET40
Surprisingly this console application exe contains references to both FSharp.Core 4.3.0.0 and FSharp.Core 4.3.1.0.
How's that possible? Both type provider library and application compiled with FSharp.Core 4.3.0.0. So FSharp.Core 4.3.1.0 no-where in the picture.
When attempt to run this application fails with same error as mentioned in the original issue #23.
Binding redirects (either to 4.3.0.0 or forward to 4.3.1.0) helps to solve this.
So it is forward-compatible.

Please assist.
//cc @vladima

from fsharp.

KevinRansom avatar KevinRansom commented on May 14, 2024

This is a fundamentally very hard problem. TypeProvider authors need to think like compiler writers, and only bind types from the set of types provided to the compiler. The tendency is to think like an app and library author and bind to loadable types. As far as I can tell no type provider has yet done this correctly, I would dearly like to figure out how to solve this, but I am snowed under with other stuff to do.

What is required is a binder that will return types from a set of reachable assemblies. Those types are the ones that need to be returned to the compiler.

I had suggested and implemented a prototype of a filter between the compiler and the type provider that fixed up the references to only reachable types and it even worked. But Don convinced me that it was an invalid approach that primarily masked bugs in the type provider.

from fsharp.

dmitry-a-morozov avatar dmitry-a-morozov commented on May 14, 2024

Hi there.
I would like to mention 3 things:

  1. I really need a help because I'm lost. I thought I have some understanding of the issue but not anymore. Guidelines would be nice.
  2. Why FSharp.Core is never in the list of https://msdn.microsoft.com/en-us/library/hh323947.aspx ?
  3. Here is something I don't understand at all.
    This a project that uses FSharp.Data.SqlClient
    https://github.com/fsprojects/FSharp.Data.SqlClient/tree/2753a097f224015c76f01346311c453a43240649/src/SqlClient.Tests/SqlClient.Tests.NET40
    The project targets .NET 4 and FSharp.Core 4.3.0.0.
    but when compiled in VS 2013 it produces binary that has dependency on both versions of FSharp.Core: 4.3.0.0 and 4.3.2.0
    when compiled in VS 2012 targeting .NET 4 and FSharp.Core 4.3.0.0 it depends as expected only FSharp.Core 4.3.0.0
    image

Can you clarify?

Easiest way to repro locally is pull the whole repo
https://github.com/fsprojects/FSharp.Data.SqlClient.git
Open SqlClient.sln from root folder.
Then start project with (or without) debugging.
It opens test solution which includes SqlClient.Tests.NET40 project.

from fsharp.

veikkoeeva avatar veikkoeeva commented on May 14, 2024

@dmitry-a-morozov This is a long-shot, but during the last half a year or so I've got the feeling that whenever there's Assembly.LoadFrom, one wants to apply policies as well or things turn up wrong at some point for the end user. More info at Fsharp.Data #821.

from fsharp.

dsyme avatar dsyme commented on May 14, 2024

Hi @dmitry-a-morozov - addressing one small part of this puzzle - In #478 I describe how the ReferencedAssemblies property is not populated fully and doesn't include FSharp.Core and mscorlib in the references. This is simply a bug but an annoying one as it would be very useful information to help with multi-targeting.

from fsharp.

dmitry-a-morozov avatar dmitry-a-morozov commented on May 14, 2024

Hi @dsyme. Thanks for the update. Keep me posted. Eventually I will need somebody's help or guidelines to fix the issue. Unless F# team will find a way to magically resolve it.

from fsharp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.