fix tests/more uniq removal

This commit is contained in:
Folkert 2021-02-07 22:50:33 +01:00
parent 309eff6edd
commit ca04411523
18 changed files with 332 additions and 3256 deletions

633
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -8,7 +8,6 @@ members = [
"compiler/can",
"compiler/problem",
"compiler/types",
"compiler/uniq",
"compiler/builtins",
"compiler/constrain",
"compiler/unify",

View file

@ -40,7 +40,6 @@ roc_problem = { path = "../compiler/problem" }
roc_types = { path = "../compiler/types" }
roc_builtins = { path = "../compiler/builtins" }
roc_constrain = { path = "../compiler/constrain" }
roc_uniq = { path = "../compiler/uniq" }
roc_unify = { path = "../compiler/unify" }
roc_solve = { path = "../compiler/solve" }
roc_mono = { path = "../compiler/mono" }

View file

@ -15,7 +15,6 @@ roc_problem = { path = "../problem" }
roc_types = { path = "../types" }
roc_builtins = { path = "../builtins" }
roc_constrain = { path = "../constrain" }
roc_uniq = { path = "../uniq" }
roc_unify = { path = "../unify" }
roc_solve = { path = "../solve" }
roc_mono = { path = "../mono" }

View file

@ -10,7 +10,7 @@ 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, Bag, Parser, State};
use roc_parse::parser::{loc, Bag, Parser, State, SyntaxError};
use roc_problem::can::Problem;
use roc_region::all::{Located, Region};
use roc_types::subs::{VarStore, Variable};
@ -21,7 +21,10 @@ pub fn test_home() -> ModuleId {
}
#[allow(dead_code)]
pub fn parse_with<'a>(arena: &'a Bump, input: &'a str) -> Result<ast::Expr<'a>, Bag<'a>> {
pub fn parse_with<'a>(
arena: &'a Bump,
input: &'a str,
) -> Result<ast::Expr<'a>, Bag<'a, SyntaxError<'a>>> {
parse_loc_with(arena, input).map(|loc_expr| loc_expr.value)
}
@ -29,7 +32,7 @@ pub fn parse_with<'a>(arena: &'a Bump, input: &'a str) -> Result<ast::Expr<'a>,
pub fn parse_loc_with<'a>(
arena: &'a Bump,
input: &'a str,
) -> Result<Located<ast::Expr<'a>>, Bag<'a>> {
) -> Result<Located<ast::Expr<'a>>, Bag<'a, SyntaxError<'a>>> {
let state = State::new_in(arena, input.trim().as_bytes(), Attempting::Module);
let parser = space0_before(loc(roc_parse::expr::expr(0)), 0);
let answer = parser.parse(&arena, state);

View file

@ -13,7 +13,6 @@ roc_parse = { path = "../parse" }
roc_types = { path = "../types" }
roc_can = { path = "../can" }
roc_builtins = { path = "../builtins" }
roc_uniq = { path = "../uniq" }
[dev-dependencies]
pretty_assertions = "0.5.1"

View file

@ -5,4 +5,3 @@ pub mod builtins;
pub mod expr;
pub mod module;
pub mod pattern;
pub mod uniq;

View file

@ -26,7 +26,8 @@ pub fn constrain_module(
module: &ModuleOutput,
home: ModuleId,
mode: Mode,
var_store: &mut VarStore,
// TODO remove parameter
_var_store: &mut VarStore,
) -> Constraint {
use Mode::*;
@ -40,7 +41,7 @@ pub fn constrain_module(
match mode {
Standard => constrain_decls(home, decls),
Uniqueness => crate::uniq::constrain_decls(home, decls, var_store),
Uniqueness => constrain_decls(home, decls),
}
}

File diff suppressed because it is too large Load diff

View file

@ -17,9 +17,12 @@ mod test_fmt {
use roc_parse::ast::{Attempting, Expr};
use roc_parse::blankspace::space0_before;
use roc_parse::module::{self, module_defs};
use roc_parse::parser::{Bag, Parser, State};
use roc_parse::parser::{Bag, Parser, State, SyntaxError};
fn parse_with<'a>(arena: &'a Bump, input: &'a str) -> Result<Expr<'a>, Bag<'a>> {
fn parse_with<'a>(
arena: &'a Bump,
input: &'a str,
) -> Result<Expr<'a>, Bag<'a, SyntaxError<'a>>> {
let state = State::new_in(arena, input.trim().as_bytes(), Attempting::Module);
let parser = space0_before(loc!(roc_parse::expr::expr(0)), 0);
let answer = parser.parse(&arena, state);

View file

@ -13,7 +13,6 @@ roc_problem = { path = "../problem" }
roc_types = { path = "../types" }
roc_builtins = { path = "../builtins" }
roc_constrain = { path = "../constrain" }
roc_uniq = { path = "../uniq" }
roc_unify = { path = "../unify" }
roc_solve = { path = "../solve" }
roc_mono = { path = "../mono" }

View file

@ -14,7 +14,6 @@ roc_problem = { path = "../problem" }
roc_types = { path = "../types" }
roc_builtins = { path = "../builtins" }
roc_constrain = { path = "../constrain" }
roc_uniq = { path = "../uniq" }
roc_unify = { path = "../unify" }
roc_solve = { path = "../solve" }
roc_mono = { path = "../mono" }

View file

@ -15,7 +15,7 @@ use roc_module::ident::Ident;
use roc_module::symbol::{IdentIds, Interns, ModuleId, ModuleIds, Symbol};
use roc_parse::ast::{self, Attempting};
use roc_parse::blankspace::space0_before;
use roc_parse::parser::{loc, Bag, Parser, State};
use roc_parse::parser::{loc, Bag, Parser, State, SyntaxError};
use roc_problem::can::Problem;
use roc_region::all::{Located, Region};
use roc_solve::solve;
@ -62,7 +62,10 @@ where
}
#[allow(dead_code)]
pub fn parse_with<'a>(arena: &'a Bump, input: &'a str) -> Result<ast::Expr<'a>, Bag<'a>> {
pub fn parse_with<'a>(
arena: &'a Bump,
input: &'a str,
) -> Result<ast::Expr<'a>, Bag<'a, SyntaxError<'a>>> {
parse_loc_with(arena, input).map(|loc_expr| loc_expr.value)
}
@ -70,7 +73,7 @@ pub fn parse_with<'a>(arena: &'a Bump, input: &'a str) -> Result<ast::Expr<'a>,
pub fn parse_loc_with<'a>(
arena: &'a Bump,
input: &'a str,
) -> Result<Located<ast::Expr<'a>>, Bag<'a>> {
) -> Result<Located<ast::Expr<'a>>, Bag<'a, SyntaxError<'a>>> {
let state = State::new_in(arena, input.trim().as_bytes(), Attempting::Module);
let parser = space0_before(loc(roc_parse::expr::expr(0)), 0);
let answer = parser.parse(&arena, state);
@ -85,85 +88,6 @@ pub fn can_expr(expr_str: &str) -> CanExprOut {
can_expr_with(&Bump::new(), test_home(), expr_str)
}
#[allow(dead_code)]
pub fn uniq_expr(
expr_str: &str,
) -> (
Located<Expr>,
Output,
Vec<Problem>,
Subs,
Variable,
Constraint,
ModuleId,
Interns,
) {
let declared_idents: &ImMap<Ident, (Symbol, Region)> = &ImMap::default();
uniq_expr_with(&Bump::new(), expr_str, declared_idents)
}
#[allow(dead_code)]
pub fn uniq_expr_with(
arena: &Bump,
expr_str: &str,
declared_idents: &ImMap<Ident, (Symbol, Region)>,
) -> (
Located<Expr>,
Output,
Vec<Problem>,
Subs,
Variable,
Constraint,
ModuleId,
Interns,
) {
let home = test_home();
let CanExprOut {
loc_expr,
output,
problems,
var_store: mut old_var_store,
var,
interns,
..
} = can_expr_with(arena, home, expr_str);
// double check
let mut var_store = VarStore::new(old_var_store.fresh());
let expected2 = Expected::NoExpectation(Type::Variable(var));
let constraint = roc_constrain::uniq::constrain_declaration(
home,
&mut var_store,
Region::zero(),
&loc_expr,
declared_idents,
expected2,
);
let stdlib = uniq_stdlib();
let types = stdlib.types;
let imports: Vec<_> = types
.into_iter()
.map(|(symbol, (solved_type, region))| Import {
loc_symbol: Located::at(region, symbol),
solved_type,
})
.collect();
// load builtin values
let (_introduced_rigids, constraint) =
constrain_imported_values(imports, constraint, &mut var_store);
let subs2 = Subs::new(var_store.into());
(
loc_expr, output, problems, subs2, var, constraint, home, interns,
)
}
pub struct CanExprOut {
pub loc_expr: Located<Expr>,
pub output: Output,

View file

@ -15,7 +15,7 @@ use roc_module::ident::Ident;
use roc_module::symbol::{IdentIds, Interns, ModuleId, ModuleIds, Symbol};
use roc_parse::ast::{self, Attempting};
use roc_parse::blankspace::space0_before;
use roc_parse::parser::{loc, Bag, Parser, State};
use roc_parse::parser::{loc, Bag, Parser, State, SyntaxError};
use roc_problem::can::Problem;
use roc_region::all::{Located, Region};
use roc_solve::solve;
@ -47,7 +47,10 @@ pub fn infer_expr(
}
#[allow(dead_code)]
pub fn parse_with<'a>(arena: &'a Bump, input: &'a str) -> Result<ast::Expr<'a>, Bag<'a>> {
pub fn parse_with<'a>(
arena: &'a Bump,
input: &'a str,
) -> Result<ast::Expr<'a>, Bag<'a, SyntaxError<'a>>> {
parse_loc_with(arena, input).map(|loc_expr| loc_expr.value)
}
@ -55,7 +58,7 @@ pub fn parse_with<'a>(arena: &'a Bump, input: &'a str) -> Result<ast::Expr<'a>,
pub fn parse_loc_with<'a>(
arena: &'a Bump,
input: &'a str,
) -> Result<Located<ast::Expr<'a>>, Bag<'a>> {
) -> Result<Located<ast::Expr<'a>>, Bag<'a, SyntaxError<'a>>> {
let state = State::new_in(arena, input.as_bytes(), Attempting::Module);
let parser = space0_before(loc(roc_parse::expr::expr(0)), 0);
let answer = parser.parse(&arena, state);
@ -70,87 +73,6 @@ pub fn can_expr(expr_str: &str) -> CanExprOut {
can_expr_with(&Bump::new(), test_home(), expr_str)
}
#[allow(dead_code)]
pub fn uniq_expr(
expr_str: &str,
) -> (
Located<Expr>,
Output,
Vec<Problem>,
Subs,
Variable,
Constraint,
ModuleId,
Interns,
) {
let declared_idents: &ImMap<Ident, (Symbol, Region)> = &ImMap::default();
uniq_expr_with(&Bump::new(), expr_str, declared_idents)
}
#[allow(dead_code)]
pub fn uniq_expr_with(
arena: &Bump,
expr_str: &str,
declared_idents: &ImMap<Ident, (Symbol, Region)>,
) -> (
Located<Expr>,
Output,
Vec<Problem>,
Subs,
Variable,
Constraint,
ModuleId,
Interns,
) {
let home = test_home();
let CanExprOut {
loc_expr,
output,
problems,
var_store: mut old_var_store,
var,
interns,
..
} = can_expr_with(arena, home, expr_str);
// double check
let mut var_store = VarStore::new(old_var_store.fresh());
let expected2 = Expected::NoExpectation(Type::Variable(var));
let constraint = roc_constrain::uniq::constrain_declaration(
home,
&mut var_store,
Region::zero(),
&loc_expr,
declared_idents,
expected2,
);
let stdlib = uniq_stdlib();
let types = stdlib.types;
let imports: Vec<_> = types
.into_iter()
.map(|(symbol, (solved_type, region))| Import {
loc_symbol: Located::at(region, symbol),
solved_type,
})
.collect();
// load builtin values
// TODO what to do with those rigids?
let (_introduced_rigids, constraint) =
constrain_imported_values(imports, constraint, &mut var_store);
let subs2 = Subs::new(var_store.into());
(
loc_expr, output, problems, subs2, var, constraint, home, interns,
)
}
pub struct CanExprOut {
pub loc_expr: Located<Expr>,
pub output: Output,

View file

@ -258,7 +258,7 @@ impl Progress {
}
}
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SyntaxError<'a> {
Unexpected(Region),
OutdentedTooFar,
@ -278,7 +278,7 @@ pub enum SyntaxError<'a> {
type Row = u32;
type Col = u16;
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Type<'a> {
TRecord(TRecord<'a>, Row, Col),
///
@ -288,7 +288,7 @@ pub enum Type<'a> {
TIndentStart(Row, Col),
}
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum TRecord<'a> {
Open(Row, Col),
End(Row, Col),

View file

@ -13,7 +13,7 @@ use roc_constrain::module::{constrain_imported_values, Import};
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, Bag, Parser, State};
use roc_parse::parser::{loc, Bag, Parser, State, SyntaxError};
use roc_problem::can::Problem;
use roc_region::all::Located;
use roc_solve::solve;
@ -101,7 +101,10 @@ pub struct CanExprOut {
}
#[allow(dead_code)]
pub fn parse_with<'a>(arena: &'a Bump, input: &'a str) -> Result<ast::Expr<'a>, Bag<'a>> {
pub fn parse_with<'a>(
arena: &'a Bump,
input: &'a str,
) -> Result<ast::Expr<'a>, Bag<'a, SyntaxError<'a>>> {
parse_loc_with(arena, input).map(|loc_expr| loc_expr.value)
}
@ -109,7 +112,7 @@ pub fn parse_with<'a>(arena: &'a Bump, input: &'a str) -> Result<ast::Expr<'a>,
pub fn parse_loc_with<'a>(
arena: &'a Bump,
input: &'a str,
) -> Result<Located<ast::Expr<'a>>, Bag<'a>> {
) -> Result<Located<ast::Expr<'a>>, Bag<'a, SyntaxError<'a>>> {
let state = State::new_in(arena, input.trim().as_bytes(), Attempting::Module);
let parser = space0_before(loc(roc_parse::expr::expr(0)), 0);
let answer = parser.parse(&arena, state);
@ -121,7 +124,7 @@ pub fn parse_loc_with<'a>(
#[derive(Debug)]
pub struct ParseErrOut<'a> {
pub fail: Bag<'a>,
pub fail: Bag<'a, SyntaxError<'a>>,
pub home: ModuleId,
pub interns: Interns,
}

View file

@ -15,7 +15,7 @@ use roc_module::ident::Ident;
use roc_module::symbol::{IdentIds, Interns, ModuleId, ModuleIds, Symbol};
use roc_parse::ast::{self, Attempting};
use roc_parse::blankspace::space0_before;
use roc_parse::parser::{loc, Bag, Parser, State};
use roc_parse::parser::{loc, Bag, Parser, State, SyntaxError};
use roc_problem::can::Problem;
use roc_region::all::{Located, Region};
use roc_solve::solve;
@ -87,7 +87,10 @@ where
}
#[allow(dead_code)]
pub fn parse_with<'a>(arena: &'a Bump, input: &'a str) -> Result<ast::Expr<'a>, Bag<'a>> {
pub fn parse_with<'a>(
arena: &'a Bump,
input: &'a str,
) -> Result<ast::Expr<'a>, Bag<'a, SyntaxError<'a>>> {
parse_loc_with(arena, input).map(|loc_expr| loc_expr.value)
}
@ -95,7 +98,7 @@ pub fn parse_with<'a>(arena: &'a Bump, input: &'a str) -> Result<ast::Expr<'a>,
pub fn parse_loc_with<'a>(
arena: &'a Bump,
input: &'a str,
) -> Result<Located<ast::Expr<'a>>, Bag<'a>> {
) -> Result<Located<ast::Expr<'a>>, Bag<'a, SyntaxError<'a>>> {
let state = State::new_in(arena, input.trim().as_bytes(), Attempting::Module);
let parser = space0_before(loc(roc_parse::expr::expr(0)), 0);
let answer = parser.parse(&arena, state);
@ -110,87 +113,6 @@ pub fn can_expr(expr_str: &str) -> CanExprOut {
can_expr_with(&Bump::new(), test_home(), expr_str)
}
#[allow(dead_code)]
pub fn uniq_expr(
expr_str: &str,
) -> (
Located<Expr>,
Output,
Vec<Problem>,
Subs,
Variable,
Constraint,
ModuleId,
Interns,
) {
let declared_idents: &ImMap<Ident, (Symbol, Region)> = &ImMap::default();
uniq_expr_with(&Bump::new(), expr_str, declared_idents)
}
#[allow(dead_code)]
pub fn uniq_expr_with(
arena: &Bump,
expr_str: &str,
declared_idents: &ImMap<Ident, (Symbol, Region)>,
) -> (
Located<Expr>,
Output,
Vec<Problem>,
Subs,
Variable,
Constraint,
ModuleId,
Interns,
) {
let home = test_home();
let CanExprOut {
loc_expr,
output,
problems,
var_store: mut old_var_store,
var,
interns,
..
} = can_expr_with(arena, home, expr_str);
// double check
let mut var_store = VarStore::new(old_var_store.fresh());
let expected2 = Expected::NoExpectation(Type::Variable(var));
let constraint = roc_constrain::uniq::constrain_declaration(
home,
&mut var_store,
Region::zero(),
&loc_expr,
declared_idents,
expected2,
);
let stdlib = uniq_stdlib();
let types = stdlib.types;
let imports: Vec<_> = types
.into_iter()
.map(|(symbol, (solved_type, region))| Import {
loc_symbol: Located::at(region, symbol),
solved_type,
})
.collect();
// load builtin values
// TODO what to do with those rigids?
let (_introduced_rigids, constraint) =
constrain_imported_values(imports, constraint, &mut var_store);
let subs2 = Subs::new(var_store.into());
(
loc_expr, output, problems, subs2, var, constraint, home, interns,
)
}
pub struct CanExprOut {
pub loc_expr: Located<Expr>,
pub output: Output,

View file

@ -17,7 +17,6 @@ roc_problem = { path = "../compiler/problem" }
roc_types = { path = "../compiler/types" }
roc_builtins = { path = "../compiler/builtins" }
roc_constrain = { path = "../compiler/constrain" }
roc_uniq = { path = "../compiler/uniq" }
roc_unify = { path = "../compiler/unify" }
roc_solve = { path = "../compiler/solve" }
roc_mono = { path = "../compiler/mono" }