[m-rev.] diff: avoid massive lists in sharing analysis

Peter Wang novalazy at gmail.com
Fri Jan 25 11:17:57 AEDT 2008


Estimated hours taken: 0.5
Branches: main

Accumulate the reasons for why structure sharing analysis generated the `top'
element in sets of strings rather than lists.  This prevents building up
massive lists (with mainly duplicate elements) when analysing some modules.

compiler/prog_ctgc.m:
compiler/prog_data.m:
compiler/structure_sharing.domain.m:
	Change the `structure_sharing_domain' and `sharing_as' types to use
	sets of messages.

	Conform to the change everywhere.

Index: compiler/prog_ctgc.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/prog_ctgc.m,v
retrieving revision 1.15
diff -u -r1.15 prog_ctgc.m
--- compiler/prog_ctgc.m	1 Dec 2006 15:04:15 -0000	1.15
+++ compiler/prog_ctgc.m	25 Jan 2008 00:04:05 -0000
@@ -354,8 +354,8 @@
         ;
             Cons = "top",
             context_to_string(Context, ContextMsg),
-            SharingAs0 = structure_sharing_top(["imported top: "
-                ++ ContextMsg ++ "."])
+            SharingAs0 = structure_sharing_top(
+                set.make_singleton_set("imported top: " ++ ContextMsg ++ "."))
         )
     ->
         SharingAs = SharingAs0
@@ -442,7 +442,8 @@
         Term = term.functor(term.atom("unknown_sharing"), [], Context),
         context_to_string(Context, ContextString),
         Msg = "user declared top(" ++ ContextString ++ ")",
-        UserSharing = user_sharing(structure_sharing_top([Msg]), no)
+        UserSharing = user_sharing(structure_sharing_top(
+            set.make_singleton_set(Msg)), no)
     ;
         Term = term.functor(term.atom("sharing"),
             [TypesTerm, UserSharingTerm], _),
@@ -624,7 +625,8 @@
         ;
             VerboseTop = yes,
             io.write_string("top([", !IO),
-            io.write_list(Msgs, Separator, io.write_string, !IO),
+            io.write_list(set.to_sorted_list(Msgs), Separator, io.write_string,
+                !IO),
             io.write_string("])", !IO)
         )
     ;
Index: compiler/prog_data.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/prog_data.m,v
retrieving revision 1.202
diff -u -r1.202 prog_data.m
--- compiler/prog_data.m	22 Jan 2008 15:06:14 -0000	1.202
+++ compiler/prog_data.m	25 Jan 2008 00:04:06 -0000
@@ -356,7 +356,7 @@
 :- type structure_sharing_domain
     --->    structure_sharing_bottom
     ;       structure_sharing_real(structure_sharing)
-    ;       structure_sharing_top(list(top_feedback)).
+    ;       structure_sharing_top(set(top_feedback)).

     % Public representation of structure sharing.
     %
Index: compiler/structure_sharing.domain.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/structure_sharing.domain.m,v
retrieving revision 1.23
diff -u -r1.23 structure_sharing.domain.m
--- compiler/structure_sharing.domain.m	21 Jan 2008 05:23:32 -0000	1.23
+++ compiler/structure_sharing.domain.m	25 Jan 2008 00:04:06 -0000
@@ -307,28 +307,30 @@
 :- type sharing_as
     --->    sharing_as_real_as(sharing_set)
     ;       sharing_as_bottom
-    ;       sharing_as_top(list(string)).
+    ;       sharing_as_top(set(string)).

 sharing_as_init = sharing_as_bottom.
+
 sharing_as_is_bottom(sharing_as_bottom).
-sharing_as_top_sharing(Msg) = sharing_as_top([Msg]).
+
+sharing_as_top_sharing(Msg) = sharing_as_top(set.make_singleton_set(Msg)).
+
 sharing_as_top_sharing_accumulate(Msg, SharingAs) = TopSharing :-
     (
-        SharingAs = sharing_as_real_as(_),
-        Msgs = [Msg]
-    ;
-        SharingAs = sharing_as_bottom,
-        Msgs = [Msg]
+        ( SharingAs = sharing_as_real_as(_)
+        ; SharingAs = sharing_as_bottom
+        ),
+        TopSharing = sharing_as_top_sharing(Msg)
     ;
         SharingAs = sharing_as_top(Msgs0),
-        list.cons(Msg, Msgs0, Msgs)
-    ),
-    TopSharing = sharing_as_top(Msgs).
+        Msgs = set.insert(Msgs0, Msg),
+        TopSharing = sharing_as_top(Msgs)
+    ).

 sharing_as_is_top(sharing_as_top(_)).

 sharing_as_size(sharing_as_bottom) = 0.
-sharing_as_size(sharing_as_real_as(SharingSet)) =
sharing_set_size(SharingSet).
+sharing_as_size(sharing_as_real_as(SharingSet)) = sharing_set_size(SharingSet).

 sharing_as_short_description(sharing_as_bottom) = "b".
 sharing_as_short_description(sharing_as_top(_)) = "t".
@@ -406,7 +408,7 @@
     ;
         NewSharing = sharing_as_top(MsgNew),
         ( OldSharing = sharing_as_top(MsgOld) ->
-            ResultSharing = sharing_as_top(list.append(MsgNew, MsgOld))
+            ResultSharing = sharing_as_top(set.union(MsgNew, MsgOld))
         ;
             ResultSharing = NewSharing
         )
@@ -661,7 +663,7 @@
     ;
         Sharing1 = sharing_as_top(Msg1),
         ( Sharing2 = sharing_as_top(Msg2) ->
-            Sharing = sharing_as_top(list.append(Msg1, Msg2))
+            Sharing = sharing_as_top(set.union(Msg1, Msg2))
         ;
             Sharing = Sharing1
         )
--------------------------------------------------------------------------
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