mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
Start saving ability signature on designated variable again
This commit is contained in:
parent
eb81c68bcb
commit
6b4294307f
4 changed files with 48 additions and 17 deletions
|
@ -2,12 +2,14 @@ use roc_builtins::std::StdLib;
|
|||
use roc_can::abilities::AbilitiesStore;
|
||||
use roc_can::constraint::{Constraint, Constraints};
|
||||
use roc_can::def::Declaration;
|
||||
use roc_can::expected::Expected;
|
||||
use roc_collections::all::MutMap;
|
||||
use roc_error_macros::internal_error;
|
||||
use roc_module::symbol::{ModuleId, Symbol};
|
||||
use roc_region::all::Loc;
|
||||
use roc_region::all::{Loc, Region};
|
||||
use roc_types::solved_types::{FreeVars, SolvedType};
|
||||
use roc_types::subs::{VarStore, Variable};
|
||||
use roc_types::types::{Category, Type};
|
||||
|
||||
/// The types of all exposed values/functions of a collection of modules
|
||||
#[derive(Clone, Debug, Default)]
|
||||
|
@ -105,27 +107,53 @@ pub fn constrain_module(
|
|||
declarations: &[Declaration],
|
||||
home: ModuleId,
|
||||
) -> Constraint {
|
||||
let mut constraint = crate::expr::constrain_decls(constraints, home, declarations);
|
||||
let constraint = crate::expr::constrain_decls(constraints, home, declarations);
|
||||
|
||||
let constraint = frontload_ability_constraints(constraints, abilities_store, constraint);
|
||||
|
||||
// The module constraint should always save the environment at the end.
|
||||
debug_assert!(constraints.contains_save_the_environment(&constraint));
|
||||
|
||||
constraint
|
||||
}
|
||||
|
||||
pub fn frontload_ability_constraints(
|
||||
constraints: &mut Constraints,
|
||||
abilities_store: &AbilitiesStore,
|
||||
mut constraint: Constraint,
|
||||
) -> Constraint {
|
||||
for (member_name, member_data) in abilities_store.root_ability_members().iter() {
|
||||
// 1. Attach the type of member signature to the reserved signature_var. This is
|
||||
// infallible.
|
||||
let unify_with_signature_var = constraints.equal_types_var(
|
||||
member_data.signature_var,
|
||||
Expected::NoExpectation(member_data.signature.clone()),
|
||||
Category::Storage(std::file!(), std::column!()),
|
||||
Region::zero(),
|
||||
);
|
||||
|
||||
// 2. Store the member signature on the member symbol. This makes sure we generalize it on
|
||||
// the toplevel, as appropriate.
|
||||
let vars = &member_data.variables;
|
||||
let rigids = (vars.rigid_vars.iter())
|
||||
// For our purposes, in the let constraint, able vars are treated like rigids.
|
||||
.chain(vars.able_vars.iter())
|
||||
.copied();
|
||||
let flex = vars.flex_vars.iter().copied();
|
||||
constraint = constraints.let_constraint(
|
||||
|
||||
let let_constr = constraints.let_constraint(
|
||||
rigids,
|
||||
flex,
|
||||
[(*member_name, Loc::at_zero(member_data.signature.clone()))],
|
||||
[(
|
||||
*member_name,
|
||||
Loc::at_zero(Type::Variable(member_data.signature_var)),
|
||||
)],
|
||||
Constraint::True,
|
||||
constraint,
|
||||
);
|
||||
|
||||
constraint = constraints.and_constraint([unify_with_signature_var, let_constr]);
|
||||
}
|
||||
|
||||
// The module constraint should always save the environment at the end.
|
||||
debug_assert!(constraints.contains_save_the_environment(&constraint));
|
||||
|
||||
constraint
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue