mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 05:49:08 +00:00
Merge remote-tracking branch 'origin/main' into abilities-syntax
This commit is contained in:
commit
2da41be29f
524 changed files with 47536 additions and 15089 deletions
|
@ -1,5 +1,6 @@
|
|||
use roc_can::abilities::AbilitiesStore;
|
||||
use roc_can::expr::PendingDerives;
|
||||
use roc_checkmate::with_checkmate;
|
||||
use roc_collections::{VecMap, VecSet};
|
||||
use roc_debug_flags::dbg_do;
|
||||
#[cfg(debug_assertions)]
|
||||
|
@ -12,17 +13,19 @@ use roc_solve_problem::{
|
|||
NotDerivableContext, NotDerivableDecode, NotDerivableEncode, NotDerivableEq, TypeError,
|
||||
UnderivableReason, Unfulfilled,
|
||||
};
|
||||
use roc_solve_schema::UnificationMode;
|
||||
use roc_types::num::NumericRange;
|
||||
use roc_types::subs::{
|
||||
instantiate_rigids, Content, FlatType, GetSubsSlice, Rank, RecordFields, Subs, SubsSlice,
|
||||
TupleElems, Variable,
|
||||
};
|
||||
use roc_types::types::{AliasKind, Category, MemberImpl, PatternCategory, Polarity, Types};
|
||||
use roc_unify::unify::{Env, MustImplementConstraints};
|
||||
use roc_unify::unify::MustImplementConstraints;
|
||||
use roc_unify::unify::{MustImplementAbility, Obligated};
|
||||
use roc_unify::Env as UEnv;
|
||||
|
||||
use crate::solve::type_to_var;
|
||||
use crate::solve::{Aliases, Pools};
|
||||
use crate::env::InferenceEnv;
|
||||
use crate::{aliases::Aliases, to_var::type_to_var};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum AbilityImplError {
|
||||
|
@ -56,7 +59,7 @@ pub struct PendingDerivesTable(
|
|||
|
||||
impl PendingDerivesTable {
|
||||
pub fn new(
|
||||
subs: &mut Subs,
|
||||
env: &mut InferenceEnv,
|
||||
types: &mut Types,
|
||||
aliases: &mut Aliases,
|
||||
pending_derives: PendingDerives,
|
||||
|
@ -81,17 +84,16 @@ impl PendingDerivesTable {
|
|||
// Neither rank nor pools should matter here.
|
||||
let typ = types.from_old_type(&typ);
|
||||
let opaque_var = type_to_var(
|
||||
subs,
|
||||
env,
|
||||
Rank::toplevel(),
|
||||
problems,
|
||||
abilities_store,
|
||||
obligation_cache,
|
||||
&mut Pools::default(),
|
||||
types,
|
||||
aliases,
|
||||
typ,
|
||||
);
|
||||
let real_var = match subs.get_content_without_compacting(opaque_var) {
|
||||
let real_var = match env.subs.get_content_without_compacting(opaque_var) {
|
||||
Content::Alias(_, _, real_var, AliasKind::Opaque) => real_var,
|
||||
_ => internal_error!("Non-opaque in derives table"),
|
||||
};
|
||||
|
@ -828,6 +830,12 @@ trait DerivableVisitor {
|
|||
context: NotDerivableContext::NoContext,
|
||||
})
|
||||
}
|
||||
ErasedLambda => {
|
||||
return Err(NotDerivable {
|
||||
var,
|
||||
context: NotDerivableContext::NoContext,
|
||||
})
|
||||
}
|
||||
Error => {
|
||||
return Err(NotDerivable {
|
||||
var,
|
||||
|
@ -1280,16 +1288,19 @@ impl DerivableVisitor for DeriveEq {
|
|||
subs: &mut Subs,
|
||||
content_var: Variable,
|
||||
) -> Result<Descend, NotDerivable> {
|
||||
use roc_unify::unify::{unify, Mode};
|
||||
use roc_unify::unify::unify;
|
||||
|
||||
// Of the floating-point types,
|
||||
// only Dec implements Eq.
|
||||
let mut env = Env::new(subs);
|
||||
// TODO(checkmate): pass checkmate through
|
||||
let unified = unify(
|
||||
&mut env,
|
||||
&mut with_checkmate!({
|
||||
on => UEnv::new(subs, None),
|
||||
off => UEnv::new(subs),
|
||||
}),
|
||||
content_var,
|
||||
Variable::DECIMAL,
|
||||
Mode::EQ,
|
||||
UnificationMode::EQ,
|
||||
Polarity::Pos,
|
||||
);
|
||||
match unified {
|
||||
|
@ -1323,8 +1334,7 @@ pub fn type_implementing_specialization(
|
|||
.filter(|mia| mia.ability == ability)
|
||||
.count()
|
||||
} < 2,
|
||||
"Multiple variables bound to an ability - this is ambiguous and should have been caught in canonicalization: {:?}",
|
||||
specialization_must_implement_constraints
|
||||
"Multiple variables bound to an ability - this is ambiguous and should have been caught in canonicalization: {specialization_must_implement_constraints:?}"
|
||||
);
|
||||
|
||||
specialization_must_implement_constraints
|
||||
|
@ -1408,7 +1418,7 @@ pub fn resolve_ability_specialization<R: AbilityResolver>(
|
|||
ability_member: Symbol,
|
||||
specialization_var: Variable,
|
||||
) -> Result<Resolved, ResolveError> {
|
||||
use roc_unify::unify::{unify, Mode};
|
||||
use roc_unify::unify::unify;
|
||||
|
||||
let (parent_ability, signature_var) = resolver
|
||||
.member_parent_and_signature_var(ability_member, subs)
|
||||
|
@ -1419,10 +1429,14 @@ pub fn resolve_ability_specialization<R: AbilityResolver>(
|
|||
|
||||
instantiate_rigids(subs, signature_var);
|
||||
let (_vars, must_implement_ability, _lambda_sets_to_specialize, _meta) = unify(
|
||||
&mut Env::new(subs),
|
||||
// TODO(checkmate): pass checkmate through
|
||||
&mut with_checkmate!({
|
||||
on => UEnv::new(subs, None),
|
||||
off => UEnv::new(subs),
|
||||
}),
|
||||
specialization_var,
|
||||
signature_var,
|
||||
Mode::EQ,
|
||||
UnificationMode::EQ,
|
||||
Polarity::Pos,
|
||||
)
|
||||
.expect_success(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue