Skip to content

Commit

Permalink
Fix nightly
Browse files Browse the repository at this point in the history
  • Loading branch information
nbdd0121 committed Sep 22, 2023
1 parent 0854be3 commit 63a29d4
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 45 deletions.
3 changes: 1 addition & 2 deletions src/ctxt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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) =>
{
Expand Down
27 changes: 14 additions & 13 deletions src/monomorphize_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 } => {
Expand Down Expand Up @@ -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<Spanned<MonoItem<'tcx>>>,
) {
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);
Expand Down
21 changes: 10 additions & 11 deletions src/preempt_count/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(..)) => {
Expand Down
2 changes: 1 addition & 1 deletion src/preempt_count/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
) {
}
}
18 changes: 3 additions & 15 deletions src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<u8>; 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]);
}};
}

Expand Down

0 comments on commit 63a29d4

Please sign in to comment.