Skip to content

Commit

Permalink
Remove most nightly features, update implementors panel in IDE
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinleroy committed Dec 16, 2024
1 parent af96bb3 commit eb7ddce
Show file tree
Hide file tree
Showing 19 changed files with 373 additions and 349 deletions.
21 changes: 6 additions & 15 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@ default_to_workspace = false

[tasks.init-bindings-lib]
command = "cargo"
args = [
"test", "-p", "argus-lib", "--lib", "export_bindings", "--locked"
]
args = ["test", "-p", "argus-lib", "--lib", "export_bindings", "--locked"]

[tasks.init-bindings-ser]
command = "cargo"
args = ["test", "-p", "argus-ser", "--locked"]

[tasks.init-bindings]
dependencies = ["init-bindings-lib", "init-bindings-ser"]
command = "./scripts/ts-rs.scm"
dependences = ["tasks.init-bindings-lib", "tasks.init-bindings-ser"]

[tasks.evaluation-node]
command = "node"
Expand All @@ -30,9 +28,7 @@ args = ["ide/packages/evaluation/dist/evaluation.cjs", "-s", "./data", "${@}"]

[tasks.build-back]
command = "cargo"
args = [
"install", "--path", "crates/argus-cli", "--locked",
]
args = ["install", "--path", "crates/argus-cli", "--locked"]

# TODO: is there a way to set a command specific environment variable?
# The below will make the configuration global...
Expand All @@ -48,14 +44,9 @@ name = ["build-back", "build-ide"]
parallel = true

[tasks.watch-back]
command = "cargo"
args = [
"watch",
"-i",
"frontend",
"-x",
"'install", "--path", "crates/argus-cli", "${@}", "'",
]
script = """
cargo watch -i frontend -x 'install --path crates/argus-cli ${@}'
"""

[tasks.watch.run_task]
name = ["watch-back"]
Expand Down
2 changes: 1 addition & 1 deletion crates/argus-cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(rustc_private, trait_alias, associated_type_defaults, let_chains)]
#![feature(rustc_private)]
#![warn(clippy::pedantic)]
#![allow(clippy::module_name_repetitions, clippy::missing_errors_doc)]

Expand Down
1 change: 0 additions & 1 deletion crates/argus-ext/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![feature(
rustc_private,
if_let_guard,
let_chains,
box_patterns,
control_flow_enum
Expand Down
20 changes: 15 additions & 5 deletions crates/argus-ext/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ use smallvec::SmallVec;

use crate::EvaluationResult;

pub trait ImplCandidateExt<'tcx> {
fn is_inductive(&self, tcx: TyCtxt<'tcx>) -> bool;
}

pub trait EvaluationResultExt {
fn is_yes(&self) -> bool;

Expand Down Expand Up @@ -162,14 +166,15 @@ pub fn identify_error_sources<'tcx, T>(
/// The second goal cannot succeed because the first didn't. The solver will
/// try to solve projection goals even if the base trait goal wasn't
/// successful. This function removes the implied goals (no matter the nesting depth).
#[must_use]
pub fn retain_error_sources<'tcx, T>(
all_items: &mut Vec<T>,
all_items: &mut [T],
get_result: impl Fn(&T) -> EvaluationResult,
get_predicate: impl Fn(&T) -> Predicate<'tcx>,
get_tcx: impl Fn(&T) -> TyCtxt<'tcx>,
) {
) -> usize {
if all_items.is_empty() {
return;
return 0;
}

let idx = itertools::partition(&mut *all_items, |t| {
Expand All @@ -196,9 +201,14 @@ pub fn retain_error_sources<'tcx, T>(
drop(is_implied_by_failing_bound);
drop(trait_preds_enumerated);

for i in to_remove.iter().rev() {
all_items.remove(*i);
let mut swap_with = all_items.len();
while let Some(i) = to_remove.pop() {
swap_with -= 1;
assert!(swap_with < all_items.len());
all_items.swap(i, swap_with);
}

swap_with
}

pub fn retain_method_calls<'tcx, T>(
Expand Down
19 changes: 18 additions & 1 deletion crates/argus-ext/src/ty/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use rustc_utils::source_map::range::CharRange;

#[allow(clippy::wildcard_imports)]
use super::*;
use crate::{hash::StableHash, EvaluationResult};
use crate::{hash::StableHash, rustc::ImplCandidate, EvaluationResult};

impl EvaluationResultExt for EvaluationResult {
fn is_yes(&self) -> bool {
Expand Down Expand Up @@ -484,3 +484,20 @@ impl<'tcx, T: TypeVisitable<TyCtxt<'tcx>>> VarCounterExt<'tcx> for T {
folder.count
}
}

impl<'tcx> ImplCandidateExt<'tcx> for ImplCandidate<'tcx> {
fn is_inductive(&self, tcx: TyCtxt<'tcx>) -> bool {
// The `DefId` of the trait being implemented
let trait_id = self.trait_ref.def_id;
for (p, _) in tcx.predicates_of(self.impl_def_id).predicates {
// Check if the trait in bound `Ty: Trait` matches the trait being implemented
if let Some(ptrait_ref) = p.as_trait_clause()
&& ptrait_ref.def_id() == trait_id
{
return true;
}
}

false
}
}
93 changes: 56 additions & 37 deletions crates/argus-ser/src/argus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use rustc_macros::TypeVisitable;
use rustc_middle::ty::{self, Upcast};
use rustc_utils::source_map::range::CharRange;
use serde::Serialize;
use smallvec::SmallVec;
#[cfg(feature = "testing")]
use ts_rs::TS;

Expand Down Expand Up @@ -209,22 +210,30 @@ pub(crate) fn group_predicates_by_ty<'tcx>(
.entry(ty)
.or_default()
.push(poly_trait_pred.rebind(bound));
} else if let Some(poly_ty_outl) = p.as_type_outlives_clause() {
continue;
}

if let Some(poly_ty_outl) = p.as_type_outlives_clause() {
let ty = poly_ty_outl.map_bound(|t| t.0).skip_binder();
let r = poly_ty_outl.map_bound(|t| t.1).skip_binder();
let bound = ClauseBound::Region(r);
grouped
.entry(ty)
.or_default()
.push(poly_ty_outl.rebind(bound));
} else if let Some(poly_projection) = p.as_projection_clause()
&& let Some(output_defid) = fn_trait_output
&& poly_projection.projection_def_id() == output_defid
{
fn_output_projections.push(poly_projection);
} else {
other.push(p);
continue;
}

if let Some(poly_projection) = p.as_projection_clause() {
if let Some(output_defid) = fn_trait_output {
if poly_projection.projection_def_id() == output_defid {
fn_output_projections.push(poly_projection);
continue;
}
}
}

other.push(p);
}

let grouped = grouped
Expand All @@ -237,36 +246,46 @@ pub(crate) fn group_predicates_by_ty<'tcx>(
.into_iter()
.map(|bclause| {
let clause = bclause.skip_binder();
if let ClauseBound::Trait(p, tref) = clause
&& tcx.is_fn_trait(tref.def_id)
&& let poly_tr = bclause.rebind(tref)
&& let matching_projections = fn_output_projections
.extract_if(move |p| {
tcx.does_trait_ref_occur_in(
poly_tr,
p.map_bound(|p| {
ty::PredicateKind::Clause(ty::ClauseKind::Projection(p))
})
.upcast(tcx),
)
})
.unique()
.collect::<smallvec::SmallVec<[_; 2]>>()
&& !matching_projections.is_empty()
{
log::debug!(
"Matching projections for {bclause:?} {matching_projections:#?}"
);
let ret_ty = matching_projections[0]
.term()
.skip_binder()
.ty()
.expect("FnOnce::Output Ty");
debug_assert!(matching_projections.len() == 1);
ClauseBound::FnTrait(p, tref, ret_ty)
} else {
clause
if let ClauseBound::Trait(p, tref) = clause {
if tcx.is_fn_trait(tref.def_id) {
let poly_tr = bclause.rebind(tref);

let mut to_remove = SmallVec::<[_; 4]>::new();
let mut matching_projection = None;

for (i, p) in fn_output_projections.iter().enumerate() {
if tcx.does_trait_ref_occur_in(
poly_tr,
p.map_bound(|p| {
ty::PredicateKind::Clause(ty::ClauseKind::Projection(p))
})
.upcast(tcx),
) {
log::debug!("Removing matching projection {p:#?}");
to_remove.push(i);
}
}

while let Some(i) = to_remove.pop() {
matching_projection = Some(fn_output_projections.remove(i));
}

if let Some(proj) = matching_projection {
log::debug!(
"Matching projections for {bclause:?} {matching_projection:#?}"
);
let ret_ty = proj
.term()
.skip_binder()
.ty()
.expect("FnOnce::Output Ty");

return ClauseBound::FnTrait(p, tref, ret_ty);
}
}
}

clause
})
.collect();
ty::Binder::bind_with_vars(
Expand Down
25 changes: 13 additions & 12 deletions crates/argus-ser/src/const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,21 +181,22 @@ impl<'tcx> UnevaluatedConstDef<'tcx> {
},
DefKind::AnonConst => {
if def.is_local()
&& let span = infcx.tcx.def_span(def)
&& let Ok(snip) = infcx.tcx.sess.source_map().span_to_snippet(span)
{
Self::AnonSnippet { data: snip }
} else {
// Do not call `print_value_path` as if a parent of this anon const is an impl it will
// attempt to print out the impl trait ref i.e. `<T as Trait>::{constant#0}`. This would
// cause printing to enter an infinite recursion if the anon const is in the self type i.e.
// `impl<T: Default> Default for [T; 32 - 1 - 1 - 1] {`
// where we would try to print `<[T; /* print `constant#0` again */] as Default>::{constant#0}`
Self::AnonLocation {
krate: infcx.tcx.crate_name(def.krate),
path: path::BasicPathNoArgs::new(*def),
let span = infcx.tcx.def_span(def);
if let Ok(snip) = infcx.tcx.sess.source_map().span_to_snippet(span) {
return Self::AnonSnippet { data: snip };
}
}

// Do not call `print_value_path` as if a parent of this anon const is an impl it will
// attempt to print out the impl trait ref i.e. `<T as Trait>::{constant#0}`. This would
// cause printing to enter an infinite recursion if the anon const is in the self type i.e.
// `impl<T: Default> Default for [T; 32 - 1 - 1 - 1] {`
// where we would try to print `<[T; /* print `constant#0` again */] as Default>::{constant#0}`
Self::AnonLocation {
krate: infcx.tcx.crate_name(def.krate),
path: path::BasicPathNoArgs::new(*def),
}
}
defkind => panic!("unexpected defkind {defkind:?} {value:?}"),
}
Expand Down
9 changes: 1 addition & 8 deletions crates/argus-ser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,7 @@
//!
//! If you need to serialize an optional type then prefix it with `Option__`, and
//! lists of elements are serialized with a prefixed `Slice__`.
#![feature(
rustc_private,
let_chains,
if_let_guard,
decl_macro,
extract_if,
associated_type_defaults
)]
#![feature(rustc_private, decl_macro)]
#![allow(non_camel_case_types, non_snake_case)]
extern crate rustc_apfloat;
extern crate rustc_ast_ir;
Expand Down
Loading

0 comments on commit eb7ddce

Please sign in to comment.