[m-rev.] for review: fix bug #67

Peter Wang novalazy at gmail.com
Thu Jul 15 14:50:17 AEST 2010


On 2010-07-15, Peter Wang <novalazy at gmail.com> wrote:
> 
> Actually, it appears the underlying problem is that
> mercury_ho_call_inits.i and mercury_method_call_inits.i can be generated
> with duplicate MR_init_entry_an() lines -- probably due to make -jN.

For review.

Branches: main, 10.04

Fix bug #67, where mprof would abort due to multiple lines in the Prof.Decl
file having the same entry label.

The cause was the files runtime/mercury_ho_call_inits.i and
runtime/mercury_method_call_inits.i being generated with duplicate
MR_init_entry_an() lines.  That could happen if parallel make is used in the
runtime directory.  Due to bad makefile rules, the command which generates
the files (as side-effects) would be invoked multiple times, concurrently.
Finally, as those files weren't generated atomically, the concurrent
invocations would append duplicate lines to the files.

runtime/Mmakefile:
        Don't list multiple outputs as the result of the make_spec_ho_call and
        make_spec_method_call commands, which is the same as writing multiple
        independent rules, one for each output.

        Don't mention the *_declares.i and *_inits.i files at all.
        They will be created when the *_codes.i files are created.
        The downside is, if they are removed (and *_codes.i are not), then
        make will not know how to generate them.

tools/make_spec_ho_call:
tools/make_spec_method_call:
        Make these scripts generate the *_declares.i and *_inits.i files
        atomically (not strictly necessary with the previous change).

diff --git a/runtime/Mmakefile b/runtime/Mmakefile
index 39e9ba2..6f3f42a 100644
--- a/runtime/Mmakefile
+++ b/runtime/Mmakefile
@@ -316,30 +316,22 @@ mercury_profiling_builtin.h:	mercury_deep_call_port_body.h \
 	../tools/make_port_code
 
 mercury_ho_call.$(O):				mercury_ho_call_codes.i
-mercury_ho_call.$(O):				mercury_ho_call_declares.i
-mercury_ho_call.$(O):				mercury_ho_call_inits.i
 mercury_ho_call.$(O):				mercury_method_call_codes.i
-mercury_ho_call.$(O):				mercury_method_call_declares.i
-mercury_ho_call.$(O):				mercury_method_call_inits.i
 mercury_ho_call.$(EXT_FOR_PIC_OBJECTS):		mercury_ho_call_codes.i
-mercury_ho_call.$(EXT_FOR_PIC_OBJECTS):		mercury_ho_call_declares.i
-mercury_ho_call.$(EXT_FOR_PIC_OBJECTS):		mercury_ho_call_inits.i
 mercury_ho_call.$(EXT_FOR_PIC_OBJECTS):		mercury_method_call_codes.i
-mercury_ho_call.$(EXT_FOR_PIC_OBJECTS):		mercury_method_call_declares.i
-mercury_ho_call.$(EXT_FOR_PIC_OBJECTS):		mercury_method_call_inits.i
 
 # ../tools/make_spec_ho_call generates mercury_ho_call_declares.i
 # and mercury_ho_call_inits.i as side-effects.
-mercury_ho_call_codes.i \
-mercury_ho_call_declares.i \
-mercury_ho_call_inits.i: ../tools/make_spec_ho_call
+# These seems to be no decent way to express that, and have it work correctly
+# with parallel make.
+mercury_ho_call_codes.i: ../tools/make_spec_ho_call
 	../tools/make_spec_ho_call > mercury_ho_call_codes.i
 
 # ../tools/make_spec_method_call generates mercury_method_call_declares.i
 # and mercury_method_call_inits.i as side-effects.
-mercury_method_call_codes.i \
-mercury_method_call_declares.i \
-mercury_method_call_inits.i: ../tools/make_spec_method_call
+# These seems to be no decent way to express that, and have it work correctly
+# with parallel make.
+mercury_method_call_codes.i: ../tools/make_spec_method_call
 	../tools/make_spec_method_call > mercury_method_call_codes.i
 
 #-----------------------------------------------------------------------------#
diff --git a/tools/make_spec_ho_call b/tools/make_spec_ho_call
index 62a35a6..06e091a 100755
--- a/tools/make_spec_ho_call
+++ b/tools/make_spec_ho_call
@@ -7,8 +7,7 @@
 max_spec_explicit_arg=5
 max_spec_hidden_arg=5
 
-> mercury_ho_call_declares.i
-> mercury_ho_call_inits.i
+variants=""
 
 spec_explicit_arg=-1
 while test $spec_explicit_arg -le $max_spec_explicit_arg
@@ -123,8 +122,23 @@ do
     echo "}"
     echo
 
-    echo "MR_define_extern_entry(mercury__do_call_closure_$variant);" >> mercury_ho_call_declares.i
-    echo "    MR_init_entry_an(mercury__do_call_closure_$variant);" >> mercury_ho_call_inits.i
+    variants="$variants $variant"
 
     spec_explicit_arg=`expr $spec_explicit_arg + 1`
 done
+
+# Create these files atomically.
+
+{
+    for variant in $variants
+    do
+        echo "MR_define_extern_entry(mercury__do_call_closure_$variant);"
+    done
+} > mercury_ho_call_declares.i
+
+{
+    for variant in $variants
+    do
+        echo "    MR_init_entry_an(mercury__do_call_closure_$variant);"
+    done
+} > mercury_ho_call_inits.i
diff --git a/tools/make_spec_method_call b/tools/make_spec_method_call
index 5d5f44b..4ffabab 100755
--- a/tools/make_spec_method_call
+++ b/tools/make_spec_method_call
@@ -7,8 +7,7 @@
 max_spec_explicit_arg=6
 max_spec_hidden_arg=1
 
-> mercury_method_call_declares.i
-> mercury_method_call_inits.i
+variants=""
 
 spec_explicit_arg=-1
 while test $spec_explicit_arg -le $max_spec_explicit_arg
@@ -131,8 +130,23 @@ do
     echo "}"
     echo
 
-    echo "MR_define_extern_entry(mercury__do_call_class_method_$variant);" >> mercury_method_call_declares.i
-    echo "    MR_init_entry_an(mercury__do_call_class_method_$variant);" >> mercury_method_call_inits.i
+    variants="$variants $variant"
 
     spec_explicit_arg=`expr $spec_explicit_arg + 1`
 done
+
+# Create these files atomically.
+
+{
+    for variant in $variants
+    do
+        echo "MR_define_extern_entry(mercury__do_call_class_method_$variant);"
+    done
+} > mercury_method_call_declares.i
+
+{
+    for variant in $variants
+    do
+        echo "    MR_init_entry_an(mercury__do_call_class_method_$variant);"
+    done
+} > mercury_method_call_inits.i
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list