[m-dev.] for review: RTTI version numbers.

Tyson Dowd trd at cs.mu.OZ.AU
Tue Oct 19 17:05:16 AEST 1999


Hi,

No matter what I say here Zoltan and Fergus are going to look at it.
But I'd like someone else to surprise me by reviewing it first.

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


Estimated hours taken: 1.5

Add version information to type_ctor_infos.  This way bootstrapping is
easier and binary compatibility can be broken more slowly. 

RTTI code can check version numbers before performing operations on
data structures that have recently changed their representation.
At the least they can abort cleanly and let you know that it's time
to re-compile, at best they can handle both forms of the data structure.
It is a bootstrapping problem that currently there is no version number
information in the appropriate slot in pre-built systems.

The version numbers start at 2 simply because 2 "occurs naturally" 
much less often than 1 or 0.  And 42 was becoming trite.

compiler/base_type_info.m:
	Generate RTTI version numbers in compiler-generated
	type_ctor_infos.

library/builtin.m:
library/private_builtin.m:
library/std_util.m:
runtime/mercury_bootstrap.c:
runtime/mercury_type_info.c:
	Add RTTI version numbers for handwritten type_ctor_infos.

runtime/mercury_type_info.h:
	Add MR_RTTI_VERSION to define the current version of the RTTI
	info and the first version: MR_RTTI_VERSION_INITIAL which
	happens to have the value of 2.


Index: compiler/base_type_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/base_type_info.m,v
retrieving revision 1.26
diff -u -r1.26 base_type_info.m
--- base_type_info.m	1999/07/06 06:31:14	1.26
+++ base_type_info.m	1999/10/18 08:16:29
@@ -123,6 +123,21 @@
 
 %---------------------------------------------------------------------------%
 
+	% The version of the RTTI data structures -- useful for bootstrapping.
+	% If you write runtime code that checks this version number and
+	% can at least handle the previous version of the data
+	% structure, it makes it easier to bootstrap changes to the data
+	% structures used for RTTI.
+	%
+	% This number should be kept in sync with MR_RTTI_VERSION in
+	% runtime/mercury_type_info.h.  This means you need to update
+	% the handwritten type_ctor_info structures and the code in the
+	% runtime that uses RTTI to conform to whatever changes the new
+	% version introduces.
+
+:- func type_ctor_info_version = int.
+type_ctor_info_version = 2.
+
 base_type_info__generate_llds(ModuleInfo, CModules) :-
 	module_info_base_gen_infos(ModuleInfo, BaseGenInfos),
 	base_type_info__construct_type_ctor_infos(BaseGenInfos, ModuleInfo,
@@ -167,8 +182,9 @@
 		prog_out__sym_name_to_string(ModuleName, ModuleNameString),
 		NameArg = yes(const(string_const(TypeName))),
 		ModuleArg = yes(const(string_const(ModuleNameString))),
+		VersionArg = yes(const(int_const(type_ctor_info_version))),
 		list__append(PredAddrArgs, [TypeCtorArg, FunctorsArg, LayoutArg,
-			ModuleArg, NameArg], FinalArgs)
+			ModuleArg, NameArg, VersionArg], FinalArgs)
 	;
 		FinalArgs = PredAddrArgs
 	),
Index: library/builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/builtin.m,v
retrieving revision 1.22
diff -u -r1.22 builtin.m
--- builtin.m	1999/10/13 07:01:28	1.22
+++ builtin.m	1999/10/18 08:17:33
@@ -518,7 +518,8 @@
 	(MR_TypeCtorFunctors) & mercury_data___type_ctor_functors_int_0,
 	(MR_TypeCtorLayout) & mercury_data___type_ctor_layout_int_0,
 	string_const(""builtin"", 7),
-	string_const(""int"", 3)
+	string_const(""int"", 3),
+	MR_RTTI_VERSION
 };
 
 	/* type_ctor_info for `character' */
@@ -536,7 +537,8 @@
 	(MR_TypeCtorFunctors) & mercury_data___type_ctor_functors_character_0,
 	(MR_TypeCtorLayout) & mercury_data___type_ctor_layout_character_0,
 	string_const(""builtin"", 7),
-	string_const(""character"", 9)
+	string_const(""character"", 9),
+	MR_RTTI_VERSION
 };
 
 	/* type_ctor_info for `string' */
@@ -554,7 +556,8 @@
 	(MR_TypeCtorFunctors) & mercury_data___type_ctor_functors_string_0,
 	(MR_TypeCtorLayout) & mercury_data___type_ctor_layout_string_0,
 	string_const(""builtin"", 7),
-	string_const(""string"", 6)
+	string_const(""string"", 6),
+	MR_RTTI_VERSION
 };
 
 	/* type_ctor_info for `float' */
@@ -572,7 +575,8 @@
 	(MR_TypeCtorFunctors) & mercury_data___type_ctor_functors_float_0,
 	(MR_TypeCtorLayout) & mercury_data___type_ctor_layout_float_0,
 	string_const(""builtin"", 7),
-	string_const(""float"", 5)
+	string_const(""float"", 5),
+	MR_RTTI_VERSION
 };
 
 	/* type_ctor_info for `void' */
@@ -588,7 +592,8 @@
 	(MR_TypeCtorFunctors) & mercury_data___type_ctor_functors_void_0,
 	(MR_TypeCtorLayout) & mercury_data___type_ctor_layout_void_0,
 	string_const(""builtin"", 7),
-	string_const(""void"", 4)
+	string_const(""void"", 4),
+	MR_RTTI_VERSION
 };
 
 #ifdef	NATIVE_GC
@@ -606,7 +611,8 @@
 	(MR_TypeCtorFunctors) & mercury_data___type_ctor_functors_succip_0,
 	(MR_TypeCtorLayout) & mercury_data___type_ctor_layout_succip_0,
 	string_const(""builtin"", 7),
-	string_const(""succip"", 6)
+	string_const(""succip"", 6),
+	MR_RTTI_VERSION
 };
 
 	/* type_ctor_info for `hp' (only used by accurate gc) */
@@ -622,7 +628,8 @@
 	(MR_TypeCtorFunctors) & mercury_data___type_ctor_functors_hp_0,
 	(MR_TypeCtorLayout) & mercury_data___type_ctor_layout_hp_0,
 	string_const(""builtin"", 7),
-	string_const(""hp"", 2)
+	string_const(""hp"", 2),
+	MR_RTTI_VERSION
 };
 
 	/* type_ctor_info for `curfr' (only used by accurate gc) */
@@ -638,7 +645,8 @@
 	(MR_TypeCtorFunctors) & mercury_data___type_ctor_functors_curfr_0,
 	(MR_TypeCtorLayout) & mercury_data___type_ctor_layout_curfr_0,
 	string_const(""builtin"", 7),
-	string_const(""curfr"", 5)
+	string_const(""curfr"", 5),
+	MR_RTTI_VERSION
 };
 
 	/* type_ctor_info for `maxfr' (only used by accurate gc) */
@@ -654,7 +662,8 @@
 	(MR_TypeCtorFunctors) & mercury_data___type_ctor_functors_maxfr_0,
 	(MR_TypeCtorLayout) & mercury_data___type_ctor_layout_maxfr_0,
 	string_const(""builtin"", 7),
-	string_const(""maxfr"", 5)
+	string_const(""maxfr"", 5),
+	MR_RTTI_VERSION
 };
 
 	/* type_ctor_info for `redofr' (only used by accurate gc) */
@@ -670,7 +679,8 @@
 	(MR_TypeCtorFunctors) & mercury_data___type_ctor_functors_redofr_0,
 	(MR_TypeCtorLayout) & mercury_data___type_ctor_layout_redofr_0,
 	string_const(""builtin"", 7),
-	string_const(""redofr"", 6)
+	string_const(""redofr"", 6),
+	MR_RTTI_VERSION
 };
 
 	/* type_ctor_info for `redoip' (only used by accurate gc) */
@@ -686,7 +696,8 @@
 	(MR_TypeCtorFunctors) & mercury_data___type_ctor_functors_redoip_0,
 	(MR_TypeCtorLayout) & mercury_data___type_ctor_layout_redoip_0,
 	string_const(""builtin"", 7),
-	string_const(""redoip"", 6)
+	string_const(""redoip"", 6),
+	MR_RTTI_VERSION
 };
 
 #endif /* NATIVE_GC */
@@ -704,7 +715,8 @@
 	(MR_TypeCtorFunctors) & mercury_data___type_ctor_functors_trail_ptr_0,
 	(MR_TypeCtorLayout) & mercury_data___type_ctor_layout_trail_ptr_0,
 	string_const(""builtin"", 7),
-	string_const(""trail_ptr"", 9)
+	string_const(""trail_ptr"", 9),
+	MR_RTTI_VERSION
 };
 
 	/* type_ctor_info for `ticket' (only used by agc and debugger) */
@@ -720,7 +732,8 @@
 	(MR_TypeCtorFunctors) & mercury_data___type_ctor_functors_ticket_0,
 	(MR_TypeCtorLayout) & mercury_data___type_ctor_layout_ticket_0,
 	string_const(""builtin"", 7),
-	string_const(""ticket"", 6)
+	string_const(""ticket"", 6),
+	MR_RTTI_VERSION
 };
 
 BEGIN_MODULE(builtin_types_module)
@@ -882,7 +895,8 @@
 	(MR_TypeCtorFunctors) &mercury_data_builtin__type_ctor_functors_c_pointer_0,
 	(MR_TypeCtorLayout) &mercury_data_builtin__type_ctor_layout_c_pointer_0,
 	string_const(""builtin"", 7),
-	string_const(""c_pointer"", 9)
+	string_const(""c_pointer"", 9),
+	MR_RTTI_VERSION
 };
 
 
Index: library/private_builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/private_builtin.m,v
retrieving revision 1.30
diff -u -r1.30 private_builtin.m
--- private_builtin.m	1999/10/13 07:01:28	1.30
+++ private_builtin.m	1999/10/18 08:17:34
@@ -315,7 +315,8 @@
 	(MR_TypeCtorLayout) &
 		mercury_data_private_builtin__type_ctor_layout_type_info_1,
 	string_const(""private_builtin"", 15),
-	string_const(""type_ctor_info"", 14)
+	string_const(""type_ctor_info"", 14),
+	MR_RTTI_VERSION
 };
 
 MR_STATIC_CODE_CONST struct MR_TypeCtorInfo_struct
@@ -333,7 +334,8 @@
 	(MR_TypeCtorLayout) &
 		mercury_data_private_builtin__type_ctor_layout_type_info_1,
 	string_const(""private_builtin"", 15),
-	string_const(""type_info"", 9)
+	string_const(""type_info"", 9),
+	MR_RTTI_VERSION
 };
 
 
@@ -376,7 +378,8 @@
 	(MR_TypeCtorLayout) &
 	    mercury_data_private_builtin__type_ctor_layout_typeclass_info_1,
 	string_const(""private_builtin"", 15),
-	string_const(""base_typeclass_info"", 19)
+	string_const(""base_typeclass_info"", 19),
+	MR_RTTI_VERSION
 };
 
 MR_STATIC_CODE_CONST struct MR_TypeCtorInfo_struct
@@ -394,7 +397,8 @@
 	(MR_TypeCtorLayout) &
 	    mercury_data_private_builtin__type_ctor_layout_typeclass_info_1,
 	string_const(""private_builtin"", 15),
-	string_const(""typeclass_info"", 14)
+	string_const(""typeclass_info"", 14),
+	MR_RTTI_VERSION
 };
 
 const struct
Index: library/std_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/std_util.m,v
retrieving revision 1.163
diff -u -r1.163 std_util.m
--- std_util.m	1999/10/15 21:13:41	1.163
+++ std_util.m	1999/10/18 08:17:35
@@ -1096,7 +1096,8 @@
 	(Word *) &mercury_data_std_util__type_ctor_functors_univ_0,
 	(Word *) &mercury_data_std_util__type_ctor_layout_univ_0,
 	string_const(""std_util"", 8),
-	string_const(""univ"", 4)
+	string_const(""univ"", 4),
+	MR_RTTI_VERSION
 };
 
 
Index: runtime/mercury_bootstrap.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_bootstrap.c,v
retrieving revision 1.20
diff -u -r1.20 mercury_bootstrap.c
--- mercury_bootstrap.c	1999/10/10 03:35:23	1.20
+++ mercury_bootstrap.c	1999/10/18 08:19:51
@@ -55,7 +55,8 @@
 	(Word *) &mercury_data_std_util__type_ctor_functors_type_info_0_bootstrap,
 	(Word *) &mercury_data_std_util__type_ctor_layout_type_info_0_bootstrap,
 	string_const("std_util", 8),
-	string_const("type_info", 9)
+	string_const("type_info", 9),
+	MR_RTTI_VERSION
 };
 
 #else /* defined(USE_GCC_NONLOCAL_GOTOS) && !defined(USE_ASM_LABELS) */
Index: runtime/mercury_type_info.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_type_info.c,v
retrieving revision 1.22
diff -u -r1.22 mercury_type_info.c
--- mercury_type_info.c	1999/09/27 05:20:51	1.22
+++ mercury_type_info.c	1999/10/18 08:17:16
@@ -59,7 +59,8 @@
 	(MR_TypeCtorFunctors) & mercury_data___type_ctor_functors_pred_0,
 	(MR_TypeCtorLayout) & mercury_data___type_ctor_layout_pred_0,
 	string_const("builtin", 7),
-	string_const("func", 4)
+	string_const("func", 4),
+	MR_RTTI_VERSION
 };
 
 	/*
@@ -80,7 +81,8 @@
 	(MR_TypeCtorFunctors) & mercury_data___type_ctor_functors_pred_0,
 	(MR_TypeCtorLayout) & mercury_data___type_ctor_layout_pred_0,
 	string_const("builtin", 7),
-	string_const("pred", 4)
+	string_const("pred", 4),
+	MR_RTTI_VERSION
 };
 
 Define_extern_entry(mercury__builtin_unify_pred_2_0);
Index: runtime/mercury_type_info.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_type_info.h,v
retrieving revision 1.28
diff -u -r1.28 mercury_type_info.h
--- mercury_type_info.h	1999/10/10 02:35:17	1.28
+++ mercury_type_info.h	1999/10/18 08:20:41
@@ -21,6 +21,24 @@
 
 /*---------------------------------------------------------------------------*/
 
+#define MR_RTTI_VERSION 		MR_RTTI_VERSION__INITIAL
+#define MR_RTTI_VERSION__INITIAL 	2
+
+/* 
+** The version of the RTTI data structures -- useful for bootstrapping.
+** MR_RTTI_VERSION sets the version number in the handwritten
+** type_ctor_infos.
+** If you write runtime code that checks this version number and
+** can at least handle the previous version of the data
+** structure, it makes it easier to bootstrap changes to the data
+** structures used for RTTI.
+**
+** This number should be kept in sync with type_ctor_info_version in
+** compiler/base_type_info.m.
+*/
+
+/*---------------------------------------------------------------------------*/
+
 /*
 ** For now, we don't give a C definition of the structures of typeinfos
 ** and pseudotypeinfos. We may change this later.
@@ -832,6 +850,7 @@
 	MR_TypeCtorLayout		type_ctor_layout;
 	String				type_ctor_module_name;
 	String				type_ctor_name;
+	Integer				version;
 };
 
 typedef struct MR_TypeCtorInfo_struct *MR_TypeCtorInfo;


-- 
       Tyson Dowd           # 
                            #  Surreal humour isn't eveyone's cup of fur.
     trd at cs.mu.oz.au        # 
http://www.cs.mu.oz.au/~trd #
--------------------------------------------------------------------------
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