[m-rev.] for review: fix bug with tabling and intermodule optimization

Julien Fischer juliensf at cs.mu.OZ.AU
Thu Nov 4 16:00:10 AEDT 2004


For review by anyone.

Estimated hours taken: 2
Branches: main

Fix a problem where predicates that were tabled
but also had an inline pragma ended up being
exported in `.opt' files.

If these procedures were inlined in another
module the fact that they were tabled in the
original module was lost.

compiler/intermod.m:
	Don't put tabled procedures in the `.opt' files even
	if they have an inline pragma.

compiler/options.m:
compiler/make_hlds.m:
	Emit a warning if a tabled procedure also has an
	inline pragma.  Add an option to suppress this
	warning.

doc/user_guide.texi:
	Document the new option.

tests/warnings/Mmakefile:
tests/warnings/table_with_inline.m:
tests/warnings/table_with_inline.exp:
	Test case for the new warning.

Julien.

Index: compiler/intermod.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/intermod.m,v
retrieving revision 1.162
diff -u -r1.162 intermod.m
--- compiler/intermod.m	5 Sep 2004 23:52:13 -0000	1.162
+++ compiler/intermod.m	3 Nov 2004 07:36:13 -0000
@@ -343,12 +343,14 @@
 		globals__get_target(Globals, Target),
 		\+ clauses_contain_noninlinable_foreign_code(Target, Clauses),

+		% Don't export tabled predicates since they are not inlinable.
+		proc_info_eval_method(ProcInfo, eval_normal),
+
 		(
 			inlining__is_simple_clause_list(Clauses,
 				InlineThreshold + Arity),
 			pred_info_get_markers(PredInfo, Markers),
-			\+ check_marker(Markers, no_inline),
-			proc_info_eval_method(ProcInfo, eval_normal)
+			\+ check_marker(Markers, no_inline)
 		;
 			pred_info_requested_inlining(PredInfo)
 		;
Index: compiler/make_hlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make_hlds.m,v
retrieving revision 1.484
diff -u -r1.484 make_hlds.m
--- compiler/make_hlds.m	21 Oct 2004 07:29:18 -0000	1.484
+++ compiler/make_hlds.m	3 Nov 2004 14:47:46 -0000
@@ -5376,6 +5376,28 @@
 		true
 	),

+	% Issue a warning if this predicate/function has a pragma inline
+	% declaration.  Tabled procedures cannot be inlined.
+	pred_info_get_markers(PredInfo0, Markers),
+	globals.io_lookup_bool_option(warn_table_with_inline, WarnInline, !IO),
+	( check_marker(Markers, inline), WarnInline = yes ->
+		PredNameStr = hlds_out.simple_call_id_to_string(PredOrFunc, PredName/Arity),
+		TablePragmaStr = string.format("`:- pragma %s'", [s(EvalMethodS)]),
+		InlineWarning = [
+			words("Warning: "), fixed(PredNameStr),
+			words("has a"), nl, fixed(TablePragmaStr),
+			words("declaration but also has a"), fixed("`:- pragma inline'"),
+			words("declaration."), nl,
+			words("This inline pragma will be ignored"),
+			words("since tabled predicates cannot be inlined."), nl,
+			words("You can use the"),
+			fixed("`--no-warn-table-with-inline'"),
+			words("option to suppress this warning.")
+		],
+		error_util.report_warning(Context, 0, InlineWarning, !IO)
+	;
+		true
+	),
 	( pred_info_is_imported(PredInfo0) ->
 		module_info_incr_errors(!ModuleInfo),
 		prog_out__write_context(Context, !IO),
Index: compiler/options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.435
diff -u -r1.435 options.m
--- compiler/options.m	1 Nov 2004 04:46:19 -0000	1.435
+++ compiler/options.m	3 Nov 2004 14:41:11 -0000
@@ -95,6 +95,7 @@
 		;	warn_up_to_date
 		;	warn_stubs
 		;	warn_dead_procs
+		;	warn_table_with_inline
 	% Verbosity options
 		;	verbose
 		;	very_verbose
@@ -755,7 +756,8 @@
 	warn_target_code	-	bool(yes),
 	warn_up_to_date -		bool(yes),
 	warn_stubs		-	bool(yes),
-	warn_dead_procs	-		bool(no)
+	warn_dead_procs	-		bool(no),
+	warn_table_with_inline	-	bool(yes)
 ]).
 option_defaults_2(verbosity_option, [
 		% Verbosity Options
@@ -1387,6 +1389,7 @@
 long_option("warn-up-to-date",		warn_up_to_date).
 long_option("warn-stubs",		warn_stubs).
 long_option("warn-dead-procs",		warn_dead_procs).
+long_option("warn-table-with-inline", 	warn_table_with_inline).

 % verbosity options
 long_option("verbose",			verbose).
@@ -2606,7 +2609,10 @@
 		"\tWarn about procedures which are never called.",
 		"--no-warn-target-code",
 		"\tDisable warnings from the compiler used to process the",
-		"\ttarget code (e.g. gcc)."
+		"\ttarget code (e.g. gcc).",
+		"--no-warn-table-with-inline",
+		"\tDisable warnings about tabled procedures that also have",
+		"\ta `pragma inline' declaration."
 	]).

 :- pred options_help_verbosity(io::di, io::uo) is det.
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.395
diff -u -r1.395 user_guide.texi
--- doc/user_guide.texi	20 Oct 2004 09:45:09 -0000	1.395
+++ doc/user_guide.texi	3 Nov 2004 14:40:43 -0000
@@ -4481,6 +4481,13 @@
 @item --warn-dead-procs
 @findex --warn-dead-procs
 Warn about procedures which are never called.
+
+ at sp 1
+ at item --no-warn-table-with-inline
+ at findex --no-warn-table-with-inline
+Disable warnings about tabled procedures that also have
+a `pragma inline' declaration.
+
 @end table

 @node Verbosity options
Index: tests/warnings/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/warnings/Mmakefile,v
retrieving revision 1.34
diff -u -r1.34 Mmakefile
--- tests/warnings/Mmakefile	12 Feb 2004 03:36:17 -0000	1.34
+++ tests/warnings/Mmakefile	3 Nov 2004 14:33:46 -0000
@@ -26,6 +26,7 @@
 	simple_code \
 	singleton_test \
 	state_vars_test \
+	table_with_inline \
 	unused_args_analysis \
 	unused_args_test \
 	unused_import \
Index: tests/warnings/table_with_inline.exp
===================================================================
RCS file: tests/warnings/table_with_inline.exp
diff -N tests/warnings/table_with_inline.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/warnings/table_with_inline.exp	4 Nov 2004 04:41:12 -0000
@@ -0,0 +1,7 @@
+table_with_inline.m:011: Warning: function `table_with_inline.foo/1' has a
+table_with_inline.m:011:   `:- pragma memo' declaration but also has a
+table_with_inline.m:011:   `:- pragma inline' declaration.
+table_with_inline.m:011:   This inline pragma will be ignored since tabled
+table_with_inline.m:011:   predicates cannot be inlined.
+table_with_inline.m:011:   You can use the `--no-warn-table-with-inline' option
+table_with_inline.m:011:   to suppress this warning.
Index: tests/warnings/table_with_inline.m
===================================================================
RCS file: tests/warnings/table_with_inline.m
diff -N tests/warnings/table_with_inline.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/warnings/table_with_inline.m	3 Nov 2004 14:25:44 -0000
@@ -0,0 +1,14 @@
+:- module table_with_inline.
+
+:- interface.
+
+:- import_module int.
+
+:- func foo(int) = int.
+
+:- implementation.
+
+:- pragma memo(foo/1).
+:- pragma inline(foo/1).
+
+foo(A) = A + A.

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