The GitHub Actions job "CI" on tvm-ffi.git/optimize-structural-map-engine has 
failed.
Run started by GitHub user tqchen (triggered by tqchen).

Head commit for run:
83c02720ca4fc828ada1686776127417e828f314 / tqchen <[email protected]>
[REFACTOR][EXTRA] Optimize StructuralMap engine

Hooked StructuralMap was slower than the mutator it replaces, and the reason
was structural rather than incidental: the engine moved every result through
representations the compiler could not eliminate, and expressed the walk in a
shape that could not inline.

Result representation. The mutate and visit hooks are C-ABI function pointers
returning TVMFFIAny, a 16-byte POD that lives in registers. Routing a result
through Expected<Any> forces it to memory, because Expected<Any> is not
trivially destructible and so is classified MEMORY. The convention is now
uniform: the ABI boundary is a raw TVMFFIAny, and a hook or callback body works
in Expected<Any> and moves out at that boundary. Descent through an unmatched
node is exactly that boundary, so it stays raw end to end.

Error context. Hooks no longer attach it. The engine names a node where it
dispatches into that node, which gives exactly one frame per node: previously a
hook named its own node and the engine named it again on some paths. Both
MAYBE_EARLY_RETURN macros lose their node argument as a result, and the visit
engine's own walk no longer routes through the hook-facing macro.

Walk structure. The callback chain was continuation-passing, so each link
nested a lambda inside the previous one and the walk-order body sat at the
bottom of that nest. The mutator now owns its callbacks and tests them with a
`(... || ...)` fold, and the whole matched-node path -- selection, identity
remap, descent and invocation -- is one straight-line function.

Selection strategy. Statically typed callbacks and runtime ffi.Function links
differ only in how a link is chosen, but that difference ran through the middle
of the walk. They are now separate classes -- StructuralMapMutatorObj in the
header, StructuralMapDynMutatorObj in the .cc -- sharing only the identity remap
in StructuralMapMutatorBaseObj. That also removes a hazard rather than
relocating it: the dynamic form used to record its selected Function in mutable
state on one shared instance, where a post-order walk could descend into a
matching child and overwrite the selection its parent was about to use.
Selection is now a local that descent cannot reach.

TVM_FFI_S_MUTATE_ASSIGN_FROM existed only to skip a conversion that was
expensive while the checked macro built its error message eagerly; it and
SMutateResultUnchanged are gone, along with the helpers that existed to recover
a type the preprocessor had swallowed. The macros add no helper of their own and
use the AnyUnsafe and ExpectedUnsafe entry points that already existed.

One deliberate behavior change: when descent hands back a node whose type no
longer matches the link that selected it, the engine reports a TypeError instead
of silently passing the node through. Default mutation is required to preserve a
node's type, so this can only happen when a hook has broken that invariant.
Everything else -- match-before-descent ordering, identity-remap entry and exit,
and the pre-order in-place rules -- is unchanged.

Tests cover the dynamic mutator for the first time in the C++ suite; it was
previously reachable only from Python.

Also fixes AnyUnsafe::CheckAnyStrict, which was missing the Any special case
both of its siblings already had.

Claude-Session: https://claude.ai/code/session_018jQX1azGgoDx3zT6BwsGAk

Report URL: https://github.com/apache/tvm-ffi/actions/runs/33919318734

With regards,
GitHub Actions via GitBox


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to