[m-rev.] diff: Fix a coverage profiling bug.

Paul Bone pbone at csse.unimelb.edu.au
Fri Feb 6 21:11:44 AEDT 2009


Estimated hours taken: 2 
Branches: main

Fix a coverage profiling bug caused by new changes to the deep profiler with
regard to 'from ground term construction' scopes.

compiler/deep_profiling.m:
    Mark from ground term construction scopes as not being instrumentation
    introduced by the deep profiling pass.

compiler/goal_util.m:
    Create a predicate that transforms a goal and all it's children according
    to a higher order argument.

Index: compiler/deep_profiling.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/deep_profiling.m,v
retrieving revision 1.95
diff -u -p -b -r1.95 deep_profiling.m
--- compiler/deep_profiling.m	23 Dec 2008 01:37:31 -0000	1.95
+++ compiler/deep_profiling.m	6 Feb 2009 07:53:19 -0000
@@ -1069,7 +1069,11 @@ deep_prof_transform_goal(Path, Goal0, Go
         ),
         ScopedGoalPath = goal_path_add_at_end(Path, step_scope(MaybeCut)),
         ( Reason = from_ground_term(_, from_ground_term_construct) ->
-            SubGoal = SubGoal0,
+            % We must annotate the scope goal and it's children with a default
+            % deep profiling information structure, this is required by the
+            % coverage profiling transformation.
+            transform_all_goals(deep_prof_mark_goal_as_not_mdprof_inst,
+                SubGoal0, SubGoal),
             AddedImpurity = no
         ;
             deep_prof_transform_goal(ScopedGoalPath, SubGoal0, SubGoal,
@@ -1092,6 +1096,14 @@ deep_prof_transform_goal(Path, Goal0, Go
             "deep_prof_transform_goal: shorthand should have gone by now")
     ).
 
+:- pred deep_prof_mark_goal_as_not_mdprof_inst( hlds_goal::in, hlds_goal::out)
+    is det.
+
+deep_prof_mark_goal_as_not_mdprof_inst(Goal0, Goal) :-
+    GoalInfo0 = Goal0 ^ hlds_goal_info,
+    goal_info_set_mdprof_inst(goal_is_not_mdprof_inst, GoalInfo0, GoalInfo),
+    Goal = Goal0 ^ hlds_goal_info := GoalInfo.
+
 :- pred deep_prof_transform_conj(int::in,
     conj_type::in, goal_path::in,
     list(hlds_goal)::in, list(hlds_goal)::out, bool::out,
@@ -2069,6 +2081,11 @@ coverage_prof_second_pass_goal(Goal0, Go
     CPOptions = !.Info ^ ci_coverage_profiling_opts,
     GoalPath = goal_info_get_goal_path(GoalInfo0),
 
+    % Currently the first pass is unsupported, we don't make use of the
+    % information it provides in IsMDProfInst.
+    DPInfo = goal_info_get_dp_info(GoalInfo0),
+    DPInfo = dp_goal_info(IsMDProfInst, _MaybeDPCoverageInfo),
+
     (
         IsMDProfInst = goal_is_not_mdprof_inst,
         CoverageBeforeKnown = coverage_before_unknown
@@ -2082,11 +2099,6 @@ coverage_prof_second_pass_goal(Goal0, Go
         true
     ),
 
-    % Currently the first pass is unsupported, we don't make use of the
-    % information it provides.
-    DPInfo = goal_info_get_dp_info(GoalInfo0),
-    DPInfo = dp_goal_info(IsMDProfInst, _MaybeDPCoverageInfo),
-
     % Step 1.
     %
     % Apply transformation recursively.
Index: compiler/goal_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/goal_util.m,v
retrieving revision 1.163
diff -u -p -b -r1.163 goal_util.m
--- compiler/goal_util.m	30 Jan 2009 03:51:44 -0000	1.163
+++ compiler/goal_util.m	6 Feb 2009 10:07:25 -0000
@@ -403,6 +403,14 @@
 :- mode maybe_transform_goal_at_goal_path(pred(in, out) is det,
     in, in, out) is det.
 
+    % Transform the given goal and all it's children according to the higher
+    % order argument.  Children are transformed before their parents, therefore
+    % the higher order argument will receive a goal with children that have
+    % already been transformed.
+    %
+:- pred transform_all_goals(pred(hlds_goal, hlds_goal), hlds_goal, hlds_goal).
+:- mode transform_all_goals(pred(in, out) is det, in, out) is det.
+
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
@@ -2013,6 +2021,53 @@ maybe_transform_goal_at_goal_path(Transf
         TransformP(Goal0, MaybeGoal)
     ).
 
+transform_all_goals(Transform, Goal0, Goal) :-
+    GoalExpr0 = Goal0 ^ hlds_goal_expr,  
+    (
+        ( GoalExpr0 = unify(_, _, _, _, _) 
+        ; GoalExpr0 = plain_call(_, _, _, _, _, _)
+        ; GoalExpr0 = generic_call(_, _, _, _)
+        ; GoalExpr0 = call_foreign_proc(_, _, _, _, _, _, _)
+        ),
+        GoalExpr = GoalExpr0
+    ;
+        GoalExpr0 = conj(ConjType, Conjs0),
+        list.map(transform_all_goals(Transform), Conjs0, Conjs),
+        GoalExpr = conj(ConjType, Conjs)
+    ;
+        GoalExpr0 = disj(Disjs0),
+        list.map(transform_all_goals(Transform), Disjs0, Disjs),
+        GoalExpr = disj(Disjs)
+    ;
+        GoalExpr0 = switch(Var, CanFail, Cases0),
+        list.map((pred(Case0::in, Case::out) is det :-
+                GoalI0 = Case0 ^ case_goal,
+                transform_all_goals(Transform, GoalI0, GoalI),
+                Case = Case0 ^ case_goal := GoalI
+            ), Cases0, Cases),
+        GoalExpr = switch(Var, CanFail, Cases)
+    ;
+        GoalExpr0 = negation(SubGoal0),
+        transform_all_goals(Transform, SubGoal0, SubGoal),
+        GoalExpr = negation(SubGoal)
+    ;
+        GoalExpr0 = scope(Reason, SubGoal0),
+        transform_all_goals(Transform, SubGoal0, SubGoal),
+        GoalExpr = scope(Reason, SubGoal)
+    ;
+        GoalExpr0 = if_then_else(ExistVars, Cond0, Then0, Else0),
+        transform_all_goals(Transform, Cond0, Cond),
+        transform_all_goals(Transform, Then0, Then),
+        transform_all_goals(Transform, Else0, Else),
+        GoalExpr = if_then_else(ExistVars, Cond, Then, Else)
+    ;
+        GoalExpr0 = shorthand(_),
+        unexpected(this_file, 
+            "Shorthand goals should have been eliminated already")
+    ),
+    Goal1 = Goal0 ^ hlds_goal_expr := GoalExpr, 
+    Transform(Goal1, Goal).
+
 %-----------------------------------------------------------------------------%
 
 :- func this_file = string.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20090206/be334163/attachment.sig>


More information about the reviews mailing list