Add primitive command support#46
Conversation
d29f02c to
24a1e85
Compare
24a1e85 to
dda35a0
Compare
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
📝 WalkthroughWalkthroughThis PR adds user-defined primitive registration to egglog via a new ChangesBody-defined primitives feature
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@Cargo.toml`:
- Around line 20-22: The Cargo.toml git dependencies for egglog, egglog-ast, and
egglog-reports should be pinned to the resolved commit to ensure reproducible
builds: replace branch = "codex/split-primitive-body-runtime-apis" with rev =
"cf4fe23e104c263e07b771f4a314cf0dac8be1c8" for the egglog, egglog-ast, and
egglog-reports entries and remove the branch key so the three dependencies
reference the exact commit instead of a moving branch.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 417e4089-4256-4049-8007-2bd808ed0124
⛔ Files ignored due to path filters (17)
Cargo.lockis excluded by!**/*.locktests/fail-typecheck/primitive-bad-positional-var.eggis excluded by!**/*.eggtests/fail-typecheck/primitive-direct-function-body-in-rule.eggis excluded by!**/*.eggtests/fail-typecheck/primitive-hidden-table-dependency.eggis excluded by!**/*.eggtests/fail-typecheck/primitive-malformed-input-sorts.eggis excluded by!**/*.eggtests/fail-typecheck/primitive-missing-unstable-fn-target.eggis excluded by!**/*.eggtests/fail-typecheck/primitive-output-context-eqsort-mismatch.eggis excluded by!**/*.eggtests/fail-typecheck/primitive-output-context-mismatch.eggis excluded by!**/*.eggtests/fail-typecheck/primitive-read-body-in-seminaive-rule.eggis excluded by!**/*.eggtests/fail-typecheck/primitive-unresolved-body-symbol.eggis excluded by!**/*.eggtests/primitive-constructor-body.eggis excluded by!**/*.eggtests/primitive-function-container.eggis excluded by!**/*.eggtests/primitive-map-empty-output-context.eggis excluded by!**/*.eggtests/primitive-overload-output-context.eggis excluded by!**/*.eggtests/primitive-read-body.eggis excluded by!**/*.eggtests/primitive-table-backed-body.eggis excluded by!**/*.eggtests/primitive.eggis excluded by!**/*.egg
📒 Files selected for processing (4)
Cargo.tomlsrc/lib.rssrc/primitive.rssrc/sugar/for.rs
📜 Review details
🔇 Additional comments (3)
src/lib.rs (1)
19-25: LGTM!Also applies to: 47-47, 83-85
src/primitive.rs (1)
12-290: LGTM!src/sugar/for.rs (1)
39-47: LGTM!
…dy-primitive # Conflicts: # Cargo.lock # Cargo.toml # src/lib.rs # src/scheduling.rs # src/set_cost.rs
Context
Adds the experimental
(primitive name (InputSort*) OutputSort body)command for defining primitives from egglog expressions.Depends on: egraphs-good/egglog#881, currently pinned in
Cargo.lockto egglog commita80b23515d172d95cfbf84d9b90ee154e03a9e7doncodex/split-primitive-body-runtime-apis.This PR intentionally does not include the unrelated core-relations ordering fix from egraphs-good/egglog#899. That bug is already present in the current egglog-experimental
maindependency:mainpins an egglog commit descended from egglog PR #862, whose cleanup commit changed multi-column column-index rebuild ordering. The issue only trips adebug_assert!in debug builds; egglog-experimental CI currently runsmake test, which uses release-mode nextest/doc tests, somath_backoffstill passes in CI. PR #899 isolates that fix on egglogmainwith its own regression test.Current shape
primitiveuser-defined command innew_experimental_egraph.Pure,Read,Write, orFull) and registers the primitive in the matching runtime context.Core::eval_resolved_exprrather than duplicating expression evaluation locally.EGraph::prepare_unstable_fn_targets_for_evalbefore registration so direct literal(unstable-fn "...")targets work in primitive bodies using the same hiddenResolvedFunctionvalue as backend rule lowering.unstable-fntargets during capability inference, so custom-function targets require read-capable contexts, constructor targets require write-capable contexts, and primitive targets use the minimum compatible primitive runtime context.:naive.unstable-fntargets, missing direct targets, function-container bodies, table-backed function bodies, and constructor bodies.Ruleinitializer for egglogno_decompand adapts user-defined commands to egglog's currentVec<CommandOutput>return shape.Tried and decided against
PreparedResolvedExpr/ core-action preparation API. Replaced it with the narrower core helper plus directCore::eval_resolved_expr, which keeps the experimental command simpler and avoids exposing a general prepared-action abstraction.unstable-fntargets live in atom terms. Those were parked as larger cleanup directions and are not needed for this PR.math_backoffdebug assertion fix; that remains isolated in egglog PR #899.Validation
a80b23515d172d95cfbf84d9b90ee154e03a9e7d:cargo fmtcargo test --test files -- primitive --nocapturecargo checkgit diff --checkcargo check --locked --libcargo test --locked --lib --quietcargo test --locked --test files -- primitivecargo test --test files -- primitive_function_containerpassed.cargo test --test files --quietreported 34 passing file tests and the known unrelatedmath_backoffsorted-slice debug assertion.Known unrelated debug-only failure:
cargo test -q math_backoff --test files -- --exactfails with the core-relations sorted-slice debug assertion tracked by Fix multi-column column index rebuild ordering egglog#899. The same exact debug test fails from current egglog-experimentalmain; releasemake testpasses.