[m-dev.] for review: fix bug in record syntax

Fergus Henderson fjh at cs.mu.OZ.AU
Fri May 5 23:46:17 AEST 2000


On 04-May-2000, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> 
> > On 03-May-2000, Simon TAYLOR <stayl at cs.mu.OZ.AU> wrote:
> > > 
> > > Fix a bug in record syntax reported by Tom Conway which caused a
> > > compiler abort if there was a field and a constructor with the
> > > same name.
> 
> Fergus wrote:
> > Does this fix work for the following test case?
> > 
> > 	:- module test2.
> > 	:- interface.
> > 
> > 	:- type foo ---> some [T] debug(T).
> > 	:- type bar ---> bar( debug :: int ).
> > 
> > 	:- pred baz(int, bar).
> > 	:- mode baz(in, in) is semidet.
> > 
> > 	:- implementation.
> > 
> > 	baz(debug(X), X).
>
> It does. I've added it to tests/valid/record_syntax_bug.m.

Hmm, it looks like I got the test case slightly wrong.
The newly installed compiler still fails the test cases that
I've attached.  For record_syntax_bug_2.m, the problem is that
code that you added to fix the bug that Tom reported is trying
to second-guess typechecking and is getting it wrong.  This
causes it to wrongly think that an occurrence of `debug'
refers to a constructor rather than a field name, leading
to an obscure sequence of error messages:

record_syntax_bug_2.m:019:   In argument 1 of clause head:
record_syntax_bug_2.m:019:   error: unification for non-canonical type
record_syntax_bug_2.m:019:   `record_syntax_bug_2:foo/0'
record_syntax_bug_2.m:019:   occurs in a context which requires all solutions.
record_syntax_bug_2.m:009: In `baz(in, out)':
record_syntax_bug_2.m:009:   error: determinism declaration not satisfied.
record_syntax_bug_2.m:009:   Declared `cc_multi', inferred `cc_nondet'.
record_syntax_bug_2.m:019:   In argument 1 of clause head:
record_syntax_bug_2.m:019:   unification with `TypeInfo_4' can fail.

Could you please fix this one, Simon?

The record_syntax_bug_3.m test case is the same as
record_syntax_bug_2.m, but without the user-defined equality.
For this test case, a different problem occurs.
The bug here is that the compiler reports ambiguity errors in the
automatically generated unification & comparison predicates:

record_syntax_bug_3.m:004: In clause for unification predicate for type (record_syntax_bug_3:foo):
record_syntax_bug_3.m:004:   error: ambiguous overloading causes type ambiguity.
record_syntax_bug_3.m:004:   Possible type assignments include:
record_syntax_bug_3.m:004: V_4 :: (record_syntax_bug_3:bar) or T
record_syntax_bug_3.m:004: In clause for comparison predicate for type (record_syntax_bug_3:foo):
record_syntax_bug_3.m:004:   error: ambiguous overloading causes type ambiguity.
record_syntax_bug_3.m:004:   Possible type assignments include:
record_syntax_bug_3.m:004: V_5 :: T or (record_syntax_bug_3:bar)

But this bug is not really attributable to record syntax, as the
exist_overload_bug.m test case shows.  That test case exhibits the
same symptoms as for record_syntax_bug_3.m, but uses only functions
and existential types, with no record syntax.

-- 
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.
-------------- next part --------------
:- module record_syntax_bug_2.
:- interface.

:- type foo ---> some [T] debug(T) where equality is all_equal.

:- type bar ---> bar( debug :: foo ).

:- pred baz(foo, bar).
:- mode baz(in, out) is cc_multi.

:- pred all_equal(foo, foo).
:- mode all_equal(in, in) is semidet.

:- implementation.
:- import_module std_util.

all_equal(_, _) :- semidet_succeed.

baz(debug(X), X).
-------------- next part --------------
:- module record_syntax_bug_3.
:- interface.

:- type foo ---> some [T] debug(T).

:- type bar ---> bar( debug :: foo ).

:- pred baz(foo, bar).
:- mode baz(in, out) is cc_multi.

:- implementation.
:- import_module std_util.

baz(debug(X), X).
-------------- next part --------------
:- module exist_overload_bug.
:- interface.

:- type foo ---> some [T] debug(T).

:- type bar ---> bar.
:- func debug(bar) = foo.

:- implementation.
:- import_module exception.

debug(bar) = throw("not implemented").


More information about the developers mailing list