[m-rev.] trivial diff: clean up compiler/constraint.m

Julien Fischer juliensf at cs.mu.OZ.AU
Tue May 24 13:41:46 AEST 2005


Estimated hour taken: 0.2
Branches: main

compiler/constraint.m:
	Switch to four-space indentation throughout.

	Update the comments concerning constraints so that
	they reflect the current code; we also require
	goals acting as constraints not to throw exceptions.

	Use unexpected/2 in place of error/1.

	Remove some duplicate imports.

	Fix a couple of typos in the comments.

Julien.

Index: compiler/constraint.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/constraint.m,v
retrieving revision 1.60
diff -u -b -r1.60 constraint.m
--- compiler/constraint.m	24 Mar 2005 05:33:59 -0000	1.60
+++ compiler/constraint.m	24 May 2005 03:28:55 -0000
@@ -1,15 +1,19 @@
 %-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et
+%-----------------------------------------------------------------------------%
 % Copyright (C) 2001-2005 The University of Melbourne.
 % This file may only be copied under the terms of the GNU General
 % Public License - see the file COPYING in the Mercury distribution.
 %-----------------------------------------------------------------------------%
+%
 % File: constraint.m
 % Main author: stayl.
 %
-% The constraint propagation transformation attempts to improve
-% the efficiency of a generate-and-test style program by statically
-% scheduling constraints as early as possible, where a "constraint"
-% is any pure goal which has no outputs, can fail and cannot loop.
+% The constraint propagation transformation attempts to improve the
+% efficiency of a generate-and-test style program by statically
+% scheduling constraints as early as possible, where a "constraint" is
+% any pure goal which has no outputs, can fail, cannot loop and cannot
+% throw an exception.
 %
 %-----------------------------------------------------------------------------%

@@ -25,15 +29,19 @@

 :- import_module bool.

+%-----------------------------------------------------------------------------%
+
 :- type constraint_info.

-	% propagate_constraints_in_goal pushes constraints
-	% left and inward within a single goal. Specialized versions of
-	% procedures which are called with constrained outputs are created
-	% by deforest.m. Goals which deforest.m should try to propagate
-	% into calls are annotated with a `constraint' goal feature.
-:- pred propagate_constraints_in_goal(hlds_goal::in,
-	hlds_goal::out, constraint_info::in, constraint_info::out) is det.
+    % propagate_constraints_in_goal pushes constraints left and
+    % inward within a single goal. Specialized versions of
+    % procedures which are called with constrained outputs are
+    % created by deforest.m. Goals which deforest.m should try to
+    % propagate into calls are annotated with a `constraint' goal
+    % feature.
+    %
+:- pred propagate_constraints_in_goal(hlds_goal::in, hlds_goal::out,
+    constraint_info::in, constraint_info::out) is det.

 :- pred constraint_info_init(module_info::in, vartypes::in, prog_varset::in,
 	instmap::in, constraint_info::out) is det.
@@ -52,11 +60,10 @@
 :- import_module hlds__goal_form.
 :- import_module hlds__goal_util.
 :- import_module hlds__hlds_data.
-:- import_module hlds__hlds_module.
-:- import_module hlds__hlds_pred.
 :- import_module hlds__passes_aux.
 :- import_module libs__globals.
 :- import_module libs__options.
+:- import_module parse_tree__error_util.

 :- import_module assoc_list.
 :- import_module list.
@@ -72,11 +79,11 @@

 propagate_constraints_in_goal(Goal0, Goal, !Info) :-
 	% We need to strip off any existing constraint markers first.
-	% Constraint markers are meant to indicate where a constraint
-	% is meant to be attached to a call, and that deforest.m should
-	% consider creating a specialized version for the call.
-	% If deforest.m rearranges the goal, the constraints may
-	% not remain next to the call.
+    % Constraint markers are meant to indicate where a constraint is
+    % meant to be attached to a call, and that deforest.m should
+    % consider creating a specialized version for the call.  If
+    % deforest.m rearranges the goal, the constraints may not remain
+    % next to the call.
 	Goal1 = strip_constraint_markers(Goal0),
 	propagate_goal(Goal1, [], Goal, !Info).

@@ -195,7 +202,7 @@

 propagate_conj_sub_goal_2(Goal, _, _, !Info) :-
 	Goal = shorthand(_) - _,
-	error("propagate_conj_sub_goal_2: shorthand").
+    unexpected(this_file, "propagate_conj_sub_goal_2: shorthand").

 propagate_conj_sub_goal_2(Goal, Constraints0,
 		[Goal | Constraints], !Info) :-
@@ -205,8 +212,8 @@
 %-----------------------------------------------------------------------------%

 	% Put the constant constructions in front of the constraint.
-:- pred flatten_constraints(list(constraint)::in,
-		list(hlds_goal)::out) is det.
+    %
+:- pred flatten_constraints(list(constraint)::in, list(hlds_goal)::out) is det.

 flatten_constraints(Constraints0, Goals) :-
 	list__map((pred(Constraint::in, Lists::out) is det :-
@@ -246,11 +253,12 @@

 %-----------------------------------------------------------------------------%

-	% propagate_conj detects the constraints in
-	% a conjunction and moves them to as early as possible
-	% in the list. Some effort is made to keep the constraints
-	% in the same order as they are encountered to increase
-	% the likelihood of folding recursive calls.
+    % propagate_conj detects the constraints in a conjunction and
+    % moves them to as early as possible in the list. Some effort is
+    % made to keep the constraints in the same order as they are
+    % encountered to increase the likelihood of folding recursive
+    % calls.
+    %
 :- pred propagate_conj(list(hlds_goal)::in, list(constraint)::in,
 	list(hlds_goal)::out, constraint_info::in, constraint_info::out)
 	is det.
@@ -273,6 +281,7 @@
 	).

 	% Annotate each conjunct with the variables it produces.
+    %
 :- pred annotate_conj_output_vars(list(hlds_goal)::in, module_info::in,
 	vartypes::in, instmap::in, annotated_conj::in, annotated_conj::out)
 	is det.
@@ -288,13 +297,14 @@
 		ModuleInfo, ChangedVars0),

 	instmap__vars_list(InstMap, InstMapVars),
-
-	% Restrict the set of changed variables down to the set
-	% for which the new inst is not an acceptable subsitute
-	% for the old. This is done to allow reordering of a goal which
-	% uses a variable with inst `ground(shared, no)' with
-	% a constraint which just adds information, changing the inst
-	% to `bound(shared, ...)'.
+    %
+    % Restrict the set of changed variables down to the set for
+    % which the new inst is not an acceptable substitute for the
+    % old.  This is done to allow reordering of a goal which uses a
+    % variable with inst `ground(shared, no)' with a constraint
+    % which just adds information, changing the inst to
+    % `bound(shared, ...)'.
+    %
 	InCompatible = (pred(Var::in) is semidet :-
 			instmap__lookup_var(InstMap0, Var, InstBefore),
 			instmap_delta_search_var(InstMapDelta, Var, InstAfter),
@@ -303,7 +313,6 @@
 		),
 	IncompatibleInstVars = set__list_to_set(
 		list__filter(InCompatible, InstMapVars)),
-
 	%
 	% This will consider variables with inst `any' to be bound by
 	% the goal, so goals which have non-locals with inst `any' will
@@ -333,6 +342,7 @@

 	% Conjunction annotated with the variables each conjunct
 	% changes the instantiatedness of.
+    %
 :- type annotated_conj == list(annotated_conjunct).

 :- type annotated_conjunct
@@ -353,8 +363,10 @@
 		set(prog_var)
 	).

-	% A constraint is a goal with no outputs which can fail and
-	% always terminates.
+
+    % A constraint is a goal that may fail, has no outputs,
+    % always terminates and will not throw an exception.
+    %
 :- type constraint
 	---> constraint(
 			% The constraint itself.
@@ -376,10 +388,12 @@
 	).

 	% Conjunction annotated with constraining goals.
+    %
 :- type constrained_conj == assoc_list(hlds_goal, list(constraint)).

 	% Pass backwards over the conjunction, annotating each conjunct
 	% with the constraints that should be pushed into it.
+    %
 :- pred annotate_conj_constraints(module_info::in, annotated_conj::in,
 	list(constraint)::in, constrained_conj::in, constrained_conj::out,
 	constraint_info::in, constraint_info::out) is det.
@@ -398,17 +412,16 @@
 	Goal = GoalExpr - GoalInfo,
 	goal_info_get_nonlocals(GoalInfo, NonLocals),
 	(
-		% Propagate goals with no output variables which can fail.
-		% Propagating cc_nondet goals would be tricky, because we
-		% would need to be careful about reordering the constraints
-		% (the cc_nondet goal can't be moved before any goals
-		% which can fail).
+        % Propagate goals that can fail and have no output
+        % variables.  Propagating cc_nondet goals would be
+        % tricky, because we would need to be careful about
+        % reordering the constraints (the cc_nondet goal can't
+        % be moved before any goals which can fail).
 		%
 		goal_info_get_determinism(GoalInfo, Detism),
 		( Detism = semidet
 		; Detism = failure
 		),
-
 		%
 		% XXX This is probably a bit too conservative. For
 		% example, `any->any' moded non-locals are considered
@@ -419,7 +432,7 @@
 		% Don't propagate impure goals.
 		goal_info_is_pure(GoalInfo),

-		% Don't propagate goals that can loop.
+        % Don't propagate goals that can loop or throw exceptions..
 		goal_cannot_loop_or_throw(ModuleInfo, Goal)
 	->
 		% It's a constraint, add it to the list of constraints
@@ -433,12 +446,12 @@
 		% Look for a simple goal which some constraint depends
 		% on which can be propagated backwards. This handles
 		% cases like X = 2, Y < X. This should only be done for
-		% goals which result in no execution at runtime, such
-		% as construction of static constants. Currently we only
+        % goals which result in no execution at runtime, such as
+        % construction of static constants. Currently we only
 		% allow constructions of zero arity constants.
 		%
-		% Make a renamed copy of the goal, renaming within
-		% the constraint as well, so that a copy of the constant
+        % Make a renamed copy of the goal, renaming within the
+        % constraint as well, so that a copy of the constant
 		% doesn't need to be kept on the stack.
 		%
 		Goal = unify(_, _, _, Unify, _) - _,
@@ -453,9 +466,8 @@
 		% quantification to work that out.
 		!:Info = !.Info ^ changed := yes
 	;
-		% Prune away the constraints after a goal
-		% which cannot succeed -- they can never be
-		% executed.
+        % Prune away the constraints after a goal that cannot
+        % succeed -- they can never be executed.
 		goal_info_get_determinism(GoalInfo, Detism),
 		determinism_components(Detism, _, at_most_zero)
 	->
@@ -475,7 +487,8 @@
 		list__append(GoalsAndConstraints, Goals0, Goals1)
 	;
 		% Don't move goals which can fail before a goal which
-		% can loop if `--fully-strict' is set.
+        % can loop or throw an exception if `--fully-strict' is set.
+        %
 		\+ goal_cannot_loop_or_throw(ModuleInfo, Goal),
 		module_info_globals(ModuleInfo, Globals),
 		globals__lookup_bool_option(Globals, fully_strict, yes)
@@ -527,7 +540,6 @@

 %-----------------------------------------------------------------------------%

-
 :- pred add_constant_construction(prog_var::in, hlds_goal::in,
 	list(constraint)::in, list(constraint)::out,
 	constraint_info::in, constraint_info::out) is det.
@@ -570,12 +582,13 @@
 	%	GoalOutputVars, Constraints, DependentConstraints,
 	% 	IndependentConstraints)
 	%
-	% Find all constraints which depend on the output variables
-	% of the current goal in the conjunction being processed.
-	% The DependentConstraints should be pushed into the current goal.
-	% The IndependentConstraints should be moved to the left of
-	% the current goal, if the purity and termination properties
-	% of the current goal allow that.
+    % Find all constraints which depend on the output variables of
+    % the current goal in the conjunction being processed.  The
+    % DependentConstraints should be pushed into the current goal.
+    % The IndependentConstraints should be moved to the left of the
+    % current goal, if the purity and termination properties of the
+    % current goal allow that.
+    %
 :- pred filter_dependent_constraints(set(prog_var)::in, set(prog_var)::in,
 	list(constraint)::in, list(constraint)::out, list(constraint)::out)
 	is det.
@@ -657,6 +670,7 @@
 %-----------------------------------------------------------------------------%

 	% Push the constraints into each conjunct.
+    %
 :- pred propagate_conj_constraints(constrained_conj::in,
 	list(hlds_goal)::in, list(hlds_goal)::out,
 	constraint_info::in, constraint_info::out) is det.
@@ -687,6 +701,7 @@
 	ComplexConstraints = list__reverse(RevComplexConstraints).

 	% Don't attempt to push branched goals into other goals.
+    %
 :- pred filter_complex_constraints(list(constraint)::in,
 	list(constraint)::in, list(constraint)::out,
 	list(constraint)::in, list(constraint)::out) is det.
@@ -776,6 +791,7 @@
 	% If a non-empty list of constraints is pushed into a sub-goal,
 	% quantification, instmap_deltas and determinism need to be
 	% recomputed.
+    %
 :- pred constraint_info_update_changed(list(constraint)::in,
 	constraint_info::in, constraint_info::out) is det.

@@ -790,6 +806,7 @@

 	% Remove all `constraint' goal features from the goal_infos
 	% of all sub-goals of the given goal.
+    %
 :- func strip_constraint_markers(hlds_goal) = hlds_goal.

 strip_constraint_markers(Goal - GoalInfo0) =
@@ -834,4 +851,11 @@
 	Goal = shorthand(_).

 %-----------------------------------------------------------------------------%
+
+:- func this_file = string.
+
+this_file = "constraint.m".
+
+%-----------------------------------------------------------------------------%
+:- end_module constraint.
 %-----------------------------------------------------------------------------%
--------------------------------------------------------------------------
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