[m-rev.] for review: fix bug with mutables in high-level C grades

Julien Fischer juliensf at cs.mu.OZ.AU
Mon Apr 10 14:52:09 AEST 2006


(This is still waiting on a bootcheck).

For review by anyone.


Estimated hours taken: 3
Branches: main, release

Fix a bug that has been causing tests/hard_coded/sub-modules/non_word_mutable
to fail in high-level C grades.

The bug occurred when we had a mutable declaration in the child module whose
type was a foreign type defined in the parent module and where that foreign
type relied on other C type definitions in a foreign_decl declaration in the
parent.  The problem was that the contents of the parent's foreign_decl pragma
were not visible in the child's .mih file at the point where the declarations
for the mutable variables were made.

The fix is to make sure that we #include all ancestor .mih files before any
foreign code declarations made by the child's .mih file.

compiler/mlds_to_c.m:
	Avoid the above problem.

compiler/modules.m:
	Update module qualifier syntax in a comment.

Julien.

Index: compiler/mlds_to_c.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.185
diff -u -r1.185 mlds_to_c.m
--- compiler/mlds_to_c.m	29 Mar 2006 08:07:05 -0000	1.185
+++ compiler/mlds_to_c.m	10 Apr 2006 04:20:10 -0000
@@ -636,9 +636,21 @@
     ;
         SymName = mlds_module_name_to_sym_name(ModuleName)
     ),
+
     DeclGuard = decl_guard(SymName),
     io.write_strings(["#ifndef ", DeclGuard, "\n#define ", DeclGuard, "\n"],
         !IO),
+    %
+    % We need to make sure we #include the .mih files for any ancestor modules
+    % in cases any foreign_types defined in them are referenced by the extern
+    % declarations required by mutables.
+    %
+    AncestorModuleNames = get_ancestors(SymName),
+    list.map(module_name_to_file_name, AncestorModuleNames, AncestorFileNames),
+    WriteAncestorInclude = (pred(Ancestor::in, !.IO::di, !:IO::uo) is det :-
+        io.write_strings(["#include \"", Ancestor, ".mih", "\"\n"], !IO)
+    ),
+    list.foldl(WriteAncestorInclude, AncestorFileNames, !IO),
     io.write_list(HeaderCode, "\n",
         mlds_output_c_hdr_decl(Indent, yes(foreign_decl_is_exported)), !IO),
     io.write_string("\n#endif\n", !IO).
Index: compiler/modules.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.384
diff -u -r1.384 modules.m
--- compiler/modules.m	29 Mar 2006 08:07:10 -0000	1.384
+++ compiler/modules.m	10 Apr 2006 03:52:56 -0000
@@ -70,7 +70,7 @@
     % Convert a module name and file extension to the corresponding file name.
     % If `MkDir' is yes, then create any directories needed.
     %
-    % Currently we use the convention that the module `foo:bar:baz' should be
+    % Currently we use the convention that the module `foo.bar.baz' should be
     % named `foo.bar.baz.m', and allow other naming conventions with the
     % `-f' option.
     %

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