mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +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
18
Cargo.lock
generated
18
Cargo.lock
generated
|
@ -3375,7 +3375,7 @@ dependencies = [
|
||||||
"roc_problem",
|
"roc_problem",
|
||||||
"roc_region",
|
"roc_region",
|
||||||
"roc_reporting",
|
"roc_reporting",
|
||||||
"roc_solve",
|
"roc_solve_problem",
|
||||||
"roc_std",
|
"roc_std",
|
||||||
"roc_target",
|
"roc_target",
|
||||||
"roc_types",
|
"roc_types",
|
||||||
|
@ -3825,6 +3825,7 @@ dependencies = [
|
||||||
"roc_region",
|
"roc_region",
|
||||||
"roc_reporting",
|
"roc_reporting",
|
||||||
"roc_solve",
|
"roc_solve",
|
||||||
|
"roc_solve_problem",
|
||||||
"roc_target",
|
"roc_target",
|
||||||
"roc_test_utils",
|
"roc_test_utils",
|
||||||
"roc_types",
|
"roc_types",
|
||||||
|
@ -4026,6 +4027,7 @@ dependencies = [
|
||||||
"roc_problem",
|
"roc_problem",
|
||||||
"roc_region",
|
"roc_region",
|
||||||
"roc_solve",
|
"roc_solve",
|
||||||
|
"roc_solve_problem",
|
||||||
"roc_std",
|
"roc_std",
|
||||||
"roc_target",
|
"roc_target",
|
||||||
"roc_test_utils",
|
"roc_test_utils",
|
||||||
|
@ -4059,12 +4061,26 @@ dependencies = [
|
||||||
"roc_region",
|
"roc_region",
|
||||||
"roc_reporting",
|
"roc_reporting",
|
||||||
"roc_solve",
|
"roc_solve",
|
||||||
|
"roc_solve_problem",
|
||||||
"roc_target",
|
"roc_target",
|
||||||
"roc_types",
|
"roc_types",
|
||||||
"roc_unify",
|
"roc_unify",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "roc_solve_problem"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"roc_can",
|
||||||
|
"roc_collections",
|
||||||
|
"roc_exhaustive",
|
||||||
|
"roc_module",
|
||||||
|
"roc_problem",
|
||||||
|
"roc_region",
|
||||||
|
"roc_types",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "roc_std"
|
name = "roc_std"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
|
@ -8,6 +8,7 @@ members = [
|
||||||
"crates/compiler/parse",
|
"crates/compiler/parse",
|
||||||
"crates/compiler/can",
|
"crates/compiler/can",
|
||||||
"crates/compiler/problem",
|
"crates/compiler/problem",
|
||||||
|
"crates/compiler/solve_problem",
|
||||||
"crates/compiler/types",
|
"crates/compiler/types",
|
||||||
"crates/compiler/builtins",
|
"crates/compiler/builtins",
|
||||||
"crates/compiler/constrain",
|
"crates/compiler/constrain",
|
||||||
|
|
|
@ -16,7 +16,7 @@ roc_types = { path = "../types" }
|
||||||
roc_builtins = { path = "../builtins" }
|
roc_builtins = { path = "../builtins" }
|
||||||
roc_constrain = { path = "../constrain" }
|
roc_constrain = { path = "../constrain" }
|
||||||
roc_unify = { path = "../unify" }
|
roc_unify = { path = "../unify" }
|
||||||
roc_solve = { path = "../solve" }
|
roc_solve_problem = { path = "../solve_problem" }
|
||||||
roc_mono = { path = "../mono" }
|
roc_mono = { path = "../mono" }
|
||||||
roc_load = { path = "../load" }
|
roc_load = { path = "../load" }
|
||||||
roc_target = { path = "../roc_target" }
|
roc_target = { path = "../roc_target" }
|
||||||
|
|
|
@ -5,6 +5,7 @@ use roc_load::{LoadedModule, MonomorphizedModule};
|
||||||
use roc_module::symbol::{Interns, ModuleId};
|
use roc_module::symbol::{Interns, ModuleId};
|
||||||
use roc_mono::ir::OptLevel;
|
use roc_mono::ir::OptLevel;
|
||||||
use roc_region::all::LineInfo;
|
use roc_region::all::LineInfo;
|
||||||
|
use roc_solve_problem::TypeError;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
|
@ -60,7 +61,7 @@ fn report_problems_help(
|
||||||
sources: &MutMap<ModuleId, (PathBuf, Box<str>)>,
|
sources: &MutMap<ModuleId, (PathBuf, Box<str>)>,
|
||||||
interns: &Interns,
|
interns: &Interns,
|
||||||
can_problems: &mut MutMap<ModuleId, Vec<roc_problem::can::Problem>>,
|
can_problems: &mut MutMap<ModuleId, Vec<roc_problem::can::Problem>>,
|
||||||
type_problems: &mut MutMap<ModuleId, Vec<roc_solve::solve::TypeError>>,
|
type_problems: &mut MutMap<ModuleId, Vec<TypeError>>,
|
||||||
) -> Problems {
|
) -> Problems {
|
||||||
use roc_reporting::report::{
|
use roc_reporting::report::{
|
||||||
can_problem, type_problem, Report, RocDocAllocator, Severity::*, DEFAULT_PALETTE,
|
can_problem, type_problem, Report, RocDocAllocator, Severity::*, DEFAULT_PALETTE,
|
||||||
|
|
|
@ -20,6 +20,7 @@ roc_problem = { path = "../problem" }
|
||||||
roc_unify = { path = "../unify" }
|
roc_unify = { path = "../unify" }
|
||||||
roc_parse = { path = "../parse" }
|
roc_parse = { path = "../parse" }
|
||||||
roc_solve = { path = "../solve" }
|
roc_solve = { path = "../solve" }
|
||||||
|
roc_solve_problem = { path = "../solve_problem" }
|
||||||
roc_late_solve = { path = "../late_solve" }
|
roc_late_solve = { path = "../late_solve" }
|
||||||
roc_mono = { path = "../mono" }
|
roc_mono = { path = "../mono" }
|
||||||
roc_target = { path = "../roc_target" }
|
roc_target = { path = "../roc_target" }
|
||||||
|
|
|
@ -43,7 +43,7 @@ use roc_parse::parser::{FileError, Parser, SyntaxError};
|
||||||
use roc_region::all::{LineInfo, Loc, Region};
|
use roc_region::all::{LineInfo, Loc, Region};
|
||||||
use roc_reporting::report::RenderTarget;
|
use roc_reporting::report::RenderTarget;
|
||||||
use roc_solve::module::{extract_module_owned_implementations, Solved, SolvedModule};
|
use roc_solve::module::{extract_module_owned_implementations, Solved, SolvedModule};
|
||||||
use roc_solve::solve;
|
use roc_solve_problem::TypeError;
|
||||||
use roc_target::TargetInfo;
|
use roc_target::TargetInfo;
|
||||||
use roc_types::subs::{ExposedTypesStorageSubs, Subs, VarStore, Variable};
|
use roc_types::subs::{ExposedTypesStorageSubs, Subs, VarStore, Variable};
|
||||||
use roc_types::types::{Alias, AliasKind};
|
use roc_types::types::{Alias, AliasKind};
|
||||||
|
@ -139,7 +139,7 @@ struct ModuleCache<'a> {
|
||||||
top_level_thunks: MutMap<ModuleId, MutSet<Symbol>>,
|
top_level_thunks: MutMap<ModuleId, MutSet<Symbol>>,
|
||||||
documentation: MutMap<ModuleId, ModuleDocumentation>,
|
documentation: MutMap<ModuleId, ModuleDocumentation>,
|
||||||
can_problems: MutMap<ModuleId, Vec<roc_problem::can::Problem>>,
|
can_problems: MutMap<ModuleId, Vec<roc_problem::can::Problem>>,
|
||||||
type_problems: MutMap<ModuleId, Vec<solve::TypeError>>,
|
type_problems: MutMap<ModuleId, Vec<TypeError>>,
|
||||||
|
|
||||||
sources: MutMap<ModuleId, (PathBuf, &'a str)>,
|
sources: MutMap<ModuleId, (PathBuf, &'a str)>,
|
||||||
}
|
}
|
||||||
|
@ -556,7 +556,7 @@ pub struct LoadedModule {
|
||||||
pub interns: Interns,
|
pub interns: Interns,
|
||||||
pub solved: Solved<Subs>,
|
pub solved: Solved<Subs>,
|
||||||
pub can_problems: MutMap<ModuleId, Vec<roc_problem::can::Problem>>,
|
pub can_problems: MutMap<ModuleId, Vec<roc_problem::can::Problem>>,
|
||||||
pub type_problems: MutMap<ModuleId, Vec<solve::TypeError>>,
|
pub type_problems: MutMap<ModuleId, Vec<TypeError>>,
|
||||||
pub declarations_by_id: MutMap<ModuleId, Declarations>,
|
pub declarations_by_id: MutMap<ModuleId, Declarations>,
|
||||||
pub exposed_to_host: MutMap<Symbol, Variable>,
|
pub exposed_to_host: MutMap<Symbol, Variable>,
|
||||||
pub dep_idents: IdentIdsByModule,
|
pub dep_idents: IdentIdsByModule,
|
||||||
|
@ -671,7 +671,7 @@ pub struct MonomorphizedModule<'a> {
|
||||||
pub output_path: Box<Path>,
|
pub output_path: Box<Path>,
|
||||||
pub platform_path: Box<Path>,
|
pub platform_path: Box<Path>,
|
||||||
pub can_problems: MutMap<ModuleId, Vec<roc_problem::can::Problem>>,
|
pub can_problems: MutMap<ModuleId, Vec<roc_problem::can::Problem>>,
|
||||||
pub type_problems: MutMap<ModuleId, Vec<solve::TypeError>>,
|
pub type_problems: MutMap<ModuleId, Vec<TypeError>>,
|
||||||
pub procedures: MutMap<(Symbol, ProcLayout<'a>), Proc<'a>>,
|
pub procedures: MutMap<(Symbol, ProcLayout<'a>), Proc<'a>>,
|
||||||
pub toplevel_expects: VecMap<Symbol, Region>,
|
pub toplevel_expects: VecMap<Symbol, Region>,
|
||||||
pub entry_point: EntryPoint<'a>,
|
pub entry_point: EntryPoint<'a>,
|
||||||
|
@ -4115,7 +4115,7 @@ fn run_solve_solve(
|
||||||
Solved<Subs>,
|
Solved<Subs>,
|
||||||
ResolvedImplementations,
|
ResolvedImplementations,
|
||||||
Vec<(Symbol, Variable)>,
|
Vec<(Symbol, Variable)>,
|
||||||
Vec<solve::TypeError>,
|
Vec<TypeError>,
|
||||||
AbilitiesStore,
|
AbilitiesStore,
|
||||||
) {
|
) {
|
||||||
let Module {
|
let Module {
|
||||||
|
|
|
@ -16,6 +16,7 @@ roc_can = { path = "../can" }
|
||||||
roc_derive_key = { path = "../derive_key" }
|
roc_derive_key = { path = "../derive_key" }
|
||||||
roc_derive = { path = "../derive" }
|
roc_derive = { path = "../derive" }
|
||||||
roc_problem = { path = "../problem" }
|
roc_problem = { path = "../problem" }
|
||||||
|
roc_solve_problem = { path = "../solve_problem" }
|
||||||
roc_unify = { path = "../unify" }
|
roc_unify = { path = "../unify" }
|
||||||
roc_debug_flags = { path = "../debug_flags" }
|
roc_debug_flags = { path = "../debug_flags" }
|
||||||
arrayvec = "0.7.2"
|
arrayvec = "0.7.2"
|
||||||
|
|
|
@ -4,13 +4,14 @@ use roc_collections::{VecMap, VecSet};
|
||||||
use roc_error_macros::internal_error;
|
use roc_error_macros::internal_error;
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
use roc_region::all::{Loc, Region};
|
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::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::MustImplementConstraints;
|
||||||
use roc_unify::unify::{MustImplementAbility, Obligated};
|
use roc_unify::unify::{MustImplementAbility, Obligated};
|
||||||
|
|
||||||
use crate::solve::type_to_var;
|
use crate::solve::type_to_var;
|
||||||
use crate::solve::{Aliases, Pools, TypeError};
|
use crate::solve::{Aliases, Pools};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum AbilityImplError {
|
pub enum AbilityImplError {
|
||||||
|
@ -22,35 +23,6 @@ pub enum AbilityImplError {
|
||||||
BadPattern(Region, PatternCategory, Variable),
|
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.
|
/// Indexes a requested deriving of an ability for an opaque type.
|
||||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||||
pub struct RequestedDeriveKey {
|
pub struct RequestedDeriveKey {
|
||||||
|
|
|
@ -8,6 +8,7 @@ use roc_collections::VecMap;
|
||||||
use roc_derive::SharedDerivedModule;
|
use roc_derive::SharedDerivedModule;
|
||||||
use roc_error_macros::internal_error;
|
use roc_error_macros::internal_error;
|
||||||
use roc_module::symbol::{ModuleId, Symbol};
|
use roc_module::symbol::{ModuleId, Symbol};
|
||||||
|
use roc_solve_problem::TypeError;
|
||||||
use roc_types::subs::{Content, ExposedTypesStorageSubs, FlatType, StorageSubs, Subs, Variable};
|
use roc_types::subs::{Content, ExposedTypesStorageSubs, FlatType, StorageSubs, Subs, Variable};
|
||||||
use roc_types::types::{Alias, MemberImpl};
|
use roc_types::types::{Alias, MemberImpl};
|
||||||
|
|
||||||
|
@ -32,7 +33,7 @@ impl<T> Solved<T> {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SolvedModule {
|
pub struct SolvedModule {
|
||||||
pub problems: Vec<solve::TypeError>,
|
pub problems: Vec<TypeError>,
|
||||||
|
|
||||||
/// all aliases and their definitions. this has to include non-exposed aliases
|
/// all aliases and their definitions. this has to include non-exposed aliases
|
||||||
/// because exposed aliases can depend on non-exposed ones)
|
/// because exposed aliases can depend on non-exposed ones)
|
||||||
|
@ -64,12 +65,7 @@ pub fn run_solve(
|
||||||
pending_derives: PendingDerives,
|
pending_derives: PendingDerives,
|
||||||
exposed_by_module: &ExposedByModule,
|
exposed_by_module: &ExposedByModule,
|
||||||
derived_module: SharedDerivedModule,
|
derived_module: SharedDerivedModule,
|
||||||
) -> (
|
) -> (Solved<Subs>, solve::Env, Vec<TypeError>, AbilitiesStore) {
|
||||||
Solved<Subs>,
|
|
||||||
solve::Env,
|
|
||||||
Vec<solve::TypeError>,
|
|
||||||
AbilitiesStore,
|
|
||||||
) {
|
|
||||||
for (var, name) in rigid_variables.named {
|
for (var, name) in rigid_variables.named {
|
||||||
subs.rigid_var(var, name);
|
subs.rigid_var(var, name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::ability::{
|
use crate::ability::{
|
||||||
resolve_ability_specialization, type_implementing_specialization, AbilityImplError,
|
resolve_ability_specialization, type_implementing_specialization, AbilityImplError,
|
||||||
CheckedDerives, ObligationCache, PendingDerivesTable, Resolved, Unfulfilled,
|
CheckedDerives, ObligationCache, PendingDerivesTable, Resolved,
|
||||||
};
|
};
|
||||||
use crate::module::Solved;
|
use crate::module::Solved;
|
||||||
use bumpalo::Bump;
|
use bumpalo::Bump;
|
||||||
|
@ -21,6 +21,7 @@ use roc_module::ident::TagName;
|
||||||
use roc_module::symbol::{ModuleId, Symbol};
|
use roc_module::symbol::{ModuleId, Symbol};
|
||||||
use roc_problem::can::CycleEntry;
|
use roc_problem::can::CycleEntry;
|
||||||
use roc_region::all::{Loc, Region};
|
use roc_region::all::{Loc, Region};
|
||||||
|
use roc_solve_problem::TypeError;
|
||||||
use roc_types::subs::{
|
use roc_types::subs::{
|
||||||
self, get_member_lambda_sets_at_region, AliasVariables, Content, Descriptor, FlatType,
|
self, get_member_lambda_sets_at_region, AliasVariables, Content, Descriptor, FlatType,
|
||||||
GetSubsSlice, LambdaSet, Mark, OptVariable, Rank, RecordFields, Subs, SubsIndex, SubsSlice,
|
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::Type::{self, *};
|
||||||
use roc_types::types::{
|
use roc_types::types::{
|
||||||
gather_fields_unsorted_iter, AliasCommon, AliasKind, Category, ErrorType, MemberImpl,
|
gather_fields_unsorted_iter, AliasCommon, AliasKind, Category, MemberImpl, OptAbleType,
|
||||||
OptAbleType, OptAbleVar, PatternCategory, Reason, TypeExtension, Uls,
|
OptAbleVar, Reason, TypeExtension, Uls,
|
||||||
};
|
};
|
||||||
use roc_unify::unify::{
|
use roc_unify::unify::{
|
||||||
unify, unify_introduced_ability_specialization, Mode, MustImplementConstraints, Obligated,
|
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
|
// 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.
|
// 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;
|
use roc_types::types::Alias;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
|
|
@ -21,7 +21,7 @@ mod solve_expr {
|
||||||
use roc_problem::can::Problem;
|
use roc_problem::can::Problem;
|
||||||
use roc_region::all::{LineColumn, LineColumnRegion, LineInfo, Region};
|
use roc_region::all::{LineColumn, LineColumnRegion, LineInfo, Region};
|
||||||
use roc_reporting::report::{can_problem, type_problem, RocDocAllocator};
|
use roc_reporting::report::{can_problem, type_problem, RocDocAllocator};
|
||||||
use roc_solve::solve::TypeError;
|
use roc_solve_problem::TypeError;
|
||||||
use roc_types::{
|
use roc_types::{
|
||||||
pretty_print::{name_and_print_var, DebugPrint},
|
pretty_print::{name_and_print_var, DebugPrint},
|
||||||
types::MemberImpl,
|
types::MemberImpl,
|
||||||
|
|
15
crates/compiler/solve_problem/Cargo.toml
Normal file
15
crates/compiler/solve_problem/Cargo.toml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
[package]
|
||||||
|
name = "roc_solve_problem"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["The Roc Contributors"]
|
||||||
|
license = "UPL-1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
roc_collections = { path = "../collections" }
|
||||||
|
roc_region = { path = "../region" }
|
||||||
|
roc_module = { path = "../module" }
|
||||||
|
roc_types = { path = "../types" }
|
||||||
|
roc_can = { path = "../can" }
|
||||||
|
roc_problem = { path = "../problem" }
|
||||||
|
roc_exhaustive = { path = "../exhaustive" }
|
61
crates/compiler/solve_problem/src/lib.rs
Normal file
61
crates/compiler/solve_problem/src/lib.rs
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
use roc_can::expected::{Expected, PExpected};
|
||||||
|
use roc_module::symbol::Symbol;
|
||||||
|
use roc_problem::can::CycleEntry;
|
||||||
|
use roc_region::all::Region;
|
||||||
|
|
||||||
|
use roc_types::types::{Category, ErrorType, PatternCategory};
|
||||||
|
|
||||||
|
#[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,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq, Debug, Clone)]
|
||||||
|
pub enum UnderivableReason {
|
||||||
|
NotABuiltin,
|
||||||
|
/// The surface type is not derivable
|
||||||
|
SurfaceNotDerivable,
|
||||||
|
/// A nested type is not derivable
|
||||||
|
NestedNotDerivable(ErrorType),
|
||||||
|
}
|
|
@ -14,8 +14,8 @@ roc_parse = { path = "../compiler/parse" }
|
||||||
roc_problem = { path = "../compiler/problem" }
|
roc_problem = { path = "../compiler/problem" }
|
||||||
roc_types = { path = "../compiler/types" }
|
roc_types = { path = "../compiler/types" }
|
||||||
roc_can = { path = "../compiler/can" }
|
roc_can = { path = "../compiler/can" }
|
||||||
roc_solve = { path = "../compiler/solve" }
|
|
||||||
roc_fmt = { path = "../compiler/fmt" }
|
roc_fmt = { path = "../compiler/fmt" }
|
||||||
|
roc_solve_problem = { path = "../compiler/solve_problem" }
|
||||||
roc_std = { path = "../roc_std" }
|
roc_std = { path = "../roc_std" }
|
||||||
ven_pretty = { path = "../vendor/pretty" }
|
ven_pretty = { path = "../vendor/pretty" }
|
||||||
distance = "0.4.0"
|
distance = "0.4.0"
|
||||||
|
@ -30,6 +30,7 @@ roc_problem = { path = "../compiler/problem" }
|
||||||
roc_parse = { path = "../compiler/parse" }
|
roc_parse = { path = "../compiler/parse" }
|
||||||
roc_target = { path = "../compiler/roc_target" }
|
roc_target = { path = "../compiler/roc_target" }
|
||||||
roc_test_utils = { path = "../test_utils" }
|
roc_test_utils = { path = "../test_utils" }
|
||||||
|
roc_solve = { path = "../compiler/solve" }
|
||||||
pretty_assertions = "1.0.0"
|
pretty_assertions = "1.0.0"
|
||||||
indoc = "1.0.3"
|
indoc = "1.0.3"
|
||||||
insta = "1.15.0"
|
insta = "1.15.0"
|
||||||
|
|
|
@ -7,8 +7,7 @@ use roc_module::called_via::{BinOp, CalledVia};
|
||||||
use roc_module::ident::{Ident, IdentStr, Lowercase, TagName};
|
use roc_module::ident::{Ident, IdentStr, Lowercase, TagName};
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
use roc_region::all::{LineInfo, Loc, Region};
|
use roc_region::all::{LineInfo, Loc, Region};
|
||||||
use roc_solve::ability::{UnderivableReason, Unfulfilled};
|
use roc_solve_problem::{TypeError, UnderivableReason, Unfulfilled};
|
||||||
use roc_solve::solve;
|
|
||||||
use roc_std::RocDec;
|
use roc_std::RocDec;
|
||||||
use roc_types::pretty_print::{Parens, WILDCARD};
|
use roc_types::pretty_print::{Parens, WILDCARD};
|
||||||
use roc_types::types::{
|
use roc_types::types::{
|
||||||
|
@ -30,9 +29,9 @@ pub fn type_problem<'b>(
|
||||||
alloc: &'b RocDocAllocator<'b>,
|
alloc: &'b RocDocAllocator<'b>,
|
||||||
lines: &LineInfo,
|
lines: &LineInfo,
|
||||||
filename: PathBuf,
|
filename: PathBuf,
|
||||||
problem: solve::TypeError,
|
problem: TypeError,
|
||||||
) -> Option<Report<'b>> {
|
) -> Option<Report<'b>> {
|
||||||
use solve::TypeError::*;
|
use TypeError::*;
|
||||||
|
|
||||||
fn report(title: String, doc: RocDocBuilder<'_>, filename: PathBuf) -> Option<Report<'_>> {
|
fn report(title: String, doc: RocDocBuilder<'_>, filename: PathBuf) -> Option<Report<'_>> {
|
||||||
Some(Report {
|
Some(Report {
|
||||||
|
|
|
@ -16,6 +16,7 @@ use roc_parse::parser::{SourceError, SyntaxError};
|
||||||
use roc_problem::can::Problem;
|
use roc_problem::can::Problem;
|
||||||
use roc_region::all::Loc;
|
use roc_region::all::Loc;
|
||||||
use roc_solve::solve::{self, Aliases};
|
use roc_solve::solve::{self, Aliases};
|
||||||
|
use roc_solve_problem::TypeError;
|
||||||
use roc_types::subs::{Content, Subs, VarStore, Variable};
|
use roc_types::subs::{Content, Subs, VarStore, Variable};
|
||||||
use roc_types::types::Type;
|
use roc_types::types::Type;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
@ -29,7 +30,7 @@ pub fn test_home() -> ModuleId {
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn infer_expr(
|
pub fn infer_expr(
|
||||||
subs: Subs,
|
subs: Subs,
|
||||||
problems: &mut Vec<solve::TypeError>,
|
problems: &mut Vec<TypeError>,
|
||||||
constraints: &Constraints,
|
constraints: &Constraints,
|
||||||
constraint: &Constraint,
|
constraint: &Constraint,
|
||||||
pending_derives: PendingDerives,
|
pending_derives: PendingDerives,
|
||||||
|
|
|
@ -21,7 +21,7 @@ mod test_reporting {
|
||||||
DEFAULT_PALETTE,
|
DEFAULT_PALETTE,
|
||||||
};
|
};
|
||||||
use roc_reporting::report::{RocDocAllocator, RocDocBuilder};
|
use roc_reporting::report::{RocDocAllocator, RocDocBuilder};
|
||||||
use roc_solve::solve;
|
use roc_solve_problem::TypeError;
|
||||||
use roc_types::subs::Subs;
|
use roc_types::subs::Subs;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ mod test_reporting {
|
||||||
) -> Result<
|
) -> Result<
|
||||||
(
|
(
|
||||||
String,
|
String,
|
||||||
Vec<solve::TypeError>,
|
Vec<TypeError>,
|
||||||
Vec<roc_problem::can::Problem>,
|
Vec<roc_problem::can::Problem>,
|
||||||
ModuleId,
|
ModuleId,
|
||||||
Interns,
|
Interns,
|
||||||
|
@ -185,7 +185,7 @@ mod test_reporting {
|
||||||
expr_src: &'a str,
|
expr_src: &'a str,
|
||||||
) -> Result<
|
) -> Result<
|
||||||
(
|
(
|
||||||
Vec<solve::TypeError>,
|
Vec<TypeError>,
|
||||||
Vec<roc_problem::can::Problem>,
|
Vec<roc_problem::can::Problem>,
|
||||||
ModuleId,
|
ModuleId,
|
||||||
Interns,
|
Interns,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue