mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-11 05:34:11 +03:00
Merge pull request #225 from rtfeldman/workspace2
Extract can/ into its own crate, plus its deps
This commit is contained in:
commit
758de2e7bf
54
Cargo.lock
generated
54
Cargo.lock
generated
@ -878,15 +878,38 @@ dependencies = [
|
|||||||
"pretty_assertions",
|
"pretty_assertions",
|
||||||
"quickcheck",
|
"quickcheck",
|
||||||
"quickcheck_macros",
|
"quickcheck_macros",
|
||||||
|
"roc_can",
|
||||||
"roc_collections",
|
"roc_collections",
|
||||||
"roc_module",
|
"roc_module",
|
||||||
"roc_parse",
|
"roc_parse",
|
||||||
"roc_region",
|
"roc_region",
|
||||||
|
"roc_types",
|
||||||
"target-lexicon",
|
"target-lexicon",
|
||||||
"tokio",
|
"tokio",
|
||||||
"wyhash",
|
"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]]
|
[[package]]
|
||||||
name = "roc_collections"
|
name = "roc_collections"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@ -930,6 +953,23 @@ dependencies = [
|
|||||||
name = "roc_region"
|
name = "roc_region"
|
||||||
version = "0.1.0"
|
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]]
|
[[package]]
|
||||||
name = "rustc_version"
|
name = "rustc_version"
|
||||||
version = "0.2.3"
|
version = "0.2.3"
|
||||||
@ -1076,6 +1116,20 @@ version = "0.1.5"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "63f18aa3b0e35fed5a0048f029558b1518095ffe2a0a31fb87c93dece93a4993"
|
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]]
|
[[package]]
|
||||||
name = "version_check"
|
name = "version_check"
|
||||||
version = "0.9.1"
|
version = "0.9.1"
|
||||||
|
@ -5,5 +5,9 @@ members = [
|
|||||||
"compiler/region",
|
"compiler/region",
|
||||||
"compiler/collections",
|
"compiler/collections",
|
||||||
"compiler/module",
|
"compiler/module",
|
||||||
"compiler/parse"
|
"compiler/parse",
|
||||||
|
"compiler/can",
|
||||||
|
"compiler/types",
|
||||||
|
"vendor/ena",
|
||||||
|
"vendor/pathfinding"
|
||||||
]
|
]
|
||||||
|
@ -9,6 +9,8 @@ roc_collections = { path = "./collections" }
|
|||||||
roc_region = { path = "./region" }
|
roc_region = { path = "./region" }
|
||||||
roc_module = { path = "./module" }
|
roc_module = { path = "./module" }
|
||||||
roc_parse = { path = "./parse" }
|
roc_parse = { path = "./parse" }
|
||||||
|
roc_types = { path = "./types" }
|
||||||
|
roc_can = { path = "./can" }
|
||||||
log = "0.4.8"
|
log = "0.4.8"
|
||||||
petgraph = { version = "0.4.5", optional = true }
|
petgraph = { version = "0.4.5", optional = true }
|
||||||
im = "14" # im and im-rc should always have the same version!
|
im = "14" # im and im-rc should always have the same version!
|
||||||
|
24
compiler/can/Cargo.toml
Normal file
24
compiler/can/Cargo.toml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
[package]
|
||||||
|
name = "roc_can"
|
||||||
|
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_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"
|
@ -1,8 +1,5 @@
|
|||||||
use crate::can;
|
use crate::env::Env;
|
||||||
use crate::can::env::Env;
|
use crate::scope::Scope;
|
||||||
use crate::can::scope::Scope;
|
|
||||||
use crate::subs::{VarStore, Variable};
|
|
||||||
use crate::types::{Alias, Problem, Type};
|
|
||||||
use roc_collections::all::{ImMap, MutMap, MutSet, SendMap};
|
use roc_collections::all::{ImMap, MutMap, MutSet, SendMap};
|
||||||
use roc_module::ident::Ident;
|
use roc_module::ident::Ident;
|
||||||
use roc_module::ident::{Lowercase, TagName};
|
use roc_module::ident::{Lowercase, TagName};
|
||||||
@ -10,6 +7,8 @@ use roc_module::symbol::Symbol;
|
|||||||
use roc_parse::ast::{AssignedField, Tag, TypeAnnotation};
|
use roc_parse::ast::{AssignedField, Tag, TypeAnnotation};
|
||||||
use roc_region::all::Located;
|
use roc_region::all::Located;
|
||||||
use roc_region::all::Region;
|
use roc_region::all::Region;
|
||||||
|
use roc_types::subs::{VarStore, Variable};
|
||||||
|
use roc_types::types::{Alias, Problem, Type};
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct Annotation {
|
pub struct Annotation {
|
||||||
@ -120,7 +119,7 @@ fn can_annotation_help(
|
|||||||
match scope.lookup(&ident, region) {
|
match scope.lookup(&ident, region) {
|
||||||
Ok(symbol) => symbol,
|
Ok(symbol) => symbol,
|
||||||
Err(problem) => {
|
Err(problem) => {
|
||||||
env.problem(crate::can::problem::Problem::RuntimeError(problem));
|
env.problem(crate::problem::Problem::RuntimeError(problem));
|
||||||
|
|
||||||
return Type::Erroneous(Problem::UnrecognizedIdent(ident.into()));
|
return Type::Erroneous(Problem::UnrecognizedIdent(ident.into()));
|
||||||
}
|
}
|
||||||
@ -131,7 +130,7 @@ fn can_annotation_help(
|
|||||||
Err(problem) => {
|
Err(problem) => {
|
||||||
// Either the module wasn't imported, or
|
// Either the module wasn't imported, or
|
||||||
// it was imported but it doesn't expose this ident.
|
// 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()));
|
return Type::Erroneous(Problem::UnrecognizedIdent((*ident).into()));
|
||||||
}
|
}
|
||||||
@ -185,7 +184,9 @@ fn can_annotation_help(
|
|||||||
|
|
||||||
Err((original_region, shadow)) => {
|
Err((original_region, shadow)) => {
|
||||||
let problem = Problem::Shadowed(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);
|
return Type::Erroneous(problem);
|
||||||
}
|
}
|
97
compiler/can/src/constraint.rs
Normal file
97
compiler/can/src/constraint.rs
Normal file
@ -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<Type>, Region),
|
||||||
|
Lookup(Symbol, Expected<Type>, Region),
|
||||||
|
Pattern(Region, PatternCategory, Type, PExpected<Type>),
|
||||||
|
True, // Used for things that always unify, e.g. blanks and runtime errors
|
||||||
|
SaveTheEnvironment,
|
||||||
|
Let(Box<LetConstraint>),
|
||||||
|
And(Vec<Constraint>),
|
||||||
|
}
|
||||||
|
|
||||||
|
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<Symbol, Alias>,
|
||||||
|
var_store: &VarStore,
|
||||||
|
introduced: &mut ImSet<Variable>,
|
||||||
|
) {
|
||||||
|
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<Variable>,
|
||||||
|
pub flex_vars: Vec<Variable>,
|
||||||
|
pub def_types: SendMap<Symbol, Located<Type>>,
|
||||||
|
pub def_aliases: SendMap<Symbol, Alias>,
|
||||||
|
pub defs_constraint: Constraint,
|
||||||
|
pub ret_constraint: Constraint,
|
||||||
|
}
|
@ -1,26 +1,26 @@
|
|||||||
use crate::can::annotation::canonicalize_annotation;
|
use crate::annotation::canonicalize_annotation;
|
||||||
use crate::can::env::Env;
|
use crate::env::Env;
|
||||||
use crate::can::expr::Expr::{self, *};
|
use crate::expr::Expr::{self, *};
|
||||||
use crate::can::expr::{
|
use crate::expr::{
|
||||||
canonicalize_expr, local_successors, references_from_call, references_from_local, Output,
|
canonicalize_expr, local_successors, references_from_call, references_from_local, Output,
|
||||||
Recursive,
|
Recursive,
|
||||||
};
|
};
|
||||||
use crate::can::pattern::PatternType;
|
use crate::pattern::PatternType;
|
||||||
use crate::can::pattern::{bindings_from_patterns, canonicalize_pattern, Pattern};
|
use crate::pattern::{bindings_from_patterns, canonicalize_pattern, Pattern};
|
||||||
use crate::can::problem::Problem;
|
use crate::problem::Problem;
|
||||||
use crate::can::problem::RuntimeError;
|
use crate::problem::RuntimeError;
|
||||||
use crate::can::procedure::References;
|
use crate::procedure::References;
|
||||||
use crate::can::scope::Scope;
|
use crate::scope::Scope;
|
||||||
use crate::graph::{strongly_connected_components, topological_sort_into_groups};
|
|
||||||
use crate::subs::{VarStore, Variable};
|
|
||||||
use crate::types::{Alias, Type};
|
|
||||||
use roc_collections::all::{default_hasher, ImMap, ImSet, MutMap, MutSet, SendMap};
|
use roc_collections::all::{default_hasher, ImMap, ImSet, MutMap, MutSet, SendMap};
|
||||||
use roc_module::ident::{Ident, Lowercase};
|
use roc_module::ident::{Ident, Lowercase};
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
use roc_parse::ast;
|
use roc_parse::ast;
|
||||||
use roc_region::all::{Located, Region};
|
use roc_region::all::{Located, Region};
|
||||||
|
use roc_types::subs::{VarStore, Variable};
|
||||||
|
use roc_types::types::{Alias, Type};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
use ven_graph::{strongly_connected_components, topological_sort_into_groups};
|
||||||
|
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
@ -208,7 +208,7 @@ pub fn canonicalize_defs<'a>(
|
|||||||
make_tag_union_recursive(symbol, &mut can_ann.typ, var_store);
|
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,
|
region: ann.region,
|
||||||
vars: can_vars,
|
vars: can_vars,
|
||||||
typ: can_ann.typ,
|
typ: can_ann.typ,
|
@ -1,5 +1,5 @@
|
|||||||
use crate::can::problem::{Problem, RuntimeError};
|
use crate::problem::{Problem, RuntimeError};
|
||||||
use crate::can::procedure::References;
|
use crate::procedure::References;
|
||||||
use inlinable_string::InlinableString;
|
use inlinable_string::InlinableString;
|
||||||
use roc_collections::all::{MutMap, MutSet};
|
use roc_collections::all::{MutMap, MutSet};
|
||||||
use roc_module::symbol::{IdentIds, ModuleId, ModuleIds, Symbol};
|
use roc_module::symbol::{IdentIds, ModuleId, ModuleIds, Symbol};
|
66
compiler/can/src/expected.rs
Normal file
66
compiler/can/src/expected.rs
Normal file
@ -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<T> {
|
||||||
|
NoExpectation(T),
|
||||||
|
FromAnnotation(Located<Pattern>, usize, AnnotationSource, T),
|
||||||
|
ForReason(Reason, T, Region),
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Like Expected, but for Patterns.
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub enum PExpected<T> {
|
||||||
|
NoExpectation(T),
|
||||||
|
ForReason(PReason, T, Region),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> PExpected<T> {
|
||||||
|
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<T> Expected<T> {
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,22 +1,22 @@
|
|||||||
use crate::can::def::{can_defs_with_return, Def};
|
use crate::def::{can_defs_with_return, Def};
|
||||||
use crate::can::env::Env;
|
use crate::env::Env;
|
||||||
use crate::can::num::{
|
use crate::num::{
|
||||||
finish_parsing_base, finish_parsing_float, finish_parsing_int, float_expr_from_result,
|
finish_parsing_base, finish_parsing_float, finish_parsing_int, float_expr_from_result,
|
||||||
int_expr_from_result,
|
int_expr_from_result,
|
||||||
};
|
};
|
||||||
use crate::can::pattern::PatternType::*;
|
use crate::pattern::PatternType::*;
|
||||||
use crate::can::pattern::{canonicalize_pattern, Pattern};
|
use crate::pattern::{canonicalize_pattern, Pattern};
|
||||||
use crate::can::problem::{Problem, RuntimeError};
|
use crate::problem::{Problem, RuntimeError};
|
||||||
use crate::can::procedure::References;
|
use crate::procedure::References;
|
||||||
use crate::can::scope::Scope;
|
use crate::scope::Scope;
|
||||||
use crate::subs::{VarStore, Variable};
|
|
||||||
use crate::types::Alias;
|
|
||||||
use roc_collections::all::{ImSet, MutMap, MutSet, SendMap};
|
use roc_collections::all::{ImSet, MutMap, MutSet, SendMap};
|
||||||
use roc_module::ident::{Lowercase, TagName};
|
use roc_module::ident::{Lowercase, TagName};
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
use roc_parse::ast;
|
use roc_parse::ast;
|
||||||
use roc_parse::operator::CalledVia;
|
use roc_parse::operator::CalledVia;
|
||||||
use roc_region::all::{Located, Region};
|
use roc_region::all::{Located, Region};
|
||||||
|
use roc_types::subs::{VarStore, Variable};
|
||||||
|
use roc_types::types::Alias;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::i64;
|
use std::i64;
|
||||||
use std::ops::Neg;
|
use std::ops::Neg;
|
26
compiler/can/src/lib.rs
Normal file
26
compiler/can/src/lib.rs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#![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;
|
||||||
|
pub mod env;
|
||||||
|
pub mod expected;
|
||||||
|
pub mod expr;
|
||||||
|
pub mod module;
|
||||||
|
pub mod num;
|
||||||
|
pub mod operator;
|
||||||
|
pub mod pattern;
|
||||||
|
pub mod problem;
|
||||||
|
pub mod procedure;
|
||||||
|
pub mod scope;
|
||||||
|
pub mod string;
|
@ -1,12 +1,10 @@
|
|||||||
use crate::can::def::{canonicalize_defs, sort_can_defs, Declaration};
|
use crate::def::{canonicalize_defs, sort_can_defs, Declaration};
|
||||||
use crate::can::env::Env;
|
use crate::env::Env;
|
||||||
use crate::can::expr::Output;
|
use crate::expr::Output;
|
||||||
use crate::can::operator::desugar_def;
|
use crate::operator::desugar_def;
|
||||||
use crate::can::pattern::PatternType;
|
use crate::pattern::PatternType;
|
||||||
use crate::can::problem::{Problem, RuntimeError};
|
use crate::problem::{Problem, RuntimeError};
|
||||||
use crate::can::scope::Scope;
|
use crate::scope::Scope;
|
||||||
use crate::subs::{VarStore, Variable};
|
|
||||||
use crate::types::Alias;
|
|
||||||
use bumpalo::Bump;
|
use bumpalo::Bump;
|
||||||
use roc_collections::all::{MutMap, MutSet};
|
use roc_collections::all::{MutMap, MutSet};
|
||||||
use roc_module::ident::Ident;
|
use roc_module::ident::Ident;
|
||||||
@ -14,6 +12,8 @@ use roc_module::ident::Lowercase;
|
|||||||
use roc_module::symbol::{IdentIds, ModuleId, ModuleIds, Symbol};
|
use roc_module::symbol::{IdentIds, ModuleId, ModuleIds, Symbol};
|
||||||
use roc_parse::ast;
|
use roc_parse::ast;
|
||||||
use roc_region::all::{Located, Region};
|
use roc_region::all::{Located, Region};
|
||||||
|
use roc_types::subs::{VarStore, Variable};
|
||||||
|
use roc_types::types::Alias;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ModuleOutput {
|
pub struct ModuleOutput {
|
||||||
@ -139,7 +139,7 @@ pub fn canonicalize_module_defs<'a>(
|
|||||||
|
|
||||||
match sort_can_defs(&mut env, defs, Output::default()) {
|
match sort_can_defs(&mut env, defs, Output::default()) {
|
||||||
(Ok(declarations), output) => {
|
(Ok(declarations), output) => {
|
||||||
use crate::can::def::Declaration::*;
|
use crate::def::Declaration::*;
|
||||||
|
|
||||||
let mut exposed_vars_by_symbol = Vec::with_capacity(exposed_symbols.len());
|
let mut exposed_vars_by_symbol = Vec::with_capacity(exposed_symbols.len());
|
||||||
|
|
@ -1,9 +1,9 @@
|
|||||||
use crate::can::env::Env;
|
use crate::env::Env;
|
||||||
use crate::can::expr::Expr;
|
use crate::expr::Expr;
|
||||||
use crate::can::problem::Problem;
|
use crate::problem::Problem;
|
||||||
use crate::can::problem::RuntimeError::*;
|
use crate::problem::RuntimeError::*;
|
||||||
use crate::subs::VarStore;
|
|
||||||
use roc_parse::ast::Base;
|
use roc_parse::ast::Base;
|
||||||
|
use roc_types::subs::VarStore;
|
||||||
use std::i64;
|
use std::i64;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
@ -1,13 +1,12 @@
|
|||||||
use crate::can::env::Env;
|
use crate::env::Env;
|
||||||
use crate::can::num::{finish_parsing_base, finish_parsing_float, finish_parsing_int};
|
use crate::num::{finish_parsing_base, finish_parsing_float, finish_parsing_int};
|
||||||
use crate::can::problem::{Problem, RuntimeError};
|
use crate::problem::{Problem, RuntimeError};
|
||||||
use crate::can::scope::Scope;
|
use crate::scope::Scope;
|
||||||
use crate::subs::VarStore;
|
|
||||||
use crate::subs::Variable;
|
|
||||||
use roc_module::ident::{Ident, Lowercase, TagName};
|
use roc_module::ident::{Ident, Lowercase, TagName};
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
use roc_parse::ast;
|
use roc_parse::ast;
|
||||||
use roc_region::all::{Located, Region};
|
use roc_region::all::{Located, Region};
|
||||||
|
use roc_types::subs::{VarStore, Variable};
|
||||||
|
|
||||||
/// A pattern, including possible problems (e.g. shadowing) so that
|
/// A pattern, including possible problems (e.g. shadowing) so that
|
||||||
/// codegen can generate a runtime error if this pattern is reached.
|
/// codegen can generate a runtime error if this pattern is reached.
|
@ -1,10 +1,10 @@
|
|||||||
use crate::can::pattern::PatternType;
|
use crate::pattern::PatternType;
|
||||||
use crate::types;
|
|
||||||
use inlinable_string::InlinableString;
|
use inlinable_string::InlinableString;
|
||||||
use roc_module::ident::Ident;
|
use roc_module::ident::Ident;
|
||||||
use roc_module::symbol::{ModuleId, Symbol};
|
use roc_module::symbol::{ModuleId, Symbol};
|
||||||
use roc_parse::operator::BinOp;
|
use roc_parse::operator::BinOp;
|
||||||
use roc_region::all::{Located, Region};
|
use roc_region::all::{Located, Region};
|
||||||
|
use roc_types::types;
|
||||||
|
|
||||||
/// Problems that can occur in the course of canonicalization.
|
/// Problems that can occur in the course of canonicalization.
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
@ -1,9 +1,9 @@
|
|||||||
use crate::can::expr::Expr;
|
use crate::expr::Expr;
|
||||||
use crate::can::pattern::Pattern;
|
use crate::pattern::Pattern;
|
||||||
use crate::subs::Variable;
|
|
||||||
use roc_collections::all::ImSet;
|
use roc_collections::all::ImSet;
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
use roc_region::all::{Located, Region};
|
use roc_region::all::{Located, Region};
|
||||||
|
use roc_types::subs::Variable;
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct Procedure {
|
pub struct Procedure {
|
@ -1,10 +1,10 @@
|
|||||||
use crate::can::problem::RuntimeError;
|
use crate::problem::RuntimeError;
|
||||||
use crate::subs::Variable;
|
|
||||||
use crate::types::{Alias, Type};
|
|
||||||
use roc_collections::all::ImMap;
|
use roc_collections::all::ImMap;
|
||||||
use roc_module::ident::{Ident, Lowercase};
|
use roc_module::ident::{Ident, Lowercase};
|
||||||
use roc_module::symbol::{IdentIds, ModuleId, Symbol};
|
use roc_module::symbol::{IdentIds, ModuleId, Symbol};
|
||||||
use roc_region::all::{Located, Region};
|
use roc_region::all::{Located, Region};
|
||||||
|
use roc_types::subs::Variable;
|
||||||
|
use roc_types::types::{Alias, Type};
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct Scope {
|
pub struct Scope {
|
126
compiler/can/tests/helpers/mod.rs
Normal file
126
compiler/can/tests/helpers/mod.rs
Normal file
@ -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<ast::Expr<'a>, 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<Located<ast::Expr<'a>>, 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<Expr>,
|
||||||
|
pub output: Output,
|
||||||
|
pub problems: Vec<Problem>,
|
||||||
|
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<K, V, I>(pairs: I) -> MutMap<K, V>
|
||||||
|
where
|
||||||
|
I: IntoIterator<Item = (K, V)>,
|
||||||
|
K: Hash + Eq,
|
||||||
|
{
|
||||||
|
let mut answer = MutMap::default();
|
||||||
|
|
||||||
|
for (key, value) in pairs {
|
||||||
|
answer.insert(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
answer
|
||||||
|
}
|
@ -4,7 +4,8 @@ extern crate pretty_assertions;
|
|||||||
extern crate indoc;
|
extern crate indoc;
|
||||||
|
|
||||||
extern crate bumpalo;
|
extern crate bumpalo;
|
||||||
extern crate roc;
|
extern crate roc_can;
|
||||||
|
extern crate roc_parse;
|
||||||
extern crate roc_region;
|
extern crate roc_region;
|
||||||
|
|
||||||
mod helpers;
|
mod helpers;
|
||||||
@ -13,9 +14,9 @@ mod helpers;
|
|||||||
mod test_canonicalize {
|
mod test_canonicalize {
|
||||||
use crate::helpers::{can_expr_with, test_home, CanExprOut};
|
use crate::helpers::{can_expr_with, test_home, CanExprOut};
|
||||||
use bumpalo::Bump;
|
use bumpalo::Bump;
|
||||||
use roc::can::expr::Expr::{self, *};
|
use roc_can::expr::Expr::{self, *};
|
||||||
use roc::can::expr::Recursive;
|
use roc_can::expr::Recursive;
|
||||||
use roc::can::problem::{Problem, RuntimeError};
|
use roc_can::problem::{Problem, RuntimeError};
|
||||||
use roc_region::all::{Located, Region};
|
use roc_region::all::{Located, Region};
|
||||||
use std::{f64, i64};
|
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 {
|
match expr {
|
||||||
LetRec(assignments, body, _, _) => {
|
LetRec(assignments, body, _, _) => {
|
||||||
match &assignments.get(i).map(|def| &def.loc_expr.value) {
|
match &assignments.get(i).map(|def| &def.loc_expr.value) {
|
@ -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 ident;
|
||||||
pub mod symbol;
|
pub mod symbol;
|
||||||
|
|
||||||
|
@ -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]
|
#[macro_use]
|
||||||
pub mod parser;
|
pub mod parser;
|
||||||
pub mod ast;
|
pub mod ast;
|
||||||
|
@ -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;
|
pub mod all;
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
use crate::solve::{BuiltinAlias, SolvedType};
|
use crate::solve::{BuiltinAlias, SolvedType};
|
||||||
use crate::subs::VarId;
|
|
||||||
use roc_collections::all::{default_hasher, MutMap};
|
use roc_collections::all::{default_hasher, MutMap};
|
||||||
use roc_module::ident::TagName;
|
use roc_module::ident::TagName;
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
use roc_region::all::{Located, Region};
|
use roc_region::all::{Located, Region};
|
||||||
|
use roc_types::subs::VarId;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
pub mod annotation;
|
|
||||||
pub mod def;
|
|
||||||
pub mod env;
|
|
||||||
pub mod expr;
|
|
||||||
pub mod module;
|
|
||||||
pub mod num;
|
|
||||||
pub mod operator;
|
|
||||||
pub mod pattern;
|
|
||||||
pub mod problem;
|
|
||||||
pub mod procedure;
|
|
||||||
pub mod scope;
|
|
||||||
pub mod string;
|
|
@ -1,11 +1,12 @@
|
|||||||
use crate::subs::Variable;
|
use roc_can::constraint::Constraint::{self, *};
|
||||||
use crate::types::Constraint::{self, *};
|
use roc_can::constraint::LetConstraint;
|
||||||
use crate::types::Expected::{self, *};
|
use roc_can::expected::Expected::{self, *};
|
||||||
use crate::types::Type::{self, *};
|
|
||||||
use crate::types::{LetConstraint, Reason};
|
|
||||||
use roc_collections::all::SendMap;
|
use roc_collections::all::SendMap;
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
use roc_region::all::Region;
|
use roc_region::all::Region;
|
||||||
|
use roc_types::subs::Variable;
|
||||||
|
use roc_types::types::Reason;
|
||||||
|
use roc_types::types::Type::{self, *};
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn int_literal(num_var: Variable, expected: Expected<Type>, region: Region) -> Constraint {
|
pub fn int_literal(num_var: Variable, expected: Expected<Type>, region: Region) -> Constraint {
|
||||||
|
@ -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::{
|
use crate::constrain::builtins::{
|
||||||
empty_list_type, float_literal, int_literal, list_type, str_type,
|
empty_list_type, float_literal, int_literal, list_type, str_type,
|
||||||
};
|
};
|
||||||
use crate::constrain::pattern::{constrain_pattern, PatternState};
|
use crate::constrain::pattern::{constrain_pattern, PatternState};
|
||||||
use crate::subs::Variable;
|
use roc_can::constraint::Constraint::{self, *};
|
||||||
use crate::types::Alias;
|
use roc_can::constraint::LetConstraint;
|
||||||
use crate::types::AnnotationSource::{self, *};
|
use roc_can::def::{Declaration, Def};
|
||||||
use crate::types::Constraint::{self, *};
|
use roc_can::expected::Expected::{self, *};
|
||||||
use crate::types::Expected::{self, *};
|
use roc_can::expected::PExpected;
|
||||||
use crate::types::PReason;
|
use roc_can::expr::Expr::{self, *};
|
||||||
use crate::types::Type::{self, *};
|
use roc_can::expr::Field;
|
||||||
use crate::types::{LetConstraint, PExpected, Reason};
|
use roc_can::pattern::Pattern;
|
||||||
use roc_collections::all::{ImMap, SendMap};
|
use roc_collections::all::{ImMap, SendMap};
|
||||||
use roc_module::ident::{Lowercase, TagName};
|
use roc_module::ident::{Lowercase, TagName};
|
||||||
use roc_module::symbol::{ModuleId, Symbol};
|
use roc_module::symbol::{ModuleId, Symbol};
|
||||||
use roc_region::all::{Located, Region};
|
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
|
/// This is for constraining Defs
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
use crate::builtins;
|
use crate::builtins;
|
||||||
use crate::can::def::Declaration;
|
|
||||||
use crate::constrain::expr::constrain_decls;
|
use crate::constrain::expr::constrain_decls;
|
||||||
use crate::solve::{BuiltinAlias, SolvedAtom, SolvedType};
|
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;
|
||||||
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_collections::all::{ImMap, MutMap, SendMap};
|
||||||
use roc_module::ident::Lowercase;
|
use roc_module::ident::Lowercase;
|
||||||
use roc_module::symbol::{ModuleId, Symbol};
|
use roc_module::symbol::{ModuleId, Symbol};
|
||||||
use roc_region::all::Located;
|
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)]
|
#[inline(always)]
|
||||||
pub fn constrain_module(
|
pub fn constrain_module(
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
use crate::can::pattern::Pattern::{self, *};
|
|
||||||
use crate::can::pattern::RecordDestruct;
|
|
||||||
use crate::constrain::builtins;
|
use crate::constrain::builtins;
|
||||||
use crate::subs::Variable;
|
use roc_can::constraint::Constraint;
|
||||||
use crate::types::{Constraint, Expected, PExpected, PatternCategory, Type};
|
use roc_can::expected::{Expected, PExpected};
|
||||||
|
use roc_can::pattern::Pattern::{self, *};
|
||||||
|
use roc_can::pattern::RecordDestruct;
|
||||||
use roc_collections::all::SendMap;
|
use roc_collections::all::SendMap;
|
||||||
use roc_module::ident::Lowercase;
|
use roc_module::ident::Lowercase;
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
use roc_region::all::{Located, Region};
|
use roc_region::all::{Located, Region};
|
||||||
|
use roc_types::subs::Variable;
|
||||||
|
use roc_types::types::{PatternCategory, Type};
|
||||||
|
|
||||||
pub struct PatternState {
|
pub struct PatternState {
|
||||||
pub headers: SendMap<Symbol, Located<Type>>,
|
pub headers: SendMap<Symbol, Located<Type>>,
|
||||||
|
@ -16,9 +16,9 @@ use cranelift_module::{Backend, FuncId, Linkage, Module};
|
|||||||
use crate::crane::convert::{sig_from_layout, type_from_layout};
|
use crate::crane::convert::{sig_from_layout, type_from_layout};
|
||||||
use crate::mono::expr::{Expr, Proc, Procs};
|
use crate::mono::expr::{Expr, Proc, Procs};
|
||||||
use crate::mono::layout::{Builtin, Layout};
|
use crate::mono::layout::{Builtin, Layout};
|
||||||
use crate::subs::{Subs, Variable};
|
|
||||||
use roc_collections::all::ImMap;
|
use roc_collections::all::ImMap;
|
||||||
use roc_module::symbol::{Interns, Symbol};
|
use roc_module::symbol::{Interns, Symbol};
|
||||||
|
use roc_types::subs::{Subs, Variable};
|
||||||
|
|
||||||
type Scope = ImMap<Symbol, ScopeEntry>;
|
type Scope = ImMap<Symbol, ScopeEntry>;
|
||||||
|
|
||||||
|
@ -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<Problem>,
|
|
||||||
constraint: &Constraint,
|
|
||||||
expr_var: Variable,
|
|
||||||
) -> (Content, Solved<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)
|
|
||||||
}
|
|
@ -11,8 +11,6 @@
|
|||||||
// re-enable this when working on performance optimizations than have it block PRs.
|
// re-enable this when working on performance optimizations than have it block PRs.
|
||||||
#![allow(clippy::large_enum_variant)]
|
#![allow(clippy::large_enum_variant)]
|
||||||
|
|
||||||
pub mod can;
|
|
||||||
pub mod graph;
|
|
||||||
pub mod uniqueness;
|
pub mod uniqueness;
|
||||||
|
|
||||||
pub mod string;
|
pub mod string;
|
||||||
@ -22,18 +20,11 @@ pub mod unique_builtins;
|
|||||||
|
|
||||||
pub mod constrain;
|
pub mod constrain;
|
||||||
pub mod crane;
|
pub mod crane;
|
||||||
pub mod ena;
|
|
||||||
pub mod fmt;
|
pub mod fmt;
|
||||||
pub mod infer;
|
|
||||||
pub mod llvm;
|
pub mod llvm;
|
||||||
pub mod load;
|
pub mod load;
|
||||||
pub mod mono;
|
pub mod mono;
|
||||||
pub mod pretty_print_types;
|
pub mod pretty_print_types;
|
||||||
pub mod reporting;
|
pub mod reporting;
|
||||||
pub mod solve;
|
pub mod solve;
|
||||||
pub mod subs;
|
|
||||||
pub mod types;
|
|
||||||
pub mod unify;
|
pub mod unify;
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate log;
|
|
||||||
|
@ -11,9 +11,9 @@ use inkwell::{FloatPredicate, IntPredicate};
|
|||||||
use crate::llvm::convert::{basic_type_from_layout, get_fn_type};
|
use crate::llvm::convert::{basic_type_from_layout, get_fn_type};
|
||||||
use crate::mono::expr::{Expr, Proc, Procs};
|
use crate::mono::expr::{Expr, Proc, Procs};
|
||||||
use crate::mono::layout::Layout;
|
use crate::mono::layout::Layout;
|
||||||
use crate::subs::{Subs, Variable};
|
|
||||||
use roc_collections::all::ImMap;
|
use roc_collections::all::ImMap;
|
||||||
use roc_module::symbol::{Interns, Symbol};
|
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
|
/// 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!
|
/// output in debug builds, but we don't want it to print to stdout in release builds!
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
use crate::builtins;
|
use crate::builtins;
|
||||||
use crate::builtins::StdLib;
|
use crate::builtins::StdLib;
|
||||||
use crate::can;
|
|
||||||
use crate::can::def::Declaration;
|
|
||||||
use crate::can::module::{canonicalize_module_defs, ModuleOutput};
|
|
||||||
use crate::constrain::module::{
|
use crate::constrain::module::{
|
||||||
constrain_imported_aliases, constrain_imported_values, constrain_module, load_builtin_aliases,
|
constrain_imported_aliases, constrain_imported_values, constrain_module, load_builtin_aliases,
|
||||||
Import,
|
Import,
|
||||||
};
|
};
|
||||||
use crate::solve::{self, BuiltinAlias, ExposedModuleTypes, Solved, SolvedType, SubsByModule};
|
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 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};
|
use roc_collections::all::{default_hasher, MutMap, MutSet, SendMap};
|
||||||
use roc_module::ident::{Ident, Lowercase, ModuleName};
|
use roc_module::ident::{Ident, Lowercase, ModuleName};
|
||||||
use roc_module::symbol::{IdentIds, Interns, ModuleId, ModuleIds, Symbol};
|
use roc_module::symbol::{IdentIds, Interns, ModuleId, ModuleIds, Symbol};
|
||||||
@ -18,6 +17,8 @@ use roc_parse::ast::{self, Attempting, ExposesEntry, ImportsEntry, InterfaceHead
|
|||||||
use roc_parse::module::module_defs;
|
use roc_parse::module::module_defs;
|
||||||
use roc_parse::parser::{Fail, Parser, State};
|
use roc_parse::parser::{Fail, Parser, State};
|
||||||
use roc_region::all::{Located, Region};
|
use roc_region::all::{Located, Region};
|
||||||
|
use roc_types::subs::{Subs, VarStore, Variable};
|
||||||
|
use roc_types::types::{self, Alias};
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::fs::read_to_string;
|
use std::fs::read_to_string;
|
||||||
use std::io;
|
use std::io;
|
||||||
@ -49,7 +50,7 @@ pub struct LoadedModule {
|
|||||||
pub module_id: ModuleId,
|
pub module_id: ModuleId,
|
||||||
pub interns: Interns,
|
pub interns: Interns,
|
||||||
pub solved: Solved<Subs>,
|
pub solved: Solved<Subs>,
|
||||||
pub can_problems: Vec<can::problem::Problem>,
|
pub can_problems: Vec<roc_can::problem::Problem>,
|
||||||
pub type_problems: Vec<types::Problem>,
|
pub type_problems: Vec<types::Problem>,
|
||||||
pub declarations: Vec<Declaration>,
|
pub declarations: Vec<Declaration>,
|
||||||
}
|
}
|
||||||
@ -83,7 +84,7 @@ enum Msg {
|
|||||||
module: Module,
|
module: Module,
|
||||||
constraint: Constraint,
|
constraint: Constraint,
|
||||||
ident_ids: IdentIds,
|
ident_ids: IdentIds,
|
||||||
problems: Vec<can::problem::Problem>,
|
problems: Vec<roc_can::problem::Problem>,
|
||||||
var_store: VarStore,
|
var_store: VarStore,
|
||||||
},
|
},
|
||||||
Solved {
|
Solved {
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
use crate::can::pattern::Pattern;
|
|
||||||
use crate::can::{self};
|
|
||||||
use crate::mono::layout::{Builtin, Layout};
|
use crate::mono::layout::{Builtin, Layout};
|
||||||
use crate::subs::{Content, Subs, Variable};
|
|
||||||
use bumpalo::collections::Vec;
|
use bumpalo::collections::Vec;
|
||||||
use bumpalo::Bump;
|
use bumpalo::Bump;
|
||||||
|
use roc_can::pattern::Pattern;
|
||||||
|
use roc_can::{self};
|
||||||
use roc_collections::all::MutMap;
|
use roc_collections::all::MutMap;
|
||||||
use roc_module::ident::{Lowercase, TagName};
|
use roc_module::ident::{Lowercase, TagName};
|
||||||
use roc_module::symbol::{IdentIds, ModuleId, Symbol};
|
use roc_module::symbol::{IdentIds, ModuleId, Symbol};
|
||||||
use roc_region::all::Located;
|
use roc_region::all::Located;
|
||||||
|
use roc_types::subs::{Content, Subs, Variable};
|
||||||
|
|
||||||
pub type Procs<'a> = MutMap<Symbol, Option<Proc<'a>>>;
|
pub type Procs<'a> = MutMap<Symbol, Option<Proc<'a>>>;
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ impl<'a> Expr<'a> {
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
arena: &'a Bump,
|
arena: &'a Bump,
|
||||||
subs: &'a Subs,
|
subs: &'a Subs,
|
||||||
can_expr: can::expr::Expr,
|
can_expr: roc_can::expr::Expr,
|
||||||
procs: &mut Procs<'a>,
|
procs: &mut Procs<'a>,
|
||||||
home: ModuleId,
|
home: ModuleId,
|
||||||
ident_ids: &mut IdentIds,
|
ident_ids: &mut IdentIds,
|
||||||
@ -133,12 +133,12 @@ impl<'a> Expr<'a> {
|
|||||||
|
|
||||||
fn from_can<'a>(
|
fn from_can<'a>(
|
||||||
env: &mut Env<'a, '_>,
|
env: &mut Env<'a, '_>,
|
||||||
can_expr: can::expr::Expr,
|
can_expr: roc_can::expr::Expr,
|
||||||
procs: &mut Procs<'a>,
|
procs: &mut Procs<'a>,
|
||||||
name: Option<Symbol>,
|
name: Option<Symbol>,
|
||||||
) -> Expr<'a> {
|
) -> Expr<'a> {
|
||||||
use crate::can::expr::Expr::*;
|
use roc_can::expr::Expr::*;
|
||||||
use crate::can::pattern::Pattern::*;
|
use roc_can::pattern::Pattern::*;
|
||||||
|
|
||||||
match can_expr {
|
match can_expr {
|
||||||
Int(_, val) => Expr::Int(val),
|
Int(_, val) => Expr::Int(val),
|
||||||
@ -349,7 +349,7 @@ fn from_can<'a>(
|
|||||||
fn add_closure<'a>(
|
fn add_closure<'a>(
|
||||||
env: &mut Env<'a, '_>,
|
env: &mut Env<'a, '_>,
|
||||||
symbol: Symbol,
|
symbol: Symbol,
|
||||||
can_body: can::expr::Expr,
|
can_body: roc_can::expr::Expr,
|
||||||
ret_var: Variable,
|
ret_var: Variable,
|
||||||
loc_args: &[(Variable, Located<Pattern>)],
|
loc_args: &[(Variable, Located<Pattern>)],
|
||||||
procs: &mut Procs<'a>,
|
procs: &mut Procs<'a>,
|
||||||
@ -396,12 +396,12 @@ fn add_closure<'a>(
|
|||||||
fn store_pattern<'a>(
|
fn store_pattern<'a>(
|
||||||
env: &mut Env<'a, '_>,
|
env: &mut Env<'a, '_>,
|
||||||
can_pat: Pattern,
|
can_pat: Pattern,
|
||||||
can_expr: can::expr::Expr,
|
can_expr: roc_can::expr::Expr,
|
||||||
var: Variable,
|
var: Variable,
|
||||||
procs: &mut Procs<'a>,
|
procs: &mut Procs<'a>,
|
||||||
stored: &mut Vec<'a, (Symbol, Variable, Expr<'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
|
// 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!
|
// 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, '_>,
|
env: &mut Env<'a, '_>,
|
||||||
cond_var: Variable,
|
cond_var: Variable,
|
||||||
expr_var: Variable,
|
expr_var: Variable,
|
||||||
loc_cond: Located<can::expr::Expr>,
|
loc_cond: Located<roc_can::expr::Expr>,
|
||||||
branches: std::vec::Vec<(Located<can::pattern::Pattern>, Located<can::expr::Expr>)>,
|
branches: std::vec::Vec<(
|
||||||
|
Located<roc_can::pattern::Pattern>,
|
||||||
|
Located<roc_can::expr::Expr>,
|
||||||
|
)>,
|
||||||
procs: &mut Procs<'a>,
|
procs: &mut Procs<'a>,
|
||||||
) -> Expr<'a> {
|
) -> Expr<'a> {
|
||||||
use crate::can::pattern::Pattern::*;
|
use roc_can::pattern::Pattern::*;
|
||||||
|
|
||||||
match branches.len() {
|
match branches.len() {
|
||||||
0 => {
|
0 => {
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
use crate::subs::{Content, FlatType, Subs, Variable};
|
|
||||||
use bumpalo::collections::Vec;
|
use bumpalo::collections::Vec;
|
||||||
use bumpalo::Bump;
|
use bumpalo::Bump;
|
||||||
use roc_collections::all::MutMap;
|
use roc_collections::all::MutMap;
|
||||||
use roc_module::ident::{Lowercase, TagName};
|
use roc_module::ident::{Lowercase, TagName};
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
|
use roc_types::subs::{Content, FlatType, Subs, Variable};
|
||||||
|
|
||||||
/// Types for code gen must be monomorphic. No type variables allowed!
|
/// Types for code gen must be monomorphic. No type variables allowed!
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[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
|
/// Panics if given a FlexVar or RigidVar, since those should have been
|
||||||
/// monomorphized away already!
|
/// monomorphized away already!
|
||||||
pub fn from_content(arena: &'a Bump, content: Content, subs: &Subs) -> Result<Self, ()> {
|
pub fn from_content(arena: &'a Bump, content: Content, subs: &Subs) -> Result<Self, ()> {
|
||||||
use crate::subs::Content::*;
|
use roc_types::subs::Content::*;
|
||||||
|
|
||||||
match content {
|
match content {
|
||||||
var @ FlexVar(_) | var @ RigidVar(_) => {
|
var @ FlexVar(_) | var @ RigidVar(_) => {
|
||||||
@ -103,7 +103,7 @@ fn layout_from_flat_type<'a>(
|
|||||||
flat_type: FlatType,
|
flat_type: FlatType,
|
||||||
subs: &Subs,
|
subs: &Subs,
|
||||||
) -> Result<Layout<'a>, ()> {
|
) -> Result<Layout<'a>, ()> {
|
||||||
use crate::subs::FlatType::*;
|
use roc_types::subs::FlatType::*;
|
||||||
|
|
||||||
match flat_type {
|
match flat_type {
|
||||||
Apply(symbol, args) => {
|
Apply(symbol, args) => {
|
||||||
@ -253,8 +253,8 @@ fn layout_from_flat_type<'a>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn layout_from_num_content<'a>(content: Content) -> Result<Layout<'a>, ()> {
|
fn layout_from_num_content<'a>(content: Content) -> Result<Layout<'a>, ()> {
|
||||||
use crate::subs::Content::*;
|
use roc_types::subs::Content::*;
|
||||||
use crate::subs::FlatType::*;
|
use roc_types::subs::FlatType::*;
|
||||||
|
|
||||||
match content {
|
match content {
|
||||||
var @ FlexVar(_) | var @ RigidVar(_) => {
|
var @ FlexVar(_) | var @ RigidVar(_) => {
|
||||||
@ -287,8 +287,8 @@ fn flatten_union(
|
|||||||
ext_var: Variable,
|
ext_var: Variable,
|
||||||
subs: &Subs,
|
subs: &Subs,
|
||||||
) {
|
) {
|
||||||
use crate::subs::Content::*;
|
use roc_types::subs::Content::*;
|
||||||
use crate::subs::FlatType::*;
|
use roc_types::subs::FlatType::*;
|
||||||
|
|
||||||
match subs.get_without_compacting(ext_var).content {
|
match subs.get_without_compacting(ext_var).content {
|
||||||
Structure(EmptyTagUnion) => (),
|
Structure(EmptyTagUnion) => (),
|
||||||
@ -308,8 +308,8 @@ fn flatten_union(
|
|||||||
/// Recursively inline the contents ext_var into this record until we have
|
/// Recursively inline the contents ext_var into this record until we have
|
||||||
/// a flat record containing all the fields.
|
/// a flat record containing all the fields.
|
||||||
fn flatten_record(fields: &mut MutMap<Lowercase, Variable>, ext_var: Variable, subs: &Subs) {
|
fn flatten_record(fields: &mut MutMap<Lowercase, Variable>, ext_var: Variable, subs: &Subs) {
|
||||||
use crate::subs::Content::*;
|
use roc_types::subs::Content::*;
|
||||||
use crate::subs::FlatType::*;
|
use roc_types::subs::FlatType::*;
|
||||||
|
|
||||||
match subs.get_without_compacting(ext_var).content {
|
match subs.get_without_compacting(ext_var).content {
|
||||||
Structure(EmptyRecord) => (),
|
Structure(EmptyRecord) => (),
|
||||||
|
@ -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_collections::all::{ImSet, MutMap, MutSet};
|
||||||
use roc_module::ident::{Lowercase, TagName};
|
use roc_module::ident::{Lowercase, TagName};
|
||||||
use roc_module::symbol::{Interns, ModuleId, Symbol};
|
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 WILDCARD: &str = "*";
|
||||||
static EMPTY_RECORD: &str = "{}";
|
static EMPTY_RECORD: &str = "{}";
|
||||||
@ -74,8 +74,8 @@ fn find_names_needed(
|
|||||||
root_appearances: &mut MutMap<Variable, Appearances>,
|
root_appearances: &mut MutMap<Variable, Appearances>,
|
||||||
names_taken: &mut MutSet<Lowercase>,
|
names_taken: &mut MutSet<Lowercase>,
|
||||||
) {
|
) {
|
||||||
use crate::subs::Content::*;
|
use roc_types::subs::Content::*;
|
||||||
use crate::subs::FlatType::*;
|
use roc_types::subs::FlatType::*;
|
||||||
|
|
||||||
while let Some((recursive, _)) = subs.occurs(variable) {
|
while let Some((recursive, _)) = subs.occurs(variable) {
|
||||||
if let Content::Structure(FlatType::TagUnion(tags, ext_var)) = subs.get(recursive).content {
|
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) {
|
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);
|
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) {
|
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 {
|
match content {
|
||||||
FlexVar(Some(name)) => buf.push_str(name.as_str()),
|
FlexVar(Some(name)) => buf.push_str(name.as_str()),
|
||||||
@ -337,7 +337,7 @@ fn write_flat_type(
|
|||||||
buf: &mut String,
|
buf: &mut String,
|
||||||
parens: Parens,
|
parens: Parens,
|
||||||
) {
|
) {
|
||||||
use crate::subs::FlatType::*;
|
use roc_types::subs::FlatType::*;
|
||||||
|
|
||||||
match flat_type {
|
match flat_type {
|
||||||
Apply(symbol, args) => write_apply(env, symbol, args, subs, buf, parens),
|
Apply(symbol, args) => write_apply(env, symbol, args, subs, buf, parens),
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use crate::can::problem::Problem;
|
|
||||||
use crate::pretty_print_types::content_to_string;
|
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_module::symbol::{Interns, ModuleId, Symbol};
|
||||||
use roc_region::all::Region;
|
use roc_region::all::Region;
|
||||||
|
use roc_types::subs::{Content, Subs};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
/// A textual report.
|
/// A textual report.
|
||||||
|
@ -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::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_collections::all::{ImMap, MutMap, SendMap};
|
||||||
use roc_module::ident::{Lowercase, TagName};
|
use roc_module::ident::{Lowercase, TagName};
|
||||||
use roc_module::symbol::{ModuleId, Symbol};
|
use roc_module::symbol::{ModuleId, Symbol};
|
||||||
use roc_region::all::{Located, Region};
|
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
|
// Type checking system adapted from Elm by Evan Czaplicki, BSD-3-Clause Licensed
|
||||||
// https://github.com/elm/compiler
|
// https://github.com/elm/compiler
|
||||||
@ -83,7 +85,7 @@ impl SolvedType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_type(solved_subs: &Solved<Subs>, typ: Type) -> Self {
|
pub fn from_type(solved_subs: &Solved<Subs>, typ: Type) -> Self {
|
||||||
use crate::types::Type::*;
|
use roc_types::types::Type::*;
|
||||||
|
|
||||||
match typ {
|
match typ {
|
||||||
EmptyRec => SolvedType::EmptyRecord,
|
EmptyRec => SolvedType::EmptyRecord,
|
||||||
@ -207,7 +209,7 @@ impl SolvedType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn from_flat_type(subs: &Subs, flat_type: FlatType) -> Self {
|
fn from_flat_type(subs: &Subs, flat_type: FlatType) -> Self {
|
||||||
use crate::subs::FlatType::*;
|
use roc_types::subs::FlatType::*;
|
||||||
|
|
||||||
match flat_type {
|
match flat_type {
|
||||||
Apply(symbol, args) => {
|
Apply(symbol, args) => {
|
||||||
@ -653,12 +655,14 @@ fn solve(
|
|||||||
.get(next_rank)
|
.get(next_rank)
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|var| {
|
.filter(|var| {
|
||||||
subs.get_without_compacting(crate::subs::Variable::clone(var))
|
subs.get_without_compacting(roc_types::subs::Variable::clone(
|
||||||
.rank
|
var,
|
||||||
.into_usize()
|
))
|
||||||
|
.rank
|
||||||
|
.into_usize()
|
||||||
> next_rank.into_usize()
|
> next_rank.into_usize()
|
||||||
})
|
})
|
||||||
.collect::<Vec<&crate::subs::Variable>>();
|
.collect::<Vec<&roc_types::subs::Variable>>();
|
||||||
|
|
||||||
offenders.is_empty()
|
offenders.is_empty()
|
||||||
});
|
});
|
||||||
@ -1191,8 +1195,8 @@ fn adjust_rank_content(
|
|||||||
group_rank: Rank,
|
group_rank: Rank,
|
||||||
content: Content,
|
content: Content,
|
||||||
) -> Rank {
|
) -> Rank {
|
||||||
use crate::subs::Content::*;
|
use roc_types::subs::Content::*;
|
||||||
use crate::subs::FlatType::*;
|
use roc_types::subs::FlatType::*;
|
||||||
|
|
||||||
match content {
|
match content {
|
||||||
FlexVar(_) | RigidVar(_) | Error => group_rank,
|
FlexVar(_) | RigidVar(_) | Error => group_rank,
|
||||||
@ -1313,8 +1317,8 @@ fn deep_copy_var_help(
|
|||||||
pools: &mut Pools,
|
pools: &mut Pools,
|
||||||
var: Variable,
|
var: Variable,
|
||||||
) -> Variable {
|
) -> Variable {
|
||||||
use crate::subs::Content::*;
|
use roc_types::subs::Content::*;
|
||||||
use crate::subs::FlatType::*;
|
use roc_types::subs::FlatType::*;
|
||||||
|
|
||||||
let desc = subs.get_without_compacting(var);
|
let desc = subs.get_without_compacting(var);
|
||||||
|
|
||||||
|
@ -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_collections::all::{relative_complement, union, MutMap, SendSet};
|
||||||
use roc_module::ident::{Lowercase, TagName};
|
use roc_module::ident::{Lowercase, TagName};
|
||||||
use roc_module::symbol::Symbol;
|
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;
|
use std::hash::Hash;
|
||||||
|
|
||||||
macro_rules! mismatch {
|
macro_rules! mismatch {
|
||||||
@ -446,7 +446,7 @@ fn unify_flat_type(
|
|||||||
left: &FlatType,
|
left: &FlatType,
|
||||||
right: &FlatType,
|
right: &FlatType,
|
||||||
) -> Outcome {
|
) -> Outcome {
|
||||||
use crate::subs::FlatType::*;
|
use roc_types::subs::FlatType::*;
|
||||||
|
|
||||||
match (left, right) {
|
match (left, right) {
|
||||||
(EmptyRecord, EmptyRecord) => merge(subs, ctx, Structure(left.clone())),
|
(EmptyRecord, EmptyRecord) => merge(subs, ctx, Structure(left.clone())),
|
||||||
@ -668,7 +668,7 @@ pub fn gather_fields(
|
|||||||
fields: MutMap<Lowercase, Variable>,
|
fields: MutMap<Lowercase, Variable>,
|
||||||
var: Variable,
|
var: Variable,
|
||||||
) -> RecordStructure {
|
) -> RecordStructure {
|
||||||
use crate::subs::FlatType::*;
|
use roc_types::subs::FlatType::*;
|
||||||
|
|
||||||
match subs.get(var).content {
|
match subs.get(var).content {
|
||||||
Structure(Record(sub_fields, sub_ext)) => {
|
Structure(Record(sub_fields, sub_ext)) => {
|
||||||
@ -689,7 +689,7 @@ fn gather_tags(
|
|||||||
tags: MutMap<TagName, Vec<Variable>>,
|
tags: MutMap<TagName, Vec<Variable>>,
|
||||||
var: Variable,
|
var: Variable,
|
||||||
) -> TagUnionStructure {
|
) -> TagUnionStructure {
|
||||||
use crate::subs::FlatType::*;
|
use roc_types::subs::FlatType::*;
|
||||||
|
|
||||||
match subs.get(var).content {
|
match subs.get(var).content {
|
||||||
Structure(TagUnion(sub_tags, sub_ext)) => {
|
Structure(TagUnion(sub_tags, sub_ext)) => {
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
use crate::builtins;
|
use crate::builtins;
|
||||||
use crate::builtins::StdLib;
|
use crate::builtins::StdLib;
|
||||||
use crate::solve::{BuiltinAlias, SolvedAtom, SolvedType};
|
use crate::solve::{BuiltinAlias, SolvedAtom, SolvedType};
|
||||||
use crate::subs::VarId;
|
|
||||||
use roc_collections::all::{default_hasher, MutMap};
|
use roc_collections::all::{default_hasher, MutMap};
|
||||||
use roc_module::ident::TagName;
|
use roc_module::ident::TagName;
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
use roc_region::all::{Located, Region};
|
use roc_region::all::{Located, Region};
|
||||||
|
use roc_types::subs::VarId;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
/// Keep this up to date by hand!
|
/// Keep this up to date by hand!
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
use crate::subs::Variable;
|
use roc_can::constraint::Constraint::{self, *};
|
||||||
use crate::types::Constraint::{self, *};
|
use roc_can::constraint::LetConstraint;
|
||||||
use crate::types::Expected::{self, *};
|
use roc_can::expected::Expected::{self, *};
|
||||||
use crate::types::Type::{self, *};
|
|
||||||
use crate::types::{LetConstraint, Reason};
|
|
||||||
use crate::uniqueness::boolean_algebra::Bool;
|
|
||||||
use roc_collections::all::SendMap;
|
use roc_collections::all::SendMap;
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
use roc_region::all::Region;
|
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)]
|
#[inline(always)]
|
||||||
pub fn int_literal(num_var: Variable, expected: Expected<Type>, region: Region) -> Constraint {
|
pub fn int_literal(num_var: Variable, expected: Expected<Type>, region: Region) -> Constraint {
|
||||||
|
@ -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::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::builtins::{attr_type, list_type, str_type};
|
||||||
use crate::uniqueness::sharing::{Container, FieldAccess, Mark, Usage, VarUsage};
|
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_collections::all::{ImMap, ImSet, SendMap};
|
||||||
use roc_module::ident::{Ident, Lowercase, TagName};
|
use roc_module::ident::{Ident, Lowercase, TagName};
|
||||||
use roc_module::symbol::{ModuleId, Symbol};
|
use roc_module::symbol::{ModuleId, Symbol};
|
||||||
use roc_region::all::{Located, Region};
|
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 builtins;
|
||||||
pub mod sharing;
|
pub mod sharing;
|
||||||
|
|
||||||
@ -147,8 +142,8 @@ fn constrain_pattern(
|
|||||||
pattern: &Located<Pattern>,
|
pattern: &Located<Pattern>,
|
||||||
expected: PExpected<Type>,
|
expected: PExpected<Type>,
|
||||||
) {
|
) {
|
||||||
use crate::can::pattern::Pattern::*;
|
use roc_can::pattern::Pattern::*;
|
||||||
use crate::types::PatternCategory;
|
use roc_types::types::PatternCategory;
|
||||||
|
|
||||||
match &pattern.value {
|
match &pattern.value {
|
||||||
Identifier(symbol) => {
|
Identifier(symbol) => {
|
||||||
@ -343,7 +338,7 @@ pub fn constrain_expr(
|
|||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
expected: Expected<Type>,
|
expected: Expected<Type>,
|
||||||
) -> Constraint {
|
) -> Constraint {
|
||||||
pub use crate::can::expr::Expr::*;
|
pub use roc_can::expr::Expr::*;
|
||||||
|
|
||||||
match expr {
|
match expr {
|
||||||
Int(var, _) => {
|
Int(var, _) => {
|
||||||
@ -540,7 +535,7 @@ pub fn constrain_expr(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
Closure(fn_var, _symbol, recursion, args, boxed) => {
|
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 (loc_body_expr, ret_var) = &**boxed;
|
||||||
let mut state = PatternState {
|
let mut state = PatternState {
|
||||||
@ -1402,7 +1397,7 @@ fn annotation_to_attr_type(
|
|||||||
rigids: &mut ImMap<Variable, Variable>,
|
rigids: &mut ImMap<Variable, Variable>,
|
||||||
change_var_kind: bool,
|
change_var_kind: bool,
|
||||||
) -> (Vec<Variable>, Type) {
|
) -> (Vec<Variable>, Type) {
|
||||||
use crate::types::Type::*;
|
use roc_types::types::Type::*;
|
||||||
|
|
||||||
match ann {
|
match ann {
|
||||||
Variable(var) => {
|
Variable(var) => {
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
use crate::can::expr::Expr;
|
use roc_can::expr::Expr;
|
||||||
use crate::subs::Variable;
|
|
||||||
use roc_collections::all::{ImMap, ImSet};
|
use roc_collections::all::{ImMap, ImSet};
|
||||||
use roc_module::ident::Lowercase;
|
use roc_module::ident::Lowercase;
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
use roc_region::all::Located;
|
use roc_region::all::Located;
|
||||||
|
use roc_types::subs::Variable;
|
||||||
|
|
||||||
// fake field names for container elements
|
// fake field names for container elements
|
||||||
// e.g. for lists, internally it's a record with a `list_elem` field
|
// e.g. for lists, internally it's a record with a `list_elem` field
|
||||||
|
@ -1,25 +1,27 @@
|
|||||||
extern crate bumpalo;
|
extern crate bumpalo;
|
||||||
|
|
||||||
use self::bumpalo::Bump;
|
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::expr::constrain_expr;
|
||||||
use roc::constrain::module::Import;
|
use roc::constrain::module::Import;
|
||||||
use roc::subs::{Subs, VarStore, Variable};
|
|
||||||
use roc::types::{Constraint, Expected, Type};
|
|
||||||
use roc::unique_builtins;
|
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::ident::Ident;
|
||||||
use roc_module::symbol::{IdentIds, Interns, ModuleId, ModuleIds, Symbol};
|
use roc_module::symbol::{IdentIds, Interns, ModuleId, ModuleIds, Symbol};
|
||||||
use roc_parse::ast::{self, Attempting};
|
use roc_parse::ast::{self, Attempting};
|
||||||
use roc_parse::blankspace::space0_before;
|
use roc_parse::blankspace::space0_before;
|
||||||
use roc_parse::parser::{loc, Fail, Parser, State};
|
use roc_parse::parser::{loc, Fail, Parser, State};
|
||||||
use roc_region::all::{Located, Region};
|
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::hash::Hash;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
@ -27,6 +29,24 @@ pub fn test_home() -> ModuleId {
|
|||||||
ModuleIds::default().get_or_insert(&"Test".into())
|
ModuleIds::default().get_or_insert(&"Test".into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn infer_expr(
|
||||||
|
subs: Subs,
|
||||||
|
problems: &mut Vec<roc_types::types::Problem>,
|
||||||
|
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.
|
/// 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
|
/// This way, we find out if any of our tests are blowing the stack even after
|
||||||
/// optimizations in release builds.
|
/// optimizations in release builds.
|
||||||
|
@ -11,7 +11,7 @@ mod helpers;
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test_gen {
|
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 bumpalo::Bump;
|
||||||
use cranelift::prelude::{AbiParam, ExternalName, FunctionBuilder, FunctionBuilderContext};
|
use cranelift::prelude::{AbiParam, ExternalName, FunctionBuilder, FunctionBuilderContext};
|
||||||
use cranelift_codegen::ir::InstBuilder;
|
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::build::{declare_proc, define_proc_body, ScopeEntry};
|
||||||
use roc::crane::convert::type_from_layout;
|
use roc::crane::convert::type_from_layout;
|
||||||
use roc::crane::imports::define_malloc;
|
use roc::crane::imports::define_malloc;
|
||||||
use roc::infer::infer_expr;
|
|
||||||
use roc::llvm::build::{build_proc, build_proc_header};
|
use roc::llvm::build::{build_proc, build_proc_header};
|
||||||
use roc::llvm::convert::basic_type_from_layout;
|
use roc::llvm::convert::basic_type_from_layout;
|
||||||
use roc::mono::expr::Expr;
|
use roc::mono::expr::Expr;
|
||||||
use roc::mono::layout::Layout;
|
use roc::mono::layout::Layout;
|
||||||
use roc::subs::Subs;
|
|
||||||
use roc_collections::all::{ImMap, MutMap};
|
use roc_collections::all::{ImMap, MutMap};
|
||||||
|
use roc_types::subs::Subs;
|
||||||
use std::ffi::{CStr, CString};
|
use std::ffi::{CStr, CString};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::os::raw::c_char;
|
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 CanExprOut { loc_expr, var_store, var, constraint, home, interns, .. } = can_expr($src);
|
||||||
let subs = Subs::new(var_store.into());
|
let subs = Subs::new(var_store.into());
|
||||||
let mut unify_problems = Vec::new();
|
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_builder = settings::builder();
|
||||||
let shared_flags = settings::Flags::new(shared_builder);
|
let shared_flags = settings::Flags::new(shared_builder);
|
||||||
let mut module: Module<SimpleJITBackend> =
|
let mut module: Module<SimpleJITBackend> =
|
||||||
@ -58,7 +57,6 @@ mod test_gen {
|
|||||||
let main_fn_name = "$Test.main";
|
let main_fn_name = "$Test.main";
|
||||||
|
|
||||||
// Compute main_fn_ret_type before moving subs to Env
|
// Compute main_fn_ret_type before moving subs to Env
|
||||||
let subs = solved.into_inner();
|
|
||||||
let layout = Layout::from_content(&arena, content, &subs)
|
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));
|
.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);
|
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 CanExprOut { loc_expr, var_store, var, constraint, home, interns, .. } = can_expr($src);
|
||||||
let subs = Subs::new(var_store.into());
|
let subs = Subs::new(var_store.into());
|
||||||
let mut unify_problems = Vec::new();
|
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 context = Context::create();
|
||||||
let module = context.create_module("app");
|
let module = context.create_module("app");
|
||||||
@ -198,7 +196,6 @@ mod test_gen {
|
|||||||
fpm.initialize();
|
fpm.initialize();
|
||||||
|
|
||||||
// Compute main_fn_type before moving subs to Env
|
// Compute main_fn_type before moving subs to Env
|
||||||
let subs = solved.into_inner();
|
|
||||||
let layout = Layout::from_content(&arena, content, &subs)
|
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));
|
.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)
|
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 (loc_expr, _output, _problems, subs, var, constraint, home, interns) = uniq_expr($src);
|
||||||
|
|
||||||
let mut unify_problems = Vec::new();
|
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 context = Context::create();
|
||||||
let module = context.create_module("app");
|
let module = context.create_module("app");
|
||||||
@ -335,7 +332,6 @@ mod test_gen {
|
|||||||
fpm.initialize();
|
fpm.initialize();
|
||||||
|
|
||||||
// Compute main_fn_type before moving subs to Env
|
// Compute main_fn_type before moving subs to Env
|
||||||
let subs = solved.into_inner();
|
|
||||||
let layout = Layout::from_content(&arena, content, &subs)
|
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));
|
.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)
|
let main_fn_type = basic_type_from_layout(&context, &layout)
|
||||||
|
@ -10,18 +10,17 @@ mod helpers;
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test_infer {
|
mod test_infer {
|
||||||
use crate::helpers::{assert_correct_variable_usage, can_expr, CanExprOut};
|
use crate::helpers::{assert_correct_variable_usage, can_expr, infer_expr, CanExprOut};
|
||||||
use roc::infer::infer_expr;
|
|
||||||
use roc::pretty_print_types::{content_to_string, name_all_type_vars};
|
use roc::pretty_print_types::{content_to_string, name_all_type_vars};
|
||||||
use roc::subs::Subs;
|
use roc_types::subs::Subs;
|
||||||
|
|
||||||
// HELPERS
|
// HELPERS
|
||||||
|
|
||||||
fn infer_eq_help(
|
fn infer_eq_help(
|
||||||
src: &str,
|
src: &str,
|
||||||
) -> (
|
) -> (
|
||||||
Vec<roc::types::Problem>,
|
Vec<roc_types::types::Problem>,
|
||||||
Vec<roc::can::problem::Problem>,
|
Vec<roc_can::problem::Problem>,
|
||||||
String,
|
String,
|
||||||
) {
|
) {
|
||||||
let CanExprOut {
|
let CanExprOut {
|
||||||
@ -43,8 +42,7 @@ mod test_infer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut unify_problems = Vec::new();
|
let mut unify_problems = Vec::new();
|
||||||
let (content, solved) = infer_expr(subs, &mut unify_problems, &constraint, var);
|
let (content, mut subs) = infer_expr(subs, &mut unify_problems, &constraint, var);
|
||||||
let mut subs = solved.into_inner();
|
|
||||||
|
|
||||||
name_all_type_vars(var, &mut subs);
|
name_all_type_vars(var, &mut subs);
|
||||||
|
|
||||||
|
@ -17,14 +17,14 @@ mod test_load {
|
|||||||
use crate::helpers::fixtures_dir;
|
use crate::helpers::fixtures_dir;
|
||||||
use inlinable_string::InlinableString;
|
use inlinable_string::InlinableString;
|
||||||
use roc::builtins;
|
use roc::builtins;
|
||||||
use roc::can::def::Declaration::*;
|
|
||||||
use roc::can::def::Def;
|
|
||||||
use roc::load::{load, LoadedModule};
|
use roc::load::{load, LoadedModule};
|
||||||
use roc::pretty_print_types::{content_to_string, name_all_type_vars};
|
use roc::pretty_print_types::{content_to_string, name_all_type_vars};
|
||||||
use roc::solve::SubsByModule;
|
use roc::solve::SubsByModule;
|
||||||
use roc::subs::Subs;
|
use roc_can::def::Declaration::*;
|
||||||
|
use roc_can::def::Def;
|
||||||
use roc_collections::all::MutMap;
|
use roc_collections::all::MutMap;
|
||||||
use roc_module::symbol::{Interns, ModuleId};
|
use roc_module::symbol::{Interns, ModuleId};
|
||||||
|
use roc_types::subs::Subs;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
// HELPERS
|
// HELPERS
|
||||||
|
@ -10,13 +10,12 @@ mod helpers;
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test_infer_uniq {
|
mod test_infer_uniq {
|
||||||
use crate::helpers::{assert_correct_variable_usage, uniq_expr};
|
use crate::helpers::{assert_correct_variable_usage, infer_expr, uniq_expr};
|
||||||
use roc::infer::infer_expr;
|
|
||||||
use roc::pretty_print_types::{content_to_string, name_all_type_vars};
|
use roc::pretty_print_types::{content_to_string, name_all_type_vars};
|
||||||
|
|
||||||
// HELPERS
|
// HELPERS
|
||||||
|
|
||||||
fn infer_eq_help(src: &str) -> (Vec<roc::types::Problem>, String) {
|
fn infer_eq_help(src: &str) -> (Vec<roc_types::types::Problem>, String) {
|
||||||
let (_loc_expr, output, _problems, mut subs, variable, constraint, home, interns) =
|
let (_loc_expr, output, _problems, mut subs, variable, constraint, home, interns) =
|
||||||
uniq_expr(src);
|
uniq_expr(src);
|
||||||
|
|
||||||
@ -27,8 +26,7 @@ mod test_infer_uniq {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut unify_problems = Vec::new();
|
let mut unify_problems = Vec::new();
|
||||||
let (content, solved) = infer_expr(subs, &mut unify_problems, &constraint, variable);
|
let (content, mut subs) = infer_expr(subs, &mut unify_problems, &constraint, variable);
|
||||||
let mut subs = solved.into_inner();
|
|
||||||
|
|
||||||
name_all_type_vars(variable, &mut subs);
|
name_all_type_vars(variable, &mut subs);
|
||||||
|
|
||||||
|
@ -16,15 +16,15 @@ mod test_uniqueness_load {
|
|||||||
use crate::helpers::fixtures_dir;
|
use crate::helpers::fixtures_dir;
|
||||||
use inlinable_string::InlinableString;
|
use inlinable_string::InlinableString;
|
||||||
use roc::builtins;
|
use roc::builtins;
|
||||||
use roc::can::def::Declaration::*;
|
|
||||||
use roc::can::def::Def;
|
|
||||||
use roc::load::{load, LoadedModule};
|
use roc::load::{load, LoadedModule};
|
||||||
use roc::pretty_print_types::{content_to_string, name_all_type_vars};
|
use roc::pretty_print_types::{content_to_string, name_all_type_vars};
|
||||||
use roc::solve::SubsByModule;
|
use roc::solve::SubsByModule;
|
||||||
use roc::subs::Subs;
|
|
||||||
use roc::unique_builtins;
|
use roc::unique_builtins;
|
||||||
|
use roc_can::def::Declaration::*;
|
||||||
|
use roc_can::def::Def;
|
||||||
use roc_collections::all::MutMap;
|
use roc_collections::all::MutMap;
|
||||||
use roc_module::symbol::{Interns, ModuleId};
|
use roc_module::symbol::{Interns, ModuleId};
|
||||||
|
use roc_types::subs::Subs;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
// HELPERS
|
// HELPERS
|
||||||
|
20
compiler/types/Cargo.toml
Normal file
20
compiler/types/Cargo.toml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
[package]
|
||||||
|
name = "roc_types"
|
||||||
|
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_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"
|
15
compiler/types/src/lib.rs
Normal file
15
compiler/types/src/lib.rs
Normal file
@ -0,0 +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;
|
@ -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::types::{name_type_var, ErrorType, Problem, TypeExt};
|
||||||
use crate::uniqueness::boolean_algebra;
|
|
||||||
use roc_collections::all::{ImMap, ImSet, MutMap, MutSet, SendMap};
|
use roc_collections::all::{ImMap, ImSet, MutMap, MutSet, SendMap};
|
||||||
use roc_module::ident::{Lowercase, TagName};
|
use roc_module::ident::{Lowercase, TagName};
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::iter::{once, Iterator};
|
use std::iter::{once, Iterator};
|
||||||
use std::sync::atomic::{AtomicU32, Ordering};
|
use std::sync::atomic::{AtomicU32, Ordering};
|
||||||
|
use ven_ena::unify::{InPlace, UnificationTable, UnifyKey};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Hash, PartialEq, Eq)]
|
#[derive(Clone, Copy, Hash, PartialEq, Eq)]
|
||||||
pub struct Mark(i32);
|
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) {
|
fn restore_content(subs: &mut Subs, content: &Content) {
|
||||||
use crate::subs::Content::*;
|
use Content::*;
|
||||||
use crate::subs::FlatType::*;
|
use FlatType::*;
|
||||||
|
|
||||||
match content {
|
match content {
|
||||||
FlexVar(_) | RigidVar(_) | Error => (),
|
FlexVar(_) | RigidVar(_) | Error => (),
|
@ -1,6 +1,5 @@
|
|||||||
use crate::can::pattern::Pattern;
|
use crate::boolean_algebra;
|
||||||
use crate::subs::{VarStore, Variable};
|
use crate::subs::{VarStore, Variable};
|
||||||
use crate::uniqueness::boolean_algebra;
|
|
||||||
use inlinable_string::InlinableString;
|
use inlinable_string::InlinableString;
|
||||||
use roc_collections::all::{ImMap, ImSet, MutSet, SendMap};
|
use roc_collections::all::{ImMap, ImSet, MutSet, SendMap};
|
||||||
use roc_module::ident::{Ident, Lowercase, TagName};
|
use roc_module::ident::{Ident, Lowercase, TagName};
|
||||||
@ -589,43 +588,6 @@ fn variables_help(tipe: &Type, accum: &mut ImSet<Variable>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
|
||||||
pub enum Expected<T> {
|
|
||||||
NoExpectation(T),
|
|
||||||
FromAnnotation(Located<Pattern>, usize, AnnotationSource, T),
|
|
||||||
ForReason(Reason, T, Region),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Like Expected, but for Patterns.
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
||||||
pub enum PExpected<T> {
|
|
||||||
NoExpectation(T),
|
|
||||||
ForReason(PReason, T, Region),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> PExpected<T> {
|
|
||||||
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)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum PReason {
|
pub enum PReason {
|
||||||
TypedArg { name: Box<str>, index: usize },
|
TypedArg { name: Box<str>, index: usize },
|
||||||
@ -635,32 +597,6 @@ pub enum PReason {
|
|||||||
Tail,
|
Tail,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Expected<T> {
|
|
||||||
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)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum AnnotationSource {
|
pub enum AnnotationSource {
|
||||||
TypedIfBranch(usize /* index */),
|
TypedIfBranch(usize /* index */),
|
||||||
@ -687,87 +623,6 @@ pub enum Reason {
|
|||||||
RecordUpdateKeys(Symbol, SendMap<Lowercase, Type>),
|
RecordUpdateKeys(Symbol, SendMap<Lowercase, Type>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
|
||||||
pub enum Constraint {
|
|
||||||
Eq(Type, Expected<Type>, Region),
|
|
||||||
Lookup(Symbol, Expected<Type>, Region),
|
|
||||||
Pattern(Region, PatternCategory, Type, PExpected<Type>),
|
|
||||||
True, // Used for things that always unify, e.g. blanks and runtime errors
|
|
||||||
SaveTheEnvironment,
|
|
||||||
Let(Box<LetConstraint>),
|
|
||||||
And(Vec<Constraint>),
|
|
||||||
}
|
|
||||||
|
|
||||||
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<Symbol, Alias>,
|
|
||||||
var_store: &VarStore,
|
|
||||||
introduced: &mut ImSet<Variable>,
|
|
||||||
) {
|
|
||||||
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)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum PatternCategory {
|
pub enum PatternCategory {
|
||||||
Record,
|
Record,
|
||||||
@ -781,16 +636,6 @@ pub enum PatternCategory {
|
|||||||
Float,
|
Float,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
|
||||||
pub struct LetConstraint {
|
|
||||||
pub rigid_vars: Vec<Variable>,
|
|
||||||
pub flex_vars: Vec<Variable>,
|
|
||||||
pub def_types: SendMap<Symbol, Located<Type>>,
|
|
||||||
pub def_aliases: SendMap<Symbol, Alias>,
|
|
||||||
pub defs_constraint: Constraint,
|
|
||||||
pub ret_constraint: Constraint,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct Alias {
|
pub struct Alias {
|
||||||
pub region: Region,
|
pub region: Region,
|
13
vendor/ena/Cargo.toml
vendored
Normal file
13
vendor/ena/Cargo.toml
vendored
Normal file
@ -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 <niko@alum.mit.edu>"]
|
||||||
|
readme = "README.md"
|
||||||
|
keywords = ["unification", "union-find"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
log = "0.4"
|
201
vendor/ena/LICENSE-APACHE
vendored
Normal file
201
vendor/ena/LICENSE-APACHE
vendored
Normal file
@ -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.
|
25
vendor/ena/LICENSE-MIT
vendored
Normal file
25
vendor/ena/LICENSE-MIT
vendored
Normal file
@ -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.
|
@ -13,3 +13,6 @@
|
|||||||
|
|
||||||
pub mod snapshot_vec;
|
pub mod snapshot_vec;
|
||||||
pub mod unify;
|
pub mod unify;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate log;
|
@ -1,4 +1,4 @@
|
|||||||
use crate::ena::snapshot_vec as sv;
|
use crate::snapshot_vec as sv;
|
||||||
#[cfg(feature = "persistent")]
|
#[cfg(feature = "persistent")]
|
||||||
use im_rc::Vector;
|
use im_rc::Vector;
|
||||||
use std::fmt::{self, Debug};
|
use std::fmt::{self, Debug};
|
16
vendor/pathfinding/Cargo.toml
vendored
Normal file
16
vendor/pathfinding/Cargo.toml
vendored
Normal file
@ -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 <sam@rfc1149.net>"]
|
||||||
|
categories = ["algorithms"]
|
||||||
|
readme = "README.md"
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
roc_collections = { path = "../../compiler/collections" }
|
Loading…
Reference in New Issue
Block a user