[m-dev.] for review: higher-order write_graph
Peter Ross
peter.ross at miscrit.be
Wed Feb 28 08:05:14 AEDT 2001
On Wed, Feb 28, 2001 at 04:26:35AM +1100, Fergus Henderson wrote:
> On 27-Feb-2001, Peter Ross <peter.ross at miscrit.be> wrote:
> > On Wed, Feb 28, 2001 at 03:54:47AM +1100, Fergus Henderson wrote:
> > > What happens if someone calls build_dependency_graph
> > > with the option to include the imported procedures,
> > > and then later some code calls ensure_dependency_graph?
> > > Will the later code get the version that includes imported
> > > procedures?
> > >
> > > Unless the code is changed, I think it will, and I think
> > > that is likely to cause future problems.
> >
> > The only predicate which stores the dependency_graph in the module_info
> > is ensure_dependency_graph, and it only ever calls build_dependency_graph
> > with the bool set to yes.
>
> OK. That makes sense. But this invariant (that the dependency_graph
> in the module_info is must always be one that was built with the
> imported procedures excluded) should be documented in hlds_module.m.
>
Estimated hours taken: 1.25
Move changes from reuse branch onto the main branch.
These changes were introduced on the reuse branch so that we could
produce dot files which showed which predicates were calling reuse
versions, and hence easily determine where reuse was being lost.
compiler/dependency_graph.m:
Add two new predicates write_graph and write_graph_nodes, which take
higher order arguments which determine what to write for a node and
edge in the graph.
Change build_dependency_graph so that it optionally also includes
arcs to imported procedures.
Change write_dependency_graph and write_prof_dependency_graph to use
the new higher order predicates.
compiler/hlds_module.m:
Document the constraints on the dependency_info stored in the
module_info.
diff -u compiler/dependency_graph.m compiler/dependency_graph.m
--- compiler/dependency_graph.m
+++ compiler/dependency_graph.m
@@ -23,12 +23,18 @@
:- import_module hlds_module, hlds_pred.
:- import_module bool, list, io.
+ % Ensure that the module_info contains a version of the
+ % dependency_info which only contains arcs between procedures
+ % for which there are clauses defined (ie not imported except
+ % for opt_imported).
+ %
:- pred module_info_ensure_dependency_info(module_info, module_info).
:- mode module_info_ensure_dependency_info(in, out) is det.
% Build the dependency graph, if the bool is yes then
- % imported_procedures aren't included in the dependency graph,
- % otherwise they are.
+ % imported procedures are included in the dependency graph,
+ % otherwise they aren't.
+ %
:- pred dependency_graph__build_dependency_graph(module_info, bool,
dependency_info).
:- mode dependency_graph__build_dependency_graph(in, in, out) is det.
@@ -116,19 +122,19 @@
( MaybeDepInfo = yes(_) ->
ModuleInfo = ModuleInfo0
;
- dependency_graph__build_dependency_graph(ModuleInfo0, yes, DepInfo),
+ dependency_graph__build_dependency_graph(ModuleInfo0, no, DepInfo),
module_info_set_dependency_info(ModuleInfo0, DepInfo, ModuleInfo)
).
% Traverse the module structure, calling `dependency_graph__add_arcs'
% for each procedure body.
-dependency_graph__build_dependency_graph(ModuleInfo0, LocalOnly, DepInfo) :-
+dependency_graph__build_dependency_graph(ModuleInfo0, Imported, DepInfo) :-
module_info_predids(ModuleInfo0, PredIds),
relation__init(DepGraph0),
- dependency_graph__add_pred_nodes(PredIds, ModuleInfo0, LocalOnly,
+ dependency_graph__add_pred_nodes(PredIds, ModuleInfo0, Imported,
DepGraph0, DepGraph1),
- dependency_graph__add_pred_arcs(PredIds, ModuleInfo0, LocalOnly,
+ dependency_graph__add_pred_arcs(PredIds, ModuleInfo0, Imported,
DepGraph1, DepGraph),
hlds_dependency_info_init(DepInfo0),
hlds_dependency_info_set_dependency_graph(DepInfo0, DepGraph,
@@ -155,7 +161,7 @@
:- mode dependency_graph__add_pred_nodes(in, in, in, in, out) is det.
dependency_graph__add_pred_nodes([], _ModuleInfo, _, DepGraph, DepGraph).
-dependency_graph__add_pred_nodes([PredId | PredIds], ModuleInfo, LocalOnly,
+dependency_graph__add_pred_nodes([PredId | PredIds], ModuleInfo, Imported,
DepGraph0, DepGraph) :-
module_info_preds(ModuleInfo, PredTable),
map__lookup(PredTable, PredId, PredInfo),
@@ -163,16 +169,16 @@
% Don't bother adding nodes (or arcs) for procedures
% which which are imported (ie we don't have any
% `clauses' for).
- LocalOnly = yes,
+ Imported = no,
pred_info_non_imported_procids(PredInfo, ProcIds)
;
- LocalOnly = no,
+ Imported = yes,
pred_info_procids(PredInfo, ProcIds)
),
dependency_graph__add_proc_nodes(ProcIds, PredId, ModuleInfo,
DepGraph0, DepGraph1),
- dependency_graph__add_pred_nodes(PredIds, ModuleInfo, LocalOnly,
+ dependency_graph__add_pred_nodes(PredIds, ModuleInfo, Imported,
DepGraph1, DepGraph).
:- pred dependency_graph__add_proc_nodes(list(proc_id), pred_id, module_info,
@@ -194,7 +200,7 @@
:- mode dependency_graph__add_pred_arcs(in, in, in, in, out) is det.
dependency_graph__add_pred_arcs([], _ModuleInfo, _, DepGraph, DepGraph).
-dependency_graph__add_pred_arcs([PredId | PredIds], ModuleInfo, LocalOnly,
+dependency_graph__add_pred_arcs([PredId | PredIds], ModuleInfo, Imported,
DepGraph0, DepGraph) :-
module_info_preds(ModuleInfo, PredTable),
map__lookup(PredTable, PredId, PredInfo),
@@ -202,15 +208,15 @@
% Don't bother adding nodes (or arcs) for procedures
% which which are imported (ie we don't have any
% `clauses' for).
- LocalOnly = yes,
+ Imported = no,
pred_info_non_imported_procids(PredInfo, ProcIds)
;
- LocalOnly = no,
+ Imported = yes,
pred_info_procids(PredInfo, ProcIds)
),
- dependency_graph__add_proc_arcs(ProcIds, PredId, ModuleInfo, LocalOnly,
+ dependency_graph__add_proc_arcs(ProcIds, PredId, ModuleInfo, Imported,
DepGraph0, DepGraph1),
- dependency_graph__add_pred_arcs(PredIds, ModuleInfo, LocalOnly,
+ dependency_graph__add_pred_arcs(PredIds, ModuleInfo, Imported,
DepGraph1, DepGraph).
:- pred dependency_graph__add_proc_arcs(list(proc_id), pred_id, module_info,
@@ -220,7 +226,7 @@
dependency_graph__add_proc_arcs([], _PredId, _ModuleInfo, _,
DepGraph, DepGraph).
dependency_graph__add_proc_arcs([ProcId | ProcIds], PredId, ModuleInfo,
- LocalOnly, DepGraph0, DepGraph) :-
+ IncludeImported, DepGraph0, DepGraph) :-
module_info_preds(ModuleInfo, PredTable0),
map__lookup(PredTable0, PredId, PredInfo0),
@@ -228,7 +234,7 @@
map__lookup(ProcTable0, ProcId, ProcInfo0),
(
- LocalOnly = yes,
+ IncludeImported = no,
proc_info_goal(ProcInfo0, Goal),
relation__lookup_element(DepGraph0,
@@ -236,7 +242,7 @@
dependency_graph__add_arcs_in_goal(Goal, Caller,
DepGraph0, DepGraph1)
;
- LocalOnly = no,
+ IncludeImported = yes,
pred_info_import_status(PredInfo0, ImportStatus),
status_is_imported(ImportStatus, Imported),
(
@@ -252,8 +258,8 @@
DepGraph0, DepGraph1)
)
),
- dependency_graph__add_proc_arcs(ProcIds, PredId, ModuleInfo, LocalOnly,
- DepGraph1, DepGraph).
+ dependency_graph__add_proc_arcs(ProcIds, PredId, ModuleInfo,
+ IncludeImported, DepGraph1, DepGraph).
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
only in patch2:
--- compiler/hlds_module.m 2001/01/17 01:41:50 1.64
+++ compiler/hlds_module.m 2001/02/27 20:55:10
@@ -266,6 +266,8 @@
module_info, module_info).
:- mode module_add_foreign_body_code(in, in, in, in, out) is det.
+ % Please see module_info_ensure_dependency_info for the
+ % constraints on this dependency_info.
:- pred module_info_get_maybe_dependency_info(module_info,
maybe(dependency_info)).
:- mode module_info_get_maybe_dependency_info(in, out) is det.
@@ -399,6 +401,8 @@
:- pred module_info_consids(module_info, list(cons_id)).
:- mode module_info_consids(in, out) is det.
+ % Please see module_info_ensure_dependency_info for the
+ % constraints on this dependency_info.
:- pred module_info_dependency_info(module_info, dependency_info).
:- mode module_info_dependency_info(in, out) is det.
@@ -406,6 +410,8 @@
aditi_dependency_ordering).
:- mode module_info_aditi_dependency_ordering(in, out) is det.
+ % Please see module_info_ensure_dependency_info for the
+ % constraints on this dependency_info.
:- pred module_info_set_dependency_info(module_info, dependency_info,
module_info).
:- mode module_info_set_dependency_info(in, in, out) is det.
@@ -485,6 +491,11 @@
globals :: globals,
foreign_decl_info :: foreign_decl_info,
foreign_body_info :: foreign_body_info,
+
+ % This dependency info is constrained to be only
+ % for between procedures which have clauses
+ % defined for them in this compilation unit
+ % (that includes opt_imported procedures).
maybe_dependency_info :: maybe(dependency_info),
num_errors :: int,
last_lambda_number :: int,
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list