[m-dev.] Name mangling (was Re: [m-rev.] For review: Convert Mercury terms to XML)

Ralph Becket rafe at cs.mu.OZ.AU
Mon Dec 13 11:27:20 AEDT 2004

Fergus Henderson, Saturday, 11 December 2004:
> On 08-Dec-2004, Zoltan Somogyi <zs at cs.mu.OZ.AU> wrote:
> > On 07-Dec-2004, Ralph Becket <rafe at cs.mu.OZ.AU> wrote:
> > > Can I propose the following scheme:
> > > 
> > > Unmangled character		Mangled output
> > > -------------------		--------------
> > > Z				ZZ
> > > c in [a-zA-Y0-9_]		c
> > > c not in [a-zA-Z0-9]		Z## (where ## is the ASCII hex code for c)
> > 
> > That won't work very well, but the reason why is best discussed in person.
> I would be interested to hear the reason, since I have been using a very
> similar name mangling algorithm myself (I use decimal rather than hex,
> and have some special cases such as using "ZD" rather than "Z46" for ".",
> but otherwise it is the same).
> One potential problem is that it does not deal with names that match
> keywords, or that start with "__" or start with or contain reserved
> patterns.  This I have addressed in my own name mangling algorithm
> by using a second pass that checks for those cases.

We had a discussion about this last week.

One objection was that users should not have to be aware of the name
mangling scheme if they want to call Mercury from C (or whatever), but
we decided that it was the job of pragma export to deal with this
problem, and that other Mercury compiler emitted names should not,
generally, be "visible" in user space.

Zoltan argued that choosing `Z' was a bad idea and that we should rather
pick a sequence of letters.  I don't agree, but I don't really care that
much either way.

The problems we have at the moment are

(1) mangled names containing non-[a-zA-Z0-9_] are converted to 
f_DDD_DDD_DDD_... where each DDD is the decimal code of the
corresponding unmangled name, making them utterly unreadable for

(2) the current (de)mangling scheme is implemented in three places and
the demangler tries to do way too much.  So much, in fact, that nobody
can work out how to change it (we would like to change the names of
special preds from, e.g., __Unify__ to __Unify__<type>/<arity>, but
can't because we don't know how to do it without breaking demangling).

We decided that demangling should not try to do anything clever.  If the
user ever sees a compiler generated name in an error message then we're
doing something wrong.

Zoltan wants to sort this out himself over the Xmas break if he has the

-- Ralph
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au

More information about the developers mailing list