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
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2024-09-08"
channel = "nightly-2025-03-08"
components = [ "rustc-dev", "rust-src", "llvm-tools-preview", "rust-analyzer" ]
2 changes: 1 addition & 1 deletion src/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ impl<'tcx> Analyzer<'tcx> {
attr_path: &[Symbol],
) -> Option<DefId> {
let map = self.tcx.hir();
let body = map.maybe_body_owned_by(local_def_id)?;
let body = self.tcx.hir_maybe_body_owned_by(local_def_id)?;

let rustc_hir::ExprKind::Block(block, _) = body.value.kind else {
return None;
Expand Down
24 changes: 10 additions & 14 deletions src/analyze/annot.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Supporting implementation for parsing Thrust annotations.

use rustc_ast::ast::Attribute;
use rustc_ast::tokenstream::TokenStream;
use rustc_hir::Attribute;
use rustc_index::IndexVec;
use rustc_span::symbol::{Ident, Symbol};

Expand Down Expand Up @@ -198,31 +198,27 @@ impl ResultResolver {
}

pub fn extract_annot_tokens(attr: Attribute) -> TokenStream {
use rustc_ast::{AttrArgs, AttrKind, DelimArgs};

let AttrKind::Normal(attr) = &attr.kind else {
panic!("invalid attribute");
let Attribute::Unparsed(item) = attr else {
panic!("invalid attribute: expected unparsed");
};

let AttrArgs::Delimited(DelimArgs { tokens, .. }, ..) = &attr.item.args else {
panic!("invalid attribute");
let rustc_hir::AttrArgs::Delimited(d) = item.args else {
panic!("invalid attribute: expected delimited args");
};

tokens.clone()
d.tokens
}

pub fn split_param(ts: &TokenStream) -> (Ident, TokenStream) {
use rustc_ast::token::TokenKind;
use rustc_ast::tokenstream::TokenTree;

let mut cursor = ts.trees();
let (ident, _) = match cursor.next() {
let mut iter = ts.iter();
let (ident, _) = match iter.next() {
Some(TokenTree::Token(t, _)) => t.ident().expect("expected parameter name"),
_ => panic!("expected parameter name"),
};
match cursor.next() {
match iter.next() {
Some(TokenTree::Token(t, _)) if t.kind == TokenKind::Colon => {}
_ => panic!("expected :"),
}
(ident, cursor.cloned().collect())
(ident, iter.cloned().collect())
}
22 changes: 9 additions & 13 deletions src/analyze/annot_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct FormulaFn<'tcx> {
formula: chc::Formula<rty::FunctionParamIdx>,
}

impl<'a, 'b, D> Pretty<'a, D, termcolor::ColorSpec> for &'b FormulaFn<'_>
impl<'a, D> Pretty<'a, D, termcolor::ColorSpec> for &FormulaFn<'_>
where
D: pretty::DocAllocator<'a, termcolor::ColorSpec>,
D::Doc: Clone,
Expand Down Expand Up @@ -141,8 +141,7 @@ pub struct AnnotFnTranslator<'tcx> {

impl<'tcx> AnnotFnTranslator<'tcx> {
pub fn new(tcx: TyCtxt<'tcx>, local_def_id: LocalDefId) -> Self {
let map = tcx.hir();
let body = map.body_owned_by(local_def_id);
let body = tcx.hir_body_owned_by(local_def_id);
let generic_args = tcx.mk_args(&[]);
let typeck = tcx.typeck(local_def_id);
let def_ids = DefIdCache::new(tcx);
Expand Down Expand Up @@ -208,15 +207,15 @@ impl<'tcx> AnnotFnTranslator<'tcx> {
fn expr_ty(&self, expr: &'tcx rustc_hir::Expr<'tcx>) -> mir_ty::Ty<'tcx> {
let ty = self.typeck.expr_ty(expr);
let instantiated = mir_ty::EarlyBinder::bind(ty).instantiate(self.tcx, self.generic_args);
let param_env = mir_ty::ParamEnv::reveal_all();
self.tcx.normalize_erasing_regions(param_env, instantiated)
let typing_env = mir_ty::TypingEnv::fully_monomorphized();
self.tcx.normalize_erasing_regions(typing_env, instantiated)
}

fn pat_ty(&self, pat: &'tcx rustc_hir::Pat<'tcx>) -> mir_ty::Ty<'tcx> {
let ty = self.typeck.pat_ty(pat);
let instantiated = mir_ty::EarlyBinder::bind(ty).instantiate(self.tcx, self.generic_args);
let param_env = mir_ty::ParamEnv::reveal_all();
self.tcx.normalize_erasing_regions(param_env, instantiated)
let typing_env = mir_ty::TypingEnv::fully_monomorphized();
self.tcx.normalize_erasing_regions(typing_env, instantiated)
}

pub fn to_formula_fn(&self) -> FormulaFn<'tcx> {
Expand Down Expand Up @@ -427,7 +426,7 @@ impl<'tcx> AnnotFnTranslator<'tcx> {
let ExprKind::Closure(closure) = args[0].kind else {
panic!("exists argument must be a closure");
};
let closure_body = self.tcx.hir().body(closure.body);
let closure_body = self.tcx.hir_body(closure.body);

let mut inner_translator = self.clone();
let mut vars = Vec::new();
Expand Down Expand Up @@ -487,10 +486,7 @@ impl<'tcx> AnnotFnTranslator<'tcx> {
.next()
.is_some()
{
let param_env = self
.tcx
.param_env(self.local_def_id)
.with_reveal_all_normalized(self.tcx);
let typing_env = mir_ty::TypingEnv::fully_monomorphized();
let generic_args = self.typeck.node_args(func_expr.hir_id);
tracing::debug!(
lhs = ?def_id,
Expand All @@ -503,7 +499,7 @@ impl<'tcx> AnnotFnTranslator<'tcx> {
.instantiate(self.tcx, self.generic_args);
let instance = mir_ty::Instance::try_resolve(
self.tcx,
param_env,
typing_env,
def_id,
generic_args,
)
Expand Down
34 changes: 16 additions & 18 deletions src/analyze/basic_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,9 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
let bytes = alloc
.inner()
.inspect_with_uninit_and_ptr_outside_interpreter(range.clone());
let param_env = self.tcx.param_env(self.local_def_id);
let layout = self.tcx.layout_of(param_env.and(ty)).unwrap();
let lcx = mir_ty::layout::LayoutCx {
tcx: self.tcx,
param_env,
};
let typing_env = self.body.typing_env(self.tcx);
let layout = self.tcx.layout_of(typing_env.as_query_input(ty)).unwrap();
let lcx = mir_ty::layout::LayoutCx::new(self.tcx, typing_env);
match ty.kind() {
mir_ty::TyKind::Str => {
let content = std::str::from_utf8(bytes).unwrap();
Expand Down Expand Up @@ -271,9 +268,10 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
let global_alloc = self.tcx.global_alloc(prov.alloc_id());
match global_alloc {
mir::interpret::GlobalAlloc::Memory(alloc) => {
let typing_env = self.body.typing_env(self.tcx);
let layout = self
.tcx
.layout_of(mir_ty::ParamEnv::reveal_all().and(*elem))
.layout_of(typing_env.as_query_input(*elem))
.unwrap();
let size = layout.size;
let range =
Expand All @@ -297,10 +295,10 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
mir::Const::Unevaluated(unevaluated, ty) => {
// since all constants are immutable in current setup,
// it should be okay to evaluate them here on-the-fly
let param_env = self.tcx.param_env(self.local_def_id);
let typing_env = self.body.typing_env(self.tcx);
let val = self
.tcx
.const_eval_resolve(param_env, *unevaluated, rustc_span::DUMMY_SP)
.const_eval_resolve(typing_env, *unevaluated, rustc_span::DUMMY_SP)
.unwrap();
self.const_value_ty(&val, ty)
}
Expand Down Expand Up @@ -445,7 +443,10 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
}
}
Rvalue::Cast(
mir::CastKind::PointerCoercion(mir_ty::adjustment::PointerCoercion::ReifyFnPointer),
mir::CastKind::PointerCoercion(
mir_ty::adjustment::PointerCoercion::ReifyFnPointer,
_,
),
operand,
_ty,
) => {
Expand Down Expand Up @@ -614,12 +615,9 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
tracing::debug!(?closure_def_id, "closure instance");
(*closure_def_id, args)
} else {
let param_env = self
.tcx
.param_env(self.local_def_id)
.with_reveal_all_normalized(self.tcx);
let typing_env = self.body.typing_env(self.tcx);
let instance =
mir_ty::Instance::try_resolve(self.tcx, param_env, def_id, args).unwrap();
mir_ty::Instance::try_resolve(self.tcx, typing_env, def_id, args).unwrap();
if let Some(instance) = instance {
(instance.def_id(), instance.args)
} else {
Expand Down Expand Up @@ -852,7 +850,7 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
} = &term.kind
{
let destination = match destination {
p if p.projection.len() == 0 => p.local,
p if p.projection.is_empty() => p.local,
_ => unimplemented!(),
};
if self.is_defined(destination) {
Expand Down Expand Up @@ -955,7 +953,7 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
{
if let Some((p, Rvalue::Ref(_, mir::BorrowKind::Mut { .. }, _))) = stmt.kind.as_assign()
{
if p.projection.len() != 0 {
if !p.projection.is_empty() {
unimplemented!();
}
// TODO: is it appropriate to use builtin_deref here... maybe we should handle dereferencing logic in `refine`
Expand Down Expand Up @@ -1088,7 +1086,7 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {

let bb_ty = self.basic_block_ty(self.basic_block).clone();
let params = &bb_ty.as_ref().params;
assert!(params.len() >= 1);
assert!(!params.is_empty());
for (param_idx, param_rty) in params.iter_enumerated() {
let param_ty = &param_rty.ty;
if let Some(local) = bb_ty.local_of_param(param_idx) {
Expand Down
30 changes: 17 additions & 13 deletions src/analyze/basic_block/drop_point.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::collections::HashMap;

use rustc_index::bit_set::BitSet;
use rustc_index::bit_set::DenseBitSet;
use rustc_middle::mir::{self, BasicBlock, Body, Local};
use rustc_mir_dataflow::{impls::MaybeLiveLocals, ResultsCursor};

#[derive(Debug, Clone, Default)]
pub struct DropPoints {
// TODO: ad-hoc
pub before_statements: Vec<Local>,
after_statements: Vec<BitSet<Local>>,
after_terminator: HashMap<BasicBlock, BitSet<Local>>,
after_statements: Vec<DenseBitSet<Local>>,
after_terminator: HashMap<BasicBlock, DenseBitSet<Local>>,
}

impl DropPoints {
Expand Down Expand Up @@ -40,11 +40,11 @@ impl DropPoints {
self.after_statements[statement_index].insert(local)
}

pub fn after_statement(&self, statement_index: usize) -> BitSet<Local> {
pub fn after_statement(&self, statement_index: usize) -> DenseBitSet<Local> {
self.after_statements[statement_index].clone()
}

pub fn after_terminator(&self, target: &BasicBlock) -> BitSet<Local> {
pub fn after_terminator(&self, target: &BasicBlock) -> DenseBitSet<Local> {
let mut t = self.after_terminator[target].clone();
t.union(self.after_statements.last().unwrap());
t
Expand All @@ -54,12 +54,10 @@ impl DropPoints {
#[derive(Debug, Clone)]
pub struct DropPointsBuilder<'mir, 'tcx> {
body: &'mir Body<'tcx>,
bb_ins_cache: HashMap<BasicBlock, BitSet<Local>>,
bb_ins_cache: HashMap<BasicBlock, DenseBitSet<Local>>,
}

fn def_local<'a, 'tcx, T: mir::visit::MirVisitable<'tcx> + ?Sized>(
visitable: &'a T,
) -> Option<Local> {
fn def_local<'tcx>(data: &mir::BasicBlockData<'tcx>, statement_index: usize) -> Option<Local> {
struct Visitor {
local: Option<Local>,
}
Expand All @@ -77,7 +75,13 @@ fn def_local<'a, 'tcx, T: mir::visit::MirVisitable<'tcx> + ?Sized>(
}
}
let mut visitor = Visitor { local: None };
visitable.apply(mir::Location::START, &mut visitor);
let loc = mir::Location::START;
use mir::visit::Visitor as _;
if statement_index < data.statements.len() {
visitor.visit_statement(&data.statements[statement_index], loc);
} else if let Some(tmnt) = &data.terminator {
visitor.visit_terminator(tmnt, loc);
}
visitor.local
}

Expand All @@ -91,13 +95,13 @@ impl<'mir, 'tcx> DropPointsBuilder<'mir, 'tcx> {

let mut after_terminator = HashMap::new();
let mut after_statements = Vec::new();
after_statements.resize_with(data.statements.len() + 1, || BitSet::new_empty(0));
after_statements.resize_with(data.statements.len() + 1, || DenseBitSet::new_empty(0));

results.seek_to_block_end(bb);
let live_locals_after_terminator = results.get().clone();

use rustc_data_structures::graph::Successors as _;
let mut ins = BitSet::new_empty(self.body.local_decls.len());
let mut ins = DenseBitSet::new_empty(self.body.local_decls.len());
for succ_bb in self.body.basic_blocks.successors(bb) {
self.bb_ins_cache.entry(succ_bb).or_insert_with(|| {
results.seek_to_block_start(succ_bb);
Expand Down Expand Up @@ -127,7 +131,7 @@ impl<'mir, 'tcx> DropPointsBuilder<'mir, 'tcx> {
tracing::debug!(?live_locals, ?loc);
after_statements[statement_index] = {
let mut t = live_locals.clone();
if let Some(def) = def_local(data.visitable(statement_index)) {
if let Some(def) = def_local(data, statement_index) {
t.insert(def);
}
t.subtract(&last_live_locals);
Expand Down
2 changes: 1 addition & 1 deletion src/analyze/basic_block/visitor/rust_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl<'a, 'tcx, 'ctx> mir::visit::MutVisitor<'tcx> for RustCallVisitor<'a, 'tcx,
panic!("expected closure arg for fn trait");
};
let fn_sig = self.analyzer.ctx().fn_sig(*resolved_def_id);
if !matches!(fn_sig.abi, rustc_target::spec::abi::Abi::RustCall) {
if !matches!(fn_sig.abi, rustc_abi::ExternAbi::RustCall) {
self.super_terminator(terminator, location);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/analyze/crate_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
use rustc_ast::tokenstream::TokenTree;

let ts = analyze::annot::extract_annot_tokens(attrs.clone());
let tt = ts.trees().next().expect("string literal");
let tt = ts.iter().next().expect("string literal").clone();

let raw_command = match tt {
TokenTree::Token(
Expand Down Expand Up @@ -206,7 +206,7 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
mir_ty::GenericParamDefKind::Const { .. } => {
unimplemented!()
}
mir_ty::GenericParamDefKind::Lifetime { .. } => self.tcx.lifetimes.re_erased.into(),
mir_ty::GenericParamDefKind::Lifetime => self.tcx.lifetimes.re_erased.into(),
};
args.push(arg);
}
Expand Down
7 changes: 3 additions & 4 deletions src/analyze/did_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
use std::cell::OnceCell;
use std::rc::Rc;

use rustc_abi::FieldIdx;
use rustc_middle::ty::TyCtxt;
use rustc_span::def_id::DefId;
use rustc_span::symbol::Symbol;
use rustc_target::abi::FieldIdx;

#[derive(Debug, Clone, Default)]
struct DefIds {
Expand Down Expand Up @@ -80,14 +80,13 @@ impl<'tcx> DefIdCache<'tcx> {
}

fn annotated_def(&self, path: &[Symbol]) -> Option<DefId> {
let map = self.tcx.hir();
for item_id in map.items() {
for item_id in self.tcx.hir_free_items() {
let def_id = item_id.owner_id.to_def_id();
if self.tcx.get_attrs_by_path(def_id, path).next().is_some() {
return Some(def_id);
}

let item = map.item(item_id);
let item = self.tcx.hir_item(item_id);
if let rustc_hir::ItemKind::Trait(_, _, _, _, trait_item_refs) = item.kind {
for trait_item_ref in trait_item_refs {
let def_id = trait_item_ref.id.owner_id.to_def_id();
Expand Down
Loading