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 all commits
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
438 changes: 213 additions & 225 deletions src/librustc/infer/README.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/librustc/infer/equate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
a,
b);
let origin = Subtype(self.fields.trace.clone());
self.fields.infcx.region_vars.make_eqregion(origin, a, b);
self.fields.infcx.borrow_region_constraints()
.make_eqregion(origin, a, b);
Ok(a)
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/infer/error_reporting/different_lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
use hir;
use infer::InferCtxt;
use ty::{self, Region};
use infer::region_inference::RegionResolutionError::*;
use infer::region_inference::RegionResolutionError;
use infer::lexical_region_resolve::RegionResolutionError::*;
use infer::lexical_region_resolve::RegionResolutionError;
use hir::map as hir_map;
use middle::resolve_lifetime as rl;
use hir::intravisit::{self, Visitor, NestedVisitorMap};
Expand Down
76 changes: 37 additions & 39 deletions src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@

use infer;
use super::{InferCtxt, TypeTrace, SubregionOrigin, RegionVariableOrigin, ValuePairs};
use super::region_inference::{RegionResolutionError, ConcreteFailure, SubSupConflict,
GenericBoundFailure, GenericKind};
use super::region_constraints::GenericKind;
use super::lexical_region_resolve::RegionResolutionError;

use std::fmt;
use hir;
Expand Down Expand Up @@ -177,13 +177,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {

ty::ReEarlyBound(_) |
ty::ReFree(_) => {
let scope = match *region {
ty::ReEarlyBound(ref br) => {
self.parent_def_id(br.def_id).unwrap()
}
ty::ReFree(ref fr) => fr.scope,
_ => bug!()
};
let scope = region.free_region_binding_scope(self);
let prefix = match *region {
ty::ReEarlyBound(ref br) => {
format!("the lifetime {} as defined on", br.name)
Expand Down Expand Up @@ -293,33 +287,37 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
debug!("report_region_errors: error = {:?}", error);

if !self.try_report_named_anon_conflict(&error) &&
!self.try_report_anon_anon_conflict(&error) {

match error.clone() {
// These errors could indicate all manner of different
// problems with many different solutions. Rather
// than generate a "one size fits all" error, what we
// attempt to do is go through a number of specific
// scenarios and try to find the best way to present
// the error. If all of these fails, we fall back to a rather
// general bit of code that displays the error information
ConcreteFailure(origin, sub, sup) => {
self.report_concrete_failure(region_scope_tree, origin, sub, sup).emit();
}

GenericBoundFailure(kind, param_ty, sub) => {
self.report_generic_bound_failure(region_scope_tree, kind, param_ty, sub);
}

SubSupConflict(var_origin, sub_origin, sub_r, sup_origin, sup_r) => {
!self.try_report_anon_anon_conflict(&error)
{
match error.clone() {
// These errors could indicate all manner of different
// problems with many different solutions. Rather
// than generate a "one size fits all" error, what we
// attempt to do is go through a number of specific
// scenarios and try to find the best way to present
// the error. If all of these fails, we fall back to a rather
// general bit of code that displays the error information
RegionResolutionError::ConcreteFailure(origin, sub, sup) => {
self.report_concrete_failure(region_scope_tree, origin, sub, sup).emit();
}

RegionResolutionError::GenericBoundFailure(kind, param_ty, sub) => {
self.report_generic_bound_failure(region_scope_tree, kind, param_ty, sub);
}

RegionResolutionError::SubSupConflict(var_origin,
sub_origin,
sub_r,
sup_origin,
sup_r) => {
self.report_sub_sup_conflict(region_scope_tree,
var_origin,
sub_origin,
sub_r,
sup_origin,
sup_r);
}
}
}
}
}
}
}
Expand Down Expand Up @@ -351,9 +349,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
// the only thing in the list.

let is_bound_failure = |e: &RegionResolutionError<'tcx>| match *e {
ConcreteFailure(..) => false,
SubSupConflict(..) => false,
GenericBoundFailure(..) => true,
RegionResolutionError::GenericBoundFailure(..) => true,
RegionResolutionError::ConcreteFailure(..) |
RegionResolutionError::SubSupConflict(..) => false,
};


Expand All @@ -365,9 +363,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {

// sort the errors by span, for better error message stability.
errors.sort_by_key(|u| match *u {
ConcreteFailure(ref sro, _, _) => sro.span(),
GenericBoundFailure(ref sro, _, _) => sro.span(),
SubSupConflict(ref rvo, _, _, _, _) => rvo.span(),
RegionResolutionError::ConcreteFailure(ref sro, _, _) => sro.span(),
RegionResolutionError::GenericBoundFailure(ref sro, _, _) => sro.span(),
RegionResolutionError::SubSupConflict(ref rvo, _, _, _, _) => rvo.span(),
});
errors
}
Expand Down Expand Up @@ -880,14 +878,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
};

if let SubregionOrigin::CompareImplMethodObligation {
span, item_name, impl_item_def_id, trait_item_def_id, lint_id
span, item_name, impl_item_def_id, trait_item_def_id,
} = origin {
self.report_extra_impl_obligation(span,
item_name,
impl_item_def_id,
trait_item_def_id,
&format!("`{}: {}`", bound_kind, sub),
lint_id)
&format!("`{}: {}`", bound_kind, sub))
.emit();
return;
}
Expand Down Expand Up @@ -1026,6 +1023,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
let var_name = self.tcx.hir.name(var_node_id);
format!(" for capture of `{}` by closure", var_name)
}
infer::NLL(..) => bug!("NLL variable found in lexical phase"),
};

struct_span_err!(self.tcx.sess, var_origin.span(), E0495,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/infer/error_reporting/named_anon_conflict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
//! Error Reporting for Anonymous Region Lifetime Errors
//! where one region is named and the other is anonymous.
use infer::InferCtxt;
use infer::region_inference::RegionResolutionError::*;
use infer::region_inference::RegionResolutionError;
use infer::lexical_region_resolve::RegionResolutionError::*;
use infer::lexical_region_resolve::RegionResolutionError;
use ty;

impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
Expand Down
6 changes: 2 additions & 4 deletions src/librustc/infer/error_reporting/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,14 +445,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
infer::CompareImplMethodObligation { span,
item_name,
impl_item_def_id,
trait_item_def_id,
lint_id } => {
trait_item_def_id } => {
self.report_extra_impl_obligation(span,
item_name,
impl_item_def_id,
trait_item_def_id,
&format!("`{}: {}`", sup, sub),
lint_id)
&format!("`{}: {}`", sup, sub))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/infer/fudge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
self.type_variables.borrow_mut().types_created_since_snapshot(
&snapshot.type_snapshot);
let region_vars =
self.region_vars.vars_created_since_snapshot(
&snapshot.region_vars_snapshot);
self.borrow_region_constraints().vars_created_since_snapshot(
&snapshot.region_constraints_snapshot);

Ok((type_variables, region_vars, value))
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/glb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
b);

let origin = Subtype(self.fields.trace.clone());
Ok(self.fields.infcx.region_vars.glb_regions(origin, a, b))
Ok(self.fields.infcx.borrow_region_constraints().glb_regions(self.tcx(), origin, a, b))
}

fn binders<T>(&mut self, a: &ty::Binder<T>, b: &ty::Binder<T>)
Expand Down
26 changes: 17 additions & 9 deletions src/librustc/infer/higher_ranked/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use super::{CombinedSnapshot,
SubregionOrigin,
SkolemizationMap};
use super::combine::CombineFields;
use super::region_inference::{TaintDirections};
use super::region_constraints::{TaintDirections};

use ty::{self, TyCtxt, Binder, TypeFoldable};
use ty::error::TypeError;
Expand Down Expand Up @@ -176,9 +176,10 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
.filter(|&r| r != representative)
{
let origin = SubregionOrigin::Subtype(self.trace.clone());
self.infcx.region_vars.make_eqregion(origin,
*representative,
*region);
self.infcx.borrow_region_constraints()
.make_eqregion(origin,
*representative,
*region);
}
}

Expand Down Expand Up @@ -427,7 +428,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
fn fresh_bound_variable<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
debruijn: ty::DebruijnIndex)
-> ty::Region<'tcx> {
infcx.region_vars.new_bound(debruijn)
infcx.borrow_region_constraints().new_bound(infcx.tcx, debruijn)
}
}
}
Expand Down Expand Up @@ -481,7 +482,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
r: ty::Region<'tcx>,
directions: TaintDirections)
-> FxHashSet<ty::Region<'tcx>> {
self.region_vars.tainted(&snapshot.region_vars_snapshot, r, directions)
self.borrow_region_constraints().tainted(
self.tcx,
&snapshot.region_constraints_snapshot,
r,
directions)
}

fn region_vars_confined_to_snapshot(&self,
Expand Down Expand Up @@ -539,7 +544,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
*/

let mut region_vars =
self.region_vars.vars_created_since_snapshot(&snapshot.region_vars_snapshot);
self.borrow_region_constraints().vars_created_since_snapshot(
&snapshot.region_constraints_snapshot);

let escaping_types =
self.type_variables.borrow_mut().types_escaping_snapshot(&snapshot.type_snapshot);
Expand Down Expand Up @@ -581,7 +587,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
where T : TypeFoldable<'tcx>
{
let (result, map) = self.tcx.replace_late_bound_regions(binder, |br| {
self.region_vars.push_skolemized(br, &snapshot.region_vars_snapshot)
self.borrow_region_constraints()
.push_skolemized(self.tcx, br, &snapshot.region_constraints_snapshot)
});

debug!("skolemize_bound_regions(binder={:?}, result={:?}, map={:?})",
Expand Down Expand Up @@ -766,7 +773,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
{
debug!("pop_skolemized({:?})", skol_map);
let skol_regions: FxHashSet<_> = skol_map.values().cloned().collect();
self.region_vars.pop_skolemized(&skol_regions, &snapshot.region_vars_snapshot);
self.borrow_region_constraints()
.pop_skolemized(self.tcx, &skol_regions, &snapshot.region_constraints_snapshot);
if !skol_map.is_empty() {
self.projection_cache.borrow_mut().rollback_skolemized(
&snapshot.projection_cache_snapshot);
Expand Down
Loading