From 3b6ed43126e110400097ab037ca544f65b7341d0 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 5 Mar 2020 20:58:12 -0500 Subject: [PATCH 1/3] Extract can/ into its own crate, plus its deps --- Cargo.lock | 54 +++++ Cargo.toml | 6 +- compiler/Cargo.toml | 2 + compiler/can/Cargo.toml | 24 +++ compiler/{src/can => can/src}/annotation.rs | 17 +- compiler/can/src/constraint.rs | 97 +++++++++ compiler/{src/can => can/src}/def.rs | 28 +-- compiler/{src/can => can/src}/env.rs | 4 +- compiler/can/src/expected.rs | 66 ++++++ compiler/{src/can => can/src}/expr.rs | 20 +- compiler/{src/can/mod.rs => can/src/lib.rs} | 2 + compiler/{src/can => can/src}/module.rs | 20 +- compiler/{src/can => can/src}/num.rs | 10 +- compiler/{src/can => can/src}/operator.rs | 0 compiler/{src/can => can/src}/pattern.rs | 11 +- compiler/{src/can => can/src}/problem.rs | 4 +- compiler/{src/can => can/src}/procedure.rs | 6 +- compiler/{src/can => can/src}/scope.rs | 6 +- compiler/{src/can => can/src}/string.rs | 0 compiler/can/tests/helpers/mod.rs | 126 +++++++++++ compiler/{ => can}/tests/test_canonicalize.rs | 11 +- compiler/src/builtins.rs | 2 +- compiler/src/constrain/builtins.rs | 11 +- compiler/src/constrain/expr.rs | 24 +-- compiler/src/constrain/module.rs | 9 +- compiler/src/constrain/pattern.rs | 10 +- compiler/src/crane/build.rs | 2 +- compiler/src/infer.rs | 21 -- compiler/src/lib.rs | 9 - compiler/src/llvm/build.rs | 2 +- compiler/src/load/mod.rs | 15 +- compiler/src/mono/expr.rs | 29 +-- compiler/src/mono/layout.rs | 18 +- compiler/src/pretty_print_types.rs | 16 +- compiler/src/reporting.rs | 4 +- compiler/src/solve.rs | 36 ++-- compiler/src/unify.rs | 14 +- compiler/src/unique_builtins.rs | 2 +- compiler/src/uniqueness/builtins.rs | 13 +- compiler/src/uniqueness/mod.rs | 39 ++-- compiler/src/uniqueness/sharing.rs | 4 +- compiler/tests/helpers/mod.rs | 40 +++- compiler/tests/test_gen.rs | 14 +- compiler/tests/test_infer.rs | 12 +- compiler/tests/test_load.rs | 6 +- compiler/tests/test_uniqueness_infer.rs | 8 +- compiler/tests/test_uniqueness_load.rs | 6 +- compiler/types/Cargo.toml | 20 ++ .../src}/boolean_algebra.rs | 0 compiler/types/src/lib.rs | 3 + compiler/{ => types}/src/subs.rs | 8 +- .../{src/types/mod.rs => types/src/types.rs} | 157 +------------- vendor/ena/Cargo.toml | 13 ++ vendor/ena/LICENSE-APACHE | 201 ++++++++++++++++++ vendor/ena/LICENSE-MIT | 25 +++ .../src/ena => vendor/ena/src}/bitvec.rs | 0 .../src/ena/mod.rs => vendor/ena/src/lib.rs | 3 + .../ena => vendor/ena/src}/snapshot_vec.rs | 0 .../ena/src}/unify/backing_vec.rs | 2 +- .../src/ena => vendor/ena/src}/unify/mod.rs | 0 vendor/pathfinding/Cargo.toml | 16 ++ .../graph.rs => vendor/pathfinding/src/lib.rs | 0 62 files changed, 910 insertions(+), 418 deletions(-) create mode 100644 compiler/can/Cargo.toml rename compiler/{src/can => can/src}/annotation.rs (96%) create mode 100644 compiler/can/src/constraint.rs rename compiler/{src/can => can/src}/def.rs (98%) rename compiler/{src/can => can/src}/env.rs (97%) create mode 100644 compiler/can/src/expected.rs rename compiler/{src/can => can/src}/expr.rs (98%) rename compiler/{src/can/mod.rs => can/src/lib.rs} (83%) rename compiler/{src/can => can/src}/module.rs (95%) rename compiler/{src/can => can/src}/num.rs (91%) rename compiler/{src/can => can/src}/operator.rs (100%) rename compiler/{src/can => can/src}/pattern.rs (98%) rename compiler/{src/can => can/src}/problem.rs (97%) rename compiler/{src/can => can/src}/procedure.rs (95%) rename compiler/{src/can => can/src}/scope.rs (97%) rename compiler/{src/can => can/src}/string.rs (100%) create mode 100644 compiler/can/tests/helpers/mod.rs rename compiler/{ => can}/tests/test_canonicalize.rs (99%) delete mode 100644 compiler/src/infer.rs create mode 100644 compiler/types/Cargo.toml rename compiler/{src/uniqueness => types/src}/boolean_algebra.rs (100%) create mode 100644 compiler/types/src/lib.rs rename compiler/{ => types}/src/subs.rs (99%) rename compiler/{src/types/mod.rs => types/src/types.rs} (83%) create mode 100644 vendor/ena/Cargo.toml create mode 100644 vendor/ena/LICENSE-APACHE create mode 100644 vendor/ena/LICENSE-MIT rename {compiler/src/ena => vendor/ena/src}/bitvec.rs (100%) rename compiler/src/ena/mod.rs => vendor/ena/src/lib.rs (94%) rename {compiler/src/ena => vendor/ena/src}/snapshot_vec.rs (100%) rename {compiler/src/ena => vendor/ena/src}/unify/backing_vec.rs (99%) rename {compiler/src/ena => vendor/ena/src}/unify/mod.rs (100%) create mode 100644 vendor/pathfinding/Cargo.toml rename compiler/src/graph.rs => vendor/pathfinding/src/lib.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index b2cc74b3b0..45338fff84 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -878,15 +878,38 @@ dependencies = [ "pretty_assertions", "quickcheck", "quickcheck_macros", + "roc_can", "roc_collections", "roc_module", "roc_parse", "roc_region", + "roc_types", "target-lexicon", "tokio", "wyhash", ] +[[package]] +name = "roc_can" +version = "0.1.0" +dependencies = [ + "bumpalo", + "im", + "im-rc", + "indoc", + "inlinable_string", + "maplit", + "pretty_assertions", + "quickcheck", + "quickcheck_macros", + "roc_collections", + "roc_module", + "roc_parse", + "roc_region", + "roc_types", + "ven_graph", +] + [[package]] name = "roc_collections" version = "0.1.0" @@ -930,6 +953,23 @@ dependencies = [ name = "roc_region" version = "0.1.0" +[[package]] +name = "roc_types" +version = "0.1.0" +dependencies = [ + "indoc", + "inlinable_string", + "maplit", + "pretty_assertions", + "quickcheck", + "quickcheck_macros", + "roc_collections", + "roc_module", + "roc_parse", + "roc_region", + "ven_ena", +] + [[package]] name = "rustc_version" version = "0.2.3" @@ -1076,6 +1116,20 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "63f18aa3b0e35fed5a0048f029558b1518095ffe2a0a31fb87c93dece93a4993" +[[package]] +name = "ven_ena" +version = "0.13.1" +dependencies = [ + "log", +] + +[[package]] +name = "ven_graph" +version = "2.0.5-pre" +dependencies = [ + "roc_collections", +] + [[package]] name = "version_check" version = "0.9.1" diff --git a/Cargo.toml b/Cargo.toml index fcc7ec0dcf..e645f9bd9f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,5 +5,9 @@ members = [ "compiler/region", "compiler/collections", "compiler/module", - "compiler/parse" + "compiler/parse", + "compiler/can", + "compiler/types", + "vendor/ena", + "vendor/pathfinding" ] diff --git a/compiler/Cargo.toml b/compiler/Cargo.toml index 781fdb7de2..c32e190896 100644 --- a/compiler/Cargo.toml +++ b/compiler/Cargo.toml @@ -9,6 +9,8 @@ roc_collections = { path = "./collections" } roc_region = { path = "./region" } roc_module = { path = "./module" } roc_parse = { path = "./parse" } +roc_types = { path = "./types" } +roc_can = { path = "./can" } log = "0.4.8" petgraph = { version = "0.4.5", optional = true } im = "14" # im and im-rc should always have the same version! diff --git a/compiler/can/Cargo.toml b/compiler/can/Cargo.toml new file mode 100644 index 0000000000..c9c76cefcc --- /dev/null +++ b/compiler/can/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "roc_can" +version = "0.1.0" +authors = ["Richard Feldman "] +edition = "2018" + +[dependencies] +roc_collections = { path = "../collections" } +roc_region = { path = "../region" } +roc_module = { path = "../module" } +roc_parse = { path = "../parse" } +roc_types = { path = "../types" } +ven_graph = { path = "../../vendor/pathfinding" } +im = "14" # im and im-rc should always have the same version! +im-rc = "14" # im and im-rc should always have the same version! +bumpalo = "2.6" +inlinable_string = "0.1.0" + +[dev-dependencies] +pretty_assertions = "0.5.1 " +maplit = "1.0.1" +indoc = "0.3.3" +quickcheck = "0.8" +quickcheck_macros = "0.8" diff --git a/compiler/src/can/annotation.rs b/compiler/can/src/annotation.rs similarity index 96% rename from compiler/src/can/annotation.rs rename to compiler/can/src/annotation.rs index e340ab47ea..4e8decb8c6 100644 --- a/compiler/src/can/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -1,8 +1,7 @@ -use crate::can; -use crate::can::env::Env; -use crate::can::scope::Scope; -use crate::subs::{VarStore, Variable}; -use crate::types::{Alias, Problem, Type}; +use crate::env::Env; +use crate::scope::Scope; +use roc_types::subs::{VarStore, Variable}; +use roc_types::types::{Alias, Problem, Type}; use roc_collections::all::{ImMap, MutMap, MutSet, SendMap}; use roc_module::ident::Ident; use roc_module::ident::{Lowercase, TagName}; @@ -120,7 +119,7 @@ fn can_annotation_help( match scope.lookup(&ident, region) { Ok(symbol) => symbol, Err(problem) => { - env.problem(crate::can::problem::Problem::RuntimeError(problem)); + env.problem(crate::problem::Problem::RuntimeError(problem)); return Type::Erroneous(Problem::UnrecognizedIdent(ident.into())); } @@ -131,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::can::problem::Problem::RuntimeError(problem)); + env.problem(crate::problem::Problem::RuntimeError(problem)); return Type::Erroneous(Problem::UnrecognizedIdent((*ident).into())); } @@ -185,7 +184,9 @@ fn can_annotation_help( Err((original_region, shadow)) => { let problem = Problem::Shadowed(original_region, shadow); - env.problem(can::problem::Problem::ErroneousAnnotation(problem.clone())); + env.problem(crate::problem::Problem::ErroneousAnnotation( + problem.clone(), + )); return Type::Erroneous(problem); } diff --git a/compiler/can/src/constraint.rs b/compiler/can/src/constraint.rs new file mode 100644 index 0000000000..f3d7da1252 --- /dev/null +++ b/compiler/can/src/constraint.rs @@ -0,0 +1,97 @@ +use crate::expected::{Expected, PExpected}; +use roc_collections::all::{ImMap, ImSet, SendMap}; +use roc_module::symbol::Symbol; +use roc_region::all::{Located, Region}; +use roc_types::subs::{VarStore, Variable}; +use roc_types::types::{Alias, PatternCategory, Type}; + +#[derive(Debug, Clone, PartialEq)] +pub enum Constraint { + Eq(Type, Expected, Region), + Lookup(Symbol, Expected, Region), + Pattern(Region, PatternCategory, Type, PExpected), + True, // Used for things that always unify, e.g. blanks and runtime errors + SaveTheEnvironment, + Let(Box), + And(Vec), +} + +impl Constraint { + pub fn instantiate_aliases(&mut self, var_store: &VarStore) { + Self::instantiate_aliases_help(self, &ImMap::default(), var_store, &mut ImSet::default()) + } + + fn instantiate_aliases_help( + &mut self, + aliases: &ImMap, + var_store: &VarStore, + introduced: &mut ImSet, + ) { + use Constraint::*; + + match self { + True | SaveTheEnvironment => {} + + Eq(typ, expected, _) => { + expected + .get_type_mut_ref() + .instantiate_aliases(aliases, var_store, introduced); + typ.instantiate_aliases(aliases, var_store, introduced); + } + + Lookup(_, expected, _) => { + expected + .get_type_mut_ref() + .instantiate_aliases(aliases, var_store, introduced); + } + + Pattern(_, _, typ, pexpected) => { + pexpected + .get_type_mut_ref() + .instantiate_aliases(aliases, var_store, introduced); + typ.instantiate_aliases(aliases, var_store, introduced); + } + + And(nested) => { + for c in nested.iter_mut() { + c.instantiate_aliases_help(aliases, var_store, introduced); + } + } + + Let(letcon) => { + let mut new_aliases = aliases.clone(); + for (k, v) in letcon.def_aliases.iter() { + new_aliases.insert(*k, v.clone()); + } + + let mut introduced = ImSet::default(); + for Located { value: typ, .. } in letcon.def_types.iter_mut() { + typ.instantiate_aliases(&new_aliases, var_store, &mut introduced); + } + + letcon.defs_constraint.instantiate_aliases_help( + &new_aliases, + var_store, + &mut introduced, + ); + letcon.ret_constraint.instantiate_aliases_help( + &new_aliases, + var_store, + &mut introduced, + ); + + letcon.flex_vars.extend(introduced); + } + } + } +} + +#[derive(Debug, Clone, PartialEq)] +pub struct LetConstraint { + pub rigid_vars: Vec, + pub flex_vars: Vec, + pub def_types: SendMap>, + pub def_aliases: SendMap, + pub defs_constraint: Constraint, + pub ret_constraint: Constraint, +} diff --git a/compiler/src/can/def.rs b/compiler/can/src/def.rs similarity index 98% rename from compiler/src/can/def.rs rename to compiler/can/src/def.rs index 8fa5786e61..b75ba8a662 100644 --- a/compiler/src/can/def.rs +++ b/compiler/can/src/def.rs @@ -1,26 +1,26 @@ -use crate::can::annotation::canonicalize_annotation; -use crate::can::env::Env; -use crate::can::expr::Expr::{self, *}; -use crate::can::expr::{ +use crate::annotation::canonicalize_annotation; +use crate::env::Env; +use crate::expr::Expr::{self, *}; +use crate::expr::{ canonicalize_expr, local_successors, references_from_call, references_from_local, Output, Recursive, }; -use crate::can::pattern::PatternType; -use crate::can::pattern::{bindings_from_patterns, canonicalize_pattern, Pattern}; -use crate::can::problem::Problem; -use crate::can::problem::RuntimeError; -use crate::can::procedure::References; -use crate::can::scope::Scope; -use crate::graph::{strongly_connected_components, topological_sort_into_groups}; -use crate::subs::{VarStore, Variable}; -use crate::types::{Alias, Type}; +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_region::all::{Located, Region}; +use roc_types::subs::{VarStore, Variable}; +use roc_types::types::{Alias, Type}; use std::collections::HashMap; use std::fmt::Debug; +use ven_graph::{strongly_connected_components, topological_sort_into_groups}; #[allow(clippy::type_complexity)] #[derive(Clone, Debug, PartialEq)] @@ -208,7 +208,7 @@ pub fn canonicalize_defs<'a>( make_tag_union_recursive(symbol, &mut can_ann.typ, var_store); } - let alias = crate::types::Alias { + let alias = roc_types::types::Alias { region: ann.region, vars: can_vars, typ: can_ann.typ, diff --git a/compiler/src/can/env.rs b/compiler/can/src/env.rs similarity index 97% rename from compiler/src/can/env.rs rename to compiler/can/src/env.rs index e538630902..10311425bf 100644 --- a/compiler/src/can/env.rs +++ b/compiler/can/src/env.rs @@ -1,5 +1,5 @@ -use crate::can::problem::{Problem, RuntimeError}; -use crate::can::procedure::References; +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}; diff --git a/compiler/can/src/expected.rs b/compiler/can/src/expected.rs new file mode 100644 index 0000000000..d6c0b27afe --- /dev/null +++ b/compiler/can/src/expected.rs @@ -0,0 +1,66 @@ +use crate::pattern::Pattern; +use roc_region::all::{Located, Region}; +use roc_types::types::{AnnotationSource, PReason, Reason}; + +#[derive(Debug, Clone, PartialEq)] +pub enum Expected { + NoExpectation(T), + FromAnnotation(Located, usize, AnnotationSource, T), + ForReason(Reason, T, Region), +} + +/// Like Expected, but for Patterns. +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum PExpected { + NoExpectation(T), + ForReason(PReason, T, Region), +} + +impl PExpected { + pub fn get_type(self) -> T { + match self { + PExpected::NoExpectation(val) => val, + PExpected::ForReason(_, val, _) => val, + } + } + + pub fn get_type_ref(&self) -> &T { + match self { + PExpected::NoExpectation(val) => val, + PExpected::ForReason(_, val, _) => val, + } + } + + pub fn get_type_mut_ref(&mut self) -> &mut T { + match self { + PExpected::NoExpectation(val) => val, + PExpected::ForReason(_, val, _) => val, + } + } +} + +impl Expected { + pub fn get_type(self) -> T { + match self { + Expected::NoExpectation(val) => val, + Expected::ForReason(_, val, _) => val, + Expected::FromAnnotation(_, _, _, val) => val, + } + } + + pub fn get_type_ref(&self) -> &T { + match self { + Expected::NoExpectation(val) => val, + Expected::ForReason(_, val, _) => val, + Expected::FromAnnotation(_, _, _, val) => val, + } + } + + pub fn get_type_mut_ref(&mut self) -> &mut T { + match self { + Expected::NoExpectation(val) => val, + Expected::ForReason(_, val, _) => val, + Expected::FromAnnotation(_, _, _, val) => val, + } + } +} diff --git a/compiler/src/can/expr.rs b/compiler/can/src/expr.rs similarity index 98% rename from compiler/src/can/expr.rs rename to compiler/can/src/expr.rs index c6e72f6ac5..5bb644ee43 100644 --- a/compiler/src/can/expr.rs +++ b/compiler/can/src/expr.rs @@ -1,22 +1,22 @@ -use crate::can::def::{can_defs_with_return, Def}; -use crate::can::env::Env; -use crate::can::num::{ +use crate::def::{can_defs_with_return, Def}; +use crate::env::Env; +use crate::num::{ finish_parsing_base, finish_parsing_float, finish_parsing_int, float_expr_from_result, int_expr_from_result, }; -use crate::can::pattern::PatternType::*; -use crate::can::pattern::{canonicalize_pattern, Pattern}; -use crate::can::problem::{Problem, RuntimeError}; -use crate::can::procedure::References; -use crate::can::scope::Scope; -use crate::subs::{VarStore, Variable}; -use crate::types::Alias; +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_types::types::Alias; use roc_collections::all::{ImSet, MutMap, MutSet, SendMap}; use roc_module::ident::{Lowercase, TagName}; use roc_module::symbol::Symbol; use roc_parse::ast; use roc_parse::operator::CalledVia; use roc_region::all::{Located, Region}; +use roc_types::subs::{VarStore, Variable}; use std::fmt::Debug; use std::i64; use std::ops::Neg; diff --git a/compiler/src/can/mod.rs b/compiler/can/src/lib.rs similarity index 83% rename from compiler/src/can/mod.rs rename to compiler/can/src/lib.rs index f9211e2c51..2c38c6b3d7 100644 --- a/compiler/src/can/mod.rs +++ b/compiler/can/src/lib.rs @@ -1,6 +1,8 @@ pub mod annotation; +pub mod constraint; pub mod def; pub mod env; +pub mod expected; pub mod expr; pub mod module; pub mod num; diff --git a/compiler/src/can/module.rs b/compiler/can/src/module.rs similarity index 95% rename from compiler/src/can/module.rs rename to compiler/can/src/module.rs index 80a358c535..0b6978e70c 100644 --- a/compiler/src/can/module.rs +++ b/compiler/can/src/module.rs @@ -1,12 +1,12 @@ -use crate::can::def::{canonicalize_defs, sort_can_defs, Declaration}; -use crate::can::env::Env; -use crate::can::expr::Output; -use crate::can::operator::desugar_def; -use crate::can::pattern::PatternType; -use crate::can::problem::{Problem, RuntimeError}; -use crate::can::scope::Scope; -use crate::subs::{VarStore, Variable}; -use crate::types::Alias; +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 roc_types::subs::{VarStore, Variable}; +use roc_types::types::Alias; use bumpalo::Bump; use roc_collections::all::{MutMap, MutSet}; use roc_module::ident::Ident; @@ -139,7 +139,7 @@ pub fn canonicalize_module_defs<'a>( match sort_can_defs(&mut env, defs, Output::default()) { (Ok(declarations), output) => { - use crate::can::def::Declaration::*; + use crate::def::Declaration::*; let mut exposed_vars_by_symbol = Vec::with_capacity(exposed_symbols.len()); diff --git a/compiler/src/can/num.rs b/compiler/can/src/num.rs similarity index 91% rename from compiler/src/can/num.rs rename to compiler/can/src/num.rs index 0282c5bf9e..2f1667e890 100644 --- a/compiler/src/can/num.rs +++ b/compiler/can/src/num.rs @@ -1,8 +1,8 @@ -use crate::can::env::Env; -use crate::can::expr::Expr; -use crate::can::problem::Problem; -use crate::can::problem::RuntimeError::*; -use crate::subs::VarStore; +use crate::env::Env; +use crate::expr::Expr; +use crate::problem::Problem; +use crate::problem::RuntimeError::*; +use roc_types::subs::VarStore; use roc_parse::ast::Base; use std::i64; diff --git a/compiler/src/can/operator.rs b/compiler/can/src/operator.rs similarity index 100% rename from compiler/src/can/operator.rs rename to compiler/can/src/operator.rs diff --git a/compiler/src/can/pattern.rs b/compiler/can/src/pattern.rs similarity index 98% rename from compiler/src/can/pattern.rs rename to compiler/can/src/pattern.rs index 14a7da5355..4f71d7b58b 100644 --- a/compiler/src/can/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -1,13 +1,12 @@ -use crate::can::env::Env; -use crate::can::num::{finish_parsing_base, finish_parsing_float, finish_parsing_int}; -use crate::can::problem::{Problem, RuntimeError}; -use crate::can::scope::Scope; -use crate::subs::VarStore; -use crate::subs::Variable; +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_region::all::{Located, Region}; +use roc_types::subs::{VarStore, Variable}; /// A pattern, including possible problems (e.g. shadowing) so that /// codegen can generate a runtime error if this pattern is reached. diff --git a/compiler/src/can/problem.rs b/compiler/can/src/problem.rs similarity index 97% rename from compiler/src/can/problem.rs rename to compiler/can/src/problem.rs index 09ea30b8c6..03eacf0798 100644 --- a/compiler/src/can/problem.rs +++ b/compiler/can/src/problem.rs @@ -1,10 +1,10 @@ -use crate::can::pattern::PatternType; -use crate::types; +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)] diff --git a/compiler/src/can/procedure.rs b/compiler/can/src/procedure.rs similarity index 95% rename from compiler/src/can/procedure.rs rename to compiler/can/src/procedure.rs index fc0ff1f642..044660b0ea 100644 --- a/compiler/src/can/procedure.rs +++ b/compiler/can/src/procedure.rs @@ -1,6 +1,6 @@ -use crate::can::expr::Expr; -use crate::can::pattern::Pattern; -use crate::subs::Variable; +use crate::expr::Expr; +use crate::pattern::Pattern; +use roc_types::subs::Variable; use roc_collections::all::ImSet; use roc_module::symbol::Symbol; use roc_region::all::{Located, Region}; diff --git a/compiler/src/can/scope.rs b/compiler/can/src/scope.rs similarity index 97% rename from compiler/src/can/scope.rs rename to compiler/can/src/scope.rs index 50ea388e2a..c2d3fd3c9a 100644 --- a/compiler/src/can/scope.rs +++ b/compiler/can/src/scope.rs @@ -1,10 +1,10 @@ -use crate::can::problem::RuntimeError; -use crate::subs::Variable; -use crate::types::{Alias, Type}; +use crate::problem::RuntimeError; use roc_collections::all::ImMap; use roc_module::ident::{Ident, Lowercase}; use roc_module::symbol::{IdentIds, ModuleId, Symbol}; use roc_region::all::{Located, Region}; +use roc_types::subs::Variable; +use roc_types::types::{Alias, Type}; #[derive(Clone, Debug, PartialEq)] pub struct Scope { diff --git a/compiler/src/can/string.rs b/compiler/can/src/string.rs similarity index 100% rename from compiler/src/can/string.rs rename to compiler/can/src/string.rs diff --git a/compiler/can/tests/helpers/mod.rs b/compiler/can/tests/helpers/mod.rs new file mode 100644 index 0000000000..815bc6bec5 --- /dev/null +++ b/compiler/can/tests/helpers/mod.rs @@ -0,0 +1,126 @@ +extern crate bumpalo; + +use self::bumpalo::Bump; +use roc_can::env::Env; +use roc_can::expr::Output; +use roc_can::expr::{canonicalize_expr, Expr}; +use roc_can::operator; +use roc_can::problem::Problem; +use roc_can::scope::Scope; +use roc_collections::all::MutMap; +use roc_module::symbol::{IdentIds, Interns, ModuleId, ModuleIds}; +use roc_parse::ast::{self, Attempting}; +use roc_parse::blankspace::space0_before; +use roc_parse::parser::{loc, Fail, Parser, State}; +use roc_region::all::{Located, Region}; +use roc_types::subs::{VarStore, Variable}; +use std::hash::Hash; + +pub fn test_home() -> ModuleId { + ModuleIds::default().get_or_insert(&"Test".into()) +} + +#[allow(dead_code)] +pub fn parse_with<'a>(arena: &'a Bump, input: &'a str) -> Result, Fail> { + parse_loc_with(arena, input).map(|loc_expr| loc_expr.value) +} + +#[allow(dead_code)] +pub fn parse_loc_with<'a>(arena: &'a Bump, input: &'a str) -> Result>, Fail> { + let state = State::new(&input, Attempting::Module); + let parser = space0_before(loc(roc_parse::expr::expr(0)), 0); + let answer = parser.parse(&arena, state); + + answer + .map(|(loc_expr, _)| loc_expr) + .map_err(|(fail, _)| fail) +} + +#[allow(dead_code)] +pub fn can_expr(expr_str: &str) -> CanExprOut { + can_expr_with(&Bump::new(), test_home(), expr_str) +} + +pub struct CanExprOut { + pub loc_expr: Located, + pub output: Output, + pub problems: Vec, + pub home: ModuleId, + pub interns: Interns, + pub var_store: VarStore, + pub var: Variable, +} + +#[allow(dead_code)] +pub fn can_expr_with(arena: &Bump, home: ModuleId, expr_str: &str) -> CanExprOut { + let loc_expr = parse_loc_with(&arena, expr_str).unwrap_or_else(|e| { + panic!( + "can_expr_with() got a parse error when attempting to canonicalize:\n\n{:?} {:?}", + expr_str, e + ) + }); + + let var_store = VarStore::default(); + let var = var_store.fresh(); + let module_ids = ModuleIds::default(); + + // Desugar operators (convert them to Apply calls, taking into account + // operator precedence and associativity rules), before doing other canonicalization. + // + // If we did this *during* canonicalization, then each time we + // visited a BinOp node we'd recursively try to apply this to each of its nested + // operators, and then again on *their* nested operators, ultimately applying the + // rules multiple times unnecessarily. + let loc_expr = operator::desugar_expr(arena, &loc_expr); + + let mut scope = Scope::new(home); + let dep_idents = IdentIds::exposed_builtins(0); + let mut env = Env::new(home, dep_idents, &module_ids, IdentIds::default()); + let (loc_expr, output) = canonicalize_expr( + &mut env, + &var_store, + &mut scope, + Region::zero(), + &loc_expr.value, + ); + + let mut all_ident_ids = MutMap::default(); + + // When pretty printing types, we may need the exposed builtins, + // so include them in the Interns we'll ultimately return. + for (module_id, ident_ids) in IdentIds::exposed_builtins(0) { + all_ident_ids.insert(module_id, ident_ids); + } + + all_ident_ids.insert(home, env.ident_ids); + + let interns = Interns { + module_ids: env.module_ids.clone(), + all_ident_ids, + }; + + CanExprOut { + loc_expr, + output, + problems: env.problems, + home: env.home, + var_store, + interns, + var, + } +} + +#[allow(dead_code)] +pub fn mut_map_from_pairs(pairs: I) -> MutMap +where + I: IntoIterator, + K: Hash + Eq, +{ + let mut answer = MutMap::default(); + + for (key, value) in pairs { + answer.insert(key, value); + } + + answer +} diff --git a/compiler/tests/test_canonicalize.rs b/compiler/can/tests/test_canonicalize.rs similarity index 99% rename from compiler/tests/test_canonicalize.rs rename to compiler/can/tests/test_canonicalize.rs index 77b1d0a653..e80ce7c0db 100644 --- a/compiler/tests/test_canonicalize.rs +++ b/compiler/can/tests/test_canonicalize.rs @@ -4,7 +4,8 @@ extern crate pretty_assertions; extern crate indoc; extern crate bumpalo; -extern crate roc; +extern crate roc_can; +extern crate roc_parse; extern crate roc_region; mod helpers; @@ -13,9 +14,9 @@ mod helpers; mod test_canonicalize { use crate::helpers::{can_expr_with, test_home, CanExprOut}; use bumpalo::Bump; - use roc::can::expr::Expr::{self, *}; - use roc::can::expr::Recursive; - use roc::can::problem::{Problem, RuntimeError}; + use roc_can::expr::Expr::{self, *}; + use roc_can::expr::Recursive; + use roc_can::problem::{Problem, RuntimeError}; use roc_region::all::{Located, Region}; use std::{f64, i64}; @@ -221,7 +222,7 @@ mod test_canonicalize { // ); // } - fn get_closure(expr: &Expr, i: usize) -> roc::can::expr::Recursive { + fn get_closure(expr: &Expr, i: usize) -> roc_can::expr::Recursive { match expr { LetRec(assignments, body, _, _) => { match &assignments.get(i).map(|def| &def.loc_expr.value) { diff --git a/compiler/src/builtins.rs b/compiler/src/builtins.rs index a713eace22..b4e5e09042 100644 --- a/compiler/src/builtins.rs +++ b/compiler/src/builtins.rs @@ -1,9 +1,9 @@ use crate::solve::{BuiltinAlias, SolvedType}; -use crate::subs::VarId; use roc_collections::all::{default_hasher, MutMap}; use roc_module::ident::TagName; use roc_module::symbol::Symbol; use roc_region::all::{Located, Region}; +use roc_types::subs::VarId; use std::collections::HashMap; #[derive(Clone, Copy)] diff --git a/compiler/src/constrain/builtins.rs b/compiler/src/constrain/builtins.rs index b3de7d2977..f4e093339f 100644 --- a/compiler/src/constrain/builtins.rs +++ b/compiler/src/constrain/builtins.rs @@ -1,11 +1,12 @@ -use crate::subs::Variable; -use crate::types::Constraint::{self, *}; -use crate::types::Expected::{self, *}; -use crate::types::Type::{self, *}; -use crate::types::{LetConstraint, Reason}; +use roc_can::constraint::Constraint::{self, *}; +use roc_can::constraint::LetConstraint; +use roc_can::expected::Expected::{self, *}; use roc_collections::all::SendMap; use roc_module::symbol::Symbol; use roc_region::all::Region; +use roc_types::subs::Variable; +use roc_types::types::Reason; +use roc_types::types::Type::{self, *}; #[inline(always)] pub fn int_literal(num_var: Variable, expected: Expected, region: Region) -> Constraint { diff --git a/compiler/src/constrain/expr.rs b/compiler/src/constrain/expr.rs index 18d265c970..74223352db 100644 --- a/compiler/src/constrain/expr.rs +++ b/compiler/src/constrain/expr.rs @@ -1,23 +1,23 @@ -use crate::can::def::{Declaration, Def}; -use crate::can::expr::Expr::{self, *}; -use crate::can::expr::Field; -use crate::can::pattern::Pattern; use crate::constrain::builtins::{ empty_list_type, float_literal, int_literal, list_type, str_type, }; use crate::constrain::pattern::{constrain_pattern, PatternState}; -use crate::subs::Variable; -use crate::types::Alias; -use crate::types::AnnotationSource::{self, *}; -use crate::types::Constraint::{self, *}; -use crate::types::Expected::{self, *}; -use crate::types::PReason; -use crate::types::Type::{self, *}; -use crate::types::{LetConstraint, PExpected, Reason}; +use roc_can::constraint::Constraint::{self, *}; +use roc_can::constraint::LetConstraint; +use roc_can::def::{Declaration, Def}; +use roc_can::expected::Expected::{self, *}; +use roc_can::expected::PExpected; +use roc_can::expr::Expr::{self, *}; +use roc_can::expr::Field; +use roc_can::pattern::Pattern; use roc_collections::all::{ImMap, SendMap}; use roc_module::ident::{Lowercase, TagName}; use roc_module::symbol::{ModuleId, Symbol}; use roc_region::all::{Located, Region}; +use roc_types::subs::Variable; +use roc_types::types::AnnotationSource::{self, *}; +use roc_types::types::Type::{self, *}; +use roc_types::types::{Alias, PReason, Reason}; /// This is for constraining Defs #[derive(Default, Debug)] diff --git a/compiler/src/constrain/module.rs b/compiler/src/constrain/module.rs index 389c319cb0..ad6ab01211 100644 --- a/compiler/src/constrain/module.rs +++ b/compiler/src/constrain/module.rs @@ -1,15 +1,16 @@ use crate::builtins; -use crate::can::def::Declaration; use crate::constrain::expr::constrain_decls; use crate::solve::{BuiltinAlias, SolvedAtom, SolvedType}; -use crate::subs::{VarId, VarStore, Variable}; -use crate::types::{Alias, Constraint, LetConstraint, Type}; use crate::uniqueness; -use crate::uniqueness::boolean_algebra::{Atom, Bool}; +use roc_can::constraint::{Constraint, LetConstraint}; +use roc_can::def::Declaration; use roc_collections::all::{ImMap, MutMap, SendMap}; use roc_module::ident::Lowercase; use roc_module::symbol::{ModuleId, Symbol}; use roc_region::all::Located; +use roc_types::boolean_algebra::{Atom, Bool}; +use roc_types::subs::{VarId, VarStore, Variable}; +use roc_types::types::{Alias, Type}; #[inline(always)] pub fn constrain_module( diff --git a/compiler/src/constrain/pattern.rs b/compiler/src/constrain/pattern.rs index 35bda1cc50..3535773c2c 100644 --- a/compiler/src/constrain/pattern.rs +++ b/compiler/src/constrain/pattern.rs @@ -1,12 +1,14 @@ -use crate::can::pattern::Pattern::{self, *}; -use crate::can::pattern::RecordDestruct; use crate::constrain::builtins; -use crate::subs::Variable; -use crate::types::{Constraint, Expected, PExpected, PatternCategory, Type}; +use roc_can::constraint::Constraint; +use roc_can::expected::{Expected, PExpected}; +use roc_can::pattern::Pattern::{self, *}; +use roc_can::pattern::RecordDestruct; use roc_collections::all::SendMap; use roc_module::ident::Lowercase; use roc_module::symbol::Symbol; use roc_region::all::{Located, Region}; +use roc_types::subs::Variable; +use roc_types::types::{PatternCategory, Type}; pub struct PatternState { pub headers: SendMap>, diff --git a/compiler/src/crane/build.rs b/compiler/src/crane/build.rs index 22a36fa087..73142030c4 100644 --- a/compiler/src/crane/build.rs +++ b/compiler/src/crane/build.rs @@ -16,9 +16,9 @@ use cranelift_module::{Backend, FuncId, Linkage, Module}; use crate::crane::convert::{sig_from_layout, type_from_layout}; use crate::mono::expr::{Expr, Proc, Procs}; use crate::mono::layout::{Builtin, Layout}; -use crate::subs::{Subs, Variable}; use roc_collections::all::ImMap; use roc_module::symbol::{Interns, Symbol}; +use roc_types::subs::{Subs, Variable}; type Scope = ImMap; diff --git a/compiler/src/infer.rs b/compiler/src/infer.rs deleted file mode 100644 index fd88e8a74b..0000000000 --- a/compiler/src/infer.rs +++ /dev/null @@ -1,21 +0,0 @@ -use crate::solve::{self, Solved}; -use crate::subs::{Content, Subs, Variable}; -use crate::types::{Constraint, Problem}; -use roc_collections::all::{MutMap, SendMap}; - -pub fn infer_expr( - subs: Subs, - problems: &mut Vec, - constraint: &Constraint, - expr_var: Variable, -) -> (Content, Solved) { - let env = solve::Env { - aliases: MutMap::default(), - vars_by_symbol: SendMap::default(), - }; - let (solved, _) = solve::run(&env, problems, subs, constraint); - - let content = solved.inner().get_without_compacting(expr_var).content; - - (content, solved) -} diff --git a/compiler/src/lib.rs b/compiler/src/lib.rs index 9ad683a932..0569865b10 100644 --- a/compiler/src/lib.rs +++ b/compiler/src/lib.rs @@ -11,8 +11,6 @@ // re-enable this when working on performance optimizations than have it block PRs. #![allow(clippy::large_enum_variant)] -pub mod can; -pub mod graph; pub mod uniqueness; pub mod string; @@ -22,18 +20,11 @@ pub mod unique_builtins; pub mod constrain; pub mod crane; -pub mod ena; pub mod fmt; -pub mod infer; pub mod llvm; pub mod load; pub mod mono; pub mod pretty_print_types; pub mod reporting; pub mod solve; -pub mod subs; -pub mod types; pub mod unify; - -#[macro_use] -extern crate log; diff --git a/compiler/src/llvm/build.rs b/compiler/src/llvm/build.rs index aff74ec951..bc5367c19a 100644 --- a/compiler/src/llvm/build.rs +++ b/compiler/src/llvm/build.rs @@ -11,9 +11,9 @@ use inkwell::{FloatPredicate, IntPredicate}; use crate::llvm::convert::{basic_type_from_layout, get_fn_type}; use crate::mono::expr::{Expr, Proc, Procs}; use crate::mono::layout::Layout; -use crate::subs::{Subs, Variable}; use roc_collections::all::ImMap; use roc_module::symbol::{Interns, Symbol}; +use roc_types::subs::{Subs, Variable}; /// This is for Inkwell's FunctionValue::verify - we want to know the verification /// output in debug builds, but we don't want it to print to stdout in release builds! diff --git a/compiler/src/load/mod.rs b/compiler/src/load/mod.rs index 3441688aeb..662411fc89 100644 --- a/compiler/src/load/mod.rs +++ b/compiler/src/load/mod.rs @@ -1,16 +1,14 @@ use crate::builtins; use crate::builtins::StdLib; -use crate::can; -use crate::can::def::Declaration; -use crate::can::module::{canonicalize_module_defs, ModuleOutput}; use crate::constrain::module::{ constrain_imported_aliases, constrain_imported_values, constrain_module, load_builtin_aliases, Import, }; use crate::solve::{self, BuiltinAlias, ExposedModuleTypes, Solved, SolvedType, SubsByModule}; -use crate::subs::{Subs, VarStore, Variable}; -use crate::types::{self, Alias, Constraint}; use bumpalo::Bump; +use roc_can; +use roc_can::def::Declaration; +use roc_can::module::{canonicalize_module_defs, ModuleOutput}; use roc_collections::all::{default_hasher, MutMap, MutSet, SendMap}; use roc_module::ident::{Ident, Lowercase, ModuleName}; use roc_module::symbol::{IdentIds, Interns, ModuleId, ModuleIds, Symbol}; @@ -18,6 +16,9 @@ use roc_parse::ast::{self, Attempting, ExposesEntry, ImportsEntry, InterfaceHead use roc_parse::module::module_defs; use roc_parse::parser::{Fail, Parser, State}; use roc_region::all::{Located, Region}; +use roc_types::subs::{Subs, VarStore, Variable}; +use roc_types::types::{self, Alias}; +use roc_can::constraint::{Constraint}; use std::collections::{HashMap, HashSet}; use std::fs::read_to_string; use std::io; @@ -49,7 +50,7 @@ pub struct LoadedModule { pub module_id: ModuleId, pub interns: Interns, pub solved: Solved, - pub can_problems: Vec, + pub can_problems: Vec, pub type_problems: Vec, pub declarations: Vec, } @@ -83,7 +84,7 @@ enum Msg { module: Module, constraint: Constraint, ident_ids: IdentIds, - problems: Vec, + problems: Vec, var_store: VarStore, }, Solved { diff --git a/compiler/src/mono/expr.rs b/compiler/src/mono/expr.rs index d2579a3514..8bce087a27 100644 --- a/compiler/src/mono/expr.rs +++ b/compiler/src/mono/expr.rs @@ -1,13 +1,13 @@ -use crate::can::pattern::Pattern; -use crate::can::{self}; use crate::mono::layout::{Builtin, Layout}; -use crate::subs::{Content, Subs, Variable}; use bumpalo::collections::Vec; use bumpalo::Bump; +use roc_can::pattern::Pattern; +use roc_can::{self}; use roc_collections::all::MutMap; use roc_module::ident::{Lowercase, TagName}; use roc_module::symbol::{IdentIds, ModuleId, Symbol}; use roc_region::all::Located; +use roc_types::subs::{Content, Subs, Variable}; pub type Procs<'a> = MutMap>>; @@ -115,7 +115,7 @@ impl<'a> Expr<'a> { pub fn new( arena: &'a Bump, subs: &'a Subs, - can_expr: can::expr::Expr, + can_expr: roc_can::expr::Expr, procs: &mut Procs<'a>, home: ModuleId, ident_ids: &mut IdentIds, @@ -133,12 +133,12 @@ impl<'a> Expr<'a> { fn from_can<'a>( env: &mut Env<'a, '_>, - can_expr: can::expr::Expr, + can_expr: roc_can::expr::Expr, procs: &mut Procs<'a>, name: Option, ) -> Expr<'a> { - use crate::can::expr::Expr::*; - use crate::can::pattern::Pattern::*; + use roc_can::expr::Expr::*; + use roc_can::pattern::Pattern::*; match can_expr { Int(_, val) => Expr::Int(val), @@ -349,7 +349,7 @@ fn from_can<'a>( fn add_closure<'a>( env: &mut Env<'a, '_>, symbol: Symbol, - can_body: can::expr::Expr, + can_body: roc_can::expr::Expr, ret_var: Variable, loc_args: &[(Variable, Located)], procs: &mut Procs<'a>, @@ -396,12 +396,12 @@ fn add_closure<'a>( fn store_pattern<'a>( env: &mut Env<'a, '_>, can_pat: Pattern, - can_expr: can::expr::Expr, + can_expr: roc_can::expr::Expr, var: Variable, procs: &mut Procs<'a>, stored: &mut Vec<'a, (Symbol, Variable, Expr<'a>)>, ) { - use crate::can::pattern::Pattern::*; + use roc_can::pattern::Pattern::*; // If we're defining a named closure, insert it into Procs and then // remove the Let. When code gen later goes to look it up, it'll be in Procs! @@ -442,11 +442,14 @@ fn from_can_when<'a>( env: &mut Env<'a, '_>, cond_var: Variable, expr_var: Variable, - loc_cond: Located, - branches: std::vec::Vec<(Located, Located)>, + loc_cond: Located, + branches: std::vec::Vec<( + Located, + Located, + )>, procs: &mut Procs<'a>, ) -> Expr<'a> { - use crate::can::pattern::Pattern::*; + use roc_can::pattern::Pattern::*; match branches.len() { 0 => { diff --git a/compiler/src/mono/layout.rs b/compiler/src/mono/layout.rs index ceb5d2de64..b35f09bbac 100644 --- a/compiler/src/mono/layout.rs +++ b/compiler/src/mono/layout.rs @@ -1,9 +1,9 @@ -use crate::subs::{Content, FlatType, Subs, Variable}; use bumpalo::collections::Vec; use bumpalo::Bump; use roc_collections::all::MutMap; use roc_module::ident::{Lowercase, TagName}; use roc_module::symbol::Symbol; +use roc_types::subs::{Content, FlatType, Subs, Variable}; /// Types for code gen must be monomorphic. No type variables allowed! #[derive(Clone, Debug, PartialEq, Eq)] @@ -34,7 +34,7 @@ impl<'a> Layout<'a> { /// Panics if given a FlexVar or RigidVar, since those should have been /// monomorphized away already! pub fn from_content(arena: &'a Bump, content: Content, subs: &Subs) -> Result { - use crate::subs::Content::*; + use roc_types::subs::Content::*; match content { var @ FlexVar(_) | var @ RigidVar(_) => { @@ -103,7 +103,7 @@ fn layout_from_flat_type<'a>( flat_type: FlatType, subs: &Subs, ) -> Result, ()> { - use crate::subs::FlatType::*; + use roc_types::subs::FlatType::*; match flat_type { Apply(symbol, args) => { @@ -253,8 +253,8 @@ fn layout_from_flat_type<'a>( } fn layout_from_num_content<'a>(content: Content) -> Result, ()> { - use crate::subs::Content::*; - use crate::subs::FlatType::*; + use roc_types::subs::Content::*; + use roc_types::subs::FlatType::*; match content { var @ FlexVar(_) | var @ RigidVar(_) => { @@ -287,8 +287,8 @@ fn flatten_union( ext_var: Variable, subs: &Subs, ) { - use crate::subs::Content::*; - use crate::subs::FlatType::*; + use roc_types::subs::Content::*; + use roc_types::subs::FlatType::*; match subs.get_without_compacting(ext_var).content { Structure(EmptyTagUnion) => (), @@ -308,8 +308,8 @@ fn flatten_union( /// Recursively inline the contents ext_var into this record until we have /// a flat record containing all the fields. fn flatten_record(fields: &mut MutMap, ext_var: Variable, subs: &Subs) { - use crate::subs::Content::*; - use crate::subs::FlatType::*; + use roc_types::subs::Content::*; + use roc_types::subs::FlatType::*; match subs.get_without_compacting(ext_var).content { Structure(EmptyRecord) => (), diff --git a/compiler/src/pretty_print_types.rs b/compiler/src/pretty_print_types.rs index bb46dad0c7..d4f9168746 100644 --- a/compiler/src/pretty_print_types.rs +++ b/compiler/src/pretty_print_types.rs @@ -1,9 +1,9 @@ -use crate::subs::{Content, FlatType, Subs, Variable}; -use crate::types::name_type_var; -use crate::uniqueness::boolean_algebra::{Atom, Bool}; use roc_collections::all::{ImSet, MutMap, MutSet}; use roc_module::ident::{Lowercase, TagName}; use roc_module::symbol::{Interns, ModuleId, Symbol}; +use roc_types::boolean_algebra::{Atom, Bool}; +use roc_types::subs::{Content, FlatType, Subs, Variable}; +use roc_types::types::name_type_var; static WILDCARD: &str = "*"; static EMPTY_RECORD: &str = "{}"; @@ -74,8 +74,8 @@ fn find_names_needed( root_appearances: &mut MutMap, names_taken: &mut MutSet, ) { - use crate::subs::Content::*; - use crate::subs::FlatType::*; + use roc_types::subs::Content::*; + use roc_types::subs::FlatType::*; while let Some((recursive, _)) = subs.occurs(variable) { if let Content::Structure(FlatType::TagUnion(tags, ext_var)) = subs.get(recursive).content { @@ -230,7 +230,7 @@ fn name_root( } fn set_root_name(root: Variable, name: &Lowercase, subs: &mut Subs) { - use crate::subs::Content::*; + use roc_types::subs::Content::*; let mut descriptor = subs.get(root); @@ -263,7 +263,7 @@ pub fn content_to_string( } fn write_content(env: &Env, content: Content, subs: &mut Subs, buf: &mut String, parens: Parens) { - use crate::subs::Content::*; + use roc_types::subs::Content::*; match content { FlexVar(Some(name)) => buf.push_str(name.as_str()), @@ -337,7 +337,7 @@ fn write_flat_type( buf: &mut String, parens: Parens, ) { - use crate::subs::FlatType::*; + use roc_types::subs::FlatType::*; match flat_type { Apply(symbol, args) => write_apply(env, symbol, args, subs, buf, parens), diff --git a/compiler/src/reporting.rs b/compiler/src/reporting.rs index 65ad298a05..ae3b7f6f95 100644 --- a/compiler/src/reporting.rs +++ b/compiler/src/reporting.rs @@ -1,8 +1,8 @@ -use crate::can::problem::Problem; use crate::pretty_print_types::content_to_string; -use crate::subs::{Content, Subs}; +use roc_can::problem::Problem; use roc_module::symbol::{Interns, ModuleId, Symbol}; use roc_region::all::Region; +use roc_types::subs::{Content, Subs}; use std::path::PathBuf; /// A textual report. diff --git a/compiler/src/solve.rs b/compiler/src/solve.rs index f8622b8811..bfada3fb4e 100644 --- a/compiler/src/solve.rs +++ b/compiler/src/solve.rs @@ -1,14 +1,16 @@ -use crate::subs::{Content, Descriptor, FlatType, Mark, OptVariable, Rank, Subs, VarId, Variable}; -use crate::types::Alias; -use crate::types::Constraint::{self, *}; -use crate::types::Problem; -use crate::types::Type::{self, *}; use crate::unify::{unify, Unified}; -use crate::uniqueness::boolean_algebra::{self, Atom}; +use roc_can::constraint::Constraint::{self, *}; use roc_collections::all::{ImMap, MutMap, SendMap}; use roc_module::ident::{Lowercase, TagName}; use roc_module::symbol::{ModuleId, Symbol}; use roc_region::all::{Located, Region}; +use roc_types::boolean_algebra::{self, Atom}; +use roc_types::subs::{ + Content, Descriptor, FlatType, Mark, OptVariable, Rank, Subs, VarId, Variable, +}; +use roc_types::types::Alias; +use roc_types::types::Problem; +use roc_types::types::Type::{self, *}; // Type checking system adapted from Elm by Evan Czaplicki, BSD-3-Clause Licensed // https://github.com/elm/compiler @@ -83,7 +85,7 @@ impl SolvedType { } pub fn from_type(solved_subs: &Solved, typ: Type) -> Self { - use crate::types::Type::*; + use roc_types::types::Type::*; match typ { EmptyRec => SolvedType::EmptyRecord, @@ -207,7 +209,7 @@ impl SolvedType { } fn from_flat_type(subs: &Subs, flat_type: FlatType) -> Self { - use crate::subs::FlatType::*; + use roc_types::subs::FlatType::*; match flat_type { Apply(symbol, args) => { @@ -653,12 +655,14 @@ fn solve( .get(next_rank) .iter() .filter(|var| { - subs.get_without_compacting(crate::subs::Variable::clone(var)) - .rank - .into_usize() + subs.get_without_compacting(roc_types::subs::Variable::clone( + var, + )) + .rank + .into_usize() > next_rank.into_usize() }) - .collect::>(); + .collect::>(); offenders.is_empty() }); @@ -1191,8 +1195,8 @@ fn adjust_rank_content( group_rank: Rank, content: Content, ) -> Rank { - use crate::subs::Content::*; - use crate::subs::FlatType::*; + use roc_types::subs::Content::*; + use roc_types::subs::FlatType::*; match content { FlexVar(_) | RigidVar(_) | Error => group_rank, @@ -1313,8 +1317,8 @@ fn deep_copy_var_help( pools: &mut Pools, var: Variable, ) -> Variable { - use crate::subs::Content::*; - use crate::subs::FlatType::*; + use roc_types::subs::Content::*; + use roc_types::subs::FlatType::*; let desc = subs.get_without_compacting(var); diff --git a/compiler/src/unify.rs b/compiler/src/unify.rs index 707ee6eb70..ebacd631e2 100644 --- a/compiler/src/unify.rs +++ b/compiler/src/unify.rs @@ -1,10 +1,10 @@ -use crate::subs::Content::{self, *}; -use crate::subs::{Descriptor, FlatType, Mark, OptVariable, Subs, Variable}; -use crate::types::{Mismatch, Problem}; -use crate::uniqueness::boolean_algebra::{Atom, Bool}; use roc_collections::all::{relative_complement, union, MutMap, SendSet}; use roc_module::ident::{Lowercase, TagName}; use roc_module::symbol::Symbol; +use roc_types::boolean_algebra::{Atom, Bool}; +use roc_types::subs::Content::{self, *}; +use roc_types::subs::{Descriptor, FlatType, Mark, OptVariable, Subs, Variable}; +use roc_types::types::{Mismatch, Problem}; use std::hash::Hash; macro_rules! mismatch { @@ -446,7 +446,7 @@ fn unify_flat_type( left: &FlatType, right: &FlatType, ) -> Outcome { - use crate::subs::FlatType::*; + use roc_types::subs::FlatType::*; match (left, right) { (EmptyRecord, EmptyRecord) => merge(subs, ctx, Structure(left.clone())), @@ -668,7 +668,7 @@ pub fn gather_fields( fields: MutMap, var: Variable, ) -> RecordStructure { - use crate::subs::FlatType::*; + use roc_types::subs::FlatType::*; match subs.get(var).content { Structure(Record(sub_fields, sub_ext)) => { @@ -689,7 +689,7 @@ fn gather_tags( tags: MutMap>, var: Variable, ) -> TagUnionStructure { - use crate::subs::FlatType::*; + use roc_types::subs::FlatType::*; match subs.get(var).content { Structure(TagUnion(sub_tags, sub_ext)) => { diff --git a/compiler/src/unique_builtins.rs b/compiler/src/unique_builtins.rs index 8f5bf763ba..2efb48661f 100644 --- a/compiler/src/unique_builtins.rs +++ b/compiler/src/unique_builtins.rs @@ -1,11 +1,11 @@ use crate::builtins; use crate::builtins::StdLib; use crate::solve::{BuiltinAlias, SolvedAtom, SolvedType}; -use crate::subs::VarId; use roc_collections::all::{default_hasher, MutMap}; use roc_module::ident::TagName; use roc_module::symbol::Symbol; use roc_region::all::{Located, Region}; +use roc_types::subs::VarId; use std::collections::HashMap; /// Keep this up to date by hand! diff --git a/compiler/src/uniqueness/builtins.rs b/compiler/src/uniqueness/builtins.rs index e054842f94..8dcbeb02c6 100644 --- a/compiler/src/uniqueness/builtins.rs +++ b/compiler/src/uniqueness/builtins.rs @@ -1,12 +1,13 @@ -use crate::subs::Variable; -use crate::types::Constraint::{self, *}; -use crate::types::Expected::{self, *}; -use crate::types::Type::{self, *}; -use crate::types::{LetConstraint, Reason}; -use crate::uniqueness::boolean_algebra::Bool; +use roc_can::constraint::Constraint::{self, *}; +use roc_can::constraint::LetConstraint; +use roc_can::expected::Expected::{self, *}; use roc_collections::all::SendMap; use roc_module::symbol::Symbol; use roc_region::all::Region; +use roc_types::boolean_algebra::Bool; +use roc_types::subs::Variable; +use roc_types::types::Reason; +use roc_types::types::Type::{self, *}; #[inline(always)] pub fn int_literal(num_var: Variable, expected: Expected, region: Region) -> Constraint { diff --git a/compiler/src/uniqueness/mod.rs b/compiler/src/uniqueness/mod.rs index bc46c52c59..2ec8101ba4 100644 --- a/compiler/src/uniqueness/mod.rs +++ b/compiler/src/uniqueness/mod.rs @@ -1,29 +1,24 @@ -use crate::can::def::{Declaration, Def}; -use crate::can::expr::Expr; -use crate::can::expr::Field; -use crate::can::pattern::{Pattern, RecordDestruct}; use crate::constrain::expr::{exists, exists_with_aliases, Info}; -use crate::subs::{VarStore, Variable}; -use crate::types::Alias; -use crate::types::AnnotationSource::{self, *}; -use crate::types::Constraint::{self, *}; -use crate::types::Expected::{self}; -use crate::types::LetConstraint; -use crate::types::PExpected::{self}; -use crate::types::PReason::{self}; -use crate::types::Reason; -use crate::types::Type::{self, *}; -use crate::uniqueness::boolean_algebra::{Atom, Bool}; use crate::uniqueness::builtins::{attr_type, list_type, str_type}; use crate::uniqueness::sharing::{Container, FieldAccess, Mark, Usage, VarUsage}; +use roc_can::constraint::Constraint::{self, *}; +use roc_can::constraint::LetConstraint; +use roc_can::def::{Declaration, Def}; +use roc_can::expected::{Expected, PExpected}; +use roc_can::expr::{Expr, Field}; +use roc_can::pattern::{Pattern, RecordDestruct}; use roc_collections::all::{ImMap, ImSet, SendMap}; use roc_module::ident::{Ident, Lowercase, TagName}; use roc_module::symbol::{ModuleId, Symbol}; use roc_region::all::{Located, Region}; +use roc_types::boolean_algebra::{Atom, Bool}; +use roc_types::subs::{VarStore, Variable}; +use roc_types::types::AnnotationSource::{self, *}; +use roc_types::types::Type::{self, *}; +use roc_types::types::{Alias, PReason, Reason}; -pub use crate::can::expr::Expr::*; +pub use roc_can::expr::Expr::*; -pub mod boolean_algebra; pub mod builtins; pub mod sharing; @@ -147,8 +142,8 @@ fn constrain_pattern( pattern: &Located, expected: PExpected, ) { - use crate::can::pattern::Pattern::*; - use crate::types::PatternCategory; + use roc_can::pattern::Pattern::*; + use roc_types::types::PatternCategory; match &pattern.value { Identifier(symbol) => { @@ -343,7 +338,7 @@ pub fn constrain_expr( expr: &Expr, expected: Expected, ) -> Constraint { - pub use crate::can::expr::Expr::*; + pub use roc_can::expr::Expr::*; match expr { Int(var, _) => { @@ -540,7 +535,7 @@ pub fn constrain_expr( ) } Closure(fn_var, _symbol, recursion, args, boxed) => { - use crate::can::expr::Recursive; + use roc_can::expr::Recursive; let (loc_body_expr, ret_var) = &**boxed; let mut state = PatternState { @@ -1402,7 +1397,7 @@ fn annotation_to_attr_type( rigids: &mut ImMap, change_var_kind: bool, ) -> (Vec, Type) { - use crate::types::Type::*; + use roc_types::types::Type::*; match ann { Variable(var) => { diff --git a/compiler/src/uniqueness/sharing.rs b/compiler/src/uniqueness/sharing.rs index 242015177e..bc38acde7c 100644 --- a/compiler/src/uniqueness/sharing.rs +++ b/compiler/src/uniqueness/sharing.rs @@ -1,9 +1,9 @@ -use crate::can::expr::Expr; -use crate::subs::Variable; +use roc_can::expr::Expr; use roc_collections::all::{ImMap, ImSet}; use roc_module::ident::Lowercase; use roc_module::symbol::Symbol; use roc_region::all::Located; +use roc_types::subs::Variable; // fake field names for container elements // e.g. for lists, internally it's a record with a `list_elem` field diff --git a/compiler/tests/helpers/mod.rs b/compiler/tests/helpers/mod.rs index 958a420fc2..3393d62d98 100644 --- a/compiler/tests/helpers/mod.rs +++ b/compiler/tests/helpers/mod.rs @@ -1,25 +1,27 @@ extern crate bumpalo; use self::bumpalo::Bump; -use roc::builtins; -use roc::can::env::Env; -use roc::can::expr::Output; -use roc::can::expr::{canonicalize_expr, Expr}; -use roc::can::operator; -use roc::can::problem::Problem; -use roc::can::scope::Scope; use roc::constrain::expr::constrain_expr; use roc::constrain::module::Import; -use roc::subs::{Subs, VarStore, Variable}; -use roc::types::{Constraint, Expected, Type}; use roc::unique_builtins; -use roc_collections::all::{ImMap, ImSet, MutMap, SendSet}; +use roc::{builtins, solve}; +use roc_can::constraint::Constraint; +use roc_can::env::Env; +use roc_can::expected::Expected; +use roc_can::expr::Output; +use roc_can::expr::{canonicalize_expr, Expr}; +use roc_can::operator; +use roc_can::problem::Problem; +use roc_can::scope::Scope; +use roc_collections::all::{ImMap, ImSet, MutMap, SendMap, SendSet}; use roc_module::ident::Ident; use roc_module::symbol::{IdentIds, Interns, ModuleId, ModuleIds, Symbol}; use roc_parse::ast::{self, Attempting}; use roc_parse::blankspace::space0_before; use roc_parse::parser::{loc, Fail, Parser, State}; use roc_region::all::{Located, Region}; +use roc_types::subs::{Content, Subs, VarStore, Variable}; +use roc_types::types::Type; use std::hash::Hash; use std::path::{Path, PathBuf}; @@ -27,6 +29,24 @@ pub fn test_home() -> ModuleId { ModuleIds::default().get_or_insert(&"Test".into()) } +#[allow(dead_code)] +pub fn infer_expr( + subs: Subs, + problems: &mut Vec, + constraint: &Constraint, + expr_var: Variable, +) -> (Content, Subs) { + let env = solve::Env { + aliases: MutMap::default(), + vars_by_symbol: SendMap::default(), + }; + let (solved, _) = solve::run(&env, problems, subs, constraint); + + let content = solved.inner().get_without_compacting(expr_var).content; + + (content, solved.into_inner()) +} + /// In --release builds, don't increase the stack size. Run the test normally. /// This way, we find out if any of our tests are blowing the stack even after /// optimizations in release builds. diff --git a/compiler/tests/test_gen.rs b/compiler/tests/test_gen.rs index 931f64b19d..5feafee63d 100644 --- a/compiler/tests/test_gen.rs +++ b/compiler/tests/test_gen.rs @@ -11,7 +11,7 @@ mod helpers; #[cfg(test)] mod test_gen { - use crate::helpers::{can_expr, uniq_expr, CanExprOut}; + use crate::helpers::{can_expr, infer_expr, uniq_expr, CanExprOut}; use bumpalo::Bump; use cranelift::prelude::{AbiParam, ExternalName, FunctionBuilder, FunctionBuilderContext}; use cranelift_codegen::ir::InstBuilder; @@ -27,13 +27,12 @@ mod test_gen { use roc::crane::build::{declare_proc, define_proc_body, ScopeEntry}; use roc::crane::convert::type_from_layout; use roc::crane::imports::define_malloc; - use roc::infer::infer_expr; use roc::llvm::build::{build_proc, build_proc_header}; use roc::llvm::convert::basic_type_from_layout; use roc::mono::expr::Expr; use roc::mono::layout::Layout; - use roc::subs::Subs; use roc_collections::all::{ImMap, MutMap}; + use roc_types::subs::Subs; use std::ffi::{CStr, CString}; use std::mem; use std::os::raw::c_char; @@ -44,7 +43,7 @@ mod test_gen { let CanExprOut { loc_expr, var_store, var, constraint, home, interns, .. } = can_expr($src); let subs = Subs::new(var_store.into()); let mut unify_problems = Vec::new(); - let (content, solved) = infer_expr(subs, &mut unify_problems, &constraint, var); + let (content, subs) = infer_expr(subs, &mut unify_problems, &constraint, var); let shared_builder = settings::builder(); let shared_flags = settings::Flags::new(shared_builder); let mut module: Module = @@ -58,7 +57,6 @@ mod test_gen { let main_fn_name = "$Test.main"; // Compute main_fn_ret_type before moving subs to Env - let subs = solved.into_inner(); let layout = Layout::from_content(&arena, content, &subs) .unwrap_or_else(|err| panic!("Code gen error in test: could not convert content to layout. Err was {:?} and Subs were {:?}", err, subs)); let main_ret_type = type_from_layout(cfg, &layout); @@ -174,7 +172,7 @@ mod test_gen { let CanExprOut { loc_expr, var_store, var, constraint, home, interns, .. } = can_expr($src); let subs = Subs::new(var_store.into()); let mut unify_problems = Vec::new(); - let (content, solved) = infer_expr(subs, &mut unify_problems, &constraint, var); + let (content, subs) = infer_expr(subs, &mut unify_problems, &constraint, var); let context = Context::create(); let module = context.create_module("app"); @@ -198,7 +196,6 @@ mod test_gen { fpm.initialize(); // Compute main_fn_type before moving subs to Env - let subs = solved.into_inner(); let layout = Layout::from_content(&arena, content, &subs) .unwrap_or_else(|err| panic!("Code gen error in test: could not convert to layout. Err was {:?} and Subs were {:?}", err, subs)); let main_fn_type = basic_type_from_layout(&context, &layout) @@ -311,7 +308,7 @@ mod test_gen { let (loc_expr, _output, _problems, subs, var, constraint, home, interns) = uniq_expr($src); let mut unify_problems = Vec::new(); - let (content, solved) = infer_expr(subs, &mut unify_problems, &constraint, var); + let (content, subs) = infer_expr(subs, &mut unify_problems, &constraint, var); let context = Context::create(); let module = context.create_module("app"); @@ -335,7 +332,6 @@ mod test_gen { fpm.initialize(); // Compute main_fn_type before moving subs to Env - let subs = solved.into_inner(); let layout = Layout::from_content(&arena, content, &subs) .unwrap_or_else(|err| panic!("Code gen error in test: could not convert to layout. Err was {:?} and Subs were {:?}", err, subs)); let main_fn_type = basic_type_from_layout(&context, &layout) diff --git a/compiler/tests/test_infer.rs b/compiler/tests/test_infer.rs index 0deb5a49db..5801572e3b 100644 --- a/compiler/tests/test_infer.rs +++ b/compiler/tests/test_infer.rs @@ -10,18 +10,17 @@ mod helpers; #[cfg(test)] mod test_infer { - use crate::helpers::{assert_correct_variable_usage, can_expr, CanExprOut}; - use roc::infer::infer_expr; + use crate::helpers::{assert_correct_variable_usage, can_expr, infer_expr, CanExprOut}; use roc::pretty_print_types::{content_to_string, name_all_type_vars}; - use roc::subs::Subs; + use roc_types::subs::Subs; // HELPERS fn infer_eq_help( src: &str, ) -> ( - Vec, - Vec, + Vec, + Vec, String, ) { let CanExprOut { @@ -43,8 +42,7 @@ mod test_infer { } let mut unify_problems = Vec::new(); - let (content, solved) = infer_expr(subs, &mut unify_problems, &constraint, var); - let mut subs = solved.into_inner(); + let (content, mut subs) = infer_expr(subs, &mut unify_problems, &constraint, var); name_all_type_vars(var, &mut subs); diff --git a/compiler/tests/test_load.rs b/compiler/tests/test_load.rs index 3048f1085b..55ff353c74 100644 --- a/compiler/tests/test_load.rs +++ b/compiler/tests/test_load.rs @@ -17,12 +17,12 @@ mod test_load { use crate::helpers::fixtures_dir; use inlinable_string::InlinableString; use roc::builtins; - use roc::can::def::Declaration::*; - use roc::can::def::Def; + use roc_can::def::Declaration::*; + use roc_can::def::Def; use roc::load::{load, LoadedModule}; use roc::pretty_print_types::{content_to_string, name_all_type_vars}; use roc::solve::SubsByModule; - use roc::subs::Subs; + use roc_types::subs::Subs; use roc_collections::all::MutMap; use roc_module::symbol::{Interns, ModuleId}; use std::collections::HashMap; diff --git a/compiler/tests/test_uniqueness_infer.rs b/compiler/tests/test_uniqueness_infer.rs index a96d26ec3f..78b77eba9f 100644 --- a/compiler/tests/test_uniqueness_infer.rs +++ b/compiler/tests/test_uniqueness_infer.rs @@ -10,13 +10,12 @@ mod helpers; #[cfg(test)] mod test_infer_uniq { - use crate::helpers::{assert_correct_variable_usage, uniq_expr}; - use roc::infer::infer_expr; + use crate::helpers::{assert_correct_variable_usage, infer_expr, uniq_expr}; use roc::pretty_print_types::{content_to_string, name_all_type_vars}; // HELPERS - fn infer_eq_help(src: &str) -> (Vec, String) { + fn infer_eq_help(src: &str) -> (Vec, String) { let (_loc_expr, output, _problems, mut subs, variable, constraint, home, interns) = uniq_expr(src); @@ -27,8 +26,7 @@ mod test_infer_uniq { } let mut unify_problems = Vec::new(); - let (content, solved) = infer_expr(subs, &mut unify_problems, &constraint, variable); - let mut subs = solved.into_inner(); + let (content, mut subs) = infer_expr(subs, &mut unify_problems, &constraint, variable); name_all_type_vars(variable, &mut subs); diff --git a/compiler/tests/test_uniqueness_load.rs b/compiler/tests/test_uniqueness_load.rs index 5659354ea6..0ee47f3b91 100644 --- a/compiler/tests/test_uniqueness_load.rs +++ b/compiler/tests/test_uniqueness_load.rs @@ -16,12 +16,12 @@ mod test_uniqueness_load { use crate::helpers::fixtures_dir; use inlinable_string::InlinableString; use roc::builtins; - use roc::can::def::Declaration::*; - use roc::can::def::Def; + use roc_can::def::Declaration::*; + use roc_can::def::Def; use roc::load::{load, LoadedModule}; use roc::pretty_print_types::{content_to_string, name_all_type_vars}; use roc::solve::SubsByModule; - use roc::subs::Subs; + use roc_types::subs::Subs; use roc::unique_builtins; use roc_collections::all::MutMap; use roc_module::symbol::{Interns, ModuleId}; diff --git a/compiler/types/Cargo.toml b/compiler/types/Cargo.toml new file mode 100644 index 0000000000..dcf46c326f --- /dev/null +++ b/compiler/types/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "roc_types" +version = "0.1.0" +authors = ["Richard Feldman "] +edition = "2018" + +[dependencies] +roc_collections = { path = "../collections" } +roc_region = { path = "../region" } +roc_module = { path = "../module" } +roc_parse = { path = "../parse" } +ven_ena = { path = "../../vendor/ena" } +inlinable_string = "0.1.0" + +[dev-dependencies] +pretty_assertions = "0.5.1 " +maplit = "1.0.1" +indoc = "0.3.3" +quickcheck = "0.8" +quickcheck_macros = "0.8" diff --git a/compiler/src/uniqueness/boolean_algebra.rs b/compiler/types/src/boolean_algebra.rs similarity index 100% rename from compiler/src/uniqueness/boolean_algebra.rs rename to compiler/types/src/boolean_algebra.rs diff --git a/compiler/types/src/lib.rs b/compiler/types/src/lib.rs new file mode 100644 index 0000000000..bbe1c47d3d --- /dev/null +++ b/compiler/types/src/lib.rs @@ -0,0 +1,3 @@ +pub mod boolean_algebra; +pub mod subs; +pub mod types; diff --git a/compiler/src/subs.rs b/compiler/types/src/subs.rs similarity index 99% rename from compiler/src/subs.rs rename to compiler/types/src/subs.rs index 345523348d..4f4d719a3a 100644 --- a/compiler/src/subs.rs +++ b/compiler/types/src/subs.rs @@ -1,12 +1,12 @@ -use crate::ena::unify::{InPlace, UnificationTable, UnifyKey}; +use crate::boolean_algebra; use crate::types::{name_type_var, ErrorType, Problem, TypeExt}; -use crate::uniqueness::boolean_algebra; use roc_collections::all::{ImMap, ImSet, MutMap, MutSet, SendMap}; use roc_module::ident::{Lowercase, TagName}; use roc_module::symbol::Symbol; use std::fmt; use std::iter::{once, Iterator}; use std::sync::atomic::{AtomicU32, Ordering}; +use ven_ena::unify::{InPlace, UnificationTable, UnifyKey}; #[derive(Clone, Copy, Hash, PartialEq, Eq)] pub struct Mark(i32); @@ -1015,8 +1015,8 @@ fn get_fresh_var_name(state: &mut NameState) -> Lowercase { } fn restore_content(subs: &mut Subs, content: &Content) { - use crate::subs::Content::*; - use crate::subs::FlatType::*; + use Content::*; + use FlatType::*; match content { FlexVar(_) | RigidVar(_) | Error => (), diff --git a/compiler/src/types/mod.rs b/compiler/types/src/types.rs similarity index 83% rename from compiler/src/types/mod.rs rename to compiler/types/src/types.rs index 718905dfdd..68edc0605d 100644 --- a/compiler/src/types/mod.rs +++ b/compiler/types/src/types.rs @@ -1,6 +1,5 @@ -use crate::can::pattern::Pattern; +use crate::boolean_algebra; use crate::subs::{VarStore, Variable}; -use crate::uniqueness::boolean_algebra; use inlinable_string::InlinableString; use roc_collections::all::{ImMap, ImSet, MutSet, SendMap}; use roc_module::ident::{Ident, Lowercase, TagName}; @@ -589,43 +588,6 @@ fn variables_help(tipe: &Type, accum: &mut ImSet) { } } -#[derive(Debug, Clone, PartialEq)] -pub enum Expected { - NoExpectation(T), - FromAnnotation(Located, usize, AnnotationSource, T), - ForReason(Reason, T, Region), -} - -/// Like Expected, but for Patterns. -#[derive(Debug, Clone, PartialEq, Eq)] -pub enum PExpected { - NoExpectation(T), - ForReason(PReason, T, Region), -} - -impl PExpected { - pub fn get_type(self) -> T { - match self { - PExpected::NoExpectation(val) => val, - PExpected::ForReason(_, val, _) => val, - } - } - - pub fn get_type_ref(&self) -> &T { - match self { - PExpected::NoExpectation(val) => val, - PExpected::ForReason(_, val, _) => val, - } - } - - pub fn get_type_mut_ref(&mut self) -> &mut T { - match self { - PExpected::NoExpectation(val) => val, - PExpected::ForReason(_, val, _) => val, - } - } -} - #[derive(Debug, Clone, PartialEq, Eq)] pub enum PReason { TypedArg { name: Box, index: usize }, @@ -635,32 +597,6 @@ pub enum PReason { Tail, } -impl Expected { - pub fn get_type(self) -> T { - match self { - Expected::NoExpectation(val) => val, - Expected::ForReason(_, val, _) => val, - Expected::FromAnnotation(_, _, _, val) => val, - } - } - - pub fn get_type_ref(&self) -> &T { - match self { - Expected::NoExpectation(val) => val, - Expected::ForReason(_, val, _) => val, - Expected::FromAnnotation(_, _, _, val) => val, - } - } - - pub fn get_type_mut_ref(&mut self) -> &mut T { - match self { - Expected::NoExpectation(val) => val, - Expected::ForReason(_, val, _) => val, - Expected::FromAnnotation(_, _, _, val) => val, - } - } -} - #[derive(Debug, Clone, PartialEq, Eq)] pub enum AnnotationSource { TypedIfBranch(usize /* index */), @@ -687,87 +623,6 @@ pub enum Reason { RecordUpdateKeys(Symbol, SendMap), } -#[derive(Debug, Clone, PartialEq)] -pub enum Constraint { - Eq(Type, Expected, Region), - Lookup(Symbol, Expected, Region), - Pattern(Region, PatternCategory, Type, PExpected), - True, // Used for things that always unify, e.g. blanks and runtime errors - SaveTheEnvironment, - Let(Box), - And(Vec), -} - -impl Constraint { - pub fn instantiate_aliases(&mut self, var_store: &VarStore) { - Self::instantiate_aliases_help(self, &ImMap::default(), var_store, &mut ImSet::default()) - } - - fn instantiate_aliases_help( - &mut self, - aliases: &ImMap, - var_store: &VarStore, - introduced: &mut ImSet, - ) { - use Constraint::*; - - match self { - True | SaveTheEnvironment => {} - - Eq(typ, expected, _) => { - expected - .get_type_mut_ref() - .instantiate_aliases(aliases, var_store, introduced); - typ.instantiate_aliases(aliases, var_store, introduced); - } - - Lookup(_, expected, _) => { - expected - .get_type_mut_ref() - .instantiate_aliases(aliases, var_store, introduced); - } - - Pattern(_, _, typ, pexpected) => { - pexpected - .get_type_mut_ref() - .instantiate_aliases(aliases, var_store, introduced); - typ.instantiate_aliases(aliases, var_store, introduced); - } - - And(nested) => { - for c in nested.iter_mut() { - c.instantiate_aliases_help(aliases, var_store, introduced); - } - } - - Let(letcon) => { - let mut new_aliases = aliases.clone(); - for (k, v) in letcon.def_aliases.iter() { - new_aliases.insert(*k, v.clone()); - } - - let mut introduced = ImSet::default(); - for Located { value: typ, .. } in letcon.def_types.iter_mut() { - typ.instantiate_aliases(&new_aliases, var_store, &mut introduced); - } - - letcon.defs_constraint.instantiate_aliases_help( - &new_aliases, - var_store, - &mut introduced, - ); - letcon.ret_constraint.instantiate_aliases_help( - &new_aliases, - var_store, - &mut introduced, - ); - - letcon.flex_vars.extend(introduced); - } - } - } -} - #[derive(Debug, Clone, PartialEq, Eq)] pub enum PatternCategory { Record, @@ -781,16 +636,6 @@ pub enum PatternCategory { Float, } -#[derive(Debug, Clone, PartialEq)] -pub struct LetConstraint { - pub rigid_vars: Vec, - pub flex_vars: Vec, - pub def_types: SendMap>, - pub def_aliases: SendMap, - pub defs_constraint: Constraint, - pub ret_constraint: Constraint, -} - #[derive(Clone, Debug, PartialEq)] pub struct Alias { pub region: Region, diff --git a/vendor/ena/Cargo.toml b/vendor/ena/Cargo.toml new file mode 100644 index 0000000000..82116c3ba9 --- /dev/null +++ b/vendor/ena/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "ven_ena" +description = "Union-find, congruence closure, and other unification code. Based on code from rustc." +license = "MIT/Apache-2.0" +homepage = "https://github.com/rust-lang-nursery/ena" +repository = "https://github.com/rust-lang-nursery/ena" +version = "0.13.1" +authors = ["Niko Matsakis "] +readme = "README.md" +keywords = ["unification", "union-find"] + +[dependencies] +log = "0.4" diff --git a/vendor/ena/LICENSE-APACHE b/vendor/ena/LICENSE-APACHE new file mode 100644 index 0000000000..16fe87b06e --- /dev/null +++ b/vendor/ena/LICENSE-APACHE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/vendor/ena/LICENSE-MIT b/vendor/ena/LICENSE-MIT new file mode 100644 index 0000000000..25597d5838 --- /dev/null +++ b/vendor/ena/LICENSE-MIT @@ -0,0 +1,25 @@ +Copyright (c) 2010 The Rust Project Developers + +Permission is hereby granted, free of charge, to any +person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the +Software without restriction, including without +limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice +shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/compiler/src/ena/bitvec.rs b/vendor/ena/src/bitvec.rs similarity index 100% rename from compiler/src/ena/bitvec.rs rename to vendor/ena/src/bitvec.rs diff --git a/compiler/src/ena/mod.rs b/vendor/ena/src/lib.rs similarity index 94% rename from compiler/src/ena/mod.rs rename to vendor/ena/src/lib.rs index 36b9093a0c..3a7485bcf4 100644 --- a/compiler/src/ena/mod.rs +++ b/vendor/ena/src/lib.rs @@ -13,3 +13,6 @@ pub mod snapshot_vec; pub mod unify; + +#[macro_use] +extern crate log; diff --git a/compiler/src/ena/snapshot_vec.rs b/vendor/ena/src/snapshot_vec.rs similarity index 100% rename from compiler/src/ena/snapshot_vec.rs rename to vendor/ena/src/snapshot_vec.rs diff --git a/compiler/src/ena/unify/backing_vec.rs b/vendor/ena/src/unify/backing_vec.rs similarity index 99% rename from compiler/src/ena/unify/backing_vec.rs rename to vendor/ena/src/unify/backing_vec.rs index 4177591c04..4b50aafa06 100644 --- a/compiler/src/ena/unify/backing_vec.rs +++ b/vendor/ena/src/unify/backing_vec.rs @@ -1,4 +1,4 @@ -use crate::ena::snapshot_vec as sv; +use crate::snapshot_vec as sv; #[cfg(feature = "persistent")] use im_rc::Vector; use std::fmt::{self, Debug}; diff --git a/compiler/src/ena/unify/mod.rs b/vendor/ena/src/unify/mod.rs similarity index 100% rename from compiler/src/ena/unify/mod.rs rename to vendor/ena/src/unify/mod.rs diff --git a/vendor/pathfinding/Cargo.toml b/vendor/pathfinding/Cargo.toml new file mode 100644 index 0000000000..b45319056d --- /dev/null +++ b/vendor/pathfinding/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "ven_graph" +description = "Pathfinding, flow, and graph algorithms" +repository = "https://github.com/samueltardieu/pathfinding" +keywords = ["shortest-path", "astar", "dijkstra", "flow", "graph"] +license = "Apache-2.0/MIT" +homepage = "https://rfc1149.net/devel/pathfinding.html" +documentation = "https://docs.rs/pathfinding/" +version = "2.0.5-pre" +authors = ["Samuel Tardieu "] +categories = ["algorithms"] +readme = "README.md" +edition = "2018" + +[dependencies] +roc_collections = { path = "../../compiler/collections" } diff --git a/compiler/src/graph.rs b/vendor/pathfinding/src/lib.rs similarity index 100% rename from compiler/src/graph.rs rename to vendor/pathfinding/src/lib.rs From 8ef2ae3de71ef08956df8e911b200953a2708302 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 5 Mar 2020 23:03:29 -0500 Subject: [PATCH 2/3] clippy clip clip --- compiler/can/src/lib.rs | 12 ++++++++++++ compiler/module/src/lib.rs | 13 +++++++++++++ compiler/parse/src/lib.rs | 13 +++++++++++++ compiler/region/src/lib.rs | 13 +++++++++++++ compiler/types/src/lib.rs | 12 ++++++++++++ 5 files changed, 63 insertions(+) diff --git a/compiler/can/src/lib.rs b/compiler/can/src/lib.rs index 2c38c6b3d7..0e6f32fcfc 100644 --- a/compiler/can/src/lib.rs +++ b/compiler/can/src/lib.rs @@ -1,3 +1,15 @@ +#![warn(clippy::all, clippy::dbg_macro)] +// I'm skeptical that clippy:large_enum_variant is a good lint to have globally enabled. +// +// It warns about a performance problem where the only quick remediation is +// to allocate more on the heap, which has lots of tradeoffs - including making it +// long-term unclear which allocations *need* to happen for compilation's sake +// (e.g. recursive structures) versus those which were only added to appease clippy. +// +// Effectively optimizing data struture memory layout isn't a quick fix, +// and encouraging shortcuts here creates bad incentives. I would rather temporarily +// re-enable this when working on performance optimizations than have it block PRs. +#![allow(clippy::large_enum_variant)] pub mod annotation; pub mod constraint; pub mod def; diff --git a/compiler/module/src/lib.rs b/compiler/module/src/lib.rs index a1a0f7fa91..78777141ce 100644 --- a/compiler/module/src/lib.rs +++ b/compiler/module/src/lib.rs @@ -1,3 +1,16 @@ +#![warn(clippy::all, clippy::dbg_macro)] +// I'm skeptical that clippy:large_enum_variant is a good lint to have globally enabled. +// +// It warns about a performance problem where the only quick remediation is +// to allocate more on the heap, which has lots of tradeoffs - including making it +// long-term unclear which allocations *need* to happen for compilation's sake +// (e.g. recursive structures) versus those which were only added to appease clippy. +// +// Effectively optimizing data struture memory layout isn't a quick fix, +// and encouraging shortcuts here creates bad incentives. I would rather temporarily +// re-enable this when working on performance optimizations than have it block PRs. +#![allow(clippy::large_enum_variant)] + pub mod ident; pub mod symbol; diff --git a/compiler/parse/src/lib.rs b/compiler/parse/src/lib.rs index 9120c59c93..cb12761886 100644 --- a/compiler/parse/src/lib.rs +++ b/compiler/parse/src/lib.rs @@ -1,3 +1,16 @@ +#![warn(clippy::all, clippy::dbg_macro)] +// I'm skeptical that clippy:large_enum_variant is a good lint to have globally enabled. +// +// It warns about a performance problem where the only quick remediation is +// to allocate more on the heap, which has lots of tradeoffs - including making it +// long-term unclear which allocations *need* to happen for compilation's sake +// (e.g. recursive structures) versus those which were only added to appease clippy. +// +// Effectively optimizing data struture memory layout isn't a quick fix, +// and encouraging shortcuts here creates bad incentives. I would rather temporarily +// re-enable this when working on performance optimizations than have it block PRs. +#![allow(clippy::large_enum_variant)] + #[macro_use] pub mod parser; pub mod ast; diff --git a/compiler/region/src/lib.rs b/compiler/region/src/lib.rs index 6dc1d959b5..79c906ee0c 100644 --- a/compiler/region/src/lib.rs +++ b/compiler/region/src/lib.rs @@ -1 +1,14 @@ +#![warn(clippy::all, clippy::dbg_macro)] +// I'm skeptical that clippy:large_enum_variant is a good lint to have globally enabled. +// +// It warns about a performance problem where the only quick remediation is +// to allocate more on the heap, which has lots of tradeoffs - including making it +// long-term unclear which allocations *need* to happen for compilation's sake +// (e.g. recursive structures) versus those which were only added to appease clippy. +// +// Effectively optimizing data struture memory layout isn't a quick fix, +// and encouraging shortcuts here creates bad incentives. I would rather temporarily +// re-enable this when working on performance optimizations than have it block PRs. +#![allow(clippy::large_enum_variant)] + pub mod all; diff --git a/compiler/types/src/lib.rs b/compiler/types/src/lib.rs index bbe1c47d3d..86db916369 100644 --- a/compiler/types/src/lib.rs +++ b/compiler/types/src/lib.rs @@ -1,3 +1,15 @@ +#![warn(clippy::all, clippy::dbg_macro)] +// I'm skeptical that clippy:large_enum_variant is a good lint to have globally enabled. +// +// It warns about a performance problem where the only quick remediation is +// to allocate more on the heap, which has lots of tradeoffs - including making it +// long-term unclear which allocations *need* to happen for compilation's sake +// (e.g. recursive structures) versus those which were only added to appease clippy. +// +// Effectively optimizing data struture memory layout isn't a quick fix, +// and encouraging shortcuts here creates bad incentives. I would rather temporarily +// re-enable this when working on performance optimizations than have it block PRs. +#![allow(clippy::large_enum_variant)] pub mod boolean_algebra; pub mod subs; pub mod types; From 5b5f800c7015e577531f2ebf839f6677b5cf9913 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 5 Mar 2020 23:03:49 -0500 Subject: [PATCH 3/3] cargo fmt --- compiler/can/src/annotation.rs | 4 ++-- compiler/can/src/expr.rs | 2 +- compiler/can/src/module.rs | 4 ++-- compiler/can/src/num.rs | 2 +- compiler/can/src/procedure.rs | 2 +- compiler/src/load/mod.rs | 2 +- compiler/tests/test_load.rs | 6 +++--- compiler/tests/test_uniqueness_load.rs | 6 +++--- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index 4e8decb8c6..80738f8246 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -1,7 +1,5 @@ use crate::env::Env; use crate::scope::Scope; -use roc_types::subs::{VarStore, Variable}; -use roc_types::types::{Alias, Problem, Type}; use roc_collections::all::{ImMap, MutMap, MutSet, SendMap}; use roc_module::ident::Ident; use roc_module::ident::{Lowercase, TagName}; @@ -9,6 +7,8 @@ use roc_module::symbol::Symbol; use roc_parse::ast::{AssignedField, Tag, TypeAnnotation}; use roc_region::all::Located; use roc_region::all::Region; +use roc_types::subs::{VarStore, Variable}; +use roc_types::types::{Alias, Problem, Type}; #[derive(Clone, Debug, PartialEq)] pub struct Annotation { diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 5bb644ee43..da6170c12e 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -9,7 +9,6 @@ use crate::pattern::{canonicalize_pattern, Pattern}; use crate::problem::{Problem, RuntimeError}; use crate::procedure::References; use crate::scope::Scope; -use roc_types::types::Alias; use roc_collections::all::{ImSet, MutMap, MutSet, SendMap}; use roc_module::ident::{Lowercase, TagName}; use roc_module::symbol::Symbol; @@ -17,6 +16,7 @@ use roc_parse::ast; use roc_parse::operator::CalledVia; use roc_region::all::{Located, Region}; use roc_types::subs::{VarStore, Variable}; +use roc_types::types::Alias; use std::fmt::Debug; use std::i64; use std::ops::Neg; diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index 0b6978e70c..0a1714029b 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -5,8 +5,6 @@ use crate::operator::desugar_def; use crate::pattern::PatternType; use crate::problem::{Problem, RuntimeError}; use crate::scope::Scope; -use roc_types::subs::{VarStore, Variable}; -use roc_types::types::Alias; use bumpalo::Bump; use roc_collections::all::{MutMap, MutSet}; use roc_module::ident::Ident; @@ -14,6 +12,8 @@ use roc_module::ident::Lowercase; use roc_module::symbol::{IdentIds, ModuleId, ModuleIds, Symbol}; use roc_parse::ast; use roc_region::all::{Located, Region}; +use roc_types::subs::{VarStore, Variable}; +use roc_types::types::Alias; #[derive(Debug)] pub struct ModuleOutput { diff --git a/compiler/can/src/num.rs b/compiler/can/src/num.rs index 2f1667e890..6f5e8a85c8 100644 --- a/compiler/can/src/num.rs +++ b/compiler/can/src/num.rs @@ -2,8 +2,8 @@ use crate::env::Env; use crate::expr::Expr; use crate::problem::Problem; use crate::problem::RuntimeError::*; -use roc_types::subs::VarStore; use roc_parse::ast::Base; +use roc_types::subs::VarStore; use std::i64; #[inline(always)] diff --git a/compiler/can/src/procedure.rs b/compiler/can/src/procedure.rs index 044660b0ea..0483cf591b 100644 --- a/compiler/can/src/procedure.rs +++ b/compiler/can/src/procedure.rs @@ -1,9 +1,9 @@ use crate::expr::Expr; use crate::pattern::Pattern; -use roc_types::subs::Variable; use roc_collections::all::ImSet; use roc_module::symbol::Symbol; use roc_region::all::{Located, Region}; +use roc_types::subs::Variable; #[derive(Clone, Debug, PartialEq)] pub struct Procedure { diff --git a/compiler/src/load/mod.rs b/compiler/src/load/mod.rs index 662411fc89..617d98216d 100644 --- a/compiler/src/load/mod.rs +++ b/compiler/src/load/mod.rs @@ -7,6 +7,7 @@ use crate::constrain::module::{ use crate::solve::{self, BuiltinAlias, ExposedModuleTypes, Solved, SolvedType, SubsByModule}; use bumpalo::Bump; use roc_can; +use roc_can::constraint::Constraint; use roc_can::def::Declaration; use roc_can::module::{canonicalize_module_defs, ModuleOutput}; use roc_collections::all::{default_hasher, MutMap, MutSet, SendMap}; @@ -18,7 +19,6 @@ use roc_parse::parser::{Fail, Parser, State}; use roc_region::all::{Located, Region}; use roc_types::subs::{Subs, VarStore, Variable}; use roc_types::types::{self, Alias}; -use roc_can::constraint::{Constraint}; use std::collections::{HashMap, HashSet}; use std::fs::read_to_string; use std::io; diff --git a/compiler/tests/test_load.rs b/compiler/tests/test_load.rs index 55ff353c74..f42e71a2f9 100644 --- a/compiler/tests/test_load.rs +++ b/compiler/tests/test_load.rs @@ -17,14 +17,14 @@ mod test_load { use crate::helpers::fixtures_dir; use inlinable_string::InlinableString; use roc::builtins; - use roc_can::def::Declaration::*; - use roc_can::def::Def; use roc::load::{load, LoadedModule}; use roc::pretty_print_types::{content_to_string, name_all_type_vars}; use roc::solve::SubsByModule; - use roc_types::subs::Subs; + use roc_can::def::Declaration::*; + use roc_can::def::Def; use roc_collections::all::MutMap; use roc_module::symbol::{Interns, ModuleId}; + use roc_types::subs::Subs; use std::collections::HashMap; // HELPERS diff --git a/compiler/tests/test_uniqueness_load.rs b/compiler/tests/test_uniqueness_load.rs index 0ee47f3b91..159456d7c2 100644 --- a/compiler/tests/test_uniqueness_load.rs +++ b/compiler/tests/test_uniqueness_load.rs @@ -16,15 +16,15 @@ mod test_uniqueness_load { use crate::helpers::fixtures_dir; use inlinable_string::InlinableString; use roc::builtins; - use roc_can::def::Declaration::*; - use roc_can::def::Def; use roc::load::{load, LoadedModule}; use roc::pretty_print_types::{content_to_string, name_all_type_vars}; use roc::solve::SubsByModule; - use roc_types::subs::Subs; use roc::unique_builtins; + use roc_can::def::Declaration::*; + use roc_can::def::Def; use roc_collections::all::MutMap; use roc_module::symbol::{Interns, ModuleId}; + use roc_types::subs::Subs; use std::collections::HashMap; // HELPERS