trivial diff: Progress messages in polymorphism, checked_malloc() move

Andrew Bromage bromage at cs.mu.OZ.AU
Mon Mar 30 13:45:01 AEST 1998


G'day all.

Sneaking a couple of changes through, one of which has already been
reviewed as part of my previous diff.

Cheers,
Andrew Bromage


Estimated hours taken: 0.5

compiler/mercury_compile.m:
compiler/polymorphism.m:
	Include some verbose progress messages in the polymorphism pass.

runtime/mercury_memory.h:
runtime/mercury_memory.c:
runtime/mercury_misc.h:
runtime/mercury_misc.c:
	Move checked_malloc() to mercury_memory.c, add checked_realloc().


Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/mercury_compile.m,v
retrieving revision 1.79
diff -u -r1.79 mercury_compile.m
--- mercury_compile.m	1998/03/20 02:58:08	1.79
+++ mercury_compile.m	1998/03/27 06:45:47
@@ -1283,7 +1283,7 @@
 		maybe_write_string(Verbose,
 			"% Transforming polymorphic unifications..."),
 		maybe_flush_output(Verbose),
-		{ polymorphism__process_module(HLDS0, HLDS) },
+		polymorphism__process_module(HLDS0, HLDS),
 		maybe_write_string(Verbose, " done.\n"),
 		maybe_report_stats(Stats)
 	;
Index: compiler/polymorphism.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/polymorphism.m,v
retrieving revision 1.130
diff -u -r1.130 polymorphism.m
--- polymorphism.m	1998/03/03 17:35:37	1.130
+++ polymorphism.m	1998/03/27 07:02:13
@@ -281,9 +281,11 @@
 :- module polymorphism.
 :- interface.
 :- import_module hlds_module.
+:- import_module io.
 
-:- pred polymorphism__process_module(module_info, module_info).
-:- mode polymorphism__process_module(in, out) is det.
+:- pred polymorphism__process_module(module_info, module_info,
+			io__state, io__state).
+:- mode polymorphism__process_module(in, out, di, uo) is det.
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
@@ -293,7 +295,7 @@
 :- import_module hlds_pred, hlds_goal, hlds_data, llds, (lambda).
 :- import_module prog_data, type_util, mode_util, quantification, instmap.
 :- import_module code_util, unify_proc, special_pred, prog_util, make_hlds.
-:- import_module (inst), hlds_out, base_typeclass_info.
+:- import_module (inst), hlds_out, base_typeclass_info, passes_aux.
 
 :- import_module bool, int, string, list, set, map.
 :- import_module term, varset, std_util, require, assoc_list.
@@ -308,27 +310,30 @@
 	% the argtypes of the called predicates, and so we need to make
 	% sure we don't muck them up before we've finished the first pass.
 
-polymorphism__process_module(ModuleInfo0, ModuleInfo) :-
+polymorphism__process_module(ModuleInfo0, ModuleInfo, IO0, IO) :-
 	module_info_preds(ModuleInfo0, Preds0),
 	map__keys(Preds0, PredIds0),
-	polymorphism__process_preds(PredIds0, ModuleInfo0, ModuleInfo1),
+	polymorphism__process_preds(PredIds0, ModuleInfo0, ModuleInfo1,
+				IO0, IO),
 	module_info_preds(ModuleInfo1, Preds1),
 	map__keys(Preds1, PredIds1),
 	polymorphism__fixup_preds(PredIds1, ModuleInfo1, ModuleInfo2),
 	polymorphism__expand_class_method_bodies(ModuleInfo2, ModuleInfo).
 
-:- pred polymorphism__process_preds(list(pred_id), module_info, module_info).
-:- mode polymorphism__process_preds(in, in, out) is det.
+:- pred polymorphism__process_preds(list(pred_id), module_info, module_info,
+			io__state, io__state).
+:- mode polymorphism__process_preds(in, in, out, di, uo) is det.
 
-polymorphism__process_preds([], ModuleInfo, ModuleInfo).
-polymorphism__process_preds([PredId | PredIds], ModuleInfo0, ModuleInfo) :-
+polymorphism__process_preds([], ModuleInfo, ModuleInfo) --> [].
+polymorphism__process_preds([PredId | PredIds], ModuleInfo0, ModuleInfo) -->
 	polymorphism__process_pred(PredId, ModuleInfo0, ModuleInfo1),
 	polymorphism__process_preds(PredIds, ModuleInfo1, ModuleInfo).
 
-:- pred polymorphism__process_pred(pred_id, module_info, module_info).
-:- mode polymorphism__process_pred(in, in, out) is det.
+:- pred polymorphism__process_pred(pred_id, module_info, module_info,
+			io__state, io__state).
+:- mode polymorphism__process_pred(in, in, out, di, uo) is det.
 
-polymorphism__process_pred(PredId, ModuleInfo0, ModuleInfo) :-
+polymorphism__process_pred(PredId, ModuleInfo0, ModuleInfo, IO0, IO) :-
 	module_info_pred_info(ModuleInfo0, PredId, PredInfo),
 	pred_info_module(PredInfo, PredModule),
 	pred_info_name(PredInfo, PredName),
@@ -337,25 +342,30 @@
 		polymorphism__no_type_info_builtin(PredModule,
 			PredName, PredArity) 
 	->
-		ModuleInfo = ModuleInfo0
+		ModuleInfo = ModuleInfo0,
+		IO = IO0
 	;
 		pred_info_procids(PredInfo, ProcIds),
 		polymorphism__process_procs(PredId, ProcIds,
-			ModuleInfo0, ModuleInfo)
+			ModuleInfo0, ModuleInfo, IO0, IO)
 	).
 
 :- pred polymorphism__process_procs(pred_id, list(proc_id),
-					module_info, module_info).
-:- mode polymorphism__process_procs(in, in, in, out) is det.
+					module_info, module_info,
+					io__state, io__state).
+:- mode polymorphism__process_procs(in, in, in, out, di, uo) is det.
 
-polymorphism__process_procs(_PredId, [], ModuleInfo, ModuleInfo).
+polymorphism__process_procs(_PredId, [], ModuleInfo, ModuleInfo, IO, IO).
 polymorphism__process_procs(PredId, [ProcId | ProcIds], ModuleInfo0,
-		ModuleInfo) :-
+		ModuleInfo, IO0, IO) :-
 	module_info_preds(ModuleInfo0, PredTable0),
 	map__lookup(PredTable0, PredId, PredInfo0),
 	pred_info_procedures(PredInfo0, ProcTable0),
 	map__lookup(ProcTable0, ProcId, ProcInfo0),
 
+	write_proc_progress_message("% Transforming polymorphism for ",
+				PredId, ProcId, ModuleInfo0, IO0, IO1),
+
 	polymorphism__process_proc(ProcInfo0, PredInfo0, ModuleInfo0,
 					ProcInfo, PredInfo1, ModuleInfo1),
 
@@ -366,7 +376,8 @@
 	map__det_update(PredTable1, PredId, PredInfo, PredTable),
 	module_info_set_preds(ModuleInfo1, PredTable, ModuleInfo2),
 
-	polymorphism__process_procs(PredId, ProcIds, ModuleInfo2, ModuleInfo).
+	polymorphism__process_procs(PredId, ProcIds, ModuleInfo2, ModuleInfo,
+			IO1, IO).
 
 	% unsafe_type_cast and unsafe_promise_unique are polymorphic
 	% builtins which do not need their type_infos. unsafe_type_cast
Index: runtime/mercury_memory.c
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_memory.c,v
retrieving revision 1.4
diff -u -r1.4 mercury_memory.c
--- mercury_memory.c	1998/03/16 12:23:31	1.4
+++ mercury_memory.c	1998/03/27 04:51:53
@@ -1214,3 +1214,36 @@
 	free(ptr);
 #endif
 }
+
+
+		/* Note: checked_malloc()ed structures */
+		/* never contain pointers into GCed    */
+		/* memory, so we don't need to         */
+		/* GC_malloc() them. (cf. newmem())    */
+void *
+checked_malloc(size_t n)
+{
+	reg     void    *p;
+
+	p = malloc(n);
+	if (p == NULL && n != 0) {
+		fatal_error("ran out of memory");
+	}
+
+	return p;
+}
+
+
+void *
+checked_realloc(void *old, size_t n)
+{
+	reg     void    *p;
+
+	p = realloc(old, n);
+	if (p == NULL && n != 0) {
+		fatal_error("ran out of memory");
+	}
+
+	return p;
+}
+
Index: runtime/mercury_memory.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_memory.h,v
retrieving revision 1.3
diff -u -r1.3 mercury_memory.h
--- mercury_memory.h	1998/03/16 12:23:32	1.3
+++ mercury_memory.h	1998/03/27 04:51:00
@@ -232,4 +232,19 @@
 
 void deallocate_memory(void *);
 
+
+/*
+** checked_malloc() and checked_realloc() are like the standard C
+** malloc() and realloc() functions, except that the return values
+** are checked.
+**
+** NOTE: checked_malloc()ed and checked_realloc()ed structures must
+** never contain pointers into GCed memory, otherwise those pointers
+** will never be traced.
+*/
+
+#include <stddef.h>	/* for size_t */
+void *checked_malloc(size_t n);
+void *checked_realloc(void *old, size_t n);
+
 #endif /* not MERCURY_MEMORY_H */
Index: runtime/mercury_misc.c
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_misc.c,v
retrieving revision 1.4
diff -u -r1.4 mercury_misc.c
--- mercury_misc.c	1998/03/16 12:23:33	1.4
+++ mercury_misc.c	1998/03/27 04:52:10
@@ -471,22 +471,6 @@
 	exit(1);
 }
 
-		/* Note: checked_malloc()ed structures */
-		/* never contain pointers into GCed    */
-		/* memory, so we don't need to         */
-		/* GC_malloc() them. (cf. newmem())    */
-void *
-checked_malloc(size_t n)
-{
-	reg	void	*p;
-
-	p = malloc(n);
-	if (p == NULL && n != 0) {
-		fatal_error("ran out of memory");
-	}
-
-	return p;
-}
 
 /*
 **  Note that hash_string is actually defined as a macro in mercury_imp.h,
Index: runtime/mercury_misc.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_misc.h,v
retrieving revision 1.4
diff -u -r1.4 mercury_misc.h
--- mercury_misc.h	1998/03/16 12:23:34	1.4
+++ mercury_misc.h	1998/03/27 04:48:45
@@ -63,10 +63,4 @@
 #endif
 extern	void	fatal_error(const char *msg) NO_RETURN;
 
-/* 
-** XXX checked_malloc() should be moved to mercury_memory.h or mercury_heap.h
-*/
-#include <stddef.h>	/* for size_t */
-void *checked_malloc(size_t n);
-
 #endif /* not MERCURY_MISC_H */



More information about the developers mailing list