Skip to content

[REFACTOR][IR] Phase out Downcast usages#19857

Merged
tqchen merged 9 commits into
apache:mainfrom
tqchen:task-tvm-phaseout-downcast
Jun 22, 2026
Merged

[REFACTOR][IR] Phase out Downcast usages#19857
tqchen merged 9 commits into
apache:mainfrom
tqchen:task-tvm-phaseout-downcast

Conversation

@tqchen

@tqchen tqchen commented Jun 21, 2026

Copy link
Copy Markdown
Member

This PR phases out the legacy Downcast helper and removes tvm/ir/cast.h, replacing mandatory object casts with the strict as_or_throw style APIs after bumping tvm-ffi to the latest fix.

The migration keeps nullable-object behavior explicit. Optional Any conversions that need to preserve null use the nullable value_or(nullptr).as_or_throw<ffi::Optional<T>>() pattern, while simple mandatory casts use direct receivers such as obj.as_or_throw<T>().

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/relax/transform/inline_functions.cc
Comment thread src/relax/backend/contrib/cudnn/codegen.cc Outdated
Comment thread src/s_tir/meta_schedule/postproc/rewrite_cooperative_fetch.cc Outdated
Comment thread src/s_tir/meta_schedule/postproc/rewrite_cooperative_fetch.cc Outdated
Comment thread src/s_tir/meta_schedule/schedule_rule/multi_level_tiling_tensor_core.cc Outdated
Comment thread src/s_tir/meta_schedule/mutator/mutate_thread_binding.cc Outdated
@tqchen
tqchen force-pushed the task-tvm-phaseout-downcast branch 2 times, most recently from d290a6a to d2568aa Compare June 21, 2026 20:42
tqchen added 7 commits June 22, 2026 15:32
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.
@tqchen
tqchen force-pushed the task-tvm-phaseout-downcast branch from 33a4dcd to 0977468 Compare June 22, 2026 15:35
@tqchen
tqchen merged commit a79101d into apache:main Jun 22, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants