mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 23:31:12 +00:00
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:
parent
17d8545510
commit
710a10a29c
17 changed files with 261 additions and 49 deletions
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue