Skip to content

Commit eb8fd19

Browse files
committed
Prelude cleanup
1 parent 431cebd commit eb8fd19

File tree

9 files changed

+27
-46
lines changed

9 files changed

+27
-46
lines changed

src/abi/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ pub(crate) fn get_function_name_and_sig<'tcx>(
169169
let fn_sig =
170170
tcx.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &fn_sig_for_fn_abi(tcx, inst));
171171
if fn_sig.c_variadic && !support_vararg {
172-
unimpl_fatal!(tcx, tcx.def_span(inst.def_id()), "Variadic function definitions are not yet supported");
172+
tcx.sess.span_fatal(tcx.def_span(inst.def_id()), "Variadic function definitions are not yet supported");
173173
}
174174
let sig = clif_sig_from_fn_sig(tcx, triple, fn_sig, false, inst.def.requires_caller_location(tcx));
175175
(tcx.symbol_name(inst).name.as_str().to_string(), sig)
@@ -601,7 +601,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
601601
// FIXME find a cleaner way to support varargs
602602
if fn_sig.c_variadic {
603603
if fn_sig.abi != Abi::C {
604-
unimpl_fatal!(fx.tcx, span, "Variadic call for non-C abi {:?}", fn_sig.abi);
604+
fx.tcx.sess.span_fatal(span, &format!("Variadic call for non-C abi {:?}", fn_sig.abi));
605605
}
606606
let sig_ref = fx.bcx.func.dfg.call_signature(call_inst).unwrap();
607607
let abi_params = call_args
@@ -610,7 +610,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
610610
let ty = fx.bcx.func.dfg.value_type(arg);
611611
if !ty.is_int() {
612612
// FIXME set %al to upperbound on float args once floats are supported
613-
unimpl_fatal!(fx.tcx, span, "Non int ty {:?} for variadic call", ty);
613+
fx.tcx.sess.span_fatal(span, &format!("Non int ty {:?} for variadic call", ty));
614614
}
615615
AbiParam::new(ty)
616616
})

src/archive.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use std::fs::File;
22
use std::path::{Path, PathBuf};
33

4-
use crate::prelude::*;
5-
4+
use rustc_session::Session;
65
use rustc_codegen_ssa::back::archive::{find_library, ArchiveBuilder};
76
use rustc_codegen_ssa::METADATA_FILENAME;
87

src/base.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,12 @@ pub(crate) fn trans_fn<'tcx, B: Backend + 'static>(
134134

135135
pub(crate) fn verify_func(tcx: TyCtxt<'_>, writer: &crate::pretty_clif::CommentWriter, func: &Function) {
136136
tcx.sess.time("verify clif ir", || {
137-
let flags = settings::Flags::new(settings::builder());
138-
match ::cranelift_codegen::verify_function(&func, &flags) {
137+
let flags = cranelift_codegen::settings::Flags::new(cranelift_codegen::settings::builder());
138+
match cranelift_codegen::verify_function(&func, &flags) {
139139
Ok(_) => {}
140140
Err(err) => {
141141
tcx.sess.err(&format!("{:?}", err));
142-
let pretty_error = ::cranelift_codegen::print_errors::pretty_verifier_error(
142+
let pretty_error = cranelift_codegen::print_errors::pretty_verifier_error(
143143
&func,
144144
None,
145145
Some(Box::new(writer)),
@@ -323,7 +323,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Backend>) {
323323

324324
// Black box
325325
}
326-
_ => unimpl_fatal!(fx.tcx, bb_data.terminator().source_info.span, "Inline assembly is not supported"),
326+
_ => fx.tcx.sess.span_fatal(bb_data.terminator().source_info.span, "Inline assembly is not supported"),
327327
}
328328
}
329329
TerminatorKind::Resume | TerminatorKind::Abort => {
@@ -363,7 +363,7 @@ fn trans_stmt<'tcx>(
363363
cur_block: Block,
364364
stmt: &Statement<'tcx>,
365365
) {
366-
let _print_guard = PrintOnPanic(|| format!("stmt {:?}", stmt));
366+
let _print_guard = crate::PrintOnPanic(|| format!("stmt {:?}", stmt));
367367

368368
fx.set_debug_loc(stmt.source_info);
369369

@@ -691,7 +691,7 @@ fn trans_stmt<'tcx>(
691691
"int $$0x29" => {
692692
crate::trap::trap_unimplemented(fx, "Windows abort");
693693
}
694-
_ => unimpl_fatal!(fx.tcx, stmt.source_info.span, "Inline assembly is not supported"),
694+
_ => fx.tcx.sess.span_fatal(stmt.source_info.span, "Inline assembly is not supported"),
695695
}
696696
}
697697
}

src/common.rs

-10
Original file line numberDiff line numberDiff line change
@@ -302,16 +302,6 @@ impl<'tcx, B: Backend + 'static> HasTargetSpec for FunctionCx<'_, 'tcx, B> {
302302
}
303303
}
304304

305-
impl<'tcx, B: Backend> BackendTypes for FunctionCx<'_, 'tcx, B> {
306-
type Value = Value;
307-
type Function = Value;
308-
type BasicBlock = Block;
309-
type Type = Type;
310-
type Funclet = !;
311-
type DIScope = !;
312-
type DIVariable = !;
313-
}
314-
315305
impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
316306
pub(crate) fn monomorphize<T>(&self, value: &T) -> T
317307
where

src/driver/aot.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_middle::mir::mono::CodegenUnit;
44
use rustc_session::config::{DebugInfo, OutputType};
55
use rustc_session::cgu_reuse_tracker::CguReuse;
66
use rustc_codegen_ssa::back::linker::LinkerInfo;
7-
use rustc_codegen_ssa::CrateInfo;
7+
use rustc_codegen_ssa::{CrateInfo, CodegenResults, CompiledModule, ModuleKind};
88
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
99

1010
use crate::prelude::*;
@@ -110,7 +110,7 @@ fn module_codegen(tcx: TyCtxt<'_>, cgu_name: rustc_span::Symbol) -> ModuleCodege
110110

111111
let module = new_module(tcx, cgu_name.as_str().to_string());
112112

113-
let mut cx = CodegenCx::new(tcx, module, tcx.sess.opts.debuginfo != DebugInfo::None);
113+
let mut cx = crate::CodegenCx::new(tcx, module, tcx.sess.opts.debuginfo != DebugInfo::None);
114114
super::codegen_mono_items(&mut cx, mono_items);
115115
let (mut module, debug, mut unwind_context) = tcx.sess.time("finalize CodegenCx", || cx.finalize());
116116
crate::main_shim::maybe_create_entry_wrapper(tcx, &mut module, &mut unwind_context);

src/driver/jit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>) -> ! {
5252
.into_iter()
5353
.collect::<Vec<(_, (_, _))>>();
5454

55-
let mut cx = CodegenCx::new(tcx, jit_module, false);
55+
let mut cx = crate::CodegenCx::new(tcx, jit_module, false);
5656

5757
let (mut jit_module, _debug, mut unwind_context) = super::time(tcx, "codegen mono items", || {
5858
super::codegen_mono_items(&mut cx, mono_items);

src/driver/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub(crate) fn codegen_crate(
3030
}
3131

3232
fn codegen_mono_items<'tcx>(
33-
cx: &mut CodegenCx<'tcx, impl Backend + 'static>,
33+
cx: &mut crate::CodegenCx<'tcx, impl Backend + 'static>,
3434
mono_items: Vec<(MonoItem<'tcx>, (RLinkage, Visibility))>,
3535
) {
3636
cx.tcx.sess.time("predefine functions", || {
@@ -62,9 +62,9 @@ fn trans_mono_item<'tcx, B: Backend + 'static>(
6262
match mono_item {
6363
MonoItem::Fn(inst) => {
6464
let _inst_guard =
65-
PrintOnPanic(|| format!("{:?} {}", inst, tcx.symbol_name(inst).name.as_str()));
65+
crate::PrintOnPanic(|| format!("{:?} {}", inst, tcx.symbol_name(inst).name.as_str()));
6666
debug_assert!(!inst.substs.needs_infer());
67-
let _mir_guard = PrintOnPanic(|| {
67+
let _mir_guard = crate::PrintOnPanic(|| {
6868
match inst.def {
6969
InstanceDef::Item(_)
7070
| InstanceDef::DropGlue(_, _)

src/intrinsics/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
452452
intrinsic_match! {
453453
fx, intrinsic, substs, args,
454454
_ => {
455-
unimpl_fatal!(fx.tcx, span, "unsupported intrinsic {}", intrinsic);
455+
fx.tcx.sess.span_fatal(span, &format!("unsupported intrinsic {}", intrinsic));
456456
};
457457

458458
assume, (c _a) {};

src/lib.rs

+10-18
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ use std::any::Any;
2929
use rustc_errors::ErrorReported;
3030
use rustc_middle::dep_graph::{DepGraph, WorkProduct, WorkProductId};
3131
use rustc_middle::middle::cstore::{EncodedMetadata, MetadataLoader};
32+
use rustc_session::Session;
3233
use rustc_session::config::OutputFilenames;
3334
use rustc_middle::ty::query::Providers;
35+
use rustc_codegen_ssa::CodegenResults;
3436
use rustc_codegen_ssa::traits::CodegenBackend;
3537

36-
use cranelift_codegen::settings;
38+
use cranelift_codegen::settings::{self, Configurable};
3739

3840
use crate::constant::ConstantCx;
3941
use crate::prelude::*;
@@ -75,7 +77,6 @@ mod prelude {
7577
pub(crate) use rustc_middle::bug;
7678
pub(crate) use rustc_hir::def_id::{DefId, LOCAL_CRATE};
7779
pub(crate) use rustc_middle::mir::{self, *};
78-
pub(crate) use rustc_session::Session;
7980
pub(crate) use rustc_middle::ty::layout::{self, TyAndLayout};
8081
pub(crate) use rustc_target::abi::{Abi, LayoutOf, Scalar, Size, VariantIdx};
8182
pub(crate) use rustc_middle::ty::{
@@ -86,17 +87,13 @@ mod prelude {
8687

8788
pub(crate) use rustc_index::vec::Idx;
8889

89-
pub(crate) use rustc_codegen_ssa::traits::*;
90-
pub(crate) use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleKind};
91-
9290
pub(crate) use cranelift_codegen::Context;
9391
pub(crate) use cranelift_codegen::entity::EntitySet;
9492
pub(crate) use cranelift_codegen::ir::{AbiParam, Block, ExternalName, FuncRef, Inst, InstBuilder, MemFlags, Signature, SourceLoc, StackSlot, StackSlotData, StackSlotKind, TrapCode, Type, Value};
9593
pub(crate) use cranelift_codegen::ir::condcodes::{FloatCC, IntCC};
9694
pub(crate) use cranelift_codegen::ir::function::Function;
9795
pub(crate) use cranelift_codegen::ir::types;
9896
pub(crate) use cranelift_codegen::isa::{self, CallConv};
99-
pub(crate) use cranelift_codegen::settings::{self, Configurable};
10097
pub(crate) use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext, Variable};
10198
pub(crate) use cranelift_module::{
10299
self, Backend, DataContext, DataId, FuncId, Linkage, Module,
@@ -110,23 +107,18 @@ mod prelude {
110107
pub(crate) use crate::pointer::Pointer;
111108
pub(crate) use crate::trap::*;
112109
pub(crate) use crate::value_and_place::{CPlace, CPlaceInner, CValue};
113-
pub(crate) use crate::CodegenCx;
110+
}
114111

115-
pub(crate) struct PrintOnPanic<F: Fn() -> String>(pub F);
116-
impl<F: Fn() -> String> Drop for PrintOnPanic<F> {
117-
fn drop(&mut self) {
118-
if ::std::thread::panicking() {
119-
println!("{}", (self.0)());
120-
}
112+
struct PrintOnPanic<F: Fn() -> String>(F);
113+
impl<F: Fn() -> String> Drop for PrintOnPanic<F> {
114+
fn drop(&mut self) {
115+
if ::std::thread::panicking() {
116+
println!("{}", (self.0)());
121117
}
122118
}
123-
124-
pub(crate) macro unimpl_fatal($tcx:expr, $span:expr, $($tt:tt)*) {
125-
$tcx.sess.span_fatal($span, &format!($($tt)*));
126-
}
127119
}
128120

129-
pub(crate) struct CodegenCx<'tcx, B: Backend + 'static> {
121+
struct CodegenCx<'tcx, B: Backend + 'static> {
130122
tcx: TyCtxt<'tcx>,
131123
module: Module<B>,
132124
constants_cx: ConstantCx,

0 commit comments

Comments
 (0)