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

Rollup of 7 pull requests #102960

Closed
wants to merge 30 commits into from
Closed

Commits on Oct 7, 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 7, 2022
    Configuration menu
    Copy the full SHA
    bf135de 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 7, 2022
    Configuration menu
    Copy the full SHA
    c461f3a 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 7, 2022
    Configuration menu
    Copy the full SHA
    d156a90 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    226387a 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 7, 2022
    Configuration menu
    Copy the full SHA
    c00937f 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 7, 2022
    Configuration menu
    Copy the full SHA
    8067016 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    1f0463a View commit details
    Browse the repository at this point in the history

Commits on Oct 9, 2022

  1. impl AsFd for io::{Stdin, Stdout, Stderr}, not the sys versions

    rust-lang#100892 implemented AsFd for the
    sys versions, rather than for the public types. Change the
    implementations to apply to the public types.
    joshtriplett committed Oct 9, 2022
    Configuration menu
    Copy the full SHA
    88bb4e4 View commit details
    Browse the repository at this point in the history

Commits on Oct 10, 2022

  1. macros: tidy up lint changes

    Small tweaks to changes made in a previous PR, unrelated to eager
    translation.
    
    Signed-off-by: David Wood <david.wood@huawei.com>
    davidtwco committed Oct 10, 2022
    Configuration menu
    Copy the full SHA
    febbf71 View commit details
    Browse the repository at this point in the history
  2. errors: use HashMap to store diagnostic args

    Eager translation will enable subdiagnostics to be translated multiple
    times with different arguments - this requires the ability to replace
    the value of one argument with a new value, which is better suited to a
    `HashMap` than the previous storage, a `Vec`.
    
    Signed-off-by: David Wood <david.wood@huawei.com>
    davidtwco committed Oct 10, 2022
    Configuration menu
    Copy the full SHA
    508d7e6 View commit details
    Browse the repository at this point in the history
  3. errors: AddToDiagnostic::add_to_diagnostic_with

    `AddToDiagnostic::add_to_diagnostic_with` is similar to the previous
    `AddToDiagnostic::add_to_diagnostic` but takes a function that can be
    used by the caller to modify diagnostic messages originating from the
    subdiagnostic (such as performing translation eagerly).
    
    `add_to_diagnostic` now just calls `add_to_diagnostic_with` with an
    empty closure.
    
    Signed-off-by: David Wood <david.wood@huawei.com>
    davidtwco committed Oct 10, 2022
    Configuration menu
    Copy the full SHA
    b4ac262 View commit details
    Browse the repository at this point in the history
  4. errors: DiagnosticMessage::Eager

    Add variant of `DiagnosticMessage` for eagerly translated messages
    (messages in the target language which don't need translated by the
    emitter during emission). Also adds `eager_subdiagnostic` function which
    is intended to be invoked by the diagnostic derive for subdiagnostic
    fields which are marked as needing eager translation.
    
    Signed-off-by: David Wood <david.wood@huawei.com>
    davidtwco committed Oct 10, 2022
    Configuration menu
    Copy the full SHA
    540b203 View commit details
    Browse the repository at this point in the history
  5. macros: #[subdiagnostic(eager)]

    Add support for `eager` argument to the `subdiagnostic` attribute which
    generates a call to `eager_subdiagnostic`.
    
    Signed-off-by: David Wood <david.wood@huawei.com>
    davidtwco committed Oct 10, 2022
    Configuration menu
    Copy the full SHA
    291a473 View commit details
    Browse the repository at this point in the history
  6. query_system: finish migration

    Using eager translation, migrate the remaining repeated cycle stack
    diagnostic.
    
    Signed-off-by: David Wood <david.wood@huawei.com>
    davidtwco committed Oct 10, 2022
    Configuration menu
    Copy the full SHA
    113e943 View commit details
    Browse the repository at this point in the history
  7. macros: separate suggestion fmt'ing and emission

    Diagnostic derives have previously had to take special care when
    ordering the generated code so that fields were not used after a move.
    
    This is unlikely for most fields because a field is either annotated
    with a subdiagnostic attribute and is thus likely a `Span` and copiable,
    or is a argument, in which case it is only used once by `set_arg`
    anyway.
    
    However, format strings for code in suggestions can result in fields
    being used after being moved if not ordered carefully. As a result, the
    derive currently puts `set_arg` calls last (just before emission), such
    as:
    
    ```rust
    let diag = { /* create diagnostic */ };
    
    diag.span_suggestion_with_style(
        span,
        fluent::crate::slug,
        format!("{}", __binding_0),
        Applicability::Unknown,
        SuggestionStyle::ShowAlways
    );
    /* + other subdiagnostic additions */
    
    diag.set_arg("foo", __binding_0);
    /* + other `set_arg` calls */
    
    diag.emit();
    ```
    
    For eager translation, this doesn't work, as the message being
    translated eagerly can assume that all arguments are available - so
    arguments _must_ be set first.
    
    Format strings for suggestion code are now separated into two parts - an
    initialization line that performs the formatting into a variable, and a
    usage in the subdiagnostic addition.
    
    By separating these parts, the initialization can happen before
    arguments are set, preserving the desired order so that code compiles,
    while still enabling arguments to be set before subdiagnostics are
    added.
    
    ```rust
    let diag = { /* create diagnostic */ };
    
    let __code_0 = format!("{}", __binding_0);
    /* + other formatting */
    
    diag.set_arg("foo", __binding_0);
    /* + other `set_arg` calls */
    
    diag.span_suggestion_with_style(
        span,
        fluent::crate::slug,
        __code_0,
        Applicability::Unknown,
        SuggestionStyle::ShowAlways
    );
    /* + other subdiagnostic additions */
    
    diag.emit();
    ```
    
    Signed-off-by: David Wood <david.wood@huawei.com>
    davidtwco committed Oct 10, 2022
    Configuration menu
    Copy the full SHA
    7e20929 View commit details
    Browse the repository at this point in the history
  8. macros: simplify field ordering in diag derive

    Following the approach taken in earlier commits to separate formatting
    initialization from use in the subdiagnostic derive, simplify the
    diagnostic derive by removing the field-ordering logic that previously
    solved this problem.
    
    Signed-off-by: David Wood <david.wood@huawei.com>
    davidtwco committed Oct 10, 2022
    Configuration menu
    Copy the full SHA
    fbac1f2 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    d17a69e View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    ef68327 View commit details
    Browse the repository at this point in the history

Commits on Oct 11, 2022

  1. rustdoc: remove unused CSS nav.sum

    This was added in 4fd061c, but never
    actually used.
    notriddle committed Oct 11, 2022
    Configuration menu
    Copy the full SHA
    87060c4 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    46169e6 View commit details
    Browse the repository at this point in the history
  3. Update books

    ehuss committed Oct 11, 2022
    Configuration menu
    Copy the full SHA
    f8048aa View commit details
    Browse the repository at this point in the history

Commits on Oct 12, 2022

  1. Configuration menu
    Copy the full SHA
    c646c4d View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    bef8681 View commit details
    Browse the repository at this point in the history
  3. Rollup merge of rust-lang#102623 - davidtwco:translation-eager, r=com…

    …piler-errors
    
    translation: eager translation
    
    Part of rust-lang#100717. See [Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/.23100717.20lists!/near/295010720) for additional context.
    
    - **Store diagnostic arguments in a `HashMap`**: Eager translation will enable subdiagnostics to be translated multiple times with different arguments - this requires the ability to replace the value of one argument with a new value, which is better suited to a `HashMap` than the previous storage, a `Vec`.
    - **Add `AddToDiagnostic::add_to_diagnostic_with`**: `AddToDiagnostic::add_to_diagnostic_with` is similar to the previous `AddToDiagnostic::add_to_diagnostic` but takes a function that can be used by the caller to modify diagnostic messages originating from the subdiagnostic (such as performing translation eagerly). `add_to_diagnostic` now just calls `add_to_diagnostic_with` with an empty closure.
    - **Add `DiagnosticMessage::Eager`**: Add variant of `DiagnosticMessage` for eagerly translated messages
    (messages in the target language which don't need translated by the emitter during emission). Also adds `eager_subdiagnostic` function which is intended to be invoked by the diagnostic derive for subdiagnostic fields which are marked as needing eager translation.
    - **Support `#[subdiagnostic(eager)]`**: Add support for `eager` argument to the `subdiagnostic` attribute which generates a call to `eager_subdiagnostic`.
    - **Finish migrating `rustc_query_system`**: Using eager translation, migrate the remaining repeated cycle stack diagnostic.
    - **Split formatting initialization and use in diagnostic derives**: Diagnostic derives have previously had to take special care when ordering the generated code so that fields were not used after a move.
    
      This is unlikely for most fields because a field is either annotated with a subdiagnostic attribute and is thus likely a `Span` and copiable, or is a argument, in which case it is only used once by `set_arg`
    anyway.
    
      However, format strings for code in suggestions can result in fields being used after being moved if not ordered carefully. As a result, the derive currently puts `set_arg` calls last (just before emission), such as:
    
          let diag = { /* create diagnostic */ };
    
          diag.span_suggestion_with_style(
              span,
              fluent::crate::slug,
              format!("{}", __binding_0),
              Applicability::Unknown,
              SuggestionStyle::ShowAlways
          );
          /* + other subdiagnostic additions */
    
          diag.set_arg("foo", __binding_0);
          /* + other `set_arg` calls */
    
          diag.emit();
    
      For eager translation, this doesn't work, as the message being translated eagerly can assume that all arguments are available - so arguments _must_ be set first.
    
      Format strings for suggestion code are now separated into two parts - an initialization line that performs the formatting into a variable, and a usage in the subdiagnostic addition.
    
      By separating these parts, the initialization can happen before arguments are set, preserving the desired order so that code compiles, while still enabling arguments to be set before subdiagnostics are added.
    
          let diag = { /* create diagnostic */ };
    
          let __code_0 = format!("{}", __binding_0);
          /* + other formatting */
    
          diag.set_arg("foo", __binding_0);
          /* + other `set_arg` calls */
    
          diag.span_suggestion_with_style(
              span,
              fluent::crate::slug,
              __code_0,
              Applicability::Unknown,
              SuggestionStyle::ShowAlways
          );
          /* + other subdiagnostic additions */
    
          diag.emit();
    
    - **Remove field ordering logic in diagnostic derive:** Following the approach taken in earlier commits to separate formatting initialization from use in the subdiagnostic derive, simplify the diagnostic derive by removing the field-ordering logic that previously solved this problem.
    
    r? ``@compiler-errors``
    Dylan-DPC committed Oct 12, 2022
    Configuration menu
    Copy the full SHA
    5c38950 View commit details
    Browse the repository at this point in the history
  4. Rollup merge of rust-lang#102769 - nnethercote:rustdoc-startup, r=jyn514

    Clean up rustdoc startup
    
    Startup is pretty hairy, in both rustdoc and rustc. The first commit here improves the rustdoc situation quite a bit. The remaining commits are smaller but also help.
    
    Best reviewed one commit at a time.
    
    r? ```@jyn514```
    Dylan-DPC committed Oct 12, 2022
    Configuration menu
    Copy the full SHA
    f1807cc View commit details
    Browse the repository at this point in the history
  5. Rollup merge of rust-lang#102830 - compiler-errors:constness-parity, …

    …r=fee1-dead
    
    Unify `tcx.constness` query and param env constness checks
    
    The checks that we do in the `constness` query seem inconsistent with the checks that we do to determine if an item's param-env is const, so I merged them into the `constness` query and call that from the `param_env` query.
    
    I'm not sure if this totally makes sense -- is there a case where `tcx.param_env()` would return a const param-env for an item whose `tcx.constness()` is `Constness::NotConst`? Because if not, it seems a bit dangerous that these two differ.
    
    Luckily, not many places actually use `tcx.constness()`, and the checks in `tcx.param_env()` seem stricter than the checks in `tcx.constness()` (at least for the types of items we type-check).
    
    Also, due to the way that `tcx.param_env()` is implemented, it _never_ used to return a const param-env for a item coming from a different crate, which also seems dangerous (though also probably not weaponizable currently, because we seldom actually compute the param-env for a non-local item).
    Dylan-DPC committed Oct 12, 2022
    Configuration menu
    Copy the full SHA
    aa538e6 View commit details
    Browse the repository at this point in the history
  6. Rollup merge of rust-lang#102847 - joshtriplett:bugfix-impl-fd-traits…

    …-for-io-types, r=m-ou-se
    
    impl AsFd and AsRawFd for io::{Stdin, Stdout, Stderr}, not the sys versions
    
    rust-lang#100892 implemented AsFd for the
    sys versions, rather than for the public types. Change the
    implementations to apply to the public types.
    Dylan-DPC committed Oct 12, 2022
    Configuration menu
    Copy the full SHA
    a51f145 View commit details
    Browse the repository at this point in the history
  7. Rollup merge of rust-lang#102883 - Urgau:fix-stabilization-half_open_…

    …range_patterns, r=lcnr
    
    Fix stabilization of `feature(half_open_range_patterns)`
    
    Fixes https://github.com/rust-lang/rust/pull/102275/files#r991292215 by removing the relevant code that was [already partial moved](https://github.com/rust-lang/rust/pull/102275/files#diff-307e0d3a2037c11a3fa16822fbaa0fec08e57ac7d0d6e7354f6005c9482a9e26).
    
    cc `@Undin`
    Dylan-DPC committed Oct 12, 2022
    Configuration menu
    Copy the full SHA
    f7f2ae4 View commit details
    Browse the repository at this point in the history
  8. Rollup merge of rust-lang#102936 - notriddle:notriddle/nav-sum, r=Dyl…

    …an-DPC
    
    rustdoc: remove unused CSS `nav.sum`
    
    This was added in 4fd061c, but never actually used.
    Dylan-DPC committed Oct 12, 2022
    Configuration menu
    Copy the full SHA
    678fe0f View commit details
    Browse the repository at this point in the history
  9. Rollup merge of rust-lang#102940 - ehuss:update-books, r=ehuss

    Update books
    
    ## nomicon
    
    1 commits in f53bfa056929217870a5d2df1366d2e7ba35096d..9c73283775466d22208a0b28afcab44db4c0cc10
    2022-09-05 07:19:02 -0700 to 2022-09-30 07:31:22 +0900
    - Fix typo (rust-lang/nomicon#380)
    
    ## reference
    
    9 commits in a7cdac33ca7356ad49d5c2b5e2c5010889b33eee..f6ed74f582bddcec73f753eafaab3749c4f7df61
    2022-09-19 17:39:58 -0700 to 2022-10-08 02:43:26 -0700
    - Typo 'a' -&gt; 'an' (rust-lang/reference#1280)
    - One line one sentence for expressions and statements main chapters (rust-lang/reference#1277)
    - Document let else statements (rust-lang/reference#1156)
    - Document `label_break_value` in the reference (rust-lang/reference#1263)
    - Document target_has_atomic (rust-lang/reference#1171)
    - update 'unsafe' (rust-lang/reference#1278)
    - Update tokens.md (rust-lang/reference#1276)
    - One sentence, one line Patterns chapter (rust-lang/reference#1275)
    - Use semver-compliant example version (rust-lang/reference#1272)
    
    ## rust-by-example
    
    9 commits in 767a6bd9727a596d7cfdbaeee475e65b2670ea3a..5e7b296d6c345addbd748f242aae28c42555c015
    2022-09-14 09:17:18 -0300 to 2022-10-05 08:24:45 -0300
    - Make it clear that rustdoc uses the commonmark spec (rust-lang/rust-by-example#1622)
    - Update defaults.md (rust-lang/rust-by-example#1615)
    - added "see also" for the @ binding sigil (rust-lang/rust-by-example#1612)
    - add more precision to the effects of --bin flag (rust-lang/rust-by-example#1607)
    - create bar project in cargo/dependencies example (rust-lang/rust-by-example#1606)
    - use consistent wording about type annotation (rust-lang/rust-by-example#1603)
    - cast.md improvements (rust-lang/rust-by-example#1599)
    - Fix typo in macros.md (rust-lang/rust-by-example#1598)
    - Corrected mistaken "The" instead of "There" (rust-lang/rust-by-example#1617)
    
    ## rustc-dev-guide
    
    2 commits in 9a86c0467bbe42056f73fdf5b03fff757d7c4a9b..7518c3445dc02df0d196f5f84e568d633c5141fb
    2022-10-07 18:34:51 +0200 to 2022-10-08 12:29:47 +0200
    - Update debugging.md
    - Use llvm subdomain for compiler-explorer link
    
    ## embedded-book
    
    1 commits in 4ce51cb7441a6f02b5bf9b07b2eb755c21ab7954..c533348edd69f11a8f4225d633a05d7093fddbf3
    2022-09-15 08:53:09 +0000 to 2022-10-10 10:16:49 +0000
    - Fix a typo in registers.md  (rust-embedded/book#330)
    Dylan-DPC committed Oct 12, 2022
    Configuration menu
    Copy the full SHA
    6f1de0b View commit details
    Browse the repository at this point in the history