[m-rev.] for review: fix problem with java grade and Java 1.7

Julien Fischer juliensf at csse.unimelb.edu.au
Wed Nov 30 18:02:57 AEDT 2011


For review by Peter Wang.

Branches: main, 11.07

Fix a problem that prevents Java 1.7 from compiling the Java code generated by
the Mercury compiler.  Previously, the TypeInfo_Struct class in the Java
version of Mercury's runtime defined the following constructors:

     public TypeInfo_Struct(TypeInfoStruct ti, int arity, Object... as)
     public TypeInfo_Struct(TypeInfoStruct ti, Object... as)

Changes to the way most specific varargs method selection works in Java 1.7
means the above is now rejected by the Java compiler.  (It should apparently
have never been allowed in the first place.)

The fix is to delete the first constructor above from the runtime and not
generate code that provides the arity.  (The arity argument was only ever used
as a sanity check on the number of the following arguments.)

java/runtime/TypeInfo_Struct.java
 	Delete one of the ambiguous constructors from this class.

compiler/rtti_to_mlds.m:
 	Don't pass an arity argument to the constructor for TypeInfo_Struct
 	objects.

Julien.

Index: compiler/rtti_to_mlds.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/rtti_to_mlds.m,v
retrieving revision 1.104
diff -u -r1.104 rtti_to_mlds.m
--- compiler/rtti_to_mlds.m	10 Nov 2011 05:15:27 -0000	1.104
+++ compiler/rtti_to_mlds.m	30 Nov 2011 06:49:22 -0000
@@ -455,13 +455,27 @@
                  !GlobalData),
              RttiTypeCtor = var_arity_id_to_rtti_type_ctor(VarArityId),
              module_info_get_name(ModuleInfo, ModuleName),
-            Initializer = init_struct(mlds_rtti_type(item_type(RttiId)), [
-                gen_init_rtti_name(ModuleName, RttiTypeCtor,
-                    type_ctor_type_ctor_info),
-                gen_init_int(list.length(ArgTypes)),
-                gen_init_cast_rtti_datas_array(mlds_type_info_type,
-                    ModuleName, ArgRttiDatas)
-            ]),
+            module_info_get_globals(ModuleInfo, Globals),
+            globals.get_target(Globals, TargetLang),
+
+            InitRttiName = gen_init_rtti_name(ModuleName, RttiTypeCtor,
+                type_ctor_type_ctor_info),
+            InitCastRttiDatasArray = gen_init_cast_rtti_datas_array(
+                mlds_type_info_type, ModuleName, ArgRttiDatas),
+            ( if TargetLang = target_java then
+                % For Java we need to omit the arity argument as the
+                % TypeInfo_Struct class doesn't have a constructor that
+                % supports it -- see java/runtime/TypeInfo_Struct.java for
+                % details.
+                InitializerArgs = [InitRttiName, InitCastRttiDatasArray]
+              else
+                InitializerArgs = [
+                    InitRttiName,
+                    gen_init_int(list.length(ArgTypes)),
+                    InitCastRttiDatasArray]
+            ),
+            Initializer = init_struct(mlds_rtti_type(item_type(RttiId)),
+                InitializerArgs),
              rtti_entity_name_and_init_to_defn(Name, RttiId, Initializer,
                  !GlobalData),

Index: java/runtime/TypeInfo_Struct.java
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/java/runtime/TypeInfo_Struct.java,v
retrieving revision 1.14
diff -u -r1.14 TypeInfo_Struct.java
--- java/runtime/TypeInfo_Struct.java	8 Oct 2010 03:29:48 -0000	1.14
+++ java/runtime/TypeInfo_Struct.java	30 Nov 2011 06:28:44 -0000
@@ -87,12 +87,16 @@
  	}

  	// XXX untested guess
-	public TypeInfo_Struct(TypeInfo_Struct ti, int arity, Object... as)
-	{
-		init(ti.type_ctor, arity, as);
-	}
-
-	// XXX untested guess
+	// We don't have a version of this constructor that also takes the arity
+	// as an argument (as we do with the init method above), e.g.
+	//
+	//  public TypeInfo_Struct(TypeInfo_Struct ti, int artiy, Object... as)
+	//
+	// because such overloadings are not allowed under Java 1.7.  (Previous
+	// versions of Java incorrectly allowed them.)
+	// If you change this you will also need to update the code in
+	// compiler/rtti_to_mlds.m.
+	//
  	public TypeInfo_Struct(TypeInfo_Struct ti, Object... as)
  	{
  		init(ti.type_ctor, as);

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list