This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Selection: Prune gtest TEST()s earlier
ClosedPublic

Authored by sammccall on Jan 10 2022, 3:10 PM.

Details

Summary

When searching for AST nodes that may overlap the selection, mayHit() was only
attempting to prune nodes whose begin/end are both in the main file.

While failing to prune never gives wrong results, it hurts performance.
In GTest unit-tests, TEST() macros at the top level declare classes.
These were never pruned and we traversed *every* such class for any selection.

We fix this by reasoning about what tokens such a node might claim.
They must lie within its ultimate macro expansion range, so if this doesn't
overlap with the selection, we can prune the node.

Diff Detail

Event Timeline

sammccall created this revision.Jan 10 2022, 3:10 PM
sammccall requested review of this revision.Jan 10 2022, 3:10 PM
sammccall updated this revision to Diff 398757.Jan 10 2022, 3:15 PM

Use the other end too

sammccall updated this revision to Diff 398876.Jan 11 2022, 2:18 AM

Rebase (offsetInSelFile)

nridge added a subscriber: nridge.Jan 12 2022, 8:57 PM
hokein accepted this revision.Jan 13 2022, 2:46 AM

Thanks, this looks good.

clang-tools-extra/clangd/Selection.cpp
306

sorry, I don't quite understand this sentence...

315

I think the current implementation is fine, just notice there is an alternative

  • SourceManager::getExpansionRange(SourceRange) method does similar things, we could use that to save some bits of code, but we will have some extra cost for unnecessary getImmediateExpansionRange/getFileID.
318

as discussed offline, offsetInSelFile is doing smart and efficient thing which relies on the underlying offset implementation in source manger, would be nice to have some comments and docs there and SourceManager comparison operator.

This revision is now accepted and ready to land.Jan 13 2022, 2:46 AM
sammccall marked 3 inline comments as done.Jan 13 2022, 4:56 AM
sammccall added inline comments.
clang-tools-extra/clangd/Selection.cpp
306

Rephrased.

315

Yeah, it does a fair amount of unneccesary work in order for the endpoint to be exact (handling whether intermediate exp ranges for endpoint are char ranges or token ranges).
For our case we don't care if we're a token too far to the right, and we don't want to pay for all this.

318

Oops, I forgot to document that function! Done.

This revision was automatically updated to reflect the committed changes.
sammccall marked 3 inline comments as done.