[m-rev.] diff: review comments as minor cleanups
Zoltan Somogyi
zs at cs.mu.OZ.AU
Mon Feb 6 13:31:07 AEDT 2006
Minor cleanups of Richard's recent update, basically review comments
I could address more easily myself.
compiler/abstract_mode_constraints.m:
compiler/build_mode_constraints.m:
compiler/mcsolver.m:
compiler/ordering_mode_constraints.m:
compiler/prop_mode_constraints.m:
Remove unnecessary module qualifications whose only effect was to
add clutter. When a piece of functionality was present in both
predicate and function forms, keep only the more convenient form.
Use multilevel switches on list lengths where relevant. Rename some
variables to conform with our conventions. Make comments into
complete sentences. Fix some white space issues.
Zoltan.
cvs diff: Diffing .
cvs diff: Diffing analysis
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/doc
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
Index: compiler/abstract_mode_constraints.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/abstract_mode_constraints.m,v
retrieving revision 1.5
diff -u -b -r1.5 abstract_mode_constraints.m
--- compiler/abstract_mode_constraints.m 2 Feb 2006 00:37:58 -0000 1.5
+++ compiler/abstract_mode_constraints.m 3 Feb 2006 22:31:16 -0000
@@ -154,46 +154,35 @@
%-----------------------------------------------------------------------------%
- % Initialises all the parts of a pred_p_c_constraints type.
- %
-:- pred abstract_mode_constraints.init(pred_p_c_constraints::out) is det.
-
% Function version if init/1.
%
-:- func abstract_mode_constraints.init = pred_p_c_constraints.
+:- func init = pred_p_c_constraints.
% add_constraint(Formula, !PredConstraints) adds the constraint
% given by Formula to the constraint system in PredConstraints.
%
-:- pred abstract_mode_constraints.add_constraint(prog_context::in,
- constraint_formula::in, pred_p_c_constraints::in,
- pred_p_c_constraints::out) is det.
-
- % Function version of add_constraint/3.
- %
-:- func abstract_mode_constraints.add_constraint(prog_context,
- constraint_formula, pred_p_c_constraints) = pred_p_c_constraints.
+:- pred add_constraint(prog_context::in, constraint_formula::in,
+ pred_p_c_constraints::in, pred_p_c_constraints::out) is det.
% Adds a procedure specific constraint to the system.
%
-:- pred abstract_mode_constraints.add_constraint(prog_context::in, proc_id::in,
- constraint_formula::in, pred_p_c_constraints::in,
- pred_p_c_constraints::out) is det.
+:- pred add_constraint(prog_context::in, proc_id::in, constraint_formula::in,
+ pred_p_c_constraints::in, pred_p_c_constraints::out) is det.
% pred_constraints_to_formulae rips the barebones
% constraints (those that apply to all procedures of a
% predicate) out of the pred_p_c_constraints structure
% and returns them as a list of constraint formulae.
%
-:- func abstract_mode_constraints.pred_constraints_to_formulae(
- pred_p_c_constraints) = constraint_formulae.
+:- func pred_constraints_to_formulae(pred_p_c_constraints)
+ = constraint_formulae.
% pred_constraints_to_formulae/2 returns all constraints that
% apply to the given procedure from the pred_p_c_constraints,
% including constraints that apply to all procedures.
%
-:- func abstract_mode_constraints.pred_constraints_to_formulae(
- proc_id, pred_p_c_constraints) = constraint_formulae.
+:- func pred_constraints_to_formulae(proc_id, pred_p_c_constraints)
+ = constraint_formulae.
% pred_constraints_to_formulae_and_annotations returns constraints
% that apply to all procedures of a predicate as a list of pairs of
@@ -208,16 +197,16 @@
% procedures, with their constraint annotations, in pairs.
%
:- func pred_constraints_to_formulae_and_annotations(proc_id,
- pred_p_c_constraints) = assoc_list(constraint_formula,
- constraint_annotation).
+ pred_p_c_constraints)
+ = assoc_list(constraint_formula, constraint_annotation).
% proc_constraints_to_formulae_and_annotations(ProcId, PredConstraints)
% returns constraints that apply specifically to the given
% procedure (but not constraints that apply to all procedures).
%
:- func proc_constraints_to_formulae_and_annotations(proc_id,
- pred_p_c_constraints) = assoc_list(constraint_formula,
- constraint_annotation).
+ pred_p_c_constraints)
+ = assoc_list(constraint_formula, constraint_annotation).
%-----------------------------------------------------------------------------%
@@ -225,15 +214,15 @@
% Constraints. Context should be the context of the goal or
% declaration that imposed this constraint.
%
-:- pred equiv_no(prog_context::in, mc_var::in, pred_p_c_constraints::in,
- pred_p_c_constraints::out) is det.
+:- pred equiv_no(prog_context::in, mc_var::in,
+ pred_p_c_constraints::in, pred_p_c_constraints::out) is det.
% equivalent(Context, MCVars, !Constraints) constrains MCVars in
% Constraints to all take the same value. Context should be the context of
% the goal or declaration that imposed this constraint.
%
-:- pred equivalent(prog_context::in, list(mc_var)::in, pred_p_c_constraints::in,
- pred_p_c_constraints::out) is det.
+:- pred equivalent(prog_context::in, list(mc_var)::in,
+ pred_p_c_constraints::in, pred_p_c_constraints::out) is det.
% equiv_disj(Context, X, Ys, !Constraints) constrains X and Ys in
% Constraints such that (X <-> disj(Ys)) - ie if X is true at least one of
@@ -270,8 +259,8 @@
% one of them to be true. Context should be the context of the goal or
% declaration that imposed this constraint.
%
-:- pred xor(prog_context::in, mc_var::in, mc_var::in, pred_p_c_constraints::in,
- pred_p_c_constraints::out) is det.
+:- pred xor(prog_context::in, mc_var::in, mc_var::in,
+ pred_p_c_constraints::in, pred_p_c_constraints::out) is det.
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
@@ -285,36 +274,24 @@
%-----------------------------------------------------------------------------%
- % `unit'-like type used to distinguish mode constraint variables.
+ % Dummy type used to distinguish mode constraint variables.
%
:- type mc_type ---> mc_type.
% Initialises all the parts of a mode_constraints_info type.
%
-abstract_mode_constraints.init(pred_constraints(multi_map.init, [])).
-
- % See the predicate version.
- %
-abstract_mode_constraints.init = PredConstraints :-
- abstract_mode_constraints.init(PredConstraints).
+init = pred_constraints(multi_map.init, []).
% add_constraint(Formula, !PredConstraints) adds the constraint
% given by Formula to the constraint system in PredConstraints.
%
-abstract_mode_constraints.add_constraint(Context,
- ConstraintFormula, !PredConstraints) :-
+add_constraint(Context, ConstraintFormula, !PredConstraints) :-
AllProcsConstraints = !.PredConstraints ^ pred_constraints,
ConstraintAnnotation = constraint_annotation(Context),
FormulaAndAnnotation = pair(ConstraintFormula, ConstraintAnnotation),
!:PredConstraints = !.PredConstraints ^ pred_constraints :=
list.cons(FormulaAndAnnotation, AllProcsConstraints).
-
- % Functional version of add_constraint/3.
- %
-abstract_mode_constraints.add_constraint(Ctxt, CF, PCs0) = PCs :-
- abstract_mode_constraints.add_constraint(Ctxt, CF, PCs0, PCs).
-
% add_constraint(Context, ProcId, Formula, !PredConstraints) adds the
% constraint given by Formula to the constraint system in
% PredConstraints, and associates it specificaly with procedure
@@ -324,7 +301,6 @@
ProcConstraints = !.PredConstraints ^ proc_constraints,
ConstraintAnnotation = constraint_annotation(Context),
FormulaAndAnnotation = pair(ConstraintFormula, ConstraintAnnotation),
-
!:PredConstraints = !.PredConstraints ^ proc_constraints :=
multi_map.add(ProcConstraints, ProcId, FormulaAndAnnotation).
@@ -372,27 +348,27 @@
%
equiv_no(Context, MCVar, !Constraints) :-
- abstract_mode_constraints.add_constraint(Context,
- atomic_constraint(equiv_bool(MCVar, no)), !Constraints).
+ add_constraint(Context, atomic_constraint(equiv_bool(MCVar, no)),
+ !Constraints).
equivalent(Context, MCVars, !Constraints) :-
- abstract_mode_constraints.add_constraint(Context,
- atomic_constraint(equivalent(MCVars)), !Constraints).
+ add_constraint(Context, atomic_constraint(equivalent(MCVars)),
+ !Constraints).
equiv_disj(Context, X, Ys, !Constraints) :-
- abstract_mode_constraints.add_constraint(Context,
- atomic_constraint(equiv_disj(X, Ys)), !Constraints).
+ add_constraint(Context, atomic_constraint(equiv_disj(X, Ys)),
+ !Constraints).
at_most_one(Context, MCVars, !Constraints) :-
- abstract_mode_constraints.add_constraint(Context,
- atomic_constraint(at_most_one(MCVars)), !Constraints).
+ add_constraint(Context, atomic_constraint(at_most_one(MCVars)),
+ !Constraints).
not_both(Context, A, B, !Constraints) :-
at_most_one(Context, [A, B], !Constraints).
exactly_one(Context, MCVars, !Constraints) :-
- abstract_mode_constraints.add_constraint(Context,
- atomic_constraint(exactly_one(MCVars)), !Constraints).
+ add_constraint(Context, atomic_constraint(exactly_one(MCVars)),
+ !Constraints).
xor(Context, A, B, !Constraints) :-
exactly_one(Context, [A, B], !Constraints).
@@ -425,19 +401,15 @@
dump_constraint(Varset, Indent, Annotation, disj(Constraints), !IO) :-
Context = context(Annotation),
- write_error_pieces_maybe_with_context(yes(Context), Indent,
- [words("disj(")], !IO),
+ write_error_pieces(Context, Indent, [words("disj(")], !IO),
dump_constraints(Varset, Indent+1, Annotation, Constraints, !IO),
- write_error_pieces_maybe_with_context(yes(Context), Indent,
- [words(") end disj")], !IO).
+ write_error_pieces(Context, Indent, [words(") end disj")], !IO).
dump_constraint(Varset, Indent, Annotation, conj(Constraints), !IO) :-
Context = context(Annotation),
- write_error_pieces_maybe_with_context(yes(Context), Indent,
- [words("conj(")], !IO),
+ write_error_pieces(Context, Indent, [words("conj(")], !IO),
dump_constraints(Varset, Indent+1, Annotation, Constraints, !IO),
- write_error_pieces_maybe_with_context(yes(Context), Indent,
- [words(") end conj")], !IO).
+ write_error_pieces(Context, Indent, [words(") end conj")], !IO).
dump_constraint(Varset, Indent, Annotation, atomic_constraint(Constraint),
!IO) :-
@@ -452,22 +424,20 @@
mc_var_list_to_string(Varset, [X], VarName),
mc_var_val_to_string(Val, ValString),
Context = context(Annotation),
-
- write_error_pieces_maybe_with_context(yes(Context), Indent,
+ write_error_pieces(Context, Indent,
[words(VarName ++ " = " ++ ValString)], !IO).
dump_var_constraint(Varset, Indent, Annotation, equivalent(Xs), !IO) :-
mc_var_list_to_string(Varset, Xs, VarsString),
Context = context(Annotation),
- write_error_pieces_maybe_with_context(yes(Context), Indent,
+ write_error_pieces(Context, Indent,
[words("equivalent(" ++ VarsString ++ ")")], !IO).
dump_var_constraint(Varset, Indent, Annotation, implies(X, Y), !IO) :-
mc_var_list_to_string(Varset, [X], XName),
mc_var_list_to_string(Varset, [Y], YName),
Context = context(Annotation),
-
- write_error_pieces_maybe_with_context(yes(Context), Indent,
+ write_error_pieces(Context, Indent,
[words(XName ++ " -> " ++ YName)], !IO).
dump_var_constraint(Varset, Indent, Annotation, equiv_disj(X, Xs), !IO) :-
@@ -475,20 +445,19 @@
mc_var_list_to_string(Varset, Xs, XsString),
Context = context(Annotation),
Pieces = [words(XName ++ " <-> disj(" ++ XsString ++ ")")],
-
- write_error_pieces_maybe_with_context(yes(Context), Indent, Pieces, !IO).
+ write_error_pieces(Context, Indent, Pieces, !IO).
dump_var_constraint(Varset, Indent, Annotation, at_most_one(Xs), !IO) :-
mc_var_list_to_string(Varset, Xs, XsString),
Pieces = [words("at_most_one(" ++ XsString ++ ")")],
Context = context(Annotation),
- write_error_pieces_maybe_with_context(yes(Context), Indent, Pieces, !IO).
+ write_error_pieces(Context, Indent, Pieces, !IO).
dump_var_constraint(Varset, Indent, Annotation, exactly_one(Xs), !IO) :-
mc_var_list_to_string(Varset, Xs, XsString),
Pieces = [words("exactly_one(" ++ XsString ++ ")")],
Context = context(Annotation),
- write_error_pieces_maybe_with_context(yes(Context), Indent, Pieces, !IO).
+ write_error_pieces(Context, Indent, Pieces, !IO).
% mc_var_list_to_string(Varset, MCVars, MCVarsString)
% Makes a comma separated list of MCVars as a string.
@@ -511,7 +480,6 @@
mc_var_val_to_string(yes, "yes").
mc_var_val_to_string(no, "no").
-
%-----------------------------------------------------------------------------%
%
% Pretty printing predicates for the formulae type, and others
@@ -635,17 +603,19 @@
pretty_print_bindings(VarSet, Bindings, N, N + 1, !IO) :-
io.write_string("Solution " ++ string.from_int(N) ++ ":\n{\n", !IO),
Variables = map.keys(Bindings),
- list.foldl((pred(Var::in, IO0::di, IO::uo) is det :-
- io.write_string(" ", IO0, IO1),
- io.write_string(varset.lookup_name(VarSet, Var), IO1, IO2),
- io.write_string(" = ", IO2, IO3),
- map.lookup(Bindings, Var, Value),
- io.print(Value, IO3, IO4),
- io.nl(IO4, IO)
- ),
- Variables, !IO),
+ list.foldl(pretty_print_binding(VarSet, Bindings), Variables, !IO),
io.write_string("}\n", !IO).
+:- pred pretty_print_binding(mc_varset::in, mc_bindings::in, mc_var::in,
+ io::di, io::uo) is det.
+
+pretty_print_binding(VarSet, Bindings, Var, !IO) :-
+ io.write_string(" ", !IO),
+ io.write_string(varset.lookup_name(VarSet, Var), !IO),
+ io.write_string(" = ", !IO),
+ map.lookup(Bindings, Var, Value),
+ io.print(Value, !IO),
+ io.nl(!IO).
%----------------------------------------------------------------------------%
:- end_module abstract_mode_constraints.
Index: compiler/build_mode_constraints.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/build_mode_constraints.m,v
retrieving revision 1.8
diff -u -b -r1.8 build_mode_constraints.m
--- compiler/build_mode_constraints.m 2 Feb 2006 00:37:58 -0000 1.8
+++ compiler/build_mode_constraints.m 3 Feb 2006 22:36:38 -0000
@@ -52,7 +52,6 @@
% of the proposition they represent.
).
-
% A map between the constraint variables (mc_var) and what they
% represent ie the proposition that some program variable is
% produced at some goal path (for a particular predicate).
@@ -130,8 +129,8 @@
% module.)
%
:- pred add_clauses_constraints(module_info::in, pred_id::in, pred_info::in,
- mc_var_info::in, mc_var_info::out, mode_constraints::in,
- mode_constraints::out) is det.
+ mc_var_info::in, mc_var_info::out,
+ mode_constraints::in, mode_constraints::out) is det.
% mode_decls_constraints(ModuleInfo, VarMap, PredId, Decls,
% HeadVarsList, Constraints)
@@ -271,7 +270,6 @@
list.foldl(add_mc_var_for_pred_head(ProgVarset, PredId), Headvars,
!VarInfo).
-
% add_mc_var_for_pred_head(ProgVarset, PredId, ProgVar, !VarInfo)
%
% For ProgVar, a head variable of predicate PredId, this predicate
@@ -340,8 +338,8 @@
clauses_info_varset(ClausesInfo, ProgVarset),
(
- % If the clause list is empty, then there are no
- % goals to produce constraints for.
+ % If the clause list is empty, then there are no goals
+ % to produce constraints for.
Clauses = []
;
Clauses = [FirstClause|_],
@@ -351,7 +349,7 @@
Context = clause_context(FirstClause),
% All clauses are considered for all procedures.
- % though some may not be applicable, overall the
+ % Though some may not be applicable, overall the
% waste should not be large.
Goals = list.map((func(clause(_, Body, _, _)) = Body), Clauses),
@@ -420,7 +418,6 @@
Context, GoalPath), nonlocals_positions(ConjConstraintsInfo),
!VarInfo, !Constraints).
-
add_goal_expr_constraints(ModuleInfo, ProgVarset, CallerPredId, GoalExpr,
Context, GoalPath, _Nonlocals, !VarInfo, !Constraints) :-
GoalExpr = call(CalleePredId, _, Args, _, _, _),
@@ -506,7 +503,6 @@
% In this case, LHSvar need not be produced
% - it could be a test, so no constraints.
)
-
;
RHS = lambda_goal(_, _, _, _, _, _, _, _, _),
sorry(this_file, "unify with lambda goal")
@@ -544,9 +540,9 @@
add_goal_constraints(ModuleInfo, ProgVarset, PredId, Goal, !VarInfo,
!Constraints),
- % The variables non-local to the negation are not to be
- % produced at the negation or any deeper, so we constrain
- % their mode constraint variables for these positions to `no'.
+ % The variables non-local to the negation are not to be produced
+ % at the negation or any deeper, so we constrain their mode constraint
+ % variables for these positions to `no'.
list.foldl(equiv_no(Context), NonlocalsConstraintVars, !Constraints).
add_goal_expr_constraints(ModuleInfo, ProgVarset, PredId,
@@ -573,10 +569,10 @@
!Constraints).
add_goal_expr_constraints(ModuleInfo, ProgVarset, PredId,
- if_then_else(ExistVars, If, Then, Else),
+ if_then_else(ExistVars, Cond, Then, Else),
Context, GoalPath, Nonlocals, !VarInfo, !Constraints) :-
- If = _ - IfInfo, Then = _ - ThenInfo, Else = _ - ElseInfo,
- goal_info_get_goal_path(IfInfo, CondPath),
+ Cond = _ - CondInfo, Then = _ - ThenInfo, Else = _ - ElseInfo,
+ goal_info_get_goal_path(CondInfo, CondPath),
goal_info_get_goal_path(ThenInfo, ThenPath),
goal_info_get_goal_path(ElseInfo, ElsePath),
@@ -594,16 +590,16 @@
% The existentially quantified variables shared between the condition
% and the then-part have special constraints.
%
- goal_info_get_nonlocals(IfInfo, IfNonlocals),
+ goal_info_get_nonlocals(CondInfo, CondNonlocals),
goal_info_get_nonlocals(ThenInfo, ThenNonlocals),
- list.filter(set.contains(IfNonlocals), ExistVars, NonlocalToIf),
- list.filter(set.contains(ThenNonlocals), NonlocalToIf, LocalAndShared),
+ list.filter(set.contains(CondNonlocals), ExistVars, NonlocalToCond),
+ list.filter(set.contains(ThenNonlocals), NonlocalToCond, LocalAndShared),
prog_vars_at_path(ProgVarset, PredId, LocalAndShared, CondPath,
LocalAndSharedAtCond, !VarInfo),
prog_vars_at_path(ProgVarset, PredId, LocalAndShared, ThenPath,
LocalAndSharedAtThen, !VarInfo),
- add_goal_constraints(ModuleInfo, ProgVarset, PredId, If, !VarInfo,
+ add_goal_constraints(ModuleInfo, ProgVarset, PredId, Cond, !VarInfo,
!Constraints),
add_goal_constraints(ModuleInfo, ProgVarset, PredId, Then, !VarInfo,
!Constraints),
@@ -728,11 +724,10 @@
mode_decl_constraints(ModuleInfo, CallArgsHere),
Decls)),
( ConstraintFormulae = [conj(OneModeOnlyConstraints)] ->
- list.foldl(abstract_mode_constraints.add_constraint(CallContext),
- OneModeOnlyConstraints, !Constraints)
+ list.foldl(add_constraint(CallContext), OneModeOnlyConstraints,
+ !Constraints)
;
- abstract_mode_constraints.add_constraint(CallContext,
- disj(ConstraintFormulae), !Constraints)
+ add_constraint(CallContext, disj(ConstraintFormulae), !Constraints)
).
% add_call_headvar_constraints(ProgVarset, Context, GoalPath, Caller,
@@ -988,8 +983,8 @@
% of execution). ProgVarset should contain a string name for ProgVar.
%
:- pred ensure_prog_var_at_path(prog_varset::in, pred_id::in, goal_path::in,
- prog_var::in, mc_varset::in, mc_varset::out, mc_var_map::in,
- mc_var_map::out) is det.
+ prog_var::in, mc_varset::in, mc_varset::out,
+ mc_var_map::in, mc_var_map::out) is det.
ensure_prog_var_at_path(ProgVarset, PredId, GoalPath, ProgVar,
!Varset, !VarMap) :-
@@ -1010,7 +1005,7 @@
% error if the key (ProgVar `in` PredId) `at` GoalPath does not
% exist in the map.
%
-:- func prog_var_at_path(mc_var_map, pred_id, goal_path, prog_var) = (mc_var).
+:- func prog_var_at_path(mc_var_map, pred_id, goal_path, prog_var) = mc_var.
prog_var_at_path(VarMap, PredId, GoalPath, ProgVar) =
bimap.lookup(VarMap, ((ProgVar `in` PredId) `at` GoalPath)).
@@ -1022,7 +1017,7 @@
list(mc_var)) = list(mc_var).
cons_prog_var_at_path(VarMap, PredId, GoalPath, ProgVar, MCVars) =
- [ prog_var_at_path(VarMap, PredId, GoalPath, ProgVar) | MCVars].
+ [prog_var_at_path(VarMap, PredId, GoalPath, ProgVar) | MCVars].
% prog_var_at_paths(VarMap, GoalPaths, ProgVar) = ConstraintVars
% consults the map to form a list of the constraint variable
Index: compiler/mcsolver.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mcsolver.m,v
retrieving revision 1.2
diff -u -b -r1.2 mcsolver.m
--- compiler/mcsolver.m 2 Feb 2006 12:57:31 -0000 1.2
+++ compiler/mcsolver.m 3 Feb 2006 22:49:56 -0000
@@ -28,11 +28,9 @@
:- import_module list.
:- import_module std_util.
-
-
+ % Convenient abbreviations.
:- type var == abstract_mode_constraints.mc_var.
:- type vars == list(var).
- % Convenient abbreviations
% Structure in which to collect constraints.
%
@@ -42,8 +40,6 @@
%
:- type solver_cstrts.
-
-
% We start by collecting our constraints together in a prep_cstrts
% structure, before preparing them for the solver.
%
@@ -52,8 +48,8 @@
% Prepares the constraints described in abstract_mode_constraints.m
% appropriately.
%
-:- pred prepare_abstract_constraints(constraint_formulae::in, prep_cstrts::in,
- prep_cstrts::out) is det.
+:- pred prepare_abstract_constraints(constraint_formulae::in,
+ prep_cstrts::in, prep_cstrts::out) is det.
% NOTE: where possible, prepare_abstract_constraints/3 should be used
% rather than this predicate.
@@ -115,7 +111,6 @@
%
:- pred solve(solver_cstrts::in, mc_bindings::out) is nondet.
-
% For debugging purposes only.
% :- pred main(io :: di, io :: uo) is det.
@@ -138,7 +133,6 @@
%-----------------------------------------------------------------------------%
-
% Assignment constraints.
%
:- type assgt ---> (var == bool).
@@ -267,8 +261,8 @@
% Prepares an atomic constraint (as described in
% abstract_mode_constraints.m) appropriately.
%
-:- pred prepare_var_constraint(var_constraint::in, prep_cstrts::in,
- prep_cstrts::out) is det.
+:- pred prepare_var_constraint(var_constraint::in,
+ prep_cstrts::in, prep_cstrts::out) is det.
prepare_var_constraint(equiv_bool(Var, Value), !PCs) :-
assign(Var, Value, !PCs).
@@ -332,11 +326,14 @@
%-----------------------------------------------------------------------------%
equivalent_to_disjunction(X, Ys, PCs0, PCs) :-
- ( if Ys = [] then
+ (
+ Ys = [],
assign(X, no, PCs0, PCs)
- else if Ys = [Y] then
+ ;
+ Ys = [Y],
equivalent(X, Y, PCs0, PCs)
- else
+ ;
+ Ys = [_, _ | _],
PCs = PCs0 ^ prep_complex_cstrts :=
[eqv_disj(X, Ys) | PCs0 ^ prep_complex_cstrts]
).
@@ -344,28 +341,36 @@
%-----------------------------------------------------------------------------%
at_most_one(Xs, PCs0, PCs) :-
- ( if Xs = [X, Y] then
+ (
+ Xs = [],
+ PCs = PCs0
+ ;
+ Xs = [_],
+ PCs = PCs0
+ ;
+ Xs = [X, Y],
not_both(X, Y, PCs0, PCs)
- else if Xs = [_, _, _ | _] then
+ ;
+ Xs = [_, _, _ | _],
PCs = PCs0 ^ prep_complex_cstrts :=
[at_most_one(Xs) | PCs0 ^ prep_complex_cstrts]
- else
- PCs = PCs0
).
%-----------------------------------------------------------------------------%
exactly_one(Xs, PCs0, PCs) :-
- ( if Xs = [X] then
+ (
+ Xs = [],
+ PCs = PCs0
+ ;
+ Xs = [X],
assign(X, yes, PCs0, PCs)
- else if Xs = [_, _ | _] then
+ ;
+ Xs = [_, _ | _],
PCs = PCs0 ^ prep_complex_cstrts :=
[exactly_one(Xs) | PCs0 ^ prep_complex_cstrts]
- else
- PCs = PCs0
).
-
%-----------------------------------------------------------------------------%
disjunction_of_assignments(DisjOfAssgts, PCs0, PCs) :-
@@ -454,7 +459,6 @@
%
SCs = solver_cstrts(AllVars, Eqvs, Assgts, PropGraph, ComplexCstrtsMap).
-
% eqv_var(Eqvs, Var) returns a representative member of all the
% variables equivalent to Var (in Eqvs)
%
@@ -478,10 +482,9 @@
complex_cstrt_vars(disj_of_assgts(Assgtss)) =
list.foldl(list.foldl(func((V == _), Vs) = [V | Vs]), Assgtss, []).
-
% Replaces all the variables in the supplied constraint with
- % a representative variable from those constrained to be
- % equivalent to the original.
+ % a representative variable from those constrained to be equivalent
+ % to the original.
%
:- func eqv_complex_cstrt(eqv_vars, complex_cstrt) = complex_cstrt.
@@ -509,7 +512,6 @@
bind_equivalent_vars(SCs, Bindings0, Bindings).
% unsafe.io(nl).
-
% solve(SCs, Bs0, Bs) succeeds if Bs satisfies the constraints SCs,
% given that Bs0 is known to not conflict with any of the constraints
% in SCs.
@@ -520,11 +522,11 @@
solve_assgts(SCs, SCs ^ assgts, Bs0, Bs1),
solve_vars(SCs, SCs ^ vars, Bs1, Bs).
- % Propagates the binding for every variable that has been
- % solved for to every variable it is equivalent to.
+ % Propagates the binding for every variable that has been solved for
+ % to every variable it is equivalent to.
%
-:- pred bind_equivalent_vars(solver_cstrts::in, mc_bindings::in,
- mc_bindings::out) is det.
+:- pred bind_equivalent_vars(solver_cstrts::in,
+ mc_bindings::in, mc_bindings::out) is det.
bind_equivalent_vars(SCs, !Bindings) :-
Equivalences = SCs ^ eqv_vars,
@@ -560,12 +562,11 @@
solve_assgts(SCs, Assgts, Bs0, Bs) :-
list.foldl(solve_assgt(SCs), Assgts, Bs0, Bs).
-
% solve_assgt(SCs, (X == V), Bs0, Bs) attempts to bind variable X
% to value V. It propagates the results if it succeeds.
%
-:- pred solve_assgt(solver_cstrts::in, assgt::in, mc_bindings::in,
- mc_bindings::out) is semidet.
+:- pred solve_assgt(solver_cstrts::in, assgt::in,
+ mc_bindings::in, mc_bindings::out) is semidet.
solve_assgt(SCs, (X == V), Bs0, Bs) :-
( if Bs0 ^ elem(X) = V0 then
@@ -591,10 +592,9 @@
%-----------------------------------------------------------------------------%
% solve_complex_cstrts(SCs, X, V, ComplexCstrts, Bs0, Bs) succeeds
- % if the binding (X == V) (which should already have been added to
- % Bs0) is consistant with the complex constraints variable X
- % participates in in SCs. It also propagates results where
- % appropriate.
+ % if the binding (X == V) (which should already have been added to Bs0)
+ % is consistant with the complex constraints variable X participates
+ % in SCs. It also propagates results where appropriate.
%
:- pred solve_complex_cstrts(solver_cstrts::in, var::in, bool::in,
complex_cstrts::in, mc_bindings::in, mc_bindings::out) is semidet.
@@ -603,10 +603,9 @@
list.foldl(solve_complex_cstrt(SCs, X, V), ComplexCstrts, Bs0, Bs).
% solve_complex_cstrt(SCs, X, V, ComplexCstrt, Bs0, Bs) succeeds
- % if the binding (X == V) (which should already have been added to
- % Bs0) is consistant with ComplexCstrt (in which X should
- % participate in in SCs). It also propagates results where
- % appropriate.
+ % if the binding (X == V) (which should already have been added to Bs0)
+ % is consistant with ComplexCstrt (in which X should participate in SCs).
+ % It also propagates results where appropriate.
%
:- pred solve_complex_cstrt(solver_cstrts::in, var::in, bool::in,
complex_cstrt::in, mc_bindings::in, mc_bindings::out) is semidet.
@@ -651,9 +650,8 @@
solve_complex_cstrt(SCs, X, V, exactly_one(Ys0), Bs0, Bs) :-
(
V = no,
-
- % A variable in Ys0 uniquely not bound to 'no' is bound to
- % yes. Fails if all Ys0 are 'no'.
+ % A variable in Ys0 uniquely not bound to 'no' is bound to yes.
+ % Fails if all Ys0 are 'no'.
Ys = list.filter(
(pred(Y0::in) is semidet :- not map.search(Bs0, Y0, no)), Ys0),
(
@@ -670,7 +668,7 @@
).
solve_complex_cstrt(SCs, X, V, disj_of_assgts(Assgtss), Bs0, Bs) :-
- % Filter for the assignments compatable with binding X to V
+ % Filter for the assignments compatible with binding X to V.
list.filter(
(pred(Assgts::in) is semidet :-
list.member((X == bool.not(V)), Assgts)
@@ -689,7 +687,6 @@
Bs = Bs0
).
-
%-----------------------------------------------------------------------------%
% PropGraph ^ var_consequents(X, V) returns the assignments
@@ -719,15 +716,14 @@
% to each of Vars and propagates results, looking for a solution
% to SCs.
%
-:- pred solve_vars(solver_cstrts::in, vars::in, mc_bindings::in,
- mc_bindings::out) is nondet.
+:- pred solve_vars(solver_cstrts::in, vars::in,
+ mc_bindings::in, mc_bindings::out) is nondet.
solve_vars(SCs, Vars, Bs0, Bs) :-
list.foldl(solve_var(SCs), Vars, Bs0, Bs).
-
-:- pred solve_var(solver_cstrts::in, var::in, mc_bindings::in,
- mc_bindings::out) is nondet.
+:- pred solve_var(solver_cstrts::in, var::in,
+ mc_bindings::in, mc_bindings::out) is nondet.
solve_var(SCs, X, Bs0, Bs) :-
( if contains(Bs0, X) then
@@ -749,7 +745,6 @@
Bs ^ elem(X) = yes,
all_yes(Bs, Xs).
-
% all_no(Bs, Xs) succeeds if Bs indicates all Xs are bound to no
%
:- pred all_no(mc_bindings::in, vars::in) is semidet.
Index: compiler/ordering_mode_constraints.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ordering_mode_constraints.m,v
retrieving revision 1.1
diff -u -b -r1.1 ordering_mode_constraints.m
--- compiler/ordering_mode_constraints.m 2 Feb 2006 00:37:59 -0000 1.1
+++ compiler/ordering_mode_constraints.m 3 Feb 2006 22:54:40 -0000
@@ -44,7 +44,6 @@
second :: conjunct_id % Typically the consumer
).
-
% Store for the ordering constraints for one conjunction.
%
:- type ordering_constraints_info --->
@@ -167,17 +166,17 @@
pred_info_infer_modes(PredInfo)
), SCC, PredsToInfer, PredsToCheck),
- ( PredsToInfer \= [] ->
+ (
+ PredsToInfer = [_ | _],
% XXX GIVE UP FOR NOW!!!!
sorry(this_file, "mode inference")
;
- true
+ PredsToInfer = []
),
list.foldl(pred_reordering(PredConstraintsMap, VarMap), PredsToCheck,
!ModuleInfo).
-
% pred_reordering(PredConstraintsMap, VarMap, PredID, !ModuleInfo)
% applies mode reordering to conjunctions in the body goal of the
% predicate PredID for each procedure in that predicate.
@@ -305,9 +304,9 @@
goal_reordering(PredID, VarMap, Bindings, Goal0, Goal).
goal_expr_reordering(PredID, VarMap, Bindings,
- if_then_else(Vars, If0, Then0, Else0),
- if_then_else(Vars, If, Then, Else)) :-
- goal_reordering(PredID, VarMap, Bindings, If0, If),
+ if_then_else(Vars, Cond0, Then0, Else0),
+ if_then_else(Vars, Cond, Then, Else)) :-
+ goal_reordering(PredID, VarMap, Bindings, Cond0, Cond),
goal_reordering(PredID, VarMap, Bindings, Then0, Then),
goal_reordering(PredID, VarMap, Bindings, Else0, Else).
@@ -415,8 +414,7 @@
% See make_conjuncts_nonlocal_repvars; acts on a single conjunct.
%
:- pred make_conjunct_nonlocal_repvars(pred_id::in, hlds_goal::in,
- prog_var_at_conjuncts_map::in,
- prog_var_at_conjuncts_map::out) is det.
+ prog_var_at_conjuncts_map::in, prog_var_at_conjuncts_map::out) is det.
make_conjunct_nonlocal_repvars(PredID, Goal, !RepvarMap) :-
GoalInfo = snd(Goal),
@@ -467,20 +465,17 @@
ordering_constraints_info::in, ordering_constraints_info::out) is semidet.
prog_var_ordering_constraints(VarMap, Bindings, _ProgVar, RepVars, !OCInfo) :-
-
list.filter(produced_at_path(VarMap, Bindings), RepVars,
ProgVarAtProducers, ProgVarAtConsumers),
-
(
- ProgVarAtProducers = [] % Variable not produced here
- % - no constraints.
+ ProgVarAtProducers = []
+ % Variable not produced here - no constraints.
;
ProgVarAtProducers = [RepVar], % Should be only one producer
First = get_position_in_conj(RepVar),
list.map(get_position_in_conj, ProgVarAtConsumers, Laters),
list.foldl(add_lt_constraint(First), Laters, !OCInfo)
-
).
% produced_at_path(VarMap, Bindings, ProgVar `at` GoalPath `in` _)
@@ -493,7 +488,6 @@
produced_at_path(VarMap, Bindings, RepVar) :-
map.lookup(Bindings, bimap.lookup(VarMap, RepVar)) = yes.
-
% get_position_in_conj(RepVar) fails if the deepest level of the
% goalpath in RepVar is not a conjunction, otherwise it returns
% the number of the conjunct the RepVar refers to.
@@ -558,8 +552,8 @@
% at all.
%
:- pred add_complete_order_constraints(list(conjunct_id)::in,
- set(mode_ordering_constraint)::in,
- set(mode_ordering_constraint)::out) is det.
+ set(mode_ordering_constraint)::in, set(mode_ordering_constraint)::out)
+ is det.
add_complete_order_constraints([], !MOCs).
add_complete_order_constraints([Conjunct | Conjuncts], !MOCs) :-
@@ -574,7 +568,7 @@
:- pred constrain_if_possible(mode_ordering_constraints::in,
ordering_constraints_info::in, ordering_constraints_info::out) is det.
-constrain_if_possible([] , !OCI).
+constrain_if_possible([], !OCI).
constrain_if_possible([Constraint | Constraints], !OCI) :-
( add_ordering_constraint(Constraint, !OCI) ->
constrain_if_possible(Constraints, !OCI)
@@ -597,7 +591,6 @@
CantidatesForFirst = set.difference(Conjuncts0, NotFirst),
( set.remove_least(CantidatesForFirst, First, _) ->
-
% Remove First from the system.
set.remove(Conjuncts0, First, Conjuncts),
Constraints = set.filter(
@@ -608,8 +601,8 @@
topological_sort_min_reordering(Constraints, Conjuncts, Ordering0),
Ordering = [First | Ordering0]
;
- % No cantidates for First, so we are only done if there
- % were no nodes (conjuncts) left to begin with.
+ % No cantidates for First, so we are only done if there were
+ % no nodes (conjuncts) left to begin with.
set.empty(Conjuncts0),
Ordering = []
).
@@ -617,7 +610,7 @@
%-----------------------------------------------------------------------------%
dump_goal_paths(ModuleInfo, PredIds0, !IO) :-
- % Process only predicates from this module
+ % Process only predicates from this module.
list.filter(module_info_pred_status_is_imported(ModuleInfo),
PredIds0, _, PredIds),
list.foldl(dump_pred_goal_paths(ModuleInfo), PredIds, !IO).
@@ -635,7 +628,7 @@
pred_info_procedures(PredInfo, ProcTable),
ProcIds = map.keys(ProcTable),
- % Start with a blank line
+ % Start with a blank line.
write_error_pieces_plain([fixed("")], !IO),
PredHeaderFormat = [words("Goal paths for")] ++
@@ -666,8 +659,7 @@
dump_proc_goal_paths(ProcTable, ProcId, !IO) :-
ProcIdString = string.from_int(proc_id_to_int(ProcId)),
- ProcHeaderFormat = [words("mode"), words(ProcIdString),
- suffix(":")],
+ ProcHeaderFormat = [words("mode"), words(ProcIdString), suffix(":")],
write_error_pieces_plain(ProcHeaderFormat, !IO),
map.lookup(ProcTable, ProcId, ProcInfo),
proc_info_goal(ProcInfo, Goal),
@@ -681,8 +673,7 @@
% in the order they appear, for the purposes of visually checking
% re-ordering.
%
-:- pred dump_goal_goal_paths(int::in, hlds_goal::in, io::di, io::uo)
- is det.
+:- pred dump_goal_goal_paths(int::in, hlds_goal::in, io::di, io::uo) is det.
dump_goal_goal_paths(Indent, GoalExpr - GoalInfo, !IO) :-
goal_info_get_goal_path(GoalInfo, GoalPath),
@@ -715,9 +706,6 @@
).
dump_goal_expr_goal_paths(_Indent, GoalExpr, !IO) :-
- %
- % Call unexpected/2 for unexpected goals.
- %
(
GoalExpr = switch(_, _, _),
unexpected(this_file, "switch")
@@ -743,8 +731,8 @@
dump_goal_goal_paths(Indent, Goal, !IO).
dump_goal_expr_goal_paths(Indent, GoalExpr, !IO) :-
- GoalExpr = if_then_else(_, IfGoal, ThenGoal, ElseGoal),
- Goals = [IfGoal, ThenGoal, ElseGoal],
+ GoalExpr = if_then_else(_, CondGoal, ThenGoal, ElseGoal),
+ Goals = [CondGoal, ThenGoal, ElseGoal],
list.foldl(dump_goal_goal_paths(Indent), Goals, !IO).
dump_goal_expr_goal_paths(Indent, GoalExpr, !IO) :-
Index: compiler/prop_mode_constraints.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/prop_mode_constraints.m,v
retrieving revision 1.6
diff -u -b -r1.6 prop_mode_constraints.m
--- compiler/prop_mode_constraints.m 2 Feb 2006 00:37:59 -0000 1.6
+++ compiler/prop_mode_constraints.m 3 Feb 2006 22:40:57 -0000
@@ -279,8 +279,8 @@
map.lookup(PredConstraintsMap, PredId, PredConstraints),
FormulaeAndAnnotations = pred_constraints_to_formulae_and_annotations(
PredConstraints),
- abstract_mode_constraints.dump_constraints_and_annotations(
- ConstraintVarset, FormulaeAndAnnotations, !IO),
+ dump_constraints_and_annotations(ConstraintVarset, FormulaeAndAnnotations,
+ !IO),
list.foldl(pretty_print_proc_constraints(ModuleInfo, ConstraintVarset,
PredConstraints, PredId), pred_info_all_procids(PredInfo), !IO).
@@ -300,8 +300,8 @@
should_module_qualify, proc(PredId, ProcId)) ++ [suffix(":")], !IO),
FormulaeAndAnnotations =
proc_constraints_to_formulae_and_annotations(ProcId, PredConstraints),
- abstract_mode_constraints.dump_constraints_and_annotations(
- ConstraintVarset, FormulaeAndAnnotations, !IO).
+ dump_constraints_and_annotations(ConstraintVarset, FormulaeAndAnnotations,
+ !IO).
%----------------------------------------------------------------------------%
:- end_module prop_mode_constraints.
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing debian/patches
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/aditi
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/concurrency
cvs diff: Diffing extras/curs
cvs diff: Diffing extras/curs/samples
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/error
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/easyx
cvs diff: Diffing extras/graphics/easyx/samples
cvs diff: Diffing extras/graphics/mercury_glut
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/gears
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/lex/tests
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/moose/tests
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/quickcheck
cvs diff: Diffing extras/quickcheck/tutes
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/solver_types
cvs diff: Diffing extras/solver_types/library
cvs diff: Diffing extras/stream
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/windows_installer_generator
cvs diff: Diffing extras/windows_installer_generator/sample
cvs diff: Diffing extras/windows_installer_generator/sample/images
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing extras/xml_stylesheets
cvs diff: Diffing java
cvs diff: Diffing java/runtime
cvs diff: Diffing library
cvs diff: Diffing mdbcomp
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing slice
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/general/string_format
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/grade_subdirs
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/mmc_make
cvs diff: Diffing tests/mmc_make/lib
cvs diff: Diffing tests/recompilation
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/trailing
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
cvs diff: Diffing util
cvs diff: Diffing vim
cvs diff: Diffing vim/after
cvs diff: Diffing vim/ftplugin
cvs diff: Diffing vim/syntax
--------------------------------------------------------------------------
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