[m-rev.] for review: fix tabling for foreign enumerations
Julien Fischer
juliensf at csse.unimelb.edu.au
Mon Feb 18 11:32:04 AEDT 2008
Zoltan, can you please take a look at this; I would like to commit it.
On Wed, 30 Jan 2008, Julien Fischer wrote:
>
> For review by Zoltan.
>
> Estimated hours taken: 2
> Branches: main
>
> Fix tabling of foreign enumerations. There are two problems: (1) the
> original runtime support for tabling foreign enumerations was wrong since it
> treated them like ordinary enumerations and (2) the runtime had got out of
> sync with the source-to-source transformation in the compiler which was
> generating code that hashed foreign enumeration values.
>
> This diff replaces the original runtime support for tabling foreign
> enumerations and separates the handling of foreign enumeration values
> from that of int values.
>
> compiler/table_gen.m:
> Call the new runtime infrastructure when tabling foreign
> enumerations.
>
> compiler/hlds_pred.m:
> Extend the type table_trie_step/0 to handle foreign enumerations.
>
> Re-order the type table_trie_step/0 so that it matches the ordering
> of table_statistics.table_step_kind/0 and MR_TableTrieStep in
> runtime/mercury_tabling.h.
>
> XXX Why does the comment above this type say that it doesn't have
> to handle dummy steps and yet the type contains a
> able_trie_step_dummy
> alternative?
>
> compiler/rtti.m:
> compiler/hlds_out.m:
> Conform to the above change.
>
> library/table_builtin.m:
> Add a new service predicate for doing table lookups or insertions
> of foreign enumeration values.
>
> library/table_statistics.m:
> Extend the type table_step_kind/0 to cover foreign enumerations.
>
> runtime/mercury_table_type_body.h:
> When doing an RTTI lookup on how to table a foreign enumeration
> value,
> don't treat it as an ordinary enumeration value.
>
> runtime/mercury_tabling.h:
> Extend MR_TableTrieStep to cover foreign enumerations.
>
> Update a reference: s/table_builtin.m/table_statistics.m.
>
> runtime/mercury_tabling_macros.h:
> runtime/mercury_tabling_pred.h:
> Define macros for tabling foreign enumeration values.
>
> tests/tabling/Mmakefile:
> Enable the foreign enumeration tabling test case.
>
> tests/tabling/.cvsignore:
> Ignore some generated files.
>
> Julien.
>
> Index: compiler/hlds_out.m
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/compiler/hlds_out.m,v
> retrieving revision 1.442
> diff -u -r1.442 hlds_out.m
> --- compiler/hlds_out.m 22 Jan 2008 15:06:10 -0000 1.442
> +++ compiler/hlds_out.m 30 Jan 2008 06:50:48 -0000
> @@ -4171,6 +4171,7 @@
> table_trie_step_desc(_, table_trie_step_dummy) = "dummy".
> table_trie_step_desc(_, table_trie_step_enum(N)) =
> "enum(" ++ int_to_string(N) ++ ")".
> +table_trie_step_desc(_, table_trie_step_foreign_enum) = "foreign_enum".
> table_trie_step_desc(TVarSet, table_trie_step_general(Type, IsPoly, IsAddr))
> =
> Str :-
> (
> Index: compiler/hlds_pred.m
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/compiler/hlds_pred.m,v
> retrieving revision 1.236
> diff -u -r1.236 hlds_pred.m
> --- compiler/hlds_pred.m 10 Jan 2008 04:29:52 -0000 1.236
> +++ compiler/hlds_pred.m 30 Jan 2008 06:50:48 -0000
> @@ -1735,17 +1735,19 @@
> % argument (if this info is needed and available),
> % (b) it doesn't have to be an enum, and
> % (c) it doesn't have to handle dummy steps.
> + %
> :- type table_trie_step
> - ---> table_trie_step_int
> + ---> table_trie_step_dummy
> + ; table_trie_step_int
> ; table_trie_step_char
> ; table_trie_step_string
> ; table_trie_step_float
> - ; table_trie_step_dummy
> ; table_trie_step_enum(
> % The int gives the number of alternatives in the enum type,
> % and thus the size of the corresponding trie node.
> int
> )
> + ; table_trie_step_foreign_enum
> ; table_trie_step_general(
> mer_type,
> table_is_poly,
> @@ -2366,6 +2368,7 @@
> ; Step = table_trie_step_float
> ; Step = table_trie_step_typeinfo
> ; Step = table_trie_step_typeclassinfo
> + ; Step = table_trie_step_foreign_enum
> ),
> KindStr = "MR_TABLE_STATS_DETAIL_HASH"
> ;
> Index: compiler/rtti.m
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/compiler/rtti.m,v
> retrieving revision 1.88
> diff -u -r1.88 rtti.m
> --- compiler/rtti.m 31 Dec 2007 10:03:52 -0000 1.88
> +++ compiler/rtti.m 30 Jan 2008 06:50:48 -0000
> @@ -2170,6 +2170,8 @@
> table_trie_step_to_c(table_trie_step_float, "MR_TABLE_STEP_FLOAT", no).
> table_trie_step_to_c(table_trie_step_enum(EnumRange), "MR_TABLE_STEP_ENUM",
> yes(EnumRange)).
> +table_trie_step_to_c(table_trie_step_foreign_enum,
> + "MR_TABLE_STEP_FOREIGN_ENUM", no).
> table_trie_step_to_c(table_trie_step_general(_, table_is_mono, table_value),
> "MR_TABLE_STEP_GEN", no).
> table_trie_step_to_c(table_trie_step_general(_, table_is_poly, table_value),
> Index: compiler/table_gen.m
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/compiler/table_gen.m,v
> retrieving revision 1.144
> diff -u -r1.144 table_gen.m
> --- compiler/table_gen.m 31 Dec 2007 10:03:53 -0000 1.144
> +++ compiler/table_gen.m 30 Jan 2008 06:50:48 -0000
> @@ -2428,10 +2428,10 @@
> % Mercury doesn't know the specific values of the foreign
> % enums, so we cannot use an array as a trie (since we don't
> % know how big the array would have to be). However, hashing
> - % the enum as an int will work.
> + % the foreign enum will work.
> TypeCat = type_cat_foreign_enum,
> - CatString = "int",
> - Step = table_trie_step_int
> + CatString = "foreign_enum",
> + Step = table_trie_step_foreign_enum
> ;
> TypeCat = type_cat_int,
> CatString = "int",
> Index: library/table_builtin.m
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/library/table_builtin.m,v
> retrieving revision 1.63
> diff -u -r1.63 table_builtin.m
> --- library/table_builtin.m 31 Dec 2007 10:04:01 -0000 1.63
> +++ library/table_builtin.m 30 Jan 2008 06:50:48 -0000
> @@ -1268,6 +1268,11 @@
> :- impure pred table_lookup_insert_enum(ml_trie_node::in, int::in, T::in,
> ml_trie_node::out) is det.
>
> + % Lookup or insert a foreign enumeration type in the given trie.
> + %
> +:- impure pred table_lookup_insert_foreign_enum(ml_trie_node::in, T::in,
> + ml_trie_node::out) is det.
> +
> % Lookup or insert a monomorphic general type in the given trie.
> %
> :- impure pred table_lookup_insert_gen(ml_trie_node::in, T::in,
> @@ -1446,6 +1451,14 @@
> ").
>
> :- pragma foreign_proc("C",
> + table_lookup_insert_foreign_enum(T0::in, V::in, T::out),
> + [will_not_call_mercury, does_not_affect_liveness],
> +"
> + MR_tbl_lookup_insert_foreign_enum(NULL, MR_TABLE_DEBUG_BOOL, MR_FALSE,
> T0,
> + V, T);
> +").
> +
> +:- pragma foreign_proc("C",
> table_lookup_insert_gen(T0::in, V::in, T::out),
> [will_not_call_mercury, does_not_affect_liveness],
> "
> Index: library/table_statistics.m
> ===================================================================
> RCS file:
> /home/mercury/mercury1/repository/mercury/library/table_statistics.m,v
> retrieving revision 1.1
> diff -u -r1.1 table_statistics.m
> --- library/table_statistics.m 31 Dec 2007 10:04:01 -0000 1.1
> +++ library/table_statistics.m 30 Jan 2008 06:50:48 -0000
> @@ -48,6 +48,7 @@
> % The definition of this type be an enum whose implementation matches
> % the type MR_TableTrieStep in runtime/mercury_tabling.h. It should also
> % be kept in sync with the type table_trie_step in hlds_pred.m.
> + %
> :- type table_step_kind
> ---> table_step_dummy
> ; table_step_int
> @@ -55,6 +56,7 @@
> ; table_step_string
> ; table_step_float
> ; table_step_enum
> + ; table_step_foreign_enum
> ; table_step_general
> ; table_step_general_addr
> ; table_step_general_poly
> Index: runtime/mercury_table_type_body.h
> ===================================================================
> RCS file:
> /home/mercury/mercury1/repository/mercury/runtime/mercury_table_type_body.h,v
> retrieving revision 1.7
> diff -u -r1.7 mercury_table_type_body.h
> --- runtime/mercury_table_type_body.h 31 Dec 2007 10:04:02 -0000 1.7
> +++ runtime/mercury_table_type_body.h 30 Jan 2008 06:50:48 -0000
> @@ -33,13 +33,18 @@
> switch (MR_type_ctor_rep(type_ctor_info)) {
> case MR_TYPECTOR_REP_ENUM:
> case MR_TYPECTOR_REP_ENUM_USEREQ:
> - case MR_TYPECTOR_REP_FOREIGN_ENUM:
> - case MR_TYPECTOR_REP_FOREIGN_ENUM_USEREQ:
> MR_TABLE_ENUM(STATS, DEBUG, BACK, table_next, table,
> MR_type_ctor_num_functors(type_ctor_info), data);
> table = table_next;
> return table;
>
> + case MR_TYPECTOR_REP_FOREIGN_ENUM:
> + case MR_TYPECTOR_REP_FOREIGN_ENUM_USEREQ:
> + MR_TABLE_FOREIGN_ENUM(STATS, DEBUG, BACK, table_next, table,
> + data);
> + table = table_next;
> + return table;
> +
> case MR_TYPECTOR_REP_DUMMY:
> /*
> ** If we are ever asked to table a value of a dummy type, we
> treat
> Index: runtime/mercury_tabling.h
> ===================================================================
> RCS file:
> /home/mercury/mercury1/repository/mercury/runtime/mercury_tabling.h,v
> retrieving revision 1.45
> diff -u -r1.45 mercury_tabling.h
> --- runtime/mercury_tabling.h 31 Dec 2007 10:04:03 -0000 1.45
> +++ runtime/mercury_tabling.h 30 Jan 2008 06:50:48 -0000
> @@ -240,7 +240,7 @@
>
> /*
> ** The definition of this type should correspond to the type table_step_kind
> -** in library/table_builtin.m.
> +** in library/table_statistics.m.
> */
>
> typedef enum {
> @@ -250,6 +250,7 @@
> MR_DEFINE_BUILTIN_ENUM_CONST(MR_TABLE_STEP_STRING),
> MR_DEFINE_BUILTIN_ENUM_CONST(MR_TABLE_STEP_FLOAT),
> MR_DEFINE_BUILTIN_ENUM_CONST(MR_TABLE_STEP_ENUM),
> + MR_DEFINE_BUILTIN_ENUM_CONST(MR_TABLE_STEP_FOREIGN_ENUM),
> MR_DEFINE_BUILTIN_ENUM_CONST(MR_TABLE_STEP_GEN),
> MR_DEFINE_BUILTIN_ENUM_CONST(MR_TABLE_STEP_GEN_ADDR),
> MR_DEFINE_BUILTIN_ENUM_CONST(MR_TABLE_STEP_GEN_POLY),
> Index: runtime/mercury_tabling_macros.h
> ===================================================================
> RCS file:
> /home/mercury/mercury1/repository/mercury/runtime/mercury_tabling_macros.h,v
> retrieving revision 1.17
> diff -u -r1.17 mercury_tabling_macros.h
> --- runtime/mercury_tabling_macros.h 31 Dec 2007 10:04:03 -0000 1.17
> +++ runtime/mercury_tabling_macros.h 30 Jan 2008 06:50:48 -0000
> @@ -40,10 +40,16 @@
> #define MR_RAW_TABLE_ENUM(table, range, value)
> \
> MR_int_fix_index_enum_lookup_or_add((table), (range), (value))
>
> +#define MR_RAW_TABLE_FOREIGN_ENUM(table, value)
> \
> + MR_int_hash_lookup_or_add((table), (value));
> +
> #define MR_RAW_TABLE_ENUM_STATS(stats, table, range, value)
> \
> MR_int_fix_index_enum_lookup_or_add_stats((stats), (table),
> \
> (range), (value))
>
> +#define MR_RAW_TABLE_FOREIGN_ENUM_STATS(stats, table, value)
> \
> + MR_int_hash_lookup_or_add_stats((stats), (table), (value))
> +
> #define MR_RAW_TABLE_DU(table, range, value)
> \
> MR_int_fix_index_du_lookup_or_add((table), (range), (value))
>
> @@ -149,6 +155,19 @@
> }
> \
> } while (0)
>
> +#define MR_TABLE_FOREIGN_ENUM(stats, debug, back, t, t0, value)
> \
> + do {
> \
> + if (stats != NULL) {
> \
> + (t) = MR_RAW_TABLE_FOREIGN_ENUM_STATS((stats), (t0), (value));
> \
> + } else {
> \
> + (t) = MR_RAW_TABLE_FOREIGN_ENUM((t0), (value));
> \
> + }
> \
> + if (debug && MR_tabledebug) {
> \
> + printf("TABLE %p: foreign enum %ld => %p\n",
> \
> + (t0), (long) (value), (t));
> \
> + }
> \
> + } while (0)
> +
> #define MR_TABLE_DU(stats, debug, back, t, t0, count, value)
> \
> do {
> \
> if (stats != NULL) {
> \
> Index: runtime/mercury_tabling_preds.h
> ===================================================================
> RCS file:
> /home/mercury/mercury1/repository/mercury/runtime/mercury_tabling_preds.h,v
> retrieving revision 1.13
> diff -u -r1.13 mercury_tabling_preds.h
> --- runtime/mercury_tabling_preds.h 15 Aug 2007 01:35:02 -0000 1.13
> +++ runtime/mercury_tabling_preds.h 30 Jan 2008 06:50:48 -0000
> @@ -32,6 +32,8 @@
> MR_tbl_lookup_insert_float(NULL, MR_FALSE, MR_FALSE, a, b, c)
> #define MR_table_lookup_insert_enum(a, b, c, d)
> \
> MR_tbl_lookup_insert_enum(NULL, MR_FALSE, MR_FALSE, a, b, c, d)
> +#define MR_table_lookup_insert_foreign_enum(a, b, c)
> \
> + MR_tbl_lookup_insert_foreign_enum(NULL, MR_FALSE, MR_FALSE, a, b, c)
> #define MR_table_lookup_insert_gen(a, b, c, d)
> \
> MR_tbl_lookup_insert_gen(NULL, MR_FALSE, MR_FALSE, a, b, c, d)
> #define MR_table_lookup_insert_gen_addr(a, b, c, d)
> \
> @@ -176,6 +178,11 @@
> MR_TABLE_ENUM(stats, debug, back, T, T0, R, V);
> \
> } while(0)
>
> +#define MR_tbl_lookup_insert_foreign_enum(stats, debug, back, T0, V, T)
> \
> + do {
> \
> + MR_TABLE_FOREIGN_ENUM(stats, debug, back, T, T0, V);
> \
> + } while(0)
> +
> #define MR_tbl_lookup_insert_gen(stats, debug, back, T0, TI, V, T)
> \
> do {
> \
> MR_TABLE_ANY(stats, debug, back, "gen", T, T0,
> \
> Index: tests/tabling/.cvsignore
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/tests/tabling/.cvsignore,v
> retrieving revision 1.4
> diff -u -r1.4 .cvsignore
> --- tests/tabling/.cvsignore 25 Jul 2007 06:40:21 -0000 1.4
> +++ tests/tabling/.cvsignore 30 Jan 2008 06:50:48 -0000
> @@ -1,8 +1,13 @@
> *.d
> +*.dep
> +*.dv
> *.mh
> +*.c
> *.c_date
> *.out
> *.res
> +*.res1
> CLEAN
> .mgnuc_copts
> .mgnuc_opts
> +table_foreign_enum
> Index: tests/tabling/Mmakefile
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/tests/tabling/Mmakefile,v
> retrieving revision 1.51
> diff -u -r1.51 Mmakefile
> --- tests/tabling/Mmakefile 31 Dec 2007 10:04:04 -0000 1.51
> +++ tests/tabling/Mmakefile 30 Jan 2008 06:50:48 -0000
> @@ -25,14 +25,10 @@
> oota \
> specified_hidden_arg \
> table_foreign_output \
> + table_foreign_enum \
> test_enum \
> unused_args
>
> -# The following test is currently disabled because tabling and -# foreign
> enumerations are not yet supported.
> -#
> -# table_foreign_enum -
> # Tabling of nondet predicates and deep profiling are (currently)
> # incompatible.
> ifeq "$(findstring profdeep,$(GRADE))" ""
>
> --------------------------------------------------------------------------
> 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
> --------------------------------------------------------------------------
>
--------------------------------------------------------------------------
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