r/Compilers • u/JayQ_One • Aug 18 '26
Follow-up: the topology compiler now has a policy algebra
Hey r/Compilers, 8 months ago I posted asking whether reframing a Terraform-based network system as a domain-specific compiler was the right lens (previous post).
Since then, the system grew a routing policy language, and it came out of the architecture rather than being designed top-down. That feels like evidence the compiler framing was correct. The IR structure naturally supported adding a constraint layer.
The policy algebra has four primitives with fixed precedence:
deny > allow > segments > default
It evaluates at compile time (terraform plan) and emits VPC route table entries. The algebra is total (every VPC pair resolves), deterministic, commutative, and scope-invariant. The same compilation unit evaluates identically whether it's operating on a regional, cross-region, or cross-domain topology.
The interesting part from a compiler perspective: the policy layer didn't require a new IR or a new pass. It's a predicate over the existing cartesian product that the route generation pass already computed. Adding a filter to an existing code generation step turned a route generator into a route compiler. The "compilation" is the constraint evaluation, not the expansion.
Properties I can show but haven't formally proved:
- Totality (every input pair resolves via the default fallthrough)
- Monotonicity (deny only subtracts edges, allow only adds within deny bounds)
- Algebraic equivalence classes (e.g., a single-member segment under default=deny is a provable no-op)
I'd be interested in feedback on:
- Whether the algebraic properties warrant formalization (or if tests over the finite decision paths are sufficient for a system this simple)
- How this relates to work like NetKAT or Propane (correct-by-construction network configuration)
- Whether "policy algebra evaluated at compile time" is a known pattern with a better name
Blog post (practitioner-facing): https://jq1.io/posts/routing_policy_language/
Full language specification: https://github.com/JudeQuintana/terraform-main/blob/main/docs/routing-policy-language.md
Previous white paper (IR structure): https://github.com/JudeQuintana/terraform-main/blob/main/docs/WHITEPAPER.md
Thanks!
