Skip to content

[WIP] Region vid newtype index #45906

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

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
9713c92
fulfill: remove dead code
nikomatsakis Nov 1, 2017
f9e7819
move region constraints into inference context
nikomatsakis Nov 1, 2017
1a246f4
convert EXTRA_REQUIREMENT_IN_IMPL into a hard error
nikomatsakis Nov 1, 2017
9b3c97f
assert that we are consuming all of the region obligations
nikomatsakis Nov 1, 2017
4130c68
extract `regionck_outlives` into a separate helper function
nikomatsakis Nov 2, 2017
48b7d3c
move the `region_obligations` processing code into `InferCtxt`
nikomatsakis Nov 3, 2017
0cf8668
refactor how we extract outlives bounds from trait definitions
nikomatsakis Nov 3, 2017
1bf2052
do not invoke `required_region_bounds` in `region_obligations`
nikomatsakis Nov 4, 2017
9b4dee0
regionck: only add implied bounds from root fn to `free_region_map`
nikomatsakis Nov 4, 2017
e634ffd
extract out the implied bounds code from `regionck`
nikomatsakis Nov 4, 2017
182e4aa
rename mod `region_obligations` to `outlives::obligations`
nikomatsakis Nov 4, 2017
0640faf
move the `OutlivesEnvironment` into `infer` so that `nll` can use it
nikomatsakis Nov 4, 2017
c1b6819
thread location info through mir typeck (but do not use)
nikomatsakis Nov 4, 2017
545a554
apply rustfmt to `type_check`
nikomatsakis Nov 4, 2017
80b2a29
modify MIR type-checker to process obligations as they are incurred
nikomatsakis Nov 5, 2017
305b4b8
extract lexical region resolution into its own sub-module
nikomatsakis Nov 5, 2017
3efc952
on_disk_cache: silence warnings
nikomatsakis Nov 5, 2017
b229a83
move region resolution to be a sibling of `region_inference`
nikomatsakis Nov 5, 2017
a1ae294
region_inference: tighten up `pub`, stop re-exporting enum variants
nikomatsakis Nov 5, 2017
8e27848
region_inference: extract taint into a sub-module
nikomatsakis Nov 5, 2017
edc2a81
move `RegionResolutionError` into `lexical_region_resolve`
nikomatsakis Nov 5, 2017
f52cec8
extract storage of region values from `RegionVarBindings`
nikomatsakis Nov 5, 2017
736cce7
region_inference: rustfmt
nikomatsakis Nov 5, 2017
8f20adb
extract the `tcx` out from `RegionVarBindings`
nikomatsakis Nov 5, 2017
347ad9a
move refcells out from `RegionVarBindings` and up into `InferCtxt`
nikomatsakis Nov 5, 2017
6cb70f6
rename `region_inference` module to `region_constraints`
nikomatsakis Nov 5, 2017
c73f469
infer: rename `region_vars` field to `region_constraints`
nikomatsakis Nov 5, 2017
dcd78ca
rename RegionVarBindings to RegionConstraintCollector
nikomatsakis Nov 5, 2017
ee56f9e
make the `region_constraints` field an `Option`
nikomatsakis Nov 5, 2017
042a844
separate the `Collector` from the `Data` it is collecting
nikomatsakis Nov 5, 2017
e863952
fix error messages relating to removing lint for E0276
nikomatsakis Nov 5, 2017
be2b684
make `RegionVid` implement `Idx` and use `IndexVec`
nikomatsakis Nov 5, 2017
56d5f26
region_constraints: only push givens into undo-log if in a snapshot
nikomatsakis Nov 5, 2017
bf00e64
split the `var_origins` from the `RegionConstraintData`
nikomatsakis Nov 5, 2017
9b8801a
add method `take_and_reset_region_constraints` to `InferCtxt`
nikomatsakis Nov 5, 2017
941e598
rustfmt `lexical_region_resolve`
nikomatsakis Nov 5, 2017
ea91b1a
MIR typeck: rustfmt
nikomatsakis Nov 7, 2017
fb36626
MIR typeck: refactor to track region constraints
nikomatsakis Nov 5, 2017
74edfbe
replace `usize` with `RegionIndex` in indices map
nikomatsakis Nov 6, 2017
41e27a2
replace `RegionIndex` with `RegionVid` (which now impls Idx)
nikomatsakis Nov 6, 2017
53bd655
IndexVec: add `'_` to make clear where borrowing is happening
nikomatsakis Nov 6, 2017
3f37f9a
infer: give access to region variable origins
nikomatsakis Nov 6, 2017
31d6b17
infer: extract total number of region variables from infcx
nikomatsakis Nov 6, 2017
072bae2
formalize giving ownership of region vars to region inf. context
nikomatsakis Nov 6, 2017
ee19f2c
simplify lifetime annotations for `MirBorrowckCtxt`
nikomatsakis Nov 7, 2017
73c9854
erase regions in MIR borrowck when checking if type moves by default
nikomatsakis Nov 6, 2017
f578229
MIR-dump: print return type from local_decls for `_0`
nikomatsakis Nov 7, 2017
e68750b
renumber: handle ReturnTy better
nikomatsakis Nov 7, 2017
9e42ba7
renumber: debug logs, use `visit_region` rather than `visit_rvalue`
nikomatsakis Nov 7, 2017
71ef306
region_infer: improved debug logging
nikomatsakis Nov 7, 2017
69833ab
integrate NLL with MIR type-checker
nikomatsakis Nov 6, 2017
6cddfd3
update READMEs to describe the new situation
nikomatsakis Nov 7, 2017
3caa1d1
WIP infer/outlives: add license
nikomatsakis Nov 7, 2017
126c472
convert TODO in traits into a FIXME
nikomatsakis Nov 7, 2017
7e3e488
add FIXME for converting RegionVid to use `newtype_index!`
nikomatsakis Nov 7, 2017
070a2b4
fix mir-opt NLL tests -- variable `'_#0r` is now `'static`
nikomatsakis Nov 7, 2017
5507cec
factor out `free_region_binding_scope` helper
nikomatsakis Nov 7, 2017
7f2c82f
leak the affects of closures on the free-region-map, like we used to
nikomatsakis Nov 7, 2017
cf7fe00
Make RegionVid use newtype_index!
spastorino Nov 10, 2017
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
18 changes: 9 additions & 9 deletions src/librustc/infer/lexical_region_resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
for (r, vid) in seeds {
// While all things transitively reachable in the graph
// from the variable (`'0` in the example above).
let seed_index = NodeIndex(vid.index as usize);
let seed_index = NodeIndex(vid.index() as usize);
for succ_index in graph.depth_traverse(seed_index, OUTGOING) {
let succ_index = succ_index.0;

Expand Down Expand Up @@ -512,16 +512,16 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
match *constraint {
Constraint::VarSubVar(a_id, b_id) => {
graph.add_edge(
NodeIndex(a_id.index as usize),
NodeIndex(b_id.index as usize),
NodeIndex(a_id.index() as usize),
NodeIndex(b_id.index() as usize),
*constraint,
);
}
Constraint::RegSubVar(_, b_id) => {
graph.add_edge(dummy_source, NodeIndex(b_id.index as usize), *constraint);
graph.add_edge(dummy_source, NodeIndex(b_id.index() as usize), *constraint);
}
Constraint::VarSubReg(a_id, _) => {
graph.add_edge(NodeIndex(a_id.index as usize), dummy_sink, *constraint);
graph.add_edge(NodeIndex(a_id.index() as usize), dummy_sink, *constraint);
}
Constraint::RegSubReg(..) => {
// this would be an edge from `dummy_source` to
Expand Down Expand Up @@ -630,9 +630,9 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
let node_idx = state.stack.pop().unwrap();

// check whether we've visited this node on some previous walk
if dup_vec[node_idx.index as usize] == u32::MAX {
dup_vec[node_idx.index as usize] = orig_node_idx.index;
} else if dup_vec[node_idx.index as usize] != orig_node_idx.index {
if dup_vec[node_idx.index() as usize] == u32::MAX {
dup_vec[node_idx.index() as usize] = orig_node_idx.index() as u32;
} else if dup_vec[node_idx.index() as usize] != orig_node_idx.index() as u32 {
state.dup_found = true;
}

Expand All @@ -659,7 +659,7 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
) {
debug!("process_edges(source_vid={:?}, dir={:?})", source_vid, dir);

let source_node_index = NodeIndex(source_vid.index as usize);
let source_node_index = NodeIndex(source_vid.index() as usize);
for (_, edge) in graph.adjacent_edges(source_node_index, dir) {
match edge.data {
Constraint::VarSubVar(from_vid, to_vid) => {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/infer/region_constraints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use self::CombineMapType::*;
use super::{MiscVariable, RegionVariableOrigin, SubregionOrigin};
use super::unify_key;

use rustc_data_structures::indexed_vec::IndexVec;
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stray import?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's needed because methods of Idx trait are used

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see.

use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::unify::{self, UnificationTable};
use ty::{self, Ty, TyCtxt};
Expand Down Expand Up @@ -363,7 +363,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
}
AddVar(vid) => {
self.var_origins.pop().unwrap();
assert_eq!(self.var_origins.len(), vid.index as usize);
assert_eq!(self.var_origins.len(), vid.index() as usize);
}
AddConstraint(ref constraint) => {
self.data.constraints.remove(constraint);
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/infer/unify_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct RegionVidKey {

impl Combine for RegionVidKey {
fn combine(&self, other: &RegionVidKey) -> RegionVidKey {
let min_vid = if self.min_vid.index < other.min_vid.index {
let min_vid = if self.min_vid.index() < other.min_vid.index() {
self.min_vid
} else {
other.min_vid
Expand All @@ -45,8 +45,8 @@ impl Combine for RegionVidKey {

impl UnifyKey for ty::RegionVid {
type Value = RegionVidKey;
fn index(&self) -> u32 { self.index }
fn from_index(i: u32) -> ty::RegionVid { ty::RegionVid { index: i } }
fn index(&self) -> u32 { self.0 }
fn from_index(i: u32) -> ty::RegionVid { ty::RegionVid(i) }
fn tag(_: Option<ty::RegionVid>) -> &'static str { "RegionVid" }
}

Expand Down
21 changes: 5 additions & 16 deletions src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,22 +894,11 @@ pub struct FloatVid {
pub index: u32,
}

#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Hash, Copy)]
pub struct RegionVid {
pub index: u32,
}

// FIXME: We could convert this to use `newtype_index!`
impl Idx for RegionVid {
fn new(value: usize) -> Self {
assert!(value < ::std::u32::MAX as usize);
RegionVid { index: value as u32 }
}

fn index(self) -> usize {
self.index as usize
}
}
newtype_index!(RegionVid
{
pub idx
DEBUG_FORMAT = custom,
});

#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
pub struct SkolemizedRegionVid {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/util/ppaux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ define_print! {
}
}
ty::ReVar(region_vid) if cx.identify_regions => {
write!(f, "'{}rv", region_vid.index)
write!(f, "'{}rv", region_vid.index())
}
ty::ReScope(_) |
ty::ReVar(_) |
Expand Down Expand Up @@ -850,7 +850,7 @@ impl fmt::Debug for ty::FloatVid {

impl fmt::Debug for ty::RegionVid {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "'_#{}r", self.index)
write!(f, "'_#{}r", self.index())
}
}

Expand Down