This is an archive of the discontinued LLVM Phabricator instance.

[ADT] Alias llvm::Optional to std::optional
ClosedPublic

Authored by bkramer on Dec 19 2022, 11:53 AM.

Details

Summary

This avoids the continuous API churn when upgrading things to use
std::optional and makes trivial string replace upgrades possible.

The needed tweaks are mostly trivial, the one nasty bit is Clang's usage
of OptionalStorage. To keep this working old Optional stays around as
clang::CustomizableOptional, with the default Storage removed.
Optional<File/DirectoryEntryRef> is replaced with a typedef.

I tested this with GCC 7.5, the oldest supported GCC I had around.

Diff Detail

Event Timeline

bkramer created this revision.Dec 19 2022, 11:53 AM
Herald added a reviewer: ftynse. · View Herald Transcript
Herald added a reviewer: NoQ. · View Herald Transcript
Herald added a reviewer: njames93. · View Herald Transcript
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
bkramer requested review of this revision.Dec 19 2022, 11:53 AM
Herald added a reviewer: herhut. · View Herald Transcript
Herald added a reviewer: dcaballe. · View Herald Transcript
Herald added projects: Restricted Project, Restricted Project, Restricted Project, Restricted Project, Restricted Project. · View Herald Transcript

Worth trying on MSVC, which is the other more likely place to fail.

barannikov88 added inline comments.
clang/lib/Basic/TargetInfo.cpp
513

Nit: C-style casts are generally discouraged (there are several occurrences in this patch).

llvm/lib/CodeGen/RegAllocGreedy.h
83 ↗(On Diff #484030)

Is it somehow different than ' = default'?

mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp
182 ↗(On Diff #484030)

clang-tidy would usually complain on this. Does it solve some gcc issue?

Can you push using OptionalFileEntryRef = CustomizableOptional<FileEntryRef>; and the renaming as a separate commit to make this patch smaller?
There is a smaller that this rename may be reverted.
205c0589f918f95d2f2c586a01bea2716d73d603 reverted a change related to OptionalFileEntryRef. I assume that your change is fine.

mlir/include/mlir/IR/Visitors.h
49 ↗(On Diff #484030)

Can be pushed separately

bkramer marked an inline comment as done.Dec 19 2022, 2:48 PM
bkramer added inline comments.
clang/lib/Basic/TargetInfo.cpp
513

-> static_cast

llvm/lib/CodeGen/RegAllocGreedy.h
83 ↗(On Diff #484030)

It makes the class non-trivial, std::optional::emplace has issues with trivial default constructors :(

mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp
182 ↗(On Diff #484030)

It does, this is a bug in GCC 7.

bkramer marked an inline comment as done.Dec 19 2022, 2:49 PM

Can you push using OptionalFileEntryRef = CustomizableOptional<FileEntryRef>; and the renaming as a separate commit to make this patch smaller?
There is a smaller that this rename may be reverted.
205c0589f918f95d2f2c586a01bea2716d73d603 reverted a change related to OptionalFileEntryRef. I assume that your change is fine.

Yeah, I'll split this into smaller pieces once we agree on the direction and just submit the alias. I expect a revert or two.

MaskRay accepted this revision.Dec 19 2022, 2:50 PM
This revision is now accepted and ready to land.Dec 19 2022, 2:50 PM
barannikov88 accepted this revision.Dec 19 2022, 2:58 PM
barannikov88 added inline comments.
llvm/lib/CodeGen/RegAllocGreedy.h
83 ↗(On Diff #484030)

Ah, right, thanks.

This revision was landed with ongoing or failed builds.Dec 19 2022, 3:49 PM
This revision was automatically updated to reflect the committed changes.
kazu added a comment.Dec 20 2022, 3:10 PM

Thank you for this patch!