[m-dev.] diff: get rid of unnecessary tvars

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Jun 19 14:55:07 AEST 1998


On 19-Jun-1998, David Glen JEFFERY <dgj at cs.mu.OZ.AU> wrote:
> (Can you think of a better name than varset__squash?)

I think that name is OK.

> Get rid of unnecessary type variables when creating the auxiliary predicate
> for an instance method.

The log message should document the rationale for this change.

> compiler/check_typeclass.m:
> 	Get rid of the unnecessary tvars.
> 
> compiler/typecheck.m:
> 	Undo a previous change which used all the info from
> 	typecheck_get_final_info even if we were only checking the types.
> 	Call varset__squash to evict unnecessary tvars.
> 
> library/varset.m:
> 	Add a predicate varset__squash which gets rid of unused variables.

I suggest you change the log message for check_typeclass.m to

	compiler/check_typeclass.m:
		Call varset__quash to get rid of the unnecessary tvars.

and move the log message for library/varset.m to the start.

> Index: compiler/check_typeclass.m
...
> +                % XXX this should go in type_util.m
> +        RenameConstraint = lambda([C0::in, C::out] is det,
> +                (
> +                        C0 = constraint(ClassName, ClassArgTypes0),
> +                        term__apply_variable_renaming_to_list(ClassArgTypes0,
> +                                SquashSubst, ClassArgTypes),
> +                        C = constraint(ClassName, ClassArgTypes)
> +                )),
> +        list__map(RenameConstraint, ClassContext2, ClassContext),

The comment at the XXX is correct, and you should fix it.

> +        % Given a varset and a list of variables, construct a new varset
> +        % containing only those variables. Also return a substitution
> +        % mapping the selected variables in the original varset into 
> +        % variables in the new varset.
> +:- pred varset__squash(varset, list(var), varset, map(var, var)).
> +:- mode varset__squash(in, in, out, out) is det.

The comment here is a bit misleading, because the new varset doesn't
contain the same variables as the variables in the list.

Also the specification is incomplete -- it doesn't say anything about
the ordering, which means that the call to list__sort in the
implemenation is not required by the specification.

> +        %
> +        % We need to sort the fresh variables, to
> +        % ensure that the substitution that we create below
> +        % does not alter the relative ordering of the variables
> +        %
> +        list__sort(NewVars0, NewVars),

--------------------

Can we please see another diff when you've addressed these concerns?

Thanks.

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



More information about the developers mailing list