{"id":16017717,"url":"https://github.com/zackradisic/rust-emscripten-bug","last_synced_at":"2025-10-06T13:47:09.729Z","repository":{"id":114944907,"uuid":"435841417","full_name":"zackradisic/rust-emscripten-bug","owner":"zackradisic","description":null,"archived":false,"fork":false,"pushed_at":"2021-12-07T10:50:57.000Z","size":4,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-29T07:29:55.772Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zackradisic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-07T10:46:36.000Z","updated_at":"2023-03-10T08:00:42.000Z","dependencies_parsed_at":"2023-07-12T04:45:39.936Z","dependency_job_id":null,"html_url":"https://github.com/zackradisic/rust-emscripten-bug","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zackradisic/rust-emscripten-bug","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zackradisic%2Frust-emscripten-bug","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zackradisic%2Frust-emscripten-bug/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zackradisic%2Frust-emscripten-bug/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zackradisic%2Frust-emscripten-bug/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zackradisic","download_url":"https://codeload.github.com/zackradisic/rust-emscripten-bug/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zackradisic%2Frust-emscripten-bug/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278621842,"owners_count":26017253,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-08T16:22:01.855Z","updated_at":"2025-10-06T13:47:09.723Z","avatar_url":"https://github.com/zackradisic.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rust Emscripten bug related to threads + auto-dereferencing?\n\nYou can try this bug by running:\n```\nmake wasm\n```\n\n## Context\nWhen compiling Rust with emscripten I get the following error:\n```\nnote: [parse exception: attempted pop from empty stack / beyond block start boundary at 5012790 (at 0:5012790)]\n          Fatal: error in parsing input\n          emcc: error: '/Users/zackradisic/Desktop/Code/emsdk/upstream/bin/wasm-emscripten-finalize --minimize-wasm-changes --dyncalls-i64 /Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/framex.wasm -o /Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/framex.wasm --detect-features' failed (returned 1)\n```\n\n\u003cdetails\u003e\n  \u003csummary\u003eFull error from rustc\u003c/summary\u003e\n\n```\nerror: linking with `emcc` failed: exit status: 1\n  |\n  = note: \"emcc\" \"-s\" \"EXPORTED_FUNCTIONS=[\\\"_alloc\\\",\\\"_dealloc\\\",\\\"_init\\\",\\\"_main\\\",\\\"_print_codecs\\\",\\\"_set_opt\\\",\\\"_rust_eh_personality\\\"]\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/framex.framex.f5802fb7-cgu.0.rcgu.o\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/framex.framex.f5802fb7-cgu.1.rcgu.o\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/framex.framex.f5802fb7-cgu.10.rcgu.o\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/framex.framex.f5802fb7-cgu.11.rcgu.o\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/framex.framex.f5802fb7-cgu.12.rcgu.o\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/framex.framex.f5802fb7-cgu.13.rcgu.o\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/framex.framex.f5802fb7-cgu.14.rcgu.o\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/framex.framex.f5802fb7-cgu.15.rcgu.o\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/framex.framex.f5802fb7-cgu.2.rcgu.o\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/framex.framex.f5802fb7-cgu.3.rcgu.o\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/framex.framex.f5802fb7-cgu.4.rcgu.o\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/framex.framex.f5802fb7-cgu.5.rcgu.o\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/framex.framex.f5802fb7-cgu.6.rcgu.o\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/framex.framex.f5802fb7-cgu.7.rcgu.o\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/framex.framex.f5802fb7-cgu.8.rcgu.o\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/framex.framex.f5802fb7-cgu.9.rcgu.o\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/framex.3m9l8ll8ayas3g7v.rcgu.o\" \"-L\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps\" \"-L\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/release/deps\" \"-L\" \"./wasm-libs/lib\" \"-L\" \"/Users/zackradisic/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/libframex-7860c6c7abb794c7.rlib\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/libanyhow-612bcb44f12e1d42.rlib\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/libffmpeg_next-54ea0b38a1519793.rlib\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/libffmpeg_sys_next-8de54784e88d927f.rlib\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/liblibc-ab293fa92d812261.rlib\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/libbitflags-f0b7a29eeb4093a5.rlib\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/libstd-35b925955873f6bf.rlib\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/libpanic_unwind-194edf489af57a97.rlib\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/libstd_detect-d58dd6fb52ab4b2d.rlib\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/librustc_demangle-a1931f836e2321a3.rlib\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/libhashbrown-93cb9f33d545cf77.rlib\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/librustc_std_workspace_alloc-90ae5f2c3dc1e297.rlib\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/libunwind-888b2c34d620fb42.rlib\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/libcfg_if-e5bd1b9f540b98e1.rlib\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/liblibc-f003f163c4e20282.rlib\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/liballoc-b31681533b19d24b.rlib\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/librustc_std_workspace_core-e54aa39c126b63d9.rlib\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/libcore-7c8d732fc023986c.rlib\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/libcompiler_builtins-70ec426a1130b25e.rlib\" \"-l\" \"avcodec\" \"-l\" \"avformat\" \"-l\" \"avfilter\" \"-l\" \"avdevice\" \"-l\" \"swresample\" \"-l\" \"postproc\" \"-l\" \"swscale\" \"-l\" \"avutil\" \"-l\" \"m\" \"-l\" \"mp3lame\" \"-l\" \"x264\" \"-l\" \"workerfs.js\" \"-l\" \"c\" \"-s\" \"DISABLE_EXCEPTION_CATCHING=0\" \"-L\" \"/Users/zackradisic/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib\" \"-L\" \"/Users/zackradisic/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/self-contained\" \"-o\" \"/Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/framex.js\" \"-O3\" \"--memory-init-file\" \"0\" \"-g0\" \"-s\" \"DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=[]\" \"-O3\" \"-pthread\" \"-s\" \"ALLOW_MEMORY_GROWTH=0\" \"-s\" \"INVOKE_RUN=0\" \"-s\" \"INITIAL_MEMORY=2146435072\" \"-s\" \"MODULARIZE=1\" \"-s\" \"EXPORT_NAME=framex\" \"-s\" \"USE_PTHREADS=1\" \"-s\" \"PROXY_TO_PTHREAD=1\" \"-s\" \"ENVIRONMENT=worker\" \"-s\" \"PTHREAD_POOL_SIZE=navigator.hardwareConcurrency\" \"-s\" \"EXPORTED_RUNTIME_METHODS=[FS,intArrayFromString,writeArrayToMemory,_malloc]\" \"gxx_personality_v0_stub.o\" \"-s\" \"ERROR_ON_UNDEFINED_SYMBOLS=1\" \"-s\" \"ASSERTIONS=1\" \"-s\" \"ABORTING_MALLOC=0\" \"-Wl,--fatal-warnings\"\n  = note: [parse exception: attempted pop from empty stack / beyond block start boundary at 5012790 (at 0:5012790)]\n          Fatal: error in parsing input\n          emcc: error: '/Users/zackradisic/Desktop/Code/emsdk/upstream/bin/wasm-emscripten-finalize --minimize-wasm-changes --dyncalls-i64 /Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/framex.wasm -o /Users/zackradisic/Desktop/Code/modfy/framex/target/wasm32-unknown-emscripten/release/deps/framex.wasm --detect-features' failed (returned 1)\n```\n  \n\u003c/details\u003e\n\nI narrowed down the code causing this and it seems related to Rust's auto-dereferencing. This is the section of code, and you can see the type of parameter `s` in the closure is multiple nested references (`\u0026\u0026\u0026str` or `\u0026\u0026str`). Rust's compiler will auto-dereference them to the appropriate type `\u0026str`. This code does not compile.\n\n\u003cimg width=\"852\" alt=\"Screen Shot 2021-12-07 at 10 46 16 AM\" src=\"https://user-images.githubusercontent.com/56137411/145006533-da8e6e2d-6254-4d5f-b9ed-755a239ef044.png\"\u003e\n\nHowever, when I use a [reference pattern](https://doc.rust-lang.org/reference/patterns.html#reference-patterns) to dereference the closure parameter, the code compiles and works as expected:\n\n\u003cimg width=\"861\" alt=\"Screen Shot 2021-12-07 at 10 46 02 AM\" src=\"https://user-images.githubusercontent.com/56137411/145006902-880176a3-0828-47e8-89ff-1e6eb018c640.png\"\u003e\n\nI also tested this theory by trying to compile the following code and it fails with the same error:\n```rust\nlet test: Vec\u003c\u0026str\u003e = vec![\n    \"hi\",\n    \"hello\",\n    \"mitochondria is the powerhouse of the cell\",\n];\n\nlet test = test\n    .iter()\n    .filter(|s| s.contains(\"h\")) // `s` has the type \u0026\u0026\u0026str\n    .map(|s| s.to_string())  // `s` has the type \u0026\u0026str\n    .collect::\u003cVec\u003cString\u003e\u003e();\n\nprintln!(\"Values: {:?}\", test);\n```\nNote that this error only occurs when compiling Rust with threads.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzackradisic%2Frust-emscripten-bug","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzackradisic%2Frust-emscripten-bug","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzackradisic%2Frust-emscripten-bug/lists"}