[m-rev.] diff/for review: improve warnings for obsolete procedures

Julien Fischer juliensf at cs.mu.OZ.AU
Mon Mar 27 15:00:56 AEDT 2006


Estimated hours taken: 1
Branches: main

Add a new option `--no-warn-obsolete' that disables warnings about calls to
predicates and functions that have `:- pragma obsolete' declarations.
Previously, this was controlled by `--no-warn-simple-code', but that was
non-obvious and you wouldn't necessarily want to disable all the other
warnings.  `--no-warn-simple-code' will no longer disable warnings about
obsolete procedures.

Avoid emitting warnings if about calls to obsolete procedures if those calls
are from within a procedure that is itself obsolete.

doc/user_guide.texi:
compiler/options.m:
	Add a new option: `--no-warn-obsolete'.

tests/valid/Mmakefile:
tests/valid/Mercury.options:
tests/valid/no_warn_obsolete.m:
	Test the new option.

compiler/simplify.m:
	Don't warn about calls to obsolete procedures from obsolete
	procedures.

tests/warnings/Mmakefile:
tests/warnings/spurious_obsolete.m:
tests/warnings/spurious_obsolete.exp:
	Test case for the above.

Julien.

Index: compiler/options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.506
diff -u -r1.506 options.m
--- compiler/options.m	24 Mar 2006 03:03:57 -0000	1.506
+++ compiler/options.m	27 Mar 2006 03:11:50 -0000
@@ -109,6 +109,7 @@
     ;       warn_non_term_special_preds
     ;       warn_known_bad_format_calls
     ;       warn_unknown_format_calls
+    ;       warn_obsolete

     % Verbosity options
     ;       verbose
@@ -848,7 +849,8 @@
     warn_table_with_inline              -   bool(yes),
     warn_non_term_special_preds         -   bool(yes),
     warn_known_bad_format_calls         -   bool(yes),
-    warn_unknown_format_calls           -   bool(no)
+    warn_unknown_format_calls           -   bool(no),
+    warn_obsolete                       -   bool(yes)
 ]).
 option_defaults_2(verbosity_option, [
     % Verbosity Options
@@ -1541,6 +1543,7 @@
 long_option("warn-non-term-special-preds", warn_non_term_special_preds).
 long_option("warn-known-bad-format-calls", warn_known_bad_format_calls).
 long_option("warn-unknown-format-calls", warn_unknown_format_calls).
+long_option("warn-obsolete",             warn_obsolete).

 % verbosity options
 long_option("verbose",                  verbose).
@@ -2805,7 +2808,10 @@
         "--warn-unknown-format-call",
         "\tWarn about calls to string.format or io.format for which",
         "\tthe compiler cannot tell whether there are any mismatches",
-        "\tbetween the format string and the supplied values."
+        "\tbetween the format string and the supplied values.",
+        "--no-warn-obsolete",
+        "\tDo not warn about calls to predicates or functions that have been",
+        "\tmarked as obsolete."
     ]).

 :- pred options_help_verbosity(io::di, io::uo) is det.
Index: compiler/simplify.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/simplify.m,v
retrieving revision 1.171
diff -u -r1.171 simplify.m
--- compiler/simplify.m	24 Mar 2006 03:04:02 -0000	1.171
+++ compiler/simplify.m	27 Mar 2006 03:58:25 -0000
@@ -75,6 +75,7 @@
     ;       warn_duplicate_calls    % --warn-duplicate-calls
     ;       warn_known_bad_format   % --warn-known-bad-format-calls
     ;       warn_unknown_format     % --warn-unknown-format-calls
+    ;       warn_obsolete           % --warn-obsolete
     ;       do_once                 % run things that should be done once
     ;       excess_assigns          % remove excess assignment unifications
     ;       duplicate_calls         % optimize duplicate calls
@@ -373,7 +374,9 @@
         set_by_option(Globals, warn_known_bad_format_calls,
             warn_known_bad_format, !Simps),
         set_by_option(Globals, warn_unknown_format_calls,
-            warn_unknown_format, !Simps)
+            warn_unknown_format, !Simps),
+        set_by_option(Globals, warn_obsolete, warn_obsolete,
+            !Simps)
     ;
         WarnThisPass = no
     ),
@@ -1299,17 +1302,24 @@
     module_info_pred_proc_info(ModuleInfo, PredId, ProcId, PredInfo, ProcInfo),
     % Check for calls to predicates with `pragma obsolete' declarations.
     (
-        simplify_do_warn(!.Info),
+        simplify_do_warn_obsolete(!.Info),
         pred_info_get_markers(PredInfo, Markers),
         check_marker(Markers, obsolete),

+        simplify_info_get_det_info(!.Info, DetInfo0),
+        det_info_get_pred_id(DetInfo0, ThisPredId),
+
         % Don't warn about directly recursive calls. (That would cause
         % spurious warnings, particularly with builtin predicates,
         % or preds defined using foreign_procs.)
+        PredId \= ThisPredId,

-        simplify_info_get_det_info(!.Info, DetInfo0),
-        det_info_get_pred_id(DetInfo0, ThisPredId),
-        PredId \= ThisPredId
+        % Don't warn about calls from predicates that also have a
+        % `pramga obsolete' declaration.  Doing so just results in
+        % spurious warnings.
+        module_info_pred_info(ModuleInfo, ThisPredId, ThisPredInfo),
+        pred_info_get_markers(ThisPredInfo, ThisPredMarkers),
+        not check_marker(ThisPredMarkers, obsolete)
     ->
         goal_info_get_context(GoalInfo0, Context1),
         ObsoleteMsg = warn_obsolete(PredId),
@@ -2486,6 +2496,7 @@

 :- pred simplify_do_warn(simplify_info::in) is semidet.
 :- pred simplify_do_warn_calls(simplify_info::in) is semidet.
+:- pred simplify_do_warn_obsolete(simplify_info::in) is semidet.
 :- pred simplify_do_once(simplify_info::in) is semidet.
 :- pred simplify_do_common(simplify_info::in) is semidet.
 :- pred simplify_do_excess_assigns(simplify_info::in) is semidet.
@@ -2501,6 +2512,9 @@
 simplify_do_warn_calls(Info) :-
     simplify_info_get_simplifications(Info, Simplifications),
     set.member(warn_duplicate_calls, Simplifications).
+simplify_do_warn_obsolete(Info) :-
+    simplify_info_get_simplifications(Info, Simplifications),
+    set.member(warn_obsolete, Simplifications).
 simplify_do_once(Info) :-
     simplify_info_get_simplifications(Info, Simplifications),
     set.member(do_once, Simplifications).
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.470
diff -u -r1.470 user_guide.texi
--- doc/user_guide.texi	1 Mar 2006 22:58:44 -0000	1.470
+++ doc/user_guide.texi	27 Mar 2006 03:11:57 -0000
@@ -5268,6 +5268,12 @@
 the compiler cannot tell whether there are any mismatches between
 the format string and the supplied values.

+ at sp 1
+ at item --no-warn-obsolete
+ at findex --no-warn-obsolete
+Do not warn about calls to predicates or functionat that have been
+marked as obsolete.
+
 @end table

 @node Verbosity options
Index: tests/valid/Mercury.options
===================================================================
RCS file: /home/mercury1/repository/tests/valid/Mercury.options,v
retrieving revision 1.28
diff -u -r1.28 Mercury.options
--- tests/valid/Mercury.options	17 Feb 2006 04:10:26 -0000	1.28
+++ tests/valid/Mercury.options	27 Mar 2006 03:09:59 -0000
@@ -87,6 +87,7 @@
 MCFLAGS-middle_rec_labels	= --middle-rec
 MCFLAGS-mostly_uniq_mode_inf	= --infer-all
 MCFLAGS-mpj6			= --infer-all
+MCFLAGS-no_warn_obsolete	= --no-warn-obsolete
 MCFLAGS-pred_with_no_modes	= --infer-all
 MCFLAGS-quantifier_warning	= --halt-at-warn
 MCFLAGS-simplify_bug2		= -O3
Index: tests/valid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/valid/Mmakefile,v
retrieving revision 1.168
diff -u -r1.168 Mmakefile
--- tests/valid/Mmakefile	20 Mar 2006 22:24:30 -0000	1.168
+++ tests/valid/Mmakefile	27 Mar 2006 03:10:28 -0000
@@ -154,6 +154,7 @@
 	nasty_func_test \
 	nested_mod_type_bug \
 	nested_module_bug \
+	no_warn_obsolete \
 	nondet_live \
 	overloading \
 	parsing_bug_main \
Index: tests/valid/no_warn_obsolete.m
===================================================================
RCS file: tests/valid/no_warn_obsolete.m
diff -N tests/valid/no_warn_obsolete.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/valid/no_warn_obsolete.m	27 Mar 2006 02:58:50 -0000
@@ -0,0 +1,15 @@
+% Test case for the --no-warn-obsolete option.
+%
+:- module no_warn_obsolete.
+:- interface.
+
+:- pragma obsolete(foo/1).
+:- pred foo(int::in) is semidet.
+
+:- pred bar(int::in) is semidet.
+
+:- implementation.
+
+foo(1).
+
+bar(X) :- foo(X).
Index: tests/warnings/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/warnings/Mmakefile,v
retrieving revision 1.42
diff -u -r1.42 Mmakefile
--- tests/warnings/Mmakefile	27 Feb 2006 06:57:06 -0000	1.42
+++ tests/warnings/Mmakefile	27 Mar 2006 03:16:25 -0000
@@ -27,6 +27,7 @@
 	purity_warnings \
 	simple_code \
 	singleton_test \
+	spurious_obsolete \
 	state_vars_test \
 	table_with_inline \
 	unify_f_g \
Index: tests/warnings/spurious_obsolete.exp
===================================================================
RCS file: tests/warnings/spurious_obsolete.exp
diff -N tests/warnings/spurious_obsolete.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/warnings/spurious_obsolete.exp	27 Mar 2006 03:17:20 -0000
@@ -0,0 +1,2 @@
+spurious_obsolete.m:020: Warning: call to obsolete predicate
+spurious_obsolete.m:020:   `spurious_obsolete.foo/1'.
Index: tests/warnings/spurious_obsolete.m
===================================================================
RCS file: tests/warnings/spurious_obsolete.m
diff -N tests/warnings/spurious_obsolete.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/warnings/spurious_obsolete.m	27 Mar 2006 03:17:01 -0000
@@ -0,0 +1,20 @@
+:- module spurious_obsolete.
+:- interface.
+
+:- pragma obsolete(foo/1).
+:- pred foo(int::in) is semidet.
+
+:- pragma obsolete(bar/1).
+:- pred bar(int::in) is semidet.
+
+:- pred baz(int::in) is semidet.
+
+:- implementation.
+
+foo(1).
+
+% We shouldn't get a warning about this call to foo/1 ...
+bar(X) :- foo(X).
+
+% but we should get one about this one.
+baz(X) :- foo(X).
--------------------------------------------------------------------------
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