Skip to content

Commit 945372d

Browse files
committed
Auto merge of #55012 - kennytm:rollup, r=kennytm
Rollup of 16 pull requests Successful merges: - #54755 (Documents reference equality by address (#54197)) - #54811 (During rustc bootstrap, make default for `optimize` independent of `debug`) - #54825 (NLL says "borrowed content" instead of more precise "dereference of raw pointer") - #54860 (Add doc comments about safest way to initialize a vector of zeros) - #54869 (Fix mobile docs) - #54891 (Fix tracking issue for Once::is_completed) - #54913 (doc fix: it's auto traits that make for automatic implementations) - #54920 (Fix handling of #[must_use] on unit and uninhabited types) - #54932 (A handful of random string-related improvements) - #54936 (impl Eq+Hash for TyLayout) - #54950 (std: Synchronize global allocator on wasm32) - #54956 ("(using ..." doesn't have the matching ")") - #54958 (add a macro for static (compile-time) assertions) - #54967 (Remove incorrect span for second label inner macro invocation) - #54983 (Fix slice's benchmarks) - #54989 (Fix spelling in the documentation to htmldocck.py) Failed merges: r? @ghost
2 parents e9e27e6 + d64c77a commit 945372d

File tree

31 files changed

+293
-129
lines changed

31 files changed

+293
-129
lines changed

config.toml.example

+26-9
Original file line numberDiff line numberDiff line change
@@ -243,19 +243,36 @@
243243
# =============================================================================
244244
[rust]
245245

246-
# Indicates that the build should be optimized for debugging Rust. Note that
247-
# this is typically not what you want as it takes an incredibly large amount of
248-
# time to have a debug-mode rustc compile any code (notably libstd). If this
249-
# value is set to `true` it will affect a number of configuration options below
250-
# as well, if unconfigured.
251-
#debug = false
252-
253-
# Whether or not to optimize the compiler and standard library
246+
# Whether or not to optimize the compiler and standard library.
247+
#
254248
# Note: the slowness of the non optimized compiler compiling itself usually
255249
# outweighs the time gains in not doing optimizations, therefore a
256-
# full bootstrap takes much more time with optimize set to false.
250+
# full bootstrap takes much more time with `optimize` set to false.
257251
#optimize = true
258252

253+
# Indicates that the build should be configured for debugging Rust. A
254+
# `debug`-enabled compiler and standard library will be somewhat
255+
# slower (due to e.g. checking of debug assertions) but should remain
256+
# usable.
257+
#
258+
# Note: If this value is set to `true`, it will affect a number of
259+
# configuration options below as well, if they have been left
260+
# unconfigured in this file.
261+
#
262+
# Note: changes to the `debug` setting do *not* affect `optimize`
263+
# above. In theory, a "maximally debuggable" environment would
264+
# set `optimize` to `false` above to assist the introspection
265+
# facilities of debuggers like lldb and gdb. To recreate such an
266+
# environment, explicitly set `optimize` to `false` and `debug`
267+
# to `true`. In practice, everyone leaves `optimize` set to
268+
# `true`, because an unoptimized rustc with debugging
269+
# enabled becomes *unusably slow* (e.g. rust-lang/rust#24840
270+
# reported a 25x slowdown) and bootstrapping the supposed
271+
# "maximally debuggable" environment (notably libstd) takes
272+
# hours to build.
273+
#
274+
#debug = false
275+
259276
# Number of codegen units to use for each compiler invocation. A value of 0
260277
# means "the number of cores on this machine", and 1+ is passed through to the
261278
# compiler.

src/Cargo.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
12691269

12701270
[[package]]
12711271
name = "minifier"
1272-
version = "0.0.19"
1272+
version = "0.0.20"
12731273
source = "registry+https://github.com/rust-lang/crates.io-index"
12741274
dependencies = [
12751275
"macro-utils 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2484,7 +2484,7 @@ dependencies = [
24842484
name = "rustdoc"
24852485
version = "0.0.0"
24862486
dependencies = [
2487-
"minifier 0.0.19 (registry+https://github.com/rust-lang/crates.io-index)",
2487+
"minifier 0.0.20 (registry+https://github.com/rust-lang/crates.io-index)",
24882488
"parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
24892489
"pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
24902490
"tempfile 3.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3289,7 +3289,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
32893289
"checksum memchr 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a3b4142ab8738a78c51896f704f83c11df047ff1bda9a92a661aa6361552d93d"
32903290
"checksum memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2ffa2c986de11a9df78620c01eeaaf27d94d3ff02bf81bfcca953102dd0c6ff"
32913291
"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3"
3292-
"checksum minifier 0.0.19 (registry+https://github.com/rust-lang/crates.io-index)" = "9908ed7c62f990c21ab41fdca53a864a3ada0da69d8729c4de727b397e27bc11"
3292+
"checksum minifier 0.0.20 (registry+https://github.com/rust-lang/crates.io-index)" = "96c269bb45c39b333392b2b18ad71760b34ac65666591386b0e959ed58b3f474"
32933293
"checksum miniz-sys 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "609ce024854aeb19a0ef7567d348aaa5a746b32fb72e336df7fcc16869d7e2b4"
32943294
"checksum miow 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "396aa0f2003d7df8395cb93e09871561ccc3e785f0acb369170e8cc74ddf9226"
32953295
"checksum new_debug_unreachable 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0cdc457076c78ab54d5e0d6fa7c47981757f1e34dc39ff92787f217dede586c4"

src/bootstrap/config.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,9 @@ impl Config {
628628
let default = false;
629629
config.llvm_assertions = llvm_assertions.unwrap_or(default);
630630

631+
let default = true;
632+
config.rust_optimize = optimize.unwrap_or(default);
633+
631634
let default = match &config.channel[..] {
632635
"stable" | "beta" | "nightly" => true,
633636
_ => false,
@@ -640,7 +643,6 @@ impl Config {
640643
config.debug_jemalloc = debug_jemalloc.unwrap_or(default);
641644
config.rust_debuginfo = debuginfo.unwrap_or(default);
642645
config.rust_debug_assertions = debug_assertions.unwrap_or(default);
643-
config.rust_optimize = optimize.unwrap_or(!default);
644646

645647
let default = config.channel == "dev";
646648
config.ignore_git = ignore_git.unwrap_or(default);

src/build_helper/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ pub fn try_run_suppressed(cmd: &mut Command) -> bool {
9191
output.status.success()
9292
}
9393

94-
pub fn gnu_target(target: &str) -> String {
94+
pub fn gnu_target(target: &str) -> &str {
9595
match target {
96-
"i686-pc-windows-msvc" => "i686-pc-win32".to_string(),
97-
"x86_64-pc-windows-msvc" => "x86_64-pc-win32".to_string(),
98-
"i686-pc-windows-gnu" => "i686-w64-mingw32".to_string(),
99-
"x86_64-pc-windows-gnu" => "x86_64-w64-mingw32".to_string(),
100-
s => s.to_string(),
96+
"i686-pc-windows-msvc" => "i686-pc-win32",
97+
"x86_64-pc-windows-msvc" => "x86_64-pc-win32",
98+
"i686-pc-windows-gnu" => "i686-w64-mingw32",
99+
"x86_64-pc-windows-gnu" => "x86_64-w64-mingw32",
100+
s => s,
101101
}
102102
}
103103

src/etc/htmldocck.py

+27-25
Original file line numberDiff line numberDiff line change
@@ -15,65 +15,66 @@
1515
1616
The principle is simple: This script receives a path to generated HTML
1717
documentation and a "template" script, which has a series of check
18-
commands like `@has` or `@matches`. Each command can be used to check if
18+
commands like `@has` or `@matches`. Each command is used to check if
1919
some pattern is present or not present in the particular file or in
20-
the particular node of HTML tree. In many cases, the template script
21-
happens to be a source code given to rustdoc.
20+
a particular node of the HTML tree. In many cases, the template script
21+
happens to be the source code given to rustdoc.
2222
2323
While it indeed is possible to test in smaller portions, it has been
2424
hard to construct tests in this fashion and major rendering errors were
25-
discovered much later. This script is designed for making the black-box
26-
and regression testing of Rustdoc easy. This does not preclude the needs
27-
for unit testing, but can be used to complement related tests by quickly
25+
discovered much later. This script is designed to make black-box and
26+
regression testing of Rustdoc easy. This does not preclude the needs for
27+
unit testing, but can be used to complement related tests by quickly
2828
showing the expected renderings.
2929
3030
In order to avoid one-off dependencies for this task, this script uses
3131
a reasonably working HTML parser and the existing XPath implementation
32-
from Python's standard library. Hopefully we won't render
32+
from Python's standard library. Hopefully, we won't render
3333
non-well-formed HTML.
3434
3535
# Commands
3636
3737
Commands start with an `@` followed by a command name (letters and
3838
hyphens), and zero or more arguments separated by one or more whitespace
39-
and optionally delimited with single or double quotes. The `@` mark
40-
cannot be preceded by a non-whitespace character. Other lines (including
41-
every text up to the first `@`) are ignored, but it is recommended to
42-
avoid the use of `@` in the template file.
39+
characters and optionally delimited with single or double quotes. The `@`
40+
mark cannot be preceded by a non-whitespace character. Other lines
41+
(including every text up to the first `@`) are ignored, but it is
42+
recommended to avoid the use of `@` in the template file.
4343
4444
There are a number of supported commands:
4545
46-
* `@has PATH` checks for the existence of given file.
46+
* `@has PATH` checks for the existence of the given file.
4747
4848
`PATH` is relative to the output directory. It can be given as `-`
4949
which repeats the most recently used `PATH`.
5050
5151
* `@has PATH PATTERN` and `@matches PATH PATTERN` checks for
52-
the occurrence of given `PATTERN` in the given file. Only one
53-
occurrence of given pattern is enough.
52+
the occurrence of the given pattern `PATTERN` in the specified file.
53+
Only one occurrence of the pattern is enough.
5454
5555
For `@has`, `PATTERN` is a whitespace-normalized (every consecutive
5656
whitespace being replaced by one single space character) string.
5757
The entire file is also whitespace-normalized including newlines.
5858
5959
For `@matches`, `PATTERN` is a Python-supported regular expression.
60-
The file remains intact but the regexp is matched with no `MULTILINE`
61-
and `IGNORECASE` option. You can still use a prefix `(?m)` or `(?i)`
60+
The file remains intact but the regexp is matched without the `MULTILINE`
61+
and `IGNORECASE` options. You can still use a prefix `(?m)` or `(?i)`
6262
to override them, and `\A` and `\Z` for definitely matching
6363
the beginning and end of the file.
6464
6565
(The same distinction goes to other variants of these commands.)
6666
6767
* `@has PATH XPATH PATTERN` and `@matches PATH XPATH PATTERN` checks for
68-
the presence of given `XPATH` in the given HTML file, and also
69-
the occurrence of given `PATTERN` in the matching node or attribute.
70-
Only one occurrence of given pattern in the match is enough.
68+
the presence of the given XPath `XPATH` in the specified HTML file,
69+
and also the occurrence of the given pattern `PATTERN` in the matching
70+
node or attribute. Only one occurrence of the pattern in the match
71+
is enough.
7172
7273
`PATH` should be a valid and well-formed HTML file. It does *not*
7374
accept arbitrary HTML5; it should have matching open and close tags
7475
and correct entity references at least.
7576
76-
`XPATH` is an XPath expression to match. This is fairly limited:
77+
`XPATH` is an XPath expression to match. The XPath is fairly limited:
7778
`tag`, `*`, `.`, `//`, `..`, `[@attr]`, `[@attr='value']`, `[tag]`,
7879
`[POS]` (element located in given `POS`), `[last()-POS]`, `text()`
7980
and `@attr` (both as the last segment) are supported. Some examples:
@@ -85,19 +86,20 @@
8586
- `//h1[@class="fqn"]/span[1]/a[last()]/@class` matches a value of
8687
`class` attribute in the last `a` element (can be followed by more
8788
elements that are not `a`) inside the first `span` in the `h1` with
88-
a class of `fqn`. Note that there cannot be no additional elements
89+
a class of `fqn`. Note that there cannot be any additional elements
8990
between them due to the use of `/` instead of `//`.
9091
9192
Do not try to use non-absolute paths, it won't work due to the flawed
9293
ElementTree implementation. The script rejects them.
9394
9495
For the text matches (i.e. paths not ending with `@attr`), any
9596
subelements are flattened into one string; this is handy for ignoring
96-
highlights for example. If you want to simply check the presence of
97-
given node or attribute, use an empty string (`""`) as a `PATTERN`.
97+
highlights for example. If you want to simply check for the presence of
98+
a given node or attribute, use an empty string (`""`) as a `PATTERN`.
9899
99-
* `@count PATH XPATH COUNT' checks for the occurrence of given XPath
100-
in the given file. The number of occurrences must match the given count.
100+
* `@count PATH XPATH COUNT' checks for the occurrence of the given XPath
101+
in the specified file. The number of occurrences must match the given
102+
count.
101103
102104
* `@has-dir PATH` checks for the existence of the given directory.
103105

src/liballoc/benches/slice.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::mem;
1313
use std::ptr;
1414

1515
use rand::{Rng, SeedableRng, XorShiftRng};
16+
use rand::distributions::{Standard, Alphanumeric};
1617
use test::{Bencher, black_box};
1718

1819
#[bench]
@@ -192,18 +193,20 @@ fn gen_descending(len: usize) -> Vec<u64> {
192193
(0..len as u64).rev().collect()
193194
}
194195

196+
const SEED: [u8; 16] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
197+
195198
fn gen_random(len: usize) -> Vec<u64> {
196-
let mut rng = XorShiftRng::from_seed([0, 1, 2, 3]);
197-
rng.gen_iter::<u64>().take(len).collect()
199+
let mut rng = XorShiftRng::from_seed(SEED);
200+
rng.sample_iter(&Standard).take(len).collect()
198201
}
199202

200203
fn gen_random_bytes(len: usize) -> Vec<u8> {
201-
let mut rng = XorShiftRng::from_seed([0, 1, 2, 3]);
202-
rng.gen_iter::<u8>().take(len).collect()
204+
let mut rng = XorShiftRng::from_seed(SEED);
205+
rng.sample_iter(&Standard).take(len).collect()
203206
}
204207

205208
fn gen_mostly_ascending(len: usize) -> Vec<u64> {
206-
let mut rng = XorShiftRng::from_seed([0, 1, 2, 3]);
209+
let mut rng = XorShiftRng::from_seed(SEED);
207210
let mut v = gen_ascending(len);
208211
for _ in (0usize..).take_while(|x| x * x <= len) {
209212
let x = rng.gen::<usize>() % len;
@@ -214,7 +217,7 @@ fn gen_mostly_ascending(len: usize) -> Vec<u64> {
214217
}
215218

216219
fn gen_mostly_descending(len: usize) -> Vec<u64> {
217-
let mut rng = XorShiftRng::from_seed([0, 1, 2, 3]);
220+
let mut rng = XorShiftRng::from_seed(SEED);
218221
let mut v = gen_descending(len);
219222
for _ in (0usize..).take_while(|x| x * x <= len) {
220223
let x = rng.gen::<usize>() % len;
@@ -225,18 +228,18 @@ fn gen_mostly_descending(len: usize) -> Vec<u64> {
225228
}
226229

227230
fn gen_strings(len: usize) -> Vec<String> {
228-
let mut rng = XorShiftRng::from_seed([0, 1, 2, 3]);
231+
let mut rng = XorShiftRng::from_seed(SEED);
229232
let mut v = vec![];
230233
for _ in 0..len {
231234
let n = rng.gen::<usize>() % 20 + 1;
232-
v.push(rng.gen_ascii_chars().take(n).collect());
235+
v.push(rng.sample_iter(&Alphanumeric).take(n).collect());
233236
}
234237
v
235238
}
236239

237240
fn gen_big_random(len: usize) -> Vec<[u64; 16]> {
238-
let mut rng = XorShiftRng::from_seed([0, 1, 2, 3]);
239-
rng.gen_iter().map(|x| [x; 16]).take(len).collect()
241+
let mut rng = XorShiftRng::from_seed(SEED);
242+
rng.sample_iter(&Standard).map(|x| [x; 16]).take(len).collect()
240243
}
241244

242245
macro_rules! sort {

src/liballoc/vec.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,17 @@ use raw_vec::RawVec;
120120
/// assert_eq!(vec, [1, 2, 3, 4]);
121121
/// ```
122122
///
123-
/// It can also initialize each element of a `Vec<T>` with a given value:
123+
/// It can also initialize each element of a `Vec<T>` with a given value.
124+
/// This may be more efficient than performing allocation and initialization
125+
/// in separate steps, especially when initializing a vector of zeros:
124126
///
125127
/// ```
126128
/// let vec = vec![0; 5];
127129
/// assert_eq!(vec, [0, 0, 0, 0, 0]);
130+
///
131+
/// // The following is equivalent, but potentially slower:
132+
/// let mut vec1 = Vec::with_capacity(5);
133+
/// vec1.resize(5, 0);
128134
/// ```
129135
///
130136
/// Use a `Vec<T>` as an efficient stack:

src/liballoc_system/lib.rs

+52-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
#![feature(nll)]
2121
#![feature(staged_api)]
2222
#![feature(rustc_attrs)]
23+
#![cfg_attr(
24+
all(target_arch = "wasm32", not(target_os = "emscripten")),
25+
feature(integer_atomics, stdsimd)
26+
)]
2327
#![cfg_attr(any(unix, target_os = "cloudabi", target_os = "redox"), feature(libc))]
2428
#![rustc_alloc_kind = "lib"]
2529

@@ -331,29 +335,76 @@ mod platform {
331335
use core::alloc::{GlobalAlloc, Layout};
332336
use System;
333337

334-
// No need for synchronization here as wasm is currently single-threaded
335338
static mut DLMALLOC: dlmalloc::Dlmalloc = dlmalloc::DLMALLOC_INIT;
336339

337340
#[stable(feature = "alloc_system_type", since = "1.28.0")]
338341
unsafe impl GlobalAlloc for System {
339342
#[inline]
340343
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
344+
let _lock = lock::lock();
341345
DLMALLOC.malloc(layout.size(), layout.align())
342346
}
343347

344348
#[inline]
345349
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
350+
let _lock = lock::lock();
346351
DLMALLOC.calloc(layout.size(), layout.align())
347352
}
348353

349354
#[inline]
350355
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
356+
let _lock = lock::lock();
351357
DLMALLOC.free(ptr, layout.size(), layout.align())
352358
}
353359

354360
#[inline]
355361
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
362+
let _lock = lock::lock();
356363
DLMALLOC.realloc(ptr, layout.size(), layout.align(), new_size)
357364
}
358365
}
366+
367+
#[cfg(target_feature = "atomics")]
368+
mod lock {
369+
use core::arch::wasm32;
370+
use core::sync::atomic::{AtomicI32, Ordering::SeqCst};
371+
372+
static LOCKED: AtomicI32 = AtomicI32::new(0);
373+
374+
pub struct DropLock;
375+
376+
pub fn lock() -> DropLock {
377+
loop {
378+
if LOCKED.swap(1, SeqCst) == 0 {
379+
return DropLock
380+
}
381+
unsafe {
382+
let r = wasm32::atomic::wait_i32(
383+
&LOCKED as *const AtomicI32 as *mut i32,
384+
1, // expected value
385+
-1, // timeout
386+
);
387+
debug_assert!(r == 0 || r == 1);
388+
}
389+
}
390+
}
391+
392+
impl Drop for DropLock {
393+
fn drop(&mut self) {
394+
let r = LOCKED.swap(0, SeqCst);
395+
debug_assert_eq!(r, 1);
396+
unsafe {
397+
wasm32::atomic::wake(
398+
&LOCKED as *const AtomicI32 as *mut i32,
399+
1, // only one thread
400+
);
401+
}
402+
}
403+
}
404+
}
405+
406+
#[cfg(not(target_feature = "atomics"))]
407+
mod lock {
408+
pub fn lock() {} // no atomics, no threads, that's easy!
409+
}
359410
}

0 commit comments

Comments
 (0)