[m-rev.] for review: automatically generate all type_ctor_infos on non C backends

Peter Ross pro at missioncriticalit.com
Sat Nov 29 08:20:33 AEDT 2003


On Mon, Nov 24, 2003 at 10:26:15AM +1100, Fergus Henderson wrote:
> On 23-Nov-2003, Peter Ross <pro at missioncriticalit.com> wrote:
> > On Sun, Nov 23, 2003 at 10:53:06PM +1100, Fergus Henderson wrote:
> > > On 21-Nov-2003, Peter Ross <pro at missioncriticalit.com> wrote:
> > > > compiler/type_util.m:
> > > > 	s/builtin_type_ctors/builtin_type_ctors_with_no_type_defn/
> > > > 	which better reflects which type ctors this function returns.
> > > > 
> > > > compiler/type_ctor_info.m:
> > > > 	Improve the documentation of how the code determines whether
> > > > 	or not a type_ctor_info needs to be generated.
> > > > 
> > > > compiler/typecheck.m:
> > > > 	Use builtin_type_ctors_with_no_type_defn and make the documentation
> > > > 	more explicit.
> > > 
> > > > Index: compiler/type_ctor_info.m
> > > > @@ -114,26 +114,28 @@
> > > >  		ModuleName, ModuleInfo, TypeCtorGenInfos1),
> > > >  	TypeCtor = SymName - TypeArity,
> > > >  	(
> > > > +	    % Check if we should generate a type_ctor_info for this type.
> > > > +	    % There are three cases that we have to check
> > > > +	    % 	- the builtin types which have no type defn
> > > > +	    % 	- the builtin types which are declared abstract
> > > > +	    % 	- all the rest of the types
> > > 
> > > Huh?  What's the difference between the first two cases?
> > > 
> > > Did you mean to say "no type declaration" instead of "no type defn"?
> >
> > Quite often we have code in the compiler
> > 
> >     module_info_types(ModuleInfo, TypeTable),
> >     map__lookup(TypeTable, TypeCtor, TypeDefn)
> > 
> > The first case is where this lookup will throw an exception because
> > there is no "type definition", the second case is where this will return
> > a "type definition" which type body is abstract.
> > 
> > Does this help?
> 
> It helps me understand.  But the source code should be understandable
> without the reader having to refer back to the archives of the
> mercury-reviews mailing list ;-)
> 
> > Maybe s/type defn/hlds_type_defn/ ?
> 
> That would help, yes.
> 
> But it would be even better to also explain what this means.
> E.g.
> 
> 	% There are three cases that we have to check
> 	%
> 	% 	- the builtin types which have no hlds_type_defn
> 	%	  (i.e. no declaration and no definition)
> 	%
> 	% 	- the builtin types which are declared abstract
> 	%	  and are not defined
> 	%	  (i.e. they have a declaration, but no definition)
> 	%
> 	% 	- all the rest of the types
> 	%	  (types with a definition, or both a declaration
> 	%	  and a definition)
> 
> > > > Index: compiler/type_util.m
> > > ...
> > > > +	% The list of type_ctors which are builtins which do not have a
> > > > +	% hlds_type_defn, ie. those builtin type which are not declared as
> > > > +	% abstract types in the standard library.
> > > > +:- func builtin_type_ctors_with_no_type_defn = list(type_ctor).
> > > 
> > > The comment here seems wrong, since e.g. array/1 is declared as an
> > > abstract type in the standard library, but is not included in this list.
> > > 
> > The key word you have missed is not.
> >     ie those builtin type which are **NOT** declared as abstract types in
> >     the standard library.
> 
> Sorry, my mistake.
> 
> But the comment is still wrong, since it does not take into account the
> cae of builtin types which are defined as concrete types in the standard
> library, such as e.g. builtin.comparison_result.
> 


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


Estimated hours taken: 2
Branches: main

Fix a bug where the type_ctor_info for type_info/1 and
type_ctor_info/1 weren't being generated.

compiler/type_ctor_info.m:
	Also have to generate a type_ctor_info for those types which
	have hand defined rtti due to having a fake type body.

compiler/type_util.m:
	Rename builtin_type_ctors_with_no_type_defn as
	builtin_type_ctors_with_no_hlds_type_defn as the former name
	was misleading, and remove an incorrect comment about which
	type_ctors this function returns.

compiler/make_hlds.m:
compiler/typecheck.m:
	Changes due to the renaming of
	builtin_type_ctors_with_no_hlds_type_defn.


Index: compiler/make_hlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make_hlds.m,v
retrieving revision 1.454
diff -u -r1.454 make_hlds.m
--- compiler/make_hlds.m	21 Nov 2003 15:21:31 -0000	1.454
+++ compiler/make_hlds.m	28 Nov 2003 20:34:07 -0000
@@ -183,7 +183,7 @@
 				construct_type(TypeCtor, [], Type),
 				add_special_preds(TVarSet, Type, TypeCtor,
 						Body, Context, Status, M0, M)
-			), builtin_type_ctors_with_no_type_defn, !Module)
+			), builtin_type_ctors_with_no_hlds_type_defn, !Module)
 	;
 		true
 	),
Index: compiler/type_ctor_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/type_ctor_info.m,v
retrieving revision 1.49
diff -u -r1.49 type_ctor_info.m
--- compiler/type_ctor_info.m	21 Nov 2003 15:21:35 -0000	1.49
+++ compiler/type_ctor_info.m	28 Nov 2003 20:34:09 -0000
@@ -91,7 +91,8 @@
 		ModuleName = mercury_public_builtin_module,
 		compiler_generated_rtti_for_the_builtins(!.ModuleInfo)
 	->
-		TypeCtors = builtin_type_ctors_with_no_type_defn ++ TypeCtors0
+		TypeCtors = builtin_type_ctors_with_no_hlds_type_defn ++
+				TypeCtors0
 	;
 		TypeCtors = TypeCtors0
 	),
@@ -114,16 +115,29 @@
 		ModuleName, ModuleInfo, TypeCtorGenInfos1),
 	TypeCtor = SymName - TypeArity,
 	(
-	    % Check if we should generate a type_ctor_info for this type.
-	    % There are three cases that we have to check
-	    % 	- the builtin types which have no type defn
-	    % 	- the builtin types which are declared abstract
-	    % 	- all the rest of the types
+	    % There are four cases that we have to check
+	    %
+	    %   - the builtin types which have no hlds_type_defn
+	    %     (i.e. no declaration and no definition)
+	    %
+	    %   - the builtin types which have a fake type body and
+	    %     such have to have hand-defined rtti.
+	    %	  (types such as private_builtin.type_info which is
+	    %	  defined as a discriminated union type)
+	    %
+	    %   - the builtin types which are declared abstract
+	    %     and are not defined
+	    %     (i.e. they have a declaration, but no definition)
+	    %
+	    %   - all the rest of the types
+	    %     (types with a definition, or both a declaration
+	    %     and a definition)
+	    %
 	    SymName = qualified(TypeModuleName, TypeName),
 	    ( 
 		TypeModuleName = ModuleName,
 		( list__member(TypeCtor,
-				builtin_type_ctors_with_no_type_defn) ->
+				builtin_type_ctors_with_no_hlds_type_defn) ->
 		    % the builtin types with no type definition.
 		    compiler_generated_rtti_for_the_builtins(ModuleInfo),
 		    TypeModuleName = unqualified(ModuleNameString),
@@ -133,9 +147,13 @@
 		    map__lookup(TypeTable, TypeCtor, TypeDefn),
 		    hlds_data__get_type_defn_body(TypeDefn, TypeBody),
 		    (
-			TypeBody = abstract_type(_)
+		    	( TypeBody = abstract_type(_)
+			; type_ctor_has_hand_defined_rtti(TypeCtor, TypeBody)
+			)
 		    ->
 			% the builtin types which are declared abstract
+			% or which have hand defined rtti due to having
+			% a fake type body.
 			compiler_generated_rtti_for_the_builtins(ModuleInfo),
 			TypeModuleName = unqualified(ModuleNameString),
 			( builtin_type_ctor(ModuleNameString,
Index: compiler/type_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/type_util.m,v
retrieving revision 1.132
diff -u -r1.132 type_util.m
--- compiler/type_util.m	21 Nov 2003 15:21:36 -0000	1.132
+++ compiler/type_util.m	28 Nov 2003 20:34:14 -0000
@@ -70,9 +70,8 @@
 :- mode type_ctor_is_tuple(in) is semidet.
 
 	% The list of type_ctors which are builtins which do not have a
-	% hlds_type_defn, ie. those builtin type which are not declared as
-	% abstract types in the standard library.
-:- func builtin_type_ctors_with_no_type_defn = list(type_ctor).
+	% hlds_type_defn.
+:- func builtin_type_ctors_with_no_hlds_type_defn = list(type_ctor).
 
 	% Succeed iff there was either a `where equality is <predname>' or a
 	% `where comparison is <predname>' declaration for the principal type
@@ -2062,7 +2061,7 @@
 
 %-----------------------------------------------------------------------------%
 
-builtin_type_ctors_with_no_type_defn =
+builtin_type_ctors_with_no_hlds_type_defn =
 	[ qualified(mercury_public_builtin_module, "int") - 0,
 	  qualified(mercury_public_builtin_module, "string") - 0,
 	  qualified(mercury_public_builtin_module, "character") - 0,
Index: compiler/typecheck.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/typecheck.m,v
retrieving revision 1.347
diff -u -r1.347 typecheck.m
--- compiler/typecheck.m	21 Nov 2003 15:21:37 -0000	1.347
+++ compiler/typecheck.m	28 Nov 2003 20:34:32 -0000
@@ -862,7 +862,7 @@
 	% check that the special pred isn't one of the builtin
 	% types which don't have a hlds_type_defn
 	%
-	\+ list__member(TypeCtor, builtin_type_ctors_with_no_type_defn),
+	\+ list__member(TypeCtor, builtin_type_ctors_with_no_hlds_type_defn),
 	%
 	% check whether that type is a type for which there is
 	% a user-defined equality predicate, or which is existentially typed.

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