public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: "François Dumont" <frs.dumont@gmail.com>
Cc: "libstdc++" <libstdc++@gcc.gnu.org>,
	gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH 2/5][_Hashtable] Fix implementation inconsistencies
Date: Thu, 21 Dec 2023 22:07:10 +0000	[thread overview]
Message-ID: <CACb0b4mqTL4+UeZXkMnrEU+A=QLU2tco97F4MHxk8_6=X6gCfg@mail.gmail.com> (raw)
In-Reply-To: <1e319e88-62ae-476f-bae0-afa8ba126310@gmail.com>

On Thu, 23 Nov 2023 at 21:59, François Dumont <frs.dumont@gmail.com> wrote:
>
>      libstdc++: [_Hashtable] Fix some implementation inconsistencies
>
>      Get rid of the different usages of the mutable keyword. For
>      _Prime_rehash_policy methods are exported from the library, we need to
>      keep their const qualifier, so adapt implementation to update
> previously
>      mutable member.

If anybody ever declares a const _Prime_rehash_policy and then calls
its _M_next_bkt member or _M_need_rehash member they'll get undefined
behaviour, which seems bad. Probably nobody will ever do that, but if
we just leave the mutable member then that problem doesn't exist.

It would be possible to add non-const overlaods of _M_next_bkt and
_M_need_rehash, and then make the const ones do:

return const_cast<_Prime_rehash_policy*>(this)->_M_next_bkt(n);

or even just define the const symbol as an alias of the non-const
symbol, on targets that support that.  That would still be undefined
if somebody uses a const Prime_rehash_policy object somewhere, but it
would mean the definition of the member functions don't contain nasty
surprises, and new code would call the non-const version, which
doesn't use the unsafe const_cast.

>
>      Remove useless noexcept qualification on _Hashtable _M_bucket_index
> overload.
>      Fix comment to explain that we need the computation of bucket index
> to be
>      noexcept to be able to rehash the container when needed. For Standard
>      instantiations through std::unordered_xxx containers we already force
>      usage of hash code cache when hash functor is not noexcep so it is
> guarantied.
>      The static_assert purpose in _Hashtable on _M_bucket_index is thus
> limited
>      to usages of _Hashtable with exotic _Hashtable_traits.
>
>      libstdc++-v3/ChangeLog:
>
>              * include/bits/hashtable_policy.h
> (_NodeBuilder<>::_S_build): Remove
>              const qualification on _NodeGenerator instance.
> (_ReuseOrAllocNode<>::operator()(_Args&&...)): Remove const qualification.
>              (_ReuseOrAllocNode<>::_M_nodes): Remove mutable.
>              (_Prime_rehash_policy::max_load_factor()): Remove noexcept.

Why?

>              (_Prime_rehash_policy::_M_reset()): Remove noexcept.

Why?

Those functions really are noexcept, right? We should remove noexcept
where it's incorrect or misleading, but here it's OK, isn't it? Or am
I forgetting the problem being solved here?


>              (_Prime_rehash_policy::_M_next_resize): Remove mutable.
>              (_Power2_rehash_policy::_M_next_bkt(size_t)): Remove noexcept.
>              (_Power2_rehash_policy::_M_bkt_for_elements(size_t)):
> Remove noexcept.
>              (_Power2_rehash_policy::_M_neeed_rehash): Remove noexcept.
>              (_Power2_rehash_policy::_M_reset): Remove noexcept.
>              (_Insert_base<>::_M_insert_range): Remove _NodeGetter const
> qualification.
>              (_Hash_code_base<>::_M_bucket_index(const
> _Hash_node_value<>&, size_t)):
>              Simplify noexcept declaration, we already static_assert
> that _RangeHash functor
>              is noexcept.
>              * include/bits/hashtable.h: Rework comments. Remove const
> qualifier on
>              _NodeGenerator& arguments.
>              (_Hashtable<>::_M_bucket_index(const __node_value_type&)):
> Remove useless
>              noexcept qualification.
>              * src/c++11/hashtable_c++0x.cc (_Prime_rehash_policy):
> Workaround
>              _M_next_resize not being mutable anymore.
>
> Tested under Linux x86_64,
>
> ok to commit ?
>
> François


  reply	other threads:[~2023-12-21 22:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-23 21:58 François Dumont
2023-12-21 22:07 ` Jonathan Wakely [this message]
2024-01-03 18:04   ` François Dumont

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CACb0b4mqTL4+UeZXkMnrEU+A=QLU2tco97F4MHxk8_6=X6gCfg@mail.gmail.com' \
    --to=jwakely@redhat.com \
    --cc=frs.dumont@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).