Gather arities while building can declarations

This commit is contained in:
Agus Zubiaga 2024-08-26 22:39:35 -03:00
parent 4e35a68f98
commit 2f4e80b696
No known key found for this signature in database
3 changed files with 32 additions and 28 deletions

View file

@ -18,7 +18,7 @@ use roc_error_macros::internal_error;
use roc_module::called_via::CalledVia;
use roc_module::ident::{ForeignSymbol, Lowercase, TagName};
use roc_module::low_level::LowLevel;
use roc_module::symbol::{ModuleId, Symbol};
use roc_module::symbol::{IdentId, ModuleId, Symbol};
use roc_parse::ast::{self, Defs, PrecedenceConflict, StrLiteral};
use roc_parse::ident::Accessor;
use roc_parse::pattern::PatternType::*;
@ -2776,6 +2776,9 @@ pub struct Declarations {
// used for ability member specializatons.
pub specializes: VecMap<usize, Symbol>,
// used while lowering params.
arity_by_name: VecMap<IdentId, usize>,
pub host_exposed_annotations: VecMap<usize, (Variable, crate::def::Annotation)>,
pub function_bodies: Vec<Loc<FunctionDef>>,
@ -2804,6 +2807,7 @@ impl Declarations {
expressions: Vec::with_capacity(capacity),
specializes: VecMap::default(), // number of specializations is probably low
destructs: Vec::new(), // number of destructs is probably low
arity_by_name: VecMap::with_capacity(capacity),
}
}
@ -2842,6 +2846,9 @@ impl Declarations {
arguments: loc_closure_data.value.arguments,
};
self.arity_by_name
.insert(symbol.value.ident_id(), function_def.arguments.len());
let loc_function_def = Loc::at(loc_closure_data.region, function_def);
let function_def_index = Index::push_new(&mut self.function_bodies, loc_function_def);
@ -2890,6 +2897,9 @@ impl Declarations {
arguments: loc_closure_data.value.arguments,
};
self.arity_by_name
.insert(symbol.value.ident_id(), function_def.arguments.len());
let loc_function_def = Loc::at(loc_closure_data.region, function_def);
let function_def_index = Index::push_new(&mut self.function_bodies, loc_function_def);
@ -2966,6 +2976,8 @@ impl Declarations {
.insert(self.declarations.len(), annotation);
}
self.arity_by_name.insert(symbol.value.ident_id(), 0);
self.declarations.push(DeclarationTag::Value);
self.variables.push(expr_var);
self.symbols.push(symbol);
@ -3205,6 +3217,11 @@ impl Declarations {
collector
}
pub(crate) fn take_arity_by_name(&mut self) -> VecMap<IdentId, usize> {
// `arity_by_name` is only needed for lowering module params
std::mem::take(&mut self.arity_by_name)
}
}
roc_error_macros::assert_sizeof_default!(DeclarationTag, 8);