Skip to content

Commit 8011f83

Browse files
committed
Auto merge of #68052 - Centril:rollup-xlktwp3, r=Centril
Rollup of 6 pull requests Successful merges: - #67258 (Introduce `X..`, `..X`, and `..=X` range patterns) - #67358 (Add HashSet::get_or_insert_owned) - #67935 (Relax the Sized bounds on Pin::map_unchecked(_mut)) - #67975 (Export public scalar statics in wasm) - #67988 (Change -Z time event naming scheme and make them generic activities) - #68006 (Recognise riscv64 in compiletest) Failed merges: - #67806 (Extract `rustc_ast_passes`, move gating, & refactor linting) r? @ghost
2 parents adc6572 + f2716e3 commit 8011f83

File tree

83 files changed

+2295
-1085
lines changed

Some content is hidden

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

83 files changed

+2295
-1085
lines changed

src/libcore/pin.rs

+2
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ impl<'a, T: ?Sized> Pin<&'a T> {
672672
#[stable(feature = "pin", since = "1.33.0")]
673673
pub unsafe fn map_unchecked<U, F>(self, func: F) -> Pin<&'a U>
674674
where
675+
U: ?Sized,
675676
F: FnOnce(&T) -> &U,
676677
{
677678
let pointer = &*self.pointer;
@@ -763,6 +764,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
763764
#[stable(feature = "pin", since = "1.33.0")]
764765
pub unsafe fn map_unchecked_mut<U, F>(self, func: F) -> Pin<&'a mut U>
765766
where
767+
U: ?Sized,
766768
F: FnOnce(&mut T) -> &mut U,
767769
{
768770
let pointer = Pin::get_unchecked_mut(self);

src/librustc/hir/map/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ pub fn map_crate<'hir>(
12701270
definitions,
12711271
};
12721272

1273-
sess.time("validate HIR map", || {
1273+
sess.time("validate_HIR_map", || {
12741274
hir_id_validator::check_crate(&map);
12751275
});
12761276

src/librustc/ty/query/on_disk_cache.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl<'sess> OnDiskCache<'sess> {
198198
// Encode query results.
199199
let mut query_result_index = EncodedQueryResultIndex::new();
200200

201-
tcx.sess.time("encode query results", || {
201+
tcx.sess.time("encode_query_results", || {
202202
let enc = &mut encoder;
203203
let qri = &mut query_result_index;
204204

@@ -1053,8 +1053,8 @@ where
10531053
Q: super::config::QueryDescription<'tcx, Value: Encodable>,
10541054
E: 'a + TyEncoder,
10551055
{
1056-
let desc = &format!("encode_query_results for {}", ::std::any::type_name::<Q>());
1057-
let _timer = tcx.sess.prof.generic_pass(desc);
1056+
let desc = &format!("encode_query_results_for_{}", ::std::any::type_name::<Q>());
1057+
let _timer = tcx.sess.prof.extra_verbose_generic_activity(desc);
10581058

10591059
let shards = Q::query_cache(tcx).lock_shards();
10601060
assert!(shards.iter().all(|shard| shard.active.is_empty()));

src/librustc/ty/util.rs

+73-22
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
use crate::hir::map::DefPathData;
44
use crate::ich::NodeIdHashingMode;
55
use crate::mir::interpret::{sign_extend, truncate};
6-
use crate::ty::layout::{Integer, IntegerExt};
6+
use crate::ty::layout::{Integer, IntegerExt, Size};
77
use crate::ty::query::TyCtxtAt;
88
use crate::ty::subst::{GenericArgKind, InternalSubsts, Subst, SubstsRef};
99
use crate::ty::TyKind::*;
1010
use crate::ty::{self, DefIdTree, GenericParamDefKind, Ty, TyCtxt, TypeFoldable};
1111
use crate::util::common::ErrorReported;
12+
use rustc_apfloat::Float as _;
13+
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
14+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1215
use rustc_hir as hir;
1316
use rustc_hir::def::DefKind;
1417
use rustc_hir::def_id::DefId;
15-
16-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
17-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1818
use rustc_macros::HashStable;
1919
use rustc_span::Span;
2020
use std::{cmp, fmt};
@@ -43,41 +43,54 @@ impl<'tcx> fmt::Display for Discr<'tcx> {
4343
}
4444
}
4545

46+
fn signed_min(size: Size) -> i128 {
47+
sign_extend(1_u128 << (size.bits() - 1), size) as i128
48+
}
49+
50+
fn signed_max(size: Size) -> i128 {
51+
i128::max_value() >> (128 - size.bits())
52+
}
53+
54+
fn unsigned_max(size: Size) -> u128 {
55+
u128::max_value() >> (128 - size.bits())
56+
}
57+
58+
fn int_size_and_signed<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> (Size, bool) {
59+
let (int, signed) = match ty.kind {
60+
Int(ity) => (Integer::from_attr(&tcx, SignedInt(ity)), true),
61+
Uint(uty) => (Integer::from_attr(&tcx, UnsignedInt(uty)), false),
62+
_ => bug!("non integer discriminant"),
63+
};
64+
(int.size(), signed)
65+
}
66+
4667
impl<'tcx> Discr<'tcx> {
4768
/// Adds `1` to the value and wraps around if the maximum for the type is reached.
4869
pub fn wrap_incr(self, tcx: TyCtxt<'tcx>) -> Self {
4970
self.checked_add(tcx, 1).0
5071
}
5172
pub fn checked_add(self, tcx: TyCtxt<'tcx>, n: u128) -> (Self, bool) {
52-
let (int, signed) = match self.ty.kind {
53-
Int(ity) => (Integer::from_attr(&tcx, SignedInt(ity)), true),
54-
Uint(uty) => (Integer::from_attr(&tcx, UnsignedInt(uty)), false),
55-
_ => bug!("non integer discriminant"),
56-
};
57-
58-
let size = int.size();
59-
let bit_size = int.size().bits();
60-
let shift = 128 - bit_size;
61-
if signed {
62-
let sext = |u| sign_extend(u, size) as i128;
63-
let min = sext(1_u128 << (bit_size - 1));
64-
let max = i128::max_value() >> shift;
65-
let val = sext(self.val);
73+
let (size, signed) = int_size_and_signed(tcx, self.ty);
74+
let (val, oflo) = if signed {
75+
let min = signed_min(size);
76+
let max = signed_max(size);
77+
let val = sign_extend(self.val, size) as i128;
6678
assert!(n < (i128::max_value() as u128));
6779
let n = n as i128;
6880
let oflo = val > max - n;
6981
let val = if oflo { min + (n - (max - val) - 1) } else { val + n };
7082
// zero the upper bits
7183
let val = val as u128;
7284
let val = truncate(val, size);
73-
(Self { val: val as u128, ty: self.ty }, oflo)
85+
(val, oflo)
7486
} else {
75-
let max = u128::max_value() >> shift;
87+
let max = unsigned_max(size);
7688
let val = self.val;
7789
let oflo = val > max - n;
7890
let val = if oflo { n - (max - val) - 1 } else { val + n };
79-
(Self { val: val, ty: self.ty }, oflo)
80-
}
91+
(val, oflo)
92+
};
93+
(Self { val, ty: self.ty }, oflo)
8194
}
8295
}
8396

@@ -621,6 +634,44 @@ impl<'tcx> TyCtxt<'tcx> {
621634
}
622635

623636
impl<'tcx> ty::TyS<'tcx> {
637+
/// Returns the maximum value for the given numeric type (including `char`s)
638+
/// or returns `None` if the type is not numeric.
639+
pub fn numeric_max_val(&'tcx self, tcx: TyCtxt<'tcx>) -> Option<&'tcx ty::Const<'tcx>> {
640+
let val = match self.kind {
641+
ty::Int(_) | ty::Uint(_) => {
642+
let (size, signed) = int_size_and_signed(tcx, self);
643+
let val = if signed { signed_max(size) as u128 } else { unsigned_max(size) };
644+
Some(val)
645+
}
646+
ty::Char => Some(std::char::MAX as u128),
647+
ty::Float(fty) => Some(match fty {
648+
ast::FloatTy::F32 => ::rustc_apfloat::ieee::Single::INFINITY.to_bits(),
649+
ast::FloatTy::F64 => ::rustc_apfloat::ieee::Double::INFINITY.to_bits(),
650+
}),
651+
_ => None,
652+
};
653+
val.map(|v| ty::Const::from_bits(tcx, v, ty::ParamEnv::empty().and(self)))
654+
}
655+
656+
/// Returns the minimum value for the given numeric type (including `char`s)
657+
/// or returns `None` if the type is not numeric.
658+
pub fn numeric_min_val(&'tcx self, tcx: TyCtxt<'tcx>) -> Option<&'tcx ty::Const<'tcx>> {
659+
let val = match self.kind {
660+
ty::Int(_) | ty::Uint(_) => {
661+
let (size, signed) = int_size_and_signed(tcx, self);
662+
let val = if signed { truncate(signed_min(size) as u128, size) } else { 0 };
663+
Some(val)
664+
}
665+
ty::Char => Some(0),
666+
ty::Float(fty) => Some(match fty {
667+
ast::FloatTy::F32 => (-::rustc_apfloat::ieee::Single::INFINITY).to_bits(),
668+
ast::FloatTy::F64 => (-::rustc_apfloat::ieee::Double::INFINITY).to_bits(),
669+
}),
670+
_ => None,
671+
};
672+
val.map(|v| ty::Const::from_bits(tcx, v, ty::ParamEnv::empty().and(self)))
673+
}
674+
624675
/// Checks whether values of this type `T` are *moved* or *copied*
625676
/// when referenced -- this amounts to a check for whether `T:
626677
/// Copy`, but note that we **don't** consider lifetimes when

src/librustc_ast_lowering/lib.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -2706,9 +2706,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
27062706
PatKind::Box(ref inner) => hir::PatKind::Box(self.lower_pat(inner)),
27072707
PatKind::Ref(ref inner, mutbl) => hir::PatKind::Ref(self.lower_pat(inner), mutbl),
27082708
PatKind::Range(ref e1, ref e2, Spanned { node: ref end, .. }) => hir::PatKind::Range(
2709-
self.lower_expr(e1),
2710-
self.lower_expr(e2),
2711-
self.lower_range_end(end),
2709+
e1.as_deref().map(|e| self.lower_expr(e)),
2710+
e2.as_deref().map(|e| self.lower_expr(e)),
2711+
self.lower_range_end(end, e2.is_some()),
27122712
),
27132713
PatKind::Slice(ref pats) => self.lower_pat_slice(pats),
27142714
PatKind::Rest => {
@@ -2885,10 +2885,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
28852885
hir::PatKind::Wild
28862886
}
28872887

2888-
fn lower_range_end(&mut self, e: &RangeEnd) -> hir::RangeEnd {
2888+
fn lower_range_end(&mut self, e: &RangeEnd, has_end: bool) -> hir::RangeEnd {
28892889
match *e {
2890-
RangeEnd::Included(_) => hir::RangeEnd::Included,
2891-
RangeEnd::Excluded => hir::RangeEnd::Excluded,
2890+
RangeEnd::Excluded if has_end => hir::RangeEnd::Excluded,
2891+
// No end; so `X..` behaves like `RangeFrom`.
2892+
RangeEnd::Excluded | RangeEnd::Included(_) => hir::RangeEnd::Included,
28922893
}
28932894
}
28942895

src/librustc_codegen_llvm/back/lto.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,13 @@ fn prepare_lto(
120120
info!("adding bytecode {}", name);
121121
let bc_encoded = data.data();
122122

123-
let (bc, id) = cgcx.prof.generic_pass(&format!("decode {}", name)).run(|| {
124-
match DecodedBytecode::new(bc_encoded) {
123+
let (bc, id) = cgcx
124+
.prof
125+
.extra_verbose_generic_activity(&format!("decode {}", name))
126+
.run(|| match DecodedBytecode::new(bc_encoded) {
125127
Ok(b) => Ok((b.bytecode(), b.identifier().to_string())),
126128
Err(e) => Err(diag_handler.fatal(&e)),
127-
}
128-
})?;
129+
})?;
129130
let bc = SerializedModule::FromRlib(bc);
130131
upstream_modules.push((bc, CString::new(id).unwrap()));
131132
}
@@ -280,8 +281,9 @@ fn fat_lto(
280281
// save and persist everything with the original module.
281282
let mut linker = Linker::new(llmod);
282283
for (bc_decoded, name) in serialized_modules {
284+
let _timer = cgcx.prof.generic_activity("LLVM_fat_lto_link_module");
283285
info!("linking {:?}", name);
284-
cgcx.prof.generic_pass(&format!("ll link {:?}", name)).run(|| {
286+
cgcx.prof.extra_verbose_generic_activity(&format!("ll link {:?}", name)).run(|| {
285287
let data = bc_decoded.data();
286288
linker.add(&data).map_err(|()| {
287289
let msg = format!("failed to load bc of {:?}", name);
@@ -633,7 +635,7 @@ pub(crate) fn run_pass_manager(
633635
}
634636

635637
cgcx.prof
636-
.generic_pass("LTO passes")
638+
.extra_verbose_generic_activity("LTO_passes")
637639
.run(|| llvm::LLVMRunPassManager(pm, module.module_llvm.llmod()));
638640

639641
llvm::LLVMDisposePassManager(pm);

src/librustc_codegen_llvm/back/write.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -424,13 +424,23 @@ pub(crate) unsafe fn optimize(
424424

425425
// Finally, run the actual optimization passes
426426
{
427+
let _timer = cgcx.prof.generic_activity("LLVM_module_optimize_function_passes");
427428
let desc = &format!("llvm function passes [{}]", module_name.unwrap());
428-
let _timer = if config.time_module { Some(cgcx.prof.generic_pass(desc)) } else { None };
429+
let _timer = if config.time_module {
430+
Some(cgcx.prof.extra_verbose_generic_activity(desc))
431+
} else {
432+
None
433+
};
429434
llvm::LLVMRustRunFunctionPassManager(fpm, llmod);
430435
}
431436
{
437+
let _timer = cgcx.prof.generic_activity("LLVM_module_optimize_module_passes");
432438
let desc = &format!("llvm module passes [{}]", module_name.unwrap());
433-
let _timer = if config.time_module { Some(cgcx.prof.generic_pass(desc)) } else { None };
439+
let _timer = if config.time_module {
440+
Some(cgcx.prof.extra_verbose_generic_activity(desc))
441+
} else {
442+
None
443+
};
434444
llvm::LLVMRunPassManager(mpm, llmod);
435445
}
436446

@@ -556,7 +566,11 @@ pub(crate) unsafe fn codegen(
556566

557567
{
558568
let desc = &format!("codegen passes [{}]", module_name.unwrap());
559-
let _timer = if config.time_module { Some(cgcx.prof.generic_pass(desc)) } else { None };
569+
let _timer = if config.time_module {
570+
Some(cgcx.prof.extra_verbose_generic_activity(desc))
571+
} else {
572+
None
573+
};
560574

561575
if config.emit_ir {
562576
let _timer = cgcx.prof.generic_activity("LLVM_module_codegen_emit_ir");

src/librustc_codegen_llvm/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ impl CodegenBackend for LlvmCodegenBackend {
283283
rustc_codegen_ssa::back::write::dump_incremental_data(&codegen_results);
284284
}
285285

286-
sess.time("serialize work products", move || {
286+
sess.time("serialize_work_products", move || {
287287
rustc_incremental::save_work_product_index(sess, &dep_graph, work_products)
288288
});
289289

@@ -300,7 +300,7 @@ impl CodegenBackend for LlvmCodegenBackend {
300300

301301
// Run the linker on any artifacts that resulted from the LLVM run.
302302
// This should produce either a finished executable or library.
303-
sess.time("linking", || {
303+
sess.time("link_crate", || {
304304
use crate::back::archive::LlvmArchiveBuilder;
305305
use rustc_codegen_ssa::back::link::link_binary;
306306

src/librustc_codegen_ssa/back/link.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
577577
let mut i = 0;
578578
loop {
579579
i += 1;
580-
prog = sess.time("running linker", || exec_linker(sess, &mut cmd, out_filename, tmpdir));
580+
prog = sess.time("run_linker", || exec_linker(sess, &mut cmd, out_filename, tmpdir));
581581
let output = match prog {
582582
Ok(ref output) => output,
583583
Err(_) => break,
@@ -1562,7 +1562,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
15621562
let name = cratepath.file_name().unwrap().to_str().unwrap();
15631563
let name = &name[3..name.len() - 5]; // chop off lib/.rlib
15641564

1565-
sess.prof.generic_pass(&format!("altering {}.rlib", name)).run(|| {
1565+
sess.prof.extra_verbose_generic_activity(&format!("altering {}.rlib", name)).run(|| {
15661566
let mut archive = <B as ArchiveBuilder>::new(sess, &dst, Some(cratepath));
15671567
archive.update_symbols();
15681568

src/librustc_codegen_ssa/back/symbol_export.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ fn symbol_export_level(tcx: TyCtxt<'_>, sym_def_id: DefId) -> SymbolExportLevel
345345
if is_extern && !std_internal {
346346
let target = &tcx.sess.target.target.llvm_target;
347347
// WebAssembly cannot export data symbols, so reduce their export level
348-
if target.contains("wasm32") || target.contains("emscripten") {
348+
if target.contains("emscripten") {
349349
if let Some(Node::Item(&hir::Item { kind: hir::ItemKind::Static(..), .. })) =
350350
tcx.hir().get_if_local(sym_def_id)
351351
{

src/librustc_codegen_ssa/back/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1511,7 +1511,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
15111511
llvm_start_time: &mut Option<VerboseTimingGuard<'a>>,
15121512
) {
15131513
if config.time_module && llvm_start_time.is_none() {
1514-
*llvm_start_time = Some(prof.generic_pass("LLVM passes"));
1514+
*llvm_start_time = Some(prof.extra_verbose_generic_activity("LLVM_passes"));
15151515
}
15161516
}
15171517
}

src/librustc_codegen_ssa/base.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
566566
cgu_name_builder.build_cgu_name(LOCAL_CRATE, &["crate"], Some("allocator")).to_string();
567567
let mut modules = backend.new_metadata(tcx, &llmod_id);
568568
tcx.sess
569-
.time("write allocator module", || backend.codegen_allocator(tcx, &mut modules, kind));
569+
.time("write_allocator_module", || backend.codegen_allocator(tcx, &mut modules, kind));
570570

571571
Some(ModuleCodegen { name: llmod_id, module_llvm: modules, kind: ModuleKind::Allocator })
572572
} else {
@@ -582,7 +582,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
582582
let metadata_cgu_name =
583583
cgu_name_builder.build_cgu_name(LOCAL_CRATE, &["crate"], Some("metadata")).to_string();
584584
let mut metadata_llvm_module = backend.new_metadata(tcx, &metadata_cgu_name);
585-
tcx.sess.time("write compressed metadata", || {
585+
tcx.sess.time("write_compressed_metadata", || {
586586
backend.write_compressed_metadata(
587587
tcx,
588588
&ongoing_codegen.metadata,
@@ -652,7 +652,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
652652

653653
// Since the main thread is sometimes blocked during codegen, we keep track
654654
// -Ztime-passes output manually.
655-
print_time_passes_entry(tcx.sess.time_passes(), "codegen to LLVM IR", total_codegen_time);
655+
print_time_passes_entry(tcx.sess.time_passes(), "codegen_to_LLVM_IR", total_codegen_time);
656656

657657
::rustc_incremental::assert_module_sources::assert_module_sources(tcx);
658658

@@ -712,9 +712,9 @@ impl<B: ExtraBackendMethods> Drop for AbortCodegenOnDrop<B> {
712712
}
713713

714714
fn assert_and_save_dep_graph(tcx: TyCtxt<'_>) {
715-
tcx.sess.time("assert dep graph", || ::rustc_incremental::assert_dep_graph(tcx));
715+
tcx.sess.time("assert_dep_graph", || ::rustc_incremental::assert_dep_graph(tcx));
716716

717-
tcx.sess.time("serialize dep graph", || ::rustc_incremental::save_dep_graph(tcx));
717+
tcx.sess.time("serialize_dep_graph", || ::rustc_incremental::save_dep_graph(tcx));
718718
}
719719

720720
impl CrateInfo {

0 commit comments

Comments
 (0)