Commit Graph

1189 Commits

Author SHA1 Message Date
John Kåre Alsaker
1806efe7f2 Move DepKind to rustc_query_system and define it as u16 2023-09-21 17:06:14 +02:00
bors
3223b0b5e8 Auto merge of #115542 - saethlin:fileencoder-is-bufwriter, r=WaffleLapkin
Simplify/Optimize FileEncoder

FileEncoder is basically a BufWriter except that it exposes access to the not-written-to-yet region of the buffer so that some users can write directly to the buffer. This strategy is awesome because it lets us avoid calling memcpy for small copies, but the previous strategy was based on the writer accessing a `&mut [MaybeUninit<u8>; N]` and returning a `&[u8]` which is an API which currently mandates the use of unsafe code, making that interface in general not that appealing.

So this PR cleans up the FileEncoder implementation and builds on that general idea of direct buffer access in order to prevent `memcpy` calls in a few key places when encoding the dep graph and rmeta tables. The interface used here is now 100% safe, but with the caveat that internally we need to avoid trusting the number of bytes that the provided function claims to have written.

The original primary objective of this PR was to clean up the FileEncoder implementation so that the fix for the following issues would be easy to implement. The fix for these issues is to correctly update self.buffered even when writes fail, which I think it's easy to verify manually is now done, because all the FileEncoder methods are small.

Fixes https://github.com/rust-lang/rust/issues/115298
Fixes https://github.com/rust-lang/rust/issues/114671
Fixes https://github.com/rust-lang/rust/issues/114045
Fixes https://github.com/rust-lang/rust/issues/108100
Fixes https://github.com/rust-lang/rust/issues/106787
2023-09-20 21:47:54 +00:00
bors
8ed1d4a02d Auto merge of #114750 - Enselic:metadata-dep-info, r=compiler-errors
Make `.rmeta` file in `dep-info` have correct name (`lib` prefix)

Since `filename_for_metadata()` and
`OutputFilenames::path(OutputType::Metadata)` had different logic for the name of the metadata file, the `.d` file contained a file name different from the actual name used. Share the logic to fix the out-of-sync name.

Without this fix, the `.d` file contained

    dash-separated_something-extra.rmeta: dash-separated.rs

instead of

    libdash_separated_something-extra.rmeta: dash-separated.rs

which is the name of the file that is actually written by the compiler.

Worth noting: It took me several iterations to get all tests to pass, so I am relatively confident that this PR does not break anything.

Closes #68839
2023-09-17 11:45:53 +00:00
bors
7e0261e7ea Auto merge of #115735 - bjorn3:better_list_crate_metadata, r=wesleywiser
Extend rustc -Zls

This makes it show a lot more things and thus a lot more useful.
2023-09-13 10:23:57 +00:00
bjorn3
026faca4ca Fix two typos 2023-09-12 14:42:53 +00:00
yukang
f9a9ff20a2 cleanup on messages 2023-09-12 07:27:17 +08:00
Ben Kimock
01e9798148 Reimplement FileEncoder with a small-write optimization 2023-09-10 23:37:51 -04:00
bors
7418413a7f Auto merge of #115306 - tmiasko:encode-reachable-mir, r=cjgillot
Encode only MIR reachable from other crates

Only reachable items might participate in the code generation in the
downstream crates. Omit redundant optimized MIR of unreachable items
from a crate metadata.

Additionally, include reachable closures in reachable set, so that
unreachable closures can be omitted on the same basis.
2023-09-10 16:31:11 +00:00
bjorn3
7b30550cfe Support listing all items in -Zls 2023-09-10 14:32:58 +00:00
bjorn3
ff00763dd1 Show lib features in -Zls and allow configuring which things are shown 2023-09-10 13:24:20 +00:00
bjorn3
369a8ac52b List all defined and required lang items in -Zls 2023-09-10 13:01:37 +00:00
bjorn3
7279cc0abd List more crate metadata in -Zls 2023-09-10 12:42:48 +00:00
Tomasz Miąsko
d99333e444 Encode only MIR that can be used by other crates
Only reachable items might participate in the code generation in the
downstream crates. Omit redundant optimized MIR of unreachable items
from a crate metadata.

Additionally, include reachable closures in reachable set, so that
unreachable closures can be omitted on the same basis.
2023-09-10 13:55:33 +02:00
John Kåre Alsaker
1d8fdc0332 Use FreezeLock for CStore 2023-09-09 16:02:11 +02:00
John Kåre Alsaker
c5996b80be Use Freeze for SourceFile.external_src 2023-09-07 13:04:23 +02:00
Camille GILLOT
548ba13265 Register the file while computing its start position. 2023-09-03 15:02:46 +00:00
Camille GILLOT
258ace613d Use relative positions inside a SourceFile. 2023-09-03 12:56:10 +00:00
Martin Nordholts
04d81ba153 Make .rmeta file in dep-info have correct name (lib prefix)
Since `filename_for_metadata()` and
`OutputFilenames::path(OutputType::Metadata)` had different logic for
the name of the metadata file, the `.d` file contained a file name
different from the actual name used. Share the logic to fix the
out-of-sync name.

Closes 68839.
2023-09-03 07:14:12 +02:00
bors
1fb6947abc Auto merge of #115286 - saethlin:detangler, r=petrochenkov
Skip rendering metadata strings from include_str!/include_bytes!

The const rendering code in rustdoc completely ignores consts from expansions, but the compiler was rendering all consts. So some consts (namely those from `include_bytes!`) were rendered then ignored.

Most of the diff here is from moving `print_const_expr` from rustdoc into `rustc_hir_pretty` so that it can be used in rustdoc and when building rmeta files.
2023-09-02 04:53:19 +00:00
Ben Kimock
159ad5fb0d Reuse const rendering from rustdoc in rmeta encoding 2023-09-01 17:22:48 -04:00
John Kåre Alsaker
90f5f94699 Use OnceLock for SingleCache 2023-09-01 03:11:51 +02:00
bors
d64c84562f Auto merge of #113542 - saethlin:adaptive-tables, r=b-naber
Adapt table sizes to the contents

This is an implementation of https://github.com/rust-lang/compiler-team/issues/666

The objective of this PR is to permit the rmeta format to accommodate larger crates that need offsets larger than a `u32` can store without compromising performance for crates that do not need such range. The second commit is a number of tiny optimization opportunities I noticed while looking at perf recordings of the first commit.

The rmeta tables need to have fixed-size elements to permit lazy random access. But the size only needs to be fixed _per table_, not per element type. This PR adds another `usize` to the table header which indicates the table element size. As each element of a table is set, we keep track of the widest encoded table value, then don't bother encoding all the unused trailing bytes on each value. When decoding table elements, we copy them to a full-width array if they are not already full-width.

`LazyArray` needs some special treatment. Most other values that are encoded in tables are indexes or offsets, and those tend to be small so we get to drop a lot of zero bytes off the end. But `LazyArray` encodes _two_ small values in a fixed-width table element: A position of the table and the length of the table. The treatment described above could trim zero bytes off the table length, but any nonzero length shields the position bytes from the optimization. To improve this, we interleave the bytes of position and length. This change is responsible for about half of the crate metadata win on many crates.

Fixes https://github.com/rust-lang/rust/issues/112934 (probably)
Fixes https://github.com/rust-lang/rust/issues/103607
2023-08-30 02:40:37 +00:00
Ben Kimock
225b3c0556 Document in the code how this scheme works 2023-08-29 20:16:57 -04:00
Ben Kimock
b233263309 Add a specialization for encoding byte arrays in rmeta 2023-08-27 16:33:33 -04:00
bjorn3
c6247387b4 Remove metadata_loader query
It is only used by CrateLoader. We can store the metadata loader in
CStore instead which CrateLoader has access to.
2023-08-13 16:38:50 +00:00
Vadim Petrochenkov
7353c96be8 rustc: Move features from Session to GlobalCtxt
Removes two pieces of mutable state.
Follow up to #114622.
2023-08-11 16:51:50 +08:00
Vadim Petrochenkov
0b89aac08d rustc: Move crate_types from Session to GlobalCtxt
Removes a piece of mutable state.
Follow up to #114578.
2023-08-09 14:17:54 +08:00
bors
6742e2b185 Auto merge of #114578 - petrochenkov:noplugin, r=cjgillot
rustc_interface: Dismantle `register_plugins` query

It did three independent things:
- Constructed `LintStore`
- Prepared incremental directories and dep graph
- Initialized some fields in `Session`

The `LintStore` construction (now `passes::create_lint_store`)  is more or less left in place.

The incremental stuff is now moved into `fn dep_graph_future`.
This helps us to start loading the dep graph a bit earlier.

The `Session` field initialization is moved to tcx construction point.
Now that tcx is constructed early these fields don't even need to live in `Session`, they can live in tcx instead and be initialized at its creation (see the FIXME).

Three previously existing `rustc_interface` queries are de-querified (`register_plugins`, `dep_graph_future`, `dep_graph`) because they are only used locally in `fn global_ctxt` and their results don't need to be saved elsewhere.

On the other hand, `crate_types` and `stable_crate_id` are querified.
They are used from different places and their use is very similar to the existing `crate_name` query in this regard.
2023-08-08 05:10:11 +00:00
León Orell Valerian Liehr
5468336d6b
Store the laziness of type aliases in the DefKind 2023-08-07 15:54:31 +02:00
Vadim Petrochenkov
b6ac576487 rustc_interface: Dismantle register_plugins query 2023-08-07 19:33:23 +08:00
Matthias Krüger
5ea536b35f
Rollup merge of #114253 - fmease:compute-variances-for-lazy-ty-aliases, r=oli-obk
Compute variances for lazy type aliases

Fixes #114221.

CC ``@oli-obk``
r? types
2023-08-04 09:18:58 +02:00
bors
aa70e5fb6e Auto merge of #113292 - MU001999:fix/issue-113222, r=Nilstrieb
Suggest `x build library` for a custom toolchain that fails to load `core`

Fixes #113222

The nicer suggestion for dev-channel won't be emitted if `-Z ui-testing` enabled. IMO, this is acceptable for now.
2023-08-03 00:53:01 +00:00
León Orell Valerian Liehr
263a0dec60
Compute variances for lazy type aliases 2023-08-03 01:38:23 +02:00
Jubilee
126d809287
Rollup merge of #113741 - compiler-errors:rpitit-projects-to-missing-opaque, r=spastorino
Don't install default projection bound for return-position `impl Trait` in trait methods with no body

This ensures that we never try to project to an opaque type in a trait method that has no body to infer its hidden type, which means we never later call `type_of` on that opaque. This is because opaque types try to reveal their hidden type when proving auto traits.

I thought about this a lot, and I think this is a fix that's less likely to introduce other strange downstream ICEs than #113461.

Fixes #113434

r? `@spastorino`
2023-07-30 17:50:48 -07:00
Michael Goulet
0f0ab89feb Don't install default projection bound for RPITITs 2023-07-30 21:46:29 +00:00
Matthias Krüger
3ce90b1649 inline format!() args up to and including rustc_codegen_llvm 2023-07-30 14:22:50 +02:00
Michael Goulet
50d21091ee Implement assumed_wf_types for RPITITs' implementations 2023-07-29 21:19:33 +00:00
bors
beef07fe8f Auto merge of #113958 - lukas-code:doc-links, r=GuillaumeGomez,petrochenkov
fix intra-doc links on nested `use` and `extern crate` items

This PR fixes two rustdoc ICEs that happen if there are any intra-doc links on nested `use` or `extern crate` items, for example:
```rust
/// Re-export [`fmt`] and [`io`].
pub use std::{fmt, io}; // "nested" use = use with braces

/// Re-export [`std`].
pub extern crate std;
```

Nested use items were incorrectly considered private and therefore didn't have their intra-doc links resolved. I fixed this by always resolving intra-doc links for nested `use` items that are declared `pub`.

<details>

During AST->HIR lowering, nested `use` items are desugared like this:
```rust
pub use std::{}; // "list stem"
pub use std::fmt;
pub use std::io;
```
Each of these HIR nodes has it's own effective visibility and the list stem is always considered private.
To check the effective visibility of an AST node, the AST node is mapped to a HIR node with `Resolver::local_def_id`, which returns the (private) list stem for nested use items.

</details>

For `extern crate`, there was a hack in rustdoc that stored the `DefId` of the crate itself in the cleaned item, instead of the `DefId` of the `extern crate` item. This made rustdoc look at the resolved links of the extern crate's crate root instead of the `extern crate` item. I've removed this hack and instead translate the `DefId` in the appropriate places.

As as side effect of fixing `extern crate`, i've turned
```rust
#[doc(masked)]
extern crate self as _;
```
into a no-op instead of hiding all trait impls. Proper verification for `doc(masked)` is included as a bonus.

fixes https://github.com/rust-lang/rust/issues/113896
2023-07-25 01:35:53 +00:00
Matthias Krüger
abde841f0a remove redundant clones 2023-07-23 09:48:07 +02:00
Lukas Markeffsky
a342617059 improve debuggability 2023-07-22 11:54:28 +02:00
David Tolnay
5bbf0a8306
Revert "Auto merge of #113166 - moulins:ref-niches-initial, r=oli-obk"
This reverts commit 557359f925, reversing
changes made to 1e6c09a803.
2023-07-21 22:35:57 -07:00
Moulins
8b847ef734 add crate-local -Z reference_niches unstable flag (does nothing for now) 2023-07-21 03:31:45 +02:00
bors
b14fd2359f Auto merge of #113695 - bjorn3:fix_rlib_cdylib_metadata_handling, r=pnkfelix,petrochenkov
Verify that all crate sources are in sync

This ensures that rustc will not attempt to link against a cdylib as if it is a rust dylib when an rlib for the same crate is available. Previously rustc didn't actually check if any further formats of a crate which has been loaded are of the same version and if they are actually valid. This caused a cdylib to be interpreted as rust dylib as soon as the corresponding rlib was loaded. As cdylibs don't export any rust symbols, linking would fail if rustc decides to link against the cdylib rather than the rlib.

Two crates depended on the previous behavior by separately compiling a test crate as both rlib and dylib. These have been changed to capture their original spirit to the best of my ability while still working when rustc verifies that all crates are in sync. It is unlikely that build systems depend on the current behavior and in any case we are taking a lot of measures to ensure that any change to either the source or the compilation options (including crate type) results in rustc rejecting it as incompatible. We merely didn't do this check here for now obsolete perf reasons.

Fixes https://github.com/rust-lang/rust/issues/10786
Fixes https://github.com/rust-lang/rust/issues/82151
Fixes https://github.com/rust-lang/rust/issues/82972
Closes https://github.com/bevy-cheatbook/bevy-cheatbook/issues/114
2023-07-20 09:00:10 +00:00
bors
39f42ad9e8 Auto merge of #113865 - Dylan-DPC:rollup-pt960bk, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #113444 (add tests for alias bound preference)
 - #113716 (Add the `no-builtins` attribute to functions when `no_builtins` is applied at the crate level.)
 - #113754 (Simplify native_libs query)
 - #113765 (Make it clearer that edition functions are `>=`, not `==`)
 - #113774 (Improve error message when closing bracket interpreted as formatting fill character)
 - #113785 (Fix invalid display of inlined re-export when both local and foreign items are inlined)
 - #113803 (Fix inline_const with interpolated block)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-07-19 18:17:59 +00:00
Dylan DPC
dbb6b1ac31
Rollup merge of #113754 - cjgillot:simplify-foreign, r=petrochenkov
Simplify native_libs query

Drive-by cleanup I saw while implementing https://github.com/rust-lang/rust/pull/113734
2023-07-19 22:37:07 +05:30
bjorn3
8c9a8b63c9 Fix review comments 2023-07-19 14:53:26 +00:00
bjorn3
52853c2694 Don't compress dylib metadata 2023-07-19 14:47:06 +00:00
bjorn3
008be2d7b6 Verify that all crate sources are in sync
This ensures that rustc will not attempt to link against a cdylib as if
it is a rust dylib when an rlib for the same crate is available.
Previously rustc didn't actually check if any further formats of a
crate which has been loaded are of the same version and if they are
actually valid. This caused a cdylib to be interpreted as rust dylib as
soon as the corresponding rlib was loaded. As cdylibs don't export any
rust symbols, linking would fail if rustc decides to link against the
cdylib rather than the rlib.

Two crates depended on the previous behavior by separately compiling a
test crate as both rlib and dylib. These have been changed to capture
their original spirit to the best of my ability while still working
when rustc verifies that all crates are in sync. It is unlikely that
build systems depend on the current behavior and in any case we are
taking a lot of measures to ensure that any change to either the source
or the compilation options (including crate type) results in rustc
rejecting it as incompatible. We merely didn't do this check here for
now obsolete perf reasons.
2023-07-19 14:47:05 +00:00
Camille GILLOT
186be726d6 Encode shorthands for spans in metadata. 2023-07-19 12:22:11 +00:00
Camille GILLOT
fdc93f307f Do not fetch HIR in native_libs. 2023-07-17 07:37:03 +00:00
Camille GILLOT
51e1f7a561 Simplify foreign_modules. 2023-07-17 07:37:03 +00:00
bors
6f65ef5717 Auto merge of #113562 - saethlin:larger-incr-comp-offset, r=nnethercote
Use u64 for incr comp allocation offsets

Fixes https://github.com/rust-lang/rust/issues/76037
Fixes https://github.com/rust-lang/rust/issues/95780
Fixes https://github.com/rust-lang/rust/issues/111613

These issues are all reporting ICEs caused by using `u32` to store offsets to allocations in the incremental compilation cache. This PR aims to lift that limitation by changing the offset type in question to `u64`.

There are two perf runs in this PR. The first reports a regression, and the second does not. The changes are the same in both. I rebased the PR then did the second perf run because I noticed that the primary regression in it was very commonly seen in spurious regression reports.

I do not know what the perf run will report when this is merged. I would not be surprised to see regression or neutral, but the cachegrind diffs for the regression point at `try_mark_previous_green` which is a common source of inexplicable regressions and I don't think should be perturbed by this PR.

I'm not opposed to adding a regression test such as
```rust
fn main() {
    println!("{}", [37; 1 << 30].len());
}
```
But that program takes 1 minute to compile and consumes 4.6 GB of memory then writes that much to disk. Is that a concerning amount of resource use for a test?

r? `@nnethercote`
2023-07-17 04:45:10 +00:00
Ben Kimock
4e117a9b4e Use u64 for incr comp allocation offsets 2023-07-14 17:03:34 -04:00
Matthias Krüger
0baf4406da
Rollup merge of #113698 - compiler-errors:rpitit-check, r=spastorino
Make it clearer that we're just checking for an RPITIT

Tiny nit to use `is_impl_trait_in_trait` more, to make it clearer that we're just checking whether a def-id is an RPITIT, rather than doing something meaningful with the `opt_rpitit_info`.

r? `@spastorino`
2023-07-14 19:33:29 +02:00
Michael Goulet
14672eba8b Make it clearer that we're just checking for an RPITIT 2023-07-14 15:18:48 +00:00
Mahdi Dibaiee
e55583c4b8 refactor(rustc_middle): Substs -> GenericArg 2023-07-14 13:27:35 +01:00
Ben Kimock
e0103a7b3c Micro-optimize 2023-07-14 07:50:02 -04:00
Ben Kimock
2ae197d5fc Adapt table sizes to the contents 2023-07-13 19:30:00 -04:00
Mark Rousskov
cc907f80b9 Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
Santiago Pastorino
20429af7a3
Replace RPITIT current impl with new strategy that lowers as a GAT 2023-07-08 18:21:34 -03:00
bors
0130c3a06e Auto merge of #113215 - compiler-errors:rpitit-predicates-tweaks, r=spastorino
Make RPITITs assume/require their parent method's predicates

Removes a FIXME from the `param_env` query where we were manually adding the parent function's predicates to the RPITIT's assumptions.

r? `@spastorino`
2023-07-04 04:24:24 +00:00
Mu001999
9b6bdcd86b Suggest x build library for a custom toolchain that fails to load core 2023-07-04 09:37:40 +08:00
Nilstrieb
ba0f5dcd14 Revert "Suggest x build library for a custom toolchain that fails to load core"
This reverts commit b913f5593d.

CI builds with profile=nightly, causing different test output.

Making the output depend on the release channel was not a great idea.
2023-07-03 12:48:52 +00:00
Mu001999
b913f5593d Suggest x build library for a custom toolchain that fails to load core 2023-07-02 17:53:44 +08:00
Michael Goulet
0d2fede817 reflow comment, not a FIXME i think 2023-06-30 18:51:27 +00:00
Michael Goulet
0506250f8c Encode item bounds for DefKind::ImplTraitPlaceholder 2023-06-29 16:37:13 +00:00
bors
5bd28f5eac Auto merge of #98867 - cjgillot:metaloop, r=oli-obk
Refactor metadata emission to avoid visiting HIR

This PR refactors metadata emission to be based on tables and iteration over definitions.

In a first part, this PR moves information from the `EntryKind` enum to tables, until removing the `EntryKind` enum.
In a second part, the iteration scheme is refactored to avoid fetching HIR unless strictly necessary.

r? `@ghost`
2023-06-28 16:16:27 +00:00
Camille GILLOT
0faea7728f Encode impls in encode_impls. 2023-06-27 16:50:34 +00:00
Camille GILLOT
845fcc1939 Use instrument macro. 2023-06-27 16:50:34 +00:00
Camille GILLOT
fd81e964b8 Retire encode_info_for_items. 2023-06-27 16:50:34 +00:00
Camille GILLOT
22df32264a Encode Impl separately. 2023-06-27 16:50:34 +00:00
Camille GILLOT
45a9a5460f Encode Trait info in def-id loop. 2023-06-27 16:50:34 +00:00
Camille GILLOT
1a9d34fd81 Merge assoc_item functions. 2023-06-27 16:50:34 +00:00
Camille GILLOT
3c790b3730 Encode fn_sig separately.
Closures do not have a `fn_sig`, so no reason to encode one.
2023-06-27 16:50:34 +00:00
Michael Goulet
fbdef58414 Migrate predicates_of and caller_bounds to Clause 2023-06-26 23:12:03 +00:00
Camille GILLOT
3d9ba07a0e Use constness query to encode constness. 2023-06-26 16:45:41 +00:00
Camille GILLOT
cbe1578690 Encode info for Fn/AssocFn in a single place. 2023-06-26 16:45:01 +00:00
bors
1d67eba687 Auto merge of #112891 - oli-obk:impl_trait_in_assoc_tys_cleanup, r=compiler-errors
Various impl trait in assoc tys cleanups

r? `@compiler-errors`

All commits except for the last are pure refactorings. 274dab5bd658c97886a8987340bf50ae57900c39 allows struct fields to participate in deciding whether a function has an opaque in its signature.

best reviewed commit by commit
2023-06-23 23:26:38 +00:00
Michael Goulet
471830b3a4 migrate inferred_outlives_of to Clause 2023-06-22 18:34:24 +00:00
Michael Goulet
46a650f4e0 Migrate item_bounds to ty::Clause 2023-06-22 18:34:23 +00:00
Oli Scherer
c8979e587b Move opaque_type_origin_unchecked onto TyCtxt and re-use it where it was open coded 2023-06-22 14:31:15 +00:00
Nilstrieb
a98c14f3a9
Rollup merge of #112772 - compiler-errors:clauses-1, r=lcnr
Add a fully fledged `Clause` type, rename old `Clause` to `ClauseKind`

Does two basic things before I put up a more delicate set of PRs (along the lines of #112714, but hopefully much cleaner) that migrate existing usages of `ty::Predicate` to `ty::Clause` (`predicates_of`/`item_bounds`/`ParamEnv::caller_bounds`).

1. Rename `Clause` to `ClauseKind`, so it's parallel with `PredicateKind`.
2. Add a new `Clause` type which is parallel to `Predicate`.
    * This type exposes `Clause::kind(self) -> Binder<'tcx, ClauseKind<'tcx>>` which is parallel to `Predicate::kind` 😸

The new `Clause` type essentially acts as a newtype wrapper around `Predicate` that asserts that it is specifically a `PredicateKind::Clause`. Turns out from experimentation[^1] that this is not negative performance-wise, which is wonderful, since this a much simpler design than something that requires encoding the discriminant into the alignment bits of a predicate kind, or something else like that...

r? ``@lcnr`` or ``@oli-obk``

[^1]: https://github.com/rust-lang/rust/pull/112714#issuecomment-1595653910
2023-06-21 07:37:01 +02:00
Camille GILLOT
7d5b2e4926 Make closure_saved_names_of_captured_variables a query. 2023-06-19 16:50:52 +00:00
Michael Goulet
fca56a8d2c s/Clause/ClauseKind 2023-06-19 14:57:42 +00:00
The 8472
114d5f221c s/drain_filter/extract_if/ for Vec, Btree{Map,Set} and LinkedList 2023-06-14 09:28:54 +02:00
bors
343ad6f059 Auto merge of #111626 - pjhades:output, r=b-naber
Write to stdout if `-` is given as output file

With this PR, if `-o -` or `--emit KIND=-` is provided, output will be written to stdout instead. Binary output (those of type `obj`, `llvm-bc`, `link` and `metadata`) being written this way will result in an error unless stdout is not a tty. Multiple output types going to stdout will trigger an error too, as they will all be mixded together.

This implements https://github.com/rust-lang/compiler-team/issues/431

The idea behind the changes is to introduce an `OutFileName` enum that represents the output - be it a real path or stdout - and to use this enum along the code paths that handle different output types.
2023-06-09 09:45:40 +00:00
bors
a97c36dd2e Auto merge of #109005 - Nilstrieb:dont-forgor-too-much-from-cfg, r=petrochenkov
Remember names of `cfg`-ed out items to mention them in diagnostics

# Examples

## `serde::Deserialize` without the `derive` feature (a classic beginner mistake)

I had to slightly modify serde so that it uses explicit re-exports instead of a glob re-export. (Update: a serde PR was merged that adds the manual re-exports)

```
error[E0433]: failed to resolve: could not find `Serialize` in `serde`
   --> src/main.rs:1:17
    |
1   | #[derive(serde::Serialize)]
    |                 ^^^^^^^^^ could not find `Serialize` in `serde`
    |
note: crate `serde` has an item named `Serialize` but it is inactive because its cfg predicate evaluated to false
   --> /home/gh-Nilstrieb/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.160/src/lib.rs:343:1
    |
343 | #[cfg(feature = "serde_derive")]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
344 | pub use serde_derive::{Deserialize, Serialize};
    |                                     ^^^^^^^^^
    = note: the item is gated behind the `serde_derive` feature
    = note: see https://doc.rust-lang.org/cargo/reference/features.html for how to activate a crate's feature
```
(the suggestion is not ideal but that's serde's fault)

I already tested the metadata size impact locally by compiling the `windows` crate without any features. `800k`  -> `809k`

r? `@ghost`
2023-06-07 17:38:57 +00:00
Jing Peng
ade6c36e53 fix
- remove useless commands from test Makefile
- do not unnecessarily remove metadata temporary files because they'll be managed by MaybeTempDir
- remove unused FailedRemove error introduced by this PR
2023-06-06 17:54:34 -04:00
Jing Peng
9b1a1e1d95 Write to stdout if - is given as output file
If `-o -` or `--emit KIND=-` is provided, output will be written
to stdout instead. Binary output (`obj`, `llvm-bc`, `link` and
`metadata`) being written this way will result in an error unless
stdout is not a tty. Multiple output types going to stdout will
trigger an error too, as they will all be mixded together.
2023-06-06 17:53:29 -04:00
Camille GILLOT
ca4d0d4c24 Separate AnonConst from ConstBlock in HIR. 2023-06-02 21:25:18 +00:00
Nilstrieb
a647ba250a Remember names of cfg-ed out items to mention them in diagnostics
`#[cfg]`s are frequently used to gate crate content behind cargo
features. This can lead to very confusing errors when features are
missing. For example, `serde` doesn't have the `derive` feature by
default. Therefore, `serde::Serialize` fails to resolve with a generic
error, even though the macro is present in the docs.

This commit adds a list of all stripped item names to metadata. This is
filled during macro expansion and then, through a fed query, persisted
in metadata. The downstream resolver can then access the metadata to
look at possible candidates for mentioning in the errors.

This slightly increases metadata (800k->809k for the feature-heavy
windows crate), but not enough to really matter.
2023-06-01 19:17:19 +02:00
Deadbeef
21bc5cded4 Rename impl_defaultness to defaultness 2023-06-01 06:14:06 +00:00
bors
871b595202 Auto merge of #111913 - oli-obk:valtrees2, r=lcnr
Only rewrite valtree-constants to patterns and keep other constants opaque

Now that we can reliably fall back to comparing constants with `PartialEq::eq` to the match scrutinee, we can

1. eagerly try to convert constants to valtrees
2. then deeply convert the valtree to a pattern
3. if the to-valtree conversion failed, create an "opaque constant" pattern.

This PR specifically avoids any behavioral changes or major cleanups. What we can now do as follow ups is

* move the two remaining call sites to `destructure_mir_constant` off that query
* make valtree to pattern conversion infallible
    * this needs to be done after careful analysis of the effects. There may be user visible changes from that.

based on https://github.com/rust-lang/rust/pull/111768
2023-05-31 16:36:51 +00:00
bors
ad8304a0d5 Auto merge of #111076 - notriddle:notriddle/silence-private-dep-trait-impl-suggestions, r=cjgillot
diagnostics: exclude indirect private deps from trait impl suggest

Fixes #88696
2023-05-31 13:47:36 +00:00
Oli Scherer
f8b5e0064b Lower the tracing level of some very verbose messages 2023-05-30 16:03:24 +00:00
Nilstrieb
e7fdba84e2
Rollup merge of #112060 - lcnr:early-binder, r=jackh726
`EarlyBinder::new` -> `EarlyBinder::bind`

for consistency with `Binder::bind`. it may make sense to also add `EarlyBinder::dummy` in places where we know that no parameters exist, but I left that out of this PR.

r? `@jackh726` `@kylematsuda`
2023-05-30 12:57:40 +02:00
lcnr
08d149ca85 EarlyBinder::new -> EarlyBinder::bind 2023-05-29 13:46:10 +02:00
bors
99ff5afeb8 Auto merge of #111329 - jyn514:metadata-ice, r=bjorn3
Load only the crate header for `locator::crate_matches`

Previously, we used the following info to determine whether to load the crate:
1. The METADATA_HEADER, which includes a METADATA_VERSION constant
2. The embedded rustc version
3. Various metadata in the `CrateRoot`, including the SVH

This worked ok most of the time. Unfortunately, when building locally the rustc version is always
the same because `omit-git-hash` is on by default. That meant that we depended only on 1 and 3, and
we are not very good about bumping METADATA_VERSION (it's currently at 7) so in practice we were
only depending on 3. `CrateRoot` is a very large struct and changes somewhat regularly, so this led
to a steady stream of crashes from trying to load it.

Change the logic to add an intermediate step between 2 and 3: introduce a new `CrateHeader` struct
that contains only the minimum info needed to decide whether the crate should be loaded or not. That
avoids having to load all of `CrateRoot`, which in practice means we should crash much less often.

Note that this works because the SVH should be different between any two dependencies, even if the
compiler has changed, because we use `-Zbinary-dep-depinfo` in bootstrap. See
https://github.com/rust-lang/rust/pull/111329#issuecomment-1538303474 for more details about how the
original crash happened.
2023-05-29 10:40:32 +00:00
Kyle Matsuda
03534ac8b7 Replace EarlyBinder(x) with EarlyBinder::new(x) 2023-05-28 10:44:50 -06:00
jyn
62314be705 Load only the header for crate_matches
Previously, we used the following info to determine whether to load the crate:
1. The METADATA_HEADER, which includes a METADATA_VERSION constant
2. The embedded rustc version
3. Various metadata in the `CrateRoot`, including the SVH

This worked ok most of the time. Unfortunately, when building locally the rustc version is always
the same because `omit-git-hash` is on by default. That meant that we depended only on 1 and 3, and
we are not very good about bumping METADATA_VERSION (it's currently at 7) so in practice we were
only depending on 3. `CrateRoot` is a very large struct and changes somewhat regularly, so this led
to a steady stream of crashes from trying to load it.

Change the logic to add an intermediate step between 2 and 3: introduce a new `CrateHeader` struct
that contains only the minimum info needed to decide whether the crate should be loaded or not. That
avoids having to load all of `CrateRoot`, which in practice means we should crash much less often.

Note that this works because the SVH should be different between any two dependencies, even if the
compiler has changed, because we use `-Zbinary-dep-depinfo` in bootstrap. See
https://github.com/rust-lang/rust/pull/111329#issuecomment-1538303474 for more details about how the
original crash happened.
2023-05-26 07:44:37 -05:00