new should lower to a template function call
Johan
j at j.nl
Fri Jul 24 17:14:47 UTC 2020
On Friday, 24 July 2020 at 14:06:28 UTC, Andrei Alexandrescu
wrote:
>
> We need to template all we can of druntime. All those silly
> C-style functions decaying to void* and dependencies and
> runtime type information must go.
Reliance on runtime type information for object creation is not
good, I agree. But that is easily solved by having the compiler
make a call to the ctor (instead of implementing that call in
druntime). Another option is to templatize, as you wrote.
I don't agree that everything should be moved to templates in
druntime, but I cannot formulate a strong argument against it (I
also have not seen strong arguments in favor of it though).
Because "careful consideration" is not a strong point of D
development, I am wary.
Templatizing will make certain types of functionality _harder_.
If a library/program wants to break, or hook into, object
creation inside user code, it will be impossible with templatized
functions (you cannot predict the templated function names of
code that has not yet been written). For example,
AddressSanitizer can only work with non-templatized allocation
functions. If malloc was a template, it would be _much_ harder to
implement AddressSanitizer support (and currently not possible
while keeping source location in error messages).
In favor of compiler-implemented code (instead of druntime) is
that the compiler is able to add debug information to generated
code, linking the instructions to source location in user code. I
think this will only be possible for druntime-implemented when:
a) the code is force-inlined and b) there is a way to disable
debug information tagging of the instructions inside the
druntime-implemented function (such that the source-location
stays the same as the user's code). (a) is already available in
our compilers, (b) is not yet.
Template bloat is a standard concern, because we do not have any
defense against it. Did anyone ever look into the array
comparison case with template bloat? Force-inlining _and_ not
emitting into binary (currently not available to user/druntime
code) would fix that, although then maybe someone else starts to
argue about instruction count increase...
-Johan
More information about the Digitalmars-d
mailing list