This is an archive of the discontinued LLVM Phabricator instance.

[libc++][format] Removes vector dependency.
ClosedPublic

Authored by Mordante on Apr 20 2023, 11:52 AM.

Details

Reviewers
ldionne
Group Reviewers
Restricted Project
Commits
rG03c7b93aab35: [libc++][format] Removes vector dependency.
Summary

During the review of D140653 it was suggested to use vector in
__retarget_buffer instead of manually managing the memory. Due to the
requirements of the Standard it turns out format needs to include vector
leading to a cycle. Therefore switching back to manual memory
management.

This is a preparation to fix https://llvm.org/PR61314

Diff Detail

Event Timeline

Mordante created this revision.Apr 20 2023, 11:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 20 2023, 11:52 AM
Mordante published this revision for review.Apr 22 2023, 3:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 22 2023, 3:31 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript

Do you plan to move this back to vector, or is this a permanent change? If this is permanent, could you maybe elaborate a bit on the exact cycle this creates, and why this can't be resolved by moving the code around a bit?

libcxx/include/__format/buffer.h
554

Why the #ifdef? __allocate_at_least was specifically designed to be able to write auto __alloc_result = std::__allocate_at_least(...). (Although, thinking about it we should just have a converting constructor from allocation_result)

Do you plan to move this back to vector, or is this a permanent change? If this is permanent, could you maybe elaborate a bit on the exact cycle this creates, and why this can't be resolved by moving the code around a bit?

Mark tried to split <vector> into vector<T> and vector<bool> in another revision I don't have handy right now, and we decided not to go down that route.

libcxx/include/__format/buffer.h
567

A bit subtle otherwise.

594–595

Could you confirm that for char, std::uninitialized_default_construct_n(__ptr_ + __size_, __n); is optimized out?

615–619

Same comment, personally I think auto __result = std::__allocate_at_least(__alloc_, __capacity); would be better, since this is not ABI-sensitive.

If we don't feel comfortable using this trick, then we should change how we designed __allocate_at_least.

620

If this line somehow throws, we'll leak the allocation result above. This is definitely a nitpick cause it should never throw, I guess (those are characters).

I won't feel strongly if you don't think it's worth addressing, however if you do want to address it, I think we could try to modify __allocation_guard so that it plays nicely with __allocate_at_least.

philnik added inline comments.Apr 25 2023, 10:54 AM
libcxx/include/__format/buffer.h
615–619

P2652R2 changed the interface anyways, so we might as well update it then.

Mordante updated this revision to Diff 517601.Apr 27 2023, 9:27 AM
Mordante marked 5 inline comments as done.

Addresses review comments.

Mordante marked an inline comment as done.Apr 27 2023, 9:30 AM

Thanks for the reviews!

libcxx/include/__format/buffer.h
554

Changed to this version.

594–595

I verified it -O1 suffices https://godbolt.org/z/Ex5cafPfY

620

I do not really like to modify the __allocation_guard IMO we have an ___exception_guard which can do the same without additional effort. (In fact it seems __allocation_guard is only used once.

This too is optimized away https://godbolt.org/z/c71GzE63o so I added it.

Mordante updated this revision to Diff 517618.Apr 27 2023, 9:53 AM
Mordante marked an inline comment as done.

Trigger CI.

Mordante updated this revision to Diff 517631.Apr 27 2023, 10:23 AM

Trigger CI.

Mordante updated this revision to Diff 517653.Apr 27 2023, 11:12 AM

Rebased and updated transitive includes.

ldionne accepted this revision.Apr 28 2023, 12:28 PM
This revision is now accepted and ready to land.Apr 28 2023, 12:28 PM
This revision was landed with ongoing or failed builds.Apr 30 2023, 4:33 AM
This revision was automatically updated to reflect the committed changes.