[m-rev.] For review: Move some goal path/id related code into mdbcomp

Paul Bone pbone at csse.unimelb.edu.au
Wed Jan 12 22:27:17 AEDT 2011


For review just incase anyone has a reason why this is bad as it creates a new
file in CVS which can't be undone nicely.

mdbcomp/goal_rep.m is not part of the diff, it is included below the diff in
this e-mail.

---

Move some of the goal path code from compiler/goal_path.m to the mdbcomp
library where it can be used by the deep profiler.

Also move the goal path code from program_representation.m to the new module,
goal_path.m in mdbcomp/

mdbcomp/goal_path.m:
    New module containing goal path code.

mdbcomp/program_representation.m:
    Original location of goal path code.

compiler/goal_path.m:
    Move some of this goal_path code into mdbcomp/goal_path.m

mdbcomp/feedback.automatic_parallelisation.m:
mdbcomp/rtti_access.m:
mdbcomp/slice_and_dice.m:
mdbcomp/trace_counts.m:
browser/debugger_interface.m:
browser/declarative_execution.m:
browser/declarative_tree.m:
compiler/build_mode_constraints.m:
compiler/call_gen.m:
compiler/code_info.m:
compiler/continuation_info.m:
compiler/coverage_profiling.m:
compiler/deep_profiling.m:
compiler/format_call.m:
compiler/goal_path.m:
compiler/goal_util.m:
compiler/hlds_data.m:
compiler/hlds_goal.m:
compiler/hlds_out_goal.m:
compiler/hlds_out_pred.m:
compiler/hlds_pred.m:
compiler/interval.m:
compiler/introduce_parallelism.m:
compiler/layout_out.m:
compiler/llds.m:
compiler/mode_constraint_robdd.m:
compiler/mode_constraints.m:
compiler/mode_ordering.m:
compiler/ordering_mode_constraints.m:
compiler/polymorphism.m:
compiler/post_typecheck.m:
compiler/prog_rep.m:
compiler/prop_mode_constraints.m:
compiler/push_goals_together.m:
compiler/rbmm.condition_renaming.m:
compiler/smm_common.m:
compiler/stack_layout.m:
compiler/stack_opt.m:
compiler/trace_gen.m:
compiler/tupling.m:
compiler/type_constraints.m:
compiler/typecheck.m:
compiler/unify_gen.m:
compiler/unneeded_code.m:
deep_profiler/Mmakefile:
deep_profiler/analysis_utils.m:
deep_profiler/coverage.m:
deep_profiler/create_report.m:
deep_profiler/display_report.m:
deep_profiler/dump.m:
deep_profiler/mdprof_fb.automatic_parallelism.m:
deep_profiler/message.m:
deep_profiler/old_query.m:
deep_profiler/profile.m:
deep_profiler/program_representation_utils.m:
deep_profiler/read_profile.m:
deep_profiler/recursion_patterns.m:
deep_profiler/report.m:
deep_profiler/var_use_analysis.m:
slice/Mmakefile:
slice/mcov.m:
    Conform to the move of the goal path code.

Index: browser/debugger_interface.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/debugger_interface.m,v
retrieving revision 1.28
diff -u -p -b -r1.28 debugger_interface.m
--- browser/debugger_interface.m	1 Dec 2006 15:03:43 -0000	1.28
+++ browser/debugger_interface.m	12 Jan 2011 11:17:02 -0000
@@ -42,8 +42,8 @@
 
 :- import_module mdb.interactive_query.
 :- import_module mdb.util.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.prim_data.
-:- import_module mdbcomp.program_representation.
 
 :- import_module io.
 :- import_module list.
Index: browser/declarative_execution.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/declarative_execution.m,v
retrieving revision 1.65
diff -u -p -b -r1.65 declarative_execution.m
--- browser/declarative_execution.m	26 Oct 2010 04:59:10 -0000	1.65
+++ browser/declarative_execution.m	12 Jan 2011 11:17:02 -0000
@@ -468,6 +468,7 @@
 :- implementation.
 
 :- import_module mdb.declarative_debugger.
+:- import_module mdbcomp.goal_path.
 
 :- import_module exception.
 :- import_module int.
Index: browser/declarative_tree.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/declarative_tree.m,v
retrieving revision 1.64
diff -u -p -b -r1.64 declarative_tree.m
--- browser/declarative_tree.m	30 Dec 2010 11:17:48 -0000	1.64
+++ browser/declarative_tree.m	12 Jan 2011 11:17:02 -0000
@@ -57,6 +57,7 @@
 :- import_module mdb.declarative_debugger.
 :- import_module mdb.io_action.
 :- import_module mdb.term_rep.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.prim_data.
 :- import_module mdbcomp.program_representation.
 :- import_module mdbcomp.rtti_access.
Index: compiler/build_mode_constraints.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/build_mode_constraints.m,v
retrieving revision 1.39
diff -u -p -b -r1.39 build_mode_constraints.m
--- compiler/build_mode_constraints.m	30 Dec 2010 11:17:52 -0000	1.39
+++ compiler/build_mode_constraints.m	12 Jan 2011 11:17:02 -0000
@@ -25,7 +25,7 @@
 :- import_module hlds.hlds_pred.
 :- import_module hlds.hlds_module.
 :- import_module mdbcomp.
-:- import_module mdbcomp.program_representation.
+:- import_module mdbcomp.goal_path.
 :- import_module parse_tree.
 :- import_module parse_tree.prog_data.
 
Index: compiler/call_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/call_gen.m,v
retrieving revision 1.198
diff -u -p -b -r1.198 call_gen.m
--- compiler/call_gen.m	20 Dec 2010 07:47:27 -0000	1.198
+++ compiler/call_gen.m	12 Jan 2011 11:17:02 -0000
@@ -73,6 +73,7 @@
 :- import_module ll_backend.code_util.
 :- import_module ll_backend.continuation_info.
 :- import_module ll_backend.trace_gen.
+:- import_module mdbcomp.goal_path.
 :- import_module parse_tree.prog_event.
 
 :- import_module bool.
Index: compiler/code_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/code_info.m,v
retrieving revision 1.381
diff -u -p -b -r1.381 code_info.m
--- compiler/code_info.m	30 Dec 2010 11:17:52 -0000	1.381
+++ compiler/code_info.m	12 Jan 2011 11:17:02 -0000
@@ -32,7 +32,6 @@
 
 :- import_module check_hlds.type_util.
 :- import_module hlds.code_model.
-:- import_module hlds.goal_path.
 :- import_module hlds.hlds_data.
 :- import_module hlds.hlds_goal.
 :- import_module hlds.hlds_llds.
@@ -46,7 +45,7 @@
 :- import_module ll_backend.llds.
 :- import_module ll_backend.trace_gen.
 :- import_module mdbcomp.prim_data.
-:- import_module mdbcomp.program_representation.
+:- import_module mdbcomp.goal_path.
 :- import_module parse_tree.prog_data.
 
 :- import_module assoc_list.
Index: compiler/continuation_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/continuation_info.m,v
retrieving revision 1.99
diff -u -p -b -r1.99 continuation_info.m
--- compiler/continuation_info.m	20 Dec 2010 07:47:29 -0000	1.99
+++ compiler/continuation_info.m	12 Jan 2011 11:17:02 -0000
@@ -64,7 +64,7 @@
 :- import_module ll_backend.llds.
 :- import_module ll_backend.trace_gen.
 :- import_module mdbcomp.prim_data.
-:- import_module mdbcomp.program_representation.
+:- import_module mdbcomp.goal_path.
 :- import_module parse_tree.prog_data.
 
 :- import_module assoc_list.
Index: compiler/coverage_profiling.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/coverage_profiling.m,v
retrieving revision 1.4
diff -u -p -b -r1.4 coverage_profiling.m
--- compiler/coverage_profiling.m	20 Dec 2010 07:47:29 -0000	1.4
+++ compiler/coverage_profiling.m	12 Jan 2011 11:17:02 -0000
@@ -15,10 +15,10 @@
 
 :- interface.
 
-:- import_module hlds.goal_path.
 :- import_module hlds.hlds_goal.
 :- import_module hlds.hlds_module.
 :- import_module hlds.hlds_pred.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.program_representation.
 :- import_module parse_tree.prog_data.
 
Index: compiler/deep_profiling.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/deep_profiling.m,v
retrieving revision 1.107
diff -u -p -b -r1.107 deep_profiling.m
--- compiler/deep_profiling.m	30 Dec 2010 11:17:53 -0000	1.107
+++ compiler/deep_profiling.m	12 Jan 2011 11:17:02 -0000
@@ -63,6 +63,7 @@
 :- import_module libs.globals.
 :- import_module libs.options.
 :- import_module ll_backend.coverage_profiling.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.prim_data.
 :- import_module mdbcomp.program_representation.
 :- import_module parse_tree.builtin_lib_types.
Index: compiler/format_call.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/format_call.m,v
retrieving revision 1.23
diff -u -p -b -r1.23 format_call.m
--- compiler/format_call.m	30 Dec 2010 11:17:54 -0000	1.23
+++ compiler/format_call.m	12 Jan 2011 11:17:02 -0000
@@ -144,7 +144,7 @@
 :- import_module libs.
 :- import_module libs.globals.
 :- import_module libs.options.
-:- import_module mdbcomp.program_representation.
+:- import_module mdbcomp.goal_path.
 :- import_module parse_tree.builtin_lib_types.
 
 :- import_module bool.
Index: compiler/goal_path.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/goal_path.m,v
retrieving revision 1.57
diff -u -p -b -r1.57 goal_path.m
--- compiler/goal_path.m	20 Dec 2010 07:47:30 -0000	1.57
+++ compiler/goal_path.m	12 Jan 2011 11:17:02 -0000
@@ -23,65 +23,10 @@
 :- import_module hlds.hlds_goal.
 :- import_module hlds.hlds_module.
 :- import_module hlds.hlds_pred.
-:- import_module mdbcomp.program_representation.
+:- import_module mdbcomp.goal_path.
 :- import_module parse_tree.
 :- import_module parse_tree.prog_data.
 
-:- import_module bimap.
-:- import_module map.
-
-:- type containing_goal
-    --->    whole_body_goal
-            % This goal is the entire body of its procedure.
-    ;       containing_goal(goal_id, goal_path_step).
-            % This goal is an contained immediately inside the larger goal
-            % identified by the goal_id, from which you need to take the
-            % given goal_path step to get to this goal.
-            %
-            % The goal_id of the containing goal is guaranteed to be always
-            % less than the goal_id of this goal.
-
-:- type containing_goal_map == map(goal_id, containing_goal).
-:- type goal_forward_path_map == map(goal_id, forward_goal_path).
-:- type goal_reverse_path_map == map(goal_id, reverse_goal_path).
-:- type goal_reverse_path_bimap == bimap(goal_id, reverse_goal_path).
-
-    % goal_id_inside(ContainingGoalMap, GoalIdA, GoalIdB):
-    %
-    % Succeeds if GoalIdB denotes a goal *inside* the goal denoted by GoalIdA.
-    % (It considers a goal to be inside itself.)
-    %
-:- pred goal_id_inside(containing_goal_map::in,
-    goal_id::in, goal_id::in) is semidet.
-
-    % Convert a goal_id to a forward goal path.
-    %
-:- func goal_id_to_forward_path(containing_goal_map, goal_id) =
-    forward_goal_path.
-
-    % Convert a goal_id to a reverse goal path.
-    %
-:- func goal_id_to_reverse_path(containing_goal_map, goal_id) =
-    reverse_goal_path.
-
-    % Given a containing_goal_map, create a map that maps each goal_id in it
-    % to a forwward goal path.
-    %
-:- func create_forward_goal_path_map(containing_goal_map) =
-    goal_forward_path_map.
-
-    % Given a containing_goal_map, create a map that maps each goal_id in it
-    % to a reverse goal path.
-    %
-:- func create_reverse_goal_path_map(containing_goal_map) =
-    goal_reverse_path_map.
-
-    % Given a containing_goal_map, create a map that maps each goal_id in it
-    % to a reverse goal path, and back.
-    %
-:- func create_reverse_goal_path_bimap(containing_goal_map) =
-    goal_reverse_path_bimap.
-
 %-----------------------------------------------------------------------------%
 
     % IMPORTANT: the type constraint_id in hlds_data.m makes use of goal ids
@@ -127,6 +72,7 @@
 :- import_module cord.
 :- import_module int.
 :- import_module list.
+:- import_module map.
 :- import_module maybe.
 :- import_module pair.
 :- import_module require.
@@ -135,105 +81,6 @@
 
 %-----------------------------------------------------------------------------%
 
-goal_id_inside(ContainingGoalId, GoalIdA, GoalIdB) :-
-    (
-        GoalIdB = GoalIdA
-    ;
-        map.lookup(ContainingGoalId, GoalIdB, GoalContainingB),
-        GoalContainingB = containing_goal(ParentGoalIdB, _),
-        goal_id_inside(ContainingGoalId, GoalIdA, ParentGoalIdB)
-    ).
-
-goal_id_to_forward_path(ContainingGoalMap, GoalId) = GoalPath :-
-    StepsCord = goal_id_to_steps(ContainingGoalMap, GoalId),
-    Steps = cord.list(StepsCord),
-    GoalPath = fgp(Steps).
-
-goal_id_to_reverse_path(ContainingGoalMap, GoalId) = GoalPath :-
-    StepsCord = goal_id_to_steps(ContainingGoalMap, GoalId),
-    Steps = cord.list(StepsCord),
-    list.reverse(Steps, RevSteps),
-    GoalPath = rgp(RevSteps).
-
-:- func goal_id_to_steps(containing_goal_map, goal_id) =
-    cord(goal_path_step).
-
-goal_id_to_steps(ContainingGoalMap, GoalId) = Steps :-
-    map.lookup(ContainingGoalMap, GoalId, ContainingGoal),
-    (
-        ContainingGoal = whole_body_goal,
-        Steps = cord.empty
-    ;
-        ContainingGoal = containing_goal(ParentGoalId, LastStep),
-        EarlierSteps = goal_id_to_steps(ContainingGoalMap, ParentGoalId),
-        Steps = cord.snoc(EarlierSteps, LastStep)
-    ).
-
-create_forward_goal_path_map(ContainingGoalMap) = ForwardGoalPathMap :-
-    ReverseGoalPathMap = create_reverse_goal_path_map(ContainingGoalMap),
-    map.map_values_only(rgp_to_fgp, ReverseGoalPathMap, ForwardGoalPathMap).
-
-:- pred rgp_to_fgp(reverse_goal_path::in, forward_goal_path::out) is det.
-
-rgp_to_fgp(rgp(RevSteps), fgp(Steps)) :-
-    list.reverse(RevSteps, Steps).
-
-create_reverse_goal_path_map(ContainingGoalMap) = ReverseGoalPathMap :-
-    map.to_assoc_list(ContainingGoalMap, ContainingGoalList),
-    create_reverse_goal_path_map_2(ContainingGoalList,
-        map.init, ReverseGoalPathMap).
-
-:- pred create_reverse_goal_path_map_2(
-    assoc_list(goal_id, containing_goal)::in,
-    map(goal_id, reverse_goal_path)::in, map(goal_id, reverse_goal_path)::out)
-    is det.
-
-create_reverse_goal_path_map_2([], !ReverseGoalPathMap).
-create_reverse_goal_path_map_2([Head | Tail], !ReverseGoalPathMap) :-
-    Head = GoalId - ContainingGoal,
-    (
-        ContainingGoal = whole_body_goal,
-        GoalReversePath = rgp([])
-    ;
-        ContainingGoal = containing_goal(ContainingGoalId, Step),
-        map.lookup(!.ReverseGoalPathMap, ContainingGoalId,
-            ContainingGoalReversePath),
-        ContainingGoalReversePath = rgp(ContainingGoalReverseSteps),
-        GoalReverseSteps = [Step | ContainingGoalReverseSteps],
-        GoalReversePath = rgp(GoalReverseSteps)
-    ),
-    svmap.det_insert(GoalId, GoalReversePath, !ReverseGoalPathMap),
-    create_reverse_goal_path_map_2(Tail, !ReverseGoalPathMap).
-
-create_reverse_goal_path_bimap(ContainingGoalMap) = ReverseGoalPathBiMap :-
-    map.to_assoc_list(ContainingGoalMap, ContainingGoalList),
-    create_reverse_goal_path_bimap_2(ContainingGoalList,
-        bimap.init, ReverseGoalPathBiMap).
-
-:- pred create_reverse_goal_path_bimap_2(
-    assoc_list(goal_id, containing_goal)::in,
-    bimap(goal_id, reverse_goal_path)::in,
-    bimap(goal_id, reverse_goal_path)::out) is det.
-
-create_reverse_goal_path_bimap_2([], !ReverseGoalPathBiMap).
-create_reverse_goal_path_bimap_2([Head | Tail], !ReverseGoalPathBiMap) :-
-    Head = GoalId - ContainingGoal,
-    (
-        ContainingGoal = whole_body_goal,
-        GoalReversePath = rgp([])
-    ;
-        ContainingGoal = containing_goal(ContainingGoalId, Step),
-        bimap.lookup(!.ReverseGoalPathBiMap, ContainingGoalId,
-            ContainingGoalReversePath),
-        ContainingGoalReversePath = rgp(ContainingGoalReverseSteps),
-        GoalReverseSteps = [Step | ContainingGoalReverseSteps],
-        GoalReversePath = rgp(GoalReverseSteps)
-    ),
-    svbimap.det_insert(GoalId, GoalReversePath, !ReverseGoalPathBiMap),
-    create_reverse_goal_path_bimap_2(Tail, !ReverseGoalPathBiMap).
-
-%-----------------------------------------------------------------------------%
-
 :- type slot_info
     --->    slot_info(
                 slot_info_module_info               :: module_info,
Index: compiler/goal_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/goal_util.m,v
retrieving revision 1.179
diff -u -p -b -r1.179 goal_util.m
--- compiler/goal_util.m	3 Jan 2011 06:25:39 -0000	1.179
+++ compiler/goal_util.m	12 Jan 2011 11:17:03 -0000
@@ -25,8 +25,8 @@
 :- import_module hlds.hlds_rtti.
 :- import_module hlds.instmap.
 :- import_module hlds.pred_table.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.prim_data.
-:- import_module mdbcomp.program_representation.
 :- import_module parse_tree.prog_data.
 
 :- import_module bool.
Index: compiler/hlds_data.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_data.m,v
retrieving revision 1.132
diff -u -p -b -r1.132 hlds_data.m
--- compiler/hlds_data.m	4 Jan 2011 03:51:09 -0000	1.132
+++ compiler/hlds_data.m	12 Jan 2011 11:17:03 -0000
@@ -19,8 +19,8 @@
 
 :- import_module hlds.hlds_pred.
 :- import_module libs.globals.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.prim_data.
-:- import_module mdbcomp.program_representation.
 :- import_module parse_tree.prog_data.
 
 :- import_module assoc_list.
Index: compiler/hlds_goal.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_goal.m,v
retrieving revision 1.220
diff -u -p -b -r1.220 hlds_goal.m
--- compiler/hlds_goal.m	30 Dec 2010 11:17:54 -0000	1.220
+++ compiler/hlds_goal.m	12 Jan 2011 11:17:03 -0000
@@ -21,8 +21,9 @@
 :- import_module hlds.hlds_llds.
 :- import_module hlds.hlds_pred.
 :- import_module hlds.instmap.
+:- import_module mdbcomp.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.prim_data.
-:- import_module mdbcomp.program_representation.
 :- import_module parse_tree.prog_data.
 
 :- import_module bool.
Index: compiler/hlds_out_goal.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_out_goal.m,v
retrieving revision 1.4
diff -u -p -b -r1.4 hlds_out_goal.m
--- compiler/hlds_out_goal.m	29 Dec 2010 04:52:17 -0000	1.4
+++ compiler/hlds_out_goal.m	12 Jan 2011 11:17:03 -0000
@@ -118,8 +118,8 @@
 :- import_module hlds.hlds_pred.
 :- import_module hlds.instmap.
 :- import_module libs.globals.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.prim_data.
-:- import_module mdbcomp.program_representation.
 :- import_module parse_tree.mercury_to_mercury.
 :- import_module parse_tree.prog_mode.
 :- import_module parse_tree.prog_out.
Index: compiler/hlds_out_pred.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_out_pred.m,v
retrieving revision 1.4
diff -u -p -b -r1.4 hlds_out_pred.m
--- compiler/hlds_out_pred.m	2 Jan 2011 14:37:54 -0000	1.4
+++ compiler/hlds_out_pred.m	12 Jan 2011 11:17:03 -0000
@@ -78,6 +78,7 @@
 :- import_module hlds.hlds_out.hlds_out_goal.
 :- import_module hlds.hlds_out.hlds_out_mode.
 :- import_module hlds.hlds_rtti.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.program_representation.
 :- import_module parse_tree.mercury_to_mercury.
 :- import_module parse_tree.prog_ctgc.
Index: compiler/hlds_pred.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_pred.m,v
retrieving revision 1.264
diff -u -p -b -r1.264 hlds_pred.m
--- compiler/hlds_pred.m	2 Jan 2011 14:37:54 -0000	1.264
+++ compiler/hlds_pred.m	12 Jan 2011 11:17:03 -0000
@@ -31,6 +31,7 @@
 :- import_module hlds.pred_table.
 :- import_module hlds.special_pred.
 :- import_module libs.globals.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.prim_data.
 :- import_module mdbcomp.program_representation.
 :- import_module parse_tree.prog_data.
@@ -59,7 +60,6 @@
 :- import_module hlds.hlds_rtti.
 :- import_module hlds.special_pred.
 :- import_module libs.options.
-:- import_module mdbcomp.program_representation.
 :- import_module parse_tree.prog_type.
 :- import_module parse_tree.prog_util.
 
Index: compiler/interval.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/interval.m,v
retrieving revision 1.46
diff -u -p -b -r1.46 interval.m
--- compiler/interval.m	30 Dec 2010 11:17:55 -0000	1.46
+++ compiler/interval.m	12 Jan 2011 11:17:03 -0000
@@ -36,7 +36,7 @@
 :- import_module hlds.hlds_goal.
 :- import_module hlds.hlds_module.
 :- import_module mdbcomp.
-:- import_module mdbcomp.program_representation.
+:- import_module mdbcomp.goal_path.
 :- import_module parse_tree.
 :- import_module parse_tree.prog_data.
 
Index: compiler/introduce_parallelism.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/introduce_parallelism.m,v
retrieving revision 1.1
diff -u -p -b -r1.1 introduce_parallelism.m
--- compiler/introduce_parallelism.m	4 Jan 2011 05:31:38 -0000	1.1
+++ compiler/introduce_parallelism.m	12 Jan 2011 11:17:03 -0000
@@ -49,6 +49,7 @@
 :- import_module ll_backend.stack_layout.
 :- import_module mdbcomp.feedback.
 :- import_module mdbcomp.feedback.automatic_parallelism.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.prim_data.
 :- import_module mdbcomp.program_representation.
 :- import_module parse_tree.error_util.
Index: compiler/layout_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/layout_out.m,v
retrieving revision 1.113
diff -u -p -b -r1.113 layout_out.m
--- compiler/layout_out.m	30 Dec 2010 11:17:55 -0000	1.113
+++ compiler/layout_out.m	12 Jan 2011 11:17:03 -0000
@@ -177,6 +177,7 @@
 :- import_module libs.trace_params.
 :- import_module ll_backend.llds_out.llds_out_code_addr.
 :- import_module ll_backend.llds_out.llds_out_data.
+:- import_module mdbcomp.goal_path.
 :- import_module parse_tree.mercury_to_mercury.
 :- import_module parse_tree.prog_data.
 :- import_module parse_tree.prog_foreign.
Index: compiler/llds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds.m,v
retrieving revision 1.370
diff -u -p -b -r1.370 llds.m
--- compiler/llds.m	20 Dec 2010 07:47:33 -0000	1.370
+++ compiler/llds.m	12 Jan 2011 11:17:03 -0000
@@ -27,6 +27,7 @@
 :- import_module hlds.hlds_module.
 :- import_module hlds.hlds_pred.
 :- import_module ll_backend.layout.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.prim_data.
 :- import_module mdbcomp.program_representation.
 :- import_module parse_tree.prog_data.
Index: compiler/mode_constraint_robdd.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mode_constraint_robdd.m,v
retrieving revision 1.17
diff -u -p -b -r1.17 mode_constraint_robdd.m
--- compiler/mode_constraint_robdd.m	30 Dec 2010 11:17:56 -0000	1.17
+++ compiler/mode_constraint_robdd.m	12 Jan 2011 11:17:03 -0000
@@ -26,10 +26,9 @@
 :- import_module parse_tree.
 :- import_module parse_tree.prog_data.
 :- import_module hlds.
-:- import_module hlds.goal_path.
 :- import_module hlds.hlds_pred.
 :- import_module mdbcomp.
-:- import_module mdbcomp.program_representation.
+:- import_module mdbcomp.goal_path.
 :- import_module mode_robdd.
 
 :- import_module bool.
Index: compiler/mode_constraints.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mode_constraints.m,v
retrieving revision 1.59
diff -u -p -b -r1.59 mode_constraints.m
--- compiler/mode_constraints.m	4 Jan 2011 03:51:09 -0000	1.59
+++ compiler/mode_constraints.m	12 Jan 2011 11:17:03 -0000
@@ -65,7 +65,7 @@
 :- import_module libs.globals.
 :- import_module libs.options.
 :- import_module mdbcomp.
-:- import_module mdbcomp.program_representation.
+:- import_module mdbcomp.goal_path.
 :- import_module mode_robdd.
 % :- import_module mode_robdd.check.
 % :- import_module mode_robdd.tfeir.
Index: compiler/mode_ordering.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mode_ordering.m,v
retrieving revision 1.33
diff -u -p -b -r1.33 mode_ordering.m
--- compiler/mode_ordering.m	2 Jan 2011 14:37:56 -0000	1.33
+++ compiler/mode_ordering.m	12 Jan 2011 11:17:03 -0000
@@ -53,7 +53,7 @@
 % :- import_module mode_robdd.tfeir.
 :- import_module mode_robdd.tfeirn.
 :- import_module mdbcomp.
-:- import_module mdbcomp.program_representation.
+:- import_module mdbcomp.goal_path.
 :- import_module parse_tree.
 :- import_module parse_tree.prog_data.
 
Index: compiler/ordering_mode_constraints.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ordering_mode_constraints.m,v
retrieving revision 1.28
diff -u -p -b -r1.28 ordering_mode_constraints.m
--- compiler/ordering_mode_constraints.m	2 Jan 2011 14:37:57 -0000	1.28
+++ compiler/ordering_mode_constraints.m	12 Jan 2011 11:17:03 -0000
@@ -21,9 +21,9 @@
 :- import_module check_hlds.build_mode_constraints.
 :- import_module check_hlds.prop_mode_constraints.
 :- import_module hlds.
-:- import_module hlds.goal_path.
 :- import_module hlds.hlds_pred.
 :- import_module hlds.hlds_module.
+:- import_module mdbcomp.goal_path.
 
 :- import_module io.
 :- import_module list.
@@ -112,7 +112,6 @@
 :- import_module libs.
 :- import_module libs.globals.
 :- import_module mdbcomp.
-:- import_module mdbcomp.program_representation.
 :- import_module parse_tree.
 :- import_module parse_tree.error_util.
 :- import_module parse_tree.prog_data.
Index: compiler/polymorphism.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/polymorphism.m,v
retrieving revision 1.356
diff -u -p -b -r1.356 polymorphism.m
--- compiler/polymorphism.m	2 Jan 2011 14:37:57 -0000	1.356
+++ compiler/polymorphism.m	12 Jan 2011 11:17:03 -0000
@@ -401,6 +401,7 @@
 :- import_module libs.
 :- import_module libs.globals.
 :- import_module libs.options.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.prim_data.
 :- import_module mdbcomp.program_representation.
 :- import_module parse_tree.builtin_lib_types.
Index: compiler/post_typecheck.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/post_typecheck.m,v
retrieving revision 1.143
diff -u -p -b -r1.143 post_typecheck.m
--- compiler/post_typecheck.m	20 Dec 2010 07:47:36 -0000	1.143
+++ compiler/post_typecheck.m	12 Jan 2011 11:17:03 -0000
@@ -137,7 +137,7 @@
 :- import_module libs.
 :- import_module libs.globals.
 :- import_module libs.options.
-:- import_module mdbcomp.program_representation.
+:- import_module mdbcomp.goal_path.
 :- import_module parse_tree.builtin_lib_types.
 :- import_module parse_tree.mercury_to_mercury.
 :- import_module parse_tree.prog_type.
Index: compiler/prog_rep.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_rep.m,v
retrieving revision 1.72
diff -u -p -b -r1.72 prog_rep.m
--- compiler/prog_rep.m	30 Dec 2010 11:17:57 -0000	1.72
+++ compiler/prog_rep.m	12 Jan 2011 11:17:03 -0000
@@ -24,8 +24,8 @@
 :- import_module hlds.hlds_module.
 :- import_module hlds.instmap.
 :- import_module ll_backend.stack_layout.
-:- import_module parse_tree.prog_data.
 :- import_module mdbcomp.program_representation.
+:- import_module parse_tree.prog_data.
 
 :- import_module list.
 :- import_module map.
@@ -85,6 +85,7 @@
 :- import_module hlds.code_model.
 :- import_module hlds.hlds_pred.
 :- import_module mdbcomp.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.prim_data.
 :- import_module parse_tree.prog_util.
 
Index: compiler/prop_mode_constraints.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prop_mode_constraints.m,v
retrieving revision 1.29
diff -u -p -b -r1.29 prop_mode_constraints.m
--- compiler/prop_mode_constraints.m	2 Jan 2011 14:37:58 -0000	1.29
+++ compiler/prop_mode_constraints.m	12 Jan 2011 11:17:03 -0000
@@ -22,9 +22,10 @@
 :- import_module check_hlds.abstract_mode_constraints.
 :- import_module check_hlds.build_mode_constraints.
 :- import_module hlds.
-:- import_module hlds.goal_path.
 :- import_module hlds.hlds_module.
 :- import_module hlds.hlds_pred.
+:- import_module mdbcomp.
+:- import_module mdbcomp.goal_path.
 
 :- import_module io.
 :- import_module list.
@@ -79,6 +80,7 @@
 
 :- implementation.
 
+:- import_module hlds.goal_path.
 :- import_module hlds.hlds_args.
 :- import_module hlds.hlds_clauses.
 :- import_module hlds.hlds_error_util.
Index: compiler/push_goals_together.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/push_goals_together.m,v
retrieving revision 1.5
diff -u -p -b -r1.5 push_goals_together.m
--- compiler/push_goals_together.m	5 Jan 2011 22:58:59 -0000	1.5
+++ compiler/push_goals_together.m	12 Jan 2011 11:17:03 -0000
@@ -60,7 +60,7 @@
 :- import_module hlds.quantification.
 :- import_module mdbcomp.feedback.
 :- import_module mdbcomp.feedback.automatic_parallelism.
-:- import_module mdbcomp.program_representation.
+:- import_module mdbcomp.goal_path.
 :- import_module parse_tree.prog_data.
 
 :- import_module assoc_list.
Index: compiler/rbmm.condition_renaming.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/rbmm.condition_renaming.m,v
retrieving revision 1.15
diff -u -p -b -r1.15 rbmm.condition_renaming.m
--- compiler/rbmm.condition_renaming.m	30 Dec 2010 11:17:57 -0000	1.15
+++ compiler/rbmm.condition_renaming.m	12 Jan 2011 11:17:03 -0000
@@ -42,7 +42,7 @@
 :- import_module hlds.hlds_module.
 :- import_module hlds.hlds_pred.
 :- import_module mdbcomp.
-:- import_module mdbcomp.program_representation.
+:- import_module mdbcomp.goal_path.
 :- import_module transform_hlds.rbmm.points_to_info.
 :- import_module transform_hlds.rbmm.region_liveness_info.
 :- import_module transform_hlds.rbmm.region_resurrection_renaming.
Index: compiler/smm_common.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/smm_common.m,v
retrieving revision 1.8
diff -u -p -b -r1.8 smm_common.m
--- compiler/smm_common.m	30 Dec 2010 11:17:58 -0000	1.8
+++ compiler/smm_common.m	12 Jan 2011 11:17:03 -0000
@@ -22,7 +22,7 @@
 :- import_module hlds.hlds_pred.
 :- import_module hlds.hlds_module.
 :- import_module mdbcomp.
-:- import_module mdbcomp.program_representation.
+:- import_module mdbcomp.goal_path.
 :- import_module parse_tree.
 :- import_module parse_tree.prog_data.
 
Index: compiler/stack_layout.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/stack_layout.m,v
retrieving revision 1.154
diff -u -p -b -r1.154 stack_layout.m
--- compiler/stack_layout.m	30 Dec 2010 11:17:58 -0000	1.154
+++ compiler/stack_layout.m	12 Jan 2011 11:17:03 -0000
@@ -113,6 +113,7 @@
 :- import_module ll_backend.layout_out.
 :- import_module ll_backend.ll_pseudo_type_info.
 :- import_module ll_backend.trace_gen.
+:- import_module mdbcomp.goal_path.
 :- import_module parse_tree.prog_event.
 
 :- import_module bool.
Index: compiler/stack_opt.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/stack_opt.m,v
retrieving revision 1.47
diff -u -p -b -r1.47 stack_opt.m
--- compiler/stack_opt.m	30 Dec 2010 11:17:58 -0000	1.47
+++ compiler/stack_opt.m	12 Jan 2011 11:17:03 -0000
@@ -102,7 +102,7 @@
 :- import_module ll_backend.live_vars.
 :- import_module ll_backend.liveness.
 :- import_module ll_backend.store_alloc.
-:- import_module mdbcomp.program_representation.
+:- import_module mdbcomp.goal_path.
 :- import_module parse_tree.prog_data.
 :- import_module parse_tree.prog_type.
 
Index: compiler/trace_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/trace_gen.m,v
retrieving revision 1.33
diff -u -p -b -r1.33 trace_gen.m
--- compiler/trace_gen.m	3 Jan 2011 01:55:27 -0000	1.33
+++ compiler/trace_gen.m	12 Jan 2011 11:17:03 -0000
@@ -55,7 +55,7 @@
 :- import_module ll_backend.code_info.
 :- import_module ll_backend.continuation_info.
 :- import_module ll_backend.llds.
-:- import_module mdbcomp.program_representation.
+:- import_module mdbcomp.goal_path.
 :- import_module parse_tree.prog_data.
 
 :- import_module assoc_list.
Index: compiler/tupling.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/tupling.m,v
retrieving revision 1.55
diff -u -p -b -r1.55 tupling.m
--- compiler/tupling.m	30 Dec 2010 11:17:59 -0000	1.55
+++ compiler/tupling.m	12 Jan 2011 11:17:03 -0000
@@ -115,8 +115,8 @@
 :- import_module ll_backend.call_gen.
 :- import_module ll_backend.live_vars.
 :- import_module ll_backend.liveness.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.prim_data.
-:- import_module mdbcomp.program_representation.
 :- import_module mdbcomp.trace_counts.
 :- import_module parse_tree.prog_data.
 :- import_module parse_tree.prog_mode.
Index: compiler/type_constraints.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/type_constraints.m,v
retrieving revision 1.12
diff -u -p -b -r1.12 type_constraints.m
--- compiler/type_constraints.m	2 Jan 2011 14:37:59 -0000	1.12
+++ compiler/type_constraints.m	12 Jan 2011 11:17:03 -0000
@@ -41,8 +41,8 @@
 :- import_module hlds.pred_table.
 :- import_module hlds.special_pred.
 :- import_module mdbcomp.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.prim_data.
-:- import_module mdbcomp.program_representation.
 :- import_module parse_tree.builtin_lib_types.
 :- import_module parse_tree.mercury_to_mercury.
 :- import_module parse_tree.prog_data.
Index: compiler/typecheck.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/typecheck.m,v
retrieving revision 1.452
diff -u -p -b -r1.452 typecheck.m
--- compiler/typecheck.m	2 Jan 2011 14:37:59 -0000	1.452
+++ compiler/typecheck.m	12 Jan 2011 11:17:03 -0000
@@ -119,8 +119,8 @@
 :- import_module libs.globals.
 :- import_module libs.options.
 :- import_module mdbcomp.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.prim_data.
-:- import_module mdbcomp.program_representation.
 :- import_module parse_tree.mercury_to_mercury.
 :- import_module parse_tree.builtin_lib_types.
 :- import_module parse_tree.file_names.         % undesirable dependency
Index: compiler/unify_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/unify_gen.m,v
retrieving revision 1.200
diff -u -p -b -r1.200 unify_gen.m
--- compiler/unify_gen.m	20 Dec 2010 07:47:39 -0000	1.200
+++ compiler/unify_gen.m	12 Jan 2011 11:17:03 -0000
@@ -76,8 +76,8 @@
 :- import_module ll_backend.global_data.
 :- import_module ll_backend.layout.
 :- import_module ll_backend.stack_layout.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.prim_data.
-:- import_module mdbcomp.program_representation.
 :- import_module parse_tree.prog_data.
 :- import_module parse_tree.prog_type.
 
Index: compiler/unneeded_code.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/unneeded_code.m,v
retrieving revision 1.58
diff -u -p -b -r1.58 unneeded_code.m
--- compiler/unneeded_code.m	3 Jan 2011 01:55:27 -0000	1.58
+++ compiler/unneeded_code.m	12 Jan 2011 11:17:03 -0000
@@ -85,7 +85,7 @@
 :- import_module hlds.quantification.
 :- import_module libs.globals.
 :- import_module libs.options.
-:- import_module mdbcomp.program_representation.
+:- import_module mdbcomp.goal_path.
 :- import_module parse_tree.prog_data.
 
 :- import_module assoc_list.
Index: deep_profiler/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/Mmakefile,v
retrieving revision 1.36
diff -u -p -b -r1.36 Mmakefile
--- deep_profiler/Mmakefile	30 Sep 2010 07:23:32 -0000	1.36
+++ deep_profiler/Mmakefile	12 Jan 2011 11:17:03 -0000
@@ -58,8 +58,9 @@ VPATH = $(LIBRARY_DIR) $(SSDB_DIR)
 #-----------------------------------------------------------------------------#
 
 MDBCOMP_MODULES = \
-	feedback.m \
 	feedback.automatic_parallelism.m \
+	feedback.m \
+	goal_path.m \
 	mdbcomp.m \
 	prim_data.m \
 	program_representation.m \
Index: deep_profiler/analysis_utils.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/analysis_utils.m,v
retrieving revision 1.5
diff -u -p -b -r1.5 analysis_utils.m
--- deep_profiler/analysis_utils.m	6 Jan 2011 11:23:43 -0000	1.5
+++ deep_profiler/analysis_utils.m	12 Jan 2011 11:17:03 -0000
@@ -18,6 +18,7 @@
 :- interface.
 
 :- import_module mdbcomp.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.program_representation.
 :- import_module measurements.
 :- import_module profile.
Index: deep_profiler/coverage.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/coverage.m,v
retrieving revision 1.11
diff -u -p -b -r1.11 coverage.m
--- deep_profiler/coverage.m	20 Dec 2010 07:47:45 -0000	1.11
+++ deep_profiler/coverage.m	12 Jan 2011 11:17:03 -0000
@@ -18,6 +18,7 @@
 :- interface.
 
 :- import_module mdbcomp.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.program_representation.
 :- import_module measurements.
 
Index: deep_profiler/create_report.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/create_report.m,v
retrieving revision 1.31
diff -u -p -b -r1.31 create_report.m
--- deep_profiler/create_report.m	6 Jan 2011 11:23:43 -0000	1.31
+++ deep_profiler/create_report.m	12 Jan 2011 11:17:03 -0000
@@ -86,6 +86,7 @@
 :- import_module coverage.
 :- import_module exclude.
 :- import_module mdbcomp.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.program_representation.
 :- import_module measurement_units.
 :- import_module recursion_patterns.
Index: deep_profiler/display_report.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/display_report.m,v
retrieving revision 1.34
diff -u -p -b -r1.34 display_report.m
--- deep_profiler/display_report.m	6 Jan 2011 11:23:43 -0000	1.34
+++ deep_profiler/display_report.m	12 Jan 2011 11:17:03 -0000
@@ -38,6 +38,7 @@
 :- import_module coverage.
 :- import_module exclude.
 :- import_module mdbcomp.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.program_representation.
 :- import_module measurement_units.
 :- import_module program_representation_utils.
Index: deep_profiler/dump.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/dump.m,v
retrieving revision 1.22
diff -u -p -b -r1.22 dump.m
--- deep_profiler/dump.m	6 Jan 2011 11:23:43 -0000	1.22
+++ deep_profiler/dump.m	12 Jan 2011 11:17:03 -0000
@@ -127,6 +127,7 @@
 :- import_module array_util.
 :- import_module measurements.
 :- import_module mdbcomp.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.prim_data.
 :- import_module mdbcomp.program_representation.
 
Index: deep_profiler/mdprof_fb.automatic_parallelism.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/mdprof_fb.automatic_parallelism.m,v
retrieving revision 1.26
diff -u -p -b -r1.26 mdprof_fb.automatic_parallelism.m
--- deep_profiler/mdprof_fb.automatic_parallelism.m	6 Jan 2011 11:23:43 -0000	1.26
+++ deep_profiler/mdprof_fb.automatic_parallelism.m	12 Jan 2011 11:17:03 -0000
@@ -65,6 +65,7 @@
 :- import_module branch_and_bound.
 :- import_module coverage.
 :- import_module create_report.
+:- import_module mdbcomp.goal_path.
 :- import_module measurement_units.
 :- import_module measurements.
 :- import_module program_representation_utils.
Index: deep_profiler/message.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/message.m,v
retrieving revision 1.12
diff -u -p -b -r1.12 message.m
--- deep_profiler/message.m	20 Dec 2010 07:47:46 -0000	1.12
+++ deep_profiler/message.m	12 Jan 2011 11:17:03 -0000
@@ -19,6 +19,7 @@
 :- interface.
 
 :- import_module mdbcomp.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.program_representation.
 :- import_module profile.
 
Index: deep_profiler/old_query.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/old_query.m,v
retrieving revision 1.11
diff -u -p -b -r1.11 old_query.m
--- deep_profiler/old_query.m	6 Jan 2011 11:23:43 -0000	1.11
+++ deep_profiler/old_query.m	12 Jan 2011 11:17:03 -0000
@@ -41,6 +41,7 @@
 :- import_module exclude.
 :- import_module html_format.       % for escape_break_html_string
 :- import_module mdbcomp.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.program_representation.
 :- import_module measurements.
 :- import_module old_html_format.
Index: deep_profiler/profile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/profile.m,v
retrieving revision 1.34
diff -u -p -b -r1.34 profile.m
--- deep_profiler/profile.m	6 Jan 2011 11:23:43 -0000	1.34
+++ deep_profiler/profile.m	12 Jan 2011 11:17:03 -0000
@@ -26,6 +26,7 @@
 :- import_module exclude.
 :- import_module measurements.
 :- import_module mdbcomp.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.program_representation.
 
 :- import_module array.
Index: deep_profiler/program_representation_utils.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/program_representation_utils.m,v
retrieving revision 1.29
diff -u -p -b -r1.29 program_representation_utils.m
--- deep_profiler/program_representation_utils.m	20 Dec 2010 07:47:46 -0000	1.29
+++ deep_profiler/program_representation_utils.m	12 Jan 2011 11:17:03 -0000
@@ -21,6 +21,7 @@
 :- interface.
 
 :- import_module mdbcomp.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.program_representation.
 
 :- import_module cord.
Index: deep_profiler/read_profile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/read_profile.m,v
retrieving revision 1.33
diff -u -p -b -r1.33 read_profile.m
--- deep_profiler/read_profile.m	6 Jan 2011 11:23:43 -0000	1.33
+++ deep_profiler/read_profile.m	12 Jan 2011 11:17:03 -0000
@@ -35,6 +35,7 @@
 :- import_module io_combinator.
 :- import_module measurements.
 :- import_module mdbcomp.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.prim_data.
 :- import_module mdbcomp.program_representation.
 
Index: deep_profiler/recursion_patterns.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/recursion_patterns.m,v
retrieving revision 1.10
diff -u -p -b -r1.10 recursion_patterns.m
--- deep_profiler/recursion_patterns.m	20 Dec 2010 07:47:46 -0000	1.10
+++ deep_profiler/recursion_patterns.m	12 Jan 2011 11:17:03 -0000
@@ -49,6 +49,7 @@
 :- import_module coverage.
 :- import_module create_report.
 :- import_module mdbcomp.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.program_representation.
 :- import_module measurement_units.
 :- import_module measurements.
Index: deep_profiler/report.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/report.m,v
retrieving revision 1.29
diff -u -p -b -r1.29 report.m
--- deep_profiler/report.m	6 Jan 2011 11:23:44 -0000	1.29
+++ deep_profiler/report.m	12 Jan 2011 11:17:03 -0000
@@ -22,6 +22,7 @@
 
 :- import_module coverage.
 :- import_module mdbcomp.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.program_representation.
 :- import_module measurement_units.
 :- import_module profile.
Index: deep_profiler/var_use_analysis.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/var_use_analysis.m,v
retrieving revision 1.10
diff -u -p -b -r1.10 var_use_analysis.m
--- deep_profiler/var_use_analysis.m	20 Dec 2010 07:47:47 -0000	1.10
+++ deep_profiler/var_use_analysis.m	12 Jan 2011 11:17:03 -0000
@@ -19,6 +19,7 @@
 
 :- import_module analysis_utils.
 :- import_module mdbcomp.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.program_representation.
 :- import_module coverage.
 :- import_module measurements.
Index: mdbcomp/feedback.automatic_parallelism.m
===================================================================
RCS file: /home/mercury1/repository/mercury/mdbcomp/feedback.automatic_parallelism.m,v
retrieving revision 1.9
diff -u -p -b -r1.9 feedback.automatic_parallelism.m
--- mdbcomp/feedback.automatic_parallelism.m	21 Dec 2010 12:01:34 -0000	1.9
+++ mdbcomp/feedback.automatic_parallelism.m	12 Jan 2011 11:17:03 -0000
@@ -19,6 +19,7 @@
 
 :- interface.
 
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.program_representation.
 
 :- import_module bool.
Index: mdbcomp/mdbcomp.m
===================================================================
RCS file: /home/mercury1/repository/mercury/mdbcomp/mdbcomp.m,v
retrieving revision 1.8
diff -u -p -b -r1.8 mdbcomp.m
--- mdbcomp/mdbcomp.m	15 Dec 2010 06:30:36 -0000	1.8
+++ mdbcomp/mdbcomp.m	12 Jan 2011 11:17:03 -0000
@@ -25,6 +25,7 @@
 % If you add any modules here, you should update the lists in
 % deep_profiler/Mmakefile and slice/Mmakefile.
 :- include_module feedback.
+:- include_module goal_path.
 :- include_module prim_data.
 :- include_module program_representation.
 :- include_module rtti_access.
Index: mdbcomp/program_representation.m
===================================================================
RCS file: /home/mercury1/repository/mercury/mdbcomp/program_representation.m,v
retrieving revision 1.57
diff -u -p -b -r1.57 program_representation.m
--- mdbcomp/program_representation.m	6 Jan 2011 11:23:44 -0000	1.57
+++ mdbcomp/program_representation.m	12 Jan 2011 11:17:03 -0000
@@ -35,11 +35,11 @@
 :- module mdbcomp.program_representation.
 :- interface.
 
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.prim_data.
 :- import_module mdbcomp.rtti_access.
 
 :- import_module bool.
-:- import_module char.
 :- import_module io.
 :- import_module list.
 :- import_module map.
@@ -456,179 +456,6 @@
 
 %-----------------------------------------------------------------------------%
 
-% We can think of the goal that defines a procedure to be a tree, whose leaves
-% are primitive goals and whose interior nodes are compound goals. The goal_id,
-% forward_goal_path and reverse_goal_path types describe the position of a goal
-% in this tree. Therefore value of three types can uniquely identify a goal
-% within its defining procedure.
-%
-% Goal ids are allocated in a depth-first manner that guarantees the following
-% invariants:
-%
-% - the goal id of a goal representing the procedure body will be 0, and
-% - the goal id of a goal will be greater than the goal ids of all the goals
-%   that contain it.
-%
-% A goal_path_step type says which branch to take at an interior node;
-% the integer counts inside steps start at one. For switches, the second int,
-% if present, gives the total number of function symbols in the type of the
-% switched-on var. For builtin types such as integer and string, for which
-% this number is effectively infinite, the second number won't be present.
-%
-% A forward goal path lists the step from the root of the tree to the goal
-% being identified.
-%
-% A reverse goal path lists the step from to the goal being identified to
-% the root of the tree.
-%
-% The code in the compiler that allocates goal ids also returns a containing
-% goal map, which maps each goal id to the id of its innermost containing goal
-% (if there is one). When possible, new code should use this data structure,
-% though code that needs to identify goals in files outside the compiler
-% will probably continue to need to use goal paths. The string representations
-% of goal paths always list the steps in the forward order, even though
-% most operations inside the compiler use reverse goal paths, because most
-% operations on goal paths focus on the last element, not the first.
-%
-
-:- type goal_id
-    --->    goal_id(int).
-
-:- type forward_goal_path
-    --->    fgp(list(goal_path_step)).
-
-:- type reverse_goal_path
-    --->    rgp(list(goal_path_step)).
-
-:- type goal_path_string == string.
-
-:- type goal_path_step
-    --->    step_conj(int)
-    ;       step_disj(int)
-    ;       step_switch(int, maybe(int))
-    ;       step_ite_cond
-    ;       step_ite_then
-    ;       step_ite_else
-    ;       step_neg
-    ;       step_scope(maybe_cut)
-    ;       step_lambda
-    ;       step_try
-    ;       step_atomic_main
-    ;       step_atomic_orelse(int).
-
-    % Does the scope goal have a different determinism inside than outside?
-:- type maybe_cut
-    --->    scope_is_cut
-    ;       scope_is_no_cut.
-
-:- func whole_body_goal_id = goal_id.
-
-    % Append a goal path step onto the end of a goal path.
-    %
-:- func goal_path_add_at_end(forward_goal_path, goal_path_step) =
-    forward_goal_path.
-
-    % Append a goal path step onto the end of a reverse goal path.
-    %
-:- func rev_goal_path_add_at_end(reverse_goal_path, goal_path_step) =
-    reverse_goal_path.
-
-    % Remove the last item from the goal path, returning it and the new
-    % goal path.
-    %
-:- pred goal_path_remove_last(forward_goal_path::in, forward_goal_path::out,
-    goal_path_step::out) is semidet.
-
-    % Get the last item from the goal path. This fails if the goal path is
-    % empty.
-    %
-:- pred goal_path_get_last(forward_goal_path::in, goal_path_step::out)
-    is semidet.
-
-    % Remove the last item from the goal path, returning it and the new
-    % goal path.
-    %
-:- pred rev_goal_path_remove_last(reverse_goal_path::in,
-    reverse_goal_path::out, goal_path_step::out) is semidet.
-
-    % Get the last item from the goal path. This fails if the goal path is
-    % empty.
-    %
-:- pred rev_goal_path_get_last(reverse_goal_path::in, goal_path_step::out)
-    is semidet.
-
-    % Converts a string to a forward goal path, failing if the string
-    % is not a valid goal path.
-    %
-:- pred goal_path_from_string(string::in, forward_goal_path::out) is semidet.
-
-    % Converts a string to a forward goal path, aborting if the string
-    % is not a valid goal path.
-    %
-:- pred goal_path_from_string_det(string::in, forward_goal_path::out) is det.
-
-    % Converts a string to a reverse goal path, failing if the string
-    % is not a valid goal path.
-    %
-:- pred rev_goal_path_from_string(string::in, reverse_goal_path::out)
-    is semidet.
-
-    % Converts a string to a reverse goal path, aborting if the string
-    % is not a valid goal path.
-    %
-:- pred rev_goal_path_from_string_det(string::in, reverse_goal_path::out)
-    is det.
-
-    % Converts a string to a goal path step, failing if the string is not
-    % a valid goal path step.
-    %
-:- pred goal_path_step_from_string(string::in, goal_path_step::out) is semidet.
-
-    % Convert the goal path to its string representation. The resulting string
-    % is guaranteed to be acceptable to path_from_string_det.
-    %
-:- func goal_path_to_string(forward_goal_path) = string.
-
-    % Convert the goal path to its string representation. The resulting string
-    % is guaranteed to be acceptable to rev_path_from_string_det.
-    %
-:- func rev_goal_path_to_string(reverse_goal_path) = string.
-
-    % Is this character the one that ends each goal path step?
-    %
-:- pred is_goal_path_separator(char::in) is semidet.
-
-    % goal_path_inside(PathA, PathB):
-    %
-    % Succeed if PathB denotes a goal *inside* the goal denoted by PathA.
-    % (It considers a goal to be inside itself.)
-    %
-:- pred goal_path_inside(forward_goal_path::in, forward_goal_path::in)
-    is semidet.
-:- pred rev_goal_path_inside(reverse_goal_path::in, reverse_goal_path::in)
-    is semidet.
-
-    % goal_path_inside(PathA, PathB, RelativePath):
-    %
-    % As above, except that it also return RelativePath, which denotes
-    % the same goal that PathB denotes, only from GoalA's perspective.
-    %
-:- pred goal_path_inside(forward_goal_path::in, forward_goal_path::in,
-    forward_goal_path::out) is semidet.
-:- pred rev_goal_path_inside(reverse_goal_path::in, reverse_goal_path::in,
-    reverse_goal_path::out) is semidet.
-
-    % Remove information from the goal path that depends on type information.
-    %
-    % This is necessary when using goal paths to lookup a map within the deep
-    % profiler.  The goal paths used to perform the query cannot construct the
-    % parts of the goal paths that depend on type information.
-    %
-:- pred rev_goal_path_remove_type_info(reverse_goal_path::in,
-    reverse_goal_path::out) is det.
-
-%----------------------------------------------------------------------------%
-
     % User-visible head variables are represented by a number from 1..N,
     % where N is the user-visible arity.
     %
@@ -949,170 +776,6 @@ transform_switch_case(Pred, Case0, Case)
 
 %-----------------------------------------------------------------------------%
 
-whole_body_goal_id = goal_id(0).
-
-goal_path_add_at_end(GoalPath0, GoalPathStep) = GoalPath :-
-    GoalPath0 = fgp(Steps0),
-    Steps = Steps0 ++ [GoalPathStep],
-    GoalPath = fgp(Steps).
-
-rev_goal_path_add_at_end(GoalPath0, GoalPathStep) = GoalPath :-
-    GoalPath0 = rgp(Steps0),
-    Steps = [GoalPathStep | Steps0],
-    GoalPath = rgp(Steps).
-
-goal_path_remove_last(GoalPath0, GoalPath, LastStep) :-
-    GoalPath0 = fgp(Steps0),
-    list.split_last(Steps0, Steps, LastStep),
-    GoalPath = fgp(Steps).
-
-goal_path_get_last(GoalPath, LastStep) :-
-    goal_path_remove_last(GoalPath, _, LastStep).
-
-rev_goal_path_remove_last(GoalPath0, GoalPath, LastStep) :-
-    GoalPath0 = rgp(Steps0),
-    Steps0 = [LastStep | Steps],
-    GoalPath = rgp(Steps).
-
-rev_goal_path_get_last(GoalPath, LastStep) :-
-    rev_goal_path_remove_last(GoalPath, _, LastStep).
-
-goal_path_inside(PathA, PathB, RelativePath) :-
-    PathA = fgp(StepsA),
-    PathB = fgp(StepsB),
-    list.append(StepsA, RelativeSteps, StepsB),
-    RelativePath = fgp(RelativeSteps).
-
-rev_goal_path_inside(PathA, PathB, Relative) :-
-    PathA = rgp(StepsA),
-    PathB = rgp(StepsB),
-    list.remove_suffix(StepsB, StepsA, RelativeSteps),
-    Relative = rgp(RelativeSteps).
-
-goal_path_inside(PathA, PathB) :-
-    goal_path_inside(PathA, PathB, _).
-
-rev_goal_path_inside(PathA, PathB) :-
-    rev_goal_path_inside(PathA, PathB, _).
-
-goal_path_from_string(GoalPathStr, GoalPath) :-
-    StepStrs = string.words_separator(is_goal_path_separator, GoalPathStr),
-    list.map(goal_path_step_from_string, StepStrs, Steps),
-    GoalPath = fgp(Steps).
-
-goal_path_from_string_det(GoalPathStr, GoalPath) :-
-    ( goal_path_from_string(GoalPathStr, GoalPathPrime) ->
-        GoalPath = GoalPathPrime
-    ;
-        error("path_from_string_det: goal_path_from_string failed")
-    ).
-
-rev_goal_path_from_string(GoalPathStr, GoalPath) :-
-    StepStrs = string.words_separator(is_goal_path_separator, GoalPathStr),
-    list.map(goal_path_step_from_string, StepStrs, Steps),
-    list.reverse(Steps, RevSteps),
-    GoalPath = rgp(RevSteps).
-
-rev_goal_path_from_string_det(GoalPathStr, GoalPath) :-
-    ( rev_goal_path_from_string(GoalPathStr, GoalPathPrime) ->
-        GoalPath = GoalPathPrime
-    ;
-        error("rev_path_from_string_det: rev_goal_path_from_string failed")
-    ).
-
-goal_path_step_from_string(String, Step) :-
-    string.first_char(String, First, Rest),
-    goal_path_step_from_string_2(First, Rest, Step).
-
-:- pred goal_path_step_from_string_2(char::in, string::in, goal_path_step::out)
-    is semidet.
-
-goal_path_step_from_string_2('c', NStr, step_conj(N)) :-
-    string.to_int(NStr, N).
-goal_path_step_from_string_2('d', NStr, step_disj(N)) :-
-    string.to_int(NStr, N).
-goal_path_step_from_string_2('s', Str, step_switch(N, MaybeM)) :-
-    string.words_separator(unify('-'), Str) = [NStr, MStr],
-    string.to_int(NStr, N),
-    % "na" is short for "not applicable"
-    ( MStr = "na" ->
-        MaybeM = no
-    ;
-        string.to_int(MStr, M),
-        MaybeM = yes(M)
-    ).
-goal_path_step_from_string_2('?', "", step_ite_cond).
-goal_path_step_from_string_2('t', "", step_ite_then).
-goal_path_step_from_string_2('e', "", step_ite_else).
-goal_path_step_from_string_2('~', "", step_neg).
-goal_path_step_from_string_2('q', "!", step_scope(scope_is_cut)).
-goal_path_step_from_string_2('q', "", step_scope(scope_is_no_cut)).
-goal_path_step_from_string_2('r', "", step_try).
-goal_path_step_from_string_2('=', "", step_lambda).
-goal_path_step_from_string_2('a', "", step_atomic_main).
-goal_path_step_from_string_2('o', NStr, step_atomic_orelse(N)) :-
-    string.to_int(NStr, N).
-
-is_goal_path_separator(';').
-
-goal_path_to_string(GoalPath) = GoalPathStr :-
-    GoalPath = fgp(Steps),
-    StepStrs = list.map(goal_path_step_to_string, Steps),
-    string.append_list(StepStrs, GoalPathStr).
-
-rev_goal_path_to_string(GoalPath) = GoalPathStr :-
-    GoalPath = rgp(RevSteps),
-    list.reverse(RevSteps, Steps),
-    StepStrs = list.map(goal_path_step_to_string, Steps),
-    string.append_list(StepStrs, GoalPathStr).
-
-:- func goal_path_step_to_string(goal_path_step) = string.
-
-goal_path_step_to_string(step_conj(N)) = "c" ++ int_to_string(N) ++ ";".
-goal_path_step_to_string(step_disj(N)) = "d" ++ int_to_string(N) ++ ";".
-goal_path_step_to_string(step_switch(N, yes(M))) = "s" ++ int_to_string(N)
-    ++ "-" ++ int_to_string(M) ++ ";".
-goal_path_step_to_string(step_switch(N, no)) = "s" ++ int_to_string(N)
-    ++ "-na;".      % short for "not applicable"
-goal_path_step_to_string(step_ite_cond) = "?;".
-goal_path_step_to_string(step_ite_then) = "t;".
-goal_path_step_to_string(step_ite_else) = "e;".
-goal_path_step_to_string(step_neg) = "~;".
-goal_path_step_to_string(step_scope(scope_is_cut)) = "q!;".
-goal_path_step_to_string(step_scope(scope_is_no_cut)) = "q;".
-goal_path_step_to_string(step_try) = "r;".
-goal_path_step_to_string(step_lambda) = "=;".
-goal_path_step_to_string(step_atomic_main) = "a;".
-goal_path_step_to_string(step_atomic_orelse(N)) =
-    "o" ++ int_to_string(N) ++ ";".
-
-rev_goal_path_remove_type_info(rgp(Steps0), rgp(Steps)) :-
-    map(goal_path_step_remove_type_info, Steps0, Steps).
-
-:- pred goal_path_step_remove_type_info(goal_path_step::in,
-    goal_path_step::out) is det.
-
-goal_path_step_remove_type_info(!Step) :-
-    (
-        ( !.Step = step_conj(_)
-        ; !.Step = step_disj(_)
-        ; !.Step = step_ite_cond
-        ; !.Step = step_ite_then
-        ; !.Step = step_ite_else
-        ; !.Step = step_neg
-        ; !.Step = step_scope(_)
-        ; !.Step = step_lambda
-        ; !.Step = step_try
-        ; !.Step = step_atomic_main
-        ; !.Step = step_atomic_orelse(_)
-        )
-    ;
-        !.Step = step_switch(N, _),
-        !:Step = step_switch(N, no)
-    ).
-
-%-----------------------------------------------------------------------------%
-
 detism_rep(Detism) = Rep :-
     determinism_representation(Detism, Rep).
 
Index: mdbcomp/rtti_access.m
===================================================================
RCS file: /home/mercury1/repository/mercury/mdbcomp/rtti_access.m,v
retrieving revision 1.17
diff -u -p -b -r1.17 rtti_access.m
--- mdbcomp/rtti_access.m	2 Jan 2011 17:36:55 -0000	1.17
+++ mdbcomp/rtti_access.m	12 Jan 2011 11:17:03 -0000
@@ -17,8 +17,8 @@
 :- module mdbcomp.rtti_access.
 :- interface.
 
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.prim_data.
-:- import_module mdbcomp.program_representation.
 :- import_module mdbcomp.trace_counts.
 
 :- import_module list.
Index: mdbcomp/slice_and_dice.m
===================================================================
RCS file: /home/mercury1/repository/mercury/mdbcomp/slice_and_dice.m,v
retrieving revision 1.17
diff -u -p -b -r1.17 slice_and_dice.m
--- mdbcomp/slice_and_dice.m	20 Dec 2010 07:47:48 -0000	1.17
+++ mdbcomp/slice_and_dice.m	12 Jan 2011 11:17:03 -0000
@@ -185,7 +185,7 @@
 
 :- implementation.
 
-:- import_module mdbcomp.program_representation.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.rtti_access.
 
 :- import_module float.
Index: mdbcomp/trace_counts.m
===================================================================
RCS file: /home/mercury1/repository/mercury/mdbcomp/trace_counts.m,v
retrieving revision 1.26
diff -u -p -b -r1.26 trace_counts.m
--- mdbcomp/trace_counts.m	20 Dec 2010 07:47:48 -0000	1.26
+++ mdbcomp/trace_counts.m	12 Jan 2011 11:17:03 -0000
@@ -18,8 +18,8 @@
 :- module mdbcomp.trace_counts.
 :- interface.
 
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.prim_data.
-:- import_module mdbcomp.program_representation.
 
 :- import_module bool.
 :- import_module io.
Index: slice/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/slice/Mmakefile,v
retrieving revision 1.22
diff -u -p -b -r1.22 Mmakefile
--- slice/Mmakefile	30 Sep 2010 07:23:34 -0000	1.22
+++ slice/Mmakefile	12 Jan 2011 11:17:03 -0000
@@ -47,9 +47,10 @@ VPATH = $(LIBRARY_DIR) $(SSDB_DIR)
 #-----------------------------------------------------------------------------#
 
 MDBCOMP_MODULES = \
-	mdbcomp.m \
-	feedback.m \
 	feedback.automatic_parallelism.m \
+	feedback.m \
+	goal_path.m \
+	mdbcomp.m \
 	prim_data.m \
 	program_representation.m \
 	rtti_access.m \
Index: slice/mcov.m
===================================================================
RCS file: /home/mercury1/repository/mercury/slice/mcov.m,v
retrieving revision 1.7
diff -u -p -b -r1.7 mcov.m
--- slice/mcov.m	20 Dec 2010 07:47:49 -0000	1.7
+++ slice/mcov.m	12 Jan 2011 11:17:03 -0000
@@ -26,8 +26,8 @@
 :- implementation.
 
 :- import_module mdbcomp.
+:- import_module mdbcomp.goal_path.
 :- import_module mdbcomp.prim_data.
-:- import_module mdbcomp.program_representation.
 :- import_module mdbcomp.trace_counts.
 
 :- import_module assoc_list.

mdbcomp/goal_path.m:
%-----------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%-----------------------------------------------------------------------------%
% Copyright (C) 2011 The University of Melbourne.
% This file may only be copied under the terms of the GNU Library General
% Public License - see the file COPYING.LIB in the Mercury distribution.
%-----------------------------------------------------------------------------%
%
% File: goal_path.m
% Authors: zs, pbone
%
% This module defines the representation of goal paths and goal ids.
% These identify locations within a procedure body.
%
% We can think of the goal that defines a procedure to be a tree, whose leaves
% are primitive goals and whose interior nodes are compound goals. The goal_id,
% forward_goal_path and reverse_goal_path types describe the position of a goal
% in this tree. Therefore value of three types can uniquely identify a goal
% within its defining procedure.
%
% Goal ids are allocated in a depth-first manner that guarantees the following
% invariants:
%
% - the goal id of a goal representing the procedure body will be 0, and
% - the goal id of a goal will be greater than the goal ids of all the goals
%   that contain it.
%
% A goal_path_step type says which branch to take at an interior node;
% the integer counts inside steps start at one. For switches, the second int,
% if present, gives the total number of function symbols in the type of the
% switched-on var. For builtin types such as integer and string, for which
% this number is effectively infinite, the second number won't be present.
%
% A forward goal path lists the step from the root of the tree to the goal
% being identified.
%
% A reverse goal path lists the step from to the goal being identified to
% the root of the tree.
%
% The code in the compiler that allocates goal ids also returns a containing
% goal map, which maps each goal id to the id of its innermost containing goal
% (if there is one). When possible, new code should use this data structure,
% though code that needs to identify goals in files outside the compiler
% will probably continue to need to use goal paths. The string representations
% of goal paths always list the steps in the forward order, even though
% most operations inside the compiler use reverse goal paths, because most
% operations on goal paths focus on the last element, not the first.
%
%-----------------------------------------------------------------------------%

:- module mdbcomp.goal_path.
:- interface.

:- import_module bimap.
:- import_module char.
:- import_module list.
:- import_module map.
:- import_module maybe.

%-----------------------------------------------------------------------------%

:- type goal_id
    --->    goal_id(int).

:- type forward_goal_path
    --->    fgp(list(goal_path_step)).

:- type reverse_goal_path
    --->    rgp(list(goal_path_step)).

:- type goal_path_string == string.

:- type goal_path_step
    --->    step_conj(int)
    ;       step_disj(int)
    ;       step_switch(int, maybe(int))
    ;       step_ite_cond
    ;       step_ite_then
    ;       step_ite_else
    ;       step_neg
    ;       step_scope(maybe_cut)
    ;       step_lambda
    ;       step_try
    ;       step_atomic_main
    ;       step_atomic_orelse(int).

    % Does the scope goal have a different determinism inside than outside?
:- type maybe_cut
    --->    scope_is_cut
    ;       scope_is_no_cut.

:- func whole_body_goal_id = goal_id.

    % Append a goal path step onto the end of a goal path.
    %
:- func goal_path_add_at_end(forward_goal_path, goal_path_step) =
    forward_goal_path.

    % Append a goal path step onto the end of a reverse goal path.
    %
:- func rev_goal_path_add_at_end(reverse_goal_path, goal_path_step) =
    reverse_goal_path.

    % Remove the last item from the goal path, returning it and the new
    % goal path.
    %
:- pred goal_path_remove_last(forward_goal_path::in, forward_goal_path::out,
    goal_path_step::out) is semidet.

    % Get the last item from the goal path. This fails if the goal path is
    % empty.
    %
:- pred goal_path_get_last(forward_goal_path::in, goal_path_step::out)
    is semidet.

    % Remove the last item from the goal path, returning it and the new
    % goal path.
    %
:- pred rev_goal_path_remove_last(reverse_goal_path::in,
    reverse_goal_path::out, goal_path_step::out) is semidet.

    % Get the last item from the goal path. This fails if the goal path is
    % empty.
    %
:- pred rev_goal_path_get_last(reverse_goal_path::in, goal_path_step::out)
    is semidet.

    % Converts a string to a forward goal path, failing if the string
    % is not a valid goal path.
    %
:- pred goal_path_from_string(string::in, forward_goal_path::out) is semidet.

    % Converts a string to a forward goal path, aborting if the string
    % is not a valid goal path.
    %
:- pred goal_path_from_string_det(string::in, forward_goal_path::out) is det.

    % Converts a string to a reverse goal path, failing if the string
    % is not a valid goal path.
    %
:- pred rev_goal_path_from_string(string::in, reverse_goal_path::out)
    is semidet.

    % Converts a string to a reverse goal path, aborting if the string
    % is not a valid goal path.
    %
:- pred rev_goal_path_from_string_det(string::in, reverse_goal_path::out)
    is det.

    % Converts a string to a goal path step, failing if the string is not
    % a valid goal path step.
    %
:- pred goal_path_step_from_string(string::in, goal_path_step::out) is semidet.

    % Convert the goal path to its string representation. The resulting string
    % is guaranteed to be acceptable to path_from_string_det.
    %
:- func goal_path_to_string(forward_goal_path) = string.

    % Convert the goal path to its string representation. The resulting string
    % is guaranteed to be acceptable to rev_path_from_string_det.
    %
:- func rev_goal_path_to_string(reverse_goal_path) = string.

    % Is this character the one that ends each goal path step?
    %
:- pred is_goal_path_separator(char::in) is semidet.

    % goal_path_inside(PathA, PathB):
    %
    % Succeed if PathB denotes a goal *inside* the goal denoted by PathA.
    % (It considers a goal to be inside itself.)
    %
:- pred goal_path_inside(forward_goal_path::in, forward_goal_path::in)
    is semidet.
:- pred rev_goal_path_inside(reverse_goal_path::in, reverse_goal_path::in)
    is semidet.

    % goal_path_inside(PathA, PathB, RelativePath):
    %
    % As above, except that it also return RelativePath, which denotes
    % the same goal that PathB denotes, only from GoalA's perspective.
    %
:- pred goal_path_inside(forward_goal_path::in, forward_goal_path::in,
    forward_goal_path::out) is semidet.
:- pred rev_goal_path_inside(reverse_goal_path::in, reverse_goal_path::in,
    reverse_goal_path::out) is semidet.

    % Remove information from the goal path that depends on type information.
    %
    % This is necessary when using goal paths to lookup a map within the deep
    % profiler.  The goal paths used to perform the query cannot construct the
    % parts of the goal paths that depend on type information.
    %
:- pred rev_goal_path_remove_type_info(reverse_goal_path::in,
    reverse_goal_path::out) is det.

%----------------------------------------------------------------------------%

:- type containing_goal
    --->    whole_body_goal
            % This goal is the entire body of its procedure.
    ;       containing_goal(goal_id, goal_path_step).
            % This goal is an contained immediately inside the larger goal
            % identified by the goal_id, from which you need to take the
            % given goal_path step to get to this goal.
            %
            % The goal_id of the containing goal is guaranteed to be always
            % less than the goal_id of this goal.

:- type containing_goal_map == map(goal_id, containing_goal).
:- type goal_forward_path_map == map(goal_id, forward_goal_path).
:- type goal_reverse_path_map == map(goal_id, reverse_goal_path).
:- type goal_reverse_path_bimap == bimap(goal_id, reverse_goal_path).

    % goal_id_inside(ContainingGoalMap, GoalIdA, GoalIdB):
    %
    % Succeeds if GoalIdB denotes a goal *inside* the goal denoted by GoalIdA.
    % (It considers a goal to be inside itself.)
    %
:- pred goal_id_inside(containing_goal_map::in,
    goal_id::in, goal_id::in) is semidet.

    % Convert a goal_id to a forward goal path.
    %
:- func goal_id_to_forward_path(containing_goal_map, goal_id) =
    forward_goal_path.

    % Convert a goal_id to a reverse goal path.
    %
:- func goal_id_to_reverse_path(containing_goal_map, goal_id) =
    reverse_goal_path.

    % Given a containing_goal_map, create a map that maps each goal_id in it
    % to a forwward goal path.
    %
:- func create_forward_goal_path_map(containing_goal_map) =
    goal_forward_path_map.

    % Given a containing_goal_map, create a map that maps each goal_id in it
    % to a reverse goal path.
    %
:- func create_reverse_goal_path_map(containing_goal_map) =
    goal_reverse_path_map.

    % Given a containing_goal_map, create a map that maps each goal_id in it
    % to a reverse goal path, and back.
    %
:- func create_reverse_goal_path_bimap(containing_goal_map) =
    goal_reverse_path_bimap.

%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%

:- implementation.

:- import_module assoc_list.
:- import_module cord.
:- import_module pair.
:- import_module require.
:- import_module string.
:- import_module svbimap.
:- import_module svmap.

whole_body_goal_id = goal_id(0).

goal_path_add_at_end(GoalPath0, GoalPathStep) = GoalPath :-
    GoalPath0 = fgp(Steps0),
    Steps = Steps0 ++ [GoalPathStep],
    GoalPath = fgp(Steps).

rev_goal_path_add_at_end(GoalPath0, GoalPathStep) = GoalPath :-
    GoalPath0 = rgp(Steps0),
    Steps = [GoalPathStep | Steps0],
    GoalPath = rgp(Steps).

goal_path_remove_last(GoalPath0, GoalPath, LastStep) :-
    GoalPath0 = fgp(Steps0),
    list.split_last(Steps0, Steps, LastStep),
    GoalPath = fgp(Steps).

goal_path_get_last(GoalPath, LastStep) :-
    goal_path_remove_last(GoalPath, _, LastStep).

rev_goal_path_remove_last(GoalPath0, GoalPath, LastStep) :-
    GoalPath0 = rgp(Steps0),
    Steps0 = [LastStep | Steps],
    GoalPath = rgp(Steps).

rev_goal_path_get_last(GoalPath, LastStep) :-
    rev_goal_path_remove_last(GoalPath, _, LastStep).

goal_path_inside(PathA, PathB, RelativePath) :-
    PathA = fgp(StepsA),
    PathB = fgp(StepsB),
    list.append(StepsA, RelativeSteps, StepsB),
    RelativePath = fgp(RelativeSteps).

rev_goal_path_inside(PathA, PathB, Relative) :-
    PathA = rgp(StepsA),
    PathB = rgp(StepsB),
    list.remove_suffix(StepsB, StepsA, RelativeSteps),
    Relative = rgp(RelativeSteps).

goal_path_inside(PathA, PathB) :-
    goal_path_inside(PathA, PathB, _).

rev_goal_path_inside(PathA, PathB) :-
    rev_goal_path_inside(PathA, PathB, _).

goal_path_from_string(GoalPathStr, GoalPath) :-
    StepStrs = string.words_separator(is_goal_path_separator, GoalPathStr),
    list.map(goal_path_step_from_string, StepStrs, Steps),
    GoalPath = fgp(Steps).

goal_path_from_string_det(GoalPathStr, GoalPath) :-
    ( goal_path_from_string(GoalPathStr, GoalPathPrime) ->
        GoalPath = GoalPathPrime
    ;
        unexpected($module, $pred, "goal_path_from_string failed")
    ).

rev_goal_path_from_string(GoalPathStr, GoalPath) :-
    StepStrs = string.words_separator(is_goal_path_separator, GoalPathStr),
    list.map(goal_path_step_from_string, StepStrs, Steps),
    list.reverse(Steps, RevSteps),
    GoalPath = rgp(RevSteps).

rev_goal_path_from_string_det(GoalPathStr, GoalPath) :-
    ( rev_goal_path_from_string(GoalPathStr, GoalPathPrime) ->
        GoalPath = GoalPathPrime
    ;
        unexpected($module, $pred, "rev_goal_path_from_string failed")
    ).

goal_path_step_from_string(String, Step) :-
    string.first_char(String, First, Rest),
    goal_path_step_from_string_2(First, Rest, Step).

:- pred goal_path_step_from_string_2(char::in, string::in, goal_path_step::out)
    is semidet.

goal_path_step_from_string_2('c', NStr, step_conj(N)) :-
    string.to_int(NStr, N).
goal_path_step_from_string_2('d', NStr, step_disj(N)) :-
    string.to_int(NStr, N).
goal_path_step_from_string_2('s', Str, step_switch(N, MaybeM)) :-
    string.words_separator(unify('-'), Str) = [NStr, MStr],
    string.to_int(NStr, N),
    % "na" is short for "not applicable"
    ( MStr = "na" ->
        MaybeM = no
    ;
        string.to_int(MStr, M),
        MaybeM = yes(M)
    ).
goal_path_step_from_string_2('?', "", step_ite_cond).
goal_path_step_from_string_2('t', "", step_ite_then).
goal_path_step_from_string_2('e', "", step_ite_else).
goal_path_step_from_string_2('~', "", step_neg).
goal_path_step_from_string_2('q', "!", step_scope(scope_is_cut)).
goal_path_step_from_string_2('q', "", step_scope(scope_is_no_cut)).
goal_path_step_from_string_2('r', "", step_try).
goal_path_step_from_string_2('=', "", step_lambda).
goal_path_step_from_string_2('a', "", step_atomic_main).
goal_path_step_from_string_2('o', NStr, step_atomic_orelse(N)) :-
    string.to_int(NStr, N).

is_goal_path_separator(';').

goal_path_to_string(GoalPath) = GoalPathStr :-
    GoalPath = fgp(Steps),
    StepStrs = list.map(goal_path_step_to_string, Steps),
    string.append_list(StepStrs, GoalPathStr).

rev_goal_path_to_string(GoalPath) = GoalPathStr :-
    GoalPath = rgp(RevSteps),
    list.reverse(RevSteps, Steps),
    StepStrs = list.map(goal_path_step_to_string, Steps),
    string.append_list(StepStrs, GoalPathStr).

:- func goal_path_step_to_string(goal_path_step) = string.

goal_path_step_to_string(step_conj(N)) = "c" ++ int_to_string(N) ++ ";".
goal_path_step_to_string(step_disj(N)) = "d" ++ int_to_string(N) ++ ";".
goal_path_step_to_string(step_switch(N, yes(M))) = "s" ++ int_to_string(N)
    ++ "-" ++ int_to_string(M) ++ ";".
goal_path_step_to_string(step_switch(N, no)) = "s" ++ int_to_string(N)
    ++ "-na;".      % short for "not applicable"
goal_path_step_to_string(step_ite_cond) = "?;".
goal_path_step_to_string(step_ite_then) = "t;".
goal_path_step_to_string(step_ite_else) = "e;".
goal_path_step_to_string(step_neg) = "~;".
goal_path_step_to_string(step_scope(scope_is_cut)) = "q!;".
goal_path_step_to_string(step_scope(scope_is_no_cut)) = "q;".
goal_path_step_to_string(step_try) = "r;".
goal_path_step_to_string(step_lambda) = "=;".
goal_path_step_to_string(step_atomic_main) = "a;".
goal_path_step_to_string(step_atomic_orelse(N)) =
    "o" ++ int_to_string(N) ++ ";".

rev_goal_path_remove_type_info(rgp(Steps0), rgp(Steps)) :-
    map(goal_path_step_remove_type_info, Steps0, Steps).

:- pred goal_path_step_remove_type_info(goal_path_step::in,
    goal_path_step::out) is det.

goal_path_step_remove_type_info(!Step) :-
    (
        ( !.Step = step_conj(_)
        ; !.Step = step_disj(_)
        ; !.Step = step_ite_cond
        ; !.Step = step_ite_then
        ; !.Step = step_ite_else
        ; !.Step = step_neg
        ; !.Step = step_scope(_)
        ; !.Step = step_lambda
        ; !.Step = step_try
        ; !.Step = step_atomic_main
        ; !.Step = step_atomic_orelse(_)
        )
    ;
        !.Step = step_switch(N, _),
        !:Step = step_switch(N, no)
    ).

%-----------------------------------------------------------------------------%

goal_id_inside(ContainingGoalId, GoalIdA, GoalIdB) :-
    (
        GoalIdB = GoalIdA
    ;
        map.lookup(ContainingGoalId, GoalIdB, GoalContainingB),
        GoalContainingB = containing_goal(ParentGoalIdB, _),
        goal_id_inside(ContainingGoalId, GoalIdA, ParentGoalIdB)
    ).

goal_id_to_forward_path(ContainingGoalMap, GoalId) = GoalPath :-
    StepsCord = goal_id_to_steps(ContainingGoalMap, GoalId),
    Steps = cord.list(StepsCord),
    GoalPath = fgp(Steps).

goal_id_to_reverse_path(ContainingGoalMap, GoalId) = GoalPath :-
    StepsCord = goal_id_to_steps(ContainingGoalMap, GoalId),
    Steps = cord.list(StepsCord),
    list.reverse(Steps, RevSteps),
    GoalPath = rgp(RevSteps).

:- func goal_id_to_steps(containing_goal_map, goal_id) =
    cord(goal_path_step).

goal_id_to_steps(ContainingGoalMap, GoalId) = Steps :-
    map.lookup(ContainingGoalMap, GoalId, ContainingGoal),
    (
        ContainingGoal = whole_body_goal,
        Steps = cord.empty
    ;
        ContainingGoal = containing_goal(ParentGoalId, LastStep),
        EarlierSteps = goal_id_to_steps(ContainingGoalMap, ParentGoalId),
        Steps = cord.snoc(EarlierSteps, LastStep)
    ).

create_forward_goal_path_map(ContainingGoalMap) = ForwardGoalPathMap :-
    ReverseGoalPathMap = create_reverse_goal_path_map(ContainingGoalMap),
    map.map_values_only(rgp_to_fgp, ReverseGoalPathMap, ForwardGoalPathMap).

:- pred rgp_to_fgp(reverse_goal_path::in, forward_goal_path::out) is det.

rgp_to_fgp(rgp(RevSteps), fgp(Steps)) :-
    list.reverse(RevSteps, Steps).

create_reverse_goal_path_map(ContainingGoalMap) = ReverseGoalPathMap :-
    map.to_assoc_list(ContainingGoalMap, ContainingGoalList),
    create_reverse_goal_path_map_2(ContainingGoalList,
        map.init, ReverseGoalPathMap).

:- pred create_reverse_goal_path_map_2(
    assoc_list(goal_id, containing_goal)::in,
    map(goal_id, reverse_goal_path)::in, map(goal_id, reverse_goal_path)::out)
    is det.

create_reverse_goal_path_map_2([], !ReverseGoalPathMap).
create_reverse_goal_path_map_2([Head | Tail], !ReverseGoalPathMap) :-
    Head = GoalId - ContainingGoal,
    (
        ContainingGoal = whole_body_goal,
        GoalReversePath = rgp([])
    ;
        ContainingGoal = containing_goal(ContainingGoalId, Step),
        map.lookup(!.ReverseGoalPathMap, ContainingGoalId,
            ContainingGoalReversePath),
        ContainingGoalReversePath = rgp(ContainingGoalReverseSteps),
        GoalReverseSteps = [Step | ContainingGoalReverseSteps],
        GoalReversePath = rgp(GoalReverseSteps)
    ),
    svmap.det_insert(GoalId, GoalReversePath, !ReverseGoalPathMap),
    create_reverse_goal_path_map_2(Tail, !ReverseGoalPathMap).

create_reverse_goal_path_bimap(ContainingGoalMap) = ReverseGoalPathBiMap :-
    map.to_assoc_list(ContainingGoalMap, ContainingGoalList),
    create_reverse_goal_path_bimap_2(ContainingGoalList,
        bimap.init, ReverseGoalPathBiMap).

:- pred create_reverse_goal_path_bimap_2(
    assoc_list(goal_id, containing_goal)::in,
    bimap(goal_id, reverse_goal_path)::in,
    bimap(goal_id, reverse_goal_path)::out) is det.

create_reverse_goal_path_bimap_2([], !ReverseGoalPathBiMap).
create_reverse_goal_path_bimap_2([Head | Tail], !ReverseGoalPathBiMap) :-
    Head = GoalId - ContainingGoal,
    (
        ContainingGoal = whole_body_goal,
        GoalReversePath = rgp([])
    ;
        ContainingGoal = containing_goal(ContainingGoalId, Step),
        bimap.lookup(!.ReverseGoalPathBiMap, ContainingGoalId,
            ContainingGoalReversePath),
        ContainingGoalReversePath = rgp(ContainingGoalReverseSteps),
        GoalReverseSteps = [Step | ContainingGoalReverseSteps],
        GoalReversePath = rgp(GoalReverseSteps)
    ),
    svbimap.det_insert(GoalId, GoalReversePath, !ReverseGoalPathBiMap),
    create_reverse_goal_path_bimap_2(Tail, !ReverseGoalPathBiMap).

%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 489 bytes
Desc: Digital signature
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20110112/7f338abf/attachment.sig>


More information about the reviews mailing list