Skip to content

Commit f3ff2f1

Browse files
committed
Auto merge of rust-lang#125761 - matthiaskrgr:rollup-7u082og, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#125342 (Document platform-specifics for `Read` and `Write` of `File`) - rust-lang#125711 (Make `body_owned_by` return the `Body` instead of just the `BodyId`) - rust-lang#125739 (drop_in_place: weaken the claim of equivalence with drop(ptr.read())) - rust-lang#125745 (Bump the stage0 compiler to beta.7 (2024-05-26)) - rust-lang#125746 (Fix copy-paste error in `Duration::from_weeks` panic message.) - rust-lang#125753 (compiletest: Unify `cmd2procres` with `run_command_to_procres`) - rust-lang#125754 (coverage: Rename MC/DC `conditions_num` to `num_conditions`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d43930d + 479d6ca commit f3ff2f1

File tree

16 files changed

+576
-492
lines changed

16 files changed

+576
-492
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ pub mod mcdc {
118118
#[derive(Clone, Copy, Debug, Default)]
119119
pub struct DecisionParameters {
120120
bitmap_idx: u32,
121-
conditions_num: u16,
121+
num_conditions: u16,
122122
}
123123

124124
// ConditionId in llvm is `unsigned int` at 18 while `int16_t` at [19](https://github.com/llvm/llvm-project/pull/81257)
@@ -177,8 +177,9 @@ pub mod mcdc {
177177
}
178178

179179
impl From<DecisionInfo> for DecisionParameters {
180-
fn from(value: DecisionInfo) -> Self {
181-
Self { bitmap_idx: value.bitmap_idx, conditions_num: value.conditions_num }
180+
fn from(info: DecisionInfo) -> Self {
181+
let DecisionInfo { bitmap_idx, num_conditions } = info;
182+
Self { bitmap_idx, num_conditions }
182183
}
183184
}
184185
}

compiler/rustc_middle/src/mir/coverage.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,14 @@ pub struct MCDCBranchSpan {
329329
#[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
330330
pub struct DecisionInfo {
331331
pub bitmap_idx: u32,
332-
pub conditions_num: u16,
332+
pub num_conditions: u16,
333333
}
334334

335335
#[derive(Clone, Debug)]
336336
#[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
337337
pub struct MCDCDecisionSpan {
338338
pub span: Span,
339-
pub conditions_num: usize,
339+
pub num_conditions: usize,
340340
pub end_markers: Vec<BlockMarkerId>,
341341
pub decision_depth: u16,
342342
}

compiler/rustc_middle/src/mir/pretty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -512,12 +512,12 @@ fn write_coverage_branch_info(
512512
)?;
513513
}
514514

515-
for coverage::MCDCDecisionSpan { span, conditions_num, end_markers, decision_depth } in
515+
for coverage::MCDCDecisionSpan { span, num_conditions, end_markers, decision_depth } in
516516
mcdc_decision_spans
517517
{
518518
writeln!(
519519
w,
520-
"{INDENT}coverage mcdc decision {{ conditions_num: {conditions_num:?}, end: {end_markers:?}, depth: {decision_depth:?} }} => {span:?}"
520+
"{INDENT}coverage mcdc decision {{ num_conditions: {num_conditions:?}, end: {end_markers:?}, depth: {decision_depth:?} }} => {span:?}"
521521
)?;
522522
}
523523

compiler/rustc_mir_build/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ mir_build_deref_raw_pointer_requires_unsafe_unsafe_op_in_unsafe_fn_allowed =
9797
.note = raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior
9898
.label = dereference of raw pointer
9999
100-
mir_build_exceeds_mcdc_condition_num_limit = Conditions number of the decision ({$conditions_num}) exceeds limit ({$max_conditions_num}). MCDC analysis will not count this expression.
100+
mir_build_exceeds_mcdc_condition_limit = Number of conditions in decision ({$num_conditions}) exceeds limit ({$max_conditions}). MC/DC analysis will not count this expression.
101101
102102
mir_build_extern_static_requires_unsafe =
103103
use of extern static is unsafe and requires unsafe block

compiler/rustc_mir_build/src/build/coverageinfo/mcdc.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ use rustc_middle::ty::TyCtxt;
1010
use rustc_span::Span;
1111

1212
use crate::build::Builder;
13-
use crate::errors::MCDCExceedsConditionNumLimit;
13+
use crate::errors::MCDCExceedsConditionLimit;
1414

1515
/// The MCDC bitmap scales exponentially (2^n) based on the number of conditions seen,
1616
/// So llvm sets a maximum value prevents the bitmap footprint from growing too large without the user's knowledge.
1717
/// This limit may be relaxed if the [upstream change](https://github.com/llvm/llvm-project/pull/82448) is merged.
18-
const MAX_CONDITIONS_NUM_IN_DECISION: usize = 6;
18+
const MAX_CONDITIONS_IN_DECISION: usize = 6;
1919

2020
#[derive(Default)]
2121
struct MCDCDecisionCtx {
@@ -100,22 +100,22 @@ impl MCDCState {
100100
}
101101
None => decision_ctx.processing_decision.insert(MCDCDecisionSpan {
102102
span,
103-
conditions_num: 0,
103+
num_conditions: 0,
104104
end_markers: vec![],
105105
decision_depth,
106106
}),
107107
};
108108

109109
let parent_condition = decision_ctx.decision_stack.pop_back().unwrap_or_default();
110110
let lhs_id = if parent_condition.condition_id == ConditionId::NONE {
111-
decision.conditions_num += 1;
112-
ConditionId::from(decision.conditions_num)
111+
decision.num_conditions += 1;
112+
ConditionId::from(decision.num_conditions)
113113
} else {
114114
parent_condition.condition_id
115115
};
116116

117-
decision.conditions_num += 1;
118-
let rhs_condition_id = ConditionId::from(decision.conditions_num);
117+
decision.num_conditions += 1;
118+
let rhs_condition_id = ConditionId::from(decision.num_conditions);
119119

120120
let (lhs, rhs) = match op {
121121
LogicalOp::And => {
@@ -208,28 +208,28 @@ impl MCDCInfoBuilder {
208208
// is empty, i.e. when all the conditions of the decision were instrumented,
209209
// and the decision is "complete".
210210
if let Some(decision) = decision_result {
211-
match decision.conditions_num {
211+
match decision.num_conditions {
212212
0 => {
213213
unreachable!("Decision with no condition is not expected");
214214
}
215-
1..=MAX_CONDITIONS_NUM_IN_DECISION => {
215+
1..=MAX_CONDITIONS_IN_DECISION => {
216216
self.decision_spans.push(decision);
217217
}
218218
_ => {
219219
// Do not generate mcdc mappings and statements for decisions with too many conditions.
220220
// Therefore, first erase the condition info of the (N-1) previous branch spans.
221-
let rebase_idx = self.branch_spans.len() - (decision.conditions_num - 1);
221+
let rebase_idx = self.branch_spans.len() - (decision.num_conditions - 1);
222222
for branch in &mut self.branch_spans[rebase_idx..] {
223223
branch.condition_info = None;
224224
}
225225

226226
// Then, erase this last branch span's info too, for a total of N.
227227
condition_info = None;
228228

229-
tcx.dcx().emit_warn(MCDCExceedsConditionNumLimit {
229+
tcx.dcx().emit_warn(MCDCExceedsConditionLimit {
230230
span: decision.span,
231-
conditions_num: decision.conditions_num,
232-
max_conditions_num: MAX_CONDITIONS_NUM_IN_DECISION,
231+
num_conditions: decision.num_conditions,
232+
max_conditions: MAX_CONDITIONS_IN_DECISION,
233233
});
234234
}
235235
}

compiler/rustc_mir_build/src/errors.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -812,12 +812,12 @@ pub struct NonEmptyNeverPattern<'tcx> {
812812
}
813813

814814
#[derive(Diagnostic)]
815-
#[diag(mir_build_exceeds_mcdc_condition_num_limit)]
816-
pub(crate) struct MCDCExceedsConditionNumLimit {
815+
#[diag(mir_build_exceeds_mcdc_condition_limit)]
816+
pub(crate) struct MCDCExceedsConditionLimit {
817817
#[primary_span]
818818
pub span: Span,
819-
pub conditions_num: usize,
820-
pub max_conditions_num: usize,
819+
pub num_conditions: usize,
820+
pub max_conditions: usize,
821821
}
822822

823823
#[derive(Diagnostic)]

compiler/rustc_mir_transform/src/coverage/mappings.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub(super) struct MCDCDecision {
4848
pub(super) span: Span,
4949
pub(super) end_bcbs: BTreeSet<BasicCoverageBlock>,
5050
pub(super) bitmap_idx: u32,
51-
pub(super) conditions_num: u16,
51+
pub(super) num_conditions: u16,
5252
pub(super) decision_depth: u16,
5353
}
5454

@@ -268,13 +268,13 @@ pub(super) fn extract_mcdc_mappings(
268268
// the bitmap, rounded up to a whole number of bytes.
269269
// The decision's "bitmap index" points to its first byte in the bitmap.
270270
let bitmap_idx = *mcdc_bitmap_bytes;
271-
*mcdc_bitmap_bytes += (1_u32 << decision.conditions_num).div_ceil(8);
271+
*mcdc_bitmap_bytes += (1_u32 << decision.num_conditions).div_ceil(8);
272272

273273
Some(MCDCDecision {
274274
span,
275275
end_bcbs,
276276
bitmap_idx,
277-
conditions_num: decision.conditions_num as u16,
277+
num_conditions: decision.num_conditions as u16,
278278
decision_depth: decision.decision_depth,
279279
})
280280
},

compiler/rustc_mir_transform/src/coverage/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ fn create_mappings<'tcx>(
195195
));
196196

197197
mappings.extend(mcdc_decisions.iter().filter_map(
198-
|&mappings::MCDCDecision { span, bitmap_idx, conditions_num, .. }| {
198+
|&mappings::MCDCDecision { span, bitmap_idx, num_conditions, .. }| {
199199
let code_region = region_for_span(span)?;
200-
let kind = MappingKind::MCDCDecision(DecisionInfo { bitmap_idx, conditions_num });
200+
let kind = MappingKind::MCDCDecision(DecisionInfo { bitmap_idx, num_conditions });
201201
Some(Mapping { kind, code_region })
202202
},
203203
));
@@ -269,7 +269,7 @@ fn inject_mcdc_statements<'tcx>(
269269
span: _,
270270
ref end_bcbs,
271271
bitmap_idx,
272-
conditions_num: _,
272+
num_conditions: _,
273273
decision_depth,
274274
} in &extracted_mappings.mcdc_decisions
275275
{

library/core/src/ptr/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,13 @@ mod mut_ptr;
450450

451451
/// Executes the destructor (if any) of the pointed-to value.
452452
///
453-
/// This is semantically equivalent to calling [`ptr::read`] and discarding
453+
/// This is almost the same as calling [`ptr::read`] and discarding
454454
/// the result, but has the following advantages:
455+
// FIXME: say something more useful than "almost the same"?
456+
// There are open questions here: `read` requires the value to be fully valid, e.g. if `T` is a
457+
// `bool` it must be 0 or 1, if it is a reference then it must be dereferenceable. `drop_in_place`
458+
// only requires that `*to_drop` be "valid for dropping" and we have not defined what that means. In
459+
// Miri it currently (May 2024) requires nothing at all for types without drop glue.
455460
///
456461
/// * It is *required* to use `drop_in_place` to drop unsized types like
457462
/// trait objects, because they can't be read out onto the stack and

library/core/src/time.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ impl Duration {
348348
#[inline]
349349
pub const fn from_weeks(weeks: u64) -> Duration {
350350
if weeks > u64::MAX / (SECS_PER_MINUTE * MINS_PER_HOUR * HOURS_PER_DAY * DAYS_PER_WEEK) {
351-
panic!("overflow in Duration::from_days");
351+
panic!("overflow in Duration::from_weeks");
352352
}
353353

354354
Duration::from_secs(weeks * MINS_PER_HOUR * SECS_PER_MINUTE * HOURS_PER_DAY * DAYS_PER_WEEK)

library/std/src/fs.rs

+76
Original file line numberDiff line numberDiff line change
@@ -767,11 +767,33 @@ fn buffer_capacity_required(mut file: &File) -> Option<usize> {
767767

768768
#[stable(feature = "rust1", since = "1.0.0")]
769769
impl Read for &File {
770+
/// Read some bytes from the file.
771+
///
772+
/// See [`Read::read`] docs for more info.
773+
///
774+
/// # Platform-specific behavior
775+
///
776+
/// This function currently corresponds to the `read` function on Unix and
777+
/// the `NtReadFile` function on Windows. Note that this [may change in
778+
/// the future][changes].
779+
///
780+
/// [changes]: io#platform-specific-behavior
770781
#[inline]
771782
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
772783
self.inner.read(buf)
773784
}
774785

786+
/// Like `read`, except that it reads into a slice of buffers.
787+
///
788+
/// See [`Read::read_vectored`] docs for more info.
789+
///
790+
/// # Platform-specific behavior
791+
///
792+
/// This function currently corresponds to the `readv` function on Unix and
793+
/// falls back to the `read` implementation on Windows. Note that this
794+
/// [may change in the future][changes].
795+
///
796+
/// [changes]: io#platform-specific-behavior
775797
#[inline]
776798
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
777799
self.inner.read_vectored(bufs)
@@ -782,6 +804,16 @@ impl Read for &File {
782804
self.inner.read_buf(cursor)
783805
}
784806

807+
/// Determines if `File` has an efficient `read_vectored` implementation.
808+
///
809+
/// See [`Read::is_read_vectored`] docs for more info.
810+
///
811+
/// # Platform-specific behavior
812+
///
813+
/// This function currently returns `true` on Unix an `false` on Windows.
814+
/// Note that this [may change in the future][changes].
815+
///
816+
/// [changes]: io#platform-specific-behavior
785817
#[inline]
786818
fn is_read_vectored(&self) -> bool {
787819
self.inner.is_read_vectored()
@@ -803,19 +835,63 @@ impl Read for &File {
803835
}
804836
#[stable(feature = "rust1", since = "1.0.0")]
805837
impl Write for &File {
838+
/// Write some bytes from the file.
839+
///
840+
/// See [`Write::write`] docs for more info.
841+
///
842+
/// # Platform-specific behavior
843+
///
844+
/// This function currently corresponds to the `write` function on Unix and
845+
/// the `NtWriteFile` function on Windows. Note that this [may change in
846+
/// the future][changes].
847+
///
848+
/// [changes]: io#platform-specific-behavior
806849
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
807850
self.inner.write(buf)
808851
}
809852

853+
/// Like `write`, except that it writes into a slice of buffers.
854+
///
855+
/// See [`Write::write_vectored`] docs for more info.
856+
///
857+
/// # Platform-specific behavior
858+
///
859+
/// This function currently corresponds to the `writev` function on Unix
860+
/// and falls back to the `write` implementation on Windows. Note that this
861+
/// [may change in the future][changes].
862+
///
863+
/// [changes]: io#platform-specific-behavior
810864
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
811865
self.inner.write_vectored(bufs)
812866
}
813867

868+
/// Determines if `File` has an efficient `write_vectored` implementation.
869+
///
870+
/// See [`Write::is_write_vectored`] docs for more info.
871+
///
872+
/// # Platform-specific behavior
873+
///
874+
/// This function currently returns `true` on Unix an `false` on Windows.
875+
/// Note that this [may change in the future][changes].
876+
///
877+
/// [changes]: io#platform-specific-behavior
814878
#[inline]
815879
fn is_write_vectored(&self) -> bool {
816880
self.inner.is_write_vectored()
817881
}
818882

883+
/// Flushes the file, ensuring that all intermediately buffered contents
884+
/// reach their destination.
885+
///
886+
/// See [`Write::flush`] docs for more info.
887+
///
888+
/// # Platform-specific behavior
889+
///
890+
/// Since a `File` structure doesn't contain any buffers, this function is
891+
/// currently a no-op on Unix and Windows. Note that this [may change in
892+
/// the future][changes].
893+
///
894+
/// [changes]: io#platform-specific-behavior
819895
#[inline]
820896
fn flush(&mut self) -> io::Result<()> {
821897
self.inner.flush()

0 commit comments

Comments
 (0)