Commit graph

159211 commits

Author SHA1 Message Date
bors c67497a5da Auto merge of #85013 - Mark-Simulacrum:dominators-bitset, r=pnkfelix
Replace dominators algorithm with simple Lengauer-Tarjan

This PR replaces our dominators implementation with that of the simple Lengauer-Tarjan algorithm, which is (to my knowledge and research) the currently accepted 'best' algorithm. The more complex variant has higher constant time overheads, and Semi-NCA (which is arguably a variant of Lengauer-Tarjan too) is not the preferred variant by the first paper cited in the documentation comments: simple Lengauer-Tarjan "is less sensitive to pathological instances, we think it should be preferred where performance guarantees are important" - which they are for us.

This work originally arose from noting that the keccak benchmark spent a considerable portion of its time (both instructions and cycles) in the dominator computations, which sparked an interest in potentially optimizing that code. The current algorithm largely proves slow on long "parallel" chains where the nearest common ancestor lookup (i.e., the intersect function) does not quickly identify a root; it is also inherently a pointer-chasing algorithm so is relatively slow on modern CPUs due to needing to hit memory - though usually in cache - in a tight loop, which still costs several cycles.

This was replaced with a bitset-based algorithm, previously studied in literature but implemented directly from dataflow equations in our case, which proved to be a significant speed up on the keccak benchmark: 20% instruction count wins, as can be seen in [this performance report](https://perf.rust-lang.org/compare.html?start=377d1a984cd2a53327092b90aa1d8b7e22d1e347&end=542da47ff78aa462384062229dad0675792f2638). This algorithm is also relatively simple in comparison to other algorithms and is easy to understand. However, these performance results showed a regression on a number of other benchmarks, and I was unable to get the bitsets to perform well enough that those regressions could be fully mitigated. The implementation "attempt" is seen here in the first commit, and is intended to be kept primarily so that future optimizers do not repeat that path (or can easily refer to the attempt).

The final version of this PR chooses the simple Lengauer-Tarjan algorithm, and implements it along with a number of optimizations found in literature. The current implementation is a slight improvement for many benchmarks, with keccak still being an outlier at ~20%. The implementation in this PR first implements the most basic variant of the algorithm directly from the pseudocode on page 16, physical, or 28 in the PDF of the first paper ("Linear-Time Algorithms for Dominators and Related Problems"). This is then followed by a number of commits which update the implementation to apply various performance improvements, as suggested by the paper. Finally, the last commit annotates the implementation with a number of comments, mostly drawn from the paper, which intend to help readers understand what is going on - these are incomplete without the paper, but writing them certainly helped my understanding. They may be helpful if future optimization attempts are attempted, so I chose to add them in.
2021-12-07 08:12:47 +00:00
bors 2af5c6562d Auto merge of #91599 - RalfJung:miri, r=RalfJung
update Miri

Fixes https://github.com/rust-lang/rust/issues/91542
r? `@ghost`
2021-12-07 04:19:50 +00:00
Mark Rousskov 15483ccf9d Annotate comments onto the LT algorithm 2021-12-06 20:30:15 -05:00
bors 953f8c8b1f Auto merge of #91590 - flip1995:clippyup, r=Manishearth
Update Clippy

Since RLS is now already broken #91543 , we shouldn't be blocked by it anymore. I plan to do the RLS update once new rustc-ap packages are released.

r? `@Manishearth`
2021-12-07 01:25:44 +00:00
Mark Rousskov 3187480070 Avoid using Option where values are always Some 2021-12-06 15:05:22 -05:00
Mark Rousskov 2b63059772 Create newtype around the pre order index 2021-12-06 15:05:22 -05:00
Mark Rousskov cc63ec32fb Use variables rather than lengths directly 2021-12-06 15:05:22 -05:00
Mark Rousskov 345ada0e1b Optimize: reuse the real-to-preorder mapping as the visited set 2021-12-06 15:05:22 -05:00
Mark Rousskov 8991002644 Remove separate RPO traversal
This integrates the preorder and postorder traversals into one.
2021-12-06 15:05:22 -05:00
Mark Rousskov 7d12767dc5 Use preorder indices for data structures
This largely avoids remapping from and to the 'real' indices, with the exception
of predecessor lookup and the final merge back, and is conceptually better.
2021-12-06 15:05:22 -05:00
Mark Rousskov 92186cb5c9 Avoid inserting into buckets if not necessary 2021-12-06 15:05:22 -05:00
Mark Rousskov 7379d24ebc Optimization: process buckets only once 2021-12-06 15:05:22 -05:00
Mark Rousskov c82fe0efb4 Optimization: Merge parent and ancestor arrays
As the paper indicates, the unprocessed vertices in the DFS tree and processed
vertices are disjoint, and we can use them in the same space, tracking only the index
of the split.
2021-12-06 15:05:22 -05:00
Mark Rousskov e8d7248093 Implement the simple Lengauer-Tarjan algorithm
This replaces the previous implementation with the simple variant of
Lengauer-Tarjan, which performs better in the general case. Performance on the
keccak benchmark is about equivalent between the two, but we don't see
regressions (and indeed see improvements) on other benchmarks, even on a
partially optimized implementation.

The implementation here follows that of the pseudocode in "Linear-Time
Algorithms for Dominators and Related Problems" thesis by Loukas Georgiadis. The
next few commits will optimize the implementation as suggested in the thesis.
Several related works are cited in the comments within the implementation, as
well.

Implement the simple Lengauer-Tarjan algorithm

This replaces the previous implementation (from #34169), which has not been
optimized since, with the simple variant of Lengauer-Tarjan which performs
better in the general case. A previous attempt -- not kept in commit history --
attempted a replacement with a bitset-based implementation, but this led to
regressions on perf.rust-lang.org benchmarks and equivalent wins for the keccak
benchmark, so was rejected.

The implementation here follows that of the pseudocode in "Linear-Time
Algorithms for Dominators and Related Problems" thesis by Loukas Georgiadis. The
next few commits will optimize the implementation as suggested in the thesis.
Several related works are cited in the comments within the implementation, as
well.

On the keccak benchmark, we were previously spending 15% of our cycles computing
the NCA / intersect function; this function is quite expensive, especially on
modern CPUs, as it chases pointers on every iteration in a tight loop. With this
commit, we spend ~0.05% of our time in dominator computation.
2021-12-06 15:03:09 -05:00
Ralf Jung a30d60c883 update Miri 2021-12-06 13:44:21 -05:00
bors 0fb1c371d4 Auto merge of #91279 - scottmcm:small-refactor, r=nagisa
Small mir-opt refactor

Hopefully-non-controversial changes from some not-ready-yet work that I'd figured I'd submit on their own.
2021-12-06 13:04:18 +00:00
flip1995 e36e5a519b
Update Cargo.lock 2021-12-06 12:33:55 +01:00
flip1995 f004a1b3fd
Merge commit 'a5d597637dcb78dc73f93561ce474f23d4177c35' into clippyup 2021-12-06 12:33:31 +01:00
bors bc9326d83d Auto merge of #91580 - scottmcm:less-inband-1-of-28, r=petrochenkov
Stop enabling `in_band_lifetimes` in rustc_data_structures

There's a conversation started in the tracking issue about possibly unaccepting `in_band_lifetimes`, but it's used heavily in the compiler, and thus there'd need to be a bunch of PRs like this if that were to happen.

So here's one to see how much of an impact it has.  For this crate, at least, it doesn't seem like in-band was a big win -- about half the places that were using it didn't even need a named lifetime.

(Oh, and I removed `nll` while I was here too, since it didn't seem needed.  Let me know if I should put that back.)

r? `@petrochenkov`
2021-12-06 09:58:57 +00:00
bors ba9fc4fbfe Auto merge of #91565 - dtolnay:printhelpers, r=jackh726
Delete duplicated helpers from HIR printer

These functions (`cbox`, `nbsp`, `word_nbsp`, `head`, `bopen`, `space_if_not_bol`, `break_offset_if_not_bol`, `synth_comment`, `maybe_print_trailing_comment`, `print_remaining_comments`) are duplicated with identical behavior across the AST printer and HIR printer, but are not specific to AST or HIR data structures.
2021-12-06 06:58:41 +00:00
bors a5d597637d Auto merge of #8077 - nixxquality:single_char_pattern-false-negatives, r=camsteffen
Fix some false negatives for [`single_char_pattern`]

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: Fix some false negatives for [`single_char_pattern`]

I noticed that clippy wasn't complaining about my usage of `split_once("x")` in a personal project so I updated the list of functions.

I had to update the test case for an unrelated issue because replace is now included in the list of functions to be linted.
2021-12-06 05:12:12 +00:00
Scott McMurray 308fd59f42 Stop enabling in_band_lifetimes in rustc_data_structures
There's a conversation in the tracking issue about possibly unaccepting `in_band_lifetimes`, but it's used heavily in the compiler, and thus there'd need to be a bunch of PRs like this if that were to happen.

So here's one to see how much of an impact it has.

(Oh, and I removed `nll` while I was here too, since it didn't seem needed.  Let me know if I should put that back.)
2021-12-05 20:17:35 -08:00
bors 87dce6e8df Auto merge of #91284 - t6:freebsd-riscv64, r=Amanieu
Add support for riscv64gc-unknown-freebsd

For https://doc.rust-lang.org/nightly/rustc/target-tier-policy.html#tier-3-target-policy:

* A tier 3 target must have a designated developer or developers (the "target maintainers") on record to be CCed when issues arise regarding the target. (The mechanism to track and CC such developers may evolve over time.)

For all Rust targets on FreeBSD, it's [rust@FreeBSD.org](mailto:rust@FreeBSD.org).

* Targets must use naming consistent with any existing targets; for instance, a target for the same CPU or OS as an existing Rust target should use the same name for that CPU or OS. Targets should normally use the same names and naming conventions as used elsewhere in the broader ecosystem beyond Rust (such as in other toolchains), unless they have a very good reason to diverge. Changing the name of a target can be highly disruptive, especially once the target reaches a higher tier, so getting the name right is important even for a tier 3 target.

Done.

* Target names should not introduce undue confusion or ambiguity unless absolutely necessary to maintain ecosystem compatibility. For example, if the name of the target makes people extremely likely to form incorrect beliefs about what it targets, the name should be changed or augmented to disambiguate it.

Done

* Tier 3 targets may have unusual requirements to build or use, but must not create legal issues or impose onerous legal terms for the Rust project or for Rust developers or users.

Done.

* The target must not introduce license incompatibilities.

Done.

* Anything added to the Rust repository must be under the standard Rust license (MIT OR Apache-2.0).

Fine with me.

* The target must not cause the Rust tools or libraries built for any other host (even when supporting cross-compilation to the target) to depend on any new dependency less permissive than the Rust licensing policy. This applies whether the dependency is a Rust crate that would require adding new license exceptions (as specified by the tidy tool in the rust-lang/rust repository), or whether the dependency is a native library or binary. In other words, the introduction of the target must not cause a user installing or running a version of Rust or the Rust tools to be subject to any new license requirements.

Done.

* If the target supports building host tools (such as rustc or cargo), those host tools must not depend on proprietary (non-FOSS) libraries, other than ordinary runtime libraries supplied by the platform and commonly used by other binaries built for the target. For instance, rustc built for the target may depend on a common proprietary C runtime library or console output library, but must not depend on a proprietary code generation library or code optimization library. Rust's license permits such combinations, but the Rust project has no interest in maintaining such combinations within the scope of Rust itself, even at tier 3.

Done.

* Targets should not require proprietary (non-FOSS) components to link a functional binary or library.

Done.

* "onerous" here is an intentionally subjective term. At a minimum, "onerous" legal/licensing terms include but are not limited to: non-disclosure requirements, non-compete requirements, contributor license agreements (CLAs) or equivalent, "non-commercial"/"research-only"/etc terms, requirements conditional on the employer or employment of any particular Rust developers, revocable terms, any requirements that create liability for the Rust project or its developers or users, or any requirements that adversely affect the livelihood or prospects of the Rust project or its developers or users.

Fine with me.

* Neither this policy nor any decisions made regarding targets shall create any binding agreement or estoppel by any party. If any member of an approving Rust team serves as one of the maintainers of a target, or has any legal or employment requirement (explicit or implicit) that might affect their decisions regarding a target, they must recuse themselves from any approval decisions regarding the target's tier status, though they may otherwise participate in discussions.

Ok.

* This requirement does not prevent part or all of this policy from being cited in an explicit contract or work agreement (e.g. to implement or maintain support for a target). This requirement exists to ensure that a developer or team responsible for reviewing and approving a target does not face any legal threats or obligations that would prevent them from freely exercising their judgment in such approval, even if such judgment involves subjective matters or goes beyond the letter of these requirements.

Ok.

* Tier 3 targets should attempt to implement as much of the standard libraries as possible and appropriate (core for most targets, alloc for targets that can support dynamic memory allocation, std for targets with an operating system or equivalent layer of system-provided functionality), but may leave some code unimplemented (either unavailable or stubbed out as appropriate), whether because the target makes it impossible to implement or challenging to implement. The authors of pull requests are not obligated to avoid calling any portions of the standard library on the basis of a tier 3 target not implementing those portions.

std is implemented.

* The target must provide documentation for the Rust community explaining how to build for the target, using cross-compilation if possible. If the target supports running tests (even if they do not pass), the documentation must explain how to run tests for the target, using emulation if possible or dedicated hardware if necessary.

Building is possible the same way as other Rust on FreeBSD targets.

* Tier 3 targets must not impose burden on the authors of pull requests, or other developers in the community, to maintain the target. In particular, do not post comments (automated or manual) on a PR that derail or suggest a block on the PR based on a tier 3 target. Do not send automated messages or notifications (via any medium, including via `@)` to a PR author or others involved with a PR regarding a tier 3 target, unless they have opted into such messages.

Ok.

* Backlinks such as those generated by the issue/PR tracker when linking to an issue or PR are not considered a violation of this policy, within reason. However, such messages (even on a separate repository) must not generate notifications to anyone involved with a PR who has not requested such notifications.

Ok.

* Patches adding or updating tier 3 targets must not break any existing tier 2 or tier 1 target, and must not knowingly break another tier 3 target without approval of either the compiler team or the maintainers of the other tier 3 target.

Ok.

* In particular, this may come up when working on closely related targets, such as variations of the same architecture with different features. Avoid introducing unconditional uses of features that another variation of the target may not have; use conditional compilation or runtime detection, as appropriate, to let each target run code supported by that target.

Ok.
2021-12-06 03:51:05 +00:00
bors 09d8a50ea2 Auto merge of #91573 - matthiaskrgr:rollup-wcygm2r, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #91367 (Fix ICE in `check_must_not_suspend_ty()`)
 - #91391 (Simplify --no-headless option for rustdoc-gui tester)
 - #91537 (compiler/rustc_target: make m68k-unknown-linux-gnu use the gnu base)
 - #91554 (Update doc about code block edition attributes)
 - #91563 (Bump download-ci-llvm-stamp for LLD inclusion)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-06 00:46:14 +00:00
Matthias Krüger d056cbf8d6
Rollup merge of #91563 - Aaron1011:bump-llvm-stamp, r=Mark-Simulacrum
Bump download-ci-llvm-stamp for LLD inclusion

This will make 'lld' available locally now, instead of
needing to wait for the next LLVM submodule bump.
2021-12-06 00:11:52 +01:00
Matthias Krüger d6ff1326e7
Rollup merge of #91554 - r00ster91:patch-3, r=GuillaumeGomez
Update doc about code block edition attributes
2021-12-06 00:11:51 +01:00
Matthias Krüger 971f469236
Rollup merge of #91537 - sunshowers:m68k-gnu, r=joshtriplett
compiler/rustc_target: make m68k-unknown-linux-gnu use the gnu base

This makes the m68k arch match the other GNU/Linux based targets by setting the environment to gnu.
2021-12-06 00:11:50 +01:00
Matthias Krüger 9c777fc6b0
Rollup merge of #91391 - GuillaumeGomez:simplify-no-headless, r=jsha
Simplify --no-headless option for rustdoc-gui tester

It adds a message stating the change for the concurrency and also remove the extra condition when running the tests.

r? `@camelid`
2021-12-06 00:11:48 +01:00
Matthias Krüger bd98a79eea
Rollup merge of #91367 - FabianWolff:issue-91334-ice, r=nagisa
Fix ICE in `check_must_not_suspend_ty()`

Fixes #91334. I have also used `TyS::tuple_fields()` (instead of the `SubstsRef` directly) to get the tuple fields, because that's what [the documentation](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/enum.TyKind.html#variant.Tuple) says, although it doesn't seem to make a difference in practice (this is not what fixed the ICE).
2021-12-06 00:11:47 +01:00
nixx quality 01e302b2f7
Fix dogfood 2021-12-05 23:04:56 +01:00
Fabian Wolff a8daff2724 Fix ICE in check_must_not_suspend_ty() 2021-12-05 22:24:34 +01:00
David Tolnay 596e33ac32
Delete duplicated helpers from HIR printer 2021-12-05 12:45:51 -08:00
Aaron Hill 8830cbcdc7
Bump download-ci-llvm-stamp for LLD inclusion
This will make 'lld' available locally now, instead of
needing to wait for the next LLVM submodule bump.
2021-12-05 14:25:48 -06:00
bors e2116acae5 Auto merge of #91356 - GuillaumeGomez:improve-rustdoc-layout, r=jsha
Improve rustdoc layout

This is an overtake of https://github.com/rust-lang/rust/pull/89385 originally written by `@cynecx.`

I kept the original commit and simply added the missing fixes into a new one. You can test it online [here](https://rustdoc.crud.net/imperio/improve-rustdoc-layout/std/index.html).

r? `@jsha`
2021-12-05 18:35:43 +00:00
bors 476d609c9d Auto merge of #8072 - xFrednet:0000-teach-rustbot-acronyms, r=llogiq
Enable rustbot shortcuts for rust-clippy

This enables shortcuts for ``@rustbot`.` Just a quality of life feature for contributors.

|Shortcut| Full comment |
|---|---|
| ``@rustbot` ready` | ``@rustbot` label -S-waiting-on-author +S-waiting-on-review` |
| ``@rustbot` author` | ``@rustbot` label +S-waiting-on-author -S-waiting-on-review` |

See: https://github.com/rust-lang/triagebot/wiki/Shortcuts

The documentation also states that the author/assignee will be pinged. However, this doesn't seem to be the case, it at least hasn't done so for me and in this [PR](https://github.com/rust-lang/rust/pull/90642#issuecomment-962465404)

---

changelog: none
2021-12-05 17:33:25 +00:00
nixx quality e3c60444ce
fix some false negatives for single_char_pattern 2021-12-05 17:33:52 +01:00
bors 772d51f887 Auto merge of #91555 - matthiaskrgr:rollup-pq0iaq7, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #90529 (Skip reborrows in AbstractConstBuilder)
 - #91437 (Pretty print empty blocks as {})
 - #91450 (Don't suggest types whose inner type is erroneous)
 - #91535 (Stabilize `-Z emit-future-incompat` as `--json future-incompat`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-05 15:33:44 +00:00
Matthias Krüger 068b30420a
Rollup merge of #91535 - Aaron1011:stabilize-future-incompat, r=nagisa
Stabilize `-Z emit-future-incompat` as `--json future-incompat`

The FCP was completed in https://github.com/rust-lang/rust/issues/71249
2021-12-05 15:04:22 +01:00
Matthias Krüger 609d9a0108
Rollup merge of #91450 - hkmatsumoto:hide-type-error, r=estebank
Don't suggest types whose inner type is erroneous

Currently, we check if the returned type equals to `tcx.ty_error()` not to emit
erroneous types, but this has a pitfall; for example,
`Option<[type error]> != tcx.ty_error()` holds.

Fixes #91371.
2021-12-05 15:04:21 +01:00
Matthias Krüger a8f8f746fc
Rollup merge of #91437 - dtolnay:emptybrace, r=nagisa
Pretty print empty blocks as {}

**Example:**

```rust
macro_rules! p {
    ($e:expr) => {
        println!("{}", stringify!($e));
    };
    ($i:item) => {
        println!("{}", stringify!($i));
    };
}

fn main() {
    p!(if true {});
    p!(struct S {});
}
```

**Before:**

```console
if true { }
struct S {
}
```

**After:**

```console
if true {}
struct S {}
```

This affects [`dbg!`](https://doc.rust-lang.org/std/macro.dbg.html), as well as ecosystem uses of stringify such as in [`anyhow::ensure!`](https://docs.rs/anyhow/1/anyhow/macro.ensure.html). Printing a `{ }` in today's heavily rustfmt'd world comes out looking jarring/sloppy.
2021-12-05 15:04:20 +01:00
Matthias Krüger 214b2a126b
Rollup merge of #90529 - b-naber:reborrows-consts, r=lcnr
Skip reborrows in AbstractConstBuilder

Fixes https://github.com/rust-lang/rust/issues/90455

Temporary fix to prevent confusing diagnostics that refer to implicit borrows and derefs until we allow borrows and derefs on constant expressions.

r? `@oli-obk`
2021-12-05 15:04:20 +01:00
r00ster 706faa10aa
Update doc about code block edition attributes 2021-12-05 14:43:43 +01:00
bors 1597728ef5 Auto merge of #88611 - m-ou-se:array-into-iter-new-deprecate, r=joshtriplett
Deprecate array::IntoIter::new.
2021-12-05 12:53:01 +00:00
b-naber 1777f431ad bless tests 2021-12-05 12:15:31 +01:00
b-naber 8ff50fe273 skip reborrows during AbstractConst building 2021-12-05 12:15:27 +01:00
b-naber 95209252f5 add test 2021-12-05 11:35:26 +01:00
bors cafc4582e6 Auto merge of #91510 - camelid:two-cleanups, r=GuillaumeGomez
rustdoc: Cleanup two things in `clean::types`

Explanations are in the individual commits.
2021-12-05 09:48:39 +00:00
bors 6c189bc9c2 Auto merge of #91229 - Aaron1011:dist-lld, r=Mark-Simulacrum
Include `lld` in `rust-dev` package

Fixes #88941

This will allow using `download-ci-llvm` while still having LLD
available.
2021-12-05 06:46:58 +00:00
bors bdaa901049 Auto merge of #91475 - ecstatic-morse:mir-pass-manager3, r=oli-obk
Add a MIR pass manager (Taylor's Version)

The final draft of #91386 and #77665.

While the compile-time constraints in #91386 are cool, I decided on a more minimal approach for now. I want to explore phase constraints and maybe relative-ordering constraints in the future, though. This should preserve existing behavior **exactly** (please let me know if it doesn't) while making the following changes to the way we organize things today:

- Each `MirPhase` now corresponds to a single MIR pass. `run_passes` is not responsible for listing the correct MIR phase.
- `run_passes` no longer silently skips passes if the declared MIR phase is greater than or equal to the body's. This has bitten me multiple times. If you want this behavior, you can always branch on `body.phase` yourself.
- If your pass is solely to emit errors, you can use the `MirLint` interface instead, which gets a shared reference to `Body` instead of a mutable one. By differentiating the two, I hope to make it clearer in the short term where lints belong in the pipeline. In the long term perhaps we could enforce this at compile-time?
- MIR is no longer dumped for passes that aren't enabled, or for lints.

I tried to check that `-Zvalidate` still works correctly, since the MIR phase is now updated as soon as the associated pass is done, instead of at the end of all the passes in `run_passes`. However, it looks like `-Zvalidate` is broken with current nightlies anyways 😢 (it spits out a bunch of errors).

cc `@oli-obk` `@wesleywiser`

r? rust-lang/wg-mir-opt
2021-12-05 03:41:18 +00:00
bors 5e93f6e318 Auto merge of #91539 - matthiaskrgr:rollup-rnl10yb, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #89642 (environ on macos uses directly libc which has the correct signature.)
 - #90022 (Explain why `Self` is invalid in generic parameters)
 - #90023 (Postpone the evaluation of constant expressions that depend on inference variables)
 - #91215 (Implement VecDeque::retain_mut)
 - #91355 (std: Stabilize the `thread_local_const_init` feature)
 - #91528 (LLVM support .insn directive)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-05 00:38:01 +00:00