mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 08:11:12 +00:00
includes_tag expects type index
This commit is contained in:
parent
556222caa1
commit
97d47cc05f
3 changed files with 25 additions and 40 deletions
|
@ -336,25 +336,20 @@ impl Constraints {
|
|||
Constraint::IsOpenType(type_index)
|
||||
}
|
||||
|
||||
pub fn includes_tag<I>(
|
||||
pub fn includes_tag(
|
||||
&mut self,
|
||||
typ: Type,
|
||||
type_index: TypeOrVar,
|
||||
tag_name: TagName,
|
||||
types: I,
|
||||
payloads: Slice<Variable>,
|
||||
category: PatternCategory,
|
||||
region: Region,
|
||||
) -> Constraint
|
||||
where
|
||||
I: IntoIterator<Item = Type>,
|
||||
{
|
||||
let type_index = Index::push_new(&mut self.types, Cell::new(typ));
|
||||
) -> Constraint {
|
||||
let category_index = Index::push_new(&mut self.pattern_categories, category);
|
||||
let types_slice = Slice::extend_new(&mut self.types, types.into_iter().map(Cell::new));
|
||||
|
||||
let includes_tag = IncludesTag {
|
||||
type_index,
|
||||
tag_name,
|
||||
types: types_slice,
|
||||
types: payloads,
|
||||
pattern_category: category_index,
|
||||
region,
|
||||
};
|
||||
|
@ -364,7 +359,7 @@ impl Constraints {
|
|||
Constraint::IncludesTag(includes_tag_index)
|
||||
}
|
||||
|
||||
fn variable_slice<I>(&mut self, it: I) -> Slice<Variable>
|
||||
pub fn variable_slice<I>(&mut self, it: I) -> Slice<Variable>
|
||||
where
|
||||
I: IntoIterator<Item = Variable>,
|
||||
{
|
||||
|
@ -795,9 +790,9 @@ pub struct LetConstraint {
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct IncludesTag {
|
||||
pub type_index: TypeIndex,
|
||||
pub type_index: TypeOrVar,
|
||||
pub tag_name: TagName,
|
||||
pub types: Slice<Cell<Type>>,
|
||||
pub types: Slice<Variable>,
|
||||
pub pattern_category: Index<PatternCategory>,
|
||||
pub region: Region,
|
||||
}
|
||||
|
|
|
@ -506,12 +506,12 @@ pub fn constrain_pattern(
|
|||
tag_name,
|
||||
arguments,
|
||||
} => {
|
||||
let mut argument_types = Vec::with_capacity(arguments.len());
|
||||
let argument_types = constraints.variable_slice(arguments.iter().map(|(var, _)| *var));
|
||||
|
||||
for (index, (pattern_var, loc_pattern)) in arguments.iter().enumerate() {
|
||||
state.vars.push(*pattern_var);
|
||||
|
||||
let pattern_type = Type::Variable(*pattern_var);
|
||||
argument_types.push(pattern_type.clone());
|
||||
|
||||
let expected = PExpected::ForReason(
|
||||
PReason::TagArg {
|
||||
|
@ -532,11 +532,12 @@ pub fn constrain_pattern(
|
|||
}
|
||||
|
||||
let pat_category = PatternCategory::Ctor(tag_name.clone());
|
||||
let expected_type = constraints.push_type(expected.get_type_ref().clone());
|
||||
|
||||
let whole_con = constraints.includes_tag(
|
||||
expected.clone().get_type(),
|
||||
expected_type,
|
||||
tag_name.clone(),
|
||||
argument_types.clone(),
|
||||
argument_types,
|
||||
pat_category.clone(),
|
||||
region,
|
||||
);
|
||||
|
|
|
@ -1323,40 +1323,29 @@ fn solve(
|
|||
region,
|
||||
} = includes_tag;
|
||||
|
||||
let typ_cell = &constraints.types[type_index.index()];
|
||||
let tys_cells = &constraints.types[types.indices()];
|
||||
let pattern_category = &constraints.pattern_categories[pattern_category.index()];
|
||||
|
||||
let actual = type_cell_to_var(
|
||||
let actual = either_type_index_to_var(
|
||||
constraints,
|
||||
subs,
|
||||
rank,
|
||||
pools,
|
||||
problems,
|
||||
abilities_store,
|
||||
obligation_cache,
|
||||
pools,
|
||||
aliases,
|
||||
typ_cell,
|
||||
*type_index,
|
||||
);
|
||||
|
||||
let tys = {
|
||||
let mut tys = Vec::with_capacity(tys_cells.len());
|
||||
for cell in tys_cells {
|
||||
let actual = type_cell_to_var(
|
||||
subs,
|
||||
rank,
|
||||
problems,
|
||||
abilities_store,
|
||||
obligation_cache,
|
||||
pools,
|
||||
aliases,
|
||||
cell,
|
||||
);
|
||||
tys.push(Type::Variable(actual));
|
||||
}
|
||||
tys
|
||||
};
|
||||
let payload_types = constraints.variables[types.indices()]
|
||||
.into_iter()
|
||||
.map(|v| Type::Variable(*v))
|
||||
.collect();
|
||||
|
||||
let tag_ty = Type::TagUnion(vec![(tag_name.clone(), tys)], TypeExtension::Closed);
|
||||
let tag_ty = Type::TagUnion(
|
||||
vec![(tag_name.clone(), payload_types)],
|
||||
TypeExtension::Closed,
|
||||
);
|
||||
let includes = type_to_var(
|
||||
subs,
|
||||
rank,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue