Fix performance bugs in library/relation.m which caused

Estimated hours taken: 12
Branches: main

Fix performance bugs in library/relation.m which caused
`mmc --generate-dependencies' to choke on large programs
(e.g. the compiler).

`mmc --generate-dependencies top_level' now takes
about 8 seconds on jupiter, compared to over a minute
before.

library/relation.m:
	Use sparse_bitset for sets of relation_keys.

	Rewrite relation__compose to use the indexing
	in the relation structure, rather than just
	doing a naive nested loop join.

	Clean up and fix a bug in relation__is_dag.

	Rewrite algorithms to avoid using to_sorted_list
	on sparse_bitsets of relation keys; this is not
	a cheap operation as it is with set.sets.
	Use sparse_bitset.fold{l,r} instead where
	possible.

library/sparse_bitset.m:
	Add new functions to_set and from_set,
	which convert between sparse_bitsets
	and set.sets.

	Add predicate versions of foldl and foldr with
	the same modes as the list version.

compiler/modules.m:
	Use sparse_bitset.foldl rather than sparse_bitset.to_sorted_list
	followed by list.map.

profiler/propagate.m:
	relation__dfsrev now takes a sparse_bitset(relation_key),
	not set_bbbtree(relation_key).

library/map.m:
library/tree234.m:
	Type specialize map__det_update for term.var and int.

NEWS:
	Document new predicates and functions.

tests/hard_coded/relation_test.{m,exp}:
	Test relation__is_dag.
This commit is contained in:
Simon Taylor
2003-12-22 11:21:49 +00:00
parent b4bbe631c8
commit e18d74a90e
9 changed files with 511 additions and 309 deletions

View File

@@ -1,5 +1,5 @@
%-----------------------------------------------------------------------------%
% Copyright (C) 1995-1997 The University of Melbourne.
% Copyright (C) 1995-1997, 2003 The University of Melbourne.
% This file may only be copied under the terms of the GNU General
% Public License - see the file COPYING in the Mercury distribution.
%-----------------------------------------------------------------------------%
@@ -38,7 +38,7 @@
:- implementation.
:- import_module assoc_list, float, int, list, map, multi_map, require.
:- import_module string, set_bbbtree, std_util.
:- import_module string, sparse_bitset, std_util.
% :- import_module writeln.
:- type cycle_info == pair(
@@ -80,13 +80,13 @@ propagate__identify_cycles(Rel, ATSort, CycleInfo) :-
relation__dfsrev(Rel, DfsRev),
relation__inverse(Rel, RelInv),
cycle_info_init(CycleInfo0),
set_bbbtree__init(Visit0),
init(Visit0),
propagate__identify_cycles_2(DfsRev, 1, RelInv, Visit0, [],
CycleInfo0, ATSort, CycleInfo).
:- pred propagate__identify_cycles_2(list(relation_key), int, relation(string),
set_bbbtree(relation_key), list(string),
relation_key_set, list(string),
cycle_info, list(string), cycle_info).
:- mode propagate__identify_cycles_2(in, in, in, in, in, in, out, out) is det.