[m-dev.] Making the IL backend work (maybe)

Jonathan Morgan jonmmorgan at gmail.com
Mon Aug 21 10:54:38 AEST 2006


I have looked at the IL backend again, and the problem breaking it is
to do with dummy types.  The code it objects to is the following line
in io.init_state:
    io.set_op_table(ops.init_mercury_op_table, !IO)

ops.init_mercury_op_table is defined as following, which obviously
leads to a dummy type:

:- type ops.mercury_op_table
    --->    ops.mercury_op_table.

ops.init_mercury_op_table = ops.mercury_op_table.

The (invalid) lines of IL follow.  The problem is that the dummy type
is being constructed and then assigned to a dummy_var of type
mercury.ops.mercury_op_table_0, whereas private_builtin's dummy_var is
of type object[].

io.il:
newobj     instance void [mercury]mercury.ops.mercury_op_table_0::.ctor()
stsfld     class [mercury]mercury.ops.mercury_op_table_0
[mercury]mercury.private_builtin__csharp_code.mercury_code::dummy_var

private_builtin.m:
public static object[] dummy_var;

On the other hand, hlc.gc seems to completely optimise away the dummy
variable, and just calls the function without assigning the result to
anything:

    {
#line 4707 "io.m"
      mercury__ops__init_mercury_op_table_1_f_0();
    }

It seems to me that there are a few of ways to fix this problem - I'm
not sure how feasible any of them are.  One is to ignore dummy types
completely and return to the code generated before the introduction of
dummy types (using a local variable, and assigning the result to it,
rather than to private_builtin.dummy_var).  Another is to ensure that
all dummy types are cast to type Object[] before being assigned to
dummy_var (I'm not sure if this is possible - they could certainly be
cast to Object, but whether they could be cast to Object[] I don't
know).  Another is to ignore the return of the constructor completely,
like is done in hlc.gc (again, I don't know whether this is possible
in IL).

Also, below are a few more changes to make the IL backend build on the
release branch (I think the changes are applied to main).

Jon

===============================================================
Revert incorrect s/__/. in C# foreign code on the release branch.

--- private_builtin.m	Mon Jul 17 14:24:08 2006
+++ /installs/mercury-compiler-0.13.0-beta-2006-07-29/library/private_builtin.m	Sat
Aug 19 18:32:08 2006
@@ -1098,7 +1098,7 @@
 :- pragma foreign_code("C#", "

 public static bool
-special.Unify.private_builtin.heap_pointer_0_0(object[] x, object[] y)
+special__Unify__private_builtin__heap_pointer_0_0(object[] x, object[] y)
 {
     mercury.runtime.Errors.fatal_error(
         ""called unify for type `private_builtin:heap_pointer'"");
@@ -1106,7 +1106,7 @@
 }

 public static void
-special.Compare.private_builtin.heap_pointer_0_0(
+special__Compare__private_builtin__heap_pointer_0_0(
     ref object[] result, object[] x, object[] y)
 {
     mercury.runtime.Errors.fatal_error(
@@ -1114,14 +1114,14 @@
 }

 public static bool
-special.Unify.private_builtin.ref_1_0(
+special__Unify__private_builtin__ref_1_0(
     object[] type_info, object[] x, object[] y)
 {
     return x == y;
 }

 public static void
-special.Compare.private_builtin.ref_1_0(
+special__Compare__private_builtin__ref_1_0(
     object[] type_info, ref object[] result, object[] x, object[] y)
 {
     mercury.runtime.Errors.fatal_error(
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at csse.unimelb.edu.au
Administrative Queries: owner-mercury-developers at csse.unimelb.edu.au
Subscriptions:          mercury-developers-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the developers mailing list