8

Assorted improvements for `rustc_middle::mir::traversal` by WaffleLapkin · Pull...

 11 months ago
source link: https://github.com/rust-lang/rust/pull/116254
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

This comment has been minimized.

Collaborator

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@@ -178,7 +178,7 @@ impl<'a, 'tcx> Postorder<'a, 'tcx> {

// When we yield `C` and call `traverse_successor`, we push `B` to the stack, but

// since we've already visited `E`, that child isn't added to the stack. The last

// two iterations yield `B` and finally `A` for a final traversal of [E, D, C, B, A]

while let Some(&mut (_, ref mut iter)) = self.visit_stack.last_mut() && let Some(bb) = iter.next_back() {

while let Some(bb) = self.visit_stack.last_mut().and_then(|(_, iter)| iter.next_back()) {

Contributor

Should this use a let chain ?

I can drop 0e0dc59 if you want :P

My point for using and_then was to show that iter is only used for next_back and is not used in the body of the loop. IMO with let chain it was a bit harder to read

/// Construction of a `ReversePostorder` traversal requires doing a full

/// postorder traversal of the graph, therefore this traversal should be

/// constructed as few times as possible. Use the `reset` method to be able

/// to re-use the traversal

Contributor

This comment is very useful to newcomers that do not know the different types of traversal. Can it be preserved somewhere ?

What do you think about ef3c5bb?

traversal::Postorder::new(&mir.basic_blocks, location.block)

.collect::<Vec<_>>()

.into_iter()

.rev()

Contributor

Can the cached traversal be used here ?

Not easily I think, this uses a root block setting, but we only cache this for root = START_BLOCK.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK