From: Martin Sebor <msebor@gmail.com>
To: Trevor Saunders <tbsaunde@tbsaunde.org>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH 1/6] auto_vec copy/move improvements
Date: Tue, 15 Jun 2021 10:18:30 -0600 [thread overview]
Message-ID: <75e9c91d-ce9f-4366-1934-027d1b0784fa@gmail.com> (raw)
In-Reply-To: <20210615055922.27205-1-tbsaunde@tbsaunde.org>
On 6/14/21 11:59 PM, Trevor Saunders wrote:
> - Unfortunately using_auto_storage () needs to handle m_vec being null.
> - Handle self move of an auto_vec to itself.
> - punt on defining copy or move operators for auto_vec with inline storage,
> until there is a need for them and we can decide what semantics they should
> have.
> - Make sure auto_vec defines the classes move constructor and assignment
> operator, as well as ones taking vec<T>, so the compiler does not generate
> them for us. Per https://en.cppreference.com/w/cpp/language/move_constructor
> the ones taking vec<T> do not count as the classes move constructor or
> assignment operator, but we want them as well to assign a plain vec to a
> auto_vec.
> - Explicitly delete auto_vec's copy constructor and assignment operator. This
> prevents unintentional expenssive coppies of the vector and makes it clear
> when coppies are needed that that is what is intended. When it is necessary to
> copy a vector copy () can be used.
>
> Signed-off-by: Trevor Saunders <tbsaunde@tbsaunde.org>
>
> bootstrapped and regtested on x86_64-linux-gnu, ok?
>
> gcc/ChangeLog:
>
> * vec.h (vl_ptr>::using_auto_storage): Handle null m_vec.
> (auto_vec<T, 0>::auto_vec): Define move constructor, and delete copy
> constructor.
> (auto_vec<T, 0>::operator=): Define move assignment and delete copy
> assignment.
> (auto_vec<T, N>::auto_vec): Delete copy and move constructors.
> (auto_vec<T, N>::operator=): Delete copy and move assignment.
auto_vec should be copy constructible and copy assignable to be
usable as its own element (for example). There is nothing to gain
by preventing it but make auto_vec harder to use.
Martin
> ---
> gcc/vec.h | 41 ++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 40 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/vec.h b/gcc/vec.h
> index 193377cb69c..ceefa67e1ad 100644
> --- a/gcc/vec.h
> +++ b/gcc/vec.h
> @@ -1549,6 +1549,16 @@ public:
> this->release ();
> }
>
> + // Punt for now on moving auto_vec with inline storage. For now this
> + // prevents people creating dangling pointers or the like.
> + auto_vec (auto_vec &&) = delete;
> + auto_vec &operator= (auto_vec &&) = delete;
> +
> + // Punt for now on the inline storage, and you probably don't want to copy
> + // vectors anyway. If you really must copy a vector use copy ().
> + auto_vec(const auto_vec &) = delete;
> + auto_vec &operator= (const auto_vec &) = delete;
> +
> private:
> vec<T, va_heap, vl_embed> m_auto;
> T m_data[MAX (N - 1, 1)];
> @@ -1570,14 +1580,43 @@ public:
> this->m_vec = r.m_vec;
> r.m_vec = NULL;
> }
> +
> + auto_vec (auto_vec<T> &&r)
> + {
> + gcc_assert (!r.using_auto_storage ());
> + this->m_vec = r.m_vec;
> + r.m_vec = NULL;
> + }
> +
> auto_vec& operator= (vec<T, va_heap>&& r)
> {
> + if (this == &r)
> + return *this;
> +
> + gcc_assert (!r.using_auto_storage ());
> + this->release ();
> + this->m_vec = r.m_vec;
> + r.m_vec = NULL;
> + return *this;
> + }
> +
> + auto_vec& operator= (auto_vec<T> &&r)
> + {
> + if (this == &r)
> + return *this;
> +
> gcc_assert (!r.using_auto_storage ());
> this->release ();
> this->m_vec = r.m_vec;
> r.m_vec = NULL;
> return *this;
> }
> +
> + // You probably don't want to copy a vector, so these are deleted to prevent
> + // unintentional use. If you really need a copy of the vectors contents you
> + // can use copy ().
> + auto_vec(const auto_vec &) = delete;
> + auto_vec &operator= (const auto_vec &) = delete;
> };
>
>
> @@ -2147,7 +2186,7 @@ template<typename T>
> inline bool
> vec<T, va_heap, vl_ptr>::using_auto_storage () const
> {
> - return m_vec->m_vecpfx.m_using_auto_storage;
> + return m_vec ? m_vec->m_vecpfx.m_using_auto_storage : false;
> }
>
> /* Release VEC and call release of all element vectors. */
>
next prev parent reply other threads:[~2021-06-15 16:18 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-15 5:59 Trevor Saunders
2021-06-15 5:59 ` [PATCH 2/6] return auto_vec from cgraph_node::collect_callers Trevor Saunders
2021-06-15 6:45 ` Richard Biener
2021-06-15 5:59 ` [PATCH 3/6] return auto_vec from get_loop_hot_path Trevor Saunders
2021-06-15 6:45 ` Richard Biener
2021-06-17 13:48 ` Christophe Lyon
2021-06-17 14:41 ` Trevor Saunders
2021-06-17 18:34 ` Christophe Lyon
2021-06-15 5:59 ` [PATCH 4/6] return auto_vec from get_dominated_by Trevor Saunders
2021-06-15 6:46 ` Richard Biener
2021-06-15 11:18 ` Bernhard Reutner-Fischer
2021-06-16 3:09 ` Trevor Saunders
2021-06-16 5:45 ` Bernhard Reutner-Fischer
2021-06-17 6:56 ` Trevor Saunders
2021-06-15 5:59 ` [PATCH 5/6] make get_domminated_by_region return a auto_vec Trevor Saunders
2021-06-15 6:49 ` Richard Biener
2021-06-16 12:46 ` Richard Sandiford
2021-06-16 16:01 ` Martin Sebor
2021-06-17 6:03 ` Richard Biener
2021-06-17 8:23 ` Trevor Saunders
2021-06-17 14:43 ` Martin Sebor
2021-06-18 10:38 ` Richard Biener
2021-06-18 10:53 ` Jakub Jelinek
2021-06-18 11:03 ` Jonathan Wakely
2021-06-18 11:04 ` Jonathan Wakely
2021-06-18 16:03 ` Martin Sebor
2021-06-21 7:15 ` Richard Biener
2021-06-22 20:01 ` Martin Sebor
2021-06-23 5:23 ` Trevor Saunders
2021-06-23 7:43 ` Richard Biener
2021-06-23 10:22 ` Richard Sandiford
2021-06-24 9:20 ` Richard Biener
2021-06-24 16:28 ` Richard Sandiford
2021-06-25 8:29 ` Richard Biener
2021-06-23 22:56 ` Martin Sebor
2021-06-24 9:27 ` Richard Biener
2021-06-24 15:01 ` Martin Sebor
2021-06-23 23:43 ` Martin Sebor
2021-06-28 7:01 ` Trevor Saunders
2021-06-15 5:59 ` [PATCH 6/6] return auto_vec from more dominance functions Trevor Saunders
2021-06-15 6:50 ` Richard Biener
2021-06-15 6:42 ` [PATCH 1/6] auto_vec copy/move improvements Richard Biener
2021-06-15 7:04 ` Trevor Saunders
2021-06-15 7:11 ` Richard Biener
2021-06-15 7:57 ` Trevor Saunders
2021-06-15 9:36 ` Richard Biener
2021-06-16 3:17 ` [PATCH, V2] " Trevor Saunders
2021-06-16 10:13 ` Richard Biener
2021-06-16 17:01 ` Martin Sebor
2021-06-15 16:18 ` Martin Sebor [this message]
2021-06-16 3:31 ` [PATCH 1/6] " Trevor Saunders
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=75e9c91d-ce9f-4366-1934-027d1b0784fa@gmail.com \
--to=msebor@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=tbsaunde@tbsaunde.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).