Move solve and unify into their own crates

This commit is contained in:
Richard Feldman 2020-03-06 01:42:53 -05:00
parent 908e485fca
commit cc92ca7e7c
15 changed files with 108 additions and 9 deletions

View file

@ -15,6 +15,8 @@ roc_can = { path = "./can" }
roc_builtins = { path = "./builtins" }
roc_constrain = { path = "./constrain" }
roc_uniqueness = { path = "./uniqueness" }
roc_unify = { path = "./unify" }
roc_solve = { path = "./solve" }
log = "0.4.8"
petgraph = { version = "0.4.5", optional = true }
im = "14" # im and im-rc should always have the same version!

20
compiler/solve/Cargo.toml Normal file
View file

@ -0,0 +1,20 @@
[package]
name = "roc_solve"
version = "0.1.0"
authors = ["Richard Feldman <oss@rtfeldman.com>"]
edition = "2018"
[dependencies]
roc_collections = { path = "../collections" }
roc_region = { path = "../region" }
roc_module = { path = "../module" }
roc_types = { path = "../types" }
roc_can = { path = "../can" }
roc_unify = { path = "../unify" }
[dev-dependencies]
pretty_assertions = "0.5.1 "
maplit = "1.0.1"
indoc = "0.3.3"
quickcheck = "0.8"
quickcheck_macros = "0.8"

14
compiler/solve/src/lib.rs Normal file
View file

@ -0,0 +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 solve;

View file

@ -1,4 +1,3 @@
use crate::unify::{unify, Unified};
use roc_can::constraint::Constraint::{self, *};
use roc_collections::all::{ImMap, MutMap, SendMap};
use roc_module::ident::TagName;
@ -9,6 +8,7 @@ use roc_types::solved_types::{Solved, SolvedType};
use roc_types::subs::{Content, Descriptor, FlatType, Mark, OptVariable, Rank, Subs, Variable};
use roc_types::types::Type::{self, *};
use roc_types::types::{Alias, Problem};
use roc_unify::unify::{unify, Unified};
// Type checking system adapted from Elm by Evan Czaplicki, BSD-3-Clause Licensed
// https://github.com/elm/compiler

View file

@ -22,5 +22,3 @@ pub mod load;
pub mod mono;
pub mod pretty_print_types;
pub mod reporting;
pub mod solve;
pub mod unify;

View file

@ -1,4 +1,3 @@
use crate::solve::{self, ExposedModuleTypes, SubsByModule};
use bumpalo::Bump;
use roc_builtins::all::Mode;
use roc_builtins::all::StdLib;
@ -17,6 +16,7 @@ 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_solve::solve::{self, ExposedModuleTypes, SubsByModule};
use roc_types::solved_types::{BuiltinAlias, Solved, SolvedType};
use roc_types::subs::{Subs, VarStore, Variable};
use roc_types::types::{self, Alias};

View file

@ -345,8 +345,7 @@ fn write_flat_type(
EmptyTagUnion => buf.push_str(EMPTY_TAG_UNION),
Func(args, ret) => write_fn(env, args, ret, subs, buf, parens),
Record(fields, ext_var) => {
use crate::unify::gather_fields;
use crate::unify::RecordStructure;
use roc_unify::unify::{gather_fields, RecordStructure};
// If the `ext` has concrete fields (e.g. { foo : Int}{ bar : Bool }), merge them
let RecordStructure { fields, ext } = gather_fields(subs, fields, ext_var);

View file

@ -1,7 +1,6 @@
extern crate bumpalo;
use self::bumpalo::Bump;
use roc::solve;
use roc::unique_builtins;
use roc_can::constraint::Constraint;
use roc_can::env::Env;
@ -20,6 +19,7 @@ use roc_parse::blankspace::space0_before;
use roc_parse::parser::{loc, Fail, Parser, State};
use roc_problem::can::Problem;
use roc_region::all::{Located, Region};
use roc_solve::solve;
use roc_types::subs::{Content, Subs, VarStore, Variable};
use roc_types::types::Type;
use std::hash::Hash;

View file

@ -18,11 +18,11 @@ mod test_load {
use inlinable_string::InlinableString;
use roc::load::{load, LoadedModule};
use roc::pretty_print_types::{content_to_string, name_all_type_vars};
use roc::solve::SubsByModule;
use roc_can::def::Declaration::*;
use roc_can::def::Def;
use roc_collections::all::MutMap;
use roc_module::symbol::{Interns, ModuleId};
use roc_solve::solve::SubsByModule;
use roc_types::subs::Subs;
use std::collections::HashMap;

View file

@ -17,12 +17,12 @@ mod test_uniqueness_load {
use inlinable_string::InlinableString;
use roc::load::{load, LoadedModule};
use roc::pretty_print_types::{content_to_string, name_all_type_vars};
use roc::solve::SubsByModule;
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_solve::solve::SubsByModule;
use roc_types::subs::Subs;
use std::collections::HashMap;

17
compiler/unify/Cargo.toml Normal file
View file

@ -0,0 +1,17 @@
[package]
name = "roc_unify"
version = "0.1.0"
authors = ["Richard Feldman <oss@rtfeldman.com>"]
edition = "2018"
[dependencies]
roc_collections = { path = "../collections" }
roc_module = { path = "../module" }
roc_types = { path = "../types" }
[dev-dependencies]
pretty_assertions = "0.5.1 "
maplit = "1.0.1"
indoc = "0.3.3"
quickcheck = "0.8"
quickcheck_macros = "0.8"

14
compiler/unify/src/lib.rs Normal file
View file

@ -0,0 +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 unify;