[m-rev.] for review: printing streams sensibly in the debugger

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Sep 25 14:32:10 AEST 2003

On 04-Sep-2003, Zoltan Somogyi <zs at cs.mu.OZ.AU> wrote:
> Print streams sensibly in the debugger.
> runtime/mercury_library_types.h:
> 	Define MercuryFilePtr as a shorthand for MercuryFile *.
> library/io.m:
> 	To allow the debugger to detect which variables are I/O streams,
> 	change the stream types from being equivalent to c_pointer (and thus
> 	indistinguishable from other c_pointers) to their own type.  Implement
> 	this type as MercuryFilePtr in the C backend. In the IL backend, we
> 	represent it as Object[], the minimum representation change possible.
> 	Use the C type definition to get rid of many casts.

Contrary to the log message, io__stream was not previously equivalent
to c_pointer; rather, it was a no_tag type that wrapped c_pointer.
So I don't think it was actually necessary to change the definition
of io__stream to allow the debugger to detect which variables are I/O

Nevertheless, although not needed for printing streams in the debugger,
this change might still be nice from a stylistic point of view anyway...
EXCEPT that it breaks various things, due to io__(input_)stream being an
abstract equivalence type whose definition's C type no longer corresponds
to MR_Word.

In particular, if the browser is compiled in grade asm_fast.gc
with intermodule optimization enabled (as happens on earth.cs.mu.oz.au),
we get

	../runtime/mercury_init.h:143: conflicting types for
	mdb.debugger_interface.mh:39: previous declaration of

because the C type for the io__stream argument of output_current_vars
is either MR_Word (without intermodule optimization) or MercuryFilePtr
(with intermodule optimization).

Similarly, in grade hlc.gc using lcc, we get

	Mercury/cs/mdb.browse.c: browse.m:546: type error in argument 1 to
	found `unsigned int' expected `pointer to void'

because the C type for the stream argument of io__write_char/4 is either
MR_Word (from outside io.m) or MR_Box (from inside io.m).
[It is MR_Box (i.e. `void *') rather than `MercuryFilePtr' because
all C foreign types get "boxed" in case they are not word-sized.]
The same thing happens with gcc, except in that case it is just a warning,
not an error.

I guess the way to fix this would be to make io__stream a no_tag type
which wraps another type named say io__stream_defn, which is then
defined using pragma foreign_type.  But then we'd need to write Mercury
wrapper routines around every C foreign_proc routine that wrap/unwrap the
io__stream arguments.  That seems about as bad as the original C casts;
more type-safe, but also considerably more verbose.

So perhaps it's best to just back out this part of the change?

Fergus Henderson <fjh at 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.
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe

More information about the reviews mailing list