mirror of
https://github.com/roc-lang/roc.git
synced 2025-07-24 06:55:15 +00:00
Fix types SoA usage in solve
This commit is contained in:
parent
6b5f632364
commit
a2e90c3709
6 changed files with 30 additions and 16 deletions
|
@ -4713,7 +4713,7 @@ fn canonicalize_and_constrain<'a>(
|
||||||
&symbols_from_requires,
|
&symbols_from_requires,
|
||||||
&mut var_store,
|
&mut var_store,
|
||||||
);
|
);
|
||||||
let types = Types::new();
|
let mut types = Types::new();
|
||||||
|
|
||||||
// _after has an underscore because it's unused in --release builds
|
// _after has an underscore because it's unused in --release builds
|
||||||
let _after = roc_types::types::get_type_clone_count();
|
let _after = roc_types::types::get_type_clone_count();
|
||||||
|
|
|
@ -75,6 +75,7 @@ impl PendingDerivesTable {
|
||||||
let derive_key = RequestedDeriveKey { opaque, ability };
|
let derive_key = RequestedDeriveKey { opaque, ability };
|
||||||
|
|
||||||
// Neither rank nor pools should matter here.
|
// Neither rank nor pools should matter here.
|
||||||
|
let typ = types.from_old_type(&typ);
|
||||||
let opaque_var = type_to_var(
|
let opaque_var = type_to_var(
|
||||||
subs,
|
subs,
|
||||||
Rank::toplevel(),
|
Rank::toplevel(),
|
||||||
|
@ -84,7 +85,7 @@ impl PendingDerivesTable {
|
||||||
&mut Pools::default(),
|
&mut Pools::default(),
|
||||||
types,
|
types,
|
||||||
aliases,
|
aliases,
|
||||||
&typ,
|
typ,
|
||||||
);
|
);
|
||||||
let real_var = match subs.get_content_without_compacting(opaque_var) {
|
let real_var = match subs.get_content_without_compacting(opaque_var) {
|
||||||
Content::Alias(_, _, real_var, AliasKind::Opaque) => real_var,
|
Content::Alias(_, _, real_var, AliasKind::Opaque) => real_var,
|
||||||
|
|
|
@ -1347,10 +1347,10 @@ fn solve(
|
||||||
.map(|v| Type::Variable(*v))
|
.map(|v| Type::Variable(*v))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let tag_ty = Type::TagUnion(
|
let tag_ty = can_types.from_old_type(&Type::TagUnion(
|
||||||
vec![(tag_name.clone(), payload_types)],
|
vec![(tag_name.clone(), payload_types)],
|
||||||
TypeExtension::Closed,
|
TypeExtension::Closed,
|
||||||
);
|
));
|
||||||
let includes = type_to_var(
|
let includes = type_to_var(
|
||||||
subs,
|
subs,
|
||||||
rank,
|
rank,
|
||||||
|
@ -1360,7 +1360,7 @@ fn solve(
|
||||||
pools,
|
pools,
|
||||||
&mut can_types,
|
&mut can_types,
|
||||||
aliases,
|
aliases,
|
||||||
&tag_ty,
|
tag_ty,
|
||||||
);
|
);
|
||||||
|
|
||||||
match unify(
|
match unify(
|
||||||
|
@ -2265,7 +2265,7 @@ fn type_cell_to_var(
|
||||||
aliases: &mut Aliases,
|
aliases: &mut Aliases,
|
||||||
typ_cell: &Cell<Index<TypeTag>>,
|
typ_cell: &Cell<Index<TypeTag>>,
|
||||||
) -> Variable {
|
) -> Variable {
|
||||||
let typ = typ_cell.replace(Type::EmptyTagUnion);
|
let typ = typ_cell.get();
|
||||||
let var = type_to_var(
|
let var = type_to_var(
|
||||||
subs,
|
subs,
|
||||||
rank,
|
rank,
|
||||||
|
@ -2275,9 +2275,12 @@ fn type_cell_to_var(
|
||||||
pools,
|
pools,
|
||||||
types,
|
types,
|
||||||
aliases,
|
aliases,
|
||||||
&typ,
|
typ,
|
||||||
);
|
);
|
||||||
typ_cell.replace(Type::Variable(var));
|
unsafe {
|
||||||
|
types.set_variable(typ, var);
|
||||||
|
}
|
||||||
|
|
||||||
var
|
var
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2290,13 +2293,12 @@ pub(crate) fn type_to_var(
|
||||||
pools: &mut Pools,
|
pools: &mut Pools,
|
||||||
types: &mut Types,
|
types: &mut Types,
|
||||||
aliases: &mut Aliases,
|
aliases: &mut Aliases,
|
||||||
typ: &Type,
|
typ: Index<TypeTag>,
|
||||||
) -> Variable {
|
) -> Variable {
|
||||||
if let Type::Variable(var) = typ {
|
if let TypeTag::Variable(var) = types[typ] {
|
||||||
*var
|
var
|
||||||
} else {
|
} else {
|
||||||
let mut arena = take_scratchpad();
|
let mut arena = take_scratchpad();
|
||||||
let typ = types.from_old_type(typ);
|
|
||||||
|
|
||||||
let var = type_to_variable(
|
let var = type_to_variable(
|
||||||
subs,
|
subs,
|
||||||
|
|
|
@ -27,6 +27,7 @@ use roc_reporting::report::{type_problem, RocDocAllocator};
|
||||||
use roc_types::{
|
use roc_types::{
|
||||||
pretty_print::{name_and_print_var, DebugPrint},
|
pretty_print::{name_and_print_var, DebugPrint},
|
||||||
subs::{ExposedTypesStorageSubs, Subs, Variable},
|
subs::{ExposedTypesStorageSubs, Subs, Variable},
|
||||||
|
types::Types,
|
||||||
};
|
};
|
||||||
|
|
||||||
const DERIVED_MODULE: ModuleId = ModuleId::DERIVED_SYNTH;
|
const DERIVED_MODULE: ModuleId = ModuleId::DERIVED_SYNTH;
|
||||||
|
@ -343,11 +344,12 @@ fn check_derived_typechecks_and_golden(
|
||||||
check_golden: impl Fn(&str),
|
check_golden: impl Fn(&str),
|
||||||
) {
|
) {
|
||||||
// constrain the derived
|
// constrain the derived
|
||||||
|
let mut types = Types::new();
|
||||||
let mut constraints = Constraints::new();
|
let mut constraints = Constraints::new();
|
||||||
let def_var = derived_def.expr_var;
|
let def_var = derived_def.expr_var;
|
||||||
let mut decls = Declarations::new();
|
let mut decls = Declarations::new();
|
||||||
decls.push_def(derived_def);
|
decls.push_def(derived_def);
|
||||||
let constr = constrain_decls(&mut constraints, test_module, &decls);
|
let constr = constrain_decls(&mut types, &mut constraints, test_module, &decls);
|
||||||
|
|
||||||
// the derived implementation on stuff from the builtin module, so
|
// the derived implementation on stuff from the builtin module, so
|
||||||
// - we need to add those dependencies as imported on the constraint
|
// - we need to add those dependencies as imported on the constraint
|
||||||
|
@ -394,7 +396,7 @@ fn check_derived_typechecks_and_golden(
|
||||||
);
|
);
|
||||||
let (mut solved_subs, _, problems, _) = roc_solve::module::run_solve(
|
let (mut solved_subs, _, problems, _) = roc_solve::module::run_solve(
|
||||||
test_module,
|
test_module,
|
||||||
Default::default(),
|
types,
|
||||||
&constraints,
|
&constraints,
|
||||||
constr,
|
constr,
|
||||||
RigidVariables::default(),
|
RigidVariables::default(),
|
||||||
|
|
|
@ -586,6 +586,13 @@ impl Types {
|
||||||
(tags, payload_slices)
|
(tags, payload_slices)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// May only be called if `var` is known to represent the type at `index`.
|
||||||
|
pub unsafe fn set_variable(&mut self, index: Index<TypeTag>, var: Variable) {
|
||||||
|
self.tags[index.index()] = TypeTag::Variable(var);
|
||||||
|
}
|
||||||
|
|
||||||
fn reserve_type_tags(&mut self, length: usize) -> Slice<TypeTag> {
|
fn reserve_type_tags(&mut self, length: usize) -> Slice<TypeTag> {
|
||||||
use std::iter::repeat;
|
use std::iter::repeat;
|
||||||
|
|
||||||
|
|
|
@ -143,11 +143,12 @@ pub fn can_expr_with<'a>(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut types = Types::new();
|
||||||
let mut constraints = Constraints::new();
|
let mut constraints = Constraints::new();
|
||||||
|
|
||||||
let mut var_store = VarStore::default();
|
let mut var_store = VarStore::default();
|
||||||
let var = var_store.fresh();
|
let var = var_store.fresh();
|
||||||
let var_index = constraints.push_type(Type::Variable(var));
|
let var_index = constraints.push_variable(var);
|
||||||
let expected = constraints.push_expected_type(Expected::NoExpectation(var_index));
|
let expected = constraints.push_expected_type(Expected::NoExpectation(var_index));
|
||||||
let mut module_ids = ModuleIds::default();
|
let mut module_ids = ModuleIds::default();
|
||||||
|
|
||||||
|
@ -176,6 +177,7 @@ pub fn can_expr_with<'a>(
|
||||||
);
|
);
|
||||||
|
|
||||||
let constraint = constrain_expr(
|
let constraint = constrain_expr(
|
||||||
|
&mut types,
|
||||||
&mut constraints,
|
&mut constraints,
|
||||||
&mut roc_constrain::expr::Env {
|
&mut roc_constrain::expr::Env {
|
||||||
rigids: MutMap::default(),
|
rigids: MutMap::default(),
|
||||||
|
@ -205,7 +207,7 @@ pub fn can_expr_with<'a>(
|
||||||
var,
|
var,
|
||||||
constraint,
|
constraint,
|
||||||
constraints,
|
constraints,
|
||||||
types: Default::default(),
|
types,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue