Skip to content

Commit

Permalink
Lots'O Goodies (#25)
Browse files Browse the repository at this point in the history
* Add Bottom Up -> Top Down jump and implementors

* Typo and using details for Toggle

* Highlight jumped to obligations and update GoalKind in aadebug::tree

* Force rerender of workspace when jump target changes

* Cache panel contents and force rerender on programatic change.

* Remove unused ty mod

* Remove unused type CandidateImplementors
  • Loading branch information
gavinleroy authored Aug 6, 2024
1 parent 23ef5fa commit 1a680ed
Show file tree
Hide file tree
Showing 41 changed files with 1,374 additions and 950 deletions.
2 changes: 1 addition & 1 deletion crates/argus-ext/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub mod iter;
// Most of the rustc code is copied from private rustc modules
// and it's not worth fixing all the clippy warnings.
#[allow(clippy::pedantic)]
mod rustc;
pub mod rustc;
pub mod ty;
pub mod utils;

Expand Down
98 changes: 49 additions & 49 deletions crates/argus-ext/src/rustc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ pub trait InferCtxtExt<'tcx> {
error: ty::Predicate<'tcx>,
) -> bool;

// fn find_similar_impl_candidates(
// &self,
// trait_pred: ty::PolyTraitPredicate<'tcx>,
// ) -> Vec<ImplCandidate<'tcx>>;
fn find_similar_impl_candidates(
&self,
trait_pred: ty::PolyTraitPredicate<'tcx>,
) -> Vec<ImplCandidate<'tcx>>;

fn fuzzy_match_tys(
&self,
Expand Down Expand Up @@ -219,52 +219,52 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
}
}

// fn find_similar_impl_candidates(
// &self,
// trait_pred: ty::PolyTraitPredicate<'tcx>,
// ) -> Vec<ImplCandidate<'tcx>> {
// let mut candidates: Vec<_> = self
// .tcx
// .all_impls(trait_pred.def_id())
// .filter_map(|def_id| {
// let imp = self.tcx.impl_trait_header(def_id).unwrap();
// if imp.polarity == ty::ImplPolarity::Negative
// || !self.tcx.is_user_visible_dep(def_id.krate)
// {
// return None;
// }
// let imp = imp.trait_ref.skip_binder();
fn find_similar_impl_candidates(
&self,
trait_pred: ty::PolyTraitPredicate<'tcx>,
) -> Vec<ImplCandidate<'tcx>> {
let mut candidates: Vec<_> = self
.tcx
.all_impls(trait_pred.def_id())
.filter_map(|def_id| {
let imp = self.tcx.impl_trait_header(def_id).unwrap();
if imp.polarity == ty::ImplPolarity::Negative
|| !self.tcx.is_user_visible_dep(def_id.krate)
{
return None;
}
let imp = imp.trait_ref.skip_binder();

// self
// .fuzzy_match_tys(
// trait_pred.skip_binder().self_ty(),
// imp.self_ty(),
// false,
// )
// .map(|similarity| ImplCandidate {
// trait_ref: imp,
// similarity,
// impl_def_id: def_id,
// })
// .or(Some(ImplCandidate {
// trait_ref: imp,
// similarity: CandidateSimilarity::Other,
// impl_def_id: def_id,
// }))
// })
// .collect();
// if candidates
// .iter()
// .any(|c| matches!(c.similarity, CandidateSimilarity::Exact { .. }))
// {
// // If any of the candidates is a perfect match, we don't want to show all of them.
// // This is particularly relevant for the case of numeric types (as they all have the
// // same category).
// candidates
// .retain(|c| matches!(c.similarity, CandidateSimilarity::Exact { .. }));
// }
// candidates
// }
self
.fuzzy_match_tys(
trait_pred.skip_binder().self_ty(),
imp.self_ty(),
false,
)
.map(|similarity| ImplCandidate {
trait_ref: imp,
similarity,
impl_def_id: def_id,
})
.or(Some(ImplCandidate {
trait_ref: imp,
similarity: CandidateSimilarity::Other,
impl_def_id: def_id,
}))
})
.collect();
if candidates
.iter()
.any(|c| matches!(c.similarity, CandidateSimilarity::Exact { .. }))
{
// If any of the candidates is a perfect match, we don't want to show all of them.
// This is particularly relevant for the case of numeric types (as they all have the
// same category).
candidates
.retain(|c| matches!(c.similarity, CandidateSimilarity::Exact { .. }));
}
candidates
}

fn fuzzy_match_tys(
&self,
Expand Down
16 changes: 11 additions & 5 deletions crates/argus/src/aadebug/dnf.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
use smallvec::{smallvec, SmallVec};

const MAX_CONJUNCTS: usize = 4;

// TODO: this is a very naive implementation, we can certainly make it more efficient.
pub struct And<I: Copy>(Vec<I>);
#[derive(Clone)]
pub struct And<I: Copy>(SmallVec<[I; MAX_CONJUNCTS]>);

pub struct Dnf<I: Copy>(Vec<And<I>>);

impl<I: Copy> IntoIterator for And<I> {
type Item = I;
type IntoIter = std::vec::IntoIter<I>;
type IntoIter = smallvec::IntoIter<[I; MAX_CONJUNCTS]>;

fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
Expand All @@ -31,8 +37,8 @@ impl<I: Copy> And<I> {
}

impl<I: Copy> Dnf<I> {
pub fn into_iter_conjuncts(self) -> impl Iterator<Item = And<I>> {
self.0.into_iter()
pub fn iter_conjuncts(&self) -> impl Iterator<Item = &And<I>> {
self.0.iter()
}

pub fn and(vs: impl Iterator<Item = Self>) -> Option<Self> {
Expand Down Expand Up @@ -63,7 +69,7 @@ impl<I: Copy> Dnf<I> {

#[inline]
pub fn single(i: I) -> Self {
Self(vec![And(vec![i])])
Self(vec![And(smallvec![i])])
}

#[inline]
Expand Down
31 changes: 15 additions & 16 deletions crates/argus/src/aadebug/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
mod dnf;
pub(crate) mod tree;
mod ty;

use std::time::Instant;

use anyhow::Result;
use argus_ext::ty::EvaluationResultExt;
use index_vec::IndexVec;
use rustc_data_structures::fx::FxHashMap as HashMap;
use rustc_infer::traits::solve::GoalSource;
use rustc_trait_selection::solve::inspect::{InspectCandidate, InspectGoal};
use rustc_utils::timer;
use serde::Serialize;
use serde_json as json;
#[cfg(feature = "testing")]
use ts_rs::TS;

Expand All @@ -26,7 +27,13 @@ pub struct Storage<'tcx> {
#[cfg_attr(feature = "testing", derive(TS))]
#[cfg_attr(feature = "testing", ts(export))]
pub struct AnalysisResults {
problematic_sets: Vec<tree::SetHeuristic>,
pub problematic_sets: Vec<tree::SetHeuristic>,

#[cfg_attr(
feature = "testing",
ts(type = "Record<ProofNodeIdx, ImplHeader[]>")
)]
pub impl_candidates: HashMap<ProofNodeIdx, Vec<json::Value>>,
}

impl<'tcx> Storage<'tcx> {
Expand Down Expand Up @@ -107,27 +114,19 @@ impl<'tcx> Storage<'tcx> {
root: ProofNodeIdx,
topo: &TreeTopology,
) -> AnalysisResults {
let tree = &tree::T {
root,
ns: &self.ns,
topology: topo,
maybe_ambiguous: false,
};

let tree = &tree::T::new(root, &self.ns, topo, false);
let tree_start = Instant::now();

let sets =
tree
.iter_correction_sets()
.fold(Vec::new(), |mut sets, conjunct| {
sets.push(tree.weight(&conjunct));
sets
});
let mut sets = vec![];
tree.for_correction_set(|conjunct| {
sets.push(tree.weight(&conjunct));
});

timer::elapsed("aadeg::into_results", tree_start);

AnalysisResults {
problematic_sets: sets,
impl_candidates: tree.reportable_impl_candidates(),
}
}
}
Loading

0 comments on commit 1a680ed

Please sign in to comment.