fsharp / fslang-suggestions

The place to make suggestions, discuss and vote on F# language and core library features
343 stars 20 forks source link

Complete FSharp.Linq.RuntimeHelpers.LeafExpressionConverter.QuotationToExpression #956

Open Happypig375 opened 3 years ago

Happypig375 commented 3 years ago

It is especially unexpected when

Linq.RuntimeHelpers.LeafExpressionConverter.QuotationToLambdaExpression <@ System.Func<int, int>(fun x -> System.Console.WriteLine "1"; System.Console.WriteLine "2"; x) @>

fails with

System.NotSupportedException: Could not convert the following F# Quotation to a LINQ Expression Tree
--------
Sequential (Call (None, WriteLine, [Value ("1")]),
            Sequential (Call (None, WriteLine, [Value ("2")]), x))
-------------

when System.Linq.Expressions.Expression.Block is available.

VarSet is also not convertible despite the existence of System.Linq.Expressions.Expression.Assign.

Ditto PropertySet, FieldSet, TryWith, TryFinally, ForIntegerRangeLoop, and WhileLoop.

The existing way of approaching this problem in F# is hand-building expressions without using quotations.

Are there expressions that are unconvertible from quotations to expressions instead of just not being implemented?

raise and reraise should be treated as special functions and be converted to special expressions just like conversion operators as well.

Pros and Cons

The advantages of making this adjustment to F# are

  1. Enabling more efficient reflection-based code
  2. Allowing more uses of quotations to compile code on-the-fly

The disadvantages of making this adjustment to F# are none?

Extra information

Estimated cost (XS, S, M, L, XL, XXL): S to M

Related suggestions: (put links to related suggestions here)

Affidavit (please submit!)

Please tick this by placing a cross in the box:

Please tick all that apply:

For Readers

If you would like to see this issue implemented, please click the :+1: emoji on this issue. These counts are used to generally order the suggestions by engagement.

dsyme commented 3 years ago

I'm ok with improving this in principle, but part of the problem is determining an appropriate additional level of completeness.

There's code in the F# test suites (tests\fsharp\tools\eval) completing most of these cases, even without using LINQ statement execution, but problems arise with "let rec" and some other constructs.

So I'll approve in principle but you should address this if you write an RFC

In the meantime there are other quotation evaluators around and they can be used