This is an archive of the discontinued LLVM Phabricator instance.

[libc++][format] Removes optional dependency.
AbandonedPublic

Authored by Mordante on May 7 2023, 3:23 AM.

Details

Reviewers
None
Group Reviewers
Restricted Project
Summary

This is not strictly required, but avoids potential circular header
dependencies when there will be an formatter specialization for
optional.

Diff Detail

Event Timeline

Mordante created this revision.May 7 2023, 3:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 7 2023, 3:23 AM
Mordante updated this revision to Diff 520164.May 7 2023, 4:08 AM

CI fixes.

Mordante published this revision for review.May 7 2023, 5:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 7 2023, 5:52 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
ldionne added a subscriber: ldionne.May 9 2023, 9:45 AM
ldionne added inline comments.
libcxx/include/__format/format_context.h
17

IMO it would be nice to be able to keep using optional here. I am not concerned about potential circular dependency problems because we could always granularize <optional> into <__optional/optional.h> and <__optional/formatter.h>. Then here you'd include <__optional/optional.h> only.

71–75

It's surprising to provide a move constructor here if the underlying locale is not movable. Also, should we be disengaging __other?

77–85

If you retain this, you could inline __assign into operator=(__locale const&) and call operator=(__locale const&) from operator=(__locale&&). And actually you don't need to provide operator=(__locale&&) at all, since the copy-assignment will be used if you do x = std::move(y) and x only has a copy-assignment.

EricWF added a subscriber: EricWF.May 16 2023, 12:18 PM

I'm with ldionne that we should keep using optional here. The correctness seems like a very important quality that we'll be loosing some certainty in.

libcxx/include/__format/format_context.h
56

I think __locale is already a class inside namespace std. I would prefer that we use a slightly different name so it's more clear when the type is spelled elsewhere.

Mordante abandoned this revision.May 18 2023, 10:26 AM

I'm with ldionne that we should keep using optional here. The correctness seems like a very important quality that we'll be loosing some certainty in.

My main concern was when we need a formatter<optional, charT>. In D150509 I tested an alternative approach as suggested by Louis, which works without creating header cycles. So when somebody writes a paper for such a formatter we don't risk possible ABI breaks.

(MSVC STL and libstdc++ don't use an optional to implement the locale.)

Since the alternative works, this patch will be abandoned.