Propogate render target forward

This commit is contained in:
Ayaz Hafiz 2022-04-12 15:45:42 -04:00
parent 15a040ec87
commit ce7c61eb09
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
8 changed files with 51 additions and 12 deletions

2
Cargo.lock generated
View file

@ -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",

View file

@ -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"

View file

@ -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 {

View file

@ -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());

View file

@ -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);

View file

@ -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"

View file

@ -424,6 +424,7 @@ pub fn load_modules_for_files(filenames: Vec<PathBuf>) -> Vec<LoadedModule> {
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)) => {

View file

@ -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 {