[m-dev.] for review: RTTI for existential types (revised)

David Glen JEFFERY dgj at cs.mu.OZ.AU
Thu Dec 9 15:24:07 AEDT 1999


On 08-Dec-1999, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> On 07-Dec-1999, David Glen JEFFERY <dgj at cs.mu.OZ.AU> wrote:
> That looks good. 
> 
> The log message did not mention the test case.
> 
> I also have a lot of minor comments about the layout.

Ok. A relative diff follows. I will commit this now.

> > +                        /* Maybe we need to thread the value */
> > +                        /* down as well... */
> >                  equiv_type_info = (Word) MR_create_type_info(
> >                                  (Word *) maybe_equiv_type_info, 
> >                                  (Word *) equiv_type_info);
> 
> That comment is not properly formatted.
> 
> More importantly, I don't know exactly what the comment means
> by "the value"... and the comment certainly doesn't inspire confidence
> in the code.

I'm confident that comment can be deleted now. (It was basically saying that
at the time I wasn't sure if that call to MR_create_type_info should be
MR_create_type_info_maybe_existq). A comment above that piece of code says:

	** Keep looking past equivalences until the there are no more.
	** This only looks past equivalences of the top level type, not
	** the argument typeinfos.

so it seems correct.


diff -u -r tmp/LOGMESSAGE.rtti mercury/LOGMESSAGE.rtti
--- tmp/LOGMESSAGE.rtti	Thu Dec  9 13:59:15 1999
+++ mercury/LOGMESSAGE.rtti	Thu Dec  9 14:43:21 1999
@@ -46,5 +46,8 @@
 	Change the macros which access typeclass infos to reflect the new
 	structure.
 
+tests/hard_coded/existential_rtti.{m,exp}:
+	A bunch of test cases for this change.
 
-
+tests/hard_coded/Mmakefile:
+	Turn this test case on.
diff -u -r tmp/compiler/base_type_layout.m mercury/compiler/base_type_layout.m
--- tmp/compiler/base_type_layout.m	Thu Dec  9 13:59:50 1999
+++ mercury/compiler/base_type_layout.m	Thu Dec  9 14:45:41 1999
@@ -728,7 +728,7 @@
 	base_type_layout__no_tag_indicator(yes, NoTagIndicator),
 	Rval0 = yes(const(int_const(NoTagIndicator))),
 
-	base_type_layout__get_type_id(LayoutInfo0, _-NumUnivQTvars),
+	base_type_layout__get_type_id(LayoutInfo0, _ - NumUnivQTvars),
 
 		% This is a no-tag type so there can't be any existentially
 		% quantified args.
@@ -1016,7 +1016,7 @@
 		% We do this to maintain the ordering of the type variables.
 	list__delete_elems(Tvars, UnconstrainedTvars, ConstrainedTvars),
 	map__init(Locns0),
-	list__foldl((pred(T::in, N0-Ls0::in, N-Ls::out) is det :- 
+	list__foldl((pred(T::in, N0 - Ls0::in, N - Ls::out) is det :- 
 			make_direct_typeinfo_index(N0, Locn),
 			map__det_insert(Ls0, T, Locn, Ls),
 			N = N0 + 1
@@ -1056,7 +1056,7 @@
 		TypeInfoIndex = Index
 	;
 		first_matching_type_class_info(Cs, Tvar, MatchingConstraint,
-			N0+1, N, TypeInfoIndex)
+			N0 + 1, N, TypeInfoIndex)
 	).
 
 %--------------------------------------------------------------------------%
diff -u -r tmp/library/std_util.m mercury/library/std_util.m
--- tmp/library/std_util.m	Thu Dec  9 14:06:16 1999
+++ mercury/library/std_util.m	Thu Dec  9 14:47:02 1999
@@ -78,10 +78,7 @@
 
 	% univ_value(Univ):
 	%	returns the value of the object stored in Univ.
-	%
-	% Warning: support for existential types is still experimental.
-	%
-:- some([T], func univ_value(univ) = T).
+:- some [T] func univ_value(univ) = T.
 
 %-----------------------------------------------------------------------------%
 
@@ -271,9 +268,6 @@
 	% inverse to the function type_of/1.  It constrains the type
 	% of the first argument to be the type represented by the
 	% second argument.
-	%
-	% Warning: support for existential types is still experimental.
-	%
 :- some [T] pred has_type(T::unused, type_info::in) is det.
 
 	% type_name(Type) returns the name of the specified type
@@ -2252,7 +2246,7 @@
                         info->type_info_vector[i] = 
 			    (Word) MR_create_type_info_maybe_existq(
                                 	type_info, arg_pseudo_type_info, 
-					(Word *)data_value,
+					(Word *) data_value,
 					functor_descriptor);
                     }
                 }
@@ -2299,7 +2293,7 @@
                     info->type_info_vector[i] = 
 		    	(Word) MR_create_type_info_maybe_existq(
                             type_info, arg_pseudo_type_info, 
-					(Word *)data_value,
+					(Word *) data_value,
 					functor_descriptor);
                 }
             }
diff -u -r tmp/runtime/mercury_deep_copy_body.h mercury/runtime/mercury_deep_copy_body.h
--- tmp/runtime/mercury_deep_copy_body.h	Thu Dec  9 14:08:35 1999
+++ mercury/runtime/mercury_deep_copy_body.h	Thu Dec  9 14:49:00 1999
@@ -114,7 +114,7 @@
 
                     /* copy arguments */
                     for (i = 0; i < arity; i++) {
-                        MR_field(0, new_data, i + num_extra_args+ 1) 
+                        MR_field(0, new_data, i + num_extra_args + 1) 
 			    = copy_arg(data_value,
 				    &argument_vector[i + num_extra_args], 
 				    functor_descriptor, type_info,
@@ -507,11 +507,12 @@
                 ** allocated statically, so we never copy them.
 		*/
 
-		base_typeclass_info = (Word *)*typeclass_info;
+		base_typeclass_info = (Word *) *typeclass_info;
 
 		arity = MR_typeclass_info_instance_arity(typeclass_info);
 		num_super = MR_typeclass_info_num_superclasses(typeclass_info);
-		num_arg_typeinfos = MR_typeclass_info_num_type_infos(typeclass_info);
+		num_arg_typeinfos = 
+			MR_typeclass_info_num_type_infos(typeclass_info);
 		incr_saved_hp(LVALUE_CAST(Word, new_typeclass_info),
                                 arity + num_super + num_arg_typeinfos + 1);
 
@@ -531,10 +532,10 @@
                 }
 		leave_forwarding_pointer(typeclass_info_ptr, 
 			(Word) new_typeclass_info);
-                return (Word)new_typeclass_info;
+                return (Word) new_typeclass_info;
         } else {
                 found_forwarding_pointer(typeclass_info);
-                return (Word)typeclass_info;
+                return (Word) typeclass_info;
         }
 }
 
diff -u -r tmp/runtime/mercury_type_info.c mercury/runtime/mercury_type_info.c
--- tmp/runtime/mercury_type_info.c	Thu Dec  9 14:08:26 1999
+++ mercury/runtime/mercury_type_info.c	Thu Dec  9 15:00:56 1999
@@ -261,25 +261,28 @@
 	num_univ_type_infos =
 		MR_TYPEINFO_GET_TYPE_CTOR_INFO(term_type_info)->arity;
 
-	if ((Word)arg_pseudo_type_info <= num_univ_type_infos) {
+	if ((Word) arg_pseudo_type_info <= num_univ_type_infos) {
 
 		/* This is a universally quantified type variable */
 
 		arg_type_info = (Word *) 
 			term_type_info[(Word) arg_pseudo_type_info];
-	}
-	else {
+	} else {
 
 		/* This is an existentially quantified type variable */
 
 		Word type_info_locn;
 
-		type_info_locn = 
-			((Word *)MR_TYPE_CTOR_LAYOUT_FUNCTOR_DESCRIPTOR_TYPE_INFO_LOCNS(functor_descriptor))[(Integer)arg_pseudo_type_info - num_univ_type_infos - 1];
+		type_info_locn = ((Word *) 
+			MR_TYPE_CTOR_LAYOUT_FUNCTOR_DESCRIPTOR_TYPE_INFO_LOCNS(
+			functor_descriptor))
+				[(Integer)arg_pseudo_type_info 
+				- num_univ_type_infos - 1];
 
 		if (MR_TYPE_INFO_LOCN_IS_INDIRECT(type_info_locn)) {
 
-			/* This is indirect; the type-info
+			/*
+			** This is indirect; the type-info
 			** is inside a typeclass-info 
 			*/
 
@@ -294,12 +297,11 @@
 				MR_typeclass_info_type_info(
 					data_value[arg_number],
 					typeinfo_number);
-		}
-		else {
+		} else {
 			/* This is direct */
 
 			arg_type_info = 
-				(Word *)data_value[MR_TYPE_INFO_LOCN_DIRECT_GET_TYPEINFO_NUMBER(type_info_locn)];
+				(Word *) data_value[MR_TYPE_INFO_LOCN_DIRECT_GET_TYPEINFO_NUMBER(type_info_locn)];
 		}
 	}
 
@@ -446,8 +448,6 @@
 		/* Look past equivalences */
 	while (MR_TYPE_CTOR_FUNCTORS_INDICATOR(functors) == MR_TYPE_CTOR_FUNCTORS_EQUIV) {
 		equiv_type_info = (Word) MR_TYPE_CTOR_FUNCTORS_EQUIV_TYPE(functors);
-			/* Maybe we need to thread the value */
-			/* down as well... */
 		equiv_type_info = (Word) MR_create_type_info(
 				(Word *) maybe_equiv_type_info, 
 				(Word *) equiv_type_info);


dgj
-- 
David Jeffery (dgj at cs.mu.oz.au) | If your thesis is utterly vacuous
PhD student,                    | Use first-order predicate calculus.
Dept. of Comp. Sci. & Soft. Eng.|     With sufficient formality
The University of Melbourne     |     The sheerist banality
Australia                       | Will be hailed by the critics: "Miraculous!"
                                |     -- Anon.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list