Expand description
§OxiLean Meta Layer — Metavar-Aware Operations & Tactics
The meta layer extends the kernel with metavariable support, providing all the infrastructure
for elaboration, unification, and interactive tactic proving. It mirrors LEAN 4’s Lean.Meta
namespace and sits logically between the elaborator and the trusted kernel.
§Quick Start
§Creating a Meta Context
use oxilean_meta::{MetaContext, MetaConfig};
use oxilean_kernel::Environment;
let env = Environment::new();
let config = MetaConfig::default();
let mut meta_ctx = MetaContext::new(&env, config);§Creating and Solving Metavariables
use oxilean_meta::MVarId;
let m1 = meta_ctx.mk_metavar(ty)?;
// ... unification happens ...
let solution = meta_ctx.get_assignment(m1)?;§Running a Tactic
use oxilean_meta::TacticState;
let mut state = TacticState::new(&meta_ctx, goal)?;
// ... execute tactics ...
let proof = state.close()?;§Architecture Overview
The meta layer is organized into three functional areas:
┌──────────────────────────────────────────────────────┐
│ Meta Layer (oxilean-meta) │
├────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────┐ ┌──────────────────┐ │
│ │ Core Meta Ops │ │ Advanced Features│ │
│ ├─────────────────┤ ├──────────────────┤ │
│ │- MetaContext │ │- Instance Synth │ │
│ │- MetaWhnf │ │- Discrimination │ │
│ │- MetaDefEq │ │ Trees │ │
│ │- MetaInferType │ │- App Builder │ │
│ │- Level DefEq │ │- Congr Theorems │ │
│ └─────────────────┘ └──────────────────┘ │
│ │
│ ┌──────────────────────────────────────┐ │
│ │ Tactic System │ │
│ ├──────────────────────────────────────┤ │
│ │- intro, apply, exact, rw, simp, ... │ │
│ │- Goal & TacticState management │ │
│ │- Calc proofs, Omega solver, etc. │ │
│ └──────────────────────────────────────┘ │
│ │
└──────────────────────────────────────────────────────────┘
│
│ uses (doesn't modify)
▼
┌──────────────────────────────────────────────────────┐
│ OxiLean Kernel (TCB) │
│ (Expression, Type Checking, WHNF, ...) │
└──────────────────────────────────────────────────────┘§Key Concepts & Terminology
§MetaContext vs MetaState
-
MetaContext: Global state during a proof session
- All metavariables and their assignments
- Configuration (recursion depth, timeouts, etc.)
- Doesn’t change during individual tactics
-
MetaState: Local goal-solving state
- Current goal and subgoals
- Local context (variables and hypotheses)
- Changes as tactics are applied
§Goal
A proof goal represented as:
x : Nat
h : P x
⊢ Q xComponents:
- Local context: Variables
x : Nat, hypothesesh : P x - Type (target): What to prove
Q x
Goals are solved when type is inhabited (proof term provided).
§Tactic
A tactic transforms goals:
Tactic: Goal → (Proof ∪ NewGoals ∪ Error)Examples:
intro: Transform⊢ P → Qtop : P ⊢ Qexact t: Ift : P, close goal⊢ Prw [eq]: Transform using equality
§Metavariable Assignment
Unification solves ?m =?= expr by assigning:
?m := exprSubsequent references to ?m automatically get the value.
§Discrimination Tree
Fast indexing structure for term-based lookup (e.g., for simp lemmas):
- Index by discriminator: First argument, head function, etc.
- Retrieve candidates in O(log n) instead of O(n)
§Instance Synthesis
Automated search for typeclass instances:
- Given
[C x], find value of typeC x - Uses tabled resolution (memoization)
- Prevents infinite loops
§Module Organization
§Batch 4.1: Core Meta Infrastructure
| Module | Purpose |
|---|---|
basic | MetaContext, MetaState, MVarId, metavariable creation |
whnf | Weak head normal form with metavar support |
def_eq | Definitional equality and unification |
infer_type | Type synthesis and checking (metavar-aware) |
level_def_eq | Universe level unification |
discr_tree | Discrimination tree indexing for fast lookup |
§Batch 4.2: Advanced Features
| Module | Purpose |
|---|---|
app_builder | Helpers for building common proof terms (eq, symm, etc.) |
congr_theorems | Automatic congruence lemma generation |
match_basic | Basic pattern matching representation |
match_dectree | Decision tree compilation for patterns |
match_exhaust | Exhaustiveness checking |
synth_instance | Typeclass instance synthesis |
§Batch 4.3: Core Tactics
| Module | Purpose |
|---|---|
tactic | Tactic engine and state management |
tactic::intro | intro (introduce binders) |
tactic::apply | apply (apply theorems) |
tactic::rewrite | rw (rewrite by equality) |
tactic::simp | simp (simplification with lemmas) |
tactic::omega | omega (linear arithmetic) |
tactic::calc | calc (calculational proofs) |
§Batch 4.4: Utilities
| Module | Purpose |
|---|---|
util | Utilities: collect_mvars, collect_fvars, FunInfo |
proof_replay | Proof term caching and memoization |
simp_engine | Simplification engine and simp lemma management |
§Meta Operations Pipeline
§Type Inference (Meta Version)
MetaInferType::infer_synth(expr)
│
├─ Recursively infer subexpressions
├─ Create metavars for unknown types
├─ Collect unification constraints
└─ Return: (expr_with_metavars, type)§Unification Pipeline
MetaDefEq::unify(goal_expr, expr)
│
├─ Reduce both to WHNF (with metavar support)
├─ Check if structurally equal
├─ If not, try:
│ ├─ Variable unification: ?m := expr
│ ├─ Application: f a =? g b
│ │ └─ Unify: f =? g, a =? b
│ ├─ Lambda: λ x. t =? λ y. u
│ │ └─ Unify: t[x/?a] =? u[y/?a] (fresh ?a)
│ └─ Higher-order cases
├─ Occurs check: Prevent ?m := f ?m
└─ Return: Success or failure§Tactic Execution
TacticState::execute(tactic)
│
├─ For each goal:
│ ├─ Apply tactic to goal
│ ├─ If success: Add new subgoals to queue
│ ├─ If exact: Mark goal closed
│ └─ If failure: Backtrack or error
│
├─ Recursively solve subgoals
│
└─ When all goals closed: Construct proof term§Usage Examples
§Example 1: Type Inference with Metavars
use oxilean_meta::MetaInferType;
let mut infer = MetaInferType::new(&meta_ctx);
let (expr_with_metas, ty) = infer.infer_synth(surface_expr)?;
// expr_with_metas may contain unsolved metavars§Example 2: Unification
use oxilean_meta::MetaDefEq;
let mut def_eq = MetaDefEq::new(&meta_ctx);
def_eq.unify(goal, candidate)?;
// If successful, metavars are assigned§Example 3: Tactic Execution
use oxilean_meta::TacticState;
let mut state = TacticState::new(&meta_ctx, initial_goal)?;
state.intro()?; // Run intro tactic
state.apply(theorem)?; // Run apply tactic
let proof = state.close()?; // Get proof term§Example 4: Instance Synthesis
use oxilean_meta::InstanceSynthesizer;
let synth = InstanceSynthesizer::new(&meta_ctx);
let instance = synth.synth_instance(class_type)?;
// Returns proof that satisfies typeclass constraint§Tactic Language
Common tactics:
- Proof construction:
intro,apply,exact,refine - Rewriting:
rw [h],simp,simp only - Analysis:
cases x,induction x on y,split - Automation:
omega(linear arith),decide(decidable) - Control:
;(then),<|>(or),repeat,try
§Integration with Other Crates
§With oxilean-kernel
- Uses kernel
Expr,Level,Environment - Reads kernel operations: WHNF, type checking
- Does not modify kernel (immutable reference)
- Proof terms eventually passed to kernel for validation
§With oxilean-elab
- Elaborator uses MetaContext for managing elaboration state
- MetaDefEq/MetaWhnf for type checking during elaboration
- Instance synthesis for implicit arguments
- Tactic execution during proof elaboration
§Performance Optimizations
- Memoization: Cache WHNF results for repeated reductions
- Discrimination trees: O(log n) lookup for simp lemmas
- Proof replay: Avoid re-executing identical tactics
- Lazy normalization: Only normalize when needed
- Constraint postponement: Defer hard constraints
§Further Reading
- ARCHITECTURE.md — System architecture
- Module documentation for specific subcomponents
Re-exports§
pub use basic::MVarId;pub use basic::MetaConfig;pub use basic::MetaContext;pub use basic::MetaState;pub use basic::MetavarDecl;pub use basic::MetavarKind;pub use basic::PostponedConstraint;pub use def_eq::MetaDefEq;pub use def_eq::UnificationResult;pub use discr_tree::DiscrTree;pub use discr_tree::DiscrTreeKey;pub use infer_type::MetaInferType;pub use level_def_eq::LevelDefEq;pub use whnf::MetaWhnf;pub use app_builder::mk_eq;pub use app_builder::mk_eq_refl;pub use app_builder::mk_eq_symm;pub use app_builder::mk_eq_trans;pub use congr_theorems::CongrArgKind;pub use congr_theorems::MetaCongrTheorem;pub use match_basic::MetaMatchArm;pub use match_basic::MetaMatchExpr;pub use match_basic::MetaPattern;pub use match_dectree::DecisionBranch;pub use match_dectree::DecisionTree;pub use match_dectree::MatchEquation;pub use match_exhaust::ConstructorSpec;pub use match_exhaust::ExhaustivenessResult;pub use synth_instance::InstanceEntry;pub use synth_instance::InstanceSynthesizer;pub use synth_instance::SynthResult;pub use tactic::rewrite::RewriteDirection;pub use tactic::GoalView;pub use tactic::TacticError;pub use tactic::TacticResult;pub use tactic::TacticState;pub use tactic::calc::CalcProof;pub use tactic::calc::CalcStep;pub use tactic::calc::ConvSide;pub use tactic::omega::LinearConstraint;pub use tactic::omega::LinearExpr;pub use tactic::omega::OmegaResult;pub use tactic::simp::discharge::DischargeStrategy;pub use tactic::simp::types::default_simp_lemmas;pub use tactic::simp::types::SimpConfig;pub use tactic::simp::types::SimpLemma;pub use tactic::simp::types::SimpResult;pub use tactic::simp::types::SimpTheorems;pub use util::collect_fvars;pub use util::collect_mvars;pub use util::FunInfo;
Modules§
- app_
builder - Auto-generated module structure
- ast_
cache - Auto-generated module structure
- basic
- Auto-generated module structure
- congr_
theorems - Auto-generated module structure
- convenience
- Auto-generated module structure
- def_eq
- Auto-generated module structure
- discr_
tree - Auto-generated module structure
- infer_
type - Auto-generated module structure
- level_
def_ eq - Auto-generated module structure
- match_
basic - Auto-generated module structure
- match_
dectree - Auto-generated module structure
- match_
exhaust - Auto-generated module structure
- meta_
debug - Auto-generated module structure
- proof_
replay - Auto-generated module structure
- prop_
test - Auto-generated module structure
- simp_
engine - Auto-generated module structure
- synth_
instance - Auto-generated module structure
- tactic
- Tactic framework for interactive proof construction.
- util
- Auto-generated module structure
- whnf
- Auto-generated module structure
Structs§
- LibAnalysis
Pass - An analysis pass for Lib.
- LibConfig
- A configuration store for Lib.
- LibDiagnostics
- A diagnostic reporter for Lib.
- LibDiff
- A diff for Lib analysis results.
- LibExt
Config1300 - LibExt
Diag1300 - LibExt
Diff1300 - LibExt
Pass1300 - LibExt
Pipeline1300 - LibPipeline
- A pipeline of Lib analysis passes.
- Meta
Cache - A simple cache for memoizing meta computations.
- Meta
Features - Feature flags for the meta layer.
- Meta
LibBuilder - A builder pattern for MetaLib.
- Meta
LibCounter Map - A counter map for MetaLib frequency analysis.
- Meta
LibExt Map - An extended map for MetaLib keys to values.
- Meta
LibExt Util - An extended utility type for MetaLib.
- Meta
LibState Machine - A state machine controller for MetaLib.
- Meta
LibWindow - A sliding window accumulator for MetaLib.
- Meta
LibWork Queue - A work queue for MetaLib items.
- Meta
Stats - Summary statistics about a
MetaContext. - Perf
Stats - Simple accumulator for meta-layer performance statistics.
- Proof
State Report - Report of proof state completeness.
- Scored
Candidate - A scored candidate.
- Tactic
Group - A named group of related tactics.
- Tactic
Registry - A named tactic registry.
Enums§
- LibConfig
Value - A typed slot for Lib configuration.
- LibExt
Config Val1300 - LibExt
Result1300 - LibResult
- A result type for Lib analysis.
- Meta
LibState - A state machine for MetaLib.
Constants§
- META_
VERSION - Version of the meta layer.
Functions§
- collect_
meta_ stats - Collect statistics from a
MetaContext. - default_
tactic_ registry - Build a default tactic registry.
- is_
automation_ tactic - Check if a tactic is an automation tactic.
- is_
core_ tactic - Check if a tactic name is a core tactic.
- meta_
version_ str - Return the meta layer version string.
- mk_
test_ ctx - Helper to create a minimal
MetaContextfor testing. - sort_
candidates - Sort candidates by descending score.
- standard_
tactic_ groups - Return the standard tactic groups.
- tactic_
description - Describe a tactic’s purpose.
- tactic_
group_ for - Find the group that a tactic belongs to.