diff --git a/src/ctxt.rs b/src/ctxt.rs index 66b2186..aecb9a7 100644 --- a/src/ctxt.rs +++ b/src/ctxt.rs @@ -256,8 +256,7 @@ impl<'tcx> AnalysisCtxt<'tcx> { pub fn new(tcx: TyCtxt<'tcx>) -> Self { let output_filenames = tcx.output_filenames(()); - let rmeta_path = - rustc_session::output::filename_for_metadata(tcx.sess, output_filenames); + let rmeta_path = rustc_session::output::filename_for_metadata(tcx.sess, output_filenames); let rmeta_path = rmeta_path.as_path(); // Double check that the rmeta file is .rlib or .rmeta diff --git a/src/mir.rs b/src/mir.rs index dc0421d..3a89bc4 100644 --- a/src/mir.rs +++ b/src/mir.rs @@ -8,7 +8,7 @@ use rustc_data_structures::fx::FxHashMap; use rustc_hir::{self as hir, def::DefKind}; use rustc_middle::mir::CallSource; use rustc_middle::mir::{ - Body, Constant, LocalDecl, Operand, Place, ProjectionElem, Rvalue, SourceInfo, Statement, + Body, ConstOperand, LocalDecl, Operand, Place, ProjectionElem, Rvalue, SourceInfo, Statement, StatementKind, TerminatorKind, }; use rustc_middle::ty::{self, TyCtxt}; @@ -63,14 +63,14 @@ fn remap_mir_for_const_eval_select<'tcx>( let terminator = bb.terminator.as_mut().expect("invalid terminator"); match terminator.kind { TerminatorKind::Call { - func: Operand::Constant(box Constant { ref literal, .. }), + func: Operand::Constant(box ConstOperand { ref const_, .. }), ref mut args, destination, target, unwind, fn_span, .. - } if let ty::FnDef(def_id, _) = *literal.ty().kind() + } if let ty::FnDef(def_id, _) = *const_.ty().kind() && tcx.item_name(def_id) == sym::const_eval_select && tcx.is_intrinsic(def_id) => { diff --git a/src/monomorphize_collector.rs b/src/monomorphize_collector.rs index 94537f0..05e0f6f 100644 --- a/src/monomorphize_collector.rs +++ b/src/monomorphize_collector.rs @@ -10,7 +10,7 @@ use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId}; use rustc_hir::lang_items::LangItem; -use rustc_middle::mir::interpret::{AllocId, ConstValue}; +use rustc_middle::mir::interpret::AllocId; use rustc_middle::mir::interpret::{ErrorHandled, GlobalAlloc, Scalar}; use rustc_middle::mir::mono::MonoItem; use rustc_middle::mir::visit::Visitor as MirVisitor; @@ -582,20 +582,20 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> { /// This does not walk the constant, as it has been handled entirely here and trying /// to walk it would attempt to evaluate the `ty::Const` inside, which doesn't necessarily /// work, as some constants cannot be represented in the type system. - fn visit_constant(&mut self, constant: &mir::Constant<'tcx>, location: Location) { - let literal = self.monomorphize(constant.literal); + fn visit_constant(&mut self, constant: &mir::ConstOperand<'tcx>, location: Location) { + let const_ = self.monomorphize(constant.const_); let param_env = ty::ParamEnv::reveal_all(); - let val = match literal.eval(self.tcx, param_env, None) { + let val = match const_.eval(self.tcx, param_env, None) { Ok(v) => v, Err(ErrorHandled::Reported(..)) => return, Err(ErrorHandled::TooGeneric(..)) => span_bug!( self.body.source_info(location).span, "collection encountered polymorphic constant: {:?}", - literal + const_ ), }; collect_const_value(self.tcx, val, self.output); - MirVisitor::visit_ty(self, literal.ty(), TyContext::Location(location)); + MirVisitor::visit_ty(self, const_.ty(), TyContext::Location(location)); } fn visit_terminator(&mut self, terminator: &mir::Terminator<'tcx>, location: Location) { @@ -623,7 +623,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> { for op in operands { match *op { mir::InlineAsmOperand::SymFn { ref value } => { - let fn_ty = self.monomorphize(value.literal.ty()); + let fn_ty = self.monomorphize(value.const_.ty()); visit_fn_use(self.tcx, fn_ty, false, source, &mut self.output); } mir::InlineAsmOperand::SymStatic { def_id } => { @@ -1186,16 +1186,17 @@ fn collect_used_items<'tcx>( fn collect_const_value<'tcx>( tcx: TyCtxt<'tcx>, - value: ConstValue<'tcx>, + value: mir::ConstValue<'tcx>, output: &mut Vec>>, ) { match value { - ConstValue::Scalar(Scalar::Ptr(ptr, _size)) => collect_alloc(tcx, ptr.provenance, output), - ConstValue::Indirect { alloc_id, .. } => collect_alloc(tcx, alloc_id, output), - ConstValue::Slice { + mir::ConstValue::Scalar(Scalar::Ptr(ptr, _size)) => { + collect_alloc(tcx, ptr.provenance, output) + } + mir::ConstValue::Indirect { alloc_id, .. } => collect_alloc(tcx, alloc_id, output), + mir::ConstValue::Slice { data: alloc, - start: _, - end: _, + meta: _, } => { for id in alloc.inner().provenance().provenances() { collect_alloc(tcx, id, output); diff --git a/src/preempt_count/check.rs b/src/preempt_count/check.rs index 6ab5f25..cc712ca 100644 --- a/src/preempt_count/check.rs +++ b/src/preempt_count/check.rs @@ -3,7 +3,7 @@ use crate::ctxt::AnalysisCtxt; use rustc_hir::def_id::DefId; use rustc_hir::LangItem; use rustc_infer::traits::util::PredicateSet; -use rustc_middle::mir::interpret::{AllocId, ConstValue, ErrorHandled, GlobalAlloc, Scalar}; +use rustc_middle::mir::interpret::{AllocId, ErrorHandled, GlobalAlloc, Scalar}; use rustc_middle::mir::{self, visit::Visitor as MirVisitor, Body, Location}; use rustc_middle::ty::adjustment::PointerCoercion; use rustc_middle::ty::{ @@ -217,16 +217,15 @@ impl<'mir, 'tcx, 'cx> MirNeighborVisitor<'mir, 'tcx, 'cx> { Ok(()) } - fn check_const(&mut self, value: ConstValue, span: Span) -> Result<(), Error> { + fn check_const(&mut self, value: mir::ConstValue, span: Span) -> Result<(), Error> { match value { - ConstValue::Scalar(Scalar::Ptr(ptr, _size)) => { + mir::ConstValue::Scalar(Scalar::Ptr(ptr, _size)) => { self.check_alloc(ptr.provenance, span)?; } - ConstValue::Indirect { alloc_id, .. } => self.check_alloc(alloc_id, span)?, - ConstValue::Slice { + mir::ConstValue::Indirect { alloc_id, .. } => self.check_alloc(alloc_id, span)?, + mir::ConstValue::Slice { data: alloc, - start: _, - end: _, + meta: _, } => { for id in alloc.inner().provenance().provenances() { self.check_alloc(id, span)?; @@ -281,7 +280,7 @@ impl<'mir, 'tcx, 'cx> MirNeighborVisitor<'mir, 'tcx, 'cx> { for op in operands { match *op { mir::InlineAsmOperand::SymFn { ref value } => { - let fn_ty = self.monomorphize(value.literal.ty()); + let fn_ty = self.monomorphize(value.const_.ty()); if let ty::FnDef(def_id, args) = *fn_ty.kind() { let instance = ty::Instance::resolve( self.cx.tcx, @@ -350,14 +349,14 @@ impl<'mir, 'tcx, 'cx> MirVisitor<'tcx> for MirNeighborVisitor<'mir, 'tcx, 'cx> { self.super_rvalue(rvalue, location); } - fn visit_constant(&mut self, constant: &mir::Constant<'tcx>, location: Location) { + fn visit_constant(&mut self, constant: &mir::ConstOperand<'tcx>, location: Location) { if self.result.is_err() { return; } - let literal = self.monomorphize(constant.literal); + let const_ = self.monomorphize(constant.const_); let param_env = ty::ParamEnv::reveal_all(); - let val = match literal.eval(self.cx.tcx, param_env, None) { + let val = match const_.eval(self.cx.tcx, param_env, None) { Ok(v) => v, Err(ErrorHandled::Reported(..)) => return, Err(ErrorHandled::TooGeneric(..)) => { diff --git a/src/preempt_count/dataflow.rs b/src/preempt_count/dataflow.rs index ff0e09c..8d8706e 100644 --- a/src/preempt_count/dataflow.rs +++ b/src/preempt_count/dataflow.rs @@ -311,7 +311,7 @@ impl<'tcx> Analysis<'tcx> for AdjustmentComputation<'_, 'tcx, '_> { &mut self, _state: &mut Self::Domain, _block: BasicBlock, - _return_places: rustc_middle::mir::terminator::CallReturnPlaces<'_, 'tcx>, + _return_places: rustc_middle::mir::CallReturnPlaces<'_, 'tcx>, ) { } } diff --git a/src/serde.rs b/src/serde.rs index 9c16604..5646f0e 100644 --- a/src/serde.rs +++ b/src/serde.rs @@ -8,7 +8,6 @@ use rustc_session::StableCrateId; use rustc_span::def_id::{CrateNum, DefIndex}; use rustc_span::source_map::StableSourceFileId; use rustc_span::{BytePos, SourceFile, Span, SyntaxContext, DUMMY_SP}; -use std::mem::MaybeUninit; // This is the last available version of `MemEncoder` in rustc_serialize::opaque before its removal. pub struct MemEncoder { @@ -33,20 +32,9 @@ impl MemEncoder { macro_rules! write_leb128 { ($enc:expr, $value:expr, $int_ty:ty, $fun:ident) => {{ const MAX_ENCODED_LEN: usize = rustc_serialize::leb128::max_leb128_len::<$int_ty>(); - let old_len = $enc.data.len(); - - if MAX_ENCODED_LEN > $enc.data.capacity() - old_len { - $enc.data.reserve(MAX_ENCODED_LEN); - } - - // SAFETY: The above check and `reserve` ensures that there is enough - // room to write the encoded value to the vector's internal buffer. - unsafe { - let buf = &mut *($enc.data.as_mut_ptr().add(old_len) - as *mut [MaybeUninit; MAX_ENCODED_LEN]); - let encoded = rustc_serialize::leb128::$fun(buf, $value); - $enc.data.set_len(old_len + encoded.len()); - } + let mut buf = [0; MAX_ENCODED_LEN]; + let encoded = rustc_serialize::leb128::$fun(&mut buf, $value); + $enc.data.extend_from_slice(&buf[..encoded]); }}; }