Skip to content

Commit 3f19c9e

Browse files
author
The Miri Cronjob Bot
committed
Merge ref '269d5b56bcfd' from rust-lang/rust
Pull recent changes from https://github.com/rust-lang/rust via Josh. Upstream ref: 269d5b5 Filtered ref: a221b1d3ebb78ec8a01dcb1fe6bb165378e2f5c9 This merge was created using https://github.com/rust-lang/josh-sync.
2 parents dffa096 + 78b966c commit 3f19c9e

File tree

44 files changed

+187
-416
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+187
-416
lines changed

alloc/src/boxed.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,11 +2128,6 @@ impl<F: ?Sized + Future + Unpin, A: Allocator> Future for Box<F, A> {
21282128

21292129
#[stable(feature = "box_error", since = "1.8.0")]
21302130
impl<E: Error> Error for Box<E> {
2131-
#[allow(deprecated, deprecated_in_future)]
2132-
fn description(&self) -> &str {
2133-
Error::description(&**self)
2134-
}
2135-
21362131
#[allow(deprecated)]
21372132
fn cause(&self) -> Option<&dyn Error> {
21382133
Error::cause(&**self)

alloc/src/boxed/convert.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -608,12 +608,7 @@ impl<'a> From<String> for Box<dyn Error + Send + Sync + 'a> {
608608
fn from(err: String) -> Box<dyn Error + Send + Sync + 'a> {
609609
struct StringError(String);
610610

611-
impl Error for StringError {
612-
#[allow(deprecated)]
613-
fn description(&self) -> &str {
614-
&self.0
615-
}
616-
}
611+
impl Error for StringError {}
617612

618613
impl fmt::Display for StringError {
619614
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

alloc/src/collections/btree/map.rs

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,30 +40,15 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT;
4040

4141
/// An ordered map based on a [B-Tree].
4242
///
43-
/// B-Trees represent a fundamental compromise between cache-efficiency and actually minimizing
44-
/// the amount of work performed in a search. In theory, a binary search tree (BST) is the optimal
45-
/// choice for a sorted map, as a perfectly balanced BST performs the theoretical minimum amount of
46-
/// comparisons necessary to find an element (log<sub>2</sub>n). However, in practice the way this
47-
/// is done is *very* inefficient for modern computer architectures. In particular, every element
48-
/// is stored in its own individually heap-allocated node. This means that every single insertion
49-
/// triggers a heap-allocation, and every single comparison should be a cache-miss. Since these
50-
/// are both notably expensive things to do in practice, we are forced to, at the very least,
51-
/// reconsider the BST strategy.
52-
///
53-
/// A B-Tree instead makes each node contain B-1 to 2B-1 elements in a contiguous array. By doing
54-
/// this, we reduce the number of allocations by a factor of B, and improve cache efficiency in
55-
/// searches. However, this does mean that searches will have to do *more* comparisons on average.
56-
/// The precise number of comparisons depends on the node search strategy used. For optimal cache
57-
/// efficiency, one could search the nodes linearly. For optimal comparisons, one could search
58-
/// the node using binary search. As a compromise, one could also perform a linear search
59-
/// that initially only checks every i<sup>th</sup> element for some choice of i.
43+
/// Given a key type with a [total order], an ordered map stores its entries in key order.
44+
/// That means that keys must be of a type that implements the [`Ord`] trait,
45+
/// such that two keys can always be compared to determine their [`Ordering`].
46+
/// Examples of keys with a total order are strings with lexicographical order,
47+
/// and numbers with their natural order.
6048
///
61-
/// Currently, our implementation simply performs naive linear search. This provides excellent
62-
/// performance on *small* nodes of elements which are cheap to compare. However in the future we
63-
/// would like to further explore choosing the optimal search strategy based on the choice of B,
64-
/// and possibly other factors. Using linear search, searching for a random element is expected
65-
/// to take B * log(n) comparisons, which is generally worse than a BST. In practice,
66-
/// however, performance is excellent.
49+
/// Iterators obtained from functions such as [`BTreeMap::iter`], [`BTreeMap::into_iter`], [`BTreeMap::values`], or
50+
/// [`BTreeMap::keys`] produce their items in key order, and take worst-case logarithmic and
51+
/// amortized constant time per item returned.
6752
///
6853
/// It is a logic error for a key to be modified in such a way that the key's ordering relative to
6954
/// any other key, as determined by the [`Ord`] trait, changes while it is in the map. This is
@@ -72,14 +57,6 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT;
7257
/// `BTreeMap` that observed the logic error and not result in undefined behavior. This could
7358
/// include panics, incorrect results, aborts, memory leaks, and non-termination.
7459
///
75-
/// Iterators obtained from functions such as [`BTreeMap::iter`], [`BTreeMap::into_iter`], [`BTreeMap::values`], or
76-
/// [`BTreeMap::keys`] produce their items in order by key, and take worst-case logarithmic and
77-
/// amortized constant time per item returned.
78-
///
79-
/// [B-Tree]: https://en.wikipedia.org/wiki/B-tree
80-
/// [`Cell`]: core::cell::Cell
81-
/// [`RefCell`]: core::cell::RefCell
82-
///
8360
/// # Examples
8461
///
8562
/// ```
@@ -169,6 +146,43 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT;
169146
/// // modify an entry before an insert with in-place mutation
170147
/// player_stats.entry("mana").and_modify(|mana| *mana += 200).or_insert(100);
171148
/// ```
149+
///
150+
/// # Background
151+
///
152+
/// A B-tree is (like) a [binary search tree], but adapted to the natural granularity that modern
153+
/// machines like to consume data at. This means that each node contains an entire array of elements,
154+
/// instead of just a single element.
155+
///
156+
/// B-Trees represent a fundamental compromise between cache-efficiency and actually minimizing
157+
/// the amount of work performed in a search. In theory, a binary search tree (BST) is the optimal
158+
/// choice for a sorted map, as a perfectly balanced BST performs the theoretical minimum number of
159+
/// comparisons necessary to find an element (log<sub>2</sub>n). However, in practice the way this
160+
/// is done is *very* inefficient for modern computer architectures. In particular, every element
161+
/// is stored in its own individually heap-allocated node. This means that every single insertion
162+
/// triggers a heap-allocation, and every comparison is a potential cache-miss due to the indirection.
163+
/// Since both heap-allocations and cache-misses are notably expensive in practice, we are forced to,
164+
/// at the very least, reconsider the BST strategy.
165+
///
166+
/// A B-Tree instead makes each node contain B-1 to 2B-1 elements in a contiguous array. By doing
167+
/// this, we reduce the number of allocations by a factor of B, and improve cache efficiency in
168+
/// searches. However, this does mean that searches will have to do *more* comparisons on average.
169+
/// The precise number of comparisons depends on the node search strategy used. For optimal cache
170+
/// efficiency, one could search the nodes linearly. For optimal comparisons, one could search
171+
/// the node using binary search. As a compromise, one could also perform a linear search
172+
/// that initially only checks every i<sup>th</sup> element for some choice of i.
173+
///
174+
/// Currently, our implementation simply performs naive linear search. This provides excellent
175+
/// performance on *small* nodes of elements which are cheap to compare. However in the future we
176+
/// would like to further explore choosing the optimal search strategy based on the choice of B,
177+
/// and possibly other factors. Using linear search, searching for a random element is expected
178+
/// to take B * log(n) comparisons, which is generally worse than a BST. In practice,
179+
/// however, performance is excellent.
180+
///
181+
/// [B-Tree]: https://en.wikipedia.org/wiki/B-tree
182+
/// [binary search tree]: https://en.wikipedia.org/wiki/Binary_search_tree
183+
/// [total order]: https://en.wikipedia.org/wiki/Total_order
184+
/// [`Cell`]: core::cell::Cell
185+
/// [`RefCell`]: core::cell::RefCell
172186
#[stable(feature = "rust1", since = "1.0.0")]
173187
#[cfg_attr(not(test), rustc_diagnostic_item = "BTreeMap")]
174188
#[rustc_insignificant_dtor]

alloc/src/collections/btree/map/entry.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,6 @@ impl<'a, K: Debug + Ord, V: Debug, A: Allocator + Clone> fmt::Display
136136
impl<'a, K: core::fmt::Debug + Ord, V: core::fmt::Debug> core::error::Error
137137
for crate::collections::btree_map::OccupiedError<'a, K, V>
138138
{
139-
#[allow(deprecated)]
140-
fn description(&self) -> &str {
141-
"key already exists"
142-
}
143139
}
144140

145141
impl<'a, K: Ord, V, A: Allocator + Clone> Entry<'a, K, V, A> {

alloc/src/ffi/c_str.rs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,17 +1061,10 @@ impl IntoStringError {
10611061
}
10621062
}
10631063

1064-
impl IntoStringError {
1065-
fn description(&self) -> &str {
1066-
"C string contained non-utf8 bytes"
1067-
}
1068-
}
1069-
10701064
#[stable(feature = "cstring_into", since = "1.7.0")]
10711065
impl fmt::Display for IntoStringError {
1072-
#[allow(deprecated, deprecated_in_future)]
10731066
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1074-
self.description().fmt(f)
1067+
"C string contained non-utf8 bytes".fmt(f)
10751068
}
10761069
}
10771070

@@ -1291,23 +1284,13 @@ impl PartialEq<CString> for Cow<'_, CStr> {
12911284
}
12921285

12931286
#[stable(feature = "rust1", since = "1.0.0")]
1294-
impl core::error::Error for NulError {
1295-
#[allow(deprecated)]
1296-
fn description(&self) -> &str {
1297-
"nul byte found in data"
1298-
}
1299-
}
1287+
impl core::error::Error for NulError {}
13001288

13011289
#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")]
13021290
impl core::error::Error for FromVecWithNulError {}
13031291

13041292
#[stable(feature = "cstring_into", since = "1.7.0")]
13051293
impl core::error::Error for IntoStringError {
1306-
#[allow(deprecated)]
1307-
fn description(&self) -> &str {
1308-
"C string contained non-utf8 bytes"
1309-
}
1310-
13111294
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
13121295
Some(&self.error)
13131296
}

alloc/src/raw_vec/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl RawVecInner<Global> {
155155
}
156156

157157
// Tiny Vecs are dumb. Skip to:
158-
// - 8 if the element size is 1, because any heap allocators is likely
158+
// - 8 if the element size is 1, because any heap allocator is likely
159159
// to round up a request of less than 8 bytes to at least 8 bytes.
160160
// - 4 if elements are moderate-sized (<= 1 KiB).
161161
// - 1 otherwise, to avoid wasting too much space for very short Vecs.

alloc/src/string.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2285,20 +2285,10 @@ impl fmt::Display for FromUtf16Error {
22852285
}
22862286

22872287
#[stable(feature = "rust1", since = "1.0.0")]
2288-
impl Error for FromUtf8Error {
2289-
#[allow(deprecated)]
2290-
fn description(&self) -> &str {
2291-
"invalid utf-8"
2292-
}
2293-
}
2288+
impl Error for FromUtf8Error {}
22942289

22952290
#[stable(feature = "rust1", since = "1.0.0")]
2296-
impl Error for FromUtf16Error {
2297-
#[allow(deprecated)]
2298-
fn description(&self) -> &str {
2299-
"invalid utf-16"
2300-
}
2301-
}
2291+
impl Error for FromUtf16Error {}
23022292

23032293
#[cfg(not(no_global_oom_handling))]
23042294
#[stable(feature = "rust1", since = "1.0.0")]

alloc/src/sync.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4113,11 +4113,6 @@ impl<T: ?Sized, A: Allocator> Drop for UniqueArcUninit<T, A> {
41134113

41144114
#[stable(feature = "arc_error", since = "1.52.0")]
41154115
impl<T: core::error::Error + ?Sized> core::error::Error for Arc<T> {
4116-
#[allow(deprecated, deprecated_in_future)]
4117-
fn description(&self) -> &str {
4118-
core::error::Error::description(&**self)
4119-
}
4120-
41214116
#[allow(deprecated)]
41224117
fn cause(&self) -> Option<&dyn core::error::Error> {
41234118
core::error::Error::cause(&**self)

compiler-builtins/compiler-builtins/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ to be added as an explicit dependency in `Cargo.toml`.
1010

1111
[`compiler-rt`]: https://github.com/llvm/llvm-project/tree/1b1dc505057322f4fa1110ef4f53c44347f52986/compiler-rt
1212

13+
## Configuration
14+
15+
`compiler-builtins` can be configured with the following environment variables when the `c` feature
16+
is enabled:
17+
18+
- `LLVM_COMPILER_RT_LIB`
19+
- `RUST_COMPILER_RT_ROOT`
20+
21+
See `build.rs` for details.
22+
1323
## Contributing
1424

1525
See [CONTRIBUTING.md](CONTRIBUTING.md).

compiler-builtins/compiler-builtins/build.rs

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -540,20 +540,28 @@ mod c {
540540
sources.extend(&[("__emutls_get_address", "emutls.c")]);
541541
}
542542

543+
// Optionally, link against a prebuilt llvm compiler-rt containing the builtins
544+
// library. Only the builtins library is required. On many platforms, this is
545+
// available as a library named libclang_rt.builtins.a.
546+
let link_against_prebuilt_rt = env::var_os("LLVM_COMPILER_RT_LIB").is_some();
547+
543548
// When compiling the C code we require the user to tell us where the
544549
// source code is, and this is largely done so when we're compiling as
545550
// part of rust-lang/rust we can use the same llvm-project repository as
546551
// rust-lang/rust.
547552
let root = match env::var_os("RUST_COMPILER_RT_ROOT") {
548553
Some(s) => PathBuf::from(s),
554+
// If a prebuild libcompiler-rt is provided, set a valid
555+
// path to simplify later logic. Nothing should be compiled.
556+
None if link_against_prebuilt_rt => PathBuf::new(),
549557
None => {
550558
panic!(
551559
"RUST_COMPILER_RT_ROOT is not set. You may need to run \
552560
`ci/download-compiler-rt.sh`."
553561
);
554562
}
555563
};
556-
if !root.exists() {
564+
if !link_against_prebuilt_rt && !root.exists() {
557565
panic!("RUST_COMPILER_RT_ROOT={} does not exist", root.display());
558566
}
559567

@@ -569,7 +577,7 @@ mod c {
569577
let src_dir = root.join("lib/builtins");
570578
if target.arch == "aarch64" && target.env != "msvc" && target.os != "uefi" {
571579
// See below for why we're building these as separate libraries.
572-
build_aarch64_out_of_line_atomics_libraries(&src_dir, cfg);
580+
build_aarch64_out_of_line_atomics_libraries(&src_dir, cfg, link_against_prebuilt_rt);
573581

574582
// Some run-time CPU feature detection is necessary, as well.
575583
let cpu_model_src = if src_dir.join("cpu_model.c").exists() {
@@ -583,20 +591,45 @@ mod c {
583591
let mut added_sources = HashSet::new();
584592
for (sym, src) in sources.map.iter() {
585593
let src = src_dir.join(src);
586-
if added_sources.insert(src.clone()) {
594+
if !link_against_prebuilt_rt && added_sources.insert(src.clone()) {
587595
cfg.file(&src);
588596
println!("cargo:rerun-if-changed={}", src.display());
589597
}
590598
println!("cargo:rustc-cfg={}=\"optimized-c\"", sym);
591599
}
592600

593-
cfg.compile("libcompiler-rt.a");
601+
if link_against_prebuilt_rt {
602+
let rt_builtins_ext = PathBuf::from(env::var_os("LLVM_COMPILER_RT_LIB").unwrap());
603+
if !rt_builtins_ext.exists() {
604+
panic!(
605+
"LLVM_COMPILER_RT_LIB={} does not exist",
606+
rt_builtins_ext.display()
607+
);
608+
}
609+
if let Some(dir) = rt_builtins_ext.parent() {
610+
println!("cargo::rustc-link-search=native={}", dir.display());
611+
}
612+
if let Some(lib) = rt_builtins_ext.file_name() {
613+
println!(
614+
"cargo::rustc-link-lib=static:+verbatim={}",
615+
lib.to_str().unwrap()
616+
);
617+
}
618+
} else {
619+
cfg.compile("libcompiler-rt.a");
620+
}
594621
}
595622

596-
fn build_aarch64_out_of_line_atomics_libraries(builtins_dir: &Path, cfg: &mut cc::Build) {
623+
fn build_aarch64_out_of_line_atomics_libraries(
624+
builtins_dir: &Path,
625+
cfg: &mut cc::Build,
626+
link_against_prebuilt_rt: bool,
627+
) {
597628
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
598629
let outlined_atomics_file = builtins_dir.join("aarch64").join("lse.S");
599-
println!("cargo:rerun-if-changed={}", outlined_atomics_file.display());
630+
if !link_against_prebuilt_rt {
631+
println!("cargo:rerun-if-changed={}", outlined_atomics_file.display());
632+
}
600633

601634
cfg.include(&builtins_dir);
602635

@@ -609,6 +642,13 @@ mod c {
609642
for (model_number, model_name) in
610643
&[(1, "relax"), (2, "acq"), (3, "rel"), (4, "acq_rel")]
611644
{
645+
let sym = format!("__aarch64_{}{}_{}", instruction_type, size, model_name);
646+
println!("cargo:rustc-cfg={}=\"optimized-c\"", sym);
647+
648+
if link_against_prebuilt_rt {
649+
continue;
650+
}
651+
612652
// The original compiler-rt build system compiles the same
613653
// source file multiple times with different compiler
614654
// options. Here we do something slightly different: we
@@ -632,9 +672,6 @@ mod c {
632672
.unwrap();
633673
drop(file);
634674
cfg.file(path);
635-
636-
let sym = format!("__aarch64_{}{}_{}", instruction_type, size, model_name);
637-
println!("cargo:rustc-cfg={}=\"optimized-c\"", sym);
638675
}
639676
}
640677
}

0 commit comments

Comments
 (0)