www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Should `pragma(inline, expression)` be allowed ?

reply Basile B. <b2.temp gmx.com> writes:
Example usage, probably the only that's interesting at first 
glance.

---
version(D_Coverage)
     enum do_inline = true;
else
     enum do_inline = false;


pragma(inline, do_inline)
void stuff(){}
---

Although this could be controlled from the command line side, i.e 
if -cov is there then be smart and dont put -inline.
Oct 14 2020
next sibling parent reply Basile B. <b2.temp gmx.com> writes:
On Wednesday, 14 October 2020 at 17:20:46 UTC, Basile B. wrote:
 Example usage, probably the only that's interesting at first 
 glance.

 ---
 version(D_Coverage)
     enum do_inline = true;
 else
     enum do_inline = false;
sorry I meant version(D_Coverage) enum do_inline = false; else enum do_inline = true; obviously...
Oct 14 2020
parent reply Per =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
On Wednesday, 14 October 2020 at 17:22:40 UTC, Basile B. wrote:
 version(D_Coverage)
     enum do_inline = true;
 else
     enum do_inline = false;
This has been discussed but Walter is against it if I remember correctly. I use void foo() { version(D_Coverage) {} else pragma(inline, true); }
Oct 15 2020
parent reply Basile B. <b2.temp gmx.com> writes:
On Thursday, 15 October 2020 at 09:14:05 UTC, Per Nordlöw wrote:
 On Wednesday, 14 October 2020 at 17:22:40 UTC, Basile B. wrote:
 version(D_Coverage)
     enum do_inline = true;
 else
     enum do_inline = false;
This has been discussed but Walter is against it if I remember correctly.
That's exactly why I ask here be fore opening an issue
 I use

 void foo()
 {
     version(D_Coverage) {} else pragma(inline, true);
 }
Ah yeah ? this works to attach or not the pragma to a func in particular? I didn't think to that
Oct 15 2020
parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 10/15/20 9:23 AM, Basile B. wrote:
 On Thursday, 15 October 2020 at 09:14:05 UTC, Per Nordlöw wrote:
 On Wednesday, 14 October 2020 at 17:22:40 UTC, Basile B. wrote:
 version(D_Coverage)
     enum do_inline = true;
 else
     enum do_inline = false;
This has been discussed but Walter is against it if I remember correctly.
That's exactly why I ask here be fore opening an issue
I think this falls in the "gratuitous limitations" category and should be fixed. Any place where a compile-time Boolean fits, a compile-time-computable expression should fit. Same about numbers, strings etc. I'm glad that the related issue with `align(number)` has been fixed. Up until recently only literals were allowed.
Oct 15 2020
next sibling parent Walter Bright <newshound2 digitalmars.com> writes:
On 10/15/2020 7:05 AM, Andrei Alexandrescu wrote:
 On 10/15/20 9:23 AM, Basile B. wrote:
 On Thursday, 15 October 2020 at 09:14:05 UTC, Per Nordlöw wrote:
 On Wednesday, 14 October 2020 at 17:22:40 UTC, Basile B. wrote:
 version(D_Coverage)
     enum do_inline = true;
 else
     enum do_inline = false;
This has been discussed but Walter is against it if I remember correctly.
That's exactly why I ask here be fore opening an issue
I think this falls in the "gratuitous limitations" category and should be fixed. Any place where a compile-time Boolean fits, a compile-time-computable expression should fit. Same about numbers, strings etc.
I don't remember why I was against it, but it would be worth finding out why before going ahead and missing something important.
Oct 16 2020
prev sibling parent reply James Blachly <james.blachly gmail.com> writes:
On Thursday, 15 October 2020 at 14:05:20 UTC, Andrei Alexandrescu 
wrote:
 On 10/15/20 9:23 AM, Basile B. wrote:
 On Thursday, 15 October 2020 at 09:14:05 UTC, Per Nordlöw 
 wrote:
 On Wednesday, 14 October 2020 at 17:22:40 UTC, Basile B. 
 wrote:
 version(D_Coverage)
     enum do_inline = true;
 else
     enum do_inline = false;
This has been discussed but Walter is against it if I remember correctly.
That's exactly why I ask here be fore opening an issue
I think this falls in the "gratuitous limitations" category and should be fixed. Any place where a compile-time Boolean fits, a compile-time-computable expression should fit. Same about numbers, strings etc.
This would solve a problem I had whereby we had several compile time backends available and wanted to do version(A || B)
Oct 19 2020
parent reply Basile B. <b2.temp gmx.com> writes:
On Tuesday, 20 October 2020 at 01:32:23 UTC, James Blachly wrote:
 This would solve a problem I had whereby we had several compile 
 time backends available and wanted to do

 version(A || B)
I would not bet too much on this one if I were you...
Oct 19 2020
parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Tue, Oct 20, 2020 at 01:54:38AM +0000, Basile B. via Digitalmars-d wrote:
 On Tuesday, 20 October 2020 at 01:32:23 UTC, James Blachly wrote:
 This would solve a problem I had whereby we had several compile time
 backends available and wanted to do
 
 version(A || B)
I would not bet too much on this one if I were you...
This has cropped up countless times over the years, and so far, the answer has been an adamant No. I'm not holding my breath on this one. If you *really* can't live without ||, use static if instead. (Yes, it's uglier, but no, I don't have a better idea.) T -- Without outlines, life would be pointless.
Oct 19 2020
parent reply Basile B. <b2.temp gmx.com> writes:
On Tuesday, 20 October 2020 at 05:18:50 UTC, H. S. Teoh wrote:
 On Tue, Oct 20, 2020 at 01:54:38AM +0000, Basile B. via 
 Digitalmars-d wrote:
 On Tuesday, 20 October 2020 at 01:32:23 UTC, James Blachly 
 wrote:
 This would solve a problem I had whereby we had several 
 compile time backends available and wanted to do
 
 version(A || B)
I would not bet too much on this one if I were you...
This has cropped up countless times over the years, and so far, the answer has been an adamant No. I'm not holding my breath on this one. If you *really* can't live without ||, use static if instead. (Yes, it's uglier, but no, I don't have a better idea.) T
yeah, CTFE on `version()` would be basically like `static if (ident <op> ident)` and alikes, so `version()` much less justified because not special anymore. By the way, to the attention of James, the other day I've found this nice helper by Simons K: https://forum.dlang.org/post/tghdaffyugrajmenddav forum.dlang.org, allowing to use version idents in static if expressions, the easiest way possible.
Oct 20 2020
parent reply Max Samukha <maxsamukha gmail.com> writes:
On Tuesday, 20 October 2020 at 08:52:07 UTC, Basile B. wrote:

 yeah, CTFE on `version()` would be basically like `static if 
 (ident <op> ident)` and alikes, so `version()` much less 
 justified because not special anymore.

 By the way, to the attention of James, the other day I've found 
 this nice helper by Simons K: 
 https://forum.dlang.org/post/tghdaffyugrajmenddav forum.dlang.org, allowing to
use version idents in static if expressions, the easiest way possible.
It takes a special kind of stubbornness to reject the fact that version's limitations failed to serve their purpose.
Oct 20 2020
parent Basile B. <b2.temp gmx.com> writes:
On Tuesday, 20 October 2020 at 10:16:26 UTC, Max Samukha wrote:
 On Tuesday, 20 October 2020 at 08:52:07 UTC, Basile B. wrote:

 yeah, CTFE on `version()` would be basically like `static if 
 (ident <op> ident)` and alikes, so `version()` much less 
 justified because not special anymore.

 By the way, to the attention of James, the other day I've 
 found this nice helper by Simons K: 
 https://forum.dlang.org/post/tghdaffyugrajmenddav forum.dlang.org, allowing to
use version idents in static if expressions, the easiest way possible.
It takes a special kind of stubbornness to reject the fact that version's limitations failed to serve their purpose.
IIRC the main rationale for version limitations is that they are supposed to prevent bugs related to preprocessors in other languages, which may be counter- intuitive to verify: People complain that it's not super friendly to combine versions but do they complain because of pernicious bugs inherent to the lack of combinations ? side note: I'm not especially pro D-versions (my toy language allows version operator for example [1]), but I understand why they are limited in D. It's been explained many times. [1]: https://gitlab.com/basile.b/styx/-/blob/master/src/styx/semantic/versions.d#L403
Oct 20 2020
prev sibling parent reply Nicholas Wilson <iamthewilsonator hotmail.com> writes:
On Wednesday, 14 October 2020 at 17:20:46 UTC, Basile B. wrote:
 Example usage, probably the only that's interesting at first 
 glance.

 ---
 version(D_Coverage)
     enum do_inline = true;
 else
     enum do_inline = false;


 pragma(inline, do_inline)
 void stuff(){}
 ---

 Although this could be controlled from the command line side, 
 i.e if -cov is there then be smart and dont put -inline.
https://github.com/dlang/dmd/pull/11954
Nov 11 2020
parent Basile B. <b2.temp gmx.com> writes:
On Thursday, 12 November 2020 at 00:54:35 UTC, Nicholas Wilson 
wrote:
 On Wednesday, 14 October 2020 at 17:20:46 UTC, Basile B. wrote:
 Example usage, probably the only that's interesting at first 
 glance.

 ---
 version(D_Coverage)
     enum do_inline = true;
 else
     enum do_inline = false;


 pragma(inline, do_inline)
 void stuff(){}
 ---

 Although this could be controlled from the command line side, 
 i.e if -cov is there then be smart and dont put -inline.
https://github.com/dlang/dmd/pull/11954
Hi, thanks for trying the feature. I've created an issue[1] that can be referenced in the PR ;) [1] https://issues.dlang.org/show_bug.cgi?id=21378
Nov 12 2020