Prelude cleanup

This commit is contained in:
bjorn3 2020-06-20 18:44:49 +02:00
parent 431cebdca1
commit eb8fd197ab
9 changed files with 27 additions and 46 deletions

View File

@ -169,7 +169,7 @@ pub(crate) fn get_function_name_and_sig<'tcx>(
let fn_sig =
tcx.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &fn_sig_for_fn_abi(tcx, inst));
if fn_sig.c_variadic && !support_vararg {
unimpl_fatal!(tcx, tcx.def_span(inst.def_id()), "Variadic function definitions are not yet supported");
tcx.sess.span_fatal(tcx.def_span(inst.def_id()), "Variadic function definitions are not yet supported");
}
let sig = clif_sig_from_fn_sig(tcx, triple, fn_sig, false, inst.def.requires_caller_location(tcx));
(tcx.symbol_name(inst).name.as_str().to_string(), sig)
@ -601,7 +601,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
// FIXME find a cleaner way to support varargs
if fn_sig.c_variadic {
if fn_sig.abi != Abi::C {
unimpl_fatal!(fx.tcx, span, "Variadic call for non-C abi {:?}", fn_sig.abi);
fx.tcx.sess.span_fatal(span, &format!("Variadic call for non-C abi {:?}", fn_sig.abi));
}
let sig_ref = fx.bcx.func.dfg.call_signature(call_inst).unwrap();
let abi_params = call_args
@ -610,7 +610,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
let ty = fx.bcx.func.dfg.value_type(arg);
if !ty.is_int() {
// FIXME set %al to upperbound on float args once floats are supported
unimpl_fatal!(fx.tcx, span, "Non int ty {:?} for variadic call", ty);
fx.tcx.sess.span_fatal(span, &format!("Non int ty {:?} for variadic call", ty));
}
AbiParam::new(ty)
})

View File

@ -1,8 +1,7 @@
use std::fs::File;
use std::path::{Path, PathBuf};
use crate::prelude::*;
use rustc_session::Session;
use rustc_codegen_ssa::back::archive::{find_library, ArchiveBuilder};
use rustc_codegen_ssa::METADATA_FILENAME;

View File

@ -134,12 +134,12 @@ pub(crate) fn trans_fn<'tcx, B: Backend + 'static>(
pub(crate) fn verify_func(tcx: TyCtxt<'_>, writer: &crate::pretty_clif::CommentWriter, func: &Function) {
tcx.sess.time("verify clif ir", || {
let flags = settings::Flags::new(settings::builder());
match ::cranelift_codegen::verify_function(&func, &flags) {
let flags = cranelift_codegen::settings::Flags::new(cranelift_codegen::settings::builder());
match cranelift_codegen::verify_function(&func, &flags) {
Ok(_) => {}
Err(err) => {
tcx.sess.err(&format!("{:?}", err));
let pretty_error = ::cranelift_codegen::print_errors::pretty_verifier_error(
let pretty_error = cranelift_codegen::print_errors::pretty_verifier_error(
&func,
None,
Some(Box::new(writer)),
@ -323,7 +323,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Backend>) {
// Black box
}
_ => unimpl_fatal!(fx.tcx, bb_data.terminator().source_info.span, "Inline assembly is not supported"),
_ => fx.tcx.sess.span_fatal(bb_data.terminator().source_info.span, "Inline assembly is not supported"),
}
}
TerminatorKind::Resume | TerminatorKind::Abort => {
@ -363,7 +363,7 @@ fn trans_stmt<'tcx>(
cur_block: Block,
stmt: &Statement<'tcx>,
) {
let _print_guard = PrintOnPanic(|| format!("stmt {:?}", stmt));
let _print_guard = crate::PrintOnPanic(|| format!("stmt {:?}", stmt));
fx.set_debug_loc(stmt.source_info);
@ -691,7 +691,7 @@ fn trans_stmt<'tcx>(
"int $$0x29" => {
crate::trap::trap_unimplemented(fx, "Windows abort");
}
_ => unimpl_fatal!(fx.tcx, stmt.source_info.span, "Inline assembly is not supported"),
_ => fx.tcx.sess.span_fatal(stmt.source_info.span, "Inline assembly is not supported"),
}
}
}

View File

@ -302,16 +302,6 @@ impl<'tcx, B: Backend + 'static> HasTargetSpec for FunctionCx<'_, 'tcx, B> {
}
}
impl<'tcx, B: Backend> BackendTypes for FunctionCx<'_, 'tcx, B> {
type Value = Value;
type Function = Value;
type BasicBlock = Block;
type Type = Type;
type Funclet = !;
type DIScope = !;
type DIVariable = !;
}
impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
pub(crate) fn monomorphize<T>(&self, value: &T) -> T
where

View File

@ -4,7 +4,7 @@ use rustc_middle::mir::mono::CodegenUnit;
use rustc_session::config::{DebugInfo, OutputType};
use rustc_session::cgu_reuse_tracker::CguReuse;
use rustc_codegen_ssa::back::linker::LinkerInfo;
use rustc_codegen_ssa::CrateInfo;
use rustc_codegen_ssa::{CrateInfo, CodegenResults, CompiledModule, ModuleKind};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use crate::prelude::*;
@ -110,7 +110,7 @@ fn module_codegen(tcx: TyCtxt<'_>, cgu_name: rustc_span::Symbol) -> ModuleCodege
let module = new_module(tcx, cgu_name.as_str().to_string());
let mut cx = CodegenCx::new(tcx, module, tcx.sess.opts.debuginfo != DebugInfo::None);
let mut cx = crate::CodegenCx::new(tcx, module, tcx.sess.opts.debuginfo != DebugInfo::None);
super::codegen_mono_items(&mut cx, mono_items);
let (mut module, debug, mut unwind_context) = tcx.sess.time("finalize CodegenCx", || cx.finalize());
crate::main_shim::maybe_create_entry_wrapper(tcx, &mut module, &mut unwind_context);

View File

@ -52,7 +52,7 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>) -> ! {
.into_iter()
.collect::<Vec<(_, (_, _))>>();
let mut cx = CodegenCx::new(tcx, jit_module, false);
let mut cx = crate::CodegenCx::new(tcx, jit_module, false);
let (mut jit_module, _debug, mut unwind_context) = super::time(tcx, "codegen mono items", || {
super::codegen_mono_items(&mut cx, mono_items);

View File

@ -30,7 +30,7 @@ pub(crate) fn codegen_crate(
}
fn codegen_mono_items<'tcx>(
cx: &mut CodegenCx<'tcx, impl Backend + 'static>,
cx: &mut crate::CodegenCx<'tcx, impl Backend + 'static>,
mono_items: Vec<(MonoItem<'tcx>, (RLinkage, Visibility))>,
) {
cx.tcx.sess.time("predefine functions", || {
@ -62,9 +62,9 @@ fn trans_mono_item<'tcx, B: Backend + 'static>(
match mono_item {
MonoItem::Fn(inst) => {
let _inst_guard =
PrintOnPanic(|| format!("{:?} {}", inst, tcx.symbol_name(inst).name.as_str()));
crate::PrintOnPanic(|| format!("{:?} {}", inst, tcx.symbol_name(inst).name.as_str()));
debug_assert!(!inst.substs.needs_infer());
let _mir_guard = PrintOnPanic(|| {
let _mir_guard = crate::PrintOnPanic(|| {
match inst.def {
InstanceDef::Item(_)
| InstanceDef::DropGlue(_, _)

View File

@ -452,7 +452,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
intrinsic_match! {
fx, intrinsic, substs, args,
_ => {
unimpl_fatal!(fx.tcx, span, "unsupported intrinsic {}", intrinsic);
fx.tcx.sess.span_fatal(span, &format!("unsupported intrinsic {}", intrinsic));
};
assume, (c _a) {};

View File

@ -29,11 +29,13 @@ use std::any::Any;
use rustc_errors::ErrorReported;
use rustc_middle::dep_graph::{DepGraph, WorkProduct, WorkProductId};
use rustc_middle::middle::cstore::{EncodedMetadata, MetadataLoader};
use rustc_session::Session;
use rustc_session::config::OutputFilenames;
use rustc_middle::ty::query::Providers;
use rustc_codegen_ssa::CodegenResults;
use rustc_codegen_ssa::traits::CodegenBackend;
use cranelift_codegen::settings;
use cranelift_codegen::settings::{self, Configurable};
use crate::constant::ConstantCx;
use crate::prelude::*;
@ -75,7 +77,6 @@ mod prelude {
pub(crate) use rustc_middle::bug;
pub(crate) use rustc_hir::def_id::{DefId, LOCAL_CRATE};
pub(crate) use rustc_middle::mir::{self, *};
pub(crate) use rustc_session::Session;
pub(crate) use rustc_middle::ty::layout::{self, TyAndLayout};
pub(crate) use rustc_target::abi::{Abi, LayoutOf, Scalar, Size, VariantIdx};
pub(crate) use rustc_middle::ty::{
@ -86,9 +87,6 @@ mod prelude {
pub(crate) use rustc_index::vec::Idx;
pub(crate) use rustc_codegen_ssa::traits::*;
pub(crate) use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleKind};
pub(crate) use cranelift_codegen::Context;
pub(crate) use cranelift_codegen::entity::EntitySet;
pub(crate) use cranelift_codegen::ir::{AbiParam, Block, ExternalName, FuncRef, Inst, InstBuilder, MemFlags, Signature, SourceLoc, StackSlot, StackSlotData, StackSlotKind, TrapCode, Type, Value};
@ -96,7 +94,6 @@ mod prelude {
pub(crate) use cranelift_codegen::ir::function::Function;
pub(crate) use cranelift_codegen::ir::types;
pub(crate) use cranelift_codegen::isa::{self, CallConv};
pub(crate) use cranelift_codegen::settings::{self, Configurable};
pub(crate) use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext, Variable};
pub(crate) use cranelift_module::{
self, Backend, DataContext, DataId, FuncId, Linkage, Module,
@ -110,23 +107,18 @@ mod prelude {
pub(crate) use crate::pointer::Pointer;
pub(crate) use crate::trap::*;
pub(crate) use crate::value_and_place::{CPlace, CPlaceInner, CValue};
pub(crate) use crate::CodegenCx;
}
pub(crate) struct PrintOnPanic<F: Fn() -> String>(pub F);
impl<F: Fn() -> String> Drop for PrintOnPanic<F> {
fn drop(&mut self) {
if ::std::thread::panicking() {
println!("{}", (self.0)());
}
struct PrintOnPanic<F: Fn() -> String>(F);
impl<F: Fn() -> String> Drop for PrintOnPanic<F> {
fn drop(&mut self) {
if ::std::thread::panicking() {
println!("{}", (self.0)());
}
}
pub(crate) macro unimpl_fatal($tcx:expr, $span:expr, $($tt:tt)*) {
$tcx.sess.span_fatal($span, &format!($($tt)*));
}
}
pub(crate) struct CodegenCx<'tcx, B: Backend + 'static> {
struct CodegenCx<'tcx, B: Backend + 'static> {
tcx: TyCtxt<'tcx>,
module: Module<B>,
constants_cx: ConstantCx,