[m-dev.] for review: polymorphic ground insts

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Oct 10 22:43:59 AEDT 2000


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?
What about if I change the definition of type `t' to

	:- type t ---> f(int).

?

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.

> 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.

> @@ -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?

Apart from that, the relative diff looks fine.

-- 
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.
--------------------------------------------------------------------------
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