1
//! The v1 closure-value shape gate: only required-only lambdas become wasm
2
//! closure values; every other lambda value is the one structured error.
3

            
4
use crate::ast::{Expr, LambdaParams};
5
use crate::error::{Error, Result};
6
use crate::runtime::SymbolTable;
7

            
8
/// Whether `params` / `body` fit the v1 emit slice: required-only params;
9
/// captures of stable locals are supported.
10
266158
pub(super) fn is_v1_eligible(_symbols: &SymbolTable, params: &LambdaParams, _body: &Expr) -> bool {
11
266158
    has_v1_param_shape(params)
12
266158
}
13

            
14
1906
pub(in crate::compiler) fn non_v1_lambda_error() -> Error {
15
1906
    Error::Compile(
16
1906
        "lambda value with &optional/&rest/&key/&aux not yet supported as a \
17
1906
         first-class wasm closure; rewrite the lambda to take only required \
18
1906
         parameters or invoke it inline (the const-fold path still handles \
19
1906
         keyword args)"
20
1906
            .to_string(),
21
1906
    )
22
1906
}
23

            
24
633
pub(in crate::compiler) fn reject_non_v1_lambda(expr: &Expr) -> Result<()> {
25
633
    match expr {
26
422
        Expr::Lambda(params, _) if !has_v1_param_shape(params) => Err(non_v1_lambda_error()),
27
420
        _ => Ok(()),
28
    }
29
633
}
30

            
31
703277
pub(in crate::compiler) fn has_v1_param_shape(params: &LambdaParams) -> bool {
32
703277
    params.optional.is_empty()
33
702422
        && params.rest.is_none()
34
701581
        && params.key.is_empty()
35
701364
        && params.aux.is_empty()
36
703277
}
37

            
38
#[cfg(test)]
39
#[path = "shape_tests.rs"]
40
mod tests;