This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Disable _LIBCPP_DEBUG_ASSERT during constant evaluation
ClosedPublic

Authored by philnik on Dec 15 2021, 1:04 AM.

Details

Summary

Disable _LIBCPP_DEBUG_ASSERT and debug iterators in <string> during constant evaluation

Diff Detail

Event Timeline

philnik requested review of this revision.Dec 15 2021, 1:04 AM
philnik created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptDec 15 2021, 1:04 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
philnik updated this revision to Diff 394483.Dec 15 2021, 1:10 AM

Added <__debug> changes

philnik retitled this revision from [libc++] Disable debug bookkeeping during constant evaluation to [libc++] Disable debug bookkeeping during constant evaluation in <string>.Dec 15 2021, 1:19 AM
philnik edited the summary of this revision. (Show Details)
philnik updated this revision to Diff 394487.Dec 15 2021, 1:33 AM
  • Forgot an !
libcxx/include/__debug
37

This feels like a change in meaning, from "Assert in debug mode" to "Assert specifically concerned with debug iterators." It turns out that this macro has pretty much always been used with the latter meaning, though, so even though a better name might be _LIBCPP_DEBUG_ITERATOR_ASSERT, I think this is fine.

However, the one place in libc++ that doesn't use the macro with the latter meaning, needs to be updated to use _LIBCPP_ASSERT instead.

../libcxx/include/bit:    _LIBCPP_DEBUG_ASSERT(__libcpp_is_constant_evaluated() || __n != numeric_limits<_Tp>::digits, "Bad input to bit_ceil");

I think this should just be _LIBCPP_ASSERT(__n != numeric_limits<_Tp>::digits, "Bad input to bit_ceil"); and if that's not right then investigation is needed as to why that's not right.

Then, please update the summary/commit-message to talk about the semantic change here, which I think is more important than the <string> part. Something like, "_LIBCPP_DEBUG_ASSERT is now used strictly for debug iterators, and disabled during constant evaluation." Observe that this is a change for both <__hash_table> (since ages ago) and <string> (since D115765).

libcxx/include/string
828–832

Somewhere in the past year I'd suggested something like

_LIBCPP_IF_DEBUG_ITERATORS(
  __get_db()->__insert_c(this);
)

which could simplify this repeated pattern. Thoughts on reviving that idea?

2990

Stray blank line here

philnik added inline comments.Dec 15 2021, 10:13 AM
libcxx/include/__debug
37

There are not that many usages of _LIBCPP_DEBUG_ASSERT. Maybe it would be good to change the meaning and rename it to _LIBCPP_DEBUG_ITERATOR_ASSERT in another patch?

libcxx/include/string
828–832

I do quite like the idea of _LIBCPP_IF_DEBUG_ITERATORS. Should I make this a more general patch to simplify the debug iterators across the repo, or would that be too much?

ldionne requested changes to this revision.Dec 15 2021, 2:25 PM
ldionne added inline comments.
libcxx/include/__debug
37

IMO this is fine, but needs to be called out in the commit message. Basically, the important thing this patch is doing is that we're not going to check debug-only assertions inside constant expressions anymore. I think that's acceptable, since those assertions are meant to catch things like UB, and the compiler will do that for us during constexpr evaluation.

libcxx/include/string
828–832

I am leery of adding a bunch of macros as "shortcuts" for these things. I think the current approach is fine.

3497

After your patch, this is a mix of 4 space and 2 space indentation. Please consistently use 4 space in this file, since that's what is done for the other functions in that file.

This applies to all the other functions you touched AFAICT.

This revision now requires changes to proceed.Dec 15 2021, 2:25 PM
philnik updated this revision to Diff 394842.Dec 16 2021, 5:49 AM
philnik marked 6 inline comments as done.
  • Changed indentation
  • Replaced _LIBCPP_DEBUG_ASSET with _LIBCPP_ASSERT in <bit>
philnik updated this revision to Diff 394843.Dec 16 2021, 5:54 AM
  • More indentation changes
philnik updated this revision to Diff 394844.Dec 16 2021, 5:56 AM
  • And even more
philnik retitled this revision from [libc++] Disable debug bookkeeping during constant evaluation in <string> to [libc++] Disable _LIBCPP_DEBUG_ASSERT during constant evaluation.Dec 16 2021, 6:02 AM
philnik edited the summary of this revision. (Show Details)
ldionne accepted this revision.Dec 16 2021, 6:27 AM
This revision is now accepted and ready to land.Dec 16 2021, 6:27 AM

Why have non-libc++ builds been triggered? Can I land with them failing? They don't seem to fail because of this patch.

Why have non-libc++ builds been triggered?

I don't know. @goncharov ?

Can I land with them failing? They don't seem to fail because of this patch.

Yes, you can land if the libc++ CI is green, but thanks for being diligent and asking.

philnik updated this revision to Diff 394986.Dec 16 2021, 1:46 PM
philnik edited the summary of this revision. (Show Details)

Rebased