November 16, 2003 10:55 pm (permalink)

Generic Collections

gmcs can now finally compile System.Collections.Generic - at least the classes which are currently in CVS.

As a side note, the problem with "recursive" interfaces I mentioned yesterday is now also fixed.

Posted by martin at November 16, 2003 10:55 pm.

November 15, 2003 12:08 pm (permalink)

Interfaces, inheritance and type parameters - Part II

Got up really early this morning and finally got everything working. Here's a summary of what I fixed the last two days:

First of all, inheritance is now actually working. Previously, simple examples like

class Foo<T> { } class Bar<T> : Foo<T> { }

already worked, but it did not if the base class had a different number or another order of type parameters, for instance:

class Foo<R,S> { } class Bar<T,U> : Foo<U,T> { }

or

class Foo<S> { } class Bar<T,U> : Foo<U> { }

This is now working.


The second thing are interfaces. Like I already mentioned in my blog last week, I needed to do some larger mcs changes for this. Now, I also implemented the reflection/runtime part of it.

Let's have a look at yesterday's example again:

interface Foo<S> { void Hello (S s); } interface Bar<T,U> : Foo<U> { void Test (T t, U u); } class X { static void Test (Bar<int,string> bar) { bar.Hello ("World"); } }

When instantiating Bar, it's not a class (which has exactly one parent class), but it's an interface which can have any number of "parent" interfaces (ie. interfaces it implements). This means its System.Reflection.MonoGenericInst instance must also inflate the methods from all these interfaces.


Ok, so far, this is a summary of things which are already working. Now let's have a look at what still needs to be done.

  • "Recursive" generic interfaces

    Things like

    interface Foo<T> { } interface Bar<T> : Foo<Bar<T>> { } aren't working yet.
  • Generic collections

    Another thing I need to look at are the generic collection classes in corlib/System.Collections.Generic - can gmcs already compile them, if not, then why ....

  • Making gmcs compile normal code again

    I already mentioned this a few times in my blog and some day, I need to look at it.

I'm also planning to do a mcs bug fixing session on Sunday and Monday.

Posted by martin at November 15, 2003 12:08 pm.

November 15, 2003 12:15 am (permalink)

Interfaces, inheritance and type parameters

While implementing generic interfaces, I realized we have some problems with type parameters and inheritance. Let's have a look at the following example:

interface Foo<S> { void Hello (S s); } interface Bar<T,U> : Foo<U> { void Test (T t, U u); }

Now let's assume we instantiate this as Bar<int,string> and try to call Hello() on it, like this:

class X { static void Test (Bar<int,string> bar) { bar.Hello ("World"); } }

We need to encode this as

IL_0000: ldarg.0 IL_0001: ldstr "Test" IL_0006: callvirt instance void class Foo<string>::Hello(!0)

Update: This is not a problem anymore :-) I blogged this tonight shortly before falling asleep and already fixed it this morning.

Posted by martin at November 15, 2003 12:15 am.

November 06, 2003 06:51 am (permalink)

Generic Collection Classes

The film was excellent :-) This weekend, I'll watch it a second time in Luxemburg - the big problem about german cinemas is that they're showing films in german ...

Today, I'm back in generics land. Ben just offered to help me implementing the System.Collections.Generic classes which is really great since I can now concentrate on gmcs stuff.

So let's have a look at the problems which impede gmcs from compiling these classes:

interface Foo<T> { } interface Bar<T> : Foo<T> { }

This example looks easy, but it's not because you could also do something like this:

interface Foo<T> { } interface Bar<T> : Foo<Bar<T>> { }

So we're in the same situation than in gen-23 here.


Btw. I was asked whether gmcs can compile "normal" code like corlib. Unfortunately, it can not and it's also not trivial to fix. Things like this (from test-48):

const int aaa = 1, bbb = 2;

are causing problems in the grammar.

Posted by martin at November 06, 2003 06:51 am.

November 05, 2003 11:46 am (permalink)

It's "Matrix" day today

Today, at 14:00 UTC - that's in 3 hours and 18 minutes - is the world premier of Matrix.

I'm one of the happy people who were able to get a ticket for it and - since our local cinema has numbered seats - I already know that I'll have an excellent one :-)

Posted by martin at November 05, 2003 11:46 am.

November 03, 2003 10:03 am (permalink)

Another "generic" week

I'm making really good progress with generics support and getting really happy about this :-)

At the moment, I'm concentrating on reflection and runtime stuff and try to make sure gmcs produces correct IL for all the gen-* tests in mcs/tests. This is now almost working and I'm really confident that I may fix the remaining issues today.

Latest update:
gmcs is now producing valid IL for all the tests; all tests except gen-21.exe are running with Mono (gen-21.exe is valid IL and runs under the MS runtime).

Posted by martin at November 03, 2003 10:03 am.