[m-rev.] trivial diff: replace some if-then-elses with switches

Julien Fischer juliensf at csse.unimelb.edu.au
Mon Nov 19 17:10:03 AEDT 2007


Estimated hours taken: 0.5
Branches: main

compiler/cse_detection.m:
compiler/module_qual.m:
compiler/simplify.m:
compiler/switch_detection.m:
compiler/unused_args.m:
 	Replace some switches with if-then-elses.

 	Minor formatting improvements, break overlong lines etc.

Julien.

Index: cse_detection.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/cse_detection.m,v
retrieving revision 1.111
diff -u -r1.111 cse_detection.m
--- cse_detection.m	10 Oct 2007 14:35:25 -0000	1.111
+++ cse_detection.m	19 Nov 2007 06:06:00 -0000
@@ -593,9 +593,13 @@
          Unif0 = deconstruct(_, Consid, Args, Submodes, CanFail, CanCGC)
      ->
          Unif = deconstruct(Var, Consid, Args, Submodes, CanFail, CanCGC),
-        ( RHS = rhs_functor(_, _, _) ->
+        (
+            RHS = rhs_functor(_, _, _),
              GoalExpr1 = unify(Var, RHS, Umode, Unif, Ucontext)
          ;
+            ( RHS = rhs_var(_)
+            ; RHS = rhs_lambda_goal(_, _, _, _, _, _, _, _)
+            ),
              unexpected(this_file,
                  "non-functor unify in construct_common_unify")
          ),
Index: module_qual.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/module_qual.m,v
retrieving revision 1.158
diff -u -r1.158 module_qual.m
--- module_qual.m	20 Aug 2007 03:36:02 -0000	1.158
+++ module_qual.m	19 Nov 2007 06:06:00 -0000
@@ -352,9 +352,11 @@
      mq_info::in, mq_info::out) is det.

  collect_mq_info_qualified_symname(SymName, !Info) :-
-    ( SymName = qualified(ModuleName, _) ->
+    (
+        SymName = qualified(ModuleName, _),
          mq_info_set_module_used(ModuleName, !Info)
      ;
+        SymName = unqualified(_),
          unexpected(this_file,
              "collect_mq_info_qualified_symname: not qualified.")
      ).
@@ -419,10 +421,18 @@
  :- pred add_imports(sym_list::in, mq_info::in, mq_info::out) is det.

  add_imports(Imports, !Info) :-
-    ( Imports = list_module(ImportedModules) ->
+    (
+        Imports = list_module(ImportedModules),
          add_imports_2(ImportedModules, !Info)
      ;
-        true
+        ( Imports = list_sym(_)
+        ; Imports = list_pred(_)
+        ; Imports = list_func(_)
+        ; Imports = list_cons(_)
+        ; Imports = list_op(_)
+        ; Imports = list_adt(_)
+        ; Imports = list_type(_)
+        )
      ).

  :- pred add_imports_2(list(sym_name)::in, mq_info::in, mq_info::out) is det.
@@ -1046,12 +1056,24 @@
  qualify_bound_inst_list([], [], !Info, !Specs).
  qualify_bound_inst_list([bound_functor(ConsId, Insts0) | BoundInsts0],
           [bound_functor(ConsId, Insts) | BoundInsts], !Info, !Specs) :-
-    ( ConsId = cons(Name, Arity) ->
+    (
+        ConsId = cons(Name, Arity),
          Id = item_name(Name, Arity),
          update_recompilation_info(
              recompilation.record_used_item(functor_item, Id, Id), !Info)
      ;
-        true
+        ( ConsId = int_const(_)
+        ; ConsId = string_const(_)
+        ; ConsId = float_const(_)
+        ; ConsId = pred_const(_, _)
+        ; ConsId = type_ctor_info_const(_, _, _)
+        ; ConsId = base_typeclass_info_const(_, _, _, _)
+        ; ConsId = type_info_cell_constructor(_)
+        ; ConsId = typeclass_info_cell_constructor
+        ; ConsId = tabling_info_const(_)
+        ; ConsId = deep_profiling_proc_layout(_)
+        ; ConsId = table_io_decl(_)
+        )
      ),
      qualify_inst_list(Insts0, Insts, !Info, !Specs),
      qualify_bound_inst_list(BoundInsts0, BoundInsts, !Info, !Specs).
@@ -1133,7 +1155,8 @@
          !Info, !Specs) :-
      qualify_type(Type0, Type, !Info, !Specs).

-:- pred qualify_type_ctor(type_ctor::in, type_ctor::out, mq_info::in, mq_info::out,
+:- pred qualify_type_ctor(type_ctor::in, type_ctor::out,
+    mq_info::in, mq_info::out,
      list(error_spec)::in, list(error_spec)::out) is det.

  qualify_type_ctor(!TypeCtor, !Info, !Specs) :-
@@ -1143,7 +1166,8 @@
      ;
          TypeCtorId0 = mq_id(SymName0, Arity),
          mq_info_get_types(!.Info, Types),
-        find_unique_match(TypeCtorId0, TypeCtorId, Types, type_id, !Info, !Specs),
+        find_unique_match(TypeCtorId0, TypeCtorId, Types, type_id,
+            !Info, !Specs),
          TypeCtorId = mq_id(SymName, _)
      ),
      !:TypeCtor = type_ctor(SymName, Arity).
@@ -1348,9 +1372,11 @@
          InstanceBody = instance_body_abstract
      ;
          InstanceBody0 = instance_body_concrete(M0s),
-        ( ClassName = unqualified(_) ->
+        (
+            ClassName = unqualified(_),
              Ms = M0s
          ;
+            ClassName = qualified(_, _),
              sym_name_get_module_name(ClassName, unqualified(""), Module),
              Qualify = (pred(M0::in, M::out) is det :-
                  M0 = instance_method(A, Method0, C, D, E),
@@ -1965,7 +1991,7 @@
                  list.member(MatchModule, AllMatchingModules),
                  set.member(MatchModule, DefiningModules)
              ),
-            solutions.solutions(FindMatch, MatchingModules)
+            solutions(FindMatch, MatchingModules)
          )
      ;
          MatchingModules = []
Index: simplify.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/simplify.m,v
retrieving revision 1.219
diff -u -r1.219 simplify.m
--- simplify.m	8 Nov 2007 05:00:18 -0000	1.219
+++ simplify.m	19 Nov 2007 06:06:00 -0000
@@ -1234,11 +1234,15 @@
      ;
          U0 = complicated_unify(UniMode, CanFail, TypeInfoVars)
      ->
-        ( RT0 = rhs_var(V) ->
+        (
+            RT0 = rhs_var(V),
              process_compl_unify(LT0, V, UniMode, CanFail, TypeInfoVars, C,
                  GoalInfo0, GoalExpr1, !Info, !IO),
              GoalExpr1 = hlds_goal(GoalExpr, GoalInfo)
          ;
+            ( RT0 = rhs_functor(_, _, _)
+            ; RT0 = rhs_lambda_goal(_, _, _, _, _, _, _, _)
+            ),
              unexpected(this_file, "invalid RHS for complicated unify")
          )
      ;
Index: switch_detection.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/switch_detection.m,v
retrieving revision 1.135
diff -u -r1.135 switch_detection.m
--- switch_detection.m	7 Aug 2007 07:10:06 -0000	1.135
+++ switch_detection.m	19 Nov 2007 06:06:00 -0000
@@ -29,6 +29,8 @@
  :- import_module io.
  :- import_module list.

+%-----------------------------------------------------------------------------%
+
  :- pred detect_switches(module_info::in, module_info::out,
      io::di, io::uo) is det.

@@ -231,7 +233,8 @@
          Goal = scope(Reason, SubGoal)
      ;
          Goal0 = unify(_, RHS0, _, _, _),
-        ( RHS0 = rhs_lambda_goal(_, _, _, _, Vars, Modes, _, LambdaGoal0) ->
+        (
+            RHS0 = rhs_lambda_goal(_, _, _, _, Vars, Modes, _, LambdaGoal0),
              % We need to insert the initial insts for the lambda variables
              % in the instmap before processing the lambda goal.
              instmap.pre_lambda_update(ModuleInfo, Vars, Modes,
@@ -241,6 +244,9 @@
              RHS = RHS0 ^ rhs_lambda_goal := LambdaGoal,
              Goal = Goal0 ^ unify_rhs := RHS
          ;
+            ( RHS0 = rhs_var(_)
+            ; RHS0 = rhs_functor(_, _, _)
+            ),
              Goal = Goal0
          )
      ;
@@ -263,7 +269,7 @@
  :- type cases == map(cons_id, list(hlds_goal)).

  :- type sorted_case_list == list(case).
-    % the sorted_case_list should always be sorted on cons_id -
+    % The sorted_case_list should always be sorted on cons_id -
      % `delete_unreachable_cases' relies on this.

  :- type again
@@ -719,7 +725,7 @@
      sorted_case_list::in) is semidet.

  switch_covers_all_cases(ModuleInfo, Type, CasesList) :-
-    type_util.switch_type_num_functors(ModuleInfo, Type, NumFunctors),
+    switch_type_num_functors(ModuleInfo, Type, NumFunctors),
      list.length(CasesList, NumCases),
      NumCases = NumFunctors.

Index: unused_args.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/unused_args.m,v
retrieving revision 1.145
diff -u -r1.145 unused_args.m
--- unused_args.m	28 Sep 2007 03:17:14 -0000	1.145
+++ unused_args.m	19 Nov 2007 06:06:00 -0000
@@ -720,10 +720,14 @@
              % These should be transformed into calls by polymorphism.m.
              % This is here to cover the case where unused arguments is called
              % with --error-check-only and polymorphism has not been run.
-            ( RHS = rhs_var(RHSVar) ->
+            (
+                RHS = rhs_var(RHSVar),
                  set_var_used(RHSVar, !VarDep),
                  set_var_used(LHS, !VarDep)
              ;
+                ( RHS = rhs_functor(_, _, _)
+                ; RHS = rhs_lambda_goal(_, _, _, _, _, _, _, _)
+                ),
                  unexpected(this_file,
                      "complicated unifications should only be var-var")
              )

--------------------------------------------------------------------------
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