[m-rev.] diff: fix typechecking bug (resend)

Mark Brown mark at csse.unimelb.edu.au
Wed Nov 22 12:17:54 AEDT 2006


This post from last night doesn't seem to have got through yet...

----- Forwarded message from Mark Brown <mark at cs.mu.oz.au> -----

Date: Tue, 21 Nov 2006 22:49:01 +1100
From: Mark Brown <mark at cs.mu.oz.au>
To: Mercury Reviews <mercury-reviews at cs.mu.oz.au>
Subject: diff: fix typechecking bug
User-Agent: Mutt/1.5.11

Estimated hours taken: 6
Branches: main, release

Fix a bug reported by Peter Ross.

compiler/typeclasses.m:
	When recovering after an unsatisfiable constraint, don't merely
	delete the existing unproven constraints.  Instead construct new
	hlds_constraints from scratch.  This ensures that the invariants
	on it are maintained.

tests/invalid/Mmakefile:
tests/invalid/unsatisfiable_constraint_bug.err_exp:
tests/invalid/unsatisfiable_constraint_bug.m:
	Regression test.

Index: compiler/typeclasses.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/typeclasses.m,v
retrieving revision 1.17
diff -u -r1.17 typeclasses.m
--- compiler/typeclasses.m	22 Oct 2006 09:14:27 -0000	1.17
+++ compiler/typeclasses.m	21 Nov 2006 10:17:28 -0000
@@ -126,10 +126,13 @@
         Spec = report_unsatisfiable_constraints(!.Info, TypeAssignSet0),
         typecheck_info_add_error(Spec, !Info),
         DeleteConstraints = (pred(TA0::in, TA::out) is det :-
+            % Make a new hlds_constraints structure for the type assign,
+            % with the same assumed constraints but all unproven constraints
+            % deleted.
             type_assign_get_typeclass_constraints(TA0, Constraints0),
-            Constraints = (Constraints0
-                ^ unproven := [])
-                ^ redundant := multi_map.init,
+            type_assign_get_typevarset(TA0, TVarSet),
+            make_hlds_constraints(ClassTable, TVarSet, [],
+                Constraints0 ^ assumed, Constraints),
             type_assign_set_typeclass_constraints(Constraints, TA0, TA)
         ),
         list.map(DeleteConstraints, OrigTypeAssignSet, NewTypeAssignSet),
Index: tests/invalid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/Mmakefile,v
retrieving revision 1.200
diff -u -r1.200 Mmakefile
--- tests/invalid/Mmakefile	29 Oct 2006 03:18:54 -0000	1.200
+++ tests/invalid/Mmakefile	21 Nov 2006 10:30:28 -0000
@@ -209,6 +209,7 @@
 	uniq_mutable \
 	uniq_neg \
 	unsatisfiable_constraint \
+	unsatisfiable_constraint_bug \
 	unsatisfiable_super \
 	user_eq_dummy \
 	uu_type \
Index: tests/invalid/unsatisfiable_constraint_bug.err_exp
===================================================================
RCS file: tests/invalid/unsatisfiable_constraint_bug.err_exp
diff -N tests/invalid/unsatisfiable_constraint_bug.err_exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/invalid/unsatisfiable_constraint_bug.err_exp	21 Nov 2006 10:32:16 -0000
@@ -0,0 +1,9 @@
+unsatisfiable_constraint_bug.m:023: In clause for predicate `test_stream'/5:
+unsatisfiable_constraint_bug.m:023:   unsatisfiable typeclass constraint:
+unsatisfiable_constraint_bug.m:023:   `stream.writer(S, float, B)'.
+unsatisfiable_constraint_bug.m:025: In clause for predicate `test_stream'/5:
+unsatisfiable_constraint_bug.m:025:   unsatisfiable typeclass constraint:
+unsatisfiable_constraint_bug.m:025:   `stream.reader(S, float, B, E)'.
+unsatisfiable_constraint_bug.m:026: In clause for predicate `test_stream'/5:
+unsatisfiable_constraint_bug.m:026:   unsatisfiable typeclass constraint:
+unsatisfiable_constraint_bug.m:026:   `stream.reader(S, float, State, E)'.
Index: tests/invalid/unsatisfiable_constraint_bug.m
===================================================================
RCS file: tests/invalid/unsatisfiable_constraint_bug.m
diff -N tests/invalid/unsatisfiable_constraint_bug.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/invalid/unsatisfiable_constraint_bug.m	21 Nov 2006 10:24:10 -0000
@@ -0,0 +1,33 @@
+% The code caused the compiler the abort, rather than report an error
+% for the unsatisfiable constraints.
+
+% Software Error: map.lookup: key not found
+% Key Type: term.var(parse_tree.prog_data.prog_var_type)
+% Key Value: var(6)
+% Value Type: parse_tree.prog_data.mer_type
+
+:- module unsatisfiable_constraint_bug.
+:- interface.
+:- import_module io.
+:- import_module stream.
+
+:- pred test_stream(S::in, B::di, B::uo, io::di, io::uo) is det
+        <= (reader(S, int, B, E), writer(S, int, B)).
+            % XXX add these two lines and the program compiles
+            % reader(S, float, B, E), writer(S, float, B)).
+
+:- implementation.
+
+test_stream(S, !Buffer, !IO) :-
+	stream.put(S, 10, !Buffer),
+	stream.put(S, 3.14, !Buffer),
+	stream.get(S, ResultA : stream.result(int, E), !Buffer),
+	stream.get(S, ResultB : stream.result(float, E), !Buffer),
+	stream.get(S, ResultC : stream.result(float, E), !Buffer),
+	io.write(ResultA, !IO),
+	io.nl(!IO),
+	io.write(ResultB, !IO),
+	io.nl(!IO),
+	io.write(ResultC, !IO),
+	io.nl(!IO).
+

----- End forwarded message -----
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list