Skip to content

Commit eb2446a

Browse files
committed
Auto merge of rust-lang#115820 - matthiaskrgr:rollup-kyglvpu, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#115736 (Remove `verbose_generic_activity_with_arg`) - rust-lang#115771 (cleanup leftovers of const_err lint) - rust-lang#115798 (add helper method for finding the one non-1-ZST field) - rust-lang#115812 (Merge settings.css into rustdoc.css) - rust-lang#115815 (fix: return early when has tainted in mir pass) - rust-lang#115816 (Disabled socketpair for Vita) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5adddad + 156f50b commit eb2446a

File tree

25 files changed

+232
-228
lines changed

25 files changed

+232
-228
lines changed

compiler/rustc_codegen_cranelift/src/driver/aot.rs

+15-26
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ fn module_codegen(
269269
),
270270
) -> OngoingModuleCodegen {
271271
let (cgu_name, mut cx, mut module, codegened_functions) =
272-
tcx.prof.verbose_generic_activity_with_arg("codegen cgu", cgu_name.as_str()).run(|| {
272+
tcx.prof.generic_activity_with_arg("codegen cgu", cgu_name.as_str()).run(|| {
273273
let cgu = tcx.codegen_unit(cgu_name);
274274
let mono_items = cgu.items_in_deterministic_order(tcx);
275275

@@ -322,35 +322,24 @@ fn module_codegen(
322322
});
323323

324324
OngoingModuleCodegen::Async(std::thread::spawn(move || {
325-
cx.profiler.clone().verbose_generic_activity_with_arg("compile functions", &*cgu_name).run(
326-
|| {
327-
cranelift_codegen::timing::set_thread_profiler(Box::new(super::MeasuremeProfiler(
328-
cx.profiler.clone(),
329-
)));
330-
331-
let mut cached_context = Context::new();
332-
for codegened_func in codegened_functions {
333-
crate::base::compile_fn(
334-
&mut cx,
335-
&mut cached_context,
336-
&mut module,
337-
codegened_func,
338-
);
339-
}
340-
},
341-
);
325+
cx.profiler.clone().generic_activity_with_arg("compile functions", &*cgu_name).run(|| {
326+
cranelift_codegen::timing::set_thread_profiler(Box::new(super::MeasuremeProfiler(
327+
cx.profiler.clone(),
328+
)));
329+
330+
let mut cached_context = Context::new();
331+
for codegened_func in codegened_functions {
332+
crate::base::compile_fn(&mut cx, &mut cached_context, &mut module, codegened_func);
333+
}
334+
});
342335

343-
let global_asm_object_file = cx
344-
.profiler
345-
.verbose_generic_activity_with_arg("compile assembly", &*cgu_name)
346-
.run(|| {
336+
let global_asm_object_file =
337+
cx.profiler.generic_activity_with_arg("compile assembly", &*cgu_name).run(|| {
347338
crate::global_asm::compile_global_asm(&global_asm_config, &cgu_name, &cx.global_asm)
348339
})?;
349340

350-
let codegen_result = cx
351-
.profiler
352-
.verbose_generic_activity_with_arg("write object file", &*cgu_name)
353-
.run(|| {
341+
let codegen_result =
342+
cx.profiler.generic_activity_with_arg("write object file", &*cgu_name).run(|| {
354343
emit_cgu(
355344
&global_asm_config.output_filenames,
356345
&cx.profiler,

compiler/rustc_codegen_cranelift/src/vtable.rs

+6-13
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,12 @@ pub(crate) fn get_ptr_and_method_ref<'tcx>(
4848
) -> (Pointer, Value) {
4949
let (ptr, vtable) = 'block: {
5050
if let Abi::Scalar(_) = arg.layout().abi {
51-
'descend_newtypes: while !arg.layout().ty.is_unsafe_ptr() && !arg.layout().ty.is_ref() {
52-
for i in 0..arg.layout().fields.count() {
53-
let field = arg.value_field(fx, FieldIdx::new(i));
54-
if !field.layout().is_1zst() {
55-
// we found the one non-1-ZST field that is allowed
56-
// now find *its* non-zero-sized field, or stop if it's a
57-
// pointer
58-
arg = field;
59-
continue 'descend_newtypes;
60-
}
61-
}
62-
63-
bug!("receiver has no non-zero-sized fields {:?}", arg);
51+
while !arg.layout().ty.is_unsafe_ptr() && !arg.layout().ty.is_ref() {
52+
let (idx, _) = arg
53+
.layout()
54+
.non_1zst_field(fx)
55+
.expect("not exactly one non-1-ZST field in a `DispatchFromDyn` type");
56+
arg = arg.value_field(fx, FieldIdx::new(idx));
6457
}
6558
}
6659

compiler/rustc_codegen_llvm/src/back/lto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ pub(crate) fn run_pass_manager(
605605
module: &mut ModuleCodegen<ModuleLlvm>,
606606
thin: bool,
607607
) -> Result<(), FatalError> {
608-
let _timer = cgcx.prof.verbose_generic_activity_with_arg("LLVM_lto_optimize", &*module.name);
608+
let _timer = cgcx.prof.generic_activity_with_arg("LLVM_lto_optimize", &*module.name);
609609
let config = cgcx.config(module.kind);
610610

611611
// Now we have one massive module inside of llmod. Time to run the

compiler/rustc_codegen_ssa/src/mir/block.rs

+10-31
Original file line numberDiff line numberDiff line change
@@ -928,21 +928,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
928928
// we get a value of a built-in pointer type.
929929
//
930930
// This is also relevant for `Pin<&mut Self>`, where we need to peel the `Pin`.
931-
'descend_newtypes: while !op.layout.ty.is_unsafe_ptr()
932-
&& !op.layout.ty.is_ref()
933-
{
934-
for i in 0..op.layout.fields.count() {
935-
let field = op.extract_field(bx, i);
936-
if !field.layout.is_1zst() {
937-
// we found the one non-1-ZST field that is allowed
938-
// now find *its* non-zero-sized field, or stop if it's a
939-
// pointer
940-
op = field;
941-
continue 'descend_newtypes;
942-
}
943-
}
944-
945-
span_bug!(span, "receiver has no non-zero-sized fields {:?}", op);
931+
while !op.layout.ty.is_unsafe_ptr() && !op.layout.ty.is_ref() {
932+
let (idx, _) = op.layout.non_1zst_field(bx).expect(
933+
"not exactly one non-1-ZST field in a `DispatchFromDyn` type",
934+
);
935+
op = op.extract_field(bx, idx);
946936
}
947937

948938
// now that we have `*dyn Trait` or `&dyn Trait`, split it up into its
@@ -970,22 +960,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
970960
}
971961
Immediate(_) => {
972962
// See comment above explaining why we peel these newtypes
973-
'descend_newtypes: while !op.layout.ty.is_unsafe_ptr()
974-
&& !op.layout.ty.is_ref()
975-
{
976-
for i in 0..op.layout.fields.count() {
977-
let field = op.extract_field(bx, i);
978-
if !field.layout.is_1zst() {
979-
// We found the one non-1-ZST field that is allowed. (The rules
980-
// for `DispatchFromDyn` ensure there's exactly one such field.)
981-
// Now find *its* non-zero-sized field, or stop if it's a
982-
// pointer.
983-
op = field;
984-
continue 'descend_newtypes;
985-
}
986-
}
987-
988-
span_bug!(span, "receiver has no non-zero-sized fields {:?}", op);
963+
while !op.layout.ty.is_unsafe_ptr() && !op.layout.ty.is_ref() {
964+
let (idx, _) = op.layout.non_1zst_field(bx).expect(
965+
"not exactly one non-1-ZST field in a `DispatchFromDyn` type",
966+
);
967+
op = op.extract_field(bx, idx);
989968
}
990969

991970
// Make sure that we've actually unwrapped the rcvr down

compiler/rustc_const_eval/src/const_eval/error.rs

+3-22
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rustc_errors::{DiagnosticArgValue, DiagnosticMessage, IntoDiagnostic, IntoDi
44
use rustc_middle::mir::AssertKind;
55
use rustc_middle::ty::TyCtxt;
66
use rustc_middle::ty::{layout::LayoutError, ConstInt};
7-
use rustc_span::source_map::Spanned;
87
use rustc_span::{ErrorGuaranteed, Span, Symbol};
98

109
use super::InterpCx;
@@ -132,35 +131,17 @@ where
132131
{
133132
// Special handling for certain errors
134133
match error {
135-
// Don't emit a new diagnostic for these errors
134+
// Don't emit a new diagnostic for these errors, they are already reported elsewhere or
135+
// should remain silent.
136136
err_inval!(Layout(LayoutError::Unknown(_))) | err_inval!(TooGeneric) => {
137137
ErrorHandled::TooGeneric
138138
}
139139
err_inval!(AlreadyReported(guar)) => ErrorHandled::Reported(guar),
140140
err_inval!(Layout(LayoutError::ReferencesError(guar))) => {
141141
ErrorHandled::Reported(guar.into())
142142
}
143-
err_inval!(Layout(layout_error @ LayoutError::SizeOverflow(_))) => {
144-
// We must *always* hard error on these, even if the caller wants just a lint.
145-
// The `message` makes little sense here, this is a more serious error than the
146-
// caller thinks anyway.
147-
// See <https://github.com/rust-lang/rust/pull/63152>.
148-
let (our_span, frames) = get_span_and_frames();
149-
let span = span.unwrap_or(our_span);
150-
let mut err =
151-
tcx.sess.create_err(Spanned { span, node: layout_error.into_diagnostic() });
152-
err.code(rustc_errors::error_code!(E0080));
153-
let Some((mut err, handler)) = err.into_diagnostic() else {
154-
panic!("did not emit diag");
155-
};
156-
for frame in frames {
157-
err.eager_subdiagnostic(handler, frame);
158-
}
159-
160-
ErrorHandled::Reported(handler.emit_diagnostic(&mut err).unwrap().into())
161-
}
143+
// Report remaining errors.
162144
_ => {
163-
// Report as hard error.
164145
let (our_span, frames) = get_span_and_frames();
165146
let span = span.unwrap_or(our_span);
166147
let err = mk(span, frames);

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
372372
};
373373
let alloc_id = mplace.ptr().provenance.unwrap();
374374

375-
// Validation failed, report an error. This is always a hard error.
375+
// Validation failed, report an error.
376376
if let Err(error) = validation {
377377
let (error, backtrace) = error.into_parts();
378378
backtrace.print_backtrace();

compiler/rustc_const_eval/src/interpret/terminator.rs

+7-32
Original file line numberDiff line numberDiff line change
@@ -269,19 +269,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
269269
match layout.ty.kind() {
270270
ty::Adt(adt_def, _) if adt_def.repr().transparent() && may_unfold(*adt_def) => {
271271
assert!(!adt_def.is_enum());
272-
// Find the non-1-ZST field.
273-
let mut non_1zst_fields = (0..layout.fields.count()).filter_map(|idx| {
274-
let field = layout.field(self, idx);
275-
if field.is_1zst() { None } else { Some(field) }
276-
});
277-
let first = non_1zst_fields.next().expect("`unfold_transparent` called on 1-ZST");
278-
assert!(
279-
non_1zst_fields.next().is_none(),
280-
"more than one non-1-ZST field in a transparent type"
281-
);
282-
283-
// Found it!
284-
self.unfold_transparent(first, may_unfold)
272+
// Find the non-1-ZST field, and recurse.
273+
let (_, field) = layout.non_1zst_field(self).unwrap();
274+
self.unfold_transparent(field, may_unfold)
285275
}
286276
// Not a transparent type, no further unfolding.
287277
_ => layout,
@@ -797,25 +787,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
797787
_ => {
798788
// Not there yet, search for the only non-ZST field.
799789
// (The rules for `DispatchFromDyn` ensure there's exactly one such field.)
800-
let mut non_zst_field = None;
801-
for i in 0..receiver.layout.fields.count() {
802-
let field = self.project_field(&receiver, i)?;
803-
let zst = field.layout.is_1zst();
804-
if !zst {
805-
assert!(
806-
non_zst_field.is_none(),
807-
"multiple non-1-ZST fields in dyn receiver type {}",
808-
receiver.layout.ty
809-
);
810-
non_zst_field = Some(field);
811-
}
812-
}
813-
receiver = non_zst_field.unwrap_or_else(|| {
814-
panic!(
815-
"no non-1-ZST fields in dyn receiver type {}",
816-
receiver.layout.ty
817-
)
818-
});
790+
let (idx, _) = receiver.layout.non_1zst_field(self).expect(
791+
"not exactly one non-1-ZST field in a `DispatchFromDyn` type",
792+
);
793+
receiver = self.project_field(&receiver, idx)?;
819794
}
820795
}
821796
};

compiler/rustc_middle/src/mir/mod.rs

+37
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use rustc_target::abi::{FieldIdx, Size, VariantIdx};
2626

2727
use polonius_engine::Atom;
2828
pub use rustc_ast::Mutability;
29+
use rustc_data_structures::fx::FxHashMap;
2930
use rustc_data_structures::fx::FxHashSet;
3031
use rustc_data_structures::graph::dominators::Dominators;
3132
use rustc_index::{Idx, IndexSlice, IndexVec};
@@ -36,6 +37,8 @@ use rustc_span::{Span, DUMMY_SP};
3637
use either::Either;
3738

3839
use std::borrow::Cow;
40+
use std::cell::RefCell;
41+
use std::collections::hash_map::Entry;
3942
use std::fmt::{self, Debug, Display, Formatter, Write};
4043
use std::ops::{Index, IndexMut};
4144
use std::{iter, mem};
@@ -98,6 +101,36 @@ impl<'tcx> HasLocalDecls<'tcx> for Body<'tcx> {
98101
}
99102
}
100103

104+
thread_local! {
105+
static PASS_NAMES: RefCell<FxHashMap<&'static str, &'static str>> = {
106+
RefCell::new(FxHashMap::default())
107+
};
108+
}
109+
110+
/// Converts a MIR pass name into a snake case form to match the profiling naming style.
111+
fn to_profiler_name(type_name: &'static str) -> &'static str {
112+
PASS_NAMES.with(|names| match names.borrow_mut().entry(type_name) {
113+
Entry::Occupied(e) => *e.get(),
114+
Entry::Vacant(e) => {
115+
let snake_case: String = type_name
116+
.chars()
117+
.flat_map(|c| {
118+
if c.is_ascii_uppercase() {
119+
vec!['_', c.to_ascii_lowercase()]
120+
} else if c == '-' {
121+
vec!['_']
122+
} else {
123+
vec![c]
124+
}
125+
})
126+
.collect();
127+
let result = &*String::leak(format!("mir_pass{}", snake_case));
128+
e.insert(result);
129+
result
130+
}
131+
})
132+
}
133+
101134
/// A streamlined trait that you can implement to create a pass; the
102135
/// pass will be named after the type, and it will consist of a main
103136
/// loop that goes over each available MIR and applies `run_pass`.
@@ -107,6 +140,10 @@ pub trait MirPass<'tcx> {
107140
if let Some((_, tail)) = name.rsplit_once(':') { tail } else { name }
108141
}
109142

143+
fn profiler_name(&self) -> &'static str {
144+
to_profiler_name(self.name())
145+
}
146+
110147
/// Returns `true` if this pass is enabled with the current combination of compiler flags.
111148
fn is_enabled(&self, _sess: &Session) -> bool {
112149
true

compiler/rustc_mir_transform/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,11 @@ fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> {
606606
let body = tcx.mir_drops_elaborated_and_const_checked(did).steal();
607607
let mut body = remap_mir_for_const_eval_select(tcx, body, hir::Constness::NotConst);
608608
debug!("body: {:#?}", body);
609+
610+
if body.tainted_by_errors.is_some() {
611+
return body;
612+
}
613+
609614
run_optimization_passes(tcx, &mut body);
610615

611616
body

compiler/rustc_mir_transform/src/pass_manager.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ fn run_passes_inner<'tcx>(
9494
let overridden_passes = &tcx.sess.opts.unstable_opts.mir_enable_passes;
9595
trace!(?overridden_passes);
9696

97+
let prof_arg = tcx.sess.prof.enabled().then(|| format!("{:?}", body.source.def_id()));
98+
9799
if !body.should_skip() {
98100
for pass in passes {
99101
let name = pass.name();
@@ -121,7 +123,14 @@ fn run_passes_inner<'tcx>(
121123
validate_body(tcx, body, format!("before pass {name}"));
122124
}
123125

124-
tcx.sess.time(name, || pass.run_pass(tcx, body));
126+
if let Some(prof_arg) = &prof_arg {
127+
tcx.sess
128+
.prof
129+
.generic_activity_with_arg(pass.profiler_name(), &**prof_arg)
130+
.run(|| pass.run_pass(tcx, body));
131+
} else {
132+
pass.run_pass(tcx, body);
133+
}
125134

126135
if dump_enabled {
127136
dump_mir_for_pass(tcx, body, &name, true);

compiler/rustc_query_impl/src/plumbing.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,7 @@ pub(crate) fn encode_query_results<'a, 'tcx, Q>(
348348
Q: super::QueryConfigRestored<'tcx>,
349349
Q::RestoredValue: Encodable<CacheEncoder<'a, 'tcx>>,
350350
{
351-
let _timer =
352-
qcx.profiler().verbose_generic_activity_with_arg("encode_query_results_for", query.name());
351+
let _timer = qcx.profiler().generic_activity_with_arg("encode_query_results_for", query.name());
353352

354353
assert!(query.query_state(qcx).all_inactive());
355354
let cache = query.query_cache(qcx);

compiler/rustc_target/src/abi/mod.rs

+21
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,25 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
144144

145145
offset
146146
}
147+
148+
/// Finds the one field that is not a 1-ZST.
149+
/// Returns `None` if there are multiple non-1-ZST fields or only 1-ZST-fields.
150+
pub fn non_1zst_field<C>(&self, cx: &C) -> Option<(usize, Self)>
151+
where
152+
Ty: TyAbiInterface<'a, C> + Copy,
153+
{
154+
let mut found = None;
155+
for field_idx in 0..self.fields.count() {
156+
let field = self.field(cx, field_idx);
157+
if field.is_1zst() {
158+
continue;
159+
}
160+
if found.is_some() {
161+
// More than one non-1-ZST field.
162+
return None;
163+
}
164+
found = Some((field_idx, field));
165+
}
166+
found
167+
}
147168
}

0 commit comments

Comments
 (0)