[m-rev.] for review: type class constraint info in du functor descriptors

Zoltan Somogyi zs at cs.mu.OZ.AU
Tue Jan 27 09:03:37 AEDT 2004


For review by anyone.

Zoltan.

Augment the descriptors of du functors with information about the type class
constraints on their existentially typed arguments (if any). This is not yet
used, but will be needed to perform type class membership tests (as we
discussed on wednesday). We will need to bump the binary compatibility version
number when we start relying on the newly generated data.

Turn on the generation of the new type class descriptor data structures, since
we now need them to describe functors with type class constraints.

This in turn required making the generation of those data structures work
for the MLDS backends as well as the LLDS backend. (The original diff that
added those data structures updated only the LLDS backend.)

compiler/mercury_compile.m:
	Always generate descriptors for type class declarations in both LLDS
	and MLDS backends. Generate descriptors for type class instances
	(which are not referred to from functor descriptors) only if
	--new-type-class-rtti is given.

compiler/rtti.m:
	Instead of recording just the number of constraints on existentially
	typed arguments of functors, record the constraints themselves.

	Add new rtti_ids to describe (arrays of) constraints in DuExistInfos.

	Add predicates to look up the types of not just the data structures
	denoted by rtti_ids, but also their element types if they are arrays.
	This is needed because functor desciptors may now contain arrays of
	MR_TypeClassConstraints, even though we generate no data structure
	of that type; we generate structures of type MR_TypeClassConstraintN
	for various values of N, and cast them to MR_TypeClassConstraint.

	Factor out some common code.

compiler/rtti_out.m:
	Implement the new field of DuExistInfos, and comment out the code
	needed to generate type class instances' method descriptors.

	Comment out the code for generating method addresses. (See the comment
	on mercury_typeclass_info.h below.)

	Fix a misleading variable name.

compiler/rtti_to_mlds.m:
	Replace "not yet implemented" aborts when translating the new style
	type class decl and instance structures with actual translation code.

	Implement the new field of DuExistInfos.

	Factor out common code for making arrays of pseudo-typeinfos.

compiler/mlds_to_gcc.m:
	Factor out the code for turning the type of an rtti data structure
	into the type of an array of them, to allow the latter step not to be
	done if we are want the type of the array elements.

	Add code for defining the types of type class declaration and instance
	descriptors.

	Implement the new field of DuExistInfos.

compiler/type_ctor_info.m:
	Instead of recording just the number of constraints on existentially
	typed arguments of functors, record the constraints themselves.

compiler/type_class_info.m:
	Generate instance descriptors only if requested.

	Export a function now needed by type_ctor_info.m.

compiler/mlds.m:
	Allow mlds__rtti_type to refer to the types of elements of the arrays
	we generate, even if there is no rtti_id that has that type.

compiler/mlds_to_c.m:
	Module qualify type class declaration and instance descriptors, at
	least for now; it is only base_typeclass_infos for which we need to
	detect duplicate definitions in different modules.

	Modify the types of du functor descriptors to include type class
	constraint information.

compiler/ml_closure_gen.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_java.m:
compiler/opt_debug.m:
	Trivial changes to conform to the changes above.

runtime/mercury_type_info.h:
	Add a field giving a list of type class constraints to MR_DuExistInfo.

	Move the definitions of the types describing type class constraints
	here from mercury_typeclass_info.h, since MR_DuExistInfo now refers
	to it. mercury_type_info.h cannot include mercury_typeclass_info.h
	without causing a circularity problem.

runtime/mercury_types.h:
	Move a bunch of typedefs of structs here from mercury_typeclass_info.h,
	again to avoid circularity problems.

runtime/mercury_typeclass_info.h:
	Remove the stuff moved to mercury_type_info.h and mercury_types.h.

	For now, do not include the code addresses of the procedure's
	representing an instance's methods in the instance structure,
	since the MLDS backend doesn't really have a notion of a generic code
	address, and even if it did it doesn't have an equivalent of the LLDS
	backend's code address to proc layout structure mapping, so the code
	addresses by themselves would be useless. (The code addresses needed
	for method calls are stored in the base_typeclass_info, not the
	instance structure.)

	When we want to start using information about instance methods
	in ways beyond what is afforded by the dictionary in the
	base_typeclass_info, we will need to revisit this decision, and will
	probably have to include the necessary information about the instance
	methods in the instance's data structure directly instead of via a
	pointer to the instance method implementations themselves.

runtime/mercury_type_info.h:
runtime/mercury_tags.h:
	Move a macro used to define enum constants that compiler generated code
	can refer to from mercury_type_info.h to mercury_tags.h (which already
	contains a similar macro whose definition is also dependent on
	--reserve-tag), since it is now also needed in mercury_proc_id.h.

runtime/mercury_proc_id.h:
	Use that macro define MR_PREDICATE and MR_FUNCTION, since the compiler
	now generates references to them.

cvs diff: Diffing .
cvs diff: Diffing analysis
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/doc
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.299
diff -u -b -r1.299 mercury_compile.m
--- compiler/mercury_compile.m	1 Jan 2004 05:57:09 -0000	1.299
+++ compiler/mercury_compile.m	23 Jan 2004 01:07:48 -0000
@@ -3630,15 +3630,10 @@
 	{ type_ctor_info__generate_rtti(HLDS, TypeCtorRttiData) },
 	{ base_typeclass_info__generate_rtti(HLDS, OldTypeClassInfoRttiData) },
 	globals__io_lookup_bool_option(new_type_class_rtti, NewTypeClassRtti),
-	{
-		NewTypeClassRtti = no,
-		TypeClassInfoRttiData = OldTypeClassInfoRttiData
-	;
-		NewTypeClassRtti = yes,
-		type_class_info__generate_rtti(HLDS, NewTypeClassInfoRttiData),
-		list__append(OldTypeClassInfoRttiData, NewTypeClassInfoRttiData,
-			TypeClassInfoRttiData)
-	},
+	{ type_class_info__generate_rtti(HLDS, NewTypeClassRtti,
+		NewTypeClassInfoRttiData) },
+	{ list__append(OldTypeClassInfoRttiData, NewTypeClassInfoRttiData,
+		TypeClassInfoRttiData) },
 	{ list__map(llds__wrap_rtti_data, TypeCtorRttiData, TypeCtorTables) },
 	{ list__map(llds__wrap_rtti_data, TypeClassInfoRttiData,
 		TypeClassInfos) },
@@ -4006,7 +4001,13 @@
 mercury_compile__mlds_gen_rtti_data(HLDS, MLDS0, MLDS) :-
 	type_ctor_info__generate_rtti(HLDS, TypeCtorRtti),
 	base_typeclass_info__generate_rtti(HLDS, TypeClassInfoRtti),
-	list__append(TypeCtorRtti, TypeClassInfoRtti, RttiData),
+	module_info_globals(HLDS, Globals),
+	globals__lookup_bool_option(Globals, new_type_class_rtti,
+		NewTypeClassRtti),
+	type_class_info__generate_rtti(HLDS, NewTypeClassRtti,
+		NewTypeClassInfoRttiData),
+	list__condense([TypeCtorRtti, TypeClassInfoRtti,
+		NewTypeClassInfoRttiData], RttiData),
 	RttiDefns = rtti_data_list_to_mlds(HLDS, RttiData),
 	MLDS0 = mlds(ModuleName, ForeignCode, Imports, Defns0),
 	list__append(RttiDefns, Defns0, Defns),
Index: compiler/ml_closure_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_closure_gen.m,v
retrieving revision 1.23
diff -u -b -r1.23 ml_closure_gen.m
--- compiler/ml_closure_gen.m	1 Dec 2003 22:31:35 -0000	1.23
+++ compiler/ml_closure_gen.m	23 Jan 2004 19:32:41 -0000
@@ -391,7 +391,7 @@
 		MLDS_ModuleName = mercury_module_name_to_mlds(ModuleName),
 		Rval = const(data_addr_const(data_addr(MLDS_ModuleName,
 			rtti(RttiId)))),
-		Type = mlds__rtti_type(RttiId)
+		Type = mlds__rtti_type(item_type(RttiId))
 	).
 
 :- pred ml_gen_type_info(module_info::in, rtti_type_info::in,
@@ -430,7 +430,7 @@
 	MLDS_ModuleName = mercury_module_name_to_mlds(ModuleName),
 	Rval = const(data_addr_const(data_addr(MLDS_ModuleName,
 		rtti(RttiId)))),
-	Type = mlds__rtti_type(RttiId).
+	Type = mlds__rtti_type(item_type(RttiId)).
 
 :- func arg_maybe_pseudo_type_infos(rtti_pseudo_type_info)
 	= list(rtti_maybe_pseudo_type_info).
Index: compiler/ml_util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_util.m,v
retrieving revision 1.28
diff -u -b -r1.28 ml_util.m
--- compiler/ml_util.m	1 Dec 2003 06:53:28 -0000	1.28
+++ compiler/ml_util.m	23 Jan 2004 19:32:41 -0000
@@ -500,7 +500,7 @@
 defn_is_type_ctor_info(Defn) :-
 	Defn = mlds__defn(_Name, _Context, _Flags, Body),
 	Body = mlds__data(Type, _, _),
-	Type = mlds__rtti_type(RttiId),
+	Type = mlds__rtti_type(item_type(RttiId)),
 	RttiId = ctor_rtti_id(_, RttiName),
 	RttiName = type_ctor_info.
 
Index: compiler/mlds.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mlds.m,v
retrieving revision 1.107
diff -u -b -r1.107 mlds.m
--- compiler/mlds.m	5 Dec 2003 04:19:30 -0000	1.107
+++ compiler/mlds.m	23 Jan 2004 19:32:41 -0000
@@ -744,7 +744,7 @@
 
 	;	mlds__pseudo_type_info_type
 
-	;	mlds__rtti_type(rtti_id)
+	;	mlds__rtti_type(rtti_id_maybe_element)
 
 		% A type used by the ML code generator for references 
 		% to variables that have yet to be declared.  This occurs 
Index: compiler/mlds_to_c.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.157
diff -u -b -r1.157 mlds_to_c.m
--- compiler/mlds_to_c.m	26 Jan 2004 21:15:47 -0000	1.157
+++ compiler/mlds_to_c.m	26 Jan 2004 21:28:25 -0000
@@ -1673,7 +1673,8 @@
 			% instance decls, even if they are in a different
 			% module
 			%
-			Name = data(rtti(tc_rtti_id(_)))
+			Name = data(rtti(tc_rtti_id(
+				base_typeclass_info(_, _, _))))
 		;
 			% We don't module qualify pragma export names.
 			Name = export(_)
@@ -1903,8 +1904,8 @@
 	;
 		io__write_string("jmp_buf", !IO)
 	).
-mlds_output_type_prefix(mlds__rtti_type(RttiId), !IO) :-
-	rtti_id_c_type(RttiId, CType, _IsArray),
+mlds_output_type_prefix(mlds__rtti_type(RttiIdMaybeElement), !IO) :-
+	rtti_id_maybe_element_c_type(RttiIdMaybeElement, CType, _IsArray),
 	io__write_string(CType, !IO).
 mlds_output_type_prefix(mlds__unknown_type, !IO) :-
 	error("mlds_to_c.m: prefix has unknown type").
@@ -2058,8 +2059,8 @@
 		io__write_string(")", !IO)
 	).
 mlds_output_type_suffix(mlds__commit_type, _, !IO).
-mlds_output_type_suffix(mlds__rtti_type(RttiId), ArraySize, !IO) :-
-	( rtti_id_has_array_type(RttiId) = yes ->
+mlds_output_type_suffix(mlds__rtti_type(RttiIdMaybeElement), ArraySize, !IO) :-
+	( rtti_id_maybe_element_has_array_type(RttiIdMaybeElement) = yes ->
 		mlds_output_array_type_suffix(ArraySize, !IO)
 	;
 		true
Index: compiler/mlds_to_gcc.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mlds_to_gcc.m,v
retrieving revision 1.90
diff -u -b -r1.90 mlds_to_gcc.m
--- compiler/mlds_to_gcc.m	1 Dec 2003 06:53:28 -0000	1.90
+++ compiler/mlds_to_gcc.m	23 Jan 2004 21:28:14 -0000
@@ -1832,9 +1832,9 @@
 	gcc__build_function_type(gcc__void_type_node, GCC_ParamTypes, FuncType),
 	gcc__build_pointer_type(FuncType, GCC_Type).
 build_type(mlds__commit_type, _, _, gcc__jmpbuf_type_node) --> [].
-build_type(mlds__rtti_type(RttiName), InitializerSize, _GlobalInfo,
+build_type(mlds__rtti_type(RttiIdMaybeElement), InitializerSize, _GlobalInfo,
 		GCC_Type) -->
-	build_rtti_type(RttiName, InitializerSize, GCC_Type).
+	build_rtti_type(RttiIdMaybeElement, InitializerSize, GCC_Type).
 build_type(mlds__unknown_type, _, _, _) -->
 	{ unexpected(this_file, "build_type: unknown type") }.
 
@@ -1958,34 +1958,57 @@
 % XXX it would be more efficient to construct these types once,
 % at initialization time, rather than every time they are used.
 
-:- pred build_rtti_type(rtti_id::in, initializer_array_size::in,
+:- pred build_rtti_type(rtti_id_maybe_element::in, initializer_array_size::in,
 	gcc__type::out, io__state::di, io__state::uo) is det.
 
-build_rtti_type(ctor_rtti_id(_, RttiName), Size, GCC_Type) -->
-	build_rtti_type_name(RttiName, Size, GCC_Type).
-build_rtti_type(tc_rtti_id(TCRttiName), Size, GCC_Type) -->
-	build_rtti_type_tc_name(TCRttiName, Size, GCC_Type).
+build_rtti_type(RttiIdMaybeElement, Size, GCC_Type, !IO) :-
+	(
+		RttiIdMaybeElement = item_type(RttiId)
+	;
+		RttiIdMaybeElement = element_type(RttiId)
+	),
+	(
+		RttiId = ctor_rtti_id(_, RttiName), 
+		build_rtti_type_name(RttiName, BaseType, !IO)
+	;
+		RttiId = tc_rtti_id(TCRttiName),
+		build_rtti_type_tc_name(TCRttiName, BaseType, !IO)
+	),
+	IsArray = rtti_id_has_array_type(RttiId),
+	(
+		RttiIdMaybeElement = item_type(_),
+		(
+			IsArray = no,
+			GCC_Type = BaseType
+		;
+			IsArray = yes,
+			build_sized_array_type(BaseType, Size, GCC_Type, !IO)
+		)
+	;
+		RttiIdMaybeElement = element_type(_),
+		require(unify(IsArray, yes),
+			"build_rtti_type: element of non-array"),
+		GCC_Type = BaseType
+	).
 
-:- pred build_rtti_type_name(ctor_rtti_name::in, initializer_array_size::in,
-	gcc__type::out, io__state::di, io__state::uo) is det.
+:- pred build_rtti_type_name(ctor_rtti_name::in, gcc__type::out,
+	io__state::di, io__state::uo) is det.
 
-build_rtti_type_name(exist_locns(_), Size, GCC_Type) -->
-	build_du_exist_locn_type(MR_DuExistLocn),
-	build_sized_array_type(MR_DuExistLocn, Size, GCC_Type).
-build_rtti_type_name(exist_locn, _, GCC_Type) -->
-	build_du_exist_locn_type(GCC_Type).
-build_rtti_type_name(exist_info(_), _, MR_DuExistInfo) -->
-	build_du_exist_info_type(MR_DuExistInfo).
-build_rtti_type_name(field_names(_), Size, GCC_Type) -->
-	build_sized_array_type('MR_ConstString', Size, GCC_Type).
-build_rtti_type_name(field_types(_), Size, GCC_Type) -->
-	build_sized_array_type('MR_PseudoTypeInfo', Size, GCC_Type).
-build_rtti_type_name(res_addrs, Size, GCC_Type) -->
-	build_sized_array_type(gcc__ptr_type_node, Size, GCC_Type).
-build_rtti_type_name(res_addr_functors, Size, GCC_Type) -->
-	{ MR_ReservedAddrFunctorDescPtr = gcc__ptr_type_node },
-	build_sized_array_type(MR_ReservedAddrFunctorDescPtr, Size, GCC_Type).
-build_rtti_type_name(enum_functor_desc(_), _, GCC_Type) -->
+build_rtti_type_name(exist_locns(_), GCC_Type, !IO) :-
+	build_du_exist_locn_type(GCC_Type, !IO).
+build_rtti_type_name(exist_locn, GCC_Type, !IO) :-
+	build_du_exist_locn_type(GCC_Type, !IO).
+build_rtti_type_name(exist_tc_constr(_, _, N), GCC_Type, !IO) :-
+	build_tc_constr_struct_type(N, GCC_Type, !IO).
+build_rtti_type_name(exist_tc_constrs(_), GCC_Type, !IO) :-
+	build_tc_constr_type(GCC_Type, !IO).
+build_rtti_type_name(exist_info(_), GCC_Type, !IO) :-
+	build_du_exist_info_type(GCC_Type, !IO).
+build_rtti_type_name(field_names(_), 'MR_ConstString', !IO).
+build_rtti_type_name(field_types(_), 'MR_PseudoTypeInfo', !IO).
+build_rtti_type_name(res_addrs, gcc__ptr_type_node, !IO).
+build_rtti_type_name(res_addr_functors, gcc__ptr_type_node, !IO).
+build_rtti_type_name(enum_functor_desc(_), GCC_Type, !IO) :-
 	% typedef struct {
 	%     MR_ConstString      MR_enum_functor_name;
 	%     MR_int_least32_t    MR_enum_functor_ordinal;
@@ -1993,8 +2016,8 @@
 	build_struct_type("MR_EnumFunctorDesc",
 		['MR_ConstString'	- "MR_enum_functor_name",
 		 'MR_int_least32_t'	- "MR_enum_functor_ordinal"],
-		GCC_Type).
-build_rtti_type_name(notag_functor_desc, _, GCC_Type) -->
+		GCC_Type, !IO).
+build_rtti_type_name(notag_functor_desc, GCC_Type, !IO) :-
 	% typedef struct {
 	%     MR_ConstString      MR_notag_functor_name;
 	%     MR_PseudoTypeInfo   MR_notag_functor_arg_type;
@@ -2004,8 +2027,8 @@
 		['MR_ConstString'	- "MR_notag_functor_name",
 		 'MR_PseudoTypeInfo'	- "MR_notag_functor_arg_type",
 		 'MR_ConstString'	- "MR_notag_functor_arg_name"],
-		GCC_Type).
-build_rtti_type_name(du_functor_desc(_), _, GCC_Type) -->
+		GCC_Type, !IO).
+build_rtti_type_name(du_functor_desc(_), GCC_Type, !IO) :-
 	% typedef struct {
 	%     MR_ConstString          MR_du_functor_name;
 	%     MR_int_least16_t        MR_du_functor_orig_arity;
@@ -2018,10 +2041,10 @@
 	%     const MR_ConstString    *MR_du_functor_arg_names;
 	%     const MR_DuExistInfo    *MR_du_functor_exist_info;
 	% } MR_DuFunctorDesc;
-	build_du_exist_info_type(MR_DuExistInfo),
-	gcc__build_pointer_type('MR_PseudoTypeInfo', MR_PseudoTypeInfoPtr),
-	gcc__build_pointer_type(MR_DuExistInfo, MR_DuExistInfoPtr),
-	gcc__build_pointer_type('MR_ConstString', MR_ConstStringPtr),
+	build_du_exist_info_type(MR_DuExistInfo, !IO),
+	gcc__build_pointer_type('MR_PseudoTypeInfo', MR_PseudoTypeInfoPtr, !IO),
+	gcc__build_pointer_type(MR_DuExistInfo, MR_DuExistInfoPtr, !IO),
+	gcc__build_pointer_type('MR_ConstString', MR_ConstStringPtr, !IO),
 	build_struct_type("MR_DuFunctorDesc",
 		['MR_ConstString'	- "MR_du_functor_name",
 		 'MR_int_least16_t'	- "MR_du_functor_orig_arity",
@@ -2033,8 +2056,8 @@
 		 MR_PseudoTypeInfoPtr	- "MR_du_functor_arg_types",
 		 MR_ConstStringPtr	- "MR_du_functor_arg_names",
 		 MR_DuExistInfoPtr	- "MR_du_functor_exist_info"],
-		GCC_Type).
-build_rtti_type_name(res_functor_desc(_), _, GCC_Type) -->
+		GCC_Type, !IO).
+build_rtti_type_name(res_functor_desc(_), GCC_Type, !IO) :-
 	% typedef struct {
 	%     MR_ConstString      MR_ra_functor_name;
 	%     MR_int_least32_t    MR_ra_functor_ordinal;
@@ -2044,23 +2067,14 @@
 		['MR_ConstString'	- "MR_ra_functor_name",
 		 'MR_int_least32_t'	- "MR_ra_functor_ordinal",
 		 gcc__ptr_type_node	- "MR_ra_functor_reserved_addr"],
-		GCC_Type).
-build_rtti_type_name(enum_name_ordered_table, Size, GCC_Type) -->
-	{ MR_EnumFunctorDescPtr = gcc__ptr_type_node },
-	build_sized_array_type(MR_EnumFunctorDescPtr, Size, GCC_Type).
-build_rtti_type_name(enum_value_ordered_table, Size, GCC_Type) -->
-	{ MR_EnumFunctorDescPtr = gcc__ptr_type_node },
-	build_sized_array_type(MR_EnumFunctorDescPtr, Size, GCC_Type).
-build_rtti_type_name(du_name_ordered_table, Size, GCC_Type) -->
-	{ MR_DuFunctorDescPtr = gcc__ptr_type_node },
-	build_sized_array_type(MR_DuFunctorDescPtr, Size, GCC_Type).
-build_rtti_type_name(du_stag_ordered_table(_), Size, GCC_Type) -->
-	{ MR_DuFunctorDescPtr = gcc__ptr_type_node },
-	build_sized_array_type(MR_DuFunctorDescPtr, Size, GCC_Type).
-build_rtti_type_name(du_ptag_ordered_table, Size, GCC_Type) -->
-	build_rtti_type_name(du_ptag_layout(0), Size, MR_DuPtagLayout),
-	build_sized_array_type(MR_DuPtagLayout, Size, GCC_Type).
-build_rtti_type_name(du_ptag_layout(_), _, GCC_Type) -->
+		GCC_Type, !IO).
+build_rtti_type_name(enum_name_ordered_table, gcc__ptr_type_node, !IO).
+build_rtti_type_name(enum_value_ordered_table, gcc__ptr_type_node, !IO).
+build_rtti_type_name(du_name_ordered_table, gcc__ptr_type_node, !IO).
+build_rtti_type_name(du_stag_ordered_table(_), gcc__ptr_type_node, !IO).
+build_rtti_type_name(du_ptag_ordered_table, GCC_Type, !IO) :-
+	build_rtti_type_name(du_ptag_layout(0), GCC_Type, !IO).
+build_rtti_type_name(du_ptag_layout(_), GCC_Type, !IO) :-
 	% typedef struct {
 	%     MR_int_least32_t        MR_sectag_sharers;
 	%     MR_Sectag_Locn          MR_sectag_locn;
@@ -2070,8 +2084,8 @@
 		['MR_int_least32_t'	- "MR_sectag_sharers",
 		 'MR_Sectag_Locn'	- "MR_sectag_locn",
 		 gcc__ptr_type_node	- "MR_sectag_alternatives"],
-		GCC_Type).
-build_rtti_type_name(res_value_ordered_table, _, GCC_Type) -->
+		GCC_Type, !IO).
+build_rtti_type_name(res_value_ordered_table, GCC_Type, !IO) :-
 	% typedef struct {
 	%     MR_int_least16_t    MR_ra_num_res_numeric_addrs;
 	%     MR_int_least16_t    MR_ra_num_res_symbolic_addrs;
@@ -2085,12 +2099,10 @@
 		 gcc__ptr_type_node	- "MR_ra_res_symbolic_addrs",
 		 gcc__ptr_type_node	- "MR_ra_constants",
 		 gcc__ptr_type_node	- "MR_ra_other_functors"
-		], GCC_Type).
-build_rtti_type_name(res_name_ordered_table, Size, GCC_Type) -->
-	build_rtti_type_name(maybe_res_addr_functor_desc, Size,
-		MR_MaybeResAddrFunctorDesc),
-	build_sized_array_type(MR_MaybeResAddrFunctorDesc, Size, GCC_Type).
-build_rtti_type_name(maybe_res_addr_functor_desc, _, GCC_Type) -->
+		], GCC_Type, !IO).
+build_rtti_type_name(res_name_ordered_table, GCC_Type, !IO) :-
+	build_rtti_type_name(maybe_res_addr_functor_desc, GCC_Type, !IO).
+build_rtti_type_name(maybe_res_addr_functor_desc, GCC_Type, !IO) :-
 	% typedef union {
     	%	MR_DuFunctorDesc            *MR_maybe_res_du_ptr;
     	%	MR_ReservedAddrFunctorDesc  *MR_maybe_res_res_ptr;
@@ -2104,22 +2116,22 @@
 	% } MR_MaybeResAddrFunctorDesc;
 	build_struct_type("MR_MaybeResFunctorDesc",
 		[gcc__ptr_type_node	- "MR_maybe_res_init"],
-		MR_MaybeResFunctorDescPtr),
+		MR_MaybeResFunctorDescPtr, !IO),
 	build_struct_type("MR_MaybeResAddrFunctorDesc",
 		['MR_ConstString'	- "MR_maybe_res_name",
 		 'MR_Integer'		- "MR_maybe_res_arity",
 		 'MR_bool'		- "MR_maybe_res_is_res",
 		 MR_MaybeResFunctorDescPtr	- "MR_maybe_res_ptr"
-		], GCC_Type).
-build_rtti_type_name(type_functors, _, GCC_Type) -->
+		], GCC_Type, !IO).
+build_rtti_type_name(type_functors, GCC_Type, !IO) :-
 	build_struct_type("MR_TypeFunctors",
 		[gcc__ptr_type_node	- "MR_functors_init"],
-		GCC_Type).
-build_rtti_type_name(type_layout, _, GCC_Type) -->
+		GCC_Type, !IO).
+build_rtti_type_name(type_layout, GCC_Type, !IO) :-
 	build_struct_type("MR_TypeLayout",
 		[gcc__ptr_type_node	- "MR_layout_init"],
-		GCC_Type).
-build_rtti_type_name(type_ctor_info, Size, GCC_Type) -->
+		GCC_Type, !IO).
+build_rtti_type_name(type_ctor_info, GCC_Type, !IO) :-
 	% MR_Integer          MR_type_ctor_arity;
 	% MR_int_least8_t     MR_type_ctor_version;
 	% MR_int_least8_t     MR_type_ctor_num_ptags;         /* if DU */
@@ -2132,9 +2144,9 @@
 	% MR_TypeLayout       MR_type_ctor_layout;
 	% MR_int_least32_t    MR_type_ctor_num_functors;
 	% MR_int_least16_t    MR_type_ctor_flags;
-	{ MR_ProcAddr = gcc__ptr_type_node },
-	build_rtti_type_name(type_functors, Size, MR_TypeFunctors),
-	build_rtti_type_name(type_layout, Size, MR_TypeLayout),
+	MR_ProcAddr = gcc__ptr_type_node,
+	build_rtti_type_name(type_functors, MR_TypeFunctors, !IO),
+	build_rtti_type_name(type_layout, MR_TypeLayout, !IO),
 	build_struct_type("MR_TypeCtorInfo_Struct",
 		['MR_Integer'		- "MR_type_ctor_arity",
 		 'MR_int_least8_t'	- "MR_type_ctor_version",
@@ -2149,66 +2161,50 @@
 		 MR_TypeLayout		- "MR_type_ctor_layout",
 		 'MR_int_least32_t'	- "MR_type_ctor_num_functors",
 		 'MR_int_least16_t'	- "MR_type_ctor_flags"],
-		GCC_Type).
-build_rtti_type_name(type_info(TypeInfo), _, GCC_Type) -->
-	build_type_info_type(TypeInfo, GCC_Type).
-build_rtti_type_name(pseudo_type_info(PseudoTypeInfo), _, GCC_Type) -->
-	build_pseudo_type_info_type(PseudoTypeInfo, GCC_Type).
-build_rtti_type_name(type_hashcons_pointer, _, MR_TableNodePtrPtr) -->
-	{ MR_TableNodePtrPtr = gcc__ptr_type_node }.
+		GCC_Type, !IO).
+build_rtti_type_name(type_info(TypeInfo), GCC_Type, !IO) :-
+	build_type_info_type(TypeInfo, GCC_Type, !IO).
+build_rtti_type_name(pseudo_type_info(PseudoTypeInfo), GCC_Type, !IO) :-
+	build_pseudo_type_info_type(PseudoTypeInfo, GCC_Type, !IO).
+build_rtti_type_name(type_hashcons_pointer, gcc__ptr_type_node, !IO).
 
-:- pred build_rtti_type_tc_name(tc_rtti_name::in, initializer_array_size::in,
-	gcc__type::out, io__state::di, io__state::uo) is det.
+:- pred build_rtti_type_tc_name(tc_rtti_name::in, gcc__type::out,
+	io__state::di, io__state::uo) is det.
 
-build_rtti_type_tc_name(base_typeclass_info(_, _, _), Size, GCC_Type) -->
-	{ MR_BaseTypeclassInfo = gcc__ptr_type_node },
-	build_sized_array_type(MR_BaseTypeclassInfo, Size, GCC_Type).
-build_rtti_type_tc_name(type_class_id(_), _Size, _GCC_Type) -->
-	{ sorry(this_file,
-		"build_rtti_type_tc_name: type_class_id") }.
-build_rtti_type_tc_name(type_class_decl(_), _Size, _GCC_Type) -->
-	{ sorry(this_file,
-		"build_rtti_type_tc_name: type_class_decl") }.
-build_rtti_type_tc_name(type_class_decl_super(_, _, _), _Size, _GCC_Type) -->
-	{ sorry(this_file,
-		"build_rtti_type_tc_name: type_class_decl_super") }.
-build_rtti_type_tc_name(type_class_decl_supers(_), _Size, _GCC_Type) -->
-	{ sorry(this_file,
-		"build_rtti_type_tc_name: type_class_decl_supers") }.
-build_rtti_type_tc_name(type_class_id_var_names(_), _Size, _GCC_Type) -->
-	{ sorry(this_file,
-		"build_rtti_type_tc_name: type_class_id_var_names") }.
-build_rtti_type_tc_name(type_class_id_method_ids(_), _Size, _GCC_Type) -->
-	{ sorry(this_file,
-		"build_rtti_type_tc_name: type_class_id_method_ids") }.
-build_rtti_type_tc_name(type_class_instance(_, _), _Size, _GCC_Type) -->
-	{ sorry(this_file,
-		"build_rtti_type_tc_name: type_class_instance") }.
-build_rtti_type_tc_name(type_class_instance_tc_type_vector(_, _), _Size,
-		_GCC_Type) -->
-	{ sorry(this_file,
-		"build_rtti_type_tc_name: " ++
-		"type_class_instance_tc_type_vector") }.
-build_rtti_type_tc_name(type_class_instance_constraint(_, _, _, _), _Size,
-		_GCC_Type) -->
-	{ sorry(this_file,
-		"build_rtti_type_tc_name: " ++
-		"type_class_instance_constraint") }.
-build_rtti_type_tc_name(type_class_instance_constraints(_, _), _Size,
-		_GCC_Type) -->
-	{ sorry(this_file,
-		"build_rtti_type_tc_name: " ++
-		"type_class_instance_constraints") }.
-build_rtti_type_tc_name(type_class_instance_methods(_, _), _Size,
-		_GCC_Type) -->
-	{ sorry(this_file,
-		"build_rtti_type_tc_name: type_class_instance_methods") }.
+build_rtti_type_tc_name(base_typeclass_info(_, _, _), gcc__ptr_type_node, !IO).
+build_rtti_type_tc_name(type_class_id(_), GCC_Type, !IO) :-
+	build_tc_id_type(GCC_Type, !IO).
+build_rtti_type_tc_name(type_class_id_var_names(_), 'MR_ConstString', !IO).
+build_rtti_type_tc_name(type_class_id_method_ids(_), GCC_Type, !IO) :-
+	build_tc_id_method_type(GCC_Type, !IO).
+build_rtti_type_tc_name(type_class_decl(_), GCC_Type, !IO) :-
+	build_tc_decl_type(GCC_Type, !IO).
+build_rtti_type_tc_name(type_class_decl_super(_, _, N), GCC_Type, !IO) :-
+	build_tc_constr_struct_type(N, GCC_Type, !IO).
+build_rtti_type_tc_name(type_class_decl_supers(_), GCC_Type, !IO) :-
+	build_tc_constr_type(StructType, !IO),
+	gcc__build_pointer_type(StructType, GCC_Type, !IO).
+build_rtti_type_tc_name(type_class_instance(_, _), GCC_Type, !IO) :-
+	build_tc_instance_type(GCC_Type, !IO).
+build_rtti_type_tc_name(type_class_instance_tc_type_vector(_, _),
+		'MR_PseudoTypeInfo', !IO).
+build_rtti_type_tc_name(type_class_instance_constraint(_, _, _, N),
+		GCC_Type, !IO) :-
+	build_tc_constr_struct_type(N, GCC_Type, !IO).
+build_rtti_type_tc_name(type_class_instance_constraints(_, _),
+		GCC_Type, !IO) :-
+	build_tc_constr_type(StructType, !IO),
+	gcc__build_pointer_type(StructType, GCC_Type, !IO).
+build_rtti_type_tc_name(type_class_instance_methods(_, _),
+		_GCC_Type, !IO) :-
+	sorry(this_file,
+		"build_rtti_type_tc_name: type_class_instance_methods").
 
 :- pred build_type_info_type(rtti_type_info::in,
 	gcc__type::out, io__state::di, io__state::uo) is det.
 
 build_type_info_type(plain_arity_zero_type_info(_), GCC_Type) -->
-	build_rtti_type_name(type_ctor_info, no_size, GCC_Type).
+	build_rtti_type_name(type_ctor_info, GCC_Type).
 build_type_info_type(plain_type_info(_TypeCtor, ArgTypes),
 		GCC_Type) -->
 	{ Arity = list__length(ArgTypes) },
@@ -2250,7 +2246,7 @@
 	% rather than pointers, so there is no pointed-to type
 	{ error("mlds_rtti_type: type_var") }.
 build_pseudo_type_info_type(plain_arity_zero_pseudo_type_info(_), GCC_Type) -->
-	build_rtti_type_name(type_ctor_info, no_size, GCC_Type).
+	build_rtti_type_name(type_ctor_info, GCC_Type).
 build_pseudo_type_info_type(plain_pseudo_type_info(_TypeCtor, ArgTypes),
 		GCC_Type) -->
 	{ Arity = list__length(ArgTypes) },
@@ -2287,6 +2283,122 @@
 		 		"MR_pti_var_arity_arg_pseudo_typeinfos"],
 		GCC_Type).
 
+:- pred build_tc_constr_struct_type(int::in, gcc__type::out,
+	io__state::di, io__state::uo) is det.
+
+build_tc_constr_struct_type(N, MR_TypeClassConstraint_NStruct) -->
+	% typedef struct MR_TypeClassConstraint_NStruct{
+	%    MR_TypeClassDecl    MR_tc_constr_type_class;
+	%    MR_PseudoTypeInfo   MR_tc_constr_arg_ptis[Arity];
+	% } MR_TypeClassConstraint_N;
+	gcc__build_array_type('MR_PseudoTypeInfo', N, MR_PseudoTypeInfoArray),
+	build_tc_decl_type(MR_TypeClassDecl),
+	gcc__build_pointer_type(MR_TypeClassDecl, MR_TypeClassDeclPtr),
+	{ StructName = string__format("MR_TypeClassConstraint_%dStruct",
+		[i(N)]) },
+	build_struct_type(StructName,
+		[MR_TypeClassDeclPtr	- "MR_tc_constr_type_class",
+		 MR_PseudoTypeInfoArray	- "MR_tc_constr_arg_ptis"],
+		MR_TypeClassConstraint_NStruct).
+
+:- pred build_tc_constr_type(gcc__type::out, io__state::di, io__state::uo)
+	is det.
+
+build_tc_constr_type(MR_TypeClassConstraint) -->
+	build_tc_constr_struct_type(5, MR_TypeClassConstraint5Struct),
+	gcc__build_pointer_type(MR_TypeClassConstraint5Struct,
+		MR_TypeClassConstraint).
+
+:- pred build_tc_id_method_type(gcc__type::out, io__state::di, io__state::uo)
+	is det.
+
+build_tc_id_method_type(MR_TypeClassMethod) -->
+	% typedef struct {
+	%    MR_ConstString              MR_tc_method_name;
+	%    const MR_int_least8_t       MR_tc_method_arity;
+	%    const MR_PredFunc           MR_tc_method_pred_func;
+	% } MR_TypeClassMethod;
+	build_struct_type("MR_TypeClassMethod",
+		['MR_ConstString'	- "MR_tc_method_name",
+		 'MR_int_least8_t'	- "MR_tc_method_arity",
+		 'MR_PredFunc'		- "MR_tc_method_pred_func"],
+		MR_TypeClassMethod).
+
+:- pred build_tc_id_type(gcc__type::out, io__state::di, io__state::uo)
+	is det.
+
+build_tc_id_type(MR_TypeClassId) -->
+	% typedef struct {
+	%    MR_ConstString              MR_tc_id_module_name;
+	%    MR_ConstString              MR_tc_id_name;
+	%    const MR_int_least8_t       MR_tc_id_arity;
+	%    const MR_int_least8_t       MR_tc_id_num_type_vars;
+	%    const MR_int_least16_t      MR_tc_id_num_methods;
+	%    const MR_ConstString        *MR_tc_id_type_var_names;
+	%    const MR_TypeClassMethod    *MR_tc_id_methods;
+	% } MR_TypeClassId;
+	gcc__build_pointer_type('MR_ConstString', MR_ConstStringPtr),
+	build_tc_id_method_type(MR_TypeClassMethod),
+	gcc__build_pointer_type(MR_TypeClassMethod, MR_TypeClassMethodPtr),
+	build_struct_type("MR_TypeClassId",
+		['MR_ConstString'	- "MR_tc_id_module_name",
+		 'MR_ConstString'	- "MR_tc_id_name",
+		 'MR_int_least8_t'	- "MR_tc_id_arity",
+		 'MR_int_least8_t'	- "MR_tc_id_num_type_vars",
+		 'MR_int_least16_t'	- "MR_tc_id_num_methods",
+		 MR_ConstStringPtr	- "MR_tc_id_type_var_names",
+		 MR_TypeClassMethodPtr	- "MR_tc_id_methods"],
+		MR_TypeClassId).
+
+:- pred build_tc_decl_type(gcc__type::out, io__state::di, io__state::uo)
+	is det.
+
+build_tc_decl_type(MR_TypeClassDecl) -->
+	% struct MR_TypeClassDecl_Struct {
+	%    const MR_TypeClassId            *MR_tc_decl_id;
+	%    const MR_int_least8_t           MR_tc_decl_version_number;
+	%    const MR_int_least8_t           MR_tc_decl_num_supers;
+	%    const MR_TypeClassConstraint    *MR_tc_decl_supers;
+	% };
+	build_du_exist_locn_type(MR_TypeClassId),
+	gcc__build_pointer_type(MR_TypeClassId, MR_TypeClassIdPtr),
+	build_tc_constr_type(MR_TypeClassConstraint),
+	gcc__build_pointer_type(MR_TypeClassConstraint,
+		MR_TypeClassConstraintPtr),
+	build_struct_type("MR_TypeClassDeclStruct",
+		[MR_TypeClassIdPtr	- "MR_tc_decl_id",
+		 'MR_int_least8_t'	- "MR_tc_decl_version_number",
+		 'MR_int_least8_t'	- "MR_tc_decl_num_supers",
+		 MR_TypeClassConstraintPtr - "MR_tc_decl_supers"],
+		MR_TypeClassDecl).
+
+:- pred build_tc_instance_type(gcc__type::out, io__state::di, io__state::uo)
+	is det.
+
+build_tc_instance_type(MR_Instance) -->
+	% struct MR_Instance_Struct {
+	%    const MR_TypeClassDecl        MR_tc_inst_type_class;
+	%    const MR_int_least8_t         MR_tc_inst_num_type_vars;
+	%    const MR_int_least8_t	   MR_tc_inst_num_instance_constraints;
+	%    const MR_PseudoTypeInfo       *MR_tc_inst_type_args;
+	%    const MR_TypeClassConstraint  *MR_tc_inst_instance_constraints;
+	%    const MR_CodePtr              MR_tc_inst_methods;
+	% };
+	build_tc_decl_type(MR_TypeClassDecl),
+	gcc__build_pointer_type(MR_TypeClassDecl, MR_TypeClassDeclPtr),
+	gcc__build_pointer_type('MR_PseudoTypeInfo', MR_PseudoTypeInfoPtr),
+	build_tc_constr_type(MR_TypeClassConstraint),
+	gcc__build_pointer_type(MR_TypeClassConstraint,
+		MR_TypeClassConstraintPtr),
+	build_struct_type("MR_Instance",
+		[MR_TypeClassDeclPtr	- "MR_tc_inst_type_class",
+		 'MR_int_least8_t'	- "MR_tc_inst_num_type_vars",
+		 'MR_int_least8_t'	- "MR_tc_inst_num_instance_constraints",
+		 'MR_int_least8_t'	- "MR_tc_decl_num_supers",
+		 MR_PseudoTypeInfoPtr	- "MR_tc_inst_type_args",
+		 MR_TypeClassConstraintPtr - "MR_tc_inst_instance_constraints"],
+		MR_Instance).
+
 :- pred build_du_exist_locn_type(gcc__type, io__state, io__state).
 :- mode build_du_exist_locn_type(out, di, uo) is det.
 
@@ -2372,6 +2484,8 @@
 rtti_enum_const("MR_SECTAG_LOCAL", 1).
 rtti_enum_const("MR_SECTAG_REMOTE", 2).
 rtti_enum_const("MR_SECTAG_VARIABLE", 3).
+rtti_enum_const("MR_PREDICATE", 0).
+rtti_enum_const("MR_FUNCTION", 1).
 
 :- pred build_struct_type(gcc__struct_name::in,
 		list(pair(gcc__type, gcc__field_name))::in,
@@ -3630,6 +3744,7 @@
 :- func 'MR_PseudoTypeInfo'	= gcc__type.
 :- func 'MR_Sectag_Locn'	= gcc__type.
 :- func 'MR_TypeCtorRep'	= gcc__type.
+:- func 'MR_PredFunc'		= gcc__type.
 
 :- func 'MR_int_least8_t'	= gcc__type.
 :- func 'MR_int_least16_t'	= gcc__type.
@@ -3652,12 +3767,13 @@
 'MR_TypeCtorInfo'	= gcc__ptr_type_node.
 'MR_PseudoTypeInfo'	= gcc__ptr_type_node.
 
-	% XXX MR_Sectag_Locn and MR_TypeCtorRep are actually enums
-	% in the C back-end.  Binary compatibility between this
+	% XXX MR_Sectag_Locn, MR_TypeCtorRep, and MR_PredFunc are actually
+	% enums in the C back-end.  Binary compatibility between this
 	% back-end and the C back-end only works if the C compiler
 	% represents these enums the same as `int'.
 'MR_Sectag_Locn'	= gcc__integer_type_node.
 'MR_TypeCtorRep'	= gcc__integer_type_node.
+'MR_PredFunc'		= gcc__integer_type_node.
 
 'MR_int_least8_t'	= gcc__int8_type_node.
 'MR_int_least16_t'	= gcc__int16_type_node.
Index: compiler/mlds_to_java.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mlds_to_java.m,v
retrieving revision 1.50
diff -u -b -r1.50 mlds_to_java.m
--- compiler/mlds_to_java.m	7 Jan 2004 04:54:58 -0000	1.50
+++ compiler/mlds_to_java.m	23 Jan 2004 19:31:03 -0000
@@ -1840,8 +1840,9 @@
 	io__write_string("mercury.runtime.MethodPtr").
 output_type(mlds__commit_type) -->
 	io__write_string("mercury.runtime.Commit").
-output_type(mlds__rtti_type(RttiId)) -->
-	{ rtti_id_java_type(RttiId, JavaTypeName, IsArray) },
+output_type(mlds__rtti_type(RttiIdMaybeElement)) -->
+	{ rtti_id_maybe_element_java_type(RttiIdMaybeElement, JavaTypeName,
+		IsArray) },
 	io__write_string(JavaTypeName),
 	( { IsArray = yes } ->
 		io__write_string("[]")
@@ -1930,8 +1931,9 @@
 		IsArray = yes
 	; Type = mercury_type(_, TypeCategory, _) ->
 		IsArray = type_category_is_array(TypeCategory)
-	; Type = mlds__rtti_type(RttiId) ->
-		rtti_id_java_type(RttiId, _JavaTypeName, IsArray)
+	; Type = mlds__rtti_type(RttiIdMaybeElement) ->
+		rtti_id_maybe_element_java_type(RttiIdMaybeElement,
+			_JavaTypeName, IsArray)
 	;
 		IsArray = no
 	).
Index: compiler/opt_debug.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/opt_debug.m,v
retrieving revision 1.136
diff -u -b -r1.136 opt_debug.m
--- compiler/opt_debug.m	1 Dec 2003 06:53:29 -0000	1.136
+++ compiler/opt_debug.m	23 Jan 2004 19:31:03 -0000
@@ -385,6 +385,15 @@
 	string__append("exist_locns_", Ordinal_str, Str).
 opt_debug__dump_rtti_name(exist_locn, Str) :-
 	Str = "exist_loc".
+opt_debug__dump_rtti_name(exist_tc_constr(Ordinal, TCCNum, Arity), Str) :-
+	string__int_to_string(Ordinal, Ordinal_str),
+	string__int_to_string(TCCNum, TCCNum_str),
+	string__int_to_string(Arity, Arity_str),
+	string__append_list(["exist_tc_constr_", Ordinal_str, "_", TCCNum_str,
+		"_", Arity_str], Str).
+opt_debug__dump_rtti_name(exist_tc_constrs(Ordinal), Str) :-
+	string__int_to_string(Ordinal, Ordinal_str),
+	string__append("exist_tc_constrs_", Ordinal_str, Str).
 opt_debug__dump_rtti_name(exist_info(Ordinal), Str) :-
 	string__int_to_string(Ordinal, Ordinal_str),
 	string__append("exist_info_", Ordinal_str, Str).
Index: compiler/rtti.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/rtti.m,v
retrieving revision 1.38
diff -u -b -r1.38 rtti.m
--- compiler/rtti.m	1 Dec 2003 13:16:53 -0000	1.38
+++ compiler/rtti.m	23 Jan 2004 19:31:03 -0000
@@ -278,7 +278,7 @@
 	--->	exist_info(
 			exist_num_plain_typeinfos	:: int,
 			exist_num_typeinfos_in_tcis	:: int,
-			exist_num_typeclass_infos	:: int,
+			exist_typeclass_constraints	:: list(tc_constraint),
 			exist_typeinfo_locns		::
 						list(exist_typeinfo_locn)
 		).
@@ -596,6 +596,10 @@
 :- type ctor_rtti_name
 	--->	exist_locns(int)		% functor ordinal
 	;	exist_locn
+	;	exist_tc_constr(int, int, int)	% functor ordinal,
+						% constraint ordinal,
+						% constraint arity
+	;	exist_tc_constrs(int)		% functor ordinal
 	;	exist_info(int)			% functor ordinal
 	;	field_names(int)		% functor ordinal
 	;	field_types(int)		% functor ordinal
@@ -662,7 +666,16 @@
 	% type of that kind.
 :- func var_arity_id_to_rtti_type_ctor(var_arity_ctor_id) = rtti_type_ctor.
 
+:- type rtti_id_maybe_element
+	--->	item_type(rtti_id)
+		% The type is the type of the data structure identified by the
+		% rtti_id.
+	;	element_type(rtti_id).
+		% The type is the type of the elements of the data structure
+		% identified by the rtti_id, which must be an array.
+
 	% Return yes iff the specified entity is an array.
+:- func rtti_id_maybe_element_has_array_type(rtti_id_maybe_element) = bool.
 :- func rtti_id_has_array_type(rtti_id) = bool.
 :- func ctor_rtti_name_has_array_type(ctor_rtti_name) = bool.
 :- func tc_rtti_name_has_array_type(tc_rtti_name) = bool.
@@ -685,6 +698,9 @@
 	% by the input argument.
 :- pred rtti__id_to_c_identifier(rtti_id::in, string::out) is det.
 
+	% Return the C representation of a pred_or_func indication.
+:- pred rtti__pred_or_func_to_string(pred_or_func::in, string::out) is det.
+
 	% Return the C representation of a secondary tag location.
 :- pred rtti__sectag_locn_to_string(sectag_locn::in, string::out) is det.
 
@@ -759,6 +775,8 @@
 	%	To declare a variable of the type specified by RttiId,
 	%	put Type before the name of the variable; if IsArray is true,
 	%	also put "[]" after the name.
+:- pred rtti_id_maybe_element_c_type(rtti_id_maybe_element::in, string::out,
+	bool::out) is det.
 :- pred rtti_id_c_type(rtti_id::in, string::out, bool::out) is det.
 :- pred ctor_rtti_name_c_type(ctor_rtti_name::in, string::out, bool::out)
 	is det.
@@ -766,6 +784,8 @@
 	is det.
 
 	% Analogous to rtti_id_c_type.
+:- pred rtti_id_maybe_element_java_type(rtti_id_maybe_element::in, string::out,
+	bool::out) is det.
 :- pred rtti_id_java_type(rtti_id::in, string::out, bool::out) is det.
 :- pred ctor_rtti_name_java_type(ctor_rtti_name::in, string::out, bool::out)
 	is det.
@@ -862,6 +882,12 @@
 	mercury_public_builtin_module(Builtin),
 	Ctor = rtti_type_ctor(Builtin, "tuple", 0).
 
+rtti_id_maybe_element_has_array_type(item_type(RttiId)) =
+	rtti_id_has_array_type(RttiId).
+rtti_id_maybe_element_has_array_type(element_type(RttiId)) = no :-
+	require(unify(rtti_id_has_array_type(RttiId), yes),
+		"rtti_id_maybe_element_has_array_type: base is not array").
+
 rtti_id_has_array_type(ctor_rtti_id(_, RttiName)) =
 	ctor_rtti_name_has_array_type(RttiName).
 rtti_id_has_array_type(tc_rtti_id(TCRttiName)) =
@@ -880,6 +906,8 @@
 
 ctor_rtti_name_is_exported(exist_locns(_))		= no.
 ctor_rtti_name_is_exported(exist_locn)			= no.
+ctor_rtti_name_is_exported(exist_tc_constr(_, _, _))	= no.
+ctor_rtti_name_is_exported(exist_tc_constrs(_))		= no.
 ctor_rtti_name_is_exported(exist_info(_))       	= no.
 ctor_rtti_name_is_exported(field_names(_))      	= no.
 ctor_rtti_name_is_exported(field_types(_))      	= no.
@@ -983,6 +1011,17 @@
 		string__append_list([ModuleName, "__exist_locn_",
 			TypeName, "_", A_str], Str)
 	;
+		RttiName = exist_tc_constr(Ordinal, TCCNum, _),
+		string__int_to_string(Ordinal, O_str),
+		string__int_to_string(TCCNum, N_str),
+		string__append_list([ModuleName, "__exist_tc_constr_",
+			TypeName, "_", A_str, "_", O_str, "_", N_str], Str)
+	;
+		RttiName = exist_tc_constrs(Ordinal),
+		string__int_to_string(Ordinal, O_str),
+		string__append_list([ModuleName, "__exist_tc_constrs_",
+			TypeName, "_", A_str, "_", O_str], Str)
+	;
 		RttiName = exist_info(Ordinal),
 		string__int_to_string(Ordinal, O_str),
 		string__append_list([ModuleName, "__exist_info_",
@@ -1345,6 +1384,9 @@
 
 %-----------------------------------------------------------------------------%
 
+rtti__pred_or_func_to_string(predicate, "MR_PREDICATE").
+rtti__pred_or_func_to_string(function,  "MR_FUNCTION").
+
 rtti__sectag_locn_to_string(sectag_none,   "MR_SECTAG_NONE").
 rtti__sectag_locn_to_string(sectag_local,  "MR_SECTAG_LOCAL").
 rtti__sectag_locn_to_string(sectag_remote, "MR_SECTAG_REMOTE").
@@ -1545,6 +1587,8 @@
 
 ctor_rtti_name_would_include_code_addr(exist_locns(_)) =		no.
 ctor_rtti_name_would_include_code_addr(exist_locn) 	=		no.
+ctor_rtti_name_would_include_code_addr(exist_tc_constr(_, _, _)) =	no.
+ctor_rtti_name_would_include_code_addr(exist_tc_constrs(_)) =		no.
 ctor_rtti_name_would_include_code_addr(exist_info(_)) =			no.
 ctor_rtti_name_would_include_code_addr(field_names(_)) =		no.
 ctor_rtti_name_would_include_code_addr(field_types(_)) =		no.
@@ -1587,7 +1631,7 @@
 tc_rtti_name_would_include_code_addr(type_class_instance_constraints(_, _))
 	= no.
 tc_rtti_name_would_include_code_addr(type_class_instance_methods(_, _))
-	= yes.
+	= no.
 
 type_info_would_incl_code_addr(plain_arity_zero_type_info(_)) = yes.
 type_info_would_incl_code_addr(plain_type_info(_, _)) =	no.
@@ -1599,6 +1643,18 @@
 pseudo_type_info_would_incl_code_addr(var_arity_pseudo_type_info(_, _))	= no.
 pseudo_type_info_would_incl_code_addr(type_var(_)) = no.
 
+rtti_id_maybe_element_c_type(item_type(RttiId), CTypeName, IsArray) :-
+	rtti_id_c_type(RttiId, CTypeName, IsArray).
+rtti_id_maybe_element_c_type(element_type(RttiId), CTypeName, IsArray) :-
+	rtti_id_c_type(RttiId, CTypeName, IsArray0),
+	(
+		IsArray0 = no,
+		error("rtti_id_maybe_element_c_type: base is not array")
+	;
+		IsArray0 = yes,
+		IsArray = no
+	).
+
 rtti_id_c_type(ctor_rtti_id(_, RttiName), CTypeName, IsArray) :-
 	ctor_rtti_name_c_type(RttiName, CTypeName, IsArray).
 rtti_id_c_type(tc_rtti_id(TCRttiName), CTypeName, IsArray) :-
@@ -1612,6 +1668,18 @@
 	tc_rtti_name_type(TCRttiName, GenTypeName, IsArray),
 	CTypeName = string__append("MR_", GenTypeName).
 
+rtti_id_maybe_element_java_type(item_type(RttiId), CTypeName, IsArray) :-
+	rtti_id_java_type(RttiId, CTypeName, IsArray).
+rtti_id_maybe_element_java_type(element_type(RttiId), CTypeName, IsArray) :-
+	rtti_id_java_type(RttiId, CTypeName, IsArray0),
+	(
+		IsArray0 = no,
+		error("rtti_id_maybe_element_java_type: base is not array")
+	;
+		IsArray0 = yes,
+		IsArray = no
+	).
+
 rtti_id_java_type(ctor_rtti_id(_, RttiName), JavaTypeName, IsArray) :-
 	ctor_rtti_name_java_type(RttiName, JavaTypeName, IsArray).
 rtti_id_java_type(tc_rtti_id(TCRttiName), JavaTypeName, IsArray) :-
@@ -1646,6 +1714,9 @@
 
 ctor_rtti_name_type(exist_locns(_),             "DuExistLocn", yes).
 ctor_rtti_name_type(exist_locn,                 "DuExistLocn", no).
+ctor_rtti_name_type(exist_tc_constr(_, _, N), TypeName, no) :-
+	TypeName = tc_constraint_type_name(N).
+ctor_rtti_name_type(exist_tc_constrs(_),        "TypeClassConstraint", yes).
 ctor_rtti_name_type(exist_info(_),              "DuExistInfo", no).
 ctor_rtti_name_type(field_names(_),             "ConstString", yes).
 ctor_rtti_name_type(field_types(_),             "PseudoTypeInfo", yes).
@@ -1683,22 +1754,25 @@
 tc_rtti_name_type(type_class_id_var_names(_),	"ConstString", yes).
 tc_rtti_name_type(type_class_id_method_ids(_),	"TypeClassMethod", yes).
 tc_rtti_name_type(type_class_decl(_),		"TypeClassDeclStruct", no).
-tc_rtti_name_type(type_class_decl_supers(_),	"TypeClassConstraint", yes).
 tc_rtti_name_type(type_class_decl_super(_, _, N), TypeName, no) :-
-	string__int_to_string(N, NStr),
-	string__append_list(["TypeClassConstraint_", NStr, "Struct"],
-		TypeName).
+	TypeName = tc_constraint_type_name(N).
+tc_rtti_name_type(type_class_decl_supers(_),	"TypeClassConstraint", yes).
 tc_rtti_name_type(type_class_instance(_, _),	"InstanceStruct", no).
 tc_rtti_name_type(type_class_instance_tc_type_vector(_, _),
 						"PseudoTypeInfo", yes).
 tc_rtti_name_type(type_class_instance_constraint(_, _, _, N), TypeName, no) :-
-	string__int_to_string(N, NStr),
-	string__append_list(["TypeClassConstraint_", NStr, "Struct"],
-		TypeName).
+	TypeName = tc_constraint_type_name(N).
 tc_rtti_name_type(type_class_instance_constraints(_, _),
 						"TypeClassConstraint", yes).
 tc_rtti_name_type(type_class_instance_methods(_, _),
 						"CodePtr", yes).
+
+:- func tc_constraint_type_name(int) = string.
+
+tc_constraint_type_name(N) = TypeName :-
+	string__int_to_string(N, NStr),
+	string__append_list(["TypeClassConstraint_", NStr, "Struct"],
+		TypeName).
 
 :- func type_info_name_type(rtti_type_info) = string.
 
Index: compiler/rtti_out.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/rtti_out.m,v
retrieving revision 1.40
diff -u -b -r1.40 rtti_out.m
--- compiler/rtti_out.m	11 Nov 2003 03:35:08 -0000	1.40
+++ compiler/rtti_out.m	22 Jan 2004 23:33:16 -0000
@@ -271,7 +271,7 @@
 
 output_type_class_instance_defn(Instance, !DeclSet, !IO) :-
 	Instance = tc_instance(TCName, TCTypes, NumTypeVars, Constraints,
-		MethodProcLabels),
+		_MethodProcLabels),
 	list__foldl2(output_maybe_pseudo_type_info_defn, TCTypes,
 		!DeclSet, !IO),
 	TCTypeRttiDatas = list__map(maybe_pseudo_type_info_to_rtti_data,
@@ -301,21 +301,21 @@
 			ConstraintIds, !IO),
 		io__write_string("};\n", !IO)
 	),
-	TCInstanceMethodsRttiId = tc_rtti_id(
-		type_class_instance_methods(TCName, TCTypes)),
-	(
-		MethodProcLabels = []
-	;
-		MethodProcLabels = [_ | _],
-		MethodCodeAddrs = list__map(make_code_addr, MethodProcLabels),
-		list__foldl2(output_code_addr_decls, MethodCodeAddrs,
-			!DeclSet, !IO),
-		output_generic_rtti_data_defn_start(TCInstanceMethodsRttiId,
-			!DeclSet, !IO),
-		io__write_string(" = {\n", !IO),
-		list__foldl(output_code_addr_in_list, MethodCodeAddrs, !IO),
-		io__write_string("};\n", !IO)
-	),
+%	TCInstanceMethodsRttiId = tc_rtti_id(
+%		type_class_instance_methods(TCName, TCTypes)),
+%	(
+%		MethodProcLabels = []
+%	;
+%		MethodProcLabels = [_ | _],
+%		MethodCodeAddrs = list__map(make_code_addr, MethodProcLabels),
+%		list__foldl2(output_code_addr_decls, MethodCodeAddrs,
+%			!DeclSet, !IO),
+%		output_generic_rtti_data_defn_start(TCInstanceMethodsRttiId,
+%			!DeclSet, !IO),
+%		io__write_string(" = {\n", !IO),
+%		list__foldl(output_code_addr_in_list, MethodCodeAddrs, !IO),
+%		io__write_string("};\n", !IO)
+%	),
 	TCDeclRttiId = tc_rtti_id(type_class_decl(TCName)),
 	output_rtti_id_decls(TCDeclRttiId, "", "", 0, _, !DeclSet, !IO),
 	TCInstanceRttiId = tc_rtti_id(type_class_instance(TCName, TCTypes)),
@@ -336,15 +336,15 @@
 		Constraints = [_ | _],
 		output_rtti_id(TCInstanceConstraintsRttiId, !IO)
 	),
-	io__write_string(",\n\t", !IO),
-	(
-		MethodProcLabels = [],
-		io__write_string("NULL", !IO)
-	;
-		MethodProcLabels = [_ | _],
-		io__write_string("&", !IO),
-		output_rtti_id(TCInstanceMethodsRttiId, !IO)
-	),
+%	io__write_string(",\n\t", !IO),
+%	(
+%		MethodProcLabels = [],
+%		io__write_string("NULL", !IO)
+%	;
+%		MethodProcLabels = [_ | _],
+%		io__write_string("&", !IO),
+%		output_rtti_id(TCInstanceMethodsRttiId, !IO)
+%	),
 	io__write_string("\n};\n", !IO).
 
 :- pred make_tc_instance_constraint_id(tc_name::in, list(tc_type)::in,
@@ -373,8 +373,8 @@
 		!Counter, !DeclSet, !IO) :-
 	Constraint = tc_constraint(TCName, Types),
 	list__length(Types, NumTypes),
-	counter__allocate(Ordinal, !Counter),
-	MakeRttiId(Ordinal, NumTypes, TCDeclSuperRttiId),
+	counter__allocate(TCNum, !Counter),
+	MakeRttiId(TCNum, NumTypes, TCDeclSuperRttiId),
 	TCDeclRttiId = tc_rtti_id(type_class_decl(TCName)),
 	output_generic_rtti_data_decl(TCDeclRttiId, !DeclSet, !IO),
 	list__foldl2(output_maybe_pseudo_type_info_defn, Types, !DeclSet, !IO),
@@ -904,13 +904,43 @@
 		io__write_string("};\n", !IO)
 	).
 
+:- pred make_exist_tc_constr_id(rtti_type_ctor::in, int::in,
+	int::in, int::in, rtti_id::out) is det.
+
+make_exist_tc_constr_id(RttiTypeCtor, Ordinal, TCNum, Arity, RttiId) :-
+	RttiName = exist_tc_constr(Ordinal, TCNum, Arity),
+	RttiId = ctor_rtti_id(RttiTypeCtor, RttiName).
+
+:- pred output_exist_constraints_data(rtti_type_ctor::in, int::in,
+	list(tc_constraint)::in, decl_set::in, decl_set::out,
+	io__state::di, io__state::uo) is det.
+
+output_exist_constraints_data(RttiTypeCtor, Ordinal, Constraints, !DeclSet,
+		!IO) :-
+	list__map_foldl3(output_type_class_constraint(
+		make_exist_tc_constr_id(RttiTypeCtor, Ordinal)), Constraints,
+		ConstraintIds, counter__init(1), _, !DeclSet, !IO),
+	RttiId = ctor_rtti_id(RttiTypeCtor, exist_tc_constrs(Ordinal)),
+	output_generic_rtti_data_defn_start(RttiId, !DeclSet, !IO),
+	io__write_string(" = {\n\t", !IO),
+	output_cast_addr_of_rtti_ids("(MR_TypeClassConstraint) ",
+		ConstraintIds, !IO),
+	io__write_string("\n};\n", !IO).
+
 :- pred output_exist_info(rtti_type_ctor::in, int::in, exist_info::in,
 	decl_set::in, decl_set::out, io__state::di, io__state::uo) is det.
 
 output_exist_info(RttiTypeCtor, Ordinal, ExistInfo, !DeclSet, !IO) :-
-	ExistInfo = exist_info(Plain, InTci, Tci, Locns),
+	ExistInfo = exist_info(Plain, InTci, Constraints, Locns),
 	output_exist_locns_array(RttiTypeCtor, Ordinal, Locns,
 		!DeclSet, !IO),
+	(
+		Constraints = [_ | _],
+		output_exist_constraints_data(RttiTypeCtor, Ordinal,
+			Constraints, !DeclSet, !IO)
+	;
+		Constraints = []
+	),
 	output_generic_rtti_data_defn_start(
 		ctor_rtti_id(RttiTypeCtor, exist_info(Ordinal)),
 		!DeclSet, !IO),
@@ -919,9 +949,18 @@
 	io__write_string(",\n\t", !IO),
 	io__write_int(InTci, !IO),
 	io__write_string(",\n\t", !IO),
+	list__length(Constraints, Tci),
 	io__write_int(Tci, !IO),
 	io__write_string(",\n\t", !IO),
 	output_ctor_rtti_id(RttiTypeCtor, exist_locns(Ordinal), !IO),
+	io__write_string(",\n\t", !IO),
+	(
+		Constraints = [_ | _],
+		output_ctor_rtti_id(RttiTypeCtor, exist_tc_constrs(Ordinal),
+			!IO)
+	;
+		Constraints = []
+	),
 	io__write_string("\n};\n", !IO).
 
 :- pred output_du_arg_types(rtti_type_ctor::in, int::in,
Index: compiler/rtti_to_mlds.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/rtti_to_mlds.m,v
retrieving revision 1.45
diff -u -b -r1.45 rtti_to_mlds.m
--- compiler/rtti_to_mlds.m	11 Dec 2003 02:55:54 -0000	1.45
+++ compiler/rtti_to_mlds.m	23 Jan 2004 22:18:20 -0000
@@ -42,7 +42,7 @@
 :- import_module parse_tree__prog_util.
 
 :- import_module bool, string, int, list, assoc_list, map.
-:- import_module std_util, term, require.
+:- import_module std_util, term, counter, require.
 
 rtti_data_list_to_mlds(ModuleInfo, RttiDatas) = MLDS_Defns :-
 	RealRttiDatas = list__filter(real_rtti_data, RttiDatas),
@@ -70,8 +70,8 @@
 rtti_data_to_mlds(ModuleInfo, RttiData) = MLDS_Defns :-
 	( RttiData = pseudo_type_info(type_var(_)) ->
 		% These just get represented as integers,
-		% so we don't need to define them.
-		% Also rtti_data_to_name/3 does not handle this case.
+		% so we don't need to define a structure for them;
+		% which is why rtti_data_to_name/3 does not handle this case.
 		MLDS_Defns = []
     	;
 		rtti_data_to_id(RttiData, RttiId),
@@ -126,7 +126,7 @@
 	% Generate the declaration body,
 	% i.e. the type and the initializer
 	%
-	MLDS_Type = rtti_type(RttiId),
+	MLDS_Type = rtti_type(item_type(RttiId)),
 	DefnBody = mlds__data(MLDS_Type, Initializer, GC_TraceCode),
 	MLDS_Defn = mlds__defn(Name, MLDS_Context, Flags, DefnBody).
 
@@ -173,12 +173,6 @@
 		gen_init_boxed_int(N5)
 		| MethodInitializers
 	]).
-gen_init_rtti_data_defn(RttiData, _RttiId, _ModuleInfo, _Init, _SubDefns) :-
-	RttiData = type_class_decl(_), 
-	error("gen_init_rtti_data_defn: type_class_decl NYI").
-gen_init_rtti_data_defn(RttiData, _RttiId, _ModuleInfo, _Init, _SubDefns) :-
-	RttiData = type_class_instance(_), 
-	error("gen_init_rtti_data_defn: type_class_instance NYI").
 gen_init_rtti_data_defn(RttiData, RttiId, ModuleInfo, Init, SubDefns) :-
 	RttiData = type_info(TypeInfo), 
 	gen_type_info_defn(ModuleInfo, TypeInfo, RttiId, Init, SubDefns).
@@ -186,7 +180,13 @@
 	RttiData = pseudo_type_info(PseudoTypeInfo), 
 	gen_pseudo_type_info_defn(ModuleInfo, PseudoTypeInfo, RttiId,
 		Init, SubDefns).
-
+gen_init_rtti_data_defn(RttiData, RttiId, ModuleInfo, Init, SubDefns) :-
+	RttiData = type_class_decl(TCDecl), 
+	gen_type_class_decl_defn(TCDecl, RttiId, ModuleInfo, Init, SubDefns).
+gen_init_rtti_data_defn(RttiData, RttiId, ModuleInfo, Init, SubDefns) :-
+	RttiData = type_class_instance(Instance), 
+	gen_type_class_instance_defn(Instance, RttiId, ModuleInfo, Init,
+		SubDefns).
 gen_init_rtti_data_defn(RttiData, RttiId, ModuleInfo, Init, SubDefns) :-
 	RttiData = type_ctor_info(TypeCtorData), 
 	TypeCtorData = type_ctor_data(Version, TypeModule, TypeName,
@@ -203,18 +203,20 @@
 			TypeCtorDetails, FunctorsInfo, LayoutInfo, !:Defns),
 
 	    %
-	    % Note that gen_init_special_pred will by necessity add an extra
-	    % level of indirection to calling the special preds.  However the
-	    % backend compiler should be smart enough to ensure that this is
-	    % inlined away.
-	    %
-	    gen_init_special_pred(ModuleInfo, UnifyUniv, UnifyInit, !Defns),
-	    gen_init_special_pred(ModuleInfo, CompareUniv, CompareInit, !Defns),
+		% Note that gen_init_special_pred will by necessity add an
+		% extra level of indirection to calling the special preds.
+		% However the backend compiler should be smart enough
+		% to ensure that this is inlined away.
+		%
+		gen_init_special_pred(ModuleInfo, UnifyUniv, UnifyInit,
+			!Defns),
+		gen_init_special_pred(ModuleInfo, CompareUniv, CompareInit,
+			!Defns),
 
 	    SubDefns = !.Defns
 	),
 
-	Init = init_struct(mlds__rtti_type(RttiId), [
+	Init = init_struct(mlds__rtti_type(item_type(RttiId)), [
 		gen_init_int(TypeArity),
 		gen_init_int(Version),
 		gen_init_int(NumPtags),
@@ -226,10 +228,10 @@
 		% In the C back-end, these two "structs" are actually unions.
 		% We need to use `init_struct' here so that the initializers
 		% get enclosed in curly braces.
-		init_struct(mlds__rtti_type(FunctorsRttiId), [
+		init_struct(mlds__rtti_type(item_type(FunctorsRttiId)), [
 			FunctorsInfo
 		]),
-		init_struct(mlds__rtti_type(LayoutRttiId), [
+		init_struct(mlds__rtti_type(item_type(LayoutRttiId)), [
 			LayoutInfo
 		]),
 		gen_init_int(NumFunctors),
@@ -246,6 +248,170 @@
 
 %-----------------------------------------------------------------------------%
 
+:- pred gen_type_class_decl_defn(tc_decl::in, rtti_id::in, module_info::in,
+	mlds__initializer::out, list(mlds__defn)::out) is det.
+
+gen_type_class_decl_defn(TCDecl, RttiId, ModuleInfo, Init, SubDefns) :-
+	TCDecl = tc_decl(TCId, Version, Supers),
+	TCId = tc_id(TCName, TVarNames, MethodIds),
+	TCName = tc_name(ModuleSymName, ClassName, Arity),
+	module_info_name(ModuleInfo, ModuleName),
+	TVarNamesRttiId = tc_rtti_id(type_class_id_var_names(TCName)),
+	(
+		TVarNames = [],
+		TVarNameDefns = [],
+		TVarNamesInit = gen_init_null_pointer(
+			mlds__rtti_type(item_type(TVarNamesRttiId)))
+	;
+		TVarNames = [_ | _],
+		gen_tc_id_var_names(TVarNamesRttiId, TVarNames, TVarNameDefn),
+		TVarNameDefns = [TVarNameDefn],
+		TVarNamesInit = gen_init_rtti_id(ModuleName, TVarNamesRttiId)
+	),
+	MethodIdsRttiId = tc_rtti_id(type_class_id_method_ids(TCName)),
+	(
+		MethodIds = [],
+		MethodIdDefns = [],
+		MethodIdsInit = gen_init_null_pointer(
+			mlds__rtti_type(item_type(MethodIdsRttiId)))
+	;
+		MethodIds = [_ | _],
+		gen_tc_id_method_ids(MethodIdsRttiId, TCName, MethodIds,
+			MethodIdDefn),
+		MethodIdDefns = [MethodIdDefn],
+		MethodIdsInit = gen_init_rtti_id(ModuleName, MethodIdsRttiId)
+	),
+	TCIdRttiId = tc_rtti_id(type_class_id(TCName)),
+	prog_out__sym_name_to_string(ModuleSymName, ModuleSymNameStr),
+	list__length(TVarNames, NumTVars),
+	list__length(MethodIds, NumMethods),
+	TCIdInit = init_struct(mlds__rtti_type(item_type(TCIdRttiId)), [
+		gen_init_string(ModuleSymNameStr),
+		gen_init_string(ClassName),
+		gen_init_int(Arity),
+		gen_init_int(NumTVars),
+		gen_init_int(NumMethods),
+		TVarNamesInit,
+		MethodIdsInit
+	]),
+	rtti_id_and_init_to_defn(TCIdRttiId, TCIdInit, TCIdDefn),
+	(
+		Supers = [],
+		SuperDefns = [],
+		SupersInit = gen_init_null_pointer(
+			mlds__rtti_type(item_type(MethodIdsRttiId)))
+	;
+		Supers = [_ | _],
+		list__map_foldl2(gen_tc_constraint(ModuleInfo,
+			make_decl_super_id(TCName)), Supers, SuperRttiIds,
+			counter__init(1), _, [], SuperConstrDefns),
+		SuperArrayRttiId = tc_rtti_id(SuperArrayRttiName),
+		ElementType = mlds__rtti_type(element_type(SuperArrayRttiId)),
+		SuperArrayInit = gen_init_array(
+			gen_init_cast_rtti_id(ElementType, ModuleName),
+			SuperRttiIds),
+		SuperArrayRttiName = type_class_decl_supers(TCName),
+		rtti_id_and_init_to_defn(SuperArrayRttiId, SuperArrayInit,
+			SuperDefn),
+		list__append(SuperConstrDefns, [SuperDefn], SuperDefns),
+		SupersInit = gen_init_null_pointer(
+			mlds__rtti_type(item_type(MethodIdsRttiId)))
+	),
+	list__length(Supers, NumSupers),
+	Init = init_struct(mlds__rtti_type(item_type(RttiId)), [
+		gen_init_rtti_id(ModuleName, TCIdRttiId),
+		gen_init_int(Version),
+		gen_init_int(NumSupers),
+		SupersInit
+	]),
+	list__condense([TVarNameDefns, MethodIdDefns, [TCIdDefn], SuperDefns],
+		SubDefns).
+
+:- pred make_decl_super_id(tc_name::in, int::in, int::in, rtti_id::out)
+	is det.
+
+make_decl_super_id(TCName, TCNum, Arity, RttiId) :-
+	TCRttiName = type_class_decl_super(TCName, TCNum, Arity),
+	RttiId = tc_rtti_id(TCRttiName).
+
+:- pred gen_tc_id_var_names(rtti_id::in, list(string)::in, mlds__defn::out)
+	is det.
+
+gen_tc_id_var_names(RttiId, Names, MLDS_Defn) :-
+	Init = gen_init_array(gen_init_string, Names),
+	rtti_id_and_init_to_defn(RttiId, Init, MLDS_Defn).
+
+:- pred gen_tc_id_method_ids(rtti_id::in, tc_name::in, list(tc_method_id)::in,
+	mlds__defn::out) is det.
+
+gen_tc_id_method_ids(RttiId, TCName, MethodIds, Defn) :-
+	Init = gen_init_array(gen_tc_id_method_id(TCName), MethodIds),
+	rtti_id_and_init_to_defn(RttiId, Init, Defn).
+
+:- func gen_tc_id_method_id(tc_name, tc_method_id) = mlds__initializer.
+
+gen_tc_id_method_id(TCName, MethodId) = Init :-
+	MethodId = tc_method_id(MethodName, MethodArity, PredOrFunc),
+	RttiId = tc_rtti_id(type_class_id_method_ids(TCName)),
+	Init = init_struct(mlds__rtti_type(element_type(RttiId)), [
+		gen_init_string(MethodName),
+		gen_init_int(MethodArity),
+		gen_init_pred_or_func(PredOrFunc)
+	]).
+
+%-----------------------------------------------------------------------------%
+
+:- pred gen_type_class_instance_defn(tc_instance::in, rtti_id::in,
+	module_info::in, mlds__initializer::out, list(mlds__defn)::out) is det.
+
+gen_type_class_instance_defn(Instance, RttiId, ModuleInfo, Init, SubDefns) :-
+	Instance = tc_instance(TCName, Types, NumTypeVars,
+		InstanceConstraints, _Methods),
+	TCDeclRttiId = tc_rtti_id(type_class_decl(TCName)),
+	list__length(InstanceConstraints, NumInstanceConstraints),
+	InstanceTypesTCRttiName =
+		type_class_instance_tc_type_vector(TCName, Types),
+	InstanceTypesRttiId = tc_rtti_id(InstanceTypesTCRttiName),
+	InstanceConstrsTCRttiName =
+		type_class_instance_constraints(TCName, Types),
+	InstanceConstrsRttiId = tc_rtti_id(InstanceConstrsTCRttiName),
+	module_info_name(ModuleInfo, ModuleName),
+
+	TypeRttiDatas = list__map(maybe_pseudo_type_info_to_rtti_data, Types),
+	gen_pseudo_type_info_array(ModuleInfo, TypeRttiDatas, TypesInit,
+		TypesDefns),
+	rtti_id_and_init_to_defn(InstanceTypesRttiId, TypesInit, TypesDefn),
+
+	list__map_foldl2(gen_tc_constraint(ModuleInfo,
+		make_instance_constr_id(TCName, Types)),
+		InstanceConstraints, TCConstrIds, counter__init(1), _,
+		[], TCConstrDefns),
+	ElementType = mlds__rtti_type(element_type(InstanceConstrsRttiId)),
+	InstanceConstrsInit = gen_init_array(
+		gen_init_cast_rtti_id(ElementType, ModuleName),
+		TCConstrIds),
+	rtti_id_and_init_to_defn(InstanceConstrsRttiId, InstanceConstrsInit,
+		InstanceConstrsDefn),
+
+	Init = init_struct(mlds__rtti_type(item_type(RttiId)), [
+		gen_init_rtti_id(ModuleName, TCDeclRttiId),
+		gen_init_int(NumTypeVars),
+		gen_init_int(NumInstanceConstraints),
+		gen_init_rtti_id(ModuleName, InstanceTypesRttiId),
+		gen_init_rtti_id(ModuleName, InstanceConstrsRttiId)
+	]),
+	list__condense([TypesDefns, [TypesDefn], TCConstrDefns,
+		[InstanceConstrsDefn]], SubDefns).
+
+:- pred make_instance_constr_id(tc_name::in, list(tc_type)::in,
+	int::in, int::in, rtti_id::out) is det.
+
+make_instance_constr_id(TCName, Types, TCNum, Arity, RttiId) :-
+	RttiName = type_class_instance_constraint(TCName, Types, TCNum, Arity),
+	RttiId = tc_rtti_id(RttiName).
+
+%-----------------------------------------------------------------------------%
+
 :- pred gen_type_info_defn(module_info::in, rtti_type_info::in, rtti_id::in,
 	mlds__initializer::out, list(mlds__defn)::out) is det.
 
@@ -258,7 +424,7 @@
 	SubDefnLists = list__map(rtti_data_to_mlds(ModuleInfo), RealRttiDatas),
 	SubDefns = list__condense(SubDefnLists),
 	module_info_name(ModuleInfo, ModuleName),
-	Init = init_struct(mlds__rtti_type(RttiId), [
+	Init = init_struct(mlds__rtti_type(item_type(RttiId)), [
 		gen_init_rtti_name(ModuleName, RttiTypeCtor, type_ctor_info),
 		gen_init_cast_rtti_datas_array(mlds__type_info_type,
 			ModuleName, ArgRttiDatas)
@@ -271,7 +437,7 @@
 	SubDefns = list__condense(SubDefnLists),
 	RttiTypeCtor = var_arity_id_to_rtti_type_ctor(VarArityId),
 	module_info_name(ModuleInfo, ModuleName),
-	Init = init_struct(mlds__rtti_type(RttiId), [
+	Init = init_struct(mlds__rtti_type(item_type(RttiId)), [
 		gen_init_rtti_name(ModuleName, RttiTypeCtor, type_ctor_info),
 		gen_init_int(list__length(ArgTypes)),
 		gen_init_cast_rtti_datas_array(mlds__type_info_type,
@@ -290,7 +456,7 @@
 	SubDefnLists = list__map(rtti_data_to_mlds(ModuleInfo), RealRttiDatas),
 	SubDefns = list__condense(SubDefnLists),
 	module_info_name(ModuleInfo, ModuleName),
-	Init = init_struct(mlds__rtti_type(RttiId), [
+	Init = init_struct(mlds__rtti_type(item_type(RttiId)), [
 		gen_init_rtti_name(ModuleName, RttiTypeCtor, type_ctor_info),
 		gen_init_cast_rtti_datas_array(mlds__pseudo_type_info_type,
 			ModuleName, ArgRttiDatas)
@@ -303,7 +469,7 @@
 	SubDefns = list__condense(SubDefnLists),
 	RttiTypeCtor = var_arity_id_to_rtti_type_ctor(VarArityId),
 	module_info_name(ModuleInfo, ModuleName),
-	Init = init_struct(mlds__rtti_type(RttiId), [
+	Init = init_struct(mlds__rtti_type(item_type(RttiId)), [
 		gen_init_rtti_name(ModuleName, RttiTypeCtor, type_ctor_info),
 		gen_init_int(list__length(ArgTypes)),
 		gen_init_cast_rtti_datas_array(mlds__pseudo_type_info_type,
@@ -381,12 +547,8 @@
 	;
 		TypeCtorDetails = eqv(EqvType),
 		TypeRttiData = maybe_pseudo_type_info_to_rtti_data(EqvType),
-		RealRttiDatas = list__filter(real_rtti_data, [TypeRttiData]),
-		DefnsList = list__map(rtti_data_to_mlds(ModuleInfo),
-			RealRttiDatas),
-		Defns = list__condense(DefnsList),
-		LayoutInit = gen_init_cast_rtti_data(
-			mlds__pseudo_type_info_type, ModuleName, TypeRttiData),
+		gen_pseudo_type_info(ModuleInfo, TypeRttiData, LayoutInit,
+			Defns),
 			% The type is a lie, but a safe one.
 		FunctorInit = gen_init_null_pointer(mlds__generic_type)
 	;
@@ -415,7 +577,7 @@
 	EnumFunctor = enum_functor(FunctorName, Ordinal),
 	RttiName = enum_functor_desc(Ordinal),
 	RttiId = ctor_rtti_id(RttiTypeCtor, RttiName),
-	Init = init_struct(mlds__rtti_type(RttiId), [
+	Init = init_struct(mlds__rtti_type(item_type(RttiId)), [
  		gen_init_string(FunctorName),
  		gen_init_int(Ordinal)
  	]),
@@ -427,20 +589,16 @@
 gen_notag_functor_desc(ModuleInfo, RttiTypeCtor, NotagFunctorDesc)
 		= MLDS_Defns :-
 	NotagFunctorDesc = notag_functor(FunctorName, ArgType, MaybeArgName),
-	module_info_name(ModuleInfo, ModuleName),
 	ArgTypeRttiData = maybe_pseudo_type_info_to_rtti_data(ArgType),
+	gen_pseudo_type_info(ModuleInfo, ArgTypeRttiData, PTIInit, SubDefns),
 	RttiName = notag_functor_desc,
 	RttiId = ctor_rtti_id(RttiTypeCtor, RttiName),
-	Init = init_struct(mlds__rtti_type(RttiId), [
+	Init = init_struct(mlds__rtti_type(item_type(RttiId)), [
 		gen_init_string(FunctorName),
-		gen_init_cast_rtti_data(mlds__pseudo_type_info_type,
-			ModuleName, ArgTypeRttiData),
+		PTIInit,
 		gen_init_maybe(ml_string_type, gen_init_string, MaybeArgName)
 	]),
 	rtti_id_and_init_to_defn(RttiId, Init, MLDS_Defn),
-	RealRttiDatas = list__filter(real_rtti_data, [ArgTypeRttiData]),
-	SubDefnsList = list__map(rtti_data_to_mlds(ModuleInfo), RealRttiDatas),
-	SubDefns = list__condense(SubDefnsList),
 	MLDS_Defns = [MLDS_Defn | SubDefns].
 
 :- func gen_du_functor_desc(module_info, rtti_type_ctor, du_functor)
@@ -464,8 +622,8 @@
 		ArgInfos = [],
 		ArgTypeDefns = [],
 		ArgTypeInit = gen_init_null_pointer(
-			mlds__rtti_type(
-				ctor_rtti_id(RttiTypeCtor, field_types(0))))
+			mlds__rtti_type(item_type(
+				ctor_rtti_id(RttiTypeCtor, field_types(0)))))
 	),
 	(
 		ArgNames = [_ | _],
@@ -478,8 +636,8 @@
 		ArgNames = [],
 		ArgNameDefns = [],
 		ArgNameInit = gen_init_null_pointer(
-			mlds__rtti_type(
-				ctor_rtti_id(RttiTypeCtor, field_names(0))))
+			mlds__rtti_type(item_type(
+				ctor_rtti_id(RttiTypeCtor, field_names(0)))))
 	),
 	(
 		MaybeExistInfo = yes(ExistInfo),
@@ -491,8 +649,8 @@
 		MaybeExistInfo = no,
 		ExistInfoDefns = [],
 		ExistInfoInit = gen_init_null_pointer(
-			mlds__rtti_type(
-				ctor_rtti_id(RttiTypeCtor, exist_info(0))))
+			mlds__rtti_type(item_type(
+				ctor_rtti_id(RttiTypeCtor, exist_info(0)))))
 	),
 	SubDefns = list__condense([ArgTypeDefns, ArgNameDefns,
 		ExistInfoDefns]),
@@ -515,7 +673,7 @@
 	),
 	RttiName = du_functor_desc(Ordinal),
 	RttiId = ctor_rtti_id(RttiTypeCtor, RttiName),
-	Init = init_struct(mlds__rtti_type(RttiId), [
+	Init = init_struct(mlds__rtti_type(item_type(RttiId)), [
 		gen_init_string(FunctorName),
 		gen_init_int(Arity),
 		gen_init_int(ContainsVarBitVector),
@@ -537,7 +695,7 @@
 	ResFunctor = reserved_functor(FunctorName, Ordinal, ReservedAddress),
 	RttiName = res_functor_desc(Ordinal),
 	RttiId = ctor_rtti_id(RttiTypeCtor, RttiName),
-	Init = init_struct(mlds__rtti_type(RttiId), [
+	Init = init_struct(mlds__rtti_type(item_type(RttiId)), [
 		gen_init_string(FunctorName),
 		gen_init_int(Ordinal),
 		gen_init_reserved_address(ModuleInfo, ReservedAddress)
@@ -573,7 +731,7 @@
 		SlotInTci = -1
 	),
 	RttiId = ctor_rtti_id(RttiTypeCtor, exist_locn),
-	Init = init_struct(mlds__rtti_type(RttiId), [
+	Init = init_struct(mlds__rtti_type(item_type(RttiId)), [
 		gen_init_int(SlotInCell),
 		gen_init_int(SlotInTci)
 	]).
@@ -586,25 +744,84 @@
 	RttiName = exist_locns(Ordinal),
 	rtti_name_and_init_to_defn(RttiTypeCtor, RttiName, Init, MLDS_Defn).
 
+:- pred gen_tc_constraint(module_info::in,
+	pred(int, int, rtti_id)::in(pred(in, in, out) is det),
+	tc_constraint::in, rtti_id::out, counter::in, counter::out,
+	list(mlds__defn)::in, list(mlds__defn)::out) is det.
+
+gen_tc_constraint(ModuleInfo, MakeRttiId, Constraint, RttiId, !Counter,
+		!Defns) :-
+	Constraint = tc_constraint(TCName, Types),
+	list__length(Types, Arity),
+	counter__allocate(TCNum, !Counter),
+	MakeRttiId(TCNum, Arity, RttiId),
+	TCDeclRttiName = type_class_decl(TCName),
+	module_info_name(ModuleInfo, ModuleName),
+	TypeRttiDatas = list__map(maybe_pseudo_type_info_to_rtti_data, Types),
+	gen_pseudo_type_info_array(ModuleInfo, TypeRttiDatas, PTIInits,
+		PTIDefns),
+ 	Init = init_struct(mlds__rtti_type(item_type(RttiId)), [
+		gen_init_tc_rtti_name(ModuleName, TCDeclRttiName),
+		PTIInits
+ 	]),
+	rtti_id_and_init_to_defn(RttiId, Init, ConstrDefn),
+	list__append(PTIDefns, [ConstrDefn], NewDefns),
+	list__append(!.Defns, NewDefns, !:Defns).
+
+:- pred make_exist_tc_constr_id(rtti_type_ctor::in, int::in, int::in, int::in,
+	rtti_id::out) is det.
+
+make_exist_tc_constr_id(RttiTypeCtor, Ordinal, TCNum, Arity, RttiId) :-
+	RttiName = exist_tc_constr(Ordinal, TCNum, Arity),
+	RttiId = ctor_rtti_id(RttiTypeCtor, RttiName).
+
 :- func gen_exist_info(module_info, rtti_type_ctor, int, exist_info)
 	= list(mlds__defn).
 
 gen_exist_info(ModuleInfo, RttiTypeCtor, Ordinal, ExistInfo) = MLDS_Defns :-
-	ExistInfo = exist_info(Plain, InTci, Tci, Locns),
+	ExistInfo = exist_info(Plain, InTci, Constraints, Locns),
 	module_info_name(ModuleInfo, ModuleName),
 	RttiName = exist_info(Ordinal),
 	RttiId = ctor_rtti_id(RttiTypeCtor, RttiName),
- 	Init = init_struct(mlds__rtti_type(RttiId), [
+	list__length(Constraints, Tci),
+	(
+		Constraints = [],
+		ConstrInit = gen_init_null_pointer(
+			mlds__rtti_type(item_type(ctor_rtti_id(RttiTypeCtor,
+				exist_tc_constrs(Ordinal))))),
+		ConstrDefns = []
+	;
+		Constraints = [_ | _],
+		ConstrInit = gen_init_rtti_name(ModuleName, RttiTypeCtor,
+			exist_tc_constrs(Ordinal)),
+		list__map_foldl2(gen_tc_constraint(ModuleInfo,
+			make_exist_tc_constr_id(RttiTypeCtor, Ordinal)),
+			Constraints, TCConstrIds, counter__init(1), _,
+			[], TCConstrDefns),
+		TCConstrArrayRttiName = exist_tc_constrs(Ordinal),
+		TCConstrArrayRttiId = ctor_rtti_id(RttiTypeCtor,
+			TCConstrArrayRttiName),
+		ElementType = mlds__rtti_type(
+			element_type(TCConstrArrayRttiId)),
+		TCConstrArrayInit = gen_init_array(
+			gen_init_cast_rtti_id(ElementType, ModuleName),
+			TCConstrIds),
+		rtti_name_and_init_to_defn(RttiTypeCtor, TCConstrArrayRttiName,
+			TCConstrArrayInit, TCConstrArrayDefn),
+		list__append(TCConstrDefns, [TCConstrArrayDefn], ConstrDefns)
+	),
+ 	Init = init_struct(mlds__rtti_type(item_type(RttiId)), [
  		gen_init_int(Plain),
  		gen_init_int(InTci),
  		gen_init_int(Tci),
  		gen_init_rtti_name(ModuleName, RttiTypeCtor,
-			exist_locns(Ordinal))
+			exist_locns(Ordinal)),
+		ConstrInit
  	]),
 	rtti_id_and_init_to_defn(RttiId, Init, MLDS_Defn),
-	Sub_Defn = gen_exist_locns_array(ModuleInfo, RttiTypeCtor, Ordinal,
+	LocnsDefn = gen_exist_locns_array(ModuleInfo, RttiTypeCtor, Ordinal,
 		Locns),
-	MLDS_Defns = [MLDS_Defn, Sub_Defn].
+	MLDS_Defns = [MLDS_Defn, LocnsDefn | ConstrDefns].
 
 :- func gen_field_names(module_info, rtti_type_ctor, int, list(maybe(string)))
 	= mlds__defn.
@@ -622,17 +839,11 @@
 	list(rtti_maybe_pseudo_type_info_or_self)) = list(mlds__defn).
 
 gen_field_types(ModuleInfo, RttiTypeCtor, Ordinal, Types) = MLDS_Defns :-
-	module_info_name(ModuleInfo, ModuleName),
 	TypeRttiDatas = list__map(maybe_pseudo_type_info_or_self_to_rtti_data,
 		Types),
-	Init = gen_init_array(
-		gen_init_cast_rtti_data(mlds__pseudo_type_info_type,
-		ModuleName), TypeRttiDatas),
+	gen_pseudo_type_info_array(ModuleInfo, TypeRttiDatas, Init, SubDefns),
 	RttiName = field_types(Ordinal),
 	rtti_name_and_init_to_defn(RttiTypeCtor, RttiName, Init, MLDS_Defn),
-	RealRttiDatas = list__filter(real_rtti_data, TypeRttiDatas),
-	SubDefnsList = list__map(rtti_data_to_mlds(ModuleInfo), RealRttiDatas),
-	SubDefns = list__condense(SubDefnsList),
 	MLDS_Defns = [MLDS_Defn | SubDefns].
 
 %-----------------------------------------------------------------------------%
@@ -676,13 +887,15 @@
 			% reserved tag first.
 		RttiElemName = du_ptag_layout(0),
 		RttiElemId = ctor_rtti_id(RttiTypeCtor, RttiElemName),
-		PtagInitPrefix = [init_struct(mlds__rtti_type(RttiElemId), [
-			gen_init_int(0),
+		PtagInitPrefix = [
+			init_struct(mlds__rtti_type(item_type(RttiElemId)),
+			[gen_init_int(0),
 			gen_init_builtin_const("MR_SECTAG_VARIABLE"),
 			gen_init_null_pointer(
-				mlds__rtti_type(ctor_rtti_id(RttiTypeCtor,
-					du_stag_ordered_table(0))))
-		])],
+				mlds__rtti_type(item_type(
+					ctor_rtti_id(RttiTypeCtor,
+						du_stag_ordered_table(0)))))]
+		)],
 		FirstPtag = 1
 	; PtagList = [0 - _ | _] ->
 		PtagInitPrefix = [],
@@ -711,7 +924,7 @@
 	SectagTable = sectag_table(SectagLocn, NumSharers, _SectagMap),
 	RttiName = du_ptag_layout(Ptag),
 	RttiId = ctor_rtti_id(RttiTypeCtor, RttiName),
-	Init = init_struct(mlds__rtti_type(RttiId), [
+	Init = init_struct(mlds__rtti_type(item_type(RttiId)), [
 		gen_init_int(NumSharers),
 		gen_init_sectag_locn(SectagLocn),
 		gen_init_rtti_name(ModuleName, RttiTypeCtor,
@@ -775,7 +988,7 @@
 	SubDefns = list__condense([ResDefns, ResAddrDefns, DuDefns]),
 	RttiName = res_value_ordered_table,
 	RttiId = ctor_rtti_id(RttiTypeCtor, RttiName),
-	Init = init_struct(mlds__rtti_type(RttiId), [
+	Init = init_struct(mlds__rtti_type(item_type(RttiId)), [
 		gen_init_int(NumNumericResFunctorReps),
 		gen_init_int(NumSymbolicResFunctorReps),
 		ResAddrInit,
@@ -828,7 +1041,7 @@
 		MaybeResFunctor) = Init :-
 	RttiName = maybe_res_addr_functor_desc,
 	RttiId = ctor_rtti_id(RttiTypeCtor, RttiName),
-	Type = mlds__rtti_type(RttiId),
+	Type = mlds__rtti_type(item_type(RttiId)),
 	(
 		MaybeResFunctor = res_func(ResFunctor),
 		Name = ResFunctor ^ res_name,
@@ -855,16 +1068,20 @@
 
 :- func gen_init_rtti_names_array(module_name, rtti_type_ctor,
 		list(ctor_rtti_name)) = mlds__initializer.
+
 gen_init_rtti_names_array(ModuleName, RttiTypeCtor, RttiNames) =
-	gen_init_array(gen_init_rtti_name(ModuleName, RttiTypeCtor), RttiNames).
+	gen_init_array(gen_init_rtti_name(ModuleName, RttiTypeCtor),
+		RttiNames).
 
 :- func gen_init_rtti_datas_array(module_name, list(rtti_data)) =
 	mlds__initializer.
+
 gen_init_rtti_datas_array(ModuleName, RttiDatas) =
 	gen_init_array(gen_init_rtti_data(ModuleName), RttiDatas).
 
 :- func gen_init_cast_rtti_datas_array(mlds__type, module_name,
 		list(rtti_data)) = mlds__initializer.
+
 gen_init_cast_rtti_datas_array(Type, ModuleName, RttiDatas) =
 	gen_init_array(gen_init_cast_rtti_data(Type, ModuleName), RttiDatas).
 
@@ -886,9 +1103,9 @@
 		RttiData = base_typeclass_info(InstanceModuleName, ClassId,
 			InstanceString, _)
 	->
-		SrcType = rtti_type(tc_rtti_id(
+		SrcType = rtti_type(item_type(tc_rtti_id(
 			base_typeclass_info(InstanceModuleName,
-			ClassId, InstanceString))),
+			ClassId, InstanceString)))),
 		MLDS_ModuleName = mercury_module_name_to_mlds(
 			InstanceModuleName),
 		MLDS_DataName = rtti(tc_rtti_id(
@@ -906,6 +1123,7 @@
 
 	% currently casts only store the destination type
 :- func gen_cast(mlds__type, mlds__type) = mlds__unary_op.
+
 gen_cast(_SrcType, DestType) = cast(DestType).
 
 	% Generate the MLDS initializer comprising the rtti_name
@@ -918,8 +1136,7 @@
 
 	% Generate an MLDS initializer comprising just the
 	% the rval for a given rtti_id
-:- func gen_init_rtti_id(module_name, rtti_id) =
-	mlds__initializer.
+:- func gen_init_rtti_id(module_name, rtti_id) = mlds__initializer.
 
 gen_init_rtti_id(ModuleName, ctor_rtti_id(RttiTypeCtor, RttiName)) =
 	gen_init_rtti_name(ModuleName, RttiTypeCtor, RttiName).
@@ -948,7 +1165,7 @@
 	= mlds__initializer.
 
 gen_init_cast_rtti_id(DestType, ModuleName, RttiId) = Initializer :-
-	SrcType = rtti_type(RttiId), 
+	SrcType = rtti_type(item_type(RttiId)), 
 	Initializer = init_obj(unop(gen_cast(SrcType, DestType),
 		gen_rtti_id(ModuleName, RttiId))).
 
@@ -1061,11 +1278,48 @@
 
 %-----------------------------------------------------------------------------%
 
-:- pred gen_init_method(module_info, int, rtti_proc_label, mlds__initializer,
-		list(mlds__defn), list(mlds__defn)).
-:- mode gen_init_method(in, in, in, out, in, out) is det.
+:- pred gen_pseudo_type_info(module_info::in, rtti_data::in,
+	mlds__initializer::out, list(mlds__defn)::out) is det.
+
+gen_pseudo_type_info(ModuleInfo, PTIRttiData, Init, Defns) :-
+	RealRttiDatas = list__filter(real_rtti_data, [PTIRttiData]),
+	DefnLists = list__map(rtti_data_to_mlds(ModuleInfo), RealRttiDatas),
+	Defns = list__condense(DefnLists),
+	module_info_name(ModuleInfo, ModuleName),
+	Init = gen_init_cast_rtti_data(mlds__pseudo_type_info_type,
+		ModuleName, PTIRttiData).
+
+:- pred gen_pseudo_type_info_array(module_info::in, list(rtti_data)::in,
+	mlds__initializer::out, list(mlds__defn)::out) is det.
+
+gen_pseudo_type_info_array(ModuleInfo, PTIRttiDatas, Init, Defns) :-
+	RealRttiDatas = list__filter(real_rtti_data, PTIRttiDatas),
+	DefnLists = list__map(rtti_data_to_mlds(ModuleInfo), RealRttiDatas),
+	Defns = list__condense(DefnLists),
+	module_info_name(ModuleInfo, ModuleName),
+	Init = gen_init_cast_rtti_datas_array(mlds__pseudo_type_info_type,
+		ModuleName, PTIRttiDatas).
 
-gen_init_method(ModuleInfo, NumExtra, RttiProcId, Init, !ExtraDefns) :-
+:- pred gen_pseudo_type_info_list(module_info::in, list(rtti_data)::in,
+	list(mlds__initializer)::out, list(mlds__defn)::out) is det.
+
+gen_pseudo_type_info_list(ModuleInfo, PTIRttiDatas, Inits, Defns) :-
+	RealRttiDatas = list__filter(real_rtti_data, PTIRttiDatas),
+	DefnLists = list__map(rtti_data_to_mlds(ModuleInfo), RealRttiDatas),
+	Defns = list__condense(DefnLists),
+	module_info_name(ModuleInfo, ModuleName),
+	Inits = list__map(
+		gen_init_cast_rtti_data(mlds__pseudo_type_info_type,
+			ModuleName),
+		PTIRttiDatas).
+
+%-----------------------------------------------------------------------------%
+
+:- pred gen_init_method(module_info::in, int::in, rtti_proc_label::in,
+	mlds__initializer::out, list(mlds__defn)::in, list(mlds__defn)::out)
+	is det.
+
+gen_init_method(ModuleInfo, NumExtra, RttiProcLabel, Init, !ExtraDefns) :-
 	%
 	% we can't store the address of the typeclass method directly in
 	% the base_typeclass_info; instead, we need to generate
@@ -1080,7 +1334,7 @@
 	% Hopefully the Mercury HLDS->HLDS inlining and/or
 	% the target code compiler will be able to optimize this...
 	%
-	gen_wrapper_func_and_initializer(ModuleInfo, NumExtra, RttiProcId,
+	gen_wrapper_func_and_initializer(ModuleInfo, NumExtra, RttiProcLabel,
 			typeclass_info_closure, Init, !ExtraDefns).
 
 :- pred gen_init_special_pred(module_info::in, univ::in, mlds__initializer::out,
@@ -1206,6 +1460,11 @@
 % The rvals generated are just named constants in
 % the private_builtin module, which the Mercury
 % runtime is expected to define.
+
+:- func gen_init_pred_or_func(pred_or_func) = mlds__initializer.
+
+gen_init_pred_or_func(PredOrFunc) = gen_init_builtin_const(Name) :-
+	rtti__pred_or_func_to_string(PredOrFunc, Name).
 
 :- func gen_init_sectag_locn(sectag_locn) = mlds__initializer.
 
Index: compiler/type_class_info.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/type_class_info.m,v
retrieving revision 1.2
diff -u -b -r1.2 type_class_info.m
--- compiler/type_class_info.m	24 Oct 2003 06:17:50 -0000	1.2
+++ compiler/type_class_info.m	23 Jan 2004 01:04:15 -0000
@@ -8,9 +8,9 @@
 % that hold the data structures representing the type class and instance
 % declarations in the current module.
 %
-% For now, this module is not invoked by default, and the data structures it
-% generates are used only by the debugger to inform the user, not by the
-% runtime system to invoke type class methods.
+% For now, the data structures generated by this module are used only by
+% the debugger to inform the user, not by the runtime system to invoke type
+% class methods.
 %
 % Author: zs.
 %
@@ -22,11 +22,14 @@
 
 :- import_module backend_libs__rtti.
 :- import_module hlds__hlds_module.
+:- import_module parse_tree__prog_data.
+
+:- import_module bool, list.
 
-:- import_module list.
+:- pred type_class_info__generate_rtti(module_info::in, bool::in,
+	list(rtti_data)::out) is det.
 
-:- pred type_class_info__generate_rtti(module_info::in, list(rtti_data)::out)
-	is det.
+:- func generate_class_constraint(class_constraint) = tc_constraint.
 
 :- implementation.
 
@@ -36,26 +39,36 @@
 :- import_module hlds__hlds_pred.
 :- import_module libs__globals.
 :- import_module libs__options.
-:- import_module parse_tree__prog_data.
 :- import_module parse_tree__prog_io.
 :- import_module parse_tree__prog_out.
 :- import_module backend_libs__pseudo_type_info.
 :- import_module backend_libs__base_typeclass_info.
 
-:- import_module bool, int, string, assoc_list, map.
+:- import_module int, string, assoc_list, map.
 :- import_module std_util, require, term, varset.
 
 %---------------------------------------------------------------------------%
 
-generate_rtti(ModuleInfo, RttiDatas) :-
+% We always generate descriptors for type class declarations, since these may
+% be referred to from the descriptors of function symbols with existentially
+% typed arguments. We generate descriptors for type class instances only if
+% requested to generate all the descriptors we can.
+
+generate_rtti(ModuleInfo, GenerateAll, RttiDatas) :-
 	module_info_classes(ModuleInfo, ClassTable),
 	map__to_assoc_list(ClassTable, Classes),
 	list__foldl(generate_class_decl(ModuleInfo), Classes,
 		[], RttiDatas0),
+	(
+		GenerateAll = yes,
 	module_info_instances(ModuleInfo, InstanceTable),
 	map__to_assoc_list(InstanceTable, Instances),
 	list__foldl(generate_instance_decls(ModuleInfo), Instances,
-		RttiDatas0, RttiDatas).
+			RttiDatas0, RttiDatas)
+	;
+		GenerateAll = no,
+		RttiDatas = RttiDatas0
+	).
 
 %---------------------------------------------------------------------------%
 
@@ -179,8 +192,6 @@
 		error("generate_class_name: unqualified sym_name")
 	),
 	TCName = tc_name(ModuleName, ClassName, Arity).
-
-:- func generate_class_constraint(class_constraint) = tc_constraint.
 
 generate_class_constraint(constraint(ClassName, Types)) = TCConstr :-
 	Arity = list__length(Types),
Index: compiler/type_ctor_info.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/type_ctor_info.m,v
retrieving revision 1.51
diff -u -b -r1.51 type_ctor_info.m
--- compiler/type_ctor_info.m	21 Dec 2003 05:04:38 -0000	1.51
+++ compiler/type_ctor_info.m	22 Jan 2004 01:14:58 -0000
@@ -62,6 +62,7 @@
 :- import_module backend_libs__builtin_ops.
 :- import_module backend_libs__pseudo_type_info.
 :- import_module backend_libs__rtti.
+:- import_module backend_libs__type_class_info.
 :- import_module check_hlds__type_util.
 :- import_module hlds__error_util.
 :- import_module hlds__hlds_code_util.
@@ -809,11 +810,11 @@
 	list__foldl(
 		find_type_info_index(Constraints, ClassTable, TIsPlain),
 		ConstrainedTvars, LocnMap1, LocnMap),
-	list__length(Constraints, TCIs),
+	TCConstraints = list__map(generate_class_constraint, Constraints),
 	list__map((pred(Tvar::in, Locn::out) is det :-
 		map__lookup(LocnMap, Tvar, Locn)),
 		ExistTvars, ExistLocns),
-	ExistInfo = exist_info(TIsPlain, TIsInTCIs, TCIs, ExistLocns).
+	ExistInfo = exist_info(TIsPlain, TIsInTCIs, TCConstraints, ExistLocns).
 
 :- pred find_type_info_index(list(class_constraint)::in, class_table::in,
 	int::in, tvar::in, map(tvar, exist_typeinfo_locn)::in,
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/aditi
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/concurrency
cvs diff: Diffing extras/curs
cvs diff: Diffing extras/curs/samples
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/error
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/lex/tests
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/quickcheck
cvs diff: Diffing extras/quickcheck/tutes
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/stream
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing java
cvs diff: Diffing java/library
cvs diff: Diffing java/runtime
cvs diff: Diffing library
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
Index: runtime/mercury_proc_id.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_proc_id.h,v
retrieving revision 1.1
diff -u -b -r1.1 mercury_proc_id.h
--- runtime/mercury_proc_id.h	20 Oct 2003 07:29:32 -0000	1.1
+++ runtime/mercury_proc_id.h	24 Jan 2004 02:17:26 -0000
@@ -10,6 +10,7 @@
 #define MERCURY_PROC_ID_H
 
 #include "mercury_types.h"		/* for MR_ConstString etc */
+#include "mercury_tags.h"		/* for MR_DEFINE_BUILTIN_ENUM_CONST */
 
 /*
 ** This type indicates whether a procedure came from a predicate or a function.
@@ -17,7 +18,10 @@
 ** in browser/util.m.
 */
 
-typedef	enum { MR_PREDICATE, MR_FUNCTION } MR_PredFunc;
+typedef	enum {
+	MR_DEFINE_BUILTIN_ENUM_CONST(MR_PREDICATE),
+	MR_DEFINE_BUILTIN_ENUM_CONST(MR_FUNCTION)
+} MR_PredFunc;
 
 /*
 ** MR_Proc_Id is a union. The usual alternative identifies ordinary
Index: runtime/mercury_tags.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_tags.h,v
retrieving revision 1.17
diff -u -b -r1.17 mercury_tags.h
--- runtime/mercury_tags.h	20 Oct 2003 07:29:32 -0000	1.17
+++ runtime/mercury_tags.h	24 Jan 2004 02:31:12 -0000
@@ -15,6 +15,7 @@
 #include <limits.h>		/* for `CHAR_BIT' */
 #include "mercury_conf.h"	/* for `MR_LOW_TAG_BITS' */
 #include "mercury_types.h"	/* for `MR_Word' */
+#include "mercury_std.h"	/* for `MR_PASTE2' */
 
 /* DEFINITIONS FOR WORD LAYOUT */
 
@@ -306,5 +307,22 @@
 	#define MR_DEFINE_MERCURY_ENUM_CONST(x)	x
 
 #endif
+
+/*
+** For each enumeration constant defined in the runtime (not in Mercury)
+** that we need the compiler to be able to generate, we define it using two
+** names; first we define the unqualified name, and then we define
+** another enumeration constant whose name is the unqualified name
+** prefixed with `mercury__private_builtin__' and whose value is
+** the same as that of the unqualified name.
+** The qualified versions are used by the MLDS->C back-end,
+** which generates references to them.
+*/
+
+#define MR_DEFINE_BUILTIN_ENUM_CONST(x) \
+        MR_PASTE2(x, _val),     \
+        x = MR_CONVERT_C_ENUM_CONSTANT(MR_PASTE2(x, _val)), \
+        MR_PASTE2(mercury__private_builtin__,x) = x, \
+        MR_PASTE2(x, _dummy) = MR_PASTE2(x, _val)
 
 #endif	/* not MERCURY_TAGS_H */
Index: runtime/mercury_type_info.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_type_info.h,v
retrieving revision 1.109
diff -u -b -r1.109 mercury_type_info.h
--- runtime/mercury_type_info.h	21 Jan 2004 02:52:37 -0000	1.109
+++ runtime/mercury_type_info.h	23 Jan 2004 21:50:21 -0000
@@ -58,7 +58,7 @@
 
 #include "mercury_std.h"    /* for `MR_STRINGIFY', `MR_PASTEn' and MR_CALL */
 #include "mercury_types.h"  /* for `MR_Word' */
-#include "mercury_tags.h"   /* for `MR_CONVERT_C_ENUM_CONSTANT' */
+#include "mercury_tags.h"   /* for `MR_DEFINE_BUILTIN_ENUM_CONST' */
 #include "mercury_hlc_types.h" /* for `MR_Mercury_Type_Info' */
 
 /*---------------------------------------------------------------------------*/
@@ -559,22 +559,6 @@
 */
 
 /*
-** For each enumeration constant, we define it using two names;
-** first we define the unqualified name, and then we define
-** another enumeration constant whose name is the unqualified name
-** prefixed with `mercury__private_builtin__' and whose value is
-** the same as that of the unqualified name.
-** The qualified versions are used by the MLDS->C back-end,
-** which generates references to them.
-*/
-
-#define MR_DEFINE_BUILTIN_ENUM_CONST(x) \
-        MR_PASTE2(x, _val),     \
-        x = MR_CONVERT_C_ENUM_CONSTANT(MR_PASTE2(x, _val)), \
-        MR_PASTE2(mercury__private_builtin__,x) = x, \
-        MR_PASTE2(x, _dummy) = MR_PASTE2(x, _val)
-
-/*
 ** MR_TypeCtorRep specifies the representation scheme for a particular type
 ** constructor.
 **
@@ -702,6 +686,44 @@
 /*---------------------------------------------------------------------------*/
 
 /*
+** A typeclass constraint asserts the membership of a possibly nonground
+** vector of types in a type class, as one may find constraining a typeclass
+** declaration, an instance declaration, or a predicate/function declaration.
+**
+** Type class constraints for type classes with arity N will be of type
+** MR_TypeClassConstraint_N. Generic code will manipulate them as if they were
+** of type MR_TypeClassConstraint, getting the actual number of arguments from
+** MR_tc_constr_type_class_info->MR_tc_decl_id->MR_tc_id_arity.
+**
+** Note that the arity cannot be zero, so we do not have to worry about
+** zero-size arrays. On the other hand, type classes with more than even two
+** arguments can be expected to be very rare, so having five as a fixed limit
+** should not be a problem. If it is, we can lift the limit by defining
+** MR_TypeClassConstraint_N on demand for all N > 5.
+**
+** We will have to rethink this structure once we start supporting constructor
+** classes.
+*/
+
+#define MR_DEFINE_TYPECLASS_CONSTRAINT_STRUCT(NAME, ARITY)                  \
+    typedef struct MR_PASTE2(NAME, _Struct) {                               \
+        MR_TypeClassDecl    MR_tc_constr_type_class;                        \
+        MR_PseudoTypeInfo   MR_tc_constr_arg_ptis[ARITY];                   \
+    } MR_PASTE2(NAME, Struct)
+
+MR_DEFINE_TYPECLASS_CONSTRAINT_STRUCT(MR_TypeClassConstraint_1, 1);
+MR_DEFINE_TYPECLASS_CONSTRAINT_STRUCT(MR_TypeClassConstraint_2, 2);
+MR_DEFINE_TYPECLASS_CONSTRAINT_STRUCT(MR_TypeClassConstraint_3, 3);
+MR_DEFINE_TYPECLASS_CONSTRAINT_STRUCT(MR_TypeClassConstraint_4, 4);
+MR_DEFINE_TYPECLASS_CONSTRAINT_STRUCT(MR_TypeClassConstraint_5, 5);
+
+typedef MR_TypeClassConstraint_5Struct          MR_TypeClassConstraintStruct;
+typedef const MR_TypeClassConstraintStruct      *MR_TypeClassConstraint;
+
+#define MR_STD_TYPECLASS_CONSTRAINT_ADDR(p) \
+        ((MR_TypeClassConstraint) &((p).MR_tc_constr_type_class_info))
+
+/*
 ** The argument number field gives the offset in the cell (in a form in which
 ** it can be given to the MR_field macro directly) of either of the typeinfo
 ** itself or of the typeclassinfo containing the typeinfo. If the former,
@@ -740,6 +762,11 @@
 ** The typeinfo for type variable N will be at the offset
 ** N - MR_PSEUDOTYPEINFO_EXIST_VAR_BASE - 1. (The one is subtracted to convert
 ** from type var numbering, which starts at 1, to array offset numbering).
+**
+** The MR_exist_constraints field points to an array of type class constraints
+** (each of which is a pointer to a type class constraint structure). The array
+** contains MR_exist_tci elements, giving the constraint from which each
+** typeclass_info in the functor is derived.
 */
 
 typedef struct {
@@ -747,6 +774,7 @@
     MR_int_least16_t        MR_exist_typeinfos_in_tci;
     MR_int_least16_t        MR_exist_tcis;
     const MR_DuExistLocn    *MR_exist_typeinfo_locns;
+    const MR_TypeClassConstraint    *MR_exist_constraints;
 } MR_DuExistInfo;
 
 /*
Index: runtime/mercury_typeclass_info.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_typeclass_info.h,v
retrieving revision 1.3
diff -u -b -r1.3 mercury_typeclass_info.h
--- runtime/mercury_typeclass_info.h	23 Oct 2003 02:02:31 -0000	1.3
+++ runtime/mercury_typeclass_info.h	22 Jan 2004 23:30:31 -0000
@@ -86,53 +86,6 @@
 
 /*****************************************************************************/
 
-typedef       struct MR_TypeClassDecl_Struct            MR_TypeClassDeclStruct;
-typedef const struct MR_TypeClassDecl_Struct            *MR_TypeClassDecl;
-typedef       struct MR_Instance_Struct                 MR_InstanceStruct;
-typedef const struct MR_Instance_Struct                 *MR_Instance;
-typedef       struct MR_DictId_Struct                   MR_DictIdStruct;
-typedef const struct MR_DictId_Struct                   *MR_DictId;
-typedef       struct MR_Dictionary_Struct               MR_DictionaryStruct;
-typedef const struct MR_Dictionary_Struct               *MR_Dictionary;
-
-/*
-** A typeclass constraint asserts the membership of a possibly nonground
-** vector of types in a type class, as one may find constraining a typeclass
-** declaration, an instance declaration, or a predicate/function declaration.
-**
-** Type class constraints for type classes with arity N will be of type
-** MR_TypeClassConstraint_N. Generic code will manipulate them as if they were
-** of type MR_TypeClassConstraint, getting the actual number of arguments from
-** MR_tc_constr_type_class_info->MR_tc_decl_id->MR_tc_id_arity.
-**
-** Note that the arity cannot be zero, so we do not have to worry about
-** zero-size arrays. On the other hand, type classes with more than even two
-** arguments can be expected to be very rare, so having five as a fixed limit
-** should not be a problem. If it is, we can lift the limit by defining
-** MR_TypeClassConstraint_N on demand for all N > 5.
-**
-** We will have to rethink this structure once we start supporting constructor
-** classes.
-*/
-
-#define MR_DEFINE_TYPECLASS_CONSTRAINT_STRUCT(NAME, ARITY)                  \
-    typedef struct MR_PASTE2(NAME, _Struct) {                               \
-        MR_TypeClassDecl    MR_tc_constr_type_class_info;                   \
-        MR_PseudoTypeInfo   MR_tc_constr_arg_ptis[ARITY];                   \
-    } MR_PASTE2(NAME, Struct)
-
-MR_DEFINE_TYPECLASS_CONSTRAINT_STRUCT(MR_TypeClassConstraint_1, 1);
-MR_DEFINE_TYPECLASS_CONSTRAINT_STRUCT(MR_TypeClassConstraint_2, 2);
-MR_DEFINE_TYPECLASS_CONSTRAINT_STRUCT(MR_TypeClassConstraint_3, 3);
-MR_DEFINE_TYPECLASS_CONSTRAINT_STRUCT(MR_TypeClassConstraint_4, 4);
-MR_DEFINE_TYPECLASS_CONSTRAINT_STRUCT(MR_TypeClassConstraint_5, 5);
-
-typedef MR_TypeClassConstraint_5Struct          MR_TypeClassConstraintStruct;
-typedef const MR_TypeClassConstraintStruct      *MR_TypeClassConstraint;
-
-#define MR_STD_TYPECLASS_CONSTRAINT_ADDR(p) \
-        ((MR_TypeClassConstraint) &((p).MR_tc_constr_type_class_info))
-
 /*
 ** We generate one static MR_TypeClassMethod structure for every method in
 ** every typeclass declaration in the program.
@@ -279,10 +232,12 @@
 ** constraints on the instance declaration itself, while the
 ** MR_tc_inst_instance_constraints field gives the constraints themselves.
 **
-** The MR_tc_inst_methods field gives the methods declared by the instance
-** declaration. It points to a vector of code addresses, one for each method;
-** the length of the vector is MR_tc_inst_type_class->MR_tc_decl_id->
-** MR_tc_id_num_methods. The procedures being pointed to may be polymorphic,
+** There will eventually be a MR_tc_inst_methods field, which will give
+** information about the methods declared by the instance declaration.
+** It will point to a vector, with one element for each method;
+** the length of the vector will be MR_tc_inst_type_class->MR_tc_decl_id->
+** MR_tc_id_num_methods. We haven't yet decided what information we will want
+** about each method. Note that the methods may be polymorphic,
 ** for either one of two reasons: the instance declaration may specify
 ** nonground types, and the method may have universally quantified type
 ** variables in its signature in any case.
@@ -294,7 +249,6 @@
     const MR_int_least8_t           MR_tc_inst_num_instance_constraints;
     const MR_PseudoTypeInfo         *MR_tc_inst_type_args;
     const MR_TypeClassConstraint    *MR_tc_inst_instance_constraints;
-    const MR_CodePtr                MR_tc_inst_methods;
 };
 
 /*
Index: runtime/mercury_types.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_types.h,v
retrieving revision 1.35
diff -u -b -r1.35 mercury_types.h
--- runtime/mercury_types.h	23 Oct 2003 02:02:31 -0000	1.35
+++ runtime/mercury_types.h	22 Jan 2004 00:42:12 -0000
@@ -187,6 +187,15 @@
   typedef MR_Code                                       *MR_BaseTypeclassInfo;
 #endif
 
+typedef       struct MR_TypeClassDecl_Struct            MR_TypeClassDeclStruct;
+typedef const struct MR_TypeClassDecl_Struct            *MR_TypeClassDecl;
+typedef       struct MR_Instance_Struct                 MR_InstanceStruct;
+typedef const struct MR_Instance_Struct                 *MR_Instance;
+typedef       struct MR_DictId_Struct                   MR_DictIdStruct;
+typedef const struct MR_DictId_Struct                   *MR_DictId;
+typedef       struct MR_Dictionary_Struct               MR_DictionaryStruct;
+typedef const struct MR_Dictionary_Struct               *MR_Dictionary;
+
 typedef struct MR_Closure_Struct                MR_Closure;
 typedef const MR_Closure                        *MR_ClosurePtr;
 
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/general/string_format
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/grade_subdirs
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/mmc_make
cvs diff: Diffing tests/mmc_make/lib
cvs diff: Diffing tests/recompilation
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
cvs diff: Diffing util
cvs diff: Diffing vim
cvs diff: Diffing vim/after
cvs diff: Diffing vim/ftplugin
cvs diff: Diffing vim/syntax
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list