[m-rev.] minor cleanups
Zoltan Somogyi
zs at csse.unimelb.edu.au
Mon Jul 20 12:22:34 AEST 2009
compiler/delay_info.m:
Reorder some arguments to allow the use of state variables.
compiler/modes.m:
Rename a predicate to avoid ambibuity.
Replace a bool with a purpose-specific type.
compiler/mercury_compile.m:
Conform to the changes above.
Zoltan.
cvs diff: Diffing .
Index: delay_info.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/delay_info.m,v
retrieving revision 1.30
diff -u -b -r1.30 delay_info.m
--- delay_info.m 6 Jan 2007 09:23:29 -0000 1.30
+++ delay_info.m 20 Jul 2009 01:14:18 -0000
@@ -54,8 +54,8 @@
% Insert a new delayed goal into the delay_info structure.
%
-:- pred delay_info_delay_goal(delay_info::in, mode_error_info::in,
- hlds_goal::in, delay_info::out) is det.
+:- pred delay_info_delay_goal(mode_error_info::in, hlds_goal::in,
+ delay_info::in, delay_info::out) is det.
% Mark a list of variables as having been bound.
% This may allow a previously delayed goal to change status
@@ -297,7 +297,7 @@
% We are going to delay a goal.
% Update the delay info structure to record the delayed goal.
%
-delay_info_delay_goal(DelayInfo0, Error, Goal, DelayInfo) :-
+delay_info_delay_goal(Error, Goal, DelayInfo0, DelayInfo) :-
delay_info_check_invariant(DelayInfo0),
Error = mode_error_info(Vars, _, _, _),
DelayInfo0 = delay_info(CurrentDepth, DelayedGoalStack0,
Index: mercury_compile.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.495
diff -u -b -r1.495 mercury_compile.m
--- mercury_compile.m 1 Jul 2009 07:09:30 -0000 1.495
+++ mercury_compile.m 20 Jul 2009 01:30:17 -0000
@@ -2583,14 +2583,14 @@
maybe_mode_constraints(Verbose, Stats, !HLDS, !IO),
maybe_dump_hlds(!.HLDS, 33, "mode_constraints", !DumpInfo, !IO),
- modecheck(Verbose, Stats, !HLDS, FoundModeError, UnsafeToContinue, !IO),
+ modecheck(Verbose, Stats, !HLDS, FoundModeError, SafeToContinue, !IO),
maybe_dump_hlds(!.HLDS, 35, "modecheck", !DumpInfo, !IO),
(
- UnsafeToContinue = yes,
+ SafeToContinue = modes_unsafe_to_continue,
FoundError = yes
;
- UnsafeToContinue = no,
+ SafeToContinue = modes_safe_to_continue,
detect_switches(Verbose, Stats, !HLDS, !IO),
maybe_dump_hlds(!.HLDS, 40, "switch_detect", !DumpInfo, !IO),
@@ -3143,24 +3143,24 @@
maybe_report_stats(Stats, !IO).
:- pred modecheck(bool::in, bool::in, module_info::in, module_info::out,
- bool::out, bool::out, io::di, io::uo) is det.
+ bool::out, modes_safe_to_continue::out, io::di, io::uo) is det.
-modecheck(Verbose, Stats, !HLDS, FoundModeError, UnsafeToContinue, !IO) :-
+modecheck(Verbose, Stats, !HLDS, FoundModeError, SafeToContinue, !IO) :-
module_info_get_num_errors(!.HLDS, NumErrors0),
maybe_benchmark_modes(
(pred(H0::in, {H, U}::out, !.IO::di, !:IO::uo) is det :-
- modecheck(H0, H, U, !IO)
+ modecheck_module(H0, H, U, !IO)
),
- "modecheck", !.HLDS, {!:HLDS, UnsafeToContinue}, !IO),
+ "modecheck", !.HLDS, {!:HLDS, SafeToContinue}, !IO),
module_info_get_num_errors(!.HLDS, NumErrors),
- ( NumErrors \= NumErrors0 ->
+ ( NumErrors = NumErrors0 ->
+ FoundModeError = no,
+ maybe_write_string(Verbose, "% Program is mode-correct.\n", !IO)
+ ;
FoundModeError = yes,
maybe_write_string(Verbose, "% Program contains mode error(s).\n",
!IO),
io.set_exit_status(1, !IO)
- ;
- FoundModeError = no,
- maybe_write_string(Verbose, "% Program is mode-correct.\n", !IO)
),
maybe_report_stats(Stats, !IO).
Index: modes.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/modes.m,v
retrieving revision 1.377
diff -u -b -r1.377 modes.m
--- modes.m 11 Jun 2009 07:00:15 -0000 1.377
+++ modes.m 20 Jul 2009 01:30:52 -0000
@@ -114,14 +114,14 @@
% used in liveness.m and the code generator. Here, we consider
% a variable live if its value will be used later on in the computation.
%
-% XXX we ought to allow unification of free with free even when both
-% *variables* are live, if one of the particular *sub-nodes* is
-% dead (causes problems handling e.g. `list.same_length').
+% XXX We ought to allow unification of free with free even when both
+% *variables* are live, if one of the particular *sub-nodes* is dead
+% (causes problems handling e.g. `list.same_length').
%
-% XXX we ought to break unifications into "micro-unifications", because
+% XXX We ought to break unifications into "micro-unifications", because
% some code can't be scheduled without splitting up unifications.
-% For example, `p(X) :- X = f(A, B), B is A + 1.', where
-% p is declared as `:- mode p(bound(f(ground,free))->ground).'.
+% For example, `p(X) :- X = f(A, B), B is A + 1.', where p is declared as
+% `:- mode p(bound(f(ground,free))->ground).'.
%
%-----------------------------------------------------------------------------%
@@ -145,22 +145,27 @@
%-----------------------------------------------------------------------------%
- % modecheck(HLDS0, HLDS, UnsafeToContinue):
+:- type modes_safe_to_continue
+ ---> modes_safe_to_continue
+ ; modes_unsafe_to_continue.
+
+ % modecheck_module(!HLDS, safeToContinue, !IO):
%
% Perform mode inference and checking for a whole module.
- % UnsafeToContinue = yes means that mode inference was halted
- % prematurely, due to an error, and that we should therefore
- % not perform determinism-checking, because we might get
- % internal errors.
%
-:- pred modecheck(module_info::in, module_info::out, bool::out,
- io::di, io::uo) is det.
+ % SafeToContinue = modes_unsafe_to_continue means that mode inference
+ % was halted prematurely due to an error, and that we should therefore
+ % not perform determinism-checking, because we might get internal errors.
+ %
+:- pred modecheck_module(module_info::in, module_info::out,
+ modes_safe_to_continue::out, io::di, io::uo) is det.
% Mode-check or unique-mode-check the code of all the predicates
% in a module.
%
:- pred check_pred_modes(how_to_check_goal::in, may_change_called_proc::in,
- module_info::in, module_info::out, bool::out, io::di, io::uo) is det.
+ module_info::in, module_info::out, modes_safe_to_continue::out,
+ io::di, io::uo) is det.
% Mode-check the code for the given predicate in a given mode.
% Returns the number of errs found and a bool `Changed'
@@ -405,13 +410,13 @@
%-----------------------------------------------------------------------------%
-modecheck(!Module, UnsafeToContinue, !IO) :-
+modecheck_module(!Module, SafeToContinue, !IO) :-
globals.io_lookup_bool_option(statistics, Statistics, !IO),
globals.io_lookup_bool_option(verbose, Verbose, !IO),
maybe_write_string(Verbose, "% Mode-checking clauses...\n", !IO),
check_pred_modes(check_modes, may_change_called_proc, !Module,
- UnsafeToContinue, !IO),
+ SafeToContinue, !IO),
maybe_report_stats(Statistics, !IO).
%-----------------------------------------------------------------------------%
@@ -419,25 +424,25 @@
% Mode-check the code for all the predicates in a module.
check_pred_modes(WhatToCheck, MayChangeCalledProc,
- !ModuleInfo, UnsafeToContinue, !IO) :-
+ !ModuleInfo, SafeToContinue, !IO) :-
module_info_predids(PredIds, !ModuleInfo),
globals.io_lookup_int_option(mode_inference_iteration_limit,
MaxIterations, !IO),
modecheck_to_fixpoint(PredIds, MaxIterations, WhatToCheck,
- MayChangeCalledProc, !ModuleInfo, UnsafeToContinue0, !IO),
+ MayChangeCalledProc, !ModuleInfo, SafeToContinue0, !IO),
(
WhatToCheck = check_unique_modes,
write_mode_inference_messages(PredIds, yes, !.ModuleInfo, !IO),
check_eval_methods(!ModuleInfo, !IO),
- UnsafeToContinue = UnsafeToContinue0
+ SafeToContinue = SafeToContinue0
;
WhatToCheck = check_modes,
(
- UnsafeToContinue0 = yes,
+ SafeToContinue0 = modes_unsafe_to_continue,
write_mode_inference_messages(PredIds, no, !.ModuleInfo, !IO),
- UnsafeToContinue = yes
+ SafeToContinue = modes_unsafe_to_continue
;
- UnsafeToContinue0 = no,
+ SafeToContinue0 = modes_safe_to_continue,
globals.io_lookup_bool_option(delay_partial_instantiations,
DelayPartialInstantiations, !IO),
(
@@ -447,10 +452,10 @@
% --delay-partial-instantiations requires mode checking to be
% run again.
modecheck_to_fixpoint(ChangedPreds, MaxIterations, WhatToCheck,
- MayChangeCalledProc, !ModuleInfo, UnsafeToContinue, !IO)
+ MayChangeCalledProc, !ModuleInfo, SafeToContinue, !IO)
;
DelayPartialInstantiations = no,
- UnsafeToContinue = no
+ SafeToContinue = modes_safe_to_continue
)
)
).
@@ -459,10 +464,11 @@
%
:- pred modecheck_to_fixpoint(list(pred_id)::in, int::in,
how_to_check_goal::in, may_change_called_proc::in,
- module_info::in, module_info::out, bool::out, io::di, io::uo) is det.
+ module_info::in, module_info::out, modes_safe_to_continue::out,
+ io::di, io::uo) is det.
modecheck_to_fixpoint(PredIds, MaxIterations, WhatToCheck, MayChangeCalledProc,
- !ModuleInfo, UnsafeToContinue, !IO) :-
+ !ModuleInfo, SafeToContinue, !IO) :-
% Save the old procedure bodies so that we can restore them for the
% next pass.
module_info_preds(!.ModuleInfo, OldPredTable0),
@@ -480,13 +486,15 @@
bool.or(Changed1, Changed2, Changed),
% Stop if we have reached a fixpoint or found any errors.
- ( ( Changed = no ; NumErrors > 0 ; ExitStatus \= 0 ) ->
- UnsafeToContinue = Changed
+ ( Changed = no ->
+ SafeToContinue = modes_safe_to_continue
+ ; ( NumErrors > 0 ; ExitStatus \= 0 ) ->
+ SafeToContinue = modes_unsafe_to_continue
;
% Stop if we have exceeded the iteration limit.
( MaxIterations =< 1 ->
report_max_iterations_exceeded(!.ModuleInfo, !IO),
- UnsafeToContinue = yes
+ SafeToContinue = modes_unsafe_to_continue
;
globals.io_lookup_bool_option(debug_modes, DebugModes, !IO),
(
@@ -520,7 +528,7 @@
MaxIterations1 = MaxIterations - 1,
modecheck_to_fixpoint(PredIds, MaxIterations1, WhatToCheck,
- MayChangeCalledProc, !ModuleInfo, UnsafeToContinue, !IO)
+ MayChangeCalledProc, !ModuleInfo, SafeToContinue, !IO)
)
).
@@ -2558,7 +2566,7 @@
mode_info_set_errors([], !ModeInfo),
mode_info_set_instmap(InstMap0, !ModeInfo),
mode_info_add_live_vars(NonLocalVars, !ModeInfo),
- delay_info_delay_goal(DelayInfo0, FirstErrorInfo, Goal0, DelayInfo1),
+ delay_info_delay_goal(FirstErrorInfo, Goal0, DelayInfo0, DelayInfo1),
% Delaying an impure goal is an impurity error.
(
Impure = yes,
@@ -3130,11 +3138,11 @@
:- pred redelay_goals(list(delayed_goal)::in, delay_info::in, delay_info::out)
is det.
-redelay_goals([], DelayInfo, DelayInfo).
-redelay_goals([DelayedGoal | DelayedGoals], DelayInfo0, DelayInfo) :-
+redelay_goals([], !DelayInfo).
+redelay_goals([DelayedGoal | DelayedGoals], !DelayInfo) :-
DelayedGoal = delayed_goal(_WaitingVars, ModeErrorInfo, Goal),
- delay_info_delay_goal(DelayInfo0, ModeErrorInfo, Goal, DelayInfo1),
- redelay_goals(DelayedGoals, DelayInfo1, DelayInfo).
+ delay_info_delay_goal(ModeErrorInfo, Goal, !DelayInfo),
+ redelay_goals(DelayedGoals, !DelayInfo).
%-----------------------------------------------------------------------------%
cvs diff: Diffing notes
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list