mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-18 19:10:18 +00:00
Move solve problems to their own crate
This commit is contained in:
parent
ae4916ceb7
commit
0989b2cb82
17 changed files with 125 additions and 85 deletions
|
@ -4,13 +4,14 @@ use roc_collections::{VecMap, VecSet};
|
|||
use roc_error_macros::internal_error;
|
||||
use roc_module::symbol::Symbol;
|
||||
use roc_region::all::{Loc, Region};
|
||||
use roc_solve_problem::{TypeError, UnderivableReason, Unfulfilled};
|
||||
use roc_types::subs::{instantiate_rigids, Content, FlatType, GetSubsSlice, Rank, Subs, Variable};
|
||||
use roc_types::types::{AliasKind, Category, ErrorType, PatternCategory};
|
||||
use roc_types::types::{AliasKind, Category, PatternCategory};
|
||||
use roc_unify::unify::MustImplementConstraints;
|
||||
use roc_unify::unify::{MustImplementAbility, Obligated};
|
||||
|
||||
use crate::solve::type_to_var;
|
||||
use crate::solve::{Aliases, Pools, TypeError};
|
||||
use crate::solve::{Aliases, Pools};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum AbilityImplError {
|
||||
|
@ -22,35 +23,6 @@ pub enum AbilityImplError {
|
|||
BadPattern(Region, PatternCategory, Variable),
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug, Clone)]
|
||||
pub enum UnderivableReason {
|
||||
NotABuiltin,
|
||||
/// The surface type is not derivable
|
||||
SurfaceNotDerivable,
|
||||
/// A nested type is not derivable
|
||||
NestedNotDerivable(ErrorType),
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug, Clone)]
|
||||
pub enum Unfulfilled {
|
||||
/// No claimed implementation of an ability for an opaque type.
|
||||
OpaqueDoesNotImplement { typ: Symbol, ability: Symbol },
|
||||
/// Cannot derive implementation of an ability for a structural type.
|
||||
AdhocUnderivable {
|
||||
typ: ErrorType,
|
||||
ability: Symbol,
|
||||
reason: UnderivableReason,
|
||||
},
|
||||
/// Cannot derive implementation of an ability for an opaque type.
|
||||
OpaqueUnderivable {
|
||||
typ: ErrorType,
|
||||
ability: Symbol,
|
||||
opaque: Symbol,
|
||||
derive_region: Region,
|
||||
reason: UnderivableReason,
|
||||
},
|
||||
}
|
||||
|
||||
/// Indexes a requested deriving of an ability for an opaque type.
|
||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||
pub struct RequestedDeriveKey {
|
||||
|
|
|
@ -8,6 +8,7 @@ use roc_collections::VecMap;
|
|||
use roc_derive::SharedDerivedModule;
|
||||
use roc_error_macros::internal_error;
|
||||
use roc_module::symbol::{ModuleId, Symbol};
|
||||
use roc_solve_problem::TypeError;
|
||||
use roc_types::subs::{Content, ExposedTypesStorageSubs, FlatType, StorageSubs, Subs, Variable};
|
||||
use roc_types::types::{Alias, MemberImpl};
|
||||
|
||||
|
@ -32,7 +33,7 @@ impl<T> Solved<T> {
|
|||
|
||||
#[derive(Debug)]
|
||||
pub struct SolvedModule {
|
||||
pub problems: Vec<solve::TypeError>,
|
||||
pub problems: Vec<TypeError>,
|
||||
|
||||
/// all aliases and their definitions. this has to include non-exposed aliases
|
||||
/// because exposed aliases can depend on non-exposed ones)
|
||||
|
@ -64,12 +65,7 @@ pub fn run_solve(
|
|||
pending_derives: PendingDerives,
|
||||
exposed_by_module: &ExposedByModule,
|
||||
derived_module: SharedDerivedModule,
|
||||
) -> (
|
||||
Solved<Subs>,
|
||||
solve::Env,
|
||||
Vec<solve::TypeError>,
|
||||
AbilitiesStore,
|
||||
) {
|
||||
) -> (Solved<Subs>, solve::Env, Vec<TypeError>, AbilitiesStore) {
|
||||
for (var, name) in rigid_variables.named {
|
||||
subs.rigid_var(var, name);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::ability::{
|
||||
resolve_ability_specialization, type_implementing_specialization, AbilityImplError,
|
||||
CheckedDerives, ObligationCache, PendingDerivesTable, Resolved, Unfulfilled,
|
||||
CheckedDerives, ObligationCache, PendingDerivesTable, Resolved,
|
||||
};
|
||||
use crate::module::Solved;
|
||||
use bumpalo::Bump;
|
||||
|
@ -21,6 +21,7 @@ use roc_module::ident::TagName;
|
|||
use roc_module::symbol::{ModuleId, Symbol};
|
||||
use roc_problem::can::CycleEntry;
|
||||
use roc_region::all::{Loc, Region};
|
||||
use roc_solve_problem::TypeError;
|
||||
use roc_types::subs::{
|
||||
self, get_member_lambda_sets_at_region, AliasVariables, Content, Descriptor, FlatType,
|
||||
GetSubsSlice, LambdaSet, Mark, OptVariable, Rank, RecordFields, Subs, SubsIndex, SubsSlice,
|
||||
|
@ -28,8 +29,8 @@ use roc_types::subs::{
|
|||
};
|
||||
use roc_types::types::Type::{self, *};
|
||||
use roc_types::types::{
|
||||
gather_fields_unsorted_iter, AliasCommon, AliasKind, Category, ErrorType, MemberImpl,
|
||||
OptAbleType, OptAbleVar, PatternCategory, Reason, TypeExtension, Uls,
|
||||
gather_fields_unsorted_iter, AliasCommon, AliasKind, Category, MemberImpl, OptAbleType,
|
||||
OptAbleVar, Reason, TypeExtension, Uls,
|
||||
};
|
||||
use roc_unify::unify::{
|
||||
unify, unify_introduced_ability_specialization, Mode, MustImplementConstraints, Obligated,
|
||||
|
@ -86,32 +87,6 @@ use roc_unify::unify::{
|
|||
// Ranks are used to limit the number of type variables considered for generalization. Only those inside
|
||||
// of the let (so those used in inferring the type of `\x -> x`) are considered.
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum TypeError {
|
||||
BadExpr(Region, Category, ErrorType, Expected<ErrorType>),
|
||||
BadPattern(Region, PatternCategory, ErrorType, PExpected<ErrorType>),
|
||||
CircularType(Region, Symbol, ErrorType),
|
||||
CircularDef(Vec<CycleEntry>),
|
||||
BadType(roc_types::types::Problem),
|
||||
UnexposedLookup(Symbol),
|
||||
UnfulfilledAbility(Unfulfilled),
|
||||
BadExprMissingAbility(Region, Category, ErrorType, Vec<Unfulfilled>),
|
||||
BadPatternMissingAbility(Region, PatternCategory, ErrorType, Vec<Unfulfilled>),
|
||||
Exhaustive(roc_exhaustive::Error),
|
||||
StructuralSpecialization {
|
||||
region: Region,
|
||||
typ: ErrorType,
|
||||
ability: Symbol,
|
||||
member: Symbol,
|
||||
},
|
||||
WrongSpecialization {
|
||||
region: Region,
|
||||
ability_member: Symbol,
|
||||
expected_opaque: Symbol,
|
||||
found_opaque: Symbol,
|
||||
},
|
||||
}
|
||||
|
||||
use roc_types::types::Alias;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue