[m-rev.] for review 1/3: Move pointer/equals to new private shared library module.

Paul Bone paul at bone.id.au
Fri Jun 28 16:26:34 AEST 2013


For review by Julien.

Move pointer/equals to new private shared library module.

This will allow other library code to use this predicate.

library/private.m:
library/version_hash_table.m:
    As above.

    I've created the new module private.m for any code that is shared amoung
    library modules but is intended for Mercury implementors.  Unlike
    private_builtin.m the predicates in private.m are not builtin.

doc/Mmakefile:
library/library.m:
mdbcomp/prim_data.m:
    Include the new library module and prevent its documentation from being
    added to the library reference manual.
---
 doc/Mmakefile                |  4 +++
 library/library.m            |  2 ++
 library/private.m            | 68 ++++++++++++++++++++++++++++++++++++++++++++
 library/version_hash_table.m | 30 +------------------
 mdbcomp/prim_data.m          |  8 ++++++
 5 files changed, 83 insertions(+), 29 deletions(-)
 create mode 100644 library/private.m

diff --git a/doc/Mmakefile b/doc/Mmakefile
index f8002c1..7b33e2c 100644
--- a/doc/Mmakefile
+++ b/doc/Mmakefile
@@ -256,6 +256,8 @@ library-menu.texi_pp: ../VERSION $(LIBRARY_DIR)/*.m
 				;;					\
 			$(LIBRARY_DIR)/par_builtin.m)			\
 				;;					\
+			$(LIBRARY_DIR)/private.m)		        \
+				;;					\
 			$(LIBRARY_DIR)/private_builtin.m)		\
 				;;					\
 			$(LIBRARY_DIR)/profiling_builtin.m)		\
@@ -296,6 +298,8 @@ library-chapters.texi_pp: ../VERSION $(LIBRARY_DIR)/[a-z]*.m
 				;;					\
 			$(LIBRARY_DIR)/par_builtin.m)			\
 				;;					\
+			$(LIBRARY_DIR)/private.m)		        \
+				;;					\
 			$(LIBRARY_DIR)/private_builtin.m)		\
 				;;					\
 			$(LIBRARY_DIR)/profiling_builtin.m)		\
diff --git a/library/library.m b/library/library.m
index 64dee72..558e112 100644
--- a/library/library.m
+++ b/library/library.m
@@ -143,6 +143,7 @@
 :- import_module erlang_rtti_implementation.
 :- import_module mutvar.
 :- import_module par_builtin.
+:- import_module private.
 :- import_module private_builtin.
 :- import_module profiling_builtin.
 :- import_module region_builtin.
@@ -259,6 +260,7 @@ mercury_std_library_module("parsing_utils").
 mercury_std_library_module("pprint").
 mercury_std_library_module("pqueue").
 mercury_std_library_module("pretty_printer").
+mercury_std_library_module("private").
 mercury_std_library_module("private_builtin").
 mercury_std_library_module("profiling_builtin").
 mercury_std_library_module("prolog").
diff --git a/library/private.m b/library/private.m
new file mode 100644
index 0000000..abf933b
--- /dev/null
+++ b/library/private.m
@@ -0,0 +1,68 @@
+%---------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%---------------------------------------------------------------------------%
+% Copyright (C) 2013 The University of Melbourne.
+% This file may only be copied under the terms of the GNU Library General
+% Public License - see the file COPYING.LIB in the Mercury distribution.
+%---------------------------------------------------------------------------%
+% 
+% File: private.m.
+% Author: pbone
+%
+% This file contains private definitions intended for the internal use of
+% the Mercury standard library.  Unlike private_builtin.m it is not
+% automatically imported during compilation.  The interface for this module
+% does not get included in the Mercury library reference manual.
+%
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- module private.
+
+%-----------------------------------------------------------------------------%
+
+:- interface.
+
+    % True if the two parameters are pointer-equal according to whichever
+    % backend is being used.
+    %
+    % This provides a cheap equality test that can be used to short-circut
+    % other equality tests.
+    % 
+:- pred pointer_equals(T::in, T::in) is semidet.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- implementation.
+
+:- pragma inline(pointer_equals/2).
+
+:- pragma foreign_proc("C", pointer_equals(A::in, B::in),
+    [promise_pure, thread_safe, will_not_call_mercury,
+        will_not_throw_exception, terminates],
+"
+    SUCCESS_INDICATOR = (A == B);
+").
+
+:- pragma foreign_proc("Java", pointer_equals(A::in, B::in),
+    [promise_pure, thread_safe, will_not_call_mercury,
+        will_not_throw_exception, terminates],
+"
+    SUCCESS_INDICATOR = (A == B);
+").
+
+:- pragma foreign_proc("C#", pointer_equals(A::in, B::in),
+    [promise_pure, thread_safe, will_not_call_mercury,
+        will_not_throw_exception, terminates],
+"
+    SUCCESS_INDICATOR = System.Object.ReferenceEquals(A, B);
+").
+
+% Conservative default if a backend does not have pointer equality, such as
+% Erlang.  (Erlang does have erts_debug:same/1 but I don't know if we can
+% rely on that.)
+pointer_equals(_A, _B) :- semidet_false.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
diff --git a/library/version_hash_table.m b/library/version_hash_table.m
index b2765c2..c75cda2 100644
--- a/library/version_hash_table.m
+++ b/library/version_hash_table.m
@@ -234,6 +234,7 @@
 :- import_module int.
 :- import_module list.
 :- import_module pair.
+:- import_module private.
 :- import_module require.
 :- import_module string.
 :- import_module type_desc.
@@ -879,35 +880,6 @@ equals(A, B) :-
 compare_item(Table, K, V, unit, unit) :-
     search(Table, K, V).
 
-:- pred pointer_equals(T::in, T::in) is semidet.
-:- pragma inline(pointer_equals/2).
-
-:- pragma foreign_proc("C", pointer_equals(A::in, B::in),
-    [promise_pure, thread_safe, will_not_call_mercury,
-        will_not_throw_exception, terminates],
-"
-    SUCCESS_INDICATOR = (A == B);
-").
-
-:- pragma foreign_proc("Java", pointer_equals(A::in, B::in),
-    [promise_pure, thread_safe, will_not_call_mercury,
-        will_not_throw_exception, terminates],
-"
-    SUCCESS_INDICATOR = (A == B);
-").
-
-:- pragma foreign_proc("C#", pointer_equals(A::in, B::in),
-    [promise_pure, thread_safe, will_not_call_mercury,
-        will_not_throw_exception, terminates],
-"
-    SUCCESS_INDICATOR = System.Object.ReferenceEquals(A, B);
-").
-
-% Conservative default if a backend does not have pointer equality, such as
-% Erlang.  (Erlang does have erts_debug:same/1 but I don't know if we can
-% rely on that.)
-pointer_equals(_A, _B) :- semidet_false.
-
 %-----------------------------------------------------------------------------%
 :- end_module version_hash_table.
 %-----------------------------------------------------------------------------%
diff --git a/mdbcomp/prim_data.m b/mdbcomp/prim_data.m
index 9e18651..fa7b3a1 100644
--- a/mdbcomp/prim_data.m
+++ b/mdbcomp/prim_data.m
@@ -293,6 +293,12 @@
     %
 :- func mercury_private_builtin_module = sym_name.
 
+    % Returns the name of the module containing private definitions which
+    % are not builtin.  Unlike mercury_private_builtin_module above this
+    % module is not automatically imported.
+    %
+:- func mercury_private_module = sym_name.
+
     % Returns the name of the module containing builtins for region-based
     % memory management.  This module is automatically imported iff
     % RBMM is enabled.
@@ -568,6 +574,7 @@ get_special_pred_id_arity(Id) = Arity :-
 all_builtin_modules = [
     mercury_public_builtin_module,
     mercury_private_builtin_module,
+    mercury_private_module,
     mercury_region_builtin_module,
     mercury_stm_builtin_module,
     mercury_table_builtin_module,
@@ -585,6 +592,7 @@ all_builtin_modules = [
 %       qualified(unqualified("std"), "private_builtin"))).
 mercury_public_builtin_module = unqualified("builtin").
 mercury_private_builtin_module = unqualified("private_builtin").
+mercury_private_module = unqualified("private").
 mercury_region_builtin_module = unqualified("region_builtin").
 mercury_stm_builtin_module = unqualified("stm_builtin").
 % Exception is a non-builtin module needed by the STM system.
-- 
1.8.1.3




More information about the reviews mailing list