Skip to content

Commit

Permalink
Update nightly toolchain
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinleroy committed Apr 8, 2024
1 parent 7d8c074 commit a510a61
Show file tree
Hide file tree
Showing 27 changed files with 264 additions and 821 deletions.
4 changes: 0 additions & 4 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ 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" }
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ If rustup fails, especially with an error like "could not rename the downloaded
To solve the issue, go to the command line and run:

```
rustup toolchain install nightly-2024-01-24 -c rust-src -c rustc-dev -c llvm-tools-preview
rustup toolchain install nightly-2024-04-08 -c rust-src -c rustc-dev -c llvm-tools-preview
```

Then go back to VSCode and click "Continue" to let Argus continue installing.
Expand Down
19 changes: 11 additions & 8 deletions crates/argus/src/analysis/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use crate::{

fluid_let! {
pub static INSPECTING: bool;
pub static BODY_ID: BodyId;
}

macro_rules! guard_inspection {
Expand All @@ -55,8 +56,7 @@ pub fn process_obligation<'tcx>(
) {
guard_inspection! {}

let Some(_ldef_id) = infcx.body_id() else {
log::warn!("Skipping obligation unassociated with local body {obl:?}");
let Some(body_id) = BODY_ID.copied() else {
return;
};

Expand Down Expand Up @@ -89,7 +89,8 @@ pub fn process_obligation<'tcx>(
None
};

let obligation = transform::compute_provenance(infcx, obl, result, dataid);
let obligation =
transform::compute_provenance(body_id, infcx, obl, result, dataid);

tls::store_obligation(obligation);

Expand Down Expand Up @@ -195,11 +196,13 @@ fn generate_tree<'tcx>(
predicate: obligation.predicate,
param_env: obligation.param_env,
};
let item_def_id = infcx
.body_id()
.ok_or(anyhow!("body not local"))?
.to_def_id();
serialize_proof_tree(goal, infcx, item_def_id)

let Some(body_id) = BODY_ID.copied() else {
bail!("missing body id");
};

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

pub(in crate::analysis) fn build_obligations_in_body<'tcx>(
Expand Down
3 changes: 1 addition & 2 deletions crates/argus/src/analysis/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,13 @@ macro_rules! simple_visitors {
impl HirVisitor<'_> for FindNodeBySpan {
simple_visitors! {
[visit_param, walk_param, hir::Param],
[visit_local, walk_local, hir::Local],
[visit_local, walk_local, hir::LetStmt],
[visit_block, walk_block, hir::Block],
[visit_stmt, walk_stmt, hir::Stmt],
[visit_arm, walk_arm, hir::Arm],
[visit_pat, walk_pat, hir::Pat],
[visit_pat_field, walk_pat_field, hir::PatField],
[visit_expr, walk_expr, hir::Expr],
[visit_let_expr, walk_let_expr, hir::Let],
[visit_expr_field, walk_expr_field, hir::ExprField],
[visit_ty, walk_ty, hir::Ty],
[visit_generic_param, walk_generic_param, hir::GenericParam],
Expand Down
7 changes: 6 additions & 1 deletion crates/argus/src/analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn obligations<'tcx>(
body_id: BodyId,
) -> Result<ObligationsInBody> {
rustc_middle::ty::print::with_no_trimmed_paths! {{
log::info!("Typeck'ing body {body_id:?}");
fluid_let::fluid_set!(entry::BODY_ID, body_id);

let typeck_results = tcx.inspect_typeck(body_id, entry::process_obligation);

Expand All @@ -50,6 +50,8 @@ pub fn tree<'tcx>(
body_id: BodyId,
) -> Result<SerializedTree> {
rustc_middle::ty::print::with_no_trimmed_paths! {{
fluid_let::fluid_set!(entry::BODY_ID, body_id);

let typeck_results =
tcx.inspect_typeck(body_id, entry::process_obligation_for_tree);

Expand All @@ -62,6 +64,8 @@ pub fn tree<'tcx>(
/// NOTE: this requires quite a bit of memory as everything is generated eagerly, favor
/// using a combination of `obligation` and `tree` analyses for a reduced memory footprint.
pub fn bundle<'tcx>(tcx: TyCtxt<'tcx>, body_id: BodyId) -> Result<BodyBundle> {
fluid_let::fluid_set!(entry::BODY_ID, body_id);

let (full_data, obligations_in_body) = body_data(tcx, body_id)?;
let t = (&*full_data, &obligations_in_body);
let thunk = || t;
Expand All @@ -82,6 +86,7 @@ pub fn bundle<'tcx>(tcx: TyCtxt<'tcx>, body_id: BodyId) -> Result<BodyBundle> {
.prefer_local()
.to_string_lossy()
.to_string();

Ok(BodyBundle {
filename,
body: obligations_in_body,
Expand Down
2 changes: 1 addition & 1 deletion crates/argus/src/analysis/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub fn replace_reported_errors(infcx: &InferCtxt) {
.reported_trait_errors
.borrow()
.iter()
.map(|(span, predicates)| {
.map(|(span, (predicates, _))| {
(
*span,
predicates
Expand Down
45 changes: 17 additions & 28 deletions crates/argus/src/analysis/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,17 @@ macro_rules! property_is_ok {
}

pub fn compute_provenance<'tcx>(
body_id: BodyId,
infcx: &InferCtxt<'tcx>,
obligation: &PredicateObligation<'tcx>,
result: EvaluationResult,
dataid: Option<UODIdx>,
) -> Provenance<Obligation> {
let Some(ldef_id) = infcx.body_id() else {
unreachable!("argus analysis should only happen on local bodies");
};

let hir = infcx.tcx.hir();
let fdata = infcx.bless_fulfilled(obligation, result, false);

// If the span is coming from a macro, point to the callsite.
let callsite_cause_span = fdata.obligation.cause.span.source_callsite();
let body_id = hir.body_owned_by(ldef_id);
let hir_id = hier_hir::find_most_enclosing_node(
&infcx.tcx,
body_id,
Expand Down Expand Up @@ -220,16 +216,15 @@ impl<'a, 'tcx: 'a> ObligationsBuilder<'a, 'tcx> {
BinKind::Call => Call,
BinKind::MethodReceiver => MethodReceiver,
BinKind::MethodCall => {
let Some(hir::Node::Expr(
let hir::Node::Expr(
call_expr @ hir::Expr {
kind: hir::ExprKind::MethodCall(segment, recvr, args, call_span),
..
},
)) = hir.find(hir_id)
) = hir.hir_node(hir_id)
else {
unreachable!(
"Bin kind `MethodCall` for non `ExprKind::MethodCall` {:?}",
hir.node_to_string(hir_id)
"bin kind is method call, but node is not method call"
);
};

Expand Down Expand Up @@ -517,19 +512,11 @@ impl<'a, 'tcx: 'a> ObligationsBuilder<'a, 'tcx> {

let ty_id = |ty: Ty<'tcx>| ty;

let ty_with_ref = move |ty: Ty<'tcx>| {
Ty::new_ref(tcx, region, ty::TypeAndMut {
ty,
mutbl: hir::Mutability::Not,
})
};
let ty_with_ref =
move |ty: Ty<'tcx>| Ty::new_ref(tcx, region, ty, hir::Mutability::Not);

let ty_with_mut_ref = move |ty: Ty<'tcx>| {
Ty::new_ref(tcx, region, ty::TypeAndMut {
ty,
mutbl: hir::Mutability::Mut,
})
};
let ty_with_mut_ref =
move |ty: Ty<'tcx>| Ty::new_ref(tcx, region, ty, hir::Mutability::Mut);

// TODO: rustc also considers raw pointers, ignoring for now ...
let ty_mutators: Vec<&dyn Fn(Ty<'tcx>) -> Ty<'tcx>> =
Expand Down Expand Up @@ -580,8 +567,13 @@ impl<'a, 'tcx: 'a> ObligationsBuilder<'a, 'tcx> {
infcx.probe(|_| {
let res = infcx.evaluate_obligation(&obligation);

let mut with_provenance =
compute_provenance(&infcx, &obligation, res, None);
let mut with_provenance = compute_provenance(
self.body_id,
&infcx,
&obligation,
res,
None,
);

let syn_id = self.synthetic_data.add(SyntheticData {
full_data: full_query_idx,
Expand Down Expand Up @@ -743,12 +735,9 @@ mod tree_search {
}

impl<'tcx> ProofTreeVisitor<'tcx> for BranchlessSearch {
type BreakTy = ();
type Result = ControlFlow<()>;

fn visit_goal(
&mut self,
goal: &InspectGoal<'_, 'tcx>,
) -> ControlFlow<Self::BreakTy> {
fn visit_goal(&mut self, goal: &InspectGoal<'_, 'tcx>) -> Self::Result {
let infcx = goal.infcx();
let predicate = &goal.goal().predicate;
let hash = infcx.predicate_hash(predicate).into();
Expand Down
28 changes: 8 additions & 20 deletions crates/argus/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ use rustc_data_structures::{
fx::FxIndexMap,
stable_hasher::{Hash64, HashStable, StableHasher},
};
use rustc_hir::{
def_id::{DefId, LocalDefId},
BodyId, HirId,
};
use rustc_hir::{def_id::DefId, BodyId, HirId};
use rustc_hir_typeck::inspect_typeck;
use rustc_infer::{
infer::InferCtxt,
Expand Down Expand Up @@ -201,8 +198,6 @@ pub trait InferCtxtExt<'tcx> {
obligation: &PredicateObligation<'tcx>,
) -> ObligationNecessity;

fn body_id(&self) -> Option<LocalDefId>;

fn predicate_hash(&self, p: &Predicate<'tcx>) -> Hash64;

fn evaluate_obligation(
Expand Down Expand Up @@ -270,7 +265,7 @@ pub fn group_predicates_by_ty<'tcx>(
let trait_ref =
poly_trait_pred.map_bound(|tr| tr.trait_ref).skip_binder();
let bound = ClauseBound::Trait(
poly_trait_pred.polarity(),
poly_trait_pred.polarity().into(),
TraitRefPrintOnlyTraitPathDef(trait_ref),
);
grouped.entry(ty).or_default().push(bound);
Expand Down Expand Up @@ -314,7 +309,7 @@ impl<'tcx> TyCtxtExt<'tcx> for TyCtxt<'tcx> {
let tcx = *self;
let impl_def_id = def_id;

// From [`rustc_trait_selection::traits::specialize`]
// 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)
Expand Down Expand Up @@ -347,7 +342,10 @@ impl<'tcx> TyCtxtExt<'tcx> for TyCtxt<'tcx> {
if let Some(poly_trait_ref) = p.as_trait_clause() {
if Some(poly_trait_ref.def_id()) == sized_trait {
types_without_default_bounds
.remove(&poly_trait_ref.self_ty().skip_binder());
// NOTE: we don't rely on the ordering of the types without bounds here,
// so `swap_remove` is preferred because it's O(1) instead of `shift_remove`
// which is O(n).
.swap_remove(&poly_trait_ref.self_ty().skip_binder());
continue;
}
}
Expand Down Expand Up @@ -484,16 +482,6 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
}
}

// TODO there has to be a better way to do this, right?
fn body_id(&self) -> Option<LocalDefId> {
use rustc_infer::traits::DefiningAnchor::*;
if let Bind(ldef_id) = self.defining_use_anchor {
Some(ldef_id)
} else {
None
}
}

fn predicate_hash(&self, p: &Predicate<'tcx>) -> Hash64 {
let mut freshener = rustc_infer::infer::TypeFreshener::new(self);
let p = p.fold_with(&mut freshener);
Expand Down Expand Up @@ -556,7 +544,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
.evaluate_root_goal(obligation.clone().into(), GenerateProofTree::Never)
.0
{
Ok((_, c, _)) => Ok(c),
Ok((_, c)) => Ok(c),
_ => Err(NoSolution),
}
}
Expand Down
6 changes: 4 additions & 2 deletions crates/argus/src/proof_tree/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl EvaluationResultExt for EvaluationResult {
fn pretty(&self) -> String {
let str = match self {
Ok(Certainty::Yes) => "Yes",
Ok(Certainty::Maybe(MaybeCause::Overflow)) => "No: Overflow",
Ok(Certainty::Maybe(MaybeCause::Overflow { .. })) => "No: Overflow",
Ok(Certainty::Maybe(MaybeCause::Ambiguity)) => "No: Ambiguity",
Err(NoSolution) => "No",
};
Expand All @@ -48,8 +48,10 @@ impl CandidateExt for InspectCandidate<'_, '_> {
ProbeKind::NormalizedSelfTyAssembly => {
"normalized-self-ty-asm".to_string()
}
ProbeKind::TryNormalizeNonRigid { .. } => {
"try-normalize-non-rigid".to_string()
}
ProbeKind::UnsizeAssembly => "unsize-asm".to_string(),
ProbeKind::CommitIfOk => "commit-if-ok".to_string(),
ProbeKind::UpcastProjectionCompatibility => {
"upcase-proj-compat".to_string()
}
Expand Down
4 changes: 3 additions & 1 deletion crates/argus/src/proof_tree/interners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ impl Interners {
ProbeKind::NormalizedSelfTyAssembly => {
self.intern_can_string("normalized-self-ty-asm")
}
ProbeKind::TryNormalizeNonRigid { .. } => {
self.intern_can_string("try-normalize-non-rigid")
}
ProbeKind::UnsizeAssembly => self.intern_can_string("unsize-asm"),
ProbeKind::CommitIfOk => self.intern_can_string("commit-if-ok"),
ProbeKind::UpcastProjectionCompatibility => {
self.intern_can_string("upcase-proj-compat")
}
Expand Down
11 changes: 3 additions & 8 deletions crates/argus/src/proof_tree/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,9 @@ impl SerializedTreeVisitor {
}

impl<'tcx> ProofTreeVisitor<'tcx> for SerializedTreeVisitor {
type BreakTy = !;
type Result = ();

fn visit_goal(
&mut self,
goal: &InspectGoal<'_, 'tcx>,
) -> ControlFlow<Self::BreakTy> {
fn visit_goal(&mut self, goal: &InspectGoal<'_, 'tcx>) -> Self::Result {
let here_node = self.interners.mk_goal_node(goal);
let here_idx = self.nodes.push(here_node.clone());

Expand Down Expand Up @@ -161,14 +158,12 @@ impl<'tcx> ProofTreeVisitor<'tcx> for SerializedTreeVisitor {
let candidate_idx = self.nodes.push(here_candidate);
self.topology.add(here_idx, candidate_idx);
self.previous = Some(candidate_idx);
c.visit_nested(self)?;
c.visit_nested(self);
add_result_if_empty(self, candidate_idx);
}

add_result_if_empty(self, here_idx);
self.previous = here_parent;

ControlFlow::Continue(())
}
}

Expand Down
Loading

0 comments on commit a510a61

Please sign in to comment.