[m-dev.] Polymorphic modes

Fergus Henderson fjh at cs.mu.OZ.AU
Thu May 3 00:11:41 AEST 2001


On 02-May-2001, Ralph Becket <rbeck at microsoft.com> wrote:
> > Another problem is that currently it is unsound, due to RTTI
> > (std_util__construct, io__read and the like): using polymorphic modes
> > and RTTI, you can write programs that will seg fault.
> 
> Can you be more precise?
> 
> Is it the case that calls to io__read etc. in a context using polymorphic
> modes will segfault or can this happen even outside a polymorphic mode
> context?

Sorry, I was confused.  The unsoundness issue that I was thinking of would
only occur if we were to make polymorphic types imply polymorphic modes,
which currently we don't.

In investigating this, I did however discover a bug.  The attached
program is not determinism-correct.  But the compiler allows it, and
unsurprisingly goes to generate incorrect code.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
-------------- next part --------------
:- module bug.
:- interface.
:- import_module io.

:- pred main(io__state::di, io__state::uo) is det.

:- implementation.
:- import_module list, require.

:- inst non_empty_list ---> [ground | ground].

:- pred p(T::in(I), T::out(I), io__state::di, io__state::uo) is det.

main -->
    p([1], L),
    { L = [H|T] },
    print("Head = "), print(H `with_type` int), nl,
    print("Tail = "), print(T), nl.

p(X, X) -->
    io__read(Result),
    { Result = ok(X0) ->
	X = X0
    ;
	error("expected end-of-file, syntax error, or I/O error")
    }.


More information about the developers mailing list