[OT] RTTI (Was: Re: On C/C++ undefined behaviours)

dsimcha dsimcha at yahoo.com
Fri Aug 20 16:24:10 PDT 2010


== Quote from retard (re at tard.com.invalid)'s article
> Fri, 20 Aug 2010 16:57:34 -0500, Andrei Alexandrescu wrote:
> > On 08/20/2010 04:48 PM, retard wrote:
> >>> I've tried eclipse with the fancy stuff off, and it's still slower
> >>> than C::B or PN2 for me.
> >>
> >> Of course it is. You're comparing apples and oranges. The core of
> >> Eclipse is much more customizable.
> >
> > I've seen a live demo by Erich Gamma in which he wrote a simple Eclipse
> > plugin inside Eclipse and then he immediately used it. It was pretty
> > darn impressive.
> >
> > Today's compiler technology still has us pay for customizability even
> > when it's not realized, so even with all plugins turned off a pluggable
> > program would still be slower than a monolithic one.
> Indeed. But even if it (static compilation) allowed controlling the
> customizability in every possible way, there can't be a single binary
> that suits everyone.
> Programs like C::B force you to choose these features on compile time.
> This is very typical in C/C++ applications - you have the choice, but it
> has to be done as early as possible. For instance, I forgot to compile in
> mp3 support when building ffmpeg or some other multimedia lib. Now the
> only choice I have is to recompile the library and possibly even all
> dependencies. It's the same thing in some Linux distributions - they
> forgot to set on the Truetype bytecode interpreter so I need to recompile
> some core libraries.
> Eclipse's philosophy seems to be completely different - some of the
> choices are made on launching the application, others when starting
> individual components. The only limitation that comes to mind is that
> because of SWT, Eclipse needs two distributions (32-bit and 64-bit), at
> least on Linux. Swing using applications don't have this limitation.

This ties into an idea I've had for awhile as a low-priority "maybe eventually"
feature.  Template metaprogramming is a big part of writing idiomatic D code.
IMHO the emphasis on it and taking it to the Nth degree are **the** main thing
that makes D special.  Its biggest weakness is that it can't be done at runtime.
I wonder if we could eventually do something like make the caller available from
the language and allow templates to be instantiated at runtime.  For example:

import std.getopt;

/**A function that is called multiple times with the same constant
 * and can only be made efficient if that constant is known at
 * compile time.
 */
double numericsFunction(int needsConstFolding)(double runtimeArgs) {
    // do stuff.
}

void main(string[] args) {
    int param;
    getopt(args, "param", &param);

    // runtimeInstantiate instantiates a function template at runtime,
    // including recursive instantiation of all templates the
    // function instantiates, loads it into the current address
    // space and returns a function pointer to it.
    auto fun = runtimeInstantiate!numericsFunction(param);

    foreach(i; 0..someHugeNumber) {
        fun(i);
    }
}

This could be implemented by embedding all necessary source code as a string
inside the executable.  For structs and classes, runtimeInstantiate would be more
difficult, but might return a factory method for creating the struct/class.


More information about the Digitalmars-d mailing list