[m-rev.] diff: implement array__make_empty_array on il backend.
Peter Ross
pro at missioncriticalit.com
Tue Dec 3 20:37:24 AEDT 2002
On Tue, Dec 03, 2002 at 06:55:40PM +1100, Fergus Henderson wrote:
> On 03-Dec-2002, Peter Ross <pro at missioncriticalit.com> wrote:
> > fjh wrote:
> >
> > > On 02-Dec-2002, Peter Ross <pro at missioncriticalit.com> wrote:
> > > > Implement array__make_empty_array on the IL backend.
> > > >
> > > > library/array.m:
> > > > Use the null pointer to signify an empty array in
> > > > array__make_empty_array. Check for this null pointer before
> > > > manipulating an array object in all the relevant places.
> > >
> > > I think this is a bad idea. IMHO we should represent empty arrays as
> > > arrays of length zero, not as null pointers. This is important for
> > > interoperability with other languages. Also, it's more efficient in
> > > the common case of non-empty arrays.
> >
> > I tried that first, by creating an array of size 0 with elem type of
> > System.Object. Unfortunately we will attempt to cast this array to a more
> > specific type in the code which uses this result, and get an invalid cast
> > exception. So there were two solutions. The easy one which was to use null
> > to signify the empty array. The more difficult one which was to write a lot
> > of code to determine the correct type name from the RTTI, remembering that
> > not all types map to high-level data names, and use the reflection framework
> > to get the representation of the type from the name. I took the easy one.
> >
> > A possible third solution would be to add an extra field to the RTTI which
> > has the type of a pointer to the IL representation of the Mercury type.
> > Then we could use the reflection framework to get the type. This I think
> > would be the best option, but again would take quite a lot of work.
> >
> > The current solution is the minimum amount of work which allows arrays to be
> > used.
>
> Well, I guess that is OK for now.
> But there should be an XXX comment in the source explaining this issue.
>
Hi,
===================================================================
Estimated hours taken: 0.25
Branches: main
library/array.m:
Document why we have chosen to represent arrays of size 0 as
the null pointer on the .NET backend.
Index: array.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/array.m,v
retrieving revision 1.117
diff -u -r1.117 array.m
--- array.m 2 Dec 2002 20:45:53 -0000 1.117
+++ array.m 3 Dec 2002 09:35:25 -0000
@@ -786,6 +786,13 @@
:- pragma foreign_proc("C#",
array__make_empty_array(Array::array_uo),
[will_not_call_mercury, promise_pure, thread_safe], "
+ // XXX A better solution then using the null pointer to represent
+ // the empty array would be to create an array of size 0. However
+ // we need to determine the element type of the array before we can
+ // do that. This could be done by examing the RTTI of the array
+ // type and then using System.Type.GetType(""<mercury type>"") to
+ // determine it. However constructing the <mercury type> string is
+ // a non-trival amount of work.
Array = null;
").
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list