Skip to content

Commit ae3e8c6

Browse files
committed
Auto merge of #140751 - GuillaumeGomez:rollup-eahw4ta, r=GuillaumeGomez
Rollup of 8 pull requests Successful merges: - #140234 (Separate dataflow analysis and results) - #140614 (Correct warning message in restricted visibility) - #140671 (Parser: Recover error from named params while parse_path) - #140700 (Don't crash on error codes passed to `--explain` which exceed our internal limit of 9999 ) - #140706 ([rustdoc] Ensure that temporary doctest folder is correctly removed even if doctests failed) - #140734 (Fix regression from #140393 for espidf / horizon / nuttx / vita) - #140741 (add armv5te-unknown-linux-gnueabi target maintainer) - #140745 (run-make-support: set rustc dylib path for cargo wrapper) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e9f8103 + 5e5043d commit ae3e8c6

Some content is hidden

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

52 files changed

+643
-292
lines changed

compiler/rustc_borrowck/src/lib.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use rustc_mir_dataflow::impls::{
4747
use rustc_mir_dataflow::move_paths::{
4848
InitIndex, InitLocation, LookupResult, MoveData, MovePathIndex,
4949
};
50-
use rustc_mir_dataflow::{Analysis, EntryStates, Results, ResultsVisitor, visit_results};
50+
use rustc_mir_dataflow::{Analysis, Results, ResultsVisitor, visit_results};
5151
use rustc_session::lint::builtin::{TAIL_EXPR_DROP_ORDER, UNUSED_MUT};
5252
use rustc_span::{ErrorGuaranteed, Span, Symbol};
5353
use smallvec::SmallVec;
@@ -469,11 +469,13 @@ fn do_mir_borrowck<'tcx>(
469469
// Compute and report region errors, if any.
470470
mbcx.report_region_errors(nll_errors);
471471

472-
let mut flow_results = get_flow_results(tcx, body, &move_data, &borrow_set, &regioncx);
472+
let (mut flow_analysis, flow_entry_states) =
473+
get_flow_results(tcx, body, &move_data, &borrow_set, &regioncx);
473474
visit_results(
474475
body,
475476
traversal::reverse_postorder(body).map(|(bb, _)| bb),
476-
&mut flow_results,
477+
&mut flow_analysis,
478+
&flow_entry_states,
477479
&mut mbcx,
478480
);
479481

@@ -533,7 +535,7 @@ fn get_flow_results<'a, 'tcx>(
533535
move_data: &'a MoveData<'tcx>,
534536
borrow_set: &'a BorrowSet<'tcx>,
535537
regioncx: &RegionInferenceContext<'tcx>,
536-
) -> Results<'tcx, Borrowck<'a, 'tcx>> {
538+
) -> (Borrowck<'a, 'tcx>, Results<BorrowckDomain>) {
537539
// We compute these three analyses individually, but them combine them into
538540
// a single results so that `mbcx` can visit them all together.
539541
let borrows = Borrows::new(tcx, body, regioncx, borrow_set).iterate_to_fixpoint(
@@ -558,14 +560,14 @@ fn get_flow_results<'a, 'tcx>(
558560
ever_inits: ever_inits.analysis,
559561
};
560562

561-
assert_eq!(borrows.entry_states.len(), uninits.entry_states.len());
562-
assert_eq!(borrows.entry_states.len(), ever_inits.entry_states.len());
563-
let entry_states: EntryStates<'_, Borrowck<'_, '_>> =
564-
itertools::izip!(borrows.entry_states, uninits.entry_states, ever_inits.entry_states)
563+
assert_eq!(borrows.results.len(), uninits.results.len());
564+
assert_eq!(borrows.results.len(), ever_inits.results.len());
565+
let results: Results<_> =
566+
itertools::izip!(borrows.results, uninits.results, ever_inits.results)
565567
.map(|(borrows, uninits, ever_inits)| BorrowckDomain { borrows, uninits, ever_inits })
566568
.collect();
567569

568-
Results { analysis, entry_states }
570+
(analysis, results)
569571
}
570572

571573
pub(crate) struct BorrowckInferCtxt<'tcx> {
@@ -713,7 +715,7 @@ struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
713715
impl<'a, 'tcx> ResultsVisitor<'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<'a, '_, 'tcx> {
714716
fn visit_after_early_statement_effect(
715717
&mut self,
716-
_results: &mut Results<'tcx, Borrowck<'a, 'tcx>>,
718+
_analysis: &mut Borrowck<'a, 'tcx>,
717719
state: &BorrowckDomain,
718720
stmt: &Statement<'tcx>,
719721
location: Location,
@@ -789,7 +791,7 @@ impl<'a, 'tcx> ResultsVisitor<'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<'a,
789791

790792
fn visit_after_early_terminator_effect(
791793
&mut self,
792-
_results: &mut Results<'tcx, Borrowck<'a, 'tcx>>,
794+
_analysis: &mut Borrowck<'a, 'tcx>,
793795
state: &BorrowckDomain,
794796
term: &Terminator<'tcx>,
795797
loc: Location,
@@ -909,7 +911,7 @@ impl<'a, 'tcx> ResultsVisitor<'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<'a,
909911

910912
fn visit_after_primary_terminator_effect(
911913
&mut self,
912-
_results: &mut Results<'tcx, Borrowck<'a, 'tcx>>,
914+
_analysis: &mut Borrowck<'a, 'tcx>,
913915
state: &BorrowckDomain,
914916
term: &Terminator<'tcx>,
915917
loc: Location,

compiler/rustc_driver_impl/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ fn handle_explain(early_dcx: &EarlyDiagCtxt, registry: Registry, code: &str, col
463463
// Allow "E0123" or "0123" form.
464464
let upper_cased_code = code.to_ascii_uppercase();
465465
if let Ok(code) = upper_cased_code.strip_prefix('E').unwrap_or(&upper_cased_code).parse::<u32>()
466+
&& code <= ErrCode::MAX_AS_U32
466467
&& let Ok(description) = registry.try_find_description(ErrCode::from_u32(code))
467468
{
468469
let mut is_in_code_block = false;

compiler/rustc_middle/src/ty/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,10 @@ impl Visibility {
309309
} else if restricted_id == tcx.parent_module_from_def_id(def_id).to_local_def_id() {
310310
"pub(self)".to_string()
311311
} else {
312-
format!("pub({})", tcx.item_name(restricted_id.to_def_id()))
312+
format!(
313+
"pub(in crate{})",
314+
tcx.def_path(restricted_id.to_def_id()).to_string_no_crate_verbose()
315+
)
313316
}
314317
}
315318
ty::Visibility::Public => "pub".to_string(),

compiler/rustc_mir_dataflow/src/framework/cursor.rs

+47-31
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Random access inspection of the results of a dataflow analysis.
22
3+
use std::borrow::Cow;
34
use std::cmp::Ordering;
45
use std::ops::{Deref, DerefMut};
56

@@ -9,38 +10,30 @@ use rustc_middle::mir::{self, BasicBlock, Location};
910

1011
use super::{Analysis, Direction, Effect, EffectIndex, Results};
1112

12-
/// Some `ResultsCursor`s want to own a `Results`, and some want to borrow a `Results`, either
13-
/// mutable or immutably. This type allows all of the above. It's similar to `Cow`.
14-
pub enum ResultsHandle<'a, 'tcx, A>
15-
where
16-
A: Analysis<'tcx>,
17-
{
18-
BorrowedMut(&'a mut Results<'tcx, A>),
19-
Owned(Results<'tcx, A>),
13+
/// Some `ResultsCursor`s want to own an `Analysis`, and some want to borrow an `Analysis`, either
14+
/// mutable or immutably. This type allows all of the above. It's similar to `Cow`, but `Cow`
15+
/// doesn't allow mutable borrowing.
16+
enum CowMut<'a, T> {
17+
BorrowedMut(&'a mut T),
18+
Owned(T),
2019
}
2120

22-
impl<'tcx, A> Deref for ResultsHandle<'_, 'tcx, A>
23-
where
24-
A: Analysis<'tcx>,
25-
{
26-
type Target = Results<'tcx, A>;
21+
impl<T> Deref for CowMut<'_, T> {
22+
type Target = T;
2723

28-
fn deref(&self) -> &Results<'tcx, A> {
24+
fn deref(&self) -> &T {
2925
match self {
30-
ResultsHandle::BorrowedMut(borrowed) => borrowed,
31-
ResultsHandle::Owned(owned) => owned,
26+
CowMut::BorrowedMut(borrowed) => borrowed,
27+
CowMut::Owned(owned) => owned,
3228
}
3329
}
3430
}
3531

36-
impl<'tcx, A> DerefMut for ResultsHandle<'_, 'tcx, A>
37-
where
38-
A: Analysis<'tcx>,
39-
{
40-
fn deref_mut(&mut self) -> &mut Results<'tcx, A> {
32+
impl<T> DerefMut for CowMut<'_, T> {
33+
fn deref_mut(&mut self) -> &mut T {
4134
match self {
42-
ResultsHandle::BorrowedMut(borrowed) => borrowed,
43-
ResultsHandle::Owned(owned) => owned,
35+
CowMut::BorrowedMut(borrowed) => borrowed,
36+
CowMut::Owned(owned) => owned,
4437
}
4538
}
4639
}
@@ -60,7 +53,8 @@ where
6053
A: Analysis<'tcx>,
6154
{
6255
body: &'mir mir::Body<'tcx>,
63-
results: ResultsHandle<'mir, 'tcx, A>,
56+
analysis: CowMut<'mir, A>,
57+
results: Cow<'mir, Results<A::Domain>>,
6458
state: A::Domain,
6559

6660
pos: CursorPosition,
@@ -88,11 +82,15 @@ where
8882
self.body
8983
}
9084

91-
/// Returns a new cursor that can inspect `results`.
92-
pub fn new(body: &'mir mir::Body<'tcx>, results: ResultsHandle<'mir, 'tcx, A>) -> Self {
93-
let bottom_value = results.analysis.bottom_value(body);
85+
fn new(
86+
body: &'mir mir::Body<'tcx>,
87+
analysis: CowMut<'mir, A>,
88+
results: Cow<'mir, Results<A::Domain>>,
89+
) -> Self {
90+
let bottom_value = analysis.bottom_value(body);
9491
ResultsCursor {
9592
body,
93+
analysis,
9694
results,
9795

9896
// Initialize to the `bottom_value` and set `state_needs_reset` to tell the cursor that
@@ -107,6 +105,24 @@ where
107105
}
108106
}
109107

108+
/// Returns a new cursor that takes ownership of and inspects analysis results.
109+
pub fn new_owning(
110+
body: &'mir mir::Body<'tcx>,
111+
analysis: A,
112+
results: Results<A::Domain>,
113+
) -> Self {
114+
Self::new(body, CowMut::Owned(analysis), Cow::Owned(results))
115+
}
116+
117+
/// Returns a new cursor that borrows and inspects analysis results.
118+
pub fn new_borrowing(
119+
body: &'mir mir::Body<'tcx>,
120+
analysis: &'mir mut A,
121+
results: &'mir Results<A::Domain>,
122+
) -> Self {
123+
Self::new(body, CowMut::BorrowedMut(analysis), Cow::Borrowed(results))
124+
}
125+
110126
/// Allows inspection of unreachable basic blocks even with `debug_assertions` enabled.
111127
#[cfg(test)]
112128
pub(crate) fn allow_unreachable(&mut self) {
@@ -116,7 +132,7 @@ where
116132

117133
/// Returns the `Analysis` used to generate the underlying `Results`.
118134
pub fn analysis(&self) -> &A {
119-
&self.results.analysis
135+
&self.analysis
120136
}
121137

122138
/// Resets the cursor to hold the entry set for the given basic block.
@@ -128,7 +144,7 @@ where
128144
#[cfg(debug_assertions)]
129145
assert!(self.reachable_blocks.contains(block));
130146

131-
self.state.clone_from(self.results.entry_set_for_block(block));
147+
self.state.clone_from(&self.results[block]);
132148
self.pos = CursorPosition::block_entry(block);
133149
self.state_needs_reset = false;
134150
}
@@ -220,7 +236,7 @@ where
220236
let target_effect_index = effect.at_index(target.statement_index);
221237

222238
A::Direction::apply_effects_in_range(
223-
&mut self.results.analysis,
239+
&mut *self.analysis,
224240
&mut self.state,
225241
target.block,
226242
block_data,
@@ -236,7 +252,7 @@ where
236252
/// This can be used, e.g., to apply the call return effect directly to the cursor without
237253
/// creating an extra copy of the dataflow state.
238254
pub fn apply_custom_effect(&mut self, f: impl FnOnce(&mut A, &mut A::Domain)) {
239-
f(&mut self.results.analysis, &mut self.state);
255+
f(&mut self.analysis, &mut self.state);
240256
self.state_needs_reset = true;
241257
}
242258
}

compiler/rustc_mir_dataflow/src/framework/direction.rs

+22-26
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_middle::mir::{
55
};
66

77
use super::visitor::ResultsVisitor;
8-
use super::{Analysis, Effect, EffectIndex, Results};
8+
use super::{Analysis, Effect, EffectIndex};
99

1010
pub trait Direction {
1111
const IS_FORWARD: bool;
@@ -36,13 +36,13 @@ pub trait Direction {
3636
A: Analysis<'tcx>;
3737

3838
/// Called by `ResultsVisitor` to recompute the analysis domain values for
39-
/// all locations in a basic block (starting from the entry value stored
40-
/// in `Results`) and to visit them with `vis`.
39+
/// all locations in a basic block (starting from `entry_state` and to
40+
/// visit them with `vis`.
4141
fn visit_results_in_block<'mir, 'tcx, A>(
4242
state: &mut A::Domain,
4343
block: BasicBlock,
4444
block_data: &'mir mir::BasicBlockData<'tcx>,
45-
results: &mut Results<'tcx, A>,
45+
analysis: &mut A,
4646
vis: &mut impl ResultsVisitor<'tcx, A>,
4747
) where
4848
A: Analysis<'tcx>;
@@ -211,28 +211,26 @@ impl Direction for Backward {
211211
state: &mut A::Domain,
212212
block: BasicBlock,
213213
block_data: &'mir mir::BasicBlockData<'tcx>,
214-
results: &mut Results<'tcx, A>,
214+
analysis: &mut A,
215215
vis: &mut impl ResultsVisitor<'tcx, A>,
216216
) where
217217
A: Analysis<'tcx>,
218218
{
219-
state.clone_from(results.entry_set_for_block(block));
220-
221219
vis.visit_block_end(state);
222220

223221
let loc = Location { block, statement_index: block_data.statements.len() };
224222
let term = block_data.terminator();
225-
results.analysis.apply_early_terminator_effect(state, term, loc);
226-
vis.visit_after_early_terminator_effect(results, state, term, loc);
227-
results.analysis.apply_primary_terminator_effect(state, term, loc);
228-
vis.visit_after_primary_terminator_effect(results, state, term, loc);
223+
analysis.apply_early_terminator_effect(state, term, loc);
224+
vis.visit_after_early_terminator_effect(analysis, state, term, loc);
225+
analysis.apply_primary_terminator_effect(state, term, loc);
226+
vis.visit_after_primary_terminator_effect(analysis, state, term, loc);
229227

230228
for (statement_index, stmt) in block_data.statements.iter().enumerate().rev() {
231229
let loc = Location { block, statement_index };
232-
results.analysis.apply_early_statement_effect(state, stmt, loc);
233-
vis.visit_after_early_statement_effect(results, state, stmt, loc);
234-
results.analysis.apply_primary_statement_effect(state, stmt, loc);
235-
vis.visit_after_primary_statement_effect(results, state, stmt, loc);
230+
analysis.apply_early_statement_effect(state, stmt, loc);
231+
vis.visit_after_early_statement_effect(analysis, state, stmt, loc);
232+
analysis.apply_primary_statement_effect(state, stmt, loc);
233+
vis.visit_after_primary_statement_effect(analysis, state, stmt, loc);
236234
}
237235

238236
vis.visit_block_start(state);
@@ -393,29 +391,27 @@ impl Direction for Forward {
393391
state: &mut A::Domain,
394392
block: BasicBlock,
395393
block_data: &'mir mir::BasicBlockData<'tcx>,
396-
results: &mut Results<'tcx, A>,
394+
analysis: &mut A,
397395
vis: &mut impl ResultsVisitor<'tcx, A>,
398396
) where
399397
A: Analysis<'tcx>,
400398
{
401-
state.clone_from(results.entry_set_for_block(block));
402-
403399
vis.visit_block_start(state);
404400

405401
for (statement_index, stmt) in block_data.statements.iter().enumerate() {
406402
let loc = Location { block, statement_index };
407-
results.analysis.apply_early_statement_effect(state, stmt, loc);
408-
vis.visit_after_early_statement_effect(results, state, stmt, loc);
409-
results.analysis.apply_primary_statement_effect(state, stmt, loc);
410-
vis.visit_after_primary_statement_effect(results, state, stmt, loc);
403+
analysis.apply_early_statement_effect(state, stmt, loc);
404+
vis.visit_after_early_statement_effect(analysis, state, stmt, loc);
405+
analysis.apply_primary_statement_effect(state, stmt, loc);
406+
vis.visit_after_primary_statement_effect(analysis, state, stmt, loc);
411407
}
412408

413409
let loc = Location { block, statement_index: block_data.statements.len() };
414410
let term = block_data.terminator();
415-
results.analysis.apply_early_terminator_effect(state, term, loc);
416-
vis.visit_after_early_terminator_effect(results, state, term, loc);
417-
results.analysis.apply_primary_terminator_effect(state, term, loc);
418-
vis.visit_after_primary_terminator_effect(results, state, term, loc);
411+
analysis.apply_early_terminator_effect(state, term, loc);
412+
vis.visit_after_early_terminator_effect(analysis, state, term, loc);
413+
analysis.apply_primary_terminator_effect(state, term, loc);
414+
vis.visit_after_primary_terminator_effect(analysis, state, term, loc);
419415

420416
vis.visit_block_end(state);
421417
}

0 commit comments

Comments
 (0)