Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigInt literals in JS libraries do not compile #13297

Closed
juj opened this issue Jan 21, 2021 · 13 comments
Closed

BigInt literals in JS libraries do not compile #13297

juj opened this issue Jan 21, 2021 · 13 comments

Comments

@juj
Copy link
Collaborator

juj commented Jan 21, 2021

a.c

#include <emscripten.h>
void foo(void);
int main() { foo(); }

a.js

mergeInto(LibraryManager.library, {
	foo: function() {
		console.log(1n);
	}
});
emcc a.c --js-library a.js -o o.js -O2

outputs

E:\code\emsdk\emscripten\master\third_party\terser\terser.js:6857
                expr.print(output);
                     ^

TypeError: Cannot read property 'print' of undefined
    at E:\code\emsdk\emscripten\master\third_party\terser\terser.js:6857:22
    at Array.forEach (<anonymous>)
    at E:\code\emsdk\emscripten\master\third_party\terser\terser.js:6855:23
    at Object.with_parens (E:\code\emsdk\emscripten\master\third_party\terser\terser.js:5765:19)
    at E:\code\emsdk\emscripten\master\third_party\terser\terser.js:6854:16
    at doit (E:\code\emsdk\emscripten\master\third_party\terser\terser.js:5999:13)
    at AST_Call.<anonymous> (E:\code\emsdk\emscripten\master\third_party\terser\terser.js:6006:13)
    at E:\code\emsdk\emscripten\master\third_party\terser\terser.js:6309:19
    at doit (E:\code\emsdk\emscripten\master\third_party\terser\terser.js:5999:13)
    at AST_SimpleStatement.<anonymous> (E:\code\emsdk\emscripten\master\third_party\terser\terser.js:6006:13)
emcc: error: 'E:/code/emsdk/node/12.18.1_64bit/bin/node.exe E:\code\emsdk\emscripten\master\tools\acorn-optimizer.js C:\Users\jukkaj\AppData\Local\Temp\emscripten_temp_1zqpdmu4\a.js JSDCE minifyWhitespace' failed (1)

it looks like acorn is unable to parse 1n.

Quickly glancing at our version usage, acorn-optimizer.js does have ecmaVersion: 2020, but that does not seem to be enough?

@sbc100
Copy link
Collaborator

sbc100 commented Jan 21, 2021

Looks like there is plan for upgrade #12410. I would hope that fixing that would also fix this?

@kripken
Copy link
Member

kripken commented Jan 22, 2021

Yes, an upgrade is needed. For now, BigInt(1) etc. is a workaround.

@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.

@stale stale bot added the wontfix label Apr 16, 2022
@hoodmane
Copy link
Contributor

@sbc100 is this fixed?

@stale stale bot removed the wontfix label Jun 24, 2022
@sbc100
Copy link
Collaborator

sbc100 commented Jun 27, 2022

Yes!

@sbc100 sbc100 closed this as completed Jun 27, 2022
@firasdib
Copy link

firasdib commented Jul 15, 2022

I'm still getting this error after pulling the latest changes from this repository. What am I missing :)?

Edit:
I only get this error when I use USE_ES6_IMPORT_META=0

@sbc100
Copy link
Collaborator

sbc100 commented Jul 15, 2022

@firasdib what error exactly are you seeing? Which version of emscripten works for and which one breaks? How are you installing emscripten?

@firasdib
Copy link

I cloned the repo and ran:

git pull
./emsdk install latest
./emsdk activate latest
source "/home/firas/projects/emsdk/emsdk_env.sh"

After compiling .NET 7 with USE_ES6_IMPORT_META=0 I get the following error:

MSBuild version 17.3.0-preview-22329-01+77c72dd0f for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
/home/firas/projects/dotnet/sdk/7.0.100-preview.6.22352.1/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.RuntimeIdentifierInference.targets(219,5): message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy [/home/firas/projects/regex101-app/emscripten/dotnet/Regex101/Regex101.csproj]
  Microsoft.JSInterop.WebAssembly -> /home/firas/projects/regex101-app/emscripten/dotnet/JSInterop/bin/Release/net7.0/Microsoft.JSInterop.WebAssembly.dll
  Regex101 -> /home/firas/projects/regex101-app/emscripten/dotnet/Regex101/bin/Release/net7.0/Regex101.dll
  Regex101 (Blazor output) -> /home/firas/projects/regex101-app/emscripten/dotnet/Regex101/bin/Release/net7.0/wwwroot
  Optimizing assemblies for size may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
  Optimizing assemblies for size. This process might take a while.
  Microsoft.JSInterop.WebAssembly -> /home/firas/projects/regex101-app/emscripten/dotnet/JSInterop/bin/Release/net7.0/Microsoft.JSInterop.WebAssembly.dll
  Optimizing assemblies for size may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
  AOT'ing 9 assemblies
  Compiling native assets with emcc with -O3 -s ENVIRONMENT="worker". This may take a while ...
  [1/3] corebindings.c -> corebindings.o [took 0.118s]
  [2/3] pinvoke.c -> pinvoke.o [took 0.163s]
  [3/3] driver.c -> driver.o [took 0.164s]
  Compiling assembly bitcode files with -O3 -s ENVIRONMENT="worker" -s USE_ES6_IMPORT_META=0 ...
  [1/8] System.Runtime.dll.bc -> System.Runtime.dll.o [took 0.107s]
  [2/8] System.Collections.dll.bc -> System.Collections.dll.o [took 0.164s]
  [3/8] Regex101.dll.bc -> Regex101.dll.o [took 0.283s]
  [4/8] System.Collections.Concurrent.dll.bc -> System.Collections.Concurrent.dll.o [took 0.337s]
  [5/8] System.Runtime.InteropServices.JavaScript.dll.bc -> System.Runtime.InteropServices.JavaScript.dll.o [took 0.632s]
  [6/8] System.Private.Uri.dll.bc -> System.Private.Uri.dll.o [took 1.403s]
  [7/8] System.Text.RegularExpressions.dll.bc -> System.Text.RegularExpressions.dll.o [took 7.091s]
  [8/8] System.Private.CoreLib.dll.bc -> System.Private.CoreLib.dll.o [took 12.505s]
  Linking with emcc with -O3 -s ENVIRONMENT="worker" -s USE_ES6_IMPORT_META=0. This may take a while ...
   "/home/firas/projects/emsdk/upstream/bin/wasm-ld" -o /home/firas/projects/regex101-app/emscripten/dotnet/Regex101/obj/Release/net7.0/wasm/for-publish/dotnet.wasm --allow-undefined --allow-undefined /home/firas/projects/regex101-app/emscripten/dotnet/Regex101/obj/Release/net7.0/wasm/for-publish/Regex101.dll.o /home/firas/projects/regex101-app/emscripten/dotnet/Regex101/obj/Release/net7.0/wasm/for-publish/System.Collections.Concurrent.dll.o /home/firas/projects/regex101-app/emscripten/dotnet/Regex101/obj/Release/net7.0/wasm/for-publish/System.Collections.dll.o /home/firas/projects/regex101-app/emscripten/dotnet/Regex101/obj/Release/net7.0/wasm/for-publish/System.Private.Uri.dll.o /home/firas/projects/regex101-app/emscripten/dotnet/Regex101/obj/Release/net7.0/wasm/for-publish/System.Runtime.InteropServices.JavaScript.dll.o /home/firas/projects/regex101-app/emscripten/dotnet/Regex101/obj/Release/net7.0/wasm/for-publish/System.Runtime.dll.o /home/firas/projects/regex101-app/emscripten/dotnet/Regex101/obj/Release/net7.0/wasm/for-publish/System.Text.RegularExpressions.dll.o /home/firas/projects/regex101-app/emscripten/dotnet/Regex101/obj/Release/net7.0/wasm/for-publish/System.Private.CoreLib.dll.o /home/firas/projects/regex101-app/emscripten/dotnet/Regex101/obj/Release/net7.0/wasm/for-publish/pinvoke.o /home/firas/projects/regex101-app/emscripten/dotnet/Regex101/obj/Release/net7.0/wasm/for-publish/driver.o /home/firas/projects/regex101-app/emscripten/dotnet/Regex101/obj/Release/net7.0/wasm/for-publish/corebindings.o /home/firas/projects/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.browser-wasm/7.0.0-rc.1.22364.7/runtimes/browser-wasm/native/libicudata.a /home/firas/projects/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.browser-wasm/7.0.0-rc.1.22364.7/runtimes/browser-wasm/native/libicui18n.a /home/firas/projects/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.browser-wasm/7.0.0-rc.1.22364.7/runtimes/browser-wasm/native/libicuuc.a /home/firas/projects/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.browser-wasm/7.0.0-rc.1.22364.7/runtimes/browser-wasm/native/libmono-component-debugger-stub-static.a /home/firas/projects/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.browser-wasm/7.0.0-rc.1.22364.7/runtimes/browser-wasm/native/libmono-component-diagnostics_tracing-stub-static.a /home/firas/projects/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.browser-wasm/7.0.0-rc.1.22364.7/runtimes/browser-wasm/native/libmono-component-hot_reload-stub-static.a /home/firas/projects/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.browser-wasm/7.0.0-rc.1.22364.7/runtimes/browser-wasm/native/libmono-ee-interp.a /home/firas/projects/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.browser-wasm/7.0.0-rc.1.22364.7/runtimes/browser-wasm/native/libmono-icall-table.a /home/firas/projects/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.browser-wasm/7.0.0-rc.1.22364.7/runtimes/browser-wasm/native/libmono-ilgen.a /home/firas/projects/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.browser-wasm/7.0.0-rc.1.22364.7/runtimes/browser-wasm/native/libmono-profiler-aot.a /home/firas/projects/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.browser-wasm/7.0.0-rc.1.22364.7/runtimes/browser-wasm/native/libmono-wasm-eh-js.a /home/firas/projects/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.browser-wasm/7.0.0-rc.1.22364.7/runtimes/browser-wasm/native/libmonosgen-2.0.a /home/firas/projects/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.browser-wasm/7.0.0-rc.1.22364.7/runtimes/browser-wasm/native/libSystem.IO.Compression.Native.a /home/firas/projects/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.browser-wasm/7.0.0-rc.1.22364.7/runtimes/browser-wasm/native/libSystem.Native.a /home/firas/projects/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.browser-wasm/7.0.0-rc.1.22364.7/runtimes/browser-wasm/native/libSystem.Security.Cryptography.Native.Browser.a -L/home/firas/.emscripten_cache/sysroot/lib/wasm32-emscripten -lGL -lal -lhtml5 -lstubs -lnoexit -lc -ldlmalloc -lcompiler_rt -lc++ -lc++abi -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-cxx-exceptions -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --import-undefined --export-if-defined=malloc --export-if-defined=memalign --export-if-defined=memset --export-if-defined=htons --export-if-defined=ntohs --export-if-defined=free --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export=stackSave --export=stackRestore --export=stackAlloc --export=__wasm_call_ctors --export=__errno_location --export=malloc --export=free --export=__cxa_is_pointer_type --export=__cxa_can_catch --export=setThrew --export=ntohs --export=htons --export=__dl_seterr --export=htonl --export=emscripten_builtin_memalign --export-table -z stack-size=5242880 --initial-memory=536870912 --no-entry --max-memory=2147483648 --global-base=1024
   "/home/firas/projects/emsdk/upstream/bin/wasm-emscripten-finalize" -g --dyncalls-i64 /home/firas/projects/regex101-app/emscripten/dotnet/Regex101/obj/Release/net7.0/wasm/for-publish/dotnet.wasm -o /home/firas/projects/regex101-app/emscripten/dotnet/Regex101/obj/Release/net7.0/wasm/for-publish/dotnet.wasm --detect-features
   "/home/firas/projects/emsdk/node/14.18.2_64bit/bin/node" /home/firas/projects/dotnet/packs/Microsoft.NET.Runtime.Emscripten.3.1.12.Sdk.linux-x64/7.0.0-rc.1.22362.2/tools/emscripten/src/compiler.js /tmp/tmprkzytlmn.json
   "/home/firas/projects/emsdk/upstream/bin/wasm-opt" --strip-dwarf --post-emscripten -O3 --low-memory-unused --zero-filled-memory --strip-debug --strip-producers /home/firas/projects/regex101-app/emscripten/dotnet/Regex101/obj/Release/net7.0/wasm/for-publish/dotnet.wasm -o /home/firas/projects/regex101-app/emscripten/dotnet/Regex101/obj/Release/net7.0/wasm/for-publish/dotnet.wasm -g --mvp-features --enable-mutable-globals
   "/home/firas/projects/emsdk/node/14.18.2_64bit/bin/node" /home/firas/projects/dotnet/packs/Microsoft.NET.Runtime.Emscripten.3.1.12.Sdk.linux-x64/7.0.0-rc.1.22362.2/tools/emscripten/tools/acorn-optimizer.js /tmp/emscripten_temp_pdebyfyf/dotnet.js.pp.js AJSDCE minifyWhitespace --exportES6
  /home/firas/projects/dotnet/packs/Microsoft.NET.Runtime.Emscripten.3.1.12.Sdk.linux-x64/7.0.0-rc.1.22362.2/tools/emscripten/third_party/terser/terser.js:7192
            expr.print(output);
                 ^
  
  TypeError: Cannot read property 'print' of undefined
      at /home/firas/projects/dotnet/packs/Microsoft.NET.Runtime.Emscripten.3.1.12.Sdk.linux-x64/7.0.0-rc.1.22362.2/tools/emscripten/third_party/terser/terser.js:7192:16
      at doit (/home/firas/projects/dotnet/packs/Microsoft.NET.Runtime.Emscripten.3.1.12.Sdk.linux-x64/7.0.0-rc.1.22362.2/tools/emscripten/third_party/terser/terser.js:6289:15)
      at AST_Dot.<anonymous> (/home/firas/projects/dotnet/packs/Microsoft.NET.Runtime.Emscripten.3.1.12.Sdk.linux-x64/7.0.0-rc.1.22362.2/tools/emscripten/third_party/terser/terser.js:6296:15)
      at /home/firas/projects/dotnet/packs/Microsoft.NET.Runtime.Emscripten.3.1.12.Sdk.linux-x64/7.0.0-rc.1.22362.2/tools/emscripten/third_party/terser/terser.js:7157:24
      at Array.forEach (<anonymous>)
      at /home/firas/projects/dotnet/packs/Microsoft.NET.Runtime.Emscripten.3.1.12.Sdk.linux-x64/7.0.0-rc.1.22362.2/tools/emscripten/third_party/terser/terser.js:7155:25
      at Object.with_parens (/home/firas/projects/dotnet/packs/Microsoft.NET.Runtime.Emscripten.3.1.12.Sdk.linux-x64/7.0.0-rc.1.22362.2/tools/emscripten/third_party/terser/terser.js:6044:21)
      at /home/firas/projects/dotnet/packs/Microsoft.NET.Runtime.Emscripten.3.1.12.Sdk.linux-x64/7.0.0-rc.1.22362.2/tools/emscripten/third_party/terser/terser.js:7154:18
      at doit (/home/firas/projects/dotnet/packs/Microsoft.NET.Runtime.Emscripten.3.1.12.Sdk.linux-x64/7.0.0-rc.1.22362.2/tools/emscripten/third_party/terser/terser.js:6289:15)
      at AST_Call.<anonymous> (/home/firas/projects/dotnet/packs/Microsoft.NET.Runtime.Emscripten.3.1.12.Sdk.linux-x64/7.0.0-rc.1.22362.2/tools/emscripten/third_party/terser/terser.js:6296:15)
emcc : error : '/home/firas/projects/emsdk/node/14.18.2_64bit/bin/node /home/firas/projects/dotnet/packs/Microsoft.NET.Runtime.Emscripten.3.1.12.Sdk.linux-x64/7.0.0-rc.1.22362.2/tools/emscripten/tools/acorn-optimizer.js /tmp/emscripten_temp_pdebyfyf/dotnet.js.pp.js AJSDCE minifyWhitespace --exportES6' failed (returned 1) [/home/firas/projects/regex101-app/emscripten/dotnet/Regex101/Regex101.csproj]
/home/firas/projects/dotnet/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/7.0.0-rc.1.22364.7/Sdk/WasmApp.Native.targets(422,5): error MSB3073: The command "emcc "@/home/firas/projects/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.browser-wasm/7.0.0-rc.1.22364.7/runtimes/browser-wasm/native/src/emcc-default.rsp" "@/home/firas/projects/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.browser-wasm/7.0.0-rc.1.22364.7/runtimes/browser-wasm/native/src/emcc-link.rsp" "@/home/firas/projects/regex101-app/emscripten/dotnet/Regex101/obj/Release/net7.0/wasm/for-publish/emcc-link.rsp"" exited with code 1. [/home/firas/projects/regex101-app/emscripten/dotnet/Regex101/Regex101.csproj]

@sbc100
Copy link
Collaborator

sbc100 commented Jul 17, 2022

Can you try building with EMCC_DEBUG_SAVE=1 and attaching the the JS file being used as the input to acorn. It will be something like /tmp/emscripten_temp/dotnet.js.pp.js

@firasdib
Copy link

Here is the file
dotnet.js.pp.zip
:

@sbc100
Copy link
Collaborator

sbc100 commented Jul 17, 2022

Sorry EMCC_DEBUG_SAVE=1 is an environment variable, not and emscripten setting.

@sbc100
Copy link
Collaborator

sbc100 commented Jul 17, 2022

It looks like the problematic statement is the call the import function here:

      __dotnet_replacements.requirePromise = import(/* webpackIgnore: true */'module').then(mod => {
          const require = mod.createRequire(import.meta.url);                    
          const path = require('path');                                          
          const url = require('url');                                            
          __dotnet_replacements.require = require;                               
          __dirname = scriptDirectory = path.dirname(url.fileURLToPath(import.meta.url)) + '/';
          return require;                                                        
      }); 

It doesn't looks like that code comes from emscripten itself...

So you know if used to work in the past? What version of emscripten did this last work with?

@firasdib
Copy link

firasdib commented Jul 17, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants