Skip to content

Commit

Permalink
Auto merge of #122939 - joboet:proc_macro_bridge_state, r=petrochenkov
Browse files Browse the repository at this point in the history
Simplify proc macro bridge state

Currently, `proc_macro` uses a `ScopedCell` to store the client-side proc-macro bridge. Unfortunately, this requires the `Bridge`, which has non-negligible size, to be copied out and back again on every access. In some cases, the optimizer might be able to elide these copies, but in general, this is suboptimal.

This PR removes `ScopedCell` and employs a similar trick as in [`scoped_tls`](https://crates.io/crates/scoped-tls), meaning that the only thing stored in TLS is a pointer to the state, which now is a `RefCell`. Access to the pointer is then scoped so that it is always within the lifetime of the reference to the state. Unfortunately, `scoped_tls` requires the referenced type to be `'static`, which `Bridge` is not, therefore we cannot simply copy that macro but have to reimplement its TLS trick.

This removes the `#[forbid(unsafe_code)]` on the `client` module so that we do not have to export `Bridge`, which currently is private, to the whole crate. I can change that, if necessary.
  • Loading branch information
bors committed Mar 26, 2024
2 parents 873b9a4 + caa3e75 commit 7de4c34
Showing 0 changed files with 0 additions and 0 deletions.

0 comments on commit 7de4c34

Please sign in to comment.