Files
mercury/tests/valid/superclass_bug.m
Mark Brown 01a0b8278f Implement superclass reduction in the style of CHRs rather than as a top
Estimated hours taken: 15
Branches: main, release

Implement superclass reduction in the style of CHRs rather than as a top
down search.  This is shorter, simpler, and more consistent with the rest
of the typeclass implementation.  It also removes a few XXXs and fixes a
bug reported by Julien.

compiler/hlds_data.m:
	Add an ancestors field to the hlds_constraint type.  This caches
	all the ancestors of assumed constraints, along with proofs (in the
	form of a sequence of subclass constraints) of how each ancestor is
	derived.

	Update this field whenever new assumed constraints are created, by
	traversing the class hierarchy bottom up.

	Delete the old subclass_details type, which was part of the
	superclass table.

compiler/typeclasses.m:
	Use the cached ancestors to apply the class rules, rather than
	performing a top down search.

compiler/type_util.m:
	Apply substitutions to the ancestors.

compiler/typecheck.m:
compiler/typecheck_info.m:
	Update to account for the additional field.

compiler/*.m:
	Remove the superclass table from the module_info and from the
	interface to context reduction; it is no longer needed.

compiler/hlds_out.m:
	Don't output the superclass table.

tests/valid/Mmakefile:
tests/valid/superclass_bug.m:
	Regression test for the bug that is now fixed.
2006-10-22 09:14:33 +00:00

39 lines
897 B
Mathematica

:- module superclass_bug.
:- interface.
:- type s ---> s.
:- type e ---> e.
:- type c ---> c.
:- typeclass my_stream(Stream, State) <= (Stream -> State) where
[
pred name(Stream::in, string::out, State::di, State::uo) is det
].
:- typeclass my_god(Stream, State, Error)
<= ( my_stream(Stream, State), (Stream -> Error) ) where [].
:- typeclass my_input(Stream, Unit, State, Error)
<= my_god(Stream, State, Error) where [].
:- type tab_expander(S).
:- instance my_stream(tab_expander(S), s)
<= my_input(S, c, s, e).
:- implementation.
:- type tab_expander(S)
---> tab_expander(int, S).
:- instance my_stream(tab_expander(S), s)
<= my_input(S, c, s, e) where
[
pred(name/4) is foo
].
:- pred foo(tab_expander(S)::in, string::out, s::di, s::uo) is det
<= my_input(S, c, s, e).
foo(tab_expander(_, Stream), Name, !S) :-
name(Stream, Name, !S).