[m-rev.] for post-commit review: cons_table reorganization
Zoltan Somogyi
zs at csse.unimelb.edu.au
Mon Aug 22 14:21:56 AEST 2011
The cons_table maps fully, partially and not-at-all module-qualified versions
of cons_ids to the definitions of the corresponding data constructors.
Up till now, this table has been implemented as a simple map from cons_ids
to hlds_cons_defns. However, since cons_ids are nontrivial data structures,
comparisons of the keys in this map is relatively expensive, and since each
constructor's name is in the table several times, an access will perform
many of these expensive comparisons.
This diff makes the cons_table abstract, and changes its organization to a
two-level map. The first level is a map from the constructor's name to an inner
map, with the inner map mapping all cons_ids with a given name to their
definitions.
This can be expected to make lookups faster because lookups in the outer table
need fewer comparisons (due to the absence of repetition) and these comparisons
are faster (since a name is simpler than a cons_id). We still have to contend
with repetitions and expensive comparisons in the inner table, but each inner
table should be tiny.
The overall effect on tools/speedtest -l is a speedup of about 2.5%.
compiler/hlds_data.m:
Make the change described above. Provide the operations on the
cons_table that are needed by the rest of the compiler.
Provide a predicate to look up not just a cons_id, but a cons_id
in a particular type constructor. This factors out code that was
present at several call sites, and allows those call sites to avoid
repeatedly executing the same code on the same data, to wit, the
several hlds_cons_defns returned for a given cons_id in a given
type_ctor, which should ALL be identical.
Insert all versions of a cons_id into the table at once, since
this is significantly more efficient.
compiler/add_type.m:
compiler/equiv_type_hlds.m:
compiler/hlds_module.m:
compiler/intermod.m:
compiler/passes_aux.m:
compiler/post_typecheck.m:
compiler/recompilation.usage.m:
compiler/type_constraints.m:
compiler/type_util.m:
compiler/typecheck.m:
compiler/typecheck_errors.m:
Conform to the change above, taking advantage of the new facilities
in hlds_data.m if possible.
Zoltan.
cvs diff: Diffing .
cvs diff: Diffing analysis
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/doc
cvs diff: Diffing boehm_gc/extra
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/extra
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/libatomic_ops
cvs diff: Diffing boehm_gc/libatomic_ops/doc
cvs diff: Diffing boehm_gc/libatomic_ops/src
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/armcc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/gcc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/hpc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/ibmc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/icc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/msftc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/sunc
cvs diff: Diffing boehm_gc/libatomic_ops/tests
cvs diff: Diffing boehm_gc/libatomic_ops-1.2
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/doc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/tests
cvs diff: Diffing boehm_gc/m4
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
Index: compiler/add_type.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/add_type.m,v
retrieving revision 1.44
diff -u -b -r1.44 add_type.m
--- compiler/add_type.m 5 Jul 2011 03:34:29 -0000 1.44
+++ compiler/add_type.m 21 Aug 2011 11:48:27 -0000
@@ -692,59 +692,51 @@
ConsDefn = hlds_cons_defn(TypeCtor, TVarSet, TypeParams, KindMap,
ExistQVars, Constraints, Args, Context),
- % Insert the fully-qualified version of this cons_id into the cons_table.
- % Also check that there is at most one definition of a given cons_id
- % in each type.
+ some [!OtherConsIds] (
+ MainConsId = QualifiedConsIdB,
+ !:OtherConsIds = [],
- ( map.search(!.Ctors, QualifiedConsIdA, QualifiedConsDefnsA0) ->
- QualifiedConsDefnsA1 = QualifiedConsDefnsA0
- ;
- QualifiedConsDefnsA1 = []
- ),
- ( map.search(!.Ctors, QualifiedConsIdB, QualifiedConsDefnsB0) ->
- QualifiedConsDefnsB1 = QualifiedConsDefnsB0
- ;
- QualifiedConsDefnsB1 = []
- ),
+ % Check that there is at most one definition of a given cons_id
+ % in each type.
(
+ search_cons_table(!.Ctors, QualifiedConsIdA, QualifiedConsDefnsA),
some [OtherConsDefn] (
- list.member(OtherConsDefn, QualifiedConsDefnsA1),
+ list.member(OtherConsDefn, QualifiedConsDefnsA),
OtherConsDefn ^ cons_type_ctor = TypeCtor
)
->
QualifiedConsIdStr = cons_id_and_arity_to_string(QualifiedConsIdA),
TypeCtorStr = type_ctor_to_string(TypeCtor),
Pieces = [words("Error: constructor"), quote(QualifiedConsIdStr),
- words("for type"), quote(TypeCtorStr), words("multiply defined.")],
+ words("for type"), quote(TypeCtorStr),
+ words("multiply defined."), nl],
Msg = simple_msg(Context, [always(Pieces)]),
Spec = error_spec(severity_error, phase_parse_tree_to_hlds, [Msg]),
- !:Specs = [Spec | !.Specs],
- QualifiedConsDefnsA = QualifiedConsDefnsA1
+ !:Specs = [Spec | !.Specs]
;
- QualifiedConsDefnsA = [ConsDefn | QualifiedConsDefnsA1]
+ !:OtherConsIds = [QualifiedConsIdA | !.OtherConsIds]
),
- QualifiedConsDefnsB = [ConsDefn | QualifiedConsDefnsB1],
- map.set(QualifiedConsIdA, QualifiedConsDefnsA, !Ctors),
- map.set(QualifiedConsIdB, QualifiedConsDefnsB, !Ctors),
% Add the unqualified version of the cons_id to the cons_table,
% if appropriate.
(
NeedQual = may_be_unqualified,
- multi_map.set(UnqualifiedConsIdA, ConsDefn, !Ctors),
- multi_map.set(UnqualifiedConsIdB, ConsDefn, !Ctors)
+ !:OtherConsIds =
+ [UnqualifiedConsIdA, UnqualifiedConsIdB | !.OtherConsIds]
;
NeedQual = must_be_qualified
),
% Add partially qualified versions of the cons_id.
get_partial_qualifiers(TypeCtorModuleName, PQInfo, PartialQuals),
- list.foldl(
- add_ctor(TypeCtor, BaseName, Arity, ConsDefn),
- PartialQuals, !Ctors),
- list.foldl(
- add_ctor(cons_id_dummy_type_ctor, BaseName, Arity, ConsDefn),
- PartialQuals, !Ctors),
+ list.foldl(add_ctor_to_list(TypeCtor, BaseName, Arity),
+ PartialQuals, !OtherConsIds),
+
+ insert_into_cons_table(MainConsId, !.OtherConsIds, ConsDefn,
+ !Ctors)
+ ),
+
+ % Insert the fully-qualified version of this cons_id into the cons_table.
FieldNames = list.map(func(C) = C ^ arg_field_name, Args),
FirstField = 1,
@@ -756,12 +748,14 @@
KindMap, NeedQual, PQInfo, Context, ImportStatus, !FieldNameTable,
!Ctors, !Specs).
-:- pred add_ctor(type_ctor::in, string::in, int::in, hlds_cons_defn::in,
- module_name::in, cons_table::in, cons_table::out) is det.
+:- pred add_ctor_to_list(type_ctor::in, string::in, int::in, module_name::in,
+ list(cons_id)::in, list(cons_id)::out) is det.
-add_ctor(TypeCtor, ConsName, Arity, ConsDefn, ModuleQual, !Ctors) :-
- ConsId = cons(qualified(ModuleQual, ConsName), Arity, TypeCtor),
- multi_map.set(ConsId, ConsDefn, !Ctors).
+add_ctor_to_list(TypeCtor, ConsName, Arity, ModuleQual, !ConsIds) :-
+ ConsIdA = cons(qualified(ModuleQual, ConsName), Arity, TypeCtor),
+ ConsIdB = cons(qualified(ModuleQual, ConsName), Arity,
+ cons_id_dummy_type_ctor),
+ !:ConsIds = [ConsIdA, ConsIdB | !.ConsIds].
:- pred add_ctor_field_names(list(maybe(ctor_field_name))::in,
need_qualifier::in, list(module_name)::in, type_ctor::in, cons_id::in,
Index: compiler/equiv_type_hlds.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/equiv_type_hlds.m,v
retrieving revision 1.68
diff -u -b -r1.68 equiv_type_hlds.m
--- compiler/equiv_type_hlds.m 5 Jul 2011 03:34:31 -0000 1.68
+++ compiler/equiv_type_hlds.m 21 Aug 2011 10:18:51 -0000
@@ -302,13 +302,8 @@
is det.
replace_in_cons_table(EqvMap, !ConsTable) :-
- map.map_values_only(replace_in_cons_defns(EqvMap), !ConsTable).
-
-:- pred replace_in_cons_defns(eqv_map::in,
- list(hlds_cons_defn)::in, list(hlds_cons_defn)::out) is det.
-
-replace_in_cons_defns(EqvMap, !ConsDefns) :-
- list.map(replace_in_cons_defn(EqvMap), !ConsDefns).
+ replace_cons_defns_in_cons_table(replace_in_cons_defn(EqvMap),
+ !ConsTable).
:- pred replace_in_cons_defn(eqv_map::in,
hlds_cons_defn::in, hlds_cons_defn::out) is det.
Index: compiler/hlds_data.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/hlds_data.m,v
retrieving revision 1.139
diff -u -b -r1.139 hlds_data.m
--- compiler/hlds_data.m 5 Jul 2011 03:34:31 -0000 1.139
+++ compiler/hlds_data.m 21 Aug 2011 11:56:26 -0000
@@ -39,6 +39,7 @@
:- import_module int.
:- import_module multi_map.
:- import_module require.
+:- import_module solutions.
:- import_module varset.
%-----------------------------------------------------------------------------%
@@ -49,7 +50,7 @@
% The symbol table for constructors. This table is used by the type-checker
% to look up the type of functors/constants.
%
-:- type cons_table == map(cons_id, list(hlds_cons_defn)).
+:- type cons_table.
% A cons_defn is the definition of a constructor (i.e. a constant
% or a functor) for a particular type.
@@ -87,8 +88,176 @@
cons_context :: prog_context
).
+:- func init_cons_table = cons_table.
+
+:- pred insert_into_cons_table(cons_id::in, list(cons_id)::in,
+ hlds_cons_defn::in, cons_table::in, cons_table::out) is det.
+
+:- pred search_cons_table(cons_table::in, cons_id::in,
+ list(hlds_cons_defn)::out) is semidet.
+
+:- pred search_cons_table_of_type_ctor(cons_table::in, type_ctor::in,
+ cons_id::in, hlds_cons_defn::out) is semidet.
+
+:- pred lookup_cons_table_of_type_ctor(cons_table::in, type_ctor::in,
+ cons_id::in, hlds_cons_defn::out) is det.
+
+:- pred get_all_cons_defns(cons_table::in,
+ assoc_list(cons_id, list(hlds_cons_defn))::out) is det.
+
+:- pred return_other_arities(cons_table::in, sym_name::in, int::in,
+ list(int)::out) is det.
+
+:- pred replace_cons_defns_in_cons_table(
+ pred(hlds_cons_defn, hlds_cons_defn)::in(pred(in, out) is det),
+ cons_table::in, cons_table::out) is det.
+
+:- pred cons_table_optimize(cons_table::in, cons_table::out) is det.
+
+:- implementation.
+
+:- type cons_table == map(string, inner_cons_table).
+:- type inner_cons_table == map(cons_id, list(hlds_cons_defn)).
+
+init_cons_table = map.init.
+
+insert_into_cons_table(MainConsId, OtherConsIds, ConsDefn, !ConsTable) :-
+ ( MainConsId = cons(MainSymName, _, _) ->
+ MainName = unqualify_name(MainSymName),
+ ( map.search(!.ConsTable, MainName, InnerConsTable0) ->
+ insert_into_inner_cons_table(MainName, [MainConsId | OtherConsIds],
+ ConsDefn, InnerConsTable0, InnerConsTable),
+ map.det_update(MainName, InnerConsTable, !ConsTable)
+ ;
+ insert_into_inner_cons_table(MainName, [MainConsId | OtherConsIds],
+ ConsDefn, map.init, InnerConsTable),
+ map.det_insert(MainName, InnerConsTable, !ConsTable)
+ )
+ ;
+ unexpected($module, $pred, "MainConsId is not cons")
+ ).
+
+:- pred insert_into_inner_cons_table(string::in, list(cons_id)::in,
+ hlds_cons_defn::in, inner_cons_table::in, inner_cons_table::out) is det.
+
+insert_into_inner_cons_table(_MainName, [], _ConsDefn, !InnerConsTable).
+insert_into_inner_cons_table(MainName, [ConsId | ConsIds], ConsDefn,
+ !InnerConsTable) :-
+ ( ConsId = cons(SymName, _, _) ->
+ Name = unqualify_name(SymName),
+ ( Name = MainName ->
+ multi_map.set(ConsId, ConsDefn, !InnerConsTable)
+ ;
+ unexpected($module, $pred, "SymName mismatch")
+ )
+ ;
+ unexpected($module, $pred, "ConsId is not cons")
+ ),
+ insert_into_inner_cons_table(MainName, ConsIds, ConsDefn, !InnerConsTable).
+
+search_cons_table(ConsTable, ConsId, ConsDefns) :-
+ ConsId = cons(SymName, _, _),
+ Name = unqualify_name(SymName),
+ map.search(ConsTable, Name, InnerConsTable),
+ map.search(InnerConsTable, ConsId, ConsDefns).
+
+search_cons_table_of_type_ctor(ConsTable, TypeCtor, ConsId, ConsDefn) :-
+ ConsId = cons(SymName, _, _),
+ Name = unqualify_name(SymName),
+ map.search(ConsTable, Name, InnerConsTable),
+ map.search(InnerConsTable, ConsId, AllConsDefns),
+ search_cons_defns_for_type_ctor(TypeCtor, AllConsDefns, ConsDefn).
+
+:- pred search_cons_defns_for_type_ctor(type_ctor::in,
+ list(hlds_cons_defn)::in, hlds_cons_defn::out) is semidet.
+
+search_cons_defns_for_type_ctor(TypeCtor, [HeadConsDefn | TailConsDefns],
+ ConsDefn) :-
+ ( HeadConsDefn ^ cons_type_ctor = TypeCtor ->
+ verify_cons_defns_for_type_ctor(TypeCtor, HeadConsDefn, TailConsDefns,
+ ConsDefn)
+ ;
+ search_cons_defns_for_type_ctor(TypeCtor, TailConsDefns, ConsDefn)
+ ).
+
+:- pred verify_cons_defns_for_type_ctor(type_ctor::in, hlds_cons_defn::in,
+ list(hlds_cons_defn)::in, hlds_cons_defn::out) is semidet.
+
+verify_cons_defns_for_type_ctor(_TypeCtor, FirstConsDefn, [], FirstConsDefn).
+verify_cons_defns_for_type_ctor(TypeCtor, FirstConsDefn,
+ [HeadConsDefn | TailConsDefns], ConsDefn) :-
+ ( HeadConsDefn ^ cons_type_ctor = TypeCtor ->
+ ( HeadConsDefn = FirstConsDefn ->
+ verify_cons_defns_for_type_ctor(TypeCtor, FirstConsDefn,
+ TailConsDefns, ConsDefn)
+ ;
+ unexpected($module, $pred,
+ "different cons_defns for same cons_id in same type")
+ )
+ ;
+ verify_cons_defns_for_type_ctor(TypeCtor, FirstConsDefn,
+ TailConsDefns, ConsDefn)
+ ).
+
+lookup_cons_table_of_type_ctor(ConsTable, TypeCtor, ConsId, ConsDefn) :-
+ (
+ search_cons_table_of_type_ctor(ConsTable, TypeCtor, ConsId,
+ ConsDefnPrime)
+ ->
+ ConsDefn = ConsDefnPrime
+ ;
+ unexpected($module, $pred, "lookup failed")
+ ).
+
+get_all_cons_defns(ConsTable, AllConsDefns) :-
+ map.foldl(accumulate_all_inner_cons_defns, ConsTable, [], AllConsDefns).
+
+:- pred accumulate_all_inner_cons_defns(string::in, inner_cons_table::in,
+ assoc_list(cons_id, list(hlds_cons_defn))::in,
+ assoc_list(cons_id, list(hlds_cons_defn))::out) is det.
+
+accumulate_all_inner_cons_defns(_Name, InnerConsTable, !AllConsDefns) :-
+ map.to_assoc_list(InnerConsTable, InnerConsList),
+ !:AllConsDefns = InnerConsList ++ !.AllConsDefns.
+
+return_other_arities(ConsTable, SymName, Arity, OtherArities) :-
+ Name = unqualify_name(SymName),
+ ( map.search(ConsTable, Name, InnerConsTable) ->
+ solutions.solutions(
+ (pred(N::out) is nondet :-
+ map.member(InnerConsTable, cons(SymName, N, _), _),
+ N \= Arity
+ ), OtherArities)
+ ;
+ OtherArities = []
+ ).
+
+replace_cons_defns_in_cons_table(Replace, !ConsTable) :-
+ map.map_values_only(replace_cons_defns_in_inner_cons_table(Replace),
+ !ConsTable).
+
+:- pred replace_cons_defns_in_inner_cons_table(
+ pred(hlds_cons_defn, hlds_cons_defn)::in(pred(in, out) is det),
+ inner_cons_table::in, inner_cons_table::out) is det.
+
+replace_cons_defns_in_inner_cons_table(Replace, !InnerConsTable) :-
+ map.map_values_only(replace_cons_defns_in_cons_defns(Replace),
+ !InnerConsTable).
+
+:- pred replace_cons_defns_in_cons_defns(
+ pred(hlds_cons_defn, hlds_cons_defn)::in(pred(in, out) is det),
+ list(hlds_cons_defn)::in, list(hlds_cons_defn)::out) is det.
+
+replace_cons_defns_in_cons_defns(Replace, !ConsDefns) :-
+ list.map(Replace, !ConsDefns).
+
+cons_table_optimize(!ConsTable) :-
+ map.optimize(!ConsTable).
+
%-----------------------------------------------------------------------------%
+:- interface.
+
:- type ctor_field_table == map(ctor_field_name, list(hlds_ctor_field_defn)).
:- type hlds_ctor_field_defn
Index: compiler/hlds_module.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/hlds_module.m,v
retrieving revision 1.173
diff -u -b -r1.173 hlds_module.m
--- compiler/hlds_module.m 31 May 2011 03:14:20 -0000 1.173
+++ compiler/hlds_module.m 21 Aug 2011 11:20:50 -0000
@@ -919,7 +919,7 @@
TypeTable = init_type_table,
inst_table_init(Insts),
mode_table_init(Modes),
- map.init(Ctors),
+ Ctors = init_cons_table,
map.init(ClassTable),
map.init(InstanceTable),
assertion_table_init(AssertionTable),
@@ -1368,7 +1368,7 @@
module_info_set_mode_table(Modes, !ModuleInfo),
module_info_get_cons_table(!.ModuleInfo, Ctors0),
- map.optimize(Ctors0, Ctors),
+ cons_table_optimize(Ctors0, Ctors),
module_info_set_cons_table(Ctors, !ModuleInfo).
visible_module(VisibleModule, ModuleInfo) :-
Index: compiler/intermod.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/intermod.m,v
retrieving revision 1.266
diff -u -b -r1.266 intermod.m
--- compiler/intermod.m 5 Jul 2011 03:34:32 -0000 1.266
+++ compiler/intermod.m 21 Aug 2011 10:21:04 -0000
@@ -980,7 +980,7 @@
(
ConsId = cons(InstanceMethodName0, MethodArity,
cons_id_dummy_type_ctor),
- map.search(Ctors, ConsId, MatchingConstructors)
+ search_cons_table(Ctors, ConsId, MatchingConstructors)
->
TypeCtors1 = list.map(
(func(ConsDefn) = TypeCtor :-
Index: compiler/passes_aux.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/passes_aux.m,v
retrieving revision 1.106
diff -u -b -r1.106 passes_aux.m
--- compiler/passes_aux.m 25 May 2011 02:02:51 -0000 1.106
+++ compiler/passes_aux.m 21 Aug 2011 09:34:15 -0000
@@ -460,7 +460,9 @@
io.format("Type table size = %d\n", [i(list.length(TypeCtorDefns))], !IO),
module_info_get_cons_table(ModuleInfo, CtorTable),
- io.format("Constructor table size = %d\n", [i(map.count(CtorTable))], !IO).
+ get_all_cons_defns(CtorTable, CtorDefns),
+ io.format("Constructor table size = %d\n",
+ [i(list.length(CtorDefns))], !IO).
%-----------------------------------------------------------------------------%
Index: compiler/post_typecheck.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/post_typecheck.m,v
retrieving revision 1.152
diff -u -b -r1.152 post_typecheck.m
--- compiler/post_typecheck.m 16 Aug 2011 03:26:33 -0000 1.152
+++ compiler/post_typecheck.m 21 Aug 2011 10:00:07 -0000
@@ -1221,13 +1221,10 @@
find_matching_constructor(ModuleInfo, TVarSet, ConsId, Type, ArgTypes) :-
type_to_ctor_and_args(Type, TypeCtor, _),
module_info_get_cons_table(ModuleInfo, ConsTable),
- map.search(ConsTable, ConsId, ConsDefns),
- list.member(ConsDefn, ConsDefns),
+ search_cons_table_of_type_ctor(ConsTable, TypeCtor, ConsId, ConsDefn),
% Overloading resolution ignores the class constraints.
- ConsDefn = hlds_cons_defn(ConsTypeCtor, _, _, _, ConsExistQVars, _,
- ConsArgs, _),
- ConsTypeCtor = TypeCtor,
+ ConsDefn = hlds_cons_defn(_, _, _, _, ConsExistQVars, _, ConsArgs, _),
module_info_get_type_table(ModuleInfo, TypeTable),
search_type_ctor_defn(TypeTable, TypeCtor, TypeDefn),
Index: compiler/recompilation.usage.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/recompilation.usage.m,v
retrieving revision 1.59
diff -u -b -r1.59 recompilation.usage.m
--- compiler/recompilation.usage.m 16 Jun 2011 06:42:15 -0000 1.59
+++ compiler/recompilation.usage.m 21 Aug 2011 10:01:48 -0000
@@ -730,15 +730,15 @@
% Is it a constructor.
module_info_get_cons_table(ModuleInfo, Ctors),
ConsId = cons(SymName, Arity, cons_id_dummy_type_ctor),
- ( map.search(Ctors, ConsId, ConsDefns0) ->
+ ( search_cons_table(Ctors, ConsId, ConsDefns0) ->
ConsDefns1 = ConsDefns0
;
ConsDefns1 = []
),
(
remove_new_prefix(SymName, SymNameMinusNew),
- ConsIdMinumNew = cons(SymNameMinusNew, Arity, cons_id_dummy_type_ctor),
- map.search(Ctors, ConsIdMinumNew, ConsDefns2)
+ ConsIdMinusNew = cons(SymNameMinusNew, Arity, cons_id_dummy_type_ctor),
+ search_cons_table(Ctors, ConsIdMinusNew, ConsDefns2)
->
ConsDefns = ConsDefns1 ++ ConsDefns2
;
Index: compiler/type_constraints.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/type_constraints.m,v
retrieving revision 1.19
diff -u -b -r1.19 type_constraints.m
--- compiler/type_constraints.m 5 Jul 2011 03:34:34 -0000 1.19
+++ compiler/type_constraints.m 21 Aug 2011 09:35:57 -0000
@@ -1701,10 +1701,10 @@
% If it is a data constructor, create a disjunction constraint
% with each possible type of the constructor.
Environment = tconstr_environment(_, _, FuncEnv, PredEnv),
- ( map.search(FuncEnv, ConsId, Cons_Defns) ->
+ ( search_cons_table(FuncEnv, ConsId, ConsDefns) ->
list.map_foldl(
functor_unif_constraint(LTVar, ArgTypeVars, GoalInfo),
- Cons_Defns, TypeConstraints, !TCInfo)
+ ConsDefns, TypeConstraints, !TCInfo)
;
TypeConstraints = []
),
Index: compiler/type_util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/type_util.m,v
retrieving revision 1.209
diff -u -b -r1.209 type_util.m
--- compiler/type_util.m 5 Jul 2011 03:34:34 -0000 1.209
+++ compiler/type_util.m 21 Aug 2011 10:00:36 -0000
@@ -1015,11 +1015,8 @@
% XXX We should look it up in a type_ctor-specific table, not a global one.
module_info_get_cons_table(ModuleInfo, Ctors),
- map.lookup(Ctors, ConsId, ConsDefns),
- list.member(ConsDefn, ConsDefns),
-
- ConsDefn = hlds_cons_defn(TypeCtor, _, TypeParams, _, ExistQVars0, _,
- Args, _),
+ search_cons_table_of_type_ctor(Ctors, TypeCtor, ConsId, ConsDefn),
+ ConsDefn = hlds_cons_defn(_, _, TypeParams, _, ExistQVars0, _, Args, _),
% XXX handle ExistQVars
ExistQVars0 = [],
@@ -1038,13 +1035,8 @@
% XXX We should look it up in a type_ctor-specific table, not a global one.
module_info_get_cons_table(ModuleInfo, Ctors),
- % will fail for builtin cons_ids.
- map.search(Ctors, ConsId, ConsDefns),
- MatchingCons =
- (pred(ThisConsDefn::in) is semidet :-
- ThisConsDefn ^ cons_type_ctor = TypeCtor
- ),
- list.filter(MatchingCons, ConsDefns, [ConsDefn]).
+ % Will fail for builtin cons_ids.
+ search_cons_table_of_type_ctor(Ctors, TypeCtor, ConsId, ConsDefn).
get_cons_defn_det(ModuleInfo, TypeCtor, ConsId, ConsDefn) :-
( get_cons_defn(ModuleInfo, TypeCtor, ConsId, ConsDefnPrime) ->
Index: compiler/typecheck.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/typecheck.m,v
retrieving revision 1.460
diff -u -b -r1.460 typecheck.m
--- compiler/typecheck.m 16 Aug 2011 03:26:34 -0000 1.460
+++ compiler/typecheck.m 21 Aug 2011 09:52:00 -0000
@@ -2778,12 +2778,7 @@
IsFieldAccessFunc = yes
),
module_info_get_cons_table(ModuleInfo, Ctors),
- map.lookup(Ctors, ConsId, ConsDefns0),
- list.filter(
- (pred(CtorDefn::in) is semidet :-
- TypeCtor = CtorDefn ^ cons_type_ctor
- ), ConsDefns0, ConsDefns),
- ConsDefns = [ConsDefn],
+ lookup_cons_table_of_type_ctor(Ctors, TypeCtor, ConsId, ConsDefn),
(
AccessType = get,
ConsAction = do_not_flip_constraints
@@ -2792,8 +2787,7 @@
ConsAction = flip_constraints_for_field_set
),
OrigExistTVars = ConsDefn ^ cons_exist_tvars,
- convert_cons_defn(Info, GoalId, ConsAction, ConsDefn,
- FunctorConsTypeInfo).
+ convert_cons_defn(Info, GoalId, ConsAction, ConsDefn, FunctorConsTypeInfo).
:- type maybe_cons_type_info
---> ok(cons_type_info)
@@ -3023,7 +3017,7 @@
typecheck_info_get_ctors(Info, Ctors),
(
Functor = cons(_, _, _),
- map.search(Ctors, Functor, HLDS_ConsDefns)
+ search_cons_table(Ctors, Functor, HLDS_ConsDefns)
->
convert_cons_defn_list(Info, GoalId, do_not_flip_constraints,
HLDS_ConsDefns, PlainMaybeConsInfos)
@@ -3051,7 +3045,7 @@
Functor = cons(Name, Arity, FunctorTypeCtor),
remove_new_prefix(Name, OrigName),
OrigFunctor = cons(OrigName, Arity, FunctorTypeCtor),
- map.search(Ctors, OrigFunctor, HLDS_ExistQConsDefns)
+ search_cons_table(Ctors, OrigFunctor, HLDS_ExistQConsDefns)
->
convert_cons_defn_list(Info, GoalId, flip_constraints_for_new,
HLDS_ExistQConsDefns, UnivQuantifiedMaybeConsInfos)
Index: compiler/typecheck_errors.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/typecheck_errors.m,v
retrieving revision 1.52
diff -u -b -r1.52 typecheck_errors.m
--- compiler/typecheck_errors.m 23 May 2011 05:08:14 -0000 1.52
+++ compiler/typecheck_errors.m 21 Aug 2011 09:56:28 -0000
@@ -1087,15 +1087,11 @@
Functor = cons(Constructor, FunctorArity, _),
expect(unify(Arity, FunctorArity), $module, $pred, "arity mismatch"),
typecheck_info_get_ctors(Info, ConsTable),
- solutions.solutions(
- (pred(N::out) is nondet :-
- map.member(ConsTable, cons(Constructor, N, _), _),
- N \= Arity
- ), ActualArities),
- ActualArities = [_ | _]
+ return_other_arities(ConsTable, Constructor, Arity, OtherArities),
+ OtherArities = [_ | _]
->
FunctorPieces = wrong_arity_constructor_to_pieces(Constructor, Arity,
- ActualArities),
+ OtherArities),
FunctorComps = [always(FunctorPieces)],
ReportConsErrors = yes
;
cvs diff: Diffing compiler/notes
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/base64
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/curs
cvs diff: Diffing extras/curs/samples
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/error
cvs diff: Diffing extras/fixed
cvs diff: Diffing extras/gator
cvs diff: Diffing extras/gator/generations
cvs diff: Diffing extras/gator/generations/1
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/easyx
cvs diff: Diffing extras/graphics/easyx/samples
cvs diff: Diffing extras/graphics/mercury_allegro
cvs diff: Diffing extras/graphics/mercury_allegro/examples
cvs diff: Diffing extras/graphics/mercury_allegro/samples
cvs diff: Diffing extras/graphics/mercury_allegro/samples/demo
cvs diff: Diffing extras/graphics/mercury_allegro/samples/mandel
cvs diff: Diffing extras/graphics/mercury_allegro/samples/pendulum2
cvs diff: Diffing extras/graphics/mercury_allegro/samples/speed
cvs diff: Diffing extras/graphics/mercury_cairo
cvs diff: Diffing extras/graphics/mercury_cairo/samples
cvs diff: Diffing extras/graphics/mercury_cairo/samples/data
cvs diff: Diffing extras/graphics/mercury_cairo/tutorial
cvs diff: Diffing extras/graphics/mercury_glut
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/gears
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/lex/tests
cvs diff: Diffing extras/log4m
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/monte
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/moose/tests
cvs diff: Diffing extras/mopenssl
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/net
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/posix/samples
cvs diff: Diffing extras/quickcheck
cvs diff: Diffing extras/quickcheck/tutes
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/solver_types
cvs diff: Diffing extras/solver_types/library
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/windows_installer_generator
cvs diff: Diffing extras/windows_installer_generator/sample
cvs diff: Diffing extras/windows_installer_generator/sample/images
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing extras/xml_stylesheets
cvs diff: Diffing java
cvs diff: Diffing java/runtime
cvs diff: Diffing library
cvs diff: Diffing mdbcomp
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/appengine
cvs diff: Diffing samples/appengine/war
cvs diff: Diffing samples/appengine/war/WEB-INF
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/standalone_c
cvs diff: Diffing samples/concurrency
cvs diff: Diffing samples/concurrency/dining_philosophers
cvs diff: Diffing samples/concurrency/midimon
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/java_interface
cvs diff: Diffing samples/java_interface/java_calls_mercury
cvs diff: Diffing samples/java_interface/mercury_calls_java
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/solver_types
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing slice
cvs diff: Diffing ssdb
cvs diff: Diffing tests
cvs diff: Diffing tests/analysis
cvs diff: Diffing tests/analysis/ctgc
cvs diff: Diffing tests/analysis/excp
cvs diff: Diffing tests/analysis/ext
cvs diff: Diffing tests/analysis/sharing
cvs diff: Diffing tests/analysis/table
cvs diff: Diffing tests/analysis/trail
cvs diff: Diffing tests/analysis/unused_args
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/general/string_format
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/grade_subdirs
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/mmc_make
cvs diff: Diffing tests/mmc_make/lib
cvs diff: Diffing tests/par_conj
cvs diff: Diffing tests/recompilation
cvs diff: Diffing tests/stm
cvs diff: Diffing tests/stm/orig
cvs diff: Diffing tests/stm/orig/stm-compiler
cvs diff: Diffing tests/stm/orig/stm-compiler/test1
cvs diff: Diffing tests/stm/orig/stm-compiler/test10
cvs diff: Diffing tests/stm/orig/stm-compiler/test2
cvs diff: Diffing tests/stm/orig/stm-compiler/test3
cvs diff: Diffing tests/stm/orig/stm-compiler/test4
cvs diff: Diffing tests/stm/orig/stm-compiler/test5
cvs diff: Diffing tests/stm/orig/stm-compiler/test6
cvs diff: Diffing tests/stm/orig/stm-compiler/test7
cvs diff: Diffing tests/stm/orig/stm-compiler/test8
cvs diff: Diffing tests/stm/orig/stm-compiler/test9
cvs diff: Diffing tests/stm/orig/stm-compiler-par
cvs diff: Diffing tests/stm/orig/stm-compiler-par/bm1
cvs diff: Diffing tests/stm/orig/stm-compiler-par/bm2
cvs diff: Diffing tests/stm/orig/stm-compiler-par/stmqueue
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test1
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test10
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test11
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test2
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test3
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test4
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test5
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test6
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test7
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test8
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test9
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test1
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test2
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test3
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test4
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test5
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test6
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test7
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test8
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test9
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/trailing
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
cvs diff: Diffing util
cvs diff: Diffing vim
cvs diff: Diffing vim/after
cvs diff: Diffing vim/ftplugin
cvs diff: Diffing vim/syntax
--------------------------------------------------------------------------
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