Skip to content

[Feat][Rust] Add leaf lookup dispatch for match_any#685

Draft
tlopex wants to merge 3 commits into
apache:mainfrom
tlopex:feat/rust-match-any-phase-2-main
Draft

[Feat][Rust] Add leaf lookup dispatch for match_any#685
tlopex wants to merge 3 commits into
apache:mainfrom
tlopex:feat/rust-match-any-phase-2-main

Conversation

@tlopex

@tlopex tlopex commented Jul 24, 2026

Copy link
Copy Markdown
Member

This PR adds a leaf-only lookup fast path to Rust match_any!. For at least two unguarded arms with simple bindings, when every pattern corresponds to one stable runtime TypeIndex, it lazily maps each TypeIndex to a source-order ArmId and uses a native Rust match to select only the relevant conversion. The table stores no closures or arm bodies, duplicate types preserve first-arm semantics, and misses use the _ fallback. Single-arm, guarded, non-leaf/category, or content-dependent matches retain the Phase 1 ordered path. The PR also adds opt-in final-type metadata and focused integration tests. The two-arm threshold is based on release benchmarks of standard ObjectRef conversions.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@tlopex
tlopex marked this pull request as draft July 24, 2026 07:29

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.

Why we need to add modules here instead of in tests

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

okay, would move it

let type_key = get_attr(&derive_input, "type_key")
.map(attr_to_str)
.expect("Expect #[type_key = \"<my_type_key>\"] attribute");
let type_final = match get_attr(&derive_input, "type_final") {

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.

I think type_final can be false in cpp side?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes. false is the default, so a type whose C++ definition has _type_final = false simply omits the attribute.

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.

Tests should not be here. why we have another file for match_any

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

moved

/// Whether every instance of this type has exactly `Self::type_index()`.
///
/// A final type must never have a registered subtype.
#[doc(hidden)]

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.

I'm not sure if it's necessary. I think ObjectCore is not designed to be exposed to users.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ObjectCore is already public because downstream #[derive(Object)]expansions need it; TYPE_FINAL is default-false and #[doc(hidden)], so it remains internal derive metadata rather than a user-facing API.

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