This is an archive of the discontinued LLVM Phabricator instance.

Return None instead of Optional<T>() (NFC)
ClosedPublic

Authored by kazu on Nov 21 2022, 5:49 PM.

Details

Summary

This patch replaces:

return Optional<T>();

with:

return None;

to make the migration from llvm::Optional to std::optional easier.
Specifically, I can deprecate None (in my source tree, that is) to
identify all the instances of None that should be replaced with
std::nullopt.

Note that "return None" far outnumbers "return Optional<T>();". There
are more than 2000 instances of "return None" in our source tree.

All of the instances in this patch come from functions that return
Optional<T> except Archive::findSym and ASTNodeImporter::import, where
we return Expected<Optional<T>>. Note that we can construct
Expected<Optional<T>> from any parameter convertible to Optional<T>,
which None certainly is.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Diff Detail

Event Timeline

kazu created this revision.Nov 21 2022, 5:49 PM
Herald added a reviewer: aartbik. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
kazu requested review of this revision.Nov 21 2022, 5:49 PM
Herald added a reviewer: dcaballe. · View Herald Transcript
Herald added projects: Restricted Project, Restricted Project, Restricted Project. · View Herald Transcript
MaskRay accepted this revision.Nov 21 2022, 6:44 PM

We have return llvm::None; and return None;. Shall we always prefer llvm::None?

This revision is now accepted and ready to land.Nov 21 2022, 6:44 PM
kazu added a comment.Nov 21 2022, 6:54 PM

Thanks for the review!

We have return llvm::None; and return None;. Shall we always prefer llvm::None?

Either one is OK (to me). I can deprecate None in my personal tree, and get a warning for both llvm::None and None.

This revision was landed with ongoing or failed builds.Nov 21 2022, 7:06 PM
This revision was automatically updated to reflect the committed changes.