Skip to content

Commit bcb610d

Browse files
committed
Auto merge of #108587 - matthiaskrgr:rollup-rw6po59, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - #108376 (compiler/rustc_session: fix sysroot detection logic) - #108400 (add llvm cgu instructions stats to perf) - #108496 (fix #108495, postfix decrement and prefix decrement has no warning) - #108505 (Further unify validity intrinsics) - #108520 (Small cleanup to `one_bound_for_assoc_type`) - #108560 (Some `infer/mod.rs` cleanups) - #108563 (Make mailmap more correct) - #108564 (Fix `x clean` with specific paths) - #108571 (Add contains_key to SortedIndexMultiMap) - #108578 (Update Fuchsia platform team members) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5983a3a + cd5352d commit bcb610d

File tree

29 files changed

+343
-227
lines changed

29 files changed

+343
-227
lines changed

Diff for: .mailmap

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Adrien Tétar <[email protected]>
1515
1616
Alan Egerton <[email protected]>
1717
Alan Stoate <[email protected]>
18-
Albert Larsan <[email protected]> Albert Larsan <[email protected]>
18+
1919
Alessandro Decina <[email protected]>
2020
Alex Burka <[email protected]> Alex Burka <[email protected]>
2121
Alex Hansen <[email protected]>

Diff for: Cargo.lock

+2
Original file line numberDiff line numberDiff line change
@@ -3801,6 +3801,8 @@ dependencies = [
38013801
"rustc_span",
38023802
"rustc_symbol_mangling",
38033803
"rustc_target",
3804+
"serde",
3805+
"serde_json",
38043806
"smallvec",
38053807
"tempfile",
38063808
"tracing",

Diff for: compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

+31-49
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub(crate) use cpuid::codegen_cpuid_call;
2222
pub(crate) use llvm::codegen_llvm_intrinsic_call;
2323

2424
use rustc_middle::ty;
25-
use rustc_middle::ty::layout::{HasParamEnv, InitKind};
25+
use rustc_middle::ty::layout::{HasParamEnv, ValidityRequirement};
2626
use rustc_middle::ty::print::with_no_trimmed_paths;
2727
use rustc_middle::ty::subst::SubstsRef;
2828
use rustc_span::symbol::{kw, sym, Symbol};
@@ -628,57 +628,39 @@ fn codegen_regular_intrinsic_call<'tcx>(
628628
intrinsic_args!(fx, args => (); intrinsic);
629629

630630
let ty = substs.type_at(0);
631-
let layout = fx.layout_of(ty);
632-
if layout.abi.is_uninhabited() {
633-
with_no_trimmed_paths!({
634-
crate::base::codegen_panic_nounwind(
635-
fx,
636-
&format!("attempted to instantiate uninhabited type `{}`", layout.ty),
637-
source_info,
638-
)
639-
});
640-
return;
641-
}
642631

643-
if intrinsic == sym::assert_zero_valid
644-
&& !fx
645-
.tcx
646-
.check_validity_of_init((InitKind::Zero, fx.param_env().and(ty)))
647-
.expect("expected to have layout during codegen")
648-
{
649-
with_no_trimmed_paths!({
650-
crate::base::codegen_panic_nounwind(
651-
fx,
652-
&format!(
653-
"attempted to zero-initialize type `{}`, which is invalid",
654-
layout.ty
655-
),
656-
source_info,
657-
);
658-
});
659-
return;
660-
}
632+
let requirement = ValidityRequirement::from_intrinsic(intrinsic);
661633

662-
if intrinsic == sym::assert_mem_uninitialized_valid
663-
&& !fx
634+
if let Some(requirement) = requirement {
635+
let do_panic = !fx
664636
.tcx
665-
.check_validity_of_init((
666-
InitKind::UninitMitigated0x01Fill,
667-
fx.param_env().and(ty),
668-
))
669-
.expect("expected to have layout during codegen")
670-
{
671-
with_no_trimmed_paths!({
672-
crate::base::codegen_panic_nounwind(
673-
fx,
674-
&format!(
675-
"attempted to leave type `{}` uninitialized, which is invalid",
676-
layout.ty
677-
),
678-
source_info,
679-
)
680-
});
681-
return;
637+
.check_validity_requirement((requirement, fx.param_env().and(ty)))
638+
.expect("expect to have layout during codegen");
639+
640+
if do_panic {
641+
let layout = fx.layout_of(ty);
642+
643+
with_no_trimmed_paths!({
644+
crate::base::codegen_panic_nounwind(
645+
fx,
646+
&if layout.abi.is_uninhabited() {
647+
format!("attempted to instantiate uninhabited type `{}`", layout.ty)
648+
} else if requirement == ValidityRequirement::Zero {
649+
format!(
650+
"attempted to zero-initialize type `{}`, which is invalid",
651+
layout.ty
652+
)
653+
} else {
654+
format!(
655+
"attempted to leave type `{}` uninitialized, which is invalid",
656+
layout.ty
657+
)
658+
},
659+
source_info,
660+
)
661+
});
662+
return;
663+
}
682664
}
683665
}
684666

Diff for: compiler/rustc_codegen_llvm/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
3636
rustc_ast = { path = "../rustc_ast" }
3737
rustc_span = { path = "../rustc_span" }
3838
tempfile = "3.2.0"
39+
serde = { version = "1", features = [ "derive" ]}
40+
serde_json = "1"

Diff for: compiler/rustc_codegen_llvm/src/back/write.rs

+21
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,7 @@ pub(crate) unsafe fn codegen(
761761
EmitObj::None => {}
762762
}
763763

764+
record_llvm_cgu_instructions_stats(&cgcx.prof, llmod);
764765
drop(handlers);
765766
}
766767

@@ -974,3 +975,23 @@ fn record_artifact_size(
974975
self_profiler_ref.artifact_size(artifact_kind, artifact_name.to_string_lossy(), file_size);
975976
}
976977
}
978+
979+
fn record_llvm_cgu_instructions_stats(prof: &SelfProfilerRef, llmod: &llvm::Module) {
980+
if !prof.enabled() {
981+
return;
982+
}
983+
984+
let raw_stats =
985+
llvm::build_string(|s| unsafe { llvm::LLVMRustModuleInstructionStats(&llmod, s) })
986+
.expect("cannot get module instruction stats");
987+
988+
#[derive(serde::Deserialize)]
989+
struct InstructionsStats {
990+
module: String,
991+
total: u64,
992+
}
993+
994+
let InstructionsStats { module, total } =
995+
serde_json::from_str(&raw_stats).expect("cannot parse llvm cgu instructions stats");
996+
prof.artifact_size("cgu_instructions", module, total);
997+
}

Diff for: compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2410,6 +2410,8 @@ extern "C" {
24102410
pub fn LLVMRustModuleBufferLen(p: &ModuleBuffer) -> usize;
24112411
pub fn LLVMRustModuleBufferFree(p: &'static mut ModuleBuffer);
24122412
pub fn LLVMRustModuleCost(M: &Module) -> u64;
2413+
#[allow(improper_ctypes)]
2414+
pub fn LLVMRustModuleInstructionStats(M: &Module, Str: &RustString);
24132415

24142416
pub fn LLVMRustThinLTOBufferCreate(M: &Module, is_thin: bool) -> &'static mut ThinLTOBuffer;
24152417
pub fn LLVMRustThinLTOBufferFree(M: &'static mut ThinLTOBuffer);

Diff for: compiler/rustc_codegen_ssa/src/mir/block.rs

+11-31
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
1414
use rustc_hir::lang_items::LangItem;
1515
use rustc_index::vec::Idx;
1616
use rustc_middle::mir::{self, AssertKind, SwitchTargets};
17-
use rustc_middle::ty::layout::{HasTyCtxt, InitKind, LayoutOf};
17+
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, ValidityRequirement};
1818
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
1919
use rustc_middle::ty::{self, Instance, Ty, TypeVisitableExt};
2020
use rustc_session::config::OptLevel;
@@ -655,44 +655,24 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
655655
// Emit a panic or a no-op for `assert_*` intrinsics.
656656
// These are intrinsics that compile to panics so that we can get a message
657657
// which mentions the offending type, even from a const context.
658-
#[derive(Debug, PartialEq)]
659-
enum AssertIntrinsic {
660-
Inhabited,
661-
ZeroValid,
662-
MemUninitializedValid,
663-
}
664-
let panic_intrinsic = intrinsic.and_then(|i| match i {
665-
sym::assert_inhabited => Some(AssertIntrinsic::Inhabited),
666-
sym::assert_zero_valid => Some(AssertIntrinsic::ZeroValid),
667-
sym::assert_mem_uninitialized_valid => Some(AssertIntrinsic::MemUninitializedValid),
668-
_ => None,
669-
});
670-
if let Some(intrinsic) = panic_intrinsic {
671-
use AssertIntrinsic::*;
672-
658+
let panic_intrinsic = intrinsic.and_then(|s| ValidityRequirement::from_intrinsic(s));
659+
if let Some(requirement) = panic_intrinsic {
673660
let ty = instance.unwrap().substs.type_at(0);
661+
662+
let do_panic = !bx
663+
.tcx()
664+
.check_validity_requirement((requirement, bx.param_env().and(ty)))
665+
.expect("expect to have layout during codegen");
666+
674667
let layout = bx.layout_of(ty);
675-
let do_panic = match intrinsic {
676-
Inhabited => layout.abi.is_uninhabited(),
677-
ZeroValid => !bx
678-
.tcx()
679-
.check_validity_of_init((InitKind::Zero, bx.param_env().and(ty)))
680-
.expect("expected to have layout during codegen"),
681-
MemUninitializedValid => !bx
682-
.tcx()
683-
.check_validity_of_init((
684-
InitKind::UninitMitigated0x01Fill,
685-
bx.param_env().and(ty),
686-
))
687-
.expect("expected to have layout during codegen"),
688-
};
668+
689669
Some(if do_panic {
690670
let msg_str = with_no_visible_paths!({
691671
with_no_trimmed_paths!({
692672
if layout.abi.is_uninhabited() {
693673
// Use this error even for the other intrinsics as it is more precise.
694674
format!("attempted to instantiate uninhabited type `{}`", ty)
695-
} else if intrinsic == ZeroValid {
675+
} else if requirement == ValidityRequirement::Zero {
696676
format!("attempted to zero-initialize type `{}`, which is invalid", ty)
697677
} else {
698678
format!(

Diff for: compiler/rustc_const_eval/src/interpret/intrinsics.rs

+26-48
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_middle::mir::{
1111
BinOp, NonDivergingIntrinsic,
1212
};
1313
use rustc_middle::ty;
14-
use rustc_middle::ty::layout::{InitKind, LayoutOf as _};
14+
use rustc_middle::ty::layout::{LayoutOf as _, ValidityRequirement};
1515
use rustc_middle::ty::subst::SubstsRef;
1616
use rustc_middle::ty::{Ty, TyCtxt};
1717
use rustc_span::symbol::{sym, Symbol};
@@ -418,57 +418,35 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
418418
| sym::assert_zero_valid
419419
| sym::assert_mem_uninitialized_valid => {
420420
let ty = instance.substs.type_at(0);
421-
let layout = self.layout_of(ty)?;
422-
423-
// For *all* intrinsics we first check `is_uninhabited` to give a more specific
424-
// error message.
425-
if layout.abi.is_uninhabited() {
426-
// The run-time intrinsic panics just to get a good backtrace; here we abort
427-
// since there is no problem showing a backtrace even for aborts.
428-
M::abort(
429-
self,
430-
format!(
421+
let requirement = ValidityRequirement::from_intrinsic(intrinsic_name).unwrap();
422+
423+
let should_panic = !self
424+
.tcx
425+
.check_validity_requirement((requirement, self.param_env.and(ty)))
426+
.map_err(|_| err_inval!(TooGeneric))?;
427+
428+
if should_panic {
429+
let layout = self.layout_of(ty)?;
430+
431+
let msg = match requirement {
432+
// For *all* intrinsics we first check `is_uninhabited` to give a more specific
433+
// error message.
434+
_ if layout.abi.is_uninhabited() => format!(
431435
"aborted execution: attempted to instantiate uninhabited type `{}`",
432436
ty
433437
),
434-
)?;
435-
}
436-
437-
if intrinsic_name == sym::assert_zero_valid {
438-
let should_panic = !self
439-
.tcx
440-
.check_validity_of_init((InitKind::Zero, self.param_env.and(ty)))
441-
.map_err(|_| err_inval!(TooGeneric))?;
442-
443-
if should_panic {
444-
M::abort(
445-
self,
446-
format!(
447-
"aborted execution: attempted to zero-initialize type `{}`, which is invalid",
448-
ty
449-
),
450-
)?;
451-
}
452-
}
438+
ValidityRequirement::Inhabited => bug!("handled earlier"),
439+
ValidityRequirement::Zero => format!(
440+
"aborted execution: attempted to zero-initialize type `{}`, which is invalid",
441+
ty
442+
),
443+
ValidityRequirement::UninitMitigated0x01Fill => format!(
444+
"aborted execution: attempted to leave type `{}` uninitialized, which is invalid",
445+
ty
446+
),
447+
};
453448

454-
if intrinsic_name == sym::assert_mem_uninitialized_valid {
455-
let should_panic = !self
456-
.tcx
457-
.check_validity_of_init((
458-
InitKind::UninitMitigated0x01Fill,
459-
self.param_env.and(ty),
460-
))
461-
.map_err(|_| err_inval!(TooGeneric))?;
462-
463-
if should_panic {
464-
M::abort(
465-
self,
466-
format!(
467-
"aborted execution: attempted to leave type `{}` uninitialized, which is invalid",
468-
ty
469-
),
470-
)?;
471-
}
449+
M::abort(self, msg)?;
472450
}
473451
}
474452
sym::simd_insert => {

Diff for: compiler/rustc_const_eval/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub fn provide(providers: &mut Providers) {
6161
let (param_env, value) = param_env_and_value.into_parts();
6262
const_eval::deref_mir_constant(tcx, param_env, value)
6363
};
64-
providers.check_validity_of_init = |tcx, (init_kind, param_env_and_ty)| {
65-
util::might_permit_raw_init(tcx, init_kind, param_env_and_ty)
64+
providers.check_validity_requirement = |tcx, (init_kind, param_env_and_ty)| {
65+
util::check_validity_requirement(tcx, init_kind, param_env_and_ty)
6666
};
6767
}

0 commit comments

Comments
 (0)