Commit Graph

60 Commits

Author SHA1 Message Date
csmoe 64f61c7888 remove indexed_vec re-export from rustc_data_structures 2019-09-29 16:48:31 +00:00
Nicholas Nethercote aa10abb211 Rename a variable.
Because the meaning of this `index` variable is quite different to all
the other `index` variables in this file.
2019-09-20 12:53:22 +10:00
Nicholas Nethercote 27c7c23840 Rename `waiting_cache`.
The name `waiting_cache` sounds like it is related to the states
`NodeState::Waiting`, but it's not; the cache holds nodes of various
states.

This commit changes it to `active_state`.
2019-09-20 11:31:50 +10:00
Nicholas Nethercote 75fd4f754e Rename a loop variable.
We normally use `index` for indices to `ObligationForest::nodes`, but
this is a `Nodes::dependents` index.
2019-09-20 11:26:07 +10:00
Nicholas Nethercote 8d73faf9ab Remove some unnecessary `backtrace` intermediate variables. 2019-09-20 11:25:16 +10:00
Nicholas Nethercote aaff05bd1c Reorder the state handling in `process_cycles()`.
This gives a slight speed-up.
2019-09-20 07:22:10 +10:00
Nicholas Nethercote 7f6e160875 Rename some index variables.
Now that all indices have type `usize`, it makes sense to be more
consistent about their naming. This commit removes all uses of `i` in
favour of `index`.
2019-09-17 15:32:29 +10:00
Nicholas Nethercote cf3a562c98 Remove `NodeIndex`.
The size of the indices doesn't matter much here, and having a
`newtype_index!` index type without also using `IndexVec` requires lots
of conversions. So this commit removes `NodeIndex` in favour of uniform
use of `usize` as the index type. As well as making the code slightly
more concise, it also slightly speeds things up.
2019-09-17 15:32:29 +10:00
Nicholas Nethercote 476e75ded7 Move a `Node`'s parent into the descendents list.
`Node` has an optional parent and a list of other descendents. Most of
the time the parent is treated the same as the other descendents --
error-handling is the exception -- and chaining them together for
iteration has a non-trivial cost.

This commit changes the representation. There is now a single list of
descendants, and a boolean flag that indicates if there is a parent (in
which case it is first descendent). This representation encodes the same
information, in a way that is less idiomatic but cheaper to iterate over
for the common case where the parent doesn't need special treatment.

As a result, some benchmark workloads are up to 2% faster.
2019-09-17 15:32:29 +10:00
Nicholas Nethercote 4ecd94e121 Move `impl Node` just after `struct Node`. 2019-09-16 12:47:46 +10:00
Nicholas Nethercote 201afa6455 Minor comment tweaks. 2019-09-16 12:47:04 +10:00
Nicholas Nethercote f22bb2e722 Use `retain` for `waiting_cache` in `apply_rewrites()`.
It's more concise, more idiomatic, and measurably faster.
2019-09-16 12:43:48 +10:00
Nicholas Nethercote 6e48053d5d Use iterators in `error_at` and `process_cycle`.
This makes the code a little faster, presumably because bounds checks
aren't needed on `nodes` accesses. It requires making `scratch` a
`RefCell`, which is not unreasonable.
2019-09-16 12:43:16 +10:00
Nicholas Nethercote e2492b7163 Add comments about `waiting_cache`. 2019-09-16 12:41:36 +10:00
Nicholas Nethercote 6391ef4d6e Fix incorrect comment about contents of a `Node`. 2019-09-16 12:40:31 +10:00
Nicholas Nethercote ac061dc5c8 Fix some out-of-date names of things in comments. 2019-09-16 12:39:21 +10:00
Nicholas Nethercote 3fda9578e0 Remove out-of-date comments.
These refer to code that no longer exists.
2019-09-16 12:38:24 +10:00
Nicholas Nethercote 1936e44c13 Factor out repeated `self.nodes[i]` expressions. 2019-09-16 11:57:10 +10:00
Nicholas Nethercote 43c0d2ce8e Redefine `NodeIndex` as a `newtype_index!`.
This commit removes the custom index implementation of `NodeIndex`,
which probably predates `newtype_index!`.

As well as eliminating code, it improves the debugging experience,
because the custom implementation had the property of being incremented
by 1 (so it could use `NonZeroU32`), which was incredibly confusing if
you didn't expect it.

For some reason, I also had to remove an `unsafe` block marker from
`from_u32_unchecked()` that the compiler said was now unnecessary.
2019-09-16 11:53:12 +10:00
Nicholas Nethercote 04b1111ae8 Name index variables consistently.
Those with type `usize` are now called `i`, those with type `NodeIndex`
are called `index`.
2019-09-16 11:52:47 +10:00
Nicholas Nethercote a2261ad664 Inline `mark_neighbours_as_waiting_from`.
This function is very hot, doesn't get inlined because it's recursive,
and the function calls are significant.

This commit splits it into inlined and uninlined variants, and uses the
inlined variant for the hot call site. This wins several percent on a
few benchmarks.
2019-09-13 13:46:23 +10:00
Vadim Petrochenkov e118eb6c79 librustc_data_structures: Unconfigure tests during normal build 2019-08-02 01:59:01 +03:00
Igor Matuszewski 33f58baf6e Fix clippy::redundant_closure 2019-06-26 14:11:58 +02:00
Alexander Regueiro c3e182cf43 rustc: doc comments 2019-02-10 23:42:32 +00:00
Taiki Endo 3e2b5a4b08 librustc_data_structures => 2018 2019-02-09 01:36:22 +09:00
mark a6294b7628 update/remove some old readmes 2019-01-15 19:38:02 -06:00
Mark Rousskov 2a663555dd Remove licenses 2018-12-25 21:08:33 -07:00
Alexander Regueiro ee89c088b0 Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00
Nicholas Nethercote dbc3c6e56f Make `process_obligations`' computation of `completed` optional.
It's only used in tests.

This reduces instruction counts on several benchmarks by 0.5--1%.
2018-10-30 20:20:04 +11:00
Oliver Scherer 3c9258e604 Prefer `Default::default` over `FxHash*::default` in struct constructors 2018-10-19 14:34:44 +02:00
Oliver Scherer ee81739dc1 Deprecate the `FxHashMap()` and `FxHashSet()` constructor function hack 2018-10-19 14:34:44 +02:00
Diogo Sousa 3fc275df6c Added graphviz visualization for obligation forests.
This can be a big help when debugging the trait resolver.
2018-10-14 16:12:07 +01:00
Diogo Sousa 6bfa6aa872 Deduplicate errors in the obligation forest.
Fixes #40827.
2018-09-30 20:01:35 +01:00
Diogo Sousa d2ff5d696c Typos and style fixes. 2018-09-30 20:01:28 +01:00
ljedrz 94c3856804 A few cleanups for rustc_data_structures 2018-08-09 19:50:12 +02:00
ljedrz 384d04d31d Reduce the number of clone()s needed in obligation_forest
Some can be avoided by using remove_entry instead of remove.
2018-07-14 07:31:19 +02:00
Nicholas Nethercote 70d22fa051 Improve `Node::{parent,dependents}` interplay.
This patch:

- Reorders things a bit so that `parent` is always handled before
  `dependents`.

- Uses iterator chaining to avoid some code duplication.
2018-06-18 10:04:23 +10:00
Nicholas Nethercote 6151bab8e1 Improve pushing to `Node::dependents`.
This patch makes it impossible for a node to end up in both
`node.parent` and `node.dependents`.
2018-06-18 10:04:23 +10:00
bors 68cee8bb36 Auto merge of #51411 - nnethercote:process_predicate, r=nikomatsakis
Speed up obligation forest code

Here are the rustc-perf benchmarks that get at least a 1% speedup on one or more of their runs with these patches applied:
```
inflate-check
        avg: -8.7%      min: -12.1%     max: 0.0%
inflate
        avg: -5.9%      min: -8.6%      max: 1.1%
inflate-opt
        avg: -1.5%      min: -2.0%      max: -0.3%
clap-rs-check
        avg: -0.6%      min: -1.9%      max: 0.5%
coercions
        avg: -0.2%?     min: -1.3%?     max: 0.6%?
serde-opt
        avg: -0.6%      min: -1.0%      max: 0.1%
coercions-check
        avg: -0.4%?     min: -1.0%?     max: -0.0%?
```
2018-06-16 03:06:10 +00:00
Nicholas Nethercote b0440d359b Avoid useless Vec clones in pending_obligations().
The only instance of `ObligationForest` in use has an obligation type of
`PendingPredicateObligation`, which contains a `PredicateObligation` and a
`Vec<Ty>`.

`FulfillmentContext::pending_obligations()` calls
`ObligationForest::pending_obligations()`, which clones all the
`PendingPredicateObligation`s. But the `Vec<Ty>` field of those cloned
obligations is never touched.

This patch changes `ObligationForest::pending_obligations()` to
`map_pending_obligations` -- which gives callers control about which part
of the obligation to clone -- and takes advantage of the change to avoid
cloning the `Vec<Ty>`. The change speeds up runs of a few rustc-perf
benchmarks, the best by 1%.
2018-06-08 09:00:17 +10:00
Nicholas Nethercote c83d152eba Introduce `ProcessResult`.
A tri-valued enum is nicer than Result<Option<T>>, and it's slightly
faster.
2018-06-07 20:34:39 +10:00
Nicholas Nethercote f46d0213e4 Remove `ObligationForest::cache_list`.
It's never used in a meaningful way.
2018-05-31 09:22:07 +10:00
leonardo.yvens 2e7e68b762 while let all the things 2018-03-05 15:58:54 -03:00
Vadim Petrochenkov de4dbe5789 rustc: Remove some dead code 2017-08-19 13:27:16 +03:00
Zack M. Davis 1b6c9605e4 use field init shorthand EVERYWHERE
Like #43008 (f668999), but _much more aggressive_.
2017-08-15 15:29:17 -07:00
Bruce Mitchener 539df8121b Fix some doc/comment typos. 2017-07-23 22:48:01 +07:00
Niko Matsakis 59babd80bd add some comments and `debug!` calls to "obligation forest" 2017-04-11 20:32:48 -04:00
Nicholas Nethercote 00e48affde Replace FnvHasher use with FxHasher.
This speeds up compilation by 3--6% across most of rustc-benchmarks.
2016-11-08 15:14:59 +11:00
Nicholas Nethercote 7b33f7e3e7 Optimize ObligationForest's NodeState handling.
This commit partially inlines two functions, `find_cycles_from_node` and
`mark_as_waiting_from`, at two call sites in order to avoid function
unnecessary function calls on hot paths.

It also fully inlines and removes `is_popped`.

These changes speeds up rustc-benchmarks/inflate-0.1.0 by about 2% when
doing debug builds with a stage1 compiler.
2016-11-02 13:37:10 +11:00
Jonas Schievink 0c844d2304 Set stalled=false when encountering an error 2016-10-17 21:53:27 +02:00