Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #99007

Closed
wants to merge 27 commits into from
Closed
Changes from 6 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
907ea55
Adapt tests to be able to run in miri
Noratrieb Jun 3, 2022
4d67f5b
Remove needless FIXME
camelid Jun 29, 2022
8192288
Replace weird handling of edge case with panic
camelid Jun 29, 2022
2d2fd31
Remove FIXME that hasn't been an issue in practice
camelid Jun 29, 2022
a2799b2
fix projectionelem validation
beepster4096 May 9, 2022
8371a03
incr: cache dwarf objects in work products
davidtwco Jul 4, 2022
fc641f2
ssa: remove dwo of metadata and allocator module
davidtwco Jul 6, 2022
e106523
ssa: abort if dwarf packaging fails
davidtwco Jul 6, 2022
211fb66
Fix stacked borrows violation in rustc_arena
Noratrieb Jun 3, 2022
14d288f
socket `set_mark` addition.
devnexen Apr 23, 2022
48ef00e
doc additions
devnexen Apr 27, 2022
10f5a19
changes from feedback
devnexen Jul 6, 2022
6c6388c
Document, that some lint have to be expected on the crate level (RFC …
xFrednet Jun 16, 2022
c8b4873
Add function to manually fulfill lint expectations (RFC 2383)
xFrednet Jun 16, 2022
a2810cd
Fix `#[expect]` and `#[allow]` for `clippy::duplicate_mod`
xFrednet Jun 25, 2022
c9dd1d9
Make MIR basic blocks field public
tmiasko Jul 4, 2022
2446b17
Move `is_cfg_cyclic` from Body to BasicBlocks
tmiasko Jul 5, 2022
39d9c1c
Move `predecessors` from Body to BasicBlocks
tmiasko Jul 5, 2022
dfa6a7c
Move `switch_sources` from Body to BasicBlocks
tmiasko Jul 5, 2022
17adfeb
Move `dominators` from Body to BasicBlocks
tmiasko Jul 5, 2022
691b371
Rollup merge of #96334 - devnexen:socket_mark, r=dtolnay
Dylan-DPC Jul 7, 2022
cc0d421
Rollup merge of #96856 - DrMeepster:fix_projection_validation, r=Icnr
Dylan-DPC Jul 7, 2022
19021fc
Rollup merge of #97711 - Nilstrieb:rustc-arena-ub, r=wesleywiser
Dylan-DPC Jul 7, 2022
469ca7e
Rollup merge of #98507 - xFrednet:rfc-2383-manual-expectation-magic, …
Dylan-DPC Jul 7, 2022
43ef6d0
Rollup merge of #98692 - camelid:more-fixmes, r=GuillaumeGomez
Dylan-DPC Jul 7, 2022
66e47df
Rollup merge of #98901 - davidtwco:split-dwarf-incr-workproduct, r=mi…
Dylan-DPC Jul 7, 2022
8d8aa2c
Rollup merge of #98930 - tmiasko:pub-basic-blocks, r=oli-obk
Dylan-DPC Jul 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
@@ -1628,7 +1628,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
location: Location,
) -> impl Iterator<Item = Location> + Captures<'tcx> + 'a {
if location.statement_index == 0 {
let predecessors = body.predecessors()[location.block].to_vec();
let predecessors = body.basic_blocks.predecessors()[location.block].to_vec();
Either::Left(predecessors.into_iter().map(move |bb| body.terminator_loc(bb)))
} else {
Either::Right(std::iter::once(Location {
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/invalidation.rs
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ pub(super) fn generate_invalidates<'tcx>(

if let Some(all_facts) = all_facts {
let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation");
let dominators = body.dominators();
let dominators = body.basic_blocks.dominators();
let mut ig = InvalidationGenerator {
all_facts,
borrow_set,
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
@@ -334,7 +334,7 @@ fn do_mir_borrowck<'a, 'tcx>(
};
}

let dominators = body.dominators();
let dominators = body.basic_blocks.dominators();

let mut mbcx = MirBorrowckCtxt {
infcx,
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/type_check/liveness/trace.rs
Original file line number Diff line number Diff line change
@@ -258,7 +258,7 @@ impl<'me, 'typeck, 'flow, 'tcx> LivenessResults<'me, 'typeck, 'flow, 'tcx> {

let block = self.cx.elements.to_location(block_start).block;
self.stack.extend(
self.cx.body.predecessors()[block]
self.cx.body.basic_blocks.predecessors()[block]
.iter()
.map(|&pred_bb| self.cx.body.terminator_loc(pred_bb))
.map(|pred_loc| self.cx.elements.point_from_location(pred_loc)),
@@ -354,7 +354,7 @@ impl<'me, 'typeck, 'flow, 'tcx> LivenessResults<'me, 'typeck, 'flow, 'tcx> {
}

let body = self.cx.body;
for &pred_block in body.predecessors()[block].iter() {
for &pred_block in body.basic_blocks.predecessors()[block].iter() {
debug!("compute_drop_live_points_for_block: pred_block = {:?}", pred_block,);

// Check whether the variable is (at least partially)
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/mir/analyze.rs
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ pub fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
fx: &FunctionCx<'a, 'tcx, Bx>,
) -> BitSet<mir::Local> {
let mir = fx.mir;
let dominators = mir.dominators();
let dominators = mir.basic_blocks.dominators();
let locals = mir
.local_decls
.iter()
5 changes: 3 additions & 2 deletions compiler/rustc_const_eval/src/transform/promote_consts.rs
Original file line number Diff line number Diff line change
@@ -856,7 +856,8 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
literal: ConstantKind::from_const(_const, tcx),
}))
};
let (blocks, local_decls) = self.source.basic_blocks_and_local_decls_mut();
let blocks = self.source.basic_blocks.as_mut();
let local_decls = &mut self.source.local_decls;
let loc = candidate.location;
let statement = &mut blocks[loc.block].statements[loc.statement_index];
match statement.kind {
@@ -865,7 +866,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
Rvalue::Ref(ref mut region, borrow_kind, ref mut place),
)) => {
// Use the underlying local for this (necessarily interior) borrow.
let ty = local_decls.local_decls()[place.local].ty;
let ty = local_decls[place.local].ty;
let span = statement.source_info.span;

let ref_ty = tcx.mk_ref(
147 changes: 147 additions & 0 deletions compiler/rustc_middle/src/mir/basic_blocks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
use crate::mir::graph_cyclic_cache::GraphIsCyclicCache;
use crate::mir::predecessors::{PredecessorCache, Predecessors};
use crate::mir::switch_sources::{SwitchSourceCache, SwitchSources};
use crate::mir::traversal::PostorderCache;
use crate::mir::{BasicBlock, BasicBlockData, Successors, START_BLOCK};

use rustc_data_structures::graph;
use rustc_data_structures::graph::dominators::{dominators, Dominators};
use rustc_index::vec::IndexVec;

#[derive(Clone, TyEncodable, TyDecodable, Debug, HashStable, TypeFoldable, TypeVisitable)]
pub struct BasicBlocks<'tcx> {
basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
predecessor_cache: PredecessorCache,
switch_source_cache: SwitchSourceCache,
is_cyclic: GraphIsCyclicCache,
postorder_cache: PostorderCache,
}

impl<'tcx> BasicBlocks<'tcx> {
#[inline]
pub fn new(basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>) -> Self {
BasicBlocks {
basic_blocks,
predecessor_cache: PredecessorCache::new(),
switch_source_cache: SwitchSourceCache::new(),
is_cyclic: GraphIsCyclicCache::new(),
postorder_cache: PostorderCache::new(),
}
}

/// Returns true if control-flow graph contains a cycle reachable from the `START_BLOCK`.
#[inline]
pub fn is_cfg_cyclic(&self) -> bool {
self.is_cyclic.is_cyclic(self)
}

#[inline]
pub fn dominators(&self) -> Dominators<BasicBlock> {
dominators(&self)
}

/// Returns predecessors for each basic block.
#[inline]
pub fn predecessors(&self) -> &Predecessors {
self.predecessor_cache.compute(&self.basic_blocks)
}

/// Returns basic blocks in a postorder.
#[inline]
pub fn postorder(&self) -> &[BasicBlock] {
self.postorder_cache.compute(&self.basic_blocks)
}

/// `switch_sources()[&(target, switch)]` returns a list of switch
/// values that lead to a `target` block from a `switch` block.
#[inline]
pub fn switch_sources(&self) -> &SwitchSources {
self.switch_source_cache.compute(&self.basic_blocks)
}

/// Returns mutable reference to basic blocks. Invalidates CFG cache.
#[inline]
pub fn as_mut(&mut self) -> &mut IndexVec<BasicBlock, BasicBlockData<'tcx>> {
self.invalidate_cfg_cache();
&mut self.basic_blocks
}

/// Get mutable access to basic blocks without invalidating the CFG cache.
///
/// By calling this method instead of e.g. [`BasicBlocks::as_mut`] you promise not to change
/// the CFG. This means that
///
/// 1) The number of basic blocks remains unchanged
/// 2) The set of successors of each terminator remains unchanged.
/// 3) For each `TerminatorKind::SwitchInt`, the `targets` remains the same and the terminator
/// kind is not changed.
///
/// If any of these conditions cannot be upheld, you should call [`BasicBlocks::invalidate_cfg_cache`].
#[inline]
pub fn as_mut_preserves_cfg(&mut self) -> &mut IndexVec<BasicBlock, BasicBlockData<'tcx>> {
&mut self.basic_blocks
}

/// Invalidates cached information about the CFG.
///
/// You will only ever need this if you have also called [`BasicBlocks::as_mut_preserves_cfg`].
/// All other methods that allow you to mutate the basic blocks also call this method
/// themselves, thereby avoiding any risk of accidentaly cache invalidation.
pub fn invalidate_cfg_cache(&mut self) {
self.predecessor_cache.invalidate();
self.switch_source_cache.invalidate();
self.is_cyclic.invalidate();
self.postorder_cache.invalidate();
}
}

impl<'tcx> std::ops::Deref for BasicBlocks<'tcx> {
type Target = IndexVec<BasicBlock, BasicBlockData<'tcx>>;

#[inline]
fn deref(&self) -> &IndexVec<BasicBlock, BasicBlockData<'tcx>> {
&self.basic_blocks
}
}

impl<'tcx> graph::DirectedGraph for BasicBlocks<'tcx> {
type Node = BasicBlock;
}

impl<'tcx> graph::WithNumNodes for BasicBlocks<'tcx> {
#[inline]
fn num_nodes(&self) -> usize {
self.basic_blocks.len()
}
}

impl<'tcx> graph::WithStartNode for BasicBlocks<'tcx> {
#[inline]
fn start_node(&self) -> Self::Node {
START_BLOCK
}
}

impl<'tcx> graph::WithSuccessors for BasicBlocks<'tcx> {
#[inline]
fn successors(&self, node: Self::Node) -> <Self as graph::GraphSuccessors<'_>>::Iter {
self.basic_blocks[node].terminator().successors()
}
}

impl<'a, 'b> graph::GraphSuccessors<'b> for BasicBlocks<'a> {
type Item = BasicBlock;
type Iter = Successors<'b>;
}

impl<'tcx, 'graph> graph::GraphPredecessors<'graph> for BasicBlocks<'tcx> {
type Item = BasicBlock;
type Iter = std::iter::Copied<std::slice::Iter<'graph, BasicBlock>>;
}

impl<'tcx> graph::WithPredecessors for BasicBlocks<'tcx> {
#[inline]
fn predecessors(&self, node: Self::Node) -> <Self as graph::GraphPredecessors<'_>>::Iter {
self.predecessors()[node].iter().copied()
}
}
Loading