[m-dev.] diff for review
Simon TAYLOR
stayl at students.cs.mu.oz.au
Thu Apr 24 17:37:40 AEST 1997
Hi Fergus,
My last attempt at this didn't quite fix the multiple error messages
problem, since if simplify.m merges two switches, it reruns simplify__goal
on the merged goal. The proper fix is to revert to using a set to hold the
list of warnings, and to make the det_msg stay the same even if the
goal changes.
Estimated hours taken: 4
Fix an abort and a duplicate warning message problem.
compiler/det_report.m
Replace the goals and goal_infos from the type det_msg,
and replace them with the contexts of the goals. This ensures
that the det_msg for a particular construct is unique, even
if goal is changed and simplification is rerun on the goal.
compiler/simplify.m
Fix and enable the code to optimize if-then-elses that cannot
succeed.
Stop warnings appearing multiple times.
Produce warnings for all cases of a negated goal not succeeding
or failing, not just \+ true and \+ fail.
compiler/liveness.m
Fix a bug in the liveness annotations for if-then-elses which cannot
succeed. Since simplify.m now optimizes away all such if-then-elses,
this change isn't really necessary, but may prevent the bug
reappearing in future.
compiler/modes.m
Remove code to optimize if-then-elses with conditions that cannot
succeed, since that is now done in simplify.m. Also the code
here was buggy, in that it set the instmap_delta of the negated
condition to reachable, even if the condition's determinism turned
out to be erroneous. This couldn't be fixed easily, because
determinism information is not available in modes.m
compiler/unique_modes.m
Removed the commented out version of the if-then-else optimization
removed from mode analysis.
tests/warnings/simple_code.{m, exp}
Test cases for the warnings from simplify.m
tests/valid/fail_ite.m
Regression test for the abort.
Index: common.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/common.m,v
retrieving revision 1.38
diff -u -r1.38 common.m
--- common.m 1997/04/07 05:39:08 1.38
+++ common.m 1997/04/23 06:53:06
@@ -476,9 +476,10 @@
map__apply_to_list(OutputArgs2, VarTypes,
OutputArgTypes)
->
+ goal_info_get_context(GoalInfo, Context),
simplify_info_add_msg(Info0,
duplicate_call(SeenCall, PrevContext,
- GoalInfo),
+ Context),
Info1)
;
Info1 = Info0
Index: det_report.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/det_report.m,v
retrieving revision 1.33
diff -u -r1.33 det_report.m
--- det_report.m 1997/04/23 01:02:30 1.33
+++ det_report.m 1997/04/23 06:58:56
@@ -19,24 +19,24 @@
:- type det_msg --->
% warnings
- multidet_disj(hlds_goal_info, list(hlds_goal))
- ; det_disj(hlds_goal_info, list(hlds_goal))
- ; semidet_disj(hlds_goal_info, list(hlds_goal))
- ; zero_soln_disj(hlds_goal_info, list(hlds_goal))
- ; zero_soln_disjunct(hlds_goal_info)
- ; ite_cond_cannot_fail(hlds_goal_info)
- ; ite_cond_cannot_succeed(hlds_goal_info)
- ; negated_goal_cannot_fail(hlds_goal_info)
- ; negated_goal_cannot_succeed(hlds_goal_info)
- ; warn_obsolete(pred_id, hlds_goal_info)
+ multidet_disj(term__context, list(term__context))
+ ; det_disj(term__context, list(term__context))
+ ; semidet_disj(term__context, list(term__context))
+ ; zero_soln_disj(term__context, list(term__context))
+ ; zero_soln_disjunct(term__context)
+ ; ite_cond_cannot_fail(term__context)
+ ; ite_cond_cannot_succeed(term__context)
+ ; negated_goal_cannot_fail(term__context)
+ ; negated_goal_cannot_succeed(term__context)
+ ; warn_obsolete(pred_id, term__context)
% warning about calls to predicates
% for which there is a `:- pragma obsolete'
% declaration.
- ; warn_infinite_recursion(hlds_goal_info)
+ ; warn_infinite_recursion(term__context)
% warning about recursive calls
% which would cause infinite loops.
; duplicate_call(seen_call_id, term__context,
- hlds_goal_info)
+ term__context)
% multiple calls with the same input args.
% errors
; cc_pred_in_wrong_context(hlds_goal_info, determinism,
@@ -837,70 +837,55 @@
:- pred det_report_msg(det_msg, module_info, io__state, io__state).
:- mode det_report_msg(in, in, di, uo) is det.
-det_report_msg(multidet_disj(GoalInfo, Disjuncts0), _) -->
- { goal_info_get_context(GoalInfo, Context) },
+det_report_msg(multidet_disj(Context, DisjunctContexts), _) -->
prog_out__write_context(Context),
io__write_string("Warning: the disjunction with arms on lines "),
- { det_report_sort_context_lines(Disjuncts0, Disjuncts) },
- det_report_context_lines(Disjuncts, yes),
+ det_report_context_lines(DisjunctContexts, yes),
io__write_string("\n"),
prog_out__write_context(Context),
io__write_string(" has no outputs, but can succeed more than once.\n").
-det_report_msg(det_disj(GoalInfo, Disjuncts0), _) -->
- { goal_info_get_context(GoalInfo, Context) },
+det_report_msg(det_disj(Context, DisjunctContexts), _) -->
prog_out__write_context(Context),
io__write_string("Warning: the disjunction with arms on lines "),
- { det_report_sort_context_lines(Disjuncts0, Disjuncts) },
- det_report_context_lines(Disjuncts, yes),
+ det_report_context_lines(DisjunctContexts, yes),
io__write_string("\n"),
prog_out__write_context(Context),
io__write_string(" will succeed exactly once.\n").
-det_report_msg(semidet_disj(GoalInfo, Disjuncts0), _) -->
- { goal_info_get_context(GoalInfo, Context) },
+det_report_msg(semidet_disj(Context, DisjunctContexts), _) -->
prog_out__write_context(Context),
io__write_string("Warning: the disjunction with arms on lines "),
- { det_report_sort_context_lines(Disjuncts0, Disjuncts) },
- det_report_context_lines(Disjuncts, yes),
+ det_report_context_lines(DisjunctContexts, yes),
io__write_string("\n"),
prog_out__write_context(Context),
io__write_string(" is semidet, yet it has an output.\n").
-det_report_msg(zero_soln_disj(GoalInfo, Disjuncts0), _) -->
- { goal_info_get_context(GoalInfo, Context) },
+det_report_msg(zero_soln_disj(Context, DisjunctContexts), _) -->
prog_out__write_context(Context),
io__write_string("Warning: the disjunction with arms on lines "),
- { det_report_sort_context_lines(Disjuncts0, Disjuncts) },
- det_report_context_lines(Disjuncts, yes),
+ det_report_context_lines(DisjunctContexts, yes),
io__write_string("\n"),
prog_out__write_context(Context),
io__write_string(" cannot succeed.\n").
-det_report_msg(zero_soln_disjunct(GoalInfo), _) -->
- { goal_info_get_context(GoalInfo, Context) },
+det_report_msg(zero_soln_disjunct(Context), _) -->
prog_out__write_context(Context),
io__write_string("Warning: this disjunct will never have any solutions.\n").
-det_report_msg(ite_cond_cannot_fail(GoalInfo), _) -->
- { goal_info_get_context(GoalInfo, Context) },
+det_report_msg(ite_cond_cannot_fail(Context), _) -->
prog_out__write_context(Context),
io__write_string("Warning: the condition of this if-then-else cannot fail.\n").
-det_report_msg(ite_cond_cannot_succeed(GoalInfo), _) -->
- { goal_info_get_context(GoalInfo, Context) },
+det_report_msg(ite_cond_cannot_succeed(Context), _) -->
prog_out__write_context(Context),
io__write_string("Warning: the condition of this if-then-else cannot succeed.\n").
-det_report_msg(negated_goal_cannot_fail(GoalInfo), _) -->
- { goal_info_get_context(GoalInfo, Context) },
+det_report_msg(negated_goal_cannot_fail(Context), _) -->
prog_out__write_context(Context),
io__write_string("Warning: the negated goal cannot fail.\n").
-det_report_msg(negated_goal_cannot_succeed(GoalInfo), _) -->
- { goal_info_get_context(GoalInfo, Context) },
+det_report_msg(negated_goal_cannot_succeed(Context), _) -->
prog_out__write_context(Context),
io__write_string("Warning: the negated goal cannot succeed.\n").
-det_report_msg(warn_obsolete(PredId, GoalInfo), ModuleInfo) -->
- { goal_info_get_context(GoalInfo, Context) },
+det_report_msg(warn_obsolete(PredId, Context), ModuleInfo) -->
prog_out__write_context(Context),
io__write_string("Warning: call to obsolete "),
hlds_out__write_pred_id(ModuleInfo, PredId),
io__write_string(".\n").
-det_report_msg(warn_infinite_recursion(GoalInfo), _ModuleInfo) -->
- { goal_info_get_context(GoalInfo, Context) },
+det_report_msg(warn_infinite_recursion(Context), _ModuleInfo) -->
/*
% it would be better if we supplied more information
% than just the line number.
@@ -920,8 +905,7 @@
;
[]
).
-det_report_msg(duplicate_call(SeenCall, PrevContext, GoalInfo), ModuleInfo) -->
- { goal_info_get_context(GoalInfo, Context) },
+det_report_msg(duplicate_call(SeenCall, PrevContext, Context), ModuleInfo) -->
prog_out__write_context(Context),
io__write_string("Warning: redundant "),
det_report_seen_call_id(SeenCall, ModuleInfo),
@@ -985,52 +969,21 @@
).
%-----------------------------------------------------------------------------%
- % Insertion sort is good enough.
-
-:- pred det_report_sort_context_lines(list(hlds_goal), list(hlds_goal)).
-:- mode det_report_sort_context_lines(in, out) is det.
-
-det_report_sort_context_lines([], []).
-det_report_sort_context_lines([Goal0 | Goals0], Goals) :-
- det_report_sort_context_lines(Goals0, Goals1),
- det_report_insert_context_line(Goals1, Goal0, Goals).
-
-:- pred det_report_insert_context_line(list(hlds_goal), hlds_goal,
- list(hlds_goal)).
-:- mode det_report_insert_context_line(in, in, out) is det.
-
-det_report_insert_context_line([], Goal, [Goal]).
-det_report_insert_context_line([Goal0 | Goals0], Goal, Goals) :-
- Goal0 = _ - GoalInfo0,
- goal_info_get_context(GoalInfo0, Context0),
- term__context_line(Context0, Line0),
- Goal = _ - GoalInfo,
- goal_info_get_context(GoalInfo, Context),
- term__context_line(Context, Line),
- ( Line < Line0 ->
- Goals = [Goal, Goal0 | Goals0]
- ;
- det_report_insert_context_line(Goals0, Goal, Goals1),
- Goals = [Goal0 | Goals1]
- ).
-
-%-----------------------------------------------------------------------------%
-
-:- pred det_report_context_lines(list(hlds_goal), bool, io__state, io__state).
+:- pred det_report_context_lines(list(term__context), bool,
+ io__state, io__state).
:- mode det_report_context_lines(in, in, di, uo) is det.
det_report_context_lines([], _) --> [].
-det_report_context_lines([_ - GoalInfo | Goals], First) -->
- { goal_info_get_context(GoalInfo, Context) },
+det_report_context_lines([Context | Contexts], First) -->
{ term__context_line(Context, Line) },
( { First = yes } ->
[]
- ; { Goals = [] } ->
+ ; { Contexts = [] } ->
io__write_string(" and ")
;
io__write_string(", ")
),
io__write_int(Line),
- det_report_context_lines(Goals, no).
+ det_report_context_lines(Contexts, no).
%-----------------------------------------------------------------------------%
Index: liveness.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/liveness.m,v
retrieving revision 1.69
diff -u -r1.69 liveness.m
--- liveness.m 1997/02/23 06:06:49 1.69
+++ liveness.m 1997/04/23 01:11:39
@@ -187,8 +187,23 @@
Liveness0, NonLocals, LiveInfo, Liveness,
if_then_else(Vars, Cond, Then, Else, SM)) :-
detect_liveness_in_goal(Cond0, Liveness0, LiveInfo, LivenessCond, Cond),
- detect_liveness_in_goal(Then0, LivenessCond, LiveInfo, LivenessThen,
- Then1),
+
+ %
+ % If the condition cannot succeed, any variables which become
+ % live in the else part should put in the post-birth set of the
+ % then part by add_liveness_after_goal, and the other sets
+ % should be empty.
+ %
+ Cond = _ - CondInfo,
+ goal_info_get_instmap_delta(CondInfo, CondDelta),
+ ( instmap_delta_is_unreachable(CondDelta) ->
+ LivenessThen = LivenessCond,
+ Then1 = Then0
+ ;
+ detect_liveness_in_goal(Then0, LivenessCond, LiveInfo,
+ LivenessThen, Then1)
+ ),
+
detect_liveness_in_goal(Else0, Liveness0, LiveInfo, LivenessElse,
Else1),
Index: modes.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/modes.m,v
retrieving revision 1.197
diff -u -r1.197 modes.m
--- modes.m 1997/04/21 13:40:05 1.197
+++ modes.m 1997/04/22 04:42:19
@@ -719,7 +719,6 @@
modecheck_goal(A0, A),
mode_info_remove_live_vars(B_Vars),
mode_info_unlock_vars(NonLocals),
- mode_info_dcg_get_instmap(InstMapA),
modecheck_goal(B0, B),
mode_info_dcg_get_instmap(InstMapB),
mode_info_set_instmap(InstMap0),
@@ -727,29 +726,7 @@
mode_info_dcg_get_instmap(InstMapC),
mode_info_set_instmap(InstMap0),
instmap__merge(NonLocals, [InstMapB, InstMapC], if_then_else),
- ( { instmap__is_unreachable(InstMapA) } ->
- % if the condition can never succeed, we delete the
- % unreachable `then' part by replacing
- % if some [Vs] A then B else C
- % with
- % (not some [Vs] A), C
- { goal_get_nonlocals(A, A_Vars) },
- { goal_get_nonlocals(C, C_Vars) },
- { set__union(NonLocals, C_Vars, OutsideVars) },
- { set__delete_list(OutsideVars, Vs, OutsideVars1) },
- { set__intersect(OutsideVars1, A_Vars, SomeA_NonLocals) },
- { goal_info_init(EmptyGoalInfo) },
- { goal_info_set_nonlocals(EmptyGoalInfo, SomeA_NonLocals,
- SomeA_GoalInfo) },
- { instmap_delta_init_reachable(EmptyInstmapDelta) },
- { goal_info_set_instmap_delta(SomeA_GoalInfo,
- EmptyInstmapDelta, NotSomeA_GoalInfo) },
-
- { Goal = conj([not(some(Vs, A) - SomeA_GoalInfo) -
- NotSomeA_GoalInfo, C]) }
- ;
- { Goal = if_then_else(Vs, A, B, C, SM) }
- ),
+ { Goal = if_then_else(Vs, A, B, C, SM) },
mode_checkpoint(exit, "if-then-else").
modecheck_goal_expr(not(A0), GoalInfo0, not(A)) -->
Index: simplify.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/simplify.m,v
retrieving revision 1.29
diff -u -r1.29 simplify.m
--- simplify.m 1997/04/08 02:26:34 1.29
+++ simplify.m 1997/04/24 04:24:34
@@ -80,9 +80,8 @@
VarSet0, VarTypes0, Info0),
write_pred_progress_message("% Simplifying ", PredId, ModuleInfo0,
State1, State2),
+ Simplify = simplify(Warn, WarnCalls, Once, Switch, _, Excess, Calls),
( simplify_do_common(Info0) ->
- Simplify = simplify(Warn, WarnCalls, Once,
- Switch, _, Excess, Calls),
% On the first pass do common structure elimination and
% branch merging.
simplify_info_set_simplify(Info0,
@@ -94,7 +93,7 @@
proc_info_variables(Proc1, VarSet1),
proc_info_vartypes(Proc1, VarTypes1),
simplify_info_init(DetInfo,
- simplify(Warn, WarnCalls, Once, no, no, Excess, no),
+ simplify(no, no, Once, no, no, Excess, no),
InstMap0, VarSet1, VarTypes1, Info3),
simplify_info_set_msgs(Info3, Msgs1, Info4),
%proc_info_goal(Proc1, OutGoal),
@@ -114,7 +113,7 @@
Info4, Info, State4, State5),
simplify_info_get_msgs(Info, Msgs2),
set__to_sorted_list(Msgs2, Msgs),
- ( simplify_do_warn(Info) ->
+ ( (Warn = yes ; WarnCalls = yes) ->
det_report_msgs(Msgs, ModuleInfo, WarnCnt,
ErrCnt, State5, State)
;
@@ -371,7 +370,9 @@
pred_info_get_marker_list(PredInfo, Markers),
list__member(request(obsolete), Markers)
->
- simplify_info_add_msg(Info0, warn_obsolete(PredId, GoalInfo),
+
+ goal_info_get_context(GoalInfo, Context1),
+ simplify_info_add_msg(Info0, warn_obsolete(PredId, Context1),
Info1)
;
Info1 = Info0
@@ -414,7 +415,8 @@
simplify__input_args_are_equiv(Args, HeadVars, ArgModes,
CommonInfo1, ModuleInfo1)
->
- simplify_info_add_msg(Info1, warn_infinite_recursion(GoalInfo),
+ goal_info_get_context(GoalInfo, Context2),
+ simplify_info_add_msg(Info1, warn_infinite_recursion(Context2),
Info2)
;
Info2 = Info1
@@ -472,40 +474,64 @@
% is finished, or when we start doing coroutining.
simplify__goal_2(if_then_else(Vars, Cond0, Then0, Else0, SM),
- GoalInfo, Goal, GoalInfo, Info0, Info) :-
+ GoalInfo0, Goal, GoalInfo, Info0, Info) :-
Cond0 = _ - CondInfo0,
goal_info_get_determinism(CondInfo0, CondDetism),
- determinism_components(CondDetism, CondCanFail, _CondSolns),
+ determinism_components(CondDetism, CondCanFail, CondSolns),
( CondCanFail = cannot_fail ->
goal_to_conj_list(Cond0, CondList),
goal_to_conj_list(Then0, ThenList),
list__append(CondList, ThenList, List),
- simplify__goal(conj(List) - GoalInfo, Goal - _,
+ simplify__goal(conj(List) - GoalInfo0, Goal - GoalInfo,
Info0, Info1),
- simplify_info_add_msg(Info1, ite_cond_cannot_fail(GoalInfo),
+ goal_info_get_context(GoalInfo, Context),
+ simplify_info_add_msg(Info1, ite_cond_cannot_fail(Context),
Info)
-/*********
- The following optimization is disabled, because it is
- buggy (see the XXX below). It's not important, since
- most of these cases will be optimized by modes.m anyway.
; CondSolns = at_most_zero ->
% Optimize away the condition and the `then' part.
+ goal_info_get_determinism(CondInfo0, Detism),
+ det_negation_det(Detism, MaybeNegDetism),
+ ( Cond0 = not(NegCond) - _ ->
+ Cond = NegCond
+ ;
+ (
+ MaybeNegDetism = yes(NegDetism1),
+ (
+ NegDetism1 = erroneous,
+ instmap_delta_init_unreachable(
+ NegInstMapDelta1)
+ ;
+ NegDetism1 = det,
+ instmap_delta_init_reachable(
+ NegInstMapDelta1)
+ )
+ ->
+ NegDetism = NegDetism1,
+ NegInstMapDelta = NegInstMapDelta1
+ ;
+ error("simplify__goal_2: cannot get negated determinism")
+ ),
+ goal_info_set_determinism(CondInfo0,
+ NegDetism, NegCondInfo0),
+ goal_info_set_instmap_delta(NegCondInfo0,
+ NegInstMapDelta, NegCondInfo),
+ Cond = not(Cond0) - NegCondInfo
+ ),
goal_to_conj_list(Else0, ElseList),
- % XXX Using CondInfo without updating the determinism is a bug.
- % We should probably update other goal_info fields as well,
- % e.g. the instmap_delta.
- List = [not(Cond0) - CondInfo | ElseList],
- simplify__goal(conj(List) - GoalInfo, InstMap0, DetInfo,
- Goal - _, Msgs1),
- Msgs = [ite_cond_cannot_succeed(GoalInfo) | Msgs1]
-**********/
+ List = [Cond | ElseList],
+ simplify__goal(conj(List) - GoalInfo0, Goal - GoalInfo,
+ Info0, Info1),
+ goal_info_get_context(GoalInfo, Context),
+ simplify_info_add_msg(Info1, ite_cond_cannot_succeed(Context),
+ 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) - GoalInfo, Goal - _, Info0, Info)
+ simplify__goal(conj(List) - GoalInfo0, Goal - GoalInfo,
+ Info0, Info)
;
simplify__goal(Cond0, Cond, Info0, Info1),
simplify_info_update_instmap(Info1, Cond, Info2),
@@ -523,7 +549,8 @@
goal_info_get_instmap_delta(ElseInfo, ElseDelta),
simplify_info_create_branch_info(Info0, Info6,
[ElseDelta, CondThenDelta], Info),
- Goal = if_then_else(Vars, Cond, Then, Else, SM)
+ Goal = if_then_else(Vars, Cond, Then, Else, SM),
+ GoalInfo = GoalInfo0
).
simplify__goal_2(not(Goal0), GoalInfo, Goal, GoalInfo, Info0, Info) :-
@@ -532,24 +559,38 @@
simplify_info_get_common_info(Info0, Common),
simplify__goal(Goal0, Goal1, Info0, Info1),
simplify_info_set_common_info(Info1, Common, Info2),
+ Goal1 = _ - GoalInfo1,
+ goal_info_get_determinism(GoalInfo1, Detism),
+ determinism_components(Detism, CanFail, MaxSoln),
+ ( CanFail = cannot_fail ->
+ goal_info_get_context(GoalInfo, Context),
+ simplify_info_add_msg(Info2,
+ negated_goal_cannot_fail(Context), Info)
+ ; MaxSoln = at_most_zero ->
+ goal_info_get_context(GoalInfo, Context),
+ simplify_info_add_msg(Info2,
+ negated_goal_cannot_succeed(Context), Info)
+ ;
+ Info = Info2
+ ),
(
% replace `not true' with `fail'
Goal1 = conj([]) - _GoalInfo
->
map__init(Empty),
- Goal = disj([], Empty),
- simplify_info_add_msg(Info2,
- negated_goal_cannot_fail(GoalInfo), Info)
+ Goal = disj([], Empty)
;
% replace `not fail' with `true'
Goal1 = disj([], _) - _GoalInfo2
->
- Goal = conj([]),
- simplify_info_add_msg(Info1,
- negated_goal_cannot_succeed(GoalInfo), Info)
+ Goal = conj([])
;
- Goal = not(Goal1),
- Info = Info2
+ % remove double negation
+ Goal1 = not(SubGoal - _) - _
+ ->
+ Goal = SubGoal
+ ;
+ Goal = not(Goal1)
).
simplify__goal_2(some(Vars1, Goal1), SomeInfo, Goal, SomeInfo, Info0, Info) :-
@@ -1004,7 +1045,8 @@
determinism_components(Detism, _, MaxSolns),
MaxSolns = at_most_zero
->
- simplify_info_add_msg(Info4, zero_soln_disjunct(GoalInfo),
+ goal_info_get_context(GoalInfo, Context),
+ simplify_info_add_msg(Info4, zero_soln_disjunct(Context),
Info)
;
Info = Info4
@@ -1139,8 +1181,8 @@
).
simplify_info_init(DetInfo, Simplify, InstMap, VarSet, VarTypes, Info) :-
- set__init(Msgs),
common_info_init(CommonInfo),
+ set__init(Msgs),
Info = simplify_info(DetInfo, Msgs, Simplify, CommonInfo,
InstMap, VarSet, VarTypes, no, no, no).
Index: unique_modes.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/unique_modes.m,v
retrieving revision 1.34
diff -u -r1.34 unique_modes.m
--- unique_modes.m 1997/04/08 02:26:43 1.34
+++ unique_modes.m 1997/04/15 07:10:19
@@ -452,32 +452,6 @@
mode_info_dcg_get_instmap(InstMapC),
mode_info_set_instmap(InstMap0),
instmap__merge(NonLocals, [InstMapB, InstMapC], if_then_else),
-/*
-% this optimization from modes.m does not need to be repeated here
- ( { InstMapA = unreachable } ->
- % if the condition can never succeed, we delete the
- % unreachable `then' part by replacing
- % if some [Vs] A then B else C
- % with
- % (not some [Vs] A), C
- { A = _A_Goal - A_GoalInfo },
- { goal_info_get_nonlocals(A_GoalInfo, A_Vars) },
- { set__union(NonLocals, C_Vars, OutsideVars) },
- { set__delete_list(OutsideVars, Vs, OutsideVars1) },
- { set__intersect(OutsideVars1, A_Vars, SomeA_NonLocals) },
- { goal_info_init(EmptyGoalInfo) },
- { goal_info_set_nonlocals(EmptyGoalInfo, SomeA_NonLocals,
- SomeA_GoalInfo) },
- { map__init(EmptyInstmapDelta) },
- { goal_info_set_instmap_delta(SomeA_GoalInfo,
- reachable(EmptyInstmapDelta), NotSomeA_GoalInfo) },
-
- { Goal = conj([not(some(Vs, A) - SomeA_GoalInfo) -
- NotSomeA_GoalInfo, C]) }
- ;
- { Goal = if_then_else(Vs, A, B, C) }
- ),
-*/
{ Goal = if_then_else(Vs, A, B, C, SM) },
mode_checkpoint(exit, "if-then-else").
More information about the developers
mailing list