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
|
@ -16,7 +16,7 @@ roc_types = { path = "../types" }
|
|||
roc_builtins = { path = "../builtins" }
|
||||
roc_constrain = { path = "../constrain" }
|
||||
roc_unify = { path = "../unify" }
|
||||
roc_solve = { path = "../solve" }
|
||||
roc_solve_problem = { path = "../solve_problem" }
|
||||
roc_mono = { path = "../mono" }
|
||||
roc_load = { path = "../load" }
|
||||
roc_target = { path = "../roc_target" }
|
||||
|
|
|
@ -5,6 +5,7 @@ use roc_load::{LoadedModule, MonomorphizedModule};
|
|||
use roc_module::symbol::{Interns, ModuleId};
|
||||
use roc_mono::ir::OptLevel;
|
||||
use roc_region::all::LineInfo;
|
||||
use roc_solve_problem::TypeError;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
|
@ -60,7 +61,7 @@ fn report_problems_help(
|
|||
sources: &MutMap<ModuleId, (PathBuf, Box<str>)>,
|
||||
interns: &Interns,
|
||||
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 {
|
||||
use roc_reporting::report::{
|
||||
can_problem, type_problem, Report, RocDocAllocator, Severity::*, DEFAULT_PALETTE,
|
||||
|
|
|
@ -20,6 +20,7 @@ roc_problem = { path = "../problem" }
|
|||
roc_unify = { path = "../unify" }
|
||||
roc_parse = { path = "../parse" }
|
||||
roc_solve = { path = "../solve" }
|
||||
roc_solve_problem = { path = "../solve_problem" }
|
||||
roc_late_solve = { path = "../late_solve" }
|
||||
roc_mono = { path = "../mono" }
|
||||
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_reporting::report::RenderTarget;
|
||||
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_types::subs::{ExposedTypesStorageSubs, Subs, VarStore, Variable};
|
||||
use roc_types::types::{Alias, AliasKind};
|
||||
|
@ -139,7 +139,7 @@ struct ModuleCache<'a> {
|
|||
top_level_thunks: MutMap<ModuleId, MutSet<Symbol>>,
|
||||
documentation: MutMap<ModuleId, ModuleDocumentation>,
|
||||
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)>,
|
||||
}
|
||||
|
@ -556,7 +556,7 @@ pub struct LoadedModule {
|
|||
pub interns: Interns,
|
||||
pub solved: Solved<Subs>,
|
||||
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 exposed_to_host: MutMap<Symbol, Variable>,
|
||||
pub dep_idents: IdentIdsByModule,
|
||||
|
@ -671,7 +671,7 @@ pub struct MonomorphizedModule<'a> {
|
|||
pub output_path: Box<Path>,
|
||||
pub platform_path: Box<Path>,
|
||||
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 toplevel_expects: VecMap<Symbol, Region>,
|
||||
pub entry_point: EntryPoint<'a>,
|
||||
|
@ -4115,7 +4115,7 @@ fn run_solve_solve(
|
|||
Solved<Subs>,
|
||||
ResolvedImplementations,
|
||||
Vec<(Symbol, Variable)>,
|
||||
Vec<solve::TypeError>,
|
||||
Vec<TypeError>,
|
||||
AbilitiesStore,
|
||||
) {
|
||||
let Module {
|
||||
|
|
|
@ -16,6 +16,7 @@ roc_can = { path = "../can" }
|
|||
roc_derive_key = { path = "../derive_key" }
|
||||
roc_derive = { path = "../derive" }
|
||||
roc_problem = { path = "../problem" }
|
||||
roc_solve_problem = { path = "../solve_problem" }
|
||||
roc_unify = { path = "../unify" }
|
||||
roc_debug_flags = { path = "../debug_flags" }
|
||||
arrayvec = "0.7.2"
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -21,7 +21,7 @@ mod solve_expr {
|
|||
use roc_problem::can::Problem;
|
||||
use roc_region::all::{LineColumn, LineColumnRegion, LineInfo, Region};
|
||||
use roc_reporting::report::{can_problem, type_problem, RocDocAllocator};
|
||||
use roc_solve::solve::TypeError;
|
||||
use roc_solve_problem::TypeError;
|
||||
use roc_types::{
|
||||
pretty_print::{name_and_print_var, DebugPrint},
|
||||
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),
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue