From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 091703858D39 for ; Tue, 3 Oct 2023 21:57:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 091703858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696370236; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mk1DTOdW2hbJWZE0SJEP1sOUTgykuLN+d+lqsfUBvRI=; b=DeNGj9z8HyuEWFhVyExFuKBcBTsidbglJv1HWDpHyeX9BLye+WH8fjWAiLTE+4Qswust8R 4El3JHHOS9/R/3903vx7n/u8V9jMVkFQ8IQPx+2/lM1ndLsFvOo7v8I0iiD5ywZcLrZm1q dwdFPqfgTcUlZxV4Tz4yw9uW52WEzxY= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-642-d8VtxcrTOf-nS4wfMUGj9Q-1; Tue, 03 Oct 2023 17:57:15 -0400 X-MC-Unique: d8VtxcrTOf-nS4wfMUGj9Q-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-7740bc7ad68so178235185a.2 for ; Tue, 03 Oct 2023 14:57:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696370234; x=1696975034; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=mk1DTOdW2hbJWZE0SJEP1sOUTgykuLN+d+lqsfUBvRI=; b=kNgJN49sD+um/2Pwmdet5i9MA2k0wKUuf9v3/Chs+yAOWb0BR2bQjY5vxuVHxc0Llh kLT6wTgar9bhCpFseSvZlyXd3+ny2a4YjDayrqD6xcsGvjfAV+2jseh9G/T5/P96u5tm nvD5IwJXL8fywxR5jwc8IzuyQ4hkbJZnR+yEqVOwwD9M0twtjxseNrwJ7q9iWocJoPTt Qua/XOZwzca6Y9yiL3rVvq0RnFhU5+g1jDcLT3trNIuN/cWvBqANkSrkxje/alonu1wp 6c7uEgCjBa3Ciivr/dvqgC5B6pIr+Tspv62klYCucblj/Z5KEuFiIOGDt06i0WdotYVa u4mA== X-Gm-Message-State: AOJu0Ywn1mByF0/ylmHaWEp0AFrty2Uj6r7suq17yCsKDEii/9q12T4c ureBKwJpwymTETOpGxneIWm7zxFCzQ8x6JwL2kxkHLkm0b4yMftIpfB4LB5ohBBnyHKPq+HHjLp qEjtML/pcocbfPDPfb9H38zSvkQ== X-Received: by 2002:a05:620a:2283:b0:76d:aa3b:ac9c with SMTP id o3-20020a05620a228300b0076daa3bac9cmr677938qkh.46.1696370234688; Tue, 03 Oct 2023 14:57:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFtMv3VbIvZbWP/Oo2pfwSpVa1JzfbroyVSeql4xM4rsBri110U87DWGYeMU6nn3M7ZDe1Neg== X-Received: by 2002:a05:620a:2283:b0:76d:aa3b:ac9c with SMTP id o3-20020a05620a228300b0076daa3bac9cmr677920qkh.46.1696370234217; Tue, 03 Oct 2023 14:57:14 -0700 (PDT) Received: from [192.168.1.108] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id d20-20020a05620a159400b00767b0c35c15sm795024qkk.91.2023.10.03.14.57.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 03 Oct 2023 14:57:13 -0700 (PDT) Message-ID: Date: Tue, 3 Oct 2023 17:57:12 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] c++: merge tsubst_copy into tsubst_copy_and_build To: Patrick Palka Cc: gcc-patches@gcc.gnu.org References: <20230925204302.1277285-2-ppalka@redhat.com> <20231002193738.3900509-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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