[m-dev.] diff: prepare to fix type specialization of class method calls

Simon Taylor stayl at cs.mu.OZ.AU
Thu Aug 24 16:44:09 AEST 2000


Estimated hours taken: 0.5

Prepare to fix type specialization of class method calls
where the instance contains unconstrained type variables.
This change is being committed now to make it easier to
test the fix.

library/private_builtin.m:
	Add a predicate `unconstrained_type_info_from_typeclass_info/3',
	which is similar to `type_info_from_typeclass_info/3' but
	it extracts a type_info for one of the unconstrained type variables 
	in an instance declaration.

runtime/mercury_type_info.h:
	Add a macro MR_typeclass_info_unconstrained_type_info,
	for use by `unconstrained_type_info_from_typeclass_info/3'.

compiler/hlds_pred.m:
	Add `unconstrained_type_info_from_typeclass_info/3'
	to the list of builtins for which type-infos are not needed.


Index: library/private_builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/private_builtin.m,v
retrieving revision 1.53
diff -u -u -r1.53 private_builtin.m
--- library/private_builtin.m	2000/08/02 14:13:08	1.53
+++ library/private_builtin.m	2000/08/23 10:11:14
@@ -256,6 +256,14 @@
 :- pred type_info_from_typeclass_info(typeclass_info(_), int, type_info(T)).
 :- mode type_info_from_typeclass_info(in, in, out) is det.
 
+	% unconstrained_type_info_from_typeclass_info(TypeClassInfo, 
+	%               Index, TypeInfo)
+	% extracts the TypeInfo for the Indexth unconstrained type variable
+	% from the instance represented by TypeClassInfo.
+:- pred unconstrained_type_info_from_typeclass_info(typeclass_info(_),
+		int, type_info(_)).
+:- mode unconstrained_type_info_from_typeclass_info(in, in, out) is det.
+
 	% superclass_from_typeclass_info(TypeClassInfo, Index, SuperClass)
 	% extracts SuperClass from TypeClassInfo where SuperClass is the
 	% Indexth superclass of the class.
@@ -267,6 +275,9 @@
 	%       InstanceConstraintTypeClassInfo)
 	% extracts the typeclass_info for the Indexth typeclass constraint
 	% of the instance described by TypeClassInfo.
+	%
+	% Note: Index must be equal to the number of the desired constraint
+	% plus the number of unconstrained type variables for this instance.
 :- pred instance_constraint_from_typeclass_info(
 		typeclass_info(_), int, typeclass_info(_)).
 :- mode instance_constraint_from_typeclass_info(in, in, out) is det.
@@ -386,6 +397,13 @@
 	TypeInfo::out), [will_not_call_mercury, thread_safe],
 "
 	TypeInfo = MR_typeclass_info_type_info(TypeClassInfo, Index);
+").
+
+:- pragma c_code(unconstrained_type_info_from_typeclass_info(TypeClassInfo::in,
+	Index::in, TypeInfo::out), [will_not_call_mercury, thread_safe],
+"
+	TypeInfo = MR_typeclass_info_unconstrained_type_info(TypeClassInfo,
+			Index);
 ").
 
 :- pragma c_code(superclass_from_typeclass_info(TypeClassInfo0::in, Index::in,
Index: runtime/mercury_type_info.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_type_info.h,v
retrieving revision 1.53
diff -u -u -r1.53 mercury_type_info.h
--- runtime/mercury_type_info.h	2000/08/03 06:19:02	1.53
+++ runtime/mercury_type_info.h	2000/08/23 10:14:00
@@ -342,8 +342,17 @@
     ((MR_Integer)(*(MR_Word **)(tci))[4])
 #define MR_typeclass_info_class_method(tci, n)                      \
     ((MR_Code *)(*(MR_Word **)tci)[(n+4)])
-#define	MR_typeclass_info_arg_typeclass_info(tci, n)                \
-    (((MR_Word *)(tci))[(n)])
+
+/*
+** The following have the same definitions. This is because
+** the call to MR_typeclass_info_arg_typeclass_info must already
+** have the number of unconstrained type variables for the instance
+** added to it.
+*/
+#define MR_typeclass_info_arg_typeclass_info(tci, n)                \
+    (((Word *)(tci))[(n)])
+#define MR_typeclass_info_unconstrained_type_info(tci, n)           \
+    (((Word *)(tci))[(n)])
 
 /*
 ** The following have the same definitions. This is because
Index: compiler/hlds_pred.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_pred.m,v
retrieving revision 1.80
diff -u -u -r1.80 hlds_pred.m
--- compiler/hlds_pred.m	2000/08/09 07:46:42	1.80
+++ compiler/hlds_pred.m	2000/08/23 11:01:27
@@ -1881,8 +1881,10 @@
 no_type_info_builtin_2(builtin, "unsafe_promise_unique", 2).
 no_type_info_builtin_2(private_builtin, "superclass_from_typeclass_info", 3).
 no_type_info_builtin_2(private_builtin,
-				"instance_constraint_from_typeclass_info", 3).
+			"instance_constraint_from_typeclass_info", 3).
 no_type_info_builtin_2(private_builtin, "type_info_from_typeclass_info", 3).
+no_type_info_builtin_2(private_builtin,
+			"unconstrained_type_info_from_typeclass_info", 3).
 no_type_info_builtin_2(private_builtin, "table_restore_any_ans", 3).
 no_type_info_builtin_2(private_builtin, "table_lookup_insert_enum", 4).
 
--------------------------------------------------------------------------
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