Skip to content

Commit 9eb6f32

Browse files
committed
Use normal newtype_index macro for MIR dataflow
1 parent a89c03a commit 9eb6f32

File tree

8 files changed

+30
-76
lines changed

8 files changed

+30
-76
lines changed

src/librustc_mir/borrow_check/error_reporting.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ use super::borrow_set::BorrowData;
2525
use super::{Context, MirBorrowckCtxt};
2626
use super::{InitializationRequiringAction, PrefixSet};
2727
use crate::dataflow::drop_flag_effects;
28-
use crate::dataflow::move_paths::indexes::MoveOutIndex;
29-
use crate::dataflow::move_paths::MovePathIndex;
28+
use crate::dataflow::indexes::{MovePathIndex, MoveOutIndex};
3029
use crate::util::borrowck_errors::{BorrowckErrors, Origin};
3130

3231
#[derive(Debug)]

src/librustc_mir/borrow_check/flows.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::borrow_check::location::LocationIndex;
1111

1212
use polonius_engine::Output;
1313

14-
use crate::dataflow::move_paths::indexes::BorrowIndex;
14+
use crate::dataflow::indexes::BorrowIndex;
1515
use crate::dataflow::move_paths::HasMoveData;
1616
use crate::dataflow::Borrows;
1717
use crate::dataflow::EverInitializedPlaces;

src/librustc_mir/borrow_check/nll/facts.rs

-12
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,6 @@ impl Atom for BorrowIndex {
7272
}
7373
}
7474

75-
impl From<usize> for BorrowIndex {
76-
fn from(i: usize) -> BorrowIndex {
77-
BorrowIndex::new(i)
78-
}
79-
}
80-
81-
impl From<BorrowIndex> for usize {
82-
fn from(vid: BorrowIndex) -> usize {
83-
Idx::index(vid)
84-
}
85-
}
86-
8775
impl Atom for LocationIndex {
8876
fn index(self) -> usize {
8977
Idx::index(self)

src/librustc_mir/borrow_check/nll/invalidation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::borrow_check::ArtificialField;
99
use crate::borrow_check::{ReadKind, WriteKind};
1010
use crate::borrow_check::nll::facts::AllFacts;
1111
use crate::borrow_check::path_utils::*;
12-
use crate::dataflow::move_paths::indexes::BorrowIndex;
12+
use crate::dataflow::indexes::BorrowIndex;
1313
use rustc::ty::TyCtxt;
1414
use rustc::mir::visit::Visitor;
1515
use rustc::mir::{BasicBlock, Location, Mir, Place, PlaceBase, Rvalue};

src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::borrow_check::nll::region_infer::values::{self, PointIndex, RegionVal
33
use crate::borrow_check::nll::type_check::liveness::local_use_map::LocalUseMap;
44
use crate::borrow_check::nll::type_check::NormalizeLocation;
55
use crate::borrow_check::nll::type_check::TypeChecker;
6-
use crate::dataflow::move_paths::indexes::MovePathIndex;
6+
use crate::dataflow::indexes::MovePathIndex;
77
use crate::dataflow::move_paths::MoveData;
88
use crate::dataflow::{FlowAtLocation, FlowsAtLocation, MaybeInitializedPlaces};
99
use rustc::infer::canonical::QueryRegionConstraint;

src/librustc_mir/dataflow/impls/borrows.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ use rustc_data_structures::fx::FxHashMap;
1010
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
1111

1212
use crate::dataflow::{BitDenotation, BlockSets, InitialFlow};
13-
pub use crate::dataflow::indexes::BorrowIndex;
1413
use crate::borrow_check::nll::region_infer::RegionInferenceContext;
1514
use crate::borrow_check::nll::ToRegionVid;
1615
use crate::borrow_check::places_conflict;
1716

1817
use std::rc::Rc;
1918

19+
newtype_index! {
20+
pub struct BorrowIndex {
21+
DEBUG_FORMAT = "bw{}"
22+
}
23+
}
24+
2025
/// `Borrows` stores the data used in the analyses that track the flow
2126
/// of borrows.
2227
///

src/librustc_mir/dataflow/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ mod graphviz;
3333
mod impls;
3434
pub mod move_paths;
3535

36-
pub(crate) use self::move_paths::indexes;
36+
pub(crate) mod indexes {
37+
pub(crate) use super::{
38+
move_paths::{MovePathIndex, MoveOutIndex, InitIndex},
39+
impls::borrows::BorrowIndex,
40+
};
41+
}
3742

3843
pub(crate) struct DataflowBuilder<'a, 'tcx: 'a, BD>
3944
where

src/librustc_mir/dataflow/move_paths/mod.rs

+14-57
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc::ty::{self, TyCtxt};
22
use rustc::mir::*;
33
use rustc::util::nodemap::FxHashMap;
4-
use rustc_data_structures::indexed_vec::{IndexVec};
4+
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
55
use smallvec::SmallVec;
66
use syntax_pos::{Span};
77

@@ -12,66 +12,23 @@ use self::abs_domain::{AbstractElem, Lift};
1212

1313
mod abs_domain;
1414

15-
// This submodule holds some newtype'd Index wrappers that are using
16-
// NonZero to ensure that Option<Index> occupies only a single word.
17-
// They are in a submodule to impose privacy restrictions; namely, to
18-
// ensure that other code does not accidentally access `index.0`
19-
// (which is likely to yield a subtle off-by-one error).
20-
pub(crate) mod indexes {
21-
use std::fmt;
22-
use std::num::NonZeroUsize;
23-
use rustc_data_structures::indexed_vec::Idx;
24-
25-
macro_rules! new_index {
26-
($(#[$attrs:meta])* $Index:ident, $debug_name:expr) => {
27-
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
28-
pub struct $Index(NonZeroUsize);
29-
30-
impl Idx for $Index {
31-
fn new(idx: usize) -> Self {
32-
$Index(NonZeroUsize::new(idx + 1).unwrap())
33-
}
34-
fn index(self) -> usize {
35-
self.0.get() - 1
36-
}
37-
}
38-
39-
impl fmt::Debug for $Index {
40-
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
41-
write!(fmt, "{}{}", $debug_name, self.index())
42-
}
43-
}
44-
}
15+
newtype_index! {
16+
pub struct MovePathIndex {
17+
DEBUG_FORMAT = "mp{}"
4518
}
19+
}
4620

47-
new_index!(
48-
/// Index into MovePathData.move_paths
49-
MovePathIndex,
50-
"mp"
51-
);
52-
53-
new_index!(
54-
/// Index into MoveData.moves.
55-
MoveOutIndex,
56-
"mo"
57-
);
58-
59-
new_index!(
60-
/// Index into MoveData.inits.
61-
InitIndex,
62-
"in"
63-
);
64-
65-
new_index!(
66-
/// Index into Borrows.locations
67-
BorrowIndex,
68-
"bw"
69-
);
21+
newtype_index! {
22+
pub struct MoveOutIndex {
23+
DEBUG_FORMAT = "mo{}"
24+
}
7025
}
7126

72-
pub use self::indexes::MovePathIndex;
73-
pub use self::indexes::MoveOutIndex;
74-
pub use self::indexes::InitIndex;
27+
newtype_index! {
28+
pub struct InitIndex {
29+
DEBUG_FORMAT = "in{}"
30+
}
31+
}
7532

7633
impl MoveOutIndex {
7734
pub fn move_path_index(&self, move_data: &MoveData<'_>) -> MovePathIndex {

0 commit comments

Comments
 (0)