Constrain and solve import params

No reporting yet
This commit is contained in:
Agus Zubiaga 2024-06-27 18:27:33 -03:00
parent c541dd5747
commit 5ec4b042bb
No known key found for this signature in database
18 changed files with 238 additions and 26 deletions

View file

@ -602,7 +602,8 @@ impl Constraints {
| Constraint::Exhaustive { .. }
| Constraint::Resolve(..)
| Constraint::IngestedFile(..)
| Constraint::CheckCycle(..) => false,
| Constraint::CheckCycle(..)
| Constraint::ImportParams(..) => false,
}
}
@ -685,6 +686,15 @@ impl Constraints {
) -> Constraint {
Constraint::IngestedFile(type_index, file_path, bytes)
}
pub fn import_params(
&mut self,
type_index: TypeOrVar,
module_id: ModuleId,
region: Region,
) -> Constraint {
Constraint::ImportParams(type_index, module_id, region)
}
}
roc_error_macros::assert_sizeof_default!(Constraint, 3 * 8);
@ -787,6 +797,7 @@ pub enum Constraint {
CheckCycle(Index<Cycle>, IllegalCycleMark),
IngestedFile(TypeOrVar, Box<PathBuf>, Arc<Vec<u8>>),
ImportParams(TypeOrVar, ModuleId, Region),
}
#[derive(Debug, Clone, Copy, Default)]
@ -865,6 +876,9 @@ impl std::fmt::Debug for Constraint {
Self::IngestedFile(arg0, arg1, arg2) => {
write!(f, "IngestedFile({arg0:?}, {arg1:?}, {arg2:?})")
}
Self::ImportParams(arg0, arg1, arg2) => {
write!(f, "ImportParams({arg0:?}, {arg1:?}, {arg2:?})")
}
}
}
}

View file

@ -297,9 +297,11 @@ fn deep_copy_expr_help<C: CopyEnv>(env: &mut C, copied: &mut Vec<Variable>, expr
params: *params,
var: sub!(*var),
},
ImportParams(loc_expr, module_id) => {
ImportParams(Box::new(loc_expr.map(|e| go_help!(e))), *module_id)
}
ImportParams(loc_expr, var, module_id) => ImportParams(
Box::new(loc_expr.map(|e| go_help!(e))),
sub!(*var),
*module_id,
),
&AbilityMember(sym, specialization, specialization_var) => {
AbilityMember(sym, specialization, sub!(specialization_var))
}

View file

@ -209,7 +209,7 @@ fn expr<'a>(c: &Ctx, p: EPrec, f: &'a Arena<'a>, e: &'a Expr) -> DocBuilder<'a,
Var(sym, _) | ParamsVar { symbol: sym, .. } | AbilityMember(sym, _, _) => {
pp_sym(c, f, *sym)
}
ImportParams(loc_expr, _) => expr(c, p, f, &loc_expr.value),
ImportParams(loc_expr, _, _) => expr(c, p, f, &loc_expr.value),
When {
loc_cond, branches, ..
} => maybe_paren!(

View file

@ -2422,7 +2422,7 @@ fn canonicalize_pending_value_def<'a>(
let loc_expr = Loc::at(
loc_pattern.region,
Expr::ImportParams(Box::new(loc_record), module_id),
Expr::ImportParams(Box::new(loc_record), var_store.fresh(), module_id),
);
let def = single_can_def(

View file

@ -184,7 +184,7 @@ pub enum Expr {
},
/// Module params expression in import
ImportParams(Box<Loc<Expr>>, ModuleId),
ImportParams(Box<Loc<Expr>>, Variable, ModuleId),
/// The "crash" keyword
Crash {
@ -338,7 +338,7 @@ impl Expr {
Self::RecordAccessor(data) => Category::Accessor(data.field.clone()),
Self::TupleAccess { index, .. } => Category::TupleAccess(*index),
Self::RecordUpdate { .. } => Category::Record,
Self::ImportParams(loc_expr, _) => loc_expr.value.category(),
Self::ImportParams(loc_expr, _, _) => loc_expr.value.category(),
Self::Tag {
name, arguments, ..
} => Category::TagApply {
@ -2225,9 +2225,9 @@ pub fn inline_calls(var_store: &mut VarStore, expr: Expr) -> Expr {
);
}
ImportParams(loc_expr, module_id) => {
ImportParams(loc_expr, var, module_id) => {
let loc_expr = Loc::at(loc_expr.region, inline_calls(var_store, loc_expr.value));
ImportParams(Box::new(loc_expr), module_id)
ImportParams(Box::new(loc_expr), var, module_id)
}
RecordAccess {
@ -3242,7 +3242,7 @@ pub(crate) fn get_lookup_symbols(expr: &Expr) -> Vec<ExpectLookup> {
Expr::Tuple { elems, .. } => {
stack.extend(elems.iter().map(|(_, elem)| &elem.value));
}
Expr::ImportParams(loc_expr, _) => {
Expr::ImportParams(loc_expr, _, _) => {
stack.push(&loc_expr.value);
}
Expr::Expect {

View file

@ -1254,7 +1254,7 @@ fn fix_values_captured_in_closure_expr(
}
}
ImportParams(loc_expr, _) => {
ImportParams(loc_expr, _, _) => {
fix_values_captured_in_closure_expr(
&mut loc_expr.value,
no_capture_symbols,

View file

@ -318,7 +318,7 @@ pub fn walk_expr<V: Visitor>(visitor: &mut V, expr: &Expr, var: Variable) {
.iter()
.for_each(|(var, elem)| visitor.visit_expr(&elem.value, elem.region, *var)),
Expr::EmptyRecord => { /* terminal */ }
Expr::ImportParams(expr, _) => visitor.visit_expr(&expr.value, expr.region, var),
Expr::ImportParams(expr, _, _) => visitor.visit_expr(&expr.value, expr.region, var),
Expr::RecordAccess {
field_var,
loc_expr,