Commit graph

10081 commits

Author SHA1 Message Date
Krasimir Georgiev
4ce56b414d RustWrapper: adapt for an LLVM API change
No functional changes intended.

The LLVM commit
ec501f15a8
removed the signed version of `createExpression`. This adapts the Rust
LLVM wrappers accordingly.
2022-01-03 11:25:33 +01:00
bors
b5da80871d Auto merge of #92395 - Kobzol:rustdoc-bindings-thin-vec, r=camelid
Rustdoc: use ThinVec for GenericArgs bindings

The bindings are almost always empty. This reduces the size of `PathSegment` and `GenericArgs` by about one fourth.
2022-01-03 03:49:01 +00:00
bors
8f3238f898 Auto merge of #90128 - joshtriplett:stabilize-symbol-mangling-version, r=wesleywiser
Stabilize -Z symbol-mangling-version=v0 as -C symbol-mangling-version=v0

This allows selecting `v0` symbol-mangling without an unstable option. Selecting `legacy` still requires -Z unstable-options.

This does not change the default symbol-mangling-version. See https://github.com/rust-lang/rust/pull/89917 for a pull request changing the default. Rationale, from #89917:

Rust's current mangling scheme depends on compiler internals; loses information about generic parameters (and other things) which makes for a worse experience when using external tools that need to interact with Rust symbol names; is inconsistent; and can contain . characters which aren't universally supported. Therefore, Rust has defined its own symbol mangling scheme which is defined in terms of the Rust language, not the compiler implementation; encodes information about generic parameters in a reversible way; has a consistent definition; and generates symbols that only use the characters A-Z, a-z, 0-9, and _.

Support for the new Rust symbol mangling scheme has been added to upstream tools that will need to interact with Rust symbols (e.g. debuggers).

This pull request allows enabling the new v0 symbol-mangling-version.

See #89917 for references to the implementation of v0, and for references to the tool changes to decode Rust symbols.
2022-01-02 15:49:23 +00:00
bors
03360be6b7 Auto merge of #92066 - Smittyvb:concat_bytes-repeat, r=nagisa
Support [x; n] expressions in concat_bytes!

Currently trying to use `concat_bytes!` with a repeating array value like `[42; 5]` results in an error:
```
error: expected a byte literal
 --> src/main.rs:3:27
  |
3 |     let x = concat_bytes!([3; 4]);
  |                           ^^^^^^
  |
  = note: only byte literals (like `b"foo"`, `b's'`, and `[3, 4, 5]`) can be passed to `concat_bytes!()`
```

This makes it so repeating array syntax can be used the same way normal arrays can be. The RFC doesn't explicitly mention repeat expressions, but it seems reasonable to allow them as well, since normal arrays are allowed.

It is possible to make the compiler get stuck compiling forever with `concat_bytes!([3; 999999999])`, but I don't think that's much of an issue since you can do that already with `const X: [u8; 999999999] = [3; 999999999];`.

Contributes to #87555.
2022-01-02 12:38:41 +00:00
bors
f7934f693b Auto merge of #92034 - petrochenkov:nolinknores, r=joshtriplett
Remove effect of `#[no_link]` attribute on name resolution

Previously it hid all non-macro names from other crates.
This has no relation to linking and can change name resolution behavior in some cases (e.g. glob conflicts), in addition to just producing the "unresolved name" errors.

I can kind of understand the possible reasoning behind the current behavior - if you can use names from a `no_link` crates then you can use, for example, functions too, but whether it will actually work or produce link-time errors will depend on random factors like inliner behavior.
(^^^ This is not the actual reason why the current behavior exist, I've looked through git history and it's mostly accidental.)

I think this risk is ok for such an obscure attribute, and we don't need to specifically prevent use of non-macro items from such crates.
(I'm not actually sure why would anyone use `#[no_link]` on a crate, even if it's macro only, if you aware of any use cases, please share. IIRC, at some point it was used for crates implementing custom derives - the now removed legacy ones, not the current proc macros.)

Extracted from https://github.com/rust-lang/rust/pull/91795.
2022-01-02 06:28:34 +00:00
Josh Triplett
ff94b3b12b Update references to -Z symbol-mangling-version to use -C
Replace `-Z symbol-mangling-version=v0` with `-C symbol-mangling-version=v0`.

Replace `-Z symbol-mangling-version=legacy` with
`-Z unstable-options -C symbol-mangling-version=legacy`.
2022-01-01 15:53:11 -08:00
Josh Triplett
bbf4b6699e Stabilize -Z symbol-mangling-version as -C symbol-mangling-version
This allows selecting `v0` symbol-mangling without an unstable option.
Selecting `legacy` still requires -Z unstable-options.

Continue supporting -Z symbol-mangling-version for compatibility for
now, but show a deprecation warning for it.
2022-01-01 15:51:02 -08:00
Matthias Krüger
2004a51fa4
Rollup merge of #92468 - NieDzejkob:silent-cfg, r=petrochenkov
Emit an error for `--cfg=)`

Fixes #73026

See also: #64467, #89468

The issue stems from a `FatalError` being silently raised in
`panictry_buffer`. Normally this is not a problem, because
`panictry_buffer` emits the causes of the error, but they are not
themselves fatal, so they get filtered out by the silent emitter.

To fix this, we use a parser entrypoint which doesn't use
`panictry_buffer`, and we handle the error ourselves.
2022-01-01 22:49:53 +01:00
bors
c145692254 Auto merge of #92455 - petrochenkov:alltraits2, r=cjgillot
rustc_metadata: Use a query for collecting all traits in encoder

Implement refactoring suggested in https://github.com/rust-lang/rust/pull/92244#discussion_r775976336
r? `@cjgillot`
2022-01-01 17:34:12 +00:00
bors
4f49627c6f Auto merge of #92419 - erikdesjardins:coldland, r=nagisa
Mark drop calls in landing pads `cold` instead of `noinline`

Now that deferred inlining has been disabled in LLVM (#92110), this shouldn't cause catastrophic size blowup.

I confirmed that the test cases from https://github.com/rust-lang/rust/issues/41696#issuecomment-298696944 still compile quickly (<1s) after this change. ~Although note that I wasn't able to reproduce the original issue using a recent rustc/llvm with deferred inlining enabled, so those tests may no longer be representative. I was also unable to create a modified test case that reproduced the original issue.~ (edit: I reproduced it on CI by accident--the first commit timed out on the LLVM 12 builder, because I forgot to make it conditional on LLVM version)

r? `@nagisa`
cc `@arielb1` (this effectively reverts #42771 "mark calls in the unwind path as !noinline")
cc `@RalfJung` (fixes #46515)

edit: also fixes #87055
2022-01-01 13:28:13 +00:00
Jakub Beránek
3d8d3f1435
Rustdoc: use ThinVec for GenericArgs bindings 2022-01-01 11:29:14 +01:00
Matthias Krüger
913bc8644a
Rollup merge of #92460 - dwrensha:fix-92267, r=petrochenkov
[rustc_builtin_macros] add indices to format_foreign::printf::Substitution::Escape

Fixes #92267.

The problem was that the escape string "%%" does not need to appear at the very beginning of the format string, but
the iterator implementation assumed that it did.

The solution follows the pattern used by `format_foregin:🐚:Subtitution::Escape`: 8ed935e92d/compiler/rustc_builtin_macros/src/format_foreign.rs (L629)
2022-01-01 10:48:57 +01:00
Matthias Krüger
a76128b365
Rollup merge of #92457 - bjorn3:sync_cg_gcc-2021-12-31, r=antoyo
Sync rustc_codegen_gcc

r? `@ghost`

cc `@antoyo`

`@rustbot` label +A-codegen +A-gcc +T-compiler
2022-01-01 10:48:57 +01:00
Matthias Krüger
efe415878b
Rollup merge of #92420 - dtolnay:patrange, r=Mark-Simulacrum
Fix whitespace in pretty printed PatKind::Range

Follow-up to #92238 fixing one of the FIXMEs.

```rust
macro_rules! repro {
    ($pat:pat) => {
        stringify!($pat)
    };
}

fn main() {
    println!("{}", repro!(0..=1));
}
```

Before:&ensp;`0 ..=1`
After:&ensp;`0..=1`

The canonical spacing applied by rustfmt has no space after the lower expr. Rustc's parser diagnostics also do not put a space there:

df96fb166f/compiler/rustc_parse/src/parser/pat.rs (L754)
2022-01-01 10:48:56 +01:00
Matthias Krüger
682b4cbc4e
Rollup merge of #92412 - dtolnay:tryspace, r=Mark-Simulacrum
Fix double space in pretty printed TryBlock

Follow-up to #92238 fixing one of the FIXMEs.

```rust
macro_rules! repro {
    ($expr:expr) => {
        stringify!($expr)
    };
}

fn main() {
    println!("{}", repro!(try {}));
}
```

Before:&ensp;<code>try&nbsp;&nbsp;{}</code>
After:&ensp;<code>try&nbsp;{}</code>

The `head` helper already appends a space:

2b67c30bfe/compiler/rustc_ast_pretty/src/pprust/state.rs (L654-L664)

so doing `head` followed by `space` resulted in a double space:

2b67c30bfe/compiler/rustc_ast_pretty/src/pprust/state.rs (L2241-L2242)
2022-01-01 10:48:55 +01:00
Vadim Petrochenkov
2dd50d5eb2 rustc_metadata: Use a query for collecting all traits in encoder 2022-01-01 13:06:50 +08:00
Jakub Kądziołka
193342eb8d
Emit an error for --cfg=)
Fixes #73026

See also: #64467, #89468

The issue stems from a `FatalError` being silently raised in
`panictry_buffer`. Normally this is not a problem, because
`panictry_buffer` emits the causes of the error, but they are not
themselves fatal, so they get filtered out by the silent emitter.

To fix this, we use a parser entrypoint which doesn't use
`panictry_buffer`, and we handle the error ourselves.
2022-01-01 05:21:36 +01:00
bors
c9cf9c6507 Auto merge of #92294 - Kobzol:rustdoc-meta-kind, r=GuillaumeGomez
Add Attribute::meta_kind

The `AttrItem::meta` function is being called on a lot of places, however almost always the caller is only interested in the `kind` of the result `MetaItem`. Before, the `path`  had to be cloned in order to get the kind, now it does not have to be.

There is a larger related "problem". In a lot of places, something wants to know contents of attributes. This is accessed through `Attribute::meta_item_list`, which calls `AttrItem::meta` (now `AttrItem::meta_kind`), among other methods. When this function is called, the meta item list has to be recreated from scratch. Everytime something asks a simple question (like is this item/list of attributes `#[doc(hidden)]`?), the tokens of the attribute(s) are cloned, parsed and the results are allocated on the heap. That seems really unnecessary. What would be the best way to cache this? Turn `meta_item_list` into a query perhaps? Related PR: https://github.com/rust-lang/rust/pull/92227

r? rust-lang/rustdoc
2022-01-01 02:03:23 +00:00
bors
4d2e0fd96c Auto merge of #92465 - matthiaskrgr:rollup-yuary84, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #90383 (Extend check for UnsafeCell in consts to cover unions)
 - #91375 (config.rs: Add support for a per-target default_linker option.)
 - #91480 (rustdoc: use smaller number of colors to distinguish items)
 - #92338 (Add try_reserve and  try_reserve_exact for OsString)
 - #92405 (Add a couple needs-asm-support headers to tests)
 - #92435 (Sync rustc_codegen_cranelift)
 - #92440 (Fix mobile toggles position)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-31 22:57:51 +00:00
Matthias Krüger
4e4d2585e5
Rollup merge of #92435 - bjorn3:sync_cg_clif-2021-12-30, r=bjorn3
Sync rustc_codegen_cranelift

The main highlight this sync is enforcing rustfmt and lack of warnings on cg_clif's CI. I will open a separate PR to remove the cg_clif exceptions for them from this repo.

r? `@ghost`

`@rustbot` label +A-codegen +A-cranelift +T-compiler
2021-12-31 23:14:48 +01:00
Matthias Krüger
ac1060e188
Rollup merge of #90383 - tmiasko:union-validity, r=RalfJung
Extend check for UnsafeCell in consts to cover unions

A validity companion to changes from #90373.

`@rust-lang/wg-const-eval`
2021-12-31 23:14:44 +01:00
bors
cfa3fe5af3 Auto merge of #90637 - Mark-Simulacrum:liveness-btree, r=lqd
Store liveness in interval sets for region inference

On the 100,000 line test case from https://github.com/rust-lang/rust/issues/90445, this reduces memory usage from 35 GB to 444 MB at peak (based on DHAT results, though with regular malloc), and yields a 9.4x speedup, with wall time going from 14.5 seconds to 1.5s. Performance results show that for the majority of real-world code this has little to no impact, but it's expected to generally scale better for auto-generated functions and other cases which stress this area of the compiler, as results on #90445 illustrate.

There may also be further room for improvement in future PRs making use of this data structures benefits over raw bitsets (which, at some level, are a less perfect fit for representing liveness, which is almost always composed of contiguous ranges, not point locations).

Fixes #90445.
2021-12-31 19:54:10 +00:00
David Renshaw
4a7f276cb6 update tests 2021-12-31 12:51:27 -05:00
David Renshaw
a661671ae3 [rustc_builtin_macros] add indices to format_foreign::printf::Substitution::Escape 2021-12-31 12:42:15 -05:00
bors
984a6bf9c1 Auto merge of #92175 - Aaron1011:fix-missing-source-file, r=cjgillot
Import `SourceFile`s from crate before decoding foreign `Span`

Fixes #92163
Fixes #92014

When writing to the incremental cache, we encode all `Span`s
we encounter, regardless of whether or not their `SourceFile`
comes from the local crate, or from a foreign crate.

When we decode a `Span`, we use the `StableSourceFileId` we encoded
to locate the matching `SourceFile` in the current session. If this
id corresponds to a `SourceFile` from another crate, then we need to
have already imported that `SourceFile` into our current session.

This usually happens automatically during resolution / macro expansion,
when we try to resolve definitions from other crates. In certain cases,
however, we may try to load a `Span` from a transitive dependency
without having ever imported the `SourceFile`s from that crate, leading
to an ICE.

This PR fixes the issue by enconding the `SourceFile`'s `CrateNum`
when we encode a `Span`. During decoding, we call `imported_source_files()`
when we encounter a foreign `CrateNum`, which ensure that all
`SourceFile`s from that crate are imported into the current session.
2021-12-31 16:38:23 +00:00
bjorn3
e7357e3340 Remove unused extern crate rustc_symbol_mangling 2021-12-31 16:57:33 +01:00
bjorn3
b799d6e0a5 Merge commit '1411a98352ba6bee8ba3b0131c9243e5db1e6a2e' into sync_cg_clif-2021-12-31 2021-12-31 16:26:32 +01:00
Tomasz Miąsko
2eb637a9f2 Extend check for UnsafeCell in consts to cover unions
A validity companion to changes from #90373.
2021-12-31 08:53:12 +01:00
bors
e670844012 Auto merge of #91929 - anuvratsingh:remove_in_band_lifetimes_compiler_rustc_traits, r=jackh726
Removed `in_band_lifetimes` from `rustc_traits`

Issue: [#91867](https://github.com/rust-lang/rust/issues/91867)
2021-12-31 05:08:24 +00:00
Mark Rousskov
4abb3283f3 Use SparseIntervalMatrix instead of SparseBitMatrix
Region inference contains several bitsets which are filled with large intervals
representing liveness. These can cause excessive memory usage, and are
relatively slow when growing to large sizes compared to the IntervalSet.
2021-12-30 22:33:52 -05:00
Mark Rousskov
00c55a1bb8 Introduce IntervalSet
This is a compact, fast storage for variable-sized sets, typically consisting of
larger ranges. It is less efficient than a bitset if ranges are both small and
the domain size is small, but will still perform acceptably. With enormous
domain sizes and large ranges, the interval set performs much better, as it can
be much more densely packed in memory than the uncompressed bit set alternative.
2021-12-30 22:33:44 -05:00
Anuvrat
58a888fcc1
Removed in_band_lifetimes from rustc_traits 2021-12-30 13:59:19 -05:00
bors
b60e32c828 Auto merge of #92434 - matthiaskrgr:rollup-m8wuq0v, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #91519 (ast: Avoid aborts on fatal errors thrown from mutable AST visitor)
 - #92414 (Fix spacing of pretty printed const item without body)
 - #92423 (Add UI test for #92292)
 - #92427 (Use `UnsafeCell::get_mut()` in `core::lazy::OnceCell::get_mut()`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-30 14:52:50 +00:00
bjorn3
a8e6d5b04d Merge commit '40b00f4200fbdeefd11815398cb46394b8cb0a5e' into sync_cg_clif-2021-12-30 2021-12-30 14:53:41 +01:00
Matthias Krüger
e810487b4d
Rollup merge of #92414 - dtolnay:constnoexpr, r=oli-obk
Fix spacing of pretty printed const item without body

Follow-up to #92238 fixing one of the FIXMEs.

```rust
macro_rules! repro {
    ($item:item) => {
        stringify!($item)
    };
}

fn main() {
    println!("{}", repro!(extern "C" { static S: i32; }));
}
```

Before:&ensp;`extern "C" { static S: i32 ; }`
After:&ensp;`extern "C" { static S: i32; }`
2021-12-30 13:12:34 +01:00
Matthias Krüger
b9f7197ab3
Rollup merge of #91519 - petrochenkov:cratexp2, r=Aaron1011
ast: Avoid aborts on fatal errors thrown from mutable AST visitor

Set the node to some dummy value and rethrow the error instead.

When using the old aborting `visit_clobber` in `InvocationCollector::visit_crate` the next tests abort due to fatal errors:
```
ui\modules\path-invalid-form.rs
ui\modules\path-macro.rs
ui\modules\path-no-file-name.rs
ui\parser\issues\issue-5806.rs
ui\parser\mod_file_with_path_attr.rs
```

Follow up to https://github.com/rust-lang/rust/pull/91313.
2021-12-30 13:12:33 +01:00
bors
f8d4ee7c7a Auto merge of #89336 - Aaron1011:variance-struct-diag, r=cjgillot
Refactor variance diagnostics to work with more types

Instead of special-casing mutable pointers/references, we
now support general generic types (currently, we handle
`ty::Ref`, `ty::RawPtr`, and `ty::Adt`)

When a `ty::Adt` is involved, we show an additional note
explaining which of the type's generic parameters is
invariant (e.g. the `T` in `Cell<T>`). Currently, we don't
explain *why* a particular generic parameter ends up becoming
invariant. In the general case, this could require printing
a long 'backtrace' of types, so doing this would be
more suitable for a follow-up PR.

We still only handle the case where our variance switches
to `ty::Invariant`.
2021-12-30 11:34:24 +00:00
Erik Desjardins
e4463b2453 keep noinline for system llvm < 14 2021-12-30 00:15:51 -05:00
bors
1b3a5f29dd Auto merge of #91125 - eskarn:llvm-passes-plugin-support, r=nagisa
Allow loading LLVM plugins with both legacy and new pass manager

Opening a draft PR to get feedback and start discussion on this feature. There is already a codegen option `passes` which allow giving a list of LLVM pass names, however we currently can't use a LLVM pass plugin (as described here : https://llvm.org/docs/WritingAnLLVMPass.html), the only available passes are the LLVM built-in ones.

The proposed modification would be to add another codegen option `pass-plugins`, which can be set with a list of paths to shared library files. These libraries are loaded using the LLVM function `PassPlugin::Load`, which calls the expected symbol `lvmGetPassPluginInfo`, and register the pipeline parsing and optimization callbacks.

An example usage with a single plugin and 3 passes would look like this in the `.cargo/config`:

```toml
rustflags = [
    "-C", "pass-plugins=/tmp/libLLVMPassPlugin",
    "-C", "passes=pass1 pass2 pass3",
]
```
This would give the same functionality as the opt LLVM tool directly integrated in rust build system.

Additionally, we can also not specify the `passes` option, and use a plugin which inserts passes in the optimization pipeline, as one could do using clang.
2021-12-30 02:53:09 +00:00
Aaron Hill
b15cb29a4a
Refactor variance diagnostics to work with more types
Instead of special-casing mutable pointers/references, we
now support general generic types (currently, we handle
`ty::Ref`, `ty::RawPtr`, and `ty::Adt`)

When a `ty::Adt` is involved, we show an additional note
explaining which of the type's generic parameters is
invariant (e.g. the `T` in `Cell<T>`). Currently, we don't
explain *why* a particular generic parameter ends up becoming
invariant. In the general case, this could require printing
a long 'backtrace' of types, so doing this would be
more suitable for a follow-up PR.

We still only handle the case where our variance switches
to `ty::Invariant`.
2021-12-29 18:53:40 -05:00
bors
d331cb710f Auto merge of #88354 - Jmc18134:hint-space-pauth-opt, r=nagisa
Add codegen option for branch protection and pointer authentication on AArch64

The branch-protection codegen option enables the use of hint-space pointer
authentication code for AArch64 targets.
2021-12-29 22:35:11 +00:00
David Tolnay
bc1a1ff3c8
Fix whitespace in pretty printed PatKind::Range 2021-12-29 13:02:14 -08:00
Erik Desjardins
2b662217e7 Mark drop calls in landing pads cold instead of noinline
Now that deferred inlining has been disabled in LLVM,
this shouldn't cause catastrophic size blowup.
2021-12-29 15:47:49 -05:00
David Tolnay
b62163515a
Move equal sign back into head ibox 2021-12-29 12:26:50 -08:00
David Tolnay
b7df49895c
Fix spacing of pretty printed const item without body 2021-12-29 12:26:50 -08:00
bors
78fd0f633f Auto merge of #92244 - petrochenkov:alltraits, r=cjgillot
rustc_metadata: Encode list of all crate's traits into metadata

While working on https://github.com/rust-lang/rust/pull/88679 I noticed that rustdoc is casually doing something quite expensive, something that is used only for error reporting in rustc - collecting all traits from all crates in the dependency tree.

This PR trades some minor extra time spent by metadata encoder in rustc for major gains for rustdoc (and for rustc runs with errors, which execute the `all_traits` query for better diagnostics).
2021-12-29 19:22:33 +00:00
David Tolnay
2f25a4ab30
Fix double space in pretty printed TryBlock 2021-12-29 11:13:33 -08:00
bors
2b67c30bfe Auto merge of #92397 - matthiaskrgr:rollup-xnfou17, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #92075 (rustdoc: Only special case struct fields for intra-doc links, not enum variants)
 - #92118 (Parse and suggest moving where clauses after equals for type aliases)
 - #92237 (Visit expressions in-order when resolving pattern bindings)
 - #92340 (rustdoc: Start cleaning up search index generation)
 - #92351 (Add long error explanation for E0227)
 - #92371 (Remove pretty printer space inside block with only outer attrs)
 - #92372 (Print space after formal generic params in fn type)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-29 12:07:33 +00:00
Matthias Krüger
949769cf3b
Rollup merge of #92372 - dtolnay:fntype, r=jackh726
Print space after formal generic params in fn type

Follow-up to #92238 fixing one of the FIXMEs.

```rust
macro_rules! repro {
    ($ty:ty) => {
        stringify!($ty)
    };
}

fn main() {
    println!("{}", repro!(for<'a> fn(&'a u8)));
}
```

Before:&ensp;`for<'a>fn(&'a u8)`
After:&ensp;`for<'a> fn(&'a u8)`

The pretty printer's `print_formal_generic_params` already prints formal generic params correctly with a space, we just need to call it when printing BareFn types instead of reimplementing the printing incorrectly without a space.

83b15bfe1c/compiler/rustc_ast_pretty/src/pprust/state.rs (L1394-L1400)
2021-12-29 10:17:13 +01:00
Matthias Krüger
5583010347
Rollup merge of #92371 - dtolnay:attrblock, r=oli-obk
Remove pretty printer space inside block with only outer attrs

Follow-up to #92238 fixing one of the FIXMEs.

```rust
macro_rules! repro {
    ($expr:expr) => {
        stringify!($expr)
    };
}

fn main() {
    println!("{}", repro!(#[attr] {}));
}
```

Before:&ensp;`#[attr] { }`
After:&ensp;`#[attr] {}`
2021-12-29 10:17:12 +01:00