[m-dev.] diff: fix bug in inter-module optimization

Simon Taylor stayl at cs.mu.OZ.AU
Sat Aug 5 10:00:38 AEST 2000



Estimated hours taken: 0.5

compiler/intermod.m:
	Append the variable numbers to variables in the clauses
	written to `.opt' files. This fixes a bug which caused
	type errors to be reported for predicates in a `.opt' file.
	The problem was that the names of the DCG variables inside
	a DCG pred expression clashed with the DCG variables of
	the enclosing clause.

tests/valid/Mmakefile:
tests/valid/intermod_dcg_bug.m:
tests/valid/intermod_dcg_bug2.m:
	Test case.


Index: compiler/intermod.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/intermod.m,v
retrieving revision 1.79
diff -u -u -r1.79 intermod.m
--- compiler/intermod.m	2000/07/06 06:25:09	1.79
+++ compiler/intermod.m	2000/08/03 22:51:58
@@ -1371,7 +1371,11 @@
 		PredOrFunc, Clause0) -->
 	{ strip_headvar_unifications(HeadVars, Clause0,
 		ClauseHeadVars, Clause) },
-	hlds_out__write_clause(1, ModuleInfo, PredId, VarSet, no,
+	% Variable numbers need to be appended for the case
+	% where the added arguments for a DCG pred expression
+	% are named the same as variables in the enclosing clause.
+	{ AppendVarNums = yes },
+	hlds_out__write_clause(1, ModuleInfo, PredId, VarSet, AppendVarNums,
 		ClauseHeadVars, PredOrFunc, Clause, no).
 
 	% Strip the `Headvar__n = Term' unifications from each clause,
Index: tests/valid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/valid/Mmakefile,v
retrieving revision 1.66
diff -u -u -r1.66 Mmakefile
--- tests/valid/Mmakefile	2000/07/27 15:09:09	1.66
+++ tests/valid/Mmakefile	2000/08/04 23:45:21
@@ -71,6 +71,7 @@
 	inlining_bug.m \
 	inst_perf_bug_1.m \
 	int64.m \
+	intermod_dcg_bug.m \
 	intermod_impure.m \
 	intermod_lambda.m \
 	intermod_nested_module.m \
@@ -211,6 +212,8 @@
 MCFLAGS-explicit_quant		= --halt-at-warn
 MCFLAGS-higher_order_implied_mode = -O-1
 MCFLAGS-inhibit_warn_test       = --inhibit-warnings --halt-at-warn
+MCFLAGS-intermod_dcg_bug	= --intermodule-optimization
+MCFLAGS-intermod_dcg_bug2	= --intermodule-optimization
 MCFLAGS-intermod_impure		= --intermodule-optimization
 MCFLAGS-intermod_impure2	= --intermodule-optimization
 MCFLAGS-intermod_lambda		= --intermodule-optimization
Index: tests/valid/intermod_dcg_bug.m
===================================================================
RCS file: intermod_dcg_bug.m
diff -N intermod_dcg_bug.m
--- /dev/null	Sat Aug  5 09:48:43 2000
+++ intermod_dcg_bug.m	Fri Aug  4 13:26:57 2000
@@ -0,0 +1,21 @@
+% Mercury ROTD 2/8/2000 reported a type error when typechecking
+% the clauses for foo/2 from intermod_dcg_bug2.opt.
+% The problem was that the DCG arguments introduced for the
+% DCG pred expressions clashed with the DCG arguments for
+% the enclosing clauses. The solution was to add variable numbers
+% to clauses in `.opt' files.
+% 
+:- module intermod_dcg_bug.
+
+:- interface.
+
+:- import_module io.
+
+:- pred main(io__state, io__state).
+:- mode main(di, uo) is det.
+
+:- implementation.
+
+:- import_module intermod_dcg_bug2.
+
+main --> foo.
Index: tests/valid/intermod_dcg_bug2.m
===================================================================
RCS file: intermod_dcg_bug2.m
diff -N intermod_dcg_bug2.m
--- /dev/null	Sat Aug  5 09:48:43 2000
+++ intermod_dcg_bug2.m	Fri Aug  4 13:26:57 2000
@@ -0,0 +1,27 @@
+:- module intermod_dcg_bug2.
+
+:- interface.
+
+:- import_module io.
+
+:- pred foo(io__state, io__state).
+:- mode foo(di, uo) is det.
+
+:- implementation.
+
+:- import_module int, list.
+
+:- pragma inline(foo/2).
+
+foo -->
+	{ list__foldl(
+		(pred(_::in, di, uo) is det -->
+			=(Var0),
+			:=(Var0 + 1)
+		), [1, 2, 3], 0, Count) },	
+	io__write_int(Count),
+	
+	list__foldl(
+		(pred(X::in, di, uo) is det -->
+			io__write(X)
+		), [1, 2, 3]).
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list