mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 05:49:08 +00:00
Move unify::Mode to roc_solve_schema
This commit is contained in:
parent
87d108eccc
commit
18e9f8f034
19 changed files with 140 additions and 98 deletions
50
crates/compiler/solve_schema/src/unify.rs
Normal file
50
crates/compiler/solve_schema/src/unify.rs
Normal file
|
@ -0,0 +1,50 @@
|
|||
use bitflags::bitflags;
|
||||
|
||||
bitflags! {
|
||||
pub struct UnificationMode : u8 {
|
||||
/// Instructs the unifier to solve two types for equality.
|
||||
///
|
||||
/// For example, { n : Str }a ~ { n: Str, m : Str } will solve "a" to "{ m : Str }".
|
||||
const EQ = 1 << 0;
|
||||
/// Instructs the unifier to treat the right-hand-side of a constraint as
|
||||
/// present in the left-hand-side, rather than strictly equal.
|
||||
///
|
||||
/// For example, t1 += [A Str] says we should "add" the tag "A Str" to the type of "t1".
|
||||
const PRESENT = 1 << 1;
|
||||
/// Like [`UnificationMode::EQ`], but also instructs the unifier that the ambient lambda set
|
||||
/// specialization algorithm is running. This has implications for the unification of
|
||||
/// unspecialized lambda sets; see [`unify_unspecialized_lambdas`].
|
||||
const LAMBDA_SET_SPECIALIZATION = UnificationMode::EQ.bits | (1 << 2);
|
||||
}
|
||||
}
|
||||
|
||||
impl UnificationMode {
|
||||
pub fn is_eq(&self) -> bool {
|
||||
debug_assert!(!self.contains(UnificationMode::EQ | UnificationMode::PRESENT));
|
||||
self.contains(UnificationMode::EQ)
|
||||
}
|
||||
|
||||
pub fn is_present(&self) -> bool {
|
||||
debug_assert!(!self.contains(UnificationMode::EQ | UnificationMode::PRESENT));
|
||||
self.contains(UnificationMode::PRESENT)
|
||||
}
|
||||
|
||||
pub fn is_lambda_set_specialization(&self) -> bool {
|
||||
debug_assert!(!self.contains(UnificationMode::EQ | UnificationMode::PRESENT));
|
||||
self.contains(UnificationMode::LAMBDA_SET_SPECIALIZATION)
|
||||
}
|
||||
|
||||
pub fn as_eq(self) -> Self {
|
||||
(self - UnificationMode::PRESENT) | UnificationMode::EQ
|
||||
}
|
||||
|
||||
pub fn pretty_print(&self) -> &str {
|
||||
if self.contains(UnificationMode::EQ) {
|
||||
"~"
|
||||
} else if self.contains(UnificationMode::PRESENT) {
|
||||
"+="
|
||||
} else {
|
||||
unreachable!("Bad mode!")
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue