Closed
Description
Right now the compiler writes main
as a wrapper that magically obtains the pointer to the Rust main
function and to the crate map, then calls the runtime start
function. Imagine something like:
fn _rust_main(argc: int, argv: **i8) {
// note neither `get_main` or `get_crate_map` actually exist
rt::start(get_main(), argc, argv, get_crate_map());
}
There are several reasons why this is not the best arrangement. One impact of this is that our most basic entry point, start
, takes a third crate_map
argument that must be supplied before main.
We could turn this logic into a syntax extension, making the only real entry point start
, taking argc and argv (types tbd).
- Make a way to retrieve the crate map at runtime, either an intrinsic (for now) or by some other mechanism once logging becomes a syntax extension.
- Add a syntax extension that looks for either
main
or#[main]
and, if it finds it, add a wrapper function,#[start] __start
. - Later passes look only for
#[start]
. - Trans generates the minimal code to call
#[start]
.
Related #3309