rust/src
bors bcb05a0ab2 Auto merge of #55043 - oliver-giersch:unchecked_thread_spawning, r=alexcrichton
Unchecked thread spawning

# Summary

Add an unsafe interface for spawning lifetime-unrestricted threads for
library authors to build less-contrived, less-hacky safe abstractions
on.

# Motivation

So a few years back scoped threads were entirely removed from the Rust
stdlib, the reason being that it was possible to leak the scoped thread's
join guards without resorting to unsafe code, which meant the concept
was not completely safe, either.
Only a maximally-restrictive safe API for thread spawning was kept in the
stdlib, that requires `'static` lifetime bounds on both the thread closure
and its return type.
A number of 3rd party libraries sprung up to offer their implementations
for safe scoped threads implementations.
These work by essentially hiding the join guards from the user, thus
forcing them to join at the end of an (internal) function scope.

However, since these libraries have to use the maximally restrictive
thread spawning API, they have to resort to some very contrived manipulations
and subversions of Rust's type system to basically achieve what this commit does
with some minimal restructuring of the current code and exposing a new unsafe
function signature for spawning threads without lifetime restrictions.
Obviously this is unsafe, but its main use would be to allow library authors
to write safe abstractions with and around it.
To further illustrate my point, here's a quick summary of the hoops that,
for instance `crossbeam`, has to jump through to spawn a lifetime unrestricted
thread, all of which would not be necessary if an unsafe API existed as part
of the stdlib:

1. Allocate an `Arc<Option<T>>` on the heap where the result with type
`T: 'a` will go (in practice requires `Mutex` or `UnsafeCell` as well).

2. Wrap the desired thread closure with lifetime bound `'a` into another
closure (also `..: 'a`) that returns `()`, executes the inner closure and
writes its result into the pre-allocated `Option<T>`.

3. Box the wrapping closure, cast it to a trait object (`FnBox`) and
(unsafely) transmute its lifetime bound from `'a` to `'static`.

So while this new `spawn_unchecked` function is certainly not very relevant
for general use, since scoped threads are so common I think it makes sense
to expose an interface for libraries implementing these to build on.
The changes implemented are also very minimal: The current `spawn` function
(which internally contains unsafe code) is moved into an unsafe `spawn_unchecked`
function, which the safe function then wraps around.

# Issues

- ~~so far, no documentation for the new function (yet)~~
- the name of the function might be controversial, as `*_unchecked` more commonly
indicates that some sort of runtime check is omitted (`unrestricted` may be
more fitting)
- if accepted, it might make sense to add a freestanding `thread::spawn_unchecked`
function similar to the current `thread::spawn` for convenience.
2018-10-28 21:34:12 +00:00
..
bootstrap Rollup merge of #55391 - matthiaskrgr:bootstrap_cleanup, r=oli-obk 2018-10-26 23:10:38 +08:00
build_helper Prefer unwrap_or_else to unwrap_or in case of function calls/allocations 2018-10-19 09:45:45 +02:00
ci CI: Set codegen-units-std=1 for dist builds. 2018-10-26 15:07:03 +02:00
dlmalloc@c99638dc2e
doc Reflect by-value object safety in the unstable book. 2018-10-24 21:59:07 +09:00
etc fix typos in various places 2018-10-23 15:56:25 +02:00
grammar
jemalloc@1f5a28755e
liballoc Update string.rs 2018-10-27 14:33:07 +08:00
liballoc_jemalloc Bump to 1.31.0 and bootstrap from 1.30 beta 2018-09-27 20:52:53 -07:00
liballoc_system std: Synchronize global allocator on wasm32 2018-10-09 23:35:45 -07:00
libarena Update TypedArena tests 2018-10-19 14:34:44 +02:00
libbacktrace@f4d02bbdbf
libcompiler_builtins@0703bfa725 Revert "renamed emit_nil to emit_unit" 2018-09-11 22:20:22 +09:00
libcore Rollup merge of #55421 - CAD97:patch-1, r=kennytm 2018-10-28 21:32:03 +08:00
libfmt_macros remove padding from multiline format string label 2018-10-03 14:29:39 -04:00
libgraphviz Remove graphviz::IntoCow 2018-10-05 14:16:10 +02:00
liblibc@1844a772b6 Revert "renamed emit_nil to emit_unit" 2018-09-11 22:20:22 +09:00
libpanic_abort wasm: Explicitly export all symbols with LLD 2018-10-02 13:49:51 -07:00
libpanic_unwind Bump to 1.31.0 and bootstrap from 1.30 beta 2018-09-27 20:52:53 -07:00
libproc_macro All proc_macro_span APIs tracked at #54725 now 2018-10-01 12:15:35 -07:00
libprofiler_builtins Bump to 1.31.0 and bootstrap from 1.30 beta 2018-09-27 20:52:53 -07:00
librustc Auto merge of #54487 - RalfJung:ctfe-backtrace, r=oli-obk 2018-10-28 18:49:46 +00:00
librustc_allocator Bump to 1.31.0 and bootstrap from 1.30 beta 2018-09-27 20:52:53 -07:00
librustc_apfloat Bump to 1.31.0 and bootstrap from 1.30 beta 2018-09-27 20:52:53 -07:00
librustc_asan Rollup merge of #54681 - alexcrichton:san-names, r=kennytm 2018-10-01 16:13:04 +08:00
librustc_borrowck Auto merge of #55150 - pnkfelix:issues-47215-54797-fix-ice-from-moving-out-of-thread-local-under-ast-borrowck, r=nikomatsakis 2018-10-27 09:56:37 +00:00
librustc_codegen_llvm Auto merge of #54183 - qnighy:by-value-object-safety, r=oli-obk 2018-10-27 19:29:35 +00:00
librustc_codegen_utils Auto merge of #54183 - qnighy:by-value-object-safety, r=oli-obk 2018-10-27 19:29:35 +00:00
librustc_cratesio_shim Bump to 1.31.0 and bootstrap from 1.30 beta 2018-09-27 20:52:53 -07:00
librustc_data_structures Auto merge of #54778 - scottmcm:stabilize-ihle, r=pnkfelix 2018-10-23 04:05:50 +00:00
librustc_driver Add extern crate items to extern prelude 2018-10-24 00:14:50 +03:00
librustc_errors Auto merge of #55014 - ljedrz:lazyboye_unwraps, r=matthewjasper 2018-10-20 11:22:48 +00:00
librustc_fs_util
librustc_incremental Prefer Default::default over FxHash*::default in struct constructors 2018-10-19 14:34:44 +02:00
librustc_lint Auto merge of #54929 - csmoe:cfg_lint, r=petrochenkov 2018-10-26 21:46:13 +00:00
librustc_llvm Revert "rustc: Fix (again) simd vectors by-val in ABI" 2018-10-23 00:59:14 -07:00
librustc_lsan Bump to 1.31.0 and bootstrap from 1.30 beta 2018-09-27 20:52:53 -07:00
librustc_metadata Auto merge of #54626 - alexcrichton:dwarf-generics, r=michaelwoerister 2018-10-26 14:30:26 +00:00
librustc_metadata_utils
librustc_mir Auto merge of #54487 - RalfJung:ctfe-backtrace, r=oli-obk 2018-10-28 18:49:46 +00:00
librustc_msan Bump to 1.31.0 and bootstrap from 1.30 beta 2018-09-27 20:52:53 -07:00
librustc_passes Auto merge of #55150 - pnkfelix:issues-47215-54797-fix-ice-from-moving-out-of-thread-local-under-ast-borrowck, r=nikomatsakis 2018-10-27 09:56:37 +00:00
librustc_platform_intrinsics Bump to 1.31.0 and bootstrap from 1.30 beta 2018-09-27 20:52:53 -07:00
librustc_plugin Bump to 1.31.0 and bootstrap from 1.30 beta 2018-09-27 20:52:53 -07:00
librustc_privacy Deprecate the FxHashMap() and FxHashSet() constructor function hack 2018-10-19 14:34:44 +02:00
librustc_resolve Add note linking to Rust 2018 path semantics docs. 2018-10-28 09:16:10 +01:00
librustc_save_analysis Remove redundant clone 2018-10-26 12:07:39 +09:00
librustc_target Remove redundant clone 2018-10-26 12:07:39 +09:00
librustc_traits add user_ty.projs support to AscribeUserType. 2018-10-26 23:47:53 +02:00
librustc_tsan Rollup merge of #54681 - alexcrichton:san-names, r=kennytm 2018-10-01 16:13:04 +08:00
librustc_typeck Rollup merge of #55257 - mjbshaw:static, r=oli-obk 2018-10-28 21:38:12 +08:00
librustdoc Fix sub-variant doc display 2018-10-27 14:05:34 +02:00
libserialize Bump to 1.31.0 and bootstrap from 1.30 beta 2018-09-27 20:52:53 -07:00
libstd Auto merge of #55043 - oliver-giersch:unchecked_thread_spawning, r=alexcrichton 2018-10-28 21:34:12 +00:00
libsyntax Auto merge of #55192 - cramertj:nested-mod, r=petrochenkov 2018-10-28 13:13:55 +00:00
libsyntax_ext Auto merge of #54929 - csmoe:cfg_lint, r=petrochenkov 2018-10-26 21:46:13 +00:00
libsyntax_pos Add macro call span when lacking any other span in diagnostic 2018-10-23 10:07:11 -07:00
libterm Bump to 1.31.0 and bootstrap from 1.30 beta 2018-09-27 20:52:53 -07:00
libtest add option to libtest to run all tests 2018-10-14 00:58:17 +02:00
libunwind Bump to 1.31.0 and bootstrap from 1.30 beta 2018-09-27 20:52:53 -07:00
llvm@caddcd9b9d Update LLVM to fix "bool" arguments on PPC32 2018-09-16 04:33:58 +08:00
llvm-emscripten@2717444753
rtstartup
rustc
rustllvm Revert "rustc: Fix (again) simd vectors by-val in ABI" 2018-10-23 00:59:14 -07:00
stdsimd@431766a3fb Update stdsimd submodule 2018-10-23 09:51:02 -07:00
test Auto merge of #55433 - kennytm:rollup, r=kennytm 2018-10-28 16:00:00 +00:00
tools Rollup merge of #55269 - matthiaskrgr:typos_oct, r=zackmdavis 2018-10-25 14:31:13 +02:00
.gitignore
Cargo.lock submodules: update clippy from 5afdf8b7 to b1d03437 2018-10-21 17:56:00 +02:00
Cargo.toml Use rls-data 0.18.1 2018-09-28 01:54:01 +02:00
README.md
stage0.txt bump bootstrap compiler to rustc beta 2018-10-13 2018-10-14 00:52:47 +02:00

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

  • rustc and its tests
  • libstd
  • Various submodules for tools, like rustdoc, rls, etc.

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

Their is also useful content in the following READMEs, which are gradually being moved over to the guide: