From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by sourceware.org (Postfix) with ESMTPS id BA196383F86A for ; Mon, 25 May 2020 14:35:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BA196383F86A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nathanmsidwell@gmail.com Received: by mail-qv1-xf2f.google.com with SMTP id d1so8099050qvl.6 for ; Mon, 25 May 2020 07:35:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=4ztg9pmh35LqWzDPVfA8opm0WwLN0F3KZBNUW7ZKx1k=; b=jyLrUN/0xHaM2Ke7y+d2jThxda1fefzbB7f7N4hpb/Mm+73dqMxmyFYq5Or32B/AAH NcC36GlZLosQkqGryXQiPTcRQsuy3lM4ww4fj2v1Stg4a6BKIwsfFzohoSIBjxlU6juR UL7UMgl1T4mvaltzB4ihZf6jAG26Mr3VGj4H2Bm/MwVcKDYDGotMr1vKMdpO6+LOciSD MI8k+x4vzcHHRoMfwf/OaW3VHKJH05u81QD6GtnWsytczPLmsetexNKCF7QNsn/KC+UQ P78DRc2gaXKZcqYqr4jeQZ5OQbv0XkYFvHAHI3HzMUUqusTUuYcezXRXDuvFwJockor0 jjXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=4ztg9pmh35LqWzDPVfA8opm0WwLN0F3KZBNUW7ZKx1k=; b=N7P6/610SjWUlcfDbXZI1wF/9GfNBYA3QRzKxVOYYJyLII0B/2+8BpDsy1Y0GwS7Tn khXjkalJa+w8G8G6uzh4JG02xsRUfZF2WJvhFKq0A9+TYy+ilQ+G0b5dr1rSqHyy7wWf /H+1isFr2mBozPDTewLAWcb0Y0/+bzjQjHrgLS4aV16YedJT6/pArETlcmX0lpoX4igT lQUD5iGI9B2dOV3tEZjh2CUsVrBJhaK/BTMmf+lzs0FLJ9BQpOcUgxuNcXgO8npQP+t/ IOWU3hjQJobdOfBUb5r/3Q9biR85oIbCELa2Lo58NvwB32PEEs68ZlCLwIXMFlTaMehD wOcw== X-Gm-Message-State: AOAM5318hrboOdLXxOcXG5yYsDv7WsFdEMfC9GMMHgE+F0XzPwce69YL OOHaBe14DmXhkzZOs46ORVo= X-Google-Smtp-Source: ABdhPJxGBzBOUaRQ7+BqbtuTTjKeDAwLEOevOj1tbDwI5lcmpgVMp/ZqvrsQcjPjmeVrRaveaP53qw== X-Received: by 2002:a05:6214:18ec:: with SMTP id ep12mr15874173qvb.216.1590417318005; Mon, 25 May 2020 07:35:18 -0700 (PDT) Received: from ?IPv6:2601:181:c400:1050:8865:20a2:e4bf:2d44? ([2601:181:c400:1050:8865:20a2:e4bf:2d44]) by smtp.googlemail.com with ESMTPSA id q4sm16356153qtf.35.2020.05.25.07.35.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 May 2020 07:35:17 -0700 (PDT) Sender: Nathan Sidwell Subject: Re: Question about implicit template instantiation in C++ modules. To: Kubota Takafumi , gcc-help@gcc.gnu.org References: From: Nathan Sidwell Message-ID: Date: Mon, 25 May 2020 10:35:16 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 May 2020 14:35:22 -0000 [redirected to gcc-help] On 5/25/20 12:27 AM, Kubota Takafumi wrote: > Hi all, > > I am studying C++ modules and, especially, trying to understand how implicitly > instantiated template specializations are exported. Thanks for trying things out! > I encounter an example where GCC and Clang behave differently. > > For example: > > |/* mod1.cpp */ export module mod1; export { // function template definition > template T tmpl (T t) { return t; } // explicit instantiation of > "char tmpl" template char tmpl (char t); // implicit instantiation of "int > tmpl" in exported section int f(int i) { return tmpl(i); } } // implicit > instantiation of "double tmpl" in not-exported section double g(double > d) { return tmpl(d); } /* main1.cpp */ import mod1; int main() { tmpl('c'); // > #1 tmpl(1); // #2 tmpl(1.0); // #3 return 0; } | > > Here, GCC reuses the explicitly instantiated specialization from mod1 at #1. > > But, it implicitly re-instantiates at #2 and #3. > > On the other hand, Clang reuses all specializations from module mod1 for each point. Neither compiler is wrong. It is an implementation choice. All such implicit instantiations, regardless of origin are required to be ODR-same. I chose not to emit implicit instantiations, unless they are referenced by something else in the emitted graph. (it is not at all obvious which strategy is better) > So, I read the sections about modules and template instantiations in the working > draft of the technical specification [0][1][2]. > > However, as far as my understanding, there is no explanation about how > implicitly instantiated template specializations are exported. Instantiations (explicit, implicit or partial) are not exported. Only named entities may be exported. (using the language's definition of 'export', not the closely related implementation concept of 'emitted into a Compiled Module Interface'. > According to the comment of gcc/cp/module.c, there seem to be two design choices > for exporting implicit specializations: re-instantiating them on-demand (GCC's > style) and streaming them (Clang's style) in modules. > > So my questions are: > > *Does how implicit specializations are exported depend on compiler implementations?* Correct. > if not, > > *Does anyone know the expected behavior based on the technical specification?* The std requires that a well formed program cannot tell the difference :) > > Best Regards, > > Takafumi. > > [0] > http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/n4849.pdf > > [1] http://eel.is/c++draft/ > > [2] > http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1103r3.pdf > > > -- > Takafumi Kubota > Ph.D. student at Keio University > http://tk1012.github.io/ -- Nathan Sidwell