[m-dev.] for review: bug fix for existential constructors

David Glen JEFFERY dgj at students.cs.mu.oz.au
Fri Aug 25 17:09:27 AEST 2000


------------------------
Estimated hours taken: 2

This change fixes a bug reported by Tom Conway yesterday. The problem was
that when a construction using a constructor with existentially quantified
args appeared in more than one disjunct, the necessary typeclass infos were
only created on one branch.

compiler/polymorphism.m:
	Only update the locations of typeclass info variables when doing
	a deconstruction of a functor with existentially typed arguments.
	(ie. don't do it for constructions). This is analagous to our handling
	of universally/existentially quantified arguments to predicate calls.

tests/hard_coded/typeclasses/exist_disjunction.{m,exp}:
	A test case for this change.
tests/hard_coded/typeclasses/Mmakefile:
	Turn this test case on.

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

Index: compiler/polymorphism.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/polymorphism.m,v
retrieving revision 1.194
diff -u -t -r1.194 polymorphism.m
--- compiler/polymorphism.m	2000/08/24 05:59:28	1.194
+++ compiler/polymorphism.m	2000/08/25 06:14:50
@@ -1372,7 +1372,7 @@
                 polymorphism__make_typeclass_info_vars( 
                                 ExistentialConstraints, [], Context,
                                 ExtraTypeClassVars, ExtraTypeClassGoals,
-                                PolyInfo1, PolyInfo2)
+                                PolyInfo1, PolyInfo3)
         ;
                 IsConstruction = no,
                 % assume it's a deconstruction
@@ -1380,12 +1380,12 @@
                                 ExistentialConstraints, 
                                 ExtraTypeClassVars,
                                 PolyInfo1, PolyInfo2),
-                ExtraTypeClassGoals = []
+                ExtraTypeClassGoals = [],
+                polymorphism__update_typeclass_infos(
+                        ExistentialConstraints, ExtraTypeClassVars,
+                        PolyInfo2, PolyInfo3)
         ),
 
-        polymorphism__update_typeclass_infos(
-                        ExistentialConstraints, ExtraTypeClassVars,
-                        PolyInfo2, PolyInfo3),
 
         %
         % Compute the set of _unconstrained_ existentially quantified type

Index: tests//hard_coded/typeclasses/Mmakefile
===================================================================
RCS file: /home/staff/zs/imp/tests/hard_coded/typeclasses/Mmakefile,v
retrieving revision 1.32
diff -u -t -r1.32 Mmakefile
--- tests//hard_coded/typeclasses/Mmakefile	2000/08/24 06:08:20	1.32
+++ tests//hard_coded/typeclasses/Mmakefile	2000/08/25 07:06:03
@@ -10,6 +10,7 @@
 PROGS=  \
         constrained_lambda \
         extract_typeinfo \
+        exist_disjunction \
         existential_type_classes \
         existential_data_types \
         existential_data_types_regr_test \
===================================================================
New file exist_disjunction.m

:- module exist_disjunction.

:- interface.

:- import_module io.

:- pred main(io__state::di, io__state::uo) is det.

:- implementation.

:- type t
	--->	a(int)
	;	b(int)
	.

:- type u
	--->	some [T] (u(T) => v(T))
	%--->	some [T] u(T)
	;	f.

:- typeclass v(T) where [].

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

:- instance v(w) where [].

:- pred p(t, u).
:- mode p(in, out) is det.

p(T, V) :-
    (
    	T = a(C),
	V = 'new u'(f(C))
    ;
    	T = b(C),
	V = 'new u'(f(C))
    ).

main -->
	{ p(a(42), X) },
	write(X), nl.

===================================================================
New file exist_disjunction.exp

u(f(42))
===================================================================


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