[log in to unmask] wrote:
...
> I'm still skeptical about the desirability of the processor keeping a
> database of instances. If you have a system-wide database, I can see
> changing one jot or tittle triggering a compilation that may take weeks.
???
I still can't get why you bring this up. An implementation that
statically resolves generic references has to maintain a database
of all instanced versions of the generic, no matter how they are
instanced. Nothing in either of your proposals reduces the
number of instances below the number required to satisfy the
actual references in the code. If the presence of a reference
is what triggers the formation of an instance, that keeps the number
of instances below (or at worst, equal to) any implementation in
which users may declare instances that are never used.
What is worse is if it's possible in a single program to create
multiple instances of the generic with the *same* types but they
are required by the definition of the feature to be regarded as
distinct (for example:the user chose a different name for the
instance).
In the meantime, it is not always even desirable to preserve
run-time efficiency when the user may be more interested in
other aspects of the functionality. Pretty much the canonical
example of a dynamically generic language is LISP, where
I haven't noticed any exponential explosion occuring in their
implementations. They tend to have just *one* instance of each
procedure (which runs slower) or the option to specify that a
specific instance be created "on the fly" as needed. If the
generic is in a dynamically associated library, the ability to
still make calls may outweigh the run-tme efficiency of the code.
The design of the language feature should not take this decision
on its own. The processor (and preferrably the user) should be
allowed to choose either dynamic instancing or static instancing
as suits the purposes of the program. And all of that is completely
independent of the syntax chosen to express such features. This
early in the discussion of a feature that can't possibly be standard
for years we should keep our options open.
Compiler technology is sufficiently mature that explicit instance
declarations are *not* inherently required in order for static instancing
to be accomplished efficiently. The usual method these days
(unfortunately) is to create a mangled name (containing the type(s)
for which the instance is desired). All references to the generic
with the same type signature of the arguments call the same mangled
name. Ultimately, one instance of the generic for each type signature
referenced by the whole program is needed. If this is supplied in an
existing library, that's used. If not, the compiler can generate that
instance automatically. This is *not* more of a burden on the compiler
than a rather complex new syntax would be.
--
J. Giles
|