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.129.124]) by sourceware.org (Postfix) with ESMTPS id 81A553858D1E for ; Thu, 19 Oct 2023 21:43:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 81A553858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 81A553858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697751795; cv=none; b=raPRUsNiQB+am5KbFIyZheBFJkDBb3DmsUgENJFNXLjcr5UqkTHZk81ZPoRUKWnbYkqig3rmiVRMSufSBRLjTC/T8dtxugWm41iaqYFOzEsOw+sZejDlVRBPE61LXrd+4GhPmL3YdBb3tKy7Vxc+sNdQ/drm8tQgsxbxocaQD5o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697751795; c=relaxed/simple; bh=yF5R5VlYmDcyai+CYjl78zPmHYT6wBEfOFwONfcfGFA=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=RfwoxKw7fxiR9OHQVauv91sySYCot6EZ7jq4Ledu46SLHcgYbRcG1q4UeFgCCHkM2gjlFkl1yV4Ynrb0SnnyMzWhy/rErrxU+xBMo06ts/VrEsxR1+39jOdxcorruoW/8FX+E4yzVQ3oYmP+6sgSIJEU1BeuXwRm5slMG3BQ860= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697751793; 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=U09DbbvfmP8Ucf5kaa1sM1f7AOtJe8ZsyMgpjXn2SI8=; b=YuhoZReVbZMkRSEqsofI6oJBOEh96YKSAErhRRg5JM25zVO9aEuL2rQ5lQ3RrGHKYZGeF8 lAOCJNGL3LGp4D2nH4KmMKhI0j+HZYl7GLCmcdQF+jfDwJnonc65pAmj1KR3FnRgyCiJoe kDb3zFxDcoCAfVXxKZz/Is9H7o2ACB8= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-515-eIPLSZF9OKuMI983LXxPSg-1; Thu, 19 Oct 2023 17:43:10 -0400 X-MC-Unique: eIPLSZF9OKuMI983LXxPSg-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-65af758fa1eso2257636d6.2 for ; Thu, 19 Oct 2023 14:43:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697751790; x=1698356590; 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=U09DbbvfmP8Ucf5kaa1sM1f7AOtJe8ZsyMgpjXn2SI8=; b=u8ytTWi6YRd414oQgLpoGW8gijYJ6P8zq8RfU2ru6xBKt5KZ6qL8V6ylKNcTPeccUj TaXFsEJa9A5IA5yrj/XhYgR+y889dnoOL9aWQMAMg0FZz9Yx1WKqRioVW59yqcRxIPbs 1ijCsk8pEJdIqCvcvEWMpCQteApHkL5mnA7qeruvRCzqdEzuYA2rS8Yn1/1/TVtoBug6 PvCOOoHBbXDwO37kylpvW0NIXARG4WLueyOwsOC5e3rk3UxXJs2MHVXIaW7YlIPATQjR qftUQ6gTFdVppT/G66LPFZ7krfjtLuPVbffkTquH11jYxv4CrdV01LV4xnFixDG2KhVe tgoQ== X-Gm-Message-State: AOJu0Yzyrr7PLxX5JtTLQqEXhk2/dmfPy5Yf4P8WghdP2Y01Kcv7gJwX POkGrsJ85sguTpOxLlTA3vsSiw7baFbZRCN6X/yDBvIAv1MhB6ZaZl6zYwgdMGnKLbudeS/FkLb pBXlbsRtol0s5morgcA== X-Received: by 2002:ad4:4ea7:0:b0:649:384f:ed4 with SMTP id ed7-20020ad44ea7000000b00649384f0ed4mr150919qvb.19.1697751790328; Thu, 19 Oct 2023 14:43:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFmUL9vTTdzwJqUceplyVSqNKeZqW4hNK2zZ5IMhpseUSxTM5xP2/BCKoA7C9STSxriyvwbEw== X-Received: by 2002:ad4:4ea7:0:b0:649:384f:ed4 with SMTP id ed7-20020ad44ea7000000b00649384f0ed4mr150906qvb.19.1697751789988; Thu, 19 Oct 2023 14:43:09 -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 w13-20020a0cef8d000000b0065b17b925d0sm167632qvr.38.2023.10.19.14.43.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Oct 2023 14:43:09 -0700 (PDT) Message-ID: <501f2cd1-62d8-4dc1-8d45-6ca3a550ce3e@redhat.com> Date: Thu, 19 Oct 2023 17:43:08 -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> <662bb1db-fa27-1c59-2fa5-5986458cb074@idea> From: Jason Merrill In-Reply-To: <662bb1db-fa27-1c59-2fa5-5986458cb074@idea> 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_H4,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/4/23 12:08, Patrick Palka wrote: > On Tue, 3 Oct 2023, Jason Merrill wrote: > >> 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. > > Ah, that makes sense I think. > >> >>>> and finally it dispatches to tsubst for type trees. >> >> And it looks like you fix the callers to avoid that? > > Yes, I'll make a note of that in the commit message. > >> >>>> 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? > > Good idea, that'll complement tsubst_scope nicely. > >> >> Can we also merge in tsubst_expr and use that name instead of the unwieldy >> tsubst_copy_and_build? > > That'd be nice. Another idea would be to rename tsubst_expr to > tsubst_stmt and make it disjoint from tsubst_copy_and_build, and then > rename tsubst_copy_and_build to tsubst_expr, to draw a distinction > between statement-like trees (the substitution of which typically has > side effects like calling add_stmt) and expression-like trees (which > don't usually have such side effects). I can work on that as a > follow-up patch. > > Here's v2 which guards the call to maybe_dependent_member_ref and adds > tsubst_name, bootstrapped and regtested on x86_64-pc-linux-gnu: OK.