1
//! What a closure cell holds and what a definition's init asks of its cell.
2

            
3
use crate::ast::WasmType;
4

            
5
/// The signature of a closure a cell holds, which the next attempt interns
6
/// again: a signature id belongs to one attempt's context.
7
#[derive(Clone, Debug, PartialEq)]
8
pub(crate) struct ClosureShape {
9
    pub(crate) params: Vec<WasmType>,
10
    pub(crate) result: WasmType,
11
}
12

            
13
impl ClosureShape {
14
    /// The shape a next attempt can intern: none for a closure whose
15
    /// signature names other closures.
16
7649
    pub(crate) fn of(params: &[WasmType], result: WasmType) -> Option<Self> {
17
12575
        let flat = |ty: &WasmType| !matches!(ty, WasmType::Closure(_));
18
7649
        (params.iter().all(flat) && flat(&result)).then(|| Self {
19
7647
            params: params.to_vec(),
20
7647
            result,
21
7647
        })
22
7649
    }
23
}
24

            
25
/// What the init of a definition that asks for a cell probes to: the cell's
26
/// type, or the closure the cell holds, whose signature the next attempt
27
/// interns again.
28
#[derive(Clone, Debug, PartialEq)]
29
pub(crate) enum Asked {
30
    Typed(WasmType),
31
    Closure(ClosureShape),
32
    Untyped,
33
}