[m-rev.] diff: fix goal scheduling problem

Julien Fischer juliensf at csse.unimelb.edu.au
Thu Nov 1 02:18:25 AEDT 2007


Estimated hours taken: 2
Branches: main

Fix a problem with conjunction re-ordering that was introduced by my
recent change to remove automatic solver type initialisation.
This was causing the stage 2 deep profiler to break.

compiler/modes.m:
 	Despite its name, modecheck_delayed_solver_goals, in fact
 	attempts to reschedule all goals, not just solver goals.
 	Call this predicate as we did before my previous change and
 	shift the code disables automatic initialisation to a place
 	where the rescheduling of non-solver goals will not be affected.

tests/valid/Mmakefile:
tests/valid/trace_goal_reorder.m:
 	A test case for the above bug.

Julien.

Index: compiler/modes.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/modes.m,v
retrieving revision 1.361
diff -u -r1.361 modes.m
--- compiler/modes.m	31 Oct 2007 03:58:28 -0000	1.361
+++ compiler/modes.m	31 Oct 2007 15:06:57 -0000
@@ -1198,7 +1198,7 @@
                  %
                  inst_match.inst_is_free(ModuleInfo, VarInst),
                  inst_match.inst_is_any(ModuleInfo, Inst),
-                type_is_solver_type_with_auto_init(ModuleInfo, Type), 
+                type_is_solver_type_with_auto_init(ModuleInfo, Type),
                  mode_info_solver_init_is_supported(!.ModeInfo)
              ->
                  prepend_initialisation_call(Var, Type, VarInst, !Goal,
@@ -2207,6 +2207,9 @@
      % from inst free to inst any. This predicate attempts to schedule
      % such goals.
      %
+    % XXX despite its name this predicate will in fact try to reschedule all
+    %     delayed goals, not just delayed solver goals.
+    %
  :- pred modecheck_delayed_solver_goals(conj_type::in, list(hlds_goal)::out,
      list(delayed_goal)::in, list(delayed_goal)::out,
      impurity_errors::in, impurity_errors::out,
@@ -2214,20 +2217,16 @@

  modecheck_delayed_solver_goals(ConjType, Goals, !DelayedGoals,
          !ImpurityErrors, !ModeInfo, !IO) :-
-    ( mode_info_solver_init_is_supported(!.ModeInfo) ->
-        % Try to handle any unscheduled goals by inserting solver
-        % initialisation calls, aiming for a deterministic schedule.
-        modecheck_delayed_goals_try_det(ConjType, !DelayedGoals,
-            Goals0, !ImpurityErrors, !ModeInfo, !IO),
-
-        % Try to handle any unscheduled goals by inserting solver
-        % initialisation calls, aiming for *any* workable schedule.
-        modecheck_delayed_goals_eager(ConjType, !DelayedGoals,
-            Goals1, !ImpurityErrors, !ModeInfo, !IO),
-        Goals = Goals0 ++ Goals1
-    ;
-        Goals = []
-    ).
+    % Try to handle any unscheduled goals by inserting solver
+    % initialisation calls, aiming for a deterministic schedule.
+    modecheck_delayed_goals_try_det(ConjType, !DelayedGoals,
+        Goals0, !ImpurityErrors, !ModeInfo, !IO),
+
+    % Try to handle any unscheduled goals by inserting solver
+    % initialisation calls, aiming for *any* workable schedule.
+    modecheck_delayed_goals_eager(ConjType, !DelayedGoals,
+        Goals1, !ImpurityErrors, !ModeInfo, !IO),
+    Goals = Goals0 ++ Goals1.

      % We may still have some unscheduled goals.  This may be because some
      % initialisation calls are needed to turn some solver type vars
@@ -2304,7 +2303,8 @@
                      map.lookup(VarTypes, Var, VarType),
                      type_is_solver_type_with_auto_init(ModuleInfo, VarType)
                  )
-            )
+            ),
+            mode_info_solver_init_is_supported(!.ModeInfo)
          ->
              % Construct the inferred initialisation goals
              % and try scheduling again.
Index: tests/valid/Mmakefile
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/valid/Mmakefile,v
retrieving revision 1.199
diff -u -r1.199 Mmakefile
--- tests/valid/Mmakefile	31 Oct 2007 13:27:24 -0000	1.199
+++ tests/valid/Mmakefile	31 Oct 2007 15:06:58 -0000
@@ -210,6 +210,7 @@
  	switches \
  	tabled_for_io \
  	tabled_io \
+	trace_goal_reorder \
  	transitive_instance \
  	tricky_assert2 \
  	tricky_ite \
Index: tests/valid/trace_goal_reorder.m
===================================================================
RCS file: tests/valid/trace_goal_reorder.m
diff -N tests/valid/trace_goal_reorder.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/valid/trace_goal_reorder.m	31 Oct 2007 15:06:58 -0000
@@ -0,0 +1,32 @@
+% The removal of automatic initialisation for solver types in 
+% rotd-2007-10-31 inadvertently weakened the scheduling of
+% delayed goals such as the trace goal below.
+:- module trace_goal_reorder. 
+:- interface.
+
+:- import_module io.
+:- import_module maybe.
+
+:- pred read_deep_byte(maybe_error(int)::out,
+    io::di, io::uo) is det.
+
+:- implementation.
+
+read_deep_byte(Res, !IO) :-
+    read_byte(Res0, !IO),
+    trace [compile_time(flag("debug_read_profdeep")), io(!IO)] (
+        io.write_string("byte ", !IO),
+        io.write(Res, !IO),
+        io.write_string("\n", !IO)
+    ),
+    (
+        Res0 = ok(Byte),
+        Res = ok(Byte)
+    ;
+        Res0 = eof,
+        Res = error("unexpected end of file")
+    ;
+        Res0 = error(Err),
+        io.error_message(Err, Msg),
+        Res = error(Msg)
+    ).

--------------------------------------------------------------------------
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