Split lang_start in two functions to reduce generated code

This commit is contained in:
Bastian Köcher 2017-12-24 00:15:38 +01:00
parent c2f22f01a9
commit 7dfec34a20

View File

@ -26,10 +26,11 @@
// Reexport some of our utilities which are expected by other crates. // Reexport some of our utilities which are expected by other crates.
pub use panicking::{begin_panic, begin_panic_fmt, update_panic_count}; pub use panicking::{begin_panic, begin_panic_fmt, update_panic_count};
// To reduce the generated code of the new `lang_start`, this function is doing
// the real work.
#[cfg(not(any(test, stage0)))] #[cfg(not(any(test, stage0)))]
#[lang = "start"] fn lang_start_real<F>(main: F, argc: isize, argv: *const *const u8) -> !
fn lang_start<T: ::termination::Termination + 'static> where F: FnOnce() -> i32 + Send + ::panic::UnwindSafe + 'static
(main: fn() -> T, argc: isize, argv: *const *const u8) -> !
{ {
use panic; use panic;
use sys; use sys;
@ -59,16 +60,24 @@ fn lang_start<T: ::termination::Termination + 'static>
// Let's run some code! // Let's run some code!
#[cfg(feature = "backtrace")] #[cfg(feature = "backtrace")]
let exit_code = panic::catch_unwind(|| { let exit_code = panic::catch_unwind(|| {
::sys_common::backtrace::__rust_begin_short_backtrace(move || main().report()) ::sys_common::backtrace::__rust_begin_short_backtrace(move || main())
}); });
#[cfg(not(feature = "backtrace"))] #[cfg(not(feature = "backtrace"))]
let exit_code = panic::catch_unwind(move || main().report()); let exit_code = panic::catch_unwind(move || main());
sys_common::cleanup(); sys_common::cleanup();
exit_code.unwrap_or(101) exit_code.unwrap_or(101)
}); });
} }
#[cfg(not(any(test, stage0)))]
#[lang = "start"]
fn lang_start<T: ::termination::Termination + 'static>
(main: fn() -> T, argc: isize, argv: *const *const u8) -> !
{
lang_start_real(move || main().report(), argc, argv)
}
#[cfg(all(not(test), stage0))] #[cfg(all(not(test), stage0))]
#[lang = "start"] #[lang = "start"]
fn lang_start(main: fn(), argc: isize, argv: *const *const u8) -> isize { fn lang_start(main: fn(), argc: isize, argv: *const *const u8) -> isize {