[m-rev.] diff: fix mprof bug

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Jun 25 10:58:37 AEST 2001


Estimated hours taken: 2
Branches: main

profiler/demangle.m:
util/mdemangle.c:
	Fix a bug that broke profiling at `-O5':
	include the __ho<n> sequence number or the __ua<n> mode number
	when demangling procedures created by higher-order specialization
	or unused argument elimination (respectively).
	This avoids a problem where we were demangling distinct symbols
	onto the same mangled name.

tests/misc_tests/mdemangle_test.inp:
tests/misc_tests/mdemangle_test.exp:
	Update to reflect the new demangling algorithm.

Workspace: /home/mars/fjh/ws1/mercury
Index: profiler/demangle.m
===================================================================
RCS file: /home/mercury1/repository/mercury/profiler/demangle.m,v
retrieving revision 1.12
diff -u -d -r1.12 demangle.m
--- profiler/demangle.m	2001/05/31 06:00:09	1.12
+++ profiler/demangle.m	2001/06/25 00:46:24
@@ -162,13 +162,13 @@
 		remove_trailing_int(UA_ModeNum),
 		m_remove_suffix("__ua")
 	->
-		{ UnusedArgs = yes },
+		{ UnusedArgs = yes(ModeNum0 - no) },
 		{ ModeNum1 is UA_ModeNum mod 10000 }
 	;
 		remove_trailing_int(UA_ModeNum),
 		m_remove_suffix("__uab")
 	->
-		{ UnusedArgs = yes },
+		{ UnusedArgs = yes(ModeNum0 - yes) },
 		{ ModeNum1 is UA_ModeNum mod 10000 }
 	;
 		{ UnusedArgs = no },
@@ -181,22 +181,21 @@
 	% n is a unique identifier for this specialized version
 	%
 	(
-		remove_trailing_int(HO_ModeNum),
+		remove_trailing_int(HO_Num),
 		m_remove_suffix("__ho")
 	->
-		{ HigherOrder = yes },
-		{ ModeNum is HO_ModeNum mod 10000 }
+		{ HigherOrder = yes(HO_Num) }
 	;
-		{ HigherOrder = no },
-		{ ModeNum = ModeNum1 }
+		{ HigherOrder = no }
 	),
+	{ ModeNum = ModeNum1 },
 
 	%
 	% Make sure special predicates with unused_args 
 	% are reported correctly.
 	%
 
-	( { UnusedArgs = yes, Category0 \= ordinary } ->
+	( { UnusedArgs = yes(_), Category0 \= ordinary } ->
 		remove_trailing_int(Arity)
 	;
 		{ true }
@@ -308,7 +307,8 @@
 	dcg_set(DemangledName).
 
 :- pred format_proc(pred_category, maybe(string), string, string, int, int,
-		bool, bool, maybe(int), list(string), list(string)).
+		maybe(int), maybe(pair(int, bool)), maybe(int), list(string),
+		list(string)).
 :- mode format_proc(in, in, in, in, in, in, in, in, in, out, in) is det.
 format_proc(Category, MaybeModule, PredOrFunc, PredName, Arity, ModeNum, 
 		HigherOrder, UnusedArgs, MaybeInternalLabelNum) -->
@@ -362,13 +362,21 @@
 		)
 	},
 	[MainPart],
-	( { HigherOrder = yes } ->
-		[" (specialized)"]
+	( { HigherOrder = yes(HO_Num) } ->
+		[" (specialized [#", string__int_to_string(HO_Num), "])"]
 	;
 		[]
 	),
-	( { UnusedArgs = yes } ->
-		[" (minus unused args)"]
+	( { UnusedArgs = yes(UA_Num - Extra) } ->
+		( { Extra = yes } ->
+			[" (minus extra unused args [#",
+			 string__int_to_string(UA_Num),
+			 "])"]
+		;
+			[" (minus unused args [#",
+			 string__int_to_string(UA_Num),
+			 "])"]
+		)
 	;
 		[]
 	),
Index: tests/misc_tests/mdemangle_test.exp
===================================================================
RCS file: /home/mercury1/repository/tests/misc_tests/mdemangle_test.exp,v
retrieving revision 1.12
diff -u -d -r1.12 mdemangle_test.exp
--- tests/misc_tests/mdemangle_test.exp	2000/11/11 13:37:01	1.12
+++ tests/misc_tests/mdemangle_test.exp	2001/06/25 00:57:16
@@ -55,28 +55,28 @@
 <predicate 'copy'/2 mode 1 label 5>
 
 	unused args
-<predicate 'copy'/2 mode 1 (minus unused args)>
-<predicate 'copy'/2 mode 1 (minus unused args)>
+<predicate 'copy'/2 mode 1 (minus unused args [#0])>
+<predicate 'copy'/2 mode 1 (minus unused args [#0])>
 
 	unused args
-<predicate 'copy'/2 mode 1 (minus unused args)>
-<predicate 'copy'/2 mode 1 (minus unused args)>
+<predicate 'copy'/2 mode 1 (minus extra unused args [#0])>
+<predicate 'copy'/2 mode 1 (minus extra unused args [#0])>
 
 	higher order specialization
-<predicate 'copy'/2 mode 1 (specialized)>
-<predicate 'copy'/2 mode 1 (specialized)>
+<predicate 'copy'/2 mode 1 (specialized [#7])>
+<predicate 'copy'/2 mode 1 (specialized [#7])>
 
 	higher order specialization (regression test for 1 char pred names)
-<predicate 'c'/2 mode 1 (specialized)>
-<predicate 'c'/2 mode 1 (specialized)>
+<predicate 'c'/2 mode 1 (specialized [#7])>
+<predicate 'c'/2 mode 1 (specialized [#7])>
 
 	higher order specialization and unused args
-<predicate 'copy'/2 mode 1 (specialized) (minus unused args)>
-<predicate 'copy'/2 mode 1 (specialized) (minus unused args)>
+<predicate 'copy'/2 mode 1 (specialized [#7]) (minus unused args [#0])>
+<predicate 'copy'/2 mode 1 (specialized [#7]) (minus unused args [#0])>
 
 	mangled name with unused args
-<predicate '!'/2 mode 0 (minus unused args)>
-<predicate '!'/2 mode 0 (minus unused args)>
+<predicate '!'/2 mode 0 (minus unused args [#0])>
+<predicate '!'/2 mode 0 (minus unused args [#0])>
 
 	some tests of symbols that should not be demangled
 	(this is a regression test: previous versions of mdemangle
@@ -102,8 +102,8 @@
 
 	type specialization and deforestion
 	XXX this needs to be fixed
-<predicate 'doubleapp_impl:DeforestationIn__pred__TypeSpecOf__pred_or_func__double_app__[T = int]__21__0'/5 mode 0 (minus unused args)>
-<predicate 'doubleapp_impl:DeforestationIn__pred__TypeSpecOf__pred_or_func__double_app__[T = int]__21__0'/5 mode 0 (minus unused args)>
+<predicate 'doubleapp_impl:DeforestationIn__pred__TypeSpecOf__pred_or_func__double_app__[T = int]__21__0'/5 mode 0 (minus unused args [#0])>
+<predicate 'doubleapp_impl:DeforestationIn__pred__TypeSpecOf__pred_or_func__double_app__[T = int]__21__0'/5 mode 0 (minus unused args [#0])>
 
 	A realistic test
 ml -s asm_fast.gc.tr --no-demangle -o interpreter interpreter_init.o \
Index: tests/misc_tests/mdemangle_test.inp
===================================================================
RCS file: /home/mercury1/repository/tests/misc_tests/mdemangle_test.inp,v
retrieving revision 1.13
diff -u -d -r1.13 mdemangle_test.inp
--- tests/misc_tests/mdemangle_test.inp	2000/11/11 13:37:02	1.13
+++ tests/misc_tests/mdemangle_test.inp	2001/06/25 00:57:02
@@ -56,27 +56,27 @@
 
 	unused args
 _entry_mercury__copy__ua1_2_0
-<predicate 'copy'/2 mode 1 (minus unused args)>
+<predicate 'copy'/2 mode 1 (minus unused args [#0])>
 
 	unused args
 _entry_mercury__copy__uab1_2_0
-<predicate 'copy'/2 mode 1 (minus unused args)>
+<predicate 'copy'/2 mode 1 (minus extra unused args [#0])>
 
 	higher order specialization
 _entry_mercury__copy__ho7_2_1
-<predicate 'copy'/2 mode 1 (specialized)>
+<predicate 'copy'/2 mode 1 (specialized [#7])>
 
 	higher order specialization (regression test for 1 char pred names)
 _entry_mercury__c__ho7_2_1
-<predicate 'c'/2 mode 1 (specialized)>
+<predicate 'c'/2 mode 1 (specialized [#7])>
 
 	higher order specialization and unused args
 _entry_mercury__copy__ho7__ua1_2_0
-<predicate 'copy'/2 mode 1 (specialized) (minus unused args)>
+<predicate 'copy'/2 mode 1 (specialized [#7]) (minus unused args [#0])>
 
 	mangled name with unused args
 mercury__f_33_95_95_117_97_49_48_48_48_48_2_0
-<predicate '!'/2 mode 0 (minus unused args)>
+<predicate '!'/2 mode 0 (minus unused args [#0])>
 
 	some tests of symbols that should not be demangled
 	(this is a regression test: previous versions of mdemangle
@@ -103,7 +103,7 @@
 	type specialization and deforestion
 	XXX this needs to be fixed
 mercury__f_100_111_117_98_108_101_97_112_112_95_105_109_112_108_95_95_68_101_102_111_114_101_115_116_97_116_105_111_110_73_110_95_95_112_114_101_100_95_95_84_121_112_101_83_112_101_99_79_102_95_95_112_114_101_100_95_111_114_95_102_117_110_99_95_95_100_111_117_98_108_101_95_97_112_112_95_95_91_84_32_61_32_105_110_116_93_95_95_50_49_95_95_48_95_95_117_97_48_5_0
-<predicate 'doubleapp_impl:DeforestationIn__pred__TypeSpecOf__pred_or_func__double_app__[T = int]__21__0'/5 mode 0 (minus unused args)>
+<predicate 'doubleapp_impl:DeforestationIn__pred__TypeSpecOf__pred_or_func__double_app__[T = int]__21__0'/5 mode 0 (minus unused args [#0])>
 
 	A realistic test
 ml -s asm_fast.gc.tr --no-demangle -o interpreter interpreter_init.o \
Index: util/mdemangle.c
===================================================================
RCS file: /home/mercury1/repository/mercury/util/mdemangle.c,v
retrieving revision 1.39
diff -u -d -r1.39 mdemangle.c
--- util/mdemangle.c	2001/05/31 06:00:27	1.39
+++ util/mdemangle.c	2001/06/25 00:55:57
@@ -208,7 +208,10 @@
 	int arity;
 	const char *pred_or_func; /* either "predicate" or "function" */
 	bool unused_args = FALSE; /* does this proc have any unused arguments */
+	bool unused_args_extra = FALSE; /* __uab suffix rather than __ua */
+	int unused_args_num = 0;
 	bool higher_order = FALSE; /* has this proc been specialized */
+	int higher_order_num = 0;
 	int internal = -1;
 	char *name_before_prefixes = NULL;
 	int lambda_line = 0;
@@ -362,11 +365,15 @@
 	if (check_for_suffix(start, position, ua_suffix,
 			sizeof(ua_suffix), &mode_num2)) {
 		unused_args = TRUE;
+		unused_args_extra = FALSE;
+		unused_args_num = mode_num;
 		end = position + 1 - (sizeof(ua_suffix) - 1);
 		mode_num = mode_num2 % 10000;
 	} else if (check_for_suffix(start, position, ua_suffix2,
 			sizeof(ua_suffix2), &mode_num2)) {
 		unused_args = TRUE;
+		unused_args_extra = TRUE;
+		unused_args_num = mode_num;
 		end = position + 1 - (sizeof(ua_suffix2) - 1);
 		mode_num = mode_num2 % 10000;
 	}
@@ -384,7 +391,7 @@
 		position--;
 	} while (MR_isdigit(*position));
 	if (check_for_suffix(start, position, ho_suffix,
-			sizeof(ho_suffix), &mode_num2)) {
+			sizeof(ho_suffix), &higher_order_num)) {
 		end = position + 1 - (sizeof(ho_suffix) - 1);
 		higher_order = TRUE;
 	}
@@ -572,10 +579,15 @@
 		printf(" (type specialized %s)", type_spec_sub);	
 	}
 	if (higher_order) {
-		printf(" (specialized)");
+		printf(" (specialized [#%d])", higher_order_num);
 	}
 	if (unused_args) {
-		printf(" (minus unused args)");
+		if (unused_args_extra) {
+			printf(" (minus extra unused args [#%d])",
+				unused_args_num);
+		} else {
+			printf(" (minus unused args [#%d])", unused_args_num);
+		}
 	}
 	if (internal != -1) {
 		printf(" label %d", internal);

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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