From d90fd9e4658173c1cfcbb535b6f50c0306d190d9 Mon Sep 17 00:00:00 2001 From: rvcas Date: Thu, 29 Jul 2021 17:24:58 -0400 Subject: [PATCH 1/3] feat: add similar cases for U128 and I128 --- editor/src/lang/constrain.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/editor/src/lang/constrain.rs b/editor/src/lang/constrain.rs index cb1ed061bc..7a922a3c47 100644 --- a/editor/src/lang/constrain.rs +++ b/editor/src/lang/constrain.rs @@ -57,7 +57,7 @@ pub fn constrain_expr<'a>( Expr2::Blank => True, Expr2::EmptyRecord => constrain_empty_record(expected, region), Expr2::Var(symbol) => Lookup(*symbol, expected, region), - Expr2::SmallInt { var, .. } => { + Expr2::SmallInt { var, .. } | Expr2::I128 { var, .. } | Expr2::U128 { var, .. } => { let mut flex_vars = BumpVec::with_capacity_in(1, arena); flex_vars.push(*var); From fdfe727c5183c9c079e1de0e28f2e2243dc34d9b Mon Sep 17 00:00:00 2001 From: rvcas Date: Thu, 29 Jul 2021 17:29:35 -0400 Subject: [PATCH 2/3] feat: bring over the RunLowLevel implementation --- editor/src/lang/constrain.rs | 52 +++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/editor/src/lang/constrain.rs b/editor/src/lang/constrain.rs index 7a922a3c47..762367229d 100644 --- a/editor/src/lang/constrain.rs +++ b/editor/src/lang/constrain.rs @@ -910,7 +910,57 @@ pub fn constrain_expr<'a>( exists(arena, flex_vars, And(cons)) } - _ => todo!("implement constraints for {:?}", expr), + + Expr2::RunLowLevel { op, args, ret_var } => { + // This is a modified version of what we do for function calls. + + // The operation's return type + let ret_type = Type2::Variable(*ret_var); + + // This will be used in the occurs check + let mut vars = BumpVec::with_capacity_in(1 + args.len(), arena); + + vars.push(*ret_var); + + let mut arg_types = BumpVec::with_capacity_in(args.len(), arena); + let mut arg_cons = BumpVec::with_capacity_in(args.len(), arena); + + for (index, node_id) in args.iter_node_ids().enumerate() { + let (arg_var, arg_id) = env.pool.get(node_id); + + vars.push(*arg_var); + + let arg_type = Type2::Variable(*arg_var); + + let reason = Reason::LowLevelOpArg { + op: *op, + arg_index: Index::zero_based(index), + }; + let expected_arg = + Expected::ForReason(reason, arg_type.shallow_clone(), Region::zero()); + let arg = env.pool.get(*arg_id); + + let arg_con = constrain_expr(arena, env, arg, expected_arg, Region::zero()); + + arg_types.push(arg_type); + arg_cons.push(arg_con); + } + + let category = Category::LowLevelOpResult(*op); + + let mut and_constraints = BumpVec::with_capacity_in(2, arena); + + and_constraints.push(And(arg_cons)); + and_constraints.push(Eq(ret_type, expected, category, region)); + + exists(arena, vars, And(and_constraints)) + } + Expr2::Closure { .. } => todo!(), + Expr2::PrivateTag { .. } => todo!(), + Expr2::RuntimeError() => todo!(), + Expr2::InvalidLookup(_) => todo!(), + Expr2::LetRec { .. } => todo!(), + Expr2::LetFunction { .. } => todo!(), } } From d7c45950923c30a03e8fb68c1b715ae4e19545fe Mon Sep 17 00:00:00 2001 From: rvcas Date: Fri, 30 Jul 2021 14:21:01 -0400 Subject: [PATCH 3/3] test: add ignored test case for now --- editor/tests/solve_expr2.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/editor/tests/solve_expr2.rs b/editor/tests/solve_expr2.rs index a25c88b077..c5e8fb9512 100644 --- a/editor/tests/solve_expr2.rs +++ b/editor/tests/solve_expr2.rs @@ -328,3 +328,16 @@ fn constrain_update() { "{ name : Str }", ) } + +#[ignore = "TODO: implement builtins in the editor"] +#[test] +fn constrain_run_low_level() { + infer_eq( + indoc!( + r#" + List.map [ { name: "roc" }, { name: "bird" } ] .name + "# + ), + "List Str", + ) +}