mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
Move constrain and its deps into their own crates
This commit is contained in:
parent
758de2e7bf
commit
908e485fca
58 changed files with 633 additions and 422 deletions
|
@ -119,7 +119,7 @@ fn can_annotation_help(
|
|||
match scope.lookup(&ident, region) {
|
||||
Ok(symbol) => symbol,
|
||||
Err(problem) => {
|
||||
env.problem(crate::problem::Problem::RuntimeError(problem));
|
||||
env.problem(roc_problem::can::Problem::RuntimeError(problem));
|
||||
|
||||
return Type::Erroneous(Problem::UnrecognizedIdent(ident.into()));
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ fn can_annotation_help(
|
|||
Err(problem) => {
|
||||
// Either the module wasn't imported, or
|
||||
// it was imported but it doesn't expose this ident.
|
||||
env.problem(crate::problem::Problem::RuntimeError(problem));
|
||||
env.problem(roc_problem::can::Problem::RuntimeError(problem));
|
||||
|
||||
return Type::Erroneous(Problem::UnrecognizedIdent((*ident).into()));
|
||||
}
|
||||
|
@ -183,10 +183,12 @@ fn can_annotation_help(
|
|||
Ok(symbol) => symbol,
|
||||
|
||||
Err((original_region, shadow)) => {
|
||||
let problem = Problem::Shadowed(original_region, shadow);
|
||||
env.problem(crate::problem::Problem::ErroneousAnnotation(
|
||||
problem.clone(),
|
||||
));
|
||||
let problem = Problem::Shadowed(original_region, shadow.clone());
|
||||
|
||||
env.problem(roc_problem::can::Problem::ShadowingInAnnotation {
|
||||
original_region,
|
||||
shadow,
|
||||
});
|
||||
|
||||
return Type::Erroneous(problem);
|
||||
}
|
||||
|
|
|
@ -5,16 +5,15 @@ use crate::expr::{
|
|||
canonicalize_expr, local_successors, references_from_call, references_from_local, Output,
|
||||
Recursive,
|
||||
};
|
||||
use crate::pattern::PatternType;
|
||||
use crate::pattern::{bindings_from_patterns, canonicalize_pattern, Pattern};
|
||||
use crate::problem::Problem;
|
||||
use crate::problem::RuntimeError;
|
||||
use crate::procedure::References;
|
||||
use crate::scope::Scope;
|
||||
use roc_collections::all::{default_hasher, ImMap, ImSet, MutMap, MutSet, SendMap};
|
||||
use roc_module::ident::{Ident, Lowercase};
|
||||
use roc_module::symbol::Symbol;
|
||||
use roc_parse::ast;
|
||||
use roc_parse::pattern::PatternType;
|
||||
use roc_problem::can::{Problem, RuntimeError};
|
||||
use roc_region::all::{Located, Region};
|
||||
use roc_types::subs::{VarStore, Variable};
|
||||
use roc_types::types::{Alias, Type};
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use crate::problem::{Problem, RuntimeError};
|
||||
use crate::procedure::References;
|
||||
use inlinable_string::InlinableString;
|
||||
use roc_collections::all::{MutMap, MutSet};
|
||||
use roc_module::symbol::{IdentIds, ModuleId, ModuleIds, Symbol};
|
||||
use roc_problem::can::{Problem, RuntimeError};
|
||||
use roc_region::all::Region;
|
||||
|
||||
/// The canonicalization environment for a particular module.
|
||||
|
|
|
@ -4,9 +4,7 @@ use crate::num::{
|
|||
finish_parsing_base, finish_parsing_float, finish_parsing_int, float_expr_from_result,
|
||||
int_expr_from_result,
|
||||
};
|
||||
use crate::pattern::PatternType::*;
|
||||
use crate::pattern::{canonicalize_pattern, Pattern};
|
||||
use crate::problem::{Problem, RuntimeError};
|
||||
use crate::procedure::References;
|
||||
use crate::scope::Scope;
|
||||
use roc_collections::all::{ImSet, MutMap, MutSet, SendMap};
|
||||
|
@ -14,6 +12,8 @@ use roc_module::ident::{Lowercase, TagName};
|
|||
use roc_module::symbol::Symbol;
|
||||
use roc_parse::ast;
|
||||
use roc_parse::operator::CalledVia;
|
||||
use roc_parse::pattern::PatternType::*;
|
||||
use roc_problem::can::{Problem, RuntimeError};
|
||||
use roc_region::all::{Located, Region};
|
||||
use roc_types::subs::{VarStore, Variable};
|
||||
use roc_types::types::Alias;
|
||||
|
|
|
@ -20,7 +20,6 @@ pub mod module;
|
|||
pub mod num;
|
||||
pub mod operator;
|
||||
pub mod pattern;
|
||||
pub mod problem;
|
||||
pub mod procedure;
|
||||
pub mod scope;
|
||||
pub mod string;
|
||||
|
|
|
@ -2,8 +2,6 @@ use crate::def::{canonicalize_defs, sort_can_defs, Declaration};
|
|||
use crate::env::Env;
|
||||
use crate::expr::Output;
|
||||
use crate::operator::desugar_def;
|
||||
use crate::pattern::PatternType;
|
||||
use crate::problem::{Problem, RuntimeError};
|
||||
use crate::scope::Scope;
|
||||
use bumpalo::Bump;
|
||||
use roc_collections::all::{MutMap, MutSet};
|
||||
|
@ -11,6 +9,8 @@ use roc_module::ident::Ident;
|
|||
use roc_module::ident::Lowercase;
|
||||
use roc_module::symbol::{IdentIds, ModuleId, ModuleIds, Symbol};
|
||||
use roc_parse::ast;
|
||||
use roc_parse::pattern::PatternType;
|
||||
use roc_problem::can::{Problem, RuntimeError};
|
||||
use roc_region::all::{Located, Region};
|
||||
use roc_types::subs::{VarStore, Variable};
|
||||
use roc_types::types::Alias;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use crate::env::Env;
|
||||
use crate::expr::Expr;
|
||||
use crate::problem::Problem;
|
||||
use crate::problem::RuntimeError::*;
|
||||
use roc_parse::ast::Base;
|
||||
use roc_problem::can::Problem;
|
||||
use roc_problem::can::RuntimeError::*;
|
||||
use roc_types::subs::VarStore;
|
||||
use std::i64;
|
||||
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
use crate::env::Env;
|
||||
use crate::num::{finish_parsing_base, finish_parsing_float, finish_parsing_int};
|
||||
use crate::problem::{Problem, RuntimeError};
|
||||
use crate::scope::Scope;
|
||||
use roc_module::ident::{Ident, Lowercase, TagName};
|
||||
use roc_module::symbol::Symbol;
|
||||
use roc_parse::ast;
|
||||
use roc_parse::pattern::PatternType;
|
||||
use roc_problem::can::{Problem, RuntimeError};
|
||||
use roc_region::all::{Located, Region};
|
||||
use roc_types::subs::{VarStore, Variable};
|
||||
|
||||
|
@ -66,18 +67,6 @@ pub fn symbols_from_pattern_help(pattern: &Pattern, symbols: &mut Vec<Symbol>) {
|
|||
}
|
||||
}
|
||||
|
||||
/// Different patterns are supported in different circumstances.
|
||||
/// For example, when branches can pattern match on number literals, but
|
||||
/// assignments and function args can't. Underscore is supported in function
|
||||
/// arg patterns and in when branch patterns, but not in assignments.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum PatternType {
|
||||
TopLevelDef,
|
||||
DefExpr,
|
||||
FunctionArg,
|
||||
WhenBranch,
|
||||
}
|
||||
|
||||
pub fn canonicalize_pattern<'a>(
|
||||
env: &mut Env<'a>,
|
||||
var_store: &VarStore,
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
use crate::pattern::PatternType;
|
||||
use inlinable_string::InlinableString;
|
||||
use roc_module::ident::Ident;
|
||||
use roc_module::symbol::{ModuleId, Symbol};
|
||||
use roc_parse::operator::BinOp;
|
||||
use roc_region::all::{Located, Region};
|
||||
use roc_types::types;
|
||||
|
||||
/// Problems that can occur in the course of canonicalization.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum Problem {
|
||||
UnusedDef(Symbol, Region),
|
||||
UnusedImport(ModuleId, Region),
|
||||
UnusedArgument(Symbol, Region),
|
||||
PrecedenceProblem(PrecedenceProblem),
|
||||
// Example: (5 = 1 + 2) is an unsupported pattern in an assignment; Int patterns aren't allowed in assignments!
|
||||
UnsupportedPattern(PatternType, Region),
|
||||
ErroneousAnnotation(types::Problem),
|
||||
RuntimeError(RuntimeError),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum PrecedenceProblem {
|
||||
BothNonAssociative(Located<BinOp>, Located<BinOp>),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum RuntimeError {
|
||||
Shadowing {
|
||||
original_region: Region,
|
||||
shadow: Located<Ident>,
|
||||
},
|
||||
UnrecognizedFunctionName(Located<InlinableString>),
|
||||
LookupNotInScope(Located<InlinableString>),
|
||||
ValueNotExposed {
|
||||
module_name: InlinableString,
|
||||
ident: InlinableString,
|
||||
region: Region,
|
||||
},
|
||||
ModuleNotImported {
|
||||
module_name: InlinableString,
|
||||
ident: InlinableString,
|
||||
region: Region,
|
||||
},
|
||||
InvalidPrecedence(PrecedenceProblem, Region),
|
||||
FloatOutsideRange(Box<str>),
|
||||
IntOutsideRange(Box<str>),
|
||||
InvalidHex(std::num::ParseIntError, Box<str>),
|
||||
InvalidOctal(std::num::ParseIntError, Box<str>),
|
||||
InvalidBinary(std::num::ParseIntError, Box<str>),
|
||||
QualifiedPatternIdent(InlinableString),
|
||||
CircularDef(
|
||||
Vec<Located<Ident>>,
|
||||
Vec<(Region /* pattern */, Region /* expr */)>,
|
||||
),
|
||||
|
||||
/// When the author specifies a type annotation but no implementation
|
||||
NoImplementation,
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
use crate::problem::RuntimeError;
|
||||
use roc_collections::all::ImMap;
|
||||
use roc_module::ident::{Ident, Lowercase};
|
||||
use roc_module::symbol::{IdentIds, ModuleId, Symbol};
|
||||
use roc_problem::can::RuntimeError;
|
||||
use roc_region::all::{Located, Region};
|
||||
use roc_types::subs::Variable;
|
||||
use roc_types::types::{Alias, Type};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue