[m-rev.] diff: cleanup simplify.m and common.m
Zoltan Somogyi
zs at cs.mu.OZ.AU
Mon Mar 8 13:29:36 AEDT 2004
compiler/simplify.m:
compiler/common.m:
Bring these modules into line with our current style guidelines.
Use predmode declarations where appropriate. Use state variable
syntax where appropriate, and reorder arguments as necessary to
make this possible.
compiler/size_prof.m:
Conform to the changed argument order of a predicate in simplify.m.
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/common.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/common.m,v
retrieving revision 1.70
diff -u -b -r1.70 common.m
--- compiler/common.m 13 May 2003 07:52:14 -0000 1.70
+++ compiler/common.m 6 Mar 2004 10:27:26 -0000
@@ -43,11 +43,11 @@
% we have seen before, replace the construction with an assignment
% from the variable unified with that cell.
-:- pred common__optimise_unification(unification, prog_var, unify_rhs,
- unify_mode, unify_context, hlds_goal_expr, hlds_goal_info,
- hlds_goal_expr, hlds_goal_info, simplify_info, simplify_info).
-:- mode common__optimise_unification(in, in, in, in, in, in, in,
- out, out, in, out) is det.
+:- pred common__optimise_unification(unification::in, prog_var::in,
+ unify_rhs::in, unify_mode::in, unify_context::in,
+ hlds_goal_expr::in, hlds_goal_expr::out,
+ hlds_goal_info::in, hlds_goal_info::out,
+ simplify_info::in, simplify_info::out) is det.
% Check whether this call has been seen before and is replaceable, if
% so produce assignment unification for the non-local output variables,
@@ -56,29 +56,26 @@
% and no destructive inputs.
% It is the caller's responsibility to check that the call is pure.
-:- pred common__optimise_call(pred_id, proc_id, list(prog_var), hlds_goal_expr,
- hlds_goal_info, hlds_goal_expr, simplify_info, simplify_info).
-:- mode common__optimise_call(in, in, in, in, in, out, in, out) is det.
-
-:- pred common__optimise_higher_order_call(prog_var, list(prog_var), list(mode),
- determinism, hlds_goal_expr, hlds_goal_info, hlds_goal_expr,
- simplify_info, simplify_info).
-:- mode common__optimise_higher_order_call(in, in, in, in, in, in, out,
- in, out) is det.
+:- pred common__optimise_call(pred_id::in, proc_id::in, list(prog_var)::in,
+ hlds_goal_info::in, hlds_goal_expr::in, hlds_goal_expr::out,
+ simplify_info::in, simplify_info::out) is det.
+
+:- pred common__optimise_higher_order_call(prog_var::in, list(prog_var)::in,
+ list(mode)::in, determinism::in, hlds_goal_info::in,
+ hlds_goal_expr::in, hlds_goal_expr::out,
+ simplify_info::in, simplify_info::out) is det.
% succeeds if the two variables are equivalent
% according to the specified equivalence class.
-:- pred common__vars_are_equivalent(prog_var, prog_var, common_info).
-:- mode common__vars_are_equivalent(in, in, in) is semidet.
+:- pred common__vars_are_equivalent(prog_var::in, prog_var::in,
+ common_info::in) is semidet.
% Assorted stuff used here that simplify.m doesn't need to know about.
:- type common_info.
-:- pred common_info_init(common_info).
-:- mode common_info_init(out) is det.
+:- pred common_info_init(common_info::out) is det.
-:- pred common_info_clear_structs(common_info, common_info).
-:- mode common_info_clear_structs(in, out) is det.
+:- pred common_info_clear_structs(common_info::in, common_info::out) is det.
%---------------------------------------------------------------------------%
@@ -139,11 +136,11 @@
%---------------------------------------------------------------------------%
common__optimise_unification(Unification0, _Left0, _Right0, Mode, _Context,
- Goal0, GoalInfo0, Goal, GoalInfo, Info0, Info) :-
+ Goal0, Goal, GoalInfo0, GoalInfo, !Info) :-
(
Unification0 = construct(Var, ConsId, ArgVars, _, _, _, _),
Mode = LVarMode - _,
- simplify_info_get_module_info(Info0, ModuleInfo),
+ simplify_info_get_module_info(!.Info, ModuleInfo),
mode_get_insts(ModuleInfo, LVarMode, _, Inst),
(
% Don't optimise partially instantiated
@@ -155,8 +152,7 @@
\+ inst_is_ground(ModuleInfo, Inst)
->
Goal = Goal0,
- GoalInfo = GoalInfo0,
- Info = Info0
+ GoalInfo = GoalInfo0
;
% common__generate_assign assumes that the
% output variable is in the instmap_delta, which
@@ -165,7 +161,7 @@
goal_info_get_instmap_delta(GoalInfo0, InstMapDelta),
instmap_delta_search_var(InstMapDelta, Var, _),
common__find_matching_cell(Var, ConsId, ArgVars,
- construction, Info0, OldStruct)
+ construction, !.Info, OldStruct)
->
OldStruct = structure(OldVar, _, _, _),
( ArgVars = [] ->
@@ -174,28 +170,26 @@
% construction -- in fact, doing so
% could cause more stack usage.
common__record_equivalence(Var, OldVar,
- Info0, Info),
+ !Info),
Goal = Goal0,
GoalInfo = GoalInfo0
;
UniMode = ((free - Inst) -> (Inst - Inst)),
common__generate_assign(Var, OldVar, UniMode,
- GoalInfo0, Goal - GoalInfo,
- Info0, Info1),
- simplify_info_set_requantify(Info1, Info2),
+ GoalInfo0, Goal - GoalInfo, !Info),
+ simplify_info_set_requantify(!Info),
pd_cost__goal(Goal0 - GoalInfo0, Cost),
- simplify_info_incr_cost_delta(Info2,
- Cost, Info)
+ simplify_info_incr_cost_delta(Cost, !Info)
)
;
Goal = Goal0,
GoalInfo = GoalInfo0,
- common__record_cell(Var, ConsId, ArgVars, Info0, Info)
+ common__record_cell(Var, ConsId, ArgVars, !Info)
)
;
Unification0 = deconstruct(Var, ConsId,
ArgVars, UniModes, CanFail, _),
- simplify_info_get_module_info(Info0, ModuleInfo),
+ simplify_info_get_module_info(!.Info, ModuleInfo),
(
% Don't optimise partially instantiated
% deconstruction unifications, because it's
@@ -207,47 +201,45 @@
mode_get_insts(ModuleInfo, LVarMode, Inst0, _),
\+ inst_is_ground(ModuleInfo, Inst0)
->
- Goal = Goal0,
- Info = Info0
+ Goal = Goal0
;
% Do not delete deconstruction unifications inserted by
% stack_opt.m, which has done a more comprehensive cost
% analysis than common.m can do.
\+ goal_info_has_feature(GoalInfo, stack_opt),
common__find_matching_cell(Var, ConsId, ArgVars,
- deconstruction, Info0, OldStruct)
+ deconstruction, !.Info, OldStruct)
->
OldStruct = structure(_, _, _, OldArgVars),
common__create_output_unifications(GoalInfo0, ArgVars,
- OldArgVars, UniModes, Goals, Info0, Info1),
+ OldArgVars, UniModes, Goals, !Info),
Goal = conj(Goals),
pd_cost__goal(Goal0 - GoalInfo0, Cost),
- simplify_info_incr_cost_delta(Info1, Cost, Info2),
- simplify_info_set_requantify(Info2, Info3),
+ simplify_info_incr_cost_delta(Cost, !Info),
+ simplify_info_set_requantify(!Info),
( CanFail = can_fail ->
- simplify_info_set_rerun_det(Info3, Info)
+ simplify_info_set_rerun_det(!Info)
;
- Info = Info3
+ true
)
;
Goal = Goal0,
- common__record_cell(Var, ConsId, ArgVars, Info0, Info)
+ common__record_cell(Var, ConsId, ArgVars, !Info)
),
GoalInfo = GoalInfo0
;
Unification0 = assign(Var1, Var2),
+ common__record_equivalence(Var1, Var2, !Info),
Goal = Goal0,
- common__record_equivalence(Var1, Var2, Info0, Info),
GoalInfo = GoalInfo0
;
Unification0 = simple_test(Var1, Var2),
+ common__record_equivalence(Var1, Var2, !Info),
Goal = Goal0,
- common__record_equivalence(Var1, Var2, Info0, Info),
GoalInfo = GoalInfo0
;
Unification0 = complicated_unify(_, _, _),
Goal = Goal0,
- Info = Info0,
GoalInfo = GoalInfo0
).
@@ -257,9 +249,9 @@
---> deconstruction
; construction.
-:- pred common__find_matching_cell(prog_var, cons_id,
- list(prog_var), unification_type, simplify_info, structure).
-:- mode common__find_matching_cell(in, in, in, in, in, out) is semidet.
+:- pred common__find_matching_cell(prog_var::in, cons_id::in,
+ list(prog_var)::in, unification_type::in, simplify_info::in,
+ structure::out) is semidet.
common__find_matching_cell(Var, ConsId, ArgVars, UniType, Info, OldStruct) :-
simplify_info_get_common_info(Info, CommonInfo),
@@ -279,11 +271,9 @@
common__find_matching_cell_2(Structs, Var, ConsId, ArgVars, UniType,
VarEqv, VarTypes, OldStruct).
-:- pred common__find_matching_cell_2(list(structure), prog_var, cons_id,
- list(prog_var),
- unification_type, eqvclass(prog_var), map(prog_var, type), structure).
-:- mode common__find_matching_cell_2(in, in, in, in, in,
- in, in, out) is semidet.
+:- pred common__find_matching_cell_2(list(structure)::in, prog_var::in,
+ cons_id::in, list(prog_var)::in, unification_type::in,
+ eqvclass(prog_var)::in, vartypes::in, structure::out) is semidet.
common__find_matching_cell_2([Struct | Structs], Var, ConsId, ArgVars,
UniType, VarEqv, VarTypes, OldStruct) :-
@@ -327,8 +317,7 @@
% and `maybe(float)', but we know that they have the same
% representation.
-:- pred common__compatible_types(type, type).
-:- mode common__compatible_types(in, in) is semidet.
+:- pred common__compatible_types((type)::in, (type)::in) is semidet.
common__compatible_types(Type1, Type2) :-
type_to_ctor_and_args(Type1, TypeCtor1, _),
@@ -339,9 +328,8 @@
% succeeds if the two lists of variables are equivalent
% according to the specified equivalence class.
-:- pred common__var_lists_are_equiv(list(prog_var), list(prog_var),
- eqvclass(prog_var)).
-:- mode common__var_lists_are_equiv(in, in, in) is semidet.
+:- pred common__var_lists_are_equiv(list(prog_var)::in, list(prog_var)::in,
+ eqvclass(prog_var)::in) is semidet.
common__var_lists_are_equiv([], [], _VarEqv).
common__var_lists_are_equiv([X | Xs], [Y | Ys], VarEqv) :-
@@ -354,15 +342,10 @@
% succeeds if the two variables are equivalent
% according to the specified equivalence class.
-:- pred common__vars_are_equiv(prog_var, prog_var, eqvclass(prog_var)).
-:- mode common__vars_are_equiv(in, in, in) is semidet.
+:- pred common__vars_are_equiv(prog_var::in, prog_var::in,
+ eqvclass(prog_var)::in) is semidet.
common__vars_are_equiv(X, Y, VarEqv) :-
- % write('looking for equivalence of '),
- % write(X),
- % write(' and '),
- % write(Y),
- % nl,
(
X = Y
;
@@ -370,33 +353,30 @@
eqvclass__is_member(VarEqv, Y),
eqvclass__same_eqvclass(VarEqv, X, Y)
).
- % write('they are equivalent'),
- % nl.
%---------------------------------------------------------------------------%
-:- pred common__record_cell(prog_var, cons_id, list(prog_var),
- simplify_info, simplify_info).
-:- mode common__record_cell(in, in, in, in, out) is det.
+:- pred common__record_cell(prog_var::in, cons_id::in, list(prog_var)::in,
+ simplify_info::in, simplify_info::out) is det.
-common__record_cell(Var, ConsId, ArgVars, Info0, Info) :-
- simplify_info_get_common_info(Info0, CommonInfo0),
- simplify_info_get_var_types(Info0, VarTypes),
+common__record_cell(Var, ConsId, ArgVars, !Info) :-
+ simplify_info_get_common_info(!.Info, CommonInfo0),
+ simplify_info_get_var_types(!.Info, VarTypes),
CommonInfo0 = common(VarEqv, StructMapAll0,
StructMapLastCall0, SeenCalls),
map__lookup(VarTypes, Var, VarType),
Struct = structure(Var, VarType, ConsId, ArgVars),
- common__do_record_cell(StructMapAll0, ConsId, Struct, StructMapAll),
- common__do_record_cell(StructMapLastCall0, ConsId, Struct,
- StructMapLastCall),
+ common__do_record_cell(ConsId, Struct, StructMapAll0, StructMapAll),
+ common__do_record_cell(ConsId, Struct,
+ StructMapLastCall0, StructMapLastCall),
CommonInfo = common(VarEqv, StructMapAll,
StructMapLastCall, SeenCalls),
- simplify_info_set_common_info(Info0, CommonInfo, Info).
+ simplify_info_set_common_info(CommonInfo, !Info).
-:- pred common__do_record_cell(struct_map, cons_id, structure, struct_map).
-:- mode common__do_record_cell(in, in, in, out) is det.
+:- pred common__do_record_cell(cons_id::in, structure::in,
+ struct_map::in, struct_map::out) is det.
-common__do_record_cell(StructMap0, ConsId, Struct, StructMap) :-
+common__do_record_cell(ConsId, Struct, StructMap0, StructMap) :-
( map__search(StructMap0, ConsId, StructList0Prime) ->
StructList0 = StructList0Prime
;
@@ -412,32 +392,25 @@
%---------------------------------------------------------------------------%
-:- pred common__record_equivalence(prog_var, prog_var,
- simplify_info, simplify_info).
-:- mode common__record_equivalence(in, in, in, out) is det.
+:- pred common__record_equivalence(prog_var::in, prog_var::in,
+ simplify_info::in, simplify_info::out) is det.
-common__record_equivalence(Var1, Var2, Info0, Info) :-
- simplify_info_get_common_info(Info0, CommonInfo0),
+common__record_equivalence(Var1, Var2, !Info) :-
+ simplify_info_get_common_info(!.Info, CommonInfo0),
CommonInfo0 = common(VarEqv0, StructMap0, StructMap1, SeenCalls),
- % write('ensuring equivalence of '),
- % write(Var1),
- % write(' and '),
- % write(Var2),
- % nl,
eqvclass__ensure_equivalence(VarEqv0, Var1, Var2, VarEqv),
CommonInfo = common(VarEqv, StructMap0, StructMap1, SeenCalls),
- simplify_info_set_common_info(Info0, CommonInfo, Info).
+ simplify_info_set_common_info(CommonInfo, !Info).
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
-common__optimise_call(PredId, ProcId, Args, Goal0,
- GoalInfo, Goal, Info0, Info) :-
+common__optimise_call(PredId, ProcId, Args, GoalInfo, Goal0, Goal, !Info) :-
(
goal_info_get_determinism(GoalInfo, Det),
common__check_call_detism(Det),
- simplify_info_get_var_types(Info0, VarTypes),
- simplify_info_get_module_info(Info0, ModuleInfo),
+ simplify_info_get_var_types(!.Info, VarTypes),
+ simplify_info_get_module_info(!.Info, ModuleInfo),
module_info_pred_proc_info(ModuleInfo, PredId,
ProcId, _, ProcInfo),
proc_info_argmodes(ProcInfo, ArgModes),
@@ -445,28 +418,25 @@
Args, InputArgs, OutputArgs, OutputModes)
->
common__optimise_call_2(seen_call(PredId, ProcId), InputArgs,
- OutputArgs, OutputModes, Goal0, GoalInfo, Goal,
- Info0, Info)
+ OutputArgs, OutputModes, GoalInfo, Goal0, Goal, !Info)
;
- Goal = Goal0,
- Info = Info0
+ Goal = Goal0
).
-common__optimise_higher_order_call(Closure, Args, Modes, Det, Goal0,
- GoalInfo, Goal, Info0, Info) :-
+common__optimise_higher_order_call(Closure, Args, Modes, Det, GoalInfo,
+ Goal0, Goal, !Info) :-
(
common__check_call_detism(Det),
- simplify_info_get_var_types(Info0, VarTypes),
- simplify_info_get_module_info(Info0, ModuleInfo),
+ simplify_info_get_var_types(!.Info, VarTypes),
+ simplify_info_get_module_info(!.Info, ModuleInfo),
common__partition_call_args(VarTypes, ModuleInfo, Modes, Args,
InputArgs, OutputArgs, OutputModes)
->
common__optimise_call_2(higher_order_call,
- [Closure | InputArgs], OutputArgs, OutputModes, Goal0,
- GoalInfo, Goal, Info0, Info)
+ [Closure | InputArgs], OutputArgs, OutputModes,
+ GoalInfo, Goal0, Goal, !Info)
;
- Goal = Goal0,
- Info = Info0
+ Goal = Goal0
).
:- pred common__check_call_detism(determinism::in) is semidet.
@@ -479,14 +449,14 @@
; SolnCount = at_most_many_cc
).
-:- pred common__optimise_call_2(seen_call_id, list(prog_var), list(prog_var),
- list(mode), hlds_goal_expr, hlds_goal_info, hlds_goal_expr,
- simplify_info, simplify_info).
-:- mode common__optimise_call_2(in, in, in, in, in, in, out, in, out) is det.
-
-common__optimise_call_2(SeenCall, InputArgs, OutputArgs, Modes, Goal0,
- GoalInfo, Goal, Info0, Info) :-
- simplify_info_get_common_info(Info0, CommonInfo0),
+:- pred common__optimise_call_2(seen_call_id::in, list(prog_var)::in,
+ list(prog_var)::in, list(mode)::in, hlds_goal_info::in,
+ hlds_goal_expr::in, hlds_goal_expr::out,
+ simplify_info::in, simplify_info::out) is det.
+
+common__optimise_call_2(SeenCall, InputArgs, OutputArgs, Modes, GoalInfo,
+ Goal0, Goal, !Info) :-
+ simplify_info_get_common_info(!.Info, CommonInfo0),
CommonInfo0 = common(Eqv0, Structs0, Structs1, SeenCalls0),
(
map__search(SeenCalls0, SeenCall, SeenCallsList0)
@@ -494,16 +464,16 @@
( common__find_previous_call(SeenCallsList0, InputArgs,
Eqv0, OutputArgs2, PrevContext)
->
- simplify_info_get_module_info(Info0, ModuleInfo),
+ simplify_info_get_module_info(!.Info, ModuleInfo),
mode_util__modes_to_uni_modes(Modes, Modes, ModuleInfo,
UniModes),
common__create_output_unifications(GoalInfo,
- OutputArgs, OutputArgs2, UniModes,
- Goals, Info0, Info1),
+ OutputArgs, OutputArgs2, UniModes, Goals,
+ !Info),
Goal = conj(Goals),
- simplify_info_get_var_types(Info0, VarTypes),
+ simplify_info_get_var_types(!.Info, VarTypes),
(
- simplify_do_warn_calls(Info1),
+ simplify_do_warn_calls(!.Info),
% Don't warn for cases such as:
% set__init(Set1 : set(int)),
% set__init(Set2 : set(float)).
@@ -511,27 +481,27 @@
OutputArgTypes1),
map__apply_to_list(OutputArgs2, VarTypes,
OutputArgTypes2),
- common__types_match_exactly_list(OutputArgTypes1,
- OutputArgTypes2)
+ common__types_match_exactly_list(
+ OutputArgTypes1, OutputArgTypes2)
->
goal_info_get_context(GoalInfo, Context),
- simplify_info_do_add_msg(Info1,
+ simplify_info_do_add_msg(
duplicate_call(SeenCall, PrevContext,
Context),
- Info2)
+ !Info)
;
- Info2 = Info1
+ true
),
- CommonInfo = common(Eqv0, Structs0,
- Structs1, SeenCalls0),
+ CommonInfo = common(Eqv0, Structs0, Structs1,
+ SeenCalls0),
pd_cost__goal(Goal0 - GoalInfo, Cost),
- simplify_info_incr_cost_delta(Info2, Cost, Info3),
- simplify_info_set_requantify(Info3, Info4),
+ simplify_info_incr_cost_delta(Cost, !Info),
+ simplify_info_set_requantify(!Info),
goal_info_get_determinism(GoalInfo, Detism0),
( Detism0 \= det ->
- simplify_info_set_rerun_det(Info4, Info5)
+ simplify_info_set_rerun_det(!Info)
;
- Info5 = Info4
+ true
)
;
goal_info_get_context(GoalInfo, Context),
@@ -540,18 +510,16 @@
[ThisCall | SeenCallsList0], SeenCalls),
CommonInfo = common(Eqv0, Structs0,
Structs1, SeenCalls),
- Goal = Goal0,
- Info5 = Info0
+ Goal = Goal0
)
;
goal_info_get_context(GoalInfo, Context),
ThisCall = call_args(Context, InputArgs, OutputArgs),
map__det_insert(SeenCalls0, SeenCall, [ThisCall], SeenCalls),
CommonInfo = common(Eqv0, Structs0, Structs1, SeenCalls),
- Goal = Goal0,
- Info5 = Info0
+ Goal = Goal0
),
- simplify_info_set_common_info(Info5, CommonInfo, Info).
+ simplify_info_set_common_info(CommonInfo, !Info).
%---------------------------------------------------------------------------%
@@ -631,7 +599,7 @@
% The unneeded assignments will be removed later.
common__create_output_unifications(GoalInfo, OutputArgs, OldOutputArgs,
- UniModes, Goals, Info0, Info) :-
+ UniModes, Goals, !Info) :-
(
OutputArgs = [OutputArg | OutputArgs1],
OldOutputArgs = [OldOutputArg | OldOutputArgs1],
@@ -643,36 +611,34 @@
OutputArg \= OldOutputArg
->
common__generate_assign(OutputArg, OldOutputArg,
- UniMode, GoalInfo, Goal, Info0, Info1),
+ UniMode, GoalInfo, Goal, !Info),
common__create_output_unifications(GoalInfo,
OutputArgs1, OldOutputArgs1, UniModes1,
- Goals1, Info1, Info),
+ Goals1, !Info),
Goals = [Goal | Goals1]
;
common__create_output_unifications(GoalInfo,
OutputArgs1, OldOutputArgs1, UniModes1, Goals,
- Info0, Info)
+ !Info)
)
;
OutputArgs = [],
OldOutputArgs = [],
UniModes = []
->
- Goals = [],
- Info = Info0
+ Goals = []
;
error("common__create_output_unifications: mode mismatch")
).
-
%---------------------------------------------------------------------------%
-:- pred common__generate_assign(prog_var, prog_var, uni_mode,
- hlds_goal_info, hlds_goal, simplify_info, simplify_info).
-:- mode common__generate_assign(in, in, in, in, out, in, out) is det.
+:- pred common__generate_assign(prog_var::in, prog_var::in, uni_mode::in,
+ hlds_goal_info::in, hlds_goal::out,
+ simplify_info::in, simplify_info::out) is det.
-common__generate_assign(ToVar, FromVar, UniMode, _, Goal, Info0, Info) :-
- simplify_info_get_var_types(Info0, VarTypes),
+common__generate_assign(ToVar, FromVar, UniMode, _, Goal, !Info) :-
+ simplify_info_get_var_types(!.Info, VarTypes),
map__lookup(VarTypes, ToVar, ToVarType),
map__lookup(VarTypes, FromVar, FromVarType),
@@ -692,8 +658,7 @@
% Unfortunately this loses information for other optimizations,
% since the call to the type cast hides the equivalence of
% the input and output.
- Modes = [(ToVarInst -> ToVarInst),
- (free -> ToVarInst)],
+ Modes = [(ToVarInst -> ToVarInst), (free -> ToVarInst)],
GoalExpr = generic_call(unsafe_cast, [FromVar, ToVar],
Modes, det)
),
@@ -705,10 +670,9 @@
goal_info_init(NonLocals, InstMapDelta, det, pure, GoalInfo),
Goal = GoalExpr - GoalInfo,
- common__record_equivalence(ToVar, FromVar, Info0, Info).
+ common__record_equivalence(ToVar, FromVar, !Info).
-:- pred common__types_match_exactly((type), (type)).
-:- mode common__types_match_exactly(in, in) is semidet.
+:- pred common__types_match_exactly((type)::in, (type)::in) is semidet.
common__types_match_exactly(term__variable(Var), term__variable(Var)).
common__types_match_exactly(Type1, Type2) :-
@@ -718,8 +682,8 @@
TypeCtor1 = TypeCtor2,
common__types_match_exactly_list(Args1, Args2).
-:- pred common__types_match_exactly_list(list(type), list(type)).
-:- mode common__types_match_exactly_list(in, in) is semidet.
+:- pred common__types_match_exactly_list(list(type)::in, list(type)::in)
+ is semidet.
common__types_match_exactly_list([], []).
common__types_match_exactly_list([Type1 | Types1], [Type2 | Types2]) :-
Index: compiler/simplify.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/simplify.m,v
retrieving revision 1.128
diff -u -b -r1.128 simplify.m
--- compiler/simplify.m 19 Feb 2004 07:17:23 -0000 1.128
+++ compiler/simplify.m 6 Mar 2004 10:26:07 -0000
@@ -40,27 +40,26 @@
:- import_module io, bool, list, map.
-:- pred simplify__pred(list(simplification), pred_id, module_info, module_info,
- pred_info, pred_info, int, int, io__state, io__state).
-:- mode simplify__pred(in, in, in, out, in, out, out, out, di, uo) is det.
-
-:- pred simplify__proc(list(simplification), pred_id, proc_id,
- module_info, module_info, proc_info, proc_info, io__state, io__state).
-:- mode simplify__proc(in, in, in, in, out, in, out, di, uo) is det.
-
-:- pred simplify__proc_2(list(simplification), pred_id, proc_id, module_info,
- module_info, proc_info, proc_info, set(det_msg)).
-:- mode simplify__proc_2(in, in, in, in, out, in, out, out) is det.
-
-:- pred simplify__process_goal(hlds_goal, hlds_goal,
- simplify_info, simplify_info).
-:- mode simplify__process_goal(in, out, in, out) is det.
+:- pred simplify__pred(list(simplification)::in, pred_id::in,
+ module_info::in, module_info::out, pred_info::in, pred_info::out,
+ int::out, int::out, io::di, io::uo) is det.
+
+:- pred simplify__proc(list(simplification)::in, pred_id::in, proc_id::in,
+ module_info::in, module_info::out, proc_info::in, proc_info::out,
+ io::di, io::uo) is det.
+
+:- pred simplify__proc_return_msgs(list(simplification)::in, pred_id::in,
+ proc_id::in, module_info::in, module_info::out,
+ proc_info::in, proc_info::out, set(det_msg)::out) is det.
+
+:- pred simplify__process_goal(hlds_goal::in, hlds_goal::out,
+ simplify_info::in, simplify_info::out) is det.
% Find out which simplifications should be run from the options table
% stored in the globals. The first argument states whether warnings
% should be issued during this pass of simplification.
-:- pred simplify__find_simplifications(bool, globals, list(simplification)).
-:- mode simplify__find_simplifications(in, in, out) is det.
+:- pred simplify__find_simplifications(bool::in, globals::in,
+ list(simplification)::out) is det.
:- type simplification
---> warn_simple_code % --warn-simple-code
@@ -108,45 +107,45 @@
%-----------------------------------------------------------------------------%
-simplify__pred(Simplifications0, PredId, ModuleInfo0, ModuleInfo,
- PredInfo0, PredInfo, WarnCnt, ErrCnt) -->
- write_pred_progress_message("% Simplifying ", PredId, ModuleInfo0),
- { ProcIds = pred_info_non_imported_procids(PredInfo0) },
- { MaybeMsgs0 = no },
- {
+simplify__pred(Simplifications0, PredId, !ModuleInfo,
+ !PredInfo, WarnCnt, ErrCnt, !IO) :-
+ write_pred_progress_message("% Simplifying ", PredId, !.ModuleInfo,
+ !IO),
+ ProcIds = pred_info_non_imported_procids(!.PredInfo),
+ (
% Don't warn for compiler-generated procedures.
list__member(warn_simple_code, Simplifications0),
- is_unify_or_compare_pred(PredInfo0)
+ is_unify_or_compare_pred(!.PredInfo)
->
list__delete_all(Simplifications0, warn_simple_code,
Simplifications)
;
Simplifications = Simplifications0
- },
- { simplify__procs(Simplifications, PredId, ProcIds, ModuleInfo0,
- ModuleInfo, PredInfo0, PredInfo, MaybeMsgs0, MaybeMsgs) },
- ( { MaybeMsgs = yes(Msgs0 - Msgs1) } ->
- { set__union(Msgs0, Msgs1, Msgs2) },
- { set__to_sorted_list(Msgs2, Msgs) },
- det_report_msgs(Msgs, ModuleInfo, WarnCnt, ErrCnt)
- ;
- { WarnCnt = 0 },
- { ErrCnt = 0 }
- ).
-
-:- pred simplify__procs(list(simplification), pred_id, list(proc_id),
- module_info, module_info, pred_info, pred_info,
- maybe(pair(set(det_msg))), maybe(pair(set(det_msg)))).
-:- mode simplify__procs(in, in, in, in, out, in, out,
- in, out) is det.
+ ),
+ MaybeMsgs0 = no,
+ simplify__procs(Simplifications, PredId, ProcIds, !ModuleInfo,
+ !PredInfo, MaybeMsgs0, MaybeMsgs),
+ ( MaybeMsgs = yes(Msgs0 - Msgs1) ->
+ set__union(Msgs0, Msgs1, Msgs2),
+ set__to_sorted_list(Msgs2, Msgs),
+ det_report_msgs(Msgs, !.ModuleInfo, WarnCnt, ErrCnt, !IO)
+ ;
+ WarnCnt = 0,
+ ErrCnt = 0
+ ).
+
+:- pred simplify__procs(list(simplification)::in, pred_id::in,
+ list(proc_id)::in, module_info::in, module_info::out,
+ pred_info::in, pred_info::out,
+ maybe(pair(set(det_msg)))::in, maybe(pair(set(det_msg)))::out) is det.
simplify__procs(_, _, [], !ModuleInfo, !PredInfo, !Msgs).
simplify__procs(Simplifications, PredId, [ProcId | ProcIds], !ModuleInfo,
!PredInfo, !MaybeMsgs) :-
pred_info_procedures(!.PredInfo, Procs0),
map__lookup(Procs0, ProcId, Proc0),
- simplify__proc_2(Simplifications, PredId, ProcId, !ModuleInfo,
- Proc0, Proc, Msgs1),
+ simplify__proc_return_msgs(Simplifications, PredId, ProcId,
+ !ModuleInfo, Proc0, Proc, Msgs1),
map__det_update(Procs0, ProcId, Proc, Procs),
pred_info_set_procedures(Procs, !PredInfo),
set__to_sorted_list(Msgs1, Msgs2),
@@ -168,11 +167,11 @@
simplify__proc(Simplifications, PredId, ProcId, !ModuleInfo, !Proc, !IO) :-
write_pred_progress_message("% Simplifying ", PredId, !.ModuleInfo,
!IO),
- simplify__proc_2(Simplifications, PredId, ProcId, !ModuleInfo,
+ simplify__proc_return_msgs(Simplifications, PredId, ProcId, !ModuleInfo,
!Proc, _).
-simplify__proc_2(Simplifications, PredId, ProcId, !ModuleInfo, !ProcInfo,
- Msgs) :-
+simplify__proc_return_msgs(Simplifications, PredId, ProcId, !ModuleInfo,
+ !ProcInfo, Msgs) :-
module_info_globals(!.ModuleInfo, Globals),
proc_info_vartypes(!.ProcInfo, VarTypes0),
det_info_init(!.ModuleInfo, VarTypes0, PredId, ProcId, Globals,
@@ -200,50 +199,52 @@
simplify_info_get_module_info(Info, !:ModuleInfo),
simplify_info_get_msgs(Info, Msgs).
-simplify__process_goal(Goal0, Goal, Info0, Info) :-
- simplify_info_get_simplifications(Info0, Simplifications0),
- simplify_info_get_instmap(Info0, InstMap0),
+simplify__process_goal(Goal0, Goal, !Info) :-
+ simplify_info_get_simplifications(!.Info, Simplifications0),
+ simplify_info_get_instmap(!.Info, InstMap0),
- ( (simplify_do_common(Info0); simplify_do_calls(Info0)) ->
+ (
+ ( simplify_do_common(!.Info)
+ ; simplify_do_calls(!.Info)
+ )
+ ->
% On the first pass do common structure and call elimination.
NotOnFirstPass = [do_once, excess_assigns],
set__delete_list(Simplifications0, NotOnFirstPass,
Simplifications1),
- simplify_info_set_simplifications(Info0, Simplifications1,
- Info1),
+ simplify_info_set_simplifications(Simplifications1, !Info),
- simplify__do_process_goal(Goal0, Goal1, Info1, Info2),
+ simplify__do_process_goal(Goal0, Goal1, !Info),
NotOnSecondPass = [warn_simple_code, warn_duplicate_calls,
common_struct, duplicate_calls],
set__delete_list(Simplifications0, NotOnSecondPass,
Simplifications2),
- simplify_info_reinit(Simplifications2, InstMap0, Info2, Info3)
+ simplify_info_reinit(Simplifications2, InstMap0, !Info)
;
- Info3 = Info0,
Goal1 = Goal0
),
% On the second pass do excess assignment elimination and
% some cleaning up after the common structure pass.
- simplify__do_process_goal(Goal1, Goal, Info3, Info).
+ simplify__do_process_goal(Goal1, Goal, !Info).
:- pred simplify__do_process_goal(hlds_goal::in, hlds_goal::out,
simplify_info::in, simplify_info::out) is det.
-simplify__do_process_goal(Goal0, Goal, Info0, Info) :-
- simplify_info_get_instmap(Info0, InstMap0),
- simplify__goal(Goal0, Goal1, Info0, Info1),
- simplify_info_get_varset(Info1, VarSet0),
- simplify_info_get_var_types(Info1, VarTypes0),
- ( simplify_info_requantify(Info1) ->
+simplify__do_process_goal(Goal0, Goal, !Info) :-
+ simplify_info_get_instmap(!.Info, InstMap0),
+ simplify__goal(Goal0, Goal1, !Info),
+ simplify_info_get_varset(!.Info, VarSet0),
+ simplify_info_get_var_types(!.Info, VarTypes0),
+ ( simplify_info_requantify(!.Info) ->
Goal1 = _ - GoalInfo1,
goal_info_get_nonlocals(GoalInfo1, NonLocals),
implicitly_quantify_goal(NonLocals, _, Goal1, Goal2,
- VarSet0, VarSet, VarTypes0, VarTypes),
+ VarSet0, VarSet1, VarTypes0, VarTypes1),
- simplify_info_set_varset(Info1, VarSet, Info2),
- simplify_info_set_var_types(Info2, VarTypes, Info3),
+ simplify_info_set_varset(VarSet1, !Info),
+ simplify_info_set_var_types(VarTypes1, !Info),
% Always recompute instmap_deltas for atomic goals - this
% is safer in the case where unused variables should no
@@ -251,16 +252,15 @@
% In the alias branch this is necessary anyway.
RecomputeAtomic = yes,
- simplify_info_get_module_info(Info3, ModuleInfo3),
+ simplify_info_get_module_info(!.Info, ModuleInfo0),
recompute_instmap_delta(RecomputeAtomic, Goal2, Goal3,
- VarTypes, Info3 ^ inst_varset, InstMap0, ModuleInfo3,
- ModuleInfo4),
- simplify_info_set_module_info(Info3, ModuleInfo4, Info4)
+ VarTypes1, !.Info ^ inst_varset, InstMap0,
+ ModuleInfo0, ModuleInfo1),
+ simplify_info_set_module_info(ModuleInfo1, !Info)
;
- Goal3 = Goal1,
- Info4 = Info1
+ Goal3 = Goal1
),
- ( simplify_info_rerun_det(Info4) ->
+ ( simplify_info_rerun_det(!.Info) ->
Goal0 = _ - GoalInfo0,
goal_info_get_determinism(GoalInfo0, Det),
det_get_soln_context(Det, SolnContext),
@@ -268,52 +268,50 @@
% det_infer_goal looks up the proc_info in the module_info
% for the vartypes, so we'd better stick them back in the
% module_info.
- simplify_info_get_module_info(Info4, ModuleInfo5),
- simplify_info_get_varset(Info4, VarSet4),
- simplify_info_get_var_types(Info4, VarTypes4),
- simplify_info_get_det_info(Info4, DetInfo4),
- det_info_get_pred_id(DetInfo4, PredId),
- det_info_get_proc_id(DetInfo4, ProcId),
- module_info_pred_proc_info(ModuleInfo5, PredId, ProcId,
+ simplify_info_get_module_info(!.Info, ModuleInfo2),
+ simplify_info_get_varset(!.Info, VarSet2),
+ simplify_info_get_var_types(!.Info, VarTypes2),
+ simplify_info_get_det_info(!.Info, DetInfo2),
+ det_info_get_pred_id(DetInfo2, PredId),
+ det_info_get_proc_id(DetInfo2, ProcId),
+ module_info_pred_proc_info(ModuleInfo2, PredId, ProcId,
PredInfo, ProcInfo0),
- proc_info_set_vartypes(VarTypes4, ProcInfo0, ProcInfo1),
- proc_info_set_varset(VarSet4, ProcInfo1, ProcInfo),
+ proc_info_set_vartypes(VarTypes2, ProcInfo0, ProcInfo1),
+ proc_info_set_varset(VarSet2, ProcInfo1, ProcInfo),
module_info_set_pred_proc_info(PredId, ProcId,
- PredInfo, ProcInfo, ModuleInfo5, ModuleInfo6),
- simplify_info_set_module_info(Info4, ModuleInfo6, Info),
+ PredInfo, ProcInfo, ModuleInfo2, ModuleInfo3),
+ simplify_info_set_module_info(ModuleInfo3, !Info),
- simplify_info_get_det_info(Info, DetInfo),
+ simplify_info_get_det_info(!.Info, DetInfo),
det_infer_goal(Goal3, InstMap0, SolnContext,
DetInfo, Goal, _, _)
;
- Info = Info4,
Goal = Goal3
).
%-----------------------------------------------------------------------------%
-simplify__find_simplifications(WarnThisPass, Globals, S) :-
- simplify__find_simplifications_2(WarnThisPass, Globals, [], S).
+simplify__find_simplifications(WarnThisPass, Globals, Simps) :-
+ simplify__find_simplifications_2(WarnThisPass, Globals, [], Simps).
-:- pred simplify__find_simplifications_2(bool, globals,
- list(simplification), list(simplification)).
-:- mode simplify__find_simplifications_2(in, in, in, out) is det.
+:- pred simplify__find_simplifications_2(bool::in, globals::in,
+ list(simplification)::in, list(simplification)::out) is det.
-simplify__find_simplifications_2(WarnThisPass, Globals) -->
- ( { WarnThisPass = yes } ->
+simplify__find_simplifications_2(WarnThisPass, Globals, !Simps) :-
+ ( WarnThisPass = yes ->
simplify__lookup_option(Globals, warn_duplicate_calls,
- warn_duplicate_calls),
+ warn_duplicate_calls, !Simps),
simplify__lookup_option(Globals, warn_simple_code,
- warn_simple_code)
+ warn_simple_code, !Simps)
;
- []
+ true
),
- simplify__lookup_option(Globals, excess_assign, excess_assigns),
- simplify__lookup_option(Globals, common_struct, common_struct),
+ simplify__lookup_option(Globals, excess_assign, excess_assigns, !Simps),
+ simplify__lookup_option(Globals, common_struct, common_struct, !Simps),
simplify__lookup_option(Globals, optimize_duplicate_calls,
- duplicate_calls),
+ duplicate_calls, !Simps),
simplify__lookup_option(Globals, constant_propagation,
- constant_prop).
+ constant_prop, !Simps).
:- pred simplify__lookup_option(globals::in, option::in, simplification::in,
list(simplification)::in, list(simplification)::out) is det.
@@ -329,13 +327,13 @@
%-----------------------------------------------------------------------------%
-:- pred simplify__goal(hlds_goal, hlds_goal, simplify_info, simplify_info).
-:- mode simplify__goal(in, out, in, out) is det.
+:- pred simplify__goal(hlds_goal::in, hlds_goal::out,
+ simplify_info::in, simplify_info::out) is det.
-simplify__goal(Goal0, Goal - GoalInfo, Info0, Info) :-
+simplify__goal(Goal0, Goal - GoalInfo, !Info) :-
Goal0 = _ - GoalInfo0,
goal_info_get_determinism(GoalInfo0, Detism),
- simplify_info_get_det_info(Info0, DetInfo),
+ simplify_info_get_det_info(!.Info, DetInfo),
(
%
% if --no-fully-strict,
@@ -353,27 +351,27 @@
goal_info_get_context(GoalInfo0, Context),
(
- simplify_do_warn(Info0),
+ simplify_do_warn(!.Info),
\+ (
goal_contains_goal(Goal0, SubGoal),
SubGoal = disj([]) - _
)
->
- simplify_info_add_msg(Info0,
- goal_cannot_succeed(Context), Info1)
+ simplify_info_add_msg(goal_cannot_succeed(Context),
+ !Info)
;
- Info1 = Info0
+ true
),
% If the goal had any non-locals we should requantify.
goal_info_get_nonlocals(GoalInfo0, NonLocals0),
( set__empty(NonLocals0) ->
- Info2 = Info1
+ true
;
- simplify_info_set_requantify(Info1, Info2)
+ simplify_info_set_requantify(!Info)
),
pd_cost__goal(Goal0, CostDelta),
- simplify_info_incr_cost_delta(Info2, CostDelta, Info3),
+ simplify_info_incr_cost_delta(CostDelta, !Info),
fail_goal(Context, Goal1)
;
%
@@ -389,7 +387,7 @@
MaxSoln \= at_most_zero,
goal_info_get_instmap_delta(GoalInfo0, InstMapDelta),
goal_info_get_nonlocals(GoalInfo0, NonLocalVars),
- simplify_info_get_instmap(Info0, InstMap0),
+ simplify_info_get_instmap(!.Info, InstMap0),
det_no_output_vars(NonLocalVars, InstMap0, InstMapDelta,
DetInfo),
% ensure goal is pure or semipure
@@ -398,56 +396,54 @@
; goal_cannot_loop_or_throw(Goal0)
)
->
-/******************
-The following warning is disabled, because it often results in spurious
-warnings. Sometimes predicate calls are used just to constrain the types,
-to avoid type ambiguities or unbound type variables, and in such cases,
-it is perfectly legitimate for a call to be det and to have no outputs.
-There's no simple way of telling those cases from cases for which we
-really ought to warn.
- % warn about this, if the goal wasn't `true', wasn't `!',
- % and wasn't a deconstruction unification.
- % We don't warn about deconstruction unifications
- % with no outputs that always succeed, because that
- % would result in bogus warnings, since switch detection
- % converts deconstruction unifications that can fail
- % into ones that always succeed by moving the test into
- % the switch.
- % We also don't warn about conjunctions or existential
- % quantifications, because it seems that warnings in those
- % cases are usually spurious.
- (
- simplify_do_warn(Info0),
- % Goal0 \= conj([]) - _,
- \+ (Goal0 = call(_, _, _, _, _, SymName) - _,
- unqualify_name(SymName, "!")),
- Goal0 \= conj(_) - _,
- Goal0 \= some(_, _) - _,
- \+ (Goal0 = unify(_, _, _, Unification, _) - _,
- Unification = deconstruct(_, _, _, _, _))
- ->
- simplify_info_add_msg(Info0,
- det_goal_has_no_outputs(Context), Info1)
- ;
- Info1 = Info0
- ),
-******************/
- Info0 = Info1,
+% The following warning is disabled, because it often results in spurious
+% warnings. Sometimes predicate calls are used just to constrain the types,
+% to avoid type ambiguities or unbound type variables, and in such cases,
+% it is perfectly legitimate for a call to be det and to have no outputs.
+% There's no simple way of telling those cases from cases for which we
+% really ought to warn.
+% XXX This hasn't really been true since we added `with_type`.
+%
+% % warn about this, if the goal wasn't `true', wasn't `!',
+% % and wasn't a deconstruction unification.
+% % We don't warn about deconstruction unifications
+% % with no outputs that always succeed, because that
+% % would result in bogus warnings, since switch detection
+% % converts deconstruction unifications that can fail
+% % into ones that always succeed by moving the test into
+% % the switch.
+% % We also don't warn about conjunctions or existential
+% % quantifications, because it seems that warnings in those
+% % cases are usually spurious.
+% (
+% simplify_do_warn(!.Info),
+% % Goal0 \= conj([]) - _,
+% \+ (Goal0 = call(_, _, _, _, _, SymName) - _,
+% unqualify_name(SymName, "!")),
+% Goal0 \= conj(_) - _,
+% Goal0 \= some(_, _) - _,
+% \+ (Goal0 = unify(_, _, _, Unification, _) - _,
+% Unification = deconstruct(_, _, _, _, _))
+% ->
+% simplify_info_add_msg(det_goal_has_no_outputs(Context),
+% !Info)
+% ;
+% true
+% ),
% If the goal had any non-locals we should requantify.
goal_info_get_nonlocals(GoalInfo0, NonLocals0),
( set__empty(NonLocals0) ->
- Info2 = Info1
+ true
;
- simplify_info_set_requantify(Info1, Info2)
+ simplify_info_set_requantify(!Info)
),
pd_cost__goal(Goal0, CostDelta),
- simplify_info_incr_cost_delta(Info2, CostDelta, Info3),
+ simplify_info_incr_cost_delta(CostDelta, !Info),
goal_info_get_context(GoalInfo0, Context),
true_goal(Context, Goal1)
;
- Goal1 = Goal0,
- Info3 = Info0
+ Goal1 = Goal0
),
%
@@ -460,21 +456,20 @@
;
Goal2 = Goal1
),
- simplify_info_maybe_clear_structs(before, Goal2, Info3, Info4),
+ simplify_info_maybe_clear_structs(before, Goal2, !Info),
Goal2 = GoalExpr2 - GoalInfo2,
- simplify__goal_2(GoalExpr2, GoalInfo2, Goal, GoalInfo3, Info4, Info5),
- simplify_info_maybe_clear_structs(after, Goal - GoalInfo3,
- Info5, Info6),
- simplify__enforce_invariant(GoalInfo3, GoalInfo, Info6, Info).
-
-:- pred simplify__enforce_invariant(hlds_goal_info, hlds_goal_info,
- simplify_info, simplify_info).
-:- mode simplify__enforce_invariant(in, out, in, out) is det.
+ simplify__goal_2(GoalExpr2, Goal, GoalInfo2, GoalInfo3, !Info),
+ simplify_info_maybe_clear_structs(after, Goal - GoalInfo3, !Info),
+ simplify__enforce_invariant(GoalInfo3, GoalInfo, !Info).
+
%
% Ensure that the mode information and the determinism
% information say consistent things about unreachability.
%
-simplify__enforce_invariant(GoalInfo0, GoalInfo, Info0, Info) :-
+:- pred simplify__enforce_invariant(hlds_goal_info::in, hlds_goal_info::out,
+ simplify_info::in, simplify_info::out) is det.
+
+simplify__enforce_invariant(GoalInfo0, GoalInfo, !Info) :-
goal_info_get_determinism(GoalInfo0, Determinism0),
goal_info_get_instmap_delta(GoalInfo0, DeltaInstmap0),
determinism_components(Determinism0, CanFail0, NumSolns0),
@@ -485,39 +480,37 @@
instmap_delta_init_unreachable(UnreachableInstMapDelta),
goal_info_set_instmap_delta(GoalInfo0, UnreachableInstMapDelta,
GoalInfo),
- simplify_info_set_rerun_det(Info0, Info)
+ simplify_info_set_rerun_det(!Info)
;
instmap_delta_is_unreachable(DeltaInstmap0),
NumSolns0 \= at_most_zero
->
determinism_components(Determinism, CanFail0, at_most_zero),
goal_info_set_determinism(GoalInfo0, Determinism, GoalInfo),
- simplify_info_set_rerun_det(Info0, Info)
+ simplify_info_set_rerun_det(!Info)
;
- GoalInfo = GoalInfo0,
- Info = Info0
+ GoalInfo = GoalInfo0
).
%-----------------------------------------------------------------------------%
-:- pred simplify__goal_2(hlds_goal_expr, hlds_goal_info, hlds_goal_expr,
- hlds_goal_info, simplify_info, simplify_info).
-:- mode simplify__goal_2(in, in, out, out, in, out) is det.
+:- pred simplify__goal_2(hlds_goal_expr::in, hlds_goal_expr::out,
+ hlds_goal_info::in, hlds_goal_info::out,
+ simplify_info::in, simplify_info::out) is det.
-simplify__goal_2(conj(Goals0), GoalInfo0, Goal, GoalInfo, Info0, Info) :-
- simplify_info_get_instmap(Info0, InstMap0),
+simplify__goal_2(conj(Goals0), Goal, GoalInfo0, GoalInfo, !Info) :-
+ simplify_info_get_instmap(!.Info, InstMap0),
simplify__excess_assigns_in_conj(GoalInfo0,
- Goals0, Goals1, Info0, Info1a),
- simplify__conj(Goals1, [], Goals, GoalInfo0, Info1a, Info1),
- simplify_info_set_instmap(Info1, InstMap0, Info2),
+ Goals0, Goals1, !Info),
+ simplify__conj(Goals1, [], Goals, GoalInfo0, !Info),
+ simplify_info_set_instmap(InstMap0, !Info),
( Goals = [] ->
goal_info_get_context(GoalInfo0, Context),
- true_goal(Context, Goal - GoalInfo),
- Info = Info2
+ true_goal(Context, Goal - GoalInfo)
; Goals = [SingleGoal - SingleGoalInfo] ->
% a singleton conjunction is equivalent to the goal itself
simplify__maybe_wrap_goal(GoalInfo0, SingleGoalInfo,
- SingleGoal, Goal, GoalInfo, Info2, Info)
+ SingleGoal, Goal, GoalInfo, !Info)
;
%
% Conjunctions that cannot produce solutions may nevertheless
@@ -525,10 +518,9 @@
% conjunction is put inside a `some' to appease the code
% generator.
%
- Info = Info2,
goal_info_get_determinism(GoalInfo0, Detism),
(
- simplify_do_once(Info),
+ simplify_do_once(!.Info),
determinism_components(Detism, CanFail, at_most_zero),
simplify__contains_multisoln_goal(Goals)
->
@@ -544,49 +536,44 @@
GoalInfo = GoalInfo0
).
-simplify__goal_2(par_conj(Goals0), GoalInfo0, Goal,
- GoalInfo, Info0, Info) :-
+simplify__goal_2(par_conj(Goals0), Goal, GoalInfo0, GoalInfo, !Info) :-
(
Goals0 = []
->
goal_info_get_context(GoalInfo0, Context),
- true_goal(Context, Goal - GoalInfo),
- Info = Info0
+ true_goal(Context, Goal - GoalInfo)
;
Goals0 = [SingleGoal0]
->
simplify__goal(SingleGoal0, SingleGoal - SingleGoalInfo,
- Info0, Info1),
+ !Info),
simplify__maybe_wrap_goal(GoalInfo0, SingleGoalInfo,
- SingleGoal, Goal, GoalInfo, Info1, Info)
+ SingleGoal, Goal, GoalInfo, !Info)
;
GoalInfo = GoalInfo0,
- simplify__par_conj(Goals0, Goals, Info0, Info0, Info),
+ simplify__par_conj(Goals0, Goals, !.Info, !Info),
Goal = par_conj(Goals)
).
-simplify__goal_2(disj(Disjuncts0), GoalInfo0,
- Goal, GoalInfo, Info0, Info) :-
- simplify_info_get_instmap(Info0, InstMap0),
- simplify__disj(Disjuncts0, [], Disjuncts, [], InstMaps,
- Info0, Info0, Info1),
+simplify__goal_2(disj(Disjuncts0), Goal, GoalInfo0, GoalInfo, !Info) :-
+ simplify_info_get_instmap(!.Info, InstMap0),
+ simplify__disj(Disjuncts0, [], Disjuncts, [], InstMaps, !.Info, !Info),
( Disjuncts = [] ->
goal_info_get_context(GoalInfo0, Context),
- fail_goal(Context, Goal - GoalInfo),
- Info2 = Info1
+ fail_goal(Context, Goal - GoalInfo)
; Disjuncts = [SingleGoal] ->
% a singleton disjunction is equivalent to the goal itself
SingleGoal = Goal1 - GoalInfo1,
simplify__maybe_wrap_goal(GoalInfo0, GoalInfo1,
- Goal1, Goal, GoalInfo, Info1, Info2)
+ Goal1, Goal, GoalInfo, !Info)
;
Goal = disj(Disjuncts),
- simplify_info_get_module_info(Info1, ModuleInfo1),
+ simplify_info_get_module_info(!.Info, ModuleInfo1),
goal_info_get_nonlocals(GoalInfo0, NonLocals),
- simplify_info_get_var_types(Info1, VarTypes),
+ simplify_info_get_var_types(!.Info, VarTypes),
merge_instmap_deltas(InstMap0, NonLocals, VarTypes, InstMaps,
NewDelta, ModuleInfo1, ModuleInfo2),
- simplify_info_set_module_info(Info1, ModuleInfo2, Info2),
+ simplify_info_set_module_info(ModuleInfo2, !Info),
goal_info_set_instmap_delta(GoalInfo0, NewDelta, GoalInfo)
),
(
@@ -604,16 +591,16 @@
% because the disjunction now cannot produce variables
% it did before.
%
- simplify_info_set_requantify(Info2, Info3),
- simplify_info_set_rerun_det(Info3, Info)
+ simplify_info_set_requantify(!Info),
+ simplify_info_set_rerun_det(!Info)
;
- Info = Info2
+ true
).
-simplify__goal_2(switch(Var, SwitchCanFail0, Cases0),
- GoalInfo0, Goal, GoalInfo, Info0, Info) :-
- simplify_info_get_instmap(Info0, InstMap0),
- simplify_info_get_module_info(Info0, ModuleInfo0),
+simplify__goal_2(switch(Var, SwitchCanFail0, Cases0), Goal,
+ GoalInfo0, GoalInfo, !Info) :-
+ simplify_info_get_instmap(!.Info, InstMap0),
+ simplify_info_get_module_info(!.Info, ModuleInfo0),
instmap__lookup_var(InstMap0, Var, VarInst),
( inst_is_bound_to_functors(ModuleInfo0, VarInst, Functors) ->
functors_to_cons_ids(Functors, ConsIds0),
@@ -625,11 +612,11 @@
MaybeConsIds = no
),
simplify__switch(Var, Cases1, [], Cases, [], InstMaps,
- SwitchCanFail0, SwitchCanFail, Info0, Info0, Info1),
+ SwitchCanFail0, SwitchCanFail, !.Info, !Info),
( Cases = [] ->
% An empty switch always fails.
pd_cost__eliminate_switch(CostDelta),
- simplify_info_incr_cost_delta(Info1, CostDelta, Info5),
+ simplify_info_incr_cost_delta(CostDelta, !Info),
goal_info_get_context(GoalInfo0, Context),
fail_goal(Context, Goal - GoalInfo)
; Cases = [case(ConsId, SingleGoal)] ->
@@ -648,25 +635,24 @@
% in the types of the constructor arguments
% or their type-infos.
%
- simplify_info_get_var_types(Info1, VarTypes1),
+ simplify_info_get_var_types(!.Info, VarTypes1),
map__lookup(VarTypes1, Var, Type),
- simplify_info_get_module_info(Info1, ModuleInfo1),
+ simplify_info_get_module_info(!.Info, ModuleInfo1),
(
type_util__is_existq_cons(ModuleInfo1,
Type, ConsId)
->
Goal = switch(Var, SwitchCanFail, Cases),
goal_info_get_nonlocals(GoalInfo0, NonLocals),
- simplify_info_get_var_types(Info1, VarTypes),
+ simplify_info_get_var_types(!.Info, VarTypes),
merge_instmap_deltas(InstMap0, NonLocals, VarTypes,
InstMaps, NewDelta, ModuleInfo1, ModuleInfo2),
- simplify_info_set_module_info(Info1,
- ModuleInfo2, Info4),
+ simplify_info_set_module_info(ModuleInfo2, !Info),
goal_info_set_instmap_delta(GoalInfo0,
NewDelta, GoalInfo)
;
simplify__create_test_unification(Var, ConsId, Arity,
- UnifyGoal, Info1, Info2),
+ UnifyGoal, !Info),
% Conjoin the test and the rest of the case.
goal_to_conj_list(SingleGoal, SingleGoalConj),
@@ -677,38 +663,36 @@
goal_info_get_nonlocals(GoalInfo0, NonLocals0),
set__insert(NonLocals0, Var, NonLocals),
goal_info_get_instmap_delta(GoalInfo0, InstMapDelta0),
- simplify_info_get_instmap(Info2, InstMap),
+ simplify_info_get_instmap(!.Info, InstMap),
instmap_delta_bind_var_to_functor(Var, Type, ConsId,
InstMap, InstMapDelta0, InstMapDelta,
ModuleInfo1, ModuleInfo),
- simplify_info_set_module_info(Info2,
- ModuleInfo, Info3),
+ simplify_info_set_module_info(ModuleInfo, !Info),
goal_info_get_determinism(GoalInfo0, CaseDetism),
det_conjunction_detism(semidet, CaseDetism, Detism),
goal_list_purity(GoalList, Purity),
goal_info_init(NonLocals, InstMapDelta, Detism, Purity,
CombinedGoalInfo),
- simplify_info_set_requantify(Info3, Info4),
+ simplify_info_set_requantify(!Info),
Goal = conj(GoalList),
GoalInfo = CombinedGoalInfo
)
;
% The var can only be bound to this cons_id, so
% a test is unnecessary.
- SingleGoal = Goal - GoalInfo,
- Info4 = Info1
+ SingleGoal = Goal - GoalInfo
),
pd_cost__eliminate_switch(CostDelta),
- simplify_info_incr_cost_delta(Info4, CostDelta, Info5)
+ simplify_info_incr_cost_delta(CostDelta, !Info)
;
Goal = switch(Var, SwitchCanFail, Cases),
- simplify_info_get_module_info(Info1, ModuleInfo1),
+ simplify_info_get_module_info(!.Info, ModuleInfo1),
goal_info_get_nonlocals(GoalInfo0, NonLocals),
- simplify_info_get_var_types(Info1, VarTypes),
+ simplify_info_get_var_types(!.Info, VarTypes),
merge_instmap_deltas(InstMap0, NonLocals, VarTypes, InstMaps,
NewDelta, ModuleInfo1, ModuleInfo2),
- simplify_info_set_module_info(Info1, ModuleInfo2, Info5),
+ simplify_info_set_module_info(ModuleInfo2, !Info),
goal_info_set_instmap_delta(GoalInfo0, NewDelta, GoalInfo)
),
( list__length(Cases) \= list__length(Cases0) `with_type` int ->
@@ -723,16 +707,16 @@
% because the switch now cannot produce variables it
% did before.
%
- simplify_info_set_requantify(Info5, Info6),
- simplify_info_set_rerun_det(Info6, Info)
+ simplify_info_set_requantify(!Info),
+ simplify_info_set_rerun_det(!Info)
;
- Info = Info5
+ true
).
-simplify__goal_2(Goal0, GoalInfo, Goal, GoalInfo, Info0, Info) :-
+simplify__goal_2(Goal0, Goal, GoalInfo, GoalInfo, !Info) :-
Goal0 = generic_call(GenericCall, Args, Modes, Det),
(
- simplify_do_calls(Info0),
+ simplify_do_calls(!.Info),
% XXX We should do duplicate call elimination for
% class method calls here.
GenericCall = higher_order(Closure, Purity, _, _),
@@ -740,9 +724,9 @@
Purity = (pure)
->
common__optimise_higher_order_call(Closure, Args, Modes, Det,
- Goal0, GoalInfo, Goal, Info0, Info)
+ GoalInfo, Goal0, Goal, !Info)
;
- simplify_do_warn_calls(Info0),
+ simplify_do_warn_calls(!.Info),
GenericCall = higher_order(Closure, Purity, _, _),
% XXX Should we handle impure/semipure higher-order calls too?
Purity = (pure)
@@ -750,16 +734,15 @@
% We need to do the pass, for the warnings, but we ignore
% the optimized goal and instead use the original one.
common__optimise_higher_order_call(Closure, Args, Modes, Det,
- Goal0, GoalInfo, _Goal1, Info0, Info),
+ GoalInfo, Goal0, _Goal1, !Info),
Goal = Goal0
;
- Goal = Goal0,
- Info = Info0
+ Goal = Goal0
).
-simplify__goal_2(Goal0, GoalInfo0, Goal, GoalInfo, Info0, Info) :-
+simplify__goal_2(Goal0, Goal, GoalInfo0, GoalInfo, !Info) :-
Goal0 = call(PredId, ProcId, Args, IsBuiltin, _, _),
- simplify_info_get_module_info(Info0, ModuleInfo),
+ simplify_info_get_module_info(!.Info, ModuleInfo),
module_info_pred_info(ModuleInfo, PredId, PredInfo),
%
% Convert calls to builtin @=<, @<, @>=, @> into the corresponding
@@ -777,13 +760,13 @@
)
->
simplify__inequality_goal(TI, X, Y, Inequality, Invert,
- GoalInfo0, Goal, GoalInfo, Info0, Info)
+ GoalInfo0, Goal, GoalInfo, !Info)
;
simplify__call_goal(PredId, ProcId, Args, IsBuiltin,
- Goal0, GoalInfo0, Goal, GoalInfo, Info0, Info)
+ Goal0, Goal, GoalInfo0, GoalInfo, !Info)
).
-simplify__goal_2(Goal0, GoalInfo0, Goal, GoalInfo, Info0, Info) :-
+simplify__goal_2(Goal0, Goal, GoalInfo0, GoalInfo, !Info) :-
Goal0 = unify(LT0, RT0, M, U0, C),
(
% A unification of the form X = X can safely be
@@ -792,33 +775,32 @@
RT0 = var(LT0)
->
goal_info_get_context(GoalInfo0, Context),
- true_goal(Context, Goal - GoalInfo),
- Info = Info0
+ true_goal(Context, Goal - GoalInfo)
;
RT0 = lambda_goal(Purity, PredOrFunc, EvalMethod, FixModes,
NonLocals, Vars, Modes, LambdaDeclaredDet, LambdaGoal0)
->
- simplify_info_enter_lambda(Info0, Info1),
- simplify_info_get_common_info(Info1, Common1),
- simplify_info_get_module_info(Info1, ModuleInfo),
- simplify_info_get_instmap(Info1, InstMap1),
+ simplify_info_enter_lambda(!Info),
+ simplify_info_get_common_info(!.Info, Common1),
+ simplify_info_get_module_info(!.Info, ModuleInfo),
+ simplify_info_get_instmap(!.Info, InstMap1),
instmap__pre_lambda_update(ModuleInfo, Vars, Modes,
InstMap1, InstMap2),
- simplify_info_set_instmap(Info1, InstMap2, Info2),
+ simplify_info_set_instmap(InstMap2, !Info),
% Don't attempt to pass structs into lambda_goals,
% since that could change the curried non-locals of the
% lambda_goal, and that would be difficult to fix up.
common_info_init(Common2),
- simplify_info_set_common_info(Info2, Common2, Info3),
+ simplify_info_set_common_info(Common2, !Info),
% Don't attempt to pass structs out of lambda_goals.
- simplify__goal(LambdaGoal0, LambdaGoal, Info3, Info4),
- simplify_info_set_common_info(Info4, Common1, Info5),
- simplify_info_set_instmap(Info5, InstMap1, Info6),
+ simplify__goal(LambdaGoal0, LambdaGoal, !Info),
+ simplify_info_set_common_info(Common1, !Info),
+ simplify_info_set_instmap(InstMap1, !Info),
RT = lambda_goal(Purity, PredOrFunc, EvalMethod, FixModes,
NonLocals, Vars, Modes, LambdaDeclaredDet, LambdaGoal),
- simplify_info_leave_lambda(Info6, Info),
+ simplify_info_leave_lambda(!Info),
Goal = unify(LT0, RT, M, U0, C),
GoalInfo = GoalInfo0
;
@@ -827,20 +809,19 @@
( RT0 = var(V) ->
simplify__process_compl_unify(LT0, V,
UniMode, CanFail, TypeInfoVars,
- C, GoalInfo0, Goal1,
- Info0, Info),
+ C, GoalInfo0, Goal1, !Info),
Goal1 = Goal - GoalInfo
;
error("simplify.m: invalid RHS for complicated unify")
)
;
- simplify_do_common(Info0)
+ simplify_do_common(!.Info)
->
common__optimise_unification(U0, LT0, RT0, M, C,
- Goal0, GoalInfo0, Goal, GoalInfo, Info0, Info)
+ Goal0, Goal, GoalInfo0, GoalInfo, !Info)
;
- ( simplify_do_calls(Info0)
- ; simplify_do_warn_calls(Info0)
+ ( simplify_do_calls(!.Info)
+ ; simplify_do_warn_calls(!.Info)
)
->
% We need to do the pass, to record the variable
@@ -849,13 +830,12 @@
% the optimization, so we disregard the optimized goal
% and instead use the original one.
common__optimise_unification(U0, LT0, RT0, M, C,
- Goal0, GoalInfo0, _Goal1, _GoalInfo1, Info0, Info),
+ Goal0, _Goal1, GoalInfo0, _GoalInfo1, !Info),
Goal = Goal0,
GoalInfo = GoalInfo0
;
Goal = Goal0,
- GoalInfo = GoalInfo0,
- Info = Info0
+ GoalInfo = GoalInfo0
).
% (A -> B ; C) is logically equivalent to (A, B ; ~A, C).
@@ -883,8 +863,8 @@
% conjunction construct. This will change when constraint pushing
% is finished, or when we start doing coroutining.
-simplify__goal_2(if_then_else(Vars, Cond0, Then0, Else0),
- GoalInfo0, Goal, GoalInfo, Info0, Info) :-
+simplify__goal_2(if_then_else(Vars, Cond0, Then0, Else0), Goal,
+ GoalInfo0, GoalInfo, !Info) :-
Cond0 = _ - CondInfo0,
goal_info_get_determinism(CondInfo0, CondDetism0),
determinism_components(CondDetism0, CondCanFail0, CondSolns0),
@@ -893,12 +873,11 @@
goal_to_conj_list(Then0, ThenList),
list__append(CondList, ThenList, List),
simplify__goal(conj(List) - GoalInfo0, Goal - GoalInfo,
- Info0, Info1),
+ !Info),
goal_info_get_context(GoalInfo0, Context),
- simplify_info_add_msg(Info1, ite_cond_cannot_fail(Context),
- Info2),
- simplify_info_set_requantify(Info2, Info3),
- simplify_info_set_rerun_det(Info3, Info)
+ simplify_info_add_msg(ite_cond_cannot_fail(Context), !Info),
+ simplify_info_set_requantify(!Info),
+ simplify_info_set_rerun_det(!Info)
; CondSolns0 = at_most_zero ->
% Optimize away the condition and the `then' part.
det_negation_det(CondDetism0, MaybeNegDetism),
@@ -928,7 +907,8 @@
NegDetism = NegDetism1,
NegInstMapDelta = NegInstMapDelta1
;
- error("simplify__goal_2: cannot get negated determinism")
+ error("simplify__goal_2: " ++
+ "cannot get negated determinism")
),
goal_info_set_determinism(CondInfo0,
NegDetism, NegCondInfo0),
@@ -939,33 +919,34 @@
goal_to_conj_list(Else0, ElseList),
List = [Cond | ElseList],
simplify__goal(conj(List) - GoalInfo0, Goal - GoalInfo,
- Info0, Info1),
+ !Info),
goal_info_get_context(GoalInfo0, Context),
- simplify_info_add_msg(Info1, ite_cond_cannot_succeed(Context),
- Info2),
- simplify_info_set_requantify(Info2, Info3),
- simplify_info_set_rerun_det(Info3, Info)
+ simplify_info_add_msg(ite_cond_cannot_succeed(Context),
+ !Info),
+ simplify_info_set_requantify(!Info),
+ simplify_info_set_rerun_det(!Info)
; Else0 = disj([]) - _ ->
% (A -> C ; fail) is equivalent to (A, C)
goal_to_conj_list(Cond0, CondList),
goal_to_conj_list(Then0, ThenList),
list__append(CondList, ThenList, List),
simplify__goal(conj(List) - GoalInfo0, Goal - GoalInfo,
- Info0, Info1),
- simplify_info_set_requantify(Info1, Info2),
- simplify_info_set_rerun_det(Info2, Info)
+ !Info),
+ simplify_info_set_requantify(!Info),
+ simplify_info_set_rerun_det(!Info)
;
%
% recursively simplify the sub-goals,
% and rebuild the resulting if-then-else
%
- simplify_info_get_instmap(Info0, InstMap0),
- simplify__goal(Cond0, Cond, Info0, Info1),
- simplify_info_update_instmap(Info1, Cond, Info2),
- simplify__goal(Then0, Then, Info2, Info3),
- simplify_info_post_branch_update(Info0, Info3, Info4),
- simplify__goal(Else0, Else, Info4, Info5),
- simplify_info_post_branch_update(Info0, Info5, Info6),
+ Info0 = !.Info,
+ simplify_info_get_instmap(!.Info, InstMap0),
+ simplify__goal(Cond0, Cond, !Info),
+ simplify_info_update_instmap(Cond, !Info),
+ simplify__goal(Then0, Then, !Info),
+ simplify_info_post_branch_update(Info0, !Info),
+ simplify__goal(Else0, Else, !Info),
+ simplify_info_post_branch_update(Info0, !Info),
Cond = _ - CondInfo,
goal_info_get_instmap_delta(CondInfo, CondDelta),
Then = _ - ThenInfo,
@@ -975,12 +956,12 @@
Else = _ - ElseInfo,
goal_info_get_instmap_delta(ElseInfo, ElseDelta),
goal_info_get_nonlocals(GoalInfo0, NonLocals),
- simplify_info_get_module_info(Info6, ModuleInfo0),
- simplify_info_get_var_types(Info6, VarTypes),
+ simplify_info_get_module_info(!.Info, ModuleInfo0),
+ simplify_info_get_var_types(!.Info, VarTypes),
merge_instmap_deltas(InstMap0, NonLocals, VarTypes,
[CondThenDelta, ElseDelta], NewDelta,
ModuleInfo0, ModuleInfo1),
- simplify_info_set_module_info(Info6, ModuleInfo1, Info7),
+ simplify_info_set_module_info(ModuleInfo1, !Info),
goal_info_set_instmap_delta(GoalInfo0, NewDelta, GoalInfo1),
IfThenElse = if_then_else(Vars, Cond, Then, Else),
@@ -1003,9 +984,9 @@
; Else = disj([]) - _
)
->
- simplify_info_undo_goal_updates(Info0, Info7, Info8),
- simplify__goal_2(IfThenElse, GoalInfo1,
- Goal, GoalInfo, Info8, Info)
+ simplify_info_undo_goal_updates(Info0, !Info),
+ simplify__goal_2(IfThenElse, Goal, GoalInfo1, GoalInfo,
+ !Info)
;
(
%
@@ -1016,7 +997,7 @@
% code generator. (Both the MLDS and LLDS
% back-ends rely on this.)
%
- simplify_do_once(Info),
+ simplify_do_once(!.Info),
CondSolns = at_most_many,
IfThenElseNumSolns \= at_most_many
->
@@ -1029,42 +1010,38 @@
;
Goal = IfThenElse
),
- GoalInfo = GoalInfo1,
- Info = Info7
+ GoalInfo = GoalInfo1
)
).
-simplify__goal_2(not(Goal0), GoalInfo0, Goal, GoalInfo, Info0, Info) :-
+simplify__goal_2(not(Goal0), Goal, GoalInfo0, GoalInfo, !Info) :-
% Can't use calls or unifications seen within a negation,
% since non-local variables may not be bound within the negation.
- simplify_info_get_common_info(Info0, Common),
- simplify__goal(Goal0, Goal1, Info0, Info1),
- simplify_info_set_common_info(Info1, Common, Info2),
+ simplify_info_get_common_info(!.Info, Common),
+ simplify__goal(Goal0, Goal1, !Info),
+ simplify_info_set_common_info(Common, !Info),
Goal1 = _ - GoalInfo1,
goal_info_get_determinism(GoalInfo1, Detism),
determinism_components(Detism, CanFail, MaxSoln),
goal_info_get_context(GoalInfo0, Context),
( CanFail = cannot_fail ->
- simplify_info_add_msg(Info2,
- negated_goal_cannot_fail(Context), Info3)
+ simplify_info_add_msg(negated_goal_cannot_fail(Context), !Info)
; MaxSoln = at_most_zero ->
- simplify_info_add_msg(Info2,
- negated_goal_cannot_succeed(Context), Info3)
+ simplify_info_add_msg(negated_goal_cannot_succeed(Context),
+ !Info)
;
- Info3 = Info2
+ true
),
(
% replace `not true' with `fail'
Goal1 = conj([]) - _GoalInfo
->
- fail_goal(Context, Goal - GoalInfo),
- Info = Info3
+ fail_goal(Context, Goal - GoalInfo)
;
% replace `not fail' with `true'
Goal1 = disj([]) - _GoalInfo2
->
- true_goal(Context, Goal - GoalInfo),
- Info = Info3
+ true_goal(Context, Goal - GoalInfo)
;
% remove double negation
Goal1 = not(SubGoal - SubGoalInfo) - _,
@@ -1075,17 +1052,16 @@
semidet_fail
->
simplify__maybe_wrap_goal(GoalInfo0, SubGoalInfo, SubGoal,
- Goal, GoalInfo, Info3, Info)
+ Goal, GoalInfo, !Info)
;
Goal = not(Goal1),
- GoalInfo = GoalInfo0,
- Info = Info3
+ GoalInfo = GoalInfo0
).
-simplify__goal_2(some(Vars1, CanRemove0, Goal1), SomeInfo,
- GoalExpr, GoalInfo, Info0, Info) :-
- simplify_info_get_common_info(Info0, Common),
- simplify__goal(Goal1, Goal2, Info0, Info1),
+simplify__goal_2(some(Vars1, CanRemove0, Goal1), GoalExpr, SomeInfo, GoalInfo,
+ !Info) :-
+ simplify_info_get_common_info(!.Info, Common),
+ simplify__goal(Goal1, Goal2, !Info),
simplify__nested_somes(CanRemove0, Vars1, Goal2, SomeInfo, Goal),
Goal = GoalExpr - GoalInfo,
( Goal = some(_, _, _) - _ ->
@@ -1099,51 +1075,48 @@
% was before processing the goal inside the commit,
% to ensure that we don't make any such replacements
% when processing the rest of the goal.
- simplify_info_set_common_info(Info1, Common, Info)
+ simplify_info_set_common_info(Common, !Info)
;
- Info = Info1
+ true
).
-simplify__goal_2(Goal0, GoalInfo, Goal, GoalInfo, Info0, Info) :-
+simplify__goal_2(Goal0, Goal, GoalInfo, GoalInfo, !Info) :-
Goal0 = foreign_proc(_, PredId, ProcId, Args, _, _, _),
(
- simplify_do_calls(Info0),
+ simplify_do_calls(!.Info),
goal_info_is_pure(GoalInfo)
->
- common__optimise_call(PredId, ProcId, Args, Goal0,
- GoalInfo, Goal, Info0, Info)
+ common__optimise_call(PredId, ProcId, Args, GoalInfo,
+ Goal0, Goal, !Info)
;
- Info = Info0,
Goal = Goal0
).
-simplify__goal_2(shorthand(_), _, _, _, _, _) :-
+simplify__goal_2(shorthand(_), _, _, _, !Info) :-
% these should have been expanded out by now
error("simplify__goal_2: unexpected shorthand").
%-----------------------------------------------------------------------------%
-:- pred simplify__inequality_goal(
- prog_var, prog_var, prog_var, string, bool, hlds_goal_info,
- hlds_goal_expr, hlds_goal_info, simplify_info, simplify_info).
-:- mode simplify__inequality_goal(
- in, in, in, in, in, in,
- out, out, in, out) is det.
+:- pred simplify__inequality_goal(prog_var::in, prog_var::in, prog_var::in,
+ string::in, bool::in, hlds_goal_info::in,
+ hlds_goal_expr::out, hlds_goal_info::out,
+ simplify_info::in, simplify_info::out) is det.
simplify__inequality_goal(TI, X, Y, Inequality, Invert,
- GoalInfo, GoalExpr, GoalInfo, Info0, Info) :-
+ GoalInfo, GoalExpr, GoalInfo, !Info) :-
% Construct the variable to hold the comparison result.
%
- VarSet0 = Info0 ^ varset,
+ VarSet0 = !.Info ^ varset,
varset__new_var(VarSet0, R, VarSet),
- Info1 = Info0 ^ varset := VarSet,
+ !:Info = !.Info ^ varset := VarSet,
% We have to add the type of R to the var_types.
%
- simplify_info_get_var_types(Info1, VarTypes0),
+ simplify_info_get_var_types(!.Info, VarTypes0),
VarTypes = VarTypes0 ^ elem(R) := comparison_result_type,
- simplify_info_set_var_types(Info1, VarTypes, Info),
+ simplify_info_set_var_types(VarTypes, !Info),
% Construct the call to compare/3.
%
@@ -1151,10 +1124,10 @@
hlds_goal__goal_info_get_context(GoalInfo, Context),
Args = [TI, R, X, Y],
- simplify_info_get_instmap(Info, InstMap),
+ simplify_info_get_instmap(!.Info, InstMap),
instmap__lookup_var(InstMap, X, XInst),
instmap__lookup_var(InstMap, Y, YInst),
- simplify_info_get_module_info(Info1, ModuleInfo),
+ simplify_info_get_module_info(!.Info, ModuleInfo),
ModeNo = ( if inst_is_unique(ModuleInfo, XInst) then
( if inst_is_unique(ModuleInfo, YInst) then 1
else 2 )
@@ -1199,22 +1172,21 @@
%-----------------------------------------------------------------------------%
-:- pred simplify__call_goal(
- pred_id, proc_id, list(prog_var), builtin_state,
- hlds_goal_expr, hlds_goal_info, hlds_goal_expr, hlds_goal_info,
- simplify_info, simplify_info).
-:- mode simplify__call_goal(in, in, in, in, in, in, out, out, in, out) is det.
-
-simplify__call_goal(PredId, ProcId, Args, IsBuiltin,
- Goal0, GoalInfo0, Goal, GoalInfo, Info0, Info) :-
- simplify_info_get_module_info(Info0, ModuleInfo),
+:- pred simplify__call_goal(pred_id::in, proc_id::in, list(prog_var)::in,
+ builtin_state::in, hlds_goal_expr::in, hlds_goal_expr::out,
+ hlds_goal_info::in, hlds_goal_info::out,
+ simplify_info::in, simplify_info::out) is det.
+
+simplify__call_goal(PredId, ProcId, Args, IsBuiltin, Goal0, Goal,
+ GoalInfo0, GoalInfo, !Info) :-
+ simplify_info_get_module_info(!.Info, ModuleInfo),
module_info_pred_proc_info(ModuleInfo, PredId, ProcId,
PredInfo, ProcInfo),
%
% check for calls to predicates with `pragma obsolete' declarations
%
(
- simplify_do_warn(Info0),
+ simplify_do_warn(!.Info),
pred_info_get_markers(PredInfo, Markers),
check_marker(Markers, obsolete),
%
@@ -1223,16 +1195,16 @@
% with builtin predicates, or preds defined using
% pragma foreign.)
%
- simplify_info_get_det_info(Info0, DetInfo0),
+ simplify_info_get_det_info(!.Info, DetInfo0),
det_info_get_pred_id(DetInfo0, ThisPredId),
PredId \= ThisPredId
->
goal_info_get_context(GoalInfo0, Context1),
- simplify_info_add_msg(Info0, warn_obsolete(PredId, Context1),
- Info1)
+ simplify_info_add_msg(warn_obsolete(PredId, Context1),
+ !Info)
;
- Info1 = Info0
+ true
),
%
@@ -1240,14 +1212,14 @@
% and warn about them (since they will lead to infinite loops).
%
(
- simplify_do_warn(Info1),
+ simplify_do_warn(!.Info),
%
% Is this a (directly) recursive call,
% i.e. is the procedure being called the same as the
% procedure we're analyzing?
%
- simplify_info_get_det_info(Info1, DetInfo),
+ simplify_info_get_det_info(!.Info, DetInfo),
det_info_get_pred_id(DetInfo, PredId),
det_info_get_proc_id(DetInfo, ProcId),
@@ -1264,17 +1236,17 @@
% Don't warn if we're inside a lambda goal, because the
% recursive call may not be executed.
%
- \+ simplify_info_inside_lambda(Info1),
+ \+ simplify_info_inside_lambda(!.Info),
%
% Are the input arguments the same (or equivalent)?
%
- simplify_info_get_module_info(Info1, ModuleInfo1),
+ simplify_info_get_module_info(!.Info, ModuleInfo1),
module_info_pred_proc_info(ModuleInfo1, PredId, ProcId,
PredInfo1, ProcInfo1),
proc_info_headvars(ProcInfo1, HeadVars),
proc_info_argmodes(ProcInfo1, ArgModes),
- simplify_info_get_common_info(Info1, CommonInfo1),
+ simplify_info_get_common_info(!.Info, CommonInfo1),
simplify__input_args_are_equiv(Args, HeadVars, ArgModes,
CommonInfo1, ModuleInfo1),
@@ -1312,43 +1284,41 @@
\+ hlds_pred__pred_info_is_aditi_relation(PredInfo1)
->
goal_info_get_context(GoalInfo0, Context2),
- simplify_info_add_msg(Info1, warn_infinite_recursion(Context2),
- Info2)
+ simplify_info_add_msg(warn_infinite_recursion(Context2), !Info)
;
- Info2 = Info1
+ true
),
%
% check for duplicate calls to the same procedure
%
(
- simplify_do_calls(Info2),
+ simplify_do_calls(!.Info),
goal_info_is_pure(GoalInfo0)
->
- common__optimise_call(PredId, ProcId, Args, Goal0, GoalInfo0,
- Goal1, Info2, Info3)
+ common__optimise_call(PredId, ProcId, Args, GoalInfo0,
+ Goal0, Goal1, !Info)
;
- simplify_do_warn_calls(Info0),
+ simplify_do_warn_calls(!.Info),
goal_info_is_pure(GoalInfo0)
->
% we need to do the pass, for the warnings, but we ignore
% the optimized goal and instead use the original one
- common__optimise_call(PredId, ProcId, Args, Goal0, GoalInfo0,
- _Goal1, Info2, Info3),
+ common__optimise_call(PredId, ProcId, Args, GoalInfo0,
+ Goal0, _Goal1, !Info),
Goal1 = Goal0
;
- Goal1 = Goal0,
- Info3 = Info2
+ Goal1 = Goal0
),
%
% Try to evaluate the call at compile-time.
%
- ( simplify_do_const_prop(Info3) ->
- simplify_info_get_instmap(Info3, Instmap0),
- simplify_info_get_module_info(Info3, ModuleInfo2),
- simplify_info_get_var_types(Info3, VarTypes),
+ ( simplify_do_const_prop(!.Info) ->
+ simplify_info_get_instmap(!.Info, Instmap0),
+ simplify_info_get_module_info(!.Info, ModuleInfo2),
+ simplify_info_get_var_types(!.Info, VarTypes),
(
Goal1 = call(_, _, _, _, _, _),
const_prop.evaluate_call(PredId, ProcId, Args,
@@ -1357,35 +1327,30 @@
->
Goal = Goal2,
GoalInfo = GoalInfo2,
- simplify_info_set_module_info(Info3, ModuleInfo2,
- Info4),
- simplify_info_set_requantify(Info4, Info)
+ simplify_info_set_module_info(ModuleInfo2, !Info),
+ simplify_info_set_requantify(!Info)
;
Goal = Goal1,
- GoalInfo = GoalInfo0,
- Info = Info3
+ GoalInfo = GoalInfo0
)
;
Goal = Goal1,
- GoalInfo = GoalInfo0,
- Info = Info3
+ GoalInfo = GoalInfo0
).
%-----------------------------------------------------------------------------%
-:- pred simplify__process_compl_unify(prog_var, prog_var,
- uni_mode, can_fail, list(prog_var), unify_context,
- hlds_goal_info, hlds_goal, simplify_info, simplify_info).
-:- mode simplify__process_compl_unify(in, in, in, in, in, in, in, out,
- in, out) is det.
+:- pred simplify__process_compl_unify(prog_var::in, prog_var::in,
+ uni_mode::in, can_fail::in, list(prog_var)::in, unify_context::in,
+ hlds_goal_info::in, hlds_goal::out,
+ simplify_info::in, simplify_info::out) is det.
simplify__process_compl_unify(XVar, YVar, UniMode, CanFail, _OldTypeInfoVars,
- Context, GoalInfo0, Goal) -->
- =(Info0),
- { simplify_info_get_module_info(Info0, ModuleInfo) },
- { simplify_info_get_var_types(Info0, VarTypes) },
- { map__lookup(VarTypes, XVar, Type) },
- ( { Type = term__variable(TypeVar) } ->
+ Context, GoalInfo0, Goal, !Info) :-
+ simplify_info_get_module_info(!.Info, ModuleInfo),
+ simplify_info_get_var_types(!.Info, VarTypes),
+ map__lookup(VarTypes, XVar, Type),
+ ( Type = term__variable(TypeVar) ->
%
% Convert polymorphic unifications into calls to
% `unify/2', the general unification predicate, passing
@@ -1395,40 +1360,40 @@
% associated with the type of the variables that
% are being unified.
%
- simplify__type_info_locn(TypeVar, TypeInfoVar, ExtraGoals),
- =(Info),
- { simplify__call_generic_unify(TypeInfoVar, XVar, YVar,
- ModuleInfo, Info, Context, GoalInfo0, Call) }
+ simplify__type_info_locn(TypeVar, TypeInfoVar, ExtraGoals,
+ !Info),
+ simplify__call_generic_unify(TypeInfoVar, XVar, YVar,
+ ModuleInfo, !.Info, Context, GoalInfo0, Call)
- ; { type_is_higher_order(Type, _, _, _, _) } ->
+ ; type_is_higher_order(Type, _, _, _, _) ->
%
% convert higher-order unifications into calls to
% builtin_unify_pred (which calls error/1)
%
- { goal_info_get_context(GoalInfo0, GContext) },
- { generate_simple_call(mercury_private_builtin_module,
+ goal_info_get_context(GoalInfo0, GContext),
+ generate_simple_call(mercury_private_builtin_module,
"builtin_unify_pred", predicate, [XVar, YVar],
mode_no(0), semidet, no, [], ModuleInfo,
- GContext, Call0 - _) },
- simplify__goal_2(Call0, GoalInfo0, Call1, GoalInfo),
- { Call = Call1 - GoalInfo },
- { ExtraGoals = [] }
+ GContext, Call0 - _),
+ simplify__goal_2(Call0, Call1, GoalInfo0, GoalInfo, !Info),
+ Call = Call1 - GoalInfo,
+ ExtraGoals = []
;
- { type_to_ctor_and_args(Type, TypeCtorPrime, TypeArgsPrime) ->
+ ( type_to_ctor_and_args(Type, TypeCtorPrime, TypeArgsPrime) ->
TypeCtor = TypeCtorPrime,
TypeArgs = TypeArgsPrime
;
error("simplify: type_to_ctor_and_args failed")
- },
- { determinism_components(Det, CanFail, at_most_one) },
- { unify_proc__lookup_mode_num(ModuleInfo, TypeCtor, UniMode,
- Det, ProcId) },
- { module_info_globals(ModuleInfo, Globals) },
- { globals__lookup_bool_option(Globals, special_preds,
- SpecialPreds) },
+ ),
+ determinism_components(Det, CanFail, at_most_one),
+ unify_proc__lookup_mode_num(ModuleInfo, TypeCtor, UniMode,
+ Det, ProcId),
+ module_info_globals(ModuleInfo, Globals),
+ globals__lookup_bool_option(Globals, special_preds,
+ SpecialPreds),
+ (
+ hlds_pred__in_in_unification_proc_id(ProcId),
(
- { hlds_pred__in_in_unification_proc_id(ProcId) },
- {
SpecialPreds = no
;
SpecialPreds = yes,
@@ -1443,18 +1408,19 @@
%
special_pred_is_generated_lazily(ModuleInfo,
TypeCtor)
- }
+ )
->
simplify__make_type_info_vars([Type], TypeInfoVars,
- ExtraGoals),
- { TypeInfoVars = [TypeInfoVarPrime] ->
+ ExtraGoals, !Info),
+ ( TypeInfoVars = [TypeInfoVarPrime] ->
TypeInfoVar = TypeInfoVarPrime
;
- error("simplify__process_compl_unify: more than one typeinfo for one type var")
- },
- =(Info),
- { simplify__call_generic_unify(TypeInfoVar, XVar, YVar,
- ModuleInfo, Info, Context, GoalInfo0, Call) }
+ error("simplify__process_compl_unify: " ++
+ "more than one typeinfo " ++
+ "for one type var")
+ ),
+ simplify__call_generic_unify(TypeInfoVar, XVar, YVar,
+ ModuleInfo, !.Info, Context, GoalInfo0, Call)
;
%
% Convert other complicated unifications into
@@ -1463,17 +1429,17 @@
%
simplify__make_type_info_vars(TypeArgs,
- TypeInfoVars, ExtraGoals),
- { simplify__call_specific_unify(TypeCtor, TypeInfoVars,
+ TypeInfoVars, ExtraGoals, !Info),
+ simplify__call_specific_unify(TypeCtor, TypeInfoVars,
XVar, YVar, ProcId, ModuleInfo, Context,
- GoalInfo0, Call0, CallGoalInfo0) },
- simplify__goal_2(Call0, CallGoalInfo0,
- Call1, CallGoalInfo1),
- { Call = Call1 - CallGoalInfo1 }
+ GoalInfo0, Call0, CallGoalInfo0),
+ simplify__goal_2(Call0, Call1,
+ CallGoalInfo0, CallGoalInfo1, !Info),
+ Call = Call1 - CallGoalInfo1
)
),
- { list__append(ExtraGoals, [Call], ConjList) },
- { conj_list_to_goal(ConjList, GoalInfo0, Goal) }.
+ list__append(ExtraGoals, [Call], ConjList),
+ conj_list_to_goal(ConjList, GoalInfo0, Goal).
:- pred simplify__call_generic_unify(prog_var::in, prog_var::in, prog_var::in,
module_info::in, simplify_info::in, unify_context::in,
@@ -1514,14 +1480,13 @@
:- pred simplify__make_type_info_vars(list(type)::in, list(prog_var)::out,
list(hlds_goal)::out, simplify_info::in, simplify_info::out) is det.
-simplify__make_type_info_vars(Types, TypeInfoVars, TypeInfoGoals,
- Info0, Info) :-
+simplify__make_type_info_vars(Types, TypeInfoVars, TypeInfoGoals, !Info) :-
%
% Extract the information from simplify_info
%
- simplify_info_get_det_info(Info0, DetInfo0),
- simplify_info_get_varset(Info0, VarSet0),
- simplify_info_get_var_types(Info0, VarTypes0),
+ simplify_info_get_det_info(!.Info, DetInfo0),
+ simplify_info_get_varset(!.Info, VarSet0),
+ simplify_info_get_var_types(!.Info, VarTypes0),
det_info_get_module_info(DetInfo0, ModuleInfo0),
det_info_get_pred_id(DetInfo0, PredId),
det_info_get_proc_id(DetInfo0, ProcId),
@@ -1551,8 +1516,8 @@
%
proc_info_vartypes(ProcInfo, VarTypes),
proc_info_varset(ProcInfo, VarSet),
- simplify_info_set_var_types(Info0, VarTypes, Info1),
- simplify_info_set_varset(Info1, VarSet, Info2),
+ simplify_info_set_var_types(VarTypes, !Info),
+ simplify_info_set_varset(VarSet, !Info),
%
% Put the new proc_info and pred_info back
@@ -1561,46 +1526,44 @@
%
module_info_set_pred_proc_info(PredId, ProcId, PredInfo, ProcInfo,
ModuleInfo1, ModuleInfo),
- simplify_info_set_module_info(Info2, ModuleInfo, Info).
+ simplify_info_set_module_info(ModuleInfo, !Info).
-:- pred simplify__type_info_locn(tvar, prog_var, list(hlds_goal),
- simplify_info, simplify_info).
-:- mode simplify__type_info_locn(in, out, out, in, out) is det.
-
-simplify__type_info_locn(TypeVar, TypeInfoVar, Goals) -->
- =(Info0),
- { simplify_info_get_type_info_varmap(Info0, TypeInfoMap) },
- { map__lookup(TypeInfoMap, TypeVar, TypeInfoLocn) },
+:- pred simplify__type_info_locn(tvar::in, prog_var::out, list(hlds_goal)::out,
+ simplify_info::in, simplify_info::out) is det.
+
+simplify__type_info_locn(TypeVar, TypeInfoVar, Goals, !Info) :-
+ simplify_info_get_type_info_varmap(!.Info, TypeInfoMap),
+ map__lookup(TypeInfoMap, TypeVar, TypeInfoLocn),
(
% If the typeinfo is available in a variable,
% just use it
- { TypeInfoLocn = type_info(TypeInfoVar) },
- { Goals = [] }
+ TypeInfoLocn = type_info(TypeInfoVar),
+ Goals = []
;
% If the typeinfo is in a typeclass_info
% then we need to extract it
- { TypeInfoLocn =
- typeclass_info(TypeClassInfoVar, Index) },
+ TypeInfoLocn =
+ typeclass_info(TypeClassInfoVar, Index),
simplify__extract_type_info(TypeVar, TypeClassInfoVar, Index,
- Goals, TypeInfoVar)
+ Goals, TypeInfoVar, !Info)
).
-:- pred simplify__extract_type_info(tvar, prog_var, int,
- list(hlds_goal), prog_var, simplify_info, simplify_info).
-:- mode simplify__extract_type_info(in, in, in, out, out, in, out) is det.
+:- pred simplify__extract_type_info(tvar::in, prog_var::in, int::in,
+ list(hlds_goal)::out, prog_var::out,
+ simplify_info::in, simplify_info::out) is det.
simplify__extract_type_info(TypeVar, TypeClassInfoVar, Index,
- Goals, TypeInfoVar, Info0, Info) :-
- simplify_info_get_module_info(Info0, ModuleInfo),
- simplify_info_get_varset(Info0, VarSet0),
- simplify_info_get_var_types(Info0, VarTypes0),
+ Goals, TypeInfoVar, !Info) :-
+ simplify_info_get_module_info(!.Info, ModuleInfo),
+ simplify_info_get_varset(!.Info, VarSet0),
+ simplify_info_get_var_types(!.Info, VarTypes0),
polymorphism__gen_extract_type_info(TypeVar, TypeClassInfoVar, Index,
ModuleInfo, Goals, TypeInfoVar,
VarSet0, VarSet, VarTypes0, VarTypes),
- simplify_info_set_var_types(Info0, VarTypes, Info1),
- simplify_info_set_varset(Info1, VarSet, Info).
+ simplify_info_set_var_types(VarTypes, !Info),
+ simplify_info_set_varset(VarSet, !Info).
%-----------------------------------------------------------------------------%
@@ -1612,20 +1575,19 @@
% in HeadVars. HeadVars, Modes, and Args should all be lists of
% the same length.
-:- pred simplify__input_args_are_equiv(list(prog_var), list(prog_var),
- list(mode), common_info, module_info).
-:- mode simplify__input_args_are_equiv(in, in, in, in, in) is semidet.
+:- pred simplify__input_args_are_equiv(list(prog_var)::in, list(prog_var)::in,
+ list(mode)::in, common_info::in, module_info::in) is semidet.
simplify__input_args_are_equiv([], [], _, _, _).
-simplify__input_args_are_equiv([Arg|Args], [HeadVar|HeadVars], [Mode|Modes],
- CommonInfo, ModuleInfo1) :-
- ( mode_is_input(ModuleInfo1, Mode) ->
+simplify__input_args_are_equiv([Arg | Args], [HeadVar | HeadVars],
+ [Mode | Modes], CommonInfo, ModuleInfo) :-
+ ( mode_is_input(ModuleInfo, Mode) ->
common__vars_are_equivalent(Arg, HeadVar, CommonInfo)
;
true
),
- simplify__input_args_are_equiv(Args, HeadVars, Modes,
- CommonInfo, ModuleInfo1).
+ simplify__input_args_are_equiv(Args, HeadVars, Modes, CommonInfo,
+ ModuleInfo).
%-----------------------------------------------------------------------------%
@@ -1718,31 +1680,32 @@
%-----------------------------------------------------------------------------%
-:- pred simplify__conj(list(hlds_goal), list(hlds_goal),
- list(hlds_goal), hlds_goal_info,
- simplify_info, simplify_info).
-:- mode simplify__conj(in, in, out, in, in, out) is det.
+:- pred simplify__conj(list(hlds_goal)::in, list(hlds_goal)::in,
+ list(hlds_goal)::out, hlds_goal_info::in,
+ simplify_info::in, simplify_info::out) is det.
-simplify__conj([], RevGoals, Goals, _, Info, Info) :-
+simplify__conj([], RevGoals, Goals, _, !Info) :-
list__reverse(RevGoals, Goals).
-simplify__conj([Goal0 | Goals0], RevGoals0, Goals, ConjInfo, Info0, Info) :-
+simplify__conj([Goal0 | Goals0], RevGoals0, Goals, ConjInfo, !Info) :-
+ Info0 = !.Info,
% Flatten conjunctions.
( Goal0 = conj(SubGoals) - _ ->
list__append(SubGoals, Goals0, Goals1),
- simplify__conj(Goals1, RevGoals0, Goals, ConjInfo, Info0, Info)
+ simplify__conj(Goals1, RevGoals0, Goals, ConjInfo, !Info)
;
- simplify__goal(Goal0, Goal1, Info0, Info1),
+ simplify__goal(Goal0, Goal1, !Info),
(
% Flatten conjunctions.
Goal1 = conj(SubGoals1) - _
->
- simplify_info_undo_goal_updates(Info0, Info1, Info2),
+ simplify_info_undo_goal_updates(Info0, !Info),
list__append(SubGoals1, Goals0, Goals1),
- simplify__conj(Goals1, RevGoals0, Goals, ConjInfo, Info2, Info)
+ simplify__conj(Goals1, RevGoals0, Goals, ConjInfo,
+ !Info)
;
% Delete unreachable goals.
(
- simplify_info_get_instmap(Info1, InstMap1),
+ simplify_info_get_instmap(!.Info, InstMap1),
instmap__is_unreachable(InstMap1)
;
Goal1 = _ - GoalInfo1,
@@ -1750,11 +1713,14 @@
determinism_components(Detism1, _, at_most_zero)
)
->
- Info = Info1,
simplify__conjoin_goal_and_rev_goal_list(Goal1,
RevGoals0, RevGoals1),
- ( (Goal1 = disj([]) - _ ; Goals0 = []) ->
+ (
+ ( Goal1 = disj([]) - _
+ ; Goals0 = []
+ )
+ ->
RevGoals = RevGoals1
;
% We insert an explicit failure at the end
@@ -1762,11 +1728,11 @@
% is necessary, since the unreachability of
% the instmap could have been derived using
% inferred determinism information. Without the
- % explicit fail goal, mode errors could result if mode
- % analysis is rerun, since according to the language
- % specification, mode analysis does not use inferred
- % determinism information when deciding what can
- % never succeed.
+ % explicit fail goal, mode errors could result
+ % if mode analysis is rerun, since according
+ % to the language specification, mode analysis
+ % does not use inferred determinism information
+ % when deciding what can never succeed.
Goal0 = _ - GoalInfo0,
goal_info_get_context(GoalInfo0, Context),
fail_goal(Context, Fail),
@@ -1777,9 +1743,9 @@
;
simplify__conjoin_goal_and_rev_goal_list(Goal1,
RevGoals0, RevGoals1),
- simplify_info_update_instmap(Info1, Goal1, Info2),
- simplify__conj(Goals0, RevGoals1, Goals,
- ConjInfo, Info2, Info)
+ simplify_info_update_instmap(Goal1, !Info),
+ simplify__conj(Goals0, RevGoals1, Goals, ConjInfo,
+ !Info)
)
).
@@ -1796,15 +1762,14 @@
%-----------------------------------------------------------------------------%
-:- pred simplify__par_conj(list(hlds_goal), list(hlds_goal),
- simplify_info, simplify_info, simplify_info).
-:- mode simplify__par_conj(in, out, in, in, out) is det.
-
-simplify__par_conj([], [], _, Info, Info).
-simplify__par_conj([Goal0 |Goals0], [Goal | Goals], Info0, Info1, Info) :-
- simplify__goal(Goal0, Goal, Info1, Info2),
- simplify_info_post_branch_update(Info0, Info2, Info3),
- simplify__par_conj(Goals0, Goals, Info0, Info3, Info).
+:- pred simplify__par_conj(list(hlds_goal)::in, list(hlds_goal)::out,
+ simplify_info::in, simplify_info::in, simplify_info::out) is det.
+
+simplify__par_conj([], [], _, !Info).
+simplify__par_conj([Goal0 |Goals0], [Goal | Goals], Info0, !Info) :-
+ simplify__goal(Goal0, Goal, !Info),
+ simplify_info_post_branch_update(Info0, !Info),
+ simplify__par_conj(Goals0, Goals, Info0, !Info).
%-----------------------------------------------------------------------------%
@@ -1812,23 +1777,21 @@
list(hlds_goal)::in, list(hlds_goal)::out,
simplify_info::in, simplify_info::out) is det.
-simplify__excess_assigns_in_conj(ConjInfo, Goals0, Goals,
- Info0, Info) :-
- ( simplify_do_excess_assigns(Info0) ->
+simplify__excess_assigns_in_conj(ConjInfo, Goals0, Goals, !Info) :-
+ ( simplify_do_excess_assigns(!.Info) ->
goal_info_get_nonlocals(ConjInfo, ConjNonLocals),
map__init(Subn0),
- simplify_info_get_module_info(Info0, ModuleInfo),
+ simplify_info_get_module_info(!.Info, ModuleInfo),
module_info_globals(ModuleInfo, Globals),
globals__get_trace_level(Globals, TraceLevel),
globals__lookup_bool_option(Globals,
trace_optimized, TraceOptimized),
- simplify_info_get_varset(Info0, VarSet0),
+ simplify_info_get_varset(!.Info, VarSet0),
simplify__find_excess_assigns_in_conj(TraceLevel,
TraceOptimized, VarSet0, ConjNonLocals,
Goals0, [], RevGoals, Subn0, Subn1),
( map__is_empty(Subn1) ->
- Goals = Goals0,
- Info = Info0
+ Goals = Goals0
;
renaming_transitive_closure(Subn1, Subn),
list__reverse(RevGoals, Goals1),
@@ -1837,22 +1800,20 @@
Subn, Goals),
map__keys(Subn0, RemovedVars),
varset__delete_vars(VarSet0, RemovedVars, VarSet),
- simplify_info_set_varset(Info0, VarSet, Info1),
- simplify_info_get_type_info_varmap(Info1, TVarMap0),
+ simplify_info_set_varset(VarSet, !Info),
+ simplify_info_get_type_info_varmap(!.Info, TVarMap0),
apply_substitutions_to_var_map(TVarMap0,
map__init, map__init, Subn, TVarMap),
- simplify_info_set_type_info_varmap(Info1, TVarMap,
- Info2),
- simplify_info_get_typeclass_info_varmap(Info2,
+ simplify_info_set_type_info_varmap(TVarMap, !Info),
+ simplify_info_get_typeclass_info_varmap(!.Info,
TCVarMap0),
apply_substitutions_to_typeclass_var_map(TCVarMap0,
map__init, map__init, Subn, TCVarMap),
- simplify_info_set_typeclass_info_varmap(Info2,
- TCVarMap, Info)
+ simplify_info_set_typeclass_info_varmap(TCVarMap,
+ !Info)
)
;
- Goals = Goals0,
- Info = Info0
+ Goals = Goals0
).
:- type var_renaming == map(prog_var, prog_var).
@@ -1863,29 +1824,26 @@
var_renaming::in, var_renaming::out) is det.
simplify__find_excess_assigns_in_conj(_, _, _, _, [], RevGoals, RevGoals,
- Subn, Subn).
+ !Subn).
simplify__find_excess_assigns_in_conj(Trace, TraceOptimized, VarSet,
- ConjNonLocals, [Goal | Goals], RevGoals0, RevGoals,
- Subn0, Subn) :-
+ ConjNonLocals, [Goal | Goals], RevGoals0, RevGoals, !Subn) :-
(
goal_is_excess_assign(Trace, TraceOptimized,
- VarSet, ConjNonLocals, Goal, Subn0, Subn1)
+ VarSet, ConjNonLocals, Goal, !Subn)
->
- RevGoals1 = RevGoals0,
- Subn2 = Subn1
+ RevGoals1 = RevGoals0
;
- RevGoals1 = [Goal | RevGoals0],
- Subn2 = Subn0
+ RevGoals1 = [Goal | RevGoals0]
),
simplify__find_excess_assigns_in_conj(Trace, TraceOptimized, VarSet,
- ConjNonLocals, Goals, RevGoals1, RevGoals, Subn2, Subn).
+ ConjNonLocals, Goals, RevGoals1, RevGoals, !Subn).
:- pred goal_is_excess_assign(trace_level::in, bool::in, prog_varset::in,
set(prog_var)::in, hlds_goal::in, var_renaming::in,
var_renaming::out) is semidet.
-goal_is_excess_assign(Trace, TraceOptimized, VarSet, ConjNonLocals,
- Goal0, Subn0, Subn) :-
+goal_is_excess_assign(Trace, TraceOptimized, VarSet, ConjNonLocals, Goal0,
+ !Subn) :-
Goal0 = unify(_, _, _, Unif, _) - _,
Unif = assign(LeftVar0, RightVar0),
@@ -1893,8 +1851,8 @@
% Check if we've already substituted
% one or both of the variables.
%
- find_renamed_var(Subn0, LeftVar0, LeftVar),
- find_renamed_var(Subn0, RightVar0, RightVar),
+ find_renamed_var(!.Subn, LeftVar0, LeftVar),
+ find_renamed_var(!.Subn, RightVar0, RightVar),
CanElimLeft = ( set__member(LeftVar, ConjNonLocals) -> no ; yes ),
CanElimRight = ( set__member(RightVar, ConjNonLocals) -> no ; yes ),
@@ -1917,7 +1875,7 @@
;
fail
),
- map__det_insert(Subn0, ElimVar, ReplacementVar, Subn),
+ map__det_insert(!.Subn, ElimVar, ReplacementVar, !:Subn),
% If the module is being compiled with `--trace deep' and
% `--no-trace-optimized' don't replace a meaningful variable
@@ -1938,8 +1896,7 @@
string__to_int(Suffix, _)
).
-:- pred find_renamed_var(var_renaming, prog_var, prog_var).
-:- mode find_renamed_var(in, in, out) is det.
+:- pred find_renamed_var(var_renaming::in, prog_var::in, prog_var::out) is det.
find_renamed_var(Subn, Var0, Var) :-
( map__search(Subn, Var0, Var1) ->
@@ -1949,8 +1906,8 @@
).
% Collapse chains of renamings.
-:- pred renaming_transitive_closure(var_renaming, var_renaming).
-:- mode renaming_transitive_closure(in, out) is det.
+:- pred renaming_transitive_closure(var_renaming::in, var_renaming::out)
+ is det.
renaming_transitive_closure(VarRenaming0, VarRenaming) :-
map__map_values(
@@ -1960,34 +1917,30 @@
%-----------------------------------------------------------------------------%
-:- pred simplify__switch(prog_var, list(case), list(case), list(case),
- list(instmap_delta), list(instmap_delta), can_fail, can_fail,
- simplify_info, simplify_info, simplify_info).
-:- mode simplify__switch(in, in, in, out, in, out, in, out,
- in, in, out) is det.
+:- pred simplify__switch(prog_var::in, list(case)::in, list(case)::in,
+ list(case)::out, list(instmap_delta)::in, list(instmap_delta)::out,
+ can_fail::in, can_fail::out, simplify_info::in,
+ simplify_info::in, simplify_info::out) is det.
-simplify__switch(_, [], RevCases, Cases, InstMaps, InstMaps,
- CanFail, CanFail, _, Info, Info) :-
+simplify__switch(_, [], RevCases, Cases, !InstMaps, !CanFail, _, !Info) :-
list__reverse(RevCases, Cases).
-simplify__switch(Var, [Case0 | Cases0], RevCases0, Cases, InstMaps0, InstMaps,
- CanFail0, CanFail, Info0, Info1, Info) :-
+simplify__switch(Var, [Case0 | Cases0], RevCases0, Cases, !InstMaps,
+ !CanFail, Info0, !Info) :-
simplify_info_get_instmap(Info0, InstMap0),
Case0 = case(ConsId, Goal0),
- simplify_info_get_module_info(Info1, ModuleInfo0),
- simplify_info_get_var_types(Info1, VarTypes),
+ simplify_info_get_module_info(!.Info, ModuleInfo0),
+ simplify_info_get_var_types(!.Info, VarTypes),
map__lookup(VarTypes, Var, Type),
instmap__bind_var_to_functor(Var, Type, ConsId,
InstMap0, InstMap1, ModuleInfo0, ModuleInfo1),
- simplify_info_set_module_info(Info1, ModuleInfo1, Info2),
- simplify_info_set_instmap(Info2, InstMap1, Info3),
- simplify__goal(Goal0, Goal, Info3, Info4),
+ simplify_info_set_module_info(ModuleInfo1, !Info),
+ simplify_info_set_instmap(InstMap1, !Info),
+ simplify__goal(Goal0, Goal, !Info),
% Remove failing branches.
( Goal = disj([]) - _ ->
RevCases = RevCases0,
- InstMaps1 = InstMaps0,
- CanFail1 = can_fail,
- Info5 = Info4
+ !:CanFail = can_fail
;
Case = case(ConsId, Goal),
Goal = _ - GoalInfo,
@@ -2001,20 +1954,19 @@
% would be used, resulting in a mode error.
%
goal_info_get_instmap_delta(GoalInfo, InstMapDelta0),
- simplify_info_get_module_info(Info4, ModuleInfo5),
+ simplify_info_get_module_info(!.Info, ModuleInfo2),
instmap_delta_bind_var_to_functor(Var, Type, ConsId,
InstMap0, InstMapDelta0, InstMapDelta,
- ModuleInfo5, ModuleInfo),
- simplify_info_set_module_info(Info4, ModuleInfo, Info5),
+ ModuleInfo2, ModuleInfo),
+ simplify_info_set_module_info(ModuleInfo, !Info),
- InstMaps1 = [InstMapDelta | InstMaps0],
- RevCases = [Case | RevCases0],
- CanFail1 = CanFail0
+ !:InstMaps = [InstMapDelta | !.InstMaps],
+ RevCases = [Case | RevCases0]
),
- simplify_info_post_branch_update(Info0, Info5, Info6),
- simplify__switch(Var, Cases0, RevCases, Cases, InstMaps1, InstMaps,
- CanFail1, CanFail, Info0, Info6, Info).
+ simplify_info_post_branch_update(Info0, !Info),
+ simplify__switch(Var, Cases0, RevCases, Cases, !InstMaps,
+ !CanFail, Info0, !Info).
% Create a semidet unification at the start of a singleton case
% in a can_fail switch.
@@ -2023,19 +1975,19 @@
hlds_goal::out, simplify_info::in, simplify_info::out) is det.
simplify__create_test_unification(Var, ConsId, ConsArity,
- ExtraGoal - ExtraGoalInfo, Info0, Info) :-
- simplify_info_get_varset(Info0, VarSet0),
- simplify_info_get_var_types(Info0, VarTypes0),
+ ExtraGoal - ExtraGoalInfo, !Info) :-
+ simplify_info_get_varset(!.Info, VarSet0),
+ simplify_info_get_var_types(!.Info, VarTypes0),
varset__new_vars(VarSet0, ConsArity, ArgVars, VarSet),
map__lookup(VarTypes0, Var, VarType),
- simplify_info_get_module_info(Info0, ModuleInfo),
+ simplify_info_get_module_info(!.Info, ModuleInfo),
type_util__get_cons_id_arg_types(ModuleInfo,
VarType, ConsId, ArgTypes),
map__det_insert_from_corresponding_lists(VarTypes0, ArgVars,
ArgTypes, VarTypes),
- simplify_info_set_varset(Info0, VarSet, Info1),
- simplify_info_set_var_types(Info1, VarTypes, Info),
- simplify_info_get_instmap(Info, InstMap),
+ simplify_info_set_varset(VarSet, !Info),
+ simplify_info_set_var_types(VarTypes, !Info),
+ simplify_info_get_instmap(!.Info, InstMap),
instmap__lookup_var(InstMap, Var, Inst0),
(
inst_expand(ModuleInfo, Inst0, Inst1),
@@ -2065,16 +2017,16 @@
%-----------------------------------------------------------------------------%
-:- pred simplify__disj(list(hlds_goal), list(hlds_goal), list(hlds_goal),
- list(instmap_delta), list(instmap_delta),
- simplify_info, simplify_info, simplify_info).
-:- mode simplify__disj(in, in, out, in, out, in, in, out) is det.
+:- pred simplify__disj(list(hlds_goal)::in, list(hlds_goal)::in,
+ list(hlds_goal)::out,
+ list(instmap_delta)::in, list(instmap_delta)::out,
+ simplify_info::in, simplify_info::in, simplify_info::out) is det.
-simplify__disj([], RevGoals, Goals, InstMaps, InstMaps, _, Info, Info) :-
+simplify__disj([], RevGoals, Goals, !PostBranchInstMaps, _, !Info) :-
list__reverse(RevGoals, Goals).
-simplify__disj([Goal0 | Goals0], RevGoals0, Goals, PostBranchInstMaps0,
- PostBranchInstMaps, Info0, Info1, Info) :-
- simplify__goal(Goal0, Goal, Info1, Info2),
+simplify__disj([Goal0 | Goals0], RevGoals0, Goals, !PostBranchInstMaps,
+ Info0, !Info) :-
+ simplify__goal(Goal0, Goal, !Info),
Goal = _ - GoalInfo,
(
@@ -2086,7 +2038,7 @@
MaxSolns = at_most_zero
->
(
- simplify_do_warn(Info2),
+ simplify_do_warn(!.Info),
% Don't warn where the initial goal was fail,
% since that can result from mode analysis
% pruning away cases in a switch which cannot
@@ -2094,10 +2046,10 @@
Goal0 \= disj([]) - _
->
goal_info_get_context(GoalInfo, Context),
- simplify_info_add_msg(Info2,
- zero_soln_disjunct(Context), Info3)
+ simplify_info_add_msg(zero_soln_disjunct(Context),
+ !Info)
;
- Info3 = Info2
+ true
),
%
@@ -2110,28 +2062,26 @@
;
% Only remove disjuncts that might loop
% or call error/1 if --no-fully-strict.
- simplify_info_get_det_info(Info3, DetInfo),
+ simplify_info_get_det_info(!.Info, DetInfo),
det_info_get_fully_strict(DetInfo, no)
)
->
- RevGoals1 = RevGoals0,
- PostBranchInstMaps1 = PostBranchInstMaps0
+ RevGoals1 = RevGoals0
;
RevGoals1 = [Goal | RevGoals0],
goal_info_get_instmap_delta(GoalInfo, InstMapDelta),
- PostBranchInstMaps1 =
- [InstMapDelta | PostBranchInstMaps0]
+ !:PostBranchInstMaps =
+ [InstMapDelta | !.PostBranchInstMaps]
)
;
- Info3 = Info2,
RevGoals1 = [Goal | RevGoals0],
goal_info_get_instmap_delta(GoalInfo, InstMapDelta),
- PostBranchInstMaps1 = [InstMapDelta | PostBranchInstMaps0]
+ !:PostBranchInstMaps = [InstMapDelta | !.PostBranchInstMaps]
),
- simplify_info_post_branch_update(Info0, Info3, Info4),
- simplify__disj(Goals0, RevGoals1, Goals, PostBranchInstMaps1,
- PostBranchInstMaps, Info0, Info4, Info).
+ simplify_info_post_branch_update(Info0, !Info),
+ simplify__disj(Goals0, RevGoals1, Goals, !PostBranchInstMaps,
+ Info0, !Info).
% Disjunctions that cannot succeed more than once when viewed from the
% outside generally need some fixing up, and/or some warnings to be
@@ -2166,14 +2116,13 @@
;
****/
-:- pred simplify__fixup_disj(list(hlds_goal), determinism, bool,
- hlds_goal_info, hlds_goal_expr,
- simplify_info, simplify_info).
-:- mode simplify__fixup_disj(in, in, in, in, out, in, out) is det.
+:- pred simplify__fixup_disj(list(hlds_goal)::in, determinism::in, bool::in,
+ hlds_goal_info::in, hlds_goal_expr::out,
+ simplify_info::in, simplify_info::out) is det.
-simplify__fixup_disj(Disjuncts, _, _OutputVars, GoalInfo, Goal, Info0, Info) :-
+simplify__fixup_disj(Disjuncts, _, _OutputVars, GoalInfo, Goal, !Info) :-
det_disj_to_ite(Disjuncts, GoalInfo, IfThenElse),
- simplify__goal(IfThenElse, Simplified, Info0, Info),
+ simplify__goal(IfThenElse, Simplified, !Info),
Simplified = Goal - _.
% det_disj_to_ite is used to transform disjunctions that occur
@@ -2193,8 +2142,8 @@
% Disjunct3
% ).
-:- pred det_disj_to_ite(list(hlds_goal), hlds_goal_info, hlds_goal).
-:- mode det_disj_to_ite(in, in, out) is det.
+:- pred det_disj_to_ite(list(hlds_goal)::in, hlds_goal_info::in,
+ hlds_goal::out) is det.
det_disj_to_ite([], _GoalInfo, _) :-
error("reached base case of det_disj_to_ite").
@@ -2248,8 +2197,8 @@
%-----------------------------------------------------------------------------%
-:- type simplify_info
- ---> simplify_info(
+:- type simplify_info --->
+ simplify_info(
det_info :: det_info,
msgs :: set(det_msg),
simplifications :: set(simplification),
@@ -2312,14 +2261,13 @@
:- pred simplify_info_get_det_info(simplify_info::in, det_info::out) is det.
:- pred simplify_info_get_msgs(simplify_info::in, set(det_msg)::out) is det.
-:- pred simplify_info_get_instmap(simplify_info::in, instmap::out) is det.
:- pred simplify_info_get_simplifications(simplify_info::in,
set(simplification)::out) is det.
-:- pred simplify_info_get_common_info(simplify_info::in,
- common_info::out) is det.
+:- pred simplify_info_get_common_info(simplify_info::in, common_info::out)
+ is det.
+:- pred simplify_info_get_instmap(simplify_info::in, instmap::out) is det.
:- pred simplify_info_get_varset(simplify_info::in, prog_varset::out) is det.
-:- pred simplify_info_get_var_types(simplify_info::in,
- vartypes::out) is det.
+:- pred simplify_info_get_var_types(simplify_info::in, vartypes::out) is det.
:- pred simplify_info_requantify(simplify_info::in) is semidet.
:- pred simplify_info_recompute_atomic(simplify_info::in) is semidet.
:- pred simplify_info_rerun_det(simplify_info::in) is semidet.
@@ -2329,30 +2277,29 @@
:- pred simplify_info_get_typeclass_info_varmap(simplify_info::in,
typeclass_info_varmap::out) is det.
-:- pred simplify_info_get_module_info(simplify_info::in,
- module_info::out) is det.
-:- pred simplify_info_get_pred_info(simplify_info::in,
- pred_info::out) is det.
+:- pred simplify_info_get_module_info(simplify_info::in, module_info::out)
+ is det.
+:- pred simplify_info_get_pred_info(simplify_info::in, pred_info::out) is det.
:- implementation.
-simplify_info_get_det_info(SI, SI ^ det_info).
-simplify_info_get_msgs(SI, SI ^ msgs).
-simplify_info_get_simplifications(SI, SI ^ simplifications).
-simplify_info_get_common_info(SI, SI ^ common_info).
-simplify_info_get_instmap(SI, SI ^ instmap).
-simplify_info_get_varset(SI, SI ^ varset).
-simplify_info_get_var_types(SI, VarTypes) :-
- det_info_get_vartypes(SI ^ det_info, VarTypes).
-simplify_info_requantify(SI) :-
- SI ^ requantify = yes.
-simplify_info_recompute_atomic(SI) :-
- SI ^ recompute_atomic = yes.
-simplify_info_rerun_det(SI) :-
- SI ^ rerun_det = yes.
-simplify_info_get_cost_delta(SI, SI ^ cost_delta).
-simplify_info_get_type_info_varmap(SI, SI ^ type_info_varmap).
-simplify_info_get_typeclass_info_varmap(SI, SI ^ typeclass_info_varmap).
+simplify_info_get_det_info(Info, Info ^ det_info).
+simplify_info_get_msgs(Info, Info ^ msgs).
+simplify_info_get_simplifications(Info, Info ^ simplifications).
+simplify_info_get_common_info(Info, Info ^ common_info).
+simplify_info_get_instmap(Info, Info ^ instmap).
+simplify_info_get_varset(Info, Info ^ varset).
+simplify_info_get_var_types(Info, VarTypes) :-
+ det_info_get_vartypes(Info ^ det_info, VarTypes).
+simplify_info_requantify(Info) :-
+ Info ^ requantify = yes.
+simplify_info_recompute_atomic(Info) :-
+ Info ^ recompute_atomic = yes.
+simplify_info_rerun_det(Info) :-
+ Info ^ rerun_det = yes.
+simplify_info_get_cost_delta(Info, Info ^ cost_delta).
+simplify_info_get_type_info_varmap(Info, Info ^ type_info_varmap).
+simplify_info_get_typeclass_info_varmap(Info, Info ^ typeclass_info_varmap).
simplify_info_get_module_info(Info, ModuleInfo) :-
simplify_info_get_det_info(Info, DetInfo),
@@ -2366,39 +2313,39 @@
:- interface.
-:- pred simplify_info_set_det_info(simplify_info::in,
- det_info::in, simplify_info::out) is det.
-:- pred simplify_info_set_msgs(simplify_info::in,
- set(det_msg)::in, simplify_info::out) is det.
-:- pred simplify_info_set_simplifications(simplify_info::in,
- set(simplification)::in, simplify_info::out) is det.
-:- pred simplify_info_set_instmap(simplify_info::in,
- instmap::in, simplify_info::out) is det.
-:- pred simplify_info_set_common_info(simplify_info::in, common_info::in,
- simplify_info::out) is det.
-:- pred simplify_info_set_varset(simplify_info::in, prog_varset::in,
- simplify_info::out) is det.
-:- pred simplify_info_set_var_types(simplify_info::in, map(prog_var, type)::in,
- simplify_info::out) is det.
-:- pred simplify_info_set_requantify(simplify_info::in,
- simplify_info::out) is det.
-:- pred simplify_info_set_recompute_atomic(simplify_info::in,
- simplify_info::out) is det.
-:- pred simplify_info_set_rerun_det(simplify_info::in,
- simplify_info::out) is det.
-:- pred simplify_info_set_type_info_varmap(simplify_info::in,
- type_info_varmap::in, simplify_info::out) is det.
-:- pred simplify_info_set_typeclass_info_varmap(simplify_info::in,
- typeclass_info_varmap::in, simplify_info::out) is det.
+:- pred simplify_info_set_det_info(det_info::in,
+ simplify_info::in, simplify_info::out) is det.
+:- pred simplify_info_set_msgs(set(det_msg)::in,
+ simplify_info::in, simplify_info::out) is det.
+:- pred simplify_info_set_simplifications(set(simplification)::in,
+ simplify_info::in, simplify_info::out) is det.
+:- pred simplify_info_set_instmap(instmap::in,
+ simplify_info::in, simplify_info::out) is det.
+:- pred simplify_info_set_common_info(common_info::in,
+ simplify_info::in, simplify_info::out) is det.
+:- pred simplify_info_set_varset(prog_varset::in,
+ simplify_info::in, simplify_info::out) is det.
+:- pred simplify_info_set_var_types(map(prog_var, type)::in,
+ simplify_info::in, simplify_info::out) is det.
+:- pred simplify_info_set_requantify(
+ simplify_info::in, simplify_info::out) is det.
+:- pred simplify_info_set_recompute_atomic(
+ simplify_info::in, simplify_info::out) is det.
+:- pred simplify_info_set_rerun_det(
+ simplify_info::in, simplify_info::out) is det.
+:- pred simplify_info_set_type_info_varmap(type_info_varmap::in,
+ simplify_info::in, simplify_info::out) is det.
+:- pred simplify_info_set_typeclass_info_varmap(typeclass_info_varmap::in,
+ simplify_info::in, simplify_info::out) is det.
-:- pred simplify_info_add_msg(simplify_info::in, det_msg::in,
- simplify_info::out) is det.
-:- pred simplify_info_do_add_msg(simplify_info::in, det_msg::in,
- simplify_info::out) is det.
-:- pred simplify_info_set_cost_delta(simplify_info::in, int::in,
- simplify_info::out) is det.
-:- pred simplify_info_incr_cost_delta(simplify_info::in,
- int::in, simplify_info::out) is det.
+:- pred simplify_info_add_msg(det_msg::in,
+ simplify_info::in, simplify_info::out) is det.
+:- pred simplify_info_do_add_msg(det_msg::in,
+ simplify_info::in, simplify_info::out) is det.
+:- pred simplify_info_set_cost_delta(int::in,
+ simplify_info::in, simplify_info::out) is det.
+:- pred simplify_info_incr_cost_delta(int::in,
+ simplify_info::in, simplify_info::out) is det.
:- pred simplify_info_enter_lambda(simplify_info::in, simplify_info::out)
is det.
@@ -2406,57 +2353,57 @@
is det.
:- pred simplify_info_inside_lambda(simplify_info::in) is semidet.
-:- pred simplify_info_set_module_info(simplify_info::in,
- module_info::in, simplify_info::out) is det.
+:- pred simplify_info_set_module_info(module_info::in,
+ simplify_info::in, simplify_info::out) is det.
:- implementation.
-simplify_info_set_det_info(SI, Det, SI ^ det_info := Det).
-simplify_info_set_msgs(SI, Msgs, SI ^ msgs := Msgs).
-simplify_info_set_simplifications(SI, Simp, SI ^ simplifications := Simp).
-simplify_info_set_instmap(SI, InstMap, SI ^ instmap := InstMap).
-simplify_info_set_common_info(SI, Common, SI ^ common_info := Common).
-simplify_info_set_varset(SI, VarSet, SI ^ varset := VarSet).
-simplify_info_set_var_types(SI, VarTypes, SI ^ det_info := DetInfo) :-
- det_info_set_vartypes(SI ^ det_info, VarTypes, DetInfo).
-simplify_info_set_requantify(SI, SI ^ requantify := yes).
-simplify_info_set_recompute_atomic(SI, SI ^ recompute_atomic := yes).
-simplify_info_set_rerun_det(SI, SI ^ rerun_det := yes).
-simplify_info_set_cost_delta(SI, Delta, SI ^ cost_delta := Delta).
-simplify_info_set_type_info_varmap(SI, Map, SI ^ type_info_varmap := Map).
-simplify_info_set_typeclass_info_varmap(SI, Map,
- SI ^ typeclass_info_varmap := Map).
-
-simplify_info_incr_cost_delta(SI, Incr,
- SI ^ cost_delta := SI ^ cost_delta + Incr).
-
-simplify_info_add_msg(Info0, Msg, Info) :-
- ( simplify_do_warn(Info0) ->
- simplify_info_do_add_msg(Info0, Msg, Info)
+simplify_info_set_det_info(Det, Info, Info ^ det_info := Det).
+simplify_info_set_msgs(Msgs, Info, Info ^ msgs := Msgs).
+simplify_info_set_simplifications(Simp, Info, Info ^ simplifications := Simp).
+simplify_info_set_instmap(InstMap, Info, Info ^ instmap := InstMap).
+simplify_info_set_common_info(Common, Info, Info ^ common_info := Common).
+simplify_info_set_varset(VarSet, Info, Info ^ varset := VarSet).
+simplify_info_set_var_types(VarTypes, Info, Info ^ det_info := DetInfo) :-
+ det_info_set_vartypes(Info ^ det_info, VarTypes, DetInfo).
+simplify_info_set_requantify(Info, Info ^ requantify := yes).
+simplify_info_set_recompute_atomic(Info, Info ^ recompute_atomic := yes).
+simplify_info_set_rerun_det(Info, Info ^ rerun_det := yes).
+simplify_info_set_cost_delta(Delta, Info, Info ^ cost_delta := Delta).
+simplify_info_set_type_info_varmap(Map, Info, Info ^ type_info_varmap := Map).
+simplify_info_set_typeclass_info_varmap(Map, Info,
+ Info ^ typeclass_info_varmap := Map).
+
+simplify_info_incr_cost_delta(Incr, Info,
+ Info ^ cost_delta := Info ^ cost_delta + Incr).
+
+simplify_info_add_msg(Msg, !Info) :-
+ ( simplify_do_warn(!.Info) ->
+ simplify_info_do_add_msg(Msg, !Info)
;
- Info = Info0
+ true
).
-simplify_info_do_add_msg(Info0, Msg, Info) :-
- simplify_info_get_msgs(Info0, Msgs0),
+simplify_info_do_add_msg(Msg, !Info) :-
+ simplify_info_get_msgs(!.Info, Msgs0),
set__insert(Msgs0, Msg, Msgs),
- simplify_info_set_msgs(Info0, Msgs, Info).
+ simplify_info_set_msgs(Msgs, !Info).
-simplify_info_enter_lambda(SI, SI ^ lambdas := SI ^ lambdas + 1).
-simplify_info_leave_lambda(SI, SI ^ lambdas := LambdaCount) :-
- LambdaCount1 = SI ^ lambdas - 1,
+simplify_info_enter_lambda(Info, Info ^ lambdas := Info ^ lambdas + 1).
+simplify_info_leave_lambda(Info, Info ^ lambdas := LambdaCount) :-
+ LambdaCount1 = Info ^ lambdas - 1,
( LambdaCount1 >= 0 ->
LambdaCount = LambdaCount1
;
error("simplify_info_leave_lambda: Left too many lambdas")
).
-simplify_info_inside_lambda(SI) :-
- SI ^ lambdas > 0.
+simplify_info_inside_lambda(Info) :-
+ Info ^ lambdas > 0.
-simplify_info_set_module_info(Info0, ModuleInfo, Info) :-
- simplify_info_get_det_info(Info0, DetInfo0),
+simplify_info_set_module_info(ModuleInfo, !Info) :-
+ simplify_info_get_det_info(!.Info, DetInfo0),
det_info_set_module_info(DetInfo0, ModuleInfo, DetInfo),
- simplify_info_set_det_info(Info0, DetInfo, Info).
+ simplify_info_set_det_info(DetInfo, !Info).
:- interface.
@@ -2496,11 +2443,11 @@
simplify_info_get_simplifications(Info, Simplifications),
set__member(extra_common_struct, Simplifications).
-:- pred simplify_info_update_instmap(simplify_info::in, hlds_goal::in,
- simplify_info::out) is det.
+:- pred simplify_info_update_instmap(hlds_goal::in,
+ simplify_info::in, simplify_info::out) is det.
-simplify_info_update_instmap(SI, Goal, SI ^ instmap := InstMap) :-
- update_instmap(Goal, SI ^ instmap, InstMap).
+simplify_info_update_instmap(Goal, Info, Info ^ instmap := InstMap) :-
+ update_instmap(Goal, Info ^ instmap, InstMap).
:- type before_after
---> before
@@ -2517,17 +2464,17 @@
:- pred simplify_info_maybe_clear_structs(before_after::in, hlds_goal::in,
simplify_info::in, simplify_info::out) is det.
-simplify_info_maybe_clear_structs(BeforeAfter, Goal, Info0, Info) :-
+simplify_info_maybe_clear_structs(BeforeAfter, Goal, !Info) :-
(
( cannot_flush(Goal)
- ; simplify_do_more_common(Info0)
+ ; simplify_do_more_common(!.Info)
)
->
- Info = Info0
+ true
;
% First check to see if a call is common and can be replaced
% by a series of unifications.
- simplify_do_common(Info0),
+ simplify_do_common(!.Info),
(
BeforeAfter = after
;
@@ -2538,11 +2485,11 @@
GoalExpr \= foreign_proc(_, _, _, _, _, _, _)
)
->
- simplify_info_get_common_info(Info0, CommonInfo0),
+ simplify_info_get_common_info(!.Info, CommonInfo0),
common_info_clear_structs(CommonInfo0, CommonInfo),
- simplify_info_set_common_info(Info0, CommonInfo, Info)
+ simplify_info_set_common_info(CommonInfo, !Info)
;
- Info = Info0
+ true
).
% Reset the instmap and seen calls for the next branch.
@@ -2551,19 +2498,19 @@
simplify_info_post_branch_update(PreBranchInfo, PostBranchInfo0, Info) :-
simplify_info_get_instmap(PreBranchInfo, InstMap),
- simplify_info_set_instmap(PostBranchInfo0, InstMap, PostBranchInfo1),
+ simplify_info_set_instmap(InstMap, PostBranchInfo0, PostBranchInfo1),
simplify_info_get_common_info(PreBranchInfo, Common),
- simplify_info_set_common_info(PostBranchInfo1, Common, Info).
+ simplify_info_set_common_info(Common, PostBranchInfo1, Info).
% Undo updates to the simplify_info before redoing
% simplification on a goal.
:- pred simplify_info_undo_goal_updates(simplify_info::in, simplify_info::in,
simplify_info::out) is det.
-simplify_info_undo_goal_updates(Info1, Info2, Info) :-
- simplify_info_get_common_info(Info1, CommonInfo0),
- simplify_info_set_common_info(Info2, CommonInfo0, Info3),
- simplify_info_get_instmap(Info1, InstMap),
- simplify_info_set_instmap(Info3, InstMap, Info).
+simplify_info_undo_goal_updates(Info0, !Info) :-
+ simplify_info_get_common_info(Info0, CommonInfo0),
+ simplify_info_set_common_info(CommonInfo0, !Info),
+ simplify_info_get_instmap(Info0, InstMap),
+ simplify_info_set_instmap(InstMap, !Info).
%-----------------------------------------------------------------------------%
Index: compiler/size_prof.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/size_prof.m,v
retrieving revision 1.4
diff -u -b -r1.4 size_prof.m
--- compiler/size_prof.m 1 Dec 2003 15:55:49 -0000 1.4
+++ compiler/size_prof.m 24 Feb 2004 06:22:22 -0000
@@ -219,8 +219,8 @@
process_proc(Transform, PredId, ProcId, !ProcInfo, !ModuleInfo) :-
Simplifications = [],
- simplify__proc_2(Simplifications, PredId, ProcId, !ModuleInfo,
- !ProcInfo, _Msgs),
+ simplify__proc_return_msgs(Simplifications, PredId, ProcId,
+ !ModuleInfo, !ProcInfo, _Msgs),
proc_info_goal(!.ProcInfo, Goal0),
proc_info_varset(!.ProcInfo, VarSet0),
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
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/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/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/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/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing java
cvs diff: Diffing java/library
cvs diff: Diffing java/runtime
cvs diff: Diffing library
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 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/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