This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Replace Optional in ScopeExitGuard (fix after r322838)
AbandonedPublic

Authored by ilya-biryukov on Jan 25 2018, 3:32 AM.

Details

Reviewers
sammccall
Summary

r322838 changed semantics for llvm::Optional that removes the
guarantee of setting the value to empty after move.
This change creates a wrapper around Optional that gives this
guarantee, it is useful for code dealing with empty values that could
be moved.

Event Timeline

ilya-biryukov created this revision.Jan 25 2018, 3:32 AM
sammccall added inline comments.Jan 25 2018, 3:52 AM
clangd/Function.h
141

As noted in the thread I don't think this pulls its weight for us.
Swapping unique_ptr for optional doesn't seem like it'll ever be a bottleneck for us. If we really must avoid the allocation for some reason then adding move logic to ScopeExitGuard seems simpler.
If you feel strongly about keeping this as a separate concept, it should really go in llvm/ADT/Optional.h, and probably needs a new name.

ilya-biryukov added inline comments.Jan 25 2018, 4:27 AM
clangd/Function.h
141

It's not a bottleneck, but I don't see why something like ScopeExitGuard should incur an overhead of an extra alloc that needs to be done by unique_ptr.
That also seems like a nice reusable concept for move-only things.

I don't subscribe to the view that this class carries much weight. It's a really simple wrapper. It will probably get much more complicated if we want to support the general case (i.e. make it a substitute of llvm::Optional with extra semantics). And I don't see how we can put it into ADT/Optional.h without supporting the general case.

r323443 removed ScopeExitGuard altogether.

ilya-biryukov abandoned this revision.Jan 26 2018, 3:56 AM