fix errors
This commit is contained in:
parent
5c59b816ea
commit
ebe415cfc9
|
@ -1119,6 +1119,9 @@ impl Annotation {
|
||||||
elems.iter().find_map(|arg| arg.find_node(byte_index))
|
elems.iter().find_map(|arg| arg.find_node(byte_index))
|
||||||
}
|
}
|
||||||
Annotation::Var { .. } | Annotation::Hole { .. } => None,
|
Annotation::Var { .. } | Annotation::Hole { .. } => None,
|
||||||
|
Annotation::Pair { fst, snd, .. } => fst
|
||||||
|
.find_node(byte_index)
|
||||||
|
.or_else(|| snd.find_node(byte_index)),
|
||||||
};
|
};
|
||||||
|
|
||||||
located.or(Some(Located::Annotation(self)))
|
located.or(Some(Located::Annotation(self)))
|
||||||
|
|
|
@ -372,42 +372,32 @@ impl<'a> CodeGenerator<'a> {
|
||||||
},
|
},
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
if tipo.is_pair() {
|
let data_type = lookup_data_type_by_tipo(&self.data_types, tipo)
|
||||||
assert!(args.len() == 2);
|
.expect("Creating a record with no record definition.");
|
||||||
|
|
||||||
let arg1 = self.build(&args[0].value, module_build_name, &[]);
|
let (constr_index, _) = data_type
|
||||||
|
.constructors
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.find(|(_, dt)| &dt.name == constr_name)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let arg2 = self.build(&args[1].value, module_build_name, &[]);
|
let constr_args = args
|
||||||
|
.iter()
|
||||||
|
.zip(constr_tipo.arg_types().unwrap())
|
||||||
|
.map(|(arg, tipo)| {
|
||||||
|
if tipo.is_data() {
|
||||||
|
AirTree::cast_to_data(
|
||||||
|
self.build(&arg.value, module_build_name, &[]),
|
||||||
|
arg.value.tipo(),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
self.build(&arg.value, module_build_name, &[])
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect_vec();
|
||||||
|
|
||||||
AirTree::pair(arg1, arg2, tipo.clone())
|
AirTree::create_constr(constr_index, constr_tipo.clone(), constr_args)
|
||||||
} else {
|
|
||||||
let data_type = lookup_data_type_by_tipo(&self.data_types, tipo)
|
|
||||||
.expect("Creating a record with no record definition.");
|
|
||||||
|
|
||||||
let (constr_index, _) = data_type
|
|
||||||
.constructors
|
|
||||||
.iter()
|
|
||||||
.enumerate()
|
|
||||||
.find(|(_, dt)| &dt.name == constr_name)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let constr_args = args
|
|
||||||
.iter()
|
|
||||||
.zip(constr_tipo.arg_types().unwrap())
|
|
||||||
.map(|(arg, tipo)| {
|
|
||||||
if tipo.is_data() {
|
|
||||||
AirTree::cast_to_data(
|
|
||||||
self.build(&arg.value, module_build_name, &[]),
|
|
||||||
arg.value.tipo(),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
self.build(&arg.value, module_build_name, &[])
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect_vec();
|
|
||||||
|
|
||||||
AirTree::create_constr(constr_index, constr_tipo.clone(), constr_args)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TypedExpr::Var {
|
TypedExpr::Var {
|
||||||
|
@ -659,12 +649,6 @@ impl<'a> CodeGenerator<'a> {
|
||||||
} => {
|
} => {
|
||||||
if check_replaceable_opaque_type(&record.tipo(), &self.data_types) {
|
if check_replaceable_opaque_type(&record.tipo(), &self.data_types) {
|
||||||
self.build(record, module_build_name, &[])
|
self.build(record, module_build_name, &[])
|
||||||
} else if record.tipo().is_pair() {
|
|
||||||
AirTree::pair_index(
|
|
||||||
*index,
|
|
||||||
tipo.clone(),
|
|
||||||
self.build(record, module_build_name, &[]),
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
let function_name = format!("__access_index_{}", *index);
|
let function_name = format!("__access_index_{}", *index);
|
||||||
|
|
||||||
|
@ -714,19 +698,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
field_map,
|
field_map,
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
let val_constructor = if tipo.is_pair() {
|
let val_constructor = {
|
||||||
ValueConstructor::public(
|
|
||||||
tipo.clone(),
|
|
||||||
ValueConstructorVariant::Record {
|
|
||||||
module: "".into(),
|
|
||||||
name: name.clone(),
|
|
||||||
field_map: field_map.clone(),
|
|
||||||
arity: 2,
|
|
||||||
location: Span::empty(),
|
|
||||||
constructors_count: 1,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
let data_type = lookup_data_type_by_tipo(&self.data_types, tipo);
|
let data_type = lookup_data_type_by_tipo(&self.data_types, tipo);
|
||||||
|
|
||||||
ValueConstructor::public(
|
ValueConstructor::public(
|
||||||
|
@ -792,35 +764,43 @@ impl<'a> CodeGenerator<'a> {
|
||||||
TypedExpr::TupleIndex {
|
TypedExpr::TupleIndex {
|
||||||
index, tuple, tipo, ..
|
index, tuple, tipo, ..
|
||||||
} => {
|
} => {
|
||||||
let function_name = format!("__access_index_{}", *index);
|
if tuple.tipo().is_pair() {
|
||||||
|
AirTree::pair_index(
|
||||||
|
*index,
|
||||||
|
tipo.clone(),
|
||||||
|
self.build(tuple, module_build_name, &[]),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
let function_name = format!("__access_index_{}", *index);
|
||||||
|
|
||||||
if self.code_gen_functions.get(&function_name).is_none() {
|
if self.code_gen_functions.get(&function_name).is_none() {
|
||||||
let mut body = AirTree::local_var("__fields", list(data()));
|
let mut body = AirTree::local_var("__fields", list(data()));
|
||||||
|
|
||||||
for _ in 0..*index {
|
for _ in 0..*index {
|
||||||
body = AirTree::builtin(
|
body = AirTree::builtin(
|
||||||
DefaultFunction::TailList,
|
DefaultFunction::TailList,
|
||||||
list(data()),
|
list(data()),
|
||||||
vec![body],
|
vec![body],
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
body = AirTree::builtin(DefaultFunction::HeadList, data(), vec![body]);
|
||||||
|
|
||||||
|
self.code_gen_functions.insert(
|
||||||
|
function_name.clone(),
|
||||||
|
CodeGenFunction::Function {
|
||||||
|
body,
|
||||||
|
params: vec!["__fields".to_string()],
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
body = AirTree::builtin(DefaultFunction::HeadList, data(), vec![body]);
|
AirTree::index_access(
|
||||||
|
function_name,
|
||||||
self.code_gen_functions.insert(
|
tipo.clone(),
|
||||||
function_name.clone(),
|
self.build(tuple, module_build_name, &[]),
|
||||||
CodeGenFunction::Function {
|
)
|
||||||
body,
|
|
||||||
params: vec!["__fields".to_string()],
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AirTree::index_access(
|
|
||||||
function_name,
|
|
||||||
tipo.clone(),
|
|
||||||
self.build(tuple, module_build_name, &[]),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TypedExpr::ErrorTerm { tipo, .. } => AirTree::error(tipo.clone(), false),
|
TypedExpr::ErrorTerm { tipo, .. } => AirTree::error(tipo.clone(), false),
|
||||||
|
@ -828,66 +808,32 @@ impl<'a> CodeGenerator<'a> {
|
||||||
TypedExpr::RecordUpdate {
|
TypedExpr::RecordUpdate {
|
||||||
tipo, spread, args, ..
|
tipo, spread, args, ..
|
||||||
} => {
|
} => {
|
||||||
if tipo.is_pair() {
|
let mut index_types = vec![];
|
||||||
assert!(args.len() == 1);
|
let mut update_args = vec![];
|
||||||
|
|
||||||
let Some(arg) = args.first() else {
|
let mut highest_index = 0;
|
||||||
unreachable!("Pair update with no arguments")
|
|
||||||
};
|
|
||||||
|
|
||||||
|
for arg in args
|
||||||
|
.iter()
|
||||||
|
.sorted_by(|arg1, arg2| arg1.index.cmp(&arg2.index))
|
||||||
|
{
|
||||||
let arg_val = self.build(&arg.value, module_build_name, &[]);
|
let arg_val = self.build(&arg.value, module_build_name, &[]);
|
||||||
|
|
||||||
let other_pair = self.build(spread, module_build_name, &[]);
|
if arg.index > highest_index {
|
||||||
|
highest_index = arg.index;
|
||||||
if arg.index == 0 {
|
|
||||||
AirTree::pair(
|
|
||||||
arg_val,
|
|
||||||
AirTree::pair_index(
|
|
||||||
1,
|
|
||||||
tipo.get_inner_types()[1].clone(),
|
|
||||||
other_pair,
|
|
||||||
),
|
|
||||||
tipo.clone(),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
AirTree::pair(
|
|
||||||
AirTree::pair_index(
|
|
||||||
0,
|
|
||||||
tipo.get_inner_types()[0].clone(),
|
|
||||||
other_pair,
|
|
||||||
),
|
|
||||||
arg_val,
|
|
||||||
tipo.clone(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let mut index_types = vec![];
|
|
||||||
let mut update_args = vec![];
|
|
||||||
|
|
||||||
let mut highest_index = 0;
|
|
||||||
|
|
||||||
for arg in args
|
|
||||||
.iter()
|
|
||||||
.sorted_by(|arg1, arg2| arg1.index.cmp(&arg2.index))
|
|
||||||
{
|
|
||||||
let arg_val = self.build(&arg.value, module_build_name, &[]);
|
|
||||||
|
|
||||||
if arg.index > highest_index {
|
|
||||||
highest_index = arg.index;
|
|
||||||
}
|
|
||||||
|
|
||||||
index_types.push((arg.index, arg.value.tipo()));
|
|
||||||
update_args.push(arg_val);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AirTree::record_update(
|
index_types.push((arg.index, arg.value.tipo()));
|
||||||
index_types,
|
update_args.push(arg_val);
|
||||||
highest_index,
|
|
||||||
tipo.clone(),
|
|
||||||
self.build(spread, module_build_name, &[]),
|
|
||||||
update_args,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AirTree::record_update(
|
||||||
|
index_types,
|
||||||
|
highest_index,
|
||||||
|
tipo.clone(),
|
||||||
|
self.build(spread, module_build_name, &[]),
|
||||||
|
update_args,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
TypedExpr::UnOp { value, op, .. } => {
|
TypedExpr::UnOp { value, op, .. } => {
|
||||||
AirTree::unop(*op, self.build(value, module_build_name, &[]))
|
AirTree::unop(*op, self.build(value, module_build_name, &[]))
|
||||||
|
@ -4521,8 +4467,9 @@ impl<'a> CodeGenerator<'a> {
|
||||||
arg_vec.push(arg_stack.pop().unwrap());
|
arg_vec.push(arg_stack.pop().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
let tipo = match tipo.as_ref() {
|
let ret_tipo = match tipo.as_ref() {
|
||||||
Type::Fn { ret, .. } => ret,
|
Type::Fn { ret, .. } => ret,
|
||||||
|
// In this case the Air Opcode only holds the return type and not the function type
|
||||||
_ => &tipo,
|
_ => &tipo,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4537,11 +4484,11 @@ impl<'a> CodeGenerator<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
DefaultFunction::FstPair | DefaultFunction::SndPair => {
|
DefaultFunction::FstPair | DefaultFunction::SndPair => {
|
||||||
builder::undata_builtin(&func, count, tipo, arg_vec)
|
builder::undata_builtin(&func, count, ret_tipo, arg_vec)
|
||||||
}
|
}
|
||||||
|
|
||||||
DefaultFunction::HeadList if !tipo.is_pair() => {
|
DefaultFunction::HeadList if !tipo.is_pair() => {
|
||||||
builder::undata_builtin(&func, count, tipo, arg_vec)
|
builder::undata_builtin(&func, count, ret_tipo, arg_vec)
|
||||||
}
|
}
|
||||||
|
|
||||||
DefaultFunction::MkCons | DefaultFunction::MkPairData => {
|
DefaultFunction::MkCons | DefaultFunction::MkPairData => {
|
||||||
|
|
|
@ -937,7 +937,7 @@ impl AirTree {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pair_index(index: u64, tipo: Rc<Type>, tuple: AirTree) -> AirTree {
|
pub fn pair_index(index: usize, tipo: Rc<Type>, tuple: AirTree) -> AirTree {
|
||||||
AirTree::cast_from_data(
|
AirTree::cast_from_data(
|
||||||
AirTree::builtin(
|
AirTree::builtin(
|
||||||
if index == 0 {
|
if index == 0 {
|
||||||
|
|
|
@ -2117,7 +2117,7 @@ fn acceptance_test_22_filter_map() {
|
||||||
fn acceptance_test_23_to_list() {
|
fn acceptance_test_23_to_list() {
|
||||||
let src = r#"
|
let src = r#"
|
||||||
pub type Map<key, value> =
|
pub type Map<key, value> =
|
||||||
List<Pair<key, value>>
|
List<Pair<key, value>>
|
||||||
|
|
||||||
pub opaque type AssocList<key, value> {
|
pub opaque type AssocList<key, value> {
|
||||||
inner: Map<key, value>,
|
inner: Map<key, value>,
|
||||||
|
@ -2143,11 +2143,11 @@ fn acceptance_test_23_to_list() {
|
||||||
when elems is {
|
when elems is {
|
||||||
[] ->
|
[] ->
|
||||||
[Pair(k, v)]
|
[Pair(k, v)]
|
||||||
[Pair { fst: k2, snd: v2 }, ..rest] ->
|
[Pair(k2, v2), ..rest] ->
|
||||||
if k == k2 {
|
if k == k2 {
|
||||||
[Pair(k, v), ..rest]
|
[Pair(k, v), ..rest]
|
||||||
} else {
|
} else {
|
||||||
[Pair(k2, v2), ..do_insert(rest, k, v)]
|
[Pair(k2, v2), ..do_insert(rest, k, v)]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2159,7 +2159,7 @@ fn acceptance_test_23_to_list() {
|
||||||
}
|
}
|
||||||
|
|
||||||
test to_list_2() {
|
test to_list_2() {
|
||||||
to_list(fixture_1()) == [Pair("foo", 42), Pair("bar", 14)]
|
to_list(fixture_1()) == [Pair("foo", 42).2nd, Pair("bar", 14)]
|
||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
|
@ -2996,8 +2996,6 @@ fn acceptance_test_28_unique_list() {
|
||||||
#[test]
|
#[test]
|
||||||
fn acceptance_test_29_union_pair() {
|
fn acceptance_test_29_union_pair() {
|
||||||
let src = r#"
|
let src = r#"
|
||||||
type Map<a,b> = List<Pair<a,b>>
|
|
||||||
|
|
||||||
pub opaque type AssocList<key, value> {
|
pub opaque type AssocList<key, value> {
|
||||||
inner: Map<key, value>,
|
inner: Map<key, value>,
|
||||||
}
|
}
|
||||||
|
@ -3054,7 +3052,7 @@ fn acceptance_test_29_union_pair() {
|
||||||
when left is {
|
when left is {
|
||||||
[] ->
|
[] ->
|
||||||
right
|
right
|
||||||
[Pair{fst: k, snd: v}, ..rest] ->
|
[Pair(k, v), ..rest] ->
|
||||||
do_union(rest, do_insert(right, k, v))
|
do_union(rest, do_insert(right, k, v))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue