Expand description
Operation table for dynamically dispatching operations based on type signatures.
This module provides a scope-based registry for operations that can be looked up
based on an operation name (string) and the types of the operands. Built-in operations
use compile-time hash tables (via phf) for efficient lookup, while custom operations
can be added dynamically through scope functions.
§Design
- Operator symbols as names: Operations are identified by their operator symbols
(e.g.,
"+","-","*") to avoid conflicts with valid identifiers. - Function pointers: Built-in operations use stateless function pointers for zero-allocation dispatch.
- Scope stack: Custom operations are handled through a stack of scope functions that can be pushed and popped as needed.
- Type optimization: Most built-in operations are homogeneous (both operands share
a type), so signatures store a primary
TypeIdplus arity. Heterogeneous binary ops (e.g. shifts, where the RHS is alwaysu32) additionally store an RHSTypeIdindex.
§Semantics
Built-in operations follow Rust language semantics. Deviations are:
- Signed integer overflow: CEL returns
Errrather than panicking (debug) or wrapping (release). Use wrapping arithmetic explicitly if overflow is intended. - Bit-shift with out-of-range count: CEL returns
Errrather than panicking (debug) or masking the shift count (release).
Structs§
- OpLookup
- Operation lookup with scope stack support.
- Operand
Types - A single built-in overload’s declared operand types, exposed for the static type checker
(
cel_parser::ty::check_expr) — neverop_fn, which is execution-only and stays private. - Tuple
OpSignature - A signature for an operator/function whose selected operand is a tuple.
Functions§
- builtin_
operand_ types - Returns every built-in overload’s declared operand types for
name, in registration order. - cast_
source_ types - Lists every source
TypeIdwith a registered cast totarget_name. Used by the type checker (ty.rs) to validate a cast without needing to touch a [DynSegment] - reads the exact same tablesOpLookup::lookup_castdoes, so the two can’t drift out of sync.