[m-rev.] diff: Move pointer_equals/2 into the private_builtin module.

Paul Bone paul at bone.id.au
Fri Oct 18 11:46:24 AEDT 2013


Branches: release, master

This patch was reviewed some time ago.

Move pointer_equals/2 into the private_builtin module.

library/version_hash_table.m:
library/private_builtin.m:
    Move pointer_equals/2 as above.

    Rename pointer_equals to pointer_equal.

library/private_builtin.m:
    Adjust a comment to say that this module also contains predicates with
    normal definitions.  That is, they're built into the language but not
    built into the compiler.
---
 library/private_builtin.m    | 41 +++++++++++++++++++++++++++++++++++++++--
 library/version_hash_table.m | 32 ++------------------------------
 2 files changed, 41 insertions(+), 32 deletions(-)

diff --git a/library/private_builtin.m b/library/private_builtin.m
index 1dd866d..58532c5 100644
--- a/library/private_builtin.m
+++ b/library/private_builtin.m
@@ -23,8 +23,9 @@
 % does not get included in the Mercury library reference manual.
 % 
 % Many of the predicates defined in this module are builtin - they do not have
-% definitions because the compiler generates code for them inline. Some others
-% are implemented in the runtime.
+% definitions because the compiler generates code for them inline. A second
+% group are implemented in the runtime.  Whilst a third group are
+% implemented normally in this module.
 % 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
@@ -118,6 +119,12 @@
     %
 :- pred typed_compare(comparison_result::uo, T1::in, T2::in) is det.
 
+    % True iff the two terms occupy the same address in memory.  This is
+    % useful as a cheap but incomplete test of equality when implmenting
+    % user-defined equality.
+    %
+:- pred pointer_equal(T::in, T::in) is semidet.
+
     % N.B. interface continued below.
 
 %-----------------------------------------------------------------------------%
@@ -337,6 +344,36 @@ typed_compare(R, X, Y) :-
     ).
 
 %-----------------------------------------------------------------------------%
+
+:- pragma inline(pointer_equal/2).
+
+:- pragma foreign_proc("C", pointer_equal(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_equal(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_equal(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_equal(_A, _B) :- semidet_false.
+
+%-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
 :- interface.
diff --git a/library/version_hash_table.m b/library/version_hash_table.m
index 6b7b3aa..5e061b6 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_builtin.
 :- import_module require.
 :- import_module string.
 :- import_module type_desc.
@@ -858,7 +859,7 @@ fold_p(P, List, !A) :-
 %-----------------------------------------------------------------------------%
 
 equals(A, B) :-
-    ( pointer_equals(A, B) ->
+    ( pointer_equal(A, B) ->
         true
     ;
         % We cannot deconstruct a non-cononical type in this all-solutions
@@ -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.
 %-----------------------------------------------------------------------------%
-- 
1.8.4.rc3




More information about the reviews mailing list