[m-rev.] [PATCH 2/4] Remove unnecessary detection of sync term size during configure.

Peter Wang novalazy at gmail.com
Thu Mar 20 10:47:56 AEDT 2014


The size of a sync term must be kept synchronised between the runtime
and the compiler.  The size is "detected" during configure by running
a small program whose output would always be the same.  It also doesn't
work for cross-compilation so a value is hard-coded in
configure_mingw_cross.  This is liable to be missed if the sync term
ever changes.

configure.ac:
	Hard code sync term size as it measures a number of detstack
	slots, which does not depend on architecture.

runtime/mercury_conf.h.in:
	Define MR_SYNC_TERM_SIZE.

runtime/mercury_std.h:
	Add MR_STATIC_ASSERT macro.

runtime/mercury_context.h:
	Check at compile time that the value of MR_SYNC_TERM_SIZE
	from configure.ac matches the real size.

tools/configure_mingw_cross:
	Delete mercury_cv_sync_term_size as no longer needed.
---
 configure.ac                | 41 +++++++----------------------------------
 runtime/mercury_conf.h.in   |  5 +++++
 runtime/mercury_context.h   |  3 +++
 runtime/mercury_std.h       | 10 ++++++++++
 tools/configure_mingw_cross |  1 -
 5 files changed, 25 insertions(+), 35 deletions(-)

diff --git a/configure.ac b/configure.ac
index f8f98f5..18a5388 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2061,40 +2061,6 @@ AC_SUBST(BYTES_PER_WORD)
 
 #-----------------------------------------------------------------------------#
 
-AC_MSG_CHECKING(the number of words in a synchronization term)
-AC_CACHE_VAL(mercury_cv_sync_term_size,
-    AC_TRY_RUN([
-    #include <stdio.h>
-    #include <stdlib.h>
-    #include <pthread.h>
-    int main() {
-        struct {
-            void        *orig_context;
-            void                    *parent_sp;
-            $mercury_cv_word_type   count;
-        } x;
-        FILE *fp;
-
-        fp = fopen("conftest.syncsize", "w");
-        if (fp == NULL)
-            exit(1);
-        fprintf(fp, "%d\n", (sizeof(void *) - 1 + sizeof(x))/
-                sizeof(void *));
-
-        exit(0);
-    }],
-    [mercury_cv_sync_term_size=`cat conftest.syncsize`],
-    [mercury_cv_sync_term_size=0],
-    [mercury_cv_sync_term_size=0])
-)
-mercury_cv_sync_term_size=`echo $mercury_cv_sync_term_size | tr -d '\r'`
-AC_MSG_RESULT($mercury_cv_sync_term_size)
-AC_DEFINE_UNQUOTED(MR_SYNC_TERM_SIZE, $mercury_cv_sync_term_size)
-SYNC_TERM_SIZE=$mercury_cv_sync_term_size
-AC_SUBST(SYNC_TERM_SIZE)
-
-#-----------------------------------------------------------------------------#
-
 AC_MSG_CHECKING(the number of bits per word)
 AC_CACHE_VAL(mercury_cv_bits_per_word,
     AC_TRY_RUN([
@@ -2213,6 +2179,13 @@ AC_SUBST(MR_LONG_DOUBLE_IS_64_BIT)
 
 #-----------------------------------------------------------------------------#
 
+# The number of detstack slots (words) that a MR_SyncTerm occupies.
+SYNC_TERM_SIZE=3
+AC_SUBST(SYNC_TERM_SIZE)
+AC_DEFINE_UNQUOTED(MR_SYNC_TERM_SIZE, $SYNC_TERM_SIZE)
+
+#-----------------------------------------------------------------------------#
+
 AC_MSG_CHECKING(whether architecture is big-endian)
 AC_CACHE_VAL(mercury_cv_is_bigender,
     AC_TRY_RUN([
diff --git a/runtime/mercury_conf.h.in b/runtime/mercury_conf.h.in
index b336dad..d8b8560 100644
--- a/runtime/mercury_conf.h.in
+++ b/runtime/mercury_conf.h.in
@@ -459,6 +459,11 @@
 #undef	MR_LONG_DOUBLE_IS_64_BIT
 
 /*
+** The number of detstack slots (words) per MR_SyncTerm.
+*/
+#undef	MR_SYNC_TERM_SIZE
+
+/*
 ** The following macros specify the ordering of bytes within
 ** are used by the bytecode compiler and the
 ** bytecode interpreter when writing/reading floats from/to bytecode files.
diff --git a/runtime/mercury_context.h b/runtime/mercury_context.h
index d184143..47cb294 100644
--- a/runtime/mercury_context.h
+++ b/runtime/mercury_context.h
@@ -789,6 +789,9 @@ extern  void        MR_schedule_context(MR_Context *ctxt);
     volatile MR_Unsigned    MR_st_count;
   };
 
+  MR_STATIC_ASSERT(mercury_context,
+    MR_SYNC_TERM_SIZE == MR_bytes_to_words(sizeof(struct MR_SyncTerm_Struct)));
+
 #ifdef MR_THREADSCOPE
   #define MR_init_sync_term(sync_term, nbranches, static_conj_id)             \
     do {                                                                      \
diff --git a/runtime/mercury_std.h b/runtime/mercury_std.h
index 0f68690..eaf5d8b 100644
--- a/runtime/mercury_std.h
+++ b/runtime/mercury_std.h
@@ -312,6 +312,16 @@ typedef	char		MR_small_bool;
 #define MR_CHECK_EXPR_TYPE(expr, type) \
 	((void) sizeof(*(type *)NULL = (expr)))
 
+/*
+** MR_STATIC_ASSERT(module, expr):
+** Assert at compile time that the given expression is true.
+** A named bit-field may not have zero width.
+*/
+
+#define MR_STATIC_ASSERT(module, expr) \
+    struct MR_PASTE4(static_assert_, module, _line_, __LINE__) \
+	{ unsigned int bf : !!(expr); }
+
 /*---------------------------------------------------------------------------*/
 
 #define MR_SORRY(msg) MR_fatal_error("Sorry, not yet implemented: " msg);
diff --git a/tools/configure_mingw_cross b/tools/configure_mingw_cross
index 3f43e69..98bc968 100755
--- a/tools/configure_mingw_cross
+++ b/tools/configure_mingw_cross
@@ -66,7 +66,6 @@ mercury_cv_int_least32_type=int \
 mercury_cv_int_least16_type=short \
 mercury_cv_low_tag_bits=2 \
 mercury_cv_bytes_per_word=4 \
-mercury_cv_sync_term_size=3 \
 mercury_cv_bits_per_word=32 \
 mercury_cv_unboxed_floats=no \
 mercury_cv_float_is_64_bit=no \
-- 
1.8.4




More information about the reviews mailing list