220 21285 <CAB+4KHK8Q40JUmfcmo0oYb-v16m1qrXwHEwM8GVznQzHqLthiA@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: Andrew Tomazos <andrewtomazos@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Allow inline functions to be evaluated in
 different contexts
Date: Sun, 4 Oct 2015 22:38:45 +0200
Lines: 146
Approved: news@gmane.org
Message-ID: <CAB+4KHK8Q40JUmfcmo0oYb-v16m1qrXwHEwM8GVznQzHqLthiA@mail.gmail.com>
References: <d269a299-58c5-4d8d-8574-3820e823c16d@isocpp.org>
	<CAB+4KHJA1AnKiHkzyALxoy3ui+SS0188T6rpk1iD5_59yotyEw@mail.gmail.com>
	<dbd36de4-4359-45af-978e-5b8df45031fa@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=001a11c2b90c21228f05214d6274
X-Trace: ger.gmane.org 1443991129 5449 80.91.229.3 (4 Oct 2015 20:38:49 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sun, 4 Oct 2015 20:38:49 +0000 (UTC)
To: "std-proposals@isocpp.org" <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBD5KHQXXWYPRBVU4Y2YAKGQENPXFIOA@isocpp.org Sun Oct 04 22:38:49 2015
Return-path: <std-proposals+bncBD5KHQXXWYPRBVU4Y2YAKGQENPXFIOA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-lb0-f198.google.com ([209.85.217.198])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBD5KHQXXWYPRBVU4Y2YAKGQENPXFIOA@isocpp.org>)
	id 1Ziq3U-0008Th-3k
	for gclcip-std-proposals@m.gmane.org; Sun, 04 Oct 2015 22:38:48 +0200
Original-Received: by lbbti1 with SMTP id ti1sf30332741lbb.3
        for <gclcip-std-proposals@m.gmane.org>; Sun, 04 Oct 2015 13:38:47 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:in-reply-to:references:date
         :message-id:subject:from:to:content-type:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=AleJB1WDABkD7xwj7Fuw2Noi28EbflDqCb2s0UAers0=;
        b=C+wDSlSdHdwgBhLd4LYto8FjI/CbT09pW8PrGO2zDGQkofF92mifZJiX/oR/PibEWN
         qTNEWYm42Dq5nW7Lhzi8OsmyEsXJvA2ZFBP0bkpU5o7vJD8WR28Que1PwKAPleN3qqeM
         XpESRErqYUUpBBHFY21NzcOErIH+zSZ/3arWrfThwX60gaCVhi5Ea+vlOWSVWQcGnItg
         Di7zVnUC8ykzQxMZpTCTX/BvWWyVEDn0lPQ4qY+FisdpoH0FLTumuUskEu/8BvOc67qs
         rAEl29lbWPXmexdauUn60Ymfno+Gy0+mlmQ/9Mw+ZbTlRsenQJ5Xh0qEDdtTWE+10FtB
         1YDg==
X-Gm-Message-State: ALoCoQnfpj6UAazhfu4iBvdGklM3eroqrU2y1f7ggm7cwRpE3EvXQoyhiWMgOtW6Ew5tJ1jbpWwq
X-Received: by 10.195.18.100 with SMTP id gl4mr4573768wjd.4.1443991127596;
        Sun, 04 Oct 2015 13:38:47 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.180.75.140 with SMTP id c12ls693658wiw.7.gmail; Sun, 04 Oct
 2015 13:38:46 -0700 (PDT)
X-Received: by 10.180.37.76 with SMTP id w12mr8266261wij.0.1443991126530;
        Sun, 04 Oct 2015 13:38:46 -0700 (PDT)
Original-Received: from mail-wi0-x232.google.com (mail-wi0-x232.google.com. [2a00:1450:400c:c05::232])
        by mx.google.com with ESMTPS id p10si26802344wjo.3.2015.10.04.13.38.46
        for <std-proposals@isocpp.org>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sun, 04 Oct 2015 13:38:46 -0700 (PDT)
Received-SPF: pass (google.com: domain of andrewtomazos@gmail.com designates 2a00:1450:400c:c05::232 as permitted sender) client-ip=2a00:1450:400c:c05::232;
Original-Received: by wiclk2 with SMTP id lk2so89683241wic.1
        for <std-proposals@isocpp.org>; Sun, 04 Oct 2015 13:38:46 -0700 (PDT)
X-Received: by 10.180.10.197 with SMTP id k5mr7345682wib.22.1443991126088;
 Sun, 04 Oct 2015 13:38:46 -0700 (PDT)
Original-Received: by 10.28.73.137 with HTTP; Sun, 4 Oct 2015 13:38:45 -0700 (PDT)
In-Reply-To: <dbd36de4-4359-45af-978e-5b8df45031fa@isocpp.org>
X-Original-Sender: andrewtomazos@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of andrewtomazos@gmail.com designates 2a00:1450:400c:c05::232 as
 permitted sender) smtp.mailfrom=andrewtomazos@gmail.com;       dkim=pass
 header.i=@gmail.com;       dmarc=pass (p=NONE dis=NONE) header.from=gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: std-proposals@isocpp.org
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:21285
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/21285>

--001a11c2b90c21228f05214d6274
Content-Type: text/plain; charset=UTF-8

On Sun, Oct 4, 2015 at 7:48 PM, Jeremy Maitin-Shepard <jeremy@jeremyms.com>
wrote:

> On Sunday, October 4, 2015 at 8:07:56 AM UTC-7, Andrew Tomazos wrote:
>>
>> On Sun, Oct 4, 2015 at 2:52 PM, TONGARI J <tong...@gmail.com> wrote:
>>
>>> A more reasonable way is to allow inline functions to be
>>> context-agnostic so we can define `min` as:
>>>
>>> template<class T>
>>> inline const T& min( const T& a, const T& b )
>>> {
>>>     return (b < a) ? b : a;
>>> }
>>>
>>> When evaluated in constant context, the restrictions of
>>> constant-expression are automatically imposed,
>>>
>>
>> This has been suggested before.  You are essentially asking that all
>> functions that could be constexpr, be implicitly constexpr.  Likewise for
>> the other "contexts".
>>
>> The problem is compile-time.  Compiling a constexpr function (for
>> example) is expensive.  Doing it automatically for all function definitions
>> would increase compile times too much.
>>
>> You have to explicitly mark the functions you want to use in constexpr
>> contexts, so the compiler knows it doesn't have to do the extra analysis
>> for all the other ones.
>>
>
> I'm not sure I understand this point.  I am not really aware of exactly
> how constexpr evaluation is handled in compilers, but I assume it comes
> down to storing some type of AST when the function is parsed, and then
> either evaluating directly based on that or possibly converting it to some
> intermediate representation, which could presumably be done in a JIT
> fashion when actually required.
>

I just tested it (gcc 5.2) and observed that a 5-line C++14 constexpr
function definition takes 5% longer to compile (~105us) than the same
inline function (~100us) (even if it isn't used).  This is less than I
expected, but still quite significant.

It is unclear to me whether this completely highlights the performance
concerns about implicit constexpr.  Admittedly I am reporting them
second-hand.

-- 

--- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

--001a11c2b90c21228f05214d6274
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On S=
un, Oct 4, 2015 at 7:48 PM, Jeremy Maitin-Shepard <span dir=3D"ltr">&lt;<a =
href=3D"mailto:jeremy@jeremyms.com" target=3D"_blank">jeremy@jeremyms.com</=
a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0=
 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Sunday, October 4=
, 2015 at 8:07:56 AM UTC-7, Andrew Tomazos wrote:<span class=3D""><blockquo=
te class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div class=3D"gmail_qu=
ote">On Sun, Oct 4, 2015 at 2:52 PM, TONGARI J <span dir=3D"ltr">&lt;<a rel=
=3D"nofollow">tong...@gmail.com</a>&gt;</span> wrote:<br><blockquote class=
=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd=
ing-left:1ex"><div dir=3D"ltr"><div>A more reasonable way is to allow inlin=
e functions to be context-agnostic so we can define `<font face=3D"courier =
new, monospace">min</font>` as:<br></div><div><br></div><div style=3D"borde=
r:1px solid rgb(187,187,187);word-wrap:break-word;background-color:rgb(250,=
250,250)"><code><div><span style=3D"color:#008">template</span><span style=
=3D"color:#660">&lt;</span><span style=3D"color:#008">class</span><span sty=
le=3D"color:#000"> T</span><span style=3D"color:#660">&gt;</span><span styl=
e=3D"color:#000"> <br></span><span style=3D"color:#008">inline</span><span =
style=3D"color:#000"> </span><span style=3D"color:#008">const</span><span s=
tyle=3D"color:#000"> T</span><span style=3D"color:#660">&amp;</span><span s=
tyle=3D"color:#000"> min</span><span style=3D"color:#660">(</span><span sty=
le=3D"color:#000"> </span><span style=3D"color:#008">const</span><span styl=
e=3D"color:#000"> T</span><span style=3D"color:#660">&amp;</span><span styl=
e=3D"color:#000"> a</span><span style=3D"color:#660">,</span><span style=3D=
"color:#000"> </span><span style=3D"color:#008">const</span><span style=3D"=
color:#000"> T</span><span style=3D"color:#660">&amp;</span><span style=3D"=
color:#000"> b </span><span style=3D"color:#660">)</span><span style=3D"col=
or:#000"><br></span><span style=3D"color:#660">{</span><span style=3D"color=
:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">return</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#660">(</span><span st=
yle=3D"color:#000">b </span><span style=3D"color:#660">&lt;</span><span sty=
le=3D"color:#000"> a</span><span style=3D"color:#660">)</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">?</span><span style=3D"c=
olor:#000"> b </span><span style=3D"color:#660">:</span><span style=3D"colo=
r:#000"> a</span><span style=3D"color:#660">;</span><span style=3D"color:#0=
00"><br></span><span style=3D"color:#660">}</span></div></code></div><div><=
br></div><div>When evaluated in constant context, the restrictions of const=
ant-expression are automatically imposed, </div></div></blockquote><div></d=
iv></div></div><div><br></div><div>This has been suggested before.=C2=A0 Yo=
u are essentially asking that all functions that could be constexpr, be imp=
licitly constexpr.=C2=A0 Likewise for the other &quot;contexts&quot;.</div>=
<div><br></div><div>The problem is compile-time.=C2=A0 Compiling a constexp=
r function (for example) is expensive.=C2=A0 Doing it automatically for all=
 function definitions would increase compile times too much.</div><div><br>=
</div><div>You have to explicitly mark the functions you want to use in con=
stexpr contexts, so the compiler knows it doesn&#39;t have to do the extra =
analysis for all the other ones.</div></div></blockquote></span><div><br>I&=
#39;m not sure I understand this point.=C2=A0 I am not really aware of exac=
tly how constexpr evaluation is handled in compilers, but I assume it comes=
 down to storing some type of AST when the function is parsed, and then eit=
her evaluating directly based on that or possibly converting it to some int=
ermediate representation, which could presumably be done in a JIT fashion w=
hen actually required.</div></blockquote><div></div></div><br></div><div cl=
ass=3D"gmail_extra">I just tested it (gcc 5.2) and observed that a 5-line C=
++14 constexpr function definition takes 5% longer to compile (~105us) than=
 the same inline function (~100us) (even if it isn&#39;t used).=C2=A0 This =
is less than I expected, but still quite significant.</div><div class=3D"gm=
ail_extra"><br></div><div class=3D"gmail_extra">It is unclear to me whether=
 this completely highlights the performance concerns about implicit constex=
pr.=C2=A0 Admittedly I am reporting them second-hand.</div><div class=3D"gm=
ail_extra"><br></div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--001a11c2b90c21228f05214d6274--

.
