[m-rev.] for review: fix termination analysis bug

Julien Fischer juliensf at students.cs.mu.OZ.AU
Fri Oct 3 17:02:59 AEST 2003


On Fri, 3 Oct 2003, Fergus Henderson wrote:

> On 03-Oct-2003, Julien Fischer <juliensf at students.cs.mu.OZ.AU> wrote:
> >
> > Fix a bug that caused the termination analyser to abort when using
> > the `num-data-elems' norm whilst analysing code that (de)constructs
> > existentially typed data types.
> >
> > compiler/term_util.m:
> > 	When building the weight table add any type_infos to the list
> > 	of non-recursive arguments otherwise term_util.functor_norm/9 will
> > 	throw an exception when processing an existentially typed data item.
> > 	When calculating the weight do not add arguments that correspond
> > 	to type_info related variables.
>
> Hmm... my intuition is that termination analysis probably ought to take
> the sizes of type_info variables into account, otherwise it won't be
> able to infer termination of any procedure which recursively
> deconstructs types, e.g. io__write_univ.
>
> So I'm not sure that this is the best fix in the long term.
> But it does at least look like an improvement on the status quo.

Not counting type_info variables towards the weight of a functor but
including them in the list of arguments whose size is to be counted is
consistent with what the compiler does for the `total' norm (although
this may be more by accident than design).  (Including them in the set
of counted arguments is also consistent with what the `simple' norm
does).

> I suggest adding an XXX comment about the above point.

I've added a comment that describes what we are currently doing.
(interdiff follows)

diff -u compiler/term_util.m compiler/term_util.m
--- compiler/term_util.m	2 Oct 2003 13:39:09 -0000
+++ compiler/term_util.m	3 Oct 2003 06:36:55 -0000
@@ -296,8 +296,13 @@
 	type_ctor::in, list(type_param)::in,
 	weight_table::in, weight_table::out) is det.

+% XXX Currently, the weight of a functor is not affected by the presence
+% of any arguments that are type_info related.  However, the set of
+% arguments whose sizes should be counted towards the total size of
+% the term will include any type-info related arguments.
+
 find_weights_for_cons(Ctor, TypeCtor, Params, Weights0, Weights) :-
	Ctor = ctor(ExistQVars, _Constraints, SymName, Args),
 	list__length(ExistQVars, NumExistQVars),
 	list__length(Args, Arity),
 	( Arity > 0 ->
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list