Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions crates/argus-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "argus-cli"
version = "0.1.17"
version = "0.1.18"
edition = "2021"
authors = ["Gavin Gray <gavinleroy6@gmail.com>"]
repository = "https://github.com/cognitive-engineering-lab/argus"
Expand All @@ -10,8 +10,8 @@ license = "MIT"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
argus-lib = { version = "0.1.17", path = "../argus" }
argus-ext = { version = "0.1.17", path = "../argus-ext" }
argus-lib = { version = "0.1.18", path = "../argus" }
argus-ext = { version = "0.1.18", path = "../argus-ext" }
rustc_plugin = "=0.13.0-nightly-2025-03-03"

rustc_utils.workspace = true
Expand Down
8 changes: 6 additions & 2 deletions crates/argus-cli/tests/workspaces/diesel/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
mod bad_insertable_field;
// mod bad_sql_query; // Currerently hangs rustc
//TODO `argus bundle` fails for this module,
//we're not "totally" sure why, but there are
//macros and lots of traits involved...
//mod bad_insertable_field;
mod invalid_query;
mod invalid_select;
mod overflow;

// mod bad_sql_query; // Currerently hangs rustc
// mod queryable_order_mismatch; // Currerently hangs rustc

fn main() {}
2 changes: 1 addition & 1 deletion crates/argus-ext/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "argus-ext"
version = "0.1.17"
version = "0.1.18"
edition = "2021"
authors = ["Gavin Gray <gavinleroy6@gmail.com>"]
repository = "https://github.com/cognitive-engineering-lab/argus"
Expand Down
46 changes: 12 additions & 34 deletions crates/argus-ext/src/rustc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,9 @@ pub trait InferCtxtExt<'tcx> {
error: ty::Predicate<'tcx>,
) -> bool;

/// Private in TypeErrorCtxt
fn find_similar_impl_candidates(
fn all_impls(
&self,
trait_pred: ty::PolyTraitPredicate<'tcx>,
def_id: rustc_span::def_id::DefId,
) -> Vec<ImplCandidate<'tcx>>;

/// Public (wrapping for local `CandidateSimilarity`)
Expand Down Expand Up @@ -250,13 +249,13 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
}
}

fn find_similar_impl_candidates(
fn all_impls(
&self,
trait_pred: ty::PolyTraitPredicate<'tcx>,
def_id: rustc_span::def_id::DefId,
) -> Vec<ImplCandidate<'tcx>> {
let mut candidates: Vec<_> = self
self
.tcx
.all_impls(trait_pred.def_id())
.all_impls(def_id)
.filter_map(|def_id| {
let imp = self.tcx.impl_trait_header(def_id).unwrap();

Expand All @@ -266,34 +265,13 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
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,
})
Some(ImplCandidate {
trait_ref: imp.trait_ref.skip_binder(),
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
.collect()
}

fn fuzzy_match_tys(
Expand Down
2 changes: 1 addition & 1 deletion crates/argus-ser-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "argus-ser-macros"
version = "0.1.17"
version = "0.1.18"
edition = "2021"
authors = ["Gavin Gray <gavinleroy6@gmail.com>"]
repository = "https://github.com/cognitive-engineering-lab/argus"
Expand Down
6 changes: 3 additions & 3 deletions crates/argus-ser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "argus-ser"
version = "0.1.17"
version = "0.1.18"
edition = "2021"
authors = ["Gavin Gray <gavinleroy6@gmail.com>"]
repository = "https://github.com/cognitive-engineering-lab/argus"
Expand Down Expand Up @@ -28,8 +28,8 @@ ts-rs = { version = "7.1.1", features = [
"no-serde-warnings",
], optional = true }

argus-ser-macros = { version = "0.1.17", path = "../argus-ser-macros" }
argus-ext = { version = "0.1.17", path = "../argus-ext" }
argus-ser-macros = { version = "0.1.18", path = "../argus-ser-macros" }
argus-ext = { version = "0.1.18", path = "../argus-ext" }

[dev-dependencies]
argus-ser = { path = ".", features = ["testing"] }
Expand Down
3 changes: 1 addition & 2 deletions crates/argus-ser/src/argus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,9 @@ pub(crate) fn group_predicates_by_ty<'tcx>(

pub fn get_opt_impl_header(
tcx: ty::TyCtxt,
def_id: DefId,
impl_def_id: DefId,
) -> Option<ImplHeader> {
use rustc_data_structures::fx::FxIndexSet;
let impl_def_id = def_id;

let trait_ref = tcx.impl_trait_ref(impl_def_id)?.instantiate_identity();
let args = ty::GenericArgs::identity_for_item(tcx, impl_def_id);
Expand Down
19 changes: 15 additions & 4 deletions crates/argus-ser/src/interner.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::collections::HashMap; // FIXME: change back to above
use std::{
cell::RefCell,
cmp::{Eq, PartialEq},
hash::Hash,
};

use index_vec::{Idx, IndexVec};
// use rustc_data_structures::fx::FxHashMap as HashMap;
use rustc_data_structures::fx::FxHashMap as HashMap;
use rustc_middle::ty;

crate::define_idx! {
Expand All @@ -22,15 +21,17 @@ pub struct Interner<K: PartialEq + Eq + Hash, I: Idx, D> {
keys: HashMap<K, I>,
}

const DEFAULT_CAPACITY: usize = 1_000;

impl<K, I, D> Default for Interner<K, I, D>
where
K: PartialEq + Eq + Hash,
I: Idx,
{
fn default() -> Self {
Self {
values: IndexVec::with_capacity(1_000_000),
keys: HashMap::with_capacity(1_000_000),
values: IndexVec::with_capacity(DEFAULT_CAPACITY),
keys: HashMap::with_capacity(DEFAULT_CAPACITY),
}
}
}
Expand Down Expand Up @@ -62,3 +63,13 @@ where
self.values
}
}

trait FxHashExt {
fn with_capacity(capacity: usize) -> Self;
}

impl<K, V> FxHashExt for HashMap<K, V> {
fn with_capacity(capacity: usize) -> Self {
HashMap::with_capacity_and_hasher(capacity, Default::default())
}
}
6 changes: 3 additions & 3 deletions crates/argus/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "argus-lib"
version = "0.1.17"
version = "0.1.18"
edition = "2021"
authors = ["Gavin Gray <gavinleroy6@gmail.com>"]
repository = "https://github.com/cognitive-engineering-lab/argus"
Expand All @@ -22,8 +22,8 @@ serde.workspace = true
serde_json.workspace = true
itertools.workspace = true

argus-ext = { version = "0.1.17", path = "../argus-ext" }
argus-ser = { version = "0.1.17", path = "../argus-ser" }
argus-ext = { version = "0.1.18", path = "../argus-ext" }
argus-ser = { version = "0.1.18", path = "../argus-ser" }
index_vec = { version = "0.1.3", features = ["serde"] }
smallvec = "1.14.0"
indexmap = { version = "2.2", features = ["serde"] }
Expand Down
85 changes: 85 additions & 0 deletions crates/argus/src/proof_tree/hash_map.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//! Wrapper around `FxHashMap` that implements `ts_rs::TS`
use std::{
fmt::Debug,
ops::{Deref, DerefMut},
};

use rustc_data_structures::fx::FxHashMap;
use serde::Serialize;
#[cfg(feature = "testing")]
use ts_rs::TS;

use super::topology::Idx;

#[cfg(not(feature = "testing"))]
pub trait AllTheThings: Debug + Serialize {}

#[cfg(not(feature = "testing"))]
impl<T> AllTheThings for T where T: Debug + Serialize {}

#[cfg(feature = "testing")]
pub trait AllTheThings: Debug + Serialize + TS {}

#[cfg(feature = "testing")]
impl<T> AllTheThings for T where T: Debug + Serialize + TS {}

#[derive(Clone, Debug, Serialize)]
pub struct HashMap<K: Idx, V: AllTheThings>(FxHashMap<K, V>);

impl<K: Idx, V: AllTheThings> Deref for HashMap<K, V> {
type Target = FxHashMap<K, V>;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl<K: Idx, V: AllTheThings> DerefMut for HashMap<K, V> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

impl<K: Idx, V: AllTheThings> Default for HashMap<K, V> {
fn default() -> Self {
HashMap(FxHashMap::default())
}
}

#[cfg(feature = "testing")]
impl<K: Idx, V: AllTheThings> TS for HashMap<K, V> {
fn name() -> String {
"Record".to_owned()
}

fn name_with_type_args(args: Vec<String>) -> String {
assert_eq!(
args.len(),
2,
"called HashMap::name_with_type_args with {} args",
args.len()
);
format!("Record<{}, {}>", args[0], args[1])
}

fn inline() -> String {
format!("Record<{}, {}>", K::inline(), V::inline())
}

fn dependencies() -> Vec<ts_rs::Dependency>
where
Self: 'static,
{
[
ts_rs::Dependency::from_ty::<K>(),
ts_rs::Dependency::from_ty::<V>(),
]
.into_iter()
.flatten()
.collect()
}

fn transparent() -> bool {
true
}
}
Loading