tqchen opened a new pull request, #586: URL: https://github.com/apache/tvm-ffi/pull/586
## Summary When code throws while recursively visiting an Object tree, the resulting error message lacks position context — the user sees what went wrong but not WHERE in the tree. This change adds a typed payload to attach the visit chain to `Error` and resolve it to a structured access path. ## API - **`StructuralErrorContext`** — typed payload in `tvm/ffi/extra/`, holding a `reverse_visit_pattern` (innermost-first breadcrumb trail) and an optional `previous_error_context` (preserved when wrapping a pre-existing payload in `extra_context`). - **`TVM_FFI_STRUCTURAL_VISIT_BEGIN()` / `TVM_FFI_STRUCTURAL_VISIT_END(node)`** macros instrument visit dispatch. On throw, they populate the `StructuralErrorContext` attached to the in-flight Error. - **`StructuralErrorContext::FindAccessPaths(root, ctx, allow_prefix_match=false)`** walks `root` via reflection and returns `Array<reflection::AccessPath>` for matched positions. Strict full-match default; opt-in `allow_prefix_match=true` for best-effort partial reporting. - **`StructuralErrorContext::TryGetFromError(err)`** inline helper fetches the payload from an Error. ## ABI **No ABI changes.** No modifications to `c_api.h` or `error.h` (existing `Error::extra_context` slot is reused; direct refcount-aware assignment via existing `ObjectUnsafe` patterns). ## Test plan - [x] Layer A — macro-builds-chain: \`MacroBuildsChain\`, \`MacroPreExistingPayloadWrap\` - [x] Layer B — \`FindAccessPaths\` correctness: \`BasicMatch\`, \`AccessKindCoverage\`, \`SparsePatternAnchors\`, \`PartialChain\`, \`EdgeCases\` - [x] \`StructuralErrorContext.TryGetFromError\` helper - [x] All 363 existing C++ tests pass + 8 new tests = 371 total (2 pre-existing disabled, unrelated) - [x] All 2301 Python tests pass - [x] Pre-commit clean (27 hooks) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
