Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
4afe423
fulfill: remove dead code
nikomatsakis Nov 1, 2017
64206b4
move region constraints into inference context
nikomatsakis Nov 1, 2017
0d78e40
convert EXTRA_REQUIREMENT_IN_IMPL into a hard error
nikomatsakis Nov 1, 2017
c925008
assert that we are consuming all of the region obligations
nikomatsakis Nov 1, 2017
d73be85
extract `regionck_outlives` into a separate helper function
nikomatsakis Nov 2, 2017
22cd041
move the `region_obligations` processing code into `InferCtxt`
nikomatsakis Nov 3, 2017
e0630e8
refactor how we extract outlives bounds from trait definitions
nikomatsakis Nov 3, 2017
3cc44a5
do not invoke `required_region_bounds` in `region_obligations`
nikomatsakis Nov 4, 2017
b587c1a
regionck: only add implied bounds from root fn to `free_region_map`
nikomatsakis Nov 4, 2017
0c81d01
extract out the implied bounds code from `regionck`
nikomatsakis Nov 4, 2017
56e5eb5
rename mod `region_obligations` to `outlives::obligations`
nikomatsakis Nov 4, 2017
15a2dfa
move the `OutlivesEnvironment` into `infer` so that `nll` can use it
nikomatsakis Nov 4, 2017
6d67296
thread location info through mir typeck (but do not use)
nikomatsakis Nov 4, 2017
9e8abd7
apply rustfmt to `type_check`
nikomatsakis Nov 4, 2017
efa09db
modify MIR type-checker to process obligations as they are incurred
nikomatsakis Nov 5, 2017
467f2ea
extract lexical region resolution into its own sub-module
nikomatsakis Nov 5, 2017
58c7760
move region resolution to be a sibling of `region_inference`
nikomatsakis Nov 15, 2017
ef5de07
fix rename to block_data in type_check.rs
nikomatsakis Nov 15, 2017
9d63330
region_inference: tighten up `pub`, stop re-exporting enum variants
nikomatsakis Nov 5, 2017
8e9e154
region_inference: extract taint into a sub-module
nikomatsakis Nov 5, 2017
b769785
move `RegionResolutionError` into `lexical_region_resolve`
nikomatsakis Nov 5, 2017
ec48b01
extract storage of region values from `RegionVarBindings`
nikomatsakis Nov 5, 2017
daceedf
region_inference: rustfmt
nikomatsakis Nov 5, 2017
63d658d
extract the `tcx` out from `RegionVarBindings`
nikomatsakis Nov 5, 2017
cff191d
move refcells out from `RegionVarBindings` and up into `InferCtxt`
nikomatsakis Nov 5, 2017
23abd85
rename `region_inference` module to `region_constraints`
nikomatsakis Nov 5, 2017
48d8f72
infer: rename `region_vars` field to `region_constraints`
nikomatsakis Nov 5, 2017
326ec52
rename RegionVarBindings to RegionConstraintCollector
nikomatsakis Nov 5, 2017
adf1519
make the `region_constraints` field an `Option`
nikomatsakis Nov 5, 2017
f6037f2
separate the `Collector` from the `Data` it is collecting
nikomatsakis Nov 5, 2017
bea6b94
fix error messages relating to removing lint for E0276
nikomatsakis Nov 5, 2017
524e23a
make `RegionVid` implement `Idx` and use `IndexVec`
nikomatsakis Nov 5, 2017
a8daa37
region_constraints: only push givens into undo-log if in a snapshot
nikomatsakis Nov 5, 2017
1efcf1a
split the `var_origins` from the `RegionConstraintData`
nikomatsakis Nov 5, 2017
1430a60
add method `take_and_reset_region_constraints` to `InferCtxt`
nikomatsakis Nov 5, 2017
034018c
rustfmt `lexical_region_resolve`
nikomatsakis Nov 5, 2017
37945fe
MIR typeck: rustfmt
nikomatsakis Nov 7, 2017
ad93b69
MIR typeck: refactor to track region constraints
nikomatsakis Nov 5, 2017
89c1b60
replace `usize` with `RegionIndex` in indices map
nikomatsakis Nov 6, 2017
72675d8
replace `RegionIndex` with `RegionVid` (which now impls Idx)
nikomatsakis Nov 6, 2017
09b44bb
IndexVec: add `'_` to make clear where borrowing is happening
nikomatsakis Nov 6, 2017
a87d1bb
infer: give access to region variable origins
nikomatsakis Nov 6, 2017
109c9a7
infer: extract total number of region variables from infcx
nikomatsakis Nov 6, 2017
51ce1f9
formalize giving ownership of region vars to region inf. context
nikomatsakis Nov 6, 2017
ef392bc
simplify lifetime annotations for `MirBorrowckCtxt`
nikomatsakis Nov 7, 2017
8d3219e
erase regions in MIR borrowck when checking if type moves by default
nikomatsakis Nov 6, 2017
5592bb7
MIR-dump: print return type from local_decls for `_0`
nikomatsakis Nov 7, 2017
12534e9
renumber: handle ReturnTy better
nikomatsakis Nov 7, 2017
32f964c
renumber: debug logs, use `visit_region` rather than `visit_rvalue`
nikomatsakis Nov 7, 2017
d9e841e
region_infer: improved debug logging
nikomatsakis Nov 7, 2017
4b743da
integrate NLL with MIR type-checker
nikomatsakis Nov 6, 2017
b383ab7
update READMEs to describe the new situation
nikomatsakis Nov 7, 2017
013f88b
infer/outlives: add license
nikomatsakis Nov 7, 2017
267574c
convert TODO in traits into a FIXME
nikomatsakis Nov 7, 2017
9da54c1
add FIXME for converting RegionVid to use `newtype_index!`
nikomatsakis Nov 7, 2017
8cea053
fix mir-opt NLL tests -- variable `'_#0r` is now `'static`
nikomatsakis Nov 7, 2017
c7c2603
factor out `free_region_binding_scope` helper
nikomatsakis Nov 7, 2017
5a8c1eb
leak the affects of closures on the free-region-map, like we used to
nikomatsakis Nov 7, 2017
f722591
Nit: fix wording in README
nikomatsakis Nov 14, 2017
15739b8
Nit: rework region obligations to a snapshotted vector
nikomatsakis Nov 14, 2017
11c84c6
Nit: improve comment to explain why we wait until regionck
nikomatsakis Nov 14, 2017
a73d620
Nit: reset more state after `take_and_reset_data`
nikomatsakis Nov 14, 2017
a94d2a6
Nit: fix typo
nikomatsakis Nov 15, 2017
9e29662
obligations.rs: rustfmt
nikomatsakis Nov 16, 2017
8c109f5
infer/outlives/obligations.rs: wrap some long lines
nikomatsakis Nov 16, 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
Prev Previous commit
Next Next commit
Nit: rework region obligations to a snapshotted vector
  • Loading branch information
nikomatsakis committed Nov 16, 2017
commit 15739b820f95ea213870790e67ee04dc359192d1
13 changes: 10 additions & 3 deletions src/librustc/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use std::fmt;
use syntax::ast;
use errors::DiagnosticBuilder;
use syntax_pos::{self, Span, DUMMY_SP};
use util::nodemap::{NodeMap, FxHashMap};
use util::nodemap::FxHashMap;
use arena::DroplessArena;

use self::combine::CombineFields;
Expand Down Expand Up @@ -179,7 +179,7 @@ pub struct InferCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
// for each body-id in this map, which will process the
// obligations within. This is expected to be done 'late enough'
// that all type inference variables have been bound and so forth.
region_obligations: RefCell<NodeMap<Vec<RegionObligation<'tcx>>>>,
region_obligations: RefCell<Vec<(ast::NodeId, RegionObligation<'tcx>)>>,
}
Copy link
Contributor

@arielb1 arielb1 Nov 14, 2017

Choose a reason for hiding this comment

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

I don't think this handle snapshots correctly - i.e. are region obligations that were created in a "child" fulfillcx in a probe ignored? type_known_to_meet_bound creates a "child" fulfillment context, and I'm not sure it can't be called from typeck snapshots.

If you think nobody should be registering region obligations in a snapshot, which should eventually be the case with MIR regionck, it's a good idea to add an assertion to prevent things blowing up if someone gets this wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I'll add an assertion to check. If necessary, we could make the map snapshottable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I decided to replace this with a vector and support snapshotting.


/// A map returned by `skolemize_late_bound_regions()` indicating the skolemized
Expand Down Expand Up @@ -450,7 +450,7 @@ impl<'a, 'gcx, 'tcx> InferCtxtBuilder<'a, 'gcx, 'tcx> {
tainted_by_errors_flag: Cell::new(false),
err_count_on_creation: tcx.sess.err_count(),
in_snapshot: Cell::new(false),
region_obligations: RefCell::new(NodeMap()),
region_obligations: RefCell::new(vec![]),
}))
}
}
Expand Down Expand Up @@ -478,6 +478,7 @@ pub struct CombinedSnapshot<'a, 'tcx:'a> {
int_snapshot: unify::Snapshot<ty::IntVid>,
float_snapshot: unify::Snapshot<ty::FloatVid>,
region_constraints_snapshot: RegionSnapshot,
region_obligations_snapshot: usize,
was_in_snapshot: bool,
_in_progress_tables: Option<Ref<'a, ty::TypeckTables<'tcx>>>,
}
Expand Down Expand Up @@ -786,6 +787,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
int_snapshot: self.int_unification_table.borrow_mut().snapshot(),
float_snapshot: self.float_unification_table.borrow_mut().snapshot(),
region_constraints_snapshot: self.borrow_region_constraints().start_snapshot(),
region_obligations_snapshot: self.region_obligations.borrow().len(),
was_in_snapshot: in_snapshot,
// Borrow tables "in progress" (i.e. during typeck)
// to ban writes from within a snapshot to them.
Expand All @@ -802,6 +804,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
int_snapshot,
float_snapshot,
region_constraints_snapshot,
region_obligations_snapshot,
was_in_snapshot,
_in_progress_tables } = snapshot;

Expand All @@ -819,6 +822,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
self.float_unification_table
.borrow_mut()
.rollback_to(float_snapshot);
self.region_obligations
.borrow_mut()
.truncate(region_obligations_snapshot);
self.borrow_region_constraints()
.rollback_to(region_constraints_snapshot);
}
Expand All @@ -830,6 +836,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
int_snapshot,
float_snapshot,
region_constraints_snapshot,
region_obligations_snapshot: _,
was_in_snapshot,
_in_progress_tables } = snapshot;

Expand Down
32 changes: 19 additions & 13 deletions src/librustc/infer/outlives/obligations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
) {
self.region_obligations
.borrow_mut()
.entry(body_id)
.or_insert(vec![])
.push(obligation);
.push((body_id, obligation));
}

/// Process the region obligations that must be proven (during
Expand Down Expand Up @@ -131,10 +129,16 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
param_env: ty::ParamEnv<'tcx>,
body_id: ast::NodeId,
) {
let region_obligations = match self.region_obligations.borrow_mut().remove(&body_id) {
None => vec![],
Some(vec) => vec,
};
assert!(!self.in_snapshot.get(), "cannot process registered region obligations in a snapshot");

// pull out the region obligations with the given `body_id` (leaving the rest)
let mut my_region_obligations = Vec::with_capacity(self.region_obligations.borrow().len());
{
let mut r_o = self.region_obligations.borrow_mut();
for (_, obligation) in r_o.drain_filter(|(ro_body_id, _)| *ro_body_id == body_id) {
my_region_obligations.push(obligation);
}
}

let outlives =
TypeOutlives::new(self, region_bound_pairs, implicit_region_bound, param_env);
Expand All @@ -143,7 +147,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
sup_type,
sub_region,
cause,
} in region_obligations
} in my_region_obligations
{
let origin = SubregionOrigin::from_obligation_cause(
&cause,
Expand All @@ -170,11 +174,13 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
outlives.type_must_outlive(origin, ty, region);
}

/// Ignore the region obligations for a given `body_id`, not bothering to
/// prove them. This function should not really exist; it is used to accommodate some older
/// code for the time being.
pub fn ignore_region_obligations(&self, body_id: ast::NodeId) {
self.region_obligations.borrow_mut().remove(&body_id);
/// Ignore the region obligations, not bothering to prove
/// them. This function should not really exist; it is used to
/// accommodate some older code for the time being.
pub fn ignore_region_obligations(&self) {
assert!(!self.in_snapshot.get(), "cannot ignore registered region obligations in a snapshot");

self.region_obligations.borrow_mut().clear();
}
}

Expand Down
1 change: 1 addition & 0 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#![feature(conservative_impl_trait)]
#![feature(const_fn)]
#![feature(core_intrinsics)]
#![feature(drain_filter)]
#![feature(i128_type)]
#![feature(match_default_bindings)]
#![feature(inclusive_range_syntax)]
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,6 @@ pub fn normalize_param_env_or_error<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
unnormalized_env.reveal);

tcx.infer_ctxt().enter(|infcx| {
let body_id = cause.body_id;
let predicates = match fully_normalize(
&infcx,
cause,
Expand Down Expand Up @@ -546,7 +545,7 @@ pub fn normalize_param_env_or_error<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// properly, and that code is currently largely confined to
// regionck (though I made some efforts to extract it
// out). -nmatsakis
let _ = infcx.ignore_region_obligations(body_id);
let _ = infcx.ignore_region_obligations();

infcx.resolve_regions_and_report_errors(region_context, &region_scope_tree, &free_regions);
let predicates = match infcx.fully_resolve(&predicates) {
Expand Down