[m-rev.] diff: Fixed variable use analysis

Paul Bone pbone at csse.unimelb.edu.au
Sun Oct 10 15:20:29 AEDT 2010


Variable use analysis now uses conservative assumptions for recursive call costs
when recursive call site cost information cannot be computed.

deep_profiler/var_use_analysis.m:
    The var use analysis predicates now use instantiation state subtypes for
    the recursion type information.

    Only look for variable use in recursive calls if we know the cost of the
    recursive call.

    In call_var_first_use, use map.lookup to get the cost of a call site rather
    than map.search.  All call site costs are now guaranteed to be known since
    this predicate is only valid for recursion types that provide this
    information.

deep_profiler/recursion_patterns.m:
    Fix bugs in the calculation of recursion data in semidet code.

    Use instantiation states to support the  subtypes used in
    var_use_analysis.m.

deep_profiler/measurements.m:
    Add a new abstract type, recursion_depth.

deep_profiler/analysis_utils.m:
deep_profiler/recursion_patterns.m:
deep_profiler/mdprof_fb.automatic_parallelism.m:
    Conform to changes in measurements.m

Index: deep_profiler/analysis_utils.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/analysis_utils.m,v
retrieving revision 1.1
diff -u -p -b -r1.1 analysis_utils.m
--- deep_profiler/analysis_utils.m	7 Oct 2010 02:38:09 -0000	1.1
+++ deep_profiler/analysis_utils.m	10 Oct 2010 04:17:48 -0000
@@ -77,8 +77,8 @@
     % current call to this procedure had a particular cost.
     %
 :- pred build_recursive_call_site_cost_map(deep, clique_ptr,
-    proc_dynamic_ptr, recursion_type, maybe(float), maybe_error(map(goal_path,
-    cs_cost_csq))) is det.
+    proc_dynamic_ptr, recursion_type, maybe(recursion_depth), 
+    maybe_error(map(goal_path, cs_cost_csq))) is det.
 :- mode build_recursive_call_site_cost_map(in, in, in,
     in(recursion_type_known_costs), in(maybe_yes(ground)), 
     out(maybe_error_ok(ground))) is det.
@@ -218,8 +218,8 @@ build_recursive_call_site_cost_map(Deep,
     ;
         RecursionType = rt_single(_, _, _AvgMaxDepth, _AvgRecCost, CostFn),
         (
-            MaybeDepth = yes(DepthF),
-            Depth = round_to_int(DepthF)
+            MaybeDepth = yes(Depth),
+            DepthI = recursion_depth_to_int(Depth)
         ;
             MaybeDepth = no,
             error(this_file ++ "Expected valid depth for known recursion type")
@@ -229,7 +229,7 @@ build_recursive_call_site_cost_map(Deep,
             CallCountsMap),
         RecursiveCallSiteCostMap = map_values_only(
             (func(Count) = 
-                build_cs_cost_csq_percall(float(Count), CostFn(Depth))),
+                build_cs_cost_csq_percall(float(Count), CostFn(DepthI))),
             CallCountsMap),
         MaybeRecursiveCallSiteCostMap = ok(RecursiveCallSiteCostMap),
         
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.17
diff -u -p -b -r1.17 mdprof_fb.automatic_parallelism.m
--- deep_profiler/mdprof_fb.automatic_parallelism.m	7 Oct 2010 02:38:09 -0000	1.17
+++ deep_profiler/mdprof_fb.automatic_parallelism.m	10 Oct 2010 04:17:48 -0000
@@ -2470,7 +2470,7 @@ compute_var_modes_and_uses_lazy(Info, Go
     ).
 
 :- pred compute_var_modes_and_uses_2(implicit_parallelism_info::in,
-    int::in, recursion_type::in, maybe(float)::in, var_use_type::in,
+    int::in, recursion_type::in, maybe(recursion_depth)::in, var_use_type::in,
     float::in, call_site_dynamic_ptr::in, var_use_info::out, 
     cord(message)::out) is det.
 
@@ -2492,16 +2492,16 @@ compute_var_modes_and_uses_2(Info, ArgNu
     ).
 
 :- pred recursion_type_get_interesting_parallelisation_depth(
-    recursion_type::in, maybe(float)::out) is det.
+    recursion_type::in, maybe(recursion_depth)::out) is det.
 
 recursion_type_get_interesting_parallelisation_depth(RecursionType,
         MaybeDepth) :-
     (
         RecursionType = rt_not_recursive,
-        MaybeDepth = yes(0.0)
+        MaybeDepth = yes(recursion_depth_from_float(0.0))
     ;
-        RecursionType = rt_single(_, _, Depth, _, _),
-        MaybeDepth = yes(Depth / 2.0)
+        RecursionType = rt_single(_, _, DepthF, _, _),
+        MaybeDepth = yes(recursion_depth_from_float(DepthF / 2.0))
     ;
         ( RecursionType = rt_divide_and_conquer(_, _)
         ; RecursionType = rt_mutual_recursion(_)
Index: deep_profiler/measurements.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/measurements.m,v
retrieving revision 1.21
diff -u -p -b -r1.21 measurements.m
--- deep_profiler/measurements.m	22 Sep 2010 12:56:54 -0000	1.21
+++ deep_profiler/measurements.m	10 Oct 2010 04:17:48 -0000
@@ -145,6 +145,18 @@
 
 %-----------------------------------------------------------------------------%
 
+:- type recursion_depth.
+
+:- func recursion_depth_from_float(float) = recursion_depth.
+
+:- func recursion_depth_to_float(recursion_depth) = float.
+:- func recursion_depth_to_int(recursion_depth) = int.
+
+:- pred recursion_depth_descend(recursion_depth, recursion_depth).
+:- mode recursion_depth_descend(in, out) is det.
+
+%-----------------------------------------------------------------------------%
+
 :- type static_coverage_info.
 
 :- func zero_static_coverage = static_coverage_info.
@@ -688,6 +700,19 @@ Cost0 / Denom = Cost :-
 
 %----------------------------------------------------------------------------%
 
+:- type recursion_depth
+    --->    recursion_depth(float).
+
+recursion_depth_from_float(F) = recursion_depth(F).
+
+recursion_depth_to_float(recursion_depth(F)) = F.
+recursion_depth_to_int(D) = 
+    round_to_int(recursion_depth_to_float(D)).
+
+recursion_depth_descend(recursion_depth(D), recursion_depth(D - 1.0)).
+
+%----------------------------------------------------------------------------%
+
 :- type static_coverage_info == maybe(array(int)).
 
 zero_static_coverage = no.
Index: deep_profiler/recursion_patterns.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/recursion_patterns.m,v
retrieving revision 1.6
diff -u -p -b -r1.6 recursion_patterns.m
--- deep_profiler/recursion_patterns.m	8 Oct 2010 12:48:56 -0000	1.6
+++ deep_profiler/recursion_patterns.m	10 Oct 2010 04:17:48 -0000
@@ -18,9 +18,9 @@
 :- interface.
 
 :- import_module report.
+:- import_module measurements.
 :- import_module profile.
 
-:- import_module float.
 :- import_module maybe.
             
 %----------------------------------------------------------------------------%
@@ -33,8 +33,11 @@
 
 %----------------------------------------------------------------------------%
 
-:- pred recursion_type_get_maybe_avg_max_depth(recursion_type::in,
-    maybe(float)::out) is det.
+:- pred recursion_type_get_maybe_avg_max_depth(recursion_type,
+    maybe(recursion_depth)).
+:- mode recursion_type_get_maybe_avg_max_depth(in(recursion_type_known_costs),
+    out(maybe_yes(ground))) is det.
+:- mode recursion_type_get_maybe_avg_max_depth(in, out) is det.
 
 %----------------------------------------------------------------------------%
 %----------------------------------------------------------------------------%
@@ -301,12 +304,12 @@ goal_recursion_data(ThisClique, CallSite
     ;
         (
             GoalExpr = conj_rep(Conjs),
-            conj_recursion_data(ThisClique, CallSiteMap, GoalPath, 1, certain,
-                Conjs, !:RecursionData)
+            conj_recursion_data(ThisClique, CallSiteMap, GoalPath, 1, Conjs, 
+                !:RecursionData)
         ;
             GoalExpr = disj_rep(Disjs),
-            disj_recursion_data(ThisClique, CallSiteMap, GoalPath, 1, certain, 
-                Disjs, !:RecursionData)
+            disj_recursion_data(ThisClique, CallSiteMap, GoalPath, 1, Disjs, 
+                !:RecursionData)
         ;
             GoalExpr = switch_rep(_, _, Cases),
             switch_recursion_data(ThisClique, CallSiteMap, GoalPath, 1, Cases,
@@ -350,13 +353,12 @@ goal_recursion_data(ThisClique, CallSite
 
 :- pred conj_recursion_data(clique_ptr::in, 
     map(goal_path, cost_and_callees)::in, goal_path::in, int::in,
-    probability::in, list(goal_rep(coverage_info))::in, recursion_data::out)
-    is det.
+    list(goal_rep(coverage_info))::in, recursion_data::out) is det.
 
     % An empty conjunction is true, there is exactly one trival path through it
     % with 0 recursive calls.
-conj_recursion_data(_, _, _, _, _, [], simple_recursion_data(0.0, 0)).
-conj_recursion_data(ThisClique, CallSiteMap, GoalPath, ConjNum, SuccessProb0, 
+conj_recursion_data(_, _, _, _, [], simple_recursion_data(0.0, 0)).
+conj_recursion_data(ThisClique, CallSiteMap, GoalPath, ConjNum, 
         [Conj | Conjs], RecursionData) :- 
     goal_recursion_data(ThisClique, CallSiteMap, 
         goal_path_add_at_end(GoalPath, step_conj(ConjNum)), Conj, 
@@ -369,22 +371,42 @@ conj_recursion_data(ThisClique, CallSite
         RecursionData = proc_dead_code
     ;
         ConjRecursionData = recursion_data(_, _, _), 
+        
+        conj_recursion_data(ThisClique, CallSiteMap, GoalPath, ConjNum + 1,
+            Conjs, ConjsRecursionData0),
+        CanFail = detism_get_can_fail(Conj ^ goal_detism_rep),
+        (
+            CanFail = cannot_fail_rep,
+            merge_recursion_data_sequence(ConjRecursionData, 
+                ConjsRecursionData0, RecursionData)
+        ;
+            CanFail = can_fail_rep,
+            % It's possible that the conjunct can fail, in that case the code
+            % branches into one branch that continues with the conjunction and
+            % one that doesn't.
+
         success_probability_from_coverage(Conj ^ goal_annotation,
             ConjSuccessProb),
-        SuccessProb = and(SuccessProb0, ConjSuccessProb),
-        conj_recursion_data(ThisClique, CallSiteMap, GoalPath, ConjNum + 1,
-            SuccessProb, Conjs, ConjsRecursionData),
-        merge_recursion_data_sequence(ConjRecursionData, ConjsRecursionData,
-            RecursionData)
+            recursion_data_and_probability(ConjSuccessProb, ConjsRecursionData0,
+                ConjsRecursionData),
+            
+            ConjFailureProb = not_probability(ConjSuccessProb),
+            Failure0 = simple_recursion_data(0.0, 0),
+            recursion_data_and_probability(ConjFailureProb, Failure0, Failure),
+            merge_recursion_data_after_branch(ConjsRecursionData, Failure,
+                BranchRecursionData),
+            merge_recursion_data_sequence(ConjRecursionData,
+                BranchRecursionData, RecursionData)
+        )
     ).
 
 :- pred disj_recursion_data(clique_ptr::in, 
     map(goal_path, cost_and_callees)::in, goal_path::in, int::in, 
-    probability::in, list(goal_rep(coverage_info))::in, recursion_data::out)
+    list(goal_rep(coverage_info))::in, recursion_data::out)
     is det.
 
-disj_recursion_data(_, _, _, _, _, [], simple_recursion_data(0.0, 0)).
-disj_recursion_data(ThisClique, CallSiteMap, GoalPath, DisjNum, FailureProb0, 
+disj_recursion_data(_, _, _, _, [], simple_recursion_data(0.0, 0)).
+disj_recursion_data(ThisClique, CallSiteMap, GoalPath, DisjNum, 
         [Disj | Disjs], RecursionData) :-
     % Handle only semidet and committed-choice disjunctions, once a goal
     % succeeds it cannot be re-entered.
@@ -398,15 +420,26 @@ disj_recursion_data(ThisClique, CallSite
         RecursionData = proc_dead_code
     ;
         DisjRecursionData = recursion_data(_, _, _),
-        % Handle this just like a semidet conjunction, except that we go to the
-        % next disjunct if it _fails_.
         success_probability_from_coverage(Disj ^ goal_annotation,
-            ConjSuccessProb),
-        ConjFailureProb = not_probability(ConjSuccessProb), 
-        FailureProb = and(FailureProb0, ConjFailureProb),
+            DisjSuccessProb),
+        DisjFailureProb = not_probability(DisjSuccessProb), 
+        
+        % The code can branch here, either it tries the next disjuct, which we
+        % represent as DisjsRecursionData.
         disj_recursion_data(ThisClique, CallSiteMap, GoalPath, DisjNum + 1,
-            FailureProb, Disjs, DisjsRecursionData),
-        merge_recursion_data_sequence(DisjRecursionData, DisjsRecursionData,
+            Disjs, DisjsRecursionData0),
+        recursion_data_and_probability(DisjFailureProb, DisjsRecursionData0,
+            DisjsRecursionData),
+
+        % Or it succeeds which we represent as finished.
+        Finish0 = simple_recursion_data(0.0, 0),
+        recursion_data_and_probability(DisjSuccessProb, Finish0, Finish),
+
+        % Then the result the branch of (DisjsRecursionData or finish) appended
+        % to DisjRecursionData.
+        merge_recursion_data_after_branch(Finish, DisjsRecursionData,
+            BranchRecursionData),
+        merge_recursion_data_sequence(DisjRecursionData, BranchRecursionData,
             RecursionData)
     ).
 
@@ -951,9 +984,10 @@ finalize_histogram_proc_rec_type(Deep, N
 %----------------------------------------------------------------------------%
 %----------------------------------------------------------------------------%
 
-recursion_type_get_maybe_avg_max_depth(rt_not_recursive, yes(0.0)).
+recursion_type_get_maybe_avg_max_depth(rt_not_recursive, 
+    yes(recursion_depth_from_float(0.0))).
 recursion_type_get_maybe_avg_max_depth(rt_single(_, _, Depth, _, _),
-    yes(Depth)).
+    yes(recursion_depth_from_float(Depth))).
 recursion_type_get_maybe_avg_max_depth(rt_divide_and_conquer(_, _), no).
 recursion_type_get_maybe_avg_max_depth(rt_mutual_recursion(_), no).
 recursion_type_get_maybe_avg_max_depth(rt_other(_), no).
Index: deep_profiler/var_use_analysis.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/var_use_analysis.m,v
retrieving revision 1.5
diff -u -p -b -r1.5 var_use_analysis.m
--- deep_profiler/var_use_analysis.m	7 Oct 2010 02:38:10 -0000	1.5
+++ deep_profiler/var_use_analysis.m	10 Oct 2010 04:17:48 -0000
@@ -19,6 +19,7 @@
 
 :- import_module mdbcomp.
 :- import_module mdbcomp.program_representation.
+:- import_module measurements.
 :- import_module profile.
 :- import_module report.
 
@@ -66,9 +67,15 @@
     % variable use that is expected, VarUseType is used to produce conservative
     % defaults if a callee cannot be analyzed.
     %
-:- pred call_site_dynamic_var_use_info(deep::in, call_site_dynamic_ptr::in,
-    int::in, recursion_type::in, float::in, var_use_type::in,
-    maybe_error(var_use_info)::out) is det.
+    % The first mode avoids a check to ensure that this recursion type provides
+    % enough information.
+    %
+:- pred call_site_dynamic_var_use_info(deep, call_site_dynamic_ptr, int,
+    recursion_type, float, var_use_type, maybe_error(var_use_info)).
+:- mode call_site_dynamic_var_use_info(in, in, in,
+    in(recursion_type_known_costs), in, in, out) is det.
+:- mode call_site_dynamic_var_use_info(in, in, in,
+    in, in, in, out) is det.
 
     % call_site_dynamic_var_use_info(Deep, CliquePtr, CSDPtr, ArgPos, RT,
     %   MaybeCurDepth, Cost, CallStack, VarUseType, MaybeVarUseInfo).
@@ -82,16 +89,21 @@
     %
     % Cost is the cost of the call.
     %
-:- pred call_site_dynamic_var_use_info(deep::in, clique_ptr::in,
-    call_site_dynamic_ptr::in, int::in, recursion_type::in, maybe(float)::in,
-    float::in, set(proc_dynamic_ptr)::in,
-    var_use_type::in, maybe_error(var_use_info)::out) is det.
+:- pred call_site_dynamic_var_use_info(deep, clique_ptr, call_site_dynamic_ptr,
+    int, recursion_type, maybe(recursion_depth), float, set(proc_dynamic_ptr),
+    var_use_type, maybe_error(var_use_info)).
+:- mode call_site_dynamic_var_use_info(in, in, in, in,
+    in(recursion_type_known_costs), in(maybe_yes(ground)), in, in, in, out) 
+    is det. 
+:- mode call_site_dynamic_var_use_info(in, in, in, in, 
+    in, in, in, in, in, out) is det.
 
 :- pred clique_var_use_info(deep::in, clique_ptr::in, int::in,
     var_use_type::in, maybe_error(var_use_info)::out) is det.
 
 :- pred proc_dynamic_var_use_info(deep::in, clique_ptr::in,
-    proc_dynamic_ptr::in, int::in, recursion_type::in, maybe(float)::in,
+    proc_dynamic_ptr::in, int::in, 
+    recursion_type::in(recursion_type_known_costs), recursion_depth::in,
     float::in, set(proc_dynamic_ptr)::in, var_use_type::in,
     maybe_error(var_use_info)::out) is det.
 
@@ -102,7 +114,6 @@
 :- import_module analysis_utils.
 :- import_module coverage.
 :- import_module create_report.
-:- import_module measurements.
 :- import_module program_representation_utils.
 :- import_module recursion_patterns.
 
@@ -210,16 +221,29 @@ call_site_dynamic_var_use_info(Deep, Par
             MaybeVarUseInfo = ok(VarUseInfo)
         ;
             (
-                MaybeDepth0 = yes(Depth0),
-                % Depth is measured from the bottom, hence this is -1
-                MaybeDepth = yes(Depth0 - 1.0)
+                ( RecursionType = rt_not_recursive
+                ; RecursionType = rt_single(_, _, _, _, _)
+                ),
+                (
+                    MaybeDepth0 = yes(Depth0)
             ;
-                MaybeDepth0 = no,
-                MaybeDepth = no
+                    error("call_site_dynamic_var_use_info: " ++ 
+                        "A depth must be provided for known recursion types")
             ),
+                recursion_depth_descend(Depth0, Depth),
             proc_dynamic_var_use_info(Deep, ParentCliquePtr, CalleePDPtr,
-                ArgNum, RecursionType, MaybeDepth, Cost, CallStack,
+                    ArgNum, RecursionType, Depth, Cost, CallStack,
                 VarUseType, MaybeVarUseInfo)
+            ;
+                ( RecursionType = rt_divide_and_conquer(_, _)
+                ; RecursionType = rt_mutual_recursion(_)
+                ; RecursionType = rt_other(_)
+                ; RecursionType = rt_errors(_)
+                ),
+                MaybeVarUseInfo = error(
+                    "Cannot compute var use on a recursive call site for an"
+                    ++ " unhandled recursion type")
+            )
         )
     ).
 
@@ -240,17 +264,30 @@ clique_var_use_info(Deep, CliquePtr, Arg
             MaybeRecursionReport = error(Error),
             RecursionType = rt_errors([Error])
         ),
-        recursion_type_get_maybe_avg_max_depth(RecursionType, MaybeDepth),
+        (
+            ( RecursionType = rt_not_recursive
+            ; RecursionType = rt_single(_, _, _, _, _)
+            ),
+            recursion_type_get_maybe_avg_max_depth(RecursionType, yes(Depth)),
         proc_dynamic_var_use_info(Deep, CliquePtr, FirstPDPtr, ArgNum,
-            RecursionType, MaybeDepth, Cost, set.init, VarUseType,
+                RecursionType, Depth, Cost, set.init, VarUseType,
             MaybeVarUseInfo)
     ;
+            ( RecursionType = rt_divide_and_conquer(_, _)
+            ; RecursionType = rt_mutual_recursion(_)
+            ; RecursionType = rt_other(_)
+            ; RecursionType = rt_errors(_)
+            ),
+            pessimistic_var_use_info(VarUseType, Cost, VarUseInfo),
+            MaybeVarUseInfo = ok(VarUseInfo)
+        )
+    ;
         MaybeFirstProc = no,
         error(this_file ++ "Clique has no first procedure")
     ).
 
 proc_dynamic_var_use_info(Deep, CliquePtr, PDPtr, ArgNum, RecursionType,
-        MaybeDepth0, ProcCost, CallStack0, VarUseType, MaybeVarUseInfo) :-
+        Depth0, ProcCost, CallStack0, VarUseType, MaybeVarUseInfo) :-
     set.insert(CallStack0, PDPtr, CallStack),
     create_dynamic_procrep_coverage_report(Deep, PDPtr, MaybeProcrepCoverage),
     (
@@ -276,28 +313,16 @@ proc_dynamic_var_use_info(Deep, CliquePt
                 Slots, map.init, CallSiteCostMap),
             
             % We're following a recursive call, therefore we descend one level.
-            (
-                MaybeDepth0 = yes(Depth0),
-                MaybeDepth = yes(Depth0 - 1.0)
-            ;
-                MaybeDepth0 = no,
-                MaybeDepth = no
-            ),
+            recursion_depth_descend(Depth0, Depth),
             build_recursive_call_site_cost_map(Deep, CliquePtr, PDPtr,
-                RecursionType, MaybeDepth, MaybeRecursiveCallSiteCostMap),
-            (
-                MaybeRecursiveCallSiteCostMap = ok(RecursiveCallSiteCostMap)
-            ;
-                MaybeRecursiveCallSiteCostMap = error(_),
-                % Try to compute var use information without recursion costs.
-                RecursiveCallSiteCostMap = map.init
-            ),
+                RecursionType, yes(Depth), MaybeRecursiveCallSiteCostMap),
+            MaybeRecursiveCallSiteCostMap = ok(RecursiveCallSiteCostMap),
 
             % Do the actual computation.
             Goal = ProcDefn ^ pdr_goal,
             goal_var_first_use_wrapper(Deep, CliquePtr, CallStack,
                 CallSiteCostMap, RecursiveCallSiteCostMap, RecursionType,
-                MaybeDepth, Goal, ProcCost, Var, VarUseType, VarUseInfo),
+                Depth, Goal, ProcCost, Var, VarUseType, VarUseInfo),
             MaybeVarUseInfo = ok(VarUseInfo)
         ;
             PDPtr = proc_dynamic_ptr(PDNum),
@@ -338,7 +363,14 @@ proc_dynamic_var_use_info(Deep, CliquePt
                 fui_call_stack          :: set(proc_dynamic_ptr),
 
                 fui_recursion_type      :: recursion_type,
-                fui_maybe_cur_depth     :: maybe(float)
+                fui_cur_depth           :: recursion_depth
+            ).
+
+:- inst var_first_use_static_info
+    --->    var_first_use_static_info(
+                ground, ground, ground, ground, ground, ground, ground,
+                recursion_type_known_costs,
+                ground
             ).
 
     % Find the first use of a variable in a goal.
@@ -351,8 +383,8 @@ proc_dynamic_var_use_info(Deep, CliquePt
     % use information based on how often they are called from that call site.
     %
 :- pred goal_var_first_use(goal_path::in, goal_rep(coverage_info)::in,
-    var_first_use_static_info::in, float::in, float::out, found_first_use::out)
-    is det.
+    var_first_use_static_info::in(var_first_use_static_info), float::in, 
+    float::out, found_first_use::out) is det.
 
 goal_var_first_use(GoalPath, Goal, StaticInfo, !CostSoFar, FoundFirstUse) :-
     Goal = goal_rep(GoalExpr, Detism, Coverage),
@@ -439,7 +471,8 @@ goal_var_first_use(GoalPath, Goal, Stati
     ;       method_call_rep(ground, ground, ground).
 
 :- pred call_var_first_use(atomic_goal_rep::in(atomic_goal_rep_call),
-    list(var_rep)::in, goal_path::in, var_first_use_static_info::in,
+    list(var_rep)::in, goal_path::in, 
+    var_first_use_static_info::in(var_first_use_static_info),
     float::in, float::out, found_first_use::out) is det.
 
 call_var_first_use(AtomicGoal, BoundVars, GoalPath, StaticInfo,
@@ -451,10 +484,9 @@ call_var_first_use(AtomicGoal, BoundVars
 
     % Get the cost of the call.
     (
-        cost_and_callees_is_recursive(CliquePtr, CostAndCallees),
-        map.search(RecCostMap, GoalPath, CostPrime)
+        cost_and_callees_is_recursive(CliquePtr, CostAndCallees)
     ->
-        Cost0 = CostPrime
+        map.lookup(RecCostMap, GoalPath, Cost0)
     ;
         Cost0 = CostAndCallees ^ cac_cost
     ),
@@ -550,11 +582,12 @@ consume_ho_arg(higher_order_call_rep(Var
 consume_ho_arg(method_call_rep(Var, _, _), Var, 0.0).
 
 :- pred call_args_first_use(list(var_rep)::in, float::in, 
-    var_first_use_static_info::in, cost_and_callees::in, float::out) is nondet.
+    var_first_use_static_info::in(var_first_use_static_info), 
+    cost_and_callees::in, float::out) is nondet.
 
 call_args_first_use(Args, Cost, StaticInfo, CostAndCallees, Time) :-
     StaticInfo = var_first_use_static_info(Deep, CliquePtr, _CostMap,
-        _RecCostMap, Var, VarUseType, CallStack, RecursionType, MaybeCurDepth),
+        _RecCostMap, Var, VarUseType, CallStack, RecursionType, CurDepth),
     HigherOrder = CostAndCallees ^ cac_call_site_is_ho,
     Callees = CostAndCallees ^ cac_callees,
     member_index0(Var, Args, ArgNum), 
@@ -566,7 +599,7 @@ call_args_first_use(Args, Cost, StaticIn
         ; singleton_set(Callees, SingletonCallee) ->
             CSDPtr = SingletonCallee ^ c_csd,
             call_site_dynamic_var_use_info(Deep, CliquePtr, CSDPtr,
-                ArgNum, RecursionType, MaybeCurDepth, Cost, CallStack,
+                ArgNum, RecursionType, yes(CurDepth), Cost, CallStack,
                 VarUseType, MaybeVarUseInfo),
             (
                 MaybeVarUseInfo = ok(VarUseInfo),
@@ -629,7 +662,8 @@ atomic_trivial_var_first_use(AtomicGoal,
     % an execution order, namely disjunctions and if-then-elses.
     %
 :- pred conj_var_first_use(goal_path::in, int::in,
-    list(goal_rep(coverage_info))::in, var_first_use_static_info::in,
+    list(goal_rep(coverage_info))::in, 
+    var_first_use_static_info::in(var_first_use_static_info),
     float::in, float::out, found_first_use::out) is det.
 
 conj_var_first_use(_, _, [], _, !Cost, have_not_found_first_use).
@@ -653,8 +687,8 @@ conj_var_first_use(GoalPath, ConjNum, [C
     ).
 
 :- pred disj_var_first_use(goal_path::in, list(goal_rep(coverage_info))::in,
-    detism_rep::in, var_first_use_static_info::in, float::in, float::out,
-    found_first_use::out) is det.
+    detism_rep::in, var_first_use_static_info::in(var_first_use_static_info), 
+    float::in, float::out, found_first_use::out) is det.
 
 disj_var_first_use(GoalPath, Disjuncts, Detism, StaticInfo,
         !CostSoFar, FoundFirstUse) :-
@@ -687,7 +721,8 @@ disj_var_first_use(GoalPath, Disjuncts, 
     ).
 
 :- pred disj_var_first_use_2(goal_path::in, int::in,
-    list(goal_rep(coverage_info))::in, var_first_use_static_info::in,
+    list(goal_rep(coverage_info))::in,
+    var_first_use_static_info::in(var_first_use_static_info),
     float::in, float::out, found_first_use::out) is det.
 
 disj_var_first_use_2(_, _, [], _, !CostSoFar, have_not_found_first_use).
@@ -749,7 +784,8 @@ disj_var_first_use_2(GoalPath, DisjNum, 
     ).
 
 :- pred switch_var_first_use(goal_path::in, var_rep::in,
-    list(case_rep(coverage_info))::in, var_first_use_static_info::in,
+    list(case_rep(coverage_info))::in, 
+    var_first_use_static_info::in(var_first_use_static_info),
     float::in, float::out, found_first_use::out) is det.
 
 switch_var_first_use(GoalPath, SwitchedOnVar, Cases, StaticInfo,
@@ -784,8 +820,9 @@ switch_var_first_use(GoalPath, SwitchedO
     ).
 
 :- pred switch_var_first_use_2(goal_path::in, int::in,
-    var_first_use_static_info::in, list(case_rep(coverage_info))::in,
-    list(float)::out, float::in, list(float)::out, list(found_first_use)::out)
+    var_first_use_static_info::in(var_first_use_static_info), 
+    list(case_rep(coverage_info))::in, list(float)::out, float::in, 
+    list(float)::out, list(found_first_use)::out)
     is det.
 
 switch_var_first_use_2(_, _, _, [], [], _, [], []).
@@ -807,7 +844,8 @@ switch_var_first_use_2(GoalPath, CaseNum
 
 :- pred ite_var_first_use(goal_path::in, goal_rep(coverage_info)::in,
     goal_rep(coverage_info)::in, goal_rep(coverage_info)::in,
-    var_first_use_static_info::in, float::in, float::out, found_first_use::out)
+    var_first_use_static_info::in(var_first_use_static_info),
+    float::in, float::out, found_first_use::out)
     is det.
 
 ite_var_first_use(GoalPath, Cond, Then, Else, StaticInfo,
@@ -880,17 +918,17 @@ ffu_to_float(_, found_first_use(CostBefo
 :- pred goal_var_first_use_wrapper(deep::in, clique_ptr::in,
     set(proc_dynamic_ptr)::in, 
     map(goal_path, cost_and_callees)::in, map(goal_path, cs_cost_csq)::in, 
-    recursion_type::in, maybe(float)::in,
+    recursion_type::in(recursion_type_known_costs), recursion_depth::in,
     goal_rep(coverage_info)::in, float::in, var_rep::in, 
     var_use_type::in, var_use_info::out) is det.
 
 goal_var_first_use_wrapper(Deep, CliquePtr, CallStack, CallSiteMap,
-        RecursiveCallSiteMap, RT, MaybeCurDepth, Goal, ProcCost, Var,
+        RecursiveCallSiteMap, RT, CurDepth, Goal, ProcCost, Var,
         VarUseType, VarUseInfo) :-
     goal_var_first_use(empty_goal_path, Goal,
         var_first_use_static_info(Deep, CliquePtr, CallSiteMap,
             RecursiveCallSiteMap, Var, VarUseType, CallStack, RT,
-            MaybeCurDepth),
+            CurDepth),
         0.0, _Cost, FoundFirstUse),
     (
         FoundFirstUse = found_first_use(CostUntilUse),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: Digital signature
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20101010/2514a9cc/attachment.sig>


More information about the reviews mailing list