diff: bug fix
Simon TAYLOR
stayl at students.cs.mu.oz.au
Thu May 8 16:37:16 AEST 1997
Hi Fergus,
Could you please review this.
Simon.
Estimated hours taken: 1.5
Fix a determinism analysis abort ("inappropriate determinism inside a
negation") which was caused by det_analysis.m not updating the instmap
to include the initial insts of the lambda variables before processing
a lambda goal. This problem was also present in cse_detection.m and
simplify.m.
compiler/cse_detection.m
compiler/det_analysis.m
compiler/simplify.m
Make sure that the instmap is updated before processing a lambda goal.
compiler/switch_detection.m
compiler/instmap.m
Move some code to update the instmap before a lambda goal from
switch_detection.m into a new predicate instmap__pre_lambda_update/5,
which takes an instmap and a list of modes of a lambda expression,
and adds the initial insts of the lambda variables to the instmap.
tests/valid/Mmake
tests/valid/lambda_instmap_bug.m
Regression test.
Index: cse_detection.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/cse_detection.m,v
retrieving revision 1.42
diff -u -r1.42 cse_detection.m
--- cse_detection.m 1997/05/05 11:16:44 1.42
+++ cse_detection.m 1997/05/06 07:36:31
@@ -209,9 +209,12 @@
detect_cse_in_goal_2(call(A,B,C,D,E,F), _, _, CseInfo, CseInfo, no,
call(A,B,C,D,E,F)).
-detect_cse_in_goal_2(unify(A,B0,C,D,E), _, InstMap, CseInfo0, CseInfo, Redo,
+detect_cse_in_goal_2(unify(A,B0,C,D,E), _, InstMap0, CseInfo0, CseInfo, Redo,
unify(A,B,C,D,E)) :-
( B0 = lambda_goal(PredOrFunc, Vars, Modes, Det, Goal0) ->
+ CseInfo0 = cse_info(_, _, ModuleInfo),
+ instmap__pre_lambda_update(ModuleInfo,
+ Vars, Modes, InstMap0, InstMap),
detect_cse_in_goal(Goal0, InstMap, CseInfo0, CseInfo, Redo,
Goal),
B = lambda_goal(PredOrFunc, Vars, Modes, Det, Goal)
Index: det_analysis.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/det_analysis.m,v
retrieving revision 1.114
diff -u -r1.114 det_analysis.m
--- det_analysis.m 1997/05/05 11:16:49 1.114
+++ det_analysis.m 1997/05/06 07:36:46
@@ -448,7 +448,10 @@
;
LambdaSolnContext = all_solns
),
- det_infer_goal(Goal0, InstMap0, LambdaSolnContext, DetInfo,
+ det_info_get_module_info(DetInfo, ModuleInfo),
+ instmap__pre_lambda_update(ModuleInfo, Vars, Modes,
+ InstMap0, InstMap1),
+ det_infer_goal(Goal0, InstMap1, LambdaSolnContext, DetInfo,
Goal, LambdaInferredDet, Msgs1),
det_check_lambda(LambdaDeclaredDet, LambdaInferredDet,
Goal, GoalInfo, DetInfo, Msgs2),
Index: instmap.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/instmap.m,v
retrieving revision 1.6
diff -u -r1.6 instmap.m
--- instmap.m 1997/02/17 01:26:38 1.6
+++ instmap.m 1997/05/06 07:37:40
@@ -146,6 +146,12 @@
instmap, instmap, module_info, module_info).
:- mode instmap__bind_var_to_functor(in, in, in, out, in, out) is det.
+ % Update the given instmap to include the initial insts of the
+ % lambda variables.
+:- pred instmap__pre_lambda_update(module_info, list(var), list(mode),
+ instmap, instmap).
+:- mode instmap__pre_lambda_update(in, in, in, in, out) is det.
+
%-----------------------------------------------------------------------------%
% Given two instmaps and a set of variables, compute an instmap delta
@@ -422,6 +428,11 @@
%-----------------------------------------------------------------------------%
+instmap__pre_lambda_update(ModuleInfo, Vars, Modes, InstMap0, InstMap) :-
+ mode_list_get_initial_insts(Modes, ModuleInfo, Insts),
+ assoc_list__from_corresponding_lists(Vars, Insts, VarInsts),
+ instmap_delta_from_assoc_list(VarInsts, InstMapDelta),
+ instmap__apply_instmap_delta(InstMap0, InstMapDelta, InstMap).
%-----------------------------------------------------------------------------%
Index: simplify.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/simplify.m,v
retrieving revision 1.31
diff -u -r1.31 simplify.m
--- simplify.m 1997/05/05 11:17:30 1.31
+++ simplify.m 1997/05/06 07:37:00
@@ -440,8 +440,14 @@
LambdaGoal0)
->
simplify_info_get_common_info(Info0, Common),
- simplify__goal(LambdaGoal0, LambdaGoal, Info0, Info1),
- simplify_info_set_common_info(Info1, Common, Info),
+ simplify_info_get_module_info(Info0, ModuleInfo),
+ simplify_info_get_instmap(Info0, InstMap0),
+ instmap__pre_lambda_update(ModuleInfo, Vars, Modes,
+ InstMap0, InstMap1),
+ simplify_info_set_instmap(Info0, InstMap1, Info1),
+ simplify__goal(LambdaGoal0, LambdaGoal, Info1, Info2),
+ simplify_info_set_common_info(Info2, Common, Info3),
+ simplify_info_set_instmap(Info3, InstMap0, Info),
RT = lambda_goal(PredOrFunc, Vars, Modes, LambdaDeclaredDet,
LambdaGoal),
Goal = unify(LT0, RT, M, U0, C),
Index: switch_detection.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/switch_detection.m,v
retrieving revision 1.68
diff -u -r1.68 switch_detection.m
--- switch_detection.m 1997/05/05 11:17:34 1.68
+++ switch_detection.m 1997/05/06 07:37:16
@@ -168,10 +168,8 @@
( RHS0 = lambda_goal(PredOrFunc, Vars, Modes, Det, Goal0) ->
% we need to insert the initial insts for the lambda
% variables in the instmap before processing the lambda goal
- mode_list_get_initial_insts(Modes, ModuleInfo, Insts),
- assoc_list__from_corresponding_lists(Vars, Insts, VarInsts),
- instmap_delta_from_assoc_list(VarInsts, InstmapDelta),
- instmap__apply_instmap_delta(InstMap0, InstmapDelta, InstMap1),
+ instmap__pre_lambda_update(ModuleInfo,
+ Vars, Modes, InstMap0, InstMap1),
detect_switches_in_goal(Goal0, InstMap1, VarTypes, ModuleInfo,
Goal),
RHS = lambda_goal(PredOrFunc, Vars, Modes, Det, Goal)
% Regression test for a case where cse_detection.m, det_analysis.m
% and simplify.m were not updating the instmap before processing
% a lambda expression, causing an abort in determinism analysis.
:- module lambda_instmap_bug.
:- interface.
:- import_module set, std_util.
:- type instr == pair(instruction, string).
:- type instruction
---> clear(int)
; drop(int)
; join(int, int, int).
:- pred detect_streams(set(int), list(instr), list(instr)).
:- mode detect_streams(in, in, out) is det.
:- implementation.
:- import_module list.
detect_streams(Streams, Instrs0, Instrs) :-
% Don't attempt to clear or drop streams.
IsNotStreamClear =
lambda([Instr::in] is semidet, (
\+ (
( Instr = clear(Rel) - _
; Instr = drop(Rel) - _
),
set__member(Rel, Streams)
)
)),
list__filter(IsNotStreamClear, Instrs0, Instrs).
More information about the developers
mailing list