How google/mangle works
Mangle is an embeddable Go implementation of an extended Datalog language. The main workflow is to parse source into rules and declarations, validate and analyze the program, then evaluate it against facts and expose query results. The engine supports recursive bottom-up evaluation, while temporal evaluation and interval-backed facts serve temporal rules. Built-in functions and aggregation extend rule execution; the library also offers interactive use, package structuring, and provenance explanations. Edges reflect README statements or source-index references; unsampled implementation details are not assumed.
Main entry points: parse.go Source parser · ast.go Rules and declarations · seminaivebottomup.go Semi-naive engine · functional.go Functions and reducers
Components 19
Language and analysis
- Source parser
parse/parse.go - Rules and declarations
ast/ast.go - Package resolution
packages/packages.go - Program validation
analysis/validation.go - Rule analysis
analysis/rulecheck.go - Bound inference
analysis/boundscheck.go - Types and symbols
symbols/symbols.go
Evaluation runtime
- Semi-naive engine
engine/seminaivebottomup.go - Temporal engine
engine/temporal.go - Functions and reducers
functional/functional.go - Built-in predicates
builtin/builtin.go
Facts and extensions
- Fact store
factstore/factstore.go - Simplecolumn storage
factstore/simplecolumn.go - Temporal fact store
factstore/temporal.go - Proof explanations
provenance/provenance.go - Structured data adapters
json2struct/json2struct.go
User interfaces
- Interpreter
interpreter/interpreter.go - Explanation command
cmd/mgwhy/main.go
Other components
- Program author
Connections 25
- Program author → Source parser: writes source
README.md - Source parser → Rules and declarations: creates syntax
parse/parse.go - Program validation → Source parser: parses input
analysis/validation.go - Program validation → Package resolution: uses packages
analysis/validation.go - Program validation → Types and symbols: checks symbols
analysis/validation.go - Rule analysis → Rules and declarations: checks rules
analysis/rulecheck.go - Rule analysis → Types and symbols: uses types
analysis/rulecheck.go - Bound inference → Types and symbols: infers bounds
analysis/boundscheck.go - Interpreter → Source parser: parses programs
interpreter/interpreter.go - Interpreter → Semi-naive engine: evaluates rules
interpreter/interpreter.go - Interpreter → Fact store: manages facts
interpreter/interpreter.go - Semi-naive engine → Fact store: reads and writes
engine/seminaivebottomup.go - Semi-naive engine → Functions and reducers: evaluates functions
engine/seminaivebottomup.go - Semi-naive engine → Rules and declarations: evaluates clauses
engine/seminaivebottomup.go - Built-in predicates → Functions and reducers: evaluates calls
builtin/builtin.go - Temporal engine → Temporal fact store: stores intervals
engine/temporal.go - Temporal engine → Functions and reducers: uses functions
engine/temporal.go - Simplecolumn storage → Rules and declarations: serializes facts
factstore/simplecolumn.go - Explanation command → Source parser: loads program
cmd/mgwhy/main.go - Explanation command → Fact store: loads facts
cmd/mgwhy/main.go - Explanation command → Proof explanations: requests proofs
cmd/mgwhy/main.go - Proof explanations → Fact store: checks facts
provenance/provenance.go - Structured data adapters → Rules and declarations: converts structures
json2struct/json2struct.go - Program author → Temporal engine: defines temporal rules
README.md - Program author → Functions and reducers: uses aggregation
README.md