mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 22:09:09 +00:00
Merge pull request #2857 from rtfeldman/abilities-mono
Codegen for abilities
This commit is contained in:
commit
718b999751
15 changed files with 442 additions and 103 deletions
|
@ -1,5 +1,5 @@
|
|||
use bitflags::bitflags;
|
||||
use roc_error_macros::todo_abilities;
|
||||
use roc_error_macros::{internal_error, todo_abilities};
|
||||
use roc_module::ident::{Lowercase, TagName};
|
||||
use roc_module::symbol::Symbol;
|
||||
use roc_types::subs::Content::{self, *};
|
||||
|
@ -134,14 +134,26 @@ pub struct Context {
|
|||
pub enum Unified {
|
||||
Success {
|
||||
vars: Pool,
|
||||
must_implement_ability: Vec<MustImplementAbility>,
|
||||
must_implement_ability: MustImplementConstraints,
|
||||
},
|
||||
Failure(Pool, ErrorType, ErrorType, DoesNotImplementAbility),
|
||||
BadType(Pool, roc_types::types::Problem),
|
||||
}
|
||||
|
||||
impl Unified {
|
||||
pub fn expect_success(self, err_msg: &'static str) -> (Pool, MustImplementConstraints) {
|
||||
match self {
|
||||
Unified::Success {
|
||||
vars,
|
||||
must_implement_ability,
|
||||
} => (vars, must_implement_ability),
|
||||
_ => internal_error!("{}", err_msg),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Specifies that `type` must implement the ability `ability`.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct MustImplementAbility {
|
||||
// This only points to opaque type names currently.
|
||||
// TODO(abilities) support structural types in general
|
||||
|
@ -149,12 +161,39 @@ pub struct MustImplementAbility {
|
|||
pub ability: Symbol,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||
pub struct MustImplementConstraints(Vec<MustImplementAbility>);
|
||||
|
||||
impl MustImplementConstraints {
|
||||
pub fn push(&mut self, must_implement: MustImplementAbility) {
|
||||
self.0.push(must_implement)
|
||||
}
|
||||
|
||||
pub fn extend(&mut self, other: Self) {
|
||||
self.0.extend(other.0)
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.0.is_empty()
|
||||
}
|
||||
|
||||
pub fn get_unique(mut self) -> Vec<MustImplementAbility> {
|
||||
self.0.sort();
|
||||
self.0.dedup();
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn iter_for_ability(&self, ability: Symbol) -> impl Iterator<Item = &MustImplementAbility> {
|
||||
self.0.iter().filter(move |mia| mia.ability == ability)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Outcome {
|
||||
mismatches: Vec<Mismatch>,
|
||||
/// We defer these checks until the end of a solving phase.
|
||||
/// NOTE: this vector is almost always empty!
|
||||
must_implement_ability: Vec<MustImplementAbility>,
|
||||
must_implement_ability: MustImplementConstraints,
|
||||
}
|
||||
|
||||
impl Outcome {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue