Skip to content

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

Closed
@brson

Description

@brson

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-runtimeArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflowsA-syntaxextArea: Syntax extensionsC-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions