rust/src
bors c9e5e6a53a Auto merge of #77154 - fusion-engineering-forks:lazy-stdio, r=dtolnay
Remove std::io::lazy::Lazy in favour of SyncOnceCell

The (internal) std::io::lazy::Lazy was used to lazily initialize the stdout and stdin buffers (and mutexes). It uses atexit() to register a destructor to flush the streams on exit, and mark the streams as 'closed'. Using the stream afterwards would result in a panic.

Stdout uses a LineWriter which contains a BufWriter that will flush the buffer on drop. This one is important to be executed during shutdown, to make sure no buffered output is lost. It also forbids access to stdout afterwards, since the buffer is already flushed and gone.

Stdin uses a BufReader, which does not implement Drop. It simply forgets any previously read data that was not read from the buffer yet. This means that in the case of stdin, the atexit() function's only effect is making stdin inaccessible to the program, such that later accesses result in a panic. This is uncessary, as it'd have been safe to access stdin during shutdown of the program.

---

This change removes the entire io::lazy module in favour of SyncOnceCell. SyncOnceCell's fast path is much faster (a single atomic operation) than locking a sys_common::Mutex on every access like Lazy did.

However, SyncOnceCell does not use atexit() to drop the contained object during shutdown.

As noted above, this is not a problem for stdin. It simply means stdin is now usable during shutdown.

The atexit() call for stdout is moved to the stdio module. Unlike the now-removed Lazy struct, SyncOnceCell does not have a 'gone and unusable' state that panics. Instead of adding this again, this simply replaces the buffer with one with zero capacity. This effectively flushes the old buffer *and* makes any writes afterwards pass through directly without touching a buffer, making print!() available during shutdown without panicking.

---

In addition, because the contents of the SyncOnceCell are no longer dropped, we can now use `&'static` instead of `Arc` in `Stdout` and `Stdin`. This also saves two levels of indirection in `stdin()` and `stdout()`, since Lazy effectively stored a `Box<Arc<T>>`, and SyncOnceCell stores the `T` directly.
2020-09-27 04:50:46 +00:00
..
bootstrap Rollup merge of #76631 - jyn514:x.py-setup, r=Mark-Simulacrum 2020-09-26 12:58:13 +02:00
build_helper cleanup: Remove duplicate library names from Cargo.tomls 2020-08-30 22:57:54 +03:00
ci Do not link LLVM tools to LLVM dylib unless rustc is 2020-09-19 18:21:08 -04:00
doc Auto merge of #74430 - Manishearth:stabilize-intra-doc, r=Manishearth 2020-09-24 03:42:53 +00:00
etc Implement HashSet in terms of hashbrown::HashSet 2020-09-08 17:24:23 -07:00
librustdoc Rename whence to span 2020-09-25 14:59:00 -07:00
llvm-project@7075196da1 Rebase LLVM onto 11.0.0-rc3 2020-09-22 10:16:03 -07:00
test Auto merge of #77154 - fusion-engineering-forks:lazy-stdio, r=dtolnay 2020-09-27 04:50:46 +00:00
tools Rollup merge of #77231 - oli-obk:clippy_const_fn, r=Manishearth 2020-09-27 01:53:27 +02:00
README.md Update README.md 2020-08-30 13:40:11 -05:00
stage0.txt bump version to 1.48 2020-08-26 10:16:59 +02:00
version bootstrap: move the version number to a plaintext file 2020-09-18 14:58:22 +02:00

This directory contains the source code of the rust project, including:

  • The test suite
  • The bootstrapping build system
  • Various submodules for tools, like rustdoc, rls, etc.

For more information on how various parts of the compiler work, see the rustc dev guide.