Skip to content

[WIP] Maybe initialized liveness #45794

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
68 commits
Select commit Hold shift + click to select a range
a339932
fulfill: remove dead code
nikomatsakis Nov 1, 2017
1e32a6b
move region constraints into inference context
nikomatsakis Nov 1, 2017
58d4548
convert EXTRA_REQUIREMENT_IN_IMPL into a hard error
nikomatsakis Nov 1, 2017
57b08b0
assert that we are consuming all of the region obligations
nikomatsakis Nov 1, 2017
279882f
extract `regionck_outlives` into a separate helper function
nikomatsakis Nov 2, 2017
7317a4f
move the `region_obligations` processing code into `InferCtxt`
nikomatsakis Nov 3, 2017
9817b53
refactor how we extract outlives bounds from trait definitions
nikomatsakis Nov 3, 2017
c811e07
do not invoke `required_region_bounds` in `region_obligations`
nikomatsakis Nov 4, 2017
100a347
regionck: only add implied bounds from root fn to `free_region_map`
nikomatsakis Nov 4, 2017
3d1b78b
extract out the implied bounds code from `regionck`
nikomatsakis Nov 4, 2017
f1d95ed
rename mod `region_obligations` to `outlives::obligations`
nikomatsakis Nov 4, 2017
dc93c9d
move the `OutlivesEnvironment` into `infer` so that `nll` can use it
nikomatsakis Nov 4, 2017
23f80c9
thread location info through mir typeck (but do not use)
nikomatsakis Nov 4, 2017
bdfaff5
apply rustfmt to `type_check`
nikomatsakis Nov 4, 2017
72791b3
modify MIR type-checker to process obligations as they are incurred
nikomatsakis Nov 5, 2017
0bdc009
extract lexical region resolution into its own sub-module
nikomatsakis Nov 5, 2017
4809986
on_disk_cache: silence warnings
nikomatsakis Nov 5, 2017
9baef89
move region resolution to be a sibling of `region_inference`
nikomatsakis Nov 5, 2017
9741596
region_inference: tighten up `pub`, stop re-exporting enum variants
nikomatsakis Nov 5, 2017
ab75caf
region_inference: extract taint into a sub-module
nikomatsakis Nov 5, 2017
a51b29f
move `RegionResolutionError` into `lexical_region_resolve`
nikomatsakis Nov 5, 2017
6ff84cf
extract storage of region values from `RegionVarBindings`
nikomatsakis Nov 5, 2017
e084072
region_inference: rustfmt
nikomatsakis Nov 5, 2017
4861c79
extract the `tcx` out from `RegionVarBindings`
nikomatsakis Nov 5, 2017
69da30c
move refcells out from `RegionVarBindings` and up into `InferCtxt`
nikomatsakis Nov 5, 2017
be36920
rename `region_inference` module to `region_constraints`
nikomatsakis Nov 5, 2017
619f8bd
infer: rename `region_vars` field to `region_constraints`
nikomatsakis Nov 5, 2017
9dc09dc
rename RegionVarBindings to RegionConstraintCollector
nikomatsakis Nov 5, 2017
0c3f002
make the `region_constraints` field an `Option`
nikomatsakis Nov 5, 2017
d975b11
separate the `Collector` from the `Data` it is collecting
nikomatsakis Nov 5, 2017
4d7a1ab
fix error messages relating to removing lint for E0276
nikomatsakis Nov 5, 2017
769b30d
make `RegionVid` implement `Idx` and use `IndexVec`
nikomatsakis Nov 5, 2017
7129376
region_constraints: only push givens into undo-log if in a snapshot
nikomatsakis Nov 5, 2017
6c35c6d
split the `var_origins` from the `RegionConstraintData`
nikomatsakis Nov 5, 2017
965650a
add method `take_and_reset_region_constraints` to `InferCtxt`
nikomatsakis Nov 5, 2017
3eed63a
rustfmt `lexical_region_resolve`
nikomatsakis Nov 5, 2017
54a7dee
MIR typeck: rustfmt
nikomatsakis Nov 7, 2017
607daa0
MIR typeck: refactor to track region constraints
nikomatsakis Nov 5, 2017
33c7337
replace `usize` with `RegionIndex` in indices map
nikomatsakis Nov 6, 2017
b96e6ea
replace `RegionIndex` with `RegionVid` (which now impls Idx)
nikomatsakis Nov 6, 2017
40b773e
IndexVec: add `'_` to make clear where borrowing is happening
nikomatsakis Nov 6, 2017
3a4b321
infer: give access to region variable origins
nikomatsakis Nov 6, 2017
7dcf87b
infer: extract total number of region variables from infcx
nikomatsakis Nov 6, 2017
7947173
formalize giving ownership of region vars to region inf. context
nikomatsakis Nov 6, 2017
2cd18e3
simplify lifetime annotations for `MirBorrowckCtxt`
nikomatsakis Nov 7, 2017
2f70705
erase regions in MIR borrowck when checking if type moves by default
nikomatsakis Nov 6, 2017
48d3d7e
MIR-dump: print return type from local_decls for `_0`
nikomatsakis Nov 7, 2017
03e76cc
renumber: handle ReturnTy better
nikomatsakis Nov 7, 2017
410c433
renumber: debug logs, use `visit_region` rather than `visit_rvalue`
nikomatsakis Nov 7, 2017
ffd17ea
region_infer: improved debug logging
nikomatsakis Nov 7, 2017
00205ea
integrate NLL with MIR type-checker
nikomatsakis Nov 6, 2017
c1d84ec
update READMEs to describe the new situation
nikomatsakis Nov 7, 2017
5758d4b
WIP infer/outlives: add license
nikomatsakis Nov 7, 2017
0b7ebac
convert TODO in traits into a FIXME
nikomatsakis Nov 7, 2017
b3cad88
add FIXME for converting RegionVid to use `newtype_index!`
nikomatsakis Nov 7, 2017
d2b4f27
fix mir-opt NLL tests -- variable `'_#0r` is now `'static`
nikomatsakis Nov 7, 2017
2ccc3c7
factor out `free_region_binding_scope` helper
nikomatsakis Nov 7, 2017
2ffd2e0
leak the affects of closures on the free-region-map, like we used to
nikomatsakis Nov 7, 2017
d59af53
Initial attempt at refining liveness with "maybe initialized" analysis
Nashenas88 Nov 5, 2017
a164ae0
Take ownership of RegionInferenceContext in Borrows struct
Nashenas88 Nov 5, 2017
ce8e837
Fix tidy errors
Nashenas88 Nov 6, 2017
0bb2b66
Rename lifetimes on ConstraintGeneration, move macro impl to HasMoveD…
Nashenas88 Nov 7, 2017
e966e8c
Add initial attempt at ui/nll test for maybe-initialized drop
Nashenas88 Nov 7, 2017
ef236e4
Disable certain code on nll runs, update constraint generation to fix…
Nashenas88 Nov 8, 2017
49d53da
Simplify drop loop and account for terminators
Nashenas88 Nov 9, 2017
581b197
WIP add a bunch of debug statements
nikomatsakis Nov 9, 2017
69a0edf
Apply local effects for flow_init in constraint generation so we get …
Nashenas88 Nov 9, 2017
71ab17d
Shorten line lengths to fix tidy errors
Nashenas88 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