Skip to content

Commit

Permalink
Update cycle error message
Browse files Browse the repository at this point in the history
  • Loading branch information
imaqtkatt committed Mar 12, 2024
1 parent 16b5743 commit 4645b32
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 2 deletions.
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"interner",
"itertools",
"lcons",
"linearization",
"linearizes",
"linearizing",
"lnet",
Expand Down
2 changes: 1 addition & 1 deletion docs/lazy-definitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ This code will work as expected, because `Nat.add` is unrolled lazily only when

### Automatic optimization

HVM-lang carries out [match linearization](compiler-options#linearize-matches) and [combinator floating](compiler-options#float-combinators) optimizations, enabled through the CLI, which is active by default in strict mode.
HVM-lang carries out [match linearization](compiler-options#linearize-matches) and [combinator floating](compiler-options#float-combinators) optimizations, enabled through the CLI, which are active by default in strict mode.

Consider the code below:

Expand Down
12 changes: 11 additions & 1 deletion src/hvmc_net/mutual_recursion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ pub fn check_cycles(book: &Book) -> Result<(), String> {
let graph = Graph::from(book);
let cycles = graph.cycles();

if cycles.is_empty() { Ok(()) } else { Err(pretty_print_cycles(&cycles)) }
if cycles.is_empty() {
Ok(())
} else {
Err(format!(
"{}\n{}\n{}\n{}",
"Mutual recursion cycle detected in compiled funcions:",

Check warning on line 21 in src/hvmc_net/mutual_recursion.rs

View workflow job for this annotation

GitHub Actions / cspell

Unknown word (funcions)
pretty_print_cycles(&cycles),
"This program will expand infinitely in strict evaluation mode.",
"Read https://github.com/HigherOrderCO/hvm-lang/blob/main/docs/lazy-definitions.md for more information."
))
}
}

fn pretty_print_cycles(cycles: &[Vec<Ref>]) -> String {
Expand Down
11 changes: 11 additions & 0 deletions tests/golden_tests/mutual_recursion/multiple.hvm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(A) = (B)
(B) = (C)
(C) = (A)

(H) = (I)
(I) = (H)

(M) = (N)
(N) = (M)

(Main) = *
3 changes: 3 additions & 0 deletions tests/snapshots/mutual_recursion__a_b_c.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/mutual_recursion/a_b_c.hvm
---
Mutual recursion cycle detected in compiled funcions:
Cycle 1: A -> B -> C
This program will expand infinitely in strict evaluation mode.
Read https://github.com/HigherOrderCO/hvm-lang/blob/main/docs/lazy-definitions.md for more information.
10 changes: 10 additions & 0 deletions tests/snapshots/mutual_recursion__multiple.hvm.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
source: tests/golden_tests.rs
input_file: tests/golden_tests/mutual_recursion/multiple.hvm
---
Mutual recursion cycle detected in compiled funcions:
Cycle 1: A -> B -> C
Cycle 2: H -> I
Cycle 3: M -> N
This program will expand infinitely in strict evaluation mode.
Read https://github.com/HigherOrderCO/hvm-lang/blob/main/docs/lazy-definitions.md for more information.
3 changes: 3 additions & 0 deletions tests/snapshots/mutual_recursion__odd_even.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/mutual_recursion/odd_even.hvm
---
Mutual recursion cycle detected in compiled funcions:
Cycle 1: isEven -> isOdd
This program will expand infinitely in strict evaluation mode.
Read https://github.com/HigherOrderCO/hvm-lang/blob/main/docs/lazy-definitions.md for more information.

0 comments on commit 4645b32

Please sign in to comment.