for review: bug rerunning det_analysis

Simon Taylor stayl at cs.mu.OZ.AU
Tue Nov 3 15:56:47 AEDT 1998


Estimated hours taken: 1

compiler/simplify.m:
	Fix a bug - deforestation and simplify rerun quantification
	which can introduce new variables, but these variables were
	not in the proc_info in the predicate table which det_analysis
	looks up.

tests/valid/deforest_rerun_det.m:
	Test case.	

Index: simplify.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/simplify.m,v
retrieving revision 1.63
diff -u -t -u -r1.63 simplify.m
--- simplify.m	1998/09/10 06:38:28	1.63
+++ simplify.m	1998/10/27 03:55:22
@@ -223,22 +223,41 @@
                 % In the alias branch this is necessary anyway.
                 RecomputeAtomic = yes,
 
-                simplify_info_get_module_info(Info3, ModuleInfo1),
+                simplify_info_get_module_info(Info3, ModuleInfo3),
                 recompute_instmap_delta(RecomputeAtomic, Goal2, Goal3,
-                        InstMap0, ModuleInfo1, ModuleInfo),
-                simplify_info_set_module_info(Info3, ModuleInfo, Info)
+                        InstMap0, ModuleInfo3, ModuleInfo4),
+                simplify_info_set_module_info(Info3, ModuleInfo4, Info4)
         ;
                 Goal3 = Goal1,
-                Info = Info1
+                Info4 = Info1
         ),
-        ( simplify_info_rerun_det(Info) ->
+        ( simplify_info_rerun_det(Info4) ->
                 Goal0 = _ - GoalInfo0,
                 goal_info_get_determinism(GoalInfo0, Det),
                 det_get_soln_context(Det, SolnContext),
+
+                % 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,
+                        PredInfo, ProcInfo0),
+                proc_info_set_vartypes(ProcInfo0, VarTypes4, ProcInfo1),
+                proc_info_set_varset(ProcInfo1, VarSet4, ProcInfo),
+                module_info_set_pred_proc_info(ModuleInfo5, PredId, ProcId,
+                        PredInfo, ProcInfo, ModuleInfo6),
+                simplify_info_set_module_info(Info4, ModuleInfo6, Info),
+
                 simplify_info_get_det_info(Info, DetInfo),
                 det_infer_goal(Goal3, InstMap0, SolnContext,
                         DetInfo, Goal, _, _)
         ;
+                Info = Info4,
                 Goal = Goal3
         ).

Index: Mmakefile
===================================================================
RCS file: /home/staff/zs/imp/tests/valid/Mmakefile,v
retrieving revision 1.26
diff -u -t -u -r1.26 Mmakefile
--- Mmakefile	1998/10/28 01:52:01	1.26
+++ Mmakefile	1998/11/03 04:55:37
@@ -25,6 +25,7 @@
         complicated_unify.m \
         constructor_arg_names.m \
         dcg_test.m \
+        deforest_rerun_det.m \
         det_condition.m \
         det_inference.m \
         det_switch.m \
@@ -152,6 +153,7 @@
 MCFLAGS-two_way_unif            = -O-1
 MCFLAGS-type_inf_ambig_test     = --infer-all
 MCFLAGS-vn_float                = -O5
+MCFLAGS-deforest_rerun_det      = -O3 --check-termination
 
 # intermod_lambda.m needs inter-module optimization
 intermod_lambda.c:


tests/valid/deforest_rerun_det.m:
===================================================================
% This is a regression test for an abort during deforestation caused
% by det_analysis looking at an out-of-date map(var, type).
%
:- module deforest_rerun_det.

:- interface.

:- import_module int.

:- pred bug(int::in, int::in, int::out) is semidet.

:- implementation.

bug(Int1, Int2, Result) :-
	compare_int(Int1, Int2, Res),	
	(
		Res = (<),
		Result = Int1
	;
		Res = (=),
		fail
	;
		Res = (>),
		Result = Int2
	).

:- pred compare_int(int::in, int::in, comparison_result::out) is det.

compare_int(Int1, Int2, Res) :-
	( Int1 < Int2 ->
		Res = (<)
	; Int1 = Int2 ->
		Res = (=)
	;
		Res = (>)
	).




More information about the developers mailing list