rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.63k stars 12.74k forks source link

Tracking issue for Scoped TLS #27715

Closed alexcrichton closed 8 years ago

alexcrichton commented 9 years ago

This is a tracking issue for the unstable scoped_tls feature in the standard library. The known open questions about this API are:

nagisa commented 9 years ago

This reminds me of a Reader monad and its local method a lot. Specialisation of this monad to only work in TLS context sounds really obscure to me. Could this be generalised?

Diggsey commented 9 years ago

The stabilization of scoped TLS precludes the safe implementation of couroutines/fibers/green threads in external libraries.

Admittedly there are also problems with normal TLS, but they seem less terminal, and can probably be limited to causing unexpected behaviour or panics rather than outright memory unsafety with some changes.

Possible solutions:

All of the options have significant downsides, either due to complexity or runtime performance.

alexcrichton commented 8 years ago

:bell: This issue is now entering its cycle final comment period to be deprecation in 1.8 :bell:

Scoped TLS can currently be built externally on crates.io if truly necessary, and otherwise it seems to be getting far less usage than originally anticipated.

nikomatsakis commented 8 years ago

Even though I was an initial advocate for (and proposer of) scoped TLS, I think it's good to deprecate it. One major limitation that I didn't fully appreciate at the time is that the T of the variable must meet T: 'static, which tends to rule out a lot of the uses I've had in mind. At least without some unsafety. e.g., in the compiler we do some tricks to put a &ty::ctxt<'tcx> in there.

alexcrichton commented 8 years ago

The libs team discussed this during triage yesterday and the conclusion was to deprecate