From d882fdfb2baa308049bdd6819bd9bead019a9de4 Mon Sep 17 00:00:00 2001 From: George Stagg Date: Sat, 13 Jul 2024 16:09:11 +0200 Subject: [PATCH] Re-enable bytecode interpreter --- R/Makefile | 3 -- .../R-4.4.1/emscripten-disable-bcEval.diff | 53 ------------------- patches/R-4.4.1/series | 1 - src/repl/App.tsx | 1 - src/tests/webR/webr-main.test.ts | 4 +- src/webR/webr-main.ts | 3 +- 6 files changed, 3 insertions(+), 62 deletions(-) delete mode 100644 patches/R-4.4.1/emscripten-disable-bcEval.diff diff --git a/R/Makefile b/R/Makefile index 4fec09b8..ecbc83cd 100644 --- a/R/Makefile +++ b/R/Makefile @@ -96,7 +96,6 @@ $(BUILD)/state/R-$(R_VERSION)/r-stage1-configured: $(BUILD)/state/R-$(R_VERSION) --enable-R-profiling=no \ --with-pcre2 \ --disable-nls \ - --enable-byte-compiled-packages=no \ --enable-long-double=no \ --enable-R-shlib touch $@ @@ -182,7 +181,6 @@ $(BUILD)/state/R-$(R_VERSION)/r-stage2-configured: $(BUILD)/state/R-$(R_VERSION) --enable-R-profiling=no \ --with-pcre2 \ --disable-nls \ - --enable-byte-compiled-packages=no \ --enable-static=yes \ --host=wasm32-unknown-emscripten \ --with-internal-tzcode @@ -248,7 +246,6 @@ $(BUILD)/state/R-$(R_VERSION)/r-stage2: $(BUILD)/state/R-$(R_VERSION)/r-stage1 $ .PHONY: Rprofile Rprofile: $(BUILD)/state/R-$(R_VERSION)/r-stage2 mkdir -p "$(R_WASM)/lib/R/etc/" - echo "options(expressions=400)" > "$(R_WASM)/lib/R/etc/Rprofile.site" echo "options(bitmapType='cairo')" >> "$(R_WASM)/lib/R/etc/Rprofile.site" .PHONY: install diff --git a/patches/R-4.4.1/emscripten-disable-bcEval.diff b/patches/R-4.4.1/emscripten-disable-bcEval.diff deleted file mode 100644 index 9d27c6d3..00000000 --- a/patches/R-4.4.1/emscripten-disable-bcEval.diff +++ /dev/null @@ -1,53 +0,0 @@ -Index: R-4.4.0/src/main/eval.c -=================================================================== ---- R-4.4.0.orig/src/main/eval.c -+++ R-4.4.0/src/main/eval.c -@@ -2350,6 +2350,7 @@ static R_INLINE SEXP R_execClosure(SEXP call, SEXP new - begincontext(&cntxt, CTXT_RETURN, call, newrho, sysparent, arglist, op); - - body = BODY(op); -+ #ifndef __EMSCRIPTEN__ - if (R_CheckJIT(op)) { - int old_enabled = R_jit_enabled; - R_jit_enabled = 0; -@@ -2357,6 +2358,7 @@ static R_INLINE SEXP R_execClosure(SEXP call, SEXP new - body = BODY(op); - R_jit_enabled = old_enabled; - } -+ #endif - - /* Get the srcref record from the closure object. The old srcref was - saved in cntxt. */ -@@ -4555,6 +4557,10 @@ static SEXP R_ConstantsRegistry = NULL; - instead of a weak reference, stays in the list forever, and is a GC root.*/ - static SEXP R_ConstantsRegistry = NULL; - -+#ifdef __EMSCRIPTEN__ -+#define NO_THREADED_CODE -+#endif -+ - #if defined(__GNUC__) && ! defined(BC_PROFILING) && (! defined(NO_THREADED_CODE)) - # define THREADED_CODE - #endif -@@ -7504,6 +7510,13 @@ static SEXP bcEval_loop(struct bcEval_locals *); - ! RSTEP(fun) && ! RDEBUG(rho) && \ - R_GlobalContext->callflag != CTXT_GENERIC) - -+#ifdef __EMSCRIPTEN__ -+/* Disable bytecode machine, significantly reduces Wasm binary size */ -+static inline SEXP bcEval(SEXP body, SEXP rho) -+{ -+ return eval(bytecodeExpr(body), rho); -+} -+#else - static SEXP bcEval_loop(struct bcEval_locals *); - - static SEXP bcEval(SEXP body, SEXP rho) -@@ -8723,6 +8736,7 @@ static SEXP bcEval_loop(struct bcEval_locals *ploc) - LASTOP; - } - } -+#endif - - #ifdef THREADED_CODE - static void bcEval_init(void) { diff --git a/patches/R-4.4.1/series b/patches/R-4.4.1/series index 4ac72465..faa062fe 100644 --- a/patches/R-4.4.1/series +++ b/patches/R-4.4.1/series @@ -7,7 +7,6 @@ emscripten-input.diff emscripten-disable-system.diff emscripten-jumpctxt.diff emscripten-xhr-download.diff -emscripten-disable-bcEval.diff emscripten-fix-blas-dlsym-search.diff emscripten-avoid-testing-issues.diff emscripten-r-home-stderr.diff diff --git a/src/repl/App.tsx b/src/repl/App.tsx index 0ddb9363..541e527a 100644 --- a/src/repl/App.tsx +++ b/src/repl/App.tsx @@ -17,7 +17,6 @@ const webR = new WebR({ REnv: { R_HOME: '/usr/lib/R', FONTCONFIG_PATH: '/etc/fonts', - R_ENABLE_JIT: '0', COLORTERM: 'truecolor', }, }); diff --git a/src/tests/webR/webr-main.test.ts b/src/tests/webR/webr-main.test.ts index 86623093..1038a063 100644 --- a/src/tests/webR/webr-main.test.ts +++ b/src/tests/webR/webr-main.test.ts @@ -1046,9 +1046,9 @@ test('Default and user provided REnv properties are merged', async () => { await tempR.init(); // Confirm default REnv settings - const jit = await tempR.evalRString('Sys.getenv("R_ENABLE_JIT")'); + const webr = await tempR.evalRString('Sys.getenv("WEBR")'); const home = await tempR.evalRString('Sys.getenv("R_HOME")'); - expect(jit).toEqual('0'); + expect(webr).toEqual('1'); expect(home).toEqual('/usr/lib/R'); // Confirm a user REnv setting diff --git a/src/webR/webr-main.ts b/src/webR/webr-main.ts index 76897cd5..248c8a67 100644 --- a/src/webR/webr-main.ts +++ b/src/webR/webr-main.ts @@ -123,7 +123,7 @@ export interface WebROptions { /** * Environment variables to be made available for the R process. - * Default: `{ R_HOME: '/usr/lib/R', R_ENABLE_JIT: 0 }`. + * Default: `{ R_HOME: '/usr/lib/R' }`. */ REnv?: { [key: string]: string }; @@ -174,7 +174,6 @@ export interface WebROptions { const defaultEnv = { FONTCONFIG_PATH: '/etc/fonts', R_HOME: '/usr/lib/R', - R_ENABLE_JIT: '0', WEBR: '1', WEBR_VERSION: WEBR_VERSION, };