[clean-list] About abstract synonym types...
Fergus Henderson
fjh@cs.mu.oz.au
Fri, 6 Feb 2004 00:33:13 +1100
On 05-Feb-2004, Arjen van Weelden <arjenw@cs.kun.nl> wrote:
> Arjen van Weelden (by mistake) wrote:
> >[Fergus wrote:]
> >> - how do they interact with separate compilation?
> >> Does changing the definition of an abstact synonym type
> >> require recompiling modules that import the module which
> >> defines it?
> >
> >They should not force compilation of other modules, but because the
> >semi-abstract definition is in the .dcl definition module, it will
> >trigger recompilation.
>
> John just told me this is not correct. It SHOULD force recompilation
> because the compiler optimizes/generates different code because of the
> implementation of the semi-abstract types. Which is of course obvious,
> if you think about it ;-).
No, it's not obvious -- it is implementation-dependent. These are
abstract types, so there are no actual operations being performed on
them; they are just being passed around. Whether or not the compiler
will generate different code for different concrete types if they are
just being passed around is implementation-dependent.
For example, the original Mercury implementation represents all data types
as a single word (types such as tuples that don't fit in a single word
get boxed), and the argument passing convention is that the first input
argument goes in register r1, the second in r2, etc. This argument
passing convention does not depend on the types of the arguments.
I think many other functional programming language implementations use
a similar approach. For implementations like this, the code generated
for a module using an abstract synonym type will be the same regardless
of how that abstract synonym type is defined.
So it becomes a design issue: do you prefer better separate compilation
guarantees, so that a library's implementation can be changed without
needing to recompile the clients, or do you prefer giving the compiler
more freedom about how it generates code, which may allow improved
efficiency and/or better interoperability with code written in other
languages?
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.