Skip to content

Replace before-main logic with a syntax extension, use standard args for 'start' (main) #6322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
brson opened this issue May 8, 2013 · 5 comments
Labels
A-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows A-syntaxext Area: Syntax extensions C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@brson
Copy link
Contributor

brson commented May 8, 2013

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

@emberian
Copy link
Member

Triage bump

1 similar comment
@pcwalton
Copy link
Contributor

Triage bump

@brson
Copy link
Contributor Author

brson commented Sep 17, 2013

The crate map could possibly also be a weak symbol that std needs to link against.

@alexcrichton
Copy link
Member

This issue has progress, the crate map is no longer a required argument. Additionally, the #[start] function can be prototyped as:

#[start] fn start(argc: int, argv: **u8) -> int { ... }

Which is kind of what one would expect. @brson, I'm not entirely certain what the motivations of this issue were beyond achieving these two goals, so I'm hesitant to close this. From my understanding of this, it sounds pretty done to me though.

@alexcrichton
Copy link
Member

Closing, starting up in rust is pretty standard now (see my previous comment).

Starting a runtime is also as simple as green::start and native::start.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows A-syntaxext Area: Syntax extensions C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

4 participants