[Git][ghc/ghc][master] 2 commits: JS: fix minor typo in base's jsbits

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Wed Aug 7 15:52:20 UTC 2024



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
39fd6714 by Sylvain Henry at 2024-08-07T11:51:52-04:00
JS: fix minor typo in base's jsbits

- - - - -
e7764575 by Sylvain Henry at 2024-08-07T11:51:52-04:00
RTS: remove hack to force old cabal to build a library with only JS sources

Need to extend JSC externs with Emscripten RTS definitions to avoid
JSC_UNDEFINED_VARIABLE errors when linking without the emcc rts.

Fix #25138

Some recompilation avoidance tests now fail. This is tracked with the
other instances of this failure in #23013. My hunch is that they were
working by chance when we used the emcc linker.

Metric Decrease:
    T24602_perf_size

- - - - -


7 changed files:

- compiler/GHC/StgToJS/Linker/Linker.hs
- libraries/ghc-internal/jsbits/base.js
- rts/js/mem.js
- rts/rts.cabal
- − rts/version.c
- testsuite/tests/driver/all.T
- testsuite/tests/driver/recomp011/all.T


Changes:

=====================================
compiler/GHC/StgToJS/Linker/Linker.hs
=====================================
@@ -795,14 +795,21 @@ rtsExterns =
     , "/** @extends {Uint8Array} @constructor */ function Buffer(arg1, encoding) {}"
     , "/** @return {!Buffer} */ Buffer.alloc = function() {}"
       -- Emscripten Module
+      -- Emscripten RTS's definitions we use in mem.js to support C sources.
+      -- When we link with emcc the actual definitions are linked, but when we
+      -- don't use C sources we don't use emcc and these variables are detected
+      -- as undefined.
     , "/** @type {*} */ var Module"
+    , "/** @type {!Int8Array} */ Module.HEAP8"
+    , "/** @type {!Uint8Array} */ Module.HEAPU8"
+    , "/** @return {number} */ Module.getEmptyTableSlot = function() {}"
+    , "/** @return {*} */ Module._free = function() {}"
+    , "/** @return {*} */ Module._malloc = function() {}"
       -- Mozilla's Narcissus (JS in JS interpreter implemented on top of SpiderMonkey) environment
     , "/** @type {*} */ var putstr"
     , "/** @type {*} */ var printErr"
       -- Apples's JavaScriptCore environment
     , "/** @type {*} */ var debug"
-      -- We use only Heap8 from Emscripten
-    , "/** @type {!Int8Array} */ Module.HEAP8"
     ])
 
 writeExterns :: FilePath -> IO ()


=====================================
libraries/ghc-internal/jsbits/base.js
=====================================
@@ -285,7 +285,7 @@ function h$rename(old_path, old_path_off, new_path, new_path_off) {
 #ifndef GHCJS_BROWSER
   if (h$isNode()) {
     try {
-      fs.renameSync(h$decodeUtf8z(old_path, old_path_off), h$decodeUtf8z(new_path, new_path_off));
+      h$fs.renameSync(h$decodeUtf8z(old_path, old_path_off), h$decodeUtf8z(new_path, new_path_off));
       return 0;
     } catch(e) {
       h$setErrno(e);
@@ -318,7 +318,7 @@ function h$realpath(path,off,resolved,resolved_off) {
 #ifndef GHCJS_BROWSER
   if (h$isNode()) {
     try {
-      var rp = h$encodeUtf8(fs.realpathSync(h$decodeUtf8z(path,off)));
+      var rp = h$encodeUtf8(h$fs.realpathSync(h$decodeUtf8z(path,off)));
       if (resolved !== null) {
         h$copyMutableByteArray(rp, 0, resolved, resolved_off, Math.min(resolved.len - resolved_off, rp.len));
         RETURN_UBX_TUP2(resolved, resolved_off);
@@ -1023,7 +1023,7 @@ function h$opendir(path) {
     throw "h$opendir unsupported";
   }
 
-  const d = fs.opendirSync(h$decodeUtf8z(path,0));
+  const d = h$fs.opendirSync(h$decodeUtf8z(path,0));
   RETURN_UBX_TUP2(d,0);
 }
 


=====================================
rts/js/mem.js
=====================================
@@ -1538,7 +1538,7 @@ function h$copyFromHeap(src, buf_d, buf_o, len) {
 
 // malloc and initialize a buffer on the HEAP
 function h$initHeapBufferLen(buf_d, buf_o, len) {
-  var buf_ptr = _malloc(len);
+  var buf_ptr = Module._malloc(len);
   h$copyToHeap(buf_d, buf_o, buf_ptr, len);
   return buf_ptr;
 }
@@ -1555,11 +1555,11 @@ function h$initHeapBuffer(str_d, str_o) {
 // temporarily malloc and initialize a buffer on the HEAP, pass it to the
 // continuation, then release the buffer
 function h$withOutBufferOnHeap(ptr_d, ptr_o, len, cont) {
-  var ptr = _malloc(len);
+  var ptr = Module._malloc(len);
   h$copyToHeap(ptr_d, ptr_o, ptr, len);
   var ret = cont(ptr);
   h$copyFromHeap(ptr, ptr_d, ptr_o, len);
-  _free(ptr);
+  Module._free(ptr);
   return ret;
 }
 
@@ -1567,10 +1567,10 @@ function h$withOutBufferOnHeap(ptr_d, ptr_o, len, cont) {
 // continuation. The buffer is freed from the heap when the continuation
 // returns.
 function h$withCBufferOnHeap(str_d, str_o, len, cont) {
-    var str = _malloc(len);
+    var str = Module._malloc(len);
     if(str_d !== null) h$copyToHeap(str_d, str_o, str, len);
     var ret = cont(str);
-    _free(str);
+    Module._free(str);
     return ret;
 }
 
@@ -1602,16 +1602,16 @@ function h$putHeapAddr(a,o,offset) {
 function h$copyCStringFromHeap(offset) {
   if(offset == 0) return null;
   var len = 0;
-  while(HEAPU8[offset+len] !== 0){ len++; };
+  while(Module.HEAPU8[offset+len] !== 0){ len++; };
   var str = h$newByteArray(len+1);
-  str.u8.set(HEAPU8.subarray(offset,offset+len+1));
+  str.u8.set(Module.HEAPU8.subarray(offset,offset+len+1));
   return str;
 }
 
 // get an array of n pointers from HEAP
 function h$copyPtrArrayFromHeap(offset,n) {
   var ptr = h$newByteArray(4*n);
-  ptr.u8.set(HEAPU8.subarray(offset, offset+4*n));
+  ptr.u8.set(Module.HEAPU8.subarray(offset, offset+4*n));
   return ptr;
 }
 
@@ -1641,13 +1641,15 @@ function h$registerFunPtrOnHeap(funptr_d, funptr_o, ask_ptr, ty, mkfn) {
   // same slot. Warning: this hack doesn't work if addFunction is called in
   // mkfn, but we check this with an assertion.
   if (ask_ptr) {
-    var cb_ptr = getEmptyTableSlot();
+    var cb_ptr = Module.getEmptyTableSlot();
     Module.removeFunction(cb_ptr);
 
     var cb  = mkfn(fun,cb_ptr);
     var ptr = Module.addFunction(cb,ty);
 
-    assert(cb_ptr === ptr, "h$registerJSFunPtrOnHeap: got different pointer offsets: " + cb_ptr + " and " + ptr);
+    if (cb_ptr !== ptr) {
+      throw ("h$registerJSFunPtrOnHeap: got different pointer offsets: " + cb_ptr + " and " + ptr);
+    }
     return ptr;
   }
   else {


=====================================
rts/rts.cabal
=====================================
@@ -94,9 +94,6 @@ library
     if arch(javascript)
 
       include-dirs: include
-      -- dummy file to force the build of a .a lib
-      -- FIXME (Luite, 2022-08) do we still need the c-sources file?
-      c-sources: version.c
 
       js-sources:
         js/config.js


=====================================
rts/version.c deleted
=====================================


=====================================
testsuite/tests/driver/all.T
=====================================
@@ -299,7 +299,7 @@ test('T18369', normal, compile, ['-O'])
 test('T21682', normal, compile_fail, ['-Werror=unrecognised-warning-flags -Wfoo'])
 test('FullGHCVersion', normal, compile_and_run, ['-package ghc-boot'])
 test('OneShotTH', req_th, makefile_test, [])
-test('T17481', normal, makefile_test, [])
+test('T17481', js_broken(23013), makefile_test, [])
 test('T20084', normal, makefile_test, [])
 test('RunMode', [req_interp,extra_files(['RunMode/Test.hs'])], run_command, ['{compiler} --run -iRunMode/ -ignore-dot-ghci RunMode.hs -- hello'])
 test('T20439', normal, run_command,


=====================================
testsuite/tests/driver/recomp011/all.T
=====================================
@@ -2,5 +2,6 @@
 
 test('recomp011',
      [ extra_files(['Main.hs'])
+     , js_broken(23013)
      ],
      makefile_test, [])



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d59faaf23dd5b0d8dbca50070f81a1969f50aa8f...e7764575538b65977f00f6ecff25ede78424816e

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d59faaf23dd5b0d8dbca50070f81a1969f50aa8f...e7764575538b65977f00f6ecff25ede78424816e
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240807/acb13919/attachment-0001.html>


More information about the ghc-commits mailing list