-
Notifications
You must be signed in to change notification settings - Fork 439
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #244 from HigherOrderCO/bug/sc-527/recursion-check…
…-incorrectly-displays-some [sc-527] Recursion check incorrectly displays some generated functions
- Loading branch information
Showing
5 changed files
with
78 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(X x) = (Rec x) | ||
(Y x) = (Rec x) | ||
|
||
(Rec x) = (X x) | ||
(Rec2 x) = (X x) | ||
|
||
(Main) = (Y 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
source: tests/golden_tests.rs | ||
input_file: tests/golden_tests/mutual_recursion/merged.hvm | ||
--- | ||
Errors: | ||
Seems like you're trying to run some recursive function(s) on strict-mode. | ||
The following recursive cycles are not compatible with strict-mode the way these functions were written: | ||
* Rec -> X -> Rec | ||
* Rec -> Y -> Rec | ||
* Rec2 -> X -> Rec2 | ||
* Rec2 -> Y -> Rec2 | ||
|
||
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: refactor the program to use lazy references. | ||
|
||
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. | ||
(e.g. If pattern matching on scott-encoded ADTs, write '@a @x(x @a (Foo a) a)' instead of '@a @x(x (Foo a))') | ||
|
||
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. | ||
(e.g. write 'Foo = @f use x = Foo; (f x x)' instead of 'Foo = @f let x = Foo; (f x x)') | ||
|
||
See here for more info: https://github.com/HigherOrderCO/hvm-lang/blob/main/docs/lazy-definitions.md. |