Decision tree compilation of list patterns

This commit is contained in:
Ayaz Hafiz 2022-11-01 13:59:44 -05:00
parent da1d937277
commit ae71c7efe2
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
7 changed files with 479 additions and 38 deletions

View file

@ -6,6 +6,7 @@ use crate::num::{
ParsedNumResult,
};
use crate::scope::{PendingAbilitiesInScope, Scope};
use roc_exhaustive::ListArity;
use roc_module::ident::{Ident, Lowercase, TagName};
use roc_module::symbol::Symbol;
use roc_parse::ast::{self, StrLiteral, StrSegment};
@ -189,6 +190,17 @@ impl ListPatterns {
fn surely_exhaustive(&self) -> bool {
self.patterns.is_empty() && matches!(self.opt_rest, Some(0))
}
pub fn arity(&self) -> ListArity {
match self.opt_rest {
Some(i) => {
let before = i;
let after = self.patterns.len() - before;
ListArity::Slice(before, after)
}
None => ListArity::Exact(self.patterns.len()),
}
}
}
#[derive(Clone, Debug)]