From 8bdd1add2e69d6d232e1a1036d8d5240506fffc1 Mon Sep 17 00:00:00 2001 From: Jake Champion Date: Wed, 4 Jan 2023 17:35:19 +0000 Subject: [PATCH 1/9] update to wasmtime 0.38.0 wasmtime 0.36.0 removed it's module linking implementation to make room for the upcoming support for the component model. https://github.com/bytecodealliance/wasmtime/pull/3958 This commit removes all the module linking functionality from wizer and updates to wasmtime 0.38.0 --- Cargo.lock | 272 ++++++++----- Cargo.toml | 6 +- fuzz/Cargo.toml | 2 +- fuzz/fuzz_targets/same_result.rs | 6 +- src/dummy.rs | 307 +-------------- src/lib.rs | 4 - src/snapshot.rs | 5 +- tests/make_linker.rs | 1 - tests/tests.rs | 645 +------------------------------ 9 files changed, 192 insertions(+), 1056 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 25aec03..d0f9504 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,6 +26,17 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + [[package]] name = "aho-corasick" version = "0.7.18" @@ -52,9 +63,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.44" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61604a8f862e1d5c3229fdd78f8b02c68dcf73a4c4b05fd636d12240aaa242c1" +checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61" [[package]] name = "arbitrary" @@ -156,6 +167,12 @@ version = "3.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9df67f7bf9ef8498769f994239c45613ef0c5899415fb58e9add412d2c1a538" +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + [[package]] name = "cap-fs-ext" version = "0.24.1" @@ -281,59 +298,60 @@ dependencies = [ [[package]] name = "cranelift-bforest" -version = "0.82.3" +version = "0.85.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38faa2a16616c8e78a18d37b4726b98bfd2de192f2fdc8a39ddf568a408a0f75" +checksum = "749d0d6022c9038dccf480bdde2a38d435937335bf2bb0f14e815d94517cdce8" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.82.3" +version = "0.85.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26f192472a3ba23860afd07d2b0217dc628f21fcc72617aa1336d98e1671f33b" +checksum = "e94370cc7b37bf652ccd8bb8f09bd900997f7ccf97520edfc75554bb5c4abbea" dependencies = [ "cranelift-bforest", "cranelift-codegen-meta", "cranelift-codegen-shared", "cranelift-entity", + "cranelift-isle", "gimli 0.26.1", "log", - "regalloc", + "regalloc2", "smallvec", "target-lexicon", ] [[package]] name = "cranelift-codegen-meta" -version = "0.82.3" +version = "0.85.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f32ddb89e9b89d3d9b36a5b7d7ea3261c98235a76ac95ba46826b8ec40b1a24" +checksum = "e0a3cea8fdab90e44018c5b9a1dfd460d8ee265ac354337150222a354628bdb6" dependencies = [ "cranelift-codegen-shared", ] [[package]] name = "cranelift-codegen-shared" -version = "0.82.3" +version = "0.85.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01fd0d9f288cc1b42d9333b7a776b17e278fc888c28e6a0f09b5573d45a150bc" +checksum = "5ac72f76f2698598951ab26d8c96eaa854810e693e7dd52523958b5909fde6b2" [[package]] name = "cranelift-entity" -version = "0.82.3" +version = "0.85.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e3bfe172b83167604601faf9dc60453e0d0a93415b57a9c4d1a7ae6849185cf" +checksum = "09eaeacfcd2356fe0e66b295e8f9d59fdd1ac3ace53ba50de14d628ec902f72d" dependencies = [ "serde", ] [[package]] name = "cranelift-frontend" -version = "0.82.3" +version = "0.85.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a006e3e32d80ce0e4ba7f1f9ddf66066d052a8c884a110b91d05404d6ce26dce" +checksum = "dba69c9980d5ffd62c18a2bde927855fcd7c8dc92f29feaf8636052662cbd99c" dependencies = [ "cranelift-codegen", "log", @@ -341,11 +359,17 @@ dependencies = [ "target-lexicon", ] +[[package]] +name = "cranelift-isle" +version = "0.85.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2920dc1e05cac40304456ed3301fde2c09bd6a9b0210bcfa2f101398d628d5b" + [[package]] name = "cranelift-native" -version = "0.82.3" +version = "0.85.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "501241b0cdf903412ec9075385ac9f2b1eb18a89044d1538e97fab603231f70c" +checksum = "f04dfa45f9b2a6f587c564d6b63388e00cd6589d2df6ea2758cf79e1a13285e6" dependencies = [ "cranelift-codegen", "libc", @@ -354,9 +378,9 @@ dependencies = [ [[package]] name = "cranelift-wasm" -version = "0.82.3" +version = "0.85.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16d9e4211bbc3268042a96dd4de5bd979cda22434991d035f5f8eacba987fad2" +checksum = "31a46513ae6f26f3f267d8d75b5373d555fbbd1e68681f348d99df43f747ec54" dependencies = [ "cranelift-codegen", "cranelift-entity", @@ -364,7 +388,7 @@ dependencies = [ "itertools", "log", "smallvec", - "wasmparser 0.83.0", + "wasmparser 0.85.0", "wasmtime-types", ] @@ -616,6 +640,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + [[package]] name = "gcc" version = "0.3.55" @@ -671,6 +704,15 @@ name = "hashbrown" version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +dependencies = [ + "ahash", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "heck" @@ -681,6 +723,12 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "heck" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -716,12 +764,12 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "indexmap" -version = "1.7.0" +version = "1.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" +checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" dependencies = [ "autocfg", - "hashbrown", + "hashbrown 0.12.3", "serde", ] @@ -825,9 +873,9 @@ checksum = "3576a87f2ba00f6f106fdfcd16db1d698d648a26ad8e0573cad8537c3c362d2a" [[package]] name = "libc" -version = "0.2.115" +version = "0.2.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a8d982fa7a96a000f6ec4cfe966de9703eccde29750df2bb8949da91b0e818d" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" [[package]] name = "libfuzzer-sys" @@ -848,15 +896,15 @@ checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3" [[package]] name = "linux-raw-sys" -version = "0.0.40" +version = "0.0.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bdc16c6ce4c85d9b46b4e66f2a814be5b3f034dbd5131c268a24ca26d970db8" +checksum = "5284f00d480e1c39af34e72f8ad60b94f47007e3481cd3b731c1d67190ddc7b7" [[package]] name = "log" -version = "0.4.14" +version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if", ] @@ -946,20 +994,21 @@ dependencies = [ [[package]] name = "object" -version = "0.27.1" +version = "0.28.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67ac1d3f9a1d3616fd9a60c8d74296f22406a238b6a72f5cc1e6f314df4ffbf9" +checksum = "e42c982f2d955fac81dd7e1d0e1426a7d702acd9c98d19ab01083a6a0328c424" dependencies = [ "crc32fast", + "hashbrown 0.11.2", "indexmap", "memchr", ] [[package]] name = "once_cell" -version = "1.9.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" +checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" [[package]] name = "oorandom" @@ -1161,13 +1210,14 @@ dependencies = [ ] [[package]] -name = "regalloc" -version = "0.0.34" +name = "regalloc2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62446b1d3ebf980bdc68837700af1d77b37bc430e524bf95319c6eada2a4cc02" +checksum = "4a8d23b35d7177df3b9d31ed8a9ab4bf625c668be77a319d4f5efd4a5257701c" dependencies = [ + "fxhash", "log", - "rustc-hash", + "slice-group-by", "smallvec", ] @@ -1226,12 +1276,6 @@ version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - [[package]] name = "rustc_version" version = "0.4.0" @@ -1243,9 +1287,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.33.2" +version = "0.33.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db890a96e64911e67fa84e58ce061a40a6a65c231e5fad20b190933f8991a27c" +checksum = "938a344304321a9da4973b9ff4f9f8db9caf4597dfd9dda6a60b523340a0fff0" dependencies = [ "bitflags", "errno", @@ -1339,9 +1383,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.9.8" +version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" dependencies = [ "block-buffer", "cfg-if", @@ -1359,6 +1403,12 @@ dependencies = [ "dirs-next", ] +[[package]] +name = "slice-group-by" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03b634d87b960ab1a38c4fe143b508576f075e7c978bfad18217645ebfdfa2ec" + [[package]] name = "smallvec" version = "1.6.1" @@ -1394,7 +1444,7 @@ version = "0.4.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "134d838a2c9943ac3125cf6df165eda53493451b719f3255b2a26b85f772d0ba" dependencies = [ - "heck", + "heck 0.3.3", "proc-macro-error", "proc-macro2", "quote", @@ -1430,9 +1480,9 @@ dependencies = [ [[package]] name = "target-lexicon" -version = "0.12.2" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9bffcddbc2458fa3e6058414599e3c838a022abae82e5c67b4f7f80298d5bff" +checksum = "9410d0f6853b1d94f0e519fb95df60f29d2c1eff2d921ffdf01a4c8a3b54f12d" [[package]] name = "termcolor" @@ -1588,9 +1638,9 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "wasi-cap-std-sync" -version = "0.35.3" +version = "0.38.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9120fdc492d9d95cd7278b34f46fe9122962e4b2476c040f058971ccc00fc4d2" +checksum = "f086c5026d2fc3b268d138e65373f46422cc810f46d6e0776859c5027cb18728" dependencies = [ "anyhow", "async-trait", @@ -1612,14 +1662,15 @@ dependencies = [ [[package]] name = "wasi-common" -version = "0.35.3" +version = "0.38.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab6097a5c8e9a791227a50945b6a891da6d93f518ebfa8716f231dc03f119585" +checksum = "4e8844fede1c3787cc08853872f47e8bd91f6c939c7406bc7a5dba496b260c08" dependencies = [ "anyhow", "bitflags", "cap-rand", "cap-std", + "io-extras", "rustix", "thiserror", "tracing", @@ -1699,6 +1750,15 @@ dependencies = [ "leb128", ] +[[package]] +name = "wasm-encoder" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05632e0a66a6ed8cca593c24223aabd6262f256c3693ad9822c315285f010614" +dependencies = [ + "leb128", +] + [[package]] name = "wasm-smith" version = "0.4.5" @@ -1725,9 +1785,12 @@ checksum = "be92b6dcaa5af4b2a176b29be3bf1402fab9e69d313141185099c7d1684f2dca" [[package]] name = "wasmparser" -version = "0.83.0" +version = "0.85.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "718ed7c55c2add6548cca3ddd6383d738cd73b892df400e96b9aa876f0141d7a" +checksum = "570460c58b21e9150d2df0eaaedbb7816c34bcec009ae0dcc976e40ba81463e7" +dependencies = [ + "indexmap", +] [[package]] name = "wasmprinter" @@ -1741,9 +1804,9 @@ dependencies = [ [[package]] name = "wasmtime" -version = "0.35.3" +version = "0.38.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21ffb4705016d5ca91e18a72ed6822dab50e6d5ddd7045461b17ef19071cdef1" +checksum = "1f50eadf868ab6a04b7b511460233377d0bfbb92e417b2f6a98b98fef2e098f5" dependencies = [ "anyhow", "async-trait", @@ -1754,7 +1817,7 @@ dependencies = [ "lazy_static", "libc", "log", - "object 0.27.1", + "object 0.28.4", "once_cell", "paste", "psm", @@ -1762,7 +1825,7 @@ dependencies = [ "region", "serde", "target-lexicon", - "wasmparser 0.83.0", + "wasmparser 0.85.0", "wasmtime-cache", "wasmtime-cranelift", "wasmtime-environ", @@ -1775,9 +1838,9 @@ dependencies = [ [[package]] name = "wasmtime-cache" -version = "0.35.3" +version = "0.38.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85c6ab24291fa7cb3a181f5669f6c72599b7ef781669759b45c7828c5999d0c0" +checksum = "d1df23c642e1376892f3b72f311596976979cbf8b85469680cdd3a8a063d12a2" dependencies = [ "anyhow", "base64", @@ -1795,9 +1858,9 @@ dependencies = [ [[package]] name = "wasmtime-cranelift" -version = "0.35.3" +version = "0.38.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f04c810078a491b7bc4866ebe045f714d2b95e6b539e1f64009a4a7606be11de" +checksum = "f264ff6b4df247d15584f2f53d009fbc90032cfdc2605b52b961bffc71b6eccd" dependencies = [ "anyhow", "cranelift-codegen", @@ -1808,18 +1871,18 @@ dependencies = [ "gimli 0.26.1", "log", "more-asserts", - "object 0.27.1", + "object 0.28.4", "target-lexicon", "thiserror", - "wasmparser 0.83.0", + "wasmparser 0.85.0", "wasmtime-environ", ] [[package]] name = "wasmtime-environ" -version = "0.35.3" +version = "0.38.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61448266ea164b1ac406363cdcfac81c7c44db4d94c7a81c8620ac6c5c6cdf59" +checksum = "839d2820e4b830f4b9e7aa08d4c0acabf4a5036105d639f6dfa1c6891c73bdc6" dependencies = [ "anyhow", "cranelift-entity", @@ -1827,19 +1890,19 @@ dependencies = [ "indexmap", "log", "more-asserts", - "object 0.27.1", + "object 0.28.4", "serde", "target-lexicon", "thiserror", - "wasmparser 0.83.0", + "wasmparser 0.85.0", "wasmtime-types", ] [[package]] name = "wasmtime-fiber" -version = "0.35.3" +version = "0.38.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbaaa38c3b48822ab27044e1d4a25a1052157de4c8f27574cb00167e127e320f" +checksum = "3248be3c4911233535356025f6562193614a40155ee9094bb6a2b43f0dc82803" dependencies = [ "cc", "rustix", @@ -1848,9 +1911,9 @@ dependencies = [ [[package]] name = "wasmtime-jit" -version = "0.35.3" +version = "0.38.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "156b4623c6b0d4b8c24afb846c20525922f538ef464cc024abab7ea8de2109a2" +checksum = "ef0a0bcbfa18b946d890078ba0e1bc76bcc53eccfb40806c0020ec29dcd1bd49" dependencies = [ "addr2line 0.17.0", "anyhow", @@ -1860,7 +1923,7 @@ dependencies = [ "gimli 0.26.1", "ittapi-rs", "log", - "object 0.27.1", + "object 0.28.4", "region", "rustc-demangle", "rustix", @@ -1875,20 +1938,20 @@ dependencies = [ [[package]] name = "wasmtime-jit-debug" -version = "0.35.3" +version = "0.38.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5dc31f811760a6c76b2672c404866fd19b75e5fb3b0075a3e377a6846490654" +checksum = "4f4779d976206c458edd643d1ac622b6c37e4a0800a8b1d25dfbf245ac2f2cac" dependencies = [ "lazy_static", - "object 0.27.1", + "object 0.28.4", "rustix", ] [[package]] name = "wasmtime-runtime" -version = "0.35.3" +version = "0.38.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f907beaff69d4d920fa4688411ee4cc75c0f01859e424677f9e426e2ef749864" +checksum = "b7eb6ffa169eb5dcd18ac9473c817358cd57bc62c244622210566d473397954a" dependencies = [ "anyhow", "backtrace", @@ -1913,21 +1976,21 @@ dependencies = [ [[package]] name = "wasmtime-types" -version = "0.35.3" +version = "0.38.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514ef0e5fd197b9609dc9eb74beba0c84d5a12b2417cbae55534633329ba4852" +checksum = "8d932b0ac5336f7308d869703dd225610a6a3aeaa8e968c52b43eed96cefb1c2" dependencies = [ "cranelift-entity", "serde", "thiserror", - "wasmparser 0.83.0", + "wasmparser 0.85.0", ] [[package]] name = "wasmtime-wasi" -version = "0.35.3" +version = "0.38.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f0633261ad13d93ae84c758ce195c659a0ee57fcdbe724c8976f4b1872cdcde" +checksum = "b68b7d77fb6f2975a6fe6cc4d0015d6b0cebb65c39fce1dd4cc00880dbf7789c" dependencies = [ "anyhow", "wasi-cap-std-sync", @@ -1947,20 +2010,23 @@ dependencies = [ [[package]] name = "wast" -version = "38.0.0" +version = "50.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ebc29df4629f497e0893aacd40f13a4a56b85ef6eb4ab6d603f07244f1a7bf2" +checksum = "a2cbb59d4ac799842791fe7e806fa5dbbf6b5554d538e51cc8e176db6ff0ae34" dependencies = [ "leb128", + "memchr", + "unicode-width", + "wasm-encoder 0.20.0", ] [[package]] name = "wat" -version = "1.0.40" +version = "1.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adcfaeb27e2578d2c6271a45609f4a055e6d7ba3a12eff35b1fd5ba147bdf046" +checksum = "584aaf7a1ecf4d383bbe1a25eeab0cbb8ff96acc6796707ff65cde48f4632f15" dependencies = [ - "wast 38.0.0", + "wast 50.0.0", ] [[package]] @@ -1975,9 +2041,9 @@ dependencies = [ [[package]] name = "wiggle" -version = "0.35.3" +version = "0.38.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36fb71c833bf174b1b34979942ff33f525b97311232ef6a0a18bcdf540ae9c91" +checksum = "67dadac11343d2aabc8a906a0db0aaf7cb5046ec3d6fffccdaf2847dccdef8d6" dependencies = [ "anyhow", "async-trait", @@ -1990,12 +2056,12 @@ dependencies = [ [[package]] name = "wiggle-generate" -version = "0.35.3" +version = "0.38.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52d684c4454e953df20b5a1c3e0a8d208ef4d5a768e013f64bebfc9f74a3f739" +checksum = "63a1dccd6b3fbd9a27417f5d30ce9aa3ee9cf529aad453abbf88a49c5d605b79" dependencies = [ "anyhow", - "heck", + "heck 0.4.0", "proc-macro2", "quote", "shellexpand", @@ -2005,9 +2071,9 @@ dependencies = [ [[package]] name = "wiggle-macro" -version = "0.35.3" +version = "0.38.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1da6c96c93eced4bf71e59ca1f06f933b84f37544a354646e37c0e5c6d5a262d" +checksum = "f1c368d57d9560c34deaa67e06b0953ccf65edb906c525e5a2c866c849b48ec2" dependencies = [ "proc-macro2", "quote", @@ -2113,18 +2179,18 @@ dependencies = [ [[package]] name = "zstd" -version = "0.10.0+zstd.1.5.2" +version = "0.11.2+zstd.1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b1365becbe415f3f0fcd024e2f7b45bacfb5bdd055f0dc113571394114e7bdd" +checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4" dependencies = [ "zstd-safe", ] [[package]] name = "zstd-safe" -version = "4.1.4+zstd.1.5.2" +version = "5.0.2+zstd.1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f7cd17c9af1a4d6c24beb1cc54b17e2ef7b593dc92f19e9d9acad8b182bbaee" +checksum = "1d2a5585e04f9eea4b2a3d1eca508c4dee9592a89ef6f450c11719da0726f4db" dependencies = [ "libc", "zstd-sys", @@ -2132,9 +2198,9 @@ dependencies = [ [[package]] name = "zstd-sys" -version = "1.6.3+zstd.1.5.2" +version = "2.0.4+zstd.1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc49afa5c8d634e75761feda8c592051e7eeb4683ba827211eb0d731d3402ea8" +checksum = "4fa202f2ef00074143e219d15b62ffc317d17cc33909feac471c044087cad7b0" dependencies = [ "cc", "libc", diff --git a/Cargo.toml b/Cargo.toml index 0322a55..e4c58e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,11 +33,11 @@ env_logger = { version = "0.8.2", optional = true } log = "0.4.14" rayon = "1.5.0" structopt = { version = "0.3.21", optional = true } -wasi-cap-std-sync = "0.35.3" +wasi-cap-std-sync = "0.38.0" wasm-encoder = "0.6.0" wasmparser = "0.78.2" -wasmtime = "0.35.3" -wasmtime-wasi = "0.35.3" +wasmtime = "0.38.0" +wasmtime-wasi = "0.38.0" # Enable this dependency to get messages with WAT disassemblies when certain # internal panics occur. diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 4f8b36a..a6d280c 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -15,7 +15,7 @@ libfuzzer-sys = "0.4" log = "0.4.14" wasm-smith = "0.4.0" wasmprinter = "0.2.26" -wasmtime = "0.35.3" +wasmtime = "0.38.0" [dependencies.wizer] path = ".." diff --git a/fuzz/fuzz_targets/same_result.rs b/fuzz/fuzz_targets/same_result.rs index 2b7feeb..b069bdb 100644 --- a/fuzz/fuzz_targets/same_result.rs +++ b/fuzz/fuzz_targets/same_result.rs @@ -38,7 +38,6 @@ fuzz_target!(|module: wasm_smith::ConfiguredModule| { let mut config = Config::new(); config.cache_config_load_default().unwrap(); - config.wasm_module_linking(true); config.wasm_multi_memory(true); config.wasm_multi_value(true); @@ -162,10 +161,7 @@ fuzz_target!(|module: wasm_smith::ConfiguredModule| { panic!("divergence between snapshot and non-snapshot memories"); } } - Extern::Instance(_) - | Extern::Func(_) - | Extern::Table(_) - | Extern::Module(_) => continue, + Extern::SharedMemory(_) | Extern::Func(_) | Extern::Table(_) => continue, } } } diff --git a/src/dummy.rs b/src/dummy.rs index 0ccc1c7..0a6500a 100644 --- a/src/dummy.rs +++ b/src/dummy.rs @@ -3,7 +3,6 @@ //! Forked from `wasmtime/crates/fuzzing/src/oracles/dummy.rs`. use anyhow::Result; -use std::fmt::Write; use wasmtime::*; /// Create dummy imports for instantiating the module. @@ -15,60 +14,23 @@ pub fn dummy_imports( log::debug!("Creating dummy imports"); for imp in module.imports() { - match imp.name() { - Some(name) => { - if linker.get(&mut *store, imp.module(), Some(name)).is_some() { - // Already defined, must be part of WASI. - continue; - } - - linker - .define( - imp.module(), - name, - dummy_extern( - &mut *store, - imp.ty(), - &format!("'{}' '{}'", imp.module(), name), - )?, - ) - .unwrap(); - } - None => match imp.ty() { - wasmtime::ExternType::Instance(ty) => { - for ty in ty.exports() { - if linker - .get(&mut *store, imp.module(), Some(ty.name())) - .is_some() - { - // Already defined, must be part of WASI. - continue; - } - - linker - .define( - imp.module(), - ty.name(), - dummy_extern(&mut *store, ty.ty(), &format!("'{}'", imp.module()))?, - ) - .unwrap(); - } - } - other => { - if linker.get(&mut *store, imp.module(), None).is_some() { - // Already defined, must be part of WASI. - continue; - } - - linker - .define_name( - imp.module(), - dummy_extern(&mut *store, other, &format!("'{}'", imp.module()))?, - ) - .unwrap(); - } - }, + let name = imp.name(); + if linker.get(&mut *store, imp.module(), name).is_some() { + // Already defined, must be part of WASI. + continue; } + + linker + .define( + imp.module(), + name, + dummy_extern( + &mut *store, + imp.ty(), + &format!("'{}' '{}'", imp.module(), name), + )?, + ) + .unwrap(); } Ok(()) @@ -78,9 +40,6 @@ pub fn dummy_imports( pub fn dummy_extern(store: &mut crate::Store, ty: ExternType, name: &str) -> Result { Ok(match ty { ExternType::Func(func_ty) => Extern::Func(dummy_func(store, func_ty, name)), - ExternType::Instance(instance_ty) => { - Extern::Instance(dummy_instance(store, instance_ty, name)?) - } ExternType::Global(_) => { anyhow::bail!("Error: attempted to import unknown global: {}", name) } @@ -88,9 +47,6 @@ pub fn dummy_extern(store: &mut crate::Store, ty: ExternType, name: &str) -> Res ExternType::Memory(_) => { anyhow::bail!("Error: attempted to import unknown memory: {}", name) } - ExternType::Module(_) => { - anyhow::bail!("Error: attempted to import unknown module: {}", name) - } }) } @@ -126,234 +82,3 @@ pub fn dummy_value(val_ty: ValType) -> Val { pub fn dummy_values(val_tys: impl IntoIterator) -> Vec { val_tys.into_iter().map(dummy_value).collect() } - -/// Construct a dummy instance for the given instance type. -/// -/// This is done by using the expected type to generate a module on-the-fly -/// which we the instantiate. -pub fn dummy_instance(store: &mut crate::Store, ty: InstanceType, name: &str) -> Result { - let mut wat = WatGenerator::new(); - for ty in ty.exports() { - wat.export(&ty, name)?; - } - let module = Module::new(store.engine(), &wat.finish()).unwrap(); - Ok(Instance::new(store, &module, &[])?) -} - -struct WatGenerator { - tmp: usize, - dst: String, -} - -impl WatGenerator { - fn new() -> WatGenerator { - WatGenerator { - tmp: 0, - dst: String::from("(module\n"), - } - } - - fn finish(mut self) -> String { - self.dst.push_str(")\n"); - self.dst - } - - fn export(&mut self, ty: &ExportType<'_>, instance_name: &str) -> Result<()> { - let wat_name = format!("item{}", self.tmp); - self.tmp += 1; - let item_ty = ty.ty(); - self.item(&wat_name, &item_ty, instance_name, ty.name())?; - - write!(self.dst, "(export ").unwrap(); - self.str(ty.name()); - write!(self.dst, " (").unwrap(); - match item_ty { - ExternType::Func(_) => write!(self.dst, "func").unwrap(), - ExternType::Instance(_) => write!(self.dst, "instance").unwrap(), - ExternType::Memory(_) => anyhow::bail!( - "Error: attempted to import unknown memory: '{}' '{}'", - instance_name, - ty.name() - ), - ExternType::Global(_) => anyhow::bail!( - "Error: attempted to import unknown global: '{}' '{}'", - instance_name, - ty.name() - ), - ExternType::Table(_) => anyhow::bail!( - "Error: attempted to import unknown table: '{}' '{}'", - instance_name, - ty.name() - ), - ExternType::Module(_) => anyhow::bail!( - "Error: attempted to import unknown module: '{}' '{}'", - instance_name, - ty.name() - ), - } - writeln!(self.dst, " ${}))", wat_name).unwrap(); - Ok(()) - } - - fn item( - &mut self, - name: &str, - ty: &ExternType, - instance_name: &str, - item_name: &str, - ) -> Result<()> { - match ty { - ExternType::Func(ty) => { - write!(self.dst, "(func ${} ", name).unwrap(); - self.func_sig(ty); - for ty in ty.results() { - writeln!(self.dst, "").unwrap(); - self.value(&ty); - } - writeln!(self.dst, ")").unwrap(); - } - ExternType::Instance(ty) => { - writeln!(self.dst, "(module ${}_module", name).unwrap(); - for ty in ty.exports() { - self.export(&ty, instance_name)?; - } - self.dst.push_str(")\n"); - writeln!(self.dst, "(instance ${} (instantiate ${0}_module))", name).unwrap(); - } - ExternType::Memory(_) => anyhow::bail!( - "Error: attempted to import unknown memory: '{}' '{}'", - instance_name, - item_name - ), - ExternType::Global(_) => anyhow::bail!( - "Error: attempted to import unknown global: '{}' '{}'", - instance_name, - item_name - ), - ExternType::Table(_) => anyhow::bail!( - "Error: attempted to import unknown table: '{}' '{}'", - instance_name, - item_name - ), - ExternType::Module(_) => anyhow::bail!( - "Error: attempted to import unknown module: '{}' '{}'", - instance_name, - item_name - ), - } - Ok(()) - } - - fn func_sig(&mut self, ty: &FuncType) { - write!(self.dst, "(param ").unwrap(); - for ty in ty.params() { - write!(self.dst, "{} ", wat_ty(&ty)).unwrap(); - } - write!(self.dst, ") (result ").unwrap(); - for ty in ty.results() { - write!(self.dst, "{} ", wat_ty(&ty)).unwrap(); - } - write!(self.dst, ")").unwrap(); - } - - fn value(&mut self, ty: &ValType) { - match ty { - ValType::I32 => write!(self.dst, "i32.const 0").unwrap(), - ValType::I64 => write!(self.dst, "i64.const 0").unwrap(), - ValType::F32 => write!(self.dst, "f32.const 0").unwrap(), - ValType::F64 => write!(self.dst, "f64.const 0").unwrap(), - ValType::V128 => write!(self.dst, "v128.const i32x4 0 0 0 0").unwrap(), - ValType::ExternRef => write!(self.dst, "ref.null extern").unwrap(), - ValType::FuncRef => write!(self.dst, "ref.null func").unwrap(), - } - } - - fn str(&mut self, name: &str) { - let mut bytes = [0; 4]; - self.dst.push_str("\""); - for c in name.chars() { - let v = c as u32; - if v >= 0x20 && v < 0x7f && c != '"' && c != '\\' && v < 0xff { - self.dst.push(c); - } else { - for byte in c.encode_utf8(&mut bytes).as_bytes() { - self.hex_byte(*byte); - } - } - } - self.dst.push_str("\""); - } - - fn hex_byte(&mut self, byte: u8) { - fn to_hex(b: u8) -> char { - if b < 10 { - (b'0' + b) as char - } else { - (b'a' + b - 10) as char - } - } - self.dst.push('\\'); - self.dst.push(to_hex((byte >> 4) & 0xf)); - self.dst.push(to_hex(byte & 0xf)); - } -} - -fn wat_ty(ty: &ValType) -> &'static str { - match ty { - ValType::I32 => "i32", - ValType::I64 => "i64", - ValType::F32 => "f32", - ValType::F64 => "f64", - ValType::V128 => "v128", - ValType::ExternRef => "externref", - ValType::FuncRef => "funcref", - } -} - -#[cfg(test)] -mod tests { - use super::*; - use std::collections::HashSet; - - fn store() -> crate::Store { - let mut config = Config::default(); - config.wasm_module_linking(true); - config.wasm_multi_memory(true); - let engine = wasmtime::Engine::new(&config).unwrap(); - Store::new(&engine, None) - } - - #[test] - fn dummy_function_import() { - let mut store = store(); - let func_ty = FuncType::new(vec![ValType::I32], vec![ValType::I64]); - let func = dummy_func(&mut store, func_ty.clone(), "f"); - assert_eq!(func.ty(&store), func_ty); - } - - #[test] - fn dummy_instance_import() { - let mut store = store(); - - let mut instance_ty = InstanceType::new(); - - // Functions. - instance_ty.add_named_export("func0", FuncType::new(vec![ValType::I32], vec![]).into()); - instance_ty.add_named_export("func1", FuncType::new(vec![], vec![ValType::I64]).into()); - - // Instances. - instance_ty.add_named_export("instance0", InstanceType::new().into()); - instance_ty.add_named_export("instance1", InstanceType::new().into()); - - let instance = dummy_instance(&mut store, instance_ty.clone(), "instance").unwrap(); - - let mut expected_exports = vec!["func0", "func1", "instance0", "instance1"] - .into_iter() - .collect::>(); - for exp in instance.ty(&store).exports() { - let was_expected = expected_exports.remove(exp.name()); - assert!(was_expected); - } - assert!(expected_exports.is_empty()); - } -} diff --git a/src/lib.rs b/src/lib.rs index 5423fd5..884fec5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -543,10 +543,6 @@ impl Wizer { // Proposals we support. config.wasm_multi_memory(self.wasm_multi_memory.unwrap_or(DEFAULT_WASM_MULTI_MEMORY)); config.wasm_multi_value(self.wasm_multi_value.unwrap_or(DEFAULT_WASM_MULTI_VALUE)); - config.wasm_module_linking( - self.wasm_module_linking - .unwrap_or(DEFAULT_WASM_MODULE_LINKING), - ); // Note that we only support `memory.copy`, `memory.fill`, and // `memory.init` for the time being: config.wasm_bulk_memory(self.wasm_bulk_memory.unwrap_or(DEFAULT_WASM_BULK_MEMORY)); diff --git a/src/snapshot.rs b/src/snapshot.rs index 9e75497..9d69b6f 100644 --- a/src/snapshot.rs +++ b/src/snapshot.rs @@ -279,14 +279,11 @@ fn snapshot_instantiations( instance: &wasmtime::Instance, ) -> Vec { log::debug!("Snapshotting nested instantiations"); - let mut instantiations = vec![]; + let instantiations = vec![]; loop { let name = format!("__wizer_instance_{}", instantiations.len()); match instance.get_export(&mut *ctx, &name) { None => break, - Some(wasmtime::Extern::Instance(instance)) => { - instantiations.push(snapshot(&mut *ctx, &instance)); - } Some(_) => unreachable!(), } } diff --git a/tests/make_linker.rs b/tests/make_linker.rs index 6cb44c8..ebde070 100644 --- a/tests/make_linker.rs +++ b/tests/make_linker.rs @@ -33,7 +33,6 @@ fn run_wasm(args: &[wasmtime::Val], expected: i32, wasm: &[u8]) -> Result<()> { config.cache_config_load_default().unwrap(); config.wasm_multi_memory(true); config.wasm_multi_value(true); - config.wasm_module_linking(true); let engine = wasmtime::Engine::new(&config)?; let wasi_ctx = wasi_cap_std_sync::WasiCtxBuilder::new().build(); diff --git a/tests/tests.rs b/tests/tests.rs index 7e172de..cb56f71 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -35,7 +35,6 @@ fn run_wasm(args: &[wasmtime::Val], expected: i32, wasm: &[u8]) -> Result<()> { config.cache_config_load_default().unwrap(); config.wasm_multi_memory(true); config.wasm_multi_value(true); - config.wasm_module_linking(true); let engine = wasmtime::Engine::new(&config)?; let wasi_ctx = wasi_cap_std_sync::WasiCtxBuilder::new().build(); @@ -51,8 +50,7 @@ fn run_wasm(args: &[wasmtime::Val], expected: i32, wasm: &[u8]) -> Result<()> { .define_name("dummy_func", wasmtime::Func::wrap(&mut store, || {}))? .define("env", "f", wasmtime::Func::wrap(&mut store, || {}))? .define_name("f", wasmtime::Func::wrap(&mut store, || {}))? - .define("x", "f", wasmtime::Func::wrap(&mut store, || {}))? - .define_name("dummy_instance", dummy_instance)?; + .define("x", "f", wasmtime::Func::wrap(&mut store, || {}))?; wasmtime_wasi::add_to_linker(&mut linker, |wasi| wasi)?; @@ -137,32 +135,6 @@ fn basic_memory() -> Result<()> { ) } -#[test] -fn multi_memory() -> Result<()> { - run_wat( - &[], - 42, - r#" -(module - (memory $m1 1) - (memory $m2 1) - (func (export "wizer.initialize") - i32.const 0 - i32.const 41 - i32.store (memory $m1) offset=1337 - i32.const 0 - i32.const 1 - i32.store (memory $m2) offset=1337) - (func (export "run") (result i32) - i32.const 0 - i32.load (memory $m1) offset=1337 - i32.const 0 - i32.load (memory $m2) offset=1337 - i32.add)) -"#, - ) -} - #[test] fn reject_imported_memory() -> Result<()> { fails_wizening( @@ -347,505 +319,6 @@ fn reject_data_drop() -> Result<()> { Ok(()) } -#[test] -fn accept_module_linking_import_memory() -> Result<()> { - run_wat( - &[], - 42, - r#" -(module - (module $A - (memory (export "memory") 1)) - (instance $a (instantiate $A)) - - (module $B - (import "x" (instance $x (export "memory" (memory 1))))) - (instance $b (instantiate $B (import "x" (instance $a)))) - - (func (export "wizer.initialize") - nop) - - (func (export "run") (result i32) - i32.const 42) -) -"#, - ) -} - -#[test] -fn accept_module_linking_import_global() -> Result<()> { - run_wat( - &[], - 42, - r#" -(module - (module $A - (global (export "global") i32 (i32.const 1337))) - (instance $a (instantiate $A)) - - (module $B - (import "x" (instance $x (export "global" (global i32))))) - (instance $b (instantiate $B (import "x" (instance $a)))) - - (func (export "wizer.initialize") - nop) - - (func (export "run") (result i32) - i32.const 42) -) -"#, - ) -} - -#[test] -fn accept_module_linking_import_table() -> Result<()> { - run_wat( - &[], - 42, - r#" -(module - (module $A - (table (export "table") 0 funcref)) - (instance $a (instantiate $A)) - - (module $B - (import "x" (instance $x (export "table" (table 0 funcref))))) - (instance $b (instantiate $B (import "x" (instance $a)))) - - (func (export "wizer.initialize") - nop) - - (func (export "run") (result i32) - i32.const 42) -) -"#, - ) -} - -#[test] -fn module_linking_actually_works() -> Result<()> { - run_wat( - &[], - 42, - r#" -(module - (module $memory-module - (memory (export "memory") 1)) - (instance $memory-instance (instantiate $memory-module)) - - (module $use-memory - (import "x" (instance $m (export "memory" (memory 1)))) - (func (export "init") - i32.const 0 - i32.const 42 - i32.store (memory $m "memory") offset=1337)) - (instance $use-memory-instance - (instantiate $use-memory - (import "x" (instance $memory-instance)))) - - (func (export "wizer.initialize") - (call (func $use-memory-instance "init"))) - - (func (export "run") (result i32) - i32.const 0 - i32.load (memory $memory-instance "memory") offset=1337) -) -"#, - ) -} - -#[test] -fn module_linking_nested_instantiations_1() -> Result<()> { - run_wat( - &[], - 8, - r#" -(module - (module $A - (import "global" (global (mut i32))) - - (module $B - (import "global" (global (mut i32))) - - (module $C - (import "global" (global (mut i32))) - - (func (export "f") - i32.const 1 - global.get 0 - i32.add - global.set 0 - ) - ) - - (instance $c1 (instantiate $C (import "global" (global 0)))) - (instance $c2 (instantiate $C (import "global" (global 0)))) - - (func (export "f") - call (func $c1 "f") - call (func $c2 "f") - ) - ) - - (instance $b1 (instantiate $B (import "global" (global 0)))) - (instance $b2 (instantiate $B (import "global" (global 0)))) - - (func (export "f") - call (func $b1 "f") - call (func $b2 "f") - ) - ) - - (module $DefinesGlobal - (global (export "global") (mut i32) (i32.const 0))) - (instance $global_instance (instantiate $DefinesGlobal)) - - (instance $a1 (instantiate $A (import "global" (global $global_instance "global")))) - (instance $a2 (instantiate $A (import "global" (global $global_instance "global")))) - - (func (export "wizer.initialize") - call (func $a1 "f") - call (func $a2 "f")) - - (func (export "run") (result i32) - global.get (global $global_instance "global")) -) -"#, - ) -} - -#[test] -fn module_linking_nested_instantiations_0() -> Result<()> { - run_wat( - &[], - 42, - r#" -(module - (module $A - (import "global" (global (mut i32))) - - (module $B - (import "global" (global (mut i32))) - - (func (export "f") - i32.const 42 - global.set 0 - ) - ) - - (instance $b (instantiate $B (import "global" (global 0)))) - - (func (export "f") - call (func $b "f") - ) - ) - - (module $G - (global (export "global") (mut i32) (i32.const 0))) - - (instance $g (instantiate $G)) - - (instance $a (instantiate $A (import "global" (global $g "global")))) - - (func (export "wizer.initialize") - call (func $a "f") - ) - - (func (export "run") (result i32) - global.get (global $g "global") - ) -) -"#, - ) -} - -// Test that we handle repeated and interleaved initial sections. -#[test] -fn multiple_initial_sections() -> Result<()> { - run_wat( - &[], - 42, - r#" -(module - ;; Module section. - (module $A - (memory (export "memory") 1) - ) - - ;; Instance section. - (instance $a (instantiate $A)) - - ;; Alias section. - (alias $a "memory" (memory $memory)) - - ;; Module section. - (module $B - (import "memory" (memory 1)) - (func (export "init") - i32.const 0 - i32.const 42 - i32.store offset=1337 - ) - ) - - ;; Instance section. - (instance $b (instantiate $B (import "memory" (memory $memory)))) - - ;; Alias section. - (alias $b "init" (func $b-init)) - - ;; Module section. - (module $C - (import "memory" (memory 1)) - (func (export "run") (result i32) - i32.const 0 - i32.load offset=1337 - ) - ) - - ;; Instance section. - (instance $c (instantiate $C (import "memory" (memory $memory)))) - - ;; Alias section. - (alias $c "run" (func $c-run)) - - ;; Done with initial sections. - - (func (export "wizer.initialize") - call $b-init - ) - - (func (export "run") (result i32) - call $c-run - ) -) -"#, - ) -} - -#[test] -fn start_sections_in_nested_modules() -> Result<()> { - run_wat( - &[], - 42, - r#" -(module - (module $A - (import "global" (global $g (mut i32))) - (func $init - i32.const 41 - global.set $g) - (start $init) - ) - - (module $B - (global (export "global") (mut i32) (i32.const 0)) - ) - - (instance $b (instantiate $B)) - (alias $b "global" (global $g)) - (instance $a (instantiate $A (import "global" (global $g)))) - - (func (export "wizer.initialize") - global.get $g - i32.const 1 - i32.add - global.set $g - ) - (func (export "run") (result i32) - global.get $g - ) -) -"#, - ) -} - -#[test] -fn allow_function_imports_module_linking() -> Result<()> { - // Make sure that the umbrella module passes imports through to its - // instantiation of the root, and that the root can pass them along to its - // nested instantiations as well. - run_wat( - &[], - 42, - r#" -(module - (import "dummy_func" (func $dummy)) - (module $A - (import "dummy_func" (func))) - (instance (instantiate $A (import "dummy_func" (func $dummy)))) - (func (export "wizer.initialize") - nop - ) - (func (export "run") (result i32) - i32.const 42 - ) -) -"#, - ) -} - -#[test] -fn outer_module_alias() -> Result<()> { - run_wat( - &[], - 42, - r#" -(module - (module $A - (global (export "g") (mut i32) (i32.const 0)) - ) - - (module $B - (alias outer 0 0 (module $A)) - (instance $a (instantiate $A)) - (func (export "init") - i32.const 42 - global.set (global $a "g") - ) - (func (export "run") (result i32) - global.get (global $a "g") - ) - ) - (instance $b (instantiate $B)) - - (func (export "wizer.initialize") - call (func $b "init") - ) - (func (export "run") (result i32) - call (func $b "run") - ) -) -"#, - ) -} - -#[test] -fn instance_alias_without_entry_in_type_section() -> Result<()> { - run_wat( - &[], - 42, - r#" -(module - (module $CHILD - (module $a) - (instance $a (instantiate $a)) - (export "a" (instance $a))) - (instance $child (instantiate $CHILD)) - - ;; This root module doesn't ever declare an instance type for this alias. - (alias $child "a" (instance $no_type_for_this_instance)) - - (func (export "wizer.initialize") - nop - ) - (func (export "run") (result i32) - i32.const 42 - ) -) -"#, - ) -} - -#[test] -fn two_level_imports_and_implicit_instance_imports() -> Result<()> { - run_wat( - &[], - 42, - r#" -(module - ;; First, import an instance to make sure that we are accounting for already - ;; imported instances when forwarding implicit instances and are getting the - ;; index space correct. - (import "dummy_instance" (instance)) - - ;; This implicitly creates an instance import like: - ;; - ;; (import (env (instance (export "f" (func $f))))) - ;; - ;; We will have to forward this implicit instance from the umbrella to the - ;; root instantiation. - (import "env" "f" (func $f)) - - (module $A - (import "env" "f" (func))) - - ;; Pass that implicit instance through when instantiating `$A`. - (instance $a (instantiate $A (import "env" (instance 1)))) - - (func (export "wizer.initialize") - nop - ) - (func (export "run") (result i32) - i32.const 42 - ) -) -"#, - ) -} - -#[test] -fn implicit_instance_imports_and_other_instances() -> Result<()> { - // Test how implicit instance import injection interacts with explicit - // instance imports and explicit instantiations. - run_wat( - &[], - 42, - r#" -(module - (module $A - ;; This implicitly creates an instance import like: - ;; - ;; (import (env (instance (export "f" (func $f (result i32)))))) - (import "env" "f" (func $f (result i32))) - - (import "env2" (instance $env2 (export "g" (func (result i32))))) - - (module $B - (func (export "h") (result i32) - i32.const 1 - ) - ) - (instance $b (instantiate $B)) - - (func (export "run") (result i32) - call $f - call (func $env2 "g") - call (func $b "h") - i32.add - i32.add - ) - ) - - (module $Env - (func (export "f") (result i32) - i32.const 2 - ) - ) - (instance $env (instantiate $Env)) - - (module $Env2 - (func (export "g") (result i32) - i32.const 39 - ) - ) - (instance $env2 (instantiate $Env2)) - - (instance $a (instantiate $A - (import "env" (instance $env)) - (import "env2" (instance $env2)))) - - (func (export "wizer.initialize") - nop - ) - (func (export "run") (result i32) - call (func $a "run") - ) -) -"#, - ) -} - #[test] fn rust_regex() -> Result<()> { run_wasm( @@ -965,54 +438,6 @@ fn rename_functions() -> Result<()> { Ok(()) } -#[test] -fn renames_and_module_linking() -> Result<()> { - let wat = r#" -(module - (module $A - (func (export "a") (result i32) - i32.const 1) - (func (export "b") (result i32) - i32.const 2) - (func (export "c") (result i32) - i32.const 3) - ) - (instance $a (instantiate $A)) - (func (export "wizer.initialize") - nop - ) - (func (export "a") (result i32) - call (func $a "a") - ) - (func (export "b") (result i32) - call (func $a "b") - ) - (func (export "c") (result i32) - call (func $a "c") - ) -) - "#; - - let wasm = wat_to_wasm(wat)?; - let mut wizer = Wizer::new(); - wizer.wasm_module_linking(true); - wizer.allow_wasi(true).unwrap(); - wizer.func_rename("a", "b"); - wizer.func_rename("b", "c"); - let wasm = wizer.run(&wasm)?; - let wat = wasmprinter::print_bytes(&wasm)?; - - let expected_wat = r#" - (alias 1 "b" (func (;0;))) - (alias 1 "c" (func (;1;))) - (export "a" (func 0)) - (export "b" (func 1))) - "#; - - assert!(wat.trim().ends_with(expected_wat.trim())); - Ok(()) -} - #[test] fn wasi_reactor() -> anyhow::Result<()> { run_wat( @@ -1069,74 +494,6 @@ fn allow_undefined_import_function() -> Result<()> { ) } -#[test] -fn call_undefined_instance_import_function_during_init() -> Result<()> { - fails_wizening( - r#" - (module - (import "x" (instance (export "f" (func)))) - (alias 0 "f" (func $import)) - (func (export "wizer.initialize") - (call $import) - ) - ) - "#, - ) -} - -#[test] -fn allow_undefined_instance_import_function() -> Result<()> { - run_wat( - &[], - 42, - r#" - (module - (import "x" (instance (export "f" (func)))) - (func (export "wizer.initialize")) - (func (export "run") (result i32) - i32.const 42 - ) - ) - "#, - ) -} - -#[test] -fn reject_import_instance_global() -> Result<()> { - fails_wizening( - r#" - (module - (import "x" (instance (export "g" (global i32)))) - (func (export "wizer.initialize")) - ) - "#, - ) -} - -#[test] -fn reject_import_instance_table() -> Result<()> { - fails_wizening( - r#" - (module - (import "x" (instance (export "t" (table 0 externref)))) - (func (export "wizer.initialize")) - ) - "#, - ) -} - -#[test] -fn reject_import_instance_memory() -> Result<()> { - fails_wizening( - r#" - (module - (import "x" (instance (export "m" (memory 0)))) - (func (export "wizer.initialize")) - ) - "#, - ) -} - #[test] fn accept_bulk_memory_copy() -> Result<()> { run_wat( From 4caa57def147625cdf6b10d64e616690fd20246e Mon Sep 17 00:00:00 2001 From: Jake Champion Date: Sun, 8 Jan 2023 16:50:41 +0000 Subject: [PATCH 2/9] update to wasmtime 3.0.0 this update required changes from the removed `Trap::new` to anyhow! macro, Trap::new was removed in https://github.com/bytecodealliance/wasmtime/pull/5149/ --- Cargo.lock | 691 +++++++++++++++++++++++++++---------------- Cargo.toml | 6 +- fuzz/Cargo.toml | 2 +- src/dummy.rs | 6 +- tests/make_linker.rs | 6 +- tests/tests.rs | 28 +- 6 files changed, 478 insertions(+), 261 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d0f9504..69753d4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,30 +2,15 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "addr2line" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e61f2b7f93d2c7d2b08263acaa4a363b3e276806c68af6134c44f523bf1aacd" -dependencies = [ - "gimli 0.25.0", -] - [[package]] name = "addr2line" version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b" dependencies = [ - "gimli 0.26.1", + "gimli", ] -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - [[package]] name = "ahash" version = "0.7.6" @@ -76,6 +61,12 @@ dependencies = [ "derive_arbitrary", ] +[[package]] +name = "arrayvec" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" + [[package]] name = "async-trait" version = "0.1.51" @@ -104,21 +95,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" -[[package]] -name = "backtrace" -version = "0.3.61" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7a905d892734eea339e896738c14b9afce22b5318f64b951e70bf3844419b01" -dependencies = [ - "addr2line 0.16.0", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object 0.26.2", - "rustc-demangle", -] - [[package]] name = "base64" version = "0.13.0" @@ -142,9 +118,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "block-buffer" -version = "0.9.0" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" dependencies = [ "generic-array", ] @@ -175,14 +151,14 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "cap-fs-ext" -version = "0.24.1" +version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71f5b22f0dc04ed3404bfae102654978bfd425c5568851a89eb4d4b8f58e9590" +checksum = "0b0e103ce36d217d568903ad27b14ec2238ecb5d65bad2e756a8f3c0d651506e" dependencies = [ - "cap-primitives", - "cap-std", - "io-lifetimes", - "winapi", + "cap-primitives 0.26.1", + "cap-std 0.26.1", + "io-lifetimes 0.7.5", + "windows-sys 0.36.1", ] [[package]] @@ -193,22 +169,40 @@ checksum = "defd283f080043a702c362203c2646a4e0a2fff99baede1eea1416239f0af220" dependencies = [ "ambient-authority", "errno", - "fs-set-times", - "io-extras", - "io-lifetimes", + "fs-set-times 0.15.0", + "io-extras 0.13.2", + "io-lifetimes 0.5.3", "ipnet", "maybe-owned", - "rustix", + "rustix 0.33.7", "winapi", "winapi-util", - "winx", + "winx 0.31.0", +] + +[[package]] +name = "cap-primitives" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af3f336aa91cce16033ed3c94ac91d98956c49b420e6d6cd0dd7d0e386a57085" +dependencies = [ + "ambient-authority", + "fs-set-times 0.17.1", + "io-extras 0.15.0", + "io-lifetimes 0.7.5", + "ipnet", + "maybe-owned", + "rustix 0.35.13", + "winapi-util", + "windows-sys 0.36.1", + "winx 0.33.0", ] [[package]] name = "cap-rand" -version = "0.24.1" +version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12627a93bdbbe4fb32c1ea2b2c2665ba54c49eb48f1139440ce4c6a279701461" +checksum = "d14b9606aa9550d34651bc481443203bc014237bdb992d201d2afa62d2ec6dea" dependencies = [ "ambient-authority", "rand", @@ -220,23 +214,36 @@ version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3430d1b5ba78fa381eb227525578d2b85d77b42ff49be85d1e72a94f305e603c" dependencies = [ - "cap-primitives", - "io-extras", - "io-lifetimes", + "cap-primitives 0.24.1", + "io-extras 0.13.2", + "io-lifetimes 0.5.3", "ipnet", - "rustix", + "rustix 0.33.7", +] + +[[package]] +name = "cap-std" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9d6e70b626eceac9d6fc790fe2d72cc3f2f7bc3c35f467690c54a526b0f56db" +dependencies = [ + "cap-primitives 0.26.1", + "io-extras 0.15.0", + "io-lifetimes 0.7.5", + "ipnet", + "rustix 0.35.13", ] [[package]] name = "cap-time-ext" -version = "0.24.1" +version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a34e5a4375b768b3acaec25dd7b53bcc15c801258c43a0ef2da2027f2028e46" +checksum = "c3a0524f7c4cff2ea547ae2b652bf7a348fd3e48f76556dc928d8b45ab2f1d50" dependencies = [ - "cap-primitives", + "cap-primitives 0.26.1", "once_cell", - "rustix", - "winx", + "rustix 0.35.13", + "winx 0.33.0", ] [[package]] @@ -298,25 +305,28 @@ dependencies = [ [[package]] name = "cranelift-bforest" -version = "0.85.3" +version = "0.90.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "749d0d6022c9038dccf480bdde2a38d435937335bf2bb0f14e815d94517cdce8" +checksum = "b62c772976416112fa4484cbd688cb6fb35fd430005c1c586224fc014018abad" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.85.3" +version = "0.90.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94370cc7b37bf652ccd8bb8f09bd900997f7ccf97520edfc75554bb5c4abbea" +checksum = "9b40ed2dd13c2ac7e24f88a3090c68ad3414eb1d066a95f8f1f7b3b819cb4e46" dependencies = [ + "arrayvec", + "bumpalo", "cranelift-bforest", "cranelift-codegen-meta", "cranelift-codegen-shared", + "cranelift-egraph", "cranelift-entity", "cranelift-isle", - "gimli 0.26.1", + "gimli", "log", "regalloc2", "smallvec", @@ -325,33 +335,47 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.85.3" +version = "0.90.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0a3cea8fdab90e44018c5b9a1dfd460d8ee265ac354337150222a354628bdb6" +checksum = "bb927a8f1c27c34ee3759b6b0ffa528d2330405d5cc4511f0cab33fe2279f4b5" dependencies = [ "cranelift-codegen-shared", ] [[package]] name = "cranelift-codegen-shared" -version = "0.85.3" +version = "0.90.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ac72f76f2698598951ab26d8c96eaa854810e693e7dd52523958b5909fde6b2" +checksum = "43dfa417b884a9ab488d95fd6b93b25e959321fe7bfd7a0a960ba5d7fb7ab927" + +[[package]] +name = "cranelift-egraph" +version = "0.90.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a66b39785efd8513d2cca967ede56d6cc57c8d7986a595c7c47d0c78de8dce" +dependencies = [ + "cranelift-entity", + "fxhash", + "hashbrown", + "indexmap", + "log", + "smallvec", +] [[package]] name = "cranelift-entity" -version = "0.85.3" +version = "0.90.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09eaeacfcd2356fe0e66b295e8f9d59fdd1ac3ace53ba50de14d628ec902f72d" +checksum = "0637ffde963cb5d759bc4d454cfa364b6509e6c74cdaa21298add0ed9276f346" dependencies = [ "serde", ] [[package]] name = "cranelift-frontend" -version = "0.85.3" +version = "0.90.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dba69c9980d5ffd62c18a2bde927855fcd7c8dc92f29feaf8636052662cbd99c" +checksum = "fb72b8342685e850cb037350418f62cc4fc55d6c2eb9c7ca01b82f9f1a6f3d56" dependencies = [ "cranelift-codegen", "log", @@ -361,15 +385,15 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.85.3" +version = "0.90.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2920dc1e05cac40304456ed3301fde2c09bd6a9b0210bcfa2f101398d628d5b" +checksum = "850579cb9e4b448f7c301f1e6e6cbad99abe3f1f1d878a4994cb66e33c6db8cd" [[package]] name = "cranelift-native" -version = "0.85.3" +version = "0.90.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f04dfa45f9b2a6f587c564d6b63388e00cd6589d2df6ea2758cf79e1a13285e6" +checksum = "2d0a279e5bcba3e0466c734d8d8eb6bfc1ad29e95c37f3e4955b492b5616335e" dependencies = [ "cranelift-codegen", "libc", @@ -378,9 +402,9 @@ dependencies = [ [[package]] name = "cranelift-wasm" -version = "0.85.3" +version = "0.90.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31a46513ae6f26f3f267d8d75b5373d555fbbd1e68681f348d99df43f747ec54" +checksum = "e6b8c5e7ffb754093fb89ec4bd4f9dbb9f1c955427299e334917d284745835c2" dependencies = [ "cranelift-codegen", "cranelift-entity", @@ -388,7 +412,7 @@ dependencies = [ "itertools", "log", "smallvec", - "wasmparser 0.85.0", + "wasmparser 0.93.0", "wasmtime-types", ] @@ -481,6 +505,16 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + [[package]] name = "csv" version = "1.1.6" @@ -516,11 +550,12 @@ dependencies = [ [[package]] name = "digest" -version = "0.9.0" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" dependencies = [ - "generic-array", + "block-buffer", + "crypto-common", ] [[package]] @@ -635,11 +670,22 @@ version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7df62ee66ee2d532ea8d567b5a3f0d03ecd64636b98bad5be1e93dcc918b92aa" dependencies = [ - "io-lifetimes", - "rustix", + "io-lifetimes 0.5.3", + "rustix 0.33.7", "winapi", ] +[[package]] +name = "fs-set-times" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a267b6a9304912e018610d53fe07115d8b530b160e85db4d2d3a59f3ddde1aec" +dependencies = [ + "io-lifetimes 0.7.5", + "rustix 0.35.13", + "windows-sys 0.36.1", +] + [[package]] name = "fxhash" version = "0.2.1" @@ -676,12 +722,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "gimli" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0a01e0497841a3b2db4f8afa483cce65f7e96a3498bd6c541734792aeac8fe7" - [[package]] name = "gimli" version = "0.26.1" @@ -701,19 +741,13 @@ checksum = "62aca2aba2d62b4a7f5b33f3712cb1b0692779a56fb510499d5c0aa594daeaf3" [[package]] name = "hashbrown" -version = "0.11.2" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" dependencies = [ "ahash", ] -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - [[package]] name = "heck" version = "0.3.3" @@ -769,7 +803,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" dependencies = [ "autocfg", - "hashbrown 0.12.3", + "hashbrown", "serde", ] @@ -779,18 +813,44 @@ version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0c937cc9891c12eaa8c63ad347e4a288364b1328b924886970b47a14ab8f8f8" dependencies = [ - "io-lifetimes", + "io-lifetimes 0.5.3", "winapi", ] +[[package]] +name = "io-extras" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a5d8c2ab5becd8720e30fd25f8fa5500d8dc3fceadd8378f05859bd7b46fc49" +dependencies = [ + "io-lifetimes 0.7.5", + "windows-sys 0.36.1", +] + [[package]] name = "io-lifetimes" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec58677acfea8a15352d42fc87d11d63596ade9239e0a7c9352914417515dbe6" + +[[package]] +name = "io-lifetimes" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ce5ef949d49ee85593fc4d3f3f95ad61657076395cbbce23e2121fc5542074" dependencies = [ "libc", - "winapi", + "windows-sys 0.42.0", +] + +[[package]] +name = "io-lifetimes" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" +dependencies = [ + "libc", + "windows-sys 0.42.0", ] [[package]] @@ -801,14 +861,14 @@ checksum = "68f2d64f2edebec4ce84ad108148e67e1064789bee435edc5b60ad398714a3a9" [[package]] name = "is-terminal" -version = "0.1.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c89a757e762896bdbdfadf2860d0f8b0cea5e363d8cf3e7bdfeb63d1d976352" +checksum = "0d508111813f9af3afd2f92758f77e4ed2cc9371b642112c6a48d22eb73105c5" dependencies = [ "hermit-abi 0.2.0", - "io-lifetimes", - "rustix", - "winapi", + "io-lifetimes 0.7.5", + "rustix 0.35.13", + "windows-sys 0.36.1", ] [[package]] @@ -833,10 +893,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" [[package]] -name = "ittapi-rs" -version = "0.2.0" +name = "ittapi" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f712648a1ad72fbfb7adc2772c331e8d90f022f8cf30cbabefba2878dd3172b0" +checksum = "e8c4f6ff06169ce7048dac5150b1501c7e3716a929721aeb06b87e51a43e42f4" +dependencies = [ + "anyhow", + "ittapi-sys", + "log", +] + +[[package]] +name = "ittapi-sys" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87e078cce01485f418bae3beb34dd604aaedf2065502853c7da17fbce8e64eda" dependencies = [ "cc", ] @@ -900,6 +971,18 @@ version = "0.0.42" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5284f00d480e1c39af34e72f8ad60b94f47007e3481cd3b731c1d67190ddc7b7" +[[package]] +name = "linux-raw-sys" +version = "0.0.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4d2456c373231a208ad294c33dc5bff30051eafd954cd4caae83a712b12854d" + +[[package]] +name = "linux-raw-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" + [[package]] name = "log" version = "0.4.17" @@ -932,11 +1015,11 @@ checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" [[package]] name = "memfd" -version = "0.4.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6627dc657574b49d6ad27105ed671822be56e0d2547d413bfbf3e8d8fa92e7a" +checksum = "b20a59d985586e4a5aef64564ac77299f8586d8be6cf9106a5a40207e8908efb" dependencies = [ - "libc", + "rustix 0.36.6", ] [[package]] @@ -948,22 +1031,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "miniz_oxide" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" -dependencies = [ - "adler", - "autocfg", -] - -[[package]] -name = "more-asserts" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0debeb9fcf88823ea64d64e4a815ab1643f33127d995978e099942ce38f25238" - [[package]] name = "num-traits" version = "0.2.14" @@ -985,21 +1052,12 @@ dependencies = [ [[package]] name = "object" -version = "0.26.2" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39f37e50073ccad23b6d09bcb5b263f4e76d3bb6038e4a3c08e52162ffa8abc2" -dependencies = [ - "memchr", -] - -[[package]] -name = "object" -version = "0.28.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e42c982f2d955fac81dd7e1d0e1426a7d702acd9c98d19ab01083a6a0328c424" +checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53" dependencies = [ "crc32fast", - "hashbrown 0.11.2", + "hashbrown", "indexmap", "memchr", ] @@ -1016,12 +1074,6 @@ version = "11.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" -[[package]] -name = "opaque-debug" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" - [[package]] name = "paste" version = "1.0.5" @@ -1211,9 +1263,9 @@ dependencies = [ [[package]] name = "regalloc2" -version = "0.2.3" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a8d23b35d7177df3b9d31ed8a9ab4bf625c668be77a319d4f5efd4a5257701c" +checksum = "91b2eab54204ea0117fe9a060537e0b07a4e72f7c7d182361ecc346cab2240e5" dependencies = [ "fxhash", "log", @@ -1258,18 +1310,6 @@ dependencies = [ "regex", ] -[[package]] -name = "region" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877e54ea2adcd70d80e9179344c97f93ef0dffd6b03e1f4529e6e83ab2fa9ae0" -dependencies = [ - "bitflags", - "libc", - "mach", - "winapi", -] - [[package]] name = "rustc-demangle" version = "0.1.21" @@ -1293,14 +1333,44 @@ checksum = "938a344304321a9da4973b9ff4f9f8db9caf4597dfd9dda6a60b523340a0fff0" dependencies = [ "bitflags", "errno", - "io-lifetimes", + "io-lifetimes 0.5.3", "itoa 1.0.1", "libc", - "linux-raw-sys", + "linux-raw-sys 0.0.42", "once_cell", "winapi", ] +[[package]] +name = "rustix" +version = "0.35.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "727a1a6d65f786ec22df8a81ca3121107f235970dc1705ed681d3e6e8b9cd5f9" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes 0.7.5", + "itoa 1.0.1", + "libc", + "linux-raw-sys 0.0.46", + "once_cell", + "windows-sys 0.42.0", +] + +[[package]] +name = "rustix" +version = "0.36.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4feacf7db682c6c329c4ede12649cd36ecab0f3be5b7d74e6a20304725db4549" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes 1.0.3", + "libc", + "linux-raw-sys 0.1.4", + "windows-sys 0.42.0", +] + [[package]] name = "ryu" version = "1.0.5" @@ -1383,15 +1453,13 @@ dependencies = [ [[package]] name = "sha2" -version = "0.9.9" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" dependencies = [ - "block-buffer", "cfg-if", "cpufeatures", "digest", - "opaque-debug", ] [[package]] @@ -1464,18 +1532,18 @@ dependencies = [ [[package]] name = "system-interface" -version = "0.20.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e09bb3fb4e02ec4b87e182ea9718fadbc0fa3e50085b40a9af9690572b67f9e" +checksum = "92adbaf536f5aff6986e1e62ba36cee72b1718c5153eee08b9e728ddde3f6029" dependencies = [ "atty", "bitflags", "cap-fs-ext", - "cap-std", - "io-lifetimes", - "rustix", - "winapi", - "winx", + "cap-std 0.26.1", + "io-lifetimes 0.7.5", + "rustix 0.35.13", + "windows-sys 0.36.1", + "winx 0.33.0", ] [[package]] @@ -1638,44 +1706,45 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "wasi-cap-std-sync" -version = "0.38.3" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f086c5026d2fc3b268d138e65373f46422cc810f46d6e0776859c5027cb18728" +checksum = "ecbeebb8985a5423f36f976b2f4a0b3c6ce38d7d9a7247e1ce07aa2880e4f29b" dependencies = [ "anyhow", "async-trait", "cap-fs-ext", "cap-rand", - "cap-std", + "cap-std 0.26.1", "cap-time-ext", - "fs-set-times", - "io-extras", - "io-lifetimes", + "fs-set-times 0.17.1", + "io-extras 0.15.0", + "io-lifetimes 0.7.5", "is-terminal", - "lazy_static", - "rustix", + "once_cell", + "rustix 0.35.13", "system-interface", "tracing", "wasi-common", - "winapi", + "windows-sys 0.36.1", ] [[package]] name = "wasi-common" -version = "0.38.3" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e8844fede1c3787cc08853872f47e8bd91f6c939c7406bc7a5dba496b260c08" +checksum = "81e2171f3783fe6600ee24ff6c58ca1b329c55e458cc1622ecc1fd0427648607" dependencies = [ "anyhow", "bitflags", "cap-rand", - "cap-std", - "io-extras", - "rustix", + "cap-std 0.26.1", + "io-extras 0.15.0", + "rustix 0.35.13", "thiserror", "tracing", + "wasmtime", "wiggle", - "winapi", + "windows-sys 0.36.1", ] [[package]] @@ -1785,9 +1854,9 @@ checksum = "be92b6dcaa5af4b2a176b29be3bf1402fab9e69d313141185099c7d1684f2dca" [[package]] name = "wasmparser" -version = "0.85.0" +version = "0.93.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "570460c58b21e9150d2df0eaaedbb7816c34bcec009ae0dcc976e40ba81463e7" +checksum = "c5a4460aa3e271fa180b6a5d003e728f3963fb30e3ba0fa7c9634caa06049328" dependencies = [ "indexmap", ] @@ -1804,28 +1873,25 @@ dependencies = [ [[package]] name = "wasmtime" -version = "0.38.3" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f50eadf868ab6a04b7b511460233377d0bfbb92e417b2f6a98b98fef2e098f5" +checksum = "d18265705b1c49218776577d9f301d79ab06888c7f4a32e2ed24e68a55738ce7" dependencies = [ "anyhow", "async-trait", - "backtrace", "bincode", "cfg-if", "indexmap", - "lazy_static", "libc", "log", - "object 0.28.4", + "object", "once_cell", "paste", "psm", "rayon", - "region", "serde", "target-lexicon", - "wasmparser 0.85.0", + "wasmparser 0.93.0", "wasmtime-cache", "wasmtime-cranelift", "wasmtime-environ", @@ -1833,14 +1899,23 @@ dependencies = [ "wasmtime-jit", "wasmtime-runtime", "wat", - "winapi", + "windows-sys 0.36.1", +] + +[[package]] +name = "wasmtime-asm-macros" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a201583f6c79b96e74dcce748fa44fb2958f474ef13c93f880ea4d3bed31ae4f" +dependencies = [ + "cfg-if", ] [[package]] name = "wasmtime-cache" -version = "0.38.3" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1df23c642e1376892f3b72f311596976979cbf8b85469680cdd3a8a063d12a2" +checksum = "3f37efc6945b08fcb634cffafc438dd299bac55a27c836954656c634d3e63c31" dependencies = [ "anyhow", "base64", @@ -1848,19 +1923,19 @@ dependencies = [ "directories-next", "file-per-thread-logger", "log", - "rustix", + "rustix 0.35.13", "serde", "sha2", "toml", - "winapi", + "windows-sys 0.36.1", "zstd", ] [[package]] name = "wasmtime-cranelift" -version = "0.38.3" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f264ff6b4df247d15584f2f53d009fbc90032cfdc2605b52b961bffc71b6eccd" +checksum = "fe208297e045ea0ee6702be88772ea40f918d55fbd4163981a4699aff034b634" dependencies = [ "anyhow", "cranelift-codegen", @@ -1868,93 +1943,102 @@ dependencies = [ "cranelift-frontend", "cranelift-native", "cranelift-wasm", - "gimli 0.26.1", + "gimli", "log", - "more-asserts", - "object 0.28.4", + "object", "target-lexicon", "thiserror", - "wasmparser 0.85.0", + "wasmparser 0.93.0", "wasmtime-environ", ] [[package]] name = "wasmtime-environ" -version = "0.38.3" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "839d2820e4b830f4b9e7aa08d4c0acabf4a5036105d639f6dfa1c6891c73bdc6" +checksum = "754b97f7441ac780a7fa738db5b9c23c1b70ef4abccd8ad205ada5669d196ba2" dependencies = [ "anyhow", "cranelift-entity", - "gimli 0.26.1", + "gimli", "indexmap", "log", - "more-asserts", - "object 0.28.4", + "object", "serde", "target-lexicon", "thiserror", - "wasmparser 0.85.0", + "wasmparser 0.93.0", "wasmtime-types", ] [[package]] name = "wasmtime-fiber" -version = "0.38.3" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3248be3c4911233535356025f6562193614a40155ee9094bb6a2b43f0dc82803" +checksum = "e5f54abc960b4a055ba16b942cbbd1da641e0ad44cc97a7608f3d43c069b120e" dependencies = [ "cc", - "rustix", - "winapi", + "cfg-if", + "rustix 0.35.13", + "wasmtime-asm-macros", + "windows-sys 0.36.1", ] [[package]] name = "wasmtime-jit" -version = "0.38.3" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef0a0bcbfa18b946d890078ba0e1bc76bcc53eccfb40806c0020ec29dcd1bd49" +checksum = "32800cb6e29faabab7056593f70a4c00c65c75c365aaf05406933f2169d0c22f" dependencies = [ - "addr2line 0.17.0", + "addr2line", "anyhow", "bincode", "cfg-if", "cpp_demangle", - "gimli 0.26.1", - "ittapi-rs", + "gimli", + "ittapi", "log", - "object 0.28.4", - "region", + "object", "rustc-demangle", - "rustix", "serde", "target-lexicon", "thiserror", "wasmtime-environ", "wasmtime-jit-debug", + "wasmtime-jit-icache-coherence", "wasmtime-runtime", - "winapi", + "windows-sys 0.36.1", ] [[package]] name = "wasmtime-jit-debug" -version = "0.38.3" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f4779d976206c458edd643d1ac622b6c37e4a0800a8b1d25dfbf245ac2f2cac" +checksum = "fe057012a0ba6cee3685af1e923d6e0a6cb9baf15fb3ffa4be3d7f712c7dec42" dependencies = [ - "lazy_static", - "object 0.28.4", - "rustix", + "object", + "once_cell", + "rustix 0.35.13", +] + +[[package]] +name = "wasmtime-jit-icache-coherence" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6bbabb309c06cc238ee91b1455b748c45f0bdcab0dda2c2db85b0a1e69fcb66" +dependencies = [ + "cfg-if", + "libc", + "windows-sys 0.36.1", ] [[package]] name = "wasmtime-runtime" -version = "0.38.3" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7eb6ffa169eb5dcd18ac9473c817358cd57bc62c244622210566d473397954a" +checksum = "09a23b6e138e89594c0189162e524a29e217aec8f9a4e1959a34f74c64e8d17d" dependencies = [ "anyhow", - "backtrace", "cc", "cfg-if", "indexmap", @@ -1963,34 +2047,34 @@ dependencies = [ "mach", "memfd", "memoffset", - "more-asserts", + "paste", "rand", - "region", - "rustix", + "rustix 0.35.13", "thiserror", + "wasmtime-asm-macros", "wasmtime-environ", "wasmtime-fiber", "wasmtime-jit-debug", - "winapi", + "windows-sys 0.36.1", ] [[package]] name = "wasmtime-types" -version = "0.38.3" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d932b0ac5336f7308d869703dd225610a6a3aeaa8e968c52b43eed96cefb1c2" +checksum = "68ec7615fde8c79737f1345d81f0b18da83b3db929a87b4604f27c932246d1e2" dependencies = [ "cranelift-entity", "serde", "thiserror", - "wasmparser 0.85.0", + "wasmparser 0.93.0", ] [[package]] name = "wasmtime-wasi" -version = "0.38.3" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b68b7d77fb6f2975a6fe6cc4d0015d6b0cebb65c39fce1dd4cc00880dbf7789c" +checksum = "ca539adf155dca1407aa3656e5661bf2364b1f3ebabc7f0a8bd62629d876acfa" dependencies = [ "anyhow", "wasi-cap-std-sync", @@ -2041,9 +2125,9 @@ dependencies = [ [[package]] name = "wiggle" -version = "0.38.3" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67dadac11343d2aabc8a906a0db0aaf7cb5046ec3d6fffccdaf2847dccdef8d6" +checksum = "2da09ca5b8bb9278a2123e8c36342166b9aaa55a0dbab18b231f46d6f6ab85bc" dependencies = [ "anyhow", "async-trait", @@ -2056,9 +2140,9 @@ dependencies = [ [[package]] name = "wiggle-generate" -version = "0.38.3" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63a1dccd6b3fbd9a27417f5d30ce9aa3ee9cf529aad453abbf88a49c5d605b79" +checksum = "ba5796f53b429df7d44cfdaae8f6d9cd981d82aec3516561352ca9c5e73ee185" dependencies = [ "anyhow", "heck 0.4.0", @@ -2071,9 +2155,9 @@ dependencies = [ [[package]] name = "wiggle-macro" -version = "0.38.3" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1c368d57d9560c34deaa67e06b0953ccf65edb906c525e5a2c866c849b48ec2" +checksum = "8b830eb7203d48942fb8bc8bb105f76e7d09c33a082d638e990e02143bb2facd" dependencies = [ "proc-macro2", "quote", @@ -2112,6 +2196,106 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-sys" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" +dependencies = [ + "windows_aarch64_msvc 0.36.1", + "windows_i686_gnu 0.36.1", + "windows_i686_msvc 0.36.1", + "windows_x86_64_gnu 0.36.1", + "windows_x86_64_msvc 0.36.1", +] + +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc 0.42.0", + "windows_i686_gnu 0.42.0", + "windows_i686_msvc 0.42.0", + "windows_x86_64_gnu 0.42.0", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc 0.42.0", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" + +[[package]] +name = "windows_i686_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" + +[[package]] +name = "windows_i686_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" + [[package]] name = "winx" version = "0.31.0" @@ -2119,10 +2303,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d5973cb8cd94a77d03ad7e23bbe14889cb29805da1cec0e4aff75e21aebded" dependencies = [ "bitflags", - "io-lifetimes", + "io-lifetimes 0.5.3", "winapi", ] +[[package]] +name = "winx" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7b01e010390eb263a4518c8cebf86cb67469d1511c00b749a47b64c39e8054d" +dependencies = [ + "bitflags", + "io-lifetimes 0.7.5", + "windows-sys 0.36.1", +] + [[package]] name = "witx" version = "0.9.1" @@ -2140,7 +2335,7 @@ name = "wizer" version = "1.6.1-beta.4" dependencies = [ "anyhow", - "cap-std", + "cap-std 0.24.2", "criterion", "env_logger 0.8.4", "log", diff --git a/Cargo.toml b/Cargo.toml index e4c58e3..e6de990 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,11 +33,11 @@ env_logger = { version = "0.8.2", optional = true } log = "0.4.14" rayon = "1.5.0" structopt = { version = "0.3.21", optional = true } -wasi-cap-std-sync = "0.38.0" +wasi-cap-std-sync = "3.0.0" wasm-encoder = "0.6.0" wasmparser = "0.78.2" -wasmtime = "0.38.0" -wasmtime-wasi = "0.38.0" +wasmtime = "3.0.0" +wasmtime-wasi = "3.0.0" # Enable this dependency to get messages with WAT disassemblies when certain # internal panics occur. diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index a6d280c..ced2136 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -15,7 +15,7 @@ libfuzzer-sys = "0.4" log = "0.4.14" wasm-smith = "0.4.0" wasmprinter = "0.2.26" -wasmtime = "0.38.0" +wasmtime = "3.0.0" [dependencies.wizer] path = ".." diff --git a/src/dummy.rs b/src/dummy.rs index 0a6500a..0308881 100644 --- a/src/dummy.rs +++ b/src/dummy.rs @@ -2,7 +2,7 @@ //! //! Forked from `wasmtime/crates/fuzzing/src/oracles/dummy.rs`. -use anyhow::Result; +use anyhow::{anyhow, Result}; use wasmtime::*; /// Create dummy imports for instantiating the module. @@ -54,12 +54,12 @@ pub fn dummy_extern(store: &mut crate::Store, ty: ExternType, name: &str) -> Res pub fn dummy_func(store: &mut crate::Store, ty: FuncType, name: &str) -> Func { let name = name.to_string(); Func::new(store, ty.clone(), move |_caller, _params, _results| { - Err(Trap::new(format!( + Err(anyhow!( "Error: attempted to call an unknown imported function: {}\n\ \n\ You cannot call arbitrary imported functions during Wizer initialization.", name, - ))) + )) }) } diff --git a/tests/make_linker.rs b/tests/make_linker.rs index ebde070..2a43c91 100644 --- a/tests/make_linker.rs +++ b/tests/make_linker.rs @@ -1,4 +1,4 @@ -use anyhow::{Context, Result}; +use anyhow::{anyhow, Context, Result}; use std::rc::Rc; use wat::parse_str as wat_to_wasm; use wizer::Wizer; @@ -41,8 +41,8 @@ fn run_wasm(args: &[wasmtime::Val], expected: i32, wasm: &[u8]) -> Result<()> { wasmtime::Module::new(store.engine(), wasm).context("Wasm test case failed to compile")?; let mut linker = wasmtime::Linker::new(&engine); - linker.func_wrap("foo", "bar", |_: i32| -> Result { - Err(wasmtime::Trap::new("shouldn't be called")) + linker.func_wrap("foo", "bar", |_: i32| -> Result { + Err(anyhow!("shouldn't be called")) })?; let instance = linker.instantiate(&mut store, &module)?; diff --git a/tests/tests.rs b/tests/tests.rs index cb56f71..dbd9182 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -42,9 +42,6 @@ fn run_wasm(args: &[wasmtime::Val], expected: i32, wasm: &[u8]) -> Result<()> { let module = wasmtime::Module::new(store.engine(), wasm).context("Wasm test case failed to compile")?; - let dummy_module = wasmtime::Module::new(store.engine(), &wat::parse_str("(module)")?)?; - let dummy_instance = wasmtime::Instance::new(&mut store, &dummy_module, &[])?; - let mut linker = wasmtime::Linker::new(&engine); linker .define_name("dummy_func", wasmtime::Func::wrap(&mut store, || {}))? @@ -135,6 +132,31 @@ fn basic_memory() -> Result<()> { ) } +#[test] +fn multi_memory() -> Result<()> { + run_wat( + &[], + 42, + r#" +(module + (memory $m1 1) + (memory $m2 1) + (func (export "wizer.initialize") + i32.const 0 + i32.const 41 + i32.store $m1 offset=1337 + i32.const 0 + i32.const 1 + i32.store $m2 offset=1) + (func (export "run") (result i32) + i32.const 0 + i32.load $m1 offset=1337 + i32.const 0 + i32.load $m2 offset=1 + i32.add)) +"#, + ) +} #[test] fn reject_imported_memory() -> Result<()> { fails_wizening( From 05b7a1814e78b4f5bdf4850ff0daf4f4ffdd7fa4 Mon Sep 17 00:00:00 2001 From: Jake Champion Date: Mon, 9 Jan 2023 17:30:16 +0000 Subject: [PATCH 3/9] Update tests.rs --- tests/tests.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/tests.rs b/tests/tests.rs index dbd9182..48b17a7 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -139,21 +139,21 @@ fn multi_memory() -> Result<()> { 42, r#" (module - (memory $m1 1) - (memory $m2 1) - (func (export "wizer.initialize") - i32.const 0 - i32.const 41 - i32.store $m1 offset=1337 - i32.const 0 - i32.const 1 - i32.store $m2 offset=1) - (func (export "run") (result i32) - i32.const 0 - i32.load $m1 offset=1337 - i32.const 0 - i32.load $m2 offset=1 - i32.add)) + (memory $m1 1) + (memory $m2 1) + (func (export "wizer.initialize") + i32.const 0 + i32.const 41 + i32.store $m1 offset=1337 + i32.const 0 + i32.const 1 + i32.store $m2 offset=1337) + (func (export "run") (result i32) + i32.const 0 + i32.load $m1 offset=1337 + i32.const 0 + i32.load $m2 offset=1337 + i32.add)) "#, ) } From ed4426a84a884f4fedb15fd19fbaebb3126e577f Mon Sep 17 00:00:00 2001 From: Jake Champion Date: Tue, 10 Jan 2023 00:05:48 +0000 Subject: [PATCH 4/9] print out the pre-wizened wasm when debugging --- tests/tests.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/tests.rs b/tests/tests.rs index 48b17a7..95e1515 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -20,15 +20,21 @@ fn get_wizer() -> Wizer { fn run_wasm(args: &[wasmtime::Val], expected: i32, wasm: &[u8]) -> Result<()> { let _ = env_logger::try_init(); + log::debug!( + "=== PreWizened Wasm ==========================================================\n\ + {}\n\ + ===========================================================================", + wasmprinter::print_bytes(&wasm).unwrap() + ); let wasm = get_wizer().run(&wasm)?; log::debug!( - "=== Wizened Wasm ==========================================================\n\ - {}\n\ - ===========================================================================", - wasmprinter::print_bytes(&wasm).unwrap() + "=== Wizened Wasm ==========================================================\n\ + {}\n\ + ===========================================================================", + wasmprinter::print_bytes(&wasm).unwrap() ); if log::log_enabled!(log::Level::Debug) { - std::fs::write("test.wasm", &wasm).unwrap(); + std::fs::write("test.wasm", &wasm).unwrap(); } let mut config = wasmtime::Config::new(); From 309df093f9e8155ac0afaac31a43a96ac6415bb2 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 14 Apr 2023 13:32:40 -0700 Subject: [PATCH 5/9] Update wat/wasmprinter deps Bring these up-to-date with the latest. --- Cargo.lock | 100 +++++++++++++++++++++++++++++++++++++++++-------- Cargo.toml | 4 +- tests/tests.rs | 22 ++++++----- 3 files changed, 100 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 69753d4..d154e8b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -664,6 +664,15 @@ dependencies = [ "log", ] +[[package]] +name = "form_urlencoded" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" +dependencies = [ + "percent-encoding", +] + [[package]] name = "fs-set-times" version = "0.15.0" @@ -796,6 +805,16 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[package]] +name = "idna" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "indexmap" version = "1.9.2" @@ -1080,6 +1099,12 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf547ad0c65e31259204bd90935776d1c693cec2f4ff7abb7a1bbbd40dfe58" +[[package]] +name = "percent-encoding" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" + [[package]] name = "pin-project-lite" version = "0.2.7" @@ -1600,6 +1625,21 @@ dependencies = [ "serde_json", ] +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + [[package]] name = "toml" version = "0.5.8" @@ -1657,6 +1697,21 @@ dependencies = [ "serde_yaml", ] +[[package]] +name = "unicode-bidi" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" + +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + [[package]] name = "unicode-segmentation" version = "1.8.0" @@ -1675,6 +1730,17 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +[[package]] +name = "url" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + [[package]] name = "vec_map" version = "0.8.2" @@ -1821,9 +1887,9 @@ dependencies = [ [[package]] name = "wasm-encoder" -version = "0.20.0" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05632e0a66a6ed8cca593c24223aabd6262f256c3693ad9822c315285f010614" +checksum = "4eff853c4f09eec94d76af527eddad4e9de13b11d6286a1ef7134bc30135a2b7" dependencies = [ "leb128", ] @@ -1848,27 +1914,31 @@ checksum = "52144d4c78e5cf8b055ceab8e5fa22814ce4315d6002ad32cfd914f37c12fd65" [[package]] name = "wasmparser" -version = "0.80.1" +version = "0.93.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be92b6dcaa5af4b2a176b29be3bf1402fab9e69d313141185099c7d1684f2dca" +checksum = "c5a4460aa3e271fa180b6a5d003e728f3963fb30e3ba0fa7c9634caa06049328" +dependencies = [ + "indexmap", +] [[package]] name = "wasmparser" -version = "0.93.0" +version = "0.103.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5a4460aa3e271fa180b6a5d003e728f3963fb30e3ba0fa7c9634caa06049328" +checksum = "2c437373cac5ea84f1113d648d51f71751ffbe3d90c00ae67618cf20d0b5ee7b" dependencies = [ "indexmap", + "url", ] [[package]] name = "wasmprinter" -version = "0.2.29" +version = "0.2.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f62f18810edc34db799bcb3d555835b2eecc9b6b221f8ee74fdb5aae0bffa176" +checksum = "51befda9d7eefac615a2ef75f42d2f2bd243cdabaa141a8ea0f9ffa3fc79ccf4" dependencies = [ "anyhow", - "wasmparser 0.80.1", + "wasmparser 0.103.0", ] [[package]] @@ -2094,23 +2164,23 @@ dependencies = [ [[package]] name = "wast" -version = "50.0.0" +version = "56.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2cbb59d4ac799842791fe7e806fa5dbbf6b5554d538e51cc8e176db6ff0ae34" +checksum = "6b54185c051d7bbe23757d50fe575880a2426a2f06d2e9f6a10fd9a4a42920c0" dependencies = [ "leb128", "memchr", "unicode-width", - "wasm-encoder 0.20.0", + "wasm-encoder 0.25.0", ] [[package]] name = "wat" -version = "1.0.52" +version = "1.0.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "584aaf7a1ecf4d383bbe1a25eeab0cbb8ff96acc6796707ff65cde48f4632f15" +checksum = "56681922808216ab86d96bb750f70d500b5a7800e41564290fd46bb773581299" dependencies = [ - "wast 50.0.0", + "wast 56.0.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index e6de990..4d46480 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,8 +49,8 @@ optional = true [dev-dependencies] criterion = "0.3.4" env_logger = "0.8.2" -wasmprinter = "0.2.26" -wat = "1.0.36" +wasmprinter = "0.2.55" +wat = "1.0.62" [workspace] members = [ diff --git a/tests/tests.rs b/tests/tests.rs index 95e1515..f56ab4c 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -21,20 +21,20 @@ fn run_wasm(args: &[wasmtime::Val], expected: i32, wasm: &[u8]) -> Result<()> { let _ = env_logger::try_init(); log::debug!( - "=== PreWizened Wasm ==========================================================\n\ + "=== PreWizened Wasm ==========================================================\n\ {}\n\ ===========================================================================", - wasmprinter::print_bytes(&wasm).unwrap() + wasmprinter::print_bytes(&wasm).unwrap() ); let wasm = get_wizer().run(&wasm)?; log::debug!( - "=== Wizened Wasm ==========================================================\n\ + "=== Wizened Wasm ==========================================================\n\ {}\n\ ===========================================================================", - wasmprinter::print_bytes(&wasm).unwrap() + wasmprinter::print_bytes(&wasm).unwrap() ); if log::log_enabled!(log::Level::Debug) { - std::fs::write("test.wasm", &wasm).unwrap(); + std::fs::write("test.wasm", &wasm).unwrap(); } let mut config = wasmtime::Config::new(); @@ -453,13 +453,17 @@ fn rename_functions() -> Result<()> { (type (;1;) (func (result i32))) (func (;0;) (type 0)) (func (;1;) (type 1) (result i32) - i32.const 1) + i32.const 1 + ) (func (;2;) (type 1) (result i32) - i32.const 2) + i32.const 2 + ) (func (;3;) (type 1) (result i32) - i32.const 3) + i32.const 3 + ) (export "func_a" (func 2)) - (export "func_b" (func 3))) + (export "func_b" (func 3)) +) "#; assert_eq!(wat.trim(), expected_wat.trim()); From 2e71749bc74d67e2e0bf7aa2d03fa6f8cdf3451c Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 14 Apr 2023 14:31:36 -0700 Subject: [PATCH 6/9] Update wasmparser/wasm-encoder deps incrementally These dependencies are far behind the latest versions so this fast-forwards them up to versions where larger changes are required. This updates them enough to perform some minor rewrites here and there but nothing major is changing. --- Cargo.lock | 12 ++++++------ Cargo.toml | 4 ++-- src/info.rs | 4 ++-- src/info/types_interner.rs | 2 +- src/instrument.rs | 2 +- src/lib.rs | 6 ++++++ src/parse.rs | 34 ++++++++++++++++++---------------- src/rewrite.rs | 9 +++++---- src/translate.rs | 25 ++++++++++--------------- tests/tests.rs | 10 +++++----- 10 files changed, 56 insertions(+), 52 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d154e8b..2bbb74e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1878,9 +1878,9 @@ dependencies = [ [[package]] name = "wasm-encoder" -version = "0.6.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2caacc74c68c74f0008c4055cdf509c43e623775eaf73323bb818dcf666ed9bd" +checksum = "aa9d9bf45fc46f71c407837c9b30b1e874197f2dc357588430b21e5017d290ab" dependencies = [ "leb128", ] @@ -1908,9 +1908,9 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.78.2" +version = "0.83.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52144d4c78e5cf8b055ceab8e5fa22814ce4315d6002ad32cfd914f37c12fd65" +checksum = "718ed7c55c2add6548cca3ddd6383d738cd73b892df400e96b9aa876f0141d7a" [[package]] name = "wasmparser" @@ -2412,8 +2412,8 @@ dependencies = [ "rayon", "structopt", "wasi-cap-std-sync", - "wasm-encoder 0.6.0", - "wasmparser 0.78.2", + "wasm-encoder 0.10.0", + "wasmparser 0.83.0", "wasmprinter", "wasmtime", "wasmtime-wasi", diff --git a/Cargo.toml b/Cargo.toml index 4d46480..d833da3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,8 +34,8 @@ log = "0.4.14" rayon = "1.5.0" structopt = { version = "0.3.21", optional = true } wasi-cap-std-sync = "3.0.0" -wasm-encoder = "0.6.0" -wasmparser = "0.78.2" +wasm-encoder = "0.10.0" +wasmparser = "0.83.0" wasmtime = "3.0.0" wasmtime-wasi = "3.0.0" diff --git a/src/info.rs b/src/info.rs index 738157a..a5fbc41 100644 --- a/src/info.rs +++ b/src/info.rs @@ -355,7 +355,7 @@ impl Module { wasmparser::ImportSectionEntryType::Module(_) => { unreachable!("we disallow module imports; checked in validation") } - wasmparser::ImportSectionEntryType::Event(_) => { + wasmparser::ImportSectionEntryType::Tag(_) => { unreachable!("exceptions are unsupported; checked in validation") } } @@ -439,7 +439,7 @@ impl Module { } wasmparser::ExternalKind::Module | wasmparser::ExternalKind::Type - | wasmparser::ExternalKind::Event => unreachable!(), + | wasmparser::ExternalKind::Tag => unreachable!(), }; (name, entity) }) diff --git a/src/info/types_interner.rs b/src/info/types_interner.rs index b6179b7..4b1df08 100644 --- a/src/info/types_interner.rs +++ b/src/info/types_interner.rs @@ -161,7 +161,7 @@ impl<'a> TypesInterner<'a> { wasmparser::ImportSectionEntryType::Instance(idx) => { EntityType::Instance(types_space[usize::try_from(idx).unwrap()]) } - wasmparser::ImportSectionEntryType::Event(_) => unreachable!(), + wasmparser::ImportSectionEntryType::Tag(_) => unreachable!(), } } diff --git a/src/instrument.rs b/src/instrument.rs index 377cbab..5f959c5 100644 --- a/src/instrument.rs +++ b/src/instrument.rs @@ -135,7 +135,7 @@ pub(crate) fn instrument(cx: &ModuleContext<'_>) -> Vec { } wasmparser::ExternalKind::Module | wasmparser::ExternalKind::Type - | wasmparser::ExternalKind::Event => { + | wasmparser::ExternalKind::Tag => { unreachable!("should have been rejected in validation/parsing") } }, diff --git a/src/lib.rs b/src/lib.rs index 884fec5..3afa289 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -559,6 +559,10 @@ impl Wizer { // NB: keep this in sync with the Wasmtime config. fn wasm_features(&self) -> wasmparser::WasmFeatures { wasmparser::WasmFeatures { + mutable_global: true, + saturating_float_to_int: true, + sign_extension: true, + // Proposals that we support. multi_memory: self.wasm_multi_memory.unwrap_or(DEFAULT_WASM_MULTI_MEMORY), multi_value: self.wasm_multi_value.unwrap_or(DEFAULT_WASM_MULTI_VALUE), @@ -573,6 +577,8 @@ impl Wizer { tail_call: false, memory64: false, exceptions: false, + extended_const: false, + relaxed_simd: false, // XXX: Though we don't fully support bulk memory yet, we // unconditionally turn it on. diff --git a/src/parse.rs b/src/parse.rs index 474dcf6..5679076 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -116,7 +116,7 @@ pub(crate) fn parse<'a>(full_wasm: &'a [u8]) -> anyhow::Result } CodeSectionEntry(_) => unreachable!(), UnknownSection { .. } => anyhow::bail!("unknown section"), - EventSection(_) => anyhow::bail!("exceptions are not supported yet"), + TagSection(_) => anyhow::bail!("exceptions are not supported yet"), End => { let entry = stack.pop().unwrap(); @@ -329,19 +329,21 @@ fn check_import_type( _ => unreachable!(), } } - EntityType::Memory(mem_ty) => match mem_ty { - wasmparser::MemoryType::M32 { limits: _, shared } => { - anyhow::ensure!(!shared, "shared memories are not supported by Wizer yet"); - anyhow::ensure!( - !is_root, - "memory imports are not allowed in the root Wasm module" - ); - Ok(()) - } - wasmparser::MemoryType::M64 { .. } => { - anyhow::bail!("the memory64 proposal is not supported by Wizer yet") - } - }, + EntityType::Memory(mem_ty) => { + anyhow::ensure!( + !mem_ty.shared, + "shared memories are not supported by Wizer yet" + ); + anyhow::ensure!( + !mem_ty.memory64, + "the memory64 proposal is not supported by Wizer yet" + ); + anyhow::ensure!( + !is_root, + "memory imports are not allowed in the root Wasm module" + ); + Ok(()) + } EntityType::Table(_) | EntityType::Global(_) => { anyhow::ensure!( !is_root, @@ -436,7 +438,7 @@ fn alias_section<'a>( }; module.push_imported_global(cx, ty); } - wasmparser::ExternalKind::Event => { + wasmparser::ExternalKind::Tag => { unreachable!("validation should reject the exceptions proposal") } wasmparser::ExternalKind::Type => unreachable!("can't export types"), @@ -568,7 +570,7 @@ fn export_section<'a>( wasmparser::ExternalKind::Module => { anyhow::bail!("Wizer does not support importing and exporting modules") } - wasmparser::ExternalKind::Type | wasmparser::ExternalKind::Event => { + wasmparser::ExternalKind::Type | wasmparser::ExternalKind::Tag => { unreachable!("checked in validation") } wasmparser::ExternalKind::Function diff --git a/src/rewrite.rs b/src/rewrite.rs index 7b9dd1c..09a0d34 100644 --- a/src/rewrite.rs +++ b/src/rewrite.rs @@ -59,7 +59,7 @@ impl Wizer { for seg in &snapshot.data_segments { data_section.active( seg.memory_index, - wasm_encoder::Instruction::I32Const(seg.offset as i32), + &wasm_encoder::Instruction::I32Const(seg.offset as i32), seg.data(store).iter().copied(), ); } @@ -115,7 +115,7 @@ impl Wizer { let glob_ty = translate::global_type(glob_ty); globals.global( glob_ty, - match val { + &match val { wasmtime::Val::I32(x) => wasm_encoder::Instruction::I32Const(*x), wasmtime::Val::I64(x) => wasm_encoder::Instruction::I64Const(*x), wasmtime::Val::F32(x) => { @@ -477,6 +477,7 @@ impl Wizer { wasm_encoder::Export::Instance(umbrella_instances - 1) } wasm_encoder::ItemKind::Module => unreachable!(), + wasm_encoder::ItemKind::Tag => unreachable!(), }, ); } @@ -1089,7 +1090,7 @@ fn rewrite_state_module( let glob_ty = translate::global_type(glob_ty); globals.global( glob_ty, - match val { + &match val { wasmtime::Val::I32(x) => wasm_encoder::Instruction::I32Const(*x), wasmtime::Val::I64(x) => wasm_encoder::Instruction::I64Const(*x), wasmtime::Val::F32(x) => { @@ -1120,7 +1121,7 @@ fn rewrite_state_module( for seg in &snapshot.data_segments { data.active( seg.memory_index, - wasm_encoder::Instruction::I32Const(seg.offset as i32), + &wasm_encoder::Instruction::I32Const(seg.offset as i32), seg.data(store).iter().copied(), ); } diff --git a/src/translate.rs b/src/translate.rs index 7ff9b83..b205e15 100644 --- a/src/translate.rs +++ b/src/translate.rs @@ -3,8 +3,8 @@ pub(crate) fn table_type(table_ty: wasmparser::TableType) -> wasm_encoder::TableType { wasm_encoder::TableType { element_type: val_type(table_ty.element_type), - minimum: table_ty.limits.initial, - maximum: table_ty.limits.maximum, + minimum: table_ty.initial, + maximum: table_ty.maximum, } } @@ -31,16 +31,11 @@ pub(crate) fn global_type(ty: wasmparser::GlobalType) -> wasm_encoder::GlobalTyp } pub(crate) fn memory_type(ty: wasmparser::MemoryType) -> wasm_encoder::MemoryType { - match ty { - wasmparser::MemoryType::M32 { - shared: false, - limits: lims, - } => wasm_encoder::MemoryType { - minimum: lims.initial.into(), - maximum: lims.maximum.map(|val| val.into()), - memory64: false, - }, - _ => unreachable!("handled in validation"), + assert!(!ty.shared); + wasm_encoder::MemoryType { + minimum: ty.initial.into(), + maximum: ty.maximum.map(|val| val.into()), + memory64: ty.memory64, } } @@ -65,7 +60,7 @@ pub(crate) fn entity_type(ty: wasmparser::ImportSectionEntryType) -> wasm_encode have module types" ) } - wasmparser::ImportSectionEntryType::Event(_) => unreachable!(), + wasmparser::ImportSectionEntryType::Tag(_) => unreachable!(), } } @@ -77,7 +72,7 @@ pub(crate) fn item_kind(kind: wasmparser::ExternalKind) -> wasm_encoder::ItemKin wasmparser::ExternalKind::Global => wasm_encoder::ItemKind::Global, wasmparser::ExternalKind::Module => wasm_encoder::ItemKind::Module, wasmparser::ExternalKind::Instance => wasm_encoder::ItemKind::Instance, - wasmparser::ExternalKind::Type | wasmparser::ExternalKind::Event => unreachable!(), + wasmparser::ExternalKind::Type | wasmparser::ExternalKind::Tag => unreachable!(), } } @@ -88,7 +83,7 @@ pub(crate) fn export(kind: wasmparser::ExternalKind, index: u32) -> wasm_encoder wasmparser::ExternalKind::Table => wasm_encoder::Export::Table(index), wasmparser::ExternalKind::Memory => wasm_encoder::Export::Memory(index), wasmparser::ExternalKind::Instance => wasm_encoder::Export::Instance(index), - wasmparser::ExternalKind::Event + wasmparser::ExternalKind::Tag | wasmparser::ExternalKind::Type | wasmparser::ExternalKind::Module => unreachable!(), } diff --git a/tests/tests.rs b/tests/tests.rs index f56ab4c..ad62b4e 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -579,12 +579,12 @@ fn accept_bulk_memory_data_count() -> Result<()> { let mut code = wasm_encoder::CodeSection::new(); let mut func = wasm_encoder::Function::new(vec![]); - func.instruction(wasm_encoder::Instruction::I32Const(42)); - func.instruction(wasm_encoder::Instruction::End); + func.instruction(&wasm_encoder::Instruction::I32Const(42)); + func.instruction(&wasm_encoder::Instruction::End); code.function(&func); let mut func = wasm_encoder::Function::new(vec![]); - func.instruction(wasm_encoder::Instruction::End); + func.instruction(&wasm_encoder::Instruction::End); code.function(&func); module.section(&code); @@ -592,8 +592,8 @@ fn accept_bulk_memory_data_count() -> Result<()> { // We're expecting these two data segments to be merge into one, which will exercise wizer's // ability to output the correct data count (1 instead of 2 above). let mut data = wasm_encoder::DataSection::new(); - data.active(0, wasm_encoder::Instruction::I32Const(0), vec![0, 1, 2, 3]); - data.active(0, wasm_encoder::Instruction::I32Const(4), vec![5, 6, 7, 8]); + data.active(0, &wasm_encoder::Instruction::I32Const(0), vec![0, 1, 2, 3]); + data.active(0, &wasm_encoder::Instruction::I32Const(4), vec![5, 6, 7, 8]); module.section(&data); run_wasm(&[], 42, &module.finish()).unwrap(); From 2b227b6f2cf7b07ef5d2a64da2207965287a3212 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 14 Apr 2023 15:18:54 -0700 Subject: [PATCH 7/9] Update to wasmparser without module linking This involved deleting quite a bit more module-linking related code in `wizer`. --- Cargo.lock | 9 +- Cargo.toml | 2 +- src/info.rs | 407 +--------------- src/info/types_interner.rs | 137 +----- src/instrument.rs | 103 +--- src/lib.rs | 30 +- src/parse.rs | 324 +------------ src/rewrite.rs | 972 +------------------------------------ src/rewrite/renumbering.rs | 57 --- src/translate.rs | 61 +-- tests/tests.rs | 5 +- 11 files changed, 80 insertions(+), 2027 deletions(-) delete mode 100644 src/rewrite/renumbering.rs diff --git a/Cargo.lock b/Cargo.lock index 2bbb74e..ee2103e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1908,9 +1908,12 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.83.0" +version = "0.84.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "718ed7c55c2add6548cca3ddd6383d738cd73b892df400e96b9aa876f0141d7a" +checksum = "77dc97c22bb5ce49a47b745bed8812d30206eff5ef3af31424f2c1820c0974b2" +dependencies = [ + "indexmap", +] [[package]] name = "wasmparser" @@ -2413,7 +2416,7 @@ dependencies = [ "structopt", "wasi-cap-std-sync", "wasm-encoder 0.10.0", - "wasmparser 0.83.0", + "wasmparser 0.84.0", "wasmprinter", "wasmtime", "wasmtime-wasi", diff --git a/Cargo.toml b/Cargo.toml index d833da3..56d7d78 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,7 @@ rayon = "1.5.0" structopt = { version = "0.3.21", optional = true } wasi-cap-std-sync = "3.0.0" wasm-encoder = "0.10.0" -wasmparser = "0.83.0" +wasmparser = "0.84.0" wasmtime = "3.0.0" wasmtime-wasi = "3.0.0" diff --git a/src/info.rs b/src/info.rs index a5fbc41..13cb362 100644 --- a/src/info.rs +++ b/src/info.rs @@ -2,14 +2,13 @@ use wasm_encoder::SectionId; pub mod types_interner; -use std::collections::BTreeMap; use std::convert::TryFrom; -use types_interner::{EntityType, InstanceType, Type, TypeId, TypesInterner}; +use types_interner::{EntityType, TypeId, TypesInterner}; /// A collection of info about modules within a module linking bundle. pub(crate) struct ModuleContext<'a> { arena: Vec>, - types: TypesInterner<'a>, + types: TypesInterner, } impl<'a> ModuleContext<'a> { @@ -28,33 +27,15 @@ impl<'a> ModuleContext<'a> { } /// Get the interned types set for this module context. - pub fn types(&self) -> &TypesInterner<'a> { + pub fn types(&self) -> &TypesInterner { &self.types } - /// Does this context represent a single Wasm module that doesn't use module - /// linking, or does it represent a bundle of one or more Wasm modules that - /// use module linking? - pub fn uses_module_linking(&self) -> bool { - self.arena.len() > 1 - || self.root().initial_sections(self).any(|s| { - s.id == SectionId::Alias.into() - || s.id == SectionId::Module.into() - || s.id == SectionId::Instance.into() - }) - } - /// Get a shared reference to the `DefinedModuleInfo` for this module, /// following through aliases. fn defined(&self, module: Module) -> &DefinedModuleInfo<'a> { - let mut id = module.id; - loop { - match &self.arena[id] { - ModuleInfo::Aliased(AliasedModuleInfo { alias_of, .. }) => { - id = *alias_of; - } - ModuleInfo::Defined(d) => return d, - } + match &self.arena[module.id] { + ModuleInfo::Defined(d) => return d, } } @@ -64,22 +45,15 @@ impl<'a> ModuleContext<'a> { /// aliased modules. fn defined_mut(&mut self, module: Module) -> &mut DefinedModuleInfo<'a> { match &mut self.arena[module.id] { - ModuleInfo::Aliased(_) => panic!("not a defined module"), ModuleInfo::Defined(d) => d, } } } enum ModuleInfo<'a> { - Aliased(AliasedModuleInfo), Defined(DefinedModuleInfo<'a>), } -struct AliasedModuleInfo { - /// The id of the other module that this is an alias of. - pub alias_of: usize, -} - /// Info that we keep track of on a per module-within-a-module-linking-bundle /// basis. /// @@ -90,11 +64,6 @@ struct DefinedModuleInfo<'a> { /// The raw sections from the original Wasm input. raw_sections: Vec>, - /// This vector has `n` entries when the module has `n` import sections. The - /// `i`th entry is a count of how many instance imports are in the `i`th - /// import section. - instance_import_counts: Vec, - /// Types available in this module. /// /// We keep track of these for determining how many things we need to @@ -104,24 +73,6 @@ struct DefinedModuleInfo<'a> { /// Imports made by this module. imports: Vec>, - /// Aliases that this module defines. - aliases: Vec>, - - /// Directly nested inner modules of this module. - /// - /// These entries are populated as we finish instrumenting the inner - /// modules. - modules: Vec, - - /// A map from instance indices to each instance's type for all defined, - /// imported, and aliased instances. - instances: Vec, - - /// A map from indices of defined instantiations (as opposed to imported or - /// aliased instantiations) to the id of the module that was instantiated - /// and the import arguments. - instantiations: BTreeMap>)>, - /// A map from global indices to each global's type for all defined, /// imported, and aliased globals. globals: Vec, @@ -172,54 +123,9 @@ pub(crate) struct Module { } impl Module { - /// Construct a new, defined module. - pub fn new_defined(cx: &mut ModuleContext) -> Self { - let id = cx.arena.len(); - cx.arena.push(ModuleInfo::Defined(Default::default())); - Module { id } - } - - /// Construct a new module that is an alias of the given module. - pub fn new_aliased(cx: &mut ModuleContext, alias_of: Module) -> Self { - let id = cx.arena.len(); - cx.arena.push(ModuleInfo::Aliased(AliasedModuleInfo { - alias_of: alias_of.id, - })); - Module { id } - } - - /// Get the pre-order traversal index of this module in its associated - /// module linking bundle. - pub fn pre_order_index(self) -> u32 { - u32::try_from(self.id).unwrap() - } - - /// Get the defined module that this module is an alias of, if any. - /// - /// This will see through all aliases. - pub fn get_aliased(self, cx: &ModuleContext<'_>) -> Option { - if matches!(cx.arena[self.id], ModuleInfo::Defined(_)) { - return None; - } - - let mut id = self.id; - loop { - match &cx.arena[id] { - ModuleInfo::Aliased(AliasedModuleInfo { alias_of, .. }) => { - id = *alias_of; - } - ModuleInfo::Defined(_) => return Some(Module { id }), - } - } - } - /// Translate the given `wasmparser` entity type into its interned /// representation using this module's types space. - pub fn entity_type( - self, - cx: &ModuleContext<'_>, - ty: wasmparser::ImportSectionEntryType, - ) -> EntityType { + pub fn entity_type(self, cx: &ModuleContext<'_>, ty: wasmparser::TypeRef) -> EntityType { cx.types().entity_type(ty, &cx.defined(self).types) } @@ -240,52 +146,14 @@ impl Module { } /// Push a new type into this module's types space. - pub fn push_type<'a>(self, cx: &mut ModuleContext<'a>, ty: wasmparser::TypeDef<'a>) { + pub fn push_type<'a>(self, cx: &mut ModuleContext<'a>, ty: wasmparser::TypeDef) { let types_space = match &cx.arena[self.id] { - ModuleInfo::Aliased(_) => panic!("not a defined module"), ModuleInfo::Defined(d) => &d.types, }; let ty = cx.types.insert_wasmparser(ty, types_space); cx.defined_mut(self).types.push(ty); } - /// Push an aliased type into this module's types space. - pub fn push_aliased_type(self, cx: &mut ModuleContext<'_>, ty: TypeId) { - cx.defined_mut(self).types.push(ty); - } - - /// Push a new module onto this module's list of nested child modules. - pub fn push_child_module(self, cx: &mut ModuleContext<'_>, child: Module) { - cx.defined_mut(self).modules.push(child); - } - - /// Push a new, aliased instance into this module's instance index space. - pub fn push_aliased_instance<'a>(self, cx: &mut ModuleContext<'a>, instance_type: TypeId) { - assert!(cx.types.get(instance_type).is_instance()); - cx.defined_mut(self).instances.push(instance_type); - } - - /// Push a new, imported instance into this module's instance index space. - pub fn push_imported_instance<'a>(self, cx: &mut ModuleContext<'a>, instance_type: TypeId) { - assert!(cx.types.get(instance_type).is_instance()); - cx.defined_mut(self).instances.push(instance_type); - } - - /// Push a new, imported instance into this module's instance index space. - pub fn push_defined_instance<'a>( - self, - cx: &mut ModuleContext<'a>, - instance_type: TypeId, - module: Module, - args: Vec>, - ) { - assert!(cx.types.get(instance_type).is_instance()); - let info = cx.defined_mut(self); - let index = u32::try_from(info.instances.len()).unwrap(); - info.instances.push(instance_type); - info.instantiations.insert(index, (module, args)); - } - /// Push a new imported memory into this module's memory index space. pub fn push_imported_memory(self, cx: &mut ModuleContext, memory_type: wasmparser::MemoryType) { let info = cx.defined_mut(self); @@ -335,53 +203,25 @@ impl Module { // Add the import to the appropriate index space for our current module. match import.ty { - wasmparser::ImportSectionEntryType::Memory(ty) => { + wasmparser::TypeRef::Memory(ty) => { self.push_imported_memory(cx, ty); } - wasmparser::ImportSectionEntryType::Global(ty) => { + wasmparser::TypeRef::Global(ty) => { self.push_imported_global(cx, ty); } - wasmparser::ImportSectionEntryType::Instance(ty_idx) => { - let ty = self.instance_type_at(cx, ty_idx).clone(); - self.push_imported_instance(cx, ty); - } - wasmparser::ImportSectionEntryType::Function(ty_idx) => { + wasmparser::TypeRef::Func(ty_idx) => { let ty = self.type_id_at(cx, ty_idx); self.push_function(cx, ty); } - wasmparser::ImportSectionEntryType::Table(ty) => { + wasmparser::TypeRef::Table(ty) => { self.push_table(cx, ty); } - wasmparser::ImportSectionEntryType::Module(_) => { - unreachable!("we disallow module imports; checked in validation") - } - wasmparser::ImportSectionEntryType::Tag(_) => { + wasmparser::TypeRef::Tag(_) => { unreachable!("exceptions are unsupported; checked in validation") } } } - /// Push a count of how many instance imports an import section had. - pub fn push_instance_import_count(self, cx: &mut ModuleContext<'_>, count: u32) { - cx.defined_mut(self).instance_import_counts.push(count); - } - - /// Push an instance implicitly created by a two-level import into this - /// module. - pub fn push_implicit_instance<'a>( - self, - cx: &mut ModuleContext<'a>, - instance_type: InstanceType<'a>, - ) { - let ty = cx.types.insert(Type::Instance(instance_type)); - cx.defined_mut(self).instances.push(ty); - } - - /// Push an alias into this module. - pub fn push_alias<'a>(self, cx: &mut ModuleContext<'a>, alias: wasmparser::Alias<'a>) { - cx.defined_mut(self).aliases.push(alias); - } - /// Push an export into this module. pub fn push_export<'a>(self, cx: &mut ModuleContext<'a>, export: wasmparser::Export<'a>) { cx.defined_mut(self).exports.push(export); @@ -392,147 +232,6 @@ impl Module { self.id == 0 } - /// Define an instance type for this module's exports. - /// - /// Returns the index of the type and updates the total count of types in - /// `num_types`. - pub fn define_instance_type(self, cx: &mut ModuleContext<'_>) -> TypeId { - // Inline `cx.defined(self)` to avoid borrowck errors. - let info = { - let mut id = self.id; - loop { - match &cx.arena[id] { - ModuleInfo::Aliased(AliasedModuleInfo { alias_of, .. }) => { - id = *alias_of; - } - ModuleInfo::Defined(d) => break d, - } - } - }; - - cx.types.insert(Type::Instance(InstanceType { - exports: info - .exports - .iter() - .map(|e| { - let name = e.field.into(); - let index = usize::try_from(e.index).unwrap(); - let entity = match e.kind { - wasmparser::ExternalKind::Function => { - let func_ty = info.functions[index]; - EntityType::Function(func_ty) - } - wasmparser::ExternalKind::Table => { - let ty = info.tables[index]; - EntityType::Table(ty) - } - wasmparser::ExternalKind::Memory => { - let ty = info.memories[index]; - EntityType::Memory(ty) - } - wasmparser::ExternalKind::Global => { - let ty = info.globals[index]; - EntityType::Global(ty) - } - wasmparser::ExternalKind::Instance => { - EntityType::Instance(info.instances[index]) - } - wasmparser::ExternalKind::Module - | wasmparser::ExternalKind::Type - | wasmparser::ExternalKind::Tag => unreachable!(), - }; - (name, entity) - }) - .collect(), - })) - } - - /// Define an instance type for this module's state. - pub fn define_state_instance_type(self, cx: &mut ModuleContext<'_>) -> TypeId { - // Define instance types for each of the instances that we instantiate - // locally so that we can refer to these types in the state instance's - // type. - let instantiated_modules: Vec<_> = - self.instantiations(cx).values().map(|(m, _)| *m).collect(); - let instance_types = instantiated_modules - .into_iter() - .map(|m| m.define_instance_type(cx)) - .collect::>(); - - // Define the state instance type. - cx.types.insert(Type::Instance(InstanceType { - exports: self - .defined_globals(cx) - .enumerate() - .map(|(i, (_, g))| { - ( - format!("__wizer_global_{}", i).into(), - EntityType::Global(g), - ) - }) - .chain(self.defined_memories(cx).enumerate().map(|(i, (_, m))| { - ( - format!("__wizer_memory_{}", i).into(), - EntityType::Memory(m), - ) - })) - .chain(instance_types.iter().enumerate().map(|(i, ty)| { - ( - format!("__wizer_instance_{}", i).into(), - EntityType::Instance(*ty), - ) - })) - .collect(), - })) - } - - /// Get the count of how many instance imports are in each import section in - /// this module. - pub fn instance_import_counts<'b>(self, cx: &'b ModuleContext<'_>) -> &'b [u32] { - &cx.defined(self).instance_import_counts - } - - /// Get the aliases defined in this module. - pub fn aliases<'a, 'b>(self, cx: &'b ModuleContext<'a>) -> &'b [wasmparser::Alias<'a>] { - &cx.defined(self).aliases - } - - /// Get an export from the `n`th instance by name. - pub fn instance_export<'b>( - self, - cx: &'b ModuleContext<'_>, - instance: u32, - name: &str, - ) -> Option<&'b EntityType> { - let instance = usize::try_from(instance).unwrap(); - let info = cx.defined(self); - let type_id = info.instances[instance]; - let instance = match cx.types.get(type_id) { - Type::Instance(i) => i, - _ => unreachable!(), - }; - instance.exports.get(name) - } - - /// Do a pre-order traversal over this module tree. - pub fn pre_order<'a, F>(self, cx: &mut ModuleContext<'a>, mut f: F) - where - F: FnMut(&mut ModuleContext<'a>, Module), - { - let mut stack = vec![self]; - while let Some(module) = stack.pop() { - f(cx, module); - let info = cx.defined(module); - stack.extend(info.modules.iter().copied().rev()); - } - } - - /// Get the first index in the memory space where a memory is defined rather - /// than aliased or imported. - pub fn defined_memories_index(self, cx: &ModuleContext) -> Option { - cx.defined(self).defined_memories_index - } - /// The number of defined memories in this module. pub fn defined_memories_len(self, cx: &ModuleContext) -> usize { let info = cx.defined(self); @@ -560,22 +259,6 @@ impl Module { .map(|(i, m)| (u32::try_from(i).unwrap(), m)) } - /// Get the first index in the global space where a global is defined rather - /// than aliased or imported. - pub fn defined_globals_index(self, cx: &ModuleContext) -> Option { - cx.defined(self).defined_globals_index - } - - /// The number of defined globals in this module. - pub fn defined_globals_len(self, cx: &ModuleContext<'_>) -> usize { - let info = cx.defined(self); - info.defined_globals_index.map_or(0, |n| { - let n = usize::try_from(n).unwrap(); - assert!(info.globals.len() > n); - info.globals.len() - n - }) - } - /// Iterate over the defined globals in this module. pub fn defined_globals<'b>( self, @@ -593,25 +276,6 @@ impl Module { .map(|(i, g)| (u32::try_from(i).unwrap(), g)) } - /// Iterate over the initial sections in this Wasm module. - pub fn initial_sections<'a, 'b>( - self, - cx: &'b ModuleContext<'a>, - ) -> impl Iterator> + 'b { - let info = cx.defined(self); - info.raw_sections - .iter() - .filter(|s| s.id != SectionId::Custom.into()) - .take_while(|s| match s.id { - x if x == SectionId::Type.into() => true, - x if x == SectionId::Import.into() => true, - x if x == SectionId::Alias.into() => true, - x if x == SectionId::Module.into() => true, - x if x == SectionId::Instance.into() => true, - _ => false, - }) - } - /// Get a slice of this module's original raw sections. pub fn raw_sections<'a, 'b>( self, @@ -620,67 +284,20 @@ impl Module { &cx.defined(self).raw_sections } - /// Get a slice of this module's nested child modules. - pub fn child_modules<'b>(self, cx: &'b ModuleContext<'_>) -> &'b [Module] { - &cx.defined(self).modules - } - /// Get a slice of this module's exports. pub fn exports<'a, 'b>(self, cx: &'b ModuleContext<'a>) -> &'b [wasmparser::Export<'a>] { &cx.defined(self).exports } - /// Get a slice of this module's imports. - pub fn imports<'a, 'b>(self, cx: &'b ModuleContext<'a>) -> &'b [wasmparser::Import<'a>] { - &cx.defined(self).imports - } - - /// Get this module's defined (as opposed to imported or aliased) - /// instantiations. - /// - /// The return value maps an instance index to the module that was - /// instantiated and the associated instantiation arguments. - pub fn instantiations<'a, 'b>( - self, - cx: &'b ModuleContext<'a>, - ) -> &'b BTreeMap>)> { - &cx.defined(self).instantiations - } - - /// Get this module's `n`th nested child module. - pub fn child_module_at(self, cx: &ModuleContext<'_>, n: u32) -> Module { - cx.defined(self).modules[usize::try_from(n).unwrap()] - } - /// Get the full types index space for this module. pub fn types<'a, 'b>(self, cx: &'b ModuleContext<'a>) -> &'b [TypeId] { &cx.defined(self).types } - /// Get the type at the given index. - /// - /// Panics if the types index space does not contain the given index. - pub fn type_at<'a, 'b>(self, cx: &'b ModuleContext<'a>, type_index: u32) -> &'b Type<'a> { - let id = self.type_id_at(cx, type_index); - cx.types.get(id) - } - /// Get the type at the given index. /// /// Panics if the types index space does not contain the given index. pub fn type_id_at(self, cx: &ModuleContext<'_>, type_index: u32) -> TypeId { cx.defined(self).types[usize::try_from(type_index).unwrap()] } - - /// Get the id for instance type at the given type index. - /// - /// Panics if the types index space does not contain the given index or the - /// type at the index is not an instance type. - pub fn instance_type_at<'a, 'b>(self, cx: &'b ModuleContext<'a>, type_index: u32) -> TypeId { - if let Type::Instance(_) = self.type_at(cx, type_index) { - self.types(cx)[usize::try_from(type_index).unwrap()] - } else { - panic!("not an instance type") - } - } } diff --git a/src/info/types_interner.rs b/src/info/types_interner.rs index 4b1df08..91cade0 100644 --- a/src/info/types_interner.rs +++ b/src/info/types_interner.rs @@ -1,9 +1,4 @@ -use std::{ - borrow::Cow, - collections::{BTreeMap, HashMap}, - convert::TryFrom, - rc::Rc, -}; +use std::{collections::HashMap, convert::TryFrom, rc::Rc}; /// A de-duplicated set of type definitions. /// @@ -16,38 +11,26 @@ use std::{ /// refer to these types, and pull them into their nested types index space, via /// outer type aliases. #[derive(Default)] -pub struct TypesInterner<'a> { +pub struct TypesInterner { /// The interned types. - types: Vec>>, + types: Vec>, /// An map from a type to its index in `self.types`. - type_to_index: HashMap>, u32>, + type_to_index: HashMap, u32>, } /// An interned Wasm type definition. #[derive(PartialEq, Eq, Hash)] -pub enum Type<'a> { +pub enum Type { Func(wasmparser::FuncType), - Instance(InstanceType<'a>), - Module(ModuleType<'a>), } -impl Type<'_> { - pub fn is_instance(&self) -> bool { - matches!(self, Type::Instance(_)) - } - +impl Type { pub fn is_func(&self) -> bool { matches!(self, Type::Func(_)) } } -/// An interned Wasm instance type. -#[derive(PartialEq, Eq, Hash)] -pub struct InstanceType<'a> { - pub exports: BTreeMap, EntityType>, -} - /// An interned type for some kind of Wasm entity. #[derive(PartialEq, Eq, Hash)] pub enum EntityType { @@ -55,15 +38,6 @@ pub enum EntityType { Table(wasmparser::TableType), Memory(wasmparser::MemoryType), Global(wasmparser::GlobalType), - Module(TypeId), - Instance(TypeId), -} - -/// An interned Wasm module type. -#[derive(PartialEq, Eq, Hash)] -pub struct ModuleType<'a> { - pub imports: BTreeMap<(Cow<'a, str>, Option>), EntityType>, - pub exports: BTreeMap, EntityType>, } /// An id of a type in a `TypesInterner` type set. @@ -72,30 +46,9 @@ pub struct TypeId { index: u32, } -impl TypeId { - /// Get the index of this type inside its `TypesInterner`. - /// - /// This index is *not* the same as the index within a particular module's - /// index space, it is within the `TypesInterner`'s index space (except for - /// the eventual umbrella module, whose types index space matches the - /// interner's index space). - pub fn index(self) -> u32 { - self.index - } -} - -impl<'a> TypesInterner<'a> { - /// Iterate over the types defined in this type set and their index. - pub fn iter<'b>(&'b self) -> impl Iterator)> + 'b { - assert!((self.types.len() as u64) < (u32::MAX as u64)); - self.types - .iter() - .enumerate() - .map(|(idx, ty)| (u32::try_from(idx).unwrap(), &**ty)) - } - +impl TypesInterner { /// Get a type by id. - pub fn get(&self, id: TypeId) -> &Type<'a> { + pub fn get(&self, id: TypeId) -> &Type { &*self.types[usize::try_from(id.index).unwrap()] } @@ -108,17 +61,11 @@ impl<'a> TypesInterner<'a> { /// that entry and its id are reused. pub fn insert_wasmparser( &mut self, - ty: wasmparser::TypeDef<'a>, - types_space: &[TypeId], + ty: wasmparser::TypeDef, + _types_space: &[TypeId], ) -> TypeId { match ty { wasmparser::TypeDef::Func(func_ty) => self.insert(Type::Func(func_ty)), - wasmparser::TypeDef::Instance(inst_ty) => { - self.insert_wasmparser_instance_type(inst_ty, types_space) - } - wasmparser::TypeDef::Module(module_ty) => { - self.insert_wasmparser_module_type(module_ty, types_space) - } } } @@ -126,7 +73,7 @@ impl<'a> TypesInterner<'a> { /// /// If the type has already been inserted and assigned an id before, then /// that entry and its id are reused. - pub fn insert(&mut self, ty: Type<'a>) -> TypeId { + pub fn insert(&mut self, ty: Type) -> TypeId { if let Some(index) = self.type_to_index.get(&ty).copied() { return TypeId { index }; } @@ -138,68 +85,20 @@ impl<'a> TypesInterner<'a> { TypeId { index } } - /// Convert a `wasmparser::ImportSectionEntryType` into an interned + /// Convert a `wasmparser::EntityType` into an interned /// `EntityType`. /// /// The provided `types_space` must be a slice of the defining module's /// types index space. - pub fn entity_type( - &self, - ty: wasmparser::ImportSectionEntryType, - types_space: &[TypeId], - ) -> EntityType { + pub fn entity_type(&self, ty: wasmparser::TypeRef, types_space: &[TypeId]) -> EntityType { match ty { - wasmparser::ImportSectionEntryType::Function(idx) => { + wasmparser::TypeRef::Func(idx) => { EntityType::Function(types_space[usize::try_from(idx).unwrap()]) } - wasmparser::ImportSectionEntryType::Table(ty) => EntityType::Table(ty), - wasmparser::ImportSectionEntryType::Memory(ty) => EntityType::Memory(ty), - wasmparser::ImportSectionEntryType::Global(ty) => EntityType::Global(ty), - wasmparser::ImportSectionEntryType::Module(idx) => { - EntityType::Module(types_space[usize::try_from(idx).unwrap()]) - } - wasmparser::ImportSectionEntryType::Instance(idx) => { - EntityType::Instance(types_space[usize::try_from(idx).unwrap()]) - } - wasmparser::ImportSectionEntryType::Tag(_) => unreachable!(), + wasmparser::TypeRef::Table(ty) => EntityType::Table(ty), + wasmparser::TypeRef::Memory(ty) => EntityType::Memory(ty), + wasmparser::TypeRef::Global(ty) => EntityType::Global(ty), + wasmparser::TypeRef::Tag(_) => unreachable!(), } } - - fn insert_wasmparser_instance_type( - &mut self, - inst_ty: wasmparser::InstanceType<'a>, - types_space: &[TypeId], - ) -> TypeId { - self.insert(Type::Instance(InstanceType { - exports: inst_ty - .exports - .iter() - .map(|exp| (exp.name.into(), self.entity_type(exp.ty, types_space))) - .collect(), - })) - } - - fn insert_wasmparser_module_type( - &mut self, - module_ty: wasmparser::ModuleType<'a>, - types_space: &[TypeId], - ) -> TypeId { - self.insert(Type::Module(ModuleType { - imports: module_ty - .imports - .iter() - .map(|imp| { - ( - (imp.module.into(), imp.field.map(Cow::from)), - self.entity_type(imp.ty, types_space), - ) - }) - .collect(), - exports: module_ty - .exports - .iter() - .map(|exp| (exp.name.into(), self.entity_type(exp.ty, types_space))) - .collect(), - })) - } } diff --git a/src/instrument.rs b/src/instrument.rs index 5f959c5..6ed69ad 100644 --- a/src/instrument.rs +++ b/src/instrument.rs @@ -2,7 +2,6 @@ use crate::info::{Module, ModuleContext}; use crate::stack_ext::StackExt; -use std::convert::TryFrom; use wasm_encoder::SectionId; /// Instrument the input Wasm so that it exports its memories and globals, @@ -71,24 +70,6 @@ pub(crate) fn instrument(cx: &ModuleContext<'_>) -> Vec { /// Sections in this module info that we are iterating over. sections: std::slice::Iter<'a, wasm_encoder::RawSection<'a>>, - - /// The index of this entry's parent module on the stack. `None` if this - /// is the root module. - parent_index: Option, - - /// Nested child modules that still need to be instrumented and added to - /// one of this entry's module's module sections. - children: std::slice::Iter<'a, Module>, - - /// The current module section we are building for this entry's - /// module. Only `Some` if we are currently processing this module's - /// (transitive) children, i.e. this is not the module on the top of the - /// stack. - module_section: Option, - - /// The number of children still remaining to be interested for the - /// current module section. - children_remaining: usize, } let root = cx.root(); @@ -96,10 +77,6 @@ pub(crate) fn instrument(cx: &ModuleContext<'_>) -> Vec { module: root, encoder: wasm_encoder::Module::new(), sections: root.raw_sections(cx).iter(), - parent_index: None, - children: root.child_modules(cx).iter(), - module_section: None, - children_remaining: 0, }]; loop { @@ -116,9 +93,9 @@ pub(crate) fn instrument(cx: &ModuleContext<'_>) -> Vec { // First, copy over all the original exports. for export in entry.module.exports(cx) { exports.export( - export.field, + export.name, match export.kind { - wasmparser::ExternalKind::Function => { + wasmparser::ExternalKind::Func => { wasm_encoder::Export::Function(export.index) } wasmparser::ExternalKind::Table => { @@ -130,12 +107,7 @@ pub(crate) fn instrument(cx: &ModuleContext<'_>) -> Vec { wasmparser::ExternalKind::Global => { wasm_encoder::Export::Global(export.index) } - wasmparser::ExternalKind::Instance => { - wasm_encoder::Export::Instance(export.index) - } - wasmparser::ExternalKind::Module - | wasmparser::ExternalKind::Type - | wasmparser::ExternalKind::Tag => { + wasmparser::ExternalKind::Tag => { unreachable!("should have been rejected in validation/parsing") } }, @@ -153,89 +125,20 @@ pub(crate) fn instrument(cx: &ModuleContext<'_>) -> Vec { let name = format!("__wizer_memory_{}", i); exports.export(&name, wasm_encoder::Export::Memory(j)); } - for (i, j) in entry.module.instantiations(cx).keys().enumerate() { - let name = format!("__wizer_instance_{}", i); - exports.export(&name, wasm_encoder::Export::Instance(*j)); - } entry.encoder.section(&exports); } - // Nested module sections need to recursively instrument each child - // module. - Some(section) if section.id == SectionId::Module.into() => { - let reader = wasmparser::ModuleSectionReader::new(section.data, 0).unwrap(); - let count = usize::try_from(reader.get_count()).unwrap(); - - assert!(stack.top().module_section.is_none()); - if count == 0 { - continue; - } - - stack.top_mut().module_section = Some(wasm_encoder::ModuleSection::new()); - - assert_eq!(stack.top().children_remaining, 0); - stack.top_mut().children_remaining = count; - - let children = stack - .top_mut() - .children - .by_ref() - .copied() - .take(count) - .collect::>(); - - assert_eq!( - children.len(), - count, - "shouldn't ever have fewer children than expected" - ); - - let parent_index = Some(stack.len() - 1); - stack.extend( - children - .into_iter() - // Reverse so that we pop them off the stack in order. - .rev() - .map(|c| StackEntry { - module: c, - encoder: wasm_encoder::Module::new(), - sections: c.raw_sections(cx).iter(), - parent_index, - children: c.child_modules(cx).iter(), - module_section: None, - children_remaining: 0, - }), - ); - } - // End of the current module: if this is the root, return the // instrumented module, otherwise add it as an entry in its parent's // module section. None => { let entry = stack.pop().unwrap(); - assert!(entry.module_section.is_none()); - assert_eq!(entry.children_remaining, 0); if entry.module.is_root() { assert!(stack.is_empty()); return entry.encoder.finish(); } - - let parent = &mut stack[entry.parent_index.unwrap()]; - parent - .module_section - .as_mut() - .unwrap() - .module(&entry.encoder); - - assert!(parent.children_remaining > 0); - parent.children_remaining -= 1; - - if parent.children_remaining == 0 { - let module_section = parent.module_section.take().unwrap(); - parent.encoder.section(&module_section); - } } // All other sections don't need instrumentation and can be copied diff --git a/src/lib.rs b/src/lib.rs index 3afa289..6b86c0d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,7 +33,6 @@ const DEFAULT_INHERIT_ENV: bool = false; const DEFAULT_KEEP_INIT_FUNC: bool = false; const DEFAULT_WASM_MULTI_VALUE: bool = true; const DEFAULT_WASM_MULTI_MEMORY: bool = true; -const DEFAULT_WASM_MODULE_LINKING: bool = false; const DEFAULT_WASM_BULK_MEMORY: bool = false; const DEFAULT_WASM_SIMD: bool = true; @@ -195,12 +194,6 @@ pub struct Wizer { #[cfg_attr(feature = "structopt", structopt(long, value_name = "true|false"))] wasm_multi_value: Option, - /// Enable or disable the Wasm module-linking proposal. - /// - /// Disabled by default. - #[cfg_attr(feature = "structopt", structopt(long, value_name = "true|false"))] - wasm_module_linking: Option, - /// Enable or disable Wasm bulk memory operations. /// /// Note that only `memory.copy`, `memory.fill`, and `memory.init` operations @@ -232,7 +225,6 @@ impl std::fmt::Debug for Wizer { map_dirs, wasm_multi_memory, wasm_multi_value, - wasm_module_linking, wasm_bulk_memory, wasm_simd, } = self; @@ -248,7 +240,6 @@ impl std::fmt::Debug for Wizer { .field("map_dirs", &map_dirs) .field("wasm_multi_memory", &wasm_multi_memory) .field("wasm_multi_value", &wasm_multi_value) - .field("wasm_module_linking", &wasm_module_linking) .field("wasm_bulk_memory", &wasm_bulk_memory) .field("wasm_simd", &wasm_simd) .finish() @@ -311,7 +302,6 @@ impl Wizer { map_dirs: vec![], wasm_multi_memory: None, wasm_multi_value: None, - wasm_module_linking: None, wasm_bulk_memory: None, wasm_simd: None, } @@ -445,14 +435,6 @@ impl Wizer { self } - /// Enable or disable the Wasm module-linking proposal. - /// - /// Defaults to `false`. - pub fn wasm_module_linking(&mut self, enable: bool) -> &mut Self { - self.wasm_module_linking = Some(enable); - self - } - /// Enable or disable Wasm bulk memory operations. /// /// Note that only `memory.copy`, `memory.fill`, and `memory.init` @@ -566,9 +548,6 @@ impl Wizer { // Proposals that we support. multi_memory: self.wasm_multi_memory.unwrap_or(DEFAULT_WASM_MULTI_MEMORY), multi_value: self.wasm_multi_value.unwrap_or(DEFAULT_WASM_MULTI_VALUE), - module_linking: self - .wasm_module_linking - .unwrap_or(DEFAULT_WASM_MODULE_LINKING), // Proposals that we should add support for. reference_types: false, @@ -579,6 +558,7 @@ impl Wizer { exceptions: false, extended_const: false, relaxed_simd: false, + component_model: false, // XXX: Though we don't fully support bulk memory yet, we // unconditionally turn it on. @@ -613,8 +593,7 @@ impl Wizer { fn wasm_validate(&self, wasm: &[u8]) -> anyhow::Result<()> { log::debug!("Validating input Wasm"); - let mut validator = wasmparser::Validator::new(); - validator.wasm_features(self.wasm_features()); + let mut validator = wasmparser::Validator::new_with_features(self.wasm_features()); validator.validate_all(wasm)?; // Reject bulk memory stuff that manipulates state we don't @@ -653,10 +632,7 @@ impl Wizer { } } } - wasmparser::Payload::ModuleSectionEntry { parser, .. } => { - parsers.push(parser); - } - wasmparser::Payload::End => { + wasmparser::Payload::End(_) => { parsers.pop(); } _ => continue, diff --git a/src/parse.rs b/src/parse.rs index 5679076..63be01e 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -1,12 +1,12 @@ use crate::info::{ - types_interner::{EntityType, InstanceType, Type, TypeId}, + types_interner::{EntityType, TypeId}, Module, ModuleContext, }; use crate::stack_ext::StackExt; use anyhow::{Context, Result}; use std::convert::TryFrom; use wasm_encoder::SectionId; -use wasmparser::{SectionReader, SectionWithLimitedItems}; +use wasmparser::SectionReader; struct StackEntry { parser: wasmparser::Parser, @@ -45,28 +45,6 @@ pub(crate) fn parse<'a>(full_wasm: &'a [u8]) -> anyhow::Result Version { .. } => {} TypeSection(types) => type_section(&mut cx, &mut stack, full_wasm, types)?, ImportSection(imports) => import_section(&mut cx, &mut stack, full_wasm, imports)?, - AliasSection(aliases) => alias_section(&mut cx, &mut stack, full_wasm, aliases)?, - InstanceSection(instances) => { - instance_section(&mut cx, &mut stack, full_wasm, instances)? - } - ModuleSectionStart { - range, - size: _, - count: _, - } => { - stack.top_mut().module.add_raw_section( - &mut cx, - SectionId::Module, - range, - full_wasm, - ); - } - ModuleSectionEntry { parser, range: _ } => { - stack.push(StackEntry { - parser, - module: Module::new_defined(&mut cx), - }); - } FunctionSection(funcs) => function_section(&mut cx, &mut stack, full_wasm, funcs)?, TableSection(tables) => table_section(&mut cx, &mut stack, full_wasm, tables)?, MemorySection(mems) => memory_section(&mut cx, &mut stack, full_wasm, mems)?, @@ -117,19 +95,25 @@ pub(crate) fn parse<'a>(full_wasm: &'a [u8]) -> anyhow::Result CodeSectionEntry(_) => unreachable!(), UnknownSection { .. } => anyhow::bail!("unknown section"), TagSection(_) => anyhow::bail!("exceptions are not supported yet"), - End => { + End(_) => { let entry = stack.pop().unwrap(); // If we finished parsing the root Wasm module, then we're done. - if entry.module.is_root() { - assert!(stack.is_empty()); - return Ok(cx); - } + assert!(entry.module.is_root()); + assert!(stack.is_empty()); + return Ok(cx); + } - // Otherwise, we need to add this module to its parent's module - // section. - let parent = stack.top_mut(); - parent.module.push_child_module(&mut cx, entry.module); + ComponentTypeSection(_) + | ComponentImportSection(_) + | ComponentFunctionSection(_) + | ComponentExportSection(_) + | ComponentStartSection(_) + | AliasSection(_) + | ModuleSection { .. } + | ComponentSection { .. } + | InstanceSection(_) => { + unreachable!() } } } @@ -150,65 +134,9 @@ fn type_section<'a>( for _ in 0..count { let ty = types.read()?; match ty { - wasmparser::TypeDef::Func(_) | wasmparser::TypeDef::Instance(_) => { + wasmparser::TypeDef::Func(_) => { module.push_type(cx, ty); } - - // We need to disallow module imports, even within nested modules - // that only ever have other nested modules supplied as - // arguments. Two different modules could be supplied for two - // different instantiations of the module-importing module, but then - // after we export all modules' globals in our instrumentation - // phase, those two different module arguments could become - // type-incompatible with each other: - // - // ``` - // (module - // - // ;; Module A exports and `f` function. Internally it has - // ;; one global. - // (module $A - // (global $g ...) - // (func (export "f") ...)) - // - // ;; Module B has an identical interface as A. Internally - // ;; it has two globals. - // (module $B - // (global $g ...) - // (global $h ...) - // (func (export "f") ...)) - // - // ;; Module C imports any module that exports an `f` - // ;; function. It instantiates this imported module. - // (module $C - // (import "env" "module" - // (module (export "f" (func))) - // (instance 0))) - // - // ;; C is instantiated with both A and B. - // (instance $C (import "env" "module" $A)) - // (instance $C (import "env" "module" $B)) - // ) - // ``` - // - // After this instrumentation pass, we need to make module C - // transitively export all of the globals from its inner - // instances. Which means that the module type used in the module - // import needs to specify how many modules are in the imported - // module, but in our two instantiations, we have two different - // numbers of globals defined in each module! The only way to - // resolve this would be to duplicate and specialize module C for - // each instantiation, which we don't want to do for complexity and - // code size reasons. - // - // Since module types are only used with importing and exporting - // modules, which we don't intend to support as described above, we - // can disallow module types to reject all of them in one fell - // swoop. - wasmparser::TypeDef::Module(_) => Err(anyhow::anyhow!( - "wizer does not support importing or exporting modules" - ) - .context("module types are not supported"))?, } } @@ -227,108 +155,36 @@ fn import_section<'a>( .module .add_raw_section(cx, SectionId::Import, imports.range(), full_wasm); - let mut instance_import_count = 0; - - // Two-level imports implicitly create an instance import. That is, this - // - // (import "env" "f" (func)) - // (import "env" "g" (func)) - // - // is implicitly translated into roughly - // - // (import "env" (instance (export "f" (func)) - // (export "g" (func)))) - // (alias 0 "f") - // (alias 0 "g") - // - // However not that this is _not_ a WAT-level desugaring where we only have - // to deal with the expanded form! We have to perform this translation - // ourselves as we parse the imports. - // - // This variable keeps track of the implicit instance import that we are - // currently building. Whenever we see a consecutive run of two-level - // imports for the same module, we coalesce them into an implicit instance - // import. - let mut implicit_instance_import: Option<(&str, InstanceType)> = None; - // Check that we can properly handle all imports. let count = imports.get_count(); for _ in 0..count { let imp = imports.read()?; - if imp.module.starts_with("__wizer_") - || imp.field.map_or(false, |f| f.starts_with("__wizer_")) - { + if imp.module.starts_with("__wizer_") || imp.name.starts_with("__wizer_") { anyhow::bail!( "input Wasm module already imports entities named with the `__wizer_*` prefix" ); } - match (implicit_instance_import.as_mut(), imp.field) { - (Some((implicit_module, instance_ty)), Some(field)) - if *implicit_module == imp.module => - { - let ty = module.entity_type(cx, imp.ty); - let old = instance_ty.exports.insert(field.into(), ty); - debug_assert!(old.is_none(), "checked by validation"); - } - _ => { - if let Some((_, instance_ty)) = implicit_instance_import.take() { - module.push_implicit_instance(cx, instance_ty); - instance_import_count += 1; - } - if let Some(field) = imp.field { - let field_ty = module.entity_type(cx, imp.ty); - let instance_ty = InstanceType { - exports: Some((field.into(), field_ty)).into_iter().collect(), - }; - implicit_instance_import = Some((imp.module, instance_ty)); - } - } - } - check_import_type( cx, stack.top().module.types(cx), stack.top().module.is_root(), &module.entity_type(cx, imp.ty), )?; - if let wasmparser::ImportSectionEntryType::Instance(_) = imp.ty { - instance_import_count += 1; - } module.push_import(cx, imp); } - - if let Some((_, instance_ty)) = implicit_instance_import.take() { - module.push_implicit_instance(cx, instance_ty); - instance_import_count += 1; - } - - module.push_instance_import_count(cx, instance_import_count); Ok(()) } fn check_import_type( - cx: &ModuleContext, - types: &[TypeId], + _cx: &ModuleContext, + _types: &[TypeId], is_root: bool, ty: &EntityType, ) -> Result<()> { match ty { EntityType::Function(_) => Ok(()), - EntityType::Instance(inst_ty) => { - // We allow importing instances that only export things that are - // acceptable imports. This is equivalent to a two-layer import. - match cx.types().get(*inst_ty) { - Type::Instance(inst_ty) => { - for ty in inst_ty.exports.values() { - check_import_type(cx, types, is_root, ty)?; - } - Ok(()) - } - _ => unreachable!(), - } - } EntityType::Memory(mem_ty) => { anyhow::ensure!( !mem_ty.shared, @@ -351,135 +207,9 @@ fn check_import_type( ); Ok(()) } - EntityType::Module(_) => { - unreachable!(); - } } } -fn alias_section<'a>( - cx: &mut ModuleContext<'a>, - stack: &mut Vec, - full_wasm: &'a [u8], - mut aliases: wasmparser::AliasSectionReader<'a>, -) -> anyhow::Result<()> { - let module = stack.top().module; - module.add_raw_section(cx, SectionId::Alias, aliases.range(), full_wasm); - - // Clone any aliases over into this module's index spaces. - for _ in 0..aliases.get_count() { - let alias = aliases.read()?; - match &alias { - wasmparser::Alias::OuterType { - relative_depth, - index, - } => { - let relative_depth = usize::try_from(*relative_depth).unwrap(); - // NB: `- 2` rather than `- 1` because - // `relative_depth=0` means this module's immediate - // parent, not this module itself. - let ty = stack[stack.len() - 2 - relative_depth] - .module - .type_id_at(cx, *index); - module.push_aliased_type(cx, ty); - } - wasmparser::Alias::OuterModule { - relative_depth, - index, - } => { - let relative_depth = usize::try_from(*relative_depth).unwrap(); - // Ditto regarding `- 2`. - let alias_of = stack[stack.len() - 2 - relative_depth] - .module - .child_module_at(cx, *index); - let aliased = Module::new_aliased(cx, alias_of); - module.push_child_module(cx, aliased); - } - wasmparser::Alias::InstanceExport { - instance, - kind, - export, - } => match kind { - wasmparser::ExternalKind::Module => { - anyhow::bail!("exported modules are not supported yet") - } - wasmparser::ExternalKind::Instance => { - let inst_ty = match module.instance_export(cx, *instance, export) { - Some(EntityType::Instance(i)) => *i, - _ => unreachable!(), - }; - module.push_aliased_instance(cx, inst_ty); - } - wasmparser::ExternalKind::Function => { - let func_ty = match module.instance_export(cx, *instance, export) { - Some(EntityType::Function(ty)) => *ty, - _ => unreachable!(), - }; - module.push_function(cx, func_ty); - } - wasmparser::ExternalKind::Table => { - let table_ty = match module.instance_export(cx, *instance, export) { - Some(EntityType::Table(ty)) => *ty, - _ => unreachable!(), - }; - module.push_table(cx, table_ty); - } - wasmparser::ExternalKind::Memory => { - let ty = match module.instance_export(cx, *instance, export) { - Some(EntityType::Memory(ty)) => *ty, - _ => unreachable!(), - }; - module.push_imported_memory(cx, ty); - } - wasmparser::ExternalKind::Global => { - let ty = match module.instance_export(cx, *instance, export) { - Some(EntityType::Global(ty)) => *ty, - _ => unreachable!(), - }; - module.push_imported_global(cx, ty); - } - wasmparser::ExternalKind::Tag => { - unreachable!("validation should reject the exceptions proposal") - } - wasmparser::ExternalKind::Type => unreachable!("can't export types"), - }, - } - module.push_alias(cx, alias); - } - - Ok(()) -} - -fn instance_section<'a>( - cx: &mut ModuleContext<'a>, - stack: &mut Vec, - full_wasm: &'a [u8], - mut instances: wasmparser::InstanceSectionReader<'a>, -) -> anyhow::Result<()> { - let module = stack.top().module; - module.add_raw_section(cx, SectionId::Instance, instances.range(), full_wasm); - - // Record the instantiations made in this module, and which modules were - // instantiated. - for _ in 0..instances.get_count() { - let inst = instances.read()?; - let module_index = inst.module(); - let child_module = module.child_module_at(cx, module_index); - let inst_ty = child_module.define_instance_type(cx); - - let mut instance_args_reader = inst.args()?; - let instance_args_count = usize::try_from(instance_args_reader.get_count()).unwrap(); - let mut instance_args = Vec::with_capacity(instance_args_count); - for _ in 0..instance_args_count { - instance_args.push(instance_args_reader.read()?); - } - - module.push_defined_instance(cx, inst_ty, child_module, instance_args); - } - - Ok(()) -} - fn function_section<'a>( cx: &mut ModuleContext<'a>, stack: &mut Vec, @@ -560,24 +290,20 @@ fn export_section<'a>( for _ in 0..exports.get_count() { let export = exports.read()?; - if export.field.starts_with("__wizer_") { + if export.name.starts_with("__wizer_") { anyhow::bail!( "input Wasm module already exports entities named with the `__wizer_*` prefix" ); } match export.kind { - wasmparser::ExternalKind::Module => { - anyhow::bail!("Wizer does not support importing and exporting modules") - } - wasmparser::ExternalKind::Type | wasmparser::ExternalKind::Tag => { + wasmparser::ExternalKind::Tag => { unreachable!("checked in validation") } - wasmparser::ExternalKind::Function + wasmparser::ExternalKind::Func | wasmparser::ExternalKind::Table | wasmparser::ExternalKind::Memory - | wasmparser::ExternalKind::Global - | wasmparser::ExternalKind::Instance => { + | wasmparser::ExternalKind::Global => { module.push_export(cx, export); } } diff --git a/src/rewrite.rs b/src/rewrite.rs index 09a0d34..183daf8 100644 --- a/src/rewrite.rs +++ b/src/rewrite.rs @@ -1,17 +1,9 @@ //! Final rewrite pass. -mod renumbering; - use crate::{ - info::{ - types_interner::{EntityType, Type}, - Module, ModuleContext, - }, - snapshot::Snapshot, - translate, FuncRenames, Wizer, DEFAULT_KEEP_INIT_FUNC, + info::ModuleContext, snapshot::Snapshot, translate, FuncRenames, Wizer, DEFAULT_KEEP_INIT_FUNC, }; -use renumbering::Renumbering; -use std::{convert::TryFrom, iter}; +use std::convert::TryFrom; use wasm_encoder::SectionId; impl Wizer { @@ -28,25 +20,6 @@ impl Wizer { ) -> Vec { log::debug!("Rewriting input Wasm to pre-initialized state"); - if cx.uses_module_linking() { - self.rewrite_with_module_linking(cx, store, snapshot, renames, has_wasi_initialize) - } else { - self.rewrite_without_module_linking(cx, store, snapshot, renames, has_wasi_initialize) - } - } - - /// Rewrite a root Wasm module that has no children and doesn't use module - /// linking at all. - fn rewrite_without_module_linking( - &self, - cx: &ModuleContext<'_>, - store: &crate::Store, - snapshot: &Snapshot, - renames: &FuncRenames, - has_wasi_initialize: bool, - ) -> Vec { - assert!(snapshot.instantiations.is_empty()); - let mut encoder = wasm_encoder::Module::new(); let module = cx.root(); @@ -141,14 +114,14 @@ impl Wizer { let mut exports = wasm_encoder::ExportSection::new(); for export in module.exports(cx) { if !self.keep_init_func.unwrap_or(DEFAULT_KEEP_INIT_FUNC) - && (export.field == self.init_func - || (has_wasi_initialize && export.field == "_initialize")) + && (export.name == self.init_func + || (has_wasi_initialize && export.name == "_initialize")) { continue; } - if !renames.rename_src_to_dst.contains_key(export.field) - && renames.rename_dsts.contains(export.field) + if !renames.rename_src_to_dst.contains_key(export.name) + && renames.rename_dsts.contains(export.name) { // A rename overwrites this export, and it is not // renamed to another export, so skip it. @@ -157,8 +130,8 @@ impl Wizer { let field = renames .rename_src_to_dst - .get(export.field) - .map_or(export.field, |f| f.as_str()); + .get(export.name) + .map_or(export.name, |f| f.as_str()); let export = translate::export(export.kind, export.index); exports.export(field, export); @@ -183,10 +156,6 @@ impl Wizer { add_data_section(&mut encoder); } - s if s.id == SectionId::Module.into() => unreachable!(), - s if s.id == SectionId::Instance.into() => unreachable!(), - s if s.id == SectionId::Alias.into() => unreachable!(), - s => { encoder.section(s); } @@ -197,352 +166,6 @@ impl Wizer { add_data_section(&mut encoder); encoder.finish() } - - /// Rewrite a module linking bundle. - /// - /// ## Code Shape - /// - /// With module linking, we rewrite each module in the original bundle into - /// a *code module* that doesn't define any internal state (i.e. memories, - /// globals, and nested instances) and instead imports a *state instance* - /// that exports all of these things. For each instantiation, we have a - /// *state module* that defines the already-initialized state for that - /// instantiation, we instantiate that state module to create one such state - /// instance, and then use this as an import argument in the instantiation - /// of the original code module. This way, we do not duplicate shared code - /// bodies across multiple instantiations of the same module. - /// - /// Note that the root module is also split out into a code module and state - /// module, even though it is never explicitly instantiated inside the - /// bundle. - /// - /// The new root is an "umbrella" module that defines all the types used - /// within the whole bundle. Each nested module then aliases its types from - /// the umbrella module. The umbrella module aliases all exports of the - /// original root and re-exports them. - /// - /// For example, given this input Wasm module: - /// - /// ```wat - /// (module $A - /// (module $B - /// (memory $B_mem) - /// (global $B_glob (mut i32)) - /// (func (export "f") ...) - /// ) - /// - /// (instance $x (instantiate $B)) - /// (instance $y (instantiate $B)) - /// - /// (memory $A_mem) - /// (global $A_glob (mut i32)) - /// - /// (func (export "g") ...) - /// ) - /// ``` - /// - /// and some post-initialization state, this rewrite pass will produce the - /// following pre-initialized module: - /// - /// ```wat - /// (module $Umbrella - /// (module $A - /// ;; Locally defined state is replaced by a state instance import. - /// (import "__wizer_state" - /// (instance - /// (export "__wizer_memory_0" (memory $A_mem)) - /// (export "__wizer_global_0" (global $A_glob (mut i32))) - /// (export "__wizer_instance_0" (instance $x (export "f" (func)))) - /// (export "__wizer_instance_1" (instance $y (export "f" (func)))) - /// ) - /// ) - /// (func (export "g") ...) - /// ) - /// - /// (module $B - /// ;; Locally defined state is replaced by a state instance import. - /// (import "__wizer_state" - /// (instance - /// (export "__wizer_memory_0" (memory $B_mem)) - /// (export "__wizer_global_0" (global $B_glob (mut i32))) - /// ) - /// ) - /// (func (export "f") ...) - /// ) - /// - /// ;; Instantiations are replaced with specialized state modules that get - /// ;; instantiated exactly once to produce state instances, and finally - /// ;; the original instantiations are rewritten into instantiations of - /// ;; the corresponding code module with the state instance as an import - /// ;; argument. - /// - /// ;; State module for `$A`. - /// (module $A_state_module - /// ;; State module for `$x`. - /// (module $x_state_module - /// (memory (export "__wizer_memory_0") (memory)) - /// ;; Data segments to initialize the memory based on our snapshot - /// ;; would go here... - /// - /// (global (export "__wizer_global_0") - /// (global (mut i32) (i32.const (; ...snapshot's initialized value goes here... ;))) - /// ) - /// ) - /// - /// ;; State instance for `$x`. - /// (instance $x_state (instantiate $x_state_module)) - /// - /// ;; The instantiation of `$x` is now rewritten to use our state - /// ;; instance. - /// (instance $x (instantiate $B (import "__wizer_state" $x_state))) - /// - /// ;; Same goes for the `$y` instantiation. - /// (module $y_state_module - /// (memory (export "__wizer_memory_0") (memory)) - /// ;; Data segments... - /// (global (export "__wizer_global_0") - /// (global (mut i32) (i32.const (; ...snapshot's initialized value goes here... ;))) - /// ) - /// ) - /// (instance $y_state (instantiate $y_state_module)) - /// (instance $y (instantiate $B (import "__wizer_state" $y_state))) - /// - /// (memory $A_mem) - /// (global $A_glob (mut i32)) - /// ) - /// - /// ;; State instance for `$A`. - /// (instance $a_state (instantiate $A_state_module)) - /// - /// ;; The state is now joined with the code. - /// (instance $a_instance (instantiate $A (import "__wizer_state" $a_state))) - /// - /// ;; And finally we re-export all of our old root's exports. - /// (export "g" (func $a_instance "g")) - /// ) - /// ``` - /// - /// ## Implementation - /// - /// To implement this transformation, we first do a pre-order walk of the - /// module tree and emit the code modules as a flat sequence. Why a flat - /// sequence? The code modules cannot contain nested instantiations, because - /// nested instantiations are state that is not necessarily shared across - /// all instantiations of the outer module. And if we are already lifting - /// out nested instantiations, we need to also make nested modules available - /// for those lifted instantiations, and the easiest way to do that is to - /// flatten the code module tree (as opposed to re-exporting the nested - /// modules under well-known symbols). The pre-order traversal ensures that - /// the `Module::id` we assigned during the instrumentation phase matches - /// the module's place in the index space. - /// - /// The state modules, however, remain a nested tree, and we emit them in a - /// traversal of the `Snapshot` instance tree. We can do this because, - /// unlike code modules, each state module is only instantiated exactly - /// once. The instantiations' references to nested modules become outer - /// aliases pointing to the module's position in the parent's flat sequence - /// of nested modules. - fn rewrite_with_module_linking( - &self, - cx: &mut ModuleContext<'_>, - store: &crate::Store, - snapshot: &Snapshot, - renames: &FuncRenames, - has_wasi_initialize: bool, - ) -> Vec { - let mut umbrella = wasm_encoder::Module::new(); - - // Counts of various entities defined inside the umbrella module thus - // far. - let mut umbrella_funcs = 0; - let mut umbrella_tables = 0; - let mut umbrella_memories = 0; - let mut umbrella_globals = 0; - let mut umbrella_instances = 0; - - let (code_modules, num_code_modules) = rewrite_code_modules(cx); - - let root_state_module = rewrite_state_module(cx, store, cx.root(), &snapshot, 0); - let mut modules = wasm_encoder::ModuleSection::new(); - modules.module(&root_state_module); - let root_state_module_index = num_code_modules; - - // Imports that we will need to pass through from the umbrella to the - // root instance. - let import_sections: Vec<_> = cx - .root() - .initial_sections(cx) - .filter(|s| s.id == SectionId::Import.into()) - .collect(); - - // Instantiate the root state module by forwarding imports from the - // umbrella to the root instantiation. - // - // There is some trickery for implicit instance imports. We forward the - // implicit instance as an instantiation argument, since we can't - // provide two-level instantiation arguments, which means we need to - // determine when implicit imports are injected again. - let mut instances = wasm_encoder::InstanceSection::new(); - let mut args = vec![]; - let mut imports = cx.root().imports(cx).iter().peekable(); - loop { - let (module, is_two_level) = match imports.peek() { - Some(imp) => (imp.module, imp.field.is_some()), - None => break, - }; - - if is_two_level { - args.push((module, wasm_encoder::Export::Instance(umbrella_instances))); - umbrella_instances += 1; - } - while imports.peek().map_or(false, |imp| imp.module == module) { - let imp = imports.next().unwrap(); - let export = match imp.ty { - wasmparser::ImportSectionEntryType::Function(_) => { - umbrella_funcs += 1; - wasm_encoder::Export::Function(umbrella_funcs - 1) - } - wasmparser::ImportSectionEntryType::Instance(_) => { - umbrella_instances += 1; - wasm_encoder::Export::Instance(umbrella_instances - 1) - } - _ => unreachable!(), - }; - if !is_two_level { - args.push((module, export)); - } - } - } - instances.instantiate(root_state_module_index, args.iter().cloned()); - let root_state_instance_index = umbrella_instances; - umbrella_instances += 1; - - // Instantiate the root code module with the root state module. - let root_module_index = cx.root().pre_order_index(); - args.push(( - "__wizer_state", - wasm_encoder::Export::Instance(root_state_instance_index), - )); - instances.instantiate(root_module_index, args); - let root_instance_index = umbrella_instances; - umbrella_instances += 1; - - // Alias the root instance's exports and then re-export them. - let mut aliases = wasm_encoder::AliasSection::new(); - let mut exports = wasm_encoder::ExportSection::new(); - for exp in cx.root().exports(cx) { - if !self.keep_init_func.unwrap_or(DEFAULT_KEEP_INIT_FUNC) - && (exp.field == self.init_func - || (has_wasi_initialize && exp.field == "_initialize")) - { - continue; - } - - if !renames.rename_src_to_dst.contains_key(exp.field) - && renames.rename_dsts.contains(exp.field) - { - // A rename overwrites this export, and it is not renamed to - // another export, so skip it. - continue; - } - - let kind = translate::item_kind(exp.kind); - aliases.instance_export(root_instance_index, kind, exp.field); - - let field = renames - .rename_src_to_dst - .get(exp.field) - .map_or(exp.field, |f| f.as_str()); - exports.export( - field, - match kind { - wasm_encoder::ItemKind::Function => { - umbrella_funcs += 1; - wasm_encoder::Export::Function(umbrella_funcs - 1) - } - wasm_encoder::ItemKind::Table => { - umbrella_tables += 1; - wasm_encoder::Export::Table(umbrella_tables - 1) - } - wasm_encoder::ItemKind::Memory => { - umbrella_memories += 1; - wasm_encoder::Export::Memory(umbrella_memories - 1) - } - wasm_encoder::ItemKind::Global => { - umbrella_globals += 1; - wasm_encoder::Export::Global(umbrella_globals - 1) - } - wasm_encoder::ItemKind::Instance => { - umbrella_instances += 1; - wasm_encoder::Export::Instance(umbrella_instances - 1) - } - wasm_encoder::ItemKind::Module => unreachable!(), - wasm_encoder::ItemKind::Tag => unreachable!(), - }, - ); - } - - // NB: We encode the types last, even though it is the first section we - // place in the umbrella module, since adding state imports may need to - // define new instance types. - let types = umbrella_type_section(cx); - - // Now combine all our sections together in the umbrella module. - umbrella.section(&types); - umbrella.section(&code_modules); - umbrella.section(&modules); - for s in import_sections { - umbrella.section(s); - } - umbrella.section(&instances); - umbrella.section(&aliases); - umbrella.section(&exports); - - umbrella.finish() - } -} - -/// Create a type section with everything in the whole interned types set. -fn umbrella_type_section(cx: &ModuleContext<'_>) -> wasm_encoder::TypeSection { - let mut types = wasm_encoder::TypeSection::new(); - - let interned_entity_to_encoder_entity = |ty: &EntityType| match ty { - EntityType::Function(ty) => wasm_encoder::EntityType::Function(ty.index()), - EntityType::Table(ty) => wasm_encoder::EntityType::Table(translate::table_type(*ty)), - EntityType::Memory(ty) => wasm_encoder::EntityType::Memory(translate::memory_type(*ty)), - EntityType::Global(ty) => wasm_encoder::EntityType::Global(translate::global_type(*ty)), - EntityType::Module(ty) => wasm_encoder::EntityType::Module(ty.index()), - EntityType::Instance(ty) => wasm_encoder::EntityType::Instance(ty.index()), - }; - - for (_index, ty) in cx.types().iter() { - match ty { - Type::Func(f) => types.function( - f.params.iter().copied().map(translate::val_type), - f.returns.iter().copied().map(translate::val_type), - ), - Type::Instance(inst) => types.instance( - inst.exports - .iter() - .map(|(name, ty)| (name.as_ref(), interned_entity_to_encoder_entity(ty))), - ), - Type::Module(module) => types.module( - module.imports.iter().map(|((module, name), ty)| { - ( - module.as_ref(), - name.as_ref().map(|n| n.as_ref()), - interned_entity_to_encoder_entity(ty), - ) - }), - module - .exports - .iter() - .map(|(name, ty)| (name.as_ref(), interned_entity_to_encoder_entity(ty))), - ), - }; - } - - types } fn is_name_section(s: &wasm_encoder::RawSection) -> bool { @@ -551,582 +174,3 @@ fn is_name_section(s: &wasm_encoder::RawSection) -> bool { matches!(reader.read_string(), Ok("name")) } } - -/// Rewrite nested modules into a flat sequence, and where they import their -/// state, rather than define it locally. -/// -/// Returns the modules encoded in a module section and total number of code -/// modules defined. -fn rewrite_code_modules(cx: &mut ModuleContext) -> (wasm_encoder::ModuleSection, u32) { - let mut code_modules = wasm_encoder::ModuleSection::new(); - let mut num_code_modules = 0; - - cx.root().pre_order(cx, |cx, info| { - if info.get_aliased(cx).is_some() { - // Add a dummy module. This isn't ever actually used, since we will - // instead resolve the alias at the use sites and then use the - // aliased referent instead. If we had an alias kind like "alias a - // module from this index space" we would use that here. But we have - // to add an entry to the module index space to preserve our - // invariant that a code module is at its pre-order index in the - // umbrella's module index space. - code_modules.module(&wasm_encoder::Module::new()); - num_code_modules += 1; - return; - } - - let mut module = wasm_encoder::Module::new(); - - // We generally try to avoid renumbering entities in Wizer -- - // particularly any entities referenced from the code section, where - // renumbering could change the size of a LEB128 index and break DWARF - // debug info offsets -- because it means we can't copy whole sections - // from the original, input Wasm module. But we run into a conflicting - // constraints here with regards to instances: - // - // 1. Ideally we would import our state instance last, so that we don't - // perturb with our instance index space. - // - // 2. Locally-defined instances are state, and therefore must be pulled - // out of these code modules into our imported state instance, and - // then referenced via alias. - // - // (1) and (2) are in conflict because we can't create aliases of - // instances on the imported state instance until *after* the state - // instance is imported, which means we need to import our state - // instance first, which means we are forced to perturb the instance - // index space. - // - // Therefore, the first thing we add to each code module is an import - // section that imports the state instance. We need to explicitly - // rewrite all references to these instances (e.g. instance export - // aliases) to add one to their index so that they refer to the correct - // instance again. Luckily instances are never referenced from the code - // section, so DWARF debug info doesn't get invalidated. - // - // Finally, importing the state instance requires that we define the - // state instance's type. We really don't want to renumber types because - // those *are* referenced from the code section via `call_indirect`. To - // avoid renumbering types, we do a first pass over this module's types - // and build out a full type section with the same numbering as the - // original module, and then append the state import's type at the end. - let type_aliases = make_aliased_type_section(cx, info, 0); - module.section(&type_aliases); - let sections = make_state_import(cx, info); - for s in sections { - module.section(&s); - } - - // Now rewrite the initial sections one at a time. - // - // Note that the initial sections can occur repeatedly and in any - // order. This means that we only ever add, for example, `n` imports to - // the rewritten module when a particular import section defines `n` - // imports. We do *not* add all imports all at once. This is because - // imports and aliases might be interleaved, and adding all imports all - // at once could perturb entity numbering. - let mut sections = info.raw_sections(cx).iter(); - let mut imports = info.imports(cx).iter(); - let mut instantiations = 0..info.instantiations(cx).len(); - let mut aliases = info.aliases(cx).iter(); - let mut first_non_initial_section = None; - for section in sections.by_ref() { - match section { - // We handled this above. - s if s.id == SectionId::Type.into() => continue, - - // These are handled in subsequent steps of this pre-order - // traversal. - s if s.id == SectionId::Module.into() => continue, - - s if s.id == SectionId::Import.into() => { - let count = wasmparser::ImportSectionReader::new(s.data, 0) - .unwrap() - .get_count(); - let mut section = wasm_encoder::ImportSection::new(); - for imp in imports.by_ref().take(usize::try_from(count).unwrap()) { - section.import(imp.module, imp.field, translate::entity_type(imp.ty)); - } - module.section(§ion); - } - - // The actual instantiations are pulled out and handled in - // `rewrite_instantiations` and then we get them here via the - // state import. We need to bring them into scope via instance - // export aliases, however. - s if s.id == SectionId::Instance.into() => { - let count = wasmparser::InstanceSectionReader::new(s.data, 0) - .unwrap() - .get_count(); - let mut section = wasm_encoder::AliasSection::new(); - for idx in instantiations - .by_ref() - .take(usize::try_from(count).unwrap()) - { - // Our imported state instance is always instance 0. - let from_instance = 0; - let name = format!("__wizer_instance_{}", idx); - section.instance_export( - from_instance, - wasm_encoder::ItemKind::Instance, - &name, - ); - } - module.section(§ion); - } - - s if s.id == SectionId::Alias.into() => { - let count = wasmparser::AliasSectionReader::new(s.data, 0) - .unwrap() - .get_count(); - let mut section = wasm_encoder::AliasSection::new(); - for alias in aliases.by_ref().take(usize::try_from(count).unwrap()) { - match alias { - // We don't make any instantiations so we don't need - // modules here anymore. - wasmparser::Alias::OuterModule { .. } => continue, - // We already created a complete type section, - // including any aliases, above. - wasmparser::Alias::OuterType { .. } => continue, - // Copy over instance export aliases. - // however. - wasmparser::Alias::InstanceExport { - instance, - kind, - export, - } => { - // We need to add one to the instance's index - // because our state instance import shifted - // everything off by one. - let from_instance = instance + 1; - section.instance_export( - from_instance, - translate::item_kind(*kind), - export, - ); - } - } - } - module.section(§ion); - } - - s => { - assert!(first_non_initial_section.is_none()); - first_non_initial_section = Some(s); - break; - } - } - } - - // We don't define the memories from the original memory section, but we - // do add instance export aliases for each of them from our imported - // state instance. These aliases need to be in an alias section, which - // is an initial section and must come before the rest of the - // non-initial sections. But it must also come *after* any memories that - // might have been imported, so that we don't mess up the - // numbering. Therefore we add these aliases here, after we've processed - // the initial sections, but before we start with the rest of the - // sections. - if info.defined_memories_index(cx).is_some() { - let mut section = wasm_encoder::AliasSection::new(); - for (i, _) in info.defined_memories(cx).enumerate() { - // Our state instance is always instance 0. - let from_instance = 0; - let name = format!("__wizer_memory_{}", i); - section.instance_export(from_instance, wasm_encoder::ItemKind::Memory, &name); - } - module.section(§ion); - } - - // Globals are handled the same way as memories. - if info.defined_globals_index(cx).is_some() { - let mut section = wasm_encoder::AliasSection::new(); - for (i, _) in info.defined_globals(cx).enumerate() { - let from_instance = 0; - let name = format!("__wizer_global_{}", i); - section.instance_export(from_instance, wasm_encoder::ItemKind::Global, &name); - } - module.section(§ion); - } - - // Process the rest of the non-initial sections. - for section in first_non_initial_section.into_iter().chain(sections) { - match section { - // We replaced these with instance export aliases from our state - // instance above. - s if s.id == SectionId::Memory.into() => continue, - s if s.id == SectionId::Global.into() => continue, - - // We ignore the original data segments. We don't define - // memories anymore and state instances will define their own - // data segments based on the snapshot. - s if s.id == SectionId::Data.into() => continue, - s if s.id == SectionId::DataCount.into() => continue, - - // The start function has already been run! - s if s.id == SectionId::Start.into() => continue, - - // Finally, everything else is copied over as-is! - s => { - module.section(s); - } - } - } - - code_modules.module(&module); - num_code_modules += 1; - }); - - (code_modules, num_code_modules) -} - -/// Make the equivalent of the given module's type section from outer type -/// aliases that bring types from the umbrella module's types space into this -/// code module's types space. -fn make_aliased_type_section( - cx: &ModuleContext<'_>, - module: Module, - depth: u32, -) -> wasm_encoder::AliasSection { - let mut aliases = wasm_encoder::AliasSection::new(); - for ty in module.types(cx) { - aliases.outer_type(depth, ty.index()); - } - aliases -} - -/// Make an import section that imports a code module's state instance import. -fn make_state_import( - cx: &mut ModuleContext<'_>, - module: Module, -) -> Vec { - let mut sections = vec![]; - - // Define the state instance's type. - let state_instance_ty = module.define_state_instance_type(cx); - - // Alias the state instance type from the umbrella. - let mut alias = wasm_encoder::AliasSection::new(); - alias.outer_type(0, state_instance_ty.index()); - sections.push(StateImportSection::Alias(alias)); - - let state_instance_type_index = u32::try_from(module.types(cx).len()).unwrap(); - module.push_aliased_type(cx, state_instance_ty); - - // Define the import of the state instance, using the type - // we just defined. - let mut imports = wasm_encoder::ImportSection::new(); - imports.import( - "__wizer_state", - None, - wasm_encoder::EntityType::Instance(state_instance_type_index), - ); - sections.push(StateImportSection::Import(imports)); - - return sections; - - enum StateImportSection { - Alias(wasm_encoder::AliasSection), - Import(wasm_encoder::ImportSection), - } - - impl wasm_encoder::Section for StateImportSection { - fn id(&self) -> u8 { - match self { - StateImportSection::Alias(s) => s.id(), - StateImportSection::Import(s) => s.id(), - } - } - - fn encode(&self, sink: &mut S) - where - S: Extend, - { - match self { - StateImportSection::Alias(s) => s.encode(sink), - StateImportSection::Import(s) => s.encode(sink), - } - } - } -} - -/// Create the state module the given module instantiation and recursively do -/// the same for its nested instantiations. -fn rewrite_state_module( - cx: &ModuleContext<'_>, - store: &crate::Store, - info: Module, - snapshot: &Snapshot, - depth: u32, -) -> wasm_encoder::Module { - let mut state_module = wasm_encoder::Module::new(); - let mut exports = wasm_encoder::ExportSection::new(); - - // If there are nested instantiations, then define the nested state - // modules and then instantiate them. - assert_eq!(info.instantiations(cx).len(), snapshot.instantiations.len()); - if !snapshot.instantiations.is_empty() { - // We create nested instantiations such that each state module has - // the following module index space: - // - // [ - // alias instantiation[0]'s code module, - // alias instantiation[1]'s code module, - // ... - // alias instantiation[N]'s code module, - // define instantiation[0]'s state module, - // define instantiation[1]'s state module, - // ... - // define instantiation[N]'s state module, - // ] - // - // That is, the `i`th nested instantiation's code module is the `i`th - // module in the index space, and its state module is at index `N+i`. - // - // We define all the code module aliases up front. Nested instantiations - // may require aliasing instance exports from earlier instantiations, so - // we interleave those in the same order that they appeared in the - // original Wasm binary below. - let mut alias_section = wasm_encoder::AliasSection::new(); - for (module, _) in info.instantiations(cx).values() { - let module = module.get_aliased(cx).unwrap_or(*module); - - // Because we flatten the code modules into the umbrella module with - // a pre-order traversal, this instantiation's code module is the - // `module.pre_order_index()`th module in the root module's module - // index space. - let code_module_index_in_root = module.pre_order_index(); - alias_section.outer_module(depth, code_module_index_in_root); - } - state_module.section(&alias_section); - - // The instance index space is more complicated than the module index - // space because of potential instance imports and aliasing imported - // instance's exported nested instances. These imported/aliased - // instances can then be used as arguments to a nested instantiation, - // and then the resulting instance can also be used as an argument to - // further nested instantiations. To handle all this, we use a - // `Renumbering` map for tracking instance indices. - let mut instance_renumbering = Renumbering::default(); - - let aliased_types = make_aliased_type_section(cx, info, depth); - state_module.section(&aliased_types); - - let mut instance_import_counts = info.instance_import_counts(cx).iter().copied(); - let mut aliases = info.aliases(cx).iter(); - let mut instantiations = info.instantiations(cx).values().enumerate(); - - for section in info.initial_sections(cx) { - match section { - // Handled above. - s if s.id == SectionId::Type.into() => continue, - - // Copy the imports over and update our renumbering for any - // imported instances. - s if s.id == SectionId::Import.into() => { - state_module.section(s); - let instance_import_count = instance_import_counts.next().unwrap(); - for _ in 0..instance_import_count { - instance_renumbering.add_import(); - } - } - - // Update instance export aliases to use the numbered instance - // indices. Also update the renumbering for any aliased - // instances brought into scope. - s if s.id == SectionId::Alias.into() => { - let count = wasmparser::AliasSectionReader::new(s.data, 0) - .unwrap() - .get_count(); - let mut section = wasm_encoder::AliasSection::new(); - for alias in aliases.by_ref().take(usize::try_from(count).unwrap()) { - match alias { - wasmparser::Alias::InstanceExport { - instance, - kind, - export, - } => { - section.instance_export( - instance_renumbering.lookup(*instance), - translate::item_kind(*kind), - export, - ); - // If this brought a new instance into our - // instance index space, update our renumbering - // map. - if let wasmparser::ExternalKind::Instance = kind { - instance_renumbering.add_alias(); - } - } - // Handled by `make_complete_type_section`. - wasmparser::Alias::OuterType { .. } => continue, - // Ignore these because we alias only the modules we - // need for nested instantiations below. - wasmparser::Alias::OuterModule { .. } => continue, - } - } - state_module.section(§ion); - } - - // We alias only the modules we need for nested instantiations - // below. - s if s.id == SectionId::Module.into() => continue, - - // For each nested instantiation in this section, alias its code - // module, define its state module, instantiate the state module - // to create the state instance, instantiate the code module - // with the state instance, and finally export the code+state - // instance. - s if s.id == SectionId::Instance.into() => { - let count = wasmparser::InstanceSectionReader::new(s.data, 0) - .unwrap() - .get_count(); - let mut instance_section = wasm_encoder::InstanceSection::new(); - let mut module_section = wasm_encoder::ModuleSection::new(); - for (i, (module, instance_args)) in instantiations - .by_ref() - .take(usize::try_from(count).unwrap()) - { - // Define the state module for this instantiation. - let state_module = rewrite_state_module( - cx, - store, - *module, - &snapshot.instantiations[i], - depth + 1, - ); - module_section.module(&state_module); - - // Instantiate the state module to create the state - // instance. - let args: Vec<_> = instance_args - .iter() - .map(|arg| { - let mut arg = translate::instance_arg(arg); - if let (_name, wasm_encoder::Export::Instance(ref mut index)) = arg - { - *index = instance_renumbering.lookup(*index); - } - arg - }) - .collect(); - instance_section.instantiate( - u32::try_from(snapshot.instantiations.len() + i).unwrap(), - args, - ); - let state_instance_index = instance_renumbering.define_new(); - - // Then instantiate the associated code module, passing it this - // state instance and whatever other arguments it expects. - let args: Vec<_> = iter::once(( - "__wizer_state", - wasm_encoder::Export::Instance(state_instance_index), - )) - .chain(instance_args.iter().map(|arg| { - let mut arg = translate::instance_arg(arg); - if let (_name, wasm_encoder::Export::Instance(ref mut index)) = arg { - *index = instance_renumbering.lookup(*index); - } - arg - })) - .collect(); - instance_section.instantiate(u32::try_from(i).unwrap(), args); - let (_, code_and_state_instance_index) = instance_renumbering.define_both(); - - // Add the export for this nested instance. - let name = format!("__wizer_instance_{}", i); - exports.export( - &name, - wasm_encoder::Export::Instance( - u32::try_from(code_and_state_instance_index).unwrap(), - ), - ); - } - state_module.section(&module_section); - state_module.section(&instance_section); - } - - _ => unreachable!(), - } - } - } - - // Add defined memories. - assert_eq!(info.defined_memories_len(cx), snapshot.memory_mins.len()); - if info.defined_memories_index(cx).is_some() { - let mut memories = wasm_encoder::MemorySection::new(); - for (i, (new_min, (_, mem))) in snapshot - .memory_mins - .iter() - .copied() - .zip(info.defined_memories(cx)) - .enumerate() - { - let mut mem = translate::memory_type(mem); - assert!(new_min >= mem.minimum); - assert!(new_min <= mem.maximum.unwrap_or(u64::MAX)); - mem.minimum = new_min; - memories.memory(mem); - - let name = format!("__wizer_memory_{}", i); - exports.export( - &name, - wasm_encoder::Export::Memory(u32::try_from(i).unwrap()), - ); - } - state_module.section(&memories); - } - - // Add defined globals. - assert_eq!(info.defined_globals_len(cx), snapshot.globals.len()); - if info.defined_globals_index(cx).is_some() { - let mut globals = wasm_encoder::GlobalSection::new(); - for (i, (val, (_, glob_ty))) in snapshot - .globals - .iter() - .zip(info.defined_globals(cx)) - .enumerate() - { - let glob_ty = translate::global_type(glob_ty); - globals.global( - glob_ty, - &match val { - wasmtime::Val::I32(x) => wasm_encoder::Instruction::I32Const(*x), - wasmtime::Val::I64(x) => wasm_encoder::Instruction::I64Const(*x), - wasmtime::Val::F32(x) => { - wasm_encoder::Instruction::F32Const(f32::from_bits(*x)) - } - wasmtime::Val::F64(x) => { - wasm_encoder::Instruction::F64Const(f64::from_bits(*x)) - } - wasmtime::Val::V128(x) => wasm_encoder::Instruction::V128Const(*x as i128), - _ => unreachable!(), - }, - ); - - let name = format!("__wizer_global_{}", i); - exports.export( - &name, - wasm_encoder::Export::Global(u32::try_from(i).unwrap()), - ); - } - state_module.section(&globals); - } - - state_module.section(&exports); - - // Add data segments. - if !snapshot.data_segments.is_empty() { - let mut data = wasm_encoder::DataSection::new(); - for seg in &snapshot.data_segments { - data.active( - seg.memory_index, - &wasm_encoder::Instruction::I32Const(seg.offset as i32), - seg.data(store).iter().copied(), - ); - } - state_module.section(&data); - } - - state_module -} diff --git a/src/rewrite/renumbering.rs b/src/rewrite/renumbering.rs deleted file mode 100644 index 1d17017..0000000 --- a/src/rewrite/renumbering.rs +++ /dev/null @@ -1,57 +0,0 @@ -use std::convert::TryFrom; - -/// A renumbering of indices. -/// -/// Keeps track of which indices in the original Wasm map to which indices in -/// the rewritten Wasm. -/// -/// Only supports injective renumberings: every old index has a corresponding -/// unique new index, but each new index does not need to have a corresponding -/// old index. -#[derive(Default, Debug)] -pub struct Renumbering { - old_count: u32, - new_count: u32, - old_to_new: Vec, -} - -impl Renumbering { - /// Define an entry in both the old and new index spaces. Returns a tuple of - /// the old and new indices. - pub fn define_both(&mut self) -> (u32, u32) { - debug_assert_eq!( - self.old_to_new.len(), - usize::try_from(self.old_count).unwrap() - ); - self.old_to_new.push(self.new_count); - self.old_count += 1; - self.new_count += 1; - (self.old_count - 1, self.new_count - 1) - } - - /// Add an import to both the old and new index spaces. Returns a tuple of - /// the old and new indices. - pub fn add_import(&mut self) -> (u32, u32) { - self.define_both() - } - - /// Add an alias to both the old and new index spaces. Returns a tuple of - /// the old and new indices. - pub fn add_alias(&mut self) -> (u32, u32) { - self.define_both() - } - - /// Add an entry to the new index space. Returns the entry's index in the - /// new index space. - pub fn define_new(&mut self) -> u32 { - self.new_count += 1; - self.new_count - 1 - } - - /// Get the new index for the given old index. - /// - /// Panics when `old` is not in the old index space. - pub fn lookup(&self, old: u32) -> u32 { - self.old_to_new[usize::try_from(old).unwrap()] - } -} diff --git a/src/translate.rs b/src/translate.rs index b205e15..9be934e 100644 --- a/src/translate.rs +++ b/src/translate.rs @@ -1,13 +1,5 @@ //! Type translator functions from `wasmparser` to `wasm_encoder`. -pub(crate) fn table_type(table_ty: wasmparser::TableType) -> wasm_encoder::TableType { - wasm_encoder::TableType { - element_type: val_type(table_ty.element_type), - minimum: table_ty.initial, - maximum: table_ty.maximum, - } -} - pub(crate) fn val_type(ty: wasmparser::Type) -> wasm_encoder::ValType { use wasm_encoder::ValType; use wasmparser::Type::*; @@ -18,8 +10,7 @@ pub(crate) fn val_type(ty: wasmparser::Type) -> wasm_encoder::ValType { F64 => ValType::F64, V128 => ValType::V128, FuncRef => ValType::FuncRef, - ExternRef | ExnRef => panic!("not supported"), - Func | EmptyBlockType => unreachable!(), + ExternRef => panic!("not supported"), } } @@ -39,58 +30,12 @@ pub(crate) fn memory_type(ty: wasmparser::MemoryType) -> wasm_encoder::MemoryTyp } } -pub(crate) fn entity_type(ty: wasmparser::ImportSectionEntryType) -> wasm_encoder::EntityType { - match ty { - wasmparser::ImportSectionEntryType::Function(f) => wasm_encoder::EntityType::Function(f), - wasmparser::ImportSectionEntryType::Table(tty) => { - wasm_encoder::EntityType::Table(table_type(tty)) - } - wasmparser::ImportSectionEntryType::Memory(mty) => { - wasm_encoder::EntityType::Memory(memory_type(mty)) - } - wasmparser::ImportSectionEntryType::Global(gty) => { - wasm_encoder::EntityType::Global(global_type(gty)) - } - wasmparser::ImportSectionEntryType::Instance(ity) => { - wasm_encoder::EntityType::Instance(ity) - } - wasmparser::ImportSectionEntryType::Module(_) => { - unreachable!( - "we disallow importing/exporting modules so we shouldn't \ - have module types" - ) - } - wasmparser::ImportSectionEntryType::Tag(_) => unreachable!(), - } -} - -pub(crate) fn item_kind(kind: wasmparser::ExternalKind) -> wasm_encoder::ItemKind { - match kind { - wasmparser::ExternalKind::Function => wasm_encoder::ItemKind::Function, - wasmparser::ExternalKind::Table => wasm_encoder::ItemKind::Table, - wasmparser::ExternalKind::Memory => wasm_encoder::ItemKind::Memory, - wasmparser::ExternalKind::Global => wasm_encoder::ItemKind::Global, - wasmparser::ExternalKind::Module => wasm_encoder::ItemKind::Module, - wasmparser::ExternalKind::Instance => wasm_encoder::ItemKind::Instance, - wasmparser::ExternalKind::Type | wasmparser::ExternalKind::Tag => unreachable!(), - } -} - pub(crate) fn export(kind: wasmparser::ExternalKind, index: u32) -> wasm_encoder::Export { match kind { - wasmparser::ExternalKind::Function => wasm_encoder::Export::Function(index), + wasmparser::ExternalKind::Func => wasm_encoder::Export::Function(index), wasmparser::ExternalKind::Global => wasm_encoder::Export::Global(index), wasmparser::ExternalKind::Table => wasm_encoder::Export::Table(index), wasmparser::ExternalKind::Memory => wasm_encoder::Export::Memory(index), - wasmparser::ExternalKind::Instance => wasm_encoder::Export::Instance(index), - wasmparser::ExternalKind::Tag - | wasmparser::ExternalKind::Type - | wasmparser::ExternalKind::Module => unreachable!(), + wasmparser::ExternalKind::Tag => unreachable!(), } } - -pub(crate) fn instance_arg<'a>( - arg: &wasmparser::InstanceArg<'a>, -) -> (&'a str, wasm_encoder::Export) { - (arg.name, export(arg.kind, arg.index)) -} diff --git a/tests/tests.rs b/tests/tests.rs index ad62b4e..63ca5f3 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -12,7 +12,6 @@ fn get_wizer() -> Wizer { let mut wizer = Wizer::new(); wizer.allow_wasi(true).unwrap(); wizer.wasm_multi_memory(true); - wizer.wasm_module_linking(true); wizer.wasm_bulk_memory(true); wizer } @@ -85,9 +84,7 @@ fn fails_wizening(wat: &str) -> Result<()> { let wasm = wat_to_wasm(wat)?; - let mut validator = wasmparser::Validator::new(); - validator.wasm_features(wasmparser::WasmFeatures { - module_linking: true, + let mut validator = wasmparser::Validator::new_with_features(wasmparser::WasmFeatures { multi_memory: true, ..Default::default() }); From 509dd596977d1d7acde04ecddb6a4f47b7de9590 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 14 Apr 2023 15:20:35 -0700 Subject: [PATCH 8/9] Update `wasmparser` to a version with the latest encoding of multi-memory This commit further updates the `wasmparser` dependency across some versions with minor renamings and structuring of the API. This pulls in enough support to get the `multi_memory` test passing. --- Cargo.lock | 6 +++--- Cargo.toml | 2 +- src/info.rs | 10 +++++----- src/info/types_interner.rs | 8 ++------ src/parse.rs | 23 +++++++++++++---------- src/translate.rs | 4 ++-- 6 files changed, 26 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ee2103e..f29453c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1908,9 +1908,9 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.84.0" +version = "0.87.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77dc97c22bb5ce49a47b745bed8812d30206eff5ef3af31424f2c1820c0974b2" +checksum = "5c04e207cd2e8ecb6f9bd28a2cf3119b4c6bfeee6fe3a25cc1daf8041d00a875" dependencies = [ "indexmap", ] @@ -2416,7 +2416,7 @@ dependencies = [ "structopt", "wasi-cap-std-sync", "wasm-encoder 0.10.0", - "wasmparser 0.84.0", + "wasmparser 0.87.0", "wasmprinter", "wasmtime", "wasmtime-wasi", diff --git a/Cargo.toml b/Cargo.toml index 56d7d78..8ce0071 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,7 @@ rayon = "1.5.0" structopt = { version = "0.3.21", optional = true } wasi-cap-std-sync = "3.0.0" wasm-encoder = "0.10.0" -wasmparser = "0.84.0" +wasmparser = "0.87.0" wasmtime = "3.0.0" wasmtime-wasi = "3.0.0" diff --git a/src/info.rs b/src/info.rs index 13cb362..75de9e8 100644 --- a/src/info.rs +++ b/src/info.rs @@ -1,10 +1,10 @@ +use std::convert::TryFrom; +use std::ops::Range; +use types_interner::{EntityType, TypeId, TypesInterner}; use wasm_encoder::SectionId; pub mod types_interner; -use std::convert::TryFrom; -use types_interner::{EntityType, TypeId, TypesInterner}; - /// A collection of info about modules within a module linking bundle. pub(crate) struct ModuleContext<'a> { arena: Vec>, @@ -134,7 +134,7 @@ impl Module { self, cx: &mut ModuleContext<'a>, id: SectionId, - range: wasmparser::Range, + range: Range, full_wasm: &'a [u8], ) { cx.defined_mut(self) @@ -146,7 +146,7 @@ impl Module { } /// Push a new type into this module's types space. - pub fn push_type<'a>(self, cx: &mut ModuleContext<'a>, ty: wasmparser::TypeDef) { + pub fn push_type<'a>(self, cx: &mut ModuleContext<'a>, ty: wasmparser::Type) { let types_space = match &cx.arena[self.id] { ModuleInfo::Defined(d) => &d.types, }; diff --git a/src/info/types_interner.rs b/src/info/types_interner.rs index 91cade0..98d8fac 100644 --- a/src/info/types_interner.rs +++ b/src/info/types_interner.rs @@ -59,13 +59,9 @@ impl TypesInterner { /// /// If the type has already been inserted and assigned an id before, then /// that entry and its id are reused. - pub fn insert_wasmparser( - &mut self, - ty: wasmparser::TypeDef, - _types_space: &[TypeId], - ) -> TypeId { + pub fn insert_wasmparser(&mut self, ty: wasmparser::Type, _types_space: &[TypeId]) -> TypeId { match ty { - wasmparser::TypeDef::Func(func_ty) => self.insert(Type::Func(func_ty)), + wasmparser::Type::Func(func_ty) => self.insert(Type::Func(func_ty)), } } diff --git a/src/parse.rs b/src/parse.rs index 63be01e..349da6e 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -74,12 +74,12 @@ pub(crate) fn parse<'a>(full_wasm: &'a [u8]) -> anyhow::Result data.range(), full_wasm, ), - CustomSection { range, .. } => { - stack - .top_mut() - .module - .add_raw_section(&mut cx, SectionId::Custom, range, full_wasm) - } + CustomSection(c) => stack.top_mut().module.add_raw_section( + &mut cx, + SectionId::Custom, + c.range(), + full_wasm, + ), CodeSectionStart { range, count: _, @@ -106,13 +106,16 @@ pub(crate) fn parse<'a>(full_wasm: &'a [u8]) -> anyhow::Result ComponentTypeSection(_) | ComponentImportSection(_) - | ComponentFunctionSection(_) | ComponentExportSection(_) | ComponentStartSection(_) + | ComponentAliasSection(_) + | CoreTypeSection(_) + | InstanceSection(_) + | ComponentInstanceSection(_) + | ComponentCanonicalSection(_) | AliasSection(_) | ModuleSection { .. } - | ComponentSection { .. } - | InstanceSection(_) => { + | ComponentSection { .. } => { unreachable!() } } @@ -134,7 +137,7 @@ fn type_section<'a>( for _ in 0..count { let ty = types.read()?; match ty { - wasmparser::TypeDef::Func(_) => { + wasmparser::Type::Func(_) => { module.push_type(cx, ty); } } diff --git a/src/translate.rs b/src/translate.rs index 9be934e..80bde49 100644 --- a/src/translate.rs +++ b/src/translate.rs @@ -1,8 +1,8 @@ //! Type translator functions from `wasmparser` to `wasm_encoder`. -pub(crate) fn val_type(ty: wasmparser::Type) -> wasm_encoder::ValType { +pub(crate) fn val_type(ty: wasmparser::ValType) -> wasm_encoder::ValType { use wasm_encoder::ValType; - use wasmparser::Type::*; + use wasmparser::ValType::*; match ty { I32 => ValType::I32, I64 => ValType::I64, From f2f15f3fbef1e909cf996561d96740ed558a2b77 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 14 Apr 2023 15:33:22 -0700 Subject: [PATCH 9/9] Remove module linking support from fuzzer --- fuzz/fuzz_targets/same_result.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/fuzz/fuzz_targets/same_result.rs b/fuzz/fuzz_targets/same_result.rs index b069bdb..43fbd45 100644 --- a/fuzz/fuzz_targets/same_result.rs +++ b/fuzz/fuzz_targets/same_result.rs @@ -68,7 +68,6 @@ fuzz_target!(|module: wasm_smith::ConfiguredModule| { // initialization routine. let mut wizer = wizer::Wizer::new(); wizer - .wasm_module_linking(true) .wasm_multi_memory(true) .wasm_multi_value(true) .init_func(init_func); @@ -197,10 +196,6 @@ impl<'a> arbitrary::Arbitrary<'a> for WasmConfig { } impl wasm_smith::Config for WasmConfig { - fn module_linking_enabled(&self) -> bool { - true - } - fn max_memories(&self) -> usize { 10 }