[m-rev.] diff: cleanup ssdebug.m

Zoltan Somogyi zs at csse.unimelb.edu.au
Fri Nov 23 20:30:16 AEDT 2007


compiler/ssdebug.m:
	Fix deviations from our coding standards, and add an XXX for work that
	still remains to be done.

Zoltan.

cvs diff: Diffing .
Index: ssdebug.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ssdebug.m,v
retrieving revision 1.10
diff -u -b -r1.10 ssdebug.m
--- ssdebug.m	9 Nov 2007 02:07:36 -0000	1.10
+++ ssdebug.m	23 Nov 2007 09:05:11 -0000
@@ -127,6 +127,7 @@
 %
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
+
 :- module transform_hlds.ssdebug.
 :- interface.
 
@@ -135,10 +136,9 @@
 
 :- import_module io.
 
-%
-% Place the different events (call/exit/fail/redo) at the beginning/end of each 
-% procedure.
-%
+    % Place the different events (call/exit/fail/redo) at the beginning/end
+    % of each procedure.
+    %
 :- pred ssdebug.process_proc(pred_id::in, proc_id::in,
     proc_info::in, proc_info::out, module_info::in, module_info::out,
     io::di, io::uo) is det.
@@ -179,11 +179,13 @@
 
 %-----------------------------------------------------------------------------%
 
-     %
-     % Switch on the determinism used. It's the compiler determinism which
-     % is used. The determinism for the goal migth be the same.
-     %
 process_proc(PredId, ProcId, !ProcInfo, !ModuleInfo, !IO) :-
+    % We have different transformations for procedures of different
+    % determinisms.
+
+    % XXX The definitions of the four process_proc_* predicates are very
+    % similar; they look to have generated using cut-and-paste.
+    % The common parts should be factored out and moved here.
  
     proc_info_get_inferred_determinism(!.ProcInfo, Determinism),
     ( 
@@ -209,8 +211,6 @@
         error("detism_failure: not yet implemented in ssdb")
     ).
 
-  
-      %
       % Source-to-source transformation for a deterministic goal.
       %
 :- pred process_proc_det(pred_id::in, proc_id::in,
@@ -234,8 +234,8 @@
         proc_info_get_headvars(!.ProcInfo, HeadVars),
         proc_info_get_initial_instmap(!.ProcInfo, !.ModuleInfo, InitInstMap),
 
-        % Make a list which records the value for each of the head variables at
-        % the call port.
+        % Make a list which records the value for each of the head variables
+        % at the call port.
         make_arg_list(0, InitInstMap, HeadVars, map.init, CallArgListVar, 
             CallArgListGoals, !ModuleInfo, !ProcInfo, !PredInfo, !Varset, 
             !Vartypes, map.init, BoundVarDescsAtCall),
@@ -301,8 +301,6 @@
             !ModuleInfo, !.Varset, !.Vartypes)    
     ).
 
-
-    %
     % Source-to-source transformation for a semidet goal.
     %
 :- pred process_proc_semi(pred_id::in, proc_id::in,
@@ -326,8 +324,8 @@
         proc_info_get_headvars(!.ProcInfo, HeadVars),
         proc_info_get_initial_instmap(!.ProcInfo, !.ModuleInfo, InitInstMap),
 
-        % Make a list which records the value for each of the head variables at
-        % the call port.
+        % Make a list which records the value for each of the head variables
+        % at the call port.
         make_arg_list(0, InitInstMap, HeadVars, map.init, CallArgListVar, 
             CallArgListGoals, !ModuleInfo, !ProcInfo, !PredInfo, !Varset, 
             !Vartypes, map.init, BoundVarDescsAtCall),
@@ -418,8 +416,9 @@
 
         CallVarGoal = ProcIdGoals ++ CallArgListGoals ++ [HandleEventCallGoal],
         % XXX not sure about determinism.
-        GoalITE = hlds_goal(if_then_else(IteExistVars, CondGoal, ThenGoal, 
-            ElseGoal), GoalInfoCond),
+        GoalITE = hlds_goal(
+            if_then_else(IteExistVars, CondGoal, ThenGoal, ElseGoal),
+            GoalInfoCond),
 
         ConjGoal = CallVarGoal ++ [GoalITE],
         GoalWithoutPurity = hlds_goal(conj(plain_conj, ConjGoal), 
@@ -433,8 +432,6 @@
             !ModuleInfo, !.Varset, !.Vartypes)    
     ).
 
-
-    %
     % Source-to-source transformation for a nondeterministic procedure.
     %
 :- pred process_proc_nondet(pred_id::in, proc_id::in,
@@ -458,8 +455,8 @@
         proc_info_get_headvars(!.ProcInfo, HeadVars),
         proc_info_get_initial_instmap(!.ProcInfo, !.ModuleInfo, InitInstMap),
 
-        % Make a list which records the value for each of the head variables at
-        % the call port.
+        % Make a list which records the value for each of the head variables
+        % at the call port.
         make_arg_list(0, InitInstMap, HeadVars, map.init, CallArgListVar, 
             CallArgListGoals, !ModuleInfo, !ProcInfo, !PredInfo, !Varset, 
             !Vartypes, map.init, BoundVarDescsAtCall),
@@ -553,8 +550,7 @@
             GoalInfo0), 
         goal_add_feature(feature_preserve_backtrack_into, ConjGoal220, 
             ConjGoal22),
-        DisjGoal2 = hlds_goal(disj([ConjGoal21, ConjGoal22]), 
-            GoalInfo0),
+        DisjGoal2 = hlds_goal(disj([ConjGoal21, ConjGoal22]), GoalInfo0),
 
         GoalWithoutPurity = hlds_goal(conj(plain_conj, 
             ProcIdGoals ++ [DisjGoal2]), GoalInfo0),
@@ -567,8 +563,6 @@
             !ModuleInfo, !.Varset, !.Vartypes)
     ).
 
-
-    %
     % Create the output variable DoRetry.
     %
 :- pred make_retry_var(string::in, prog_var::out, 
@@ -581,8 +575,6 @@
     svvarset.new_named_var(VarName, RetryVar, !VarSet),
     svmap.det_insert(RetryVar, RetryType, !VarTypes).
 
-
-    %
     % Create the goal for recursive call in the case of a retry.
     %
 :- pred make_recursive_call(pred_info::in, module_info::in, pred_id::in, 
@@ -598,8 +590,6 @@
     goal_info_init(GoalInfoHG),
     Goal = hlds_goal(GoalExpr, GoalInfoHG).
 
-
-    %
     % make_switch_goal(SwitchVar, SwitchCase1, SwitchCase2, GoalInfo, Goal).
     %
     % Create an output Goal, which is a switch with following pattern :
@@ -621,12 +611,11 @@
     ConsIdDoNotRetry = cons(qualified(SSDBModule, "do_not_retry"), 0),
     CaseDoRetry = case(ConsIdDoRetry, DoRetryGoal),
     CaseDoNotRetry = case(ConsIdDoNotRetry, DoNotRetryGoal),
-    SwitchGoal = hlds_goal(switch(SwitchVar, cannot_fail, 
-        [CaseDoRetry, CaseDoNotRetry]), GoalInfo).
-
+    SwitchGoal = hlds_goal(
+        switch(SwitchVar, cannot_fail, [CaseDoRetry, CaseDoNotRetry]),
+        GoalInfo).
 
-    %
-    % wrap_with_purity_scope(Purity, GoalInfo, Goal0, Goal)
+    % wrap_with_purity_scope(Purity, GoalInfo, Goal0, Goal):
     %
     % The Goal0 is wrap with the Purity to give Goal.
     % Not wrapping impure procedures with redundant promise_impure scopes.
@@ -648,10 +637,8 @@
         Goal = hlds_goal(scope(ScopeReason, GoalWithoutPurity), GoalInfo)
     ).
 
-
-    %
-    % Commit all informations added during the source-to-source 
-    % transformations.
+    % Update the proc_info and pred_info with the result of the
+    % source-to-source transformation.
     %
 :- pred commit_goal_changes(hlds_goal::in, pred_id::in, proc_id::in,
     pred_info::in, proc_info::in, proc_info::out, 
@@ -659,7 +646,6 @@
 
 commit_goal_changes(Goal, PredId, ProcId, !.PredInfo, !ProcInfo, !ModuleInfo, 
     Varset, Vartypes) :-
-    
     proc_info_set_varset(Varset, !ProcInfo),
     proc_info_set_vartypes(Vartypes, !ProcInfo),
     proc_info_set_goal(Goal, !ProcInfo),
@@ -669,11 +655,8 @@
     repuritycheck_proc(!.ModuleInfo, proc(PredId, ProcId), !PredInfo),
     module_info_set_pred_info(PredId, !.PredInfo, !ModuleInfo).
 
-
 %-----------------------------------------------------------------------------%
 
-
-    %
     % Build the following goal : handle_event_EVENT(ProcId, Arguments).
     % EVENT = call,exit,fail or redo
     % Argument = ProcId, ListHeadVars and eventually Retry
@@ -695,8 +678,6 @@
         Arguments, Features, InstMapSrc, !.ModuleInfo, Context, 
         HandleEventGoal).
 
-
-    %
     % make_proc_id_construction(PredInfo, ProcInfo,
     %   Goals, Var, !Varset, !Vartypes)
     %
@@ -732,10 +713,7 @@
 
     Goals = [ConstructModuleName, ConstructPredName, ConstructProcIdGoal].
 
-
-    %
     % make_fail_call(FailGoal, ModuleInfo)
-    %
     % Construct the fail goal.
     %
 :- pred make_fail_call(hlds_goal::out, module_info::in) is det.
@@ -750,8 +728,6 @@
 
 %-----------------------------------------------------------------------------%
 
-
-    %
     % make_arg_list(Pos, InstMap, Vars, RenamedVar, FullListVar, Goals, 
     %   !ModuleInfo, !ProcInfo, !PredInfo, !Varset, !Vartypes, !BoundedVarDesc)
     %
@@ -786,18 +762,15 @@
 make_arg_list(Pos0, InstMap, [VarToInspect | ListVar], Renaming, Var, 
         Goals, !ModuleInfo, !ProcInfo, !PredInfo, !Varset, !Vartypes, 
         !BoundVarDescs) :-
-
     Pos = Pos0 + 1,
-
     make_arg_list(Pos, InstMap, ListVar, Renaming, Var0, Goals0, 
         !ModuleInfo, !ProcInfo, !PredInfo, !Varset, !Vartypes, !BoundVarDescs),
 
-    %
     % BoundVarDescs is filled with the description of the input variable during 
     % the first call to make_arg_list predicate. 
     % At the second call, we search if the current VarToInspect already exist 
     % in the map and if yes, copy his recorded description.
-    %
+
     ( map.search(!.BoundVarDescs, VarToInspect, ExistingVarDesc) ->
         ValueGoals = [],
         VarDesc = ExistingVarDesc
@@ -812,11 +785,9 @@
     ConsId = cons(qualified(unqualified("list"), "[|]" ), 2),
     construct_functor(Var, ConsId, [VarDesc, Var0], Goal),
     
-    %XXX Optimization : Unefficience problem with append.
+    %XXX Optimize me: repeated appends are slow.
     Goals = Goals0 ++ ValueGoals ++ [Goal].
 
-
-    %
     % Return the type list(var_value).
     %
 :- func list_var_value_type = mer_type.
@@ -829,8 +800,6 @@
     ListTypeCtor = type_ctor(qualified(unqualified("list"), "list"), 1),
     construct_type(ListTypeCtor, [VarValueType], ListVarValueType). 
     
-
-    %
     % Create the goal's argument description :
     % -> unbound_head_var(Name, Pos) if it is an unbound argument
     % -> bound_head_var(type_of_T, Name, Position, T) if it is a bound argument
@@ -843,30 +812,24 @@
     map(prog_var, prog_var)::out) is det.
 
 make_var_value(InstMap, VarToInspect, Renaming, VarDesc, VarPos, Goals, 
-        !ModuleInfo, !ProcInfo, !PredInfo, !VarSet, !VarTypes, !BoundVarDescs) :-
-
+        !ModuleInfo, !ProcInfo, !PredInfo, !VarSet, !VarTypes,
+        !BoundVarDescs) :-
     SSDBModule = mercury_ssdb_builtin_module,
     TypeCtor = type_ctor(qualified(SSDBModule, "var_value"), 0),
-
     varset.lookup_name(!.VarSet, VarToInspect, VarName),
-
     make_string_const_construction_alloc(VarName, yes("VarName"),
         ConstructVarName, VarNameVar, !VarSet, !VarTypes),
-
     make_int_const_construction_alloc(VarPos, yes("VarPos"),
         ConstructVarPos, VarPosVar, !VarSet, !VarTypes),
 
     ( var_is_ground_in_instmap(!.ModuleInfo, InstMap, VarToInspect) ->
-                    
-        %
         % Update proc_varset and proc_vartypes, without this, the
         % polymorphism_make_type_info_var uses a prog_var which is 
         % already bound.
-        %
+
         proc_info_set_varset(!.VarSet, !ProcInfo),
         proc_info_set_vartypes(!.VarTypes, !ProcInfo),
 
-        %
         % Create dynamic constructor for the value of the argument.
         %
         % Call polymorphism.m to create the type_infos, add an hidden field
@@ -874,7 +837,7 @@
         %
         % some[T] bound_head_var(string, int, T) ---->
         %   some[T] bound_head_var(type_of_T, string, int, T)
-        %
+
         create_poly_info(!.ModuleInfo, !.PredInfo, !.ProcInfo, PolyInfo0),
         term.context_init(Context),
         map.lookup(!.VarTypes, VarToInspect, MerType),
@@ -891,10 +854,8 @@
         construct_type(TypeCtor, [], VarType), 
         svmap.det_insert(VarDesc, VarType, !VarTypes),
 
-        %
-        % Renaming contain the name of all instantiated argument during the 
-        % execution of the procedure's body.
-        %
+        % Renaming contains the names of all instantiated arguments
+        % during the execution of the procedure's body.
         ( map.is_empty(Renaming) ->
             construct_functor(VarDesc, ConsId, [TypeInfoVar, VarNameVar, 
                 VarPosVar, VarToInspect], ConstructVarGoal)
@@ -903,12 +864,9 @@
             construct_functor(VarDesc, ConsId, [TypeInfoVar, VarNameVar, 
                 VarPosVar, RenamedVar], ConstructVarGoal)
         ),
-
         Goals = [ConstructVarName, ConstructVarPos | TypeInfoGoal] ++
             [ConstructVarGoal],
-
         svmap.det_insert(VarToInspect, VarDesc, !BoundVarDescs)
-
     ;
         svvarset.new_named_var("VarDesc", VarDesc, !VarSet), 
         ConsId = cons(qualified(SSDBModule, "unbound_head_var"), 2),
cvs diff: Diffing notes
--------------------------------------------------------------------------
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