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

Simon Taylor stayl at cs.mu.OZ.AU
Mon Mar 5 15:03:12 AEDT 2001



Estimated hours taken: 0.5

compiler/intermod.m:
	Don't append variable numbers to type variables in the
	`:- pred' or `:- func' declarations for predicates
	defined in foreign code. The foreign code may contain
	references to variables such as `TypeInfo_for_T' which
	will break if `T' is written as `T_1' in the `:- pred'
	or `:- func' declaration.

tests/hard_coded/Mmakefile:
tests/hard_coded/intermod_c_code.m:
tests/hard_coded/intermod_c_code2.m:
tests/hard_coded/intermod_c_code.exp:
	Test case.


Index: compiler/intermod.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/intermod.m,v
retrieving revision 1.91
diff -u -u -r1.91 intermod.m
--- compiler/intermod.m	2001/01/24 13:18:13	1.91
+++ compiler/intermod.m	2001/03/05 03:03:59
@@ -1318,7 +1318,25 @@
 	{ pred_info_get_purity(PredInfo, Purity) },
 	{ pred_info_get_is_pred_or_func(PredInfo, PredOrFunc) },
 	{ pred_info_get_class_context(PredInfo, ClassContext) },
-	{ AppendVarNums = yes },
+	{ pred_info_get_goal_type(PredInfo, GoalType) },
+	{
+		GoalType = pragmas,
+		% For foreign code goals we can't append variable numbers
+		% to type variables in the predicate declaration
+		% because the foreign code may contain references to
+		% variables such as `TypeInfo_for_T' which will break
+		% if `T' is written as `T_1' in the pred declaration.
+		AppendVarNums = no
+	;
+		GoalType = clauses,
+		AppendVarNums = yes
+	;
+		GoalType = (assertion),
+		AppendVarNums = yes
+	;
+		GoalType = none,
+		AppendVarNums = yes
+	},
 	(
 		{ PredOrFunc = predicate },
 		mercury_output_pred_type(TVarSet, ExistQVars,
Index: tests/hard_coded/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/Mmakefile,v
retrieving revision 1.111
diff -u -u -r1.111 Mmakefile
--- tests/hard_coded/Mmakefile	2001/02/15 11:23:26	1.111
+++ tests/hard_coded/Mmakefile	2001/03/05 03:12:47
@@ -68,6 +68,7 @@
 	impossible_unify \
 	impure_prune \
 	integer_test \
+	intermod_c_code \
 	merge_and_remove_dups \
 	minint_bug \
 	mode_choice \
@@ -175,6 +176,8 @@
 MCFLAGS-ho_order	=	--optimize-higher-order
 MCFLAGS-ho_order2	=	--optimize-higher-order
 MCFLAGS-no_fully_strict	=	--no-fully-strict
+MCFLAGS-intermod_c_code =	--intermodule-optimization
+MCFLAGS-intermod_c_code2 =	--intermodule-optimization
 MCFLAGS-nondet_ctrl_vn	=	--optimize-value-number
 MCFLAGS-redoip_clobber	=	--no-inlining
 MCFLAGS-rnd		=	-O6
Index: tests/hard_coded/intermod_c_code.exp
===================================================================
RCS file: intermod_c_code.exp
diff -N intermod_c_code.exp
--- /dev/null	Wed Feb 28 03:37:13 2001
+++ intermod_c_code.exp	Mon Mar  5 14:54:41 2001
@@ -0,0 +1 @@
+"Hello, world\n"
Index: tests/hard_coded/intermod_c_code.m
===================================================================
RCS file: intermod_c_code.m
diff -N intermod_c_code.m
--- /dev/null	Wed Feb 28 03:37:13 2001
+++ intermod_c_code.m	Mon Mar  5 14:54:29 2001
@@ -0,0 +1,17 @@
+:- module intermod_c_code.
+
+:- interface.
+
+:- import_module io.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- implementation.
+
+:- import_module intermod_c_code2.
+
+main -->
+	{ c_code("Hello, world\n", Y) },
+	io__write(Y),
+	io__nl.
+
Index: tests/hard_coded/intermod_c_code2.m
===================================================================
RCS file: intermod_c_code2.m
diff -N intermod_c_code2.m
--- /dev/null	Wed Feb 28 03:37:13 2001
+++ intermod_c_code2.m	Mon Mar  5 14:45:50 2001
@@ -0,0 +1,18 @@
+:- module intermod_c_code2.
+
+:- interface.
+
+:- some [U] pred c_code(T::in, U::out) is det.
+
+:- implementation.
+
+c_code(T, U) :- c_code_2(T, U).
+
+:- some [U] pred c_code_2(T::in, U::out) is det.
+
+:- pragma c_code(c_code_2(T::in, U::out),
+"{
+	U = T;
+	TypeInfo_for_U = TypeInfo_for_T;
+}").
+
--------------------------------------------------------------------------
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