diff --git a/Cargo.lock b/Cargo.lock index dc9e364812..d2babf3e7b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3351,6 +3351,7 @@ dependencies = [ "roc_parse", "roc_problem", "roc_region", + "roc_reporting", "roc_target", "roc_types", "roc_unify", @@ -3519,6 +3520,7 @@ dependencies = [ "roc_module", "roc_parse", "roc_region", + "roc_reporting", "roc_target", "roc_types", "snafu", diff --git a/ast/Cargo.toml b/ast/Cargo.toml index 86d203cee4..d1384b96ee 100644 --- a/ast/Cargo.toml +++ b/ast/Cargo.toml @@ -19,6 +19,7 @@ roc_unify = { path = "../compiler/unify"} roc_load = { path = "../compiler/load" } roc_target = { path = "../compiler/roc_target" } roc_error_macros = { path = "../error_macros" } +roc_reporting = { path = "../reporting" } arrayvec = "0.7.2" bumpalo = { version = "3.8.0", features = ["collections"] } page_size = "0.4.2" diff --git a/ast/src/module.rs b/ast/src/module.rs index 55b324b35d..769df5d162 100644 --- a/ast/src/module.rs +++ b/ast/src/module.rs @@ -19,6 +19,7 @@ pub fn load_module(src_file: &Path) -> LoadedModule { }), subs_by_module, TargetInfo::default_x86_64(), + roc_reporting::report::RenderTarget::ColorTerminal, ); match loaded { diff --git a/ast/src/solve_type.rs b/ast/src/solve_type.rs index dc2e53f3a8..f15b128827 100644 --- a/ast/src/solve_type.rs +++ b/ast/src/solve_type.rs @@ -227,12 +227,16 @@ fn solve<'a>( ); match unify(subs, actual, expected, Mode::EQ) { - Success(vars) => { + Success { + vars, + must_implement_ability: _, + } => { + // TODO(abilities) record deferred ability checks introduce(subs, rank, pools, &vars); state } - Failure(vars, actual_type, expected_type) => { + Failure(vars, actual_type, expected_type, _bad_impl) => { introduce(subs, rank, pools, &vars); let problem = TypeError::BadExpr( @@ -267,7 +271,7 @@ fn solve<'a>( // // state // } - // Failure(vars, _actual_type, _expected_type) => { + // Failure(vars, _actual_type, _expected_type, _bad_impl) => { // introduce(subs, rank, pools, &vars); // // // ERROR NOT REPORTED @@ -320,13 +324,17 @@ fn solve<'a>( ); match unify(subs, actual, expected, Mode::EQ) { - Success(vars) => { + Success { + vars, + must_implement_ability: _, + } => { + // TODO(abilities) record deferred ability checks introduce(subs, rank, pools, &vars); state } - Failure(vars, actual_type, expected_type) => { + Failure(vars, actual_type, expected_type, _bad_impl) => { introduce(subs, rank, pools, &vars); let problem = TypeError::BadExpr( @@ -391,12 +399,16 @@ fn solve<'a>( // TODO(ayazhafiz): presence constraints for Expr2/Type2 match unify(subs, actual, expected, Mode::EQ) { - Success(vars) => { + Success { + vars, + must_implement_ability: _, + } => { + // TODO(abilities) record deferred ability checks introduce(subs, rank, pools, &vars); state } - Failure(vars, actual_type, expected_type) => { + Failure(vars, actual_type, expected_type, _bad_impl) => { introduce(subs, rank, pools, &vars); let problem = TypeError::BadPattern( @@ -699,12 +711,16 @@ fn solve<'a>( let includes = type_to_var(arena, mempool, subs, rank, pools, cached_aliases, &tag_ty); match unify(subs, actual, includes, Mode::PRESENT) { - Success(vars) => { + Success { + vars, + must_implement_ability: _, + } => { + // TODO(abilities) record deferred ability checks introduce(subs, rank, pools, &vars); state } - Failure(vars, actual_type, expected_type) => { + Failure(vars, actual_type, expected_type, _bad_impl) => { introduce(subs, rank, pools, &vars); // TODO: do we need a better error type here? @@ -1281,7 +1297,7 @@ fn adjust_rank_content( use roc_types::subs::FlatType::*; match content { - FlexVar(_) | RigidVar(_) | Error => group_rank, + FlexVar(_) | RigidVar(_) | FlexAbleVar(..) | RigidAbleVar(..) | Error => group_rank, RecursionVar { .. } => group_rank, @@ -1536,7 +1552,7 @@ fn instantiate_rigids_help( }; } - FlexVar(_) | Error => {} + FlexVar(_) | FlexAbleVar(_, _) | Error => {} RecursionVar { structure, .. } => { instantiate_rigids_help(subs, max_rank, pools, structure); @@ -1547,6 +1563,11 @@ fn instantiate_rigids_help( subs.set(copy, make_descriptor(FlexVar(Some(name)))); } + RigidAbleVar(name, ability) => { + // what it's all about: convert the rigid var into a flex var + subs.set(copy, make_descriptor(FlexAbleVar(Some(name), ability))); + } + Alias(_, args, real_type_var, _) => { for var_index in args.all_variables() { let var = subs[var_index]; @@ -1772,7 +1793,7 @@ fn deep_copy_var_help( copy } - FlexVar(_) | Error => copy, + FlexVar(_) | FlexAbleVar(_, _) | Error => copy, RecursionVar { opt_name, @@ -1797,6 +1818,12 @@ fn deep_copy_var_help( copy } + RigidAbleVar(name, ability) => { + subs.set(copy, make_descriptor(FlexAbleVar(Some(name), ability))); + + copy + } + Alias(symbol, mut args, real_type_var, kind) => { let mut new_args = Vec::with_capacity(args.all_variables().len()); diff --git a/cli/src/build.rs b/cli/src/build.rs index ab3d7d0c42..c39b55f043 100644 --- a/cli/src/build.rs +++ b/cli/src/build.rs @@ -6,6 +6,7 @@ use roc_build::{ use roc_builtins::bitcode; use roc_load::LoadingProblem; use roc_mono::ir::OptLevel; +use roc_reporting::report::RenderTarget; use roc_target::TargetInfo; use std::path::PathBuf; use std::time::{Duration, SystemTime}; @@ -68,6 +69,8 @@ pub fn build_file<'a>( src_dir.as_path(), subs_by_module, target_info, + // TODO: expose this from CLI? + RenderTarget::ColorTerminal, )?; use target_lexicon::Architecture; @@ -374,6 +377,8 @@ pub fn check_file( src_dir.as_path(), subs_by_module, target_info, + // TODO: expose this from CLI? + RenderTarget::ColorTerminal, )?; let buf = &mut String::with_capacity(1024); diff --git a/docs/Cargo.toml b/docs/Cargo.toml index d377031ac9..1fe3c231e2 100644 --- a/docs/Cargo.toml +++ b/docs/Cargo.toml @@ -21,6 +21,7 @@ roc_parse = { path = "../compiler/parse" } roc_target = { path = "../compiler/roc_target" } roc_collections = { path = "../compiler/collections" } roc_highlight = { path = "../highlight"} +roc_reporting = { path = "../reporting"} bumpalo = { version = "3.8.0", features = ["collections"] } snafu = { version = "0.6.10", features = ["backtraces"] } peg = "0.8.0" diff --git a/docs/src/lib.rs b/docs/src/lib.rs index 7a4a05f0c9..d09134d98d 100644 --- a/docs/src/lib.rs +++ b/docs/src/lib.rs @@ -424,6 +424,7 @@ pub fn load_modules_for_files(filenames: Vec) -> Vec { src_dir.as_path(), Default::default(), roc_target::TargetInfo::default_x86_64(), // This is just type-checking for docs, so "target" doesn't matter + roc_reporting::report::RenderTarget::ColorTerminal, ) { Ok(loaded) => modules.push(loaded), Err(LoadingProblem::FormattedReport(report)) => { diff --git a/repl_eval/src/gen.rs b/repl_eval/src/gen.rs index a5e1fa6dbd..4e8f698c29 100644 --- a/repl_eval/src/gen.rs +++ b/repl_eval/src/gen.rs @@ -60,6 +60,7 @@ pub fn compile_to_mono<'a>( src_dir, exposed_types, target_info, + roc_reporting::report::RenderTarget::ColorTerminal, ); let mut loaded = match loaded {