Skip to content

Commit

Permalink
Fix predicate_id.
Browse files Browse the repository at this point in the history
  • Loading branch information
maximebuyse committed Jul 24, 2024
1 parent ea402a9 commit 2cb1f89
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
29 changes: 17 additions & 12 deletions frontend/exporter/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ pub enum ImplExprPathChunk {
AssocItem {
item: AssocItem,
predicate: Binder<TraitPredicate>,
predicate_id: PredicateId,
#[value(predicate.predicate_id(tcx))]predicate_id: PredicateId,
index: usize,
},
Parent {
predicate: Binder<TraitPredicate>,
predicate_id: PredicateId,
#[value(predicate.predicate_id(tcx))]predicate_id: PredicateId,
index: usize,
},
}
Expand Down Expand Up @@ -92,12 +92,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,
},
}
Expand Down Expand Up @@ -201,7 +201,7 @@ pub mod rustc {
.collect()
}

#[tracing::instrument(level = "trace", skip(s))]
#[tracing::instrument(level = "trace", skip(s, param_env))]
fn path_to(
self,
s: &S,
Expand All @@ -226,7 +226,7 @@ pub mod rustc {
}]
.into();

let target_pred = target.to_predicate(tcx);
let target_pred = target.upcast(tcx);
let mut seen = std::collections::HashSet::new();

while let Some(candidate) = candidates.pop_front() {
Expand All @@ -238,19 +238,24 @@ pub mod rustc {
}
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) {
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();
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: parent_pred.predicate_id(s),
//predicate_id,
index,
});
candidates.push_back(Candidate {
Expand All @@ -263,7 +268,7 @@ pub mod rustc {
let mut path = candidate.path.clone();
path.push(PathChunk::AssocItem {
item,
predicate_id: parent_pred.predicate_id(s),
//predicate_id: parent_pred.predicate_id(s),
predicate: parent_pred.clone(),
index,
});
Expand Down Expand Up @@ -331,7 +336,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<S: UnderOwnerState<'tcx>>(
&self,
s: &S,
Expand Down Expand Up @@ -434,7 +439,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>,
Expand Down
2 changes: 2 additions & 0 deletions frontend/exporter/src/types/new/predicate_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<crate::PredicateKind>` instead,
Expand All @@ -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);
Expand Down

0 comments on commit 2cb1f89

Please sign in to comment.