Skip to content

Commit

Permalink
Update to nightly-2024-05-20
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinleroy committed May 21, 2024
1 parent d361544 commit b5f6658
Show file tree
Hide file tree
Showing 38 changed files with 1,832 additions and 1,599 deletions.
8 changes: 6 additions & 2 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_utils = { path = "../rustc-plugin/crates/rustc_utils" }
rustc_plugin = { path = "../rustc-plugin/crates/rustc_plugin" }
4 changes: 2 additions & 2 deletions crates/argus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ testing = ["lazy_static", "ts-rs"]
doctest = false

[dependencies]
rustc_utils = { version = "=0.9.0-nightly-2024-01-24", features = ["serde"] }
rustc_utils = { version = "=0.10.0-nightly-2024-05-20", features = ["serde"] }

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

[dev-dependencies]
argus-lib = { path = ".", features = ["testing"] }
rustc_utils = { version = "=0.9.0-nightly-2024-01-24", features = ["serde", "ts-rs"] }
rustc_utils = { version = "=0.10.0-nightly-2024-05-20", features = ["serde", "ts-rs"] }
test-log = "0.2.11"
env_logger = "0.9.3"
text-diff = "0.4"
Expand Down
15 changes: 4 additions & 11 deletions crates/argus/src/analysis/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ use anyhow::{anyhow, bail, Result};
use fluid_let::fluid_let;
use rustc_hir::BodyId;
use rustc_infer::{infer::InferCtxt, traits::PredicateObligation};
use rustc_middle::ty::{Predicate, TyCtxt, TypeckResults};
use rustc_middle::ty::{TyCtxt, TypeckResults};
use rustc_trait_selection::traits::solve::Goal;
use serde::Serialize;

use crate::{
analysis::{
Expand All @@ -17,7 +16,6 @@ use crate::{
},
ext::{EvaluationResultExt, InferCtxtExt},
proof_tree::{serialize::serialize_proof_tree, SerializedTree},
serialize::ty::PredicateDef,
types::{
intermediate::{
ErrorAssemblyCtx, Forgettable, FullData, ObligationQueriesInBody,
Expand All @@ -44,11 +42,6 @@ macro_rules! guard_inspection {
// --------------------------------
// Rustc inspection points

#[derive(Serialize)]
struct PredWrapper<'a, 'tcx: 'a>(
#[serde(with = "PredicateDef")] &'a Predicate<'tcx>,
);

pub fn process_obligation<'tcx>(
infcx: &InferCtxt<'tcx>,
obl: &PredicateObligation<'tcx>,
Expand All @@ -60,6 +53,8 @@ pub fn process_obligation<'tcx>(
return;
};

log::trace!("RECV OBLIGATION {result:?} {obl:?}");

// Use this to get rid of any resolved inference variables,
// these could have been resolved while trying to solve the obligation
// and we want to present it as such to the user.
Expand All @@ -78,8 +73,6 @@ pub fn process_obligation<'tcx>(
return;
}

log::debug!("Processing obligation {obl:?}");

let necessity = infcx.obligation_necessity(obl);
let dataid = if matches!(necessity, ObligationNecessity::Yes)
|| (matches!(necessity, ObligationNecessity::OnError) && result.is_no())
Expand Down Expand Up @@ -202,7 +195,7 @@ fn generate_tree<'tcx>(
};

let body_owner = infcx.tcx.hir().body_owner_def_id(body_id).to_def_id();
serialize_proof_tree(goal, infcx, body_owner)
serialize_proof_tree(goal, obligation.cause.span, infcx, body_owner)
}

pub(in crate::analysis) fn build_obligations_in_body<'tcx>(
Expand Down
34 changes: 12 additions & 22 deletions crates/argus/src/analysis/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ use rustc_data_structures::fx::{FxHashMap as HashMap, FxIndexMap};
use rustc_hir::{self as hir, intravisit::Map, BodyId, HirId};
use rustc_infer::{
infer::{canonical::OriginalQueryValues, InferCtxt, InferOk},
traits::{self, ObligationCauseCode, PredicateObligation},
};
use rustc_middle::ty::{
self, ParamEnvAnd, ToPredicate, Ty, TyCtxt, TypeckResults,
traits::{self, PredicateObligation},
};
use rustc_middle::ty::{self, ParamEnvAnd, Ty, TyCtxt, TypeckResults, Upcast};
use rustc_span::Span;
use rustc_utils::source_map::range::CharRange;

Expand All @@ -19,10 +17,7 @@ use super::{
EvaluationResult,
};
use crate::{
ext::{
EvaluationResultExt, InferCtxtExt, PredicateExt, TyCtxtExt,
TypeckResultsExt,
},
ext::{InferCtxtExt, PredicateExt, TyCtxtExt, TypeckResultsExt},
types::{intermediate::*, *},
};

Expand Down Expand Up @@ -441,16 +436,8 @@ impl<'a, 'tcx: 'a> ObligationsBuilder<'a, 'tcx> {
);
}

let is_necessary =
// Bounds for extension method calls are always trait predicates.
fdata.obligation.predicate.is_trait_predicate() &&
// FIXME: Obligations for method calls are registered under 'misc,'
// this of course could change. There should be a stronger way
// to gather the attempted traits.
matches!(
fdata.obligation.cause.code(),
ObligationCauseCode::MiscObligation
);
let is_necessary = fdata.obligation.predicate.is_trait_predicate();

is_necessary.then(|| {
(idx, expect_trait_ref(&fdata.obligation.predicate).def_id())
Expand Down Expand Up @@ -555,8 +542,7 @@ impl<'a, 'tcx: 'a> ObligationsBuilder<'a, 'tcx> {
for trait_ref in trait_candidates.iter() {
let trait_ref = trait_ref.with_self_ty(tcx, self_ty);

let predicate: ty::Predicate<'tcx> =
ty::Binder::dummy(trait_ref).to_predicate(self.tcx);
let predicate: ty::Predicate<'tcx> = trait_ref.upcast(self.tcx);
let obligation = traits::Obligation::new(
tcx,
o.cause.clone(),
Expand Down Expand Up @@ -662,7 +648,7 @@ impl<'a, 'tcx: 'a> ObligationsBuilder<'a, 'tcx> {
anyhow::ensure!(exists, "synthetic data not found for {:?}", obl)
} else if matches!(obl.necessity, ObligationNecessity::Yes)
|| (matches!(obl.necessity, ObligationNecessity::OnError)
&& obl.result.is_no())
&& obl.result.is_err())
{
let exists = self.full_data.iter().any(|fdata| fdata.hash == obl.hash);

Expand Down Expand Up @@ -737,6 +723,10 @@ mod tree_search {
impl<'tcx> ProofTreeVisitor<'tcx> for BranchlessSearch {
type Result = ControlFlow<()>;

fn span(&self) -> Span {
rustc_span::DUMMY_SP
}

fn visit_goal(&mut self, goal: &InspectGoal<'_, 'tcx>) -> Self::Result {
let infcx = goal.infcx();
let predicate = &goal.goal().predicate;
Expand All @@ -748,9 +738,9 @@ mod tree_search {

let candidates = goal.candidates();
if 1 == candidates.len() {
ControlFlow::Break(())
candidates[0].visit_nested_in_probe(self)
} else {
candidates[0].visit_nested(self)
ControlFlow::Break(())
}
}
}
Expand Down
79 changes: 5 additions & 74 deletions crates/argus/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use rustc_infer::{
traits::{ObligationInspector, PredicateObligation},
};
use rustc_middle::ty::{
self, Predicate, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable,
TypeckResults,
self, Predicate, Ty, TyCtxt, TypeFoldable, TypeckResults,
};
use rustc_query_system::ich::StableHashingContext;
use rustc_span::FileName;
Expand All @@ -20,7 +19,6 @@ use serde::Serialize;

use crate::{
analysis::{EvaluationResult, FulfillmentData},
rustc,
serialize::{
safe::TraitRefPrintOnlyTraitPathDef, serialize_to_value,
ty::PredicateObligationDef,
Expand Down Expand Up @@ -309,13 +307,6 @@ impl<'tcx> TyCtxtExt<'tcx> for TyCtxt<'tcx> {
let tcx = *self;
let impl_def_id = def_id;

// From [`rustc_trait_selection::traits::specialize::to_pretty_impl_header`]
log::debug!(
"Serializing this impl header\n{}",
rustc::to_pretty_impl_header(tcx, impl_def_id)
.unwrap_or(String::from("{failed to get header}"))
);

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 Expand Up @@ -446,16 +437,14 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
&self,
obligation: &PredicateObligation<'tcx>,
) -> ObligationNecessity {
use rustc_infer::traits::ObligationCauseCode::*;
use ObligationNecessity::*;
use rustc_infer::traits::ObligationCauseCode;
use ObligationNecessity as ON;

let p = &obligation.predicate;
let code = obligation.cause.code();

if matches!(code, SizedReturnType) && p.is_lhs_unit() {
No
} else if matches!(code, MiscObligation) {
No
if matches!(code, ObligationCauseCode::SizedReturnType) && p.is_lhs_unit() {
ON::No
} else {
self.guess_predicate_necessity(p)
}
Expand Down Expand Up @@ -549,61 +538,3 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
}
}
}

mod ty_eraser {
use super::*;

pub(super) struct TyVarEraserVisitor<'a, 'tcx: 'a> {
pub infcx: &'a InferCtxt<'tcx>,
}

// FIXME: these placeholders are a huge hack, there's definitely
// something better we could do here.
macro_rules! gen_placeholders {
($( [$f:ident $n:literal],)*) => {$(
fn $f(&self) -> Ty<'tcx> {
Ty::new_placeholder(self.infcx.tcx, ty::PlaceholderType {
universe: self.infcx.universe(),
bound: ty::BoundTy {
var: ty::BoundVar::from_u32(ty::BoundVar::MAX_AS_U32 - $n),
kind: ty::BoundTyKind::Anon,
},
})
})*
}
}

impl<'a, 'tcx: 'a> TyVarEraserVisitor<'a, 'tcx> {
gen_placeholders! {
[ty_placeholder 0],
[int_placeholder 1],
[float_placeholder 2],
}
}

impl<'tcx> TypeFolder<TyCtxt<'tcx>> for TyVarEraserVisitor<'_, 'tcx> {
fn interner(&self) -> TyCtxt<'tcx> {
self.infcx.tcx
}

fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
// HACK: I'm not sure if replacing type variables with
// an anonymous placeholder is the best idea. It is *an*
// idea, certainly. But this should only happen before hashing.
match ty.kind() {
ty::Infer(ty::TyVar(_)) => self.ty_placeholder(),
ty::Infer(ty::IntVar(_)) => self.int_placeholder(),
ty::Infer(ty::FloatVar(_)) => self.float_placeholder(),
_ => ty.super_fold_with(self),
}
}

fn fold_binder<T>(&mut self, t: ty::Binder<'tcx, T>) -> ty::Binder<'tcx, T>
where
T: TypeFoldable<TyCtxt<'tcx>>,
{
let u = self.infcx.tcx.anonymize_bound_vars(t);
u.super_fold_with(self)
}
}
}
1 change: 1 addition & 0 deletions crates/argus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ extern crate rustc_infer;
extern crate rustc_interface;
extern crate rustc_macros;
extern crate rustc_middle;
extern crate rustc_next_trait_solver;
extern crate rustc_query_system;
extern crate rustc_serialize;
extern crate rustc_session;
Expand Down
76 changes: 0 additions & 76 deletions crates/argus/src/proof_tree/ext.rs

This file was deleted.

Loading

0 comments on commit b5f6658

Please sign in to comment.