Discussion:
[m-dev.] `pred' and `mode' declarations and the module system
Julien Fischer
2016-01-11 04:58:01 UTC
Permalink
Hi,

The reference manual does not currently define an aspect of the interaction
between `pred' (or `func`) declarations, `mode' declarations and the module
system: are all the modes of an exported predicate required to be exported
themselves? Currently, the compiler allows the following:

:- module example.
:- interface.

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

:- implementation.

:- mode foo(out, in) is semidet.

...

And indeed, it currently allows you to export a predicate without exporting any
of the modes at all:

:- module example2
:- interface.

:- pred foo(int, int).

:- implementation.

:- mode foo(in, out) is semidet.
:- mode foo(out, in) is semidet.

...

(Regardless of the what the intended behaviour is, the second example should at
least elicit a warning.)

Another issue related to `pred' and `mode' declarations is that the reference
manual says that if "a predicate or function has only one mode, the ¡pred¢ and
¡mode¢ declaration can be combined" -- this implies that it should be an error
for a predicate to have both a predmode declaration and separate mode
declarations. The compiler currently accepts that situation without complaint
as well.

:- module example3.
:- interface.

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

:- implementation.
...

(Ditto, if the same thing occurs for type class method declarations.)

I suggest that we change the language definition to require that:

1. *all* mode declarations for an exported predicate or function must also
be exported.

2. be explicit about the fact that mixing predmode declarations with separate
mode declarations is an error.

(And make the implementation conform to that.)

Julien.
Paul Bone
2016-01-11 06:03:22 UTC
Permalink
Post by Julien Fischer
1. *all* mode declarations for an exported predicate or function must also
be exported.
2. be explicit about the fact that mixing predmode declarations with separate
mode declarations is an error.
(And make the implementation conform to that.)
Agreed.
--
Paul Bone
Zoltan Somogyi
2016-01-11 10:50:48 UTC
Permalink
Post by Julien Fischer
1. *all* mode declarations for an exported predicate or function must also
be exported.
2. be explicit about the fact that mixing predmode declarations with separate
mode declarations is an error.
Agree on both points.
Post by Julien Fischer
(And make the implementation conform to that.)
Since I worked on this recently, I will do that.

Zoltan.
Julien Fischer
2016-01-11 11:42:12 UTC
Permalink
Post by Zoltan Somogyi
Post by Julien Fischer
1. *all* mode declarations for an exported predicate or function must also
be exported.
2. be explicit about the fact that mixing predmode declarations with separate
mode declarations is an error.
Agree on both points.
I'll post a change to the reference manual shortly.
Post by Zoltan Somogyi
Post by Julien Fischer
(And make the implementation conform to that.)
Since I worked on this recently, I will do that.
Incidentally, the background to this is some of the tests cases in
tests/invalid that have never been enabled. If you're looking at
the frontend you may also want to take a look at:

tests/invalid/parent.undeclared_child
tests/invalid/bad_detism

Ths issues I raised above are due to

tests/invalid/typeclass_dup_method_mode

The method p/1 has both a predmode declaration and a separate mode
declaration. (We also don't pass that test due to not checking for
indistinguishable modes in type class declarations.)

Julien.

Loading...