Check for cycles in the typeclass hierarchy.

Estimated hours taken: 3
Branches: main

Check for cycles in the typeclass hierarchy.  This fixes a long-standing
bug whereby the compiler could go into an infinite loop in the polymorphism
stage if cycles were present.

compiler/check_typeclass.m:
	Add a pass to check through all visible typeclass declarations and
	report when a cycle is found.

	The interface to this module has been made more general, to reflect
	the fact that it checks the superclass relation as well as instance
	declarations.

compiler/mercury_compile.m:
	Use the new interface to the check_typeclass module.

compiler/error_util.m:
	Add a new format_component for sym_name_and_arity.

BUGS:
	Remove the bug report from this file.

tests/invalid/Mmakefile:
test/invalid/cyclic_typeclass.err_exp:
	Enable the cyclic_typeclass test, since we now pass it, and add an
	expected output file.  Also add a couple of new tests.

test/invalid/cyclic_typeclass_2.m:
test/invalid/cyclic_typeclass_2.err_exp:
test/invalid/cyclic_typeclass_3.m:
test/invalid/cyclic_typeclass_3.err_exp:
	New test cases.
This commit is contained in:
Mark Brown
2005-01-19 05:53:07 +00:00
parent 59d2d4a573
commit 7234e16972
10 changed files with 214 additions and 20 deletions

15
BUGS
View File

@@ -152,18 +152,3 @@ test(Args0) :-
list__map_foldl(MakeIndex, Args0, _, 0, _).
-----------------------------------------------------------------------------
Date: Wed, 1 Dec 1999 22:52:57 +1100
Subject: compiler infinite loop for cyclic type classes
According to the language reference manual:
| Typeclass constraints on type class declarations gives rise to a
| superclass relation. This relation must be acyclic. That is, it is an
| error if a type class is its own (direct or indirect) superclass.
But if you try to compile modules containing cyclic typeclasses,
the compiler goes into an infinite loop and eventually gets a
stack overflow, rather than reporting a proper error message.
-----------------------------------------------------------------------------