Lines
100 %
Functions
Branches
//! What a closure cell holds and what a definition's init asks of its cell.
use crate::ast::WasmType;
/// The signature of a closure a cell holds, which the next attempt interns
/// again: a signature id belongs to one attempt's context.
#[derive(Clone, Debug, PartialEq)]
pub(crate) struct ClosureShape {
pub(crate) params: Vec<WasmType>,
pub(crate) result: WasmType,
}
impl ClosureShape {
/// The shape a next attempt can intern: none for a closure whose
/// signature names other closures.
pub(crate) fn of(params: &[WasmType], result: WasmType) -> Option<Self> {
let flat = |ty: &WasmType| !matches!(ty, WasmType::Closure(_));
(params.iter().all(flat) && flat(&result)).then(|| Self {
params: params.to_vec(),
result,
})
/// What the init of a definition that asks for a cell probes to: the cell's
/// type, or the closure the cell holds, whose signature the next attempt
/// interns again.
pub(crate) enum Asked {
Typed(WasmType),
Closure(ClosureShape),
Untyped,