[m-rev.] diff: simplifying special ites
Zoltan Somogyi
zs at unimelb.edu.au
Mon Jun 18 17:00:27 AEST 2012
compiler/simplify.m:
Move the code for handling a special case in the simplification
of if-then-elses to the predicate that handles all other special cases
for ites.
Zoltan.
cvs diff: Diffing .
Index: simplify.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/simplify.m,v
retrieving revision 1.280
diff -u -b -r1.280 simplify.m
--- simplify.m 14 Jun 2012 07:03:56 -0000 1.280
+++ simplify.m 18 Jun 2012 06:54:25 -0000
@@ -1072,8 +1072,8 @@
Goals = [_, _ | _],
% Conjunctions that cannot produce solutions may nevertheless contain
- % nondet and multi goals. If this happens, the conjunction is put
- % inside a scope to appease the code generator.
+ % nondet and multi goals. If this happens, we put the conjunction
+ % inside a commit scope to appease the code generator.
Detism = goal_info_get_determinism(GoalInfo0),
(
@@ -1485,10 +1485,10 @@
determinism_components(CondDetism0, CondCanFail0, CondSolns0),
(
CondCanFail0 = cannot_fail,
- goal_to_conj_list(Cond0, CondList),
- goal_to_conj_list(Then0, ThenList),
- list.append(CondList, ThenList, List),
- simplify_goal(hlds_goal(conj(plain_conj, List), GoalInfo0),
+ goal_to_conj_list(Cond0, CondGoals),
+ goal_to_conj_list(Then0, ThenGoals),
+ Goals = CondGoals ++ ThenGoals,
+ simplify_goal(hlds_goal(conj(plain_conj, Goals), GoalInfo0),
hlds_goal(GoalExpr, GoalInfo), !Info),
simplify_info_get_inside_duplicated_for_switch(!.Info,
InsideDuplForSwitch),
@@ -1582,9 +1582,20 @@
; CondSolns0 = at_most_many
; CondSolns0 = at_most_many_cc
),
+ ( Else0 = hlds_goal(disj([]), _) ->
+ % (Cond -> Then ; fail) is equivalent to (Cond, Then)
+ goal_to_conj_list(Cond0, CondGoals),
+ goal_to_conj_list(Then0, ThenGoals),
+ Goals = CondGoals ++ ThenGoals,
+ simplify_goal(hlds_goal(conj(plain_conj, Goals), GoalInfo0),
+ hlds_goal(GoalExpr, GoalInfo), !Info),
+ simplify_info_set_requantify(!Info),
+ simplify_info_set_rerun_det(!Info)
+ ;
simplify_goal_ordinary_ite(Vars, Cond0, Then0, Else0, GoalExpr,
GoalInfo0, GoalInfo, !Info)
)
+ )
).
:- pred simplify_goal_ordinary_ite(list(prog_var)::in,
@@ -1594,16 +1605,6 @@
simplify_goal_ordinary_ite(Vars, Cond0, Then0, Else0, GoalExpr,
GoalInfo0, GoalInfo, !Info) :-
- ( Else0 = hlds_goal(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(hlds_goal(conj(plain_conj, List), GoalInfo0),
- hlds_goal(GoalExpr, GoalInfo), !Info),
- simplify_info_set_requantify(!Info),
- simplify_info_set_rerun_det(!Info)
- ;
% Recursively simplify the sub-goals, and rebuild the resulting
% if-then-else.
@@ -1619,8 +1620,8 @@
CondDelta = goal_info_get_instmap_delta(CondInfo),
Then = hlds_goal(_, ThenInfo),
ThenDelta = goal_info_get_instmap_delta(ThenInfo),
- instmap_delta_apply_instmap_delta(CondDelta, ThenDelta,
- test_size, CondThenDelta),
+ instmap_delta_apply_instmap_delta(CondDelta, ThenDelta, test_size,
+ CondThenDelta),
Else = hlds_goal(_, ElseInfo),
ElseDelta = goal_info_get_instmap_delta(ElseInfo),
NonLocals = goal_info_get_nonlocals(GoalInfo0),
@@ -1651,8 +1652,7 @@
)
->
simplify_info_undo_goal_updates(Info0, !Info),
- simplify_goal_expr(IfThenElse, GoalExpr, GoalInfo1, GoalInfo,
- !Info)
+ simplify_goal_expr(IfThenElse, GoalExpr, GoalInfo1, GoalInfo, !Info)
;
simplify_info_get_module_info(!.Info, ModuleInfo),
warn_switch_for_ite_cond(ModuleInfo, VarTypes, Cond,
@@ -1683,18 +1683,17 @@
CanSwitch = cond_cannot_switch
),
(
- % If-then-elses that are det or semidet may nevertheless
- % contain nondet or multi conditions. If this happens,
- % the if-then-else must be put inside a `scope' to appease
- % the code generator. (Both the MLDS and LLDS back-ends
- % rely on this.)
+ % If-then-elses that are det or semidet may nevertheless contain
+ % nondet or multi conditions. If this happens, the if-then-else
+ % must be put inside a `scope' to appease the code generator.
+ % (Both the MLDS and LLDS back-ends rely on this.)
simplify_do_once(!.Info),
CondSolns = at_most_many,
IfThenElseNumSolns \= at_most_many
->
- determinism_components(InnerDetism,
- IfThenElseCanFail, at_most_many),
+ determinism_components(InnerDetism, IfThenElseCanFail,
+ at_most_many),
goal_info_set_determinism(InnerDetism, GoalInfo1, InnerInfo),
GoalExpr = scope(commit(dont_force_pruning),
hlds_goal(IfThenElse, InnerInfo))
@@ -1702,7 +1701,6 @@
GoalExpr = IfThenElse
),
GoalInfo = GoalInfo1
- )
).
:- type cond_can_switch
@@ -3051,8 +3049,8 @@
Call = hlds_goal(Call1, CallGoalInfo1)
)
),
- list.append(ExtraGoals, [Call], ConjList),
- conj_list_to_goal(ConjList, GoalInfo0, Goal).
+ Conjuncts = ExtraGoals ++ [Call],
+ conj_list_to_goal(Conjuncts, GoalInfo0, Goal).
:- pred call_generic_unify(prog_var::in, prog_var::in, prog_var::in,
module_info::in, simplify_info::in, unify_context::in,
@@ -3074,7 +3072,7 @@
call_specific_unify(TypeCtor, TypeInfoVars, XVar, YVar, ProcId, ModuleInfo,
Context, GoalInfo0, CallExpr, CallGoalInfo) :-
% Create the new call goal.
- list.append(TypeInfoVars, [XVar, YVar], ArgVars),
+ ArgVars = TypeInfoVars ++ [XVar, YVar],
module_info_get_special_pred_map(ModuleInfo, SpecialPredMap),
map.lookup(SpecialPredMap, spec_pred_unify - TypeCtor, PredId),
module_info_pred_info(ModuleInfo, PredId, PredInfo),
@@ -3320,7 +3318,7 @@
Info0 = !.Info,
% Flatten conjunctions.
( Goal0 = hlds_goal(conj(plain_conj, SubGoals), _) ->
- list.append(SubGoals, Goals0, Goals1),
+ Goals1 = SubGoals ++ Goals0,
simplify_conj(Goals1, !.RevGoals, Goals, ConjInfo, !Info)
;
simplify_goal(Goal0, Goal1, !Info),
@@ -3329,7 +3327,7 @@
Goal1 = hlds_goal(conj(plain_conj, SubGoals1), _)
->
simplify_info_undo_goal_updates(Info0, !Info),
- list.append(SubGoals1, Goals0, Goals1),
+ Goals1 = SubGoals1 ++ Goals0,
simplify_conj(Goals1, !.RevGoals, Goals, ConjInfo, !Info)
;
% Delete unreachable goals.
@@ -3377,7 +3375,7 @@
conjoin_goal_and_rev_goal_list(Goal, RevGoals0, RevGoals) :-
( Goal = hlds_goal(conj(plain_conj, Goals), _) ->
list.reverse(Goals, Goals1),
- list.append(Goals1, RevGoals0, RevGoals)
+ RevGoals = Goals1 ++ RevGoals0
;
RevGoals = [Goal | RevGoals0]
).
cvs diff: Diffing notes
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list