More tracing instrumentation
This commit is contained in:
parent
83f147b3ba
commit
9b5aa063d8
39 changed files with 252 additions and 323 deletions
|
@ -187,11 +187,11 @@ impl<'a, 'tcx> At<'a, 'tcx> {
|
|||
impl<'a, 'tcx> Trace<'a, 'tcx> {
|
||||
/// Makes `a <: b` where `a` may or may not be expected (if
|
||||
/// `a_is_expected` is true, then `a` is expected).
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
pub fn sub<T>(self, a: T, b: T) -> InferResult<'tcx, ()>
|
||||
where
|
||||
T: Relate<'tcx>,
|
||||
{
|
||||
debug!("sub({:?} <: {:?})", a, b);
|
||||
let Trace { at, trace, a_is_expected } = self;
|
||||
at.infcx.commit_if_ok(|_| {
|
||||
let mut fields = at.infcx.combine_fields(trace, at.param_env);
|
||||
|
@ -204,11 +204,11 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
|
|||
|
||||
/// Makes `a == b`; the expectation is set by the call to
|
||||
/// `trace()`.
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
pub fn eq<T>(self, a: T, b: T) -> InferResult<'tcx, ()>
|
||||
where
|
||||
T: Relate<'tcx>,
|
||||
{
|
||||
debug!("eq({:?} == {:?})", a, b);
|
||||
let Trace { at, trace, a_is_expected } = self;
|
||||
at.infcx.commit_if_ok(|_| {
|
||||
let mut fields = at.infcx.combine_fields(trace, at.param_env);
|
||||
|
@ -219,11 +219,11 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
|
|||
})
|
||||
}
|
||||
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
pub fn lub<T>(self, a: T, b: T) -> InferResult<'tcx, T>
|
||||
where
|
||||
T: Relate<'tcx>,
|
||||
{
|
||||
debug!("lub({:?} \\/ {:?})", a, b);
|
||||
let Trace { at, trace, a_is_expected } = self;
|
||||
at.infcx.commit_if_ok(|_| {
|
||||
let mut fields = at.infcx.combine_fields(trace, at.param_env);
|
||||
|
@ -234,11 +234,11 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
|
|||
})
|
||||
}
|
||||
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
pub fn glb<T>(self, a: T, b: T) -> InferResult<'tcx, T>
|
||||
where
|
||||
T: Relate<'tcx>,
|
||||
{
|
||||
debug!("glb({:?} /\\ {:?})", a, b);
|
||||
let Trace { at, trace, a_is_expected } = self;
|
||||
at.infcx.commit_if_ok(|_| {
|
||||
let mut fields = at.infcx.combine_fields(trace, at.param_env);
|
||||
|
|
|
@ -49,6 +49,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||
/// the same thing happens, but the resulting query is marked as ambiguous.
|
||||
/// - Finally, if any of the obligations result in a hard error,
|
||||
/// then `Err(NoSolution)` is returned.
|
||||
#[instrument(skip(self, inference_vars, answer, fulfill_cx), level = "trace")]
|
||||
pub fn make_canonicalized_query_response<T>(
|
||||
&self,
|
||||
inference_vars: CanonicalVarValues<'tcx>,
|
||||
|
@ -62,7 +63,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||
let query_response = self.make_query_response(inference_vars, answer, fulfill_cx)?;
|
||||
let canonical_result = self.canonicalize_response(query_response);
|
||||
|
||||
debug!("make_canonicalized_query_response: canonical_result = {:#?}", canonical_result);
|
||||
debug!("canonical_result = {:#?}", canonical_result);
|
||||
|
||||
Ok(self.tcx.arena.alloc(canonical_result))
|
||||
}
|
||||
|
@ -94,6 +95,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||
|
||||
/// Helper for `make_canonicalized_query_response` that does
|
||||
/// everything up until the final canonicalization.
|
||||
#[instrument(skip(self, fulfill_cx), level = "debug")]
|
||||
fn make_query_response<T>(
|
||||
&self,
|
||||
inference_vars: CanonicalVarValues<'tcx>,
|
||||
|
@ -105,13 +107,6 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||
{
|
||||
let tcx = self.tcx;
|
||||
|
||||
debug!(
|
||||
"make_query_response(\
|
||||
inference_vars={:?}, \
|
||||
answer={:?})",
|
||||
inference_vars, answer,
|
||||
);
|
||||
|
||||
// Select everything, returning errors.
|
||||
let true_errors = fulfill_cx.select_where_possible(self).err().unwrap_or_else(Vec::new);
|
||||
debug!("true_errors = {:#?}", true_errors);
|
||||
|
|
|
@ -94,13 +94,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
/// the actual types (`?T`, `Option<?T>`) -- and remember that
|
||||
/// after the snapshot is popped, the variable `?T` is no longer
|
||||
/// unified.
|
||||
#[instrument(skip(self, f), level = "debug")]
|
||||
pub fn fudge_inference_if_ok<T, E, F>(&self, f: F) -> Result<T, E>
|
||||
where
|
||||
F: FnOnce() -> Result<T, E>,
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
debug!("fudge_inference_if_ok()");
|
||||
|
||||
let variable_lengths = self.variable_lengths();
|
||||
let (mut fudger, value) = self.probe(|_| {
|
||||
match f() {
|
||||
|
|
|
@ -9,6 +9,7 @@ use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation};
|
|||
use rustc_middle::ty::{self, Binder, TypeFoldable};
|
||||
|
||||
impl<'a, 'tcx> CombineFields<'a, 'tcx> {
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
pub fn higher_ranked_sub<T>(
|
||||
&mut self,
|
||||
a: Binder<'tcx, T>,
|
||||
|
@ -18,8 +19,6 @@ impl<'a, 'tcx> CombineFields<'a, 'tcx> {
|
|||
where
|
||||
T: Relate<'tcx>,
|
||||
{
|
||||
debug!("higher_ranked_sub(a={:?}, b={:?})", a, b);
|
||||
|
||||
// Rather than checking the subtype relationship between `a` and `b`
|
||||
// as-is, we need to do some extra work here in order to make sure
|
||||
// that function subtyping works correctly with respect to regions
|
||||
|
|
|
@ -807,8 +807,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
#[instrument(skip(self, snapshot), level = "debug")]
|
||||
fn rollback_to(&self, cause: &str, snapshot: CombinedSnapshot<'a, 'tcx>) {
|
||||
debug!("rollback_to(cause={})", cause);
|
||||
let CombinedSnapshot {
|
||||
undo_snapshot,
|
||||
region_constraints_snapshot,
|
||||
|
@ -825,8 +825,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
inner.unwrap_region_constraints().rollback_to(region_constraints_snapshot);
|
||||
}
|
||||
|
||||
#[instrument(skip(self, snapshot), level = "debug")]
|
||||
fn commit_from(&self, snapshot: CombinedSnapshot<'a, 'tcx>) {
|
||||
debug!("commit_from()");
|
||||
let CombinedSnapshot {
|
||||
undo_snapshot,
|
||||
region_constraints_snapshot: _,
|
||||
|
@ -841,11 +841,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
}
|
||||
|
||||
/// Executes `f` and commit the bindings.
|
||||
#[instrument(skip(self, f), level = "debug")]
|
||||
pub fn commit_unconditionally<R, F>(&self, f: F) -> R
|
||||
where
|
||||
F: FnOnce(&CombinedSnapshot<'a, 'tcx>) -> R,
|
||||
{
|
||||
debug!("commit_unconditionally()");
|
||||
let snapshot = self.start_snapshot();
|
||||
let r = f(&snapshot);
|
||||
self.commit_from(snapshot);
|
||||
|
@ -853,11 +853,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
}
|
||||
|
||||
/// Execute `f` and commit the bindings if closure `f` returns `Ok(_)`.
|
||||
#[instrument(skip(self, f), level = "debug")]
|
||||
pub fn commit_if_ok<T, E, F>(&self, f: F) -> Result<T, E>
|
||||
where
|
||||
F: FnOnce(&CombinedSnapshot<'a, 'tcx>) -> Result<T, E>,
|
||||
{
|
||||
debug!("commit_if_ok()");
|
||||
let snapshot = self.start_snapshot();
|
||||
let r = f(&snapshot);
|
||||
debug!("commit_if_ok() -- r.is_ok() = {}", r.is_ok());
|
||||
|
@ -873,11 +873,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
}
|
||||
|
||||
/// Execute `f` then unroll any bindings it creates.
|
||||
#[instrument(skip(self, f), level = "debug")]
|
||||
pub fn probe<R, F>(&self, f: F) -> R
|
||||
where
|
||||
F: FnOnce(&CombinedSnapshot<'a, 'tcx>) -> R,
|
||||
{
|
||||
debug!("probe()");
|
||||
let snapshot = self.start_snapshot();
|
||||
let r = f(&snapshot);
|
||||
self.rollback_to("probe", snapshot);
|
||||
|
@ -885,11 +885,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
}
|
||||
|
||||
/// If `should_skip` is true, then execute `f` then unroll any bindings it creates.
|
||||
#[instrument(skip(self, f), level = "debug")]
|
||||
pub fn probe_maybe_skip_leak_check<R, F>(&self, should_skip: bool, f: F) -> R
|
||||
where
|
||||
F: FnOnce(&CombinedSnapshot<'a, 'tcx>) -> R,
|
||||
{
|
||||
debug!("probe()");
|
||||
let snapshot = self.start_snapshot();
|
||||
let was_skip_leak_check = self.skip_leak_check.get();
|
||||
if should_skip {
|
||||
|
@ -946,18 +946,19 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
})
|
||||
}
|
||||
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
pub fn sub_regions(
|
||||
&self,
|
||||
origin: SubregionOrigin<'tcx>,
|
||||
a: ty::Region<'tcx>,
|
||||
b: ty::Region<'tcx>,
|
||||
) {
|
||||
debug!("sub_regions({:?} <: {:?})", a, b);
|
||||
self.inner.borrow_mut().unwrap_region_constraints().make_subregion(origin, a, b);
|
||||
}
|
||||
|
||||
/// Require that the region `r` be equal to one of the regions in
|
||||
/// the set `regions`.
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
pub fn member_constraint(
|
||||
&self,
|
||||
opaque_type_def_id: DefId,
|
||||
|
@ -966,7 +967,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
region: ty::Region<'tcx>,
|
||||
in_regions: &Lrc<Vec<ty::Region<'tcx>>>,
|
||||
) {
|
||||
debug!("member_constraint({:?} <: {:?})", region, in_regions);
|
||||
self.inner.borrow_mut().unwrap_region_constraints().member_constraint(
|
||||
opaque_type_def_id,
|
||||
definition_span,
|
||||
|
|
|
@ -507,6 +507,7 @@ where
|
|||
true
|
||||
}
|
||||
|
||||
#[instrument(skip(self, info), level = "trace")]
|
||||
fn relate_with_variance<T: Relate<'tcx>>(
|
||||
&mut self,
|
||||
variance: ty::Variance,
|
||||
|
@ -514,23 +515,22 @@ where
|
|||
a: T,
|
||||
b: T,
|
||||
) -> RelateResult<'tcx, T> {
|
||||
debug!("relate_with_variance(variance={:?}, a={:?}, b={:?})", variance, a, b);
|
||||
|
||||
let old_ambient_variance = self.ambient_variance;
|
||||
self.ambient_variance = self.ambient_variance.xform(variance);
|
||||
self.ambient_variance_info = self.ambient_variance_info.xform(info);
|
||||
|
||||
debug!("relate_with_variance: ambient_variance = {:?}", self.ambient_variance);
|
||||
debug!(?self.ambient_variance);
|
||||
|
||||
let r = self.relate(a, b)?;
|
||||
|
||||
self.ambient_variance = old_ambient_variance;
|
||||
|
||||
debug!("relate_with_variance: r={:?}", r);
|
||||
debug!(?r);
|
||||
|
||||
Ok(r)
|
||||
}
|
||||
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
fn tys(&mut self, a: Ty<'tcx>, mut b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
|
||||
let a = self.infcx.shallow_resolve(a);
|
||||
|
||||
|
@ -573,7 +573,7 @@ where
|
|||
}
|
||||
|
||||
_ => {
|
||||
debug!("tys(a={:?}, b={:?}, variance={:?})", a, b, self.ambient_variance);
|
||||
debug!(?a, ?b, ?self.ambient_variance);
|
||||
|
||||
// Will also handle unification of `IntVar` and `FloatVar`.
|
||||
self.infcx.super_combine_tys(self, a, b)
|
||||
|
@ -581,18 +581,19 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[instrument(skip(self), level = "trace")]
|
||||
fn regions(
|
||||
&mut self,
|
||||
a: ty::Region<'tcx>,
|
||||
b: ty::Region<'tcx>,
|
||||
) -> RelateResult<'tcx, ty::Region<'tcx>> {
|
||||
debug!("regions(a={:?}, b={:?}, variance={:?})", a, b, self.ambient_variance);
|
||||
debug!(?self.ambient_variance);
|
||||
|
||||
let v_a = self.replace_bound_region(a, ty::INNERMOST, &self.a_scopes);
|
||||
let v_b = self.replace_bound_region(b, ty::INNERMOST, &self.b_scopes);
|
||||
|
||||
debug!("regions: v_a = {:?}", v_a);
|
||||
debug!("regions: v_b = {:?}", v_b);
|
||||
debug!(?v_a);
|
||||
debug!(?v_b);
|
||||
|
||||
if self.ambient_covariance() {
|
||||
// Covariance: a <= b. Hence, `b: a`.
|
||||
|
@ -628,6 +629,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[instrument(skip(self), level = "trace")]
|
||||
fn binders<T>(
|
||||
&mut self,
|
||||
a: ty::Binder<'tcx, T>,
|
||||
|
@ -655,7 +657,7 @@ where
|
|||
// - Instantiate binders on `b` universally, yielding a universe U1.
|
||||
// - Instantiate binders on `a` existentially in U1.
|
||||
|
||||
debug!("binders({:?}: {:?}, ambient_variance={:?})", a, b, self.ambient_variance);
|
||||
debug!(?self.ambient_variance);
|
||||
|
||||
if let (Some(a), Some(b)) = (a.no_bound_vars(), b.no_bound_vars()) {
|
||||
// Fast path for the common case.
|
||||
|
@ -673,8 +675,8 @@ where
|
|||
let b_scope = self.create_scope(b, UniversallyQuantified(true));
|
||||
let a_scope = self.create_scope(a, UniversallyQuantified(false));
|
||||
|
||||
debug!("binders: a_scope = {:?} (existential)", a_scope);
|
||||
debug!("binders: b_scope = {:?} (universal)", b_scope);
|
||||
debug!(?a_scope, "(existential)");
|
||||
debug!(?b_scope, "(universal)");
|
||||
|
||||
self.b_scopes.push(b_scope);
|
||||
self.a_scopes.push(a_scope);
|
||||
|
@ -717,8 +719,8 @@ where
|
|||
let a_scope = self.create_scope(a, UniversallyQuantified(true));
|
||||
let b_scope = self.create_scope(b, UniversallyQuantified(false));
|
||||
|
||||
debug!("binders: a_scope = {:?} (universal)", a_scope);
|
||||
debug!("binders: b_scope = {:?} (existential)", b_scope);
|
||||
debug!(?a_scope, "(universal)");
|
||||
debug!(?b_scope, "(existential)");
|
||||
|
||||
self.a_scopes.push(a_scope);
|
||||
self.b_scopes.push(b_scope);
|
||||
|
|
|
@ -540,6 +540,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
|
|||
});
|
||||
}
|
||||
|
||||
#[instrument(skip(self, origin), level = "debug")]
|
||||
pub fn make_subregion(
|
||||
&mut self,
|
||||
origin: SubregionOrigin<'tcx>,
|
||||
|
@ -547,10 +548,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
|
|||
sup: Region<'tcx>,
|
||||
) {
|
||||
// cannot add constraints once regions are resolved
|
||||
debug!(
|
||||
"RegionConstraintCollector: make_subregion({:?}, {:?}) due to {:?}",
|
||||
sub, sup, origin
|
||||
);
|
||||
debug!("origin = {:#?}", origin);
|
||||
|
||||
match (sub, sup) {
|
||||
(&ReLateBound(..), _) | (_, &ReLateBound(..)) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue