Commit a3a20a1
authored
feat!: Rego -> RVM Compiler and extensive testsuite (microsoft#506)
# RVM compiler test cases
Coverage:
- arithmetic
- arrays
- chained lookups
- comparisons
- comprehensions
- default rules
- destructuring
- function rules
- loops/quantifiers
- multiple entrypoints
- objects/sets
- variables
- negative/edge scenarios such as data/rule conflicts
- virtual data lookups
- etc
# Modify interpreter and compiled policy for RVM Compilation
- Interpreter::eval_default_rule_for_compiler:
evaluates a named default rule in isolation - allows compiler to emit a constant value instead of instructions
for the default value
# feat: Rego Compiler Scaffolding
- Introduce the rego::compiler module surface and entry point wiring
- Add the core compiler concepts:
- register allocator
- scope tracking
- literal/builtin tables
- rule worklists
- instruction emit helpers
- compiler-specific error types
- context structs for rules, comprehensions, and loops to support later lowering passes.
# feat: Compile Rules/Queries
- add compiler::compile_from_policy workflow plus rule worklist, entry-point wiring, and recursion checks
- implement query lowering:
- scheduling-aware statement ordering
- loop hoisting
- “every/some” semantics
- context yields
- literal assertions
- finalize Program construction
# feat: Expression Lowering
- add compile_rego_expr and helpers to translate every AST expression into RVM instructions,
- interop with binding plans, comprehensions, and membership checks.
- implement collection literal builders (ArrayCreate, SetCreate, ObjectCreate)
- dedupe literal keys and handle mixed literal/dynamic fields via instruction data blocks.
- operations:
- arithmetic/boolean/bin operators
- membership
- unary minus
- set unions/intersections
- etc
- user-defined and builtin function calls
- reference handling
- analyse chained refs
- distinguishe data/input/local roots
- perform rule dispatch or virtual document lookups
- emits optimized Index/ChainedIndex instructions.
# feat: Comprehensions & Loops
- shared comprehension emitter
- wraps array/set/object comprehensions with ComprehensionBegin/End
- context management
- loop lowering utilities
- read hoisting metadata
- emit LoopStart/LoopNext
- some in lowering
- every quantifiers
- index iteration
- propagate binding plans into stored registers so downstream statements see bound variables.
# feat: Destructuring Lowering
- destructuring planner integration
- assignment/parameter/loop bindings use hoisted plans instead of re-walking ASTs.
- handle :=, =, wildcard matches, and equality
- evaluate RHS
- applying destructuring plans
- emit assert condition as needed
- support nested array/object destructuring, dynamic keys, and some ... in forms
# test: Shared Testing + RVM Suites
- move YAML test helpers into test_utils.rs and re-export via common.rs for use by interpreter and vm test suites
- comprehensive compiler test suite
- compiles policies with the new Rego→RVM compiler
- runs them through RegoVM
- compares against interpreter behavior
- supports multiple entry points
- provides assembly listings
- filterable YAML suites.
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>1 parent 688e612 commit a3a20a1
43 files changed
Lines changed: 6945 additions & 139 deletions
File tree
- src
- languages/rego
- compiler
- expressions
- rvm/tests
- tests
- interpreter
- tests
- rvm
- rego
- cases
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
36 | 51 | | |
37 | 52 | | |
38 | 53 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3371 | 3371 | | |
3372 | 3372 | | |
3373 | 3373 | | |
| 3374 | + | |
| 3375 | + | |
| 3376 | + | |
| 3377 | + | |
| 3378 | + | |
| 3379 | + | |
| 3380 | + | |
| 3381 | + | |
| 3382 | + | |
| 3383 | + | |
| 3384 | + | |
| 3385 | + | |
| 3386 | + | |
| 3387 | + | |
| 3388 | + | |
| 3389 | + | |
| 3390 | + | |
| 3391 | + | |
| 3392 | + | |
| 3393 | + | |
| 3394 | + | |
| 3395 | + | |
| 3396 | + | |
| 3397 | + | |
| 3398 | + | |
| 3399 | + | |
| 3400 | + | |
| 3401 | + | |
| 3402 | + | |
| 3403 | + | |
| 3404 | + | |
| 3405 | + | |
| 3406 | + | |
3374 | 3407 | | |
3375 | 3408 | | |
3376 | 3409 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
0 commit comments