[REFACTOR][IR] Phase out Downcast usages#19857
Conversation
There was a problem hiding this comment.
Code Review
This pull request replaces numerous instances of Downcast<T>(...) with (...).as_or_throw<T>() across the codebase to modernize casting operations, alongside adding necessary tensor container headers. Feedback on these changes highlights a critical bug in src/relax/transform/inline_functions.cc where in-place map erasure during iteration causes iterator invalidation. Additionally, several comments point out redundant, nested parentheses in the new casting expressions across multiple files, suggesting cleaner alternatives to improve code readability.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
d290a6a to
d2568aa
Compare
Bump tvm-ffi to pick up strict ObjectRef cast APIs, replace remaining Downcast usage with as_or_throw/as-style casts, and remove tvm/ir/cast.h. Keep nullable Any conversions explicit with Optional casts so null remains preserved where required.
Make Op non-nullable at the object-ref boundary and initialize registry entries through a non-null constructor. Reject missing Relax call operators before type checks or printer dispatch can dereference them, and initialize TIRX tile primitive calls with their Op already present. Add regression coverage for constructing a Relax Call without an operator.
33a4dcd to
0977468
Compare
This PR phases out the legacy
Downcasthelper and removestvm/ir/cast.h, replacing mandatory object casts with the strictas_or_throwstyle APIs after bumping tvm-ffi to the latest fix.The migration keeps nullable-object behavior explicit. Optional
Anyconversions that need to preserve null use the nullablevalue_or(nullptr).as_or_throw<ffi::Optional<T>>()pattern, while simple mandatory casts use direct receivers such asobj.as_or_throw<T>().