[m-rev.] for review: mutables and intermodule optimization

Julien Fischer juliensf at cs.mu.OZ.AU
Fri Sep 16 17:04:24 AEST 2005


The following diff fixes a problem with mutables and intermodule optimization.
It raises a couple of issues:

Should the globals used to implement mutables be external or local?  Currently
they are the former, and I think this ought to be the case as doing otherwise
would prevent us inlining the access predicates across module boundaries.
(Another option here is to have a `local' attribute for the mutable and only
export clauses for the access predicates in the .opt  files if that attribute
is not set.)

We don't currently mangle the name the name of the global variable used to
implement a mutable (currently that's an XXX).  The diff below prefixes the
name of the global with that of the module.  It results in rather unwieldy
variable names on the C side of the FLI - which could be an annoyance for
writers of library bindings etc.

Some suggestions as to what could be done about this:

(1) Don't module qualify the global names - this means that the
    programmer has to ensure that conflicts don't occur.

(2) Module qualify them.

(3) Module qualify them, but allow the programmer to override that
    name if they wish, e.g a `foreign_name' attribute.

Opinions?


For review by anyone.

Estimated hours taken: 0.5
Branches: main

Make the declarations for the global variables used to implement mutables
visible across module boundaries.  This can be a problem if the access
predicates are inlined across module boundaries.

compiler/make_hlds_passes.m:
	Make sure that there is a declaration for the global variable
	in the module's .mh file.

compiler/prog_mutable.m:
	Append the module name to the name of the global variable
	used to implement the mutable.

	XXX We still need to sort out name mangling for mutables.


Julien.

Index: compiler/make_hlds_passes.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make_hlds_passes.m,v
retrieving revision 1.10
diff -u -r1.10 make_hlds_passes.m
--- compiler/make_hlds_passes.m	15 Sep 2005 07:38:43 -0000	1.10
+++ compiler/make_hlds_passes.m	16 Sep 2005 06:29:55 -0000
@@ -585,10 +585,16 @@
         %
         % XXX We don't currently support languages other than C.
         %
+        module_info_name(!.ModuleInfo, ModuleName),
         ForeignDecl = pragma(compiler(mutable_decl),
-            foreign_decl(c, foreign_decl_is_local,
-                "MR_Word " ++ mutable_c_var_name(Name) ++ ";")),
-        add_item_decl_pass_2(ForeignDecl, Context, !Status, !ModuleInfo, !IO)
+            foreign_decl(c, foreign_decl_is_exported,
+                "extern MR_Word " ++
+                    mutable_c_var_name(ModuleName, Name) ++ ";")),
+        add_item_decl_pass_2(ForeignDecl, Context, !Status, !ModuleInfo, !IO),
+        ForeignCode = pragma(compiler(mutable_decl),
+            foreign_code(c, "MR_Word " ++
+                mutable_c_var_name(ModuleName, Name) ++ ";")),
+        add_item_decl_pass_2(ForeignCode, Context, !Status, !ModuleInfo, !IO)
     ;
         true
     ).
@@ -910,7 +916,7 @@
         GetClause = pragma(compiler(mutable_decl), foreign_proc(GetAttrs,
             mutable_get_pred_sym_name(ModuleName, Name), predicate,
             [pragma_var(X, "X", out_mode(Inst))], VarSet,
-            ordinary("X = " ++ mutable_c_var_name(Name) ++ ";",
+            ordinary("X = " ++ mutable_c_var_name(ModuleName, Name) ++ ";",
                 yes(Context)))),
         add_item_clause(GetClause, !Status, Context, !ModuleInfo, !QualInfo,
             !IO),
@@ -921,13 +927,14 @@
         ;
             TrailCode =
                 "MR_trail_current_value(&" ++
-                mutable_c_var_name(Name) ++
+                mutable_c_var_name(ModuleName, Name) ++
                 ");\n"
         ),
         SetClause = pragma(compiler(mutable_decl), foreign_proc(Attrs,
             mutable_set_pred_sym_name(ModuleName, Name), predicate,
             [pragma_var(X, "X", in_mode(Inst))], VarSet,
-            ordinary(TrailCode ++ mutable_c_var_name(Name) ++ " = X;",
+            ordinary(TrailCode ++ mutable_c_var_name(ModuleName, Name)
+                    ++ " = X;",
                 yes(Context)))),
         add_item_clause(SetClause, !Status, Context, !ModuleInfo, !QualInfo,
             !IO)
Index: compiler/prog_mutable.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_mutable.m,v
retrieving revision 1.1
diff -u -r1.1 prog_mutable.m
--- compiler/prog_mutable.m	15 Sep 2005 07:38:45 -0000	1.1
+++ compiler/prog_mutable.m	16 Sep 2005 06:31:34 -0000
@@ -36,7 +36,7 @@

 :- func mutable_init_pred_sym_name(sym_name, string) = sym_name.

-:- func mutable_c_var_name(string) = string.
+:- func mutable_c_var_name(sym_name, string) = string.

 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
@@ -91,7 +91,8 @@
 mutable_init_pred_sym_name(ModuleName, Name) =
     qualified(ModuleName, "initialise_mutable_" ++ Name).

-mutable_c_var_name(Name) = "mutable_variable_" ++ Name.
+mutable_c_var_name(ModuleName, Name) =
+	sym_name_to_string(ModuleName, "__") ++ "__mutable_variable_" ++ Name.

 %-----------------------------------------------------------------------------%
 :- end_module prog_mutable.

--------------------------------------------------------------------------
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