[m-rev.] diff: avoid unnecessary conversion

Zoltan Somogyi zs at csse.unimelb.edu.au
Thu Jul 21 18:01:15 AEST 2011


compiler/stack_layout.m:
	Avoid a set->list->set round-trip conversion.

library/set.m:
library/set_ordlist.m:
	Add a predicate version of trues-only filter to make this possible.

Zoltan.

cvs diff: Diffing .
cvs diff: Diffing analysis
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/doc
cvs diff: Diffing boehm_gc/extra
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/extra
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/libatomic_ops
cvs diff: Diffing boehm_gc/libatomic_ops/doc
cvs diff: Diffing boehm_gc/libatomic_ops/src
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/armcc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/gcc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/hpc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/ibmc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/icc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/msftc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/sunc
cvs diff: Diffing boehm_gc/libatomic_ops/tests
cvs diff: Diffing boehm_gc/libatomic_ops-1.2
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/doc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/tests
cvs diff: Diffing boehm_gc/m4
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
Index: compiler/stack_layout.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/stack_layout.m,v
retrieving revision 1.161
diff -u -b -r1.161 stack_layout.m
--- compiler/stack_layout.m	24 May 2011 09:14:07 -0000	1.161
+++ compiler/stack_layout.m	21 Jul 2011 07:27:22 -0000
@@ -1192,18 +1192,18 @@
     string_table::in, string_table::out) is det.
 
 construct_var_name_rvals([], _CurNum, MaxNum, MaxNum, [], !StringTable).
-construct_var_name_rvals([Var - Name | VarNamesTail], CurNum,
-        !MaxNum, [Offset | OffsetsTail], !StringTable) :-
+construct_var_name_rvals(VarNamesHeadTail @ [Var - Name | VarNamesTail],
+        CurNum, !MaxNum, [Offset | OffsetsTail], !StringTable) :-
     ( Var = CurNum ->
         lookup_string_in_table(Name, Offset, !StringTable),
         !:MaxNum = Var,
         VarNames = VarNamesTail
     ;
         Offset = 0,
-        VarNames = [Var - Name | VarNamesTail]
+        VarNames = VarNamesHeadTail
     ),
-    construct_var_name_rvals(VarNames, CurNum + 1,
-        !MaxNum, OffsetsTail, !StringTable).
+    construct_var_name_rvals(VarNames,
+        CurNum + 1, !MaxNum, OffsetsTail, !StringTable).
 
 %---------------------------------------------------------------------------%
 
@@ -1419,22 +1419,24 @@
         map.init(ReturnTypeVarMap)
     ;
         Return = yes(return_layout_info(_, ReturnLayout)),
-        ReturnLayout = layout_label_info(ReturnLiveVarSet0, ReturnTypeVarMap0),
+        ReturnLayout = layout_label_info(ReturnLiveVarSet0, ReturnTypeVarMap),
         (
             AgcStackLayout = yes,
-            ReturnLiveVarSet = ReturnLiveVarSet0,
-            ReturnTypeVarMap = ReturnTypeVarMap0
+            ReturnLiveVarSet = ReturnLiveVarSet0
         ;
             AgcStackLayout = no,
             % This set of variables must be for uplevel printing in execution
             % tracing, so we are interested only in (a) variables, not
             % temporaries, (b) only named variables, and (c) only those
             % on the stack, not the return values.
-            set.to_sorted_list(ReturnLiveVarSet0, ReturnLiveVarList0),
-            select_trace_return(
-                ReturnLiveVarList0, ReturnTypeVarMap0,
-                ReturnLiveVarList, ReturnTypeVarMap),
-            set.list_to_set(ReturnLiveVarList, ReturnLiveVarSet)
+            %
+            % At the moment, we use ReturnTypeVarMap unchanged. Due to the
+            % deletions done by this filtering, this map may be bigger than
+            % necessary, but this fact does not compromise correctness.
+            % We use the unchanged ReturnTypeVarMap to avoid having to scan
+            % the types of all the selected layout_var_infos.
+            set.filter(select_trace_return,
+                ReturnLiveVarSet0, ReturnLiveVarSet)
         )
     ),
     (
@@ -1623,24 +1625,16 @@
 
     % Given a list of layout_var_infos and the type variables that occur
     % in them, select only the layout_var_infos that may be required
-    % by up-level printing in the trace-based debugger. At the moment
-    % the typeinfo list we return may be bigger than necessary, but this
-    % does not compromise correctness; we do this to avoid having to
-    % scan the types of all the selected layout_var_infos.
-    %
-:- pred select_trace_return(
-    list(layout_var_info)::in, map(tvar, set(layout_locn))::in,
-    list(layout_var_info)::out, map(tvar, set(layout_locn))::out) is det.
+    % by up-level printing in the trace-based debugger.
+    %
+:- pred select_trace_return(layout_var_info::in) is semidet.
 
-select_trace_return(Infos, TVars, TraceReturnInfos, TVars) :-
-    IsNamedReturnVar = (pred(LocnInfo::in) is semidet :-
+select_trace_return(LocnInfo) :-
         LocnInfo = layout_var_info(Locn, LvalType, _),
         LvalType = live_value_var(_, Name, _, _),
         Name \= "",
         ( Locn = locn_direct(Lval) ; Locn = locn_indirect(Lval, _)),
-        ( Lval = stackvar(_) ; Lval = framevar(_) )
-    ),
-    list.filter(IsNamedReturnVar, Infos, TraceReturnInfos).
+    ( Lval = stackvar(_) ; Lval = framevar(_) ).
 
     % Given a list of layout_var_infos, put the ones that tracing can be
     % interested in (whether at an internal port or for uplevel printing)
cvs diff: Diffing compiler/notes
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/base64
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/curs
cvs diff: Diffing extras/curs/samples
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/error
cvs diff: Diffing extras/fixed
cvs diff: Diffing extras/gator
cvs diff: Diffing extras/gator/generations
cvs diff: Diffing extras/gator/generations/1
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/easyx
cvs diff: Diffing extras/graphics/easyx/samples
cvs diff: Diffing extras/graphics/mercury_allegro
cvs diff: Diffing extras/graphics/mercury_allegro/examples
cvs diff: Diffing extras/graphics/mercury_allegro/samples
cvs diff: Diffing extras/graphics/mercury_allegro/samples/demo
cvs diff: Diffing extras/graphics/mercury_allegro/samples/mandel
cvs diff: Diffing extras/graphics/mercury_allegro/samples/pendulum2
cvs diff: Diffing extras/graphics/mercury_allegro/samples/speed
cvs diff: Diffing extras/graphics/mercury_cairo
cvs diff: Diffing extras/graphics/mercury_cairo/samples
cvs diff: Diffing extras/graphics/mercury_cairo/samples/data
cvs diff: Diffing extras/graphics/mercury_cairo/tutorial
cvs diff: Diffing extras/graphics/mercury_glut
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/gears
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/lex/tests
cvs diff: Diffing extras/log4m
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/monte
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/moose/tests
cvs diff: Diffing extras/mopenssl
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/net
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/posix/samples
cvs diff: Diffing extras/quickcheck
cvs diff: Diffing extras/quickcheck/tutes
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/solver_types
cvs diff: Diffing extras/solver_types/library
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/windows_installer_generator
cvs diff: Diffing extras/windows_installer_generator/sample
cvs diff: Diffing extras/windows_installer_generator/sample/images
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing extras/xml_stylesheets
cvs diff: Diffing java
cvs diff: Diffing java/runtime
cvs diff: Diffing library
Index: library/set.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/set.m,v
retrieving revision 1.94
diff -u -b -r1.94 set.m
--- library/set.m	26 May 2011 06:20:08 -0000	1.94
+++ library/set.m	19 Jul 2011 07:34:48 -0000
@@ -251,6 +251,8 @@
     %
 :- func set.filter(pred(T1), set(T1)) = set(T1).
 :- mode set.filter(pred(in) is semidet, in) = out is det.
+:- pred set.filter(pred(T1), set(T1), set(T1)).
+:- mode set.filter(pred(in) is semidet, in, out) is det.
 
     % Return the set of items for which the given predicate succeeds,
     % and the set of items for which it fails.
@@ -577,6 +579,9 @@
 set.filter(P, Set) =
     set_ordlist.filter(P, Set).
 
+set.filter(P, Set, TrueSet) :-
+    set_ordlist.filter(P, Set, TrueSet).
+
 set.filter(P, Set, TrueSet, FalseSet) :-
     set_ordlist.filter(P, Set, TrueSet, FalseSet).
 
Index: library/set_ordlist.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/set_ordlist.m,v
retrieving revision 1.40
diff -u -b -r1.40 set_ordlist.m
--- library/set_ordlist.m	21 Jul 2011 06:58:34 -0000	1.40
+++ library/set_ordlist.m	21 Jul 2011 06:59:22 -0000
@@ -229,6 +229,8 @@
     %
 :- func set_ordlist.filter(pred(T1), set_ordlist(T1)) = set_ordlist(T1).
 :- mode set_ordlist.filter(pred(in) is semidet, in) = out is det.
+:- pred set_ordlist.filter(pred(T1), set_ordlist(T1), set_ordlist(T1)).
+:- mode set_ordlist.filter(pred(in) is semidet, in, out) is det.
 
     % Return the set of items for which the given predicate succeeds,
     % and the set of items for which it fails.
@@ -717,6 +719,9 @@
     list.filter(P, List, TrueList),
     set_ordlist.sorted_list_to_set(TrueList, TrueSet).
 
+set_ordlist.filter(P, Set, TrueSet) :-
+    TrueSet = set_ordlist.filter(P, Set).
+
 set_ordlist.filter(P, Set, TrueSet, FalseSet) :-
     List = set_ordlist.to_sorted_list(Set),
     list.filter(P, List, TrueList, FalseList),
cvs diff: Diffing mdbcomp
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/appengine
cvs diff: Diffing samples/appengine/war
cvs diff: Diffing samples/appengine/war/WEB-INF
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/standalone_c
cvs diff: Diffing samples/concurrency
cvs diff: Diffing samples/concurrency/dining_philosophers
cvs diff: Diffing samples/concurrency/midimon
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/java_interface
cvs diff: Diffing samples/java_interface/java_calls_mercury
cvs diff: Diffing samples/java_interface/mercury_calls_java
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/solver_types
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing slice
cvs diff: Diffing ssdb
cvs diff: Diffing tests
cvs diff: Diffing tests/analysis
cvs diff: Diffing tests/analysis/ctgc
cvs diff: Diffing tests/analysis/excp
cvs diff: Diffing tests/analysis/ext
cvs diff: Diffing tests/analysis/sharing
cvs diff: Diffing tests/analysis/table
cvs diff: Diffing tests/analysis/trail
cvs diff: Diffing tests/analysis/unused_args
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/general/string_format
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/grade_subdirs
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/mmc_make
cvs diff: Diffing tests/mmc_make/lib
cvs diff: Diffing tests/par_conj
cvs diff: Diffing tests/recompilation
cvs diff: Diffing tests/stm
cvs diff: Diffing tests/stm/orig
cvs diff: Diffing tests/stm/orig/stm-compiler
cvs diff: Diffing tests/stm/orig/stm-compiler/test1
cvs diff: Diffing tests/stm/orig/stm-compiler/test10
cvs diff: Diffing tests/stm/orig/stm-compiler/test2
cvs diff: Diffing tests/stm/orig/stm-compiler/test3
cvs diff: Diffing tests/stm/orig/stm-compiler/test4
cvs diff: Diffing tests/stm/orig/stm-compiler/test5
cvs diff: Diffing tests/stm/orig/stm-compiler/test6
cvs diff: Diffing tests/stm/orig/stm-compiler/test7
cvs diff: Diffing tests/stm/orig/stm-compiler/test8
cvs diff: Diffing tests/stm/orig/stm-compiler/test9
cvs diff: Diffing tests/stm/orig/stm-compiler-par
cvs diff: Diffing tests/stm/orig/stm-compiler-par/bm1
cvs diff: Diffing tests/stm/orig/stm-compiler-par/bm2
cvs diff: Diffing tests/stm/orig/stm-compiler-par/stmqueue
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test1
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test10
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test11
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test2
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test3
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test4
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test5
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test6
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test7
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test8
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test9
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test1
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test2
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test3
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test4
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test5
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test6
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test7
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test8
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test9
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/trailing
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
cvs diff: Diffing util
cvs diff: Diffing vim
cvs diff: Diffing vim/after
cvs diff: Diffing vim/ftplugin
cvs diff: Diffing vim/syntax
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list