expose rigids introduced by builtins

they aren't used yet, because their names can 'leak'. Not sure what the best way forward is here
This commit is contained in:
Folkert 2020-03-06 13:41:20 +01:00
parent b9b2f70673
commit fefac9580e
5 changed files with 55 additions and 20 deletions

View file

@ -199,7 +199,7 @@ pub fn canonicalize_defs<'a>(
region: loc_lowercase.region, region: loc_lowercase.region,
}); });
} else { } else {
panic!("TODO handle phantom type variables, they are not allowed!"); panic!("TODO handle phantom type variables, they are not allowed!\nThe {:?} variable in the definition of {:?} gives trouble", loc_lowercase, symbol);
} }
} }

View file

@ -43,7 +43,7 @@ pub fn constrain_imported_values(
imports: Vec<Import<'_>>, imports: Vec<Import<'_>>,
body_con: Constraint, body_con: Constraint,
var_store: &VarStore, var_store: &VarStore,
) -> Constraint { ) -> (Vec<Variable>, Constraint) {
use Constraint::*; use Constraint::*;
let mut def_types = SendMap::default(); let mut def_types = SendMap::default();
let mut rigid_vars = Vec::new(); let mut rigid_vars = Vec::new();
@ -81,6 +81,8 @@ pub fn constrain_imported_values(
} }
} }
(
rigid_vars.clone(),
Let(Box::new(LetConstraint { Let(Box::new(LetConstraint {
rigid_vars, rigid_vars,
flex_vars: Vec::new(), flex_vars: Vec::new(),
@ -88,7 +90,8 @@ pub fn constrain_imported_values(
def_aliases: SendMap::default(), def_aliases: SendMap::default(),
defs_constraint: True, defs_constraint: True,
ret_constraint: body_con, ret_constraint: body_con,
})) })),
)
} }
pub fn load_builtin_aliases( pub fn load_builtin_aliases(
@ -110,10 +113,14 @@ pub fn load_builtin_aliases(
let mut vars = Vec::with_capacity(builtin_alias.vars.len()); let mut vars = Vec::with_capacity(builtin_alias.vars.len());
for (loc_lowercase, index) in builtin_alias.vars.iter().zip(1..) { for (loc_lowercase, index) in builtin_alias.vars.iter().zip(1..) {
let var = free_vars let var = if let Some(result) = free_vars.unnamed_vars.get(&VarId::from_u32(index)) {
.unnamed_vars result
.get(&VarId::from_u32(index)) } else {
.expect("var_id was not instantiated (is it phantom?)"); panic!(
"var_id {:?} was not instantiated in the body of {:?} : {:?} (is it phantom?)",
index, symbol, &builtin_alias
)
};
vars.push(Located::at( vars.push(Located::at(
loc_lowercase.region, loc_lowercase.region,

View file

@ -844,7 +844,10 @@ fn solve_module(
} }
// Wrap the existing module constraint in these imported constraints. // Wrap the existing module constraint in these imported constraints.
let constraint = constrain_imported_values(imported_symbols, constraint, &var_store);
// TODO what to do with the introduced rigids?
let (_introduced_rigids, constraint) =
constrain_imported_values(imported_symbols, constraint, &var_store);
let constraint = constrain_imported_aliases(imported_aliases, constraint, &var_store); let constraint = constrain_imported_aliases(imported_aliases, constraint, &var_store);
let mut constraint = load_builtin_aliases(&stdlib.aliases, constraint, &var_store); let mut constraint = load_builtin_aliases(&stdlib.aliases, constraint, &var_store);

View file

@ -152,8 +152,10 @@ pub fn uniq_expr_with(
.collect(); .collect();
// load builtin values // load builtin values
let constraint =
roc_constrain::module::constrain_imported_values(imports, constraint, &var_store); // TODO what to do with those rigids?
let (_introduced_rigids, constraint) =
roc::constrain::module::constrain_imported_values(imports, constraint, &var_store);
// load builtin types // load builtin types
let mut constraint = let mut constraint =
@ -205,7 +207,7 @@ pub fn can_expr_with(arena: &Bump, home: ModuleId, expr_str: &str) -> CanExprOut
let mut scope = Scope::new(home); let mut scope = Scope::new(home);
let dep_idents = IdentIds::exposed_builtins(0); let dep_idents = IdentIds::exposed_builtins(0);
let mut env = Env::new(home, dep_idents, &module_ids, IdentIds::default()); let mut env = Env::new(home, dep_idents, &module_ids, IdentIds::default());
let (loc_expr, output) = canonicalize_expr( let (loc_expr, mut output) = canonicalize_expr(
&mut env, &mut env,
&var_store, &var_store,
&mut scope, &mut scope,
@ -234,8 +236,13 @@ pub fn can_expr_with(arena: &Bump, home: ModuleId, expr_str: &str) -> CanExprOut
.collect(); .collect();
//load builtin values //load builtin values
let constraint = let (_introduced_rigids, constraint) =
roc_constrain::module::constrain_imported_values(imports, constraint, &var_store); roc::constrain::module::constrain_imported_values(imports, constraint, &var_store);
// TODO determine what to do with those rigids
// for var in introduced_rigids {
// output.ftv.insert(var, format!("internal_{:?}", var).into());
// }
//load builtin types //load builtin types
let mut constraint = roc_constrain::module::load_builtin_aliases( let mut constraint = roc_constrain::module::load_builtin_aliases(

View file

@ -2097,4 +2097,22 @@ mod test_infer_uniq {
"Attr * Int", "Attr * Int",
); );
} }
#[test]
fn update_cost() {
infer_eq(
indoc!(
r#"
f = \r ->
g = r.q
h = r.p
42
f
"#
),
"Attr * (Attr (* | a | b) { p : (Attr b *), q : (Attr a *) }* -> Attr * Int)",
);
}
} }