2009-10-06 Zoltan Varga <vargaz@gmail.com>
authorZoltan Varga <vargaz@gmail.com>
Tue, 6 Oct 2009 17:07:40 +0000 (17:07 -0000)
committerZoltan Varga <vargaz@gmail.com>
Tue, 6 Oct 2009 17:07:40 +0000 (17:07 -0000)
* aot-compiler.c (add_generic_class): Add an instance of GenericComparer<T> for
each instance of Comparer<T>.

* generics.cs: Add a new test.

svn path=/trunk/mono/; revision=143531

mono/mini/ChangeLog
mono/mini/aot-compiler.c
mono/mini/generics.cs

index 27d8a4aa8f6e182f90e3be3f892aea37b72cb759..3c774a321c3a0cd2769d84938c6775f37f03bd04 100644 (file)
@@ -1,3 +1,10 @@
+2009-10-06  Zoltan Varga  <vargaz@gmail.com>
+
+       * aot-compiler.c (add_generic_class): Add an instance of GenericComparer<T> for
+       each instance of Comparer<T>.
+
+       * generics.cs: Add a new test.
+
 2009-10-04  Zoltan Varga  <vargaz@gmail.com>
 
        * aot-compiler.c (add_generic_class): Only add GetGenericValueImpl wrappers
index fb62baaf487bd8b59e1589af58c489db70c868de..f6ce0fcfe0532a9083bf14527949ebafc8a3930d 100644 (file)
@@ -2150,7 +2150,27 @@ add_generic_class (MonoAotCompile *acfg, MonoClass *klass)
                                add_extra_method (acfg, mono_marshal_get_native_wrapper (mono_class_inflate_generic_method (get_method, &ctx), TRUE, TRUE));
                        }
                }
+       }
+
+       /* Add an instance of GenericComparer<T> which is created dynamically by Comparer<T> */
+       if (klass->image == mono_defaults.corlib && !strcmp (klass->name_space, "System.Collections.Generic") && !strcmp (klass->name, "Comparer`1")) {
+               MonoClass *tclass = mono_class_from_mono_type (klass->generic_class->context.class_inst->type_argv [0]);
+               MonoClass *icomparable, *gcomparer;
+               MonoGenericContext ctx;
+               MonoType *args [16];
 
+               memset (&ctx, 0, sizeof (ctx));
+
+               icomparable = mono_class_from_name (mono_defaults.corlib, "System", "IComparable`1");
+               g_assert (icomparable);
+               args [0] = &tclass->byval_arg;
+               ctx.class_inst = mono_metadata_get_generic_inst (1, args);
+
+               if (mono_class_is_assignable_from (mono_class_inflate_generic_class (icomparable, &ctx), tclass)) {
+                       gcomparer = mono_class_from_name (mono_defaults.corlib, "System.Collections.Generic", "GenericComparer`1");
+                       g_assert (gcomparer);
+                       add_generic_class (acfg, mono_class_inflate_generic_class (gcomparer, &ctx));
+               }
        }
 }
 
index 3a735ef23bd53c8bfbd386bfd4cf1482cb62141b..15fc3afc63f20b88e5d2c804491b4c1df1b9a943 100644 (file)
@@ -457,6 +457,11 @@ class Tests {
                return filteredWords.Count ();
        }
 
+       public static int test_0_fullaot_comparer_t () {
+               var l = new SortedList <TimeSpan, int> ();
+               return l.Count;
+       }
+
        static int cctor_count = 0;
 
     public abstract class Beta<TChanged>