On Tuesday, 17 February 2015 at 05:52:23 UTC, philippecp wrote:
I was wondering the same myself. I think there would be a lot
of negative side effects to using alternate memory model other
than GC (non-gc could introduce leaks, on stack has potential
to be overwritten). For that reason, I think the only choices
that make sense are that either @nogc functions are also
nothrow, or that phobos has a set of preallocated immutable
exceptions that can can thrown.
I personally think that @nogc should be relaxed to exclude
allocating exceptions since there would be no gc allocation
other than for exceptional situations. I suspect that having
code that relies on exception for main case logic is far worse
for performance than any gc overhead anyway and is a pattern
everyone knows to avoid.
Relaxing the definition of @nogc to exclude exceptions could be
an acceptable compromise. However, the nature of an exception is
that it is allocated when it is created, and deallocated after it
is caught. This model fits nicely with scope semantics. The
code catching the exception would catch a "scoped" reference
which means it would be responsible for cleaning up the
exception. It would still be allocated on the heap, but it
wouldn't be GC memory. This is how I think exceptions should
have been implemented in the first place, but back then the GC
wasn't a big deal and scope didn't exist yet.