X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmini%2Fgenerics.cs;h=19282df514e273e5f2da45e6208e835255b34b58;hb=6b104c2bc41fe0e94488f0ef461319cb3a512aa3;hp=d880ca92dd3824622e4c8b6851e7ca033300b9d9;hpb=d223813fc1ca421dd0564df77affcb3c57cc5edd;p=mono.git diff --git a/mono/mini/generics.cs b/mono/mini/generics.cs index d880ca92dd3..19282df514e 100644 --- a/mono/mini/generics.cs +++ b/mono/mini/generics.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.CompilerServices; class Tests { @@ -445,6 +446,29 @@ class Tests { return 0; } + public static int test_0_generic_virtual_on_interfaces_ref () { + Foo.count1 = 0; + Foo.count2 = 0; + Foo.count3 = 0; + Foo.count4 = 0; + + IFoo f = new Foo (""); + for (int i = 0; i < 1000; ++i) { + f.Bar (); + f.Bar (); + f.NonGeneric (); + } + + if (Foo.count2 != 1000) + return 2; + if (Foo.count3 != 1000) + return 3; + if (Foo.count4 != 1000) + return 4; + + return 0; + } + //repro for #505375 [Category ("!FULLAOT")] public static int test_2_cprop_bug () { @@ -490,6 +514,11 @@ class Tests { return l.Count; } + public static int test_0_fullaot_comparer_t_2 () { + var l = new Dictionary (); + return l.Count; + } + static void enumerate (IEnumerable arr) { foreach (var o in arr) ; @@ -528,6 +557,29 @@ class Tests { return cctor_count; } + static int cctor_count2 = 0; + + class ServiceController { + static ServiceController () { + cctor_count2 ++; + } + + public ServiceController () { + } + } + + static ServiceController Create() { + return new ServiceController(); + } + + // #631409 + public static int test_2_generic_class_init_gshared_ctor_from_gshared () { + Create (); + Create (); + + return cctor_count2; + } + public static Type get_type () { return typeof (T); } @@ -556,6 +608,127 @@ class Tests { return t () == typeof (T) ? 0 : 1; } + public static int test_0_marshalbyref_call_from_gshared_virt_elim () { + /* Calling a virtual method from gshared code which is changed to a nonvirt call */ + Class1 o = new Class1 (); + o.Do (new Class2 ()); + return 0; + } + + class Pair { + public static KeyValuePair make_pair (TKey key, TValue value) + { + return new KeyValuePair (key, value); + } + + public delegate TRet Transform (TKey key, TValue value); + } + + public static int test_0_bug_620864 () { + var d = new Pair.Transform> (Pair.make_pair); + + var p = d ("FOO", typeof (int)); + if (p.Key != "FOO" || p.Value != typeof (int)) + return 1; + + return 0; + } + + + struct RecStruct { + public void foo (RecStruct> baz) { + } + } + + public static int test_0_infinite_generic_recursion () { + // Check that the AOT compile can deal with infinite generic recursion through + // parameter types + RecStruct bla; + + return 0; + } + + struct FooStruct { + } + + bool IsNull2 (object value) where T : struct { + T? item = (T?) value; + + if (item.HasValue) + return false; + + return true; + } + + public static int test_0_full_aot_nullable_unbox_from_gshared_code () { + if (!new Tests ().IsNull2 (null)) + return 1; + if (new Tests ().IsNull2 (new FooStruct ())) + return 2; + return 0; + } + + public static int test_0_partial_sharing () { + if (PartialShared1 (new List (), 1) != typeof (string)) + return 1; + if (PartialShared1 (new List (), 1) != typeof (Tests)) + return 2; + if (PartialShared2 (new List (), 1) != typeof (int)) + return 3; + if (PartialShared2 (new List (), 1) != typeof (int)) + return 4; + return 0; + } + + public static int test_6_partial_sharing_linq () { + var messages = new List (); + + messages.Add (new Message () { MessageID = 5 }); + messages.Add (new Message () { MessageID = 6 }); + + return messages.Max(i => i.MessageID); + } + + public static int test_0_partial_shared_method_in_nonshared_class () { + var c = new Class1 (); + return (c.Foo (5).GetType () == typeof (Class1)) ? 0 : 1; + } + + class Message { + public int MessageID { + get; set; + } + } + + public static Type PartialShared1 (List list, K k) { + return typeof (T); + } + + public static Type PartialShared2 (List list, K k) { + return typeof (K); + } + + public class Class1 { + public virtual void Do (Class2 t) { + t.Foo (); + } + + public virtual object Foo (T t) { + return new Class1 (); + } + } + + public interface IFace1 { + void Foo (); + } + + public class Class2 : MarshalByRefObject, IFace1 { + public void Foo () { + } + } + + + public static void VirtualInterfaceCallFromGenericMethod (IFoo f) { f.Bar (); } @@ -623,7 +796,7 @@ class Tests { GenericEvent (this); } - public static int count1, count2, count3; + public static int count1, count2, count3, count4; public void NonGeneric () { count3 ++; @@ -634,6 +807,8 @@ class Tests { count1 ++; else if (typeof (T) == typeof (string)) count2 ++; + else if (typeof (T) == typeof (object)) + count4 ++; return null; } } @@ -675,4 +850,134 @@ class Tests { static T Unbox (object o) { return (T) o; } + + interface IDefaultRetriever + { + T GetDefault(); + } + + class DefaultRetriever : IDefaultRetriever + { + [MethodImpl(MethodImplOptions.Synchronized)] + public T GetDefault() + { + return default(T); + } + } + + [Category ("!FULLAOT")] + public static int test_0_regress_668095_synchronized_gshared () { + return DoSomething (new DefaultRetriever ()); + } + + static int DoSomething(IDefaultRetriever foo) { + int result = foo.GetDefault(); + return result; + } + + class Response { + } + + public static int test_0_687865_isinst_with_cache_wrapper () { + object o = new object (); + if (o is Action>) + return 1; + else + return 0; + } + + enum DocType { + One, + Two, + Three + } + + class Doc { + public string Name { + get; set; + } + + public DocType Type { + get; set; + } + } + + // #2155 + public static int test_0_fullaot_sflda_cctor () { + List documents = new List(); + documents.Add(new Doc { Name = "Doc1", Type = DocType.One } ); + documents.Add(new Doc { Name = "Doc2", Type = DocType.Two } ); + documents.Add(new Doc { Name = "Doc3", Type = DocType.Three } ); + documents.Add(new Doc { Name = "Doc4", Type = DocType.One } ); + documents.Add(new Doc { Name = "Doc5", Type = DocType.Two } ); + documents.Add(new Doc { Name = "Doc6", Type = DocType.Three } ); + documents.Add(new Doc { Name = "Doc7", Type = DocType.One } ); + documents.Add(new Doc { Name = "Doc8", Type = DocType.Two } ); + documents.Add(new Doc { Name = "Doc9", Type = DocType.Three } ); + + List categories = documents.Select(d=>d.Type).Distinct().ToList().OrderBy(d => d).ToList(); + foreach(DocType cat in categories) { + List catDocs = documents.Where(d => d.Type == cat).OrderBy(d => d.Name).ToList(); + } + return 0; + } + + class A { } + + static List sources = new List(); + + // #6112 + public static int test_0_fullaot_imt () { + sources.Add(null); + sources.Add(null); + + int a = sources.Count; + var enumerator = sources.GetEnumerator() as IEnumerator; + + while (enumerator.MoveNext()) + { + object o = enumerator.Current; + } + + return 0; + } + + struct Record : Foo2.IRecord { + int counter; + int Foo2.IRecord.DoSomething () { + return counter++; + } + } + + class Foo2 where T : Foo2.IRecord { + public interface IRecord { + int DoSomething (); + } + + public static int Extract (T[] t) { + return t[0].DoSomething (); + } + } + + class Foo3 where T : IComparable { + public static int CompareTo (T[] t) { + // This is a constrained call to Enum.CompareTo () + return t[0].CompareTo (t [0]); + } + } + + public static int test_1_regress_constrained_iface_call_7571 () { + var r = new Record [10]; + Foo2.Extract (r); + return Foo2.Extract (r); + } + + enum ConstrainedEnum { + Val = 1 + } + + public static int test_0_regress_constrained_iface_call_enum () { + var r = new ConstrainedEnum [10]; + return Foo3.CompareTo (r); + } }