BE-614: HashQL: Generate synthetic closure bodies for intrinsics used as first-class values#8895
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
PR SummaryMedium Risk Overview Reification: A new Supporting tweaks: Reviewed by Cursor Bugbot for commit 0694d8d. Bugbot is set up for automated code reviews on this repo. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 48906c1. Configure here.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## bm/be-615-hashql-introduce-synthetic-closures-and-trivial-closure #8895 +/- ##
====================================================================================================
+ Coverage 2.34% 3.62% +1.27%
====================================================================================================
Files 156 478 +322
Lines 3962 14463 +10501
Branches 918 3020 +2102
====================================================================================================
+ Hits 93 524 +431
- Misses 3868 13894 +10026
- Partials 1 45 +44
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merging this PR will degrade performance by 27.89%
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
4ad5098 to
74017c2
Compare
7a2aad8 to
686b850
Compare
686b850 to
538afac
Compare
74017c2 to
410fa1b
Compare
410fa1b to
ac8ed9e
Compare
538afac to
88472a7
Compare
| /// Constructs a `&'static [ConstantSymbol]` path from `::` separated segments. | ||
| /// | ||
| /// Each segment maps to the corresponding `sym::` constant. | ||
| /// | ||
| /// ```ignore | ||
| /// T![::core::math::add] // expands to &[sym::core, sym::math, sym::add] | ||
| /// T![::core::cmp::eq] // expands to &[sym::core, sym::cmp, sym::eq] | ||
| /// ``` |
88472a7 to
d3b03b8
Compare
ac8ed9e to
4aacfd8
Compare
4aacfd8 to
f2b45cb
Compare
d3b03b8 to
015b737
Compare
f2b45cb to
489dd1a
Compare
015b737 to
0694d8d
Compare


🌟 What is the purpose of this PR?
Allows intrinsics to be used in value position (passed as arguments, bound to variables) by generating synthetic MIR wrapper bodies during reification. Previously, intrinsics like
<=could only appear at call sites where specialization rewrites them. Now they can flow through higher-order functions:🔍 What does this change?
Synthetic body generation:
Syntheticsstruct inCrossCompileStatemanages creation and caching of wrapper bodiesSyntheticBuildergenerates MIR bodies with fat closure ABI (unit env as first parameter)T!macro for matching qualified paths againstConstantSymbolarrays:&T![::core::cmp::gt]in slice patterns,sym::path::core::cmp::gt::CONSTfor the namebinary!/unary!macros deriving path and name from the same segmentsThin-call specialization:
rvalue_call_thin_specializerecognizesCall(Thin, Qualified(intrinsic), [])(the administrative thunk-force from the thunking phase) and produces the closure aggregate directly, skipping thunk body generation() -> ClosureTypewrapper to extract the actual signatureIntrinsic classification:
gt,lt,gte,lte,eq,ne), boolean (and,or,not), arithmetic (add,sub), bitwise (and,or,not)!payload):mul,div,rem,mod,pow,xor,shl,shrsqrt,cbrt,rootgraph::head::entities,graph::body::filter,graph::tail::collectproduce a specific user-facing diagnosticDiagnostics:
intrinsic_not_first_class: user-facing error for graph intrinsics in value positionsynthetic_binary_arity_mismatch/synthetic_unary_arity_mismatch: ICE for monomorphized type invariant violationsPre-Merge Checklist 🚀
🚢 Has this modified a publishable library?
This PR:
📜 Does this require a change to the docs?
The changes in this PR:
🕸️ Does this require a change to the Turbo Graph?
The changes in this PR:
"<="as the entire program) is not supported. The thunking phase does not wrap the root body when it is a variable, so it never reaches the synthetic machinery. Tracked with arun: skiptest.🐾 Next steps
🛡 What tests cover this?
Compiletests (8 new):
reify/synthetic-intrinsic-value: basic synthetic body generation and thin-call specializationreify/synthetic-intrinsic-reused: same intrinsic used twice shares one body (caching)reify/synthetic-intrinsic-multiple: different intrinsics get separate bodiesreify/synthetic-graph-not-first-class: graph intrinsic in value position produces errorreify/synthetic-intrinsic-bare: bare intrinsic at root (run: skip)interpret/synthetic-intrinsic-value: end-to-end correctness (evaluates totrue)post_inline/synthetic-intrinsic-hof: full optimization cascade with constants (collapses toreturn true)post_inline/synthetic-intrinsic-hof-dynamic: HOF with dynamic inputs collapses to barex <= y❓ How to test this?
cargo run --package hashql-compiletest -- run --filter "test(synthetic)"📹 Demo
The
post_inline/synthetic-intrinsic-hof-dynamictest shows the full cascade. A higher-order function receiving<=as a value with dynamic inputs:All indirection eliminated. Indistinguishable from writing
["<=", x, y]directly.