-
Notifications
You must be signed in to change notification settings - Fork 90
update API to require use of ProvidedTypesContext and incorporate into one file #135
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
Conversation
|
@7sharp9 This brings cross-targeting generative type providers much closer @isaacabraham @sergey-tihon All erasing type providers should be upgraded to use this version of the API. @KevinRansom This does a lot of the ground work necessary to have type providers we can execute when the compiler executes with .NET Core. @Thorium I'd love to get early feedback on upgrading SQLProvider to use this |
| |> (fun arr -> arr.[n - 1]) | ||
|
|
||
| let adaptMethod = getFastFuncType args resultType | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a particular reason for GetterCode instead of getterCode here? Actually, I'm a bit confused why a lot of parameters are CamelCase. Did I miss a guideline somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I'm asking because from the changes it seems to be "less" source code breaking with lower case but that could be completely off)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am just reverting that
|
Example of upgrading a TP that already uses ProvidedTypesContext:
|
|
Yes, I think the major issue was, that using named parameters did actually call non-ProvidedTypesContext-setters ctxt.ProvidedMethod("MyMethod", providerParams, serviceType, someinvoke, IsStaticMethod = true) // Wrong
ctxt.ProvidedMethod("MyMethod", providerParams, serviceType, someinvoke, true) // CorrectI already removed named parameters, but on some level it decreases code readability. The main problem now is that type providers need sometimes reflection, and using reflection in .NET Standard is hard, because every dll has so many other dependencies which have to be also near. The answer should be Microsoft.Extensions.DependencyModel's DependencyContext.Default libraries, but |
|
Sounds promising! I'll give this a bash against the Azure TP. |
|
I still suspect that named parameters are not working and calling a method like ctxt.ProvidedMethod("GetDataContext", providerParams, serviceType, invokeCode=invoker)is wrong because it will call IL constructor for the ProvidedMethod without named parameter and then doing For that reason the parameters shouldn't be optional at all. |
They are working. I'm not sure what you're seeing but with that you will call https://github.com/fsprojects/FSharp.TypeProviders.SDK/blob/master/src/ProvidedTypes.fsi#L433 with |
|
That will pass the value through as an argument here https://github.com/fsprojects/FSharp.TypeProviders.SDK/blob/master/src/ProvidedTypes.fs#L6909 |
|
The previous version did allow to rule out some functionality with conditional compilation. The current version enforces to use the new model. The new model doesn't support F# function lambda calls in the expression tree as the old one allowed. Edit: Example that generates above: let myThingRuntime =
<@@ match myToolsCall param1 with "a" -> 1 | "b" -> 2 | _ -> failwith "unknown" @@>
ctxt.ProvidedMethod("MyMethod", providerParams, serviceType,
invokeCode = fun (_:Expr list) -> <@@ MyType(%%myThingRuntime) @@>) |
|
@Thorium Thanks? Could you provide a full repro for that? We need to fix that. |
Did you have a specific
Yes - you have to use ProvidedTypeContext. That's required now.
This is the part I've like a specific repro for |
|
Yes. To reproduce this problem, there is a branch: https://github.com/fsprojects/SQLProvider/tree/providedtypes-expr SQLProvider has multiple database connections to different databases.
We are using directly this project's files, they are located after a build at: It fails on runtime while running test from solution The error: gtd.Metadata.Methods.FindByNameAndArity(name, types.Length)
|> Array.find (fun md -> eqTypesAndILTypesWithInst types args md.ParameterTypes)...but the real problem is at recursive expression tree parsing, where it tries to parse different kind of logics to Microsoft.FSharp.Quotations.FSharpExpr. For SQLProvider this was a minor problem, I just excluded those overrides from .NET Standard version as their usage is so minor anyways, and kind of anti-pattern, but on the other hand I would like to maintain the old features for backward-compatibility. |
|
@Thorium Lovely, thanks for the repro |
|
@Thorium Could you open a pull request to SQLProvider master from https://github.com/fsprojects/SQLProvider/tree/providedtypes-expr please - I will help iterate on the pull request (e.g. updating it with fixed TPSDKs) until it is working and passing all tests, thanks |
|
@Thorium You might also want to paket-update to the latest TPSDK and see if we get a bit further (I pushed a number of fixes in today) |
|
Working! |
|
@Thorium That's great to know. |
This is a substantial set of changes to the ProvidedTypes SDK
We require that all authors of type providers now use a ProvidedTypesContext, e.g.
There are no more direct constructors for
ProvidedTypeDefinitionetc.ProvidedTypesContext.Create now takes a flag
isForGenerated. It should be set totruefor generative type providersIsStaticMethodbecomesIsStaticand some other similar naming changesDirect setters such as
prop.GetterCode <- ...are removed in favour of optional parameters. You must specifyGetterCodeas a parameterEnables use as part of .NET Core execution of the F# compiler by extending
TypeDelegatorinstead ofType. This needs to be more fully tested but the repo itself now compiles as both .NET Standard 2.0 and .NET Framework, and passes tests as both .NET CoreApp 2.0 and .NET Framework 4.6.1Puts everything into one file
ProvidedTypes.fsandProvidedTypes.fsi. This file is large but this approach makes it very easy for people writing existing type providers to update (after accounting for changes in the ProvidedTypes API)The one major thing that's remaining is cross-targeting for generative type providers. A lot of the code restructuring here is to enable us to implement that cleanly and accurately (we basically need an IL binary generator that is not dependent on .NET reflection emit, as discussed elsewhere)