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
4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ name = "thrust-rustc"
path = "src/main.rs"
test = false

[lib]
# TODO: why is this necessary?
test = false

[[test]]
name = "ui"
harness = false
Expand Down
17 changes: 17 additions & 0 deletions src/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,27 @@ mod basic_block;
mod crate_;
mod did_cache;
mod local_def;
mod reconstruct_slice_indexing;

// TODO: organize structure and remove cross dependency between refine
pub use did_cache::DefIdCache;

fn fn_operand<'tcx>(
tcx: TyCtxt<'tcx>,
def_id: DefId,
args: mir_ty::GenericArgsRef<'tcx>,
span: rustc_span::Span,
) -> mir::Operand<'tcx> {
mir::Operand::Constant(Box::new(mir::ConstOperand {
span,
user_ty: None,
const_: mir::Const::Val(
mir::ConstValue::ZeroSized,
mir_ty::Ty::new_fn_def(tcx, def_id, args),
),
}))
}

pub fn mir_borrowck_skip_formula_fn(
tcx: rustc_middle::ty::TyCtxt<'_>,
local_def_id: rustc_span::def_id::LocalDefId,
Expand Down
45 changes: 45 additions & 0 deletions src/analyze/basic_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,51 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
// definition
assert!(lhs.projection.is_empty());

if let Rvalue::UnaryOp(mir::UnOp::PtrMetadata, operand) = rvalue {
// Calls to `[T]::len` have already been lowered to this assignment in optimized MIR:
//
// _len = PtrMetadata(copy _slice);
//
let operand_mir_ty = operand.ty(&self.local_decls, self.tcx);
let mir_ty::TyKind::Ref(_, slice_ty, mutability) = operand_mir_ty.kind() else {
unimplemented!("PtrMetadata for {operand_mir_ty:?}")
};
let mir_ty::TyKind::Slice(elem_ty) = slice_ty.kind() else {
unimplemented!("PtrMetadata for {operand_mir_ty:?}")
};
Comment thread
coord-e marked this conversation as resolved.
let slice_len = self
.tcx
.lang_items()
.slice_len_fn()
.expect("slice len lang item is unavailable");
let args = self.tcx.mk_args(&[(*elem_ty).into()]);
let func = analyze::fn_operand(self.tcx, slice_len, args, rustc_span::DUMMY_SP);
let operand = if mutability.is_mut() {
let place = operand
.place()
.expect("mutable slice metadata operand must be a place");
let region = mir_ty::Region::new_from_kind(self.tcx, mir_ty::RegionKind::ReErased);
let ty = mir_ty::Ty::new_ref(self.tcx, region, *slice_ty, mir_ty::Mutability::Not);
let local = self
.local_decls
.push(mir::LocalDecl::new(ty, rustc_span::DUMMY_SP).immutable());
let rty = self.immut_borrow_place(self.tcx.mk_place_deref(place));
self.bind_local(local, rty);
Operand::Copy(local.into())
} else {
operand.clone()
};
let decl = self.local_decls[lhs.local].clone();
let rty = self
.type_builder
.for_template(&mut self.ctx)
.with_scope(&self.env)
.build_refined(decl.ty);
self.type_call(func, [operand], &rty);
self.bind_local(lhs.local, rty);
return;
}

if let Rvalue::Ref(_, mir::BorrowKind::Mut { .. }, referent) = rvalue {
// mutable borrow
let rty = self.mutable_borrow(stmt_idx, *referent);
Expand Down
1 change: 1 addition & 0 deletions src/analyze/local_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,7 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
let _guard = span.enter();

self.unelaborate_derefs();
analyze::reconstruct_slice_indexing::reconstruct(self.tcx, &mut self.body);
self.reassign_local_mutabilities();
self.refine_basic_blocks();
self.analyze_basic_blocks(expected);
Expand Down
Loading