Lines
100 %
Functions
94.44 %
Branches
use super::SymbolTable;
use crate::ast::Expr;
impl SymbolTable {
/// Records the parameter `WasmType`s for a closure signature id (see
/// [`Self::closure_params`]).
pub fn record_closure_params(
&mut self,
sig: crate::ast::ClosureSigId,
params: &[crate::ast::WasmType],
) {
self.closure_params.insert(sig.0, params.to_vec());
}
/// The recorded parameter `WasmType`s for a closure signature id, or `None`
/// when the closure wasn't recorded.
pub fn closure_params(&self, sig: crate::ast::ClosureSigId) -> Option<&[crate::ast::WasmType]> {
self.closure_params.get(&sig.0).map(Vec::as_slice)
/// The recorded first parameter `WasmType` for a closure signature id, or
/// `None` when the closure takes no parameters or wasn't recorded.
pub fn closure_param(&self, sig: crate::ast::ClosureSigId) -> Option<crate::ast::WasmType> {
self.closure_params(sig)?.first().copied()
/// Records a value-position lambda's source for the closure value in `place`.
pub fn record_closure_body(
place: crate::ast::Place,
params: crate::ast::LambdaParams,
body: Expr,
self.closure_bodies.insert(place, (params, body));
/// The source of the closure value held in `place`, if one was recorded.
#[must_use]
pub fn closure_body(
&self,
) -> Option<&(crate::ast::LambdaParams, Expr)> {
self.closure_bodies.get(&place)
/// Drops every source recorded under a local index: a function body or a
/// reset local pool reuses the indices.
pub(crate) fn forget_local_closure_bodies(&mut self) {
self.closure_bodies
.retain(|place, _| !matches!(place, crate::ast::Place::Local(_)));
/// Starts a compilation unit with no closure records. Local and global
/// places and closure signature ids all restart with each unit's context,
/// so a record outliving its unit (a failed one included) would be read
/// under a reused key.
pub(crate) fn forget_unit_closures(&mut self) {
self.closure_bodies.clear();
self.closure_results.clear();
self.closure_params.clear();
/// Drops the recorded source of `place`: a `setf` overwrote the closure, so
/// the source no longer describes the value now there.
pub fn forget_closure_body(&mut self, place: crate::ast::Place) {
self.closure_bodies.remove(&place);