[Issue 2029] Typesafe variadic functions don't work in CTFE
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Nov 18 03:46:13 PST 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2029
--- Comment #5 from Tomas Lindquist Olsen <tomas at famolsen.dk> 2009-11-18 03:46:13 PST ---
I've attached a draft patch that replaces the typesafe variadic ast rewrites to
something that works in any scope (and with ctfe).
without the patch the following function:
void foo(int[] arr ...)
when called:
foo(1,2,3);
is rewritten as:
int[3] _args;
(_args[0] = 1, _args[1] = 2, _args[2] = 3, foo(_args[]));
..
In global scope, this breaks, as you cannot assign to globals from ctfe, and in
normal ctfe, breaks somehow as well.
This patch changes the rewrite to:
foo([1,2,3]);
with each element being implicitly converted to the array element type.
One downside is that codegen always allocates array literals on the heap, so it
degrades performance a bit, but that needs to be fixed for
http://d.puremagic.com/issues/show_bug.cgi?id=2356 as well (though it's
probably a slightly different issue), and generally I'm not getting an
impression that it's a concern (performance is secondary).
In any case I added a new "scopedLiteral" field to ArrayLiteralExp so that
codegen knows it's allowed to put the array on the stack if it wants to.
Comments appreciated.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list