Skip to content

Commit

Permalink
Update rustc-plugin, fix floating-ui positions, intern goals when pos…
Browse files Browse the repository at this point in the history
…sible, invert trees and re-root for bottom-up view.
  • Loading branch information
gavinleroy committed Feb 23, 2024
1 parent 0f52e8e commit b4edd5c
Show file tree
Hide file tree
Showing 22 changed files with 349 additions and 532 deletions.
10 changes: 6 additions & 4 deletions Cargo.lock

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

4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,3 @@ resolver = "2"

[profile.dev.package.similar]
opt-level = 3

[patch.crates-io]
rustc_plugin = { git = "https://github.com/gavinleroy/rustc-plugin.git", branch = "dev" }
rustc_utils = { git = "https://github.com/gavinleroy/rustc-plugin.git", branch = "dev" }
4 changes: 2 additions & 2 deletions crates/argus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ testing = ["lazy_static", "ts-rs"]
doctest = false

[dependencies]
rustc_utils = { version = "=0.8.0-nightly-2024-01-06", features = ["serde"] }
rustc_utils = { version = "=0.9.0-nightly-2024-01-24", features = ["serde"] }

log = "0.4"
index_vec = { version = "0.1.3", features = ["serde"] }
Expand All @@ -29,7 +29,7 @@ ts-rs = { version = "7.1.1", features = ["indexmap-impl"], optional = true }

[dev-dependencies]
argus = { path = ".", features = ["testing"] }
rustc_utils = { version = "=0.8.0-nightly-2024-01-06", features = ["serde", "ts-rs"] }
rustc_utils = { version = "=0.9.0-nightly-2024-01-24", features = ["serde", "ts-rs"] }
test-log = "0.2.11"
env_logger = "0.9.3"

Expand Down
6 changes: 3 additions & 3 deletions crates/argus/src/analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use rustc_hir::BodyId;
use rustc_middle::ty::TyCtxt;
pub(crate) use tls::{FullObligationData, SynIdx, UODIdx};

#[cfg(feature = "testing")]
use crate::types::intermediate::FullData;
pub(crate) use crate::types::intermediate::{
EvaluationResult, Forgettable, FulfillmentData,
EvaluationResult, FulfillmentData,
};
#[cfg(feature = "testing")]
use crate::types::intermediate::{Forgettable, FullData};
use crate::{
ext::TyCtxtExt,
proof_tree::SerializedTree,
Expand Down
22 changes: 22 additions & 0 deletions crates/argus/src/emitter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use std::io;

use rustc_driver::DEFAULT_LOCALE_RESOURCES;
use rustc_errors::{
self,
emitter::{DynEmitter, HumanEmitter},
fallback_fluent_bundle,
};

pub struct SilentEmitter;

impl SilentEmitter {
pub fn boxed() -> Box<DynEmitter> {
// Create a new emitter writer which consumes *silently* all
// errors. There most certainly is a *better* way to do this,
// if you, the reader, know what that is, please open an issue :)
let fallback_bundle =
fallback_fluent_bundle(DEFAULT_LOCALE_RESOURCES.to_vec(), false);
let emitter = HumanEmitter::new(Box::new(io::sink()), fallback_bundle);
Box::new(emitter)
}
}
3 changes: 1 addition & 2 deletions crates/argus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
extern crate rustc_apfloat;
extern crate rustc_ast;
extern crate rustc_data_structures;
#[cfg(feature = "testing")]
extern crate rustc_driver;
#[cfg(feature = "testing")]
extern crate rustc_errors;
extern crate rustc_hash;
extern crate rustc_hir;
Expand All @@ -37,6 +35,7 @@ extern crate rustc_trait_selection;
extern crate rustc_type_ir;

pub mod analysis;
pub mod emitter;
mod ext;
mod proof_tree;
mod rustc;
Expand Down
102 changes: 38 additions & 64 deletions crates/argus/src/proof_tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::collections::HashSet;
use index_vec::IndexVec;
use rustc_infer::infer::InferCtxt;
use rustc_middle::ty;
use rustc_trait_selection::traits::solve;
use serde::Serialize;
pub use topology::*;
#[cfg(feature = "testing")]
Expand All @@ -26,7 +25,8 @@ use crate::{

crate::define_idx! {
usize,
ProofNodeIdx
ProofNodeIdx,
GoalIdx
}

// FIXME: Nodes shouldn't be PartialEq, or Eq. They are currently
Expand All @@ -38,30 +38,44 @@ crate::define_idx! {
#[cfg_attr(feature = "testing", derive(TS))]
#[cfg_attr(feature = "testing", ts(export))]
pub enum Node {
Result {
Result(
#[serde(with = "EvaluationResultDef")]
#[cfg_attr(feature = "testing", ts(type = "EvaluationResult"))]
data: EvaluationResult,
},
Candidate {
data: Candidate,
},
Goal {
data: Goal,
},
EvaluationResult,
),
Candidate(Candidate),
Goal(
GoalIdx,
#[serde(with = "EvaluationResultDef")]
#[cfg_attr(feature = "testing", ts(type = "EvaluationResult"))]
EvaluationResult,
),
}

#[derive(Serialize, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "testing", derive(TS))]
#[cfg_attr(feature = "testing", ts(export))]
pub struct Goal {}

#[derive(Serialize, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "testing", derive(TS))]
#[cfg_attr(feature = "testing", ts(export))]
pub enum Candidate {
Impl(
#[cfg_attr(feature = "testing", ts(type = "ImplHeader"))] serde_json::Value,
),
ParamEnv(usize),
// TODO remove variant once everything is structured
Any(String),
}

#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "testing", derive(TS))]
#[cfg_attr(feature = "testing", ts(export))]
pub struct Goal {
pub struct GoalData {
#[cfg_attr(feature = "testing", ts(type = "GoalPredicate"))]
goal: serde_json::Value,

#[serde(with = "EvaluationResultDef")]
#[cfg_attr(feature = "testing", ts(type = "EvaluationResult"))]
result: EvaluationResult,
value: serde_json::Value,

necessity: ObligationNecessity,
num_vars: usize,
Expand All @@ -72,31 +86,18 @@ pub struct Goal {
debug_comparison: String,
}

#[derive(Serialize, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "testing", derive(TS))]
#[cfg_attr(feature = "testing", ts(export))]
pub enum Candidate {
Impl {
#[cfg_attr(feature = "testing", ts(type = "ImplHeader"))]
data: serde_json::Value,
},
ParamEnv {
idx: usize,
},
// TODO remove variant once everything is structured
Any {
data: String,
},
}

#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "testing", derive(TS))]
#[cfg_attr(feature = "testing", ts(export))]
pub struct SerializedTree {
pub root: ProofNodeIdx,

#[cfg_attr(feature = "testing", ts(type = "Node[]"))]
pub nodes: IndexVec<ProofNodeIdx, Node>,
#[cfg_attr(feature = "testing", ts(type = "GoalData[]"))]
pub goals: IndexVec<GoalIdx, GoalData>,

pub topology: TreeTopology,
pub error_leaves: Vec<ProofNodeIdx>,
pub unnecessary_roots: HashSet<ProofNodeIdx>,
Expand All @@ -112,33 +113,6 @@ pub struct ProofCycle(Vec<ProofNodeIdx>);
// ----------------------------------------
// impls

impl Goal {
fn new<'tcx>(
infcx: &InferCtxt<'tcx>,
goal: &solve::Goal<'tcx, ty::Predicate<'tcx>>,
result: EvaluationResult,
) -> Self {
let necessity = infcx.guess_predicate_necessity(&goal.predicate);
let goal = infcx.resolve_vars_if_possible(*goal);
let num_vars =
serialize::var_counter::count_vars(infcx.tcx, goal.predicate);

let goal_value = serialize_to_value(infcx, &GoalPredicateDef(goal))
.expect("failed to serialize goal");

Self {
goal: goal_value,
result,
necessity,
num_vars,
is_lhs_ty_var: goal.predicate.is_lhs_ty_var(),

#[cfg(debug_assertions)]
debug_comparison: format!("{:?}", goal.predicate.kind().skip_binder()),
}
}
}

impl Candidate {
fn new_impl_header<'tcx>(
infcx: &InferCtxt<'tcx>,
Expand All @@ -147,12 +121,12 @@ impl Candidate {
let impl_ =
serialize_to_value(infcx, impl_).expect("couldn't serialize impl header");

Self::Impl { data: impl_ }
Self::Impl(impl_)
}

// TODO: we should pass the ParamEnv here for certainty.
fn new_param_env(idx: usize) -> Self {
Self::ParamEnv { idx }
Self::ParamEnv(idx)
}
}

Expand All @@ -164,6 +138,6 @@ impl From<&'static str> for Candidate {

impl From<String> for Candidate {
fn from(value: String) -> Self {
Candidate::Any { data: value }
Candidate::Any(value)
}
}
Loading

0 comments on commit b4edd5c

Please sign in to comment.