feat: Support package-level evaluation in RVM

オープン
#663 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
45/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
静か
技術スタック
rust
領域
compilers

調査の方向性

src/languages/rego/compiler/rules.rs の compile_from_policy と get_or_assign_rule_index() から始め、次にインタープリターの package-query の処理と比較してください。tests/rvm/rego/cases/default_rules.yaml のスキップされているケース、特に multiple_default_rules_different_names と default_rule_undefined_vs_default を確認してください。data.test がすべての package ルールを評価し、個々の rule-path の動作を維持したまま期待されるマージ済みオブジェクトを返せば完了です。

索引モデルが issue の本文から書いたものです。

説明

Summary

The RVM (Rego Virtual Machine) currently requires individual rule paths as entry points (e.g., data.test.allow). It does not support package-level queries (e.g., data.test) that evaluate all rules in a package and return a merged object of their results.

The interpreter supports this via eval_query("data.test"), but the RVM compiler rejects package paths with "not a valid rule path" since they don't map to any entry in rule_paths.

Motivation

Package-level evaluation is useful for:

  • Evaluating all rules in a package in a single call and receiving a merged result object
  • Parity with the interpreter's eval_query behavior
  • Supporting patterns where rules with defaults coexist (e.g., default allow := false + default deny := true) and the caller wants the full package state
Current Behavior
package test
default allow := false
default deny := true
allow := true if { false }
deny := false if { false }
Query Interpreter RVM
data.test.allow false ✓ false ✓
data.test.deny true ✓ true ✓
data.test {"allow": false, "deny": true} ✓ Error: "not a valid rule path"
Expected Behavior

data.test should return {"allow": false, "deny": true} — evaluating all rules in the test package and merging results into an object.

Technical Context

The RVM compiler resolves entry points in compile_from_policy via get_or_assign_rule_index(), which looks up the path in the rules map (keyed by full rule paths like data.test.allow). A package path like data.test has no entry there, so it fails.

The interpreter handles package queries differently — it evaluates all rules, then walks the data tree to extract the subtree at the requested path.

Why this is non-trivial in the RVM

The RVM compiles each entry point to a CALL_RULE + RETURN sequence that produces a single Value. Package-level evaluation would require:

  1. Discovering all rule paths under a package prefix — e.g., for data.test, find data.test.allow and data.test.deny
  2. Compiling all of them as entry points — the compiler already supports multiple entry points via execute_entry_point_by_index
  3. Merging results into an object — evaluating each rule and assembling {"allow": <result>, "deny": <result>}, handling Undefined (omit from result), nested packages, and partial objects/sets
Possible approaches

Option A — Compiler-level: synthetic package entry point

Add a new entry point type that emits CALL_RULE for each rule in the package, then OBJ_SET instructions to merge results into a single object. This keeps everything in the VM execution loop.

; Synthetic entry point for "data.test"
CALL_RULE  r1 ← rule_0 (allow)
CALL_RULE  r2 ← rule_1 (deny)
OBJ_NEW    r0
OBJ_SET    r0 "allow" r1   ; skip if r1 == Undefined
OBJ_SET    r0 "deny"  r2   ; skip if r2 == Undefined
RETURN     r0

Pros: single VM execution, fast. Cons: more compiler complexity, needs Undefined-skip semantics in OBJ_SET.

Option B — Host-side: iterate entry points and merge

Accept a package path at the API level, resolve it to individual rule paths, compile each as an entry point, execute them via execute_entry_point_by_index, and merge in the host code (Rust or bindings).

// Pseudocode
let rule_paths = compiled_policy.get_rule_paths_for_package("data.test");
let mut result = Value::new_object();
for path in rule_paths {
    let value = vm.execute_entry_point_by_name(&path)?;
    if value != Value::Undefined {
        let key = path.strip_prefix("data.test.").unwrap();
        result.insert(key, value);
    }
}

Pros: simpler, no compiler changes. Cons: multiple VM executions per package, nested packages need recursive handling.

Skipped Tests

The following test cases in tests/rvm/rego/cases/default_rules.yaml are blocked by this limitation:

  • multiple_default_rules_different_names — query data.test with default allow := false + default deny := true
  • default_rule_undefined_vs_default — query data.test with mix of defaulted and undefined rules
Impact

Medium — package-level queries are a common OPA pattern.

主要言語
Rust
スター
375
フォーク
81
平均マージ
1日 11時間
マージ済み PR(30日)
78

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートなし
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/regorus のほかの issue

microsoft/regorus の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。