Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 75db7cc

Browse files
committed
Remove logfile support from unimpl.rs
I haven't used it in months
1 parent 6129921 commit 75db7cc

File tree

5 files changed

+21
-53
lines changed

5 files changed

+21
-53
lines changed

src/base.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,8 @@ pub fn trans_fn<'clif, 'tcx, B: Backend + 'static>(
5353
source_info_set: indexmap::IndexSet::new(),
5454
};
5555

56-
with_unimpl_span(fx.mir.span, || {
57-
crate::abi::codegen_fn_prelude(&mut fx, start_ebb);
58-
codegen_fn_content(&mut fx);
59-
});
56+
crate::abi::codegen_fn_prelude(&mut fx, start_ebb);
57+
codegen_fn_content(&mut fx);
6058

6159
// Recover all necessary data from fx, before accessing func will prevent future access to it.
6260
let instance = fx.instance;
@@ -500,7 +498,7 @@ fn trans_stmt<'tcx>(
500498
to.write_cvalue(fx, operand);
501499
}
502500
}
503-
_ => unimpl!("shouldn't exist at trans {:?}", to_place_and_rval.1),
501+
_ => unreachable!("shouldn't exist at trans {:?}", to_place_and_rval.1),
504502
},
505503
}
506504
}

src/driver.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::any::Any;
22
use std::ffi::CString;
3-
use std::fs::File;
43
use std::os::raw::{c_char, c_int};
54

65
use rustc::middle::cstore::EncodedMetadata;
@@ -20,27 +19,21 @@ pub fn codegen_crate(
2019
) -> Box<dyn Any> {
2120
tcx.sess.abort_if_errors();
2221

23-
let mut log = if cfg!(debug_assertions) {
24-
Some(File::create(concat!(env!("CARGO_MANIFEST_DIR"), "/target/out/log.txt")).unwrap())
25-
} else {
26-
None
27-
};
28-
2922
if std::env::var("SHOULD_RUN").is_ok()
3023
&& tcx.sess.crate_types.get().contains(&CrateType::Executable)
3124
{
3225
#[cfg(not(target_arch = "wasm32"))]
33-
let _: ! = run_jit(tcx, &mut log);
26+
let _: ! = run_jit(tcx);
3427

3528
#[cfg(target_arch = "wasm32")]
3629
panic!("jit not supported on wasm");
3730
}
3831

39-
run_aot(tcx, metadata, need_metadata_module, &mut log)
32+
run_aot(tcx, metadata, need_metadata_module)
4033
}
4134

4235
#[cfg(not(target_arch = "wasm32"))]
43-
fn run_jit(tcx: TyCtxt<'_>, log: &mut Option<File>) -> ! {
36+
fn run_jit(tcx: TyCtxt<'_>) -> ! {
4437
use cranelift_simplejit::{SimpleJITBackend, SimpleJITBuilder};
4538

4639
let imported_symbols = load_imported_symbols_for_jit(tcx);
@@ -67,7 +60,7 @@ fn run_jit(tcx: TyCtxt<'_>, log: &mut Option<File>) -> ! {
6760
.declare_function("main", Linkage::Import, &sig)
6861
.unwrap();
6962

70-
codegen_cgus(tcx, &mut jit_module, &mut None, log);
63+
codegen_cgus(tcx, &mut jit_module, &mut None);
7164
crate::allocator::codegen(tcx, &mut jit_module);
7265
jit_module.finalize_definitions();
7366

@@ -152,7 +145,6 @@ fn run_aot(
152145
tcx: TyCtxt<'_>,
153146
metadata: EncodedMetadata,
154147
need_metadata_module: bool,
155-
log: &mut Option<File>,
156148
) -> Box<CodegenResults> {
157149
let new_module = |name: String| {
158150
let module: Module<FaerieBackend> = Module::new(
@@ -207,7 +199,7 @@ fn run_aot(
207199
None
208200
};
209201

210-
codegen_cgus(tcx, &mut faerie_module, &mut debug, log);
202+
codegen_cgus(tcx, &mut faerie_module, &mut debug);
211203

212204
tcx.sess.abort_if_errors();
213205

@@ -285,7 +277,6 @@ fn codegen_cgus<'tcx>(
285277
tcx: TyCtxt<'tcx>,
286278
module: &mut Module<impl Backend + 'static>,
287279
debug: &mut Option<DebugContext<'tcx>>,
288-
log: &mut Option<File>,
289280
) {
290281
let (_, cgus) = tcx.collect_and_partition_mono_items(LOCAL_CRATE);
291282
let mono_items = cgus
@@ -294,7 +285,7 @@ fn codegen_cgus<'tcx>(
294285
.flatten()
295286
.collect::<FxHashMap<_, (_, _)>>();
296287

297-
codegen_mono_items(tcx, module, debug.as_mut(), log, mono_items);
288+
codegen_mono_items(tcx, module, debug.as_mut(), mono_items);
298289

299290
crate::main_shim::maybe_create_entry_wrapper(tcx, module);
300291
}
@@ -303,7 +294,6 @@ fn codegen_mono_items<'tcx>(
303294
tcx: TyCtxt<'tcx>,
304295
module: &mut Module<impl Backend + 'static>,
305296
debug_context: Option<&mut DebugContext<'tcx>>,
306-
log: &mut Option<File>,
307297
mono_items: FxHashMap<MonoItem<'tcx>, (RLinkage, Visibility)>,
308298
) {
309299
let mut cx = CodegenCx::new(tcx, module, debug_context);
@@ -321,7 +311,7 @@ fn codegen_mono_items<'tcx>(
321311
}
322312

323313
for (mono_item, (linkage, visibility)) in mono_items {
324-
crate::unimpl::try_unimpl(tcx, log, || {
314+
crate::unimpl::try_unimpl(tcx, mono_item.to_string(tcx, true), || {
325315
let linkage = crate::linkage::get_clif_linkage(mono_item, linkage, visibility);
326316
trans_mono_item(&mut cx, mono_item, linkage);
327317
});

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ mod prelude {
105105
pub use crate::common::*;
106106
pub use crate::debuginfo::{DebugContext, FunctionDebugContext};
107107
pub use crate::trap::*;
108-
pub use crate::unimpl::{unimpl, with_unimpl_span};
108+
pub use crate::unimpl::unimpl;
109109
pub use crate::value_and_place::{CPlace, CPlaceInner, CValue};
110110
pub use crate::{Caches, CodegenCx};
111111

src/unimpl.rs

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@
22
//! a non-fatal error on not yet implemented things.
33
44
use std::cell::RefCell;
5-
use std::fs::File;
6-
use std::io::Write;
7-
8-
use syntax::source_map::Span;
95

106
use rustc::ty::TyCtxt;
117

128
thread_local! {
13-
static SPAN_STACK: RefCell<Vec<Span>> = RefCell::new(vec![]);
9+
static CURRENT_MSG: RefCell<String> = RefCell::new(String::new());
1410
}
1511

1612
// Just public, because of the unimpl macro
@@ -24,35 +20,21 @@ pub macro unimpl($($tt:tt)*) {
2420
panic!(NonFatal(format!($($tt)*)));
2521
}
2622

27-
pub fn try_unimpl(tcx: TyCtxt, log: &mut Option<File>, f: impl FnOnce()) {
28-
let res = ::std::panic::catch_unwind(::std::panic::AssertUnwindSafe(|| f()));
23+
pub fn try_unimpl(tcx: TyCtxt, msg: String, f: impl FnOnce()) {
24+
CURRENT_MSG.with(|current_msg| {
25+
let old = std::mem::replace(&mut *current_msg.borrow_mut(), msg);
26+
27+
let res = ::std::panic::catch_unwind(::std::panic::AssertUnwindSafe(|| f()));
2928

30-
if let Err(err) = res {
31-
SPAN_STACK.with(|span_stack| {
29+
if let Err(err) = res {
3230
match err.downcast::<NonFatal>() {
3331
Ok(non_fatal) => {
34-
if cfg!(debug_assertions) {
35-
writeln!(
36-
log.as_mut().unwrap(),
37-
"{} at {:?}",
38-
&non_fatal.0,
39-
span_stack.borrow()
40-
)
41-
.unwrap();
42-
}
43-
tcx.sess.err(&non_fatal.0)
32+
tcx.sess.err(&format!("at {}: {}", current_msg.borrow(), non_fatal.0));
4433
}
4534
Err(err) => ::std::panic::resume_unwind(err),
4635
}
47-
span_stack.borrow_mut().clear();
48-
});
49-
}
50-
}
36+
}
5137

52-
pub fn with_unimpl_span(span: Span, f: impl FnOnce()) {
53-
SPAN_STACK.with(|span_stack| {
54-
span_stack.borrow_mut().push(span);
55-
f();
56-
span_stack.borrow_mut().pop();
38+
*current_msg.borrow_mut() = old;
5739
});
5840
}

test.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,3 @@ hyperfine --runs ${COMPILE_RUNS:-100} "$COMPILE_MOD_BENCH_INLINE" "$COMPILE_MOD_
100100
echo
101101
echo "[BENCH RUN] mod_bench"
102102
hyperfine --runs ${RUN_RUNS:-10} ./target/out/mod_bench{,_inline} ./target/out/mod_bench_llvm_*
103-
104-
cat target/out/log.txt | sort | uniq -c

0 commit comments

Comments
 (0)