[m-rev.] for review: fix unused args optimisation with intermodule analysis

Peter Wang wangp at students.cs.mu.OZ.AU
Wed Dec 7 13:52:34 AEDT 2005


Estimated hours taken: 5
Branches: main

compiler/unused_args.m:
	Fix `unused_args_answer_from_string' which was not reading in the
	output of `unused_args_answer_to_string' correctly.

	Disable an assertion in `fixup_unused_args' which seems to be invalid
	with intermodule analysis.

Index: compiler/unused_args.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/unused_args.m,v
retrieving revision 1.114
diff -u -r1.114 unused_args.m
--- compiler/unused_args.m	28 Nov 2005 04:11:59 -0000	1.114
+++ compiler/unused_args.m	7 Dec 2005 02:42:50 -0000
@@ -192,20 +192,8 @@
 :- func unused_args_answer_from_string(string) = unused_args_answer is semidet.
 
 unused_args_answer_from_string(String) = unused_args(Args) :-
-    string__foldl2(accumulate_ints_from_chars, String, [], Digits, [], Args0),
-    Args = list__reverse([det_to_int(from_rev_char_list(Digits)) | Args0]),
-    semidet_succeed.
-
-:- pred accumulate_ints_from_chars(char::in,
-    list(char)::in, list(char)::out, list(int)::in, list(int)::out) is det.
-
-accumulate_ints_from_chars(Char, !Digits, !Ints) :-
-    ( char__is_digit(Char) ->
-        !:Digits = [Char | !.Digits]
-    ;
-        !:Digits = [],
-        !:Ints = [det_to_int(from_rev_char_list(!.Digits)) | !.Ints]
-    ).
+    Words = string.words(String),
+    list.map(string.to_int, Words, Args).
 
 %-----------------------------------------------------------------------------%
 
@@ -1245,10 +1233,23 @@
 
 fixup_unused_args(VarUsage, PredProcs, ProcCallInfo, !ModuleInfo, VeryVerbose,
         !IO) :-
-    map__keys(VarUsage, VarUsageKeys),
-    list__sort(PredProcs, SortedPredProcs),
-    expect(unify(VarUsageKeys, SortedPredProcs),
-        this_file, "fixup_unused_args: VarUsageKeys != SortedPredProcs"),
+    globals__io_lookup_bool_option(intermodule_analysis, Intermod, !IO),
+    (
+        Intermod = yes
+        % The following assertion is invalid with intermodule analysis.
+        % setup_proc_args handles opt_imported procedures specially.  For such
+        % procedures the pred_proc_id is not added to PredProcs but _is_ added
+        % as to the VarUsage map.  A pred_info is also added to the
+        % ProcCallInfo table, so if we did add the pred_proc_id to PredProcs
+        % then an exception is thrown later as we try to insert another
+        % proc_call_info for the same procedure.
+    ;
+        Intermod = no,
+        map__keys(VarUsage, VarUsageKeys),
+        list__sort(PredProcs, SortedPredProcs),
+        expect(unify(VarUsageKeys, SortedPredProcs),
+            this_file, "fixup_unused_args: VarUsageKeys != SortedPredProcs")
+    ),
     list__foldl2(fixup_unused_args_proc(VeryVerbose, VarUsage, ProcCallInfo),
         PredProcs, !ModuleInfo, !IO).
 
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list