Here is the same set of patches, for master, in case we want that.
>From a37033ed2aeceef85b529f49c7b79c2102ae482e Mon Sep 17 00:00:00 2001
From: Kooda <[email protected]>
Date: Sat, 21 Oct 2017 11:58:07 +0200
Subject: [PATCH 1/4] Sort the symbol table before outputing C code from the
 complier.

This helps make the compiler deterministic, as the output will not change
because of the random seeding of the symbol table.
---
 c-backend.scm | 73 ++++++++++++++++++++++++++++++++++++++---------------------
 1 file changed, 47 insertions(+), 26 deletions(-)

diff --git a/c-backend.scm b/c-backend.scm
index 3e742c9f..847f2eac 100644
--- a/c-backend.scm
+++ b/c-backend.scm
@@ -56,12 +56,25 @@
   (string->c-identifier
    (sprintf "C_~X_~A_" (random #x1000000) (current-seconds)) ) )
 
+;; Generate a sorted alist out of a symbol table
+(define (table->sorted-alist t)
+  (let ((alist '()))
+    (##sys#hash-table-for-each
+      (lambda (id ll)
+	(set! alist
+	  (cons (cons id ll) alist)))
+      t)
+
+    (sort! alist (lambda (p1 p2) (string<? (symbol->string (car p1))
+					   (symbol->string (car p2)))))))
+
 
 ;;; Generate target code:
 
 (define (generate-code literals lliterals lambda-table out source-file dynamic db
                        dbg-info-table)
-  (let ((non-av-proc #f))
+  (let ((lambda-table* (table->sorted-alist lambda-table))
+	(non-av-proc #f))
 
   ;; Don't truncate floating-point precision!
   (flonum-print-precision (+ flonum-maximum-decimal-exponent 1))
@@ -595,10 +608,12 @@
   
     (define (prototypes)
       (gen #t)
-      (##sys#hash-table-for-each
-       (lambda (id ll)
-	 (let* ((n (lambda-literal-argument-count ll))
-		(customizable (lambda-literal-customizable ll)) 
+      (for-each
+       (lambda (p)
+	 (let* ((id (car p))
+		(ll (cdr p))
+		(n (lambda-literal-argument-count ll))
+		(customizable (lambda-literal-customizable ll))
 		(empty-closure (and customizable (zero? (lambda-literal-closure-size ll))))
 		(varlist (intersperse (make-variable-list (if empty-closure (sub1 n) n) "t") #\,))
 		(rest (lambda-literal-rest-argument ll))
@@ -631,7 +646,7 @@
 	   ;;(when customizable (gen " C_c_regparm"))
 	   (unless direct (gen " C_noret"))
 	   (gen #\;) ))
-       lambda-table) )
+       lambda-table*) )
   
     (define (trampolines)
       (let ([ns '()]
@@ -644,9 +659,11 @@
 	      ((>= i n))
 	    (gen #t "C_word t" i "=av[" j "];")))
 
-	(##sys#hash-table-for-each
-	 (lambda (id ll)
-	   (let* ([argc (lambda-literal-argument-count ll)]
+	(for-each
+	 (lambda (p)
+	   (let* ([id (car p)]
+		  [ll (cdr p)]
+		  [argc (lambda-literal-argument-count ll)]
 		  [rest (lambda-literal-rest-argument ll)]
 		  [rest-mode (lambda-literal-rest-argument-mode ll)]
 		  [customizable (lambda-literal-customizable ll)]
@@ -661,7 +678,7 @@
 	       (let ([al (make-argument-list argc "t")])
 		 (apply gen (intersperse al #\,)) )
 	       (gen ");}") )))
-	 lambda-table)))
+	 lambda-table*)))
   
     (define (literal-frame)
       (do ([i 0 (add1 i)]
@@ -746,9 +763,11 @@
 	(else (bomb "invalid unboxed type" t))))
 
     (define (procedures)
-      (##sys#hash-table-for-each
-       (lambda (id ll)
-	 (let* ((n (lambda-literal-argument-count ll))
+      (for-each
+       (lambda (p)
+	 (let* ((id (car p))
+		(ll (cdr p))
+		(n (lambda-literal-argument-count ll))
 		(rname (real-name id db))
 		(demand (lambda-literal-allocated ll))
 		(max-av (apply max 0 (lambda-literal-callee-signatures ll)))
@@ -898,7 +917,7 @@
 		n)
 	    ll)
 	   (gen #\}) ) )
-       lambda-table) )
+       lambda-table*) )
 
     (debugging 'p "code generation phase...")
     (set! output out)
@@ -912,7 +931,7 @@
     (when emit-debug-info
       (emit-debug-table dbg-info-table))
     (procedures)
-    (emit-procedure-table lambda-table source-file)
+    (emit-procedure-table lambda-table* source-file)
     (trailer) ) )
 
 
@@ -934,18 +953,20 @@
 
 ;;; Emit procedure table:
 
-(define (emit-procedure-table lambda-table sf)
+(define (emit-procedure-table lambda-table* sf)
   (gen #t #t "#ifdef C_ENABLE_PTABLES"
-       #t "static C_PTABLE_ENTRY ptable[" (add1 (##sys#hash-table-size lambda-table)) "] = {")
-  (##sys#hash-table-for-each
-   (lambda (id ll)
-     (gen #t "{\"" id #\: (string->c-identifier sf) "\",(void*)")
-     (if (eq? 'toplevel id)
-         (if unit-name
-             (gen "C_" unit-name "_toplevel},")
-             (gen "C_toplevel},") )
-         (gen id "},") ) )
-   lambda-table)
+       #t "static C_PTABLE_ENTRY ptable[" (add1 (length lambda-table*)) "] = {")
+  (for-each
+   (lambda (p)
+     (let ((id (car p))
+	   (ll (cdr p)))
+       (gen #t "{\"" id #\: (string->c-identifier sf) "\",(void*)")
+       (if (eq? 'toplevel id)
+	   (if unit-name
+	       (gen "C_" unit-name "_toplevel},")
+	       (gen "C_toplevel},") )
+         (gen id "},") ) ) )
+   lambda-table*)
   (gen #t "{NULL,NULL}};")
   (gen #t "#endif")
   (gen #t #t "static C_PTABLE_ENTRY *create_ptable(void)")
-- 
2.15.0.rc1

>From 66bd8736aaf3261163b0226b4fe515088697d446 Mon Sep 17 00:00:00 2001
From: Kooda <[email protected]>
Date: Sat, 21 Oct 2017 13:25:33 +0200
Subject: [PATCH 2/4] Remove the date from the header comment of generated C
 files.

---
 c-backend.scm | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/c-backend.scm b/c-backend.scm
index 847f2eac..07cf45e6 100644
--- a/c-backend.scm
+++ b/c-backend.scm
@@ -536,19 +536,8 @@
       (expr node temps) )
   
     (define (header)
-      (define (pad0 n)
-	(if (< n 10)
-	    (string-append "0" (number->string n))
-	    n) )
-      (let* ((tm (##sys#decode-seconds (current-seconds) #f))
-	     (min (vector-ref tm 1))
-	     (hour (vector-ref tm 2))
-	     (mday (vector-ref tm 3))
-	     (mon (vector-ref tm 4))
-	     (year (vector-ref tm 5)) )
 	(gen "/* Generated from " source-file " by the CHICKEN compiler" #t
 	     "   http://www.call-cc.org"; #t
-	     "   " (+ 1900 year) #\- (pad0 (add1 mon)) #\- (pad0 mday) #\space (pad0 hour) #\: (pad0 min) #t
 	     (string-intersperse
 	      (map (cut string-append "   " <> "\n") 
 		   (string-split (chicken-version #t) "\n") ) 
@@ -567,8 +556,9 @@
 	  (gen #t)
 	  (for-each (lambda (decl) (gen #t decl)) foreign-declarations) )
 	(unless external-protos-first
-	  (generate-foreign-callback-stub-prototypes foreign-callback-stubs) ) ) )
+	  (generate-foreign-callback-stub-prototypes foreign-callback-stubs) ) )
   
+
     (define (trailer)
       (gen #t #t "/*" #t 
 	   (uncommentify
-- 
2.15.0.rc1

>From f689763b68d459801e038a4cf9e595eff0c0f206 Mon Sep 17 00:00:00 2001
From: Kooda <[email protected]>
Date: Sat, 21 Oct 2017 13:26:21 +0200
Subject: [PATCH 3/4] Make the building of .a files deterministic

---
 defaults.make | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/defaults.make b/defaults.make
index d6ee5319..4bb91160 100644
--- a/defaults.make
+++ b/defaults.make
@@ -154,7 +154,7 @@ LINKER_LIBRARY_SUFFIX ?=
 endif
 LINKER_LINK_SHARED_LIBRARY_OPTIONS ?= -shared
 LINKER_LINK_SHARED_DLOADABLE_OPTIONS ?= -shared -L.
-LIBRARIAN_OPTIONS ?= cru
+LIBRARIAN_OPTIONS ?= crD
 LIBRARIAN_OUTPUT_OPTION ?=
 LIBRARIAN_OUTPUT ?= $(LIBRARIAN_OUTPUT_OPTION) $@
 LIBRARIES ?= -lm
-- 
2.15.0.rc1

>From d045798eb176d0463f2378a39abd51e529e2062e Mon Sep 17 00:00:00 2001
From: Kooda <[email protected]>
Date: Sat, 21 Oct 2017 16:24:33 +0200
Subject: [PATCH 4/4] Remove the build tag completely.

---
 build-version.scm     | 3 ---
 defaults.make         | 1 -
 distribution/manifest | 1 -
 identify.sh           | 6 ------
 library.scm           | 4 +---
 rules.make            | 7 ++-----
 6 files changed, 3 insertions(+), 19 deletions(-)

diff --git a/build-version.scm b/build-version.scm
index 901adfb6..9539994d 100644
--- a/build-version.scm
+++ b/build-version.scm
@@ -27,8 +27,6 @@
 (declare
  (unit build-version))
 
-(foreign-declare "#include \"buildtag.h\"")
-
 ;; (read-version filename): Read line from FILENAME and return
 ;; as a string; return #f if non-existent file or blank line.
 (define-syntax read-version
@@ -41,7 +39,6 @@
 		  #f
 		  ver)))))))
 
-(define (##sys#build-tag)   (foreign-value "C_BUILD_TAG" c-string))
 (define ##sys#build-id      (read-version "buildid"))
 (define ##sys#build-branch  (read-version "buildbranch"))
 (define ##sys#build-version (read-version "buildversion"))
diff --git a/defaults.make b/defaults.make
index 4bb91160..25fa4e72 100644
--- a/defaults.make
+++ b/defaults.make
@@ -201,7 +201,6 @@ SCRIPT_EXT = .bat
 COPY_COMMAND = copy /Y
 HOSTNAME ?= $(shell hostname)
 UNAME_SYS ?= Windows
-BUILD_TAG ?= compiled $(BUILD_TIME) on $(HOSTNAME) ($(UNAME_SYS))
 # This is a poor man's version of $(file ...) in GNU Make 4.0
 # We should consider replacing it when it becomes so widespread
 # that systems (Debian, OS X, Haiku, Mingw, Cygwin) are shipping it
diff --git a/distribution/manifest b/distribution/manifest
index 67dd43db..9f081e6f 100644
--- a/distribution/manifest
+++ b/distribution/manifest
@@ -100,7 +100,6 @@ tcp.scm
 build-version.scm
 build-version.c
 buildid
-buildtag.h
 tests/thread-list.scm
 tests/data-structures-tests.scm
 tests/environment-tests.scm
diff --git a/identify.sh b/identify.sh
index 0a398d12..23912a29 100755
--- a/identify.sh
+++ b/identify.sh
@@ -12,7 +12,6 @@ fi
 
 rev0=`cat buildid || echo ""`
 branchname0=`cat buildbranch || echo ""`
-tag0=`cat buildtag.h || echo ""`
 buildtime=`date +%Y-%m-%d`
 host=`hostname`
 usys=`uname`
@@ -20,14 +19,12 @@ usys=`uname`
 if test -d "$1/.git"; then
     rev=`GIT_DIR="$1/.git" git rev-parse --short HEAD 2>/dev/null`
     branchname=`GIT_DIR="$1/.git" git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
-    tag="#define C_BUILD_TAG \"compiled ${buildtime} on ${host} (${usys})\""
 elif test -d "$1/manual-html"; then
     # Assume this is a snapshot or release build; don't touch
     # identifying files to avoid a rebuild which needs chicken
     exit
 else
     branchname=${branchname:-"custom"}
-    tag=${tag:-"#define C_BUILD_TAG \"compiled ${buildtime} on ${host} (${usys})\""}
 fi
 
 case "${branchname}" in
@@ -42,6 +39,3 @@ fi
 if test "x${branchname0}" \!= "x${branchname}"; then
     echo ${branchname} >buildbranch
 fi
-if test "x${tag0}" \!= "x${tag}"; then
-    echo ${tag} >buildtag.h
-fi
diff --git a/library.scm b/library.scm
index f7d1e918..f7f6fef3 100644
--- a/library.scm
+++ b/library.scm
@@ -3733,9 +3733,7 @@ EOF
 	 (get-config)
 	 (if (zero? (##sys#size spec))
 	     ""
-	     (string-append " [" spec " ]") )
-	 "\n"
-	 (or (##sys#build-tag) "")))
+	     (string-append " [" spec " ]") )))
       ##sys#build-version) )
 
 
diff --git a/rules.make b/rules.make
index 7e3a9e06..0ea7c7da 100644
--- a/rules.make
+++ b/rules.make
@@ -468,8 +468,6 @@ endif
 # build versioning
 
 ifdef WINDOWS_SHELL
-buildtag.h:
-	echo #define C_BUILD_TAG "$(BUILD_TAG)" >$@
 buildbranch:
 	echo.$(BRANCHNAME)>buildbranch
 buildid:
@@ -480,7 +478,6 @@ else
 identify-me:
 	@sh $(SRCDIR)identify.sh $(SRCDIR)
 
-buildtag.h: identify-me
 buildbranch: identify-me
 buildid: identify-me
 endif
@@ -557,7 +554,7 @@ stub.c: $(SRCDIR)stub.scm $(SRCDIR)common-declarations.scm
 debugger-client.c: $(SRCDIR)debugger-client.scm $(SRCDIR)common-declarations.scm dbg-stub.c
 	$(bootstrap-lib)
 build-version.c: $(SRCDIR)build-version.scm buildbranch buildid \
-	  $(SRCDIR)buildversion buildtag.h
+	  $(SRCDIR)buildversion
 	$(bootstrap-lib)
 
 define declare-bootstrap-import-lib
@@ -646,7 +643,7 @@ confclean:
 
 spotless: distclean testclean
 	-$(REMOVE_COMMAND) $(REMOVE_COMMAND_OPTIONS) $(DISTFILES) \
-	  buildtag.h buildid buildbranch
+	  buildid buildbranch
 
 
 distclean: clean confclean
-- 
2.15.0.rc1

_______________________________________________
Chicken-hackers mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/chicken-hackers

Reply via email to