[RFC FS-1071] Discussion - Quotations to contain witness information #357
Replies: 11 comments
-
There is an open question in this RFC which I wanted to record. The question is to do with witnesses for "built in" constraint solutions which do not have a corresponding direct .NET method to represent a solution. For example let inline f x = x + x
<@ f 3 @> The call to Now, because .NET IL metadata is somewhat silly it doesn't actually contain a static member There are about 500 of these type-specialized primitives in FSharp.Core (roughly speaking corresponding to all the various cases of Ideally, for quotations, However, there are not really any readily available non-generic entry points in It seems the right thing to do to ensure that FSharp.Core exposes sufficient implementations of these witness primitives (prim-types already contains these implementations as code, but doesn't expose them). Remember, the aim of this PR is for quotations to provide "accurate" witnesses for primitives. If they do, then quotations become "semantically complete" w.r.t. using |
Beta Was this translation helpful? Give feedback.
-
I had an issue which might be similar where I was creating a quotation that referenced an SRTP function but I was then calling that function with different generic parameters and using the LeafExpressionConverter to evaluate it, the end result was method not implemented due to the inline method not existing. /cc @kevmal |
Beta Was this translation helpful? Give feedback.
-
Yes, that is essentially the problem that this whole RFC is solving at the foundational level. |
Beta Was this translation helpful? Give feedback.
-
Hey, I ran into the same problems implementing constant-folding in FShade and having access to the inlined code would certainly help (or even just IL instructions would be better than nothing). I actually tried to parse the This would boil down to a reflection-utility like Is that totally insane or do you see any chance to make this work? |
Beta Was this translation helpful? Give feedback.
-
I have resolved this in the implementation by using the corresponding |
Beta Was this translation helpful? Give feedback.
-
@dsyme would it make sense to do these calls as constrained calls to structs (no allocs, JIT can fully inline) instead of FSharpFuncs for something simple as '+'? Or do you think this area is edge case enough not to worry too much? It'd be a shame not to have brought it up and be stuck with it :) |
Beta Was this translation helpful? Give feedback.
-
@dsyme At some point you might consider to remove simulated members from the internals of the F# compiler. Maybe when extension members are visible to SRTP you can use that instead. |
Beta Was this translation helpful? Give feedback.
-
I'm not sure I understand the purpose of the "WithWitnesses" method is, it looks like a trivial eta expansion on the supplied lambda. Is it simply meant to provide optional debug information or is there something more to it? |
Beta Was this translation helpful? Give feedback.
-
That's true if the implementation of the method is just to immediately invoke the constraint, e.g. let inline foo (x: ^T) = (^T : (static member Foo : ^T -> ^T) (x)) However for something like "List.sumBy" the implementation has no constraint invocations at all and the witnesses are passed to (The |
Beta Was this translation helpful? Give feedback.
-
I'm not sure what you mean here - do you mean removing methods from FSharp.Compiler.Private.dll to reduce size, or something else? |
Beta Was this translation helpful? Give feedback.
-
The F# compiler internally uses static optimizations to pretend some primitive types have certain static method, as you said before, Once you have Extension members visible to trait calls, you won't need that any longer, you can use normal extension methods instead. |
Beta Was this translation helpful? Give feedback.
-
This is the discussion thread for https://github.com/fsharp/fslang-design/blob/master/FSharp-5.0/FS-1071-witness-passing-quotations.md
Beta Was this translation helpful? Give feedback.
All reactions