Skip to content
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

Clean up rustdoc startup #102769

Merged
merged 9 commits into from
Oct 19, 2022
Merged

Clean up rustdoc startup #102769

merged 9 commits into from
Oct 19, 2022

Commits on Oct 18, 2022

  1. Clean up rustdoc startup.

    rustc's startup has several layers, including:
    - `interface::run_compiler` passes a closure, `f`, to
      `run_in_thread_pool_with_globals`, which creates a thread pool, sets
      up session globals, and passes `f` to `create_compiler_and_run`.
    - `create_compiler_and_run` creates a `Session`, a `Compiler`, sets the
      source map, and calls `f`.
    
    rustdoc is a bit different.
    - `main_args` calls `main_options` via
      `run_in_thread_pool_with_globals`, which (again) creates a thread pool
      (hardcoded to a single thread!) and sets up session globals.
    - `main_options` has four different paths.
      - The second one calls `interface::run_compiler`, which redoes the
        `run_in_thread_pool_with_globals`! This is bad.
      - The fourth one calls `interface::create_compiler_and_run`, which is
        reasonable.
      - The first and third ones don't do anything of note involving the
        above functions, except for some symbol interning which requires
        session globals.
    
    In other words, rustdoc calls into `rustc_interface` at three different
    levels. It's a bit confused, and feels like code where functionality has
    been added by different people at different times without fully
    understanding how the globally accessible stuff is set up.
    
    This commit tidies things up. It removes the
    `run_in_thread_pool_with_globals` call in `main_args`, and adjust the
    four paths in `main_options` as follows.
    - `markdown::test` calls `test::test_main`, which provides its own
      parallelism and so doesn't need a thread pool. It had one small use of
      symbol interning, which required session globals, but the commit
      removes this.
    - `doctest::run` already calls `interface::run_compiler`, so it doesn't
      need further adjustment.
    - `markdown::render` is simple but needs session globals for interning
      (which can't easily be removed), so it's now wrapped in
      `create_session_globals_then`.
    - The fourth path now uses `interface::run_compiler`, which is
      equivalent to the old `run_in_thread_pool_with_globals` +
      `create_compiler_and_run` pairing.
    nnethercote committed Oct 18, 2022
    Configuration menu
    Copy the full SHA
    021d1fb View commit details
    Browse the repository at this point in the history
  2. Merge main_options into main_args.

    There is no longer any need for them to be separate.
    nnethercote committed Oct 18, 2022
    Configuration menu
    Copy the full SHA
    2a62c92 View commit details
    Browse the repository at this point in the history
  3. Inline and remove scoped_thread.

    It has a single call site, and removing it slightly improves the
    confusing tangle of nested closures present at startup.
    nnethercote committed Oct 18, 2022
    Configuration menu
    Copy the full SHA
    134e9d3 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    dcc194e View commit details
    Browse the repository at this point in the history
  5. Inline and remove create_compiler_and_run.

    It has a single call site.
    nnethercote committed Oct 18, 2022
    Configuration menu
    Copy the full SHA
    b6ae145 View commit details
    Browse the repository at this point in the history
  6. Apply Lrc later to sess and codegen_backend.

    This avoids the need for a degenerate `Lrc::get_mut` call.
    nnethercote committed Oct 18, 2022
    Configuration menu
    Copy the full SHA
    ec409f9 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    63db9e5 View commit details
    Browse the repository at this point in the history
  8. Use interface::run_compiler for markdown::render.

    It turns out `markdown::render` is more complex than it first appears,
    because it can invoke `doctest::make_test`, which requires session
    globals and a thread pool.
    
    So this commit changes it to use `interface::run_compiler`. Three of the
    four paths in `main_args` now use `interface::run_compiler`.
    nnethercote committed Oct 18, 2022
    Configuration menu
    Copy the full SHA
    38988e6 View commit details
    Browse the repository at this point in the history
  9. Avoid cloning RenderOptions.

    By moving `RenderOptions` out of `Option`, because the two structs' uses
    are almost entirely separate.
    
    The only complication is that `unstable_features` is needed in both
    structs, but it's a tiny `Copy` type so its duplication seems fine.
    nnethercote committed Oct 18, 2022
    Configuration menu
    Copy the full SHA
    ca2561a View commit details
    Browse the repository at this point in the history