This is an archive of the discontinued LLVM Phabricator instance.

[WIP][libc++] Use checked iterators with std::span when the debug mode is enabled
AbandonedPublic

Authored by ldionne on Jun 9 2022, 6:00 AM.

Details

Reviewers
None
Group Reviewers
Restricted Project
Summary

Previously, we'd use raw pointers instead of __wrap_iter, which means
we wouldn't get out-of-range checking with std::span's iterators, which
is really useful. Unfortunately, the current implementation of the debug
mode implies that a bunch of non-trivial calls need to be inserted in
span's constructors and destructors, which is not ideal. In particular,
it means that we cannot keep std::span trivially copyable and destructible
when the debug mode is enabled.

As a fly-by change, this commit removes the _LIBCPP_ABI_SPAN_POINTER_ITERATORS
knob -- not using raw pointers in place of iterators is extremely useful
for users not to start depending on properties of iterators that are not
guaranteed, which allows them to e.g. enable the debug mode without fixing
their code.

As a follow-up change, I suggest reworking the underlying implementation
of the debug mode such that containers don't need to be registered in
order to get bounds-checking iterators.

Diff Detail

Event Timeline

ldionne created this revision.Jun 9 2022, 6:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 9 2022, 6:00 AM
Herald added a subscriber: arphaman. · View Herald Transcript
ldionne requested review of this revision.Jun 9 2022, 6:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 9 2022, 6:00 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
ldionne planned changes to this revision.Jun 9 2022, 7:03 AM

Upon making more progress on the successor to this patch, I think it might make more sense to skip directly to the "real" thing. Putting on the ice for now.

ldionne abandoned this revision.Jun 13 2022, 9:06 AM
libcxx/test/std/containers/views/views.span/span.sub/last.verify.cpp