This is an archive of the discontinued Mercurial Phabricator instance.

rust-cpython: mark PySharedState as Sync so &'PySharedState can be Send (RFC)
Needs RevisionPublic

Authored by yuja on Sep 16 2019, 7:27 PM.

Details

Reviewers
baymax
Group Reviewers
hg-reviewers
Summary

The goal is to store &'static PySharedState in $leaked struct, which allows
us to move the $leaked struct out of the macro. Currently, it depends on
$inner.py_shared_state(py).

I think PySharedState is Sync because any mutation is synchronized by the
Python GIL, but I'm not pretty sure. I want to know if that's correct before
moving forward.

Diff Detail

Repository
rHG Mercurial
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

yuja created this revision.Sep 16 2019, 7:27 PM

It is indeed Sync because the py_class! macro forces us to have a reference to the GIL at the type level to access the data attributes, but I would also like to be extra sure and have someone else confirm it.

I asked some coworkers, and they said:

I do not believe this to be correct. An object is Sync if it is *inherently* thread-safe. This object is not -- the first thing borrow_mut does is a racy read of mutably_borrowed.

so I'm now leaning towards this being a bad idea.

Also, since it's possible we could call back into Python code and *that* could release-and-reacquire the GIL, the GIL guarding is probably insufficient to make this a "safe lie".

baymax requested changes to this revision.Jan 24 2020, 12:31 PM

There seems to have been no activities on this Diff for the past 3 Months.

By policy, we are automatically moving it out of the need-review state.

Please, move it back to need-review without hesitation if this diff should still be discussed.

:baymax:need-review-idle:

This revision now requires changes to proceed.Jan 24 2020, 12:31 PM