Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Various `ObligationForest` improvements #64500
Conversation
Those with type `usize` are now called `i`, those with type `NodeIndex` are called `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.
These refer to code that no longer exists.
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.
It's more concise, more idiomatic, and measurably faster.
|
I will do a perf run. @bors try |
Various `ObligationForest` improvements These commits make the code both nicer and faster. r? @nikomatsakis
|
|
|
@rust-timer build b903678 |
|
Success: Queued b903678 with parent 3e3e06d, comparison URL. |
|
Finished benchmarking try commit b903678, comparison URL. |
| @@ -149,7 +149,7 @@ macro_rules! newtype_index { | |||
|
|
|||
| #[inline] | |||
| $v const unsafe fn from_u32_unchecked(value: u32) -> Self { | |||
| unsafe { $type { private: value } } | |||
| $type { private: value } | |||
nikomatsakis
Sep 16, 2019
Contributor
it's not needed because the function itself is unsafe, so it's allowed to have unsafe operations in the body
it's not needed because the function itself is unsafe, so it's allowed to have unsafe operations in the body
nnethercote
Sep 16, 2019
Author
Contributor
Fair enough. The obvious follow-up question is "why didn't the compiler complain about this before?"
Fair enough. The obvious follow-up question is "why didn't the compiler complain about this before?"
|
r=me once the benchmarking results are in. |
|
@nikomatsakis the bench results are already in... :D |
|
Oh, so they are. @bors r+ |
|
|
…ikomatsakis Various `ObligationForest` improvements These commits make the code both nicer and faster. r? @nikomatsakis
Rollup of 6 pull requests Successful merges: - #64085 (Tweak unsatisfied HRTB errors) - #64380 (Update bundled OpenSSL to 1.1.1d) - #64416 (Various refactorings to clean up nll diagnostics) - #64500 (Various `ObligationForest` improvements) - #64530 (Elide lifetimes in `Pin<&(mut) Self>`) - #64531 (Use shorthand syntax in the self parameter of methods of Pin) Failed merges: r? @ghost
|
Thank you for the fast review. BTW, this code can be very hot and parts of it are very perf-sensitive to change. Here is a list of other ways I tried to speed up or clean up
|
More `ObligationForest` improvements Following on from #64500, these commits alsomake the code both nicer and faster. r? @nikomatsakis
| scratch: Option<Vec<usize>>, | ||
| /// A scratch vector reused in various operations, to avoid allocating new | ||
| /// vectors. | ||
| scratch: RefCell<Vec<usize>>, |
sinkuu
Sep 19, 2019
Contributor
I believe this can be replaced with Cell, which is simpler and panic-free, as you are only calling .replace on this (i.e. not utilizing "Ref" functionality).
I believe this can be replaced with Cell, which is simpler and panic-free, as you are only calling .replace on this (i.e. not utilizing "Ref" functionality).
nnethercote
Sep 19, 2019
Author
Contributor
Thanks for the tip. I will do it in a follow-up.
Thanks for the tip. I will do it in a follow-up.
More `ObligationForest` improvements Following on from #64500, these commits alsomake the code both nicer and faster. r? @nikomatsakis
These commits make the code both nicer and faster.
r? @nikomatsakis