Check for invalid cycles after type solving recursive defs

Disallow cycles that pass through a non-function value. Since we
evaluate eagerly, having one such cycle means there is at least one path
in the program that (likely) has unbounded recursion. Of course we can't
be certain (halting problem), but it's very likely, and avoids stuff
like #1926. Also, mono (as it's done today) won't work if things in a
cycle aren't functions.

Closes #1926
This commit is contained in:
Ayaz Hafiz 2022-05-10 16:02:10 -04:00
parent 17d8545510
commit 710a10a29c
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
17 changed files with 261 additions and 49 deletions

View file

@ -2190,7 +2190,7 @@ fn from_can_let<'a>(
lower_rest!(variable, new_outer)
}
LetRec(nested_defs, nested_cont) => {
LetRec(nested_defs, nested_cont, cycle_mark) => {
use roc_can::expr::Expr::*;
// We must transform
//
@ -2223,7 +2223,7 @@ fn from_can_let<'a>(
let new_inner = LetNonRec(Box::new(new_def), cont);
let new_outer = LetRec(nested_defs, Box::new(Loc::at_zero(new_inner)));
let new_outer = LetRec(nested_defs, Box::new(Loc::at_zero(new_inner)), cycle_mark);
lower_rest!(variable, new_outer)
}
@ -3833,7 +3833,7 @@ pub fn with_hole<'a>(
variable,
Some((assigned, hole)),
),
LetRec(defs, cont) => {
LetRec(defs, cont, _cycle_mark) => {
// because Roc is strict, only functions can be recursive!
for def in defs.into_iter() {
if let roc_can::pattern::Pattern::Identifier(symbol) = &def.loc_pattern.value {
@ -5957,7 +5957,7 @@ pub fn from_can<'a>(
)
}
LetRec(defs, cont) => {
LetRec(defs, cont, _cycle_mark) => {
// because Roc is strict, only functions can be recursive!
for def in defs.into_iter() {
if let roc_can::pattern::Pattern::Identifier(symbol) = &def.loc_pattern.value {