Commit Graph

621 Commits

Author SHA1 Message Date
Ben Kimock
84facac97a Remove some unnecessary hash truncations 2023-04-16 20:05:02 -04:00
Scott McMurray
c98895d9f2 Various minor Idx-related tweaks
Nothing particularly exciting here, but a couple of things I noticed as I was looking for more index conversions to simplify.
2023-04-16 02:42:50 -07:00
bors
661b33f524 Auto merge of #109935 - michaelwoerister:fix-feed-in-eval-always, r=cjgillot
incr.comp.: Make sure dependencies are recorded when feeding queries during eval-always queries.

This PR makes sure we don't drop dependency edges when feeding queries during an eval-always query.

Background: During eval-always queries, no dependencies are recorded because the system knows to unconditionally re-evaluate them regardless of any actual dependencies. This works fine for these queries themselves but leads to a problem when feeding other queries: When queries are fed, we set up their dependency edges by copying the current set of dependencies of the feeding query. But because this set is empty for eval-always queries, we record no edges at all -- which has the effect that the fed query instances always look "green" to the system, although they should always be "red".

The fix is to explicitly add a dependency on the artificial "always red" dep-node when feeding during eval-always queries.

Fixes https://github.com/rust-lang/rust/issues/108481
Maybe also fixes issue https://github.com/rust-lang/rust/issues/88488.

cc `@jyn514`

r? `@cjgillot` or `@oli-obk`
2023-04-12 11:16:35 +00:00
Nilstrieb
81c320ea77 Fix some clippy::complexity 2023-04-09 23:22:14 +02:00
John Kåre Alsaker
6d99dd9189 Address comments 2023-04-06 08:25:53 +02:00
John Kåre Alsaker
36b4199a8e Don't rely on Debug impl for Erased 2023-04-06 08:25:53 +02:00
John Kåre Alsaker
785459d630 Erase query cache values 2023-04-06 08:25:52 +02:00
Michael Woerister
6117c06306 incr.comp.: Make sure dependencies are recorded when feeding queries during eval-always queries. 2023-04-04 14:38:46 +02:00
Oli Scherer
aad33198ff Remove a fishy Clone impl 2023-04-04 09:01:44 +00:00
Nicholas Nethercote
08dec8969f Remove an out-of-date comment on QueryCache::lookup. 2023-03-30 21:14:43 +11:00
nils
c31f75209f
Rollup merge of #108480 - Zoxc:rayon-tlv, r=cuviper
Use Rayon's TLV directly

This accesses Rayon's `TLV` thread local directly avoiding wrapper functions. This makes rustc work with https://github.com/rust-lang/rustc-rayon/pull/10.

r? `@cuviper`
2023-03-28 12:51:12 +02:00
Michael Goulet
f738b44c6d no shadow plz 2023-03-27 20:47:15 +00:00
Matthias Krüger
32aa4c03d9
Rollup merge of #109587 - cjgillot:no-hashmap-fingerprint, r=Nilstrieb
Use an IndexVec to debug fingerprints.

Uncontroversial part of https://github.com/rust-lang/rust/pull/109050
2023-03-27 08:46:52 +02:00
bors
b72e896268 Auto merge of #109100 - Zoxc:merge-query-try, r=cjgillot
Refactor `try_execute_query`

This merges `JobOwner::try_start` into `try_execute_query`, removing `TryGetJob` in the processes. 3 new functions are extracted from `try_execute_query`: `execute_job`, `cycle_error` and `wait_for_query`. This makes the control flow a bit clearer and improves performance.

Based on https://github.com/rust-lang/rust/pull/109046.

<table><tr><td rowspan="2">Benchmark</td><td colspan="1"><b>Before</b></th><td colspan="2"><b>After</b></th></tr><tr><td align="right">Time</td><td align="right">Time</td><td align="right">%</th></tr><tr><td>🟣 <b>clap</b>:check</td><td align="right">1.7134s</td><td align="right">1.7061s</td><td align="right"> -0.43%</td></tr><tr><td>🟣 <b>hyper</b>:check</td><td align="right">0.2519s</td><td align="right">0.2510s</td><td align="right"> -0.35%</td></tr><tr><td>🟣 <b>regex</b>:check</td><td align="right">0.9517s</td><td align="right">0.9481s</td><td align="right"> -0.38%</td></tr><tr><td>🟣 <b>syn</b>:check</td><td align="right">1.5389s</td><td align="right">1.5338s</td><td align="right"> -0.33%</td></tr><tr><td>🟣 <b>syntex_syntax</b>:check</td><td align="right">5.9488s</td><td align="right">5.9258s</td><td align="right"> -0.39%</td></tr><tr><td>Total</td><td align="right">10.4048s</td><td align="right">10.3647s</td><td align="right"> -0.38%</td></tr><tr><td>Summary</td><td align="right">1.0000s</td><td align="right">0.9962s</td><td align="right"> -0.38%</td></tr></table>

r? `@cjgillot`
2023-03-25 12:04:46 +00:00
Camille GILLOT
5e49f099a9 Use an IndexVec to debug fingerprints. 2023-03-25 09:22:40 +00:00
John Kåre Alsaker
820e3a8d6a Pass tcx directly 2023-03-25 03:13:05 +01:00
John Kåre Alsaker
afe4c16b29 Split the if to release the lock earlier 2023-03-25 03:12:41 +01:00
John Kåre Alsaker
dfae9c993d Remove DebugArg 2023-03-25 02:59:54 +01:00
John Kåre Alsaker
8f294066b3 Optimize incremental_verify_ich 2023-03-25 02:59:53 +01:00
John Kåre Alsaker
27c44d2e28 Update indexmap and rayon crates 2023-03-25 02:12:13 +01:00
John Kåre Alsaker
ced33ad289 Refactor try_execute_query 2023-03-21 03:29:19 +01:00
bors
822c10feb7 Auto merge of #109046 - Zoxc:split-execute-job, r=cjgillot,michaelwoerister
Split `execute_job` into `execute_job_incr` and `execute_job_non_incr`

`execute_job` was a bit large, so this splits it in 2. Performance was neutral locally, but this may affect bootstrap times.
2023-03-20 23:53:09 +00:00
bors
13b7aa4d7f Auto merge of #108524 - Zoxc:node-backtrace, r=cjgillot
Optimize dep node backtrace and ignore fatal errors

This attempts to optimize https://github.com/rust-lang/rust/pull/91742 while also passing through fatal errors.

r? `@cjgillot`
2023-03-20 11:54:00 +00:00
John Kåre Alsaker
c4bcac628c Add some assertions 2023-03-19 17:39:34 +01:00
John Kåre Alsaker
486a38723b Split execute_job into execute_job_incr and execute_job_non_incr 2023-03-19 17:39:34 +01:00
bors
938afba899 Auto merge of #108845 - Zoxc:par-fix-2, r=cjgillot
Check that a query has not completed and is not executing before starting it

This fixes a race in the query system where we only checked if the query was currently executing, but not if it was already completed, causing queries to re-execute.

r? `@cjgillot`
2023-03-12 17:03:44 +00:00
bors
f41927f309 Auto merge of #108820 - cjgillot:ensure-on-disk, r=oli-obk
Ensure value is on the on-disk cache before returning from `ensure()`.

The current logic for `ensure()` a query just checks that the node is green in the dependency graph.
However, a lot of places use `ensure()` to prevent the query from being called later. This is the case before stealing a query result.

If the query is actually green but the value is not available in the on-disk cache, `ensure` would return, but a subsequent call to the full query would run the code, and attempt to read from a stolen value.

This PR conforms the query system to the usage by checking whether the queried value is loadable from disk before returning.

Sadly, I can't manage to craft a proper test...

Should fix all instances of "attempted to read from stolen value".
2023-03-12 14:00:28 +00:00
John Kåre Alsaker
f48ff4a2cf Use Debug for formatting the dep nodes 2023-03-12 09:55:35 +01:00
John Kåre Alsaker
867de8bbb8 Remove graph parameter from try_force_from_dep_node 2023-03-12 09:55:35 +01:00
John Kåre Alsaker
8dd0f20ee6 Optimize dep node backtrace and ignore fatal errors 2023-03-12 09:55:35 +01:00
bors
501ad021b9 Auto merge of #108682 - est31:simplify_dirs, r=davidtwco
Simplify message paths

This makes it easier to open the messages file. Right now I have to first click on the `locales` dir to open it, and then on the `en-US.ftl` file. `Cargo.toml` and `build.rs` files are also in the top level, and I think there should not be more than one file, so a directory isn't really needed. The [chosen strategy for pontoon adoption](https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/pontoon.20and.20next.20steps) is out of tree. Even if this descision is changed in the future, the `messages.ftl` approach is also compatible with non-english translations living in-tree, as long as the non-english translations don't live in the `compiler/rustc_foo/` directories but in different ones. That would also be helpful for grepability purposes.

The commit was the result of automated changes:

```
for p in compiler/rustc_*; do mv $p/locales/en-US.ftl $p/messages.ftl; rmdir $p/locales; done

for p in compiler/rustc_*; do sed -i "s#\.\./locales/en-US.ftl#../messages.ftl#" $p/src/lib.rs; done
```

r? `@davidtwco`
2023-03-12 03:51:21 +00:00
Camille GILLOT
382cc909d5 Make the check for cache opt-in. 2023-03-11 22:41:01 +00:00
Camille GILLOT
1ca103a168 Ensure value is on the on-disk cache before returning. 2023-03-11 22:41:01 +00:00
est31
7e2ecb3cd8 Simplify message paths
This makes it easier to open the messages file while developing on features.

The commit was the result of automatted changes:

for p in compiler/rustc_*; do mv $p/locales/en-US.ftl $p/messages.ftl; rmdir $p/locales; done

for p in compiler/rustc_*; do sed -i "s#\.\./locales/en-US.ftl#../messages.ftl#" $p/src/lib.rs; done
2023-03-11 22:51:57 +01:00
John Kåre Alsaker
42a0aaa934 Remove dep_node_index_of_opt and dep_node_index_of 2023-03-09 08:00:54 +01:00
John Kåre Alsaker
62e4bcb168 Address comments 2023-03-09 08:00:40 +01:00
John Kåre Alsaker
60ed37c2e1 Move dep graph methods to DepGraphData to avoid branches and unwraps 2023-03-09 06:14:34 +01:00
John Kåre Alsaker
955549955f Check that a query has not completed and is not executing before starting it 2023-03-08 07:33:38 +01:00
bors
e3dfeeaa45 Auto merge of #108167 - Zoxc:query-config-instance-slim, r=cjgillot
Make `rustc_query_system` take `QueryConfig` by instance.

This allows for easy switching between virtual tables and specialized instances for queries. It also has the benefit of less turbofish. `QueryStorage` has also been merged with `QueryCache`.

Split out from https://github.com/rust-lang/rust/pull/107937.

r? `@cjgillot`
2023-03-07 18:55:36 +00:00
John Kåre Alsaker
10b08e3c9c Fix a race in the query system 2023-02-28 07:47:58 +01:00
John Kåre Alsaker
3b26d71e04 Avoid implementing Debug for QueryConfig 2023-02-26 23:35:52 +01:00
John Kåre Alsaker
3fd7c4a17d Make rustc_query_system take QueryConfig by instance. 2023-02-26 23:35:47 +01:00
John Kåre Alsaker
dd73080cc0 Don't inline try_execute_query 2023-02-25 06:11:02 +01:00
John Kåre Alsaker
ab5d3fbe7d Add inlining attributes for query system functions 2023-02-25 06:11:02 +01:00
John Kåre Alsaker
a049550c45 Move ensure_sufficient_stack to try_execute_query callers 2023-02-25 06:11:01 +01:00
John Kåre Alsaker
5fa60a5d25 Reduce calls to current_query_job 2023-02-25 06:11:01 +01:00
bors
f0bc76ac41 Auto merge of #91742 - cjgillot:force-backtrace, r=estebank
Print a backtrace when query forcing fails.

The aim of this PR is to help debugging incremental compilation bugs where query forcing panics.
For instance: https://github.com/rust-lang/rust/issues/90682 https://github.com/rust-lang/rust/issues/90697 https://github.com/rust-lang/rust/issues/90715 https://github.com/rust-lang/rust/issues/90739 https://github.com/rust-lang/rust/issues/91401

These bugs happen when the dep-graph attempts to force a dep-node whose fingerprint does not correspond to an actual DefPathHash. PR https://github.com/rust-lang/rust/pull/91741 attempts to hide this bug.

I still don't know how to reproduce these bugs, so I sadly could not test this debugging device.
2023-02-24 23:48:44 +00:00
Dylan DPC
440113ddf6
Rollup merge of #108169 - Zoxc:query-key-copy, r=cjgillot
Make query keys `Copy`

This regressed compiler performance locally, so I'm curious what perf will say about it.

<table><tr><td rowspan="2">Benchmark</td><td colspan="1"><b>Before</b></th><td colspan="2"><b>After</b></th></tr><tr><td align="right">Time</td><td align="right">Time</td><td align="right">%</th></tr><tr><td>🟣 <b>clap</b>:check</td><td align="right">1.7566s</td><td align="right">1.7657s</td><td align="right"> 0.52%</td></tr><tr><td>🟣 <b>hyper</b>:check</td><td align="right">0.2572s</td><td align="right">0.2578s</td><td align="right"> 0.20%</td></tr><tr><td>🟣 <b>regex</b>:check</td><td align="right">0.9863s</td><td align="right">0.9900s</td><td align="right"> 0.37%</td></tr><tr><td>🟣 <b>syn</b>:check</td><td align="right">1.6018s</td><td align="right">1.6073s</td><td align="right"> 0.34%</td></tr><tr><td>🟣 <b>syntex_syntax</b>:check</td><td align="right">6.2493s</td><td align="right">6.2920s</td><td align="right"> 0.68%</td></tr><tr><td>Total</td><td align="right">10.8512s</td><td align="right">10.9127s</td><td align="right"> 0.57%</td></tr><tr><td>Summary</td><td align="right">1.0000s</td><td align="right">1.0042s</td><td align="right"> 0.42%</td></tr></table>
2023-02-24 12:02:41 +05:30
bors
b869e84e58 Auto merge of #103042 - davidtwco:translation-distributed-ftl, r=oli-obk
errors: generate typed identifiers in each crate

Instead of loading the Fluent resources for every crate in `rustc_error_messages`, each crate generates typed identifiers for its own diagnostics and creates a static which are pulled together in the `rustc_driver` crate and provided to the diagnostic emitter.

There are advantages and disadvantages to this change..

#### Advantages
- Changing a diagnostic now only recompiles the crate for that diagnostic and those crates that depend on it, rather than `rustc_error_messages` and all crates thereafter.
- This approach can be used to support first-party crates that want to supply translatable diagnostics (e.g. `rust-lang/thorin` in https://github.com/rust-lang/rust/pull/102612#discussion_r985372582, cc `@JhonnyBillM)`
- We can extend this a little so that tools built using rustc internals (like clippy or rustdoc) can add their own diagnostic resources (much more easily than those resources needing to be available to `rustc_error_messages`)

#### Disadvantages
- Crates can only refer to the diagnostic messages defined in the current crate (or those from dependencies), rather than all diagnostic messages.
- `rustc_driver` (or some other crate we create for this purpose) has to directly depend on *everything* that has error messages.
  - It already transitively depended on all these crates.

#### Pending work
- [x] I don't know how to make `rustc_codegen_gcc`'s translated diagnostics work with this approach - because `rustc_driver` can't depend on that crate and so can't get its resources to provide to the diagnostic emission. I don't really know how the alternative codegen backends are actually wired up to the compiler at all.
- [x] Update `triagebot.toml` to track the moved FTL files.

r? `@compiler-errors`
cc #100717
2023-02-22 15:14:22 +00:00
David Wood
d1fcf61117 errors: generate typed identifiers in each crate
Instead of loading the Fluent resources for every crate in
`rustc_error_messages`, each crate generates typed identifiers for its
own diagnostics and creates a static which are pulled together in the
`rustc_driver` crate and provided to the diagnostic emitter.

Signed-off-by: David Wood <david.wood@huawei.com>
2023-02-22 09:15:53 +00:00
bors
bd4a96a12d Auto merge of #108300 - oli-obk:elsa, r=eholk
Use a lock-free datastructure for source_span

follow up to the perf regression in https://github.com/rust-lang/rust/pull/105462

The main regression is likely the CStore, but let's evaluate the perf impact of this on its own
2023-02-22 08:44:30 +00:00
John Kåre Alsaker
056c5b3b57 Make query keys Copy 2023-02-21 22:15:46 +01:00
Oli Scherer
decfb4d123 Use a lock-free datastructure for source_span 2023-02-21 08:38:24 +00:00
bors
3fee48c161 Auto merge of #104754 - nnethercote:more-ThinVec-in-ast, r=the8472
Use `ThinVec` more in the AST

r? `@ghost`
2023-02-21 07:02:57 +00:00
Nicholas Nethercote
06228d6e93 Upgrade thin-vec from 0.2.9 to 0.2.12.
Because 0.2.10 added supports for `ThinVec::splice`, and 0.2.12 is the
latest release.
2023-02-21 11:51:55 +11:00
Oli Scherer
6924e3c374 Make untracked.source_span lockable so that resolution can still write to it when using TyCtxt 2023-02-20 15:28:58 +00:00
Oli Scherer
ade3dceb38 Make untracked.cstore lockable so that resolution can still write to it when using TyCtxt 2023-02-20 15:28:58 +00:00
bors
f77f4d55bd Auto merge of #107542 - compiler-errors:param-envs-with-inference-vars-are-cursed, r=jackh726
Don't call `with_reveal_all_normalized` in const-eval when `param_env` has inference vars in it

**what:** This slightly shifts the order of operations from an existing hack:

5b6ed253c4/compiler/rustc_middle/src/ty/consts/kind.rs (L225-L230)

in order to avoid calling a tcx query (`TyCtxt::reveal_opaque_types_in_bounds`, via `ParamEnv::with_reveal_all_normalized`) when a param-env has inference variables in it.

**why:** This allows us to enable fingerprinting of query keys/values outside of incr-comp in deubg mode, to make sure we catch other places where we're passing infer vars and other bad things into query keys. Currently that (bbf33836b9) crashes because we introduce inference vars into a param-env in the blanket-impl finder in rustdoc 😓

5b6ed253c4/src/librustdoc/clean/blanket_impl.rs (L43)

See the CI failure here: https://github.com/rust-lang/rust/actions/runs/4058194838/jobs/6984834619
2023-02-18 23:43:42 +00:00
Oli Scherer
b4182d240a Don't allow evaluating queries that were fed in a previous compiler run 2023-02-17 16:16:01 +00:00
bors
b5c8c329a7 Auto merge of #108058 - Zoxc:query-ctxtx-byval, r=cjgillot
Pass `DepContext` and `QueryContext` by value when practical

This removes some indirections for a minor performance improvement.

<table><tr><td rowspan="2">Benchmark</td><td colspan="1"><b>Before</b></th><td colspan="2"><b>After</b></th></tr><tr><td align="right">Time</td><td align="right">Time</td><td align="right">%</th></tr><tr><td>🟣 <b>clap</b>:check</td><td align="right">1.8294s</td><td align="right">1.8255s</td><td align="right"> -0.21%</td></tr><tr><td>🟣 <b>hyper</b>:check</td><td align="right">0.2667s</td><td align="right">0.2669s</td><td align="right"> 0.07%</td></tr><tr><td>🟣 <b>regex</b>:check</td><td align="right">1.0080s</td><td align="right">1.0063s</td><td align="right"> -0.17%</td></tr><tr><td>🟣 <b>syn</b>:check</td><td align="right">1.6335s</td><td align="right">1.6295s</td><td align="right"> -0.24%</td></tr><tr><td>🟣 <b>syntex_syntax</b>:check</td><td align="right">6.3633s</td><td align="right">6.3344s</td><td align="right"> -0.45%</td></tr><tr><td>Total</td><td align="right">11.1009s</td><td align="right">11.0627s</td><td align="right"> -0.34%</td></tr><tr><td>Summary</td><td align="right">1.0000s</td><td align="right">0.9980s</td><td align="right"> -0.20%</td></tr></table>
2023-02-17 08:23:53 +00:00
bors
947b696ce0 Auto merge of #107833 - Zoxc:arena-query-clean, r=cjgillot
Factor query arena allocation out from query caches

This moves the logic for arena allocation out from the query caches into conditional code in the query system. The specialized arena caches are removed. A new `QuerySystem` type is added in `rustc_middle` which contains the arenas, providers and query caches.

Performance seems to be slightly regressed:
<table><tr><td rowspan="2">Benchmark</td><td colspan="1"><b>Before</b></th><td colspan="2"><b>After</b></th></tr><tr><td align="right">Time</td><td align="right">Time</td><td align="right">%</th></tr><tr><td>🟣 <b>clap</b>:check</td><td align="right">1.8053s</td><td align="right">1.8109s</td><td align="right"> 0.31%</td></tr><tr><td>🟣 <b>hyper</b>:check</td><td align="right">0.2600s</td><td align="right">0.2597s</td><td align="right"> -0.10%</td></tr><tr><td>🟣 <b>regex</b>:check</td><td align="right">0.9973s</td><td align="right">1.0006s</td><td align="right"> 0.34%</td></tr><tr><td>🟣 <b>syn</b>:check</td><td align="right">1.6048s</td><td align="right">1.6051s</td><td align="right"> 0.02%</td></tr><tr><td>🟣 <b>syntex_syntax</b>:check</td><td align="right">6.2992s</td><td align="right">6.3159s</td><td align="right"> 0.26%</td></tr><tr><td>Total</td><td align="right">10.9664s</td><td align="right">10.9922s</td><td align="right"> 0.23%</td></tr><tr><td>Summary</td><td align="right">1.0000s</td><td align="right">1.0017s</td><td align="right"> 0.17%</td></tr></table>

Incremental performance is a bit worse:
<table><tr><td rowspan="2">Benchmark</td><td colspan="1"><b>Before</b></th><td colspan="2"><b>After</b></th></tr><tr><td align="right">Time</td><td align="right">Time</td><td align="right">%</th></tr><tr><td>🟣 <b>clap</b>:check:initial</td><td align="right">2.2103s</td><td align="right">2.2247s</td><td align="right"> 0.65%</td></tr><tr><td>🟣 <b>hyper</b>:check:initial</td><td align="right">0.3335s</td><td align="right">0.3349s</td><td align="right"> 0.41%</td></tr><tr><td>🟣 <b>regex</b>:check:initial</td><td align="right">1.2597s</td><td align="right">1.2650s</td><td align="right"> 0.42%</td></tr><tr><td>🟣 <b>syn</b>:check:initial</td><td align="right">2.0521s</td><td align="right">2.0613s</td><td align="right"> 0.45%</td></tr><tr><td>🟣 <b>syntex_syntax</b>:check:initial</td><td align="right">7.8275s</td><td align="right">7.8583s</td><td align="right"> 0.39%</td></tr><tr><td>Total</td><td align="right">13.6832s</td><td align="right">13.7442s</td><td align="right"> 0.45%</td></tr><tr><td>Summary</td><td align="right">1.0000s</td><td align="right">1.0046s</td><td align="right"> 0.46%</td></tr></table>

It does seem like LLVM optimizers struggle a bit with the current state of the query system.

Based on top of https://github.com/rust-lang/rust/pull/107782 and https://github.com/rust-lang/rust/pull/107802.

r? `@cjgillot`
2023-02-16 22:10:10 +00:00
Maybe Waffle
8751fa1a9a if $c:expr { Some($r:expr) } else { None } =>> $c.then(|| $r) 2023-02-16 15:26:00 +00:00
John Kåre Alsaker
caf29b2727 Remove parallel compiler fix 2023-02-16 14:55:05 +01:00
John Kåre Alsaker
067bf2ac13 Move provider fields back to rustc_query_impl 2023-02-16 14:55:05 +01:00
John Kåre Alsaker
a51a20531d Factor query arena allocation out from query caches 2023-02-16 14:54:53 +01:00
Matthias Krüger
e087f61075 don't clone types that are copy 2023-02-15 23:34:25 +01:00
John Kåre Alsaker
b3a4fe7d4e Pass DepContext and QueryContext by value when practical 2023-02-14 17:21:18 +01:00
John Kåre Alsaker
80d265240b Create a single value cache for the () query key 2023-02-11 23:38:01 +01:00
bors
9433ba6394 Auto merge of #107644 - Zoxc:query-cache-tweak, r=cjgillot
Remove QueryStorage::store_nocache

This method was added in https://github.com/rust-lang/rust/pull/70674 but it doesn't seem to serve any purpose.
2023-02-08 16:59:18 +00:00
John Kåre Alsaker
d459840633 Remove QueryStorage::store_nocache 2023-02-07 17:36:01 +01:00
John Kåre Alsaker
9539737008 Make an optimal cold path for query_cache_hit 2023-02-06 15:22:12 +01:00
John Kåre Alsaker
e60ccfc6a9 Don't inline query_cache_hit to reduce code size of the query hot path. 2023-02-06 13:52:17 +01:00
Camille GILLOT
635ff8e2a8 Support parallel compiler. 2023-02-04 15:56:50 +00:00
Camille GILLOT
128f2224af Remove OnHit callback from query caches.
This is not useful now that query results are `Copy`.
2023-02-04 15:21:21 +00:00
Michael Goulet
bbf33836b9 Fingerprint even when incr comp is disabled in debug mode 2023-01-31 20:43:29 +00:00
Camille GILLOT
870dd1678e Use OnDrop. 2023-01-28 12:38:22 +00:00
Camille GILLOT
e33e2d6e9e Attempt to reduce perf impact. 2023-01-28 11:47:15 +00:00
Camille GILLOT
87644d85a2 Print a backtrace when query forcing fails. 2023-01-28 11:42:46 +00:00
Maybe Waffle
6a28fb42a8 Remove double spaces after dots in comments 2023-01-17 08:09:33 +00:00
nils
fd7a159710 Fix uninlined_format_args for some compiler crates
Convert all the crates that have had their diagnostic migration
completed (except save_analysis because that will be deleted soon and
apfloat because of the licensing problem).
2023-01-05 19:01:12 +01:00
bors
d6f99e535a Auto merge of #106307 - Nilstrieb:dynamic->static, r=cjgillot
Abolish `QueryVTable` in favour of more assoc items on `QueryConfig`

This may introduce additional mono _but_ may help const fold things better and especially may help not constructing a `QueryVTable` anymore which is cheap but not free.
2023-01-02 20:12:16 +00:00
Nilstrieb
9fe4efe115 Abolish QueryVTable in favour of more assoc items on QueryConfig
This may introduce additional mono _but_ may help const fold things
better and especially may help not constructing a `QueryVTable` anymore
which is cheap but not free.
2023-01-02 20:22:19 +01:00
Camille GILLOT
4719cb3036 Ignore span references from diagnostics.
The diagnostics are replayed at the correct place anyway.
2022-12-25 18:48:42 +00:00
Matthias Krüger
d23cb738d2
Rollup merge of #105975 - jeremystucki:rustc-remove-needless-lifetimes, r=eholk
rustc: Remove needless lifetimes
2022-12-24 00:31:41 +01:00
bors
c2ff8ad035 Auto merge of #105550 - gimbles:master, r=Nilstrieb
Use `DepKind` instead of `&'static str` in `QueryStackFrame`

`@rustbot` author

Fixes #105168
2022-12-23 16:57:21 +00:00
gimbles
f8b30084ac Use DepKind instead of &str 2022-12-23 18:39:49 +05:30
Jeremy Stucki
3dde32ca97
rustc: Remove needless lifetimes 2022-12-20 22:10:40 +01:00
Nilstrieb
8bfd6450c7 A few small cleanups for newtype_index
Remove the `..` from the body, only a few invocations used it and it's
inconsistent with rust syntax.

Use `;` instead of `,` between consts. As the Rust syntax gods inteded.
2022-12-18 21:47:28 +01:00
Nilstrieb
91c3c2040c Make #[max] an attribute in newtype_index 2022-12-18 21:22:14 +01:00
bors
fbf8b937b4 Auto merge of #105233 - mejrs:always_eager, r=estebank
Always evaluate vecs of subdiagnostics eagerly

See https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/.23100717.20lists!/near/310186705 for context
2022-12-14 16:16:50 +00:00
KaDiWa
9bc69925cb
compiler: remove unnecessary imports and qualified paths 2022-12-10 18:45:34 +01:00
Oli Scherer
75ff5c7dd3 Fold Definitions into the untracked data 2022-12-09 14:59:39 +00:00
Oli Scherer
1c1d3570ee Move the untracked cstore and source_span into a struct 2022-12-09 14:53:24 +00:00
Oli Scherer
f693b7848e feed resolver_for_lowering instead of storing it in a field 2022-12-05 10:58:55 +00:00
mejrs
a7838d8bd7 Always evaluate vecs of subdiagnostics eagerly 2022-12-04 01:13:21 +01:00
Oli Scherer
ab75d777de Fill in def_span when creating def ids.
This makes sure that ICEing because of def ids created outside of ast lowering will be able to produce a query backtrace and not cause a double panic because of trying to call the  `def_span` query
2022-12-01 10:33:28 +00:00
Camille GILLOT
9f2c6b0b09 Sanity check computed value for feeable queries. 2022-11-29 18:42:23 +00:00
Camille GILLOT
ee7a9a8641 Expand hash check. 2022-11-29 18:41:55 +00:00
Camille GILLOT
5471381349 Allow to set a query's result as a side effect. 2022-11-29 18:40:59 +00:00
Camille GILLOT
ca42dd6716 Sanity check fingerprints in the dep-graph. 2022-11-29 18:39:03 +00:00
Maybe Waffle
1d42936b18 Prefer doc comments over //-comments in compiler 2022-11-27 11:19:04 +00:00
Matthias Krüger
4843946a10
Rollup merge of #104780 - BoxyUwU:error_reported_not_be_bad, r=oli-obk
make `error_reported` check for delayed bugs

Fixes #104768

`error_reported()` was only checking if there were errors emitted, not for `delay_bug`s which can also be a source of `ErrorGuaranteed`. I assume the same is true of `lint_err_count` but i dont know
2022-11-24 21:34:54 +01:00
Boxy
72d8879c29 make error_reported check for delayed bugs 2022-11-24 11:12:46 +00:00
bors
341d8b8a2c Auto merge of #103808 - cjgillot:vec-cache, r=TaKO8Ki
Use an IndexVec to cache queries with index-like key

Revival of an old idea. Let's see if it has more effect.

r? `@ghost`
2022-11-24 06:32:23 +00:00
Camille GILLOT
d47424b833 Hash spans when interning. 2022-11-11 13:02:37 +00:00
Nilstrieb
6d26ea86da
Rename Ctxt and CTX to Tcx and Qcx
This makes it consistent and clear which context is used.
2022-11-06 13:25:06 +01:00
Nilstrieb
16558bd267
Rename tcx to qcx when it's a QueryContext 2022-11-06 13:25:06 +01:00
Nilstrieb
91971f293c
Improve tracing logging 2022-11-06 13:25:06 +01:00
Nilstrieb
3da576804a
Rename incremental_verify_ich_cold to incremental_verify_ich_failed 2022-11-06 13:10:35 +01:00
Nilstrieb
36be251a35
Merge QueryDescription into QueryConfig
`QueryDescription` has gone through a lot of refactoring and doesn't
make sense anymore.
2022-11-05 16:24:13 +01:00
Michael Howell
03968a802c rustdoc: use ThinVec for cleaned generics 2022-11-02 16:17:22 -07:00
Camille GILLOT
bc9a202a22 Use Key impl to select cache. 2022-11-01 17:07:55 +00:00
Camille GILLOT
15d2f62bd2 Use VecCache for LocalDefId. 2022-11-01 17:02:51 +00:00
Camille GILLOT
aee4d132e7 Remove CacheSelector. 2022-11-01 17:02:51 +00:00
Nilstrieb
c65ebae221
Migrate all diagnostics 2022-10-23 10:09:44 +02:00
nils
24ce4cfa20
Remove the describe method from the QueryDescription trait
It was called directly already, but now it's even more useless since it
just forwards to the free function. Call it directly.
2022-10-14 22:35:56 +02:00
David Wood
113e94369c query_system: finish migration
Using eager translation, migrate the remaining repeated cycle stack
diagnostic.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-10 14:20:16 +01:00
David Wood
b4ac26289f errors: AddToDiagnostic::add_to_diagnostic_with
`AddToDiagnostic::add_to_diagnostic_with` is similar to the previous
`AddToDiagnostic::add_to_diagnostic` but takes a function that can be
used by the caller to modify diagnostic messages originating from the
subdiagnostic (such as performing translation eagerly).

`add_to_diagnostic` now just calls `add_to_diagnostic_with` with an
empty closure.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-10 14:20:16 +01:00
Cameron Steffen
ff940db666 Rewrite representability 2022-10-07 09:33:46 -05:00
bors
0152393048 Auto merge of #99324 - reez12g:issue-99144, r=jyn514
Enable doctests in compiler/ crates

Helps with https://github.com/rust-lang/rust/issues/99144
2022-10-06 03:01:57 +00:00
Camille GILLOT
6019cbbfd3 Allow query system to recover a HirId. 2022-10-01 15:58:42 +02:00
Santiago Pastorino
b2bef02bcd
create def ids for impl traits during ast lowering 2022-09-30 15:12:01 -03:00
reez12g
9a4c5abe45 Remove from compiler/ crates 2022-09-29 16:49:04 +09:00
Pietro Albini
3975d55d98
remove cfg(bootstrap) 2022-09-26 10:14:45 +02:00
Joshua Nelson
00cde6d4b9 Move the codegen_unit debug assert from rustc_query_system to query_impl
This allows removing a function from the `DepKind` trait.
2022-09-25 12:08:36 -05:00
Joshua Nelson
ccc8d000f2 Move some more code from rustc_middle to rustc_query_system 2022-09-25 12:08:36 -05:00
Joshua Nelson
f3f91bb514 Move functions on DepKindStruct from rustc_middle to rustc_query_system 2022-09-25 12:07:17 -05:00
Joshua Nelson
93a0fb190e Move DepKindStruct from rustc_middle to rustc_query_system 2022-09-25 11:56:23 -05:00
Takayuki Maeda
8fe936099a separate definitions and HIR owners
fix a ui test

use `into`

fix clippy ui test

fix a run-make-fulldeps test

implement `IntoQueryParam<DefId>` for `OwnerId`

use `OwnerId` for more queries

change the type of `ParentOwnerIterator::Item` to `(OwnerId, OwnerNode)`
2022-09-24 23:21:19 +09:00
Camille GILLOT
fc43df0333 Revert "Auto merge of #101620 - cjgillot:compute_lint_levels_by_def, r=oli-obk"
This reverts commit 2cb9a65684, reversing
changes made to 750bd1a7ff.
2022-09-22 19:36:11 +02:00
Jhonny Bill Mena
e52e2344dc FIX - adopt new Diagnostic naming in newly migrated modules
FIX - ambiguous Diagnostic link in docs

UPDATE - rename diagnostic_items to IntoDiagnostic and AddToDiagnostic

[Gardening] FIX - formatting via `x fmt`

FIX - rebase conflicts. NOTE: Confirm wheather or not we want to handle TargetDataLayoutErrorsWrapper this way

DELETE - unneeded allow attributes in Handler method

FIX - broken test

FIX - Rebase conflict

UPDATE - rename residual _SessionDiagnostic and fix LintDiag link
2022-09-21 11:43:22 -04:00
Jhonny Bill Mena
5f91719f75 UPDATE - rename SessionSubdiagnostic macro to Subdiagnostic
Also renames:
- sym::AddSubdiagnostic to sym:: Subdiagnostic
- rustc_diagnostic_item = "AddSubdiagnostic" to rustc_diagnostic_item = "Subdiagnostic"
2022-09-21 11:39:53 -04:00
Jhonny Bill Mena
a3396b2070 UPDATE - rename DiagnosticHandler macro to Diagnostic 2022-09-21 11:39:53 -04:00
Jhonny Bill Mena
19b348fed4 UPDATE - rename DiagnosticHandler trait to IntoDiagnostic 2022-09-21 11:39:52 -04:00
Jhonny Bill Mena
5b8152807c UPDATE - move SessionDiagnostic from rustc_session to rustc_errors 2022-09-21 11:39:52 -04:00
Matthias Krüger
4757d2d57e
Rollup merge of #101801 - SparrowLii:query_depth_note, r=estebank
add note for `layout_of` when query depth overflows

Fixes #101747
Added `try_find_layout_root` function to add a note for `layout_of` when query depth overflows. This would make the error in #101747 look like this:
```
error: queries overflow the depth limit!
   |
note: Query depth increased by 66 when computing layout of `core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<alloc::boxed::Box<alloc::string::String>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>`!
  --> D:\rust-backup\parallel_rust\query_depth.rs:40:1
   |
40 | fn main() {
   | ^^^^^^^^^

error: aborting due to previous error
```

cc ``@semicoleon``
2022-09-17 19:27:06 +02:00
est31
173eb6f407 Only enable the let_else feature on bootstrap
On later stages, the feature is already stable.

Result of running:

rg -l "feature.let_else" compiler/ src/librustdoc/ library/ | xargs sed -s -i "s#\\[feature.let_else#\\[cfg_attr\\(bootstrap, feature\\(let_else\\)#"
2022-09-15 21:06:45 +02:00
SparrowLii
89fd6ae458 correct span, add help message and add UI test when query depth overflows 2022-09-15 16:05:44 +08:00
SparrowLii
44506f38e0 add note for layout_of when query depth overflows 2022-09-15 16:05:00 +08:00
Camille GILLOT
bd45139cb0 Allow query system to recover a HirId. 2022-09-14 19:04:13 +02:00
Joshua Nelson
0a9d7dbca2 Remove unnecessary TRY_LOAD_FROM_DISK constant 2022-09-09 20:24:02 -05:00
Joshua Nelson
7208bdee33 Remove cache_on_disk from QueryVTable
This is not only simpler, but removes a generic function and unwrap.
I have hope it will see compile time and bootstrap time improvements.
2022-09-09 20:21:58 -05:00
Dylan DPC
7f46d7313c
Rollup merge of #101549 - eholk:type-ir-derive-hashstable_generic, r=jackh726
Use HashStable_Generic in rustc_type_ir

A lot of the types in this crate implemented HashStable directly to avoid circular dependencies. One way around that is to use HashStable_Generic. We adopt that here to avoid a lot of boilerplate.

This doesn't update all the types, because some would require `I: Interner + HashStable`.

r? `@cjgillot`
2022-09-08 11:55:10 +05:30
bors
4af35b8e30 Auto merge of #101303 - jyn514:jnelson/handle-cycle-enum, r=cjgillot
Make `HandleCycleError` an enum instead of a macro-generated closure

Helps with https://github.com/rust-lang/rust/issues/96524. Based on https://github.com/rust-lang/rust/pull/100943 to avoid merge conflicts, so it looks larger than it is (only the last commit is relevant).

cc https://rust-lang.zulipchat.com/#narrow/stream/241847-t-compiler.2Fwg-incr-comp/topic/Moving.20.60Value.60.20to.20rustc_query_system.20.2396524

r? `@cjgillot`
2022-09-08 02:21:16 +00:00
Eric Holk
578fc49fc1 Use HashStable_Generic in rustc_type_ir
A lot of the types in this crate implemented HashStable directly to
avoid circular dependencies. One way around that is to use
HashStable_Generic. We adopt that here to avoid a lot of boilerplate.

This doesn't update all the types, because some would require
`I: Interner + HashStable`.
2022-09-07 16:05:06 -07:00
Joshua Nelson
4856affd90 Make HandleCycleError an enum instead of a macro-generated closure
- Add a `HandleCycleError` enum to rustc_query_system, along with a `handle_cycle_error` function
- Move `Value` to rustc_query_system, so `handle_cycle_error` can use it
- Move the `Value` impls from rustc_query_impl to rustc_middle. This is necessary due to orphan rules.
2022-09-06 19:26:08 -05:00
Jhonny Bill Mena
321e60bf34 UPDATE - into_diagnostic to take a Handler instead of a ParseSess
Suggested by the team in this Zulip Topic https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/.23100717.20SessionDiagnostic.20on.20Handler

Handler already has almost all the capabilities of ParseSess when it comes to diagnostic emission, in this migration we only needed to add the ability to access source_map from the emitter in order to get a Snippet and the start_point. Not sure if this is the best way to address this gap
2022-09-05 02:18:45 -04:00
Joshua Nelson
4e09a13bb8 Don't create two new closures for each query
- Parameterize DepKindStruct over `'tcx`

    This allows passing in an invariant function pointer in `query_callback`,
    rather than having to try and make it work for any lifetime.

- Add a new `execute_query` function to `QueryDescription` so we can call `tcx.$name` without needing to be in a macro context
2022-09-01 18:47:54 -05:00
bors
eac6c33bc6 Auto merge of #100869 - nnethercote:replace-ThinVec, r=spastorino
Replace `rustc_data_structures::thin_vec::ThinVec` with `thin_vec::ThinVec`

`rustc_data_structures::thin_vec::ThinVec` looks like this:
```
pub struct ThinVec<T>(Option<Box<Vec<T>>>);
```
It's just a zero word if the vector is empty, but requires two
allocations if it is non-empty. So it's only usable in cases where the
vector is empty most of the time.

This commit removes it in favour of `thin_vec::ThinVec`, which is also
word-sized, but stores the length and capacity in the same allocation as
the elements. It's good in a wider variety of situation, e.g. in enum
variants where the vector is usually/always non-empty.

The commit also:
- Sorts some `Cargo.toml` dependency lists, to make additions easier.
- Sorts some `use` item lists, to make additions easier.
- Changes `clean_trait_ref_with_bindings` to take a
  `ThinVec<TypeBinding>` rather than a `&[TypeBinding]`, because this
  avoid some unnecessary allocations.

r? `@spastorino`
2022-09-01 08:01:06 +00:00
Li Yuanheng
7ce59ebf49 SessionDiagnostic for QueryOverflow error 2022-08-31 19:43:23 +08:00
Li Yuanheng
166aef90fb delete leftover comment 2022-08-31 19:43:23 +08:00
Yuanheng Li
ac638c1f5f use derive proc macro to impl SessionDiagnostic
fixes `SessionSubdiagnostic` to accept multiple attributes
emitting list of fluent message remains unresolved
2022-08-31 19:43:12 +08:00
Li Yuanheng
d7e07c0b6b link related issue to FIXME
Co-authored-by: David Wood <agile.lion3441@fuligin.ink>
2022-08-31 19:33:51 +08:00
Yuanheng Li
b8075e4550 migrate rustc_query_system to use SessionDiagnostic
with manual impl SessionDiagnostic
2022-08-31 19:33:51 +08:00
Nicholas Nethercote
b38106b6d8 Replace rustc_data_structures::thin_vec::ThinVec with thin_vec::ThinVec.
`rustc_data_structures::thin_vec::ThinVec` looks like this:
```
pub struct ThinVec<T>(Option<Box<Vec<T>>>);
```
It's just a zero word if the vector is empty, but requires two
allocations if it is non-empty. So it's only usable in cases where the
vector is empty most of the time.

This commit removes it in favour of `thin_vec::ThinVec`, which is also
word-sized, but stores the length and capacity in the same allocation as
the elements. It's good in a wider variety of situation, e.g. in enum
variants where the vector is usually/always non-empty.

The commit also:
- Sorts some `Cargo.toml` dependency lists, to make additions easier.
- Sorts some `use` item lists, to make additions easier.
- Changes `clean_trait_ref_with_bindings` to take a
  `ThinVec<TypeBinding>` rather than a `&[TypeBinding]`, because this
  avoid some unnecessary allocations.
2022-08-29 15:42:13 +10:00
SparrowLii
cbc6bd2019 add depth_limit in QueryVTable 2022-08-24 09:42:12 +08:00
bors
14a459bf37 Auto merge of #100441 - nnethercote:shrink-ast-Attribute, r=petrochenkov
Shrink `ast::Attribute`.

r? `@ghost`
2022-08-16 07:54:22 +00:00
Nicholas Nethercote
85a6cd6a47 Shrink ast::Attribute. 2022-08-16 11:10:13 +10:00
Camille GILLOT
5d75ca5ef4 Remove unused hashing infra. 2022-08-07 17:51:55 +02:00
Camille GILLOT
8a4cbcf220 Derive HashStable for HIR Expr and Ty. 2022-08-07 17:30:45 +02:00
Camille GILLOT
b0047c18cb Stop forcing the hashing of bodies in types and expressions. 2022-08-07 17:30:45 +02:00
Camille GILLOT
2134dd3b48 Remove useless closure. 2022-07-29 22:11:23 +02:00
Camille GILLOT
6733bc3066 Remove guess_head_span. 2022-07-28 23:14:04 +02:00
Ralf Jung
3dad266f40 consistently use VTable over Vtable (matching stable stdlib API RawWakerVTable) 2022-07-20 17:12:07 -04:00
Joshua Nelson
3c9765cff1 Rename debugging_opts to unstable_opts
This is no longer used only for debugging options (e.g. `-Zoutput-width`, `-Zallow-features`).
Rename it to be more clear.
2022-07-13 17:47:06 -05:00
bors
86b8dd5389 Auto merge of #99028 - tmiasko:inline, r=estebank
Miscellaneous inlining improvements

Add `#[inline]` to a few trivial non-generic methods from a perf report
that otherwise wouldn't be candidates for inlining.
2022-07-09 04:34:51 +00:00
Tomasz Miąsko
87374de3ad Miscellaneous inlining improvements
Add `#[inline]` to a few trivial non-generic methods from a perf report
that otherwise wouldn't be candidates for inlining.
2022-07-07 22:20:08 +02:00
bors
0f573a0c54 Auto merge of #95573 - cjgillot:lower-query, r=michaelwoerister
Make lowering a query

Split from https://github.com/rust-lang/rust/pull/88186.

This PR refactors the relationship between lowering and the resolver outputs in order to make lowering itself a query.
In a first part, lowering is changed to avoid modifying resolver outputs, by maintaining its own data structures for creating new `NodeId`s and so.

Then, the `TyCtxt` is modified to allow creating new `LocalDefId`s from inside it. This is done by:
- enclosing `Definitions` in a lock, so as to allow modification;
- creating a query `register_def` whose purpose is to declare a `LocalDefId` to the query system.

See `TyCtxt::create_def` and `TyCtxt::iter_local_def_id` for more detailed explanations of the design.
2022-07-07 18:14:44 +00:00
Camille GILLOT
e912c8dfe0 Use a dedicated DepKind for the forever-red node. 2022-07-06 23:20:12 +02:00
Camille GILLOT
15530a1c84 Create a forever red node and use it to force side effects. 2022-07-06 23:11:44 +02:00
Camille GILLOT
250c71b85d Make AST lowering a query. 2022-07-06 23:04:55 +02:00
Camille GILLOT
43bb31b954 Allow to create definitions inside the query system. 2022-07-06 22:50:55 +02:00
David Wood
8371a036ea incr: cache dwarf objects in work products
Cache DWARF objects alongside object files in work products when those
exist so that DWARF object files are available for thorin in packed mode
in incremental scenarios.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-06 11:15:13 +01:00
bors
8c52a83c45 Auto merge of #98570 - SparrowLii:deadlock, r=cjgillot
get rid of `tcx` in deadlock handler when parallel compilation

This is a very obscure and hard-to-trace problem that affects thread scheduling. If we copy `tcx` to the deadlock handler thread, it will perform unpredictable behavior and cause very weird problems when executing `try_collect_active_jobs`(For example, the deadlock handler thread suddenly preempts the content of the blocked worker thread and executes the unknown judgment branch, like #94654).
Fortunately we can avoid this behavior by precomputing `query_map`. This change fixes the following ui tests failure on my environment when set `parallel-compiler = true`:
```
    [ui] src/test\ui\async-await\no-const-async.rs
    [ui] src/test\ui\infinite\infinite-struct.rs
    [ui] src/test\ui\infinite\infinite-tag-type-recursion.rs
    [ui] src/test\ui\issues\issue-3008-1.rs
    [ui] src/test\ui\issues\issue-3008-2.rs
    [ui] src/test\ui\issues\issue-32326.rs
    [ui] src/test\ui\issues\issue-57271.rs
    [ui] src/test\ui\issues\issue-72554.rs
    [ui] src/test\ui\parser\fn-header-semantic-fail.rs
    [ui] src/test\ui\union\union-nonrepresentable.rs
```

Updates #75760
Fixes #94654
2022-07-03 02:05:14 +00:00
SparrowLii
fbca21edd2 get rid of tcx in deadlock handler when parallel compilation 2022-06-29 10:02:30 +08:00
Nicholas Nethercote
7c40661ddb Update smallvec to 1.8.1.
This pulls in https://github.com/servo/rust-smallvec/pull/282, which
gives some small wins for rustc.
2022-06-27 08:48:55 +10:00
Gary Guo
8b7299dd12 Remove likely! and unlikely! macro from compiler 2022-06-18 04:52:11 +01:00
bors
3a8b0144c8 Auto merge of #98106 - cjgillot:split-definitions, r=michaelwoerister
Split up `Definitions` and `ResolverAstLowering`.

Split off https://github.com/rust-lang/rust/pull/95573

r? `@michaelwoerister`
2022-06-17 10:00:11 +00:00
Nicholas Nethercote
bb02cc47c4 Move finish out of the Encoder trait.
This simplifies things, but requires making `CacheEncoder` non-generic.

(This was previously merged as commit 4 in #94732 and then was reverted
in #97905 because it caused a perf regression.)
2022-06-16 16:20:32 +10:00
bors
ebe184a693 Auto merge of #98084 - nnethercote:rm-thread-local-IGNORED_ATTRIBUTES, r=michaelwoerister
Remove thread-local `IGNORED_ATTRIBUTES`.

It's just a copy of the read-only global `ich::IGNORED_ATTRIBUTES`, and
can be removed without any effect.

r? `@michaelwoerister`
2022-06-15 08:20:19 +00:00
Yuki Okushi
97b9347c93
Rollup merge of #98083 - nnethercote:rename-Encoder, r=bjorn3
Rename rustc_serialize::opaque::Encoder as MemEncoder.

This avoids the name clash with `rustc_serialize::Encoder` (a trait),
and allows lots qualifiers to be removed and imports to be simplified
(e.g. fewer `as` imports).

(This was previously merged as commit 5 in #94732 and then was reverted
in #97905 because of a perf regression caused by commit 4 in #94732.)

r? ```@bjorn3```
2022-06-15 12:02:04 +09:00
Camille GILLOT
34e4d72929 Separate source_span and expn_that_defined from Definitions. 2022-06-14 22:45:51 +02:00
Nicholas Nethercote
a2801625cd Remove thread-local IGNORED_ATTRIBUTES.
It's just a copy of the read-only global `ich::IGNORED_ATTRIBUTES`, and
can be removed without any effect.
2022-06-14 15:20:54 +10:00
Nicholas Nethercote
abe45a9ffa Rename rustc_serialize::opaque::Encoder as MemEncoder.
This avoids the name clash with `rustc_serialize::Encoder` (a trait),
and allows lots qualifiers to be removed and imports to be simplified
(e.g. fewer `as` imports).

(This was previously merged as commit 5 in #94732 and then was reverted
in #97905 because of a perf regression caused by commit 4 in #94732.)
2022-06-14 14:52:01 +10:00
klensy
4ea4e2e76d remove currently unused deps 2022-06-13 22:20:51 +03:00
Nicholas Nethercote
3186e311e5 Revert dc08bc51f2. 2022-06-10 11:58:29 +10:00
Nicholas Nethercote
7f51a1b976 Revert b983e42936. 2022-06-10 08:35:03 +10:00
Nicholas Nethercote
b983e42936 Rename rustc_serialize::opaque::Encoder as MemEncoder.
This avoids the name clash with `rustc_serialize::Encoder` (a trait),
and allows lots qualifiers to be removed and imports to be simplified
(e.g. fewer `as` imports).
2022-06-08 09:50:44 +10:00
Nicholas Nethercote
dc08bc51f2 Move finish out of the Encoder trait.
This simplifies things, but requires making `CacheEncoder` non-generic.
2022-06-08 09:21:05 +10:00
Nicholas Nethercote
1acbe7573d Use delayed error handling for Encodable and Encoder infallible.
There are two impls of the `Encoder` trait: `opaque::Encoder` and
`opaque::FileEncoder`. The former encodes into memory and is infallible, the
latter writes to file and is fallible.

Currently, standard `Result`/`?`/`unwrap` error handling is used, but this is a
bit verbose and has non-trivial cost, which is annoying given how rare failures
are (especially in the infallible `opaque::Encoder` case).

This commit changes how `Encoder` fallibility is handled. All the `emit_*`
methods are now infallible. `opaque::Encoder` requires no great changes for
this. `opaque::FileEncoder` now implements a delayed error handling strategy.
If a failure occurs, it records this via the `res` field, and all subsequent
encoding operations are skipped if `res` indicates an error has occurred. Once
encoding is complete, the new `finish` method is called, which returns a
`Result`. In other words, there is now a single `Result`-producing method
instead of many of them.

This has very little effect on how any file errors are reported if
`opaque::FileEncoder` has any failures.

Much of this commit is boring mechanical changes, removing `Result` return
values and `?` or `unwrap` from expressions. The more interesting parts are as
follows.
- serialize.rs: The `Encoder` trait gains an `Ok` associated type. The
  `into_inner` method is changed into `finish`, which returns
  `Result<Vec<u8>, !>`.
- opaque.rs: The `FileEncoder` adopts the delayed error handling
  strategy. Its `Ok` type is a `usize`, returning the number of bytes
  written, replacing previous uses of `FileEncoder::position`.
- Various methods that take an encoder now consume it, rather than being
  passed a mutable reference, e.g. `serialize_query_result_cache`.
2022-06-08 07:01:26 +10:00
bjorn3
e16c3b4a44 Make saved_file field of WorkProduct non-optional
A WorkProduct without a saved file is useless
2022-06-06 12:39:32 +00:00
bjorn3
85136dbe56 Remove unnecessary cgu name length hash
This is a tiny optimization
2022-06-06 12:29:44 +00:00
Nicholas Nethercote
72de7c4102 Address review comments. 2022-06-02 12:22:04 +10:00
Nicholas Nethercote
0b81d7cdc6 Lazify SourceFile::lines.
`SourceFile::lines` is a big part of metadata. It's stored in a compressed form
(a difference list) to save disk space. Decoding it is a big fraction of
compile time for very small crates/programs.

This commit introduces a new type `SourceFileLines` which has a `Lines`
form and a `Diffs` form. The latter is used when the metadata is first
read, and it is only decoded into the `Lines` form when line data is
actually needed. This avoids the decoding cost for many files,
especially in `std`. It's a performance win of up to 15% for tiny
crates/programs where metadata decoding is a high part of compilation
costs.

A `Lock` is needed because the methods that access lines data (which can
trigger decoding) take `&self` rather than `&mut self`. To allow for this,
`SourceFile::lines` now takes a `FnMut` that operates on the lines slice rather
than returning the lines slice.
2022-06-01 10:36:39 +10:00
bors
0f06824013 Auto merge of #97287 - compiler-errors:type-interner, r=jackh726,oli-obk
Move things to `rustc_type_ir`

Finishes some work proposed in https://github.com/rust-lang/compiler-team/issues/341.

r? `@ghost`
2022-05-29 08:20:13 +00:00
Michael Goulet
4638915940 Make TyCtxt implement Interner, make HashStable generic and move to rustc_type_ir 2022-05-28 12:16:05 -07:00
Wilco Kusee
a7015fe816 Move things to rustc_type_ir 2022-05-28 11:38:22 -07:00
Josh Stone
ab57e36268 Update to rebased rustc-rayon 0.4 2022-05-27 20:20:41 -07:00
bors
574830f573 Auto merge of #96094 - Elliot-Roberts:fix_doctests, r=compiler-errors
Begin fixing all the broken doctests in `compiler/`

Begins to fix #95994.
All of them pass now but 24 of them I've marked with `ignore HELP (<explanation>)` (asking for help) as I'm unsure how to get them to work / if we should leave them as they are.
There are also a few that I marked `ignore` that could maybe be made to work but seem less important.
Each `ignore` has a rough "reason" for ignoring after it parentheses, with

- `(pseudo-rust)` meaning "mostly rust-like but contains foreign syntax"
- `(illustrative)` a somewhat catchall for either a fragment of rust that doesn't stand on its own (like a lone type), or abbreviated rust with ellipses and undeclared types that would get too cluttered if made compile-worthy.
- `(not-rust)` stuff that isn't rust but benefits from the syntax highlighting, like MIR.
- `(internal)` uses `rustc_*` code which would be difficult to make work with the testing setup.

Those reason notes are a bit inconsistently applied and messy though. If that's important I can go through them again and try a more principled approach. When I run `rg '```ignore \(' .` on the repo, there look to be lots of different conventions other people have used for this sort of thing. I could try unifying them all if that would be helpful.

I'm not sure if there was a better existing way to do this but I wrote my own script to help me run all the doctests and wade through the output. If that would be useful to anyone else, I put it here: https://github.com/Elliot-Roberts/rust_doctest_fixing_tool
2022-05-07 06:30:29 +00:00
Yuki Okushi
ade123275d
Rollup merge of #96697 - oli-obk:trace_queries, r=michaelwoerister
Enable tracing for all queries

This allows you to log everything within a specific query, e.g.

```
env RUSTC_LOG=[mir_borrowck]
```

dumping all borrowck queries may be a bit verbose, so you can also restrict it to just an item of your choice:

```
env RUSTC_LOG=[mir_borrowck{key=\.\*name_of_item\.\*}]
```

the regex `.*` in the key name are because the key is a debug printed DefId, so you'd get all kinds of things like hashes in there. The tracing logs will show you the key, so you can restrict it further if you want.
2022-05-05 10:20:38 +09:00
Oli Scherer
0d5a738b8b Enable tracing for all queryies 2022-05-04 16:15:26 +00:00
Josh Triplett
0fc5c524f5 Stabilize bool::then_some 2022-05-04 13:22:08 +02:00
Elliot Roberts
7907385999 fix most compiler/ doctests 2022-05-02 17:40:30 -07:00
Camille GILLOT
443333dc1f Remove NodeIdHashingMode. 2022-04-12 19:59:32 +02:00
bors
e980c62955 Auto merge of #95524 - oli-obk:cached_stable_hash_cleanups, r=nnethercote
Cached stable hash cleanups

r? `@nnethercote`

Add a sanity assertion in debug mode to check that the cached hashes are actually the ones we get if we compute the hash each time.

Add a new data structure that bundles all the hash-caching work to make it easier to re-use it for different interned data structures
2022-04-09 02:31:24 +00:00
David Wood
7f91697b50 errors: implement fallback diagnostic translation
This commit updates the signatures of all diagnostic functions to accept
types that can be converted into a `DiagnosticMessage`. This enables
existing diagnostic calls to continue to work as before and Fluent
identifiers to be provided. The `SessionDiagnostic` derive just
generates normal diagnostic calls, so these APIs had to be modified to
accept Fluent identifiers.

In addition, loading of the "fallback" Fluent bundle, which contains the
built-in English messages, has been implemented.

Each diagnostic now has "arguments" which correspond to variables in the
Fluent messages (necessary to render a Fluent message) but no API for
adding arguments has been added yet. Therefore, diagnostics (that do not
require interpolation) can be converted to use Fluent identifiers and
will be output as before.
2022-04-05 07:01:02 +01:00
Oli Scherer
00c24dd8ce Move stable hash from TyS into a datastructure that can be shared with other interned types. 2022-03-31 14:54:04 +00:00
Yuri Astrakhan
5160f8f843 Spellchecking compiler comments
This PR cleans up the rest of the spelling mistakes in the compiler comments. This PR does not change any literal or code spelling issues.
2022-03-30 15:14:15 -04:00
bors
f132bcf3bd Auto merge of #94081 - oli-obk:lazy_tait_take_two, r=nikomatsakis
Lazy type-alias-impl-trait take two

### user visible change 1: RPIT inference from recursive call sites

Lazy TAIT has an insta-stable change. The following snippet now compiles, because opaque types can now have their hidden type set from wherever the opaque type is mentioned.

```rust
fn bar(b: bool) -> impl std::fmt::Debug {
    if b {
        return 42
    }
    let x: u32 = bar(false); // this errors on stable
    99
}
```

The return type of `bar` stays opaque, you can't do `bar(false) + 42`, you need to actually mention the hidden type.

### user visible change 2: divergence between RPIT and TAIT in return statements

Note that `return` statements and the trailing return expression are special with RPIT (but not TAIT). So

```rust
#![feature(type_alias_impl_trait)]
type Foo = impl std::fmt::Debug;

fn foo(b: bool) -> Foo {
    if b {
        return vec![42];
    }
    std::iter::empty().collect() //~ ERROR `Foo` cannot be built from an iterator
}

fn bar(b: bool) -> impl std::fmt::Debug {
    if b {
        return vec![42]
    }
    std::iter::empty().collect() // Works, magic (accidentally stabilized, not intended)
}
```

But when we are working with the return value of a recursive call, the behavior of RPIT and TAIT is the same:

```rust
type Foo = impl std::fmt::Debug;

fn foo(b: bool) -> Foo {
    if b {
        return vec![];
    }
    let mut x = foo(false);
    x = std::iter::empty().collect(); //~ ERROR `Foo` cannot be built from an iterator
    vec![]
}

fn bar(b: bool) -> impl std::fmt::Debug {
    if b {
        return vec![];
    }
    let mut x = bar(false);
    x = std::iter::empty().collect(); //~ ERROR `impl Debug` cannot be built from an iterator
    vec![]
}
```

### user visible change 3: TAIT does not merge types across branches

In contrast to RPIT, TAIT does not merge types across branches, so the following does not compile.

```rust
type Foo = impl std::fmt::Debug;

fn foo(b: bool) -> Foo {
    if b {
        vec![42_i32]
    } else {
        std::iter::empty().collect()
        //~^ ERROR `Foo` cannot be built from an iterator over elements of type `_`
    }
}
```

It is easy to support, but we should make an explicit decision to include the additional complexity in the implementation (it's not much, see a721052457cf513487fb4266e3ade65c29b272d2 which needs to be reverted to enable this).

### PR formalities

previous attempt: #92007

This PR also includes #92306 and #93783, as they were reverted along with #92007 in #93893

fixes #93411
fixes #88236
fixes #89312
fixes #87340
fixes #86800
fixes #86719
fixes #84073
fixes #83919
fixes #82139
fixes #77987
fixes #74282
fixes #67830
fixes #62742
fixes #54895
2022-03-30 05:04:45 +00:00
Oli Scherer
264cd05b16 Revert "Auto merge of #93893 - oli-obk:sad_revert, r=oli-obk"
This reverts commit 6499c5e7fc, reversing
changes made to 78450d2d60.
2022-03-28 16:27:14 +00:00
klensy
008fc79dcd Propagate parallel_compiler feature through rustc crates. Turned off feature gives change of builded crates: 238 -> 224. 2022-03-28 08:41:12 +03:00
Camille GILLOT
056951d628 Take &mut Diagnostic in emit_diagnostic.
Taking a Diagnostic by move would break the usual pattern
`diag.label(..).emit()`.
2022-03-20 20:36:08 +01:00
mark
e489a94dee rename ErrorReported -> ErrorGuaranteed 2022-03-02 09:45:25 -06:00
bors
3b1fe7e7c9 Auto merge of #94084 - Mark-Simulacrum:drop-sharded, r=cjgillot
Avoid query cache sharding code in single-threaded mode

In non-parallel compilers, this is just adding needless overhead at compilation time (since there is only one shard statically anyway). This amounts to roughly ~10 seconds reduction in bootstrap time, with overall neutral (some wins, some losses) performance results.

Parallel compiler performance should be largely unaffected by this PR; sharding is kept there.
2022-02-27 14:04:07 +00:00
Mark Rousskov
22c3a71de1 Switch bootstrap cfgs 2022-02-25 08:00:52 -05:00
Eduard-Mihai Burtescu
b7e95dee65 rustc_errors: let DiagnosticBuilder::emit return a "guarantee of emission". 2022-02-23 06:38:52 +00:00
bors
58a721af9f Auto merge of #93839 - Mark-Simulacrum:delete-json-rust-deserialization, r=nnethercote
Simplify rustc_serialize by dropping support for decoding into JSON

This PR currently bundles two (somewhat separate) tasks.

First, it removes the JSON Decoder trait impl, which permitted going from JSON to Rust structs. For now, we keep supporting JSON deserialization, but only to `Json` (an equivalent of serde_json::Value). The primary hard to remove user there is for custom targets -- which need some form of JSON deserialization -- but they already have a custom ad-hoc pass for moving from Json to a Rust struct.

A [comment](e7aca89598/compiler/rustc_target/src/spec/mod.rs (L1653)) there suggests that it would be impractical to move them to a Decodable-based impl, at least without backwards compatibility concerns. I suspect that if we were widely breaking compat there, it would make sense to use serde_json at this point which would produce better error messages; the types in rustc_target are relatively isolated so we would not particularly suffer from using serde_derive.

The second part of the PR (all but the first commit) is to simplify the Decoder API by removing the non-primitive `read_*` functions. These primarily add indirection (through a closure), which doesn't directly cause a performance issue (the unique closure types essentially guarantee monomorphization), but does increase the amount of work rustc and LLVM need to do. This could be split out to a separate PR, but is included here in part to help motivate the first part.

Future work might consist of:

* Specializing enum discriminant encoding to avoid leb128 for small enums (since we know the variant count, we can directly use read/write u8 in almost all cases)
* Adding new methods to support faster deserialization (e.g., access to the underlying byte stream)
   * Currently these are somewhat ad-hoc supported by specializations for e.g. `Vec<u8>`, but other types which could benefit don't today.
* Removing the Decoder trait entirely in favor of a concrete type -- today, we only really have one impl of it modulo wrappers used for specialization-based dispatch.

Highly recommend review with whitespace changes off, as the removal of closures frequently causes things to be de-indented.
2022-02-22 07:54:22 +00:00
Mark Rousskov
42904b0219 Delete Decoder::read_seq 2022-02-20 18:58:23 -05:00
Mark Rousskov
24dc052132 Delete Decoder::read_seq_elt 2022-02-20 18:58:22 -05:00
Mark Rousskov
19288951e1 Delete Decoder::read_struct_field 2022-02-20 18:58:22 -05:00
Mark Rousskov
c021ba48a7 Delete Decoder::read_struct 2022-02-20 18:58:22 -05:00
Mark Rousskov
594ea74bf0 Refactor Sharded out of non-parallel active query map 2022-02-20 15:10:19 -05:00
Mark Rousskov
41f124c824 Avoid sharding query caches entirely in single-threaded mode 2022-02-20 14:57:34 -05:00
Mark Rousskov
8443816176 Inline QueryStateShard into QueryState 2022-02-20 12:11:28 -05:00
Mark Rousskov
75ef068920 Delete QueryLookup
This was largely just caching the shard value at this point, which is not
particularly useful -- in the use sites the key was being hashed nearby anyway.
2022-02-20 12:11:28 -05:00
Mark Rousskov
9deed6f74e Move Sharded maps into each QueryCache impl 2022-02-20 12:10:46 -05:00
Mark Rousskov
ddda851fd5 Remove SimpleDefKind 2022-02-17 18:08:45 -05:00
Oli Scherer
d54195db22 Revert "Auto merge of #92007 - oli-obk:lazy_tait2, r=nikomatsakis"
This reverts commit e7cc3bddbe, reversing
changes made to 734368a200.
2022-02-11 07:18:06 +00:00
bors
e7aca89598 Auto merge of #93741 - Mark-Simulacrum:global-job-id, r=cjgillot
Refactor query system to maintain a global job id counter

This replaces the per-shard counters with a single global counter, simplifying
the JobId struct down to just a u64 and removing the need to pipe a DepKind
generic through a bunch of code. The performance implications on non-parallel
compilers are likely minimal (this switches to `Cell<u64>` as the backing
storage over a `u64`, but the latter was already inside a `RefCell` so it's not
really a significance divergence). On parallel compilers, the cost of a single
global u64 counter may be more significant: it adds a serialization point in
theory. On the other hand, we can imagine changing the counter to have a
thread-local component if it becomes worrisome or some similar structure.

The new design is sufficiently simpler that it warrants the potential for slight
changes down the line if/when we get parallel compilation to be more of a
default.

A u64 counter, instead of u32 (the old per-shard width), is chosen to avoid
possibly overflowing it and causing problems; it is effectively impossible that
we would overflow a u64 counter in this context.
2022-02-09 18:54:30 +00:00
Mark Rousskov
e240783a4d Switch QueryJobId to a single global counter
This replaces the per-shard counters with a single global counter, simplifying
the JobId struct down to just a u64 and removing the need to pipe a DepKind
generic through a bunch of code. The performance implications on non-parallel
compilers are likely minimal (this switches to `Cell<u64>` as the backing
storage over a `u64`, but the latter was already inside a `RefCell` so it's not
really a significance divergence). On parallel compilers, the cost of a single
global u64 counter may be more significant: it adds a serialization point in
theory. On the other hand, we can imagine changing the counter to have a
thread-local component if it becomes worrisome or some similar structure.

The new design is sufficiently simpler that it warrants the potential for slight
changes down the line if/when we get parallel compilation to be more of a
default.

A u64 counter, instead of u32 (the old per-shard width), is chosen to avoid
possibly overflowing it and causing problems; it is effectively impossible that
we would overflow a u64 counter in this context.
2022-02-08 18:49:55 -05:00
bors
e7cc3bddbe Auto merge of #92007 - oli-obk:lazy_tait2, r=nikomatsakis
Lazy type-alias-impl-trait

Previously opaque types were processed by

1. replacing all mentions of them with inference variables
2. memorizing these inference variables in a side-table
3. at the end of typeck, resolve the inference variables in the side table and use the resolved type as the hidden type of the opaque type

This worked okayish for `impl Trait` in return position, but required lots of roundabout type inference hacks and processing.

This PR instead stops this process of replacing opaque types with inference variables, and just keeps the opaque types around.
Whenever an opaque type `O` is compared with another type `T`, we make the comparison succeed and record `T` as the hidden type. If `O` is compared to `U` while there is a recorded hidden type for it, we grab the recorded type (`T`) and compare that against `U`. This makes implementing

* https://github.com/rust-lang/rfcs/pull/2515

much simpler (previous attempts on the inference based scheme were very prone to ICEs and general misbehaviour that was not explainable except by random implementation defined oddities).

r? `@nikomatsakis`

fixes #93411
fixes #88236
2022-02-07 23:40:26 +00:00
Oli Scherer
0f6e06b7c0 Lazily resolve type-alias-impl-trait defining uses
by using an opaque type obligation to bubble up comparisons between opaque types and other types

Also uses proper obligation causes so that the body id works, because out of some reason nll uses body ids for logic instead of just diagnostics.
2022-02-02 15:40:11 +00:00
est31
08be313feb Use Option::then in two places 2022-02-02 16:10:16 +01:00
lcnr
a1a30f7548 add a rustc::query_stability lint 2022-02-01 10:15:59 +01:00
Nicholas Nethercote
37fbd91eb5 Address review comments. 2022-01-22 10:38:34 +11:00
Nicholas Nethercote
416399dc10 Make Decodable and Decoder infallible.
`Decoder` has two impls:
- opaque: this impl is already partly infallible, i.e. in some places it
  currently panics on failure (e.g. if the input is too short, or on a
  bad `Result` discriminant), and in some places it returns an error
  (e.g. on a bad `Option` discriminant). The number of places where
  either happens is surprisingly small, just because the binary
  representation has very little redundancy and a lot of input reading
  can occur even on malformed data.
- json: this impl is fully fallible, but it's only used (a) for the
  `.rlink` file production, and there's a `FIXME` comment suggesting it
  should change to a binary format, and (b) in a few tests in
  non-fundamental ways. Indeed #85993 is open to remove it entirely.

And the top-level places in the compiler that call into decoding just
abort on error anyway. So the fallibility is providing little value, and
getting rid of it leads to some non-trivial performance improvements.

Much of this commit is pretty boring and mechanical. Some notes about
a few interesting parts:
- The commit removes `Decoder::{Error,error}`.
- `InternIteratorElement::intern_with`: the impl for `T` now has the same
  optimization for small counts that the impl for `Result<T, E>` has,
  because it's now much hotter.
- Decodable impls for SmallVec, LinkedList, VecDeque now all use
  `collect`, which is nice; the one for `Vec` uses unsafe code, because
  that gave better perf on some benchmarks.
2022-01-22 10:38:31 +11:00
bors
42852d7857 Auto merge of #92740 - cuviper:update-rayons, r=Mark-Simulacrum
Update rayon and rustc-rayon

This updates rayon for various tools and rustc-rayon for the compiler's parallel mode.

- rayon v1.3.1 -> v1.5.1
- rayon-core v1.7.1 -> v1.9.1
- rustc-rayon v0.3.1 -> v0.3.2
- rustc-rayon-core v0.3.1 -> v0.3.2

... and indirectly, this updates all of crossbeam-* to their latest versions.

Fixes #92677 by removing crossbeam-queue, but there's still a lingering question about how tidy discovers "runtime" dependencies. None of this is truly in the standard library's dependency tree at all.
2022-01-16 08:12:23 +00:00
bors
02c9e73e6c Auto merge of #92681 - Aaron1011:task-deps-ref, r=cjgillot
Introduce new `TaskDepsRef` enum to track allow/ignore/forbid status
2022-01-14 14:20:17 +00:00
Josh Stone
f3b8812f24 Update rayon and rustc-rayon 2022-01-10 11:34:07 -08:00
bors
d63a8d965e Auto merge of #92278 - Aaron1011:fix-fingerprint-caching, r=michaelwoerister
Ensure that `Fingerprint` caching respects hashing configuration

Fixes #92266

In some `HashStable` impls, we use a cache to avoid re-computing
the same `Fingerprint` from the same structure (e.g. an `AdtDef`).
However, the `StableHashingContext` used can be configured to
perform hashing in different ways (e.g. skipping `Span`s). This
configuration information is not included in the cache key,
which will cause an incorrect `Fingerprint` to be used if
we hash the same structure with different `StableHashingContext`
settings.

To fix this, the configuration settings of `StableHashingContext`
are split out into a separate `HashingControls` struct. This
struct is used as part of the cache key, ensuring that our caches
always produce the correct result for the given settings.

With this in place, we now turn off `Span` hashing during the
entire process of computing the hash included in legacy symbols.
This current has no effect, but will matter when a future PR
starts hashing more `Span`s that we currently skip.
2022-01-10 00:26:07 +00:00
Aaron Hill
f64cd87ca6
Introduce new TaskDepsRef enum to track allow/ignore/forbid status 2022-01-08 18:22:06 -05:00
bors
a7e2e33960 Auto merge of #91919 - Aaron1011:query-recursive-read, r=michaelwoerister
Don't perform any new queries while reading a query result on disk

In addition to being very confusing, this can cause us to add dep node edges between two queries that would not otherwise have an edge.

We now panic if any new dep node edges are created during the deserialization of a query result. This requires serializing the full `AdtDef` to disk, instead of just serializing the `DefId` and invoking the `adt_def` query during deserialization.

I'll probably split this up into several smaller PRs for perf runs.
2022-01-08 18:32:31 +00:00
Aaron Hill
4ca275add0
Address review comments 2022-01-05 10:30:49 -05:00
Aaron Hill
560c90f5df
Adjust assert_default_hashing_controls 2022-01-05 10:13:29 -05:00
Aaron Hill
5580e5e1dd
Ensure that Fingerprint caching respects hashing configuration
Fixes #92266

In some `HashStable` impls, we use a cache to avoid re-computing
the same `Fingerprint` from the same structure (e.g. an `AdtDef`).
However, the `StableHashingContext` used can be configured to
perform hashing in different ways (e.g. skipping `Span`s). This
configuration information is not included in the cache key,
which will cause an incorrect `Fingerprint` to be used if
we hash the same structure with different `StableHashingContext`
settings.

To fix this, the configuration settings of `StableHashingContext`
are split out into a separate `HashingControls` struct. This
struct is used as part of the cache key, ensuring that our caches
always produce the correct result for the given settings.

With this in place, we now turn off `Span` hashing during the
entire process of computing the hash included in legacy symbols.
This current has no effect, but will matter when a future PR
starts hashing more `Span`s that we currently skip.
2022-01-05 10:13:28 -05:00
bors
2b681ac06b Auto merge of #92259 - Aaron1011:normal-mod-hashing, r=michaelwoerister
Remove special-cased stable hashing for HIR module

All other 'containers' (e.g. `impl` blocks) hashed their contents
in the normal, order-dependent way. However, `Mod` was hashing
its contents in a (sort-of) order-independent way. However, the
exact order is exposed to consumers through `Mod.item_ids`,
and through query results like `hir_module_items`. Therefore,
stable hashing needs to take the order of items into account,
to avoid fingerprint ICEs.

Unforuntately, I was unable to directly build a reproducer
for the ICE, due to the behavior of `Fingerprint::combine_commutative`.
This operation swaps the upper and lower `u64` when constructing the
result, which makes the function non-associative. Since we start
the hashing of module items by combining `Fingerprint::ZERO` with
the first item, it's difficult to actually build an example where
changing the order of module items leaves the final hash unchanged.

However, this appears to have been hit in practice in #92218
While we're not able to reproduce it, the fact that proc-macros
are involved (which can give an entire module the same span, preventing
any span-related invalidations) makes me confident that the root
cause of that issue is our method of hashing module items.

This PR removes all of the special handling for `Mod`, instead deriving
a `HashStable` implementation. This makes `Mod` consistent with other
'contains' like `Impl`, which hash their contents through the typical
derive of `HashStable`.
2022-01-04 00:25:23 +00:00
Aaron Hill
da3f196a4e
Remove special-cased stable hashing for HIR module
All other 'containers' (e.g. `impl` blocks) hashed their contents
in the normal, order-dependent way. However, `Mod` was hashing
its contents in a (sort-of) order-independent way. However, the
exact order is exposed to consumers through `Mod.item_ids`,
and through query results like `hir_module_items`. Therefore,
stable hashing needs to take the order of items into account,
to avoid fingerprint ICEs.

Unforuntately, I was unable to directly build a reproducer
for the ICE, due to the behavior of `Fingerprint::combine_commutative`.
This operation swaps the upper and lower `u64` when constructing the
result, which makes the function non-associative. Since we start
the hashing of module items by combining `Fingerprint::ZERO` with
the first item, it's difficult to actually build an example where
changing the order of module items leaves the final hash unchanged.

However, this appears to have been hit in practice in #92218
While we're not able to reproduce it, the fact that proc-macros
are involved (which can give an entire module the same span, preventing
any span-related invalidations) makes me confident that the root
cause of that issue is our method of hashing module items.

This PR removes all of the special handling for `Mod`, instead deriving
a `HashStable` implementation. This makes `Mod` consistent with other
'contains' like `Impl`, which hash their contents through the typical
derive of `HashStable`.
2021-12-24 12:38:29 -05:00
Aaron Hill
27ed52c0a2
Adjust wording of comment 2021-12-23 13:44:04 -05:00
Aaron Hill
28f19f62c7
Address review comments 2021-12-23 13:38:54 -05:00
Aaron Hill
ab168e69ac
Some cleanup 2021-12-23 13:38:53 -05:00