mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-11 05:34:11 +03:00
Store solve aliases as TypeTag
This commit is contained in:
parent
e3dbf5c09c
commit
e3ef9828c7
@ -4409,7 +4409,7 @@ pub fn add_imports(
|
||||
#[allow(clippy::complexity)]
|
||||
fn run_solve_solve(
|
||||
exposed_for_module: ExposedForModule,
|
||||
types: Types,
|
||||
mut types: Types,
|
||||
mut constraints: Constraints,
|
||||
constraint: ConstraintSoa,
|
||||
pending_derives: PendingDerives,
|
||||
@ -4451,7 +4451,7 @@ fn run_solve_solve(
|
||||
|
||||
let mut solve_aliases = roc_solve::solve::Aliases::with_capacity(aliases.len());
|
||||
for (name, (_, alias)) in aliases.iter() {
|
||||
solve_aliases.insert(*name, alias.clone());
|
||||
solve_aliases.insert(&mut types, *name, alias.clone());
|
||||
}
|
||||
|
||||
let (solved_subs, solved_implementations, exposed_vars_by_symbol, problems, abilities_store) = {
|
||||
|
@ -138,7 +138,7 @@ impl DelayedAliasVariables {
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Aliases {
|
||||
aliases: Vec<(Symbol, Type, DelayedAliasVariables, AliasKind)>,
|
||||
aliases: Vec<(Symbol, Index<TypeTag>, DelayedAliasVariables, AliasKind)>,
|
||||
variables: Vec<OptAbleVar>,
|
||||
}
|
||||
|
||||
@ -150,7 +150,7 @@ impl Aliases {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, symbol: Symbol, alias: Alias) {
|
||||
pub fn insert(&mut self, types: &mut Types, symbol: Symbol, alias: Alias) {
|
||||
let alias_variables =
|
||||
{
|
||||
let start = self.variables.len() as _;
|
||||
@ -195,8 +195,11 @@ impl Aliases {
|
||||
}
|
||||
};
|
||||
|
||||
// TODO: can we construct Aliases from TypeTag directly?
|
||||
let alias_typ = types.from_old_type(&alias.typ);
|
||||
|
||||
self.aliases
|
||||
.push((symbol, alias.typ, alias_variables, alias.kind));
|
||||
.push((symbol, alias_typ, alias_variables, alias.kind));
|
||||
}
|
||||
|
||||
fn instantiate_result_result(
|
||||
@ -335,19 +338,16 @@ impl Aliases {
|
||||
return (var, kind);
|
||||
}
|
||||
|
||||
let (typ, delayed_variables, &mut kind) =
|
||||
match self.aliases.iter_mut().find(|(s, _, _, _)| *s == symbol) {
|
||||
let (typ, delayed_variables, kind) =
|
||||
match self.aliases.iter().find(|(s, _, _, _)| *s == symbol) {
|
||||
None => internal_error!(
|
||||
"Alias {:?} not registered in delayed aliases! {:?}",
|
||||
symbol,
|
||||
&self.aliases
|
||||
),
|
||||
Some((_, typ, delayed_variables, kind)) => (typ, delayed_variables, kind),
|
||||
Some(&(_, typ, delayed_variables, kind)) => (typ, delayed_variables, kind),
|
||||
};
|
||||
|
||||
// TODO(types-soa) store SoA type in aliases directly
|
||||
let typ = types.from_old_type(typ);
|
||||
|
||||
let mut substitutions: MutMap<_, _> = Default::default();
|
||||
|
||||
let old_type_variables = delayed_variables.type_variables(&mut self.variables);
|
||||
|
@ -18,7 +18,7 @@ use roc_region::all::Loc;
|
||||
use roc_solve::solve::{self, Aliases};
|
||||
use roc_solve_problem::TypeError;
|
||||
use roc_types::subs::{Content, Subs, VarStore, Variable};
|
||||
use roc_types::types::Type;
|
||||
use roc_types::types::{Type, Types};
|
||||
use std::hash::Hash;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
@ -31,6 +31,7 @@ pub fn test_home() -> ModuleId {
|
||||
pub fn infer_expr(
|
||||
subs: Subs,
|
||||
problems: &mut Vec<TypeError>,
|
||||
types: Types,
|
||||
constraints: &Constraints,
|
||||
constraint: &Constraint,
|
||||
pending_derives: PendingDerives,
|
||||
@ -41,7 +42,7 @@ pub fn infer_expr(
|
||||
) -> (Content, Subs) {
|
||||
let (solved, _) = solve::run(
|
||||
ModuleId::ATTR,
|
||||
Default::default(),
|
||||
types,
|
||||
constraints,
|
||||
problems,
|
||||
subs,
|
||||
@ -113,6 +114,7 @@ pub struct CanExprOut {
|
||||
pub var: Variable,
|
||||
pub constraint: Constraint,
|
||||
pub constraints: Constraints,
|
||||
pub types: Types,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -203,6 +205,7 @@ pub fn can_expr_with<'a>(
|
||||
var,
|
||||
constraint,
|
||||
constraints,
|
||||
types: Default::default(),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -202,6 +202,7 @@ mod test_reporting {
|
||||
home,
|
||||
interns,
|
||||
problems: can_problems,
|
||||
mut types,
|
||||
..
|
||||
} = can_expr(arena, expr_src)?;
|
||||
let mut subs = Subs::new_from_varstore(var_store);
|
||||
@ -217,7 +218,7 @@ mod test_reporting {
|
||||
let mut solve_aliases = roc_solve::solve::Aliases::default();
|
||||
|
||||
for (name, alias) in output.aliases {
|
||||
solve_aliases.insert(name, alias);
|
||||
solve_aliases.insert(&mut types, name, alias);
|
||||
}
|
||||
|
||||
let mut unify_problems = Vec::new();
|
||||
@ -225,6 +226,7 @@ mod test_reporting {
|
||||
let (_content, _subs) = infer_expr(
|
||||
subs,
|
||||
&mut unify_problems,
|
||||
types,
|
||||
&constraints,
|
||||
&constraint,
|
||||
// Use `new_report_problem_as` in order to get proper derives.
|
||||
|
Loading…
Reference in New Issue
Block a user