Skip to content

Commit 583d5a7

Browse files
committed
Generate DepNodeIndexNew using newtype_index macro
1 parent caeb1ae commit 583d5a7

File tree

4 files changed

+12
-27
lines changed

4 files changed

+12
-27
lines changed

src/librustc/dep_graph/graph.rs

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ impl DepGraph {
367367
for (current_dep_node_index, edges) in current_dep_graph.edges.iter_enumerated() {
368368
let start = edge_list_data.len() as u32;
369369
// This should really just be a memcpy :/
370-
edge_list_data.extend(edges.iter().map(|i| SerializedDepNodeIndex(i.index)));
370+
edge_list_data.extend(edges.iter().map(|i| SerializedDepNodeIndex(i.index() as u32)));
371371
let end = edge_list_data.len() as u32;
372372

373373
debug_assert_eq!(current_dep_node_index.index(), edge_list_indices.len());
@@ -563,34 +563,10 @@ impl CurrentDepGraph {
563563
}
564564
}
565565

566-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
567-
pub(super) struct DepNodeIndexNew {
568-
index: u32,
569-
}
570-
571-
impl Idx for DepNodeIndexNew {
572-
fn new(idx: usize) -> Self {
573-
DepNodeIndexNew::new(idx)
574-
}
575-
fn index(self) -> usize {
576-
self.index()
577-
}
578-
}
566+
newtype_index!(DepNodeIndexNew);
579567

580568
impl DepNodeIndexNew {
581-
582-
const INVALID: DepNodeIndexNew = DepNodeIndexNew {
583-
index: ::std::u32::MAX,
584-
};
585-
586-
fn new(v: usize) -> DepNodeIndexNew {
587-
assert!((v & 0xFFFF_FFFF) == v);
588-
DepNodeIndexNew { index: v as u32 }
589-
}
590-
591-
fn index(self) -> usize {
592-
self.index as usize
593-
}
569+
const INVALID: DepNodeIndexNew = DepNodeIndexNew::const_new(::std::u32::MAX);
594570
}
595571

596572
#[derive(Clone, Debug, PartialEq)]

src/librustc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#![feature(box_patterns)]
4444
#![feature(box_syntax)]
4545
#![feature(conservative_impl_trait)]
46+
#![feature(const_fn)]
4647
#![feature(core_intrinsics)]
4748
#![feature(i128_type)]
4849
#![cfg_attr(windows, feature(libc))]

src/librustc_data_structures/indexed_vec.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ macro_rules! newtype_index {
4545
RustcEncodable, RustcDecodable)]
4646
pub struct $name(u32);
4747

48+
impl $name {
49+
// HACK use for constants
50+
pub const fn const_new(x: u32) -> Self {
51+
$name(x)
52+
}
53+
}
54+
4855
impl Idx for $name {
4956
fn new(value: usize) -> Self {
5057
assert!(value < (::std::u32::MAX) as usize);

src/librustc_mir/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
1818

1919
#![feature(box_patterns)]
2020
#![feature(box_syntax)]
21+
#![feature(const_fn)]
2122
#![feature(core_intrinsics)]
2223
#![feature(i128_type)]
2324
#![feature(rustc_diagnostic_macros)]

0 commit comments

Comments
 (0)