Skip to content

toolshed: tolerate anonymous struct renames in check_cython_abi.py#2242

Open
mdboom wants to merge 1 commit into
NVIDIA:mainfrom
mdboom:fix/check-cython-abi-anon-struct-renames
Open

toolshed: tolerate anonymous struct renames in check_cython_abi.py#2242
mdboom wants to merge 1 commit into
NVIDIA:mainfrom
mdboom:fix/check-cython-abi-anon-struct-renames

Conversation

@mdboom

@mdboom mdboom commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Summary

The name of an anonymous struct is an implementation detail, so it is acceptable for the name to change between builds (e.g. from the old anon_structXX / anon_unionXX scheme to the newer MODULE__anon_podXX scheme that Cython now emits). This checker now verifies that anonymous structs have the same structure, but tolerates name changes, so pure renames are no longer reported as errors.

Three changes in toolshed/check_cython_abi.py:

  • _format_base_type_name: unwrap CConstOrVolatileTypeNode instead of falling through to its Python class name. Const/volatile qualifiers don't affect ABI layout; the old behaviour stored "CConstOrVolatileTypeNode*" literally in .abi.json files, causing spurious field-type mismatches across builds that expressed the qualifier differently.

  • _build_anon_rename_map: new iterative bottom-up pass that builds a mapping from old-style anon names (in the baseline) to new-style anon_pod names (in the current build) by matching field content. Leaf structs are matched first; each round normalises remaining candidates using already-known renames, allowing parent structs that embed renamed children to be resolved in subsequent rounds.

  • _normalize_type: switched from str.replace to re.sub with \b word-boundary anchors, so a shorter name like anon_struct1 cannot corrupt a longer one like anon_struct12 due to iteration order.

check_structs is updated to look up each expected struct through the rename map, normalise expected field types before comparing, and suppress the "Added" report for new-style names that are confirmed renames.

Note: baselines generated with the old tool (which may contain "CConstOrVolatileTypeNode*" type strings) must be regenerated with the fixed tool before the rename-matching logic can work correctly.

Test plan

  • Generate a baseline from a build that uses the old anon_structXX naming scheme
  • Run check against a build that uses the new MODULE__anon_podXX naming scheme
  • Confirm no spurious "Missing" / "Added" / field-type-changed errors for anonymous struct renames

🤖 Generated with Claude Code

The name of an anonymous struct is an implementation detail, so it is
acceptable for the name to change between builds (e.g. from the old
anon_structXX / anon_unionXX scheme to the newer MODULE__anon_podXX
scheme that Cython now emits).  This change makes the checker verify
that anonymous structs have the same *structure*, while tolerating name
changes, so spurious "Missing" / "Added" errors are no longer reported
for pure renames.

Three improvements:

1. `_format_base_type_name`: unwrap `CConstOrVolatileTypeNode` instead
   of falling through to its class name.  Const/volatile qualifiers do
   not affect ABI layout, and the old behaviour stored the Python class
   name literally ("CConstOrVolatileTypeNode*") in generated .abi.json
   files, which caused field-type mismatches when comparing builds where
   the qualifier was expressed differently.

2. `_build_anon_rename_map`: new iterative bottom-up pass that builds a
   mapping from old-style anon names (expected) to new-style anon_pod
   names (found) by matching field content.  Leaf structs (no anon-type
   fields) are matched first; each round normalises the remaining
   candidates using already-known renames, allowing parent structs that
   embed renamed children to match in subsequent rounds.

3. `_normalize_type`: uses `re.sub` with `\b` word-boundary anchors
   instead of plain `str.replace`, so a shorter name like "anon_struct1"
   cannot corrupt a longer one like "anon_struct12" if iteration order
   happens to process the shorter key first.

`check_structs` is updated to look up each expected struct through the
rename map, normalise expected field types before comparing, and skip
the "Added" report for new-style names that are confirmed renames.

Note: baselines generated with the old tool (containing
"CConstOrVolatileTypeNode*" type strings) must be regenerated with the
fixed tool before the rename-matching logic can work correctly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@mdboom mdboom added this to the cuda.bindings next milestone Jun 22, 2026
@mdboom mdboom added the enhancement Any code-related improvements label Jun 22, 2026
@mdboom mdboom requested a review from leofang June 22, 2026 19:49
@mdboom mdboom self-assigned this Jun 22, 2026
@github-actions

Copy link
Copy Markdown

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

Labels

enhancement Any code-related improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant