Skip to content

Commit a4fb414

Browse files
committed
Auto merge of rust-lang#2898 - RalfJung:rustup, r=RalfJung
Rustup
2 parents 2e17ac8 + 4014b17 commit a4fb414

File tree

187 files changed

+2152
-1232
lines changed

Some content is hidden

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

187 files changed

+2152
-1232
lines changed

RELEASES.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,7 @@ and related tools.
14811481
[is_power_of_two_usize]: https://doc.rust-lang.org/stable/core/num/struct.NonZeroUsize.html#method.is_power_of_two
14821482
[stdarch/1266]: https://github.com/rust-lang/stdarch/pull/1266
14831483

1484-
Version 1.58.1 (2022-01-19)
1484+
Version 1.58.1 (2022-01-20)
14851485
===========================
14861486

14871487
* Fix race condition in `std::fs::remove_dir_all` ([CVE-2022-21658])

compiler/rustc_builtin_macros/src/deriving/bounds.rs

+23
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,26 @@ pub fn expand_deriving_copy(
2727

2828
trait_def.expand(cx, mitem, item, push);
2929
}
30+
31+
pub fn expand_deriving_const_param_ty(
32+
cx: &mut ExtCtxt<'_>,
33+
span: Span,
34+
mitem: &MetaItem,
35+
item: &Annotatable,
36+
push: &mut dyn FnMut(Annotatable),
37+
is_const: bool,
38+
) {
39+
let trait_def = TraitDef {
40+
span,
41+
path: path_std!(marker::ConstParamTy),
42+
skip_path_as_bound: false,
43+
needs_copy_as_bound_if_packed: false,
44+
additional_bounds: Vec::new(),
45+
supports_unions: false,
46+
methods: Vec::new(),
47+
associated_types: Vec::new(),
48+
is_const,
49+
};
50+
51+
trait_def.expand(cx, mitem, item, push);
52+
}

compiler/rustc_builtin_macros/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
115115
register_derive! {
116116
Clone: clone::expand_deriving_clone,
117117
Copy: bounds::expand_deriving_copy,
118+
ConstParamTy: bounds::expand_deriving_const_param_ty,
118119
Debug: debug::expand_deriving_debug,
119120
Default: default::expand_deriving_default,
120121
Eq: eq::expand_deriving_eq,

compiler/rustc_codegen_cranelift/src/base.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -966,11 +966,7 @@ fn codegen_panic_inner<'tcx>(
966966
args: &[Value],
967967
span: Span,
968968
) {
969-
let def_id = fx
970-
.tcx
971-
.lang_items()
972-
.require(lang_item)
973-
.unwrap_or_else(|e| fx.tcx.sess.span_fatal(span, e.to_string()));
969+
let def_id = fx.tcx.require_lang_item(lang_item, Some(span));
974970

975971
let instance = Instance::mono(fx.tcx, def_id).polymorphize(fx.tcx);
976972
let symbol_name = fx.tcx.symbol_name(instance).name;

compiler/rustc_codegen_llvm/src/back/lto.rs

-49
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use std::fs::File;
2525
use std::io;
2626
use std::iter;
2727
use std::path::Path;
28-
use std::ptr;
2928
use std::slice;
3029
use std::sync::Arc;
3130

@@ -709,17 +708,6 @@ pub unsafe fn optimize_thin_module(
709708
let llmod = module.module_llvm.llmod();
710709
save_temp_bitcode(cgcx, &module, "thin-lto-input");
711710

712-
// Before we do much else find the "main" `DICompileUnit` that we'll be
713-
// using below. If we find more than one though then rustc has changed
714-
// in a way we're not ready for, so generate an ICE by returning
715-
// an error.
716-
let mut cu1 = ptr::null_mut();
717-
let mut cu2 = ptr::null_mut();
718-
llvm::LLVMRustThinLTOGetDICompileUnit(llmod, &mut cu1, &mut cu2);
719-
if !cu2.is_null() {
720-
return Err(write::llvm_err(&diag_handler, LlvmError::MultipleSourceDiCompileUnit));
721-
}
722-
723711
// Up next comes the per-module local analyses that we do for Thin LTO.
724712
// Each of these functions is basically copied from the LLVM
725713
// implementation and then tailored to suit this implementation. Ideally
@@ -766,43 +754,6 @@ pub unsafe fn optimize_thin_module(
766754
save_temp_bitcode(cgcx, &module, "thin-lto-after-import");
767755
}
768756

769-
// Ok now this is a bit unfortunate. This is also something you won't
770-
// find upstream in LLVM's ThinLTO passes! This is a hack for now to
771-
// work around bugs in LLVM.
772-
//
773-
// First discovered in #45511 it was found that as part of ThinLTO
774-
// importing passes LLVM will import `DICompileUnit` metadata
775-
// information across modules. This means that we'll be working with one
776-
// LLVM module that has multiple `DICompileUnit` instances in it (a
777-
// bunch of `llvm.dbg.cu` members). Unfortunately there's a number of
778-
// bugs in LLVM's backend which generates invalid DWARF in a situation
779-
// like this:
780-
//
781-
// https://bugs.llvm.org/show_bug.cgi?id=35212
782-
// https://bugs.llvm.org/show_bug.cgi?id=35562
783-
//
784-
// While the first bug there is fixed the second ended up causing #46346
785-
// which was basically a resurgence of #45511 after LLVM's bug 35212 was
786-
// fixed.
787-
//
788-
// This function below is a huge hack around this problem. The function
789-
// below is defined in `PassWrapper.cpp` and will basically "merge"
790-
// all `DICompileUnit` instances in a module. Basically it'll take all
791-
// the objects, rewrite all pointers of `DISubprogram` to point to the
792-
// first `DICompileUnit`, and then delete all the other units.
793-
//
794-
// This is probably mangling to the debug info slightly (but hopefully
795-
// not too much) but for now at least gets LLVM to emit valid DWARF (or
796-
// so it appears). Hopefully we can remove this once upstream bugs are
797-
// fixed in LLVM.
798-
{
799-
let _timer = cgcx
800-
.prof
801-
.generic_activity_with_arg("LLVM_thin_lto_patch_debuginfo", thin_module.name());
802-
llvm::LLVMRustThinLTOPatchDICompileUnit(llmod, cu1);
803-
save_temp_bitcode(cgcx, &module, "thin-lto-after-patch");
804-
}
805-
806757
// Alright now that we've done everything related to the ThinLTO
807758
// analysis it's time to run some optimizations! Here we use the same
808759
// `run_pass_manager` as the "fat" LTO above except that we tell it to

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

-6
Original file line numberDiff line numberDiff line change
@@ -2484,12 +2484,6 @@ extern "C" {
24842484
len: usize,
24852485
out_len: &mut usize,
24862486
) -> *const u8;
2487-
pub fn LLVMRustThinLTOGetDICompileUnit(
2488-
M: &Module,
2489-
CU1: &mut *mut c_void,
2490-
CU2: &mut *mut c_void,
2491-
);
2492-
pub fn LLVMRustThinLTOPatchDICompileUnit(M: &Module, CU: *mut c_void);
24932487

24942488
pub fn LLVMRustLinkerNew(M: &Module) -> &mut Linker<'_>;
24952489
pub fn LLVMRustLinkerAdd(

compiler/rustc_codegen_ssa/src/back/metadata.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ use snap::write::FrameEncoder;
1414

1515
use object::elf::NT_GNU_PROPERTY_TYPE_0;
1616
use rustc_data_structures::memmap::Mmap;
17-
use rustc_data_structures::owned_slice::try_slice_owned;
18-
use rustc_data_structures::sync::MetadataRef;
17+
use rustc_data_structures::owned_slice::{try_slice_owned, OwnedSlice};
1918
use rustc_metadata::fs::METADATA_FILENAME;
2019
use rustc_metadata::EncodedMetadata;
2120
use rustc_session::cstore::MetadataLoader;
@@ -39,7 +38,7 @@ pub struct DefaultMetadataLoader;
3938
fn load_metadata_with(
4039
path: &Path,
4140
f: impl for<'a> FnOnce(&'a [u8]) -> Result<&'a [u8], String>,
42-
) -> Result<MetadataRef, String> {
41+
) -> Result<OwnedSlice, String> {
4342
let file =
4443
File::open(path).map_err(|e| format!("failed to open file '{}': {}", path.display(), e))?;
4544

@@ -49,7 +48,7 @@ fn load_metadata_with(
4948
}
5049

5150
impl MetadataLoader for DefaultMetadataLoader {
52-
fn get_rlib_metadata(&self, _target: &Target, path: &Path) -> Result<MetadataRef, String> {
51+
fn get_rlib_metadata(&self, _target: &Target, path: &Path) -> Result<OwnedSlice, String> {
5352
load_metadata_with(path, |data| {
5453
let archive = object::read::archive::ArchiveFile::parse(&*data)
5554
.map_err(|e| format!("failed to parse rlib '{}': {}", path.display(), e))?;
@@ -69,7 +68,7 @@ impl MetadataLoader for DefaultMetadataLoader {
6968
})
7069
}
7170

72-
fn get_dylib_metadata(&self, _target: &Target, path: &Path) -> Result<MetadataRef, String> {
71+
fn get_dylib_metadata(&self, _target: &Target, path: &Path) -> Result<OwnedSlice, String> {
7372
load_metadata_with(path, |data| search_for_section(path, data, ".rustc"))
7473
}
7574
}

compiler/rustc_codegen_ssa/src/traits/backend.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
use std::any::Any;
2+
13
use super::write::WriteBackendMethods;
24
use super::CodegenObject;
35
use crate::back::write::TargetMachineFactoryFn;
46
use crate::{CodegenResults, ModuleCodegen};
57

68
use rustc_ast::expand::allocator::AllocatorKind;
79
use rustc_data_structures::fx::FxHashMap;
10+
use rustc_data_structures::sync::{DynSend, DynSync};
811
use rustc_errors::ErrorGuaranteed;
912
use rustc_metadata::EncodedMetadata;
1013
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
@@ -20,11 +23,6 @@ use rustc_span::symbol::Symbol;
2023
use rustc_target::abi::call::FnAbi;
2124
use rustc_target::spec::Target;
2225

23-
pub use rustc_data_structures::sync::MetadataRef;
24-
25-
use rustc_data_structures::sync::{DynSend, DynSync};
26-
use std::any::Any;
27-
2826
pub trait BackendTypes {
2927
type Value: CodegenObject;
3028
type Function: CodegenObject;

compiler/rustc_const_eval/src/const_eval/error.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use std::fmt;
33

44
use rustc_errors::Diagnostic;
55
use rustc_middle::mir::AssertKind;
6-
use rustc_middle::ty::{layout::LayoutError, query::TyCtxtAt, ConstInt};
6+
use rustc_middle::query::TyCtxtAt;
7+
use rustc_middle::ty::{layout::LayoutError, ConstInt};
78
use rustc_span::{Span, Symbol};
89

910
use super::InterpCx;
@@ -169,14 +170,14 @@ impl<'tcx> ConstEvalErr<'tcx> {
169170
// See <https://github.com/rust-lang/rust/pull/63152>.
170171
let mut err = struct_error(tcx, &self.error.to_string());
171172
self.decorate(&mut err, decorate);
172-
ErrorHandled::Reported(err.emit())
173+
ErrorHandled::Reported(err.emit().into())
173174
}
174175
_ => {
175176
// Report as hard error.
176177
let mut err = struct_error(tcx, message);
177178
err.span_label(self.span, self.error.to_string());
178179
self.decorate(&mut err, decorate);
179-
ErrorHandled::Reported(err.emit())
180+
ErrorHandled::Reported(err.emit().into())
180181
}
181182
}
182183
}

compiler/rustc_const_eval/src/const_eval/machine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
382382
rustc_span::DUMMY_SP,
383383
"This is likely a const item that is missing from its impl",
384384
);
385-
throw_inval!(AlreadyReported(guar));
385+
throw_inval!(AlreadyReported(guar.into()));
386386
} else {
387387
// `find_mir_or_eval_fn` checks that this is a const fn before even calling us,
388388
// so this should be unreachable.

compiler/rustc_const_eval/src/interpret/eval_context.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ use either::{Either, Left, Right};
77
use rustc_hir::{self as hir, def_id::DefId, definitions::DefPathData};
88
use rustc_index::IndexVec;
99
use rustc_middle::mir;
10-
use rustc_middle::mir::interpret::{ErrorHandled, InterpError};
10+
use rustc_middle::mir::interpret::{ErrorHandled, InterpError, ReportedErrorInfo};
11+
use rustc_middle::query::TyCtxtAt;
1112
use rustc_middle::ty::layout::{
1213
self, FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOf, LayoutOfHelpers,
1314
TyAndLayout,
1415
};
15-
use rustc_middle::ty::{
16-
self, query::TyCtxtAt, subst::SubstsRef, ParamEnv, Ty, TyCtxt, TypeFoldable,
17-
};
16+
use rustc_middle::ty::{self, subst::SubstsRef, ParamEnv, Ty, TyCtxt, TypeFoldable};
1817
use rustc_mir_dataflow::storage::always_storage_live_locals;
1918
use rustc_session::Limit;
2019
use rustc_span::Span;
@@ -470,7 +469,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
470469
};
471470
// do not continue if typeck errors occurred (can only occur in local crate)
472471
if let Some(err) = body.tainted_by_errors {
473-
throw_inval!(AlreadyReported(err));
472+
throw_inval!(AlreadyReported(ReportedErrorInfo::tainted_by_errors(err)));
474473
}
475474
Ok(body)
476475
}
@@ -517,7 +516,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
517516
Ok(None) => throw_inval!(TooGeneric),
518517

519518
// FIXME(eddyb) this could be a bit more specific than `AlreadyReported`.
520-
Err(error_reported) => throw_inval!(AlreadyReported(error_reported)),
519+
Err(error_reported) => throw_inval!(AlreadyReported(error_reported.into())),
521520
}
522521
}
523522

@@ -905,7 +904,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
905904
query(self.tcx.at(span.unwrap_or_else(|| self.cur_span()))).map_err(|err| {
906905
match err {
907906
ErrorHandled::Reported(err) => {
908-
if let Some(span) = span {
907+
if !err.is_tainted_by_errors() && let Some(span) = span {
909908
// To make it easier to figure out where this error comes from, also add a note at the current location.
910909
self.tcx.sess.span_note_without_error(span, "erroneous constant used");
911910
}

compiler/rustc_const_eval/src/interpret/operand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
595595
// FIXME(generic_const_exprs): `ConstKind::Expr` should be able to be evaluated
596596
ty::ConstKind::Expr(_) => throw_inval!(TooGeneric),
597597
ty::ConstKind::Error(reported) => {
598-
throw_inval!(AlreadyReported(reported))
598+
throw_inval!(AlreadyReported(reported.into()))
599599
}
600600
ty::ConstKind::Unevaluated(uv) => {
601601
let instance = self.resolve(uv.def, uv.substs)?;

compiler/rustc_data_structures/src/owned_slice.rs

+36-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use std::{borrow::Borrow, ops::Deref};
22

3+
use crate::sync::Lrc;
34
// Use our fake Send/Sync traits when on not parallel compiler,
45
// so that `OwnedSlice` only implements/requires Send/Sync
56
// for parallel compiler builds.
67
use crate::sync::{Send, Sync};
78

89
/// An owned slice.
910
///
10-
/// This is similar to `Box<[u8]>` but allows slicing and using anything as the
11+
/// This is similar to `Lrc<[u8]>` but allows slicing and using anything as the
1112
/// backing buffer.
1213
///
1314
/// See [`slice_owned`] for `OwnedSlice` construction and examples.
@@ -16,6 +17,7 @@ use crate::sync::{Send, Sync};
1617
///
1718
/// This is essentially a replacement for `owning_ref` which is a lot simpler
1819
/// and even sound! 🌸
20+
#[derive(Clone)]
1921
pub struct OwnedSlice {
2022
/// This is conceptually a `&'self.owner [u8]`.
2123
bytes: *const [u8],
@@ -31,7 +33,7 @@ pub struct OwnedSlice {
3133
// \/
3234
// ⊂(´・◡・⊂ )∘˚˳° (I am the phantom remnant of #97770)
3335
#[expect(dead_code)]
34-
owner: Box<dyn Send + Sync>,
36+
owner: Lrc<dyn Send + Sync>,
3537
}
3638

3739
/// Makes an [`OwnedSlice`] out of an `owner` and a `slicer` function.
@@ -72,23 +74,50 @@ where
7274
O: Send + Sync + 'static,
7375
F: FnOnce(&O) -> Result<&[u8], E>,
7476
{
75-
// We box the owner of the bytes, so it doesn't move.
77+
// We wrap the owner of the bytes in, so it doesn't move.
7678
//
7779
// Since the owner does not move and we don't access it in any way
78-
// before drop, there is nothing that can invalidate the bytes pointer.
80+
// before dropping, there is nothing that can invalidate the bytes pointer.
7981
//
8082
// Thus, "extending" the lifetime of the reference returned from `F` is fine.
8183
// We pretend that we pass it a reference that lives as long as the returned slice.
8284
//
8385
// N.B. the HRTB on the `slicer` is important — without it the caller could provide
8486
// a short lived slice, unrelated to the owner.
8587

86-
let owner = Box::new(owner);
88+
let owner = Lrc::new(owner);
8789
let bytes = slicer(&*owner)?;
8890

8991
Ok(OwnedSlice { bytes, owner })
9092
}
9193

94+
impl OwnedSlice {
95+
/// Slice this slice by `slicer`.
96+
///
97+
/// # Examples
98+
///
99+
/// ```rust
100+
/// # use rustc_data_structures::owned_slice::{OwnedSlice, slice_owned};
101+
/// let vec = vec![1, 2, 3, 4];
102+
///
103+
/// // Identical to slicing via `&v[1..3]` but produces an owned slice
104+
/// let slice: OwnedSlice = slice_owned(vec, |v| &v[..]);
105+
/// assert_eq!(&*slice, [1, 2, 3, 4]);
106+
///
107+
/// let slice = slice.slice(|slice| &slice[1..][..2]);
108+
/// assert_eq!(&*slice, [2, 3]);
109+
/// ```
110+
///
111+
pub fn slice(self, slicer: impl FnOnce(&[u8]) -> &[u8]) -> OwnedSlice {
112+
// This is basically identical to `try_slice_owned`,
113+
// `slicer` can only return slices of its argument or some static data,
114+
// both of which are valid while `owner` is alive.
115+
116+
let bytes = slicer(&self);
117+
OwnedSlice { bytes, ..self }
118+
}
119+
}
120+
92121
impl Deref for OwnedSlice {
93122
type Target = [u8];
94123

@@ -108,11 +137,11 @@ impl Borrow<[u8]> for OwnedSlice {
108137
}
109138
}
110139

111-
// Safety: `OwnedSlice` is conceptually `(&'self.1 [u8], Box<dyn Send + Sync>)`, which is `Send`
140+
// Safety: `OwnedSlice` is conceptually `(&'self.1 [u8], Arc<dyn Send + Sync>)`, which is `Send`
112141
#[cfg(parallel_compiler)]
113142
unsafe impl Send for OwnedSlice {}
114143

115-
// Safety: `OwnedSlice` is conceptually `(&'self.1 [u8], Box<dyn Send + Sync>)`, which is `Sync`
144+
// Safety: `OwnedSlice` is conceptually `(&'self.1 [u8], Arc<dyn Send + Sync>)`, which is `Sync`
116145
#[cfg(parallel_compiler)]
117146
unsafe impl Sync for OwnedSlice {}
118147

0 commit comments

Comments
 (0)