feat(all): F# quotations type improvements and Rust target#4774
feat(all): F# quotations type improvements and Rust target#4774Thorium wants to merge 2 commits into
Conversation
…runtimes Improves quotations in the shared emitter and adds quotation support to the Rust and PHP targets. Motivated by compiling F# query (<@ @>) expressions, e.g. toward a future TypeProviders (like SQLProvider) port to Python/Rust. Shared emitter (QuotationEmitter.fs) — benefits all targets: - typeToString: render all numeric kinds, char/regex/guid/datetime/ datetimeoffset/timespan, option/voption/list/array/seq/nullable, declared-type names, generics and delegates instead of "obj". - Call nodes record the declaring type; Get OptionValue/ListHead/ListTail map to property-getter calls. - DecisionTree inlined into IfThenElse/Let; Test nodes (union/option/list/ type) represented via union-tag comparison / getter calls. - mkNull constructor for null instances/values (no raw null literal, so statically typed languages compile); is_call maps it back to None. mk_call kept backward-compatible (3 and 4 params on Beam); mkNull added to each. Rust target (new): route Quote through the emitter (Fable2Rust), wire Replacements to tryQuotationCall, and add a transpiled F# runtime (QuotationTypes.fs + Quotation.fs) exposing FSharpExpr/FSharpVar at Microsoft.FSharp.Quotations and the quotation_ module. Construction + deconstruction verified via cargo; arithmetic evaluate works (let/lambda eval pending an upstream getZero fix for Rc<dyn Any>). Check the tests for more use-case examples.
MangelMaxime
left a comment
There was a problem hiding this comment.
Looking roughly at the diff, I see several issues.
Not all the changes are covered for example I see changes made for JavaScript but no tests added for that target.
Also, in general we try to keep the tests between target in sync and I don't think this is the case. For example, I see
let private lambdaVarName (e: Expr) =
match e with
| Lambda(v, _body) -> v.Name
| _ -> "?"
let private letVarName (e: Expr) =
match e with
| Let(v, _value, _body) -> v.Name
| _ -> "?"
let private isIfThenElseNode (e: Expr) =
match e with
| IfThenElse(_g, _t, _e) -> true
| _ -> falseIn tests/Rust/tests/src/QuotationTests.fs but unless I am mistaken I don't see that in other tests for example Python ones. So there is a variation here somewhere. Plus seems to have gained quotations support in this PRs but didn't get all the Python tests migrated.
|
Feedback addressed: Rust seems to be a bit rusty, so I think it needs a separate PR to fix some of its Todos in code, but the other test-suites should now be consistent across the targets. Edit: I have done Rust fixes to https://github.com/Thorium/Fable/tree/rust-todo-fixes but as I know you prefer small commits, it'll be a separate PR later. |
OverviewThree things bundled into one PR:
The direction is good — routing PHP/Rust through the shared emitter is exactly the "keep targets aligned" convention in AGENTS.md, and the F#-authored Rust runtime is a nice trick. But there are correctness gaps and a couple of things I don't think should ship as-is. Blocking / high-confidence issues
Rust Rust Rust PHP is entirely untested. There is no PHP test runner in
I'd either verify the PHP path by hand against generated output and say so in the PR, or split PHP out. Design concerns
DecisionTree inlining duplicates shared targets. Every Smaller notes
Test coverageStructural tests ( |
|
Thanks for the feedback. I'll address the issues and split these into multiple smaller features again.
|

Improves quotations in the shared emitter (with better type-info) and adds quotation support to the Rust and PHP targets. Motivated by compiling F# query (<@ @>) expressions, e.g. toward a future TypeProviders (like SQLProvider) port to Python/Rust.
Shared emitter (QuotationEmitter.fs) — benefits all targets:
mk_call kept backward-compatible (3 and 4 params on Beam); mkNull added to each.
Rust target (new): route Quote through the emitter (Fable2Rust), wire Replacements to tryQuotationCall, and add a transpiled F# runtime (QuotationTypes.fs + Quotation.fs) exposing FSharpExpr/FSharpVar at Microsoft.FSharp.Quotations and the quotation_ module. Construction + deconstruction verified via cargo; arithmetic evaluate works (let/lambda eval pending an upstream getZero fix for Rc).
Check the tests for more use-case examples.