parent
b807d58e89
commit
51f1da2505
|
@ -31,7 +31,7 @@ use crate::{
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
air::{Air, ExpectLevel},
|
air::{Air, ExpectLevel},
|
||||||
tree::{AirExpression, AirMsg, AirStatement, AirTree, TreePath},
|
tree::{AirMsg, AirTree, TreePath},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub type Variant = String;
|
pub type Variant = String;
|
||||||
|
@ -638,13 +638,13 @@ pub fn erase_opaque_type_operations(
|
||||||
air_tree: &mut AirTree,
|
air_tree: &mut AirTree,
|
||||||
data_types: &IndexMap<DataTypeKey, &TypedDataType>,
|
data_types: &IndexMap<DataTypeKey, &TypedDataType>,
|
||||||
) {
|
) {
|
||||||
if let AirTree::Expression(AirExpression::Constr { tipo, args, .. }) = air_tree {
|
if let AirTree::Constr { tipo, args, .. } = air_tree {
|
||||||
if check_replaceable_opaque_type(tipo, data_types) {
|
if check_replaceable_opaque_type(tipo, data_types) {
|
||||||
let arg = args.pop().unwrap();
|
let arg = args.pop().unwrap();
|
||||||
if let AirTree::Expression(AirExpression::CastToData { value, .. }) = arg {
|
|
||||||
*air_tree = *value;
|
match arg {
|
||||||
} else {
|
AirTree::CastToData { value, .. } => *air_tree = *value,
|
||||||
*air_tree = arg;
|
_ => *air_tree = arg,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -659,26 +659,15 @@ pub fn erase_opaque_type_operations(
|
||||||
/// Determine whether this air_tree node introduces any shadowing over `potential_matches`
|
/// Determine whether this air_tree node introduces any shadowing over `potential_matches`
|
||||||
pub fn find_introduced_variables(air_tree: &AirTree) -> Vec<String> {
|
pub fn find_introduced_variables(air_tree: &AirTree) -> Vec<String> {
|
||||||
match air_tree {
|
match air_tree {
|
||||||
AirTree::Expression(AirExpression::Let { name, .. }) => vec![name.clone()],
|
AirTree::Let { name, .. } => vec![name.clone()],
|
||||||
AirTree::Statement {
|
AirTree::TupleGuard { indices, .. } | AirTree::TupleClause { indices, .. } => {
|
||||||
statement: AirStatement::TupleGuard { indices, .. },
|
indices.iter().map(|(_, name)| name.clone()).collect()
|
||||||
..
|
|
||||||
}
|
}
|
||||||
| AirTree::Expression(AirExpression::TupleClause { indices, .. }) => {
|
AirTree::Fn { params, .. } => params.to_vec(),
|
||||||
indices.iter().map(|(_, name)| name).cloned().collect()
|
AirTree::ListAccessor { names, .. } => names.clone(),
|
||||||
}
|
AirTree::ListExpose {
|
||||||
AirTree::Expression(AirExpression::Fn { params, .. }) => params.to_vec(),
|
tail,
|
||||||
AirTree::Statement {
|
tail_head_names,
|
||||||
statement: AirStatement::ListAccessor { names, .. },
|
|
||||||
..
|
|
||||||
} => names.clone(),
|
|
||||||
AirTree::Statement {
|
|
||||||
statement:
|
|
||||||
AirStatement::ListExpose {
|
|
||||||
tail,
|
|
||||||
tail_head_names,
|
|
||||||
..
|
|
||||||
},
|
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
let mut ret = vec![];
|
let mut ret = vec![];
|
||||||
|
@ -691,14 +680,11 @@ pub fn find_introduced_variables(air_tree: &AirTree) -> Vec<String> {
|
||||||
}
|
}
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
AirTree::Statement {
|
AirTree::TupleAccessor { names, .. } => names.clone(),
|
||||||
statement: AirStatement::TupleAccessor { names, .. },
|
AirTree::FieldsExpose { indices, .. } => {
|
||||||
..
|
indices.iter().map(|(_, name, _)| name.clone()).collect()
|
||||||
} => names.clone(),
|
}
|
||||||
AirTree::Statement {
|
AirTree::When { subject_name, .. } => vec![subject_name.clone()],
|
||||||
statement: AirStatement::FieldsExpose { indices, .. },
|
|
||||||
..
|
|
||||||
} => indices.iter().map(|(_, name, _)| name).cloned().collect(),
|
|
||||||
_ => vec![],
|
_ => vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -709,8 +695,8 @@ pub fn is_recursive_function_call<'a>(
|
||||||
func_key: &FunctionAccessKey,
|
func_key: &FunctionAccessKey,
|
||||||
variant: &String,
|
variant: &String,
|
||||||
) -> (bool, Option<&'a Vec<AirTree>>) {
|
) -> (bool, Option<&'a Vec<AirTree>>) {
|
||||||
if let AirTree::Expression(AirExpression::Call { func, args, .. }) = air_tree {
|
if let AirTree::Call { func, args, .. } = air_tree {
|
||||||
if let AirTree::Expression(AirExpression::Var {
|
if let AirTree::Var {
|
||||||
constructor:
|
constructor:
|
||||||
ValueConstructor {
|
ValueConstructor {
|
||||||
variant: ValueConstructorVariant::ModuleFn { name, module, .. },
|
variant: ValueConstructorVariant::ModuleFn { name, module, .. },
|
||||||
|
@ -718,7 +704,7 @@ pub fn is_recursive_function_call<'a>(
|
||||||
},
|
},
|
||||||
variant_name,
|
variant_name,
|
||||||
..
|
..
|
||||||
}) = func.as_ref()
|
} = func.as_ref()
|
||||||
{
|
{
|
||||||
if name == &func_key.function_name
|
if name == &func_key.function_name
|
||||||
&& module == &func_key.module_name
|
&& module == &func_key.module_name
|
||||||
|
@ -759,7 +745,7 @@ pub fn identify_recursive_static_params(
|
||||||
// - a variable with the same name, but that was shadowed in an ancestor scope
|
// - a variable with the same name, but that was shadowed in an ancestor scope
|
||||||
// - any other type of expression
|
// - any other type of expression
|
||||||
let param_is_different = match arg {
|
let param_is_different = match arg {
|
||||||
AirTree::Expression(AirExpression::Var { name, .. }) => {
|
AirTree::Var { name, .. } => {
|
||||||
// "shadowed in an ancestor scope" means "the definition scope is a prefix of our scope"
|
// "shadowed in an ancestor scope" means "the definition scope is a prefix of our scope"
|
||||||
name != param
|
name != param
|
||||||
|| if let Some(p) = shadowed_parameters.get(param) {
|
|| if let Some(p) = shadowed_parameters.get(param) {
|
||||||
|
@ -817,8 +803,8 @@ pub fn modify_self_calls(
|
||||||
// Modify any self calls to remove recursive static parameters and append `self` as a parameter for the recursion
|
// Modify any self calls to remove recursive static parameters and append `self` as a parameter for the recursion
|
||||||
body.traverse_tree_with(
|
body.traverse_tree_with(
|
||||||
&mut |air_tree: &mut AirTree, _| {
|
&mut |air_tree: &mut AirTree, _| {
|
||||||
if let AirTree::Expression(AirExpression::Call { func, args, .. }) = air_tree {
|
if let AirTree::Call { func, args, .. } = air_tree {
|
||||||
if let AirTree::Expression(AirExpression::Var {
|
if let AirTree::Var {
|
||||||
constructor:
|
constructor:
|
||||||
ValueConstructor {
|
ValueConstructor {
|
||||||
variant: ValueConstructorVariant::ModuleFn { name, module, .. },
|
variant: ValueConstructorVariant::ModuleFn { name, module, .. },
|
||||||
|
@ -826,7 +812,7 @@ pub fn modify_self_calls(
|
||||||
},
|
},
|
||||||
variant_name,
|
variant_name,
|
||||||
..
|
..
|
||||||
}) = func.as_ref()
|
} = func.as_ref()
|
||||||
{
|
{
|
||||||
if name == &func_key.function_name
|
if name == &func_key.function_name
|
||||||
&& module == &func_key.module_name
|
&& module == &func_key.module_name
|
||||||
|
@ -865,7 +851,7 @@ pub fn modify_cyclic_calls(
|
||||||
) {
|
) {
|
||||||
body.traverse_tree_with(
|
body.traverse_tree_with(
|
||||||
&mut |air_tree: &mut AirTree, _| {
|
&mut |air_tree: &mut AirTree, _| {
|
||||||
if let AirTree::Expression(AirExpression::Var {
|
if let AirTree::Var {
|
||||||
constructor:
|
constructor:
|
||||||
ValueConstructor {
|
ValueConstructor {
|
||||||
variant: ValueConstructorVariant::ModuleFn { name, module, .. },
|
variant: ValueConstructorVariant::ModuleFn { name, module, .. },
|
||||||
|
@ -874,7 +860,7 @@ pub fn modify_cyclic_calls(
|
||||||
},
|
},
|
||||||
variant_name,
|
variant_name,
|
||||||
..
|
..
|
||||||
}) = air_tree
|
} = air_tree
|
||||||
{
|
{
|
||||||
let tipo = tipo.clone();
|
let tipo = tipo.clone();
|
||||||
let var_key = FunctionAccessKey {
|
let var_key = FunctionAccessKey {
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue