September 10, 2014 Re: Voting: std.logger | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Murphy | On 09/10/2014 03:22 PM, Daniel Murphy wrote:
> "Jacob Carlborg" wrote in message news:lupda8$nl1$1@digitalmars.com...
>> Could we modify the compiler to allow that? Just for the special
>> identifiers __LINE__, __FILE__ and similar. It wouldn't be possible to
>> specify a value for that parameter then.
>
> IIRC Andrei has a bugzilla open for this.
Why? I cannot remember a compiler version where the following did not work:
import std.stdio;
void fun(A...)(A args, int l = __LINE__){ writeln(args," ",l); }
void main(){ fun(1,2,3); }
I.e. there is absolutely no issue here.
|
September 10, 2014 Re: Voting: std.logger | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | On Wednesday, 10 September 2014 at 15:41:49 UTC, Timon Gehr wrote:
>
> Why? I cannot remember a compiler version where the following did not work:
>
> import std.stdio;
> void fun(A...)(A args, int l = __LINE__){ writeln(args," ",l); }
> void main(){ fun(1,2,3); }
>
> I.e. there is absolutely no issue here.
For every instantiation of of fun there will be a new symbol even when A are the same, because of __LINE__. For Dicebot that is a nogo
|
September 10, 2014 Re: Voting: std.logger | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | On Wednesday, 10 September 2014 at 15:41:49 UTC, Timon Gehr wrote:
>
> Why? I cannot remember a compiler version where the following did not work:
>
> import std.stdio;
> void fun(A...)(A args, int l = __LINE__){ writeln(args," ",l); }
> void main(){ fun(1,2,3); }
>
> I.e. there is absolutely no issue here.
For every instantiation of of fun there will be a new symbol even
when A are the same, because of __LINE__. For Dicebot that is a
nogo
|
September 10, 2014 Re: Voting: std.logger | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | "Timon Gehr" wrote in message news:luprft$29v6$1@digitalmars.com... > Why? I cannot remember a compiler version where the following did not > work: > > import std.stdio; > void fun(A...)(A args, int l = __LINE__){ writeln(args," ",l); } > void main(){ fun(1,2,3); } > > I.e. there is absolutely no issue here. Hmm, do it does. Maybe I was thinking of this: https://issues.dlang.org/show_bug.cgi?id=2599 |
September 10, 2014 Re: Voting: std.logger | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert burner Schadek | "Robert burner Schadek" wrote in message news:wsanssfvnomcwtnqybui@forum.dlang.org... > > import std.stdio; > > void fun(A...)(A args, int l = __LINE__){ writeln(args," ",l); } > > void main(){ fun(1,2,3); } > > For every instantiation of of fun there will be a new symbol even when A are the same, because of __LINE__. For Dicebot that is a nogo Not in that example there won't. |
September 10, 2014 Re: Voting: std.logger | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert burner Schadek | On 9/10/14, 1:47 AM, Robert burner Schadek wrote:
> On Wednesday, 10 September 2014 at 07:41:49 UTC, Andrei Alexandrescu wrote:
>> There may be a miscommunication here. In short:
>>
>> void fun(int x, string f = __FILE__)(double y);
>>
>> can be replaced with:
>>
>> void fun(int x)(double y, string f = __FILE__);
>>
>> Both work and the second produces fewer instantiations.
>>
>>
>> Andrei
>
> But
>
> void fun(int l = __LINE__, A...)(A...); cannot be replaced by
> void fun(A...)(A..., int l = __LINE__);
>
> anyway thanks for reading and for trying to help
One possibility is to have the first function be a one-liner that forwards to another. That way there will be less code bloating.
void fun(uint l = __LINE__, A...)(A... as) {
funImpl(l, as);
}
private void funImpl(A...)(uint line, A...) {
... bulk of the code goes here ...
}
Andrei
|
September 10, 2014 Re: Voting: std.logger | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Wednesday, 10 September 2014 at 16:34:06 UTC, Andrei Alexandrescu wrote:
> One possibility is to have the first function be a one-liner that forwards to another. That way there will be less code bloating.
>
> void fun(uint l = __LINE__, A...)(A... as) {
> funImpl(l, as);
> }
>
> private void funImpl(A...)(uint line, A...) {
> ... bulk of the code goes here ...
> }
Those are already small functions AFAIK (I was speaking about symbol bloat, not code bloat). It does not help with compilation issue though - each logging call creates a totally new template instance which means allocating new object for DMD internal representation and running semantic phase for it. And mature applications can have thousands of logging calls. I have yet to run tests to see actual impact but it concerns me from the pure DMD internals point of view.
|
September 10, 2014 Re: Voting: std.logger | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | On Wednesday, 10 September 2014 at 15:41:49 UTC, Timon Gehr wrote:
> On 09/10/2014 03:22 PM, Daniel Murphy wrote:
>> "Jacob Carlborg" wrote in message news:lupda8$nl1$1@digitalmars.com...
>>> Could we modify the compiler to allow that? Just for the special
>>> identifiers __LINE__, __FILE__ and similar. It wouldn't be possible to
>>> specify a value for that parameter then.
>>
>> IIRC Andrei has a bugzilla open for this.
>
> Why? I cannot remember a compiler version where the following did not work:
>
> import std.stdio;
> void fun(A...)(A args, int l = __LINE__){ writeln(args," ",l); }
> void main(){ fun(1,2,3); }
>
> I.e. there is absolutely no issue here.
This is new to me - I can definitely remember trying it and failing ~ 1-2 years ago.
|
September 10, 2014 Re: Voting: std.logger | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | Am 10.09.2014 17:41, schrieb Timon Gehr:
> On 09/10/2014 03:22 PM, Daniel Murphy wrote:
>> "Jacob Carlborg" wrote in message news:lupda8$nl1$1@digitalmars.com...
>>> Could we modify the compiler to allow that? Just for the special
>>> identifiers __LINE__, __FILE__ and similar. It wouldn't be possible to
>>> specify a value for that parameter then.
>>
>> IIRC Andrei has a bugzilla open for this.
>
> Why? I cannot remember a compiler version where the following did not work:
>
> import std.stdio;
> void fun(A...)(A args, int l = __LINE__){ writeln(args," ",l); }
> void main(){ fun(1,2,3); }
>
> I.e. there is absolutely no issue here.
Except that it unfortunately doesn't do what is intended:
import std.stdio;
void fun(A...)(A args, int l = __LINE__){ writeln(args," ",l); }
void main(){ fun(10,11); }
output:
10 11
expected:
1011 3
|
September 10, 2014 Re: Voting: std.logger | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sönke Ludwig | On 09/10/2014 08:18 PM, Sönke Ludwig wrote:
> Am 10.09.2014 17:41, schrieb Timon Gehr:
>> On 09/10/2014 03:22 PM, Daniel Murphy wrote:
>>> "Jacob Carlborg" wrote in message news:lupda8$nl1$1@digitalmars.com...
>>>> Could we modify the compiler to allow that? Just for the special
>>>> identifiers __LINE__, __FILE__ and similar. It wouldn't be possible to
>>>> specify a value for that parameter then.
>>>
>>> IIRC Andrei has a bugzilla open for this.
>>
>> Why? I cannot remember a compiler version where the following did not
>> work:
>>
>> import std.stdio;
>> void fun(A...)(A args, int l = __LINE__){ writeln(args," ",l); }
>> void main(){ fun(1,2,3); }
>>
>> I.e. there is absolutely no issue here.
>
> Except that it unfortunately doesn't do what is intended:
>
> import std.stdio;
> void fun(A...)(A args, int l = __LINE__){ writeln(args," ",l); }
> void main(){ fun(10,11); }
>
> output:
> 10 11
>
> expected:
> 1011 3
Oops! Touché! Thanks. While the code indeed works, there actually _is_ an issue here. :o)
(It is even more embarrassing seeing that I have actually built my own implementation of IFTI and it actually matches DMD's behaviour in this case.)
|
Copyright © 1999-2021 by the D Language Foundation