[m-rev.] for review: [CTGC] bugfix, use typevarset from pred_info

Nancy Mazur Nancy.Mazur at cs.kuleuven.ac.be
Mon Jun 19 23:16:18 AEST 2006


Hi,

this is a bugfix. The error occurred when analysing TypeSpecOf__ predicates,
but may as well occur in other predicates too. The problem was that the
typevarset used to determine type substitutions was in sometimes simply set to
an empty varset, instead of getting it from the pred_info structure as it
should be.

Question: I was wondering what the use is of analysing the TypeSpecOf__
predicates, as the results are (explicitly) not recorded in the trans_opt
files (Cf. the XXX remark in structure_sharing.analysis.m, and in analogy, 
in structure_reuse.analysis.m)? I might as well simply not analyse them?

Nancy

===================================================================


Estimated hours taken: 5
Branches: main

Bugfix. Make sure to use the typevarset stored in the pred_info when
determining the type substitution between formal and actual sharing 
information. 

compiler/structure_reuse.direct.detect_garbage.m:
compiler/structure_reuse.direct.m:
compiler/structure_reuse.indirect.m:
compiler/structure_sharing.domain.m:
	Use the typevarset from the pred_info structure when looking up
	and renaming sharing information. 
	Thread pred_info until the place where it is used. 


Index: compiler/structure_reuse.direct.detect_garbage.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/structure_reuse.direct.detect_garbage.m,v
retrieving revision 1.3
diff -u -d -r1.3 structure_reuse.direct.detect_garbage.m
--- compiler/structure_reuse.direct.detect_garbage.m	5 Jun 2006 05:23:27 -0000	1.3
+++ compiler/structure_reuse.direct.detect_garbage.m	19 Jun 2006 12:57:41 -0000
@@ -24,8 +24,9 @@
     % procedure goal. The table also records the reuse condition associated
     % with each of the dead cells.
     %
-:- pred determine_dead_deconstructions(module_info::in, proc_info::in, 
-    sharing_as_table::in, hlds_goal::in, dead_cell_table::out) is det.
+:- pred determine_dead_deconstructions(module_info::in, pred_info::in, 
+    proc_info::in, sharing_as_table::in, hlds_goal::in, 
+    dead_cell_table::out) is det.
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
@@ -38,13 +39,36 @@
 
 %-----------------------------------------------------------------------------%
 
-determine_dead_deconstructions(ModuleInfo, ProcInfo, SharingTable, 
-    Goal, DeadCellTable):- 
+:- type detect_bg_info
+    --->    detect_bg_info(
+                module_info     ::  module_info, 
+                pred_info       ::  pred_info, 
+                proc_info       ::  proc_info, 
+                sharing_table   ::  sharing_as_table
+            ).
+   
+:- func detect_bg_info_init(module_info, pred_info, proc_info, 
+    sharing_as_table) = detect_bg_info.
+
+detect_bg_info_init(ModuleInfo, PredInfo, ProcInfo, SharingTable) =
+    detect_bg_info(ModuleInfo, PredInfo, ProcInfo, SharingTable). 
+
+
+determine_dead_deconstructions(ModuleInfo, PredInfo, ProcInfo, SharingTable, 
+        Goal, DeadCellTable) :- 
+   determine_dead_deconstructions(
+        detect_bg_info_init(ModuleInfo, PredInfo, ProcInfo, SharingTable), 
+        Goal, DeadCellTable). 
+ 
+:- pred determine_dead_deconstructions(detect_bg_info::in, hlds_goal::in, 
+    dead_cell_table::out) is det.
+
+determine_dead_deconstructions(Background, Goal, DeadCellTable):- 
     % In this process we need to know the sharing at each program point, 
     % which boils down to reconstructing that sharing information based on the
     % sharing recorded in the sharing table. 
-    determine_dead_deconstructions_2(ModuleInfo, ProcInfo, SharingTable, 
-        Goal, sharing_as_init, _, dead_cell_table_init, DeadCellTable).
+    determine_dead_deconstructions_2(Background, Goal, 
+        sharing_as_init, _, dead_cell_table_init, DeadCellTable).
 
     % Process a procedure goal, determining the sharing at each subgoal, as
     % well as constructing the table of dead cells. 
@@ -53,23 +77,24 @@
     %   - at each program point: compute sharing
     %   - at deconstruction unifications: check for a dead cell. 
     %
-:- pred determine_dead_deconstructions_2(module_info::in, proc_info::in,
-    sharing_as_table::in, hlds_goal::in, sharing_as::in, sharing_as::out,
-    dead_cell_table::in, dead_cell_table::out) is det.
-
-determine_dead_deconstructions_2(ModuleInfo, ProcInfo, SharingTable,
-    TopGoal, !SharingAs, !DeadCellTable) :- 
+:- pred determine_dead_deconstructions_2(detect_bg_info::in, hlds_goal::in, 
+    sharing_as::in, sharing_as::out, dead_cell_table::in, 
+    dead_cell_table::out) is det.
 
+determine_dead_deconstructions_2(Background, TopGoal, !SharingAs, 
+        !DeadCellTable) :- 
     TopGoal = GoalExpr - GoalInfo, 
+    ModuleInfo = Background ^ module_info, 
+    PredInfo = Background ^ pred_info, 
+    ProcInfo = Background ^ proc_info, 
+    SharingTable = Background ^ sharing_table, 
     (
         GoalExpr = conj(_, Goals),
-        list.foldl2(
-            determine_dead_deconstructions_2(ModuleInfo, ProcInfo, 
-                SharingTable), 
+        list.foldl2(determine_dead_deconstructions_2(Background),
             Goals, !SharingAs, !DeadCellTable)
     ;
         GoalExpr = call(PredId, ProcId, ActualVars, _, _, _),
-        lookup_sharing_and_comb(ModuleInfo, ProcInfo, SharingTable,
+        lookup_sharing_and_comb(ModuleInfo, PredInfo, ProcInfo, SharingTable,
             PredId, ProcId, ActualVars, !SharingAs)
     ;
         GoalExpr = generic_call(_GenDetails, _, _, _),
@@ -86,29 +111,28 @@
             GoalInfo, !.SharingAs)
     ;
         GoalExpr = disj(Goals),
-        determine_dead_deconstructions_2_disj(ModuleInfo, ProcInfo, 
-            SharingTable, Goals, !SharingAs, !DeadCellTable)
+        determine_dead_deconstructions_2_disj(Background, Goals, !SharingAs, 
+            !DeadCellTable)
     ;
         GoalExpr = switch(_, _, Cases),
-        determine_dead_deconstructions_2_disj(ModuleInfo, ProcInfo,
-            SharingTable, list.map(
-                func(C) = G :- (G = C ^ case_goal), Cases), !SharingAs,
+        determine_dead_deconstructions_2_disj(Background, 
+            list.map(func(C) = G :- (G = C ^ case_goal), Cases), !SharingAs,
             !DeadCellTable)
     ;
         % XXX To check and compare with the theory. 
         GoalExpr = not(_Goal)
     ;
         GoalExpr = scope(_, SubGoal),
-        determine_dead_deconstructions_2(ModuleInfo, ProcInfo, 
-            SharingTable, SubGoal, !SharingAs, !DeadCellTable)
+        determine_dead_deconstructions_2(Background, SubGoal, !SharingAs, 
+            !DeadCellTable)
     ;
         GoalExpr = if_then_else(_, IfGoal, ThenGoal, ElseGoal),
-        determine_dead_deconstructions_2(ModuleInfo, ProcInfo, SharingTable,
-            IfGoal, !.SharingAs, IfSharingAs, !DeadCellTable),
-        determine_dead_deconstructions_2(ModuleInfo, ProcInfo, SharingTable,
-            ThenGoal, IfSharingAs, ThenSharingAs, !DeadCellTable),
-        determine_dead_deconstructions_2(ModuleInfo, ProcInfo, SharingTable,
-            ElseGoal, !.SharingAs, ElseSharingAs, !DeadCellTable),
+        determine_dead_deconstructions_2(Background, IfGoal, !.SharingAs, 
+            IfSharingAs, !DeadCellTable),
+        determine_dead_deconstructions_2(Background, ThenGoal, IfSharingAs, 
+            ThenSharingAs, !DeadCellTable),
+        determine_dead_deconstructions_2(Background, ElseGoal, !.SharingAs, 
+            ElseSharingAs, !DeadCellTable),
         !:SharingAs = sharing_as_least_upper_bound(ModuleInfo, ProcInfo,
             ThenSharingAs, ElseSharingAs)
     ;
@@ -127,29 +151,25 @@
             "determine_dead_deconstructions_2: shorthand goal.")
     ).
        
-:- pred determine_dead_deconstructions_2_disj(module_info::in,
-    proc_info::in, sharing_as_table::in, hlds_goals::in,
-    sharing_as::in, sharing_as::out,
+:- pred determine_dead_deconstructions_2_disj(detect_bg_info::in, 
+    hlds_goals::in, sharing_as::in, sharing_as::out,
     dead_cell_table::in, dead_cell_table::out) is det.
 
-determine_dead_deconstructions_2_disj(ModuleInfo, ProcInfo, 
-    SharingTable, Goals, !SharingAs, !DeadCellTable) :- 
-    list.foldl2(determine_dead_deconstructions_2_disj_goal(ModuleInfo,
-        ProcInfo, SharingTable, !.SharingAs), Goals, !SharingAs,
-        !DeadCellTable).
+determine_dead_deconstructions_2_disj(Background, Goals, 
+        !SharingAs, !DeadCellTable) :- 
+    list.foldl2(determine_dead_deconstructions_2_disj_goal(Background, 
+        !.SharingAs), Goals, !SharingAs, !DeadCellTable).
 
-:- pred determine_dead_deconstructions_2_disj_goal(module_info::in,
-    proc_info::in, sharing_as_table::in, sharing_as::in, hlds_goal::in,
-    sharing_as::in, sharing_as::out,
+:- pred determine_dead_deconstructions_2_disj_goal(detect_bg_info::in, 
+    sharing_as::in, hlds_goal::in, sharing_as::in, sharing_as::out,
     dead_cell_table::in, dead_cell_table::out) is det.
 
-determine_dead_deconstructions_2_disj_goal(ModuleInfo, ProcInfo, 
-        SharingTable, SharingBeforeDisj, Goal, !SharingAs, 
-        !DeadCellTable) :-
-    determine_dead_deconstructions_2(ModuleInfo, ProcInfo, SharingTable,
-        Goal, SharingBeforeDisj, GoalSharing, !DeadCellTable),
-    !:SharingAs = sharing_as_least_upper_bound(ModuleInfo, ProcInfo, 
-        !.SharingAs, GoalSharing).
+determine_dead_deconstructions_2_disj_goal(Background, SharingBeforeDisj, 
+        Goal, !SharingAs, !DeadCellTable) :-
+    determine_dead_deconstructions_2(Background, Goal, SharingBeforeDisj, 
+        GoalSharing, !DeadCellTable),
+    !:SharingAs = sharing_as_least_upper_bound(Background ^ module_info, 
+        Background ^ proc_info, !.SharingAs, GoalSharing).
 
 
     % Verify whether the unification is a deconstruction in which the 
Index: compiler/structure_reuse.direct.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/structure_reuse.direct.m,v
retrieving revision 1.2
diff -u -d -r1.2 structure_reuse.direct.m
--- compiler/structure_reuse.direct.m	5 Jun 2006 05:23:27 -0000	1.2
+++ compiler/structure_reuse.direct.m	19 Jun 2006 12:57:42 -0000
@@ -141,7 +141,7 @@
     map.lookup(Procs0, ProcId, Proc0), 
 
     direct_reuse_process_procedure(Strategy, SharingTable, PredId, ProcId, 
-        !.ModuleInfo, Proc0, Proc, ReuseAs, !IO), 
+        !.ModuleInfo, Pred0, Proc0, Proc, ReuseAs, !IO), 
     reuse_as_table_set(proc(PredId, ProcId), ReuseAs, !ReuseTable),
 
     map.det_update(Procs0, ProcId, Proc, Procs),
@@ -153,10 +153,11 @@
     %
 :- pred direct_reuse_process_procedure(reuse_strategy::in, 
     sharing_as_table::in, pred_id::in, proc_id::in, module_info::in, 
-    proc_info::in, proc_info::out, reuse_as::out, io::di, io::uo) is det.
+    pred_info::in, proc_info::in, proc_info::out, reuse_as::out, 
+    io::di, io::uo) is det.
 
 direct_reuse_process_procedure(Strategy, SharingTable, PredId, ProcId,
-        ModuleInfo, !ProcInfo, ReuseAs, !IO):- 
+        ModuleInfo, PredInfo, !ProcInfo, ReuseAs, !IO):- 
     io_lookup_bool_option(very_verbose, VeryVerbose, !IO),
 
     write_proc_progress_message("% Direct reuse analysis of ",
@@ -167,8 +168,8 @@
     % Determine the deconstructions in which data may potentially become
     % garbage.
     %
-    determine_dead_deconstructions(ModuleInfo, !.ProcInfo, SharingTable, 
-        Goal0, DeadCellTable),
+    determine_dead_deconstructions(ModuleInfo, PredInfo, !.ProcInfo, 
+        SharingTable, Goal0, DeadCellTable),
     dead_cell_table_maybe_dump(VeryVerbose, DeadCellTable, !IO),
 
     % Determine how the detected dead datastructures can be reused. 
Index: compiler/structure_reuse.indirect.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/structure_reuse.indirect.m,v
retrieving revision 1.3
diff -u -d -r1.3 structure_reuse.indirect.m
--- compiler/structure_reuse.indirect.m	15 Jun 2006 19:37:11 -0000	1.3
+++ compiler/structure_reuse.indirect.m	19 Jun 2006 12:57:43 -0000
@@ -273,9 +273,10 @@
         GoalExpr0 = call(CalleePredId, CalleeProcId, CalleeArgs, _, _, _),
         verify_indirect_reuse(BaseInfo, CalleePredId, CalleeProcId, 
             CalleeArgs, GoalInfo0, GoalInfo, !AnalysisInfo, !IO),
-        lookup_sharing_and_comb(BaseInfo ^ module_info, BaseInfo ^ proc_info,
-            BaseInfo ^ sharing_table, CalleePredId, CalleeProcId, 
-            CalleeArgs, !.AnalysisInfo ^ sharing_as, NewSharing),
+        lookup_sharing_and_comb(BaseInfo ^ module_info, BaseInfo ^ pred_info, 
+            BaseInfo ^ proc_info, BaseInfo ^ sharing_table, 
+            CalleePredId, CalleeProcId, CalleeArgs, 
+            !.AnalysisInfo ^ sharing_as, NewSharing),
         !:AnalysisInfo = !.AnalysisInfo ^ sharing_as := NewSharing,
         GoalExpr = GoalExpr0,
         !:Goal = GoalExpr - GoalInfo
Index: compiler/structure_sharing.domain.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/structure_sharing.domain.m,v
retrieving revision 1.10
diff -u -d -r1.10 structure_sharing.domain.m
--- compiler/structure_sharing.domain.m	5 Jun 2006 05:23:27 -0000	1.10
+++ compiler/structure_sharing.domain.m	19 Jun 2006 12:57:46 -0000
@@ -240,7 +240,7 @@
     % pred_id and proc_id), and combine it with any existing
     % sharing information.
     %
-:- pred lookup_sharing_and_comb(module_info::in, proc_info::in,
+:- pred lookup_sharing_and_comb(module_info::in, pred_info::in, proc_info::in,
     sharing_as_table::in, pred_id::in, proc_id::in, prog_vars::in,
     sharing_as::in, sharing_as::out) is det.
 
@@ -381,9 +381,10 @@
 
 sharing_as_rename_using_module_info(ModuleInfo, PPId, ActualVars, ActualTypes,
         ActualTVarset, FormalSharing, ActualSharing):-
-    sharing_as_rename(get_variable_renaming(ModuleInfo, PPId, ActualVars),
-        get_type_substitution(ModuleInfo, PPId, ActualTypes, ActualTVarset),
-        FormalSharing, ActualSharing).
+    VarRenaming = get_variable_renaming(ModuleInfo, PPId, ActualVars),
+    TypeRenaming = get_type_substitution(ModuleInfo, PPId, ActualTypes,
+        ActualTVarset), 
+    sharing_as_rename(VarRenaming, TypeRenaming, FormalSharing, ActualSharing).
 
 sharing_as_comb(ModuleInfo, ProcInfo, NewSharing, OldSharing) = ResultSharing :-
     (
@@ -711,8 +712,8 @@
 
 %-----------------------------------------------------------------------------%
 
-lookup_sharing_and_comb(ModuleInfo, ProcInfo, SharingTable, PredId, ProcId,
-        ActualVars, !Sharing):- 
+lookup_sharing_and_comb(ModuleInfo, PredInfo, ProcInfo, SharingTable, 
+        PredId, ProcId, ActualVars, !Sharing):- 
     PPId = proc(PredId, ProcId),
     
     lookup_sharing_or_predict(ModuleInfo, SharingTable, PPId, FormalSharing),
@@ -721,7 +722,7 @@
     list.map(map.lookup(VarTypes), ActualVars, ActualTypes), 
        
         % XXX To be checked!
-    ActualTVarset = varset.init, 
+    pred_info_get_typevarset(PredInfo, ActualTVarset), 
     sharing_as_rename_using_module_info(ModuleInfo, PPId, 
         ActualVars, ActualTypes, ActualTVarset, FormalSharing,
         ActualSharing),


-- 
nancy.mazur at cs.kuleuven.ac.be ------------ Katholieke Universiteit Leuven -
tel: +32-16-327596 - fax: +32-16-327996 ------- Dept. of Computer Science -

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

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