Skip to content

Move consistency check helpers into md_debug.h - #1513

Merged
asvetlov merged 1 commit into
aio-libs:masterfrom
asvetlov:claude/extract-consistency-macros-dea4c4
Sep 22, 2026
Merged

asvetlov merged 1 commit into
aio-libs:masterfrom
asvetlov:claude/extract-consistency-macros-dea4c4

Conversation

@asvetlov

Copy link
Copy Markdown
Member

What do these changes do?

Moves the debug-only ASSERT_CONSISTENT macro and the _md_check_consistency() / _md_dump() helpers out of hashtable.h into a new multidict/_multilib/md_debug.h header. Every file that calls ASSERT_CONSISTENT (hashtable.h, views.h, _multidict.c) now includes it directly. The function bodies are moved verbatim; the forward declarations in hashtable.h are no longer needed. The pure Python backend is unaffected.

Are there changes in behavior for the user?

No.

Is it a substantial burden for the maintainers to support this?

No, it shrinks hashtable.h and keeps debug helpers separate from the hash table logic.

Related issue number

N/A

Checklist

  • I think the code is well written
  • Unit tests for the changes exist: N/A, code move only; covered by the existing suite under debug builds
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt: N/A
  • Add a new news fragment into the CHANGES/ folder
  • make doc-spelling passes and any new technical words are added to docs/spelling_wordlist.txt

Drafted with Claude Code (Claude Opus 5); reviewed by @asvetlov.

Agent run details (optional, for reviewers)

Tests, python -m pytest tests -q -k "not test_leak":

  • 3.13.2 debug build (MULTIDICT_DEBUG_BUILD=1, asserts on): 2149 passed, 19 skipped
  • 3.14.7t debug build: 2137 passed, 31 skipped
  • 3.13.2 release build: 2149 passed, 19 skipped
  • Pure Python (--no-c-extensions): 1070 passed, 15 skipped

Lint: pre-commit on changed files passed; make doc-spelling passed.

@asvetlov
asvetlov marked this pull request as ready for review September 22, 2026 07:55
@asvetlov
asvetlov requested a review from webknjaz as a code owner September 22, 2026 07:55
@greptile-apps

greptile-apps Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

Safe to merge: the native debug build and exercised mutation and view paths completed successfully with results matching the baseline.

What we checked:

  • T-Rex ran the requested verification, but local artifact references were not uploaded. T-Rex

Reviews (1) · Last reviewed commit: "Move consistency check helpers into md_d..."

@codspeed

codspeed Bot commented Sep 22, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 298 untouched benchmarks


Comparing asvetlov:claude/extract-consistency-macros-dea4c4 (0677d4d) with master (bbee56e)

Open in CodSpeed

@asvetlov
asvetlov merged commit e2c568d into aio-libs:master Sep 22, 2026
60 of 61 checks passed
@asvetlov
asvetlov deleted the claude/extract-consistency-macros-dea4c4 branch September 22, 2026 08:14
asvetlov added a commit that referenced this pull request Sep 23, 2026
<!-- Thank you for your contribution! -->

## What do these changes do?

`hashtable.h` was 2735 lines covering three separate things: the table
itself, the single-key operations, and the multi-item `extend()`,
`update()` and `merge()` engine behind the constructors and the bulk
methods. The last of those was a contiguous block nothing else in the
file called into, whose only consumer is `_multidict.c`.

It moves verbatim into `multidict/_multilib/bulk_update.h`, along with
the `UpdateOp` enum: `_md_update()`, `_md_merge()`, the
`_md_post_update_*` family, `md_post_update()`, `md_update_from_ht()`,
`md_extend_self()`, `md_update_from_dict()`, `md_update_from_kwnames()`,
`md_update_from_seq()` and the sequence-parsing helpers beside it. The
new header includes `hashtable.h`, so `views.h`, `iter.h` and
`capsule.h` keep reaching only the hash table. This continues the split
started by #1510, #1513 and #1522.

Two things worth flagging for the reviewer.

`_list_getitem_ref()` and `_list_item_gone()` stay behind. `views.h`
uses them too, and it includes `hashtable.h` but not the new header, so
moving them would have left `views.h` compiling only by accident of the
include order in `_multidict.c`. They now have no user left in
`hashtable.h` itself, which deserves a proper home shared with the
open-coded two-element unpacking in `views.h`; that is its own change,
not this one.

The order the compiler sees does change, since the block now expands
after the rest of `hashtable.h` rather than in the middle of it.
`tools/codegen_diff.py` reports no difference at all, so nothing fell in
or out of line.

## Are there changes in behavior for the user?

No. The move is verbatim, and the pure Python implementation has no
header structure to mirror.

## Is it a substantial burden for the maintainers to support this?

No, it shrinks `hashtable.h` by around 710 lines and keeps the bulk
paths separate from the table and its single-key API.

## Related issue number

N/A

## Checklist

- [x] I think the code is well written
- [ ] Unit tests for the changes exist: N/A, code move only; the moved
  functions are already covered through the constructors, `extend()`,
  `update()` and `merge()`
- [x] Documentation reflects the changes
- [ ] If you provide code modification, please add yourself to
  `CONTRIBUTORS.txt`: N/A
- [x] Add a new news fragment into the `CHANGES/` folder
- [x] `make doc-spelling` passes and any new technical words are added
to
  `docs/spelling_wordlist.txt`

<details>
<summary>Agent run details (optional, for reviewers)</summary>

Rebased onto master after #1529 and #1530 landed; #1530 reworked the
same region, so `bulk_update.h` was rebuilt from master's text rather
than carried over from the earlier push, and its includes now name
`reflist.h` instead of the removed `deferred_decref.h`.

Verbatim-move check: the moved text, with the retained
`_list_getitem_ref` block spliced back at its original offset,
reconstructs master's `hashtable.h` lines 1693-2416 exactly.

Codegen (`tools/codegen_diff.py --ref upstream/master`):
- CPython 3.13.2: 0 of 191 functions differ
- CPython 3.14.7t: 0 of 196 functions differ

Tests, `python -m pytest tests -q -k "not test_leak"`, each in its own
venv:
- 3.13.2 release build: 2326 passed, 107 skipped
- 3.13.2 debug build (`MULTIDICT_DEBUG_BUILD=1`, asserts on): 2326
  passed, 107 skipped
- 3.14.7t debug build: 2315 passed, 118 skipped
- Pure Python (`MULTIDICT_NO_EXTENSIONS=1`, `--no-c-extensions`): 1124
  passed, 17 skipped

Lint: `pre-commit run --all-files` passed; `make doc-spelling` passed.
</details>

Drafted with Claude Code (Opus 5); reviewed by @asvetlov.
@asvetlov asvetlov mentioned this pull request Sep 25, 2026
4 of 6 tasks
asvetlov added a commit that referenced this pull request Sep 25, 2026
<!-- Thank you for your contribution! -->

## What do these changes do?

Renames `multidict/_multilib/md_debug.h` to `debug.h`. The `_multilib`
headers are private, so the `md_` prefix on the file name carries no
information. The include guard, the four `#include` sites and the file
table in `AGENTS.md` are updated to match; clang-format re-sorted the
includes. No code change.

## Are there changes in behavior for the user?

No.

## Is it a substantial burden for the maintainers to support this?

No.

## Related issue number

Follow-up to #1513.

## Checklist

- [x] I think the code is well written
- [ ] Unit tests for the changes exist N/A, pure file rename covered by
the existing suite
- [x] Documentation reflects the changes
- [ ] If you provide code modification, please add yourself to
`CONTRIBUTORS.txt` N/A
- [x] Add a new news fragment into the `CHANGES/` folder
- [x] `make doc-spelling` passes and any new technical words are added
to `docs/spelling_wordlist.txt`

Drafted with Claude Code (Claude Opus 5.5); reviewed by @asvetlov.

<details>
<summary>Agent run details (optional, for reviewers)</summary>

Tests: `MULTIDICT_DEBUG_BUILD=1` C extension on 3.13, 2683 passed, 180
skipped; C extension on 3.10.17, 2696 passed, 167 skipped. Pure-Python
leg not run, since only C headers changed.
Lint: pre-commit on changed files passed; `make doc-spelling` passed.
</details>
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.

1 participant