[m-rev.] diff: option to disable unification warnings
Mark Brown
mark at cs.mu.OZ.AU
Tue Feb 7 20:41:05 AEDT 2006
Estimated hours taken: 0.5
Branches: main
Add an option to inhibit warnings about unifications that cannot succeed.
Such code is sometimes useful, for example if you have debugging code that
is normally meant to be compiled away.
compiler/options.m:
Add and document the option.
compiler/modecheck_unify.m:
Check the option before outputting the warning.
Index: compiler/modecheck_unify.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modecheck_unify.m,v
retrieving revision 1.95
diff -u -r1.95 modecheck_unify.m
--- compiler/modecheck_unify.m 14 Dec 2005 05:14:14 -0000 1.95
+++ compiler/modecheck_unify.m 6 Feb 2006 06:31:30 -0000
@@ -67,6 +67,8 @@
:- import_module hlds.make_hlds.
:- import_module hlds.quantification.
:- import_module libs.compiler_util.
+:- import_module libs.globals.
+:- import_module libs.options.
:- import_module mdbcomp.prim_data.
:- import_module parse_tree.module_qual.
:- import_module parse_tree.prog_mode.
@@ -648,7 +650,7 @@
%
% Optimize away construction of unused terms by replacing the unification
- % with `true'. Optimize % away unifications which always fail by replacing
+ % with `true'. Optimize away unifications which always fail by replacing
% them with `fail'.
%
(
@@ -666,17 +668,24 @@
% Unifying two preds is not erroneous as far as the mode checker
% is concerned, but a mode _error_.
Goal = disj([]),
- InitMayHaveSubtype = init_instmap_may_have_subtype(!.ModeInfo),
+ globals__io_lookup_bool_option(warn_unification_cannot_succeed,
+ WarnCannotSucceed, !IO),
(
- InitMayHaveSubtype = yes
- % Suppress the warning, since the unification may succeed
- % in another mode in which the initial inst of X,
- % or of another head variable that is unified with it,
- % is not so constrained.
+ WarnCannotSucceed = yes,
+ InitMayHaveSubtype = init_instmap_may_have_subtype(!.ModeInfo),
+ (
+ InitMayHaveSubtype = yes
+ % Suppress the warning, since the unification may succeed
+ % in another mode in which the initial inst of X,
+ % or of another head variable that is unified with it,
+ % is not so constrained.
+ ;
+ InitMayHaveSubtype = no,
+ Warning = cannot_succeed_var_functor(X, InstOfX, ConsId),
+ mode_info_warning(Warning, !ModeInfo)
+ )
;
- InitMayHaveSubtype = no,
- Warning = cannot_succeed_var_functor(X, InstOfX, ConsId),
- mode_info_warning(Warning, !ModeInfo)
+ WarnCannotSucceed = no
)
;
Functor = functor(ConsId, IsExistConstruction, ArgVars),
@@ -956,19 +965,28 @@
% Unifying two preds is not erroneous as far as the
% mode checker is concerned, but a mode _error_.
Unify = disj([]),
- InitMayHaveSubtype = init_instmap_may_have_subtype(!.ModeInfo),
+ mode_info_get_module_info(!.ModeInfo, ModuleInfo),
+ module_info_get_globals(ModuleInfo, Globals),
+ globals__lookup_bool_option(Globals, warn_unification_cannot_succeed,
+ WarnCannotSucceed),
(
- InitMayHaveSubtype = yes
- % Suppress the warning, since the unification may succeed
- % in another mode in which the initial inst of X or Y,
- % or of another head variable that is unified with one of them,
- % is not so constrained.
+ WarnCannotSucceed = yes,
+ InitMayHaveSubtype = init_instmap_may_have_subtype(!.ModeInfo),
+ (
+ InitMayHaveSubtype = yes
+ % Suppress the warning, since the unification may succeed
+ % in another mode in which the initial inst of X or Y,
+ % or of another head variable that is unified with one of them,
+ % is not so constrained.
+ ;
+ InitMayHaveSubtype = no,
+ mode_get_insts(ModuleInfo0, ModeOfX, InstOfX, _),
+ mode_get_insts(ModuleInfo0, ModeOfY, InstOfY, _),
+ Warning = cannot_succeed_var_var(X, Y, InstOfX, InstOfY),
+ mode_info_warning(Warning, !ModeInfo)
+ )
;
- InitMayHaveSubtype = no,
- mode_get_insts(ModuleInfo0, ModeOfX, InstOfX, _),
- mode_get_insts(ModuleInfo0, ModeOfY, InstOfY, _),
- Warning = cannot_succeed_var_var(X, Y, InstOfX, InstOfY),
- mode_info_warning(Warning, !ModeInfo)
+ WarnCannotSucceed = no
)
;
Unify = unify(X, var(Y), ModeOfX - ModeOfY, Unification, UnifyContext)
Index: compiler/options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.494
diff -u -r1.494 options.m
--- compiler/options.m 6 Feb 2006 05:39:43 -0000 1.494
+++ compiler/options.m 6 Feb 2006 06:12:04 -0000
@@ -93,6 +93,7 @@
; warn_missing_trans_opt_files
; warn_missing_trans_opt_deps
; warn_non_stratification
+ ; warn_unification_cannot_succeed
; warn_simple_code
; warn_duplicate_calls
; warn_missing_module_name
@@ -843,6 +844,7 @@
warn_missing_opt_files - bool(yes),
warn_missing_trans_opt_files - bool(no),
warn_missing_trans_opt_deps - bool(yes),
+ warn_unification_cannot_succeed - bool(yes),
warn_simple_code - bool(yes),
warn_duplicate_calls - bool(no),
warn_missing_module_name - bool(yes),
@@ -1545,6 +1547,8 @@
long_option("warn-missing-opt-files", warn_missing_opt_files).
long_option("warn-missing-trans-opt-files", warn_missing_trans_opt_files).
long_option("warn-missing-trans-opt-deps", warn_missing_trans_opt_deps).
+long_option("warn-unification-cannot-succeed",
+ warn_unification_cannot_succeed).
long_option("warn-simple-code", warn_simple_code).
long_option("warn-duplicate-calls", warn_duplicate_calls).
long_option("warn-missing-module-name", warn_missing_module_name).
@@ -2327,6 +2331,7 @@
warn_missing_opt_files - bool(Enable),
warn_missing_trans_opt_files - bool(Enable),
warn_missing_trans_opt_deps - bool(Enable),
+ warn_unification_cannot_succeed - bool(Enable),
warn_simple_code - bool(Enable),
warn_missing_module_name - bool(Enable),
warn_wrong_module_name - bool(Enable),
@@ -2795,6 +2800,8 @@
"\tWarn about possible non-stratification in the module.",
"\tNon-stratification occurs when a predicate/function can call",
"\titself negatively through some path along its call graph.",
+ "--no-warn-unification-cannot-succeed",
+ "\tDisable warnings about unifications which cannot succeed.",
"--no-warn-simple-code",
"\tDisable warnings about constructs which are so",
"\tsimple that they are likely to be programming errors.",
--------------------------------------------------------------------------
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