diff: output superclasses and proofs in HLDS dump

David Glen JEFFERY dgj at cs.mu.OZ.AU
Fri Jun 19 11:46:14 AEST 1998


ler/polymorphism.m:
        When building the type-infos to be packaged inside a typeclass-info,
	        apply the variable type bindings first.
		
		tests/valid/instance_unconstrained_tvar.m:
		        Test case for this.
			tests/valid/Mmakefile:
			        Turn this test on. Also turn another test on which I mistakenly
				        turned off in my previous commit (because the test was failing).
					jjjjkjkjkjkjjggjjoi,

Could someone please review this? (Fergus?)
-------------------------------------------------------------------------------

Estimated hours taken: 2

Add two things to the HLDS dump:
	- Write out the superclass table for the module
	- For each pred, write out the constraint proofs.

compiler/mercury_to_mercury.m:
	Export "output_instance_methods" for use by hlds_out.m.
compiler/hlds_out.m:
	Write out the extra parts of the HLDS dump.

-------------------------------------------------------------------------------

Index: compiler/hlds_out.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/hlds_out.m,v
retrieving revision 1.194
diff -u -t -r1.194 hlds_out.m
--- hlds_out.m	1998/06/09 02:12:55	1.194
+++ hlds_out.m	1998/06/11 06:44:07
@@ -182,7 +182,7 @@
 :- import_module llds_out, prog_out, prog_util, (inst), instmap, trace.
 :- import_module termination, term_errors.
 
-:- import_module int, string, set, std_util, assoc_list.
+:- import_module int, string, set, std_util, assoc_list, multi_map.
 :- import_module term_io, require, getopt.
 
 
@@ -368,7 +368,9 @@
                 module_info_types(Module, TypeTable),
                 module_info_insts(Module, InstTable),
                 module_info_modes(Module, ModeTable),
-                module_info_classes(Module, ClassTable)
+                module_info_classes(Module, ClassTable),
+                module_info_superclasses(Module, SuperClassTable),
+                module_info_instances(Module, InstanceTable)
         },
         io__write_string("\n"),
         hlds_out__write_header(Indent, Module),
@@ -378,6 +380,10 @@
                 hlds_out__write_types(Indent, TypeTable),
                 io__write_string("\n"),
                 hlds_out__write_classes(Indent, ClassTable),
+                io__write_string("\n"),
+                hlds_out__write_superclasses(Indent, SuperClassTable),
+                io__write_string("\n"),
+                hlds_out__write_instances(Indent, InstanceTable),
                 io__write_string("\n")
         ;
                 []
@@ -485,6 +491,7 @@
         { pred_info_get_markers(PredInfo, Markers) },
         { pred_info_get_is_pred_or_func(PredInfo, PredOrFunc) },
         { pred_info_get_class_context(PredInfo, ClassContext) },
+        { pred_info_get_constraint_proofs(PredInfo, Proofs) },
         { pred_info_get_purity(PredInfo, Purity) },
         globals__io_lookup_string_option(verbose_dump_hlds, Verbose),
         ( { string__contains_char(Verbose, 'C') } ->
@@ -513,6 +520,13 @@
                         io__write_string("% markers:"),
                         hlds_out__write_marker_list(MarkerList),
                         io__write_string("\n")
+                ),
+                ( { map__is_empty(Proofs) } ->
+                        []
+                ;
+                        hlds_out__write_constraint_proofs(Indent, VarSet,
+                                Proofs),
+                        io__write_string("\n")
                 )
         ;
                 []
@@ -2043,6 +2057,139 @@
 
 %-----------------------------------------------------------------------------%
 
+:- pred hlds_out__write_superclasses(int, superclass_table, 
+        io__state, io__state).
+:- mode hlds_out__write_superclasses(in, in, di, uo) is det.
+
+hlds_out__write_superclasses(Indent, SuperClassTable) -->
+        hlds_out__write_indent(Indent),
+        io__write_string("%-------- Super Classes --------\n"),
+        { multi_map__to_assoc_list(SuperClassTable, SuperClassTableList) },
+        io__write_list(SuperClassTableList, "\n\n",
+                hlds_out__write_superclass(Indent)),
+        io__nl.
+
+:- pred hlds_out__write_superclass(int, pair(class_id, list(subclass_details)), 
+                        io__state, io__state).
+:- mode hlds_out__write_superclass(in, in, di, uo) is det.
+
+hlds_out__write_superclass(Indent, ClassId - SubClassDetailsList) -->
+        hlds_out__write_indent(Indent),
+        io__write_string("% "),
+
+        { ClassId = class_id(SymName, Arity) },
+        prog_out__write_sym_name(SymName),
+        io__write_string("/"),
+        io__write_int(Arity),
+        io__write_string(":\n"),
+
+        io__write_list(SubClassDetailsList, "\n",
+                hlds_out__write_subclass_details(Indent, ClassId)).
+
+:- pred hlds_out__write_subclass_details(int, class_id, subclass_details, 
+                        io__state, io__state).
+:- mode hlds_out__write_subclass_details(in, in, in, di, uo) is det.
+
+hlds_out__write_subclass_details(Indent, SuperClassId, SubClassDetails) -->
+        { SubClassDetails = subclass_details(SuperClassVars, SubClassId,
+                SubClassVars, VarSet) },
+
+                % curry the varset for term_io__write_variable/4
+        { PrintVar = lambda([VarName::in, IO0::di, IO::uo] is det,
+                        term_io__write_variable(VarName, VarSet, IO0, IO)
+                ) },
+        hlds_out__write_indent(Indent),
+        io__write_string("% "),
+        { SubClassId = class_id(SubSymName, _SubArity) },
+        prog_out__write_sym_name(SubSymName),
+        io__write_char('('),
+        io__write_list(SubClassVars, ", ", PrintVar),
+        io__write_string(") <= "),
+
+        { SuperClassId = class_id(SuperSymName, _SuperArity) },
+        prog_out__write_sym_name(SuperSymName),
+        io__write_char('('),
+        io__write_list(SuperClassVars, ", ", PrintVar),
+        io__write_char(')').
+
+%-----------------------------------------------------------------------------%
+
+:- pred hlds_out__write_instances(int, instance_table, io__state, io__state).
+:- mode hlds_out__write_instances(in, in, di, uo) is det.
+
+hlds_out__write_instances(Indent, InstanceTable) -->
+        hlds_out__write_indent(Indent),
+        io__write_string("%-------- Instances --------\n"),
+        { map__to_assoc_list(InstanceTable, InstanceTableList) },
+        io__write_list(InstanceTableList, "\n\n",
+                hlds_out__write_instance_defns(Indent)),
+        io__nl.
+
+:- pred hlds_out__write_instance_defns(int, 
+        pair(class_id, list(hlds_instance_defn)), io__state, io__state).
+:- mode hlds_out__write_instance_defns(in, in, di, uo) is det.
+
+hlds_out__write_instance_defns(Indent, ClassId - InstanceDefns) -->
+        hlds_out__write_indent(Indent),
+        io__write_string("% "),
+
+        { ClassId = class_id(SymName, Arity) },
+        prog_out__write_sym_name(SymName),
+        io__write_string("/"),
+        io__write_int(Arity),
+        io__write_string(":\n"),
+
+        io__write_list(InstanceDefns, "\n",
+                hlds_out__write_instance_defn(Indent)).
+
+:- pred hlds_out__write_instance_defn(int, hlds_instance_defn, 
+                        io__state, io__state).
+:- mode hlds_out__write_instance_defn(in, in, di, uo) is det.
+
+hlds_out__write_instance_defn(Indent, InstanceDefn) -->
+
+        { InstanceDefn = hlds_instance_defn(_, Constraints, Types, Interface,
+                _MaybeClassInterface, VarSet, Proofs) },
+
+        /*
+        { term__context_file(Context, FileName) },
+        { term__context_line(Context, LineNumber) },
+        ( { FileName \= "" } ->
+                hlds_out__write_indent(Indent),
+                io__write_string("% context: file `"),
+                io__write_string(FileName),
+                io__write_string("', line "),
+                io__write_int(LineNumber),
+                io__write_string("\n")
+        ;
+                []
+        ),
+        */
+
+                % curry the varset for term_io__write_variable/4
+        { PrintTerm = lambda([TypeName::in, IO0::di, IO::uo] is det,
+                        term_io__write_term(VarSet, TypeName, IO0, IO)
+                ) },
+        hlds_out__write_indent(Indent),
+        io__write_string("% Types: "),
+        io__write_list(Types, ", ", PrintTerm),
+        io__nl,
+
+        hlds_out__write_indent(Indent),
+        io__write_string("% Constraints: "),
+        io__write_list(Constraints, ", ",  mercury_output_constraint(VarSet)),
+        io__nl,
+
+        hlds_out__write_indent(Indent),
+        io__write_string("% Instance Methods: "),
+        mercury_output_instance_methods(Interface),
+        io__nl,
+
+        hlds_out__write_constraint_proofs(Indent, VarSet, Proofs),
+        io__nl.
+
+%-----------------------------------------------------------------------------%
+
 :- pred hlds_out__write_insts(int, inst_table, io__state, io__state).
 :- mode hlds_out__write_insts(in, in, di, uo) is det.
 
@@ -2292,5 +2439,36 @@
                 hlds_out__write_indent(Indent1)
         ).
 
+%-----------------------------------------------------------------------------%
+:- pred hlds_out__write_constraint_proofs(int, varset,
+        map(class_constraint, constraint_proof), io__state, io__state).
+:- mode hlds_out__write_constraint_proofs(in, in, in, di, uo) is det.
+
+hlds_out__write_constraint_proofs(Indent, VarSet, Proofs) -->
+        hlds_out__write_indent(Indent),
+        io__write_string("% Proofs: \n"),
+        { map__to_assoc_list(Proofs, ProofsList) },
+        io__write_list(ProofsList, "\n", 
+                hlds_out__write_constraint_proof(Indent, VarSet)).
+
+:- pred hlds_out__write_constraint_proof(int, varset,
+        pair(class_constraint, constraint_proof), io__state, io__state).
+:- mode hlds_out__write_constraint_proof(in, in, in, di, uo) is det.
+
+hlds_out__write_constraint_proof(Indent, VarSet, Constraint - Proof) -->
+        hlds_out__write_indent(Indent),
+        io__write_string("% "),
+        mercury_output_constraint(VarSet, Constraint),
+        io__write_string(": "),
+        (
+                { Proof = apply_instance(_, Num) },
+                io__write_string("apply instance decl #"),
+                io__write_int(Num)
+        ;
+                { Proof = superclass(Super) },
+                io__write_string("super class of "),
+                mercury_output_constraint(VarSet, Super)
+        ).
+        
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
Index: compiler/mercury_to_mercury.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/mercury_to_mercury.m,v
retrieving revision 1.137
diff -u -t -r1.137 mercury_to_mercury.m
--- mercury_to_mercury.m	1998/06/09 02:13:46	1.137
+++ mercury_to_mercury.m	1998/06/11 06:44:10
@@ -169,6 +169,10 @@
                 io__state, io__state).
 :- mode mercury_output_constraint(in, in, di, uo) is det.
 
+:- pred mercury_output_instance_methods(instance_interface, io__state,
+        io__state).
+:- mode mercury_output_instance_methods(in, di, uo) is det.
+
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
@@ -406,7 +410,7 @@
 
         io__write_string(" where [\n"),
 
-        output_instance_methods(Methods),
+        mercury_output_instance_methods(Methods),
         
         io__write_string("\n].\n").
 
@@ -461,10 +465,7 @@
                         Mode, Detism, Context, "", "")
         ).
 
-:- pred output_instance_methods(instance_interface, io__state, io__state).
-:- mode output_instance_methods(in, di, uo) is det.
-
-output_instance_methods(Methods) -->
+mercury_output_instance_methods(Methods) -->
         io__write_list(Methods, ",\n", output_instance_method).
 
 :- pred output_instance_method(instance_method, io__state, io__state).

-------------------------------------------------------------------------------


love and cuddles,
dgj
-- 
David Jeffery (dgj at cs.mu.oz.au) |  Marge: Did you just call everyone "chicken"?
MEngSc student,                 |  Homer: Noooo.  I swear on this Bible!
Department of Computer Science  |  Marge: That's not a Bible; that's a book of
University of Melbourne         |         carpet samples!
Australia                       |  Homer: Ooooh... Fuzzy.



More information about the developers mailing list