Skip to content

Commit 97ae1df

Browse files
committed
Auto merge of rust-lang#132128 - workingjubilee:rollup-uwqp2i2, r=workingjubilee
Rollup of 4 pull requests Successful merges: - rust-lang#131457 (Expand `ptr::fn_addr_eq()` documentation.) - rust-lang#132085 (Update StableMIR doc to reflect current status) - rust-lang#132118 (Add support for `~const` item bounds) - rust-lang#132125 (coverage: Emit LLVM intrinsics using the normal helper method) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 017ae1b + 7f93af1 commit 97ae1df

File tree

20 files changed

+273
-259
lines changed

20 files changed

+273
-259
lines changed

compiler/rustc_codegen_gcc/src/builder.rs

-10
Original file line numberDiff line numberDiff line change
@@ -1725,16 +1725,6 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
17251725
fn fptosi_sat(&mut self, val: RValue<'gcc>, dest_ty: Type<'gcc>) -> RValue<'gcc> {
17261726
self.fptoint_sat(true, val, dest_ty)
17271727
}
1728-
1729-
fn instrprof_increment(
1730-
&mut self,
1731-
_fn_name: RValue<'gcc>,
1732-
_hash: RValue<'gcc>,
1733-
_num_counters: RValue<'gcc>,
1734-
_index: RValue<'gcc>,
1735-
) {
1736-
unimplemented!();
1737-
}
17381728
}
17391729

17401730
impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {

compiler/rustc_codegen_llvm/src/builder.rs

+21-79
Original file line numberDiff line numberDiff line change
@@ -1165,39 +1165,6 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
11651165
self.call_lifetime_intrinsic("llvm.lifetime.end.p0i8", ptr, size);
11661166
}
11671167

1168-
fn instrprof_increment(
1169-
&mut self,
1170-
fn_name: &'ll Value,
1171-
hash: &'ll Value,
1172-
num_counters: &'ll Value,
1173-
index: &'ll Value,
1174-
) {
1175-
debug!(
1176-
"instrprof_increment() with args ({:?}, {:?}, {:?}, {:?})",
1177-
fn_name, hash, num_counters, index
1178-
);
1179-
1180-
let llfn = unsafe { llvm::LLVMRustGetInstrProfIncrementIntrinsic(self.cx().llmod) };
1181-
let llty = self.cx.type_func(
1182-
&[self.cx.type_ptr(), self.cx.type_i64(), self.cx.type_i32(), self.cx.type_i32()],
1183-
self.cx.type_void(),
1184-
);
1185-
let args = &[fn_name, hash, num_counters, index];
1186-
let args = self.check_call("call", llty, llfn, args);
1187-
1188-
unsafe {
1189-
let _ = llvm::LLVMRustBuildCall(
1190-
self.llbuilder,
1191-
llty,
1192-
llfn,
1193-
args.as_ptr() as *const &llvm::Value,
1194-
args.len() as c_uint,
1195-
[].as_ptr(),
1196-
0 as c_uint,
1197-
);
1198-
}
1199-
}
1200-
12011168
fn call(
12021169
&mut self,
12031170
llty: &'ll Type,
@@ -1667,6 +1634,18 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
16671634
kcfi_bundle
16681635
}
16691636

1637+
/// Emits a call to `llvm.instrprof.increment`. Used by coverage instrumentation.
1638+
#[instrument(level = "debug", skip(self))]
1639+
pub(crate) fn instrprof_increment(
1640+
&mut self,
1641+
fn_name: &'ll Value,
1642+
hash: &'ll Value,
1643+
num_counters: &'ll Value,
1644+
index: &'ll Value,
1645+
) {
1646+
self.call_intrinsic("llvm.instrprof.increment", &[fn_name, hash, num_counters, index]);
1647+
}
1648+
16701649
/// Emits a call to `llvm.instrprof.mcdc.parameters`.
16711650
///
16721651
/// This doesn't produce any code directly, but is used as input by
@@ -1676,80 +1655,43 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
16761655
///
16771656
/// [`CodeGenPGO::emitMCDCParameters`]:
16781657
/// https://github.com/rust-lang/llvm-project/blob/5399a24/clang/lib/CodeGen/CodeGenPGO.cpp#L1124
1658+
#[instrument(level = "debug", skip(self))]
16791659
pub(crate) fn mcdc_parameters(
16801660
&mut self,
16811661
fn_name: &'ll Value,
16821662
hash: &'ll Value,
16831663
bitmap_bits: &'ll Value,
16841664
) {
1685-
debug!("mcdc_parameters() with args ({:?}, {:?}, {:?})", fn_name, hash, bitmap_bits);
1686-
16871665
assert!(
16881666
crate::llvm_util::get_version() >= (19, 0, 0),
16891667
"MCDC intrinsics require LLVM 19 or later"
16901668
);
1691-
1692-
let llfn = unsafe { llvm::LLVMRustGetInstrProfMCDCParametersIntrinsic(self.cx().llmod) };
1693-
let llty = self.cx.type_func(
1694-
&[self.cx.type_ptr(), self.cx.type_i64(), self.cx.type_i32()],
1695-
self.cx.type_void(),
1696-
);
1697-
let args = &[fn_name, hash, bitmap_bits];
1698-
let args = self.check_call("call", llty, llfn, args);
1699-
1700-
unsafe {
1701-
let _ = llvm::LLVMRustBuildCall(
1702-
self.llbuilder,
1703-
llty,
1704-
llfn,
1705-
args.as_ptr() as *const &llvm::Value,
1706-
args.len() as c_uint,
1707-
[].as_ptr(),
1708-
0 as c_uint,
1709-
);
1710-
}
1669+
self.call_intrinsic("llvm.instrprof.mcdc.parameters", &[fn_name, hash, bitmap_bits]);
17111670
}
17121671

1672+
#[instrument(level = "debug", skip(self))]
17131673
pub(crate) fn mcdc_tvbitmap_update(
17141674
&mut self,
17151675
fn_name: &'ll Value,
17161676
hash: &'ll Value,
17171677
bitmap_index: &'ll Value,
17181678
mcdc_temp: &'ll Value,
17191679
) {
1720-
debug!(
1721-
"mcdc_tvbitmap_update() with args ({:?}, {:?}, {:?}, {:?})",
1722-
fn_name, hash, bitmap_index, mcdc_temp
1723-
);
17241680
assert!(
17251681
crate::llvm_util::get_version() >= (19, 0, 0),
17261682
"MCDC intrinsics require LLVM 19 or later"
17271683
);
1728-
1729-
let llfn =
1730-
unsafe { llvm::LLVMRustGetInstrProfMCDCTVBitmapUpdateIntrinsic(self.cx().llmod) };
1731-
let llty = self.cx.type_func(
1732-
&[self.cx.type_ptr(), self.cx.type_i64(), self.cx.type_i32(), self.cx.type_ptr()],
1733-
self.cx.type_void(),
1734-
);
17351684
let args = &[fn_name, hash, bitmap_index, mcdc_temp];
1736-
let args = self.check_call("call", llty, llfn, args);
1737-
unsafe {
1738-
let _ = llvm::LLVMRustBuildCall(
1739-
self.llbuilder,
1740-
llty,
1741-
llfn,
1742-
args.as_ptr() as *const &llvm::Value,
1743-
args.len() as c_uint,
1744-
[].as_ptr(),
1745-
0 as c_uint,
1746-
);
1747-
}
1685+
self.call_intrinsic("llvm.instrprof.mcdc.tvbitmap.update", args);
1686+
}
1687+
1688+
#[instrument(level = "debug", skip(self))]
1689+
pub(crate) fn mcdc_condbitmap_reset(&mut self, mcdc_temp: &'ll Value) {
17481690
self.store(self.const_i32(0), mcdc_temp, self.tcx.data_layout.i32_align.abi);
17491691
}
17501692

1693+
#[instrument(level = "debug", skip(self))]
17511694
pub(crate) fn mcdc_condbitmap_update(&mut self, cond_index: &'ll Value, mcdc_temp: &'ll Value) {
1752-
debug!("mcdc_condbitmap_update() with args ({:?}, {:?})", cond_index, mcdc_temp);
17531695
assert!(
17541696
crate::llvm_util::get_version() >= (19, 0, 0),
17551697
"MCDC intrinsics require LLVM 19 or later"

compiler/rustc_codegen_llvm/src/context.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,10 @@ impl<'ll> CodegenCx<'ll, '_> {
10991099

11001100
if self.sess().instrument_coverage() {
11011101
ifn!("llvm.instrprof.increment", fn(ptr, t_i64, t_i32, t_i32) -> void);
1102+
if crate::llvm_util::get_version() >= (19, 0, 0) {
1103+
ifn!("llvm.instrprof.mcdc.parameters", fn(ptr, t_i64, t_i32) -> void);
1104+
ifn!("llvm.instrprof.mcdc.tvbitmap.update", fn(ptr, t_i64, t_i32, ptr) -> void);
1105+
}
11021106
}
11031107

11041108
ifn!("llvm.type.test", fn(ptr, t_metadata) -> i1);

compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
208208
let hash = bx.const_u64(function_coverage_info.function_source_hash);
209209
let bitmap_index = bx.const_u32(bitmap_idx);
210210
bx.mcdc_tvbitmap_update(fn_name, hash, bitmap_index, cond_bitmap);
211+
bx.mcdc_condbitmap_reset(cond_bitmap);
211212
}
212213
}
213214
}

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1615,10 +1615,6 @@ unsafe extern "C" {
16151615
pub fn LLVMRustSetAllowReassoc(Instr: &Value);
16161616

16171617
// Miscellaneous instructions
1618-
pub fn LLVMRustGetInstrProfIncrementIntrinsic(M: &Module) -> &Value;
1619-
pub fn LLVMRustGetInstrProfMCDCParametersIntrinsic(M: &Module) -> &Value;
1620-
pub fn LLVMRustGetInstrProfMCDCTVBitmapUpdateIntrinsic(M: &Module) -> &Value;
1621-
16221618
pub fn LLVMRustBuildCall<'a>(
16231619
B: &Builder<'a>,
16241620
Ty: &'a Type,

compiler/rustc_codegen_ssa/src/traits/builder.rs

-8
Original file line numberDiff line numberDiff line change
@@ -437,14 +437,6 @@ pub trait BuilderMethods<'a, 'tcx>:
437437
/// Called for `StorageDead`
438438
fn lifetime_end(&mut self, ptr: Self::Value, size: Size);
439439

440-
fn instrprof_increment(
441-
&mut self,
442-
fn_name: Self::Value,
443-
hash: Self::Value,
444-
num_counters: Self::Value,
445-
index: Self::Value,
446-
);
447-
448440
fn call(
449441
&mut self,
450442
llty: Self::Type,

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

-39
Original file line numberDiff line numberDiff line change
@@ -1531,45 +1531,6 @@ extern "C" LLVMValueRef LLVMRustBuildCall(LLVMBuilderRef B, LLVMTypeRef Ty,
15311531
ArrayRef<OperandBundleDef>(OpBundles)));
15321532
}
15331533

1534-
extern "C" LLVMValueRef
1535-
LLVMRustGetInstrProfIncrementIntrinsic(LLVMModuleRef M) {
1536-
#if LLVM_VERSION_GE(20, 0)
1537-
return wrap(llvm::Intrinsic::getOrInsertDeclaration(
1538-
unwrap(M), llvm::Intrinsic::instrprof_increment));
1539-
#else
1540-
return wrap(llvm::Intrinsic::getDeclaration(
1541-
unwrap(M), llvm::Intrinsic::instrprof_increment));
1542-
#endif
1543-
}
1544-
1545-
extern "C" LLVMValueRef
1546-
LLVMRustGetInstrProfMCDCParametersIntrinsic(LLVMModuleRef M) {
1547-
#if LLVM_VERSION_LT(19, 0)
1548-
report_fatal_error("LLVM 19.0 is required for mcdc intrinsic functions");
1549-
#endif
1550-
#if LLVM_VERSION_GE(20, 0)
1551-
return wrap(llvm::Intrinsic::getOrInsertDeclaration(
1552-
unwrap(M), llvm::Intrinsic::instrprof_mcdc_parameters));
1553-
#else
1554-
return wrap(llvm::Intrinsic::getDeclaration(
1555-
unwrap(M), llvm::Intrinsic::instrprof_mcdc_parameters));
1556-
#endif
1557-
}
1558-
1559-
extern "C" LLVMValueRef
1560-
LLVMRustGetInstrProfMCDCTVBitmapUpdateIntrinsic(LLVMModuleRef M) {
1561-
#if LLVM_VERSION_LT(19, 0)
1562-
report_fatal_error("LLVM 19.0 is required for mcdc intrinsic functions");
1563-
#endif
1564-
#if LLVM_VERSION_GE(20, 0)
1565-
return wrap(llvm::Intrinsic::getOrInsertDeclaration(
1566-
unwrap(M), llvm::Intrinsic::instrprof_mcdc_tvbitmap_update));
1567-
#else
1568-
return wrap(llvm::Intrinsic::getDeclaration(
1569-
unwrap(M), llvm::Intrinsic::instrprof_mcdc_tvbitmap_update));
1570-
#endif
1571-
}
1572-
15731534
extern "C" LLVMValueRef LLVMRustBuildMemCpy(LLVMBuilderRef B, LLVMValueRef Dst,
15741535
unsigned DstAlign, LLVMValueRef Src,
15751536
unsigned SrcAlign,

compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,15 @@ where
100100
})
101101
}
102102

103+
/// Assemble additional assumptions for an alias that are not included
104+
/// in the item bounds of the alias. For now, this is limited to the
105+
/// `implied_const_bounds` for an associated type.
106+
fn consider_additional_alias_assumptions(
107+
ecx: &mut EvalCtxt<'_, D>,
108+
goal: Goal<I, Self>,
109+
alias_ty: ty::AliasTy<I>,
110+
) -> Vec<Candidate<I>>;
111+
103112
fn consider_impl_candidate(
104113
ecx: &mut EvalCtxt<'_, D>,
105114
goal: Goal<I, Self>,
@@ -594,6 +603,8 @@ where
594603
));
595604
}
596605

606+
candidates.extend(G::consider_additional_alias_assumptions(self, goal, alias_ty));
607+
597608
if kind != ty::Projection {
598609
return;
599610
}

compiler/rustc_next_trait_solver/src/solve/effect_goals.rs

+50-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
use rustc_type_ir::fast_reject::DeepRejectCtxt;
55
use rustc_type_ir::inherent::*;
6-
use rustc_type_ir::{self as ty, Interner};
6+
use rustc_type_ir::{self as ty, Interner, elaborate};
77
use tracing::instrument;
88

99
use super::assembly::Candidate;
@@ -70,6 +70,55 @@ where
7070
}
7171
}
7272

73+
/// Register additional assumptions for aliases corresponding to `~const` item bounds.
74+
///
75+
/// Unlike item bounds, they are not simply implied by the well-formedness of the alias.
76+
/// Instead, they only hold if the const conditons on the alias also hold. This is why
77+
/// we also register the const conditions of the alias after matching the goal against
78+
/// the assumption.
79+
fn consider_additional_alias_assumptions(
80+
ecx: &mut EvalCtxt<'_, D>,
81+
goal: Goal<I, Self>,
82+
alias_ty: ty::AliasTy<I>,
83+
) -> Vec<Candidate<I>> {
84+
let cx = ecx.cx();
85+
let mut candidates = vec![];
86+
87+
// FIXME(effects): We elaborate here because the implied const bounds
88+
// aren't necessarily elaborated. We probably should prefix this query
89+
// with `explicit_`...
90+
for clause in elaborate::elaborate(
91+
cx,
92+
cx.implied_const_bounds(alias_ty.def_id)
93+
.iter_instantiated(cx, alias_ty.args)
94+
.map(|trait_ref| trait_ref.to_host_effect_clause(cx, goal.predicate.host)),
95+
) {
96+
candidates.extend(Self::probe_and_match_goal_against_assumption(
97+
ecx,
98+
CandidateSource::AliasBound,
99+
goal,
100+
clause,
101+
|ecx| {
102+
// Const conditions must hold for the implied const bound to hold.
103+
ecx.add_goals(
104+
GoalSource::Misc,
105+
cx.const_conditions(alias_ty.def_id)
106+
.iter_instantiated(cx, alias_ty.args)
107+
.map(|trait_ref| {
108+
goal.with(
109+
cx,
110+
trait_ref.to_host_effect_clause(cx, goal.predicate.host),
111+
)
112+
}),
113+
);
114+
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
115+
},
116+
));
117+
}
118+
119+
candidates
120+
}
121+
73122
fn consider_impl_candidate(
74123
ecx: &mut EvalCtxt<'_, D>,
75124
goal: Goal<I, Self>,

compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,14 @@ where
193193
}
194194
}
195195

196+
fn consider_additional_alias_assumptions(
197+
_ecx: &mut EvalCtxt<'_, D>,
198+
_goal: Goal<I, Self>,
199+
_alias_ty: ty::AliasTy<I>,
200+
) -> Vec<Candidate<I>> {
201+
vec![]
202+
}
203+
196204
fn consider_impl_candidate(
197205
ecx: &mut EvalCtxt<'_, D>,
198206
goal: Goal<I, NormalizesTo<I>>,

compiler/rustc_next_trait_solver/src/solve/trait_goals.rs

+8
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ where
3939
self.def_id()
4040
}
4141

42+
fn consider_additional_alias_assumptions(
43+
_ecx: &mut EvalCtxt<'_, D>,
44+
_goal: Goal<I, Self>,
45+
_alias_ty: ty::AliasTy<I>,
46+
) -> Vec<Candidate<I>> {
47+
vec![]
48+
}
49+
4250
fn consider_impl_candidate(
4351
ecx: &mut EvalCtxt<'_, D>,
4452
goal: Goal<I, TraitPredicate<I>>,

0 commit comments

Comments
 (0)