[m-rev.] for review: fix a bug in untupling transformation

Peter Wang wangp at students.cs.mu.OZ.AU
Fri Feb 11 13:55:27 AEDT 2005


Ralph, I don't know if the fix below is necessary for loop_inv.m, but
it looks like it wouldn't hurt.


Estimated hours taken: 1
Branches: main

Predicates generated by the untupling transformation were being given the
same forms of names, no matter if the original procedure being transformed
was a predicate or a function.  If a module had a predicate and a function
with the same name and arity, and tracing was enabled, and a low enough
optimisation level was being used, this would result in an exception being
thrown.

compiler/untupling.m:
	Give generated procedures different names depending on whether the
	proc being transformed was a predicate or function.

compiler/loop_inv.m:
	Apply the same fix to the loop invariant hoisting.

tests/valid/Mercury.options:
tests/valid/Mmakefile:
tests/valid/untuple_bug.m:
	Add a test case.

Index: compiler/loop_inv.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/loop_inv.m,v
retrieving revision 1.16
diff -u -r1.16 loop_inv.m
--- compiler/loop_inv.m	28 Jan 2005 01:03:18 -0000	1.16
+++ compiler/loop_inv.m	10 Feb 2005 06:43:00 -0000
@@ -769,12 +769,13 @@
     hlds_pred__pred_info_get_origin(PredInfo, OrigOrigin),
 
     PredName = hlds_pred__pred_info_name(PredInfo),
+    PredOrFunc = hlds_pred__pred_info_is_pred_or_func(PredInfo),
     hlds_goal__goal_info_get_context(GoalInfo, Context),
     term__context_line(Context, Line),
     hlds_pred__proc_id_to_int(ProcId, ProcNo),
     AuxNamePrefix = string__format("loop_inv_%d", [i(ProcNo)]),
     prog_util__make_pred_name_with_context(ModuleName, AuxNamePrefix,
-            predicate, PredName, Line, 1, AuxPredSymName),
+            PredOrFunc, PredName, Line, 1, AuxPredSymName),
     (
         AuxPredSymName = unqualified(AuxPredName)
     ;
Index: compiler/untupling.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/untupling.m,v
retrieving revision 1.1
diff -u -r1.1 untupling.m
--- compiler/untupling.m	2 Feb 2005 02:58:43 -0000	1.1
+++ compiler/untupling.m	10 Feb 2005 06:37:28 -0000
@@ -404,12 +404,13 @@
 	pred_info_get_origin(PredInfo, OrigOrigin),
 
 	PredName = pred_info_name(PredInfo),
+	PredOrFunc = pred_info_is_pred_or_func(PredInfo),
 	goal_info_get_context(GoalInfo, Context),
 	term__context_line(Context, Line),
 	proc_id_to_int(ProcId, ProcNo),
 	AuxNamePrefix = string__format("untupling_%d", [i(ProcNo)]),
 	make_pred_name_with_context(ModuleName, AuxNamePrefix,
-		predicate, PredName, Line, 1, AuxPredSymName),
+		PredOrFunc, PredName, Line, 1, AuxPredSymName),
 	(
 		AuxPredSymName = unqualified(AuxPredName)
 	;
Index: tests/valid/Mercury.options
===================================================================
RCS file: /home/mercury1/repository/tests/valid/Mercury.options,v
retrieving revision 1.15
diff -u -r1.15 Mercury.options
--- tests/valid/Mercury.options	7 Feb 2005 07:56:53 -0000	1.15
+++ tests/valid/Mercury.options	10 Feb 2005 12:50:46 -0000
@@ -94,6 +94,7 @@
 MCFLAGS-type_inf_ambig_test	= --infer-all
 MCFLAGS-unify_typeinfo_bug	= -O3 --no-special-preds
 MCFLAGS-uniq_mode_inf_bug	= --infer-all
+MCFLAGS-untuple_bug		= -O0 --untuple --trace deep --trace-optimized
 MCFLAGS-vn_float		= -O5
 MCFLAGS-zero_arity		= --infer-modes
 MGNUCFLAGS-reg_bug		= --no-ansi
Index: tests/valid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/valid/Mmakefile,v
retrieving revision 1.147
diff -u -r1.147 Mmakefile
--- tests/valid/Mmakefile	7 Feb 2005 07:56:54 -0000	1.147
+++ tests/valid/Mmakefile	10 Feb 2005 12:43:38 -0000
@@ -194,6 +194,7 @@
 	uniq_mode_inf_bug \
 	uniq_unify \
 	unreachable_code \
+	untuple_bug \
 	unused_args_test2 \
 	vn_float \
 	zero_arity
Index: tests/valid/untuple_bug.m
===================================================================
RCS file: tests/valid/untuple_bug.m
diff -N tests/valid/untuple_bug.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/valid/untuple_bug.m	11 Feb 2005 00:12:46 -0000
@@ -0,0 +1,29 @@
+% Predicates generated by the untupling transformation were being given the
+% same forms of names, no matter if the original procedure being transformed
+% was a predicate or a function.  If a module had a predicate and a function
+% with the same name and arity, and tracing was enabled, and a low enough
+% optimisation level was being used, this would result in an exception being
+% thrown.
+%
+% mmc -C -O0 --untuple --trace deep --trace-optimized untuple_bug.m
+%
+% Uncaught Mercury exception:
+% Software Error: map__det_insert: key already present
+%         Key Type: ll_backend.llds.label
+%         Key Value: internal(2, proc(unqualified("untuple_bug"), predicate,
+%		unqualified("untuple_bug"), "untupling_0__pred__f__0__1", 1, 0))
+%         Value Type: ll_backend.llds.data_addr
+
+:- module untuple_bug.
+
+:- interface.
+
+:- type t ---> t(int).
+
+:- func f = t.
+:- pred f(t::out) is det.
+
+:- implementation.
+
+f = t(0).
+f(t(0)).


--------------------------------------------------------------------------
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