pub struct FunctionObject {
pub id: FunctionId,
pub symbol: Symbol,
pub cases: Vec<FunctionCase>,
}Expand description
A callable function object: a named set of shape-typed overload cases with selection driven by case priority and argument match score.
Fields§
§id: FunctionIdStable function identifier.
symbol: SymbolSymbol naming the function.
cases: Vec<FunctionCase>Overload cases in registration order.
Implementations§
Source§impl FunctionObject
impl FunctionObject
Sourcepub fn new(id: FunctionId, symbol: Symbol, cases: Vec<FunctionCase>) -> Self
pub fn new(id: FunctionId, symbol: Symbol, cases: Vec<FunctionCase>) -> Self
Build a function object from an id, symbol, and its overload cases.
Sourcepub fn select_case<'a>(
&'a self,
cx: &mut Cx,
prepared: &PreparedArgs,
) -> Result<SelectedCase<'a>>
pub fn select_case<'a>( &'a self, cx: &mut Cx, prepared: &PreparedArgs, ) -> Result<SelectedCase<'a>>
Pick the overload case that best matches the prepared arguments.
Cases whose argument shape accepts the arguments are ordered by priority
first, then by proven argument-shape specificity (the subshape lattice),
and only then by additive match score: a case whose argument shape is a
proven subshape of another’s is strictly more specific and wins even at
an equal or lower score. Returns Error::NoMatchingOverload when
nothing matches and Error::AmbiguousOverload when two top cases
remain unordered (equal priority, neither shape subsumes the other, and
equal score).
Sourcepub fn combined_args_shape(&self) -> Option<Arc<dyn Shape>>
pub fn combined_args_shape(&self) -> Option<Arc<dyn Shape>>
Shape accepting any case’s arguments: the lone case’s shape, or a
one-of over every case. None when the function has no cases.
Sourcepub fn combined_result_shape(&self) -> Option<Arc<dyn Shape>>
pub fn combined_result_shape(&self) -> Option<Arc<dyn Shape>>
Shape covering every case’s result, or None if any case omits a
result shape. A single result is returned directly; many become a
one-of.
Sourcepub fn declared_demand(&self, index: usize) -> Option<Demand>
pub fn declared_demand(&self, index: usize) -> Option<Demand>
Evaluation demand declared for argument index across all cases.
Returns the shared demand when every case agrees, Demand::Value when
they disagree, and None when no case declares that position.
Sourcepub fn declared_demands(&self) -> Vec<Demand>
pub fn declared_demands(&self) -> Vec<Demand>
Per-position demands for the call, sized to the widest case and
defaulting unspecified positions to Demand::Value.
Trait Implementations§
Source§impl Callable for FunctionObject
impl Callable for FunctionObject
Source§fn call(&self, cx: &mut Cx, args: Args) -> Result<Value>
fn call(&self, cx: &mut Cx, args: Args) -> Result<Value>
Args.Source§fn browse_args_shape(&self, _cx: &mut Cx) -> Result<Option<ShapeRef>>
fn browse_args_shape(&self, _cx: &mut Cx) -> Result<Option<ShapeRef>>
Source§impl Clone for FunctionObject
impl Clone for FunctionObject
Source§fn clone(&self) -> FunctionObject
fn clone(&self) -> FunctionObject
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Object for FunctionObject
impl Object for FunctionObject
Source§fn display(&self, _cx: &mut Cx) -> Result<String>
fn display(&self, _cx: &mut Cx) -> Result<String>
Source§fn header(&self) -> &ObjectHeader
fn header(&self) -> &ObjectHeader
Source§fn op(&self, _key: &OpKey) -> Option<&dyn Op>
fn op(&self, _key: &OpKey) -> Option<&dyn Op>
key, if any.