This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Dex: FALSE iterator, peephole optimizations, fix AND bug
ClosedPublic

Authored by sammccall on Oct 2 2018, 10:18 AM.

Details

Summary

The FALSE iterator will be used in a followup patch to fix a logic bug in Dex
(currently, tokens that don't have posting lists in the index are simply dropped
from the query, changing semantics).

It can usually be optimized away, so added the following opmitizations:

  • simplify booleans inside AND/OR
  • replace effectively-empty AND/OR with booleans
  • flatten nested AND/ORs

While working on this, found a bug in the AND iterator: its constructor sync()
assumes that ReachedEnd is set if applicable, but the constructor never sets it.
This crashes if a non-first iterator is nonempty.

Diff Detail

Event Timeline

sammccall created this revision.Oct 2 2018, 10:18 AM
ilya-biryukov accepted this revision.Oct 4 2018, 3:04 AM

LGTM and a few NITs.

clangd/index/dex/Iterator.cpp
376

Maybe replace with case Kind::Other to make sure compiler gives a warning to update the switch when new kinds are added?
Same for other switches on kind

378

Add braces for for statement to make sure there's a closing brace at the right indentation?

385

Maybe use the qualified std::move for consistency with the previous line?

408

Again, for () switch pattern ends up putting the closing brace at the wrong indent level. Consider adding the braces around for the loop body.

415

Maybe use the qualified std::move for consistency with the previous line?

clangd/index/dex/Iterator.h
109

Maybe put data members after functions to follow the pattern we have in most (all?) other places in clangd?

This revision is now accepted and ready to land.Oct 4 2018, 3:04 AM
sammccall marked 5 inline comments as done.Oct 4 2018, 6:09 AM
sammccall added inline comments.
clangd/index/dex/Iterator.cpp
376

Actually this is deliberate, there's no particular need to specialize on every kind. (and in fact we have Or specialized on one fewer than And, but I wrote the case out in order to leave a comment)

385

Updated throughout.
(This file was inconsistent and I was trying to preserve... something, but I'm not sure what)

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