Commit Graph

210 Commits

Author SHA1 Message Date
Nicholas Nethercote
3c4f1d85af Rename {create,emit}_warning as {create,emit}_warn.
For consistency with `warn`/`struct_warn`, and also `{create,emit}_err`,
all of which use an abbreviated form.
2024-01-10 07:33:06 +11:00
Michael Woerister
739e5ef49e Split StableCompare trait out of StableOrd trait.
StableCompare is a companion trait to `StableOrd`. Some types like `Symbol` can be compared in a cross-session stable way, but their `Ord` implementation is not stable. In such cases, a `StableOrd` implementation can be provided to offer a lightweight way for stable sorting. (The more heavyweight option is to sort via `ToStableHashKey`, but then sorting needs to have access to a stable hashing context and `ToStableHashKey` can also be expensive as in the case of `Symbol` where it has to allocate a `String`.)
2024-01-04 13:32:42 +01:00
Ben Kimock
94c43ccd87 Report I/O errors with emit_fatal not emit_err 2024-01-02 07:31:02 -05:00
Nicholas Nethercote
8a9db25459 Remove more Session methods that duplicate DiagCtxt methods. 2023-12-24 08:17:47 +11:00
Nicholas Nethercote
99472c7049 Remove Session methods that duplicate DiagCtxt methods.
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier
access.
2023-12-24 08:05:28 +11:00
zetanumbers
24f009c5e5 Move some methods from tcx.hir() to tcx
Renamings:
- find -> opt_hir_node
- get -> hir_node
- find_by_def_id -> opt_hir_node_by_def_id
- get_by_def_id -> hir_node_by_def_id

Fix rebase changes using removed methods

Use `tcx.hir_node_by_def_id()` whenever possible in compiler

Fix clippy errors

Fix compiler

Apply suggestions from code review

Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>

Add FIXME for `tcx.hir()` returned type about its removal

Simplify with with `tcx.hir_node_by_def_id`
2023-12-12 06:40:29 -08:00
surechen
40ae34194c remove redundant imports
detects redundant imports that can be eliminated.

for #117772 :

In order to facilitate review and modification, split the checking code and
removing redundant imports code into two PR.
2023-12-10 10:56:22 +08:00
Nicholas Nethercote
2c337a072c Rename HandlerInner::delayed_span_bugs as HandlerInner::span_delayed_bugs.
For reasons similar to the previous commit.
2023-12-02 09:01:34 +11:00
Nicholas Nethercote
e065d96b08 Remove unused field from IncrCompSession. 2023-12-01 08:00:56 +11:00
bors
3dbb4da042 Auto merge of #117301 - saethlin:finish-rmeta-encoding, r=WaffleLapkin
Call FileEncoder::finish in rmeta encoding

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

The bug here was that rmeta encoding never called FileEncoder::finish. Now it does. Most of the changes here are needed to support that, since rmeta encoding wants to finish _then_ access the File in the encoder, so finish can't move out.

I tried adding a `cfg(debug_assertions)` exploding Drop impl to FileEncoder that checked for finish being called before dropping, but fatal errors cause unwinding so this isn't really possible. If we encounter a fatal error with a dirty FileEncoder, the Drop impl ICEs even though the implementation is correct. If we try to paper over that by wrapping FileEncoder in ManuallyDrop then that just erases the fact that Drop automatically checks that we call finish on all paths.

I also changed the name of DepGraph::encode to DepGraph::finish_encoding, because that's what it does and it makes the fact that it is the path to FileEncoder::finish less confusing.

r? `@WaffleLapkin`
2023-11-26 14:43:02 +00:00
Vadim Petrochenkov
c697927f44 rustc: hir().local_def_id_to_hir_id() -> tcx.local_def_id_to_hir_id() cleanup 2023-11-26 12:41:21 +03:00
Nicholas Nethercote
57cd5e6551 Use rustc_fluent_macro::fluent_messages! directly.
Currently we always do this:
```
use rustc_fluent_macro::fluent_messages;
...
fluent_messages! { "./example.ftl" }
```
But there is no need, we can just do this everywhere:
```
rustc_fluent_macro::fluent_messages! { "./example.ftl" }
```
which is shorter.
2023-11-26 08:38:40 +11:00
Nicholas Nethercote
a733082be9 Avoid need for {D,Subd}iagnosticMessage imports.
The `fluent_messages!` macro produces uses of
`crate::{D,Subd}iagnosticMessage`, which means that every crate using
the macro must have this import:
```
use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
```

This commit changes the macro to instead use
`rustc_errors::{D,Subd}iagnosticMessage`, which avoids the need for the
imports.
2023-11-26 08:38:00 +11:00
Ben Kimock
fbaa24ee35 Call FileEncoder::finish in rmeta encoding 2023-11-22 22:49:22 -05:00
Nilstrieb
21a870515b Fix clippy::needless_borrow in the compiler
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`.

Then I had to remove a few unnecessary parens and muts that were exposed
now.
2023-11-21 20:13:40 +01:00
Mark Rousskov
db3e2bacb6 Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
bjorn3
a3b964b9ea Remove unused LoadResult::DecodeIncrCache variant 2023-11-04 20:16:03 +00:00
Nicholas Nethercote
8ff624a9f2 Clean up rustc_*/Cargo.toml.
- Sort dependencies and features sections.
- Add `tidy` markers to the sorted sections so they stay sorted.
- Remove empty `[lib`] sections.
- Remove "See more keys..." comments.

Excluded files:
- rustc_codegen_{cranelift,gcc}, because they're external.
- rustc_lexer, because it has external use.
- stable_mir, because it has external use.
2023-10-30 08:46:02 +11:00
Nicholas Nethercote
e0c990e32c Reduce some function exposure. 2023-10-26 09:04:26 +11:00
Nicholas Nethercote
3cf2a7441f Tiny comment fixes. 2023-10-26 09:04:17 +11:00
Nicholas Nethercote
8da1b33153 Move a use to a more sensible spot.
I.e. in the source file where it's used.
2023-10-26 08:46:10 +11:00
Nicholas Nethercote
ca29c272e7 Reduce exposure of three functions used only within rustc_incremental. 2023-10-26 08:46:10 +11:00
Nicholas Nethercote
72e8690c04 Remove unused never_type feature. 2023-10-26 08:46:10 +11:00
bors
130ff8cb6c Auto merge of #115964 - bjorn3:cgu_reuse_tracker_global_state, r=cjgillot
Remove cgu_reuse_tracker from Session

This removes a bit of global mutable state.

It will now miss post-lto cgu reuse when ThinLTO determines that a cgu doesn't get changed, but there weren't any tests for this anyway and a test for it would be fragile to the exact implementation of ThinLTO in LLVM.
2023-10-13 00:09:30 +00:00
bjorn3
e9fa2ca6ad Remove cgu_reuse_tracker from Session
This removes a bit of global mutable state
2023-10-09 18:39:41 +00:00
Michael Howell
c6e6ecb1af rustdoc: remove rust logo from non-Rust crates 2023-10-08 20:17:53 -07:00
John Kåre Alsaker
ba8d53dc8f Don't use a thread to load the dep graph 2023-09-24 00:30:43 +02:00
John Kåre Alsaker
1806efe7f2 Move DepKind to rustc_query_system and define it as u16 2023-09-21 17:06:14 +02:00
John Kåre Alsaker
2a5121b131 Avoid a source_span query when encoding Spans into query results 2023-09-08 02:08:52 +02:00
Martin Nordholts
64e8aea9ce Ignore unexpected incr-comp session dirs
Clearly the code path can be hit without the presence of a compiler bug.
All it takes is mischief. See 71698.

Ignore problematic directories instead of ICE:ing. `continue`ing is
already done for problematic dirs in the code block above us.
2023-08-18 19:57:41 +02:00
Martin Nordholts
df8aed400b More error details upon unexpected incr-comp session dir 2023-08-18 19:57:41 +02:00
bjorn3
980143b50c Pass WorkProductMap to build_dep_graph instead of FxIndexMap
Constructing an FxIndexMap is useless work as the iteration order never
matters.
2023-08-13 16:07:48 +00:00
Nilstrieb
5830ca216d Add internal_features lint
It lints against features that are inteded to be internal to the
compiler and standard library. Implements MCP #596.

We allow `internal_features` in the standard library and compiler as those
use many features and this _is_ the standard library from the "internal to the compiler and
standard library" after all.

Marking some features as internal wasn't exactly the most scientific approach, I just marked some
mostly obvious features. While there is a categorization in the macro,
it's not very well upheld (should probably be fixed in another PR).

We always pass `-Ainternal_features` in the testsuite
About 400 UI tests and several other tests use internal features.
Instead of throwing the attribute on each one, just always allow them.
There's nothing wrong with testing internal features^^
2023-08-03 14:50:50 +02:00
Matthias Krüger
3ce90b1649 inline format!() args up to and including rustc_codegen_llvm 2023-07-30 14:22:50 +02:00
Mark Rousskov
cc907f80b9 Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
Andrew Xie
0cac8455e6 Applied nits 2023-06-11 22:45:04 -04:00
Andrew Xie
54d7b327e5 Removed stable/unstable sort arg from into_sorted_stable_ord, fixed a few misc issues, added collect to UnordItems 2023-06-08 00:38:50 -04:00
Andrew Xie
f5f638c124 Fixed to_sorted => to_sorted_stable_ord 2023-06-05 00:16:20 -04:00
Andrew Xie
6f2d3dee17 Fixed unord mistake 2023-06-04 21:55:32 -04:00
Andrew Xie
96b577860d Fixed failing test + minor cleanup 2023-06-04 21:55:32 -04:00
Andrew Xie
cf7dea5716 Sorted a FxIndexSet for consistent iteration order 2023-06-04 21:55:31 -04:00
Andrew Xie
1be19f710c Switched some uses to UnordMap 2023-06-04 21:55:30 -04:00
Andrew Xie
17412bae30 Removed use of iteration through a HashMap/HashSet in rustc_incremental and replaced with IndexMap/IndexSet 2023-06-04 21:54:28 -04:00
clubby789
f97fddab91 Ensure Fluent messages are in alphabetical order 2023-05-25 23:49:35 +00:00
jyn
d5f2b8e5c6 Only depend on CFG_VERSION in rustc_interface
this avoids having to rebuild the whole compiler on each commit when
`omit-git-hash = false`.
2023-05-17 23:54:21 -05:00
Matthias Krüger
3ce6dd2a54
Rollup merge of #111024 - saethlin:stringify-full-svh, r=oli-obk
Use the full Fingerprint when stringifying Svh

Finally circling back, per https://github.com/rust-lang/rust/pull/110367#discussion_r1168340739

r? `@oli-obk`
2023-05-04 08:09:04 +02:00
Ben Kimock
3c6d9ec77d Use the full Fingerprint when stringifying Svh 2023-04-30 14:28:30 -04:00
John Kåre Alsaker
66d85438ca Remove QueryEngine trait 2023-04-26 07:46:13 +02:00
bors
d7f9e81650 Auto merge of #110407 - Nilstrieb:fluent-macro, r=davidtwco
Add `rustc_fluent_macro` to decouple fluent from `rustc_macros`

Fluent, with all the icu4x it brings in, takes quite some time to compile. `fluent_messages!` is only needed in further downstream rustc crates, but is blocking more upstream crates like `rustc_index`. By splitting it out, we allow `rustc_macros` to be compiled earlier, which speeds up `x check compiler` by about 5 seconds (and even more after the needless dependency on `serde_json` is removed from `rustc_data_structures`).
2023-04-19 08:26:47 +00:00
bors
b3f1379509 Auto merge of #110083 - saethlin:encode-hashes-as-bytes, r=cjgillot
Encode hashes as bytes, not varint

In a few places, we store hashes as `u64` or `u128` and then apply `derive(Decodable, Encodable)` to the enclosing struct/enum. It is more efficient to encode hashes directly than try to apply some varint encoding. This PR adds two new types `Hash64` and `Hash128` which are produced by `StableHasher` and replace every use of storing a `u64` or `u128` that represents a hash.

Distribution of the byte lengths of leb128 encodings, from `x build --stage 2` with `incremental = true`

Before:
```
(  1) 373418203 (53.7%, 53.7%): 1
(  2) 196240113 (28.2%, 81.9%): 3
(  3) 108157958 (15.6%, 97.5%): 2
(  4)  17213120 ( 2.5%, 99.9%): 4
(  5)    223614 ( 0.0%,100.0%): 9
(  6)    216262 ( 0.0%,100.0%): 10
(  7)     15447 ( 0.0%,100.0%): 5
(  8)      3633 ( 0.0%,100.0%): 19
(  9)      3030 ( 0.0%,100.0%): 8
( 10)      1167 ( 0.0%,100.0%): 18
( 11)      1032 ( 0.0%,100.0%): 7
( 12)      1003 ( 0.0%,100.0%): 6
( 13)        10 ( 0.0%,100.0%): 16
( 14)        10 ( 0.0%,100.0%): 17
( 15)         5 ( 0.0%,100.0%): 12
( 16)         4 ( 0.0%,100.0%): 14
```

After:
```
(  1) 372939136 (53.7%, 53.7%): 1
(  2) 196240140 (28.3%, 82.0%): 3
(  3) 108014969 (15.6%, 97.5%): 2
(  4)  17192375 ( 2.5%,100.0%): 4
(  5)       435 ( 0.0%,100.0%): 5
(  6)        83 ( 0.0%,100.0%): 18
(  7)        79 ( 0.0%,100.0%): 10
(  8)        50 ( 0.0%,100.0%): 9
(  9)         6 ( 0.0%,100.0%): 19
```

The remaining 9 or 10 and 18 or 19 are `u64` and `u128` respectively that have the high bits set. As far as I can tell these are coming primarily from `SwitchTargets`.
2023-04-18 22:27:15 +00:00