Update cycle error message

This commit is contained in:
imaqtkatt 2024-03-12 12:41:08 -03:00
parent 16b5743d77
commit 4645b3231b
7 changed files with 40 additions and 2 deletions

View File

@ -36,6 +36,7 @@
"interner",
"itertools",
"lcons",
"linearization",
"linearizes",
"linearizing",
"lnet",

View File

@ -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:

View File

@ -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:",
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 {

View File

@ -0,0 +1,11 @@
(A) = (B)
(B) = (C)
(C) = (A)
(H) = (I)
(I) = (H)
(M) = (N)
(N) = (M)
(Main) = *

View File

@ -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.

View File

@ -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.

View File

@ -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.