Message ID | ri6lerbgdt4.fsf@suse.cz |
---|---|
State | New, archived |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp315412wro; Fri, 26 Aug 2022 09:39:24 -0700 (PDT) X-Google-Smtp-Source: AA6agR6YGa6a9MWpNzvtxi7Mm9lOmsj71ENsZuReIE44yelN/05cFq9HntNLsmjBIOP/dkw7AfxO X-Received: by 2002:a17:907:2708:b0:73d:5a17:a48d with SMTP id w8-20020a170907270800b0073d5a17a48dmr5875899ejk.35.1661531964100; Fri, 26 Aug 2022 09:39:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661531964; cv=none; d=google.com; s=arc-20160816; b=y/nZUJxUUPkrti87HM4Gr5hC0c39Aj+L+MmmVfeuMjwz/oK3fYwnrilokV7d2OyTz2 sKFD06nGKg/a/Ko+2rLPg2kw3ltzbZsoJAZ2NSvlykelfLtId5xkXvE6DcR2k9U3FRv6 VvLoT0crcF1Kb2rxD34ejsKvVLpAYIJV5pcoSGVY5OM0JRq3mc4M/P7DmW0JkZyVtULM eo4PcpH7jXZ9xaX7VwNgs95XZ4qeLPXehlbKnD4VzaCg/uHKhXkHUr5bv3w3+VPvGLFO XZIAr8SKBcKP/8/4kBPh+QIqD6EG8+SwFzOp2Bh60TTFLfeI+MzMAyDFjwWxRgjtmdlO NiUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:message-id:date :user-agent:subject:to:from:dkim-signature:dkim-signature :dmarc-filter:delivered-to; bh=BAzBpaBXTdHxPO/xloCAAdw7KVJWg5vdVhqJ04JHZPA=; b=loz4DZdgRnmJN9Wnd1UDq0vFt3BSm62GYlmKcK6AXBXDXnpz4+n3HZ/r4Yl0+Oc4Ds y394ZQxfeNVy2IJLGTcDSroSyy7EmzE4bkSKNeJsDfKZ63Si7jlDMDtNERbth7rgzlCr oqPXI5j2WsMPHCLpyJ2vdETPVAlX6SNoCm8T/pSpDSSN3WjtbwYVVMorr+QkliIUGPGB pddkhpR1KG7ObA8jrWWF6rzO0jUk//l/FCl7umgIgX7Uqu5VV17qANMKNIPUrohbTyCP HFeBWU3oS2wlKOi+re5WwCAjdsLORm/UnmE4UDai9KPEpFqd/p1IGBvJtVpWsYAvApAk zkSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@suse.cz header.s=susede2_rsa header.b=JXLqR17P; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=t3MbTCq3; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id e6-20020a17090658c600b00730936657d1si1627337ejs.552.2022.08.26.09.39.23 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Aug 2022 09:39:24 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=fail header.i=@suse.cz header.s=susede2_rsa header.b=JXLqR17P; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=t3MbTCq3; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5A8CA38515E9 for <ouuuleilei@gmail.com>; Fri, 26 Aug 2022 16:39:12 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id BCBE138515FD for <gcc-patches@gcc.gnu.org>; Fri, 26 Aug 2022 16:38:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BCBE138515FD Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id AB96A1F91D; Fri, 26 Aug 2022 16:38:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1661531927; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=BAzBpaBXTdHxPO/xloCAAdw7KVJWg5vdVhqJ04JHZPA=; b=JXLqR17PzNDq5LSmUIFBx1N6df4D+NyHZYZyjFbJR8zyKpBw4u8wO6tRuQ9e8dX1JkHa0D YJGAM3kQRBLWWy4xgUi/YaGpWaNW+ChaoHKVzXOWiMKl5karICL3zBin6opSoegVCNkGW9 yNaIVP4hnk+2Vl98bnm7GuXfRQXOUb8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1661531927; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=BAzBpaBXTdHxPO/xloCAAdw7KVJWg5vdVhqJ04JHZPA=; b=t3MbTCq3etJSf9sG7taqiWtHqfJCbPn5fIPbJcO6IvYMZpElxqUB6nyaSd07No6ULLQ1yw wJlw6CHmQI3DEVAQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 9DACB13421; Fri, 26 Aug 2022 16:38:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id b1FzJhf3CGMtdwAAMHmgww (envelope-from <mjambor@suse.cz>); Fri, 26 Aug 2022 16:38:47 +0000 From: Martin Jambor <mjambor@suse.cz> To: GCC Patches <gcc-patches@gcc.gnu.org> Subject: [PATCH 1/2] vec: Add array_slice constructors from non-const and gc vectors User-Agent: Notmuch/0.35 (https://notmuchmail.org) Emacs/28.1 (x86_64-suse-linux-gnu) Date: Fri, 26 Aug 2022 18:38:47 +0200 Message-ID: <ri6lerbgdt4.fsf@suse.cz> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Cc: Richard Sandiford <richard.sandiford@arm.com>, Richard Biener <rguenther@suse.de> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1742242540590713059?= X-GMAIL-MSGID: =?utf-8?q?1742242540590713059?= |
Series |
[1/2] vec: Add array_slice constructors from non-const and gc vectors
|
|
Commit Message
Martin Jambor
Aug. 26, 2022, 4:38 p.m. UTC
Hi, This patch adds constructors of array_slice that are required to create them from non-const (heap or auto) vectors or from GC vectors. The use of non-const array_slices is somewhat limited, as creating one from const vec<some_type> still leads to array_slice<const some_type>, so I eventually also only resorted to having read-only array_slices. But I do need the constructor from the gc vector. Bootstrapped and tested along code that actually uses it on x86_64-linux. OK for trunk? Thanks, Martin gcc/ChangeLog: 2022-08-08 Martin Jambor <mjambor@suse.cz> * vec.h (array_slice): Add constructors for non-const reference to heap vector and pointers to heap vectors. --- gcc/vec.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
Comments
> Am 26.08.2022 um 18:39 schrieb Martin Jambor <mjambor@suse.cz>: > > Hi, > > This patch adds constructors of array_slice that are required to > create them from non-const (heap or auto) vectors or from GC vectors. > > The use of non-const array_slices is somewhat limited, as creating one > from const vec<some_type> still leads to array_slice<const some_type>, > so I eventually also only resorted to having read-only array_slices. > But I do need the constructor from the gc vector. > > Bootstrapped and tested along code that actually uses it on > x86_64-linux. OK for trunk? > > Thanks, > > Martin > > > gcc/ChangeLog: > > 2022-08-08 Martin Jambor <mjambor@suse.cz> > > * vec.h (array_slice): Add constructors for non-const reference to > heap vector and pointers to heap vectors. > --- > gcc/vec.h | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/gcc/vec.h b/gcc/vec.h > index eed075addc9..b0477e1044c 100644 > --- a/gcc/vec.h > +++ b/gcc/vec.h > @@ -2264,6 +2264,18 @@ public: > array_slice (const vec<OtherT> &v) > : m_base (v.address ()), m_size (v.length ()) {} > > + template<typename OtherT> > + array_slice (vec<OtherT> &v) > + : m_base (v.address ()), m_size (v.length ()) {} > + > + template<typename OtherT> > + array_slice (const vec<OtherT, va_gc> *v) > + : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {} > + > + template<typename OtherT> > + array_slice (vec<OtherT, va_gc> *v) > + : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {} > + I don’t quite understand why the generic ctor doesn’t cover the GC case. It looks more like reference vs pointer? > iterator begin () { return m_base; } > iterator end () { return m_base + m_size; } > > -- > 2.37.2 >
Hi, On Fri, Aug 26 2022, Richard Biener wrote: >> Am 26.08.2022 um 18:39 schrieb Martin Jambor <mjambor@suse.cz>: >> >> Hi, >> >> This patch adds constructors of array_slice that are required to >> create them from non-const (heap or auto) vectors or from GC vectors. >> >> The use of non-const array_slices is somewhat limited, as creating one >> from const vec<some_type> still leads to array_slice<const some_type>, >> so I eventually also only resorted to having read-only array_slices. >> But I do need the constructor from the gc vector. >> >> Bootstrapped and tested along code that actually uses it on >> x86_64-linux. OK for trunk? >> >> Thanks, >> >> Martin >> >> >> gcc/ChangeLog: >> >> 2022-08-08 Martin Jambor <mjambor@suse.cz> >> >> * vec.h (array_slice): Add constructors for non-const reference to >> heap vector and pointers to heap vectors. >> --- >> gcc/vec.h | 12 ++++++++++++ >> 1 file changed, 12 insertions(+) >> >> diff --git a/gcc/vec.h b/gcc/vec.h >> index eed075addc9..b0477e1044c 100644 >> --- a/gcc/vec.h >> +++ b/gcc/vec.h >> @@ -2264,6 +2264,18 @@ public: >> array_slice (const vec<OtherT> &v) >> : m_base (v.address ()), m_size (v.length ()) {} >> >> + template<typename OtherT> >> + array_slice (vec<OtherT> &v) >> + : m_base (v.address ()), m_size (v.length ()) {} >> + >> + template<typename OtherT> >> + array_slice (const vec<OtherT, va_gc> *v) >> + : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {} >> + >> + template<typename OtherT> >> + array_slice (vec<OtherT, va_gc> *v) >> + : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {} >> + > > I don’t quite understand why the generic ctor doesn’t cover the GC case. It looks more like reference vs pointer? > If you think that this should work: vec<tree, va_gc> *heh = cfun->local_decls; array_slice<tree> arr_slice (*heh); then it does not: /home/mjambor/gcc/mine/src/gcc/ipa-cp.cc:6693:36: error: no matching function for call to ‘array_slice<tree_node*>::array_slice(vec<tree_node*, va_gc>&)’ 6693 | array_slice<tree> arr_slice (*heh); | ^ In file included from /home/mjambor/gcc/mine/src/gcc/hash-table.h:248, from /home/mjambor/gcc/mine/src/gcc/coretypes.h:486, from /home/mjambor/gcc/mine/src/gcc/ipa-cp.cc:105: /home/mjambor/gcc/mine/src/gcc/vec.h:2264:3: note: candidate: ‘template<class OtherT> array_slice<T>::array_slice(const vec<OtherT>&) [with T = tree_node*]’ 2264 | array_slice (const vec<OtherT> &v) | ^~~~~~~~~~~ /home/mjambor/gcc/mine/src/gcc/vec.h:2264:3: note: template argument deduction/substitution failed: /home/mjambor/gcc/mine/src/gcc/ipa-cp.cc:6693:36: note: mismatched types ‘va_heap’ and ‘va_gc’ 6693 | array_slice<tree> arr_slice (*heh); | ^ [... I trimmed notes about all other candidates...] Or did you mean something else? Thanks, Martin
On Fri, 26 Aug 2022, Martin Jambor wrote: > Hi, > > On Fri, Aug 26 2022, Richard Biener wrote: > >> Am 26.08.2022 um 18:39 schrieb Martin Jambor <mjambor@suse.cz>: > >> > >> Hi, > >> > >> This patch adds constructors of array_slice that are required to > >> create them from non-const (heap or auto) vectors or from GC vectors. > >> > >> The use of non-const array_slices is somewhat limited, as creating one > >> from const vec<some_type> still leads to array_slice<const some_type>, > >> so I eventually also only resorted to having read-only array_slices. > >> But I do need the constructor from the gc vector. > >> > >> Bootstrapped and tested along code that actually uses it on > >> x86_64-linux. OK for trunk? > >> > >> Thanks, > >> > >> Martin > >> > >> > >> gcc/ChangeLog: > >> > >> 2022-08-08 Martin Jambor <mjambor@suse.cz> > >> > >> * vec.h (array_slice): Add constructors for non-const reference to > >> heap vector and pointers to heap vectors. > >> --- > >> gcc/vec.h | 12 ++++++++++++ > >> 1 file changed, 12 insertions(+) > >> > >> diff --git a/gcc/vec.h b/gcc/vec.h > >> index eed075addc9..b0477e1044c 100644 > >> --- a/gcc/vec.h > >> +++ b/gcc/vec.h > >> @@ -2264,6 +2264,18 @@ public: > >> array_slice (const vec<OtherT> &v) > >> : m_base (v.address ()), m_size (v.length ()) {} > >> > >> + template<typename OtherT> > >> + array_slice (vec<OtherT> &v) > >> + : m_base (v.address ()), m_size (v.length ()) {} > >> + > >> + template<typename OtherT> > >> + array_slice (const vec<OtherT, va_gc> *v) > >> + : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {} > >> + > >> + template<typename OtherT> > >> + array_slice (vec<OtherT, va_gc> *v) > >> + : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {} > >> + > > > > I don?t quite understand why the generic ctor doesn?t cover the GC case. It looks more like reference vs pointer? > > > > If you think that this should work: > > vec<tree, va_gc> *heh = cfun->local_decls; > array_slice<tree> arr_slice (*heh); > > then it does not: > > /home/mjambor/gcc/mine/src/gcc/ipa-cp.cc:6693:36: error: no matching function for call to ?array_slice<tree_node*>::array_slice(vec<tree_node*, va_gc>&)? > 6693 | array_slice<tree> arr_slice (*heh); > | ^ > In file included from /home/mjambor/gcc/mine/src/gcc/hash-table.h:248, > from /home/mjambor/gcc/mine/src/gcc/coretypes.h:486, > from /home/mjambor/gcc/mine/src/gcc/ipa-cp.cc:105: > /home/mjambor/gcc/mine/src/gcc/vec.h:2264:3: note: candidate: ?template<class OtherT> array_slice<T>::array_slice(const vec<OtherT>&) [with T = tree_node*]? > 2264 | array_slice (const vec<OtherT> &v) > | ^~~~~~~~~~~ > /home/mjambor/gcc/mine/src/gcc/vec.h:2264:3: note: template argument deduction/substitution failed: > /home/mjambor/gcc/mine/src/gcc/ipa-cp.cc:6693:36: note: mismatched types ?va_heap? and ?va_gc? > 6693 | array_slice<tree> arr_slice (*heh); > | ^ > > [... I trimmed notes about all other candidates...] > > Or did you mean something else? Hmm, so what if you change template<typename OtherT> array_slice (const vec<OtherT> &v) : m_base (v.address ()), m_size (v.length ()) {} to template<typename OtherT, typename l, typename a> array_slice (const vec<OtherT, l, a> &v) : m_base (v.address ()), m_size (v.length ()) {} instead? Thus allow any allocation / placement template arg? Richard. > Thanks, > > Martin >
Hi, On Mon, Aug 29 2022, Richard Biener wrote: > On Fri, 26 Aug 2022, Martin Jambor wrote: > >> Hi, >> >> On Fri, Aug 26 2022, Richard Biener wrote: >> >> Am 26.08.2022 um 18:39 schrieb Martin Jambor <mjambor@suse.cz>: >> >> >> >> Hi, >> >> >> >> This patch adds constructors of array_slice that are required to >> >> create them from non-const (heap or auto) vectors or from GC vectors. >> >> >> >> The use of non-const array_slices is somewhat limited, as creating one >> >> from const vec<some_type> still leads to array_slice<const some_type>, >> >> so I eventually also only resorted to having read-only array_slices. >> >> But I do need the constructor from the gc vector. >> >> >> >> Bootstrapped and tested along code that actually uses it on >> >> x86_64-linux. OK for trunk? >> >> >> >> Thanks, >> >> >> >> Martin >> >> >> >> >> >> gcc/ChangeLog: >> >> >> >> 2022-08-08 Martin Jambor <mjambor@suse.cz> >> >> >> >> * vec.h (array_slice): Add constructors for non-const reference to >> >> heap vector and pointers to heap vectors. >> >> --- >> >> gcc/vec.h | 12 ++++++++++++ >> >> 1 file changed, 12 insertions(+) >> >> >> >> diff --git a/gcc/vec.h b/gcc/vec.h >> >> index eed075addc9..b0477e1044c 100644 >> >> --- a/gcc/vec.h >> >> +++ b/gcc/vec.h >> >> @@ -2264,6 +2264,18 @@ public: >> >> array_slice (const vec<OtherT> &v) >> >> : m_base (v.address ()), m_size (v.length ()) {} >> >> >> >> + template<typename OtherT> >> >> + array_slice (vec<OtherT> &v) >> >> + : m_base (v.address ()), m_size (v.length ()) {} >> >> + >> >> + template<typename OtherT> >> >> + array_slice (const vec<OtherT, va_gc> *v) >> >> + : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {} >> >> + >> >> + template<typename OtherT> >> >> + array_slice (vec<OtherT, va_gc> *v) >> >> + : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {} >> >> + >> > >> > I don?t quite understand why the generic ctor doesn?t cover the GC case. It looks more like reference vs pointer? >> > >> >> If you think that this should work: >> >> vec<tree, va_gc> *heh = cfun->local_decls; >> array_slice<tree> arr_slice (*heh); >> >> then it does not: >> >> /home/mjambor/gcc/mine/src/gcc/ipa-cp.cc:6693:36: error: no matching function for call to ?array_slice<tree_node*>::array_slice(vec<tree_node*, va_gc>&)? >> 6693 | array_slice<tree> arr_slice (*heh); >> | ^ >> In file included from /home/mjambor/gcc/mine/src/gcc/hash-table.h:248, >> from /home/mjambor/gcc/mine/src/gcc/coretypes.h:486, >> from /home/mjambor/gcc/mine/src/gcc/ipa-cp.cc:105: >> /home/mjambor/gcc/mine/src/gcc/vec.h:2264:3: note: candidate: ?template<class OtherT> array_slice<T>::array_slice(const vec<OtherT>&) [with T = tree_node*]? >> 2264 | array_slice (const vec<OtherT> &v) >> | ^~~~~~~~~~~ >> /home/mjambor/gcc/mine/src/gcc/vec.h:2264:3: note: template argument deduction/substitution failed: >> /home/mjambor/gcc/mine/src/gcc/ipa-cp.cc:6693:36: note: mismatched types ?va_heap? and ?va_gc? >> 6693 | array_slice<tree> arr_slice (*heh); >> | ^ >> >> [... I trimmed notes about all other candidates...] >> >> Or did you mean something else? > > Hmm, so what if you change > > template<typename OtherT> > array_slice (const vec<OtherT> &v) > : m_base (v.address ()), m_size (v.length ()) {} > > to > > template<typename OtherT, typename l, typename a> > array_slice (const vec<OtherT, l, a> &v) > : m_base (v.address ()), m_size (v.length ()) {} > > instead? Thus allow any allocation / placement template arg? I tried this on Friday night too (but I was already only half awake) and it led to some very weird self-test ICEs (and so I went to bed). (I can try again but debugging such things is not quite what I wanted to spend my time on :-) Martin
Hi again, On Mon, Aug 29 2022, Richard Biener wrote: > On Fri, 26 Aug 2022, Martin Jambor wrote: > >> Hi, >> >> On Fri, Aug 26 2022, Richard Biener wrote: >> >> Am 26.08.2022 um 18:39 schrieb Martin Jambor <mjambor@suse.cz>: >> >> >> >> Hi, >> >> >> >> This patch adds constructors of array_slice that are required to >> >> create them from non-const (heap or auto) vectors or from GC vectors. >> >> >> >> The use of non-const array_slices is somewhat limited, as creating one >> >> from const vec<some_type> still leads to array_slice<const some_type>, >> >> so I eventually also only resorted to having read-only array_slices. >> >> But I do need the constructor from the gc vector. >> >> >> >> Bootstrapped and tested along code that actually uses it on >> >> x86_64-linux. OK for trunk? >> >> >> >> Thanks, >> >> >> >> Martin >> >> >> >> >> >> gcc/ChangeLog: >> >> >> >> 2022-08-08 Martin Jambor <mjambor@suse.cz> >> >> >> >> * vec.h (array_slice): Add constructors for non-const reference to >> >> heap vector and pointers to heap vectors. >> >> --- >> >> gcc/vec.h | 12 ++++++++++++ >> >> 1 file changed, 12 insertions(+) >> >> >> >> diff --git a/gcc/vec.h b/gcc/vec.h >> >> index eed075addc9..b0477e1044c 100644 >> >> --- a/gcc/vec.h >> >> +++ b/gcc/vec.h >> >> @@ -2264,6 +2264,18 @@ public: >> >> array_slice (const vec<OtherT> &v) >> >> : m_base (v.address ()), m_size (v.length ()) {} >> >> >> >> + template<typename OtherT> >> >> + array_slice (vec<OtherT> &v) >> >> + : m_base (v.address ()), m_size (v.length ()) {} >> >> + >> >> + template<typename OtherT> >> >> + array_slice (const vec<OtherT, va_gc> *v) >> >> + : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {} >> >> + >> >> + template<typename OtherT> >> >> + array_slice (vec<OtherT, va_gc> *v) >> >> + : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {} >> >> + >> > >> > I don?t quite understand why the generic ctor doesn?t cover the GC case. It looks more like reference vs pointer? >> > >> >> If you think that this should work: >> >> vec<tree, va_gc> *heh = cfun->local_decls; >> array_slice<tree> arr_slice (*heh); >> >> then it does not: >> >> /home/mjambor/gcc/mine/src/gcc/ipa-cp.cc:6693:36: error: no matching function for call to ?array_slice<tree_node*>::array_slice(vec<tree_node*, va_gc>&)? >> 6693 | array_slice<tree> arr_slice (*heh); >> | ^ >> In file included from /home/mjambor/gcc/mine/src/gcc/hash-table.h:248, >> from /home/mjambor/gcc/mine/src/gcc/coretypes.h:486, >> from /home/mjambor/gcc/mine/src/gcc/ipa-cp.cc:105: >> /home/mjambor/gcc/mine/src/gcc/vec.h:2264:3: note: candidate: ?template<class OtherT> array_slice<T>::array_slice(const vec<OtherT>&) [with T = tree_node*]? >> 2264 | array_slice (const vec<OtherT> &v) >> | ^~~~~~~~~~~ >> /home/mjambor/gcc/mine/src/gcc/vec.h:2264:3: note: template argument deduction/substitution failed: >> /home/mjambor/gcc/mine/src/gcc/ipa-cp.cc:6693:36: note: mismatched types ?va_heap? and ?va_gc? >> 6693 | array_slice<tree> arr_slice (*heh); >> | ^ >> >> [... I trimmed notes about all other candidates...] >> >> Or did you mean something else? > > Hmm, so what if you change > > template<typename OtherT> > array_slice (const vec<OtherT> &v) > : m_base (v.address ()), m_size (v.length ()) {} > > to > > template<typename OtherT, typename l, typename a> > array_slice (const vec<OtherT, l, a> &v) > : m_base (v.address ()), m_size (v.length ()) {} > > instead? Thus allow any allocation / placement template arg? > So being fully awake helps, the issue was of course in how I tested the code, the above works fine and I can adapt my code to use that. However, is it really preferable? We often use NULL as to mean zero-length vector, which my code handled gracefully: + template<typename OtherT> + array_slice (const vec<OtherT, va_gc> *v) + : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {} whereas using the generic method will mean that users constructing the vector will have to special case it - and I bet most will end up using the above sequence and the constructor from explicit pointer and size in all constructors from gc vectors. So, should I really change the patch and my code? Thanks, Martin
On Mon, 29 Aug 2022, Martin Jambor wrote: > Hi again, > > On Mon, Aug 29 2022, Richard Biener wrote: > > On Fri, 26 Aug 2022, Martin Jambor wrote: > > > >> Hi, > >> > >> On Fri, Aug 26 2022, Richard Biener wrote: > >> >> Am 26.08.2022 um 18:39 schrieb Martin Jambor <mjambor@suse.cz>: > >> >> > >> >> Hi, > >> >> > >> >> This patch adds constructors of array_slice that are required to > >> >> create them from non-const (heap or auto) vectors or from GC vectors. > >> >> > >> >> The use of non-const array_slices is somewhat limited, as creating one > >> >> from const vec<some_type> still leads to array_slice<const some_type>, > >> >> so I eventually also only resorted to having read-only array_slices. > >> >> But I do need the constructor from the gc vector. > >> >> > >> >> Bootstrapped and tested along code that actually uses it on > >> >> x86_64-linux. OK for trunk? > >> >> > >> >> Thanks, > >> >> > >> >> Martin > >> >> > >> >> > >> >> gcc/ChangeLog: > >> >> > >> >> 2022-08-08 Martin Jambor <mjambor@suse.cz> > >> >> > >> >> * vec.h (array_slice): Add constructors for non-const reference to > >> >> heap vector and pointers to heap vectors. > >> >> --- > >> >> gcc/vec.h | 12 ++++++++++++ > >> >> 1 file changed, 12 insertions(+) > >> >> > >> >> diff --git a/gcc/vec.h b/gcc/vec.h > >> >> index eed075addc9..b0477e1044c 100644 > >> >> --- a/gcc/vec.h > >> >> +++ b/gcc/vec.h > >> >> @@ -2264,6 +2264,18 @@ public: > >> >> array_slice (const vec<OtherT> &v) > >> >> : m_base (v.address ()), m_size (v.length ()) {} > >> >> > >> >> + template<typename OtherT> > >> >> + array_slice (vec<OtherT> &v) > >> >> + : m_base (v.address ()), m_size (v.length ()) {} > >> >> + > >> >> + template<typename OtherT> > >> >> + array_slice (const vec<OtherT, va_gc> *v) > >> >> + : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {} > >> >> + > >> >> + template<typename OtherT> > >> >> + array_slice (vec<OtherT, va_gc> *v) > >> >> + : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {} > >> >> + > >> > > >> > I don?t quite understand why the generic ctor doesn?t cover the GC case. It looks more like reference vs pointer? > >> > > >> > >> If you think that this should work: > >> > >> vec<tree, va_gc> *heh = cfun->local_decls; > >> array_slice<tree> arr_slice (*heh); > >> > >> then it does not: > >> > >> /home/mjambor/gcc/mine/src/gcc/ipa-cp.cc:6693:36: error: no matching function for call to ?array_slice<tree_node*>::array_slice(vec<tree_node*, va_gc>&)? > >> 6693 | array_slice<tree> arr_slice (*heh); > >> | ^ > >> In file included from /home/mjambor/gcc/mine/src/gcc/hash-table.h:248, > >> from /home/mjambor/gcc/mine/src/gcc/coretypes.h:486, > >> from /home/mjambor/gcc/mine/src/gcc/ipa-cp.cc:105: > >> /home/mjambor/gcc/mine/src/gcc/vec.h:2264:3: note: candidate: ?template<class OtherT> array_slice<T>::array_slice(const vec<OtherT>&) [with T = tree_node*]? > >> 2264 | array_slice (const vec<OtherT> &v) > >> | ^~~~~~~~~~~ > >> /home/mjambor/gcc/mine/src/gcc/vec.h:2264:3: note: template argument deduction/substitution failed: > >> /home/mjambor/gcc/mine/src/gcc/ipa-cp.cc:6693:36: note: mismatched types ?va_heap? and ?va_gc? > >> 6693 | array_slice<tree> arr_slice (*heh); > >> | ^ > >> > >> [... I trimmed notes about all other candidates...] > >> > >> Or did you mean something else? > > > > Hmm, so what if you change > > > > template<typename OtherT> > > array_slice (const vec<OtherT> &v) > > : m_base (v.address ()), m_size (v.length ()) {} > > > > to > > > > template<typename OtherT, typename l, typename a> > > array_slice (const vec<OtherT, l, a> &v) > > : m_base (v.address ()), m_size (v.length ()) {} > > > > instead? Thus allow any allocation / placement template arg? > > > > So being fully awake helps, the issue was of course in how I tested the > code, the above works fine and I can adapt my code to use that. > > However, is it really preferable? > > We often use NULL as to mean zero-length vector, which my code handled > gracefully: > > + template<typename OtherT> > + array_slice (const vec<OtherT, va_gc> *v) > + : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {} > > whereas using the generic method will mean that users constructing the > vector will have to special case it - and I bet most will end up using > the above sequence and the constructor from explicit pointer and size in > all constructors from gc vectors. > > So, should I really change the patch and my code? Well, it's also inconsistent with a supposed use like vec<tree> *v = NULL; auto slice = array_slice (v); no? So, if we want to provide a "safe" (as in, handle NULL pointer) CTOR, don't we want to handle non-GC allocated vectors the same way? Btw, we have template<size_t N> array_slice (T (&array)[N]) : m_base (array), m_size (N) {} which would suggest handling NULL isn't desired(?) Richard.
Hi, On Mon, Aug 29 2022, Richard Biener wrote: > On Mon, 29 Aug 2022, Martin Jambor wrote: > >> Hi again, >> >> On Mon, Aug 29 2022, Richard Biener wrote: >> > On Fri, 26 Aug 2022, Martin Jambor wrote: >> > >> >> Hi, >> >> >> >> On Fri, Aug 26 2022, Richard Biener wrote: >> >> >> Am 26.08.2022 um 18:39 schrieb Martin Jambor <mjambor@suse.cz>: >> >> >> >> >> >> Hi, >> >> >> >> >> >> This patch adds constructors of array_slice that are required to >> >> >> create them from non-const (heap or auto) vectors or from GC vectors. >> >> >> >> >> >> The use of non-const array_slices is somewhat limited, as creating one >> >> >> from const vec<some_type> still leads to array_slice<const some_type>, >> >> >> so I eventually also only resorted to having read-only array_slices. >> >> >> But I do need the constructor from the gc vector. >> >> >> >> >> >> Bootstrapped and tested along code that actually uses it on >> >> >> x86_64-linux. OK for trunk? >> >> >> >> >> >> Thanks, >> >> >> >> >> >> Martin >> >> >> >> >> >> >> >> >> gcc/ChangeLog: >> >> >> >> >> >> 2022-08-08 Martin Jambor <mjambor@suse.cz> >> >> >> >> >> >> * vec.h (array_slice): Add constructors for non-const reference to >> >> >> heap vector and pointers to heap vectors. >> >> >> --- >> >> >> gcc/vec.h | 12 ++++++++++++ >> >> >> 1 file changed, 12 insertions(+) >> >> >> >> >> >> diff --git a/gcc/vec.h b/gcc/vec.h >> >> >> index eed075addc9..b0477e1044c 100644 >> >> >> --- a/gcc/vec.h >> >> >> +++ b/gcc/vec.h >> >> >> @@ -2264,6 +2264,18 @@ public: >> >> >> array_slice (const vec<OtherT> &v) >> >> >> : m_base (v.address ()), m_size (v.length ()) {} >> >> >> >> >> >> + template<typename OtherT> >> >> >> + array_slice (vec<OtherT> &v) >> >> >> + : m_base (v.address ()), m_size (v.length ()) {} >> >> >> + >> >> >> + template<typename OtherT> >> >> >> + array_slice (const vec<OtherT, va_gc> *v) >> >> >> + : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {} >> >> >> + >> >> >> + template<typename OtherT> >> >> >> + array_slice (vec<OtherT, va_gc> *v) >> >> >> + : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {} >> >> >> + >> >> > >> >> > I don?t quite understand why the generic ctor doesn?t cover the GC case. It looks more like reference vs pointer? >> >> > >> >> >> >> If you think that this should work: >> >> >> >> vec<tree, va_gc> *heh = cfun->local_decls; >> >> array_slice<tree> arr_slice (*heh); >> >> >> >> then it does not: >> >> >> >> /home/mjambor/gcc/mine/src/gcc/ipa-cp.cc:6693:36: error: no matching function for call to ?array_slice<tree_node*>::array_slice(vec<tree_node*, va_gc>&)? >> >> 6693 | array_slice<tree> arr_slice (*heh); >> >> | ^ >> >> In file included from /home/mjambor/gcc/mine/src/gcc/hash-table.h:248, >> >> from /home/mjambor/gcc/mine/src/gcc/coretypes.h:486, >> >> from /home/mjambor/gcc/mine/src/gcc/ipa-cp.cc:105: >> >> /home/mjambor/gcc/mine/src/gcc/vec.h:2264:3: note: candidate: ?template<class OtherT> array_slice<T>::array_slice(const vec<OtherT>&) [with T = tree_node*]? >> >> 2264 | array_slice (const vec<OtherT> &v) >> >> | ^~~~~~~~~~~ >> >> /home/mjambor/gcc/mine/src/gcc/vec.h:2264:3: note: template argument deduction/substitution failed: >> >> /home/mjambor/gcc/mine/src/gcc/ipa-cp.cc:6693:36: note: mismatched types ?va_heap? and ?va_gc? >> >> 6693 | array_slice<tree> arr_slice (*heh); >> >> | ^ >> >> >> >> [... I trimmed notes about all other candidates...] >> >> >> >> Or did you mean something else? >> > >> > Hmm, so what if you change >> > >> > template<typename OtherT> >> > array_slice (const vec<OtherT> &v) >> > : m_base (v.address ()), m_size (v.length ()) {} >> > >> > to >> > >> > template<typename OtherT, typename l, typename a> >> > array_slice (const vec<OtherT, l, a> &v) >> > : m_base (v.address ()), m_size (v.length ()) {} >> > >> > instead? Thus allow any allocation / placement template arg? >> > >> >> So being fully awake helps, the issue was of course in how I tested the >> code, the above works fine and I can adapt my code to use that. >> >> However, is it really preferable? >> >> We often use NULL as to mean zero-length vector, which my code handled >> gracefully: >> >> + template<typename OtherT> >> + array_slice (const vec<OtherT, va_gc> *v) >> + : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {} >> >> whereas using the generic method will mean that users constructing the >> vector will have to special case it - and I bet most will end up using >> the above sequence and the constructor from explicit pointer and size in >> all constructors from gc vectors. >> >> So, should I really change the patch and my code? > > Well, it's also inconsistent with a supposed use like > > vec<tree> *v = NULL; > auto slice = array_slice (v); > > no? So, if we want to provide a "safe" (as in, handle NULL pointer) > CTOR, don't we want to handle non-GC allocated vectors the same way? > Our safe_* functions usually do no work with normal non-GC vectors (which are not vl_embed), they do not accept them. I guess that is because that is not how we use normal vectors, we usually pass around vNULL to mean empty vector of that type. So I'd at least be consistent with our inconsistencies. But whatever, I can have both reference and pointer template constructors, I can resort to constructing them from v->address() and v->length() too. I do not care much, I guess I trust your sense of code esthetics more than mine, just please let me know what you prefer and I'll go with that. > Btw, we have > > template<size_t N> > array_slice (T (&array)[N]) : m_base (array), m_size (N) {} > > which would suggest handling NULL isn't desired(?) > That is not how I read for example: // True if the array is valid, false if it is an array like INVALID. bool is_valid () const { return m_base || m_size == 0; } And IMHO it would be a very very strange limitation too. Martin
On Mon, 29 Aug 2022, Martin Jambor wrote: > Hi, > > On Mon, Aug 29 2022, Richard Biener wrote: > > On Mon, 29 Aug 2022, Martin Jambor wrote: > > > >> Hi again, > >> > >> On Mon, Aug 29 2022, Richard Biener wrote: > >> > On Fri, 26 Aug 2022, Martin Jambor wrote: > >> > > >> >> Hi, > >> >> > >> >> On Fri, Aug 26 2022, Richard Biener wrote: > >> >> >> Am 26.08.2022 um 18:39 schrieb Martin Jambor <mjambor@suse.cz>: > >> >> >> > >> >> >> Hi, > >> >> >> > >> >> >> This patch adds constructors of array_slice that are required to > >> >> >> create them from non-const (heap or auto) vectors or from GC vectors. > >> >> >> > >> >> >> The use of non-const array_slices is somewhat limited, as creating one > >> >> >> from const vec<some_type> still leads to array_slice<const some_type>, > >> >> >> so I eventually also only resorted to having read-only array_slices. > >> >> >> But I do need the constructor from the gc vector. > >> >> >> > >> >> >> Bootstrapped and tested along code that actually uses it on > >> >> >> x86_64-linux. OK for trunk? > >> >> >> > >> >> >> Thanks, > >> >> >> > >> >> >> Martin > >> >> >> > >> >> >> > >> >> >> gcc/ChangeLog: > >> >> >> > >> >> >> 2022-08-08 Martin Jambor <mjambor@suse.cz> > >> >> >> > >> >> >> * vec.h (array_slice): Add constructors for non-const reference to > >> >> >> heap vector and pointers to heap vectors. > >> >> >> --- > >> >> >> gcc/vec.h | 12 ++++++++++++ > >> >> >> 1 file changed, 12 insertions(+) > >> >> >> > >> >> >> diff --git a/gcc/vec.h b/gcc/vec.h > >> >> >> index eed075addc9..b0477e1044c 100644 > >> >> >> --- a/gcc/vec.h > >> >> >> +++ b/gcc/vec.h > >> >> >> @@ -2264,6 +2264,18 @@ public: > >> >> >> array_slice (const vec<OtherT> &v) > >> >> >> : m_base (v.address ()), m_size (v.length ()) {} > >> >> >> > >> >> >> + template<typename OtherT> > >> >> >> + array_slice (vec<OtherT> &v) > >> >> >> + : m_base (v.address ()), m_size (v.length ()) {} > >> >> >> + > >> >> >> + template<typename OtherT> > >> >> >> + array_slice (const vec<OtherT, va_gc> *v) > >> >> >> + : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {} > >> >> >> + > >> >> >> + template<typename OtherT> > >> >> >> + array_slice (vec<OtherT, va_gc> *v) > >> >> >> + : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {} > >> >> >> + > >> >> > > >> >> > I don?t quite understand why the generic ctor doesn?t cover the GC case. It looks more like reference vs pointer? > >> >> > > >> >> > >> >> If you think that this should work: > >> >> > >> >> vec<tree, va_gc> *heh = cfun->local_decls; > >> >> array_slice<tree> arr_slice (*heh); > >> >> > >> >> then it does not: > >> >> > >> >> /home/mjambor/gcc/mine/src/gcc/ipa-cp.cc:6693:36: error: no matching function for call to ?array_slice<tree_node*>::array_slice(vec<tree_node*, va_gc>&)? > >> >> 6693 | array_slice<tree> arr_slice (*heh); > >> >> | ^ > >> >> In file included from /home/mjambor/gcc/mine/src/gcc/hash-table.h:248, > >> >> from /home/mjambor/gcc/mine/src/gcc/coretypes.h:486, > >> >> from /home/mjambor/gcc/mine/src/gcc/ipa-cp.cc:105: > >> >> /home/mjambor/gcc/mine/src/gcc/vec.h:2264:3: note: candidate: ?template<class OtherT> array_slice<T>::array_slice(const vec<OtherT>&) [with T = tree_node*]? > >> >> 2264 | array_slice (const vec<OtherT> &v) > >> >> | ^~~~~~~~~~~ > >> >> /home/mjambor/gcc/mine/src/gcc/vec.h:2264:3: note: template argument deduction/substitution failed: > >> >> /home/mjambor/gcc/mine/src/gcc/ipa-cp.cc:6693:36: note: mismatched types ?va_heap? and ?va_gc? > >> >> 6693 | array_slice<tree> arr_slice (*heh); > >> >> | ^ > >> >> > >> >> [... I trimmed notes about all other candidates...] > >> >> > >> >> Or did you mean something else? > >> > > >> > Hmm, so what if you change > >> > > >> > template<typename OtherT> > >> > array_slice (const vec<OtherT> &v) > >> > : m_base (v.address ()), m_size (v.length ()) {} > >> > > >> > to > >> > > >> > template<typename OtherT, typename l, typename a> > >> > array_slice (const vec<OtherT, l, a> &v) > >> > : m_base (v.address ()), m_size (v.length ()) {} > >> > > >> > instead? Thus allow any allocation / placement template arg? > >> > > >> > >> So being fully awake helps, the issue was of course in how I tested the > >> code, the above works fine and I can adapt my code to use that. > >> > >> However, is it really preferable? > >> > >> We often use NULL as to mean zero-length vector, which my code handled > >> gracefully: > >> > >> + template<typename OtherT> > >> + array_slice (const vec<OtherT, va_gc> *v) > >> + : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {} > >> > >> whereas using the generic method will mean that users constructing the > >> vector will have to special case it - and I bet most will end up using > >> the above sequence and the constructor from explicit pointer and size in > >> all constructors from gc vectors. > >> > >> So, should I really change the patch and my code? > > > > Well, it's also inconsistent with a supposed use like > > > > vec<tree> *v = NULL; > > auto slice = array_slice (v); > > > > no? So, if we want to provide a "safe" (as in, handle NULL pointer) > > CTOR, don't we want to handle non-GC allocated vectors the same way? > > > > Our safe_* functions usually do no work with normal non-GC vectors > (which are not vl_embed), they do not accept them. I guess that is > because that is not how we use normal vectors, we usually pass around > vNULL to mean empty vector of that type. So I'd at least be consistent > with our inconsistencies. > > But whatever, I can have both reference and pointer template > constructors, I can resort to constructing them from v->address() and > v->length() too. I do not care much, I guess I trust your sense of code > esthetics more than mine, just please let me know what you prefer and > I'll go with that. > > > Btw, we have > > > > template<size_t N> > > array_slice (T (&array)[N]) : m_base (array), m_size (N) {} > > > > which would suggest handling NULL isn't desired(?) > > > > That is not how I read for example: > > // True if the array is valid, false if it is an array like INVALID. > bool is_valid () const { return m_base || m_size == 0; } > > And IMHO it would be a very very strange limitation too. I see. That said, the high number of CTORs does look a bit odd, but I'm fine with them if Richard is. Thanks and sorry for throwing in wrenches, Richard.
Richard Biener <rguenther@suse.de> writes: > On Mon, 29 Aug 2022, Martin Jambor wrote: > >> Hi, >> >> On Mon, Aug 29 2022, Richard Biener wrote: >> > On Mon, 29 Aug 2022, Martin Jambor wrote: >> > >> >> Hi again, >> >> >> >> On Mon, Aug 29 2022, Richard Biener wrote: >> >> > On Fri, 26 Aug 2022, Martin Jambor wrote: >> >> > >> >> >> Hi, >> >> >> >> >> >> On Fri, Aug 26 2022, Richard Biener wrote: >> >> >> >> Am 26.08.2022 um 18:39 schrieb Martin Jambor <mjambor@suse.cz>: >> >> >> >> >> >> >> >> Hi, >> >> >> >> >> >> >> >> This patch adds constructors of array_slice that are required to >> >> >> >> create them from non-const (heap or auto) vectors or from GC vectors. >> >> >> >> >> >> >> >> The use of non-const array_slices is somewhat limited, as creating one >> >> >> >> from const vec<some_type> still leads to array_slice<const some_type>, >> >> >> >> so I eventually also only resorted to having read-only array_slices. >> >> >> >> But I do need the constructor from the gc vector. >> >> >> >> >> >> >> >> Bootstrapped and tested along code that actually uses it on >> >> >> >> x86_64-linux. OK for trunk? >> >> >> >> >> >> >> >> Thanks, >> >> >> >> >> >> >> >> Martin >> >> >> >> >> >> >> >> >> >> >> >> gcc/ChangeLog: >> >> >> >> >> >> >> >> 2022-08-08 Martin Jambor <mjambor@suse.cz> >> >> >> >> >> >> >> >> * vec.h (array_slice): Add constructors for non-const reference to >> >> >> >> heap vector and pointers to heap vectors. >> >> >> >> --- >> >> >> >> gcc/vec.h | 12 ++++++++++++ >> >> >> >> 1 file changed, 12 insertions(+) >> >> >> >> >> >> >> >> diff --git a/gcc/vec.h b/gcc/vec.h >> >> >> >> index eed075addc9..b0477e1044c 100644 >> >> >> >> --- a/gcc/vec.h >> >> >> >> +++ b/gcc/vec.h >> >> >> >> @@ -2264,6 +2264,18 @@ public: >> >> >> >> array_slice (const vec<OtherT> &v) >> >> >> >> : m_base (v.address ()), m_size (v.length ()) {} >> >> >> >> >> >> >> >> + template<typename OtherT> >> >> >> >> + array_slice (vec<OtherT> &v) >> >> >> >> + : m_base (v.address ()), m_size (v.length ()) {} >> >> >> >> + >> >> >> >> + template<typename OtherT> >> >> >> >> + array_slice (const vec<OtherT, va_gc> *v) >> >> >> >> + : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {} >> >> >> >> + >> >> >> >> + template<typename OtherT> >> >> >> >> + array_slice (vec<OtherT, va_gc> *v) >> >> >> >> + : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {} >> >> >> >> + >> >> >> > >> >> >> > I don?t quite understand why the generic ctor doesn?t cover the GC case. It looks more like reference vs pointer? >> >> >> > >> >> >> >> >> >> If you think that this should work: >> >> >> >> >> >> vec<tree, va_gc> *heh = cfun->local_decls; >> >> >> array_slice<tree> arr_slice (*heh); >> >> >> >> >> >> then it does not: >> >> >> >> >> >> /home/mjambor/gcc/mine/src/gcc/ipa-cp.cc:6693:36: error: no matching function for call to ?array_slice<tree_node*>::array_slice(vec<tree_node*, va_gc>&)? >> >> >> 6693 | array_slice<tree> arr_slice (*heh); >> >> >> | ^ >> >> >> In file included from /home/mjambor/gcc/mine/src/gcc/hash-table.h:248, >> >> >> from /home/mjambor/gcc/mine/src/gcc/coretypes.h:486, >> >> >> from /home/mjambor/gcc/mine/src/gcc/ipa-cp.cc:105: >> >> >> /home/mjambor/gcc/mine/src/gcc/vec.h:2264:3: note: candidate: ?template<class OtherT> array_slice<T>::array_slice(const vec<OtherT>&) [with T = tree_node*]? >> >> >> 2264 | array_slice (const vec<OtherT> &v) >> >> >> | ^~~~~~~~~~~ >> >> >> /home/mjambor/gcc/mine/src/gcc/vec.h:2264:3: note: template argument deduction/substitution failed: >> >> >> /home/mjambor/gcc/mine/src/gcc/ipa-cp.cc:6693:36: note: mismatched types ?va_heap? and ?va_gc? >> >> >> 6693 | array_slice<tree> arr_slice (*heh); >> >> >> | ^ >> >> >> >> >> >> [... I trimmed notes about all other candidates...] >> >> >> >> >> >> Or did you mean something else? >> >> > >> >> > Hmm, so what if you change >> >> > >> >> > template<typename OtherT> >> >> > array_slice (const vec<OtherT> &v) >> >> > : m_base (v.address ()), m_size (v.length ()) {} >> >> > >> >> > to >> >> > >> >> > template<typename OtherT, typename l, typename a> >> >> > array_slice (const vec<OtherT, l, a> &v) >> >> > : m_base (v.address ()), m_size (v.length ()) {} >> >> > >> >> > instead? Thus allow any allocation / placement template arg? >> >> > >> >> >> >> So being fully awake helps, the issue was of course in how I tested the >> >> code, the above works fine and I can adapt my code to use that. >> >> >> >> However, is it really preferable? >> >> >> >> We often use NULL as to mean zero-length vector, which my code handled >> >> gracefully: >> >> >> >> + template<typename OtherT> >> >> + array_slice (const vec<OtherT, va_gc> *v) >> >> + : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {} >> >> >> >> whereas using the generic method will mean that users constructing the >> >> vector will have to special case it - and I bet most will end up using >> >> the above sequence and the constructor from explicit pointer and size in >> >> all constructors from gc vectors. >> >> >> >> So, should I really change the patch and my code? >> > >> > Well, it's also inconsistent with a supposed use like >> > >> > vec<tree> *v = NULL; >> > auto slice = array_slice (v); >> > >> > no? So, if we want to provide a "safe" (as in, handle NULL pointer) >> > CTOR, don't we want to handle non-GC allocated vectors the same way? >> > >> >> Our safe_* functions usually do no work with normal non-GC vectors >> (which are not vl_embed), they do not accept them. I guess that is >> because that is not how we use normal vectors, we usually pass around >> vNULL to mean empty vector of that type. So I'd at least be consistent >> with our inconsistencies. >> >> But whatever, I can have both reference and pointer template >> constructors, I can resort to constructing them from v->address() and >> v->length() too. I do not care much, I guess I trust your sense of code >> esthetics more than mine, just please let me know what you prefer and >> I'll go with that. >> >> > Btw, we have >> > >> > template<size_t N> >> > array_slice (T (&array)[N]) : m_base (array), m_size (N) {} >> > >> > which would suggest handling NULL isn't desired(?) >> > >> >> That is not how I read for example: >> >> // True if the array is valid, false if it is an array like INVALID. >> bool is_valid () const { return m_base || m_size == 0; } >> >> And IMHO it would be a very very strange limitation too. > > I see. That said, the high number of CTORs does look a bit odd, > but I'm fine with them if Richard is. Yeah, the patch LGTM FWWIW. I agree it feels a bit weird to convert "pointer to vector of T" into "array-like of T" without a dereference, but avoiding it might be more convoluted than going with the flow. It doesn't look like it should introduce genuine ambiguity, since the T template parameter would always need to be specified explicitly. (But I don't think we should have a make_array_slice for vector pointers.) Thanks, Richard
diff --git a/gcc/vec.h b/gcc/vec.h index eed075addc9..b0477e1044c 100644 --- a/gcc/vec.h +++ b/gcc/vec.h @@ -2264,6 +2264,18 @@ public: array_slice (const vec<OtherT> &v) : m_base (v.address ()), m_size (v.length ()) {} + template<typename OtherT> + array_slice (vec<OtherT> &v) + : m_base (v.address ()), m_size (v.length ()) {} + + template<typename OtherT> + array_slice (const vec<OtherT, va_gc> *v) + : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {} + + template<typename OtherT> + array_slice (vec<OtherT, va_gc> *v) + : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {} + iterator begin () { return m_base; } iterator end () { return m_base + m_size; }