diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index d4501a1dd3..1e89b1591f 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -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); } } diff --git a/compiler/constrain/src/module.rs b/compiler/constrain/src/module.rs index ce49f19d00..7456ac7fb9 100644 --- a/compiler/constrain/src/module.rs +++ b/compiler/constrain/src/module.rs @@ -43,7 +43,7 @@ pub fn constrain_imported_values( imports: Vec>, body_con: Constraint, var_store: &VarStore, -) -> Constraint { +) -> (Vec, 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, diff --git a/compiler/src/load/mod.rs b/compiler/src/load/mod.rs index 7a49a5ca76..07c3d794ff 100644 --- a/compiler/src/load/mod.rs +++ b/compiler/src/load/mod.rs @@ -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); diff --git a/compiler/tests/helpers/mod.rs b/compiler/tests/helpers/mod.rs index 632f44185f..45149ba0fd 100644 --- a/compiler/tests/helpers/mod.rs +++ b/compiler/tests/helpers/mod.rs @@ -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( diff --git a/compiler/tests/test_uniqueness_infer.rs b/compiler/tests/test_uniqueness_infer.rs index 8c83799f7e..f520676c6a 100644 --- a/compiler/tests/test_uniqueness_infer.rs +++ b/compiler/tests/test_uniqueness_infer.rs @@ -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)", + ); + } }