diff --git a/frontend/exporter/src/traits.rs b/frontend/exporter/src/traits.rs index c108e7f8d..caaa5e8e0 100644 --- a/frontend/exporter/src/traits.rs +++ b/frontend/exporter/src/traits.rs @@ -8,11 +8,13 @@ pub enum ImplExprPathChunk { AssocItem { item: AssocItem, predicate: Binder, + #[value(predicate.predicate_id(tcx))] predicate_id: PredicateId, index: usize, }, Parent { predicate: Binder, + #[value(predicate.predicate_id(tcx))] predicate_id: PredicateId, index: usize, }, @@ -92,12 +94,12 @@ pub mod rustc { AssocItem { item: AssocItem, predicate: PolyTraitPredicate<'tcx>, - predicate_id: PredicateId, + //predicate_id: PredicateId, index: usize, }, Parent { predicate: PolyTraitPredicate<'tcx>, - predicate_id: PredicateId, + //predicate_id: PredicateId, index: usize, }, } @@ -201,70 +203,61 @@ pub mod rustc { .collect() } - #[tracing::instrument(level = "trace", skip(s))] - fn path_to( - self, - s: &S, - target: PolyTraitRef<'tcx>, - param_env: rustc_middle::ty::ParamEnv<'tcx>, - ) -> Option> { - let tcx = s.base().tcx; + #[tracing::instrument(level = "trace", skip(s, param_env))] + fn path_to( + self, + s: &S, + target: PolyTraitRef<'tcx>, + param_env: rustc_middle::ty::ParamEnv<'tcx>, + ) -> Option> { + let tcx = s.base().tcx; - /// A candidate projects `self` along a path reaching some - /// predicate. A candidate is selected when its predicate - /// is the one expected, aka `target`. - #[derive(Debug)] - struct Candidate<'tcx> { - path: Path<'tcx>, - pred: PolyTraitPredicate<'tcx>, - } + /// A candidate projects `self` along a path reaching some + /// predicate. A candidate is selected when its predicate + /// is the one expected, aka `target`. + #[derive(Debug)] + struct Candidate<'tcx> { + path: Path<'tcx>, + pred: PolyTraitPredicate<'tcx>, + } - use std::collections::VecDeque; - let mut candidates: VecDeque> = vec![Candidate { - path: vec![], - pred: self, - }] - .into(); + use std::collections::VecDeque; + let mut candidates: VecDeque> = vec![Candidate { + path: vec![], + pred: self, + }] + .into(); - let target_pred = target.to_predicate(tcx); - let mut seen = std::collections::HashSet::new(); + let target_pred = target.upcast(tcx); + let mut seen = std::collections::HashSet::new(); - while let Some(candidate) = candidates.pop_front() { - { - // If a predicate was already seen, we know it is - // not the one we are looking for: we skip it. - if seen.contains(&candidate.pred) { - continue; + while let Some(candidate) = candidates.pop_front() { + { + // If a predicate was already seen, we know it is + // not the one we are looking for: we skip it. + if seen.contains(&candidate.pred) { + continue; + } + seen.insert(candidate.pred.clone()); } - seen.insert(candidate.pred.clone()); - } - tracing::trace!("candidate={:#?}", candidate); + //tracing::trace!("candidate={:#?}", candidate); - // if the candidate equals the target, let's return its path - if predicate_equality(candidate.pred.to_predicate(tcx), target_pred, param_env, s) { - return Some(candidate.path); - } + // if the candidate equals the target, let's return its path + if predicate_equality(candidate.pred.upcast(tcx), target_pred, param_env, s) { + return Some(candidate.path); + } - // otherwise, we add to the queue all paths reachable from the candidate - for (index, parent_pred) in self.parents_trait_predicates(s) { - let mut path = candidate.path.clone(); - path.push(PathChunk::Parent { - predicate: parent_pred.clone(), - predicate_id: parent_pred.predicate_id(s), - index, - }); - candidates.push_back(Candidate { - pred: parent_pred.clone(), - path, - }); - } - for (item, binder) in self.associated_items_trait_predicates(s) { - for (index, parent_pred) in binder.skip_binder().into_iter() { + // otherwise, we add to the queue all paths reachable from the candidate + for (index, parent_pred) in self.parents_trait_predicates(s) { let mut path = candidate.path.clone(); - path.push(PathChunk::AssocItem { - item, - predicate_id: parent_pred.predicate_id(s), + let span = tracing::span!(tracing::Level::TRACE, "trace_span2"); + let _span = span.enter(); + //let predicate_id = parent_pred.predicate_id(s); + let span = tracing::span!(tracing::Level::TRACE, "trace_span3"); + let _span = span.enter(); + path.push(PathChunk::Parent { predicate: parent_pred.clone(), + //predicate_id, index, }); candidates.push_back(Candidate { @@ -272,12 +265,26 @@ pub mod rustc { path, }); } + for (item, binder) in self.associated_items_trait_predicates(s) { + for (index, parent_pred) in binder.skip_binder().into_iter() { + let mut path = candidate.path.clone(); + path.push(PathChunk::AssocItem { + item, + //predicate_id: parent_pred.predicate_id(s), + predicate: parent_pred.clone(), + index, + }); + candidates.push_back(Candidate { + pred: parent_pred.clone(), + path, + }); + } + } } + None } - None } } -} impl ImplExprAtom { fn with_args(self, args: Vec, r#trait: TraitRef) -> ImplExpr { @@ -331,7 +338,7 @@ pub mod rustc { } } impl<'tcx> IntoImplExpr<'tcx> for rustc_middle::ty::PolyTraitRef<'tcx> { - #[tracing::instrument(level = "trace", skip(s))] + #[tracing::instrument(level = "trace", skip(s, param_env))] fn impl_expr>( &self, s: &S, @@ -434,7 +441,7 @@ pub mod rustc { Some((new_clause_no_binder, impl_expr, span.sinto(s))) } - #[tracing::instrument(level = "trace", skip(s))] + #[tracing::instrument(level = "trace", skip(s, param_env))] pub fn select_trait_candidate<'tcx, S: UnderOwnerState<'tcx>>( s: &S, param_env: rustc_middle::ty::ParamEnv<'tcx>, diff --git a/frontend/exporter/src/types/new/predicate_id.rs b/frontend/exporter/src/types/new/predicate_id.rs index 853a6ed0b..ab34ec546 100644 --- a/frontend/exporter/src/types/new/predicate_id.rs +++ b/frontend/exporter/src/types/new/predicate_id.rs @@ -27,6 +27,7 @@ mod rustc { } impl<'tcx, S: UnderOwnerState<'tcx>> IntoPredicateId<'tcx, S> for ty::Predicate<'tcx> { + #[tracing::instrument(level = "trace", skip(s))] fn predicate_id(&self, s: &S) -> PredicateId { // Here, we need to be careful about not hashing a `crate::Predicate`, // but `crate::Binder` instead, @@ -37,6 +38,7 @@ mod rustc { } impl<'tcx, S: UnderOwnerState<'tcx>> IntoPredicateId<'tcx, S> for ty::PolyTraitPredicate<'tcx> { + #[tracing::instrument(level = "trace", skip(s))] fn predicate_id(&self, s: &S) -> PredicateId { use ty::Upcast; let predicate: ty::Predicate<'tcx> = (*self).upcast(s.base().tcx);