[m-dev.] for review: polymorphic ground insts
David Overton
dmo at cs.mu.OZ.AU
Fri Oct 13 15:17:56 AEDT 2000
On Tue, Oct 10, 2000 at 10:43:59PM +1100, Fergus Henderson wrote:
> On 29-Sep-2000, David Overton <dmo at cs.mu.OZ.AU> wrote:
> > It's been a long time, but I've finally got back to this and got it
> > working. I've fixed the problem with existential types
>
> Well, I'm not really convinced that this change handles existential
> types consistently with the way it handles non-existential types.
> But if it is only the corner cases that it mishandles, and these cases
> occur rarely or not at all in practice, and the symptom is just that
> the mode checker rejects the program, and the code in question (in
> maybe_get_cons_id_arg_types in modes.m) is marked with an XXX, then I
> think it is OK to commit it.
>
> The situations I'm worried about are things like
>
> :- type t ---> some [T] f(T).
> :- inst t ---> f(ground).
>
> :- pred p(t::in, t::out(t)) is det.
> p(X, X).
>
> Is this allowed?
This case will work fine.
> What about if I change the definition of type `t' to
>
> :- type t ---> f(int).
>
> ?
This case also works.
Note: neither of these examples work in the current compiler.
The problematic case would be if you change the definition of the inst
`t' to something like
:- inst t ---> f(bound(....)).
There is no way of checking whether this bound ints contains all the
functors for the existential type T.
>
> Also, I found it confusing that the name maybe_get_cons_id_arg_types
> was used for two different procedures (/4 in modes.m, /5 in type_util.m).
> I think it would be a good idea to rename one of them.
I've renamed the one in type_util.m to `get_cons_id_non_existential_arg_types'.
>
> > compiler/type_util.m:
> > Add a new predicate, type_util__cons_id_arg_types which
> > nondeterministically returns the cons_ids and argument types for a
> > given type.
>
> The log message there doesn't describe all the changes.
I'll add this sentence:
Add a new predicate type_util__get_consid_non_existential_arg_types
which is the same as type_util__get_existential_arg_types except
that it fails rather than aborting for existenially types arguments.
>
> > @@ -814,20 +850,24 @@
> > ).
> >
> > type_util__cons_id_arg_types(ModuleInfo, VarType, ConsId, ArgTypes) :-
> > + type_to_type_id(VarType, TypeId, TypeArgs),
> > + module_info_types(ModuleInfo, Types),
> > + map__lookup(Types, TypeId, TypeDefn),
> > + hlds_data__get_type_defn_body(TypeDefn, TypeDefnBody),
> > + TypeDefnBody = du_type(_, ConsTags, _, _),
> > + map__member(ConsTags, ConsId, _),
> > +
> > module_info_ctors(ModuleInfo, Ctors),
> > -
> > - map__member(Ctors, ConsId, ConsDefns),
> > + map__lookup(Ctors, ConsId, ConsDefns),
> > list__member(ConsDefn, ConsDefns),
> >
> > - type_to_type_id(VarType, TypeId, TypeArgs),
> > ConsDefn = hlds_cons_defn(ExistQVars0, _, Args, TypeId, _),
> > - module_info_types(ModuleInfo, Types),
> > - map__lookup(Types, TypeId, TypeDefn),
> > - hlds_data__get_type_defn_tparams(TypeDefn, TypeDefnParams),
> > - term__term_list_to_var_list(TypeDefnParams, TypeDefnVars),
> >
> > % XXX handle ExistQVars
> > ExistQVars0 = [],
> > +
> > + hlds_data__get_type_defn_tparams(TypeDefn, TypeDefnParams),
> > + term__term_list_to_var_list(TypeDefnParams, TypeDefnVars),
>
> Can you explain the purpose of that change?
This predicate non-deterministically returns a ConsId and ArgTypes for
a type, VarType. My original version was extremely inefficient
(profiling showed that it contributed about 15% to the execution time
of the compiler, IIRC) since it did a search right through the
cons_table looking for constructors belonging to the type. The
revised version looks up the constructors in the type_table instead.
>
> Apart from that, the relative diff looks fine.
>
Okay, I'll make those changes and commit.
David
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list