Skip to content

Commit

Permalink
Auto merge of #55517 - nikomatsakis:universes, r=scalexm
Browse files Browse the repository at this point in the history
Universes

This PR transitions the compiler to use **universes** instead of the **leak-check**. It is marked as [WIP] for a few reasons:

- The diagnostics at present are terrible =)
- This changes the behavior of coherence, regressing some things that used to compile

The goals of this PR at present are:

- To start getting some eyes on the code
- To do a crater run
- To see the full travis results (due to #52452, I am not able to run the full test suite locally anymore at present)

The first few commits in the PR are changing how `evaluate` treats regions. We now track whether region comparisons occurred, reverting the "staticized" query approach that @arielb1 put in. The problem with "staticized" queries is that it relied on the leak-check to get higher-ranked things correct, and we are removing the leak-check in this PR series, so that caused problems.

You can see at the end a collection of test updates. Mostly we behave the same but with atrocious diagnostics, but there are a number of cases where we used to error and now no longer do, as well as single case where we used to **not** error but we now do (the coherence-subtyping change).

(Note: it would be possible to do a version of leak-check that propagates universe information and recover the old behavior. I am reluctant to do so because I'd like to leave us room to get more precise -- e.g., I want to eventually handle things like `exists<'a> { for<'b> { if ('a: 'b) { 'a: 'b } } }` which presently the leak-check cannot cope with etc. Also because it seems more consistent to me: most folks I've talked to expect the new behavior and are surprised to learn that binding sites were so significant before when it comes to coherence. One question is, though, to what extent are people relying on this in the wild?)
  • Loading branch information
bors committed Jan 3, 2019
2 parents 2442823 + 8e89184 commit c0bbc39
Show file tree
Hide file tree
Showing 115 changed files with 1,563 additions and 1,777 deletions.
60 changes: 48 additions & 12 deletions src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {

ty::ReEmpty => ("the empty lifetime".to_owned(), None),

ty::RePlaceholder(_) => (format!("any other region"), None),

// FIXME(#13998) RePlaceholder should probably print like
// ReFree rather than dumping Debug output on the user.
//
// We shouldn't really be having unification failures with ReVar
// and ReLateBound though.
ty::RePlaceholder(..) | ty::ReVar(_) | ty::ReLateBound(..) | ty::ReErased => {
ty::ReVar(_) | ty::ReLateBound(..) | ty::ReErased => {
(format!("lifetime {:?}", region), None)
}

Expand Down Expand Up @@ -324,8 +326,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
// 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();
if sub.is_placeholder() || sup.is_placeholder() {
self.report_placeholder_failure(region_scope_tree, origin, sub, sup)
.emit();
} else {
self.report_concrete_failure(region_scope_tree, origin, sub, sup)
.emit();
}
}

RegionResolutionError::GenericBoundFailure(origin, param_ty, sub) => {
Expand All @@ -339,20 +346,39 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
}

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,
);
if sub_r.is_placeholder() {
self.report_placeholder_failure(
region_scope_tree,
sub_origin,
sub_r,
sup_r,
)
.emit();
} else if sup_r.is_placeholder() {
self.report_placeholder_failure(
region_scope_tree,
sup_origin,
sub_r,
sup_r,
)
.emit();
} else {
self.report_sub_sup_conflict(
region_scope_tree,
var_origin,
sub_origin,
sub_r,
sup_origin,
sup_r,
);
}
}
}
}
Expand Down Expand Up @@ -407,7 +433,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
errors.sort_by_key(|u| match *u {
RegionResolutionError::ConcreteFailure(ref sro, _, _) => sro.span(),
RegionResolutionError::GenericBoundFailure(ref sro, _, _) => sro.span(),
RegionResolutionError::SubSupConflict(ref rvo, _, _, _, _) => rvo.span(),
RegionResolutionError::SubSupConflict(_, ref rvo, _, _, _, _) => rvo.span(),
});
errors
}
Expand Down Expand Up @@ -1306,6 +1332,16 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {

match (&sup_origin, &sub_origin) {
(&infer::Subtype(ref sup_trace), &infer::Subtype(ref sub_trace)) => {
debug!("report_sub_sup_conflict: var_origin={:?}", var_origin);
debug!("report_sub_sup_conflict: sub_region={:?}", sub_region);
debug!("report_sub_sup_conflict: sub_origin={:?}", sub_origin);
debug!("report_sub_sup_conflict: sup_region={:?}", sup_region);
debug!("report_sub_sup_conflict: sup_origin={:?}", sup_origin);
debug!("report_sub_sup_conflict: sup_trace={:?}", sup_trace);
debug!("report_sub_sup_conflict: sub_trace={:?}", sub_trace);
debug!("report_sub_sup_conflict: sup_trace.values={:?}", sup_trace.values);
debug!("report_sub_sup_conflict: sub_trace.values={:?}", sub_trace.values);

if let (Some((sup_expected, sup_found)), Some((sub_expected, sub_found))) = (
self.values_str(&sup_trace.values),
self.values_str(&sub_trace.values),
Expand Down
8 changes: 5 additions & 3 deletions src/librustc/infer/error_reporting/nice_region_error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use util::common::ErrorReported;
mod different_lifetimes;
mod find_anon_type;
mod named_anon_conflict;
mod placeholder_error;
mod outlives_closure;
mod static_impl_trait;
mod util;
Expand Down Expand Up @@ -58,19 +59,20 @@ impl<'cx, 'gcx, 'tcx> NiceRegionError<'cx, 'gcx, 'tcx> {
// Due to the improved diagnostics returned by the MIR borrow checker, only a subset of
// the nice region errors are required when running under the MIR borrow checker.
self.try_report_named_anon_conflict()
.or_else(|| self.try_report_placeholder_conflict())
}

pub fn try_report(&self) -> Option<ErrorReported> {
self.try_report_named_anon_conflict()
self.try_report_from_nll()
.or_else(|| self.try_report_anon_anon_conflict())
.or_else(|| self.try_report_outlives_closure())
.or_else(|| self.try_report_static_impl_trait())
}

pub fn get_regions(&self) -> (Span, ty::Region<'tcx>, ty::Region<'tcx>) {
match (&self.error, self.regions) {
(&Some(ConcreteFailure(ref origin, sub, sup)), None) => (origin.span(), sub, sup),
(&Some(SubSupConflict(_, ref origin, sub, _, sup)), None) => (origin.span(), sub, sup),
(Some(ConcreteFailure(origin, sub, sup)), None) => (origin.span(), sub, sup),
(Some(SubSupConflict(_, _, origin, sub, _, sup)), None) => (origin.span(), sub, sup),
(None, Some((span, sub, sup))) => (span, sub, sup),
(Some(_), Some(_)) => panic!("incorrectly built NiceRegionError"),
_ => panic!("trying to report on an incorrect lifetime failure"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
/// ...because it cannot outlive this closure
/// ```
pub(super) fn try_report_outlives_closure(&self) -> Option<ErrorReported> {
if let Some(SubSupConflict(origin,
if let Some(SubSupConflict(_,
origin,
ref sub_origin,
_,
ref sup_origin,
Expand Down
Loading

0 comments on commit c0bbc39

Please sign in to comment.