Skip to content

Refine active-rule deferral path matching; expand interpreter docs with concrete examples#745

Draft
Copilot wants to merge 5 commits into
mainfrom
copilot/fix-cyclic-references-behaviour
Draft

Refine active-rule deferral path matching; expand interpreter docs with concrete examples#745
Copilot wants to merge 5 commits into
mainfrom
copilot/fix-cyclic-references-behaviour

Conversation

Copilot AI commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

This updates the data lookup deferral path in the interpreter to be clearer and more efficient. It adds thorough inline documentation and examples while tightening path matching to avoid unnecessary allocation in hot evaluation flow.

  • Deferral matching logic

    • Replaced joined-string matching (module_path + "." + rule_path) with segment-aware prefix checks.
    • Added request_matches_active_rule_path(requested_path, module_path, rule_path) to express matching semantics directly.
  • Performance/idiomatic Rust

    • Removed per-iteration format! allocation inside active-rule evaluation checks.
    • Uses strip_prefix + boundary-aware helper logic for allocation-light path comparisons.
  • Comments and examples

    • Expanded helper docs with explicit true/false examples for segment-boundary prefix behavior.
    • Clarified dynamic lookup semantics (data.a.b and data.a.b. descendants) and recursion wording for cross-package/sibling re-entry.
// Before (allocates each iteration)
let full_rule_path = format!("{}.{}", module_path, rule_path);
if Self::path_is_prefix(requested_path, &full_rule_path) { ... }

// After (allocation-free matching)
if Self::request_matches_active_rule_path(requested_path, &module_path, &rule_path) { ... }

Copilot AI changed the title [WIP] Fix behaviour differing from OPA on cyclic references Handle cross-package cyclic references without over-eager recursion in interpreter/RVM Jun 9, 2026
Copilot AI requested a review from anakrish June 9, 2026 17:22
Copilot AI changed the title Handle cross-package cyclic references without over-eager recursion in interpreter/RVM Resolve cross-package data import recursion misclassification in interpreter and RVM Jun 9, 2026
// No rule found; fall back to module-level imports.
let import_key = format!("{}.{}", &self.current_package, root);
if let Some(import_expr) = self.policy.inner.imports.get(&import_key) {
if let Ok(mut import_chain) = parse_reference_chain(import_expr) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document this nicely. Not clear what is going on.

Comment thread src/interpreter.rs

/// Ensures all rule/default-rule paths matching a dynamic data lookup are evaluated.
/// Matches both exact path (`data.a.b`) and descendants (`data.a.b.*`).
fn ensure_matching_rules_for_dynamic_data_index(&mut self, path: &str) -> Result<()> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this called in the hot path?

Copilot AI changed the title Resolve cross-package data import recursion misclassification in interpreter and RVM Refine active-rule deferral path matching; expand interpreter docs with concrete examples Jun 9, 2026
Copilot AI requested a review from anakrish June 9, 2026 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Behaviour differing from OPA on cyclic references between multiple policies

2 participants