[Mono-bugs] [Bug 76741][Wis] Changed - No runtime support for nullable types

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Sat Nov 19 18:08:31 EST 2005


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by bmaurer at users.sf.net.

http://bugzilla.ximian.com/show_bug.cgi?id=76741

--- shadow/76741	2005-11-17 19:49:09.000000000 -0500
+++ shadow/76741.tmp.30777	2005-11-19 18:08:31.000000000 -0500
@@ -46,6 +46,58 @@
 
 Unhandled Exception: System.InvalidCastException: Cannot cast from
 source type to destination type.
 in <0x00029> X:Z[Nullable`1] (System.Object o)
 in <0x00024> X:Main ()
 
+
+------- Additional Comments From bmaurer at users.sf.net  2005-11-19 18:08 -------
+Found some interesting, and somewhat helpful blogs on this:
+
+Overview of the change:
+http://blogs.msdn.com/somasegar/archive/2005/08/11/450640.aspx
+
+Consequences wrt Reflection:
+http://blogs.msdn.com/haibo_luo/archive/2005/08/23/455241.aspx
+
+For the box/unbox part of this change, the hard part looks like it is
+that we will need to add branches inside an instruction (again!) like
+castclass and isinst. Also, it is going to be a bit akward to add. We
+implement the unbox implementation in two steps:
+
+1) check that the cast is valid (ie that the object is-a Foo)
+2) Get the offset of the boxed data and add it to the base pointer
+
+In the new implementation we will have to:
+1) check for null (if it is null, just return an MP to a null Foo?)
+2) check that the cast to Foo is valid
+3) get the offset of the boxed data, copy it into a new Foo? which is
+on the stack, and set the not_null flag to false
+
+I was brainstorming a clean way to do this and came up with one
+possible implementation. What if we added the following methods to
+Nullable<T>:
+
+class Nullable<T> {
+
+    internal static object Box (T? t) {
+        if (t == null)
+             return null;
+        return t.Value;
+    }
+
+    internal static T? Unbox (object o)
+    {
+         if (o == null)
+              return o;
+         return (T) o;
+    }
+}
+
+
+This way, our inliner can take care of the BB splitting operations,
+which are sure to be somewhat unplesent. The only issue with this
+implementation would be that it will result in more runtime metadata
+being instantiated.
+
+Paolo, Zoltan, do you guys have any comments about the inlining based
+impl?


More information about the mono-bugs mailing list