[m-rev.] for review: generating type_ctor_infos for type_info

Zoltan Somogyi zs at cs.mu.OZ.AU
Thu Jun 26 03:13:40 AEST 2003


If anyone wants to review this, that would be welcome, but I want to commit
this tonight, since I have already finished the diff that makes type_info
and typeclass_info foreign types, which depends on this change for
bootstrapping.

Zoltan.

Prepare to make type_info and typeclass_info foreign types by allowing
the compiler to generate type_ctor_infos for them, and allow them to be
passed to foreign code without warnings.

compiler/type_util.m:
	Make the predicate type_ctor_has_hand_defined_rtti return true
	only if the relevant type is not declared as a foreign type.
	This is needed to allow the compiler to bootstrap across the change
	that makes type_info and typeclass_info foreign types. This required
	passing the type definition to the predicate.

compiler/special_pred.m:
compiler/unify_proc.m:
	Pass the extra argument to type_ctor_has_hand_defined_rtti.

compiler/type_ctor_info.m:
	Pass the extra argument to type_ctor_has_hand_defined_rtti.

	Set the required flags on any compiler-generated type_ctor_info
	structures for the builtin types with fake arities.

compiler/llds_out.m:
	Fix an old bug: ensure that the second argument of the
	MR_MAYBE_UNBOX_FOREIGN_TYPE macro is of type MR_Word, because the
	macro insists on this. If applied to e.g. type_ctor_info constants,
	the old code would have generated C compiler warnings, because
	their type is not MR_Word.

	Special case the most frequently passed foreign types to avoid the
	memcpy overhead in MR_MAYBE_UNBOX_FOREIGN_TYPE.

compiler/export.m:
	Add a utility predicate to help llds_out.m. In the future,
	the MLDS C backend may want to use it too.

cvs diff: Diffing .
cvs diff: Diffing analysis
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/doc
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
Index: compiler/export.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/export.m,v
retrieving revision 1.68
diff -u -b -r1.68 export.m
--- compiler/export.m	25 Jun 2003 14:03:18 -0000	1.68
+++ compiler/export.m	25 Jun 2003 14:45:52 -0000
@@ -62,6 +62,10 @@
 :- pred convert_type_from_mercury(string, type, string).
 :- mode convert_type_from_mercury(in, in, out) is det.
 
+	% Succeeds iff the given C type is known by the compiler to be
+	% an integer or pointer type the same size as MR_Word.
+:- pred c_type_is_word_sized_int_or_ptr(string::in) is semidet.
+
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
@@ -710,6 +714,14 @@
 		[]
 	).
 	
+%-----------------------------------------------------------------------------%
+
+c_type_is_word_sized_int_or_ptr("MR_Word").
+c_type_is_word_sized_int_or_ptr("MR_TypeInfo").
+c_type_is_word_sized_int_or_ptr("MR_TypeCtorInfo").
+c_type_is_word_sized_int_or_ptr("MR_TypeClassInfo").
+c_type_is_word_sized_int_or_ptr("MR_BaseTypeClassInfo").
+
 %-----------------------------------------------------------------------------%
 
 :- func this_file = string.
Index: compiler/llds_out.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/llds_out.m,v
retrieving revision 1.214
diff -u -b -r1.214 llds_out.m
--- compiler/llds_out.m	9 May 2003 05:51:51 -0000	1.214
+++ compiler/llds_out.m	25 Jun 2003 14:49:53 -0000
@@ -1840,11 +1840,19 @@
 output_pragma_inputs([I|Inputs]) -->
 	{ I = pragma_c_input(VarName, Type, Rval, MaybeForeignType) },
 	io__write_string("\t"),
-	( { MaybeForeignType = yes(ForeignType) } ->
+	(
+		{ MaybeForeignType = yes(ForeignType) },
+		% For foreign types for which c_type_is_word_sized_int_or_ptr
+		% succeeds, the code in the else branch is not only correct,
+		% it also generates faster code than would be generated by
+		% the then branch, because MR_MAYBE_UNBOX_FOREIGN_TYPE
+		% invokes memcpy when given a word-sized type.
+		\+ { c_type_is_word_sized_int_or_ptr(ForeignType) }
+	->
 		io__write_string("MR_MAYBE_UNBOX_FOREIGN_TYPE("),
 		io__write_string(ForeignType),
 		io__write_string(", "),
-		output_rval(Rval),
+		output_rval_as_type(Rval, word),
 		io__write_string(", "),
 		io__write_string(VarName),
 		io__write_string(")")
@@ -1861,8 +1869,8 @@
 		->
 			output_rval_as_type(Rval, float)
 		;
-			% Note that for this cast to be correct the foreign type
-			% must be a word sized integer or pointer type.
+			% Note that for this cast to be correct the foreign
+			% type must be a word sized integer or pointer type.
 			( { MaybeForeignType = yes(ForeignTypeStr) } ->
 				io__write_string("(" ++ ForeignTypeStr ++ ") ")
 			;
Index: compiler/special_pred.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/special_pred.m,v
retrieving revision 1.37
diff -u -b -r1.37 special_pred.m
--- compiler/special_pred.m	27 May 2003 05:57:21 -0000	1.37
+++ compiler/special_pred.m	24 Jun 2003 17:53:59 -0000
@@ -220,6 +220,6 @@
 
 can_generate_special_pred_clauses_for_type(TypeCtor, Body) :-
 	Body \= abstract_type,
-	\+ type_ctor_has_hand_defined_rtti(TypeCtor).
+	\+ type_ctor_has_hand_defined_rtti(TypeCtor, Body).
 
 %-----------------------------------------------------------------------------%
Index: compiler/type_ctor_info.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/type_ctor_info.m,v
retrieving revision 1.40
diff -u -b -r1.40 type_ctor_info.m
--- compiler/type_ctor_info.m	29 May 2003 18:17:15 -0000	1.40
+++ compiler/type_ctor_info.m	24 Jun 2003 17:26:52 -0000
@@ -113,7 +113,7 @@
 			map__lookup(TypeTable, TypeCtor, TypeDefn),
 			hlds_data__get_type_defn_body(TypeDefn, TypeBody),
 			TypeBody \= abstract_type,
-			\+ type_ctor_has_hand_defined_rtti(TypeCtor),
+			\+ type_ctor_has_hand_defined_rtti(TypeCtor, TypeBody),
 			( are_equivalence_types_expanded(ModuleInfo)
 				=> TypeBody \= eqv_type(_) )
 		->
@@ -224,8 +224,8 @@
 	;
 		TypeBody = foreign_type(_),
 		(
-			ModuleName = unqualified(ModuleStr),
-			builtin_type_ctor(ModuleStr, TypeName, TypeArity,
+			ModuleName = unqualified(ModuleStr1),
+			builtin_type_ctor(ModuleStr1, TypeName, TypeArity,
 				BuiltinCtor)
 		->
 			Details = builtin(BuiltinCtor)
@@ -282,12 +282,26 @@
 	( TypeBody = du_type(_, _, _, _, _, _) ->
 		Flags1 = set__insert(Flags0, kind_of_du_flag),
 		( TypeBody ^ du_type_reserved_tag = yes ->
-			Flags = set__insert(Flags1, reserve_tag_flag)
+			Flags2 = set__insert(Flags1, reserve_tag_flag)
+		;
+			Flags2 = Flags1
+		)
 		;
-			Flags = Flags1
+		Flags2 = Flags0
+	),
+	(
+		ModuleName = unqualified(ModuleStr2),
+		ModuleStr2 = "private_builtin",
+		TypeArity = 1,
+		( TypeName = "type_info"
+		; TypeName = "type_ctor_info"
+		; TypeName = "typeclass_info"
+		; TypeName = "base_typeclass_info"
 		)
+	->
+		Flags = set__insert(Flags2, typeinfo_fake_arity_flag)
 	;
-		Flags = Flags0
+		Flags = Flags2
 	),
 	TypeCtorData = type_ctor_data(Version, ModuleName, TypeName, TypeArity,
 		UnifyUniv, CompareUniv, Flags, Details),
Index: compiler/type_util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/type_util.m,v
retrieving revision 1.120
diff -u -b -r1.120 type_util.m
--- compiler/type_util.m	24 Jun 2003 14:20:52 -0000	1.120
+++ compiler/type_util.m	24 Jun 2003 17:26:52 -0000
@@ -108,8 +108,8 @@
 	% structures describing the types. Since the RTTI will be hand defined,
 	% the compiler shouldn't generate RTTI for these types.
 
-:- pred type_ctor_has_hand_defined_rtti(type_ctor).
-:- mode type_ctor_has_hand_defined_rtti(in) is semidet.
+:- pred type_ctor_has_hand_defined_rtti(type_ctor, hlds_type_body).
+:- mode type_ctor_has_hand_defined_rtti(in, in) is semidet.
 
 	% A test for type_info-related types that are introduced by
 	% polymorphism.m.  These need to be handled specially in certain
@@ -558,14 +558,14 @@
 
 type_util__var(term__variable(Var), Var).
 
-type_ctor_has_hand_defined_rtti(qualified(PB, "type_info") - 1) :-
-	mercury_private_builtin_module(PB).
-type_ctor_has_hand_defined_rtti(qualified(PB, "type_ctor_info") - 1) :-
-	mercury_private_builtin_module(PB).
-type_ctor_has_hand_defined_rtti(qualified(PB, "typeclass_info") - 1) :-
-	mercury_private_builtin_module(PB).
-type_ctor_has_hand_defined_rtti(qualified(PB, "base_typeclass_info") - 1) :-
-	mercury_private_builtin_module(PB).
+type_ctor_has_hand_defined_rtti(Type, Body) :-
+	Type = qualified(mercury_private_builtin_module, Name) - 1,
+	( Name = "type_info"
+	; Name = "type_ctor_info"
+	; Name = "typeclass_info"
+	; Name = "base_typeclass_info"
+	),
+	\+ ( Body = du_type(_, _, _, _, _, yes(_)) ; Body = foreign_type(_) ).
 
 is_introduced_type_info_type(Type) :-
 	sym_name_and_args(Type, TypeName, _),
Index: compiler/unify_proc.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/unify_proc.m,v
retrieving revision 1.122
diff -u -b -r1.122 unify_proc.m
--- compiler/unify_proc.m	29 May 2003 18:17:16 -0000	1.122
+++ compiler/unify_proc.m	24 Jun 2003 17:26:52 -0000
@@ -286,16 +286,19 @@
 			unify_proc__search_mode_num(ModuleInfo1, TypeCtor,
 				UnifyMode, Determinism, _)
 		; 
+			module_info_types(ModuleInfo1, TypeTable),
+			map__search(TypeTable, TypeCtor, TypeDefn),
+			hlds_data__get_type_defn_body(TypeDefn, TypeBody),
+			(
 			TypeCtor = TypeName - _TypeArity,
 			TypeName = qualified(TypeModuleName, _),
 			module_info_name(ModuleInfo1, ModuleName),
 			ModuleName = TypeModuleName,
-			module_info_types(ModuleInfo1, TypeTable),
-			map__search(TypeTable, TypeCtor, TypeDefn),
-			hlds_data__get_type_defn_body(TypeDefn, TypeBody),
 			TypeBody = abstract_type
 		; 
-			type_ctor_has_hand_defined_rtti(TypeCtor)
+				type_ctor_has_hand_defined_rtti(TypeCtor,
+					TypeBody)
+			)
 		)
 	->
 		ModuleInfo = ModuleInfo1
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/aditi
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/concurrency
cvs diff: Diffing extras/curs
cvs diff: Diffing extras/curs/samples
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/error
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/lex/tests
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/quickcheck
cvs diff: Diffing extras/quickcheck/tutes
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/stream
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing java
cvs diff: Diffing java/library
cvs diff: Diffing java/runtime
cvs diff: Diffing library
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/general/string_format
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/grade_subdirs
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/mmc_make
cvs diff: Diffing tests/mmc_make/lib
cvs diff: Diffing tests/recompilation
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
cvs diff: Diffing util
cvs diff: Diffing vim
cvs diff: Diffing vim/after
cvs diff: Diffing vim/ftplugin
cvs diff: Diffing vim/syntax
--------------------------------------------------------------------------
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