Skip to content

feat: add ffi.GetInvalidObject global function for MISSING singleton#447

Merged
tqchen merged 1 commit intoapache:mainfrom
junrushao:2026-02-14/invalid-object
Feb 15, 2026
Merged

feat: add ffi.GetInvalidObject global function for MISSING singleton#447
tqchen merged 1 commit intoapache:mainfrom
junrushao:2026-02-14/invalid-object

Conversation

@junrushao
Copy link
Member

@junrushao junrushao commented Feb 14, 2026

C++ changes:

  • Register ffi.GetInvalidObject global function in container.cc
  • Remove ffi.MapGetMissingObject in favor of the new name

Python changes:

  • Initialize MISSING in core.pyx via _get_global_func after Function is registered
  • Re-export MISSING in container.py from core
  • Add MISSING: Object to core.pyi type stub
  • Update _ffi_api.py stubs and all

Tests:

  • Add test_missing_object verifying singleton identity across imports and Map.get() integration

@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 refactors the handling of "missing" or "invalid" object states by introducing a dedicated C API for a global singleton. This change generalizes the pattern previously specific to map operations, providing a more direct and consistent way to access this sentinel value across the FFI boundary. It simplifies Python-side integration by exposing a MISSING global, leading to cleaner code and improved maintainability.

Highlights

  • New C API for Invalid Object: Introduced a new C API, TVMFFIAnyGetInvalidObject, to provide a global singleton for an "invalid" or "missing" object state, generalizing the pattern previously specific to map operations.
  • Python Global MISSING Object: Exposed this global invalid object as MISSING in the Cython core module, allowing direct and consistent Python access to this sentinel value.
  • FFI Function Registry Cleanup: Removed the ffi.MapGetMissingObject function from the FFI function registry, streamlining the missing object pattern and reducing redundancy.
  • Python Module Integration: Updated Python modules (container.py, _ffi_api.py, core.pyi) to utilize the new MISSING global, ensuring cleaner code and improved maintainability.
  • Comprehensive Unit Testing: Added comprehensive C++ and Python unit tests to validate the functionality and singleton property of the new invalid object API and its Python exposure.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • include/tvm/ffi/c_api.h
    • Added declaration for TVMFFIAnyGetInvalidObject.
  • python/tvm_ffi/_ffi_api.py
    • Removed MapGetMissingObject from type hints and the list of exported FFI functions.
  • python/tvm_ffi/container.py
    • Updated the MISSING object import to use the new global from tvm_ffi.core.
  • python/tvm_ffi/core.pyi
    • Added a type declaration for the MISSING global.
  • python/tvm_ffi/cython/base.pxi
    • Declared the new C API function TVMFFIAnyGetInvalidObject.
  • python/tvm_ffi/cython/core.pyx
    • Implemented the MISSING global by calling TVMFFIAnyGetInvalidObject and wrapping the result.
  • src/ffi/container.cc
    • Removed the registration of ffi.MapGetMissingObject.
    • Implemented the TVMFFIAnyGetInvalidObject C API.
  • tests/cpp/test_base.cc
    • Added a C++ unit test to verify the TVMFFIAnyGetInvalidObject API returns a valid, singleton object.
  • tests/python/test_container.py
    • Added a Python unit test to confirm MISSING is a valid singleton and integrates correctly with Map.get().
Activity
  • No human activity (comments, reviews) detected on this pull request yet.
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
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 introduces a new C API TVMFFIAnyGetInvalidObject to provide a global singleton for the invalid/missing object, generalizing a pattern that was previously specific to Map FFI functions. The changes are well-structured, spanning the C++ implementation, C API headers, Cython bindings, and Python-level usage. The old FFI function MapGetMissingObject is correctly removed, and usages are updated to the new MISSING global from tvm_ffi.core. The addition of both C++ and Python unit tests ensures the new functionality is correct and robust. Overall, this is a solid improvement that enhances the FFI's consistency and usability. I have a couple of minor suggestions to improve code style in the new C++ test.

@junrushao junrushao force-pushed the 2026-02-14/invalid-object branch 2 times, most recently from fe3f68c to 3b4cbef Compare February 15, 2026 02:26
@junrushao junrushao changed the title feat: add TVMFFIAnyGetInvalidObject C API for global invalid object singleton feat: expose invalid object singleton via global function Feb 15, 2026
@junrushao junrushao force-pushed the 2026-02-14/invalid-object branch from 3b4cbef to 9afb0a2 Compare February 15, 2026 02:30
C++ changes:
- Register `ffi.GetInvalidObject` global function in container.cc
- Remove `ffi.MapGetMissingObject` in favor of the new name

Python changes:
- Initialize `MISSING` in core.pyx via `_get_global_func` after
  `Function` is registered
- Re-export `MISSING` in container.py from core
- Add `MISSING: Object` to core.pyi type stub
- Update _ffi_api.py stubs and __all__

Tests:
- Add `test_missing_object` verifying singleton identity across
  imports and Map.get() integration
@junrushao junrushao force-pushed the 2026-02-14/invalid-object branch from 9afb0a2 to 7ed6fef Compare February 15, 2026 02:30
@junrushao junrushao changed the title feat: expose invalid object singleton via global function feat: add ffi.GetInvalidObject global function for MISSING singleton Feb 15, 2026
@junrushao junrushao requested a review from tqchen February 15, 2026 05:35
@tqchen tqchen merged commit 86c4042 into apache:main Feb 15, 2026
8 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