[m-rev.] for review: handle RTTI types specially in the il grade

Peter Ross pro at missioncriticalit.com
Tue Jul 2 00:16:27 AEST 2002


Hi,

For Fergus or Tyson to review.

===================================================================


Estimated hours taken: 40
Branches: main

The types which represent the RTTI don't have valid Mercury representations,
hence the compiler is unable to generate correctly typed code to reference them
using high level data on the IL backend.  Use the old lowlevel representation
for these types instead.

compiler/ml_util.m:
	Add two predicates which record whether or not the type is represented
	using the low level type representation.
	
compiler/ml_type_gen.m:
	Filter out the types which aren't represented with high level data
	before generating the high level representations of the types in a
	module.

compiler/ml_unify_gen.m:
	Don't generate named field references for types which aren't
	represented with high level data.
	
compiler/mlds_to_il.m:
	Use the correct data representation when generating code.

Index: ml_type_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_type_gen.m,v
retrieving revision 1.28
diff -u -r1.28 ml_type_gen.m
--- ml_type_gen.m	30 Jun 2002 17:06:30 -0000	1.28
+++ ml_type_gen.m	1 Jul 2002 14:04:35 -0000
@@ -78,15 +78,21 @@
 :- import_module parse_tree__prog_util, check_hlds__type_util.
 :- import_module check_hlds__polymorphism.
 :- import_module ml_backend__ml_code_util, hlds__error_util.
+:- import_module ml_backend__ml_util.
 :- import_module libs__globals, libs__options.
 
 :- import_module bool, int, string, list, map, std_util, term, require.
 
 ml_gen_types(ModuleInfo, MLDS_TypeDefns) -->
 	globals__io_lookup_bool_option(highlevel_data, HighLevelData),
+	globals__io_get_target(Target),
 	( { HighLevelData = yes } ->
 		{ module_info_types(ModuleInfo, TypeTable) },
-		{ map__keys(TypeTable, TypeCtors) },
+		{ map__keys(TypeTable, TypeCtors0) },
+		{ list__filter((pred(TypeCtor::in) is semidet :-
+				\+ type_ctor_needs_lowlevel_rep(Target,
+					TypeCtor)
+			), TypeCtors0, TypeCtors) },
 		{ list__foldl(ml_gen_type_defn(ModuleInfo, TypeTable),
 			TypeCtors, [], MLDS_TypeDefns) }
 	;
Index: ml_unify_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_unify_gen.m,v
retrieving revision 1.57
diff -u -r1.57 ml_unify_gen.m
--- ml_unify_gen.m	30 Jun 2002 17:06:30 -0000	1.57
+++ ml_unify_gen.m	1 Jul 2002 14:04:35 -0000
@@ -86,6 +86,7 @@
 :- import_module hlds__hlds_pred, hlds__hlds_out, backend_libs__builtin_ops.
 :- import_module ml_backend__ml_code_gen, ml_backend__ml_call_gen.
 :- import_module ml_backend__ml_type_gen, ml_backend__ml_closure_gen.
+:- import_module ml_backend__ml_util.
 :- import_module parse_tree__prog_util, check_hlds__type_util.
 :- import_module check_hlds__mode_util.
 :- import_module backend_libs__rtti, hlds__error_util.
@@ -1572,7 +1573,12 @@
 		% tuple types.
 		% 
 		HighLevelData = yes,
-		( type_is_tuple(VarType, _) ->
+		globals__get_target(Globals, Target),
+		(
+			( type_is_tuple(VarType, _)
+			; type_needs_lowlevel_rep(Target, VarType)
+			)
+		->
 			FieldId = offset(const(int_const(Offset)))
 		;
 			FieldName = ml_gen_field_name(MaybeFieldName, ArgNum),
@@ -1835,8 +1841,13 @@
 		SecondaryTagField :-
 	MLDS_VarType = mercury_type_to_mlds_type(ModuleInfo, VarType),
 	module_info_globals(ModuleInfo, Globals),
+	globals__get_target(Globals, Target),
 	globals__lookup_bool_option(Globals, highlevel_data, HighLevelData),
-	( HighLevelData = no ->
+	(
+		( HighLevelData = no
+		; type_needs_lowlevel_rep(Target, VarType)
+		)
+	->
 		% Note: with the low-level data representation,
 		% all fields -- even the secondary tag -- are boxed,
 		% and so we need to unbox (i.e. cast) it back to the
Index: ml_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_util.m,v
retrieving revision 1.20
diff -u -r1.20 ml_util.m
--- ml_util.m	21 Jun 2002 13:26:41 -0000	1.20
+++ ml_util.m	1 Jul 2002 14:04:35 -0000
@@ -15,6 +15,7 @@
 :- interface.
 
 :- import_module ml_backend__mlds.
+:- import_module parse_tree__prog_data.
 :- import_module list, std_util.
 :- import_module libs__globals.  % for foreign_language
 
@@ -145,12 +146,24 @@
 :- mode lval_contains_var(in, in) is semidet.
 
 %-----------------------------------------------------------------------------%
+
+	% Does the type require the lowlevel representation on the indicated
+	% backend?
+:- pred type_needs_lowlevel_rep(compilation_target::in,
+		prog_data__type::in) is semidet.
+
+:- pred type_ctor_needs_lowlevel_rep(compilation_target::in,
+		type_ctor::in) is semidet.
+
+%-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
 :- implementation.
 
 :- import_module backend_libs__rtti.
-:- import_module bool, list, std_util, parse_tree__prog_data.
+:- import_module parse_tree__prog_io, parse_tree__prog_util.
+:- import_module check_hlds__type_util.
+:- import_module bool, list, std_util.
 
 %-----------------------------------------------------------------------------%
 
@@ -598,5 +611,40 @@
 		qual(ModuleName, var(Name))) :-
 	/* this is another place where we can succeed */
 	true.
+
+%-----------------------------------------------------------------------------%
+
+type_needs_lowlevel_rep(Target, Type) :-
+	type_to_ctor_and_args(Type, TypeCtor, _Args),
+	type_ctor_needs_lowlevel_rep(Target, TypeCtor).
+
+type_ctor_needs_lowlevel_rep(il, TypeName - _Arity) :-
+	mercury_public_builtin_module(Builtin),
+	mercury_private_builtin_module(PrivateBuiltin),
+	RttiImplementation = unqualified("rtti_implementation"),
+	StdUtil = unqualified("std_util"),
+	( TypeName = qualified(PrivateBuiltin, "base_typeclass_info")
+	; TypeName = qualified(PrivateBuiltin, "type_ctor_info")
+	; TypeName = qualified(PrivateBuiltin, "typeclass_info")
+	; TypeName = qualified(PrivateBuiltin, "type_info")
+
+	; TypeName = qualified(RttiImplementation, "arg_types")
+	; TypeName = qualified(RttiImplementation, "du_functor_descriptor")
+	; TypeName = qualified(RttiImplementation, "exist_info")
+	; TypeName = qualified(RttiImplementation, "ptag_entry")
+	; TypeName = qualified(RttiImplementation, "sectag_locn")
+	; TypeName = qualified(RttiImplementation, "typeinfo_locn")
+	; TypeName = qualified(RttiImplementation, "type_ctor_info")
+	; TypeName = qualified(RttiImplementation, "type_ctor_rep")
+	; TypeName = qualified(RttiImplementation, "type_info")
+	; TypeName = qualified(RttiImplementation, "type_layout")
+
+		% XXX These two types are referenced in IL and C# code,
+		% so it is easier to just keep their low level representation
+		% for the moment.
+	; TypeName = qualified(Builtin, "comparison_result")
+	; TypeName = qualified(StdUtil, "univ")
+	).
+	
 
 %-----------------------------------------------------------------------------%
Index: mlds_to_il.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.116
diff -u -r1.116 mlds_to_il.m
--- mlds_to_il.m	21 Jun 2002 13:26:44 -0000	1.116
+++ mlds_to_il.m	1 Jul 2002 14:04:37 -0000
@@ -1963,7 +1963,8 @@
 			Type = mlds__class_type(_, _, mlds__class) 
 		;
 			DataRep ^ highlevel_data = yes,
-			Type = mlds__mercury_type(_, user_type, _)
+			Type = mlds__mercury_type(MercuryType, user_type, _),
+			\+ type_needs_lowlevel_rep(il, MercuryType)
 		}
 	->
 			% If this is a class, we should call the
@@ -3016,7 +3017,10 @@
 mlds_type_to_ilds_type(_, mercury_type(_, polymorphic_type, _)) =
 	il_generic_type.
 mlds_type_to_ilds_type(DataRep, mercury_type(MercuryType, user_type, _)) = 
-	( DataRep ^ highlevel_data = yes ->
+	( 
+		DataRep ^ highlevel_data = yes,
+		\+ type_needs_lowlevel_rep(il, MercuryType)
+	->
 		mercury_type_to_highlevel_class_type(MercuryType)
 	;
 		il_object_array_type
@@ -3611,8 +3615,7 @@
 	;
 		ClassType = ClassType0
 	),
-	FieldILType0 = mlds_type_to_ilds_type(DataRep,
-		FieldType),
+	FieldILType0 = mlds_type_to_ilds_type(DataRep, FieldType),
 	( FieldILType0 = ilds__type(_, '&'(FieldILType1)) ->
 		FieldILType = FieldILType1
 	;

--------------------------------------------------------------------------
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