Commit graph

9657 commits

Author SHA1 Message Date
Esteban Kuber 10a74ac2e0 Use a more accurate Span for 'static obligation from return type 2021-12-10 03:08:24 +00:00
Esteban Kuber ee0fd105d8 Point at return type when it introduces 'static obligation 2021-12-10 03:08:23 +00:00
Esteban Kuber 09dbf37213 Add filtering based on involved required lifetime
More accurate filtering still needed.
2021-12-10 03:08:23 +00:00
Esteban Kuber ab45ab83ac review comments
* take diagnostic logic out of happy-path
* sort/dedup once
* add more comments
2021-12-10 03:08:22 +00:00
Esteban Kuber dd81e98466 Clean up visual output logic 2021-12-10 03:08:22 +00:00
Esteban Kuber d10fe26f39 Point at capture points for non-'static reference crossing a yield point
```
error[E0759]: `self` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
  --> $DIR/issue-72312.rs:10:24
   |
LL |     pub async fn start(&self) {
   |                        ^^^^^ this data with an anonymous lifetime `'_`...
...
LL |         require_static(async move {
   |         -------------- ...is required to live as long as `'static` here...
LL |             &self;
   |             ----- ...and is captured here
   |
note: `'static` lifetime requirement introduced by this trait bound
  --> $DIR/issue-72312.rs:2:22
   |
LL | fn require_static<T: 'static>(val: T) -> T {
   |                      ^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0759`.
```

Fix #72312.
2021-12-10 03:08:22 +00:00
bors e6b883c74f Auto merge of #91665 - matthiaskrgr:rollup-o3wnkam, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #90709 (Only shown relevant type params in E0283 label)
 - #91551 (Allow for failure of subst_normalize_erasing_regions in const_eval)
 - #91570 (Evaluate inline const pat early and report error if too generic)
 - #91571 (Remove unneeded access to pretty printer's `s` field in favor of deref)
 - #91610 (Link to rustdoc_json_types docs instead of rustdoc-json RFC)
 - #91619 (Update cargo)
 - #91630 (Add missing whitespace before disabled HTML attribute)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-08 18:45:03 +00:00
Matthias Krüger 1be98af02f
Rollup merge of #91571 - dtolnay:printerderef, r=Mark-Simulacrum
Remove unneeded access to pretty printer's `s` field in favor of deref

I found it taxing in some of my recent PRs touching the pretty printer to maintain consistency with the surrounding code, since the current code is all over the place about whether it uses `self.s.…()` or `self.…()` for invoking methods of `rustc_ast_pretty::pp::Printer`.

This PR standardizes on `self.…()` &mdash; relying on the `Deref` and `DerefMut` impls introduced by [#62532](cab453250a).
2021-12-08 16:08:09 +01:00
Matthias Krüger 67c58327fc
Rollup merge of #91570 - nbdd0121:const_typeck, r=oli-obk
Evaluate inline const pat early and report error if too generic

Fix #90150

````@rustbot```` label: T-compiler F-inline_const
2021-12-08 16:08:08 +01:00
Matthias Krüger 317f750ff7
Rollup merge of #91551 - b-naber:const-eval-normalization-ice, r=oli-obk
Allow for failure of subst_normalize_erasing_regions in const_eval

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

Using associated types that cannot be normalized previously resulted in an ICE. We now allow for normalization failure and return a "TooGeneric" error in that case.

r? ```@RalfJung``` maybe?
2021-12-08 16:08:07 +01:00
Matthias Krüger 7970fab252
Rollup merge of #90709 - estebank:erase-known-type-params, r=nagisa
Only shown relevant type params in E0283 label

When we point at a binding to suggest giving it a type, erase all the
type for ADTs that have been resolved, leaving only the ones that could
not be inferred. For small shallow types this is not a problem, but for
big nested types with lots of params, this can otherwise cause a lot of
unnecessary visual output.
2021-12-08 16:08:06 +01:00
bors f9e77f2b46 Auto merge of #91604 - nikic:section-flags, r=nagisa
Use object crate for .rustc metadata generation

We already use the object crate for generating uncompressed .rmeta
metadata object files. This switches the generation of compressed
.rustc object files to use the object crate as well. These have
slightly different requirements in that .rmeta should be completely
excluded from any final compilation artifacts, while .rustc should
be part of shared objects, but not loaded into memory.

The primary motivation for this change is #90326: In LLVM 14, the
current way of setting section flags (and in particular, preventing
the setting of SHF_ALLOC) will no longer work. There are other ways
we could work around this, but switching to the object crate seems
like the most elegant, as we already use it for .rmeta, and as it
makes this independent of the codegen backend. In particular, we
don't need separate handling in codegen_llvm and codegen_gcc.
codegen_cranelift should be able to reuse the implementation as
well, though I have omitted that here, as it is not based on
codegen_ssa.

This change mostly extracts the existing code for .rmeta handling
to allow using it for .rustc as well, and adjusts the codegen
infrastructure to handle the metadata object file separately: We
no longer create a backend-specific module for it, and directly
produce the compiled module instead.

This does not `fix` #90326 by itself yet, as .llvmbc will need to be
handled separately.

r? `@nagisa`
2021-12-08 14:58:48 +00:00
Matthias Krüger 90690dae69
Rollup merge of #91638 - scottmcm:less-inband-2-of-28, r=petrochenkov
Remove `in_band_lifetimes` from `rustc_mir_transform`

Like #91580, this was inspired by the conversation in #44524 about possibly removing the feature from the compiler.  This crate is a heavy `'tcx` user, so is a nice case study.

r? ``@petrochenkov``

Three interesting ones:

This one had the `'tcx` declared on the function, despite the trait taking a `'tcx`:
```diff
-impl Visitor<'_> for UsedLocals {
+impl<'tcx> Visitor<'tcx> for UsedLocals {
     fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
```

This one use in-band for one, and underscore for the other:
```diff
-pub fn remove_dead_blocks(tcx: TyCtxt<'tcx>, body: &mut Body<'_>) {
+pub fn remove_dead_blocks<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
```

A spurious name, since there's no single-use-lifetime warning:
```diff
-pub fn run_passes(tcx: TyCtxt<'tcx>, body: &'mir mut Body<'tcx>, passes: &[&dyn MirPass<'tcx>]) {
+pub fn run_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>, passes: &[&dyn MirPass<'tcx>]) {
```
2021-12-08 11:09:01 +01:00
Matthias Krüger 4a76541cba
Rollup merge of #91577 - ecstatic-morse:mir-pass-manager-cleanup, r=oli-obk
Address some FIXMEs left over from #91475

This shouldn't change behavior, only clarify what we're currently doing. I filed #91576 to see if the treatment of generator drop shims is intentional.

cc #91475
2021-12-08 11:09:00 +01:00
Matthias Krüger 87f2c51dcd
Rollup merge of #91531 - notriddle:notriddle/issue-87647-expected-semicolon, r=estebank
Do not add `;` to expected tokens list when it's wrong

There's a few spots where semicolons are checked for to do error recovery, and should not be suggested (or checked for other stuff).

Fixes #87647
2021-12-08 11:08:59 +01:00
Matthias Krüger 871cf2bc9e
Rollup merge of #91272 - FabianWolff:issue-90870-const-fn-eq, r=wesleywiser
Print a suggestion when comparing references to primitive types in `const fn`

Fixes #90870.
2021-12-08 11:08:57 +01:00
Matthias Krüger da158c04c4
Rollup merge of #83744 - bjorn3:deprecate_cfg_attr_crate_type_name, r=Mark-Simulacrum
Deprecate crate_type and crate_name nested inside #![cfg_attr]

This implements the proposal in https://github.com/rust-lang/rust/pull/83676#issuecomment-811213956, with a future compatibility lint imposed on usage of crate_type/crate_name inside cfg's.

This is a compromise between removing `#![crate_type]` and `#![crate_name]` completely and keeping them as a whole, which requires somewhat of a hack in rustc and is impossible to support by gcc-rust. By only removing `#![crate_type]` and `#![crate_name]` nested inside `#![cfg_attr]` it becomes possible to parse them before a big chunk of the compiler has started.

Replaces https://github.com/rust-lang/rust/pull/83676

```rust
#![crate_type = "lib"] // remains working
#![cfg_attr(foo, crate_type = "bin")] // will stop working
```

# Rationale

As it currently is it is possible to try to access the stable crate id before it is actually set, which will panic. The fact that the Session contains mutable state beyond debugging things also doesn't completely sit well with me. Especially once parallel rustc becomes the default.

I think there is currently also a cyclic dependency where you need to set the stable crate id to be able to load crates, but you need to load crates to expand proc macro attributes that may define #![crate_name] or #![crate_type]. Currently crate level proc macro attributes are unstable or completely unsupported (can't remember which), so this is not a problem, but it may become an issue in the future.

Finally if we want to add incremental compilation to macro expansion or even parsing, we need the StableCrateId to be created together with the Session or even earlier as incremental compilation determines the incremental compilation session dir based on the StableCrateId.
2021-12-08 11:08:55 +01:00
Scott McMurray a124924061 Remove in_band_lifetimes from rustc_mir_transform
This one is a heavy `'tcx` user.

Two interesting ones:

This one had the `'tcx` declared on the function, despite the trait taking a `'tcx`:
```diff
-impl Visitor<'_> for UsedLocals {
+impl<'tcx> Visitor<'tcx> for UsedLocals {
     fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
```

This one use in-band for one, and underscore for the other:
```diff
-pub fn remove_dead_blocks(tcx: TyCtxt<'tcx>, body: &mut Body<'_>) {
+pub fn remove_dead_blocks<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
```
2021-12-07 21:04:40 -08:00
bors 477fd7038c Auto merge of #91407 - the8472:deserialize-unchecked-utf8, r=michaelwoerister
Avoid string validation in rustc_serialize, check a marker byte instead

Since the serialization format isn't self-describing we need a way to detect when encoder and decoder don't match up. But for strings it doesn't have to be utf8 validation, which currently does cost a few percent of performance.
Instead we can use a marker byte at the end to be reasonably sure that we're dealing with a string and it wasn't overwritten in some way.
2021-12-07 21:50:46 +00:00
David Tolnay a79b702956
Remove unneeded access to pretty printer's s field in favor of deref 2021-12-07 09:14:46 -08:00
bjorn3 9b6c510905 Future compatibility warning on cfg_attr on crate_type and crate_name 2021-12-07 11:47:21 -05:00
bors 0b6f079e49 Auto merge of #91224 - couchand:2021-11/avr-asm, r=Amanieu
Support AVR for inline asm!

A first pass at support for the AVR platform in inline `asm!`.  Passes the initial compiler tests, have not yet done more complete verification.

In particular, the register classes could use a lot more fleshing out, this draft PR so far only includes the most basic.

cc `@Amanieu` `@dylanmckay`
2021-12-07 14:23:01 +00:00
bors c5c9494509 Auto merge of #91627 - matthiaskrgr:rollup-z3e2peg, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #87614 (Recommend fix `count()` -> `len()` on slices)
 - #91065 (Add test for evaluate_obligation: Ok(EvaluatedToOkModuloRegions) ICE)
 - #91312 (Fix AnonConst ICE)
 - #91341 (Add `array::IntoIter::{empty, from_raw_parts}`)
 - #91493 (Remove a dead code path.)
 - #91503 (Tweak "call this function" suggestion to have smaller span)
 - #91547 (Suggest try_reserve in try_reserve_exact)
 - #91562 (Pretty print async block without redundant space)
 - #91620 (Update books)
 - #91622 (⬆️ rust-analyzer)

Failed merges:

 - #91571 (Remove unneeded access to pretty printer's `s` field in favor of deref)

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-07 11:18:26 +00:00
Matthias Krüger b2dcfddb24
Rollup merge of #91562 - dtolnay:asyncspace, r=Mark-Simulacrum
Pretty print async block without redundant space

**Repro:**

```rust
macro_rules! m {
    ($e:expr) => { stringify!($e) };
}
fn main() {
    println!("{:?}", m!(async {}));
}
```

**Before:** <code>"async&nbsp;&nbsp;{}"</code>
**After:** `"async {}"`

<br>

In this function:

65c55bf931/compiler/rustc_ast_pretty/src/pprust/state.rs (L2049-L2051)

the `print_capture_clause` and `word_nbsp`/`word_space` calls already put a space after the `async` and `move` keywords being printed. The extra `self.s.space()` call removed by this PR resulted in the redundant double space.

65c55bf931/compiler/rustc_ast_pretty/src/pprust/state.rs (L2640-L2645)

65c55bf931/compiler/rustc_ast_pretty/src/helpers.rs (L34-L37)

65c55bf931/compiler/rustc_ast_pretty/src/helpers.rs (L5-L8)
2021-12-07 11:05:06 +01:00
Matthias Krüger a8f47dc7aa
Rollup merge of #91503 - estebank:call-fn-span, r=michaelwoerister
Tweak "call this function" suggestion to have smaller span
2021-12-07 11:05:03 +01:00
Matthias Krüger dd929ae4c5
Rollup merge of #91493 - oli-obk:cleanup, r=michaelwoerister
Remove a dead code path.

It is neither documented nor can I see any way it could ever be reached.

Also, no tests fail when turning that arm into an ICE
2021-12-07 11:05:00 +01:00
Matthias Krüger 57ae43d1f2
Rollup merge of #91312 - terrarier2111:anon-const-ice, r=jackh726
Fix AnonConst ICE

I am not sure if this is even the correct place to fix this issue, but i went down the path where the generic args came from and i wasn't able to find a clear cause for this down there. But if anybody has a suggestion what i should do, just tell me.
This fixes: https://github.com/rust-lang/rust/issues/91267
2021-12-07 11:04:58 +01:00
Matthias Krüger f84a734a8e
Rollup merge of #87614 - notriddle:notriddle-count2len, r=Mark-Simulacrum
Recommend fix `count()` -> `len()` on slices

Fixes #87302
2021-12-07 11:04:56 +01:00
Nikita Popov 9488cacc52 Use object crate for .rustc metadata generation
We already use the object crate for generating uncompressed .rmeta
metadata object files. This switches the generation of compressed
.rustc object files to use the object crate as well. These have
slightly different requirements in that .rmeta should be completely
excluded from any final compilation artifacts, while .rustc should
be part of shared objects, but not loaded into memory.

The primary motivation for this change is #90326: In LLVM 14, the
current way of setting section flags (and in particular, preventing
the setting of SHF_ALLOC) will no longer work. There are other ways
we could work around this, but switching to the object crate seems
like the most elegant, as we already use it for .rmeta, and as it
makes this independent of the codegen backend. In particular, we
don't need separate handling in codegen_llvm and codegen_gcc.
codegen_cranelift should be able to reuse the implementation as
well, though I have omitted that here, as it is not based on
codegen_ssa.

This change mostly extracts the existing code for .rmeta handling
to allow using it for .rustc as well, and adjust the codegen
infrastructure to handle the metadata object file separately: We
no longer create a backend-specific module for it, and directly
produce the compiled module instead.

This does not fix #90326 by itself yet, as .llvmbc will need to be
handled separately.
2021-12-07 09:39:05 +01:00
Michael Howell 6a17ee6d41 Recommend fix count() -> len() on slices
Fixes #87302
2021-12-06 20:33:23 -07:00
Esteban Kuber 7271d1f803 Add test with multiple type params failing inference 2021-12-07 02:06:58 +00:00
Esteban Kuber 6a691b1d92 Refer to const params as "const params" and not "type params" 2021-12-07 02:06:58 +00:00
Esteban Kuber 3fd15c8404 Refer to uninferred const params by their name, instead of { _: _ }
When the value of a const param isn't inferred, replace it with the
param name from the definition.
2021-12-07 02:06:56 +00:00
Esteban Kuber 78e88f46d6 Only shown relevant type params in E0283 label
When we point at a binding to suggest giving it a type, erase all the
type for ADTs that have been resolved, leaving only the ones that could
not be inferred. For small shallow types this is not a problem, but for
big nested types with lots of params, this can otherwise cause a lot of
unnecessary visual output.
2021-12-07 02:05:34 +00:00
Mark Rousskov 15483ccf9d Annotate comments onto the LT algorithm 2021-12-06 20:30:15 -05: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
Michael Howell 6611567f9e Expect extern fn with no body when parsing
Also add a test case for inserting a semicolon on extern fns.

Without this fix, we got an error like this:

    error: expected one of `->`, `where`, or `{`, found `}`
     --> chk.rs:3:1
      |
    2 |   fn foo()
      |      ---  - expected one of `->`, `where`, or `{`
      |      |
      |      while parsing this `fn`
    3 | }
      | ^ unexpected token

Since this is inside an extern block, you're required to write function
prototypes with no body. This fixes a regression, and adds a test case
for it.
2021-12-06 11:16:46 -07:00
Michael Howell 61995926d2 Add better comments for FnParseMode 2021-12-06 11:16:02 -07:00
The 8472 c640f31c9f avoid string validation in rustc_serialize, check a marker byte instead
since the serialization format isn't self-describing we need a way to detect
when encoder and decoder don't match up. but that doesn't have to
be utf8 validation for strings, which does cost a few % of performance.
Instead we can use a marker byte at the end to be reasonably
sure that we're dealing with a string and it wasn't overwritten in some
way.
2021-12-06 18:43:01 +01:00
threadexception a0fb992433 Fix AnonConst ICE
Add test

Apply suggestions

Switch to match

Apply cargofmt
2021-12-06 17:59:37 +01: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