mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 11:52:19 +00:00
make it work
This commit is contained in:
parent
43adf0635e
commit
557c3987e0
6 changed files with 126 additions and 128 deletions
|
@ -2472,6 +2472,32 @@ fn constrain_empty_record(
|
|||
constraints.equal_types(record_type_index, expected, Category::Record, region)
|
||||
}
|
||||
|
||||
fn add_host_annotation(
|
||||
types: &mut Types,
|
||||
constraints: &mut Constraints,
|
||||
host_exposed_annotation: Option<&(Variable, roc_can::def::Annotation)>,
|
||||
constraint: Constraint,
|
||||
) -> Constraint {
|
||||
if let Some((var, ann)) = host_exposed_annotation {
|
||||
let expected_bool = {
|
||||
let type_index = types.from_old_type(&ann.signature);
|
||||
let ann_type = constraints.push_type(types, type_index);
|
||||
constraints.push_expected_type(Expected::ForReason(
|
||||
Reason::ExpectCondition,
|
||||
ann_type,
|
||||
Region::zero(),
|
||||
))
|
||||
};
|
||||
|
||||
let new =
|
||||
constraints.equal_types_var(*var, expected_bool, Category::Unknown, Region::zero());
|
||||
|
||||
constraints.and_constraint([new, constraint])
|
||||
} else {
|
||||
constraint
|
||||
}
|
||||
}
|
||||
|
||||
/// Constrain top-level module declarations
|
||||
#[inline(always)]
|
||||
pub fn constrain_decls(
|
||||
|
@ -2498,8 +2524,16 @@ pub fn constrain_decls(
|
|||
|
||||
use roc_can::expr::DeclarationTag::*;
|
||||
let tag = declarations.declarations[index];
|
||||
|
||||
match tag {
|
||||
Value => {
|
||||
constraint = add_host_annotation(
|
||||
types,
|
||||
constraints,
|
||||
declarations.host_exposed_annotations.get(&index),
|
||||
constraint,
|
||||
);
|
||||
|
||||
constraint = constrain_value_def(
|
||||
types,
|
||||
constraints,
|
||||
|
@ -2509,6 +2543,70 @@ pub fn constrain_decls(
|
|||
constraint,
|
||||
);
|
||||
}
|
||||
Function(function_def_index) => {
|
||||
constraint = add_host_annotation(
|
||||
types,
|
||||
constraints,
|
||||
declarations.host_exposed_annotations.get(&index),
|
||||
constraint,
|
||||
);
|
||||
|
||||
constraint = constrain_function_def(
|
||||
types,
|
||||
constraints,
|
||||
&mut env,
|
||||
declarations,
|
||||
index,
|
||||
function_def_index,
|
||||
constraint,
|
||||
);
|
||||
}
|
||||
Recursive(_) | TailRecursive(_) => {
|
||||
constraint = add_host_annotation(
|
||||
types,
|
||||
constraints,
|
||||
declarations.host_exposed_annotations.get(&index),
|
||||
constraint,
|
||||
);
|
||||
|
||||
// for the type it does not matter that a recursive call is a tail call
|
||||
constraint = constrain_recursive_declarations(
|
||||
types,
|
||||
constraints,
|
||||
&mut env,
|
||||
declarations,
|
||||
index..index + 1,
|
||||
constraint,
|
||||
IllegalCycleMark::empty(),
|
||||
);
|
||||
}
|
||||
Destructure(destructure_def_index) => {
|
||||
constraint = constrain_destructure_def(
|
||||
types,
|
||||
constraints,
|
||||
&mut env,
|
||||
declarations,
|
||||
index,
|
||||
destructure_def_index,
|
||||
constraint,
|
||||
);
|
||||
}
|
||||
MutualRecursion { length, cycle_mark } => {
|
||||
// the next `length` defs belong to this group
|
||||
let length = length as usize;
|
||||
|
||||
constraint = constrain_recursive_declarations(
|
||||
types,
|
||||
constraints,
|
||||
&mut env,
|
||||
declarations,
|
||||
index + 1..index + 1 + length,
|
||||
constraint,
|
||||
cycle_mark,
|
||||
);
|
||||
|
||||
index += length;
|
||||
}
|
||||
Expectation => {
|
||||
let loc_expr = &declarations.expressions[index];
|
||||
|
||||
|
@ -2565,56 +2663,6 @@ pub fn constrain_decls(
|
|||
Generalizable(false),
|
||||
)
|
||||
}
|
||||
Function(function_def_index) => {
|
||||
constraint = constrain_function_def(
|
||||
types,
|
||||
constraints,
|
||||
&mut env,
|
||||
declarations,
|
||||
index,
|
||||
function_def_index,
|
||||
constraint,
|
||||
);
|
||||
}
|
||||
Recursive(_) | TailRecursive(_) => {
|
||||
// for the type it does not matter that a recursive call is a tail call
|
||||
constraint = constrain_recursive_declarations(
|
||||
types,
|
||||
constraints,
|
||||
&mut env,
|
||||
declarations,
|
||||
index..index + 1,
|
||||
constraint,
|
||||
IllegalCycleMark::empty(),
|
||||
);
|
||||
}
|
||||
Destructure(destructure_def_index) => {
|
||||
constraint = constrain_destructure_def(
|
||||
types,
|
||||
constraints,
|
||||
&mut env,
|
||||
declarations,
|
||||
index,
|
||||
destructure_def_index,
|
||||
constraint,
|
||||
);
|
||||
}
|
||||
MutualRecursion { length, cycle_mark } => {
|
||||
// the next `length` defs belong to this group
|
||||
let length = length as usize;
|
||||
|
||||
constraint = constrain_recursive_declarations(
|
||||
types,
|
||||
constraints,
|
||||
&mut env,
|
||||
declarations,
|
||||
index + 1..index + 1 + length,
|
||||
constraint,
|
||||
cycle_mark,
|
||||
);
|
||||
|
||||
index += length;
|
||||
}
|
||||
}
|
||||
|
||||
index += 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue