"bug/feature" in mercury any

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Jan 5 21:55:46 AEDT 1999


On 21-Dec-1998, Peter Stuckey <pjs at cs.mu.OZ.AU> wrote:
> We need to be able to convert an any inst to a ground inst
> and it doesnt seem like Mercury will allow this. (It should,
> it can be quite logical)
> 
> Heres an example of the problem, when we try to write
> 	promise_ground
> 
> Can this be fixed!

The problem here is one that should hopefully be solved by alias tracking.

The reason that the problem occurs is that the compiler transforms your code

	bar(X) :-
		promise_foo_ground(X).

to

	bar(HeadVar__1) :-
		HeadVar__1 = X,
		promise_foo_ground(X).

before mode analysis.  Mode analysis correctly infers that `X' is ground,
but because the current version doesn't do any alias tracking, it fails
to infer that this implies that `HeadVar__1' is ground.

> ::::::::::::::
> inst_coerce.m
> ::::::::::::::
> 
> :- module inst_coerce.
> 
> :- interface.
> 
> :- import_module int, float, list.
> 
> :- type foo ---> f(int) ; g(list(float)).
> 
> :- pred bar(foo).
> :- mode bar(any -> ground) is det.
> 
> :- implementation.
> 
> :- pred promise_foo_ground(foo).
> :- mode promise_foo_ground(any -> ground) is det.
> 
> :- pragma c_code(promise_foo_ground(X::(any -> ground)),
>                 will_not_call_mercury, "
>         /* Maybe check X is actually ground */
> ").
> 
> bar(X) :-
>         promise_foo_ground(X).
> 
> 
> 
> warwick at mundook% mmake inst_coerce.depend
> mmc --generate-dependencies    inst_coerce
> warwick at mundook% mmake inst_coerce
> rm -f inst_coerce.c
> mmc --compile-to-c --grade asm_fast.gc       inst_coerce.m > inst_coerce.err 2>&1
> gmake: *** [inst_coerce.c] Error 1
> warwick at mundook% more inst_coerce.err
> inst_coerce.m:024: In clause for `bar((any -> ground))':
> inst_coerce.m:024:   mode error: argument 1 did not get sufficiently instantiate
> d.
> inst_coerce.m:024:   Final instantiatedness of `HeadVar__1' was `any',
> inst_coerce.m:024:   expected final instantiatedness was `ground'.
> For more information, try recompiling with `-E'.
> warwick at mundook% which mmc
> /home/mercury/public/mercury-latest/alpha-dec-osf3.2/bin/mmc
> warwick at mundook% mmc -v
> Mercury Compiler, version rotd-1998-12-18, configured for alpha-dec-osf3.2
> Copyright (C) 1993-1998 The University of Melbourne
> Usage: mmc [<options>] <arguments>
> Use `mmc --help' for more information.
> warwick at mundook% 
> 
> 
> 
> 
> 

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "Binaries may die
WWW: <http://www.cs.mu.oz.au/~fjh>  |   but source code lives forever"
PGP: finger fjh at 128.250.37.3        |     -- leaked Microsoft memo.



More information about the developers mailing list