diff: bug fix
Simon TAYLOR
stayl at cs.mu.oz.au
Thu Jul 24 14:55:30 AEST 1997
Hi Fergus,
Could you please review this.
Simon.
Estimated hours taken: 1
compiler/simplify.m
compiler/higher_order.m
Fix some places where goal_info fields were not being filled
in correctly.
compiler/hlds_goal.m
Added goal_info_init/4 which takes the nonlocals, instmap_delta
and determinism of the goal. All goal_info_inits after determinism
analysis should probably use this version.
compiler/common.m
compiler/polymorphism.m
Use goal_info_init/4.
tests/general/prune_switch.m
Test case.
Index: common.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/common.m,v
retrieving revision 1.42
diff -u -r1.42 common.m
--- common.m 1997/07/24 01:26:18 1.42
+++ common.m 1997/07/24 01:59:51
@@ -599,15 +599,11 @@
UnifyContext = unify_context(explicit, []),
Goal = unify(OutputArg, var(OutputArg2),
UniMode, Unification, UnifyContext),
- goal_info_init(GoalInfo0),
- goal_info_set_determinism(GoalInfo0, det, GoalInfo1),
set__list_to_set([OutputArg, OutputArg2], GoalNonLocals),
- goal_info_set_nonlocals(GoalInfo1, GoalNonLocals, GoalInfo2),
set__list_to_set([OutputArg], OutputSet),
instmap_delta_restrict(InstMapDelta, OutputSet,
GoalInstMapDelta),
- goal_info_set_instmap_delta(GoalInfo2,
- GoalInstMapDelta, GoalInfo),
+ goal_info_init(GoalNonLocals, GoalInstMapDelta, det, GoalInfo),
common__create_output_unifications(NonLocals, InstMap,
InstMapDelta, OutputArgs, OutputArgs2, Goals1,
RecomputeAtomic1, RecomputeAtomic),
Index: higher_order.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/higher_order.m,v
retrieving revision 1.30
diff -u -r1.30 higher_order.m
--- higher_order.m 1997/07/24 01:26:24 1.30
+++ higher_order.m 1997/07/24 01:59:56
@@ -1146,18 +1146,17 @@
ModuleInfo, UniModes),
Unify = construct(LVar, pred_const(PredId, ProcId),
NewHeadVars0, UniModes),
- proc_info_inferred_determinism(ProcInfo3, Detism),
- pred_info_get_is_pred_or_func(PredInfo2, PredOrFunc),
+ proc_info_interface_determinism(CalledProcInfo, Detism),
+ pred_info_get_is_pred_or_func(CalledPredInfo, PredOrFunc),
PredInstInfo = pred_inst_info(PredOrFunc, UnCurriedArgModes, Detism),
Inst = ground(shared, yes(PredInstInfo)),
Unimode = (free -> Inst) - (Inst -> Inst),
Goal = unify(LVar, Rhs, Unimode, Unify, Context),
- goal_info_init(Info0),
- goal_info_set_determinism(Info0, Detism, Info1),
+ set__list_to_set([LVar | NewHeadVars0], NonLocals),
instmap_delta_init_reachable(InstmapDelta0),
instmap_delta_insert(InstmapDelta0, LVar, Inst, InstmapDelta),
- goal_info_set_instmap_delta(Info1, InstmapDelta, Info),
+ goal_info_init(NonLocals, InstmapDelta, det, Info),
construct_higher_order_terms(ModuleInfo, HeadVars1, HeadVars, ArgModes1,
ArgModes, HOArgs, ProcInfo3, ProcInfo, PredInfo2, PredInfo,
Substitution2, Substitution, Goals1),
Index: hlds_goal.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/hlds_goal.m,v
retrieving revision 1.36
diff -u -r1.36 hlds_goal.m
--- hlds_goal.m 1997/07/24 01:26:28 1.36
+++ hlds_goal.m 1997/07/24 01:59:57
@@ -473,6 +473,9 @@
:- pred goal_info_init(hlds_goal_info).
:- mode goal_info_init(out) is det.
+:- pred goal_info_init(set(var), instmap_delta, determinism, hlds_goal_info).
+:- mode goal_info_init(in, in, in, out) is det.
+
% Instead of recording the liveness of every variable at every
% part of the goal, we just keep track of the initial liveness
% and the changes in liveness.
@@ -647,6 +650,12 @@
GoalInfo = goal_info(PreBirths, PostBirths, PreDeaths, PostDeaths,
Detism, InstMapDelta, Context, NonLocals, no, Features,
no_resume_point).
+
+goal_info_init(NonLocals, InstMapDelta, Detism, GoalInfo) :-
+ goal_info_init(GoalInfo0),
+ goal_info_set_nonlocals(GoalInfo0, NonLocals, GoalInfo1),
+ goal_info_set_instmap_delta(GoalInfo1, InstMapDelta, GoalInfo2),
+ goal_info_set_determinism(GoalInfo2, Detism, GoalInfo).
goal_info_get_pre_births(GoalInfo, PreBirths) :-
GoalInfo = goal_info(PreBirths, _, _, _, _, _, _, _, _, _, _).
Index: polymorphism.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/polymorphism.m,v
retrieving revision 1.108
diff -u -r1.108 polymorphism.m
--- polymorphism.m 1997/07/24 01:27:05 1.108
+++ polymorphism.m 1997/07/24 02:00:05
@@ -934,14 +934,9 @@
% create a goal_info for the unification
- goal_info_init(CountGoalInfo0),
set__singleton_set(CountNonLocals, CountVar),
- goal_info_set_nonlocals(CountGoalInfo0, CountNonLocals,
- CountGoalInfo1),
instmap_delta_from_assoc_list([CountVar - CountInst], InstmapDelta),
- goal_info_set_instmap_delta(CountGoalInfo1, InstmapDelta,
- CountGoalInfo2),
- goal_info_set_determinism(CountGoalInfo2, det, CountGoalInfo),
+ goal_info_init(CountNonLocals, InstmapDelta, det, CountGoalInfo),
CountUnifyGoal = CountUnify - CountGoalInfo.
@@ -1011,12 +1006,9 @@
% create a goal_info for the unification
- goal_info_init(GoalInfo0),
set__singleton_set(NonLocals, Var),
- goal_info_set_nonlocals(GoalInfo0, NonLocals, GoalInfo1),
instmap_delta_from_assoc_list([Var - Inst], InstMapDelta),
- goal_info_set_instmap_delta(GoalInfo1, InstMapDelta, GoalInfo2),
- goal_info_set_determinism(GoalInfo2, det, GoalInfo),
+ goal_info_init(NonLocals, InstMapDelta, det, GoalInfo),
Goal = Unify - GoalInfo,
polymorphism__get_special_proc_list_2(Ids,
@@ -1127,9 +1119,7 @@
Unification, UnifyContext),
% create a goal_info for the unification
- goal_info_init(GoalInfo0),
set__list_to_set([TypeInfoVar | ArgVars], NonLocals),
- goal_info_set_nonlocals(GoalInfo0, NonLocals, GoalInfo1),
list__duplicate(NumArgVars, ground(shared, no), ArgInsts),
% note that we could perhaps be more accurate than
% `ground(shared)', but it shouldn't make any
@@ -1138,8 +1128,7 @@
instmap_delta_from_assoc_list(
[TypeInfoVar - bound(unique, [functor(InstConsId, ArgInsts)])],
InstMapDelta),
- goal_info_set_instmap_delta(GoalInfo1, InstMapDelta, GoalInfo2),
- goal_info_set_determinism(GoalInfo2, det, GoalInfo),
+ goal_info_init(NonLocals, InstMapDelta, det, GoalInfo),
TypeInfoGoal = Unify - GoalInfo.
@@ -1183,13 +1172,10 @@
Unification, UnifyContext),
% create a goal_info for the unification
- goal_info_init(GoalInfo0),
set__list_to_set([BaseTypeInfoVar], NonLocals),
- goal_info_set_nonlocals(GoalInfo0, NonLocals, GoalInfo1),
instmap_delta_from_assoc_list([BaseTypeInfoVar - ground(shared, no)],
InstmapDelta),
- goal_info_set_instmap_delta(GoalInfo1, InstmapDelta, GoalInfo2),
- goal_info_set_determinism(GoalInfo2, det, GoalInfo),
+ goal_info_init(NonLocals, InstmapDelta, det, GoalInfo),
BaseTypeInfoGoal = Unify - GoalInfo.
Index: simplify.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/simplify.m,v
retrieving revision 1.40
diff -u -r1.40 simplify.m
--- simplify.m 1997/07/24 01:27:16 1.40
+++ simplify.m 1997/07/24 02:00:09
@@ -359,14 +359,28 @@
->
simplify__create_test_unification(Var, ConsId, Arity,
UnifyGoal, Info0, Info1),
- conjoin_goals(UnifyGoal, SingleGoal0, Goal1)
+
+ % Conjoin the test and the rest of the case.
+ ( SingleGoal0 = conj(SingleGoalConj) - _ ->
+ GoalList = [UnifyGoal | SingleGoalConj]
+ ;
+ GoalList = [UnifyGoal, SingleGoal0]
+ ),
+ set__init(NonLocals),
+ instmap_delta_init_reachable(InstMapDelta),
+ goal_info_init(NonLocals, InstMapDelta, det,
+ CombinedGoalInfo0),
+ simplify__approximate_goal_info(GoalList,
+ CombinedGoalInfo0, CombinedGoalInfo),
+ simplify_info_set_requantify(Info1, Info2),
+ Goal1 = conj(GoalList) - CombinedGoalInfo
;
% The var can only be bound to this cons_id, so
% a test is unnecessary.
Goal1 = SingleGoal0,
- Info1 = Info0
+ Info2 = Info0
),
- simplify__goal(Goal1, Goal - GoalInfo, Info1, Info)
+ simplify__goal(Goal1, Goal - GoalInfo, Info2, Info)
;
GoalInfo = GoalInfo0,
simplify__switch(Var, Cases1, Cases, [], InstMaps,
@@ -1091,7 +1105,7 @@
),
InstToUniMode =
lambda([ArgInst::in, ArgUniMode::out] is det, (
- ArgUniMode = ((ArgInst - ArgInst) -> (free - ArgInst))
+ ArgUniMode = ((ArgInst - free) -> (ArgInst - ArgInst))
)),
list__map(InstToUniMode, ArgInsts, UniModes),
UniMode = (Inst0 -> Inst0) - (Inst0 -> Inst0),
@@ -1100,10 +1114,9 @@
ArgVars, UniModes, can_fail),
ExtraGoal = unify(Var, functor(ConsId, ArgVars),
UniMode, Unification, UnifyContext),
- goal_info_init(ExtraGoalInfo0),
set__singleton_set(NonLocals, Var),
- goal_info_set_nonlocals(ExtraGoalInfo0, NonLocals, ExtraGoalInfo1),
- goal_info_set_determinism(ExtraGoalInfo1, semidet, ExtraGoalInfo).
+ instmap_delta_init_reachable(InstMapDelta),
+ goal_info_init(NonLocals, InstMapDelta, semidet, ExtraGoalInfo).
%-----------------------------------------------------------------------------%
% Regression test for the switch pruning code in simplify.m.
:- module prune_switch.
:- interface.
:- import_module io.
:- pred main(io__state::di, io__state::uo) is det.
:- implementation.
:- type t
---> f(int)
; g(int)
; h(int).
main -->
{ create_switch_var(SwitchedOn) },
( (
{ SwitchedOn = f(Int) }
;
{ SwitchedOn = h(Int) }
)
->
io__write_int(Int)
;
io__write_string("Failed")
).
:- pred create_switch_var(t::out) is det.
create_switch_var(Var) :-
create_switch_var_2(Var).
:- pred create_switch_var_2(t::(free->bound(f(ground);g(ground)))) is det.
:- pragma no_inline(create_switch_var_2/1).
create_switch_var_2(f(1)).
More information about the developers
mailing list