September 05, 2014
On 04/09/14 22:30, Kagamin wrote:

> emplace calls constructor, and constructor can't be realistically
> required to be nogc. It depends on the constructor. Similar for destroy.

But if the constructor is @nogc or if there's a default constructor.

-- 
/Jacob Carlborg
September 05, 2014
On Sunday, 24 August 2014 at 09:29:53 UTC, Jacob Carlborg wrote:
> On 2014-08-24 10:03, Bienlein wrote:
>
>> I have omitted the code for the TestClass class to save space. Problem
>> is that the compiler outputs this:
>>
>> Error: @nogc function 'main.nogcNew!(TestClass, ).nogcNew' cannot call
>> non-@nogc function 'core.exception.onOutOfMemoryError'
>> Error: @nogc function 'main.nogcNew!(TestClass, ).nogcNew' cannot call
>> non-@nogc function 'std.conv.emplace!(TestClass, ).emplace'
>> Error: @nogc function 'main.nogcDel!(TestClass).nogcDel' cannot call
>> non-@nogc function 'object.destroy!(TestClass).destroy'
>>
>> Is there a way to get around this?
>
> @nogc is a very new attribute. The runtime and standard library have not been properly annotated with this attribute yet.
>
> As a workaround you could try copy implementation of these functions to you're own code and annotate them as appropriate.

The real issue here is actually the *language*. Exceptions and Errors are GC allocated, so if you try to "check" your no-GC allocation, you'll use the GC...

A possible workaround is to preemptively static allocate the Error. However, this can cause issues if you chain Errors, or re-enter your function while throwing.
September 05, 2014
On Friday, 5 September 2014 at 06:43:56 UTC, monarch_dodra wrote:
> On Sunday, 24 August 2014 at 09:29:53 UTC, Jacob Carlborg wrote:
>> On 2014-08-24 10:03, Bienlein wrote:
>>
>>> I have omitted the code for the TestClass class to save space. Problem
>>> is that the compiler outputs this:
>>>
>>> Error: @nogc function 'main.nogcNew!(TestClass, ).nogcNew' cannot call
>>> non-@nogc function 'core.exception.onOutOfMemoryError'
>>> Error: @nogc function 'main.nogcNew!(TestClass, ).nogcNew' cannot call
>>> non-@nogc function 'std.conv.emplace!(TestClass, ).emplace'
>>> Error: @nogc function 'main.nogcDel!(TestClass).nogcDel' cannot call
>>> non-@nogc function 'object.destroy!(TestClass).destroy'
>>>
>>> Is there a way to get around this?
>>
>> @nogc is a very new attribute. The runtime and standard library have not been properly annotated with this attribute yet.
>>
>> As a workaround you could try copy implementation of these functions to you're own code and annotate them as appropriate.
>
> The real issue here is actually the *language*. Exceptions and Errors are GC allocated, so if you try to "check" your no-GC allocation, you'll use the GC...
>
> A possible workaround is to preemptively static allocate the Error. However, this can cause issues if you chain Errors, or re-enter your function while throwing.

It was also discussed to exempt `new Error` (and assert) from the @nogc restriction.
1 2
Next ›   Last »