Thread overview | ||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 28, 2014 Local functions infer attributes? | ||||
---|---|---|---|---|
| ||||
void f() pure nothrow @nogc { void localFunc() { } localFunc(); } Complains because localFunc is not @nogc or nothrow. Doesn't complain about pure though. Is it reasonable to say that the scope of the outer function is nothrow+@nogc, and therefore everything declared within should also be so? |
September 28, 2014 Re: Local functions infer attributes? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | On Sunday, 28 September 2014 at 02:42:29 UTC, Manu via Digitalmars-d wrote:
> void f() pure nothrow @nogc
> {
> void localFunc()
> {
> }
>
> localFunc();
> }
>
> Complains because localFunc is not @nogc or nothrow.
> Doesn't complain about pure though.
>
> Is it reasonable to say that the scope of the outer function is
> nothrow+@nogc, and therefore everything declared within should also be
> so?
No as the function could be returned and used elsewhere, where these attribute aren't necessary. Also, inferring everything is quite expensive and we want D to compile fast.
But maybe inference could be triggered on error ?
|
September 28, 2014 Re: Local functions infer attributes? | ||||
---|---|---|---|---|
| ||||
Posted in reply to deadalnix | On 9/27/2014 7:56 PM, deadalnix wrote:
> On Sunday, 28 September 2014 at 02:42:29 UTC, Manu via Digitalmars-d wrote:
>> void f() pure nothrow @nogc
>> {
>> void localFunc()
>> {
>> }
>>
>> localFunc();
>> }
>>
>> Complains because localFunc is not @nogc or nothrow.
>> Doesn't complain about pure though.
>>
>> Is it reasonable to say that the scope of the outer function is
>> nothrow+@nogc, and therefore everything declared within should also be
>> so?
>
> No as the function could be returned and used elsewhere, where these attribute
> aren't necessary. Also, inferring everything is quite expensive and we want D to
> compile fast.
>
> But maybe inference could be triggered on error ?
Since the function body is always present, inference should always be done. It isn't costly. Should file an enhancement request on this.
|
September 28, 2014 Re: Local functions infer attributes? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Sunday, 28 September 2014 at 03:08:09 UTC, Walter Bright wrote:
> Since the function body is always present, inference should always be done. It isn't costly. Should file an enhancement request on this.
If you have a control flow graph to analyze it can become quite costly.
|
September 28, 2014 Re: Local functions infer attributes? | ||||
---|---|---|---|---|
| ||||
Posted in reply to deadalnix | On 9/27/2014 8:50 PM, deadalnix wrote:
> On Sunday, 28 September 2014 at 03:08:09 UTC, Walter Bright wrote:
>> Since the function body is always present, inference should always be done. It
>> isn't costly. Should file an enhancement request on this.
>
> If you have a control flow graph to analyze it can become quite costly.
Nope! It happens as part of semantic analysis.
|
September 28, 2014 Re: Local functions infer attributes? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Sunday, 28 September 2014 at 04:04:24 UTC, Walter Bright wrote:
> On 9/27/2014 8:50 PM, deadalnix wrote:
>> On Sunday, 28 September 2014 at 03:08:09 UTC, Walter Bright wrote:
>>> Since the function body is always present, inference should always be done. It
>>> isn't costly. Should file an enhancement request on this.
>>
>> If you have a control flow graph to analyze it can become quite costly.
>
> Nope! It happens as part of semantic analysis.
Obviously, it does. The complexity of the computation still can go quite high.
|
September 28, 2014 Re: Local functions infer attributes? | ||||
---|---|---|---|---|
| ||||
Posted in reply to deadalnix | On 9/27/2014 10:48 PM, deadalnix wrote:
> On Sunday, 28 September 2014 at 04:04:24 UTC, Walter Bright wrote:
>> On 9/27/2014 8:50 PM, deadalnix wrote:
>>> On Sunday, 28 September 2014 at 03:08:09 UTC, Walter Bright wrote:
>>>> Since the function body is always present, inference should always be done. It
>>>> isn't costly. Should file an enhancement request on this.
>>>
>>> If you have a control flow graph to analyze it can become quite costly.
>>
>> Nope! It happens as part of semantic analysis.
>
> Obviously, it does. The complexity of the computation still can go quite high.
If you look at how it is currently implemented, you'll see it doesn't go high.
|
September 28, 2014 Re: Local functions infer attributes? | ||||
---|---|---|---|---|
| ||||
Posted in reply to deadalnix | deadalnix: > the function could be returned and used elsewhere, where these attribute aren't necessary. Filed: https://issues.dlang.org/show_bug.cgi?id=13550 Bye, bearophile |
September 28, 2014 Re: Local functions infer attributes? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On 9/28/2014 1:49 AM, bearophile wrote:
> Filed:
> https://issues.dlang.org/show_bug.cgi?id=13550
Thanks!
|
September 28, 2014 Re: Local functions infer attributes? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | On 9/27/14, 7:42 PM, Manu via Digitalmars-d wrote:
> void f() pure nothrow @nogc
> {
> void localFunc()
> {
> }
>
> localFunc();
> }
>
> Complains because localFunc is not @nogc or nothrow.
> Doesn't complain about pure though.
>
> Is it reasonable to say that the scope of the outer function is
> nothrow+@nogc, and therefore everything declared within should also be
> so?
Interesting. I'd guess probably not, e.g. a function may define a static local function and return its address (without either throwing or creating garbage), whereas that local function itself may do whatever it pleases.
However, local functions have their body available by definition so they should have all deducible attributes deducted. That should take care of the problem.
Andrei
P.S. I also notice that my latest attempt at establishing communication has remained ignored.
|
Copyright © 1999-2021 by the D Language Foundation