Skip to content

Conversation

@junrushao
Copy link
Member

@junrushao junrushao commented Sep 23, 2025

This PR fixes a behavioral inconsistency between existing TVM stack and the latest main.

Originally, slicing a tvm_ffi.Array[T] always returns list[T]. This behavior was altered by PR #37, which instead returns Array[T], breaking a few unittests.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @junrushao, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a backward compatibility regression related to the slicing behavior of tvm_ffi.Array objects. Previously, slicing an Array would yield a standard Python list, but a recent change inadvertently altered this to return another Array. This PR reverts that change, ensuring that Array slicing consistently returns a list[T], thereby aligning with TVM's expected behavior and preventing potential type-related issues for existing codebases.

Highlights

  • Backward Compatibility Fix: Restores the original slicing behavior of tvm_ffi.Array[T] to return list[T], addressing a backward compatibility issue introduced by PR feat(typing): Parameterizable Array[T] and Map[K, V] #37.
  • Type Hint Update: The __getitem__ method's return type hint in python/tvm_ffi/container.py has been updated to explicitly include list[T] for slice operations.
  • Test Case Enhancement: A new assertion assert isinstance(a_slice, list) was added to tests/python/test_container.py to verify the corrected slicing behavior.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

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

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 fixes a backward compatibility issue where slicing a tvm_ffi.Array was returning an Array instead of a list. The change correctly reverts this behavior. The added test case also properly verifies the fix. My review includes one suggestion to update the type hints and docstring in Array.__getitem__ to be consistent with the new behavior, improving code clarity and maintainability.

@junrushao
Copy link
Member Author

/gemini review

Copy link
Contributor

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

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 addresses a backward compatibility issue by ensuring that slicing a tvm_ffi.Array returns a list instead of an Array. The changes in python/tvm_ffi/container.py correctly revert the slicing behavior, and the accompanying test in tests/python/test_container.py validates this fix. My review includes a suggestion to refine the type hints in __getitem__ to more accurately reflect the returned types, which will improve code clarity and maintainability.

@junrushao
Copy link
Member Author

/gemini review

Copy link
Contributor

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

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 addresses a backward compatibility issue by ensuring that slicing a tvm_ffi.Array returns a list instead of an Array. The changes in python/tvm_ffi/container.py correctly implement this behavior, and the update in tests/python/test_container.py adds a necessary check to validate it. My review includes one point of feedback to improve code documentation and maintainability.

@junrushao
Copy link
Member Author

/gemini review

Copy link
Contributor

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

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 addresses a backward compatibility issue by ensuring that slicing a tvm_ffi.Array returns a list instead of another Array. The changes in python/tvm_ffi/container.py correctly adjust the __getitem__ method's implementation, type hints, and docstring to reflect this behavior. The accompanying update to tests/python/test_container.py adds a crucial assertion to verify the returned type, which helps prevent future regressions. I've added one suggestion to make the test even more robust. Overall, this is a good and necessary fix.

@junrushao junrushao requested a review from tqchen September 23, 2025 20:44
@junrushao junrushao closed this Sep 23, 2025
@junrushao junrushao reopened this Sep 23, 2025
@tqchen tqchen changed the title fix(Array): Make array slicing behavior consistent to TVM fix(Array): Make array slicing behavior to return list Sep 23, 2025
@tqchen tqchen merged commit 90dba57 into apache:main Sep 23, 2025
14 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.

2 participants