Skip to content

Simplify downcast_primitive_array!() dfn for rust-analyzer#9454

Open
brunal wants to merge 1 commit intoapache:mainfrom
brunal:simplify-macro
Open

Simplify downcast_primitive_array!() dfn for rust-analyzer#9454
brunal wants to merge 1 commit intoapache:mainfrom
brunal:simplify-macro

Conversation

@brunal
Copy link
Contributor

@brunal brunal commented Feb 21, 2026

The original definition parses the whole "non-primitive" expression tree in detail. Additionally, the macro is recursive. As a consequence, calling the macro with many "non-primitive" branches and right-hand sides is expensive.

In practice, this causes rust-analyzer to choke on some uses of the macro (e.g. in arrow-ord/src/cmp.rs). Increasing the recursion limit up to 10k does not solve it (and higher limits causes rust-analyzer to crash).

The simple solution is to stop destructuring the "non-primitive" tree: just make it a tt*. The inner downcast_primitive_array_helper!() macro will parse it once in turn.

The original definition parses the whole "non-primitive" expression tree
in detail. Additionally, the macro is recursive. As a consequence,
calling the macro with many "non-primitive" branches and right-hand
sides is expensive.

In practice, this causes rust-analyzer to choke on some uses of the
macro (e.g. in arrow-ord/src/cmp.rs). Increasing the recursion limit up
to 10k does not solve it (and higher limits causes rust-analyzer to
crash).

The simple solution is to stop destructuring the "non-primitive" tree:
just make it a tt*. The inner downcast_primitive_array_helper!() macro
will parse it once in turn.
@github-actions github-actions bot added the arrow Changes to the arrow crate label Feb 21, 2026
@brunal brunal marked this pull request as ready for review February 21, 2026 10:48
@brunal
Copy link
Contributor Author

brunal commented Feb 21, 2026

Note that an intermediate improvement would be to use tt in the 3 recursive branches and keep the whole pattern for the last branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant