Add global type mutex for thread-safe type operations by youknowone · Pull Request #7416 · RustPython/RustPython

@youknowone

Introduce vm.state.type_mutex to serialize type mutation and version-tag assignment, matching CPython's free-threading model.

  • Add with_type_lock() helper and split modified/assign_version_tag into inner (lock-free) and public (lock-acquiring) variants
  • Add version_for_specialization() and lookup_ref_and_version_interned() for atomic type-cache lookups under the lock
  • Wrap all type-mutating paths (bases, annotations, module, type_params, doc, SetAttr) with the type lock
  • Drop old values outside the lock to prevent deadlock from weakref callbacks that may re-enter specialization
  • Fix _ctypes set_attr calls to route through proper SetAttr path
  • Reinitialize type_mutex after fork

@coderabbitai

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: ae0cda0e-cdfc-43d9-a513-452579f9ff46

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@youknowone

@youknowone

@youknowone

@youknowone

@youknowone

…IMIZED in vectorcall fast path
…_cleanup frames, guard trace dispatch

- Extract datastack_frame_size_bytes_for_code as free function, use it
  to compute init_cleanup stack bytes instead of hardcoded constant
- Add monitoring_disabled_for_code to skip instrumentation for
  synthetic init_cleanup code object in RESUME and execute_instrumented
- Add is_trace_event guard so profile-only events skip trace_func dispatch
- Reformat core.rs (rustfmt)

@youknowone

@youknowone