[m-rev.] for review: TYPE_CTOR_REP_REFERENCE
Fergus Henderson
fjh at cs.mu.OZ.AU
Mon Feb 10 07:31:44 AEDT 2003
Zoltan, what is the semantics of the first argument to return_unify_answer()?
(See the XXX at the end of this diff. Did I get it right?)
Estimated hours taken: 4
Branches: main
Implement deep_copy for reference types.
This is needed for accurate GC.
library/private_builtin.m:
compiler/mlds_to_gcc.m:
runtime/mercury_builtin_types.h:
runtime/mercury_construct.c:
runtime/mercury_hlc_types.h:
runtime/mercury_mcpp.h:
runtime/mercury_ml_expand_body.h:
runtime/mercury_tabling.h:
runtime/mercury_type_info.h:
runtime/mercury_unify_compare_body.h:
Add a new built-in type `private_builtin.ref(T)' and a
corresponding new type_ctor_rep `TYPE_CTOR_REP_REFERENCE'.
library/std_util.m:
library/store.m:
library/benchmarking.m:
Use private_builtin.ref/1 instead of c_pointer.
Workspace: /home/ceres/fjh/mercury
Index: compiler/mlds_to_gcc.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_gcc.m,v
retrieving revision 1.78
diff -u -d -r1.78 mlds_to_gcc.m
--- compiler/mlds_to_gcc.m 28 Jan 2003 14:38:32 -0000 1.78
+++ compiler/mlds_to_gcc.m 9 Feb 2003 09:35:49 -0000
@@ -2261,7 +2261,8 @@
rtti_enum_const("MR_TYPECTOR_REP_TYPEDESC", 35).
rtti_enum_const("MR_TYPECTOR_REP_TYPECTORDESC", 36).
rtti_enum_const("MR_TYPECTOR_REP_FOREIGN", 37).
-rtti_enum_const("MR_TYPECTOR_REP_UNKNOWN", 38).
+rtti_enum_const("MR_TYPECTOR_REP_REFERENCE", 38).
+rtti_enum_const("MR_TYPECTOR_REP_UNKNOWN", 39).
rtti_enum_const("MR_SECTAG_NONE", 0).
rtti_enum_const("MR_SECTAG_LOCAL", 1).
rtti_enum_const("MR_SECTAG_REMOTE", 2).
Index: library/benchmarking.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/benchmarking.m,v
retrieving revision 1.52
diff -u -d -r1.52 benchmarking.m
--- library/benchmarking.m 26 Sep 2002 06:18:55 -0000 1.52
+++ library/benchmarking.m 9 Feb 2003 09:01:20 -0000
@@ -762,7 +762,8 @@
% Impure integer references.
% This type is implemented in C.
-:- type int_reference ---> int_reference(c_pointer).
+% It is represented as a pointer to a single word on the heap.
+:- type int_reference ---> int_reference(private_builtin__ref(int)).
% Create a new int_reference given a term for it to reference.
:- impure pred new_int_reference(int::in, int_reference::out) is det.
Index: library/private_builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/private_builtin.m,v
retrieving revision 1.110
diff -u -d -r1.110 private_builtin.m
--- library/private_builtin.m 26 Nov 2002 14:03:47 -0000 1.110
+++ library/private_builtin.m 9 Feb 2003 09:15:31 -0000
@@ -452,7 +452,8 @@
static int MR_TYPECTOR_REP_TYPEDESC =35;
static int MR_TYPECTOR_REP_TYPECTORDESC =36;
static int MR_TYPECTOR_REP_FOREIGN =37;
-static int MR_TYPECTOR_REP_UNKNOWN =38;
+static int MR_TYPECTOR_REP_REFERENCE =38;
+static int MR_TYPECTOR_REP_UNKNOWN =39;
static int MR_SECTAG_NONE = 0;
static int MR_SECTAG_LOCAL = 1;
@@ -918,8 +919,8 @@
%-----------------------------------------------------------------------------%
- % This section of the module contains predicates that are used
- % internally by the compiler for manipulating the heap.
+ % This section of the module contains predicates and types that are
+ % used internally by the compiler for manipulating the heap.
% These predicates should not be used by user programs directly.
:- interface.
@@ -972,6 +973,12 @@
% which will call error/1 with an appropriate message.
:- pred reclaim_heap_nondet_pragma_foreign_code is erroneous.
+ % The following is a built-in reference type.
+ % It is used to define the types store.generic_ref/2,
+ % store.generic_mutvar/2, std_util.mutvar/1,
+ % benchmarking.int_ref/0, etc.
+:- type ref(T).
+
% N.B. interface continued below.
:- implementation.
@@ -1073,8 +1080,8 @@
%-----------------------------------------------------------------------------%
-% Code to define the `heap_pointer' type for the .NET back-end.
-% (For the C back-ends, it is defined in runtime/mercury_builtin_types.[ch].)
+% Code to define the `heap_pointer' and `ref' types for the .NET back-end.
+% (For the C back-ends, they're defined in runtime/mercury_builtin_types.[ch].)
:- pragma foreign_code("MC++", "
@@ -1111,7 +1118,37 @@
{
mercury::runtime::Errors::fatal_error(
""called compare/3 for type `private_builtin:heap_pointer'"");
- return;
+}
+
+MR_DEFINE_BUILTIN_TYPE_CTOR_INFO(private_builtin, ref, 1,
+ MR_TYPECTOR_REP_REFERENCE)
+
+static int
+__Unify__private_builtin__ref_1_0(MR_Word x, MR_Word y)
+{
+ return x == y;
+}
+
+static int
+do_unify__ref_1_0(MR_Box x, MR_Box y)
+{
+ return x == y;
+}
+
+static void
+__Compare__private_builtin__ref_1_0(
+ MR_Word_Ref result, MR_Word x, MR_Word y)
+{
+ mercury::runtime::Errors::fatal_error(
+ ""called compare/3 for type `private_builtin.ref'"");
+}
+
+static void
+do_compare__ref_1_0(
+ MR_Word_Ref result, MR_Box x, MR_Box y)
+{
+ mercury::runtime::Errors::fatal_error(
+ ""called compare/3 for type `private_builtin.ref'"");
}
").
Index: library/std_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/std_util.m,v
retrieving revision 1.279
diff -u -d -r1.279 std_util.m
--- library/std_util.m 20 Jan 2003 16:34:27 -0000 1.279
+++ library/std_util.m 9 Feb 2003 09:13:39 -0000
@@ -1300,8 +1300,8 @@
%%% :- implementation.
-% This type is implemented in C.
-:- type mutvar(T) ---> mutvar(c_pointer).
+% This type is a builtin-in type whose operations are implemented in C.
+:- type mutvar(T) ---> mutvar(private_builtin.ref(T)).
:- pragma inline(new_mutvar/2).
Index: library/store.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/store.m,v
retrieving revision 1.35
diff -u -d -r1.35 store.m
--- library/store.m 29 Jan 2003 03:13:45 -0000 1.35
+++ library/store.m 9 Feb 2003 09:02:10 -0000
@@ -243,11 +243,17 @@
:- type some_store_type ---> some_store_type.
+% The store type itself is just a dummy type,
+% with no real representation.
+
:- type store(S) ---> store(c_pointer).
-:- type generic_mutvar(T, S) ---> mutvar(c_pointer).
+% Mutvars and references are each represented as a pointer to a single word
+% on the heap.
-:- type generic_ref(T, S) ---> ref(c_pointer).
+:- type generic_mutvar(T, S) ---> mutvar(private_builtin.ref(T)).
+
+:- type generic_ref(T, S) ---> ref(private_builtin.ref(T)).
store__new(S) :-
store__do_init(S).
Index: runtime/mercury_builtin_types.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_builtin_types.h,v
retrieving revision 1.2
diff -u -d -r1.2 mercury_builtin_types.h
--- runtime/mercury_builtin_types.h 12 Sep 2002 10:00:54 -0000 1.2
+++ runtime/mercury_builtin_types.h 9 Feb 2003 09:32:27 -0000
@@ -45,6 +45,8 @@
MR_DECLARE_TYPE_CTOR_INFO_STRUCT(
MR_TYPE_CTOR_INFO_NAME(private_builtin, heap_pointer, 0));
MR_DECLARE_TYPE_CTOR_INFO_STRUCT(
+ MR_TYPE_CTOR_INFO_NAME(private_builtin, ref, 1));
+MR_DECLARE_TYPE_CTOR_INFO_STRUCT(
MR_TYPE_CTOR_INFO_NAME(private_builtin, type_ctor_info, 1));
MR_DECLARE_TYPE_CTOR_INFO_STRUCT(
MR_TYPE_CTOR_INFO_NAME(private_builtin, type_info, 1));
@@ -77,6 +79,8 @@
MR_C_Pointer x, MR_C_Pointer y);
MR_bool MR_CALL mercury__private_builtin____Unify____heap_pointer_0_0(
MR_Heap_Pointer x, MR_Heap_Pointer y);
+MR_bool MR_CALL mercury__private_builtin____Unify____ref_1_0(
+ MR_Reference x, MR_Reference y);
MR_bool MR_CALL mercury__builtin____Unify____func_0_0(MR_Func x, MR_Func y);
MR_bool MR_CALL mercury__builtin____Unify____pred_0_0(MR_Pred x, MR_Pred y);
MR_bool MR_CALL mercury__builtin____Unify____tuple_0_0(MR_Tuple x, MR_Tuple y);
@@ -111,6 +115,8 @@
MR_Comparison_Result *result, MR_C_Pointer x, MR_C_Pointer y);
void MR_CALL mercury__private_builtin____Compare____heap_pointer_0_0(
MR_Comparison_Result *result, MR_Heap_Pointer x, MR_Heap_Pointer y);
+void MR_CALL mercury__private_builtin____Compare____ref_1_0(
+ MR_Comparison_Result *result, MR_Reference x, MR_Reference y);
void MR_CALL mercury__builtin____Compare____func_0_0(
MR_Comparison_Result *result, MR_Func x, MR_Func y);
void MR_CALL mercury__builtin____Compare____pred_0_0(
Index: runtime/mercury_construct.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_construct.c,v
retrieving revision 1.6
diff -u -d -r1.6 mercury_construct.c
--- runtime/mercury_construct.c 2 Sep 2002 05:48:02 -0000 1.6
+++ runtime/mercury_construct.c 9 Feb 2003 08:37:54 -0000
@@ -160,6 +160,7 @@
case MR_TYPECTOR_REP_TRAIL_PTR:
case MR_TYPECTOR_REP_TICKET:
case MR_TYPECTOR_REP_FOREIGN:
+ case MR_TYPECTOR_REP_REFERENCE:
return MR_FALSE;
case MR_TYPECTOR_REP_UNKNOWN:
@@ -317,6 +318,7 @@
case MR_TYPECTOR_REP_TRAIL_PTR:
case MR_TYPECTOR_REP_TICKET:
case MR_TYPECTOR_REP_FOREIGN:
+ case MR_TYPECTOR_REP_REFERENCE:
functors = -1;
break;
Index: runtime/mercury_hlc_types.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_hlc_types.h,v
retrieving revision 1.1
diff -u -d -r1.1 mercury_hlc_types.h
--- runtime/mercury_hlc_types.h 9 Aug 2002 05:26:49 -0000 1.1
+++ runtime/mercury_hlc_types.h 9 Feb 2003 09:18:06 -0000
@@ -58,6 +58,7 @@
typedef struct mercury__builtin__void_0_s * MR_Void;
typedef struct mercury__builtin__c_pointer_0_s * MR_C_Pointer;
typedef struct mercury__private_builtin__heap_pointer_0_s * MR_Heap_Pointer;
+ typedef struct mercury__private_builtin__ref_1_s * MR_Reference;
typedef MR_ClosurePtr MR_Pred;
typedef MR_ClosurePtr MR_Func;
typedef struct mercury__array__array_1_s * MR_Array;
@@ -78,6 +79,7 @@
typedef MR_Word MR_Void;
typedef MR_Word MR_C_Pointer;
typedef MR_Word MR_Heap_Pointer;
+ typedef MR_Word MR_Reference;
typedef MR_Word MR_Pred;
typedef MR_Word MR_Func;
typedef MR_Word MR_Array;
Index: runtime/mercury_mcpp.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_mcpp.h,v
retrieving revision 1.24
diff -u -d -r1.24 mercury_mcpp.h
--- runtime/mercury_mcpp.h 28 Nov 2002 16:40:47 -0000 1.24
+++ runtime/mercury_mcpp.h 9 Feb 2003 08:22:50 -0000
@@ -177,7 +177,8 @@
#define MR_TYPECTOR_REP_TYPEDESC_val 35
#define MR_TYPECTOR_REP_TYPECTORDESC_val 36
#define MR_TYPECTOR_REP_FOREIGN_val 37
-#define MR_TYPECTOR_REP_UNKNOWN_val 38
+#define MR_TYPECTOR_REP_REFERENCE_val 38
+#define MR_TYPECTOR_REP_UNKNOWN_val 39
// XXX we should integrate this macro in with the version in
// mercury_typeinfo.h
Index: runtime/mercury_ml_expand_body.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_ml_expand_body.h,v
retrieving revision 1.23
diff -u -d -r1.23 mercury_ml_expand_body.h
--- runtime/mercury_ml_expand_body.h 29 Nov 2002 13:26:01 -0000 1.23
+++ runtime/mercury_ml_expand_body.h 9 Feb 2003 08:49:59 -0000
@@ -1153,6 +1153,18 @@
handle_zero_arity_args();
break;
+ case MR_TYPECTOR_REP_REFERENCE:
+ if (noncanon == MR_NONCANON_ABORT) {
+ /* XXX should throw an exception */
+ MR_fatal_error(MR_STRINGIFY(EXPAND_FUNCTION_NAME)
+ ": attempt to deconstruct noncanonical term");
+ break;
+ }
+
+ handle_functor_name("<<reference>>");
+ handle_zero_arity_args();
+ break;
+
case MR_TYPECTOR_REP_UNKNOWN: /* fallthru */
default:
MR_fatal_error(MR_STRINGIFY(EXPAND_FUNCTION_NAME)
Index: runtime/mercury_type_info.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_type_info.h,v
retrieving revision 1.97
diff -u -d -r1.97 mercury_type_info.h
--- runtime/mercury_type_info.h 21 Nov 2002 15:14:40 -0000 1.97
+++ runtime/mercury_type_info.h 9 Feb 2003 08:30:31 -0000
@@ -577,6 +577,7 @@
MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_TYPEDESC),
MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_TYPECTORDESC),
MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_FOREIGN),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_REFERENCE),
/*
** MR_TYPECTOR_REP_UNKNOWN should remain the last alternative;
** MR_TYPE_CTOR_STATS depends on this.
Index: runtime/mercury_unify_compare_body.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_unify_compare_body.h,v
retrieving revision 1.27
diff -u -d -r1.27 mercury_unify_compare_body.h
--- runtime/mercury_unify_compare_body.h 8 Nov 2002 00:45:48 -0000 1.27
+++ runtime/mercury_unify_compare_body.h 9 Feb 2003 20:23:37 -0000
@@ -674,6 +674,22 @@
case MR_TYPECTOR_REP_FOREIGN:
MR_fatal_error(attempt_msg "terms of a foreign type");
+ case MR_TYPECTOR_REP_REFERENCE:
+#ifdef select_compare_code
+ /*
+ ** This is not permitted, because keeping the order of references
+ ** consistent would cause significant difficulty for a copying
+ ** garbage collector.
+ */
+ MR_fatal_error(attempt_msg "terms of a reference type");
+#else
+ /*
+ ** XXX what should the first argument to return_unify_answer()
+ ** be here?
+ */
+ return_unify_answer(reference, (void *) x == (void *) y);
+#endif
+
case MR_TYPECTOR_REP_UNKNOWN:
MR_fatal_error(attempt_msg "terms of unknown type");
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list