mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
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:
parent
b9b2f70673
commit
fefac9580e
5 changed files with 55 additions and 20 deletions
|
@ -199,7 +199,7 @@ pub fn canonicalize_defs<'a>(
|
|||
region: loc_lowercase.region,
|
||||
});
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ pub fn constrain_imported_values(
|
|||
imports: Vec<Import<'_>>,
|
||||
body_con: Constraint,
|
||||
var_store: &VarStore,
|
||||
) -> Constraint {
|
||||
) -> (Vec<Variable>, Constraint) {
|
||||
use Constraint::*;
|
||||
let mut def_types = SendMap::default();
|
||||
let mut rigid_vars = Vec::new();
|
||||
|
@ -81,14 +81,17 @@ pub fn constrain_imported_values(
|
|||
}
|
||||
}
|
||||
|
||||
Let(Box::new(LetConstraint {
|
||||
rigid_vars,
|
||||
flex_vars: Vec::new(),
|
||||
def_types,
|
||||
def_aliases: SendMap::default(),
|
||||
defs_constraint: True,
|
||||
ret_constraint: body_con,
|
||||
}))
|
||||
(
|
||||
rigid_vars.clone(),
|
||||
Let(Box::new(LetConstraint {
|
||||
rigid_vars,
|
||||
flex_vars: Vec::new(),
|
||||
def_types,
|
||||
def_aliases: SendMap::default(),
|
||||
defs_constraint: True,
|
||||
ret_constraint: body_con,
|
||||
})),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn load_builtin_aliases(
|
||||
|
@ -110,10 +113,14 @@ pub fn load_builtin_aliases(
|
|||
let mut vars = Vec::with_capacity(builtin_alias.vars.len());
|
||||
|
||||
for (loc_lowercase, index) in builtin_alias.vars.iter().zip(1..) {
|
||||
let var = free_vars
|
||||
.unnamed_vars
|
||||
.get(&VarId::from_u32(index))
|
||||
.expect("var_id was not instantiated (is it phantom?)");
|
||||
let var = if let Some(result) = free_vars.unnamed_vars.get(&VarId::from_u32(index)) {
|
||||
result
|
||||
} else {
|
||||
panic!(
|
||||
"var_id {:?} was not instantiated in the body of {:?} : {:?} (is it phantom?)",
|
||||
index, symbol, &builtin_alias
|
||||
)
|
||||
};
|
||||
|
||||
vars.push(Located::at(
|
||||
loc_lowercase.region,
|
||||
|
|
|
@ -844,7 +844,10 @@ fn solve_module(
|
|||
}
|
||||
|
||||
// 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 mut constraint = load_builtin_aliases(&stdlib.aliases, constraint, &var_store);
|
||||
|
||||
|
|
|
@ -152,8 +152,10 @@ pub fn uniq_expr_with(
|
|||
.collect();
|
||||
|
||||
// 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
|
||||
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 dep_idents = IdentIds::exposed_builtins(0);
|
||||
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,
|
||||
&var_store,
|
||||
&mut scope,
|
||||
|
@ -234,8 +236,13 @@ pub fn can_expr_with(arena: &Bump, home: ModuleId, expr_str: &str) -> CanExprOut
|
|||
.collect();
|
||||
|
||||
//load builtin values
|
||||
let constraint =
|
||||
roc_constrain::module::constrain_imported_values(imports, constraint, &var_store);
|
||||
let (_introduced_rigids, constraint) =
|
||||
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
|
||||
let mut constraint = roc_constrain::module::load_builtin_aliases(
|
||||
|
|
|
@ -2097,4 +2097,22 @@ mod test_infer_uniq {
|
|||
"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)",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue