diff: typeclass bug fix
David Glen JEFFERY
dgj at cs.mu.OZ.AU
Thu Jun 18 13:03:11 AEST 1998
Hi,
Could someone (Fergus?) review this?
-----------------------------------------------------------------------------
Estimated hours taken: 4
Fix a bug where polymorphism.m was erroneously applying a type substition
recursively, causing an infinite loop in certain situations.
compiler/polymorphism.m:
Change a call to term__apply_rec_substitution_to_list into
term__apply_substitution_to_list.
Also put the goals to initialise the superclass type-infos *before*
the construction unification for the sub-class.
-----------------------------------------------------------------------------
Index: polymorphism.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/polymorphism.m,v
retrieving revision 1.136
diff -u -t -r1.136 polymorphism.m
--- polymorphism.m 1998/06/09 02:14:19 1.136
+++ polymorphism.m 1998/06/17 09:38:53
@@ -1149,7 +1149,7 @@
ClassId = class_id(ClassName, ClassArity),
term__vars_list(NewConstrainedTypes, NewConstrainedVars),
list__append(NewConstrainedVars, ConstrainedVars0, ConstrainedVars),
- term__apply_rec_substitution_to_list(NewConstrainedTypes, TypeSubst,
+ term__apply_substitution_to_list(NewConstrainedTypes, TypeSubst,
ConstrainedTypes0),
% we need to maintain the invariant that types in class constraints
% do not contain any information in their term__context fields
@@ -1534,7 +1534,7 @@
TypeClassInfoGoal = Unify - GoalInfo,
NewGoals0 = [TypeClassInfoGoal, BaseGoal],
- list__append(SuperClassGoals, NewGoals0, NewGoals),
+ list__append(NewGoals0, SuperClassGoals, NewGoals),
Info = poly_info(VarSet, VarTypes, TVarSet, TVarMap,
TCVarMap, Proofs, PredName, ModuleInfo).
-----------------------------------------------------------------------------
New file: tests/hard_coded/typeclasses/instance_superclass.m:
:- module instance_superclass.
% This is a regression test for the case where there is a superclass
% relationship, and the instance declaration has a type variable in the
% instance type.
:- interface.
:- import_module list.
:- typeclass c1(T) where [ ].
:- typeclass c2(T) <= c1(T) where [ ].
:- instance c1(list(T)) where [ ].
:- instance c2(list(T)) where [ ].
:- pred p is det.
:- implementation.
% The bug that this test case is checking for is at the creation of
% the typeclass info for this call: if the substitution from "T" in
% the typeclass decl to "list(T)" in the instance is applied
% recursively, an infinite loop results.
p :- q([1]).
:- pred q(T) <= c2(T).
:- mode q(in) is det.
q(_).
-----------------------------------------------------------------------------
love and cuddles,
dgj
--
David Jeffery (dgj at cs.mu.oz.au) | Marge: Did you just call everyone "chicken"?
MEngSc student, | Homer: Noooo. I swear on this Bible!
Department of Computer Science | Marge: That's not a Bible; that's a book of
University of Melbourne | carpet samples!
Australia | Homer: Ooooh... Fuzzy.
More information about the developers
mailing list