[m-rev.] diff: Fix report_memory_attribution predicates.

Peter Wang novalazy at gmail.com
Thu May 24 14:06:18 AEST 2018


The bodies of the pure report_memory_attribution predicates were
optimised away due to a misused `promise_pure'.

library/benchmarking.m:
    Swap pure and impure report_memory_attribution predicates.

    Make the impure predicates be a wrapper that calls the pure
    predicate in a trace goal.
---
 library/benchmarking.m | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/library/benchmarking.m b/library/benchmarking.m
index 41b5b25bf..f36ed33ed 100644
--- a/library/benchmarking.m
+++ b/library/benchmarking.m
@@ -222,45 +222,43 @@ extern void ML_report_full_memory_stats(void);
 
 :- pragma foreign_proc("Erlang",
     report_stats,
     [may_call_mercury, terminates],
 "
     'ML_report_stats'()
 ").
 
 %---------------------------------------------------------------------------%
 
-report_memory_attribution(Label, Collect, !IO) :-
-    promise_pure (
-        impure report_memory_attribution(Label, Collect)
-    ).
+report_memory_attribution(Label, Collect) :-
+    trace [io(!IO)] (
+        report_memory_attribution(Label, Collect, !IO)
+    ),
+    impure impure_true.
 
 :- pragma foreign_proc("C",
-    report_memory_attribution(Label::in, RunCollect::in),
-    [will_not_call_mercury],
+    report_memory_attribution(Label::in, Collect::in, _IO0::di, _IO::uo),
+    [will_not_call_mercury, promise_pure],
 "
-    MR_bool mr_run_collect = RunCollect == MR_YES ? MR_TRUE : MR_FALSE;
+    MR_bool collect = (Collect) ? MR_TRUE : MR_FALSE;
 
 #ifdef  MR_MPROF_PROFILE_MEMORY_ATTRIBUTION
-    MR_report_memory_attribution(Label, mr_run_collect);
+    MR_report_memory_attribution(Label, collect);
 #else
     (void) Label;
 #endif
 ").
 
-report_memory_attribution(_, _) :-
-    impure impure_true.
+report_memory_attribution(_, _, !IO).
 
 report_memory_attribution(Label, !IO) :-
-    promise_pure (
-        impure report_memory_attribution(Label)
-    ).
+    report_memory_attribution(Label, yes, !IO).
 
 report_memory_attribution(Label) :-
     impure report_memory_attribution(Label, yes).
 
 %---------------------------------------------------------------------------%
 
 :- pragma foreign_code("C", "
 
 #include <stdio.h>
 #include <stdlib.h>
-- 
2.17.0



More information about the reviews mailing list