Thread overview
@nogc for structs, blocks or modules?
Feb 16, 2016
maik klein
Feb 16, 2016
WebFreak001
Feb 16, 2016
maik klein
Feb 16, 2016
Era Scarecrow
Feb 16, 2016
rsw0x
Feb 16, 2016
jmh530
Feb 16, 2016
John Colvin
February 16, 2016
I am probably the minority but I almost never use the GC in D. Because I never use the GC I could mark 99% of my functions with @nogc.

I just seems very annoying to add @nogc to every function.

For people like me it seems that it could be a nice addition to also allow @nogc for structs like

@nocgc struct Foo{..}

or blocks

@nogc{
   void foo(){}
   void foo1(){}
}

or even modules

@nogc module Foo

What do you think?




February 16, 2016
On Tuesday, 16 February 2016 at 02:42:06 UTC, maik klein wrote:
> I just seems very annoying to add @nogc to every function.

you can mark everything as nogc with

// gc functions here

@nogc:

// nogc functions here
void foo() {}
February 16, 2016
On Tuesday, 16 February 2016 at 02:47:38 UTC, WebFreak001 wrote:
> On Tuesday, 16 February 2016 at 02:42:06 UTC, maik klein wrote:
>> I just seems very annoying to add @nogc to every function.
>
> you can mark everything as nogc with
>
> // gc functions here
>
> @nogc:
>
> // nogc functions here
> void foo() {}

Thanks, this should probably added to https://dlang.org/spec/attribute.html#nogc

I just realized that I can't even use @nogc because pretty much nothing in phobos uses @nogc
February 16, 2016
On Tuesday, 16 February 2016 at 03:13:48 UTC, maik klein wrote:
> I just realized that I can't even use @nogc because pretty much nothing in phobos uses @nogc

 Or it hasn't been tagged @nogc or based on templates they can't be preemptively marked it. I'd think most ranges could be @nogc; And recently with some of the toString's being rewritten to use ranges instead of allocating memory would be @nogc as well.

 Many algorithms are probably be @nogc too.
February 16, 2016
On Tuesday, 16 February 2016 at 03:41:12 UTC, Era Scarecrow wrote:
> On Tuesday, 16 February 2016 at 03:13:48 UTC, maik klein wrote:
>> I just realized that I can't even use @nogc because pretty much nothing in phobos uses @nogc
>
>  Or it hasn't been tagged @nogc or based on templates they can't be preemptively marked it. I'd think most ranges could be @nogc; And recently with some of the toString's being rewritten to use ranges instead of allocating memory would be @nogc as well.
>
>  Many algorithms are probably be @nogc too.

templated constructs aren't tagged @nogc because it's inferred, tagging them @nogc would impose restrictions on the end user
February 16, 2016
On Tuesday, 16 February 2016 at 03:13:48 UTC, maik klein wrote:
>
> Thanks, this should probably added to https://dlang.org/spec/attribute.html#nogc
>

It's actually in there, it's just easy to miss.

It's the box with the text after

"Attributes are a way to modify one or more declarations. The general forms are: "

February 16, 2016
On Tuesday, 16 February 2016 at 03:13:48 UTC, maik klein wrote:
> On Tuesday, 16 February 2016 at 02:47:38 UTC, WebFreak001 wrote:
>> On Tuesday, 16 February 2016 at 02:42:06 UTC, maik klein wrote:
>>> I just seems very annoying to add @nogc to every function.
>>
>> you can mark everything as nogc with
>>
>> // gc functions here
>>
>> @nogc:
>>
>> // nogc functions here
>> void foo() {}
>
> Thanks, this should probably added to https://dlang.org/spec/attribute.html#nogc
>
> I just realized that I can't even use @nogc because pretty much nothing in phobos uses @nogc

You probably can, remember that templates have their attributes inferred.