Skip to content

Commit 49bd3c2

Browse files
authored
feat!: add Rego Virtual Machine (RVM) implementation (#495)
* feat!: add Rego Virtual Machine (RVM) implementation This commit introduces a register-based virtual machine for executing Rego policies with bytecode-style instructions. Unlike the existing tree-walking interpreter, the RVM compiles policies into instruction sequences that operate on virtual registers, offering better performance and optimization potential. Core Components: Instruction Set Architecture: - Define instruction types for data operations, control flow, and builtins - Implement instruction parameter encoding and display formatting - Add instruction parser with comprehensive test coverage Virtual Machine Engine: - Register-based execution model with program counter management - Loop execution supporting iterators, comprehensions, and quantifiers - Function call handling with argument evaluation and context management - Rule evaluation with default value resolution and virtual data support - Arithmetic and comparison operation implementations Program Representation: - Program listing builder with instruction sequencing - Rule tree construction for organizing policy rules - Binary and JSON serialization for compiled programs - Recompilation support for program modification Testing Infrastructure: - Extensive YAML test suites covering all VM features - Rust unit tests for VM execution and instruction parsing - Test suites for loops, comprehensions, builtins, and control flow BREAKING CHANGE: Introduces new VM execution path alongside interpreter Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com> * docs: add detailed RVM architecture references Introduce architecture.md explaining program artifacts, serialization, and runtime subsystems. Document the full opcode catalog in instruction-set.md, including operands, parameter tables, and outcomes. Walk through execution flow, stacks, and operational guidance in vm-runtime.md, tying the runtime to the new architecture docs. Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com> --------- Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
1 parent 6dc505c commit 49bd3c2

File tree

89 files changed

+19158
-313
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+19158
-313
lines changed

Cargo.lock

Lines changed: 64 additions & 64 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ keywords = ["interpreter", "no_std", "opa", "policy-as-code", "rego"]
2020
doctest = false
2121

2222
[features]
23-
default = ["full-opa", "arc"]
23+
default = ["full-opa", "arc", "rvm"]
2424

2525
arc = ["scientific/arc"]
2626
ast = []
@@ -38,6 +38,7 @@ net = ["dep:ipnet"]
3838
no_std = ["lazy_static/spin_no_std"]
3939
opa-runtime = []
4040
regex = ["dep:regex"]
41+
rvm = ["dep:bincode", "dep:indexmap"]
4142
semver = ["dep:semver"]
4243
std = ["rand/std", "rand/std_rng", "serde_json/std", "msvc_spectre_libs" ]
4344
time = ["dep:chrono", "dep:chrono-tz"]
@@ -99,7 +100,7 @@ lazy_static = { version = "1.4.0", default-features = false }
99100
thiserror = { version = "2.0", default-features = false }
100101

101102
data-encoding = { version = "2.8.0", optional = true, default-features=false, features = ["alloc"] }
102-
scientific = { version = "0.5.3" }
103+
scientific = { version = "0.5.3", default-features = false }
103104

104105
globset = { version = "0.4.16", features = ["simd-accel"], default-features = false, optional = true }
105106
regex = {version = "1.11.1", optional = true, default-features = false }
@@ -120,6 +121,10 @@ msvc_spectre_libs = { version = "0.1", features = ["error"], optional = true }
120121
dashmap = { version = "6.1", default-features = false, optional = true }
121122
mimalloc = { path = "mimalloc", optional = true }
122123

124+
# rvm related deps
125+
indexmap = { version = "2.12.0", default-features = false, features = ["serde"], optional = true }
126+
bincode = { version = "2.0.1", default-features = false, features = ["alloc", "serde"], optional = true }
127+
123128
[dev-dependencies]
124129
anyhow = "1.0.45"
125130
cfg-if = "1.0.0"

0 commit comments

Comments
 (0)