[v3 PATCH, RFC] Rewrite variant. Also PR libstdc++/85517
Ville Voutilainen
ville.voutilainen@gmail.com
Sun Mar 3 23:26:00 GMT 2019
On Wed, 6 Feb 2019 at 15:12, Ville Voutilainen
<ville.voutilainen@gmail.com> wrote:
> And, to emphasize, the most important reason for this was to be able
> to write straightforward
> code for the special member functions, with the hope that it wouldn't
> have a negative codegen
> effect. Our Microsoft friends described the general technique as "has
> crazy-good codegen",
> but I have no idea what their starting point was; our starting point
> probably wasn't bad
> to begin with.
However, the codegen should be somewhat improved; this patch removes a
bag of run-time ifs from the implementation.
An amended patch attached. This gets rid of all __erased* stuff,
including hash, swap, constructors, relops.
I consider variant to no longer be in the state of sin after this.
Since this is touching just a C++17 facility with no
impact elsewhere, we could consider landing it in GCC 9 as a late
change. Failing that, it certainly seems safe enough
to put into GCC 9.2.
2019-03-04 Ville Voutilainen <ville.voutilainen@gmail.com>
Rewrite variant.
Also PR libstdc++/85517
* include/std/variant (__do_visit): New.
(__variant_cast): Likewise.
(__variant_cookie): Likewise.
(__erased_*): Remove.
(_Variant_storage::_S_vtable): Likewise.
(_Variant_storage::__M_reset_impl): Adjust to use __do_visit.
(_Variant_storage::__M_reset): Adjust.
(_Copy_ctor_base(const _Copy_ctor_base&)): Adjust to use __do_visit.
(_Move_ctor_base(_Move_ctor_base&&)): Likewise.
(_Move_ctor_base::__M_destructive_copy): New.
(_Copy_assign_base::operator=): Adjust to use __do_visit.
(_Copy_assign_alias): Adjust to check both copy assignment
and copy construction for triviality.
(_Move_assign_base::operator=): Adjust to use __do_visit.
(_Multi_array): Add support for visitors that accept and return
a __variant_cookie.
(__gen_vtable_impl::_S_apply_all_alts): Likewise.
(__gen_vtable_impl::_S_apply_single_alt): Likewise.
(__gen_vtable_impl::__element_by_index_or_cookie): New. Generate
a __variant_cookie temporary for a variant that is valueless and..
(__gen_vtable_impl::__visit_invoke): ..adjust here.
(__gen_vtable::_Array_type): Conditionally make space for
the __variant_cookie visitor case.
(relops): Adjust to use __do_visit.
(variant): Add __variant_cast as a friend.
(variant::emplace): Use _M_reset() instead of self-destruction.
(visit): Reimplement in terms of __do_visit.
* testsuite/20_util/variant/compile.cc: Adjust.
* testsuite/20_util/variant/run.cc: Likewise.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: variant-redesign-2.diff
Type: text/x-patch
Size: 25986 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20190303/d45abce3/attachment.bin>
More information about the Gcc-patches
mailing list