Skip to content

Commit 7dfec34

Browse files
committed
Split lang_start in two functions to reduce generated code
1 parent c2f22f0 commit 7dfec34

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/libstd/rt.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@
2626
// Reexport some of our utilities which are expected by other crates.
2727
pub use panicking::{begin_panic, begin_panic_fmt, update_panic_count};
2828

29+
// To reduce the generated code of the new `lang_start`, this function is doing
30+
// the real work.
2931
#[cfg(not(any(test, stage0)))]
30-
#[lang = "start"]
31-
fn lang_start<T: ::termination::Termination + 'static>
32-
(main: fn() -> T, argc: isize, argv: *const *const u8) -> !
32+
fn lang_start_real<F>(main: F, argc: isize, argv: *const *const u8) -> !
33+
where F: FnOnce() -> i32 + Send + ::panic::UnwindSafe + 'static
3334
{
3435
use panic;
3536
use sys;
@@ -59,16 +60,24 @@ fn lang_start<T: ::termination::Termination + 'static>
5960
// Let's run some code!
6061
#[cfg(feature = "backtrace")]
6162
let exit_code = panic::catch_unwind(|| {
62-
::sys_common::backtrace::__rust_begin_short_backtrace(move || main().report())
63+
::sys_common::backtrace::__rust_begin_short_backtrace(move || main())
6364
});
6465
#[cfg(not(feature = "backtrace"))]
65-
let exit_code = panic::catch_unwind(move || main().report());
66+
let exit_code = panic::catch_unwind(move || main());
6667

6768
sys_common::cleanup();
6869
exit_code.unwrap_or(101)
6970
});
7071
}
7172

73+
#[cfg(not(any(test, stage0)))]
74+
#[lang = "start"]
75+
fn lang_start<T: ::termination::Termination + 'static>
76+
(main: fn() -> T, argc: isize, argv: *const *const u8) -> !
77+
{
78+
lang_start_real(move || main().report(), argc, argv)
79+
}
80+
7281
#[cfg(all(not(test), stage0))]
7382
#[lang = "start"]
7483
fn lang_start(main: fn(), argc: isize, argv: *const *const u8) -> isize {

0 commit comments

Comments
 (0)