Skip to content

Commit

Permalink
Merge pull request #803 from powdr-labs/remove_macros
Browse files Browse the repository at this point in the history
Remove macros.
  • Loading branch information
Leo authored Nov 28, 2023
2 parents 11bc9ed + 9946b86 commit 747b15b
Show file tree
Hide file tree
Showing 21 changed files with 18 additions and 487 deletions.
19 changes: 2 additions & 17 deletions analysis/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
#![deny(clippy::print_stdout)]

mod block_enforcer;
mod macro_expansion;
mod vm;

/// expose the macro expander for use in the pil_analyzer
pub use macro_expansion::MacroExpander;

use ast::{asm_analysis::AnalysisASMFile, parsed::asm::ASMProgram, DiffMonitor};
use number::FieldElement;

Expand All @@ -22,9 +18,6 @@ pub fn analyze<T: FieldElement>(
file: ASMProgram<T>,
monitor: &mut DiffMonitor,
) -> Result<AnalysisASMFile<T>, Vec<String>> {
// expand macros
log::debug!("Run expand analysis step");
let file = macro_expansion::expand(file);
// type check
log::debug!("Run type-check analysis step");
let file = type_check::check(file)?;
Expand Down Expand Up @@ -68,20 +61,12 @@ pub mod utils {

#[cfg(test)]
mod test_util {
use ast::{asm_analysis::AnalysisASMFile, parsed::asm::ASMProgram};
use ast::asm_analysis::AnalysisASMFile;
use number::FieldElement;
use parser::parse_asm;

use crate::macro_expansion;

/// A test utility to process a source file until after macro expansion
pub fn expand_str<T: FieldElement>(source: &str) -> ASMProgram<T> {
let file = parse_asm(None, source).unwrap();
macro_expansion::expand(file)
}

/// A test utility to process a source file until after type checking
pub fn typecheck_str<T: FieldElement>(source: &str) -> Result<AnalysisASMFile<T>, Vec<String>> {
type_check::check(expand_str(source))
type_check::check(parse_asm(None, source).unwrap())
}
}
211 changes: 0 additions & 211 deletions analysis/src/macro_expansion.rs

This file was deleted.

2 changes: 0 additions & 2 deletions asm_to_pil/src/vm_to_constrained.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,6 @@ impl<T: FieldElement> ASMPILConverter<T> {

let instruction = Instruction { inputs, outputs };

// First transform into PIL so that we can apply macro expansion.

let res = match s.instruction.body {
InstructionBody::Local(mut body) => {
// Substitute parameter references by the column names
Expand Down
13 changes: 0 additions & 13 deletions ast/src/parsed/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,19 +387,6 @@ impl<T: Display> Display for PilStatement<T> {
PilStatement::ConstantDefinition(_, name, value) => {
write!(f, "constant {name} = {value};")
}
PilStatement::MacroDefinition(_, name, params, statements, expression) => {
let statements = statements
.iter()
.map(|s| format!("{s}"))
.chain(expression.iter().map(|e| format!("{e}")))
.collect::<Vec<_>>();
let body = if statements.len() <= 1 {
format!(" {} ", statements.join(""))
} else {
format!("\n {}\n", statements.join("\n "))
};
write!(f, "macro {name}({}) {{{body}}};", params.join(", "))
}
PilStatement::Expression(_, e) => {
write!(f, "{e};")
}
Expand Down
7 changes: 0 additions & 7 deletions ast/src/parsed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,6 @@ pub enum PilStatement<T> {
),
ConnectIdentity(usize, Vec<Expression<T>>, Vec<Expression<T>>),
ConstantDefinition(usize, String, Expression<T>),
MacroDefinition(
usize,
String,
Vec<String>,
Vec<PilStatement<T>>,
Option<Expression<T>>,
),
Expression(usize, Expression<T>),
}

Expand Down
2 changes: 0 additions & 2 deletions ast/src/parsed/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ impl<T> ExpressionVisitable<Expression<T, NamespacedPolynomialReference>> for Pi
PilStatement::PolynomialCommitDeclaration(_, _, None)
| PilStatement::Include(_, _)
| PilStatement::PolynomialConstantDeclaration(_, _)
| PilStatement::MacroDefinition(_, _, _, _, _)
| PilStatement::LetStatement(_, _, None) => ControlFlow::Continue(()),
}
}
Expand Down Expand Up @@ -255,7 +254,6 @@ impl<T> ExpressionVisitable<Expression<T, NamespacedPolynomialReference>> for Pi
PilStatement::PolynomialCommitDeclaration(_, _, None)
| PilStatement::Include(_, _)
| PilStatement::PolynomialConstantDeclaration(_, _)
| PilStatement::MacroDefinition(_, _, _, _, _)
| PilStatement::LetStatement(_, _, None) => ControlFlow::Continue(()),
}
}
Expand Down
1 change: 0 additions & 1 deletion book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
- [Declarations](./pil/declarations.md)
- [Expressions](./pil/expressions.md)
- [Fixed Columns](./pil/fixed_columns.md)
- [Macros](./pil/macros.md)
- [Frontends](./frontends/README.md)
- [RISCV](./frontends/riscv.md)
- [Valida](./frontends/valida.md)
Expand Down
34 changes: 0 additions & 34 deletions book/src/pil/macros.md

This file was deleted.

8 changes: 0 additions & 8 deletions compiler/tests/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,3 @@ fn hello_world_asm_fail() {
let i = [1];
verify_asm::<GoldilocksField>(f, slice_to_vec(&i));
}

#[test]
fn test_macros_in_instructions() {
let f = "macros_in_instructions.asm";
verify_asm::<GoldilocksField>(f, Default::default());
gen_halo2_proof(f, Default::default());
gen_estark_proof(f, Default::default());
}
8 changes: 0 additions & 8 deletions compiler/tests/pil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,6 @@ fn test_constant_in_identity() {
gen_estark_proof(f, Default::default());
}

#[test]
fn test_fibonacci_macro() {
let f = "fib_macro.pil";
verify_pil(f, None);
gen_halo2_proof(f, Default::default());
gen_estark_proof(f, Default::default());
}

#[test]
fn fib_arrays() {
let f = "fib_arrays.pil";
Expand Down
Loading

0 comments on commit 747b15b

Please sign in to comment.