[m-dev.] for review: bug fix for typeclasses

David Glen JEFFERY dgj at cs.mu.OZ.AU
Mon Jan 15 15:19:22 AEDT 2001


On 14-Jan-2001, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> 
> Estimated hours taken: 6
> 
> Fix a bug which caused some programs using typeclasses to
> crash with a segmentation fault.

This changes looks fine. Thanks, Simon.

Just a couple of comments below.

> compiler/polymorphism.m:
> 	For typeclass method implementations, make sure the
> 	order of the type-info and typeclass-info arguments
> 	matches the order used by do_call_class_method.
> 	The type-infos for the unconstrained type variables in
> 	the instance declaration and the typeclass-infos for the
> 	constraints on the instance declaration must come
> 	before any other type-infos and typeclass-infos.
> 
> compiler/hlds_pred.m:
> 	Add a field to the pred_info type to record for each
> 	typeclass method implementation which class constraints 
> 	come from the `:- instance' declaration and which come
> 	from the predicate or function declaration in the
> 	`:- typeclass' declaration.
> 
> compiler/check_typeclass.m:
> 	Fill in the new field in the pred_info.
> 
> compiler/typecheck.m:
> 	Apply the necessary renamings to the types and
> 	class constraints in the new field in the pred_info.
> 
> tests/hard_coded/typeclasses/Mmakefile:
> tests/hard_coded/typeclasses/typeclass_order_bug.{m,exp}
> tests/hard_coded/typeclasses/typeclass_order_bug2.{m,exp}
> 	Test cases.

> Index: compiler/polymorphism.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/compiler/polymorphism.m,v
> retrieving revision 1.204
> diff -u -u -r1.204 polymorphism.m
> --- compiler/polymorphism.m	2000/11/17 17:48:28	1.204
> +++ compiler/polymorphism.m	2001/01/13 04:11:40

You should probably add a couple of lines to the documentation at the
top of polymorphism.m and/or notes/type_class_transformation.html,
explaining that instance methods don't follow the normal convention for 
passing type infos and typeclass infos.

> +	%
> +	% For class method implementations, do_call_class_method
> +	% extras type-infos and typeclass-infos from the
> +	% typeclass-info and pastes them onto the front of
> +	% the argument list. We need to match that order here.
> +	%

s/extras/adds
?

Also, the two test cases you provided are good, but I'd like to see one
with a constraint on the type class method too.


dgj
-- 
David Jeffery (dgj at cs.mu.oz.au) | If your thesis is utterly vacuous
PhD student,                    | Use first-order predicate calculus.
Dept. of Comp. Sci. & Soft. Eng.|     With sufficient formality
The University of Melbourne     |     The sheerist banality
Australia                       | Will be hailed by the critics: "Miraculous!"
                                |     -- Anon.
--------------------------------------------------------------------------
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