emscripten icon indicating copy to clipboard operation
emscripten copied to clipboard

Add new proxying modes foo__proxy: 'abort' and foo__proxy: 'abort_debug'

Open juj opened this issue 1 year ago • 3 comments

Add new proxying modes foo__proxy: 'abort' and foo__proxy: 'abort_debug', which will add compile time checks to verify that given JS function is not called in pthreads or Wasm Workers.

juj avatar Sep 27 '24 13:09 juj

How to fix the lint errors?

C:\emsdk\emscripten\main>npm run lint --write

...

  1:4384  error  Strings must use singlequote   quotes
  1:4417  error  Operator '=' must be spaced    space-infix-ops
  1:4418  error  Strings must use singlequote   quotes
  1:4438  error  Operator '=' must be spaced    space-infix-ops
  1:4487  error  Operator '=' must be spaced    space-infix-ops
  1:4501  error  Operator '=' must be spaced    space-infix-ops
  1:4502  error  Strings must use singlequote   quotes
  1:4516  error  Operator '=' must be spaced    space-infix-ops
  1:4518  error  Operator '+' must be spaced    space-infix-ops
  1:4519  error  Strings must use singlequote   quotes
  1:4539  error  Operator '&&' must be spaced   space-infix-ops
  1:4555  error  Operator '=' must be spaced    space-infix-ops
  1:4556  error  Strings must use singlequote   quotes
  1:4579  error  Operator '=' must be spaced    space-infix-ops
  1:4597  error  Operator '=' must be spaced    space-infix-ops
  1:4612  error  Operator '=' must be spaced    space-infix-ops
  1:4628  error  Operator '=' must be spaced    space-infix-ops
  1:4629  error  Strings must use singlequote   quotes
  1:4682  error  Operator '-' must be spaced    space-infix-ops
  1:4731  error  Operator '-' must be spaced    space-infix-ops
  1:4762  error  Operator '=' must be spaced    space-infix-ops
  1:4783  error  Operator '=' must be spaced    space-infix-ops
  1:4789  error  Operator '=' must be spaced    space-infix-ops
  1:4795  error  Operator '=' must be spaced    space-infix-ops
  1:4805  error  Operator '=' must be spaced    space-infix-ops
  1:4816  error  Operator '=' must be spaced    space-infix-ops
  1:4835  error  Operator '=' must be spaced    space-infix-ops
  1:4855  error  Operator '=' must be spaced    space-infix-ops
  1:4875  error  Operator '=' must be spaced    space-infix-ops
  1:4895  error  Operator '=' must be spaced    space-infix-ops
  1:4916  error  Operator '=' must be spaced    space-infix-ops
  1:4937  error  Operator '=' must be spaced    space-infix-ops

✖ 26511 problems (26511 errors, 0 warnings)
  26507 errors and 0 warnings potentially fixable with the `--fix` option.


C:\emsdk\emscripten\main>git diff

C:\emsdk\emscripten\main>npm run check

> check
> prettier --check src/*.mjs tools/*.mjs

Checking formatting...
[warn] src/compiler.mjs
[warn] src/jsifier.mjs
[warn] src/modules.mjs
[warn] src/parseTools_legacy.mjs
[warn] src/parseTools.mjs
[warn] src/utility.mjs
[warn] tools/acorn-optimizer.mjs
[warn] tools/lz4-compress.mjs
[warn] tools/preprocessor.mjs
[warn] tools/unsafe_optimizations.mjs
[warn] Code style issues found in 10 files. Run Prettier with --write to fix.

C:\emsdk\emscripten\main>npm run check --write

> check
> prettier --check src/*.mjs tools/*.mjs

Checking formatting...
[warn] src/compiler.mjs
[warn] src/jsifier.mjs
[warn] src/modules.mjs
[warn] src/parseTools_legacy.mjs
[warn] src/parseTools.mjs
[warn] src/utility.mjs
[warn] tools/acorn-optimizer.mjs
[warn] tools/lz4-compress.mjs
[warn] tools/preprocessor.mjs
[warn] tools/unsafe_optimizations.mjs
[warn] Code style issues found in 10 files. Run Prettier with --write to fix.

C:\emsdk\emscripten\main>npm run check --write

C:\emsdk\emscripten\main>git diff

C:\emsdk\emscripten\main>prettier --check src/*.mjs tools/*.mjs
'prettier' is not recognized as an internal or external command,
operable program or batch file.

C:\emsdk\emscripten\main>npm prettier --check src/*.mjs tools/*.mjs
Unknown command: "prettier"

To see a list of supported npm commands, run:
  npm help

juj avatar Sep 27 '24 14:09 juj

Seems reasonable if there is use case for it. Are there existing system library function that you had in mind when designing this attribute?

I scanned library_browser.js and library_wasm_worker.js to see if there might be functions like this, but none stood out.

The motivation for adding this is that at Unity I am seeing more and more feature developers add their own JS functions, and they generally copy-paste the __proxy: 'sync' directives when they are unsure about what that means.

Many of these JS library functions should never use proxying, but we only ever call those JS functions in the main browser thread - if any pthread might call any of those JS functions, there would be trouble. So that is I why I wanted to make the proxying mechanism check this for me: by documenting each function that should be strictly main thread only, I can run the test suites to confirm that it indeeds happens to be the case, and that we are not getting any surprising unwanted proxying taking effect.

juj avatar Sep 30 '24 12:09 juj

It looks like there is this wholesale proxy: 'sync' directive that is happening with the filesystem, so changed https://github.com/emscripten-core/emscripten/pull/22648/files#diff-5de5cdf403acefc1dc87b4446a186049adc104ceca678d993f3d5a007bcafcc5R273 to make tests pass. fd_write is also called in Wasm Workers.

juj avatar Sep 30 '24 12:09 juj

I'll close this for later when I have time to split up the PR.

juj avatar Aug 16 '25 06:08 juj