Skip to content

[Feature Request] Introduce ffi::Expected<> #234

@junrushao

Description

@junrushao

Goal Enable an exception-free C++ API by introducing an ffi::Expected<T> type (mirroring std::expected / Rust Result) and wiring it through ffi::Function invocation and registration.

Problem Current ffi::Function calls always return Any; failures rely on exceptions. Consumers needing hard real-time or exception-free environments lack a native way to detect errors without exceptions, and we can’t guanratee callbacks are all exception-free.

Proposal

  • Add ffi::Expected<T> where T is any type TVM-FFI supports but not tvm::ffi::Error; Err is always ffi::Error.
  • Extend ffi::Function invocation helpers so users can request wrappers of type (Args...) -> ffi::Expected<T>; calls that produce an ffi::Error fill the error branch instead of throwing.
  • Allow registering functions that implement (Args...) -> ffi::Expected<T>; the dispatcher should convert returned Expected objects into the existing error propagation path so current exception-based APIs keep working.
  • Document usage patterns, including examples of calling and registering Expected functions, and guidance on when to "use exception" vs. Expected flows.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions