-
Notifications
You must be signed in to change notification settings - Fork 839
Description
Hi everyone,
In our project FShade we're making heavy use of quotations and we're totally happy with most of the features available for inspecting and changing them.
However there is one big issue I'd like to share since I could not quite get my head around the compiler-code responsible for that.
Statically resolved parameters
When using functions like
let inline run< ^a, ^b when ^a : (member Invoke : ^b -> unit) > (a : ^a) (b : ^b) =
(^a : (member Invoke : ^b -> unit) (a, b))inside quotations, the resulting Expr will look like Call(runMeth, [a]) and there is (to my knowledge) no way of getting its definition for the concrete instantiation in question.
When adding the [<ReflectedDefinition>] attribute to run the compiler complains with Quotations cannot contain expressions that make member constraint calls, or uses of operators that implicitly resolve to a member constraint call
Motivation
Currently our C99/GLSL compiler maintains a mapping from all known inline functions to their respective backend counterpart which makes it hard to add utility-functions.
Consider the following example:
type Vec2 =
// ...
member x.X : float
type Vec3 =
// ...
member x.X : float
module Vec =
let x< ^a, ^b when ^a : (member X : ^b) > (v : ^a) = (^a : (member X : ^b) (v)Since x is treated as a call our compiler needs to know about its definition. However if the code was inlined in the Expr it would only need to know about the property X (which it does anyways).
Suggestion
Would it be possible to resolve all inline functions at compile-time and simply inline their (resolved) definition in quotations like that?
let a = System.Action<int>(ignore)
<@ run a 10 @> = <@ a.Invoke(10) @>I'm aware that this scheme will not work for built-in functions (e.g. op_Addition) since they use inline-IL which cannot be represented in Expr.
Since this change would break the current behaviour of quotations one could (for example) add the inlined Expr to the CustomAttributes list for the expression.
any thoughts on that?
cheers