Skip to content

Conversation

@Veykril
Copy link
Member

@Veykril Veykril commented Oct 21, 2020

This in turn also makes algo::diff generate finer diffs(maybe even minimal diffs?) as insertions and deletions aren't always represented as as replacements of parent nodes now.

Required for #6287 to go on.

r#"
fn {a:42, b: ()} {}
fn some(, b: ()} {}
fn items() {}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks to this macro text expecting already broken output you can see the result of these changes in that the diff became smaller here 😄

deletions: Vec<SyntaxElement>,
// the vec as well as the indexmap are both here to preserve order
insertions:
IndexMap<SyntaxElement, Vec<SyntaxElement>, BuildHasherDefault<rustc_hash::FxHasher>>,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Insertion order is important as insertions might be chained after each other. The IndexMap could be replace by Vec<(SyntaxElement, Vec<SyntaxElement>) with binary_search insertion on the first tuple part as the key but I'm uncertain what would be better.

Comment on lines +201 to +204
(Some(lhs_ele), Some(rhs_ele)) => go(diff, lhs_ele, rhs_ele),
}
last_lhs = lhs_child.or(last_lhs);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, would this work corretly if the go ends up replacing the whole lhs_child, and then, on the next iteration, we use it as an anchor in inserts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it seems it will work, cool!

Comment on lines +190 to +192
// first iteration, this means we got no anchor element to insert after
// therefor replace the parent node instead
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative is to key insertion not by SyntaxElement, but by (SyntaxElement, bool), where bool should choose between prev sibling and parent. But this is also ok

@matklad
Copy link
Contributor

matklad commented Oct 21, 2020

Nifty, didn't realize that we can improve tree diffing this way!

r=me wiith FxIndexMap nit fixed

If you feel like ii though, adding some unit-tests for tree diff based on expect_test might be useufl long-term

@Veykril Veykril force-pushed the algo-diff-rewrite branch 2 times, most recently from ef08d2f to 32fc764 Compare October 22, 2020 12:08
@matklad
Copy link
Contributor

matklad commented Oct 23, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented Oct 23, 2020

@bors bors bot merged commit 2fa942a into rust-lang:master Oct 23, 2020
@Veykril Veykril deleted the algo-diff-rewrite branch November 27, 2020 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants