Skip to content

Commit

Permalink
Update mutual recursion error message
Browse files Browse the repository at this point in the history
  • Loading branch information
imaqtkatt committed Mar 21, 2024
1 parent a010f4f commit e90644d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
8 changes: 6 additions & 2 deletions src/hvmc_net/mutual_recursion.message
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ Seems like you're trying to run some recursive function(s) on strict-mode:
{refs}

Due to the ultra-greedy nature of strict-mode, that might result in infinite loops.
If the float-combinators optimization is not on, we recommend activating it.

You have 2 options:

1. Easy Fix: use lazy-mode.

Just append the `-L` option to `HVM-Lang`, and it will run in lazy-mode. It has the advantage of not doing wasteful work, having an improved complexity class, and being compatible with unrestricted recursion! It has a small overhead though, and isn't compatible with GPU.

2. Hard Fix: use combinators.
2. Hard Fix: refactor the program to use lazy references.

By converting your program to use combinators, you can avoid the direct recursive calls that result in loops. If you use the built-in `data` and `match` syntaxes, HVM-Lang usually does this for you, but it couldn't handle your program. See here for more info: https://github.com/HigherOrderCO/hvm-lang/blob/main/docs/lazy-definitions.md.
When a function reference is in head position of an application or is duplicated by the non-linear use of a `let` expression it will be greedly expanded, leading to an infinite loop.
If the application is used written as a combinator, it will automatically lifted to a lazy reference, which usually breaks the recursion cycle. Alternatively, by using the built-in `data` and `match` syntax, hvm-lang will try to do this automatically.
For let expressions where the variable is non-linear (used more than once), you can instead employ `use` expressions to statically duplicate the offending recursive term.
See here for more info: https://github.com/HigherOrderCO/hvm-lang/blob/main/docs/lazy-definitions.md.
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@ long_name_that_truncates
long_name_that_truncates$C0

Due to the ultra-greedy nature of strict-mode, that might result in infinite loops.
If the float-combinators optimization is not on, we recommend activating it.

You have 2 options:

1. Easy Fix: use lazy-mode.

Just append the `-L` option to `HVM-Lang`, and it will run in lazy-mode. It has the advantage of not doing wasteful work, having an improved complexity class, and being compatible with unrestricted recursion! It has a small overhead though, and isn't compatible with GPU.

2. Hard Fix: use combinators.
2. Hard Fix: refactor the program to use lazy references.

By converting your program to use combinators, you can avoid the direct recursive calls that result in loops. If you use the built-in `data` and `match` syntaxes, HVM-Lang usually does this for you, but it couldn't handle your program. See here for more info: https://github.com/HigherOrderCO/hvm-lang/blob/main/docs/lazy-definitions.md.
When a function reference is in head position of an application or is duplicated by the non-linear use of a `let` expression it will be greedly expanded, leading to an infinite loop.
If the application is used written as a combinator, it will automatically lifted to a lazy reference, which usually breaks the recursion cycle. Alternatively, by using the built-in `data` and `match` syntax, hvm-lang will try to do this automatically.
For let expressions where the variable is non-linear (used more than once), you can instead employ `use` expressions to statically duplicate the offending recursive term.
See here for more info: https://github.com/HigherOrderCO/hvm-lang/blob/main/docs/lazy-definitions.md.


@long_name_that_truncates = (* @long_name_that_truncates$C0)
Expand Down
8 changes: 6 additions & 2 deletions tests/snapshots/mutual_recursion__a_b_c.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ B
C

Due to the ultra-greedy nature of strict-mode, that might result in infinite loops.
If the float-combinators optimization is not on, we recommend activating it.

You have 2 options:

1. Easy Fix: use lazy-mode.

Just append the `-L` option to `HVM-Lang`, and it will run in lazy-mode. It has the advantage of not doing wasteful work, having an improved complexity class, and being compatible with unrestricted recursion! It has a small overhead though, and isn't compatible with GPU.

2. Hard Fix: use combinators.
2. Hard Fix: refactor the program to use lazy references.

By converting your program to use combinators, you can avoid the direct recursive calls that result in loops. If you use the built-in `data` and `match` syntaxes, HVM-Lang usually does this for you, but it couldn't handle your program. See here for more info: https://github.com/HigherOrderCO/hvm-lang/blob/main/docs/lazy-definitions.md.
When a function reference is in head position of an application or is duplicated by the non-linear use of a `let` expression it will be greedly expanded, leading to an infinite loop.
If the application is used written as a combinator, it will automatically lifted to a lazy reference, which usually breaks the recursion cycle. Alternatively, by using the built-in `data` and `match` syntax, hvm-lang will try to do this automatically.
For let expressions where the variable is non-linear (used more than once), you can instead employ `use` expressions to statically duplicate the offending recursive term.
See here for more info: https://github.com/HigherOrderCO/hvm-lang/blob/main/docs/lazy-definitions.md.
8 changes: 6 additions & 2 deletions tests/snapshots/mutual_recursion__multiple.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ I
...

Due to the ultra-greedy nature of strict-mode, that might result in infinite loops.
If the float-combinators optimization is not on, we recommend activating it.

You have 2 options:

1. Easy Fix: use lazy-mode.

Just append the `-L` option to `HVM-Lang`, and it will run in lazy-mode. It has the advantage of not doing wasteful work, having an improved complexity class, and being compatible with unrestricted recursion! It has a small overhead though, and isn't compatible with GPU.

2. Hard Fix: use combinators.
2. Hard Fix: refactor the program to use lazy references.

By converting your program to use combinators, you can avoid the direct recursive calls that result in loops. If you use the built-in `data` and `match` syntaxes, HVM-Lang usually does this for you, but it couldn't handle your program. See here for more info: https://github.com/HigherOrderCO/hvm-lang/blob/main/docs/lazy-definitions.md.
When a function reference is in head position of an application or is duplicated by the non-linear use of a `let` expression it will be greedly expanded, leading to an infinite loop.
If the application is used written as a combinator, it will automatically lifted to a lazy reference, which usually breaks the recursion cycle. Alternatively, by using the built-in `data` and `match` syntax, hvm-lang will try to do this automatically.
For let expressions where the variable is non-linear (used more than once), you can instead employ `use` expressions to statically duplicate the offending recursive term.
See here for more info: https://github.com/HigherOrderCO/hvm-lang/blob/main/docs/lazy-definitions.md.
8 changes: 6 additions & 2 deletions tests/snapshots/mutual_recursion__odd_even.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ isEven
isOdd

Due to the ultra-greedy nature of strict-mode, that might result in infinite loops.
If the float-combinators optimization is not on, we recommend activating it.

You have 2 options:

1. Easy Fix: use lazy-mode.

Just append the `-L` option to `HVM-Lang`, and it will run in lazy-mode. It has the advantage of not doing wasteful work, having an improved complexity class, and being compatible with unrestricted recursion! It has a small overhead though, and isn't compatible with GPU.

2. Hard Fix: use combinators.
2. Hard Fix: refactor the program to use lazy references.

By converting your program to use combinators, you can avoid the direct recursive calls that result in loops. If you use the built-in `data` and `match` syntaxes, HVM-Lang usually does this for you, but it couldn't handle your program. See here for more info: https://github.com/HigherOrderCO/hvm-lang/blob/main/docs/lazy-definitions.md.
When a function reference is in head position of an application or is duplicated by the non-linear use of a `let` expression it will be greedly expanded, leading to an infinite loop.
If the application is used written as a combinator, it will automatically lifted to a lazy reference, which usually breaks the recursion cycle. Alternatively, by using the built-in `data` and `match` syntax, hvm-lang will try to do this automatically.
For let expressions where the variable is non-linear (used more than once), you can instead employ `use` expressions to statically duplicate the offending recursive term.
See here for more info: https://github.com/HigherOrderCO/hvm-lang/blob/main/docs/lazy-definitions.md.

0 comments on commit e90644d

Please sign in to comment.