On Friday, 7 June 2013 at 14:46:30 UTC, Simen Kjaeraas wrote:
On Fri, 07 Jun 2013 16:39:15 +0200, Tyler Jameson Little
<[email protected]> wrote:
If the nogc marker could be used to overload functions then
Phobos may include both versions of the code - GC and non GC
- as some code may run faster under GC. The calling function
would pick up the right one.
I can't imagine how this would work without over-complicating
the syntax. Any ideas?
I don't understand what you mean. This is how that would work:
void foo() {} // #1, Not @nogc.
@nogc void foo() {} // #2.
void bar() {
foo(); // Calls #1.
}
@nogc void baz() {
foo(); // calls #2.
}
Ok, so it takes the @nogc flag from the calling function. I was
thinking it would involve including the attribute somewhere in
the function call. *facepalm*
In this case, I think this would work well. It seems attributes
are transitive, so the change to the language would be
overloading based on attributes. I'm not sure of all of the
implications of this, but I suppose it wouldn't be terrible.
I'm just not sure what this would do:
@nogc void foo() {} // #1
@safe void foo() {} // #2
@nogc void baz() {
foo();
}
Which gets called when -safe is passed? Is it a compile-time
error, or does it just choose one? I guess I don't understand the
specifics of attributes very well, and the docs don't even
mention anything about transitivity of attributes, so I don't
know how much existing code this would break.