Skip to content

Commit 2837b99

Browse files
committed
Auto merge of #58413 - Centril:rollup, r=Centril
Rollup of 13 pull requests Successful merges: - #57693 (Doc rewording) - #57815 (Speed up the fast path for assert_eq! and assert_ne!) - #58034 (Stabilize the time_checked_add feature) - #58057 (Stabilize linker-plugin based LTO (aka cross-language LTO)) - #58137 (Cleanup: rename node_id_to_type(_opt)) - #58166 (allow shorthand syntax for deprecation reason) - #58196 (Add specific feature gate error for const-unstable features) - #58200 (fix str mutating through a ptr derived from &self) - #58273 (Rename rustc_errors dependency in rust 2018 crates) - #58289 (impl iter() for dyn Error) - #58387 (Disallow `auto` trait alias syntax) - #58404 (use Ubuntu keyserver for CloudABI ports) - #58405 (Remove some dead code from libcore) Failed merges: r? @ghost
2 parents 0f949c2 + 3883319 commit 2837b99

File tree

131 files changed

+931
-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.

131 files changed

+931
-416
lines changed

src/ci/docker/dist-various-2/build-cloudabi-toolchain.sh

+4-5
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ ln -s ../lib/llvm-5.0/bin/lld /usr/bin/${target}-ld
3232
ln -s ../../${target} /usr/lib/llvm-5.0/${target}
3333

3434
# Install the C++ runtime libraries from CloudABI Ports.
35-
echo deb https://nuxi.nl/distfiles/cloudabi-ports/debian/ cloudabi cloudabi > \
36-
/etc/apt/sources.list.d/cloudabi.list
37-
curl 'https://pgp.mit.edu/pks/lookup?op=get&search=0x0DA51B8531344B15' | \
38-
apt-key add -
35+
apt-key adv --batch --yes --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0DA51B8531344B15
36+
add-apt-repository -y 'deb https://nuxi.nl/distfiles/cloudabi-ports/debian/ cloudabi cloudabi'
37+
3938
apt-get update
40-
apt-get install -y $(echo ${target} | sed -e s/_/-/g)-cxx-runtime
39+
apt-get install -y "${target//_/-}-cxx-runtime"

src/doc/rustc/src/SUMMARY.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
- [Targets](targets/index.md)
1414
- [Built-in Targets](targets/built-in.md)
1515
- [Custom Targets](targets/custom.md)
16-
- [Contributing to `rustc`](contributing.md)
16+
- [Linker-plugin based LTO](linker-plugin-lto.md)
17+
- [Contributing to `rustc`](contributing.md)
+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Linker-plugin-LTO
2+
3+
The `-C linker-plugin-lto` flag allows for deferring the LTO optimization
4+
to the actual linking step, which in turn allows for performing
5+
interprocedural optimizations across programming language boundaries if
6+
all the object files being linked were created by LLVM based toolchains.
7+
The prime example here would be linking Rust code together with
8+
Clang-compiled C/C++ code.
9+
10+
## Usage
11+
12+
There are two main cases how linker plugin based LTO can be used:
13+
14+
- compiling a Rust `staticlib` that is used as a C ABI dependency
15+
- compiling a Rust binary where `rustc` invokes the linker
16+
17+
In both cases the Rust code has to be compiled with `-C linker-plugin-lto` and
18+
the C/C++ code with `-flto` or `-flto=thin` so that object files are emitted
19+
as LLVM bitcode.
20+
21+
### Rust `staticlib` as dependency in C/C++ program
22+
23+
In this case the Rust compiler just has to make sure that the object files in
24+
the `staticlib` are in the right format. For linking, a linker with the
25+
LLVM plugin must be used (e.g. LLD).
26+
27+
Using `rustc` directly:
28+
29+
```bash
30+
# Compile the Rust staticlib
31+
rustc --crate-type=staticlib -Clinker-plugin-lto -Copt-level=2 ./lib.rs
32+
# Compile the C code with `-flto=thin`
33+
clang -c -O2 -flto=thin -o main.o ./main.c
34+
# Link everything, making sure that we use an appropriate linker
35+
clang -flto=thin -fuse-ld=lld -L . -l"name-of-your-rust-lib" -o main -O2 ./cmain.o
36+
```
37+
38+
Using `cargo`:
39+
40+
```bash
41+
# Compile the Rust staticlib
42+
RUSTFLAGS="-Clinker-plugin-lto" cargo build --release
43+
# Compile the C code with `-flto=thin`
44+
clang -c -O2 -flto=thin -o main.o ./main.c
45+
# Link everything, making sure that we use an appropriate linker
46+
clang -flto=thin -fuse-ld=lld -L . -l"name-of-your-rust-lib" -o main -O2 ./cmain.o
47+
```
48+
49+
### C/C++ code as a dependency in Rust
50+
51+
In this case the linker will be invoked by `rustc`. We again have to make sure
52+
that an appropriate linker is used.
53+
54+
Using `rustc` directly:
55+
56+
```bash
57+
# Compile C code with `-flto`
58+
clang ./clib.c -flto=thin -c -o ./clib.o -O2
59+
# Create a static library from the C code
60+
ar crus ./libxyz.a ./clib.o
61+
62+
# Invoke `rustc` with the additional arguments
63+
rustc -Clinker-plugin-lto -L. -Copt-level=2 -Clinker=clang -Clink-arg=-fuse-ld=lld ./main.rs
64+
```
65+
66+
Using `cargo` directly:
67+
68+
```bash
69+
# Compile C code with `-flto`
70+
clang ./clib.c -flto=thin -c -o ./clib.o -O2
71+
# Create a static library from the C code
72+
ar crus ./libxyz.a ./clib.o
73+
74+
# Set the linking arguments via RUSTFLAGS
75+
RUSTFLAGS="-Clinker-plugin-lto -Clinker=clang -Clink-arg=-fuse-ld=lld" cargo build --release
76+
```
77+
78+
### Explicitly specifying the linker plugin to be used by `rustc`
79+
80+
If one wants to use a linker other than LLD, the LLVM linker plugin has to be
81+
specified explicitly. Otherwise the linker cannot read the object files. The
82+
path to the plugin is passed as an argument to the `-Clinker-plugin-lto`
83+
option:
84+
85+
```bash
86+
rustc -Clinker-plugin-lto="/path/to/LLVMgold.so" -L. -Copt-level=2 ./main.rs
87+
```
88+
89+
90+
## Toolchain Compatibility
91+
92+
In order for this kind of LTO to work, the LLVM linker plugin must be able to
93+
handle the LLVM bitcode produced by both `rustc` and `clang`.
94+
95+
Best results are achieved by using a `rustc` and `clang` that are based on the
96+
exact same version of LLVM. One can use `rustc -vV` in order to view the LLVM
97+
used by a given `rustc` version. Note that the version number given
98+
here is only an approximation as Rust sometimes uses unstable revisions of
99+
LLVM. However, the approximation is usually reliable.
100+
101+
The following table shows known good combinations of toolchain versions.
102+
103+
| | Clang 7 | Clang 8 |
104+
|-----------|-----------|-----------|
105+
| Rust 1.34 |||
106+
| Rust 1.35 || ✓(?) |
107+
108+
Note that the compatibility policy for this feature might change in the future.

src/libcore/lib.rs

-14
Original file line numberDiff line numberDiff line change
@@ -227,20 +227,6 @@ mod unit;
227227
// `core_arch` depends on libcore, but the contents of this module are
228228
// set up in such a way that directly pulling it here works such that the
229229
// crate uses the this crate as its libcore.
230-
#[allow(unused_macros)]
231-
macro_rules! test_v16 { ($item:item) => {}; }
232-
#[allow(unused_macros)]
233-
macro_rules! test_v32 { ($item:item) => {}; }
234-
#[allow(unused_macros)]
235-
macro_rules! test_v64 { ($item:item) => {}; }
236-
#[allow(unused_macros)]
237-
macro_rules! test_v128 { ($item:item) => {}; }
238-
#[allow(unused_macros)]
239-
macro_rules! test_v256 { ($item:item) => {}; }
240-
#[allow(unused_macros)]
241-
macro_rules! test_v512 { ($item:item) => {}; }
242-
#[allow(unused_macros)]
243-
macro_rules! vector_impl { ($([$f:ident, $($args:tt)*]),*) => { $($f!($($args)*);)* } }
244230
#[path = "../stdsimd/crates/core_arch/src/mod.rs"]
245231
#[allow(missing_docs, missing_debug_implementations, dead_code, unused_imports)]
246232
#[unstable(feature = "stdsimd", issue = "48556")]

src/libcore/macros.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ macro_rules! assert_eq {
4646
match (&$left, &$right) {
4747
(left_val, right_val) => {
4848
if !(*left_val == *right_val) {
49+
// The reborrows below are intentional. Without them, the stack slot for the
50+
// borrow is initialized even before the values are compared, leading to a
51+
// noticeable slow down.
4952
panic!(r#"assertion failed: `(left == right)`
5053
left: `{:?}`,
51-
right: `{:?}`"#, left_val, right_val)
54+
right: `{:?}`"#, &*left_val, &*right_val)
5255
}
5356
}
5457
}
@@ -60,9 +63,12 @@ macro_rules! assert_eq {
6063
match (&($left), &($right)) {
6164
(left_val, right_val) => {
6265
if !(*left_val == *right_val) {
66+
// The reborrows below are intentional. Without them, the stack slot for the
67+
// borrow is initialized even before the values are compared, leading to a
68+
// noticeable slow down.
6369
panic!(r#"assertion failed: `(left == right)`
6470
left: `{:?}`,
65-
right: `{:?}`: {}"#, left_val, right_val,
71+
right: `{:?}`: {}"#, &*left_val, &*right_val,
6672
format_args!($($arg)+))
6773
}
6874
}
@@ -97,9 +103,12 @@ macro_rules! assert_ne {
97103
match (&$left, &$right) {
98104
(left_val, right_val) => {
99105
if *left_val == *right_val {
106+
// The reborrows below are intentional. Without them, the stack slot for the
107+
// borrow is initialized even before the values are compared, leading to a
108+
// noticeable slow down.
100109
panic!(r#"assertion failed: `(left != right)`
101110
left: `{:?}`,
102-
right: `{:?}`"#, left_val, right_val)
111+
right: `{:?}`"#, &*left_val, &*right_val)
103112
}
104113
}
105114
}
@@ -111,9 +120,12 @@ macro_rules! assert_ne {
111120
match (&($left), &($right)) {
112121
(left_val, right_val) => {
113122
if *left_val == *right_val {
123+
// The reborrows below are intentional. Without them, the stack slot for the
124+
// borrow is initialized even before the values are compared, leading to a
125+
// noticeable slow down.
114126
panic!(r#"assertion failed: `(left != right)`
115127
left: `{:?}`,
116-
right: `{:?}`: {}"#, left_val, right_val,
128+
right: `{:?}`: {}"#, &*left_val, &*right_val,
117129
format_args!($($arg)+))
118130
}
119131
}

src/libcore/str/mod.rs

+23-7
Original file line numberDiff line numberDiff line change
@@ -1741,9 +1741,9 @@ mod traits {
17411741
}
17421742
#[inline]
17431743
unsafe fn get_unchecked_mut(self, slice: &mut str) -> &mut Self::Output {
1744-
let ptr = slice.as_ptr().add(self.start);
1744+
let ptr = slice.as_mut_ptr().add(self.start);
17451745
let len = self.end - self.start;
1746-
super::from_utf8_unchecked_mut(slice::from_raw_parts_mut(ptr as *mut u8, len))
1746+
super::from_utf8_unchecked_mut(slice::from_raw_parts_mut(ptr, len))
17471747
}
17481748
#[inline]
17491749
fn index(self, slice: &str) -> &Self::Output {
@@ -1805,8 +1805,8 @@ mod traits {
18051805
}
18061806
#[inline]
18071807
unsafe fn get_unchecked_mut(self, slice: &mut str) -> &mut Self::Output {
1808-
let ptr = slice.as_ptr();
1809-
super::from_utf8_unchecked_mut(slice::from_raw_parts_mut(ptr as *mut u8, self.end))
1808+
let ptr = slice.as_mut_ptr();
1809+
super::from_utf8_unchecked_mut(slice::from_raw_parts_mut(ptr, self.end))
18101810
}
18111811
#[inline]
18121812
fn index(self, slice: &str) -> &Self::Output {
@@ -1867,9 +1867,9 @@ mod traits {
18671867
}
18681868
#[inline]
18691869
unsafe fn get_unchecked_mut(self, slice: &mut str) -> &mut Self::Output {
1870-
let ptr = slice.as_ptr().add(self.start);
1870+
let ptr = slice.as_mut_ptr().add(self.start);
18711871
let len = slice.len() - self.start;
1872-
super::from_utf8_unchecked_mut(slice::from_raw_parts_mut(ptr as *mut u8, len))
1872+
super::from_utf8_unchecked_mut(slice::from_raw_parts_mut(ptr, len))
18731873
}
18741874
#[inline]
18751875
fn index(self, slice: &str) -> &Self::Output {
@@ -2197,6 +2197,22 @@ impl str {
21972197
self as *const str as *const u8
21982198
}
21992199

2200+
/// Converts a mutable string slice to a raw pointer.
2201+
///
2202+
/// As string slices are a slice of bytes, the raw pointer points to a
2203+
/// [`u8`]. This pointer will be pointing to the first byte of the string
2204+
/// slice.
2205+
///
2206+
/// It is your responsibility to make sure that the string slice only gets
2207+
/// modified in a way that it remains valid UTF-8.
2208+
///
2209+
/// [`u8`]: primitive.u8.html
2210+
#[unstable(feature = "str_as_mut_ptr", issue = "58215")]
2211+
#[inline]
2212+
pub fn as_mut_ptr(&mut self) -> *mut u8 {
2213+
self as *mut str as *mut u8
2214+
}
2215+
22002216
/// Returns a subslice of `str`.
22012217
///
22022218
/// This is the non-panicking alternative to indexing the `str`. Returns
@@ -2484,7 +2500,7 @@ impl str {
24842500
// is_char_boundary checks that the index is in [0, .len()]
24852501
if self.is_char_boundary(mid) {
24862502
let len = self.len();
2487-
let ptr = self.as_ptr() as *mut u8;
2503+
let ptr = self.as_mut_ptr();
24882504
unsafe {
24892505
(from_utf8_unchecked_mut(slice::from_raw_parts_mut(ptr, mid)),
24902506
from_utf8_unchecked_mut(slice::from_raw_parts_mut(

src/librustc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ rustc-rayon-core = "0.1.1"
2525
rustc_apfloat = { path = "../librustc_apfloat" }
2626
rustc_target = { path = "../librustc_target" }
2727
rustc_data_structures = { path = "../librustc_data_structures" }
28-
rustc_errors = { path = "../librustc_errors" }
28+
errors = { path = "../librustc_errors", package = "rustc_errors" }
2929
serialize = { path = "../libserialize" }
3030
syntax = { path = "../libsyntax" }
3131
syntax_pos = { path = "../libsyntax_pos" }

src/librustc/dep_graph/graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::errors::{Diagnostic, DiagnosticBuilder};
1+
use errors::{Diagnostic, DiagnosticBuilder};
22
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
33
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
44
use rustc_data_structures::indexed_vec::{Idx, IndexVec};

src/librustc/hir/lowering.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
//! in the HIR, especially for multiple identifiers.
3232
3333
use crate::dep_graph::DepGraph;
34-
use crate::errors::Applicability;
3534
use crate::hir::{self, ParamName};
3635
use crate::hir::HirVec;
3736
use crate::hir::map::{DefKey, DefPathData, Definitions};
@@ -41,14 +40,15 @@ use crate::hir::GenericArg;
4140
use crate::lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
4241
ELIDED_LIFETIMES_IN_PATHS};
4342
use crate::middle::cstore::CrateStore;
44-
use rustc_data_structures::fx::FxHashSet;
45-
use rustc_data_structures::indexed_vec::IndexVec;
46-
use rustc_data_structures::thin_vec::ThinVec;
47-
use rustc_data_structures::sync::Lrc;
4843
use crate::session::Session;
4944
use crate::session::config::nightly_options;
5045
use crate::util::common::FN_OUTPUT_NAME;
5146
use crate::util::nodemap::{DefIdMap, NodeMap};
47+
use errors::Applicability;
48+
use rustc_data_structures::fx::FxHashSet;
49+
use rustc_data_structures::indexed_vec::IndexVec;
50+
use rustc_data_structures::thin_vec::ThinVec;
51+
use rustc_data_structures::sync::Lrc;
5252

5353
use std::collections::{BTreeSet, BTreeMap};
5454
use std::fmt::Debug;

src/librustc/hir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ pub use self::PrimTy::*;
1010
pub use self::UnOp::*;
1111
pub use self::UnsafeSource::*;
1212

13-
use crate::errors::FatalError;
1413
use crate::hir::def::Def;
1514
use crate::hir::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX};
1615
use crate::util::nodemap::{NodeMap, FxHashSet};
1716
use crate::mir::mono::Linkage;
1817

18+
use errors::FatalError;
1919
use syntax_pos::{Span, DUMMY_SP, symbol::InternedString};
2020
use syntax::source_map::Spanned;
2121
use rustc_target::spec::abi::Abi;

src/librustc/infer/error_reporting/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,16 @@ use super::region_constraints::GenericKind;
5050
use super::{InferCtxt, RegionVariableOrigin, SubregionOrigin, TypeTrace, ValuePairs};
5151
use crate::infer::{self, SuppressRegionErrors};
5252

53-
use crate::errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
5453
use crate::hir;
5554
use crate::hir::def_id::DefId;
5655
use crate::hir::Node;
5756
use crate::middle::region;
58-
use std::{cmp, fmt};
59-
use syntax_pos::{Pos, Span};
6057
use crate::traits::{ObligationCause, ObligationCauseCode};
6158
use crate::ty::error::TypeError;
6259
use crate::ty::{self, subst::Subst, Region, Ty, TyCtxt, TyKind, TypeFoldable};
60+
use errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
61+
use std::{cmp, fmt};
62+
use syntax_pos::{Pos, Span};
6363

6464
mod note;
6565

src/librustc/infer/error_reporting/need_type_info.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::infer::type_variable::TypeVariableOrigin;
55
use crate::ty::{self, Ty, Infer, TyVar};
66
use syntax::source_map::CompilerDesugaringKind;
77
use syntax_pos::Span;
8-
use crate::errors::DiagnosticBuilder;
8+
use errors::DiagnosticBuilder;
99

1010
struct FindLocalByTypeVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
1111
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
@@ -16,9 +16,9 @@ struct FindLocalByTypeVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
1616
}
1717

1818
impl<'a, 'gcx, 'tcx> FindLocalByTypeVisitor<'a, 'gcx, 'tcx> {
19-
fn node_matches_type(&mut self, node_id: HirId) -> bool {
19+
fn node_matches_type(&mut self, hir_id: HirId) -> bool {
2020
let ty_opt = self.infcx.in_progress_tables.and_then(|tables| {
21-
tables.borrow().node_id_to_type_opt(node_id)
21+
tables.borrow().node_type_opt(hir_id)
2222
});
2323
match ty_opt {
2424
Some(ty) => {

src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
44
use crate::ty;
55
use crate::util::common::ErrorReported;
6-
use crate::errors::Applicability;
6+
use errors::Applicability;
77

88
impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
99
/// When given a `ConcreteFailure` for a function with arguments containing a named region and

src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::errors::DiagnosticBuilder;
1+
use errors::DiagnosticBuilder;
22
use crate::hir::def_id::DefId;
33
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
44
use crate::infer::lexical_region_resolve::RegionResolutionError;

src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::infer::error_reporting::nice_region_error::NiceRegionError;
44
use crate::infer::lexical_region_resolve::RegionResolutionError;
55
use crate::ty::{BoundRegion, FreeRegion, RegionKind};
66
use crate::util::common::ErrorReported;
7-
use crate::errors::Applicability;
7+
use errors::Applicability;
88

99
impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
1010
/// Print the error message for lifetime errors when the return type is a static impl Trait.

0 commit comments

Comments
 (0)