Emit GenericEqualityComparer<T> instances for each EqualityComparer<T> instance in...
authorZoltan Varga <vargaz@gmail.com>
Fri, 22 Oct 2010 15:56:26 +0000 (17:56 +0200)
committerZoltan Varga <vargaz@gmail.com>
Fri, 22 Oct 2010 15:57:57 +0000 (17:57 +0200)
mono/mini/aot-compiler.c
mono/mini/generics.cs

index 7c0f43d34cc450bc892ce39952b2838978447df9..5088324c0b5726311bde679d27731c9edcc81947 100644 (file)
@@ -2697,6 +2697,25 @@ add_generic_class_with_depth (MonoAotCompile *acfg, MonoClass *klass, int depth)
                        add_generic_class (acfg, mono_class_inflate_generic_class (gcomparer, &ctx));
                }
        }
+
+       /* Add an instance of GenericEqualityComparer<T> which is created dynamically by EqualityComparer<T> */
+       if (klass->image == mono_defaults.corlib && !strcmp (klass->name_space, "System.Collections.Generic") && !strcmp (klass->name, "EqualityComparer`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);
+
+               gcomparer = mono_class_from_name (mono_defaults.corlib, "System.Collections.Generic", "GenericEqualityComparer`1");
+               g_assert (gcomparer);
+               add_generic_class (acfg, mono_class_inflate_generic_class (gcomparer, &ctx));
+       }
 }
 
 static void
index 5fce0b601bbb5638f1a432319da4517141e80c48..b7a33513ad95eca55406f231430292a3ee9df188 100644 (file)
@@ -490,6 +490,11 @@ class Tests {
                return l.Count;
        }
 
+       public static int test_0_fullaot_comparer_t_2 () {
+               var l = new Dictionary <TimeSpan, int> ();
+               return l.Count;
+       }
+
        static void enumerate<T> (IEnumerable<T> arr) {
                foreach (var o in arr)
                        ;