[m-dev.] for review: bug fix for superclasses
David Glen JEFFERY
dgj at cs.mu.OZ.AU
Thu Nov 2 17:33:10 AEDT 2000
This is for Fergus to review.
This change fixes part of a bug reported by Peter Ross earlier this week.
The test case included below now works, but Pete's test case still barfs.
(YATCB!)
(BTW, I have figured out what is going wrong with the rest of Pete's test case,
but I'm still working on a fix...)
---------------------------------------------------------------------------
Estimated hours taken: 5
Fix a bug whereby polymorphism was not using the complete set of class
constraint proofs when generating a type class info, resulting in a map
lookup failure under certain conditions.
compiler/polymorphism.m:
When generating a type class info, don't just pass the proofs for
the instance declaration that we calculated in check_typeclass.m.
These proofs just specify how to build the type class infos for any
superclass constraints *given the constraints on the instance
declaration*. Instead, we pass the union of those constraints and
those local to the predicate. This provides proofs for the constraints
on the instance declaration too.
compiler/typecheck.m:
Rather than using the headvars as the set of variables that must not
be bound when searching the superclass relation, use all the variables
in the varset. This remove a parameter from the exported constraint
reduction predicate.
compiler/check_typeclass.m:
Remove the redundant parameter.
tests/hard_coded/typeclasses/Mmakefile:
tests/hard_coded/typeclasses/superclass_bug2.exp:
tests/hard_coded/typeclasses/superclass_bug2.m:
A test case for this.
---------------------------------------------------------------------------
Index: compiler/check_typeclass.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/check_typeclass.m,v
retrieving revision 1.35
diff -u -t -r1.35 check_typeclass.m
--- compiler/check_typeclass.m 2000/10/31 01:35:26 1.35
+++ compiler/check_typeclass.m 2000/11/02 05:45:00
@@ -791,13 +791,11 @@
module_info_instances(ModuleInfo, InstanceTable),
module_info_superclasses(ModuleInfo, SuperClassTable),
- term__vars_list(InstanceTypes, UnivTvars),
-
% Try to reduce the superclass constraints,
% using the declared instance constraints
% and the usual context reduction rules.
typecheck__reduce_context_by_rule_application(InstanceTable,
- SuperClassTable, InstanceConstraints, UnivTvars, TypeSubst,
+ SuperClassTable, InstanceConstraints, TypeSubst,
InstanceVarSet1, InstanceVarSet2, Proofs0, Proofs1,
SuperClasses, UnprovenConstraints),
Index: compiler/polymorphism.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/polymorphism.m,v
retrieving revision 1.201
diff -u -t -r1.201 polymorphism.m
--- compiler/polymorphism.m 2000/10/13 13:55:48 1.201
+++ compiler/polymorphism.m 2000/11/01 07:17:40
@@ -2044,7 +2044,7 @@
apply_subst_to_constraint_proofs(RenameSubst,
SuperClassProofs0, SuperClassProofs1),
apply_rec_subst_to_constraint_proofs(InstanceSubst,
- SuperClassProofs1, SuperClassProofs),
+ SuperClassProofs1, SuperClassProofs2),
term__var_list_to_term_list(UnconstrainedTvars0,
UnconstrainedTypes0),
@@ -2053,6 +2053,9 @@
term__apply_rec_substitution_to_list(
UnconstrainedTypes1, InstanceSubst,
UnconstrainedTypes),
+
+ map__overlay(Proofs, SuperClassProofs2,
+ SuperClassProofs),
% Make the type_infos for the types
% that are constrained by this. These
Index: compiler/typecheck.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/typecheck.m,v
retrieving revision 1.289
diff -u -t -r1.289 typecheck.m
--- compiler/typecheck.m 2000/10/31 01:35:32 1.289
+++ compiler/typecheck.m 2000/11/02 05:44:25
@@ -146,12 +146,11 @@
% the instance rules or superclass rules, building up proofs for
% redundant constraints
:- pred typecheck__reduce_context_by_rule_application(instance_table,
- superclass_table, list(class_constraint), list(tvar),
- tsubst, tvarset, tvarset,
+ superclass_table, list(class_constraint), tsubst, tvarset, tvarset,
map(class_constraint, constraint_proof),
map(class_constraint, constraint_proof),
list(class_constraint), list(class_constraint)).
-:- mode typecheck__reduce_context_by_rule_application(in, in, in, in, in,
+:- mode typecheck__reduce_context_by_rule_application(in, in, in, in,
in, out, in, out, in, out) is det.
%-----------------------------------------------------------------------------%
@@ -3949,7 +3948,7 @@
Constraints0 = constraints(UnprovenConstraints0, AssumedConstraints),
typecheck__reduce_context_by_rule_application(InstanceTable,
- SuperClassTable, AssumedConstraints, HeadTypeParams,
+ SuperClassTable, AssumedConstraints,
Bindings, Tvarset0, Tvarset, Proofs0, Proofs,
UnprovenConstraints0, UnprovenConstraints),
@@ -3964,7 +3963,7 @@
typecheck__reduce_context_by_rule_application(InstanceTable, SuperClassTable,
- AssumedConstraints, HeadTypeParams, Bindings, Tvarset0, Tvarset,
+ AssumedConstraints, Bindings, Tvarset0, Tvarset,
Proofs0, Proofs, Constraints0, Constraints) :-
apply_rec_subst_to_constraint_list(Bindings, Constraints0,
Constraints1),
@@ -3972,7 +3971,8 @@
Constraints2, Changed1),
apply_instance_rules(Constraints2, InstanceTable,
Tvarset0, Tvarset1, Proofs0, Proofs1, Constraints3, Changed2),
- apply_class_rules(Constraints3, AssumedConstraints, HeadTypeParams,
+ varset__vars(Tvarset1, Tvars),
+ apply_class_rules(Constraints3, AssumedConstraints, Tvars,
SuperClassTable, Tvarset0, Proofs1, Proofs2, Constraints4,
Changed3),
(
@@ -3984,7 +3984,7 @@
Proofs = Proofs2
;
typecheck__reduce_context_by_rule_application(InstanceTable,
- SuperClassTable, AssumedConstraints, HeadTypeParams,
+ SuperClassTable, AssumedConstraints,
Bindings, Tvarset1, Tvarset, Proofs2, Proofs,
Constraints4, Constraints)
).
Index: tests/hard_coded/typeclasses/Mmakefile
===================================================================
RCS file: /home/staff/zs/imp/tests/hard_coded/typeclasses/Mmakefile,v
retrieving revision 1.40
diff -u -t -r1.40 Mmakefile
--- tests/hard_coded/typeclasses/Mmakefile 2000/10/31 01:37:48 1.40
+++ tests/hard_coded/typeclasses/Mmakefile 2000/11/02 06:17:54
@@ -42,6 +42,7 @@
operator_classname \
record_syntax \
superclass_bug \
+ superclass_bug2 \
superclass_call \
test_default_func_mode \
tuple_instance \
New File: tests/hard_coded/typeclasses/superclass_bug2.exp
===================================================================
Hi.
New File: tests/hard_coded/typeclasses/superclass_bug2.m
===================================================================
% Uncaught exception:
% Software Error: map__lookup: key not found
% Key Type: prog_data:class_constraint
% Key Functor: constraint/2
% Value Type: hlds_data:constraint_proof
%
:- module superclass_bug2.
:- interface.
:- import_module io.
:- pred main(io__state::di, io__state::uo) is det.
:- implementation.
main -->
{ foobar(t1(1)) },
io__write_string("Hi.\n").
%------------------------------------------------------------------------------%
:- typeclass g(T) where [ ].
:- typeclass h(T) <= g(T) where [ ].
%------------------------------------------------------------------------------%
% Bottom level instance
:- instance g(int) where [ ].
%------------------------------------------------------------------------------%
:- type t1(S) ---> t1(S).
:- instance g(t1(S)) <= g(S) where [ ].
:- instance h(t1(S)) <= g(S) where [ ].
%------------------------------------------------------------------------------%
:- pred foobar(T) <= h(T).
:- mode foobar(in) is det.
foobar(_).
%------------------------------------------------------------------------------%
---------------------------------------------------------------------------
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