public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Patrick Palka <ppalka@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] c++: merge tsubst_copy into tsubst_copy_and_build
Date: Tue, 3 Oct 2023 17:57:12 -0400	[thread overview]
Message-ID: <c5fc2db5-2e5a-4e4c-a562-dcc8421e948e@redhat.com> (raw)
In-Reply-To: <f1d2aa67-ad78-0ac4-0f69-0f086b1538e3@idea>

On 10/3/23 08:41, Patrick Palka wrote:
> On Mon, 2 Oct 2023, Patrick Palka wrote:
> 
>> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look
>> OK for trunk?
>>
>> -- >8 --
>>
>> The relationship between tsubst_copy_and_build and tsubst_copy (two of
>> the main template argument substitution routines for expression trees)
>> is rather hazy.  The former is mostly a superset of the latter, with
>> some differences.
>>
>> The main difference is that they handle many tree codes differently, but
>> much of the tree code handling in tsubst_copy appears to be dead code[1].
>> This is because tsubst_copy only gets directly called in a few places
>> and mostly on id-expressions.  The interesting exceptions are PARM_DECL,
>> VAR_DECL, BIT_NOT_EXPR, SCOPE_REF, TEMPLATE_ID_EXPR and IDENTIFIER_NODE:
>>
>>   * for PARM_DECL and VAR_DECL, tsubst_copy_and_build calls tsubst_copy
>>     followed by doing some extra handling of its own
>>   * for BIT_NOT_EXPR tsubst_copy implicitly handles unresolved destructor
>>     calls (i.e. the first operand is an identifier or a type)
>>   * for SCOPE_REF, TEMPLATE_ID_EXPR and IDENTIFIER_NODE tsubst_copy
>>     refrains from doing name lookup of the terminal name
>>
>> Other more minor differences are that tsubst_copy exits early when
>> 'args' is null, and it calls maybe_dependent_member_ref

That's curious, since what that function does seems like name lookup; I 
wouldn't think we would want to call it when tf_no_name_lookup.

>> and finally it dispatches to tsubst for type trees.

And it looks like you fix the callers to avoid that?

>> Thus tsubst_copy is (at this point) similar enough to tsubst_copy_and_build
>> that it makes sense to merge the two functions, with the main difference
>> being the name lookup behavior[2].  So this patch merges tsubst_copy into
>> tsubst_copy_and_build via a new tsubst tf_no_name_lookup which controls
>> name lookup and resolution of a (top-level) id-expression.
>>
>> [1]: http://thrifty.mooo.com:8008/gcc-lcov/gcc/cp/pt.cc.gcov.html#17231
>> [2]: I don't know the history of tsubst_copy but I would guess it was
>> added before we settled on using processing_template_decl to control
>> whether our AST building routines perform semantic checking and return
>> non-templated trees, and so we needed a separate tsubst routine that
>> avoids semantic checking and always returns a templated tree for e.g.
>> partial substitution.
> 
> Oops, this is wrong -- tsubst_copy_and_build came after tsubst_copy,
> and was introduced as an optimization with the intent of getting rid
> of tsubst_copy eventually:
> https://gcc.gnu.org/pipermail/gcc-patches/2003-January/093659.html

I wonder if we want to add a small tsubst_name wrapper to call 
tsubst_copy_and_build with tf_no_name_lookup?

Can we also merge in tsubst_expr and use that name instead of the 
unwieldy tsubst_copy_and_build?

Jason


  reply	other threads:[~2023-10-03 21:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-25 20:43 [PATCH 1/2] c++: remove NON_DEPENDENT_EXPR, part 1 Patrick Palka
2023-09-25 20:43 ` [PATCH 2/2] c++: remove NON_DEPENDENT_EXPR, part 2 Patrick Palka
2023-10-02 19:37   ` [PATCH] c++: merge tsubst_copy into tsubst_copy_and_build Patrick Palka
2023-10-03 12:41     ` Patrick Palka
2023-10-03 21:57       ` Jason Merrill [this message]
2023-10-04 16:08         ` Patrick Palka
2023-10-04 19:23           ` [PATCH 2/1] c++: rename tsubst_copy_and_build and tsubst_expr Patrick Palka
2023-10-19 21:43             ` Jason Merrill
2023-10-19 21:43           ` [PATCH] c++: merge tsubst_copy into tsubst_copy_and_build Jason Merrill
2023-10-19 21:46   ` [PATCH 2/2] c++: remove NON_DEPENDENT_EXPR, part 2 Jason Merrill
2023-10-20 15:57   ` Andrew Pinski
2023-09-26 23:18 ` [PATCH 1/2] c++: remove NON_DEPENDENT_EXPR, part 1 Jason Merrill
2023-09-27 11:54   ` Patrick Palka

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=c5fc2db5-2e5a-4e4c-a562-dcc8421e948e@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=ppalka@redhat.com \
    /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).