Skip to content

Commit 80d7e3e

Browse files
committed
WIP
1 parent be0ef94 commit 80d7e3e

File tree

29 files changed

+326
-251
lines changed

29 files changed

+326
-251
lines changed

src/librustc/cfg/construct.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ use syntax::ast;
1515
use syntax::ptr::P;
1616

1717
use hir::{self, PatKind};
18+
use hir::def_id::DefId;
1819

1920
struct CFGBuilder<'a, 'tcx: 'a> {
2021
tcx: TyCtxt<'a, 'tcx, 'tcx>,
22+
owner_def_id: DefId,
2123
tables: &'a ty::TypeckTables<'tcx>,
2224
graph: CFGGraph,
2325
fn_exit: CFGIndex,
@@ -56,6 +58,7 @@ pub fn construct<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
5658

5759
let mut cfg_builder = CFGBuilder {
5860
tcx: tcx,
61+
owner_def_id,
5962
tables: tables,
6063
graph: graph,
6164
fn_exit: fn_exit,
@@ -585,9 +588,10 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
585588
let mut data = CFGEdgeData { exiting_scopes: vec![] };
586589
let mut scope = self.tcx.node_extent(from_expr.id);
587590
let target_scope = self.tcx.node_extent(scope_id);
591+
let region_maps = self.tcx.region_maps(self.owner_def_id);
588592
while scope != target_scope {
589593
data.exiting_scopes.push(scope.node_id());
590-
scope = self.tcx.region_maps().encl_scope(scope);
594+
scope = region_maps.encl_scope(scope);
591595
}
592596
self.graph.add_edge(from_index, to_index, data);
593597
}

src/librustc/infer/mod.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub use self::region_inference::{GenericKind, VerifyBound};
2020

2121
use hir::def_id::DefId;
2222
use hir;
23-
use middle::free_region::FreeRegionMap;
23+
use middle::free_region::{FreeRegionMap, RegionRelations};
2424
use middle::mem_categorization as mc;
2525
use middle::mem_categorization::McResult;
2626
use middle::lang_items;
@@ -1322,9 +1322,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
13221322
}
13231323

13241324
pub fn resolve_regions_and_report_errors(&self,
1325-
free_regions: &FreeRegionMap<'tcx>,
1326-
subject_node_id: ast::NodeId) {
1327-
let errors = self.region_vars.resolve_regions(free_regions, subject_node_id);
1325+
region_context: DefId,
1326+
free_regions: &FreeRegionMap<'tcx>) {
1327+
let region_map = self.tcx.region_maps(region_context);
1328+
let region_rels = RegionRelations::new(self.tcx,
1329+
region_context,
1330+
&region_map,
1331+
free_regions);
1332+
let errors = self.region_vars.resolve_regions(&region_rels);
13281333
if !self.is_tainted_by_errors() {
13291334
// As a heuristic, just skip reporting region errors
13301335
// altogether if other errors have been reported while

src/librustc/infer/region_inference/graphviz.rs

+17-12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
/// For clarity, rename the graphviz crate locally to dot.
1919
use graphviz as dot;
2020

21+
use hir::def_id::{DefId, DefIndex};
2122
use ty::{self, TyCtxt};
2223
use middle::region::CodeExtent;
2324
use super::Constraint;
@@ -32,7 +33,6 @@ use std::fs::File;
3233
use std::io;
3334
use std::io::prelude::*;
3435
use std::sync::atomic::{AtomicBool, Ordering};
35-
use syntax::ast;
3636

3737
fn print_help_message() {
3838
println!("\
@@ -55,7 +55,7 @@ graphs will be printed. \n\
5555

5656
pub fn maybe_print_constraints_for<'a, 'gcx, 'tcx>(
5757
region_vars: &RegionVarBindings<'a, 'gcx, 'tcx>,
58-
subject_node: ast::NodeId)
58+
context: DefId)
5959
{
6060
let tcx = region_vars.tcx;
6161

@@ -64,9 +64,9 @@ pub fn maybe_print_constraints_for<'a, 'gcx, 'tcx>(
6464
}
6565

6666
let requested_node = env::var("RUST_REGION_GRAPH_NODE")
67-
.ok().and_then(|s| s.parse().map(ast::NodeId::new).ok());
67+
.ok().and_then(|s| s.parse().map(DefIndex::new).ok());
6868

69-
if requested_node.is_some() && requested_node != Some(subject_node) {
69+
if requested_node.is_some() && requested_node != Some(context.index) {
7070
return;
7171
}
7272

@@ -98,7 +98,7 @@ pub fn maybe_print_constraints_for<'a, 'gcx, 'tcx>(
9898
let mut new_str = String::new();
9999
for c in output_template.chars() {
100100
if c == '%' {
101-
new_str.push_str(&subject_node.to_string());
101+
new_str.push_str(&context.index.as_usize().to_string());
102102
} else {
103103
new_str.push(c);
104104
}
@@ -110,7 +110,7 @@ pub fn maybe_print_constraints_for<'a, 'gcx, 'tcx>(
110110
};
111111

112112
let constraints = &*region_vars.constraints.borrow();
113-
match dump_region_constraints_to(tcx, constraints, &output_path) {
113+
match dump_region_constraints_to(tcx, context, constraints, &output_path) {
114114
Ok(()) => {}
115115
Err(e) => {
116116
let msg = format!("io error dumping region constraints: {}", e);
@@ -122,6 +122,7 @@ pub fn maybe_print_constraints_for<'a, 'gcx, 'tcx>(
122122
struct ConstraintGraph<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
123123
tcx: TyCtxt<'a, 'gcx, 'tcx>,
124124
graph_name: String,
125+
context: DefId,
125126
map: &'a FxHashMap<Constraint<'tcx>, SubregionOrigin<'tcx>>,
126127
node_ids: FxHashMap<Node<'tcx>, usize>,
127128
}
@@ -142,6 +143,7 @@ enum Edge<'tcx> {
142143
impl<'a, 'gcx, 'tcx> ConstraintGraph<'a, 'gcx, 'tcx> {
143144
fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>,
144145
name: String,
146+
context: DefId,
145147
map: &'a ConstraintMap<'tcx>)
146148
-> ConstraintGraph<'a, 'gcx, 'tcx> {
147149
let mut i = 0;
@@ -159,17 +161,18 @@ impl<'a, 'gcx, 'tcx> ConstraintGraph<'a, 'gcx, 'tcx> {
159161
add_node(n2);
160162
}
161163

162-
tcx.region_maps().each_encl_scope(|sub, sup| {
164+
tcx.region_maps(context).each_encl_scope(|sub, sup| {
163165
add_node(Node::Region(ty::ReScope(sub)));
164166
add_node(Node::Region(ty::ReScope(sup)));
165167
});
166168
}
167169

168170
ConstraintGraph {
169-
tcx: tcx,
171+
tcx,
172+
context,
173+
map,
174+
node_ids,
170175
graph_name: name,
171-
map: map,
172-
node_ids: node_ids,
173176
}
174177
}
175178
}
@@ -245,7 +248,8 @@ impl<'a, 'gcx, 'tcx> dot::GraphWalk<'a> for ConstraintGraph<'a, 'gcx, 'tcx> {
245248
fn edges(&self) -> dot::Edges<Edge<'tcx>> {
246249
debug!("constraint graph has {} edges", self.map.len());
247250
let mut v: Vec<_> = self.map.keys().map(|e| Edge::Constraint(*e)).collect();
248-
self.tcx.region_maps().each_encl_scope(|sub, sup| v.push(Edge::EnclScope(sub, sup)));
251+
self.tcx.region_maps(self.context)
252+
.each_encl_scope(|sub, sup| v.push(Edge::EnclScope(sub, sup)));
249253
debug!("region graph has {} edges", v.len());
250254
Cow::Owned(v)
251255
}
@@ -264,13 +268,14 @@ impl<'a, 'gcx, 'tcx> dot::GraphWalk<'a> for ConstraintGraph<'a, 'gcx, 'tcx> {
264268
pub type ConstraintMap<'tcx> = FxHashMap<Constraint<'tcx>, SubregionOrigin<'tcx>>;
265269

266270
fn dump_region_constraints_to<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
271+
context: DefId,
267272
map: &ConstraintMap<'tcx>,
268273
path: &str)
269274
-> io::Result<()> {
270275
debug!("dump_region_constraints map (len: {}) path: {}",
271276
map.len(),
272277
path);
273-
let g = ConstraintGraph::new(tcx, format!("region_constraints"), map);
278+
let g = ConstraintGraph::new(tcx, format!("region_constraints"), context, map);
274279
debug!("dump_region_constraints calling render");
275280
let mut v = Vec::new();
276281
dot::render(&g, &mut v).unwrap();

0 commit comments

Comments
 (0)