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

@ -1037,6 +1037,28 @@ pub fn new_marks(var_store: &mut VarStore) -> (RedundantMark, ExhaustiveMark) {
)
}
/// Marks whether a recursive let-cycle was determined to be illegal during solving.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct IllegalCycleMark(Variable);
impl IllegalCycleMark {
pub fn new(var_store: &mut VarStore) -> Self {
Self(var_store.fresh())
}
pub fn variable_for_introduction(&self) -> Variable {
self.0
}
pub fn set_illegal(&self, subs: &mut Subs) {
subs.set_content(self.0, Content::Error);
}
pub fn is_illegal(&self, subs: &Subs) -> bool {
matches!(subs.get_content_without_compacting(self.0), Content::Error)
}
}
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct Variable(u32);