mangle_analysis/lib.rs
1// Copyright 2024 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Analysis and Transformation Pipeline for Mangle.
16//!
17//! This crate provides the core analysis passes and transformations that turn
18//! a parsed Mangle AST into an executable plan.
19//!
20//! # Transformation Stages
21//!
22//! 1. **Program Structure**: The raw AST is wrapped in a [`Program`] abstraction
23//! which distinguishes between extensional (data) and intensional (rules) predicates.
24//!
25//! 2. **Stratification**: The program is analyzed for dependencies and stratified
26//! to handle negation correctly. This produces a [`StratifiedProgram`], where
27//! predicates are grouped into layers (strata) that can be evaluated sequentially.
28//!
29//! 3. **Lowering**: The AST (or stratified program parts) is lowered into the
30//! Intermediate Representation (IR). See [`LoweringContext`].
31//!
32//! 4. **Type Checking**: The IR is checked for type consistency and safety.
33//! See [`BoundsChecker`].
34//!
35//! 5. **Planning**: The Logical IR rules are transformed into Physical Operations
36//! (like nested-loop joins) ready for execution or codegen.
37//! See [`Planner`].
38
39use mangle_ast as ast;
40
41mod type_check;
42pub use type_check::TypeChecker;
43
44pub mod type_expr;
45pub mod name_trie;
46
47mod bounds_check;
48pub use bounds_check::BoundsChecker;
49
50#[cfg(test)]
51mod tests;
52
53mod lowering;
54
55pub use lowering::LoweringContext;
56
57mod rename;
58
59pub use rename::rewrite_unit;
60
61mod planner;
62
63pub use planner::Planner;
64
65mod stratification;
66
67pub use stratification::{Program, StratifiedProgram};
68
69/// A set of predicate symbols, typically used to represent a stratum or a
70/// collection of EDB/IDB predicates.
71pub type PredicateSet = fxhash::FxHashSet<ast::PredicateIndex>;