[m-rev.] diff: better switch in unused_imports.m

Zoltan Somogyi zs at unimelb.edu.au
Wed Apr 18 12:22:53 AEST 2012


compiler/unused_imports.m:
	Switch a predicate definition from a bunch of clauses to a disjunction,
	factoring out common code.

Zoltan.

Index: compiler/unused_imports.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/unused_imports.m,v
retrieving revision 1.29
diff -u -b -r1.29 unused_imports.m
--- compiler/unused_imports.m	16 Apr 2012 10:49:05 -0000	1.29
+++ compiler/unused_imports.m	17 Apr 2012 02:51:02 -0000
@@ -596,31 +596,32 @@
 :- pred inst_name_used_modules(item_visibility::in, inst_name::in,
     used_modules::in, used_modules::out) is det.
 
-inst_name_used_modules(Visibility, user_inst(Name, Insts), !UsedModules) :-
+inst_name_used_modules(Visibility, InstName, !UsedModules) :-
+    (
+        InstName = user_inst(Name, Insts),
     add_sym_name_module(Visibility, Name, !UsedModules),
-    list.foldl(mer_inst_used_modules(Visibility), Insts, !UsedModules).
-inst_name_used_modules(Visibility, merge_inst(Inst0, Inst), !UsedModules) :-
-    mer_inst_used_modules(Visibility, Inst0, !UsedModules),
-    mer_inst_used_modules(Visibility, Inst, !UsedModules).
-inst_name_used_modules(Visibility, unify_inst(_, Inst0, Inst, _),
-        !UsedModules) :-
-    mer_inst_used_modules(Visibility, Inst0, !UsedModules),
-    mer_inst_used_modules(Visibility, Inst, !UsedModules).
-inst_name_used_modules(Visibility, ground_inst(InstName, _, _, _),
-        !UsedModules) :-
-    inst_name_used_modules(Visibility, InstName, !UsedModules).
-inst_name_used_modules(Visibility, any_inst(InstName, _, _, _),
-        !UsedModules) :-
-    inst_name_used_modules(Visibility, InstName, !UsedModules).
-inst_name_used_modules(Visibility, shared_inst(InstName), !UsedModules) :-
-    inst_name_used_modules(Visibility, InstName, !UsedModules).
-inst_name_used_modules(Visibility, mostly_uniq_inst(InstName), !UsedModules) :-
-    inst_name_used_modules(Visibility, InstName, !UsedModules).
-inst_name_used_modules(Visibility, typed_ground(_, Type), !UsedModules) :-
-    mer_type_used_modules(Visibility, Type, !UsedModules).
-inst_name_used_modules(Visibility, typed_inst(Type, InstName), !UsedModules) :-
+        list.foldl(mer_inst_used_modules(Visibility), Insts, !UsedModules)
+    ;
+        ( InstName = merge_inst(InstA, InstB)
+        ; InstName = unify_inst(_, InstA, InstB, _)
+        ),
+        mer_inst_used_modules(Visibility, InstA, !UsedModules),
+        mer_inst_used_modules(Visibility, InstB, !UsedModules)
+    ;
+        ( InstName = ground_inst(SubInstName, _, _, _)
+        ; InstName = any_inst(SubInstName, _, _, _)
+        ; InstName = shared_inst(SubInstName)
+        ; InstName = mostly_uniq_inst(SubInstName)
+        ),
+        inst_name_used_modules(Visibility, SubInstName, !UsedModules)
+    ;
+        InstName = typed_ground(_, Type),
+        mer_type_used_modules(Visibility, Type, !UsedModules)
+    ;
+        InstName = typed_inst(Type, SubInstName),
     mer_type_used_modules(Visibility, Type, !UsedModules),
-    inst_name_used_modules(Visibility, InstName, !UsedModules).
+        inst_name_used_modules(Visibility, SubInstName, !UsedModules)
+    ).
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
--------------------------------------------------------------------------
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