for review: fix for inlining of polymorphic procedures

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Feb 20 00:59:17 AEDT 1998


On 19-Feb-1998, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> compiler/polymorphism.m
> 	Set the type of `base_type_info's passed where a `type_info'
> 	is expected to `type_info'.

That's fine.

> compiler/common.m
> 	Don't do common structure elimination on structures
> 	which are of different types, since that could cause
> 	similar bugs.

That change would be a pity.

A much nicer fix would be to still perform the common structure
elimination even if the structures have different types, but to
preserve type correctness by inserting calls to an `unsafe_type_cast'
predicate:

	:- pred unsafe_type_cast(T1, T2).
	:- mode unsafe_type_cast(in, out) is det.

	% operational semantics equivalent to this:
	:- pragma c_code(unsafe_type_cast(X::in, Y::out),
			will_not_call_mercury, "Y = X;").

This predicate could be implemented as a compiler builtin,
to avoid the overhead of a pragma c_code.  But even if it
wasn't, an call to unsafe_cast would be quite cheap, certainly
cheaper than a call to GC_malloc().

-- 
Fergus Henderson <fjh at cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3         |     -- the last words of T. S. Garp.



More information about the developers mailing list