Skip to content

Commit 4531131

Browse files
committed
Auto merge of #44878 - Nashenas88:master, r=nikomatsakis
Store a new Region value every time we create a new region variable Paired with @spastorino to walk through this and implement #44870.
2 parents 1db1144 + 271a492 commit 4531131

File tree

10 files changed

+62
-59
lines changed

10 files changed

+62
-59
lines changed

src/Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/librustc/dep_graph/graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ impl DepGraph {
406406
for (current_dep_node_index, edges) in current_dep_graph.edges.iter_enumerated() {
407407
let start = edge_list_data.len() as u32;
408408
// This should really just be a memcpy :/
409-
edge_list_data.extend(edges.iter().map(|i| SerializedDepNodeIndex(i.index)));
409+
edge_list_data.extend(edges.iter().map(|i| SerializedDepNodeIndex::new(i.index())));
410410
let end = edge_list_data.len() as u32;
411411

412412
debug_assert_eq!(current_dep_node_index.index(), edge_list_indices.len());

src/librustc/dep_graph/serialized.rs

+1-17
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,7 @@ use dep_graph::DepNode;
1414
use ich::Fingerprint;
1515
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
1616

17-
/// The index of a DepNode in the SerializedDepGraph::nodes array.
18-
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd, Debug,
19-
RustcEncodable, RustcDecodable)]
20-
pub struct SerializedDepNodeIndex(pub u32);
21-
22-
impl Idx for SerializedDepNodeIndex {
23-
#[inline]
24-
fn new(idx: usize) -> Self {
25-
assert!(idx <= ::std::u32::MAX as usize);
26-
SerializedDepNodeIndex(idx as u32)
27-
}
28-
29-
#[inline]
30-
fn index(self) -> usize {
31-
self.0 as usize
32-
}
33-
}
17+
newtype_index!(SerializedDepNodeIndex);
3418

3519
/// Data for use when recompiling the **current crate**.
3620
#[derive(Debug, RustcEncodable, RustcDecodable)]

src/librustc/lib.rs

+2-1
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))]
@@ -71,7 +72,7 @@ extern crate graphviz;
7172
extern crate libc;
7273
extern crate owning_ref;
7374
extern crate rustc_back;
74-
extern crate rustc_data_structures;
75+
#[macro_use] extern crate rustc_data_structures;
7576
extern crate serialize;
7677
extern crate rustc_const_math;
7778
extern crate rustc_errors as errors;

src/librustc/mir/mod.rs

-24
Original file line numberDiff line numberDiff line change
@@ -43,30 +43,6 @@ pub mod visit;
4343
pub mod transform;
4444
pub mod traversal;
4545

46-
macro_rules! newtype_index {
47-
($name:ident, $debug_name:expr) => (
48-
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord,
49-
RustcEncodable, RustcDecodable)]
50-
pub struct $name(u32);
51-
52-
impl Idx for $name {
53-
fn new(value: usize) -> Self {
54-
assert!(value < (u32::MAX) as usize);
55-
$name(value as u32)
56-
}
57-
fn index(self) -> usize {
58-
self.0 as usize
59-
}
60-
}
61-
62-
impl Debug for $name {
63-
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
64-
write!(fmt, "{}{}", $debug_name, self.0)
65-
}
66-
}
67-
)
68-
}
69-
7046
/// Types for locals
7147
type LocalDecls<'tcx> = IndexVec<Local, LocalDecl<'tcx>>;
7248

src/librustc_data_structures/indexed_vec.rs

+37
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,43 @@ impl Idx for u32 {
3838
fn index(self) -> usize { self as usize }
3939
}
4040

41+
#[macro_export]
42+
macro_rules! newtype_index {
43+
($name:ident) => (
44+
newtype_index!($name, unsafe { ::std::intrinsics::type_name::<$name>() });
45+
);
46+
47+
($name:ident, $debug_name:expr) => (
48+
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord,
49+
RustcEncodable, RustcDecodable)]
50+
pub struct $name(u32);
51+
52+
impl $name {
53+
// HACK use for constants
54+
#[allow(unused)]
55+
const fn const_new(x: u32) -> Self {
56+
$name(x)
57+
}
58+
}
59+
60+
impl Idx for $name {
61+
fn new(value: usize) -> Self {
62+
assert!(value < (::std::u32::MAX) as usize);
63+
$name(value as u32)
64+
}
65+
fn index(self) -> usize {
66+
self.0 as usize
67+
}
68+
}
69+
70+
impl ::std::fmt::Debug for $name {
71+
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
72+
write!(fmt, "{}{}", $debug_name, self.0)
73+
}
74+
}
75+
)
76+
}
77+
4178
#[derive(Clone, PartialEq, Eq)]
4279
pub struct IndexVec<I: Idx, T> {
4380
pub raw: Vec<T>,

src/librustc_mir/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ rustc_const_eval = { path = "../librustc_const_eval" }
1717
rustc_const_math = { path = "../librustc_const_math" }
1818
rustc_data_structures = { path = "../librustc_data_structures" }
1919
rustc_errors = { path = "../librustc_errors" }
20+
serialize = { path = "../libserialize" }
2021
syntax = { path = "../libsyntax" }
2122
syntax_pos = { path = "../libsyntax_pos" }

src/librustc_mir/build/mod.rs

+1-13
Original file line numberDiff line numberDiff line change
@@ -311,19 +311,7 @@ struct CFG<'tcx> {
311311
basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
312312
}
313313

314-
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
315-
pub struct ScopeId(u32);
316-
317-
impl Idx for ScopeId {
318-
fn new(index: usize) -> ScopeId {
319-
assert!(index < (u32::MAX as usize));
320-
ScopeId(index as u32)
321-
}
322-
323-
fn index(self) -> usize {
324-
self.0 as usize
325-
}
326-
}
314+
newtype_index!(ScopeId);
327315

328316
///////////////////////////////////////////////////////////////////////////
329317
/// The `BlockAnd` "monad" packages up the new basic block along with a

src/librustc_mir/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
1818

1919
#![feature(box_patterns)]
2020
#![feature(box_syntax)]
21+
#![feature(const_fn)]
22+
#![feature(core_intrinsics)]
2123
#![feature(i128_type)]
2224
#![feature(rustc_diagnostic_macros)]
2325
#![feature(placement_in_syntax)]
@@ -30,7 +32,8 @@ extern crate bitflags;
3032
extern crate graphviz as dot;
3133
#[macro_use]
3234
extern crate rustc;
33-
extern crate rustc_data_structures;
35+
#[macro_use] extern crate rustc_data_structures;
36+
extern crate serialize as rustc_serialize;
3437
extern crate rustc_errors;
3538
#[macro_use]
3639
extern crate syntax;

src/librustc_mir/transform/nll/mod.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ use rustc::mir::{Mir, Location, Rvalue, BasicBlock, Statement, StatementKind};
1515
use rustc::mir::visit::{MutVisitor, Lookup};
1616
use rustc::mir::transform::{MirPass, MirSource};
1717
use rustc::infer::{self, InferCtxt};
18+
use rustc::util::nodemap::FxHashSet;
19+
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
1820
use syntax_pos::DUMMY_SP;
1921
use std::collections::HashMap;
2022

2123
#[allow(dead_code)]
2224
struct NLLVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
2325
lookup_map: HashMap<RegionVid, Lookup>,
26+
regions: IndexVec<RegionIndex, Region>,
2427
infcx: InferCtxt<'a, 'gcx, 'tcx>,
2528
}
2629

@@ -29,15 +32,17 @@ impl<'a, 'gcx, 'tcx> NLLVisitor<'a, 'gcx, 'tcx> {
2932
NLLVisitor {
3033
infcx,
3134
lookup_map: HashMap::new(),
35+
regions: IndexVec::new(),
3236
}
3337
}
3438

3539
pub fn into_results(self) -> HashMap<RegionVid, Lookup> {
3640
self.lookup_map
3741
}
3842

39-
fn renumber_regions<T>(&self, value: &T) -> T where T: TypeFoldable<'tcx> {
43+
fn renumber_regions<T>(&mut self, value: &T) -> T where T: TypeFoldable<'tcx> {
4044
self.infcx.tcx.fold_regions(value, &mut false, |_region, _depth| {
45+
self.regions.push(Region::default());
4146
self.infcx.next_region_var(infer::MiscVariable(DUMMY_SP))
4247
})
4348
}
@@ -143,4 +148,11 @@ impl MirPass for NLL {
143148
let _results = visitor.into_results();
144149
})
145150
}
146-
}
151+
}
152+
153+
#[derive(Clone, Debug, Default, PartialEq, Eq)]
154+
struct Region {
155+
points: FxHashSet<Location>,
156+
}
157+
158+
newtype_index!(RegionIndex);

0 commit comments

Comments
 (0)