Skip to content

Commit 09d67de

Browse files
authored
Add annotate_snippets for better parsing errors (#477)
Adds nicer errors for Podlang code, using the `annotate_snippets` crate, the same crate used by the Rust compiler to generate contextual errors. This prints a short snippet of the code containing the error within the error message, highlighting the part that needs to be fixed. It also includes a change to the `load_module` function, changing a `Vec` function argument to a slice.
1 parent acab26e commit 09d67de

File tree

11 files changed

+612
-40
lines changed

11 files changed

+612
-40
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ serde_arrays = "0.2.0"
4242
sha2 = { version = "0.10.9" }
4343
rand_chacha = "0.3.1"
4444
good_lp = { version = "1.8", default-features = false, features = ["microlp"] }
45+
annotate-snippets = "0.11"
4546

4647
# Uncomment for debugging with https://github.com/ed255/plonky2/ at branch `feat/debug`. The repo directory needs to be checked out next to the pod2 repo directory.
4748
# [patch."https://github.com/0xPARC/plonky2"]

examples/main_pod_points.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
8888
game_pk = game_pk,
8989
);
9090
println!("# custom predicate batch:{}", input);
91-
let module = load_module(&input, "points_module", &params, vec![])?;
91+
let module = load_module(&input, "points_module", &params, &[])?;
9292
let batch = module.batch.clone();
9393
let points_pred = batch.predicate_ref_by_name("points").unwrap();
9494
let over_9000_pred = batch.predicate_ref_by_name("over_9000").unwrap();

src/backends/plonky2/mainpod/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ pub mod tests {
11751175
"#,
11761176
"test",
11771177
&params,
1178-
vec![],
1178+
&[],
11791179
)
11801180
.unwrap();
11811181
let batch = module.batch.clone();

src/examples/custom.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn eth_dos_batch(params: &Params) -> Result<Arc<CustomPredicateBatch>> {
3030
eth_dos_ind(src, dst, distance)
3131
)
3232
"#;
33-
let module = load_module(input, "eth_dos", params, vec![]).expect("lang parse");
33+
let module = load_module(input, "eth_dos", params, &[]).expect("lang parse");
3434
let batch = module.batch.clone();
3535
println!("a.0. {}", batch.predicates()[0]);
3636
println!("a.1. {}", batch.predicates()[1]);

src/frontend/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,7 @@ pub mod tests {
13811381
Equal(b, 5)
13821382
)
13831383
"#;
1384-
let module = load_module(input, "test", &params, vec![]).unwrap();
1384+
let module = load_module(input, "test", &params, &[]).unwrap();
13851385
let batch = module.batch.clone();
13861386
let pred_test = batch.predicate_ref_by_name("Test").unwrap();
13871387

@@ -1430,7 +1430,7 @@ pub mod tests {
14301430
c(6, 3)
14311431
)
14321432
"#;
1433-
let module = load_module(input, "test", &params, vec![]).unwrap();
1433+
let module = load_module(input, "test", &params, &[]).unwrap();
14341434
let batch = module.batch.clone();
14351435
let pred_test = batch.predicate_ref_by_name("Test").unwrap();
14361436

@@ -1452,7 +1452,7 @@ pub mod tests {
14521452
c(6, 3)
14531453
)
14541454
"#;
1455-
let module = load_module(input, "test", &params, vec![]).unwrap();
1455+
let module = load_module(input, "test", &params, &[]).unwrap();
14561456
let batch = module.batch.clone();
14571457
let pred_test = batch.predicate_ref_by_name("Test").unwrap();
14581458

@@ -1491,7 +1491,7 @@ pub mod tests {
14911491
"#;
14921492

14931493
// Parse and batch the predicate (this handles splitting internally)
1494-
let module = load_module(input, "test", &params, vec![])?;
1494+
let module = load_module(input, "test", &params, &[])?;
14951495

14961496
// Verify it was split
14971497
assert!(module.split_chains.contains_key("large_pred"));

src/frontend/multi_pod/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ mod tests {
763763
"#,
764764
"test",
765765
&params,
766-
vec![],
766+
&[],
767767
)
768768
.expect("load module");
769769
let batch = &module.batch;
@@ -1492,7 +1492,7 @@ mod tests {
14921492
"#,
14931493
"test",
14941494
&params,
1495-
vec![],
1495+
&[],
14961496
)
14971497
.expect("load module");
14981498
let batch = &module.batch;
@@ -1621,7 +1621,7 @@ mod tests {
16211621
"#,
16221622
"test",
16231623
&params,
1624-
vec![],
1624+
&[],
16251625
)
16261626
.expect("load module");
16271627
let batch = &module.batch;

0 commit comments

Comments
 (0)