Skip to content

Add fallbacks to spelling wordlist - #1439

Merged
asvetlov merged 1 commit into
aio-libs:masterfrom
asvetlov:fix-fallbacks-spelling
Sep 11, 2026
Merged

asvetlov merged 1 commit into
aio-libs:masterfrom
asvetlov:fix-fallbacks-spelling

Conversation

@asvetlov

Copy link
Copy Markdown
Member

What do these changes do?

Adds the plural "fallbacks" to docs/spelling_wordlist.txt. The word
"fallback" was already allowed, but sphinxcontrib.spelling does not
stem plurals, so make doc-spelling currently fails on CHANGES.rst
line 79, which uses "fallbacks".

Are there changes in behavior for the user?

No.

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

No, it is a one-line addition to a word list.

Related issue number

None.

Checklist

  • I think the code is well written
  • Unit tests for the changes exist (N/A, wordlist entry only)
  • 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
Agent run details (optional, for reviewers)

Tests: make doc-spelling run locally; failed before this change on
the pre-existing "fallbacks" typo, passes after.

Drafted with Claude Code (Sonnet 5); reviewed by [email protected].

@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Sep 11, 2026
@asvetlov asvetlov added the bot:chronographer:skip This PR does not need to include a change note label Sep 11, 2026
@asvetlov
asvetlov marked this pull request as ready for review September 11, 2026 14:13
@asvetlov
asvetlov requested a review from webknjaz as a code owner September 11, 2026 14:13
@asvetlov
asvetlov enabled auto-merge (squash) September 11, 2026 14:13
@codspeed

codspeed Bot commented Sep 11, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 12.04%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 3 improved benchmarks
✅ 245 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_cimultidict_getall_istr_hit[c] 35.5 ms 31.4 ms +13.02%
⚡ test_multidict_getall_str_hit[cs-c] 36.6 ms 32.6 ms +12.17%
⚡ test_multidict_getall_str_hit[ci-c] 37.7 ms 34 ms +10.95%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing asvetlov:fix-fallbacks-spelling (c5d7187) with master (286a6f8)

Open in CodSpeed

@greptile-apps

greptile-apps Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

Safe to merge: no defects were found in the changed documentation files.

There are no confirmed issues requiring changes. The exact word-list behavior and documentation parsing were verified successfully.

Files Needing Attention: None.

T-Rex T-Rex Logs

What T-Rex did

  • Compared the parent revision with the current revision and confirmed the fallbacks entry changed from absent to present.
  • Built the documentation for CHANGES/1439.doc.rst with warnings treated as errors, and the build completed successfully.
  • Attempted the full spelling build; it halted before processing documentation because pyenchant could not load the OS-level Enchant C library.
  • Executed the spelling fallbacks evidence script and compared before/after results; fallbacks_accepted changed from False to True, the Sphinx dummy build succeeded, and the blocker is the OS-level Enchant library.

View all artifacts

T-Rex Ran code and verified through T-Rex

Reviews (1): Last reviewed commit: "Add fallbacks to spelling wordlist" | Re-trigger Greptile

@asvetlov
asvetlov merged commit db5d336 into aio-libs:master Sep 11, 2026
56 of 57 checks passed
@asvetlov
asvetlov deleted the fix-fallbacks-spelling branch September 11, 2026 14:22
asvetlov added a commit that referenced this pull request Sep 12, 2026
<!-- Thank you for your contribution! -->

## What do these changes do?

First slice of the lock-free read path deferred out of #1438: instead
of a critical section, `__contains__` now protects itself with a
reader-counted table retirement scheme, and the hash table a lock-free
reader might still be walking is kept alive until it's safe to free.

Two counters, gated entirely behind `Py_GIL_DISABLED`:

- `MultiDictObject.active_readers`: a coarse "some lock-free reader is
  in flight on this object" gate, bumped before a reader ever
  dereferences a keys table and dropped once it's done
  (`_md_reader_enter()`/`_md_reader_exit()`).
- `htkeys_t.readers`: a per-table count, advisory only, used purely as
  a defensive assertion once the coarse gate is already known closed.
  It is not itself load-bearing for safety: an embedded refcount can't
  safely announce "about to use this" without a bootstrap hazard,
  since the increment itself would dereference memory that might
  already be freed by the time it runs.

`_md_retire()`/`_md_drain_retired()`: a resize/shrink/clear no longer
frees the outgoing table immediately, only once `active_readers` reads
0 at a point synchronized (`seq_cst` on both the `md->keys` swap and
the `active_readers` ops -- anything weaker leaves a real,
architecture-dependent race, the same shape as Dekker's algorithm). A
table that can't be freed yet moves to a per-object retired list and
is freed opportunistically the next time the object resizes.

`_md_shrink()` gets a second implementation under `Py_GIL_DISABLED`:
the existing one compacts the currently-published table in place,
which races a lock-free reader walking the very memory being
rewritten. The free-threaded version reuses `_md_resize()` at the
current size instead (build a new table, swap, retire the old one),
which already has the right shape; the GIL build keeps the original
in-place version unchanged.

`md_clone_from_ht()` gets a matching fix: it `memcpy`s another live
table's header wholesale, which was copying that table's in-flight
reader count and retirement link along with everything else.

`md_contains()` with `pret == NULL` (`__contains__`'s actual call
shape) is the first lock-free consumer: `entry->identity`/`hash` are
write-once-at-insertion and never mutated again outside `getall()`'s
already-critical-section-only `MD_HASH_MARK` toggling, so this walk
needs nothing beyond the table's own lifetime protection -- no atomic
entry-field stores or `TryIncRef` machinery required, unlike `get()`'s
value read (out of scope here; deferred as its own follow-up). The
critical sections around `multidict_sq_contains` and
`multidict_keysview_contains` are removed accordingly; view
set-algebra callers of `md_contains(pret != NULL)` keep their existing
critical sections untouched.

Also fixes a small, pre-existing, unrelated bug noticed while
rewriting `md_contains()`: `identity` was decref'd once on a match,
then decref'd again via `goto fail` if `_md_ensure_key()` failed
afterward.

Renamed seven helpers in `hashtable.h` (`_md_reader_enter`,
`_md_reader_exit`, `_md_retire`, `_md_drain_retired`, `_md_calc_key`,
`_md_finder_slot`, `_md_finder_index`) to use the `_md_` prefix the
file already uses for internal-only helpers, since none of them have
callers outside the file.

`getall()` and the view set-algebra methods stay under the critical
section: `md_find_next()`/`md_finder_cleanup()` mark visited entries
by mutating `entry->hash` in place (`MD_HASH_MARK`), which races any
concurrent access to those entries the same way `_md_shrink()`'s
in-place compaction did. Fixing that needs moving the visited-tracking
to a call-local structure instead of shared entry state -- a
self-contained follow-up, not attempted here. `get()`/`getone()`/
`__getitem__` likewise stay locked, needing atomic stores at every
entry-mutation site plus `PyUnstable_TryIncRef` on read.

## Are there changes in behavior for the user?

No behavior change for single-threaded code or the default GIL build.
On the free-threaded build, `__contains__` no longer takes a critical
section.

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

Some: this introduces the reclamation scheme the rest of the lock-free
read work will build on, so it's more surface than a typical PR, but
it's confined to `hashtable.h` and gated entirely behind
`Py_GIL_DISABLED`; no behavior change on the GIL build and no new
public API.

## Related issue number

N/A, no linked issue.

## Checklist

- [x] I think the code is well written
- [x] Unit tests for the changes exist
- [x] Documentation reflects the changes
- [ ] If you provide code modification, please add yourself to
`CONTRIBUTORS.txt`
- [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>

Tests: `pytest -q` on the default GIL build (1834 passed) and on a
free-threaded `3.13.7t` build, both release and
`MULTIDICT_DEBUG_BUILD=1` (1829 passed, 5 skipped each), re-verified
after each structural change (retirement scheme, `_md_shrink`
rewrite, `md_contains` conversion, the rename) and again after
rebasing onto master's #1440.

Added `test_contains_lock_free_thread_safety`, driving heavy
concurrent `add()`/`pop()` churn against concurrent `in` checks
specifically to exercise the retire/drain path, not just the
(always-safe) case where `active_readers` happens to already be 0 at
retirement time.

Same honest caveat as on #1438's second regression test: I could not
force a crash on a deliberately-unprotected version of `md_contains`
by stress-testing it (release build, debug build, a heavier
standalone script) -- this allocator doesn't poison freed memory, so
a stale read tends to return coherent-looking bytes rather than
crash. The race is real by construction (verified by manually
disabling the protection and reviewing the resulting code path), just
not reliably reproducible empirically in this environment.

`make doc-spelling` passes clean (the pre-existing "fallbacks"
wordlist gap from #1438 was fixed by #1439, already on master).

Drafted with Claude Code (Sonnet 5); reviewed by
[email protected].
</details>

---------

Co-authored-by: Claude Sonnet 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided There is a change note present in this PR bot:chronographer:skip This PR does not need to include a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant