diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 8d01a9b17..d30eb909f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -35,6 +35,11 @@ jobs: with: command: test args: --verbose ${{ env.CARGO_ARGS }} + - name: check compilation without threading + uses: actions-rs/cargo@v1 + with: + command: check + args: ${{ env.CARGO_ARGS }} --no-default-features snippets_cpython: name: Run snippets and cpython tests diff --git a/Cargo.lock b/Cargo.lock index 385b861fa..fbb71e5d6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7,16 +7,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" [[package]] -name = "adler32" -version = "1.0.4" +name = "adler" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d2e7343e7fc9de883d1b0341e0b13970f764c14101234857d2ddafa1cb1cac2" +checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e" + +[[package]] +name = "adler32" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567b077b825e468cc974f0020d4082ee6e03132512f207ef1a02fd5d00d1f32d" [[package]] name = "aho-corasick" -version = "0.7.10" +version = "0.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8716408b8bc624ed7f65d223ddb9ac2d044c0547b6fa4b0d554f3a9540496ada" +checksum = "043164d8ba5c4c3035fec9bbee8647c0261d788f3474306f93bb65901cae0e86" dependencies = [ "memchr", ] @@ -47,8 +53,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0609c78bd572f4edc74310dfb63a01f5609d53fa8b4dd7c4d98aef3b3e8d72d1" dependencies = [ "proc-macro-hack", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.7", + "syn 1.0.35", ] [[package]] @@ -112,9 +118,9 @@ checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" [[package]] name = "bincode" -version = "1.2.1" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5753e2a71534719bf3f4e57006c3a4f0d2c672a4b676eec84161f763eca87dbf" +checksum = "f30d3a39baa26f9651f17b375061f3233dde33424a8b72b0dbe93a68a0bc896d" dependencies = [ "byteorder 1.3.4", "serde", @@ -122,18 +128,18 @@ dependencies = [ [[package]] name = "bit-set" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e84c238982c4b1e1ee668d136c510c67a13465279c0cb367ea6baf6310620a80" +checksum = "6e11e16035ea35e4e5997b393eacbf6f63983188f7a2ad25bfb13465f5ad59de" dependencies = [ "bit-vec", ] [[package]] name = "bit-vec" -version = "0.5.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f59bbe95d4e52a6398ec21238d31577f2b28a9d86807f06ca59d191d8440d0bb" +checksum = "5f0dc55f2d8a1a85650ac47858bb001b4c0dd73d79e3c455a842925e68d29cd3" [[package]] name = "bitflags" @@ -187,9 +193,9 @@ dependencies = [ [[package]] name = "bstr" -version = "0.2.12" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2889e6d50f394968c8bf4240dc3f2a7eb4680844d27308f798229ac9d4725f41" +checksum = "31accafdb70df7871592c058eca3985b71104e15ac32f64706022c58867da931" dependencies = [ "lazy_static 1.4.0", "memchr", @@ -205,9 +211,9 @@ checksum = "39092a32794787acd8525ee150305ff051b0aa6cc2abaf193924f5ab05425f39" [[package]] name = "bumpalo" -version = "3.2.1" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12ae9db68ad7fac5fe51304d20f016c911539251075a214f8e663babefa35187" +checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" [[package]] name = "byte-tools" @@ -239,9 +245,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.50" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95e28fa049fda1c330bcf9d723be7663a899c4679724b34c81e9f5a326aab8cd" +checksum = "f9a06fb2e53271d7c279ec1efea6ab691c35a2ae67ec0d91d7acec0caf13b518" [[package]] name = "cfg-if" @@ -251,9 +257,9 @@ checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" [[package]] name = "chrono" -version = "0.4.11" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80094f509cf8b5ae86a4966a39b3ff66cd7e2a3e594accec3743ff3fabeab5b2" +checksum = "c74d84029116787153e02106bf53e66828452a4b325cc8652b788b5967c0a0b6" dependencies = [ "js-sys", "num-integer", @@ -264,9 +270,9 @@ dependencies = [ [[package]] name = "clap" -version = "2.33.0" +version = "2.33.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" +checksum = "bdfa80d47f954d53a35a64987ca1422f495b8d6483c0fe9f7117b36c2a792129" dependencies = [ "ansi_term", "atty", @@ -379,9 +385,9 @@ version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb582b60359da160a9477ee80f15c8d784c477e69c217ef2cdd4169c24ea380f" dependencies = [ - "proc-macro2 1.0.10", - "quote 1.0.3", - "syn 1.0.17", + "proc-macro2 1.0.19", + "quote 1.0.7", + "syn 1.0.35", ] [[package]] @@ -410,16 +416,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "dirs" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c4ef5a8b902d393339e2a2c7fe573af92ce7e0ee5a3ff827b4c9ad7e07e4fa1" -dependencies = [ - "cfg-if", - "dirs-sys", -] - [[package]] name = "dirs-next" version = "1.0.1" @@ -430,18 +426,6 @@ dependencies = [ "dirs-sys-next", ] -[[package]] -name = "dirs-sys" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afa0b23de8fd801745c471deffa6e12d248f962c9fd4b4c33787b055599bde7b" -dependencies = [ - "cfg-if", - "libc", - "redox_users", - "winapi", -] - [[package]] name = "dirs-sys-next" version = "0.1.0" @@ -455,9 +439,9 @@ dependencies = [ [[package]] name = "dns-lookup" -version = "1.0.1" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13988670860b076248c74e1b54444efc4f1dec70c8bb25da4b7c0024396b72bf" +checksum = "4cbea23c15f7e685a7ad01c994407f3849fa7c88556aaafe4054215b6df93f78" dependencies = [ "libc", "socket2", @@ -560,9 +544,9 @@ dependencies = [ [[package]] name = "flate2" -version = "1.0.14" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cfff41391129e0a856d6d822600b8d71179d46879e310417eb9c762eb178b42" +checksum = "68c90b0fc46cf89d227cc78b40e494ff81287a92dd07631e5af0d06fe3cf885e" dependencies = [ "cfg-if", "crc32fast", @@ -573,9 +557,9 @@ dependencies = [ [[package]] name = "fnv" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "foreign-types" @@ -606,9 +590,9 @@ checksum = "1b980f2816d6ee8673b6517b52cb0e808a180efc92e5c19d02cdda79066703ef" [[package]] name = "generational-arena" -version = "0.2.3" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "921c3803adaeb9f9639de5149d9f0f9f4b79f00c423915b701db2e02ed80b9ce" +checksum = "8e1d3b771574f62d0548cee0ad9057857e9fc25d7a3335f140c84f6acd0bf601" dependencies = [ "cfg-if", ] @@ -645,10 +629,19 @@ dependencies = [ ] [[package]] -name = "hermit-abi" -version = "0.1.10" +name = "hashbrown" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "725cf19794cf90aa94e65050cb4191ff5d8fa87a498383774c47b332e3af952e" +checksum = "34f595585f103464d8d2f6e9864682d74c1601fed5e07d62b1c9058dba8246fb" +dependencies = [ + "autocfg 1.0.0", +] + +[[package]] +name = "hermit-abi" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9" dependencies = [ "libc", ] @@ -676,18 +669,24 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.3.2" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "076f042c5b7b98f31d205f1249267e12a6518c1481e9dae9764af19b707d2292" +checksum = "5b88cd59ee5f71fea89a62248fc8f387d44400cefe05ef548466d61ced9029a7" dependencies = [ "autocfg 1.0.0", + "hashbrown", ] [[package]] name = "instant" -version = "0.1.4" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7777a24a1ce5de49fcdde84ec46efa487c3af49d5b6e6e0a50367cc5c1096182" +checksum = "5b141fdc7836c525d4d594027d318c84161ca17aaf8113ab1f81ab93ae897485" +dependencies = [ + "js-sys", + "wasm-bindgen", + "web-sys", +] [[package]] name = "is-macro" @@ -697,9 +696,9 @@ checksum = "04807f3dc9e3ea39af3f8469a5297267faf94859637afb836b33f47d9b2650ee" dependencies = [ "Inflector", "pmutil", - "proc-macro2 1.0.10", - "quote 1.0.3", - "syn 1.0.17", + "proc-macro2 1.0.19", + "quote 1.0.7", + "syn 1.0.35", ] [[package]] @@ -713,15 +712,15 @@ dependencies = [ [[package]] name = "itoa" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8b7a7c0c47db5545ed3fef7468ee7bb5b74691498139e4b3f6a20685dc6dd8e" +checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" [[package]] name = "js-sys" -version = "0.3.37" +version = "0.3.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a27d435371a2fa5b6d2b028a74bbdb1234f308da363226a2854ca3ff8ba7055" +checksum = "52732a3d3ad72c58ad2dc70624f9c17b46ecd0943b9a4f1ee37c4c18c5d983e2" dependencies = [ "wasm-bindgen", ] @@ -801,9 +800,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.71" +version = "0.2.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49" +checksum = "bd7d4bd64732af4bf3a67f367c27df8520ad7e230c5817b8ff485864d80242b9" [[package]] name = "libz-sys" @@ -819,18 +818,18 @@ dependencies = [ [[package]] name = "lock_api" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de302ce1fe7482db13738fbaf2e21cfb06a986b89c0bf38d88abf16681aada4e" +checksum = "28247cc5a5be2f05fbcd76dd0cf2c7d3b5400cb978a28042abcd4fa0b3f8261c" dependencies = [ "scopeguard", ] [[package]] name = "log" -version = "0.4.8" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" +checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" dependencies = [ "cfg-if", ] @@ -876,11 +875,11 @@ checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" [[package]] name = "miniz_oxide" -version = "0.3.6" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa679ff6578b1cddee93d7e82e263b94a575e0bfced07284eb0c037c1d2416a5" +checksum = "be0f75932c1f6cfae3c04000e40114adf955636e19040f9c0a2c380702aa1c7f" dependencies = [ - "adler32", + "adler", ] [[package]] @@ -985,9 +984,9 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.12.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46203554f085ff89c235cd12f7075f3233af9b11ed7c9e16dfe2560d03313ce6" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" dependencies = [ "hermit-abi", "libc", @@ -1010,16 +1009,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffa5a33ddddfee04c0283a7653987d634e880347e96b5b2ed64de07efb59db9d" dependencies = [ "proc-macro-crate", - "proc-macro2 1.0.10", - "quote 1.0.3", - "syn 1.0.17", + "proc-macro2 1.0.19", + "quote 1.0.7", + "syn 1.0.35", ] [[package]] name = "once_cell" -version = "1.3.1" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1c601810575c99596d4afc46f78a678c80105117c379eb3650cf99b8a21ce5b" +checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" [[package]] name = "opaque-debug" @@ -1029,9 +1028,9 @@ checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" [[package]] name = "openssl" -version = "0.10.29" +version = "0.10.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cee6d85f4cb4c4f59a6a85d5b68a233d280c82e29e822913b9c8b129fbf20bdd" +checksum = "8d575eff3665419f9b83678ff2815858ad9d11567e082f5ac1814baba4e2bcb4" dependencies = [ "bitflags", "cfg-if", @@ -1049,18 +1048,18 @@ checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" [[package]] name = "openssl-src" -version = "111.8.1+1.1.1f" +version = "111.10.2+1.1.1g" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f04f0299a91de598dde58d2e99101895498dcf3d58896a3297798f28b27c8b72" +checksum = "a287fdb22e32b5b60624d4a5a7a02dbe82777f730ec0dbc42a0554326fef5a70" dependencies = [ "cc", ] [[package]] name = "openssl-sys" -version = "0.9.55" +version = "0.9.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7717097d810a0f2e2323f9e5d11e71608355e24828410b55b9d4f18aa5f9a5d8" +checksum = "a842db4709b604f0fe5d1170ae3565899be2ad3d9cbc72dedc789ac0511f78de" dependencies = [ "autocfg 1.0.0", "cc", @@ -1104,9 +1103,9 @@ dependencies = [ [[package]] name = "paste" -version = "0.1.10" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab4fb1930692d1b6a9cfabdde3d06ea0a7d186518e2f4d67660d8970e2fa647a" +checksum = "45ca20c77d80be666aef2b45486da86238fabe33e38306bd3118fe4af33fa880" dependencies = [ "paste-impl", "proc-macro-hack", @@ -1114,14 +1113,11 @@ dependencies = [ [[package]] name = "paste-impl" -version = "0.1.10" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62486e111e571b1e93b710b61e8f493c0013be39629b714cb166bdb06aa5a8a" +checksum = "d95a7db200b97ef370c8e6de0088252f7e0dfff7d047a28528e47456c0fc98b6" dependencies = [ "proc-macro-hack", - "proc-macro2 1.0.10", - "quote 1.0.3", - "syn 1.0.17", ] [[package]] @@ -1155,9 +1151,9 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.17" +version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" +checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33" [[package]] name = "pmutil" @@ -1165,16 +1161,16 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3894e5d549cccbe44afecf72922f277f603cd4bb0219c8342631ef18fffbe004" dependencies = [ - "proc-macro2 1.0.10", - "quote 1.0.3", - "syn 1.0.17", + "proc-macro2 1.0.19", + "quote 1.0.7", + "syn 1.0.35", ] [[package]] name = "ppv-lite86" -version = "0.2.6" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" +checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea" [[package]] name = "precomputed-hash" @@ -1184,18 +1180,18 @@ checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" [[package]] name = "proc-macro-crate" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e10d4b51f154c8a7fb96fd6dad097cb74b863943ec010ac94b9fd1be8861fe1e" +checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" dependencies = [ "toml", ] [[package]] name = "proc-macro-hack" -version = "0.5.15" +version = "0.5.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d659fe7c6d27f25e9d80a1a094c223f5246f6a6596453e09d7229bf42750b63" +checksum = "7e0456befd48169b9f13ef0f0ad46d492cf9d2dbb918bcf38e01eed4ce3ec5e4" [[package]] name = "proc-macro2" @@ -1208,11 +1204,11 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.10" +version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df246d292ff63439fea9bc8c0a270bed0e390d5ebd4db4ba15aba81111b5abe3" +checksum = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12" dependencies = [ - "unicode-xid 0.2.0", + "unicode-xid 0.2.1", ] [[package]] @@ -1242,11 +1238,11 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.3" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bdc6c187c65bca4260c9011c9e3132efe4909da44726bad24cf7572ae338d7f" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" dependencies = [ - "proc-macro2 1.0.10", + "proc-macro2 1.0.19", ] [[package]] @@ -1407,9 +1403,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.1.56" +version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" +checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" [[package]] name = "redox_users" @@ -1424,9 +1420,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.3.6" +version = "1.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f6946991529684867e47d86474e3a6d0c0ab9b82d5821e314b1ede31fa3a4b3" +checksum = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6" dependencies = [ "aho-corasick", "memchr", @@ -1445,9 +1441,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.17" +version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fe5bd57d1d7414c6b5ed48563a2c855d995ff777729dcd91c369ec7fea395ae" +checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8" [[package]] name = "result-like" @@ -1521,6 +1517,19 @@ dependencies = [ "serde", ] +[[package]] +name = "rustpython-common" +version = "0.0.0" +dependencies = [ + "cfg-if", + "hexf-parse", + "lexical", + "num-bigint", + "num-traits", + "parking_lot", + "rand 0.7.3", +] + [[package]] name = "rustpython-compiler" version = "0.1.2" @@ -1540,11 +1549,11 @@ version = "0.1.2" dependencies = [ "maplit", "once_cell", - "proc-macro2 1.0.10", - "quote 1.0.3", + "proc-macro2 1.0.19", + "quote 1.0.7", "rustpython-bytecode", "rustpython-compiler", - "syn 1.0.17", + "syn 1.0.35", ] [[package]] @@ -1631,6 +1640,7 @@ dependencies = [ "result-like", "rustc_version_runtime", "rustpython-bytecode", + "rustpython-common", "rustpython-compiler", "rustpython-derive", "rustpython-parser", @@ -1676,6 +1686,7 @@ dependencies = [ "futures", "generational-arena", "js-sys", + "parking_lot", "rustpython-compiler", "rustpython-parser", "rustpython-vm", @@ -1688,16 +1699,17 @@ dependencies = [ [[package]] name = "rustyline" -version = "6.1.0" +version = "6.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6155a1169c281a8b75ee943a83eef0e2bb63aff057688c2111be319e51fc9f63" +checksum = "3358c21cbbc1a751892528db4e1de4b7a2b6a73f001e215aaba97d712cfa9777" dependencies = [ "cfg-if", - "dirs 2.0.1", + "dirs-next", "libc", "log", "memchr", "nix", + "scopeguard", "unicode-segmentation", "unicode-width", "utf8parse", @@ -1706,15 +1718,15 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.3" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "535622e6be132bccd223f4bb2b8ac8d53cda3c7a6394944d3b2b33fb974f9d76" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" [[package]] name = "schannel" -version = "0.1.18" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "039c25b130bd8c1321ee2d7de7fde2659fa9c2744e4bb29711cfc852ea53cd19" +checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" dependencies = [ "lazy_static 1.4.0", "winapi", @@ -1743,9 +1755,9 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.106" +version = "1.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36df6ac6412072f67cf767ebbde4133a5b2e88e76dc6187fa7104cd16f783399" +checksum = "5317f7588f0a5078ee60ef675ef96735a1442132dc645eb1d12c018620ed8cd3" dependencies = [ "serde_derive", ] @@ -1764,20 +1776,20 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.106" +version = "1.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e549e3abf4fb8621bd1609f11dfc9f5e50320802273b12f3811a67e6716ea6c" +checksum = "2a0be94b04690fbaed37cddffc5c134bf537c8e3329d53e982fe04c374978f8e" dependencies = [ - "proc-macro2 1.0.10", - "quote 1.0.3", - "syn 1.0.17", + "proc-macro2 1.0.19", + "quote 1.0.7", + "syn 1.0.35", ] [[package]] name = "serde_json" -version = "1.0.51" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da07b57ee2623368351e9a0488bb0b261322a15a6e0ae53e243cbdc0f4208da9" +checksum = "3433e879a558dde8b5e8feb2a04899cf34fdde1fafb894687e52105fc1162ac3" dependencies = [ "itoa", "ryu", @@ -1798,9 +1810,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27044adfd2e1f077f649f59deb9490d3941d674002f7d062870a60ebe9bd47a0" +checksum = "a256f46ea78a0c0d9ff00077504903ac881a1dafdc20da66545699e7776b3e69" dependencies = [ "block-buffer", "digest", @@ -1835,9 +1847,9 @@ checksum = "aa0eec6425219a55511a35afac416a2eecc62f5fa1bec14f9b97de0caa7daebe" [[package]] name = "smallvec" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4" +checksum = "3757cb9d89161a2f24e1cf78efa0c1fcff485d18e3f55e0aa3480824ddaa0f3f" [[package]] name = "socket2" @@ -1889,8 +1901,8 @@ checksum = "f0f45ed1b65bf9a4bf2f7b7dc59212d1926e9eaf00fa998988e420fd124467c6" dependencies = [ "phf_generator", "phf_shared", - "proc-macro2 1.0.10", - "quote 1.0.3", + "proc-macro2 1.0.19", + "quote 1.0.7", "string_cache_shared", ] @@ -1931,13 +1943,13 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.17" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0df0eb663f387145cab623dea85b09c2c5b4b0aef44e945d928e682fce71bb03" +checksum = "fb7f4c519df8c117855e19dd8cc851e89eb746fe7a73f0157e0d95fdec5369b0" dependencies = [ - "proc-macro2 1.0.10", - "quote 1.0.3", - "unicode-xid 0.2.0", + "proc-macro2 1.0.19", + "quote 1.0.7", + "unicode-xid 0.2.1", ] [[package]] @@ -1947,7 +1959,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "edd106a334b7657c10b7c540a0106114feadeb4dc314513e97df481d5d966f42" dependencies = [ "byteorder 1.3.4", - "dirs 1.0.5", + "dirs", "winapi", ] @@ -1999,6 +2011,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "tinyvec" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53953d2d3a5ad81d9f844a32f14ebb121f50b650cd59d0ee2a07cf13c617efed" + [[package]] name = "toml" version = "0.5.6" @@ -2010,9 +2028,9 @@ dependencies = [ [[package]] name = "typenum" -version = "1.11.2" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" +checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" [[package]] name = "uname" @@ -2147,11 +2165,11 @@ checksum = "623f59e6af2a98bdafeb93fa277ac8e1e40440973001ca15cf4ae1541cd16d56" [[package]] name = "unicode-normalization" -version = "0.1.12" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5479532badd04e128284890390c1e876ef7a993d0570b3597ae43dfa1d59afa4" +checksum = "6fb19cf769fa8c6a80a162df694621ebeb4dafb606470b2b2fce0be40a98a977" dependencies = [ - "smallvec", + "tinyvec", ] [[package]] @@ -2162,9 +2180,9 @@ checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0" [[package]] name = "unicode-width" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" +checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" [[package]] name = "unicode-xid" @@ -2174,9 +2192,9 @@ checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" [[package]] name = "unicode-xid" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" [[package]] name = "unicode_names2" @@ -2202,15 +2220,15 @@ dependencies = [ [[package]] name = "vcpkg" -version = "0.2.8" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fc439f2794e98976c88a2a2dafce96b930fe8010b0a256b3c2199a773933168" +checksum = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c" [[package]] name = "vec_map" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" [[package]] name = "void" @@ -2232,9 +2250,9 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasm-bindgen" -version = "0.2.60" +version = "0.2.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cc57ce05287f8376e998cbddfb4c8cb43b84a7ec55cf4551d7c00eef317a47f" +checksum = "f3edbcc9536ab7eababcc6d2374a0b7bfe13a2b6d562c5e07f370456b1a8f33d" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -2242,16 +2260,16 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.60" +version = "0.2.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d967d37bf6c16cca2973ca3af071d0a2523392e4a594548155d89a678f4237cd" +checksum = "89ed2fb8c84bfad20ea66b26a3743f3e7ba8735a69fe7d95118c33ec8fc1244d" dependencies = [ "bumpalo", "lazy_static 1.4.0", "log", - "proc-macro2 1.0.10", - "quote 1.0.3", - "syn 1.0.17", + "proc-macro2 1.0.19", + "quote 1.0.7", + "syn 1.0.35", "wasm-bindgen-shared", ] @@ -2270,38 +2288,38 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.60" +version = "0.2.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bd151b63e1ea881bb742cd20e1d6127cef28399558f3b5d415289bc41eee3a4" +checksum = "eb071268b031a64d92fc6cf691715ca5a40950694d8f683c5bb43db7c730929e" dependencies = [ - "quote 1.0.3", + "quote 1.0.7", "wasm-bindgen-macro-support", ] [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.60" +version = "0.2.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d68a5b36eef1be7868f668632863292e37739656a80fc4b9acec7b0bd35a4931" +checksum = "cf592c807080719d1ff2f245a687cbadb3ed28b2077ed7084b47aba8b691f2c6" dependencies = [ - "proc-macro2 1.0.10", - "quote 1.0.3", - "syn 1.0.17", + "proc-macro2 1.0.19", + "quote 1.0.7", + "syn 1.0.35", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.60" +version = "0.2.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "daf76fe7d25ac79748a37538b7daeed1c7a6867c92d3245c12c6222e4a20d639" +checksum = "72b6c0220ded549d63860c78c38f3bcc558d1ca3f4efa74942c536ddbbb55e87" [[package]] name = "web-sys" -version = "0.3.37" +version = "0.3.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d6f51648d8c56c366144378a33290049eafdd784071077f6fe37dae64c1c4cb" +checksum = "8be2398f326b7ba09815d0b403095f34dd708579220d099caae89be0b32137b2" dependencies = [ "js-sys", "wasm-bindgen", @@ -2309,9 +2327,9 @@ dependencies = [ [[package]] name = "winapi" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ "winapi-i686-pc-windows-gnu", "winapi-x86_64-pc-windows-gnu", @@ -2325,9 +2343,9 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa515c5163a99cc82bab70fd3bfdd36d827be85de63737b40fcef2ce084a436e" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ "winapi", ] diff --git a/Cargo.toml b/Cargo.toml index 78a179ade..8491aea3f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,15 +8,17 @@ repository = "https://github.com/RustPython/RustPython" license = "MIT" [workspace] -members = [".", "derive", "vm", "wasm/lib", "parser", "compiler", "bytecode", "examples/freeze", "vm/pylib-crate"] +members = [".", "derive", "vm", "wasm/lib", "parser", "compiler", "bytecode", "examples/freeze", "vm/pylib-crate", "common"] [[bench]] name = "bench" path = "./benchmarks/bench.rs" [features] +default = ["threading"] flame-it = ["rustpython-vm/flame-it", "flame", "flamescope"] freeze-stdlib = ["rustpython-vm/freeze-stdlib"] +threading = ["rustpython-vm/threading"] ssl = ["rustpython-vm/ssl"] @@ -24,9 +26,9 @@ ssl = ["rustpython-vm/ssl"] log = "0.4" env_logger = "0.7" clap = "2.33" -rustpython-compiler = {path = "compiler", version = "0.1.1"} -rustpython-parser = {path = "parser", version = "0.1.1"} -rustpython-vm = {path = "vm", version = "0.1.1"} +rustpython-compiler = { path = "compiler", version = "0.1.1" } +rustpython-parser = { path = "parser", version = "0.1.1" } +rustpython-vm = { path = "vm", version = "0.1.1", default-features = false, features = ["compile-parse"] } dirs = { package = "dirs-next", version = "1.0" } num-traits = "0.2.8" cfg-if = "0.1" diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py index f8ff5f4f2..a4e6a7176 100644 --- a/Lib/importlib/_bootstrap_external.py +++ b/Lib/importlib/_bootstrap_external.py @@ -1587,7 +1587,10 @@ def _setup(_bootstrap_module): setattr(self_module, '_pathseps_with_colon', {f':{s}' for s in path_separators}) # Directly load the _thread module (needed during bootstrap). - thread_module = _bootstrap._builtin_from_name('_thread') + try: + thread_module = _bootstrap._builtin_from_name('_thread') + except ImportError: + thread_module = None setattr(self_module, '_thread', thread_module) # Directly load the _weakref module (needed during bootstrap). diff --git a/common/Cargo.toml b/common/Cargo.toml new file mode 100644 index 000000000..b8603397a --- /dev/null +++ b/common/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "rustpython-common" +version = "0.0.0" +authors = ["RustPython Team"] +edition = "2018" + +[features] +threading = ["parking_lot"] + +[dependencies] +parking_lot = { version = "0.11.0", optional = true } +num-traits = "0.2" +num-bigint = "0.3" +lexical = "4" +hexf-parse = "0.1.0" +cfg-if = "0.1" + +[dev-dependencies] +rand = "0.7.3" diff --git a/common/src/cell.rs b/common/src/cell.rs new file mode 100644 index 000000000..4c48326eb --- /dev/null +++ b/common/src/cell.rs @@ -0,0 +1,132 @@ +#[cfg(feature = "threading")] +use parking_lot::{Mutex, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard}; +#[cfg(not(feature = "threading"))] +use std::cell::{Ref, RefCell, RefMut}; +use std::ops::{Deref, DerefMut}; + +cfg_if::cfg_if! { + if #[cfg(feature = "threading")] { + type MutexInner = Mutex; + type MutexGuardInner<'a, T> = MutexGuard<'a, T>; + const fn new_mutex(value: T) -> MutexInner { + parking_lot::const_mutex(value) + } + fn lock_mutex(m: &MutexInner) -> MutexGuardInner { + m.lock() + } + } else { + type MutexInner = RefCell; + type MutexGuardInner<'a, T> = RefMut<'a, T>; + const fn new_mutex(value: T) -> MutexInner { + RefCell::new(value) + } + fn lock_mutex(m: &MutexInner) -> MutexGuardInner { + m.borrow_mut() + } + } +} + +#[derive(Debug, Default)] +#[repr(transparent)] +pub struct PyMutex(MutexInner); + +impl PyMutex { + pub const fn new(value: T) -> Self { + Self(new_mutex(value)) + } +} + +impl PyMutex { + pub fn lock(&self) -> PyMutexGuard { + PyMutexGuard(lock_mutex(&self.0)) + } +} + +#[derive(Debug)] +#[repr(transparent)] +pub struct PyMutexGuard<'a, T: ?Sized>(MutexGuardInner<'a, T>); +impl Deref for PyMutexGuard<'_, T> { + type Target = T; + fn deref(&self) -> &T { + self.0.deref() + } +} +impl DerefMut for PyMutexGuard<'_, T> { + fn deref_mut(&mut self) -> &mut T { + self.0.deref_mut() + } +} + +cfg_if::cfg_if! { + if #[cfg(feature = "threading")] { + type RwLockInner = RwLock; + type RwLockReadInner<'a, T> = RwLockReadGuard<'a, T>; + type RwLockWriteInner<'a, T> = RwLockWriteGuard<'a, T>; + const fn new_rwlock(value: T) -> RwLockInner { + parking_lot::const_rwlock(value) + } + fn read_rwlock(m: &RwLockInner) -> RwLockReadInner { + m.read() + } + fn write_rwlock(m: &RwLockInner) -> RwLockWriteInner { + m.write() + } + } else { + type RwLockInner = RefCell; + type RwLockReadInner<'a, T> = Ref<'a, T>; + type RwLockWriteInner<'a, T> = RefMut<'a, T>; + const fn new_rwlock(value: T) -> RwLockInner { + RefCell::new(value) + } + fn read_rwlock(m: &RwLockInner) -> RwLockReadInner { + m.borrow() + } + fn write_rwlock(m: &RwLockInner) -> RwLockWriteInner { + m.borrow_mut() + } + } +} + +#[derive(Debug, Default)] +#[repr(transparent)] +pub struct PyRwLock(RwLockInner); + +impl PyRwLock { + pub const fn new(value: T) -> Self { + Self(new_rwlock(value)) + } +} + +impl PyRwLock { + pub fn read(&self) -> PyRwLockReadGuard { + PyRwLockReadGuard(read_rwlock(&self.0)) + } + pub fn write(&self) -> PyRwLockWriteGuard { + PyRwLockWriteGuard(write_rwlock(&self.0)) + } +} + +#[derive(Debug)] +#[repr(transparent)] +pub struct PyRwLockReadGuard<'a, T: ?Sized>(RwLockReadInner<'a, T>); +impl Deref for PyRwLockReadGuard<'_, T> { + type Target = T; + fn deref(&self) -> &T { + self.0.deref() + } +} + +#[derive(Debug)] +#[repr(transparent)] +pub struct PyRwLockWriteGuard<'a, T: ?Sized>(RwLockWriteInner<'a, T>); +impl Deref for PyRwLockWriteGuard<'_, T> { + type Target = T; + fn deref(&self) -> &T { + self.0.deref() + } +} +impl DerefMut for PyRwLockWriteGuard<'_, T> { + fn deref_mut(&mut self) -> &mut T { + self.0.deref_mut() + } +} diff --git a/common/src/float_ops.rs b/common/src/float_ops.rs new file mode 100644 index 000000000..34f2c4e6a --- /dev/null +++ b/common/src/float_ops.rs @@ -0,0 +1,194 @@ +use num_bigint::{BigInt, ToBigInt}; +use num_traits::{Float, Signed, ToPrimitive, Zero}; + +pub fn ufrexp(value: f64) -> (f64, i32) { + if 0.0 == value { + (0.0, 0i32) + } else { + let bits = value.to_bits(); + let exponent: i32 = ((bits >> 52) & 0x7ff) as i32 - 1022; + let mantissa_bits = bits & (0x000f_ffff_ffff_ffff) | (1022 << 52); + (f64::from_bits(mantissa_bits), exponent) + } +} + +pub fn eq_int(value: f64, other: &BigInt) -> bool { + if let (Some(self_int), Some(other_float)) = (value.to_bigint(), other.to_f64()) { + value == other_float && self_int == *other + } else { + false + } +} + +pub fn lt_int(value: f64, other_int: &BigInt) -> bool { + match (value.to_bigint(), other_int.to_f64()) { + (Some(self_int), Some(other_float)) => value < other_float || self_int < *other_int, + // finite float, other_int too big for float, + // the result depends only on other_int’s sign + (Some(_), None) => other_int.is_positive(), + // infinite float must be bigger or lower than any int, depending on its sign + _ if value.is_infinite() => value.is_sign_negative(), + // NaN, always false + _ => false, + } +} + +pub fn gt_int(value: f64, other_int: &BigInt) -> bool { + match (value.to_bigint(), other_int.to_f64()) { + (Some(self_int), Some(other_float)) => value > other_float || self_int > *other_int, + // finite float, other_int too big for float, + // the result depends only on other_int’s sign + (Some(_), None) => other_int.is_negative(), + // infinite float must be bigger or lower than any int, depending on its sign + _ if value.is_infinite() => value.is_sign_positive(), + // NaN, always false + _ => false, + } +} + +pub fn parse_str(literal: &str) -> Option { + if literal.starts_with('_') || literal.ends_with('_') { + return None; + } + + let mut buf = String::with_capacity(literal.len()); + let mut last_tok: Option = None; + for c in literal.chars() { + if !(c.is_ascii_alphanumeric() || c == '_' || c == '+' || c == '-' || c == '.') { + return None; + } + + if !c.is_ascii_alphanumeric() { + if let Some(l) = last_tok { + if !l.is_ascii_alphanumeric() && !(c == '.' && (l == '-' || l == '+')) { + return None; + } + } + } + + if c != '_' { + buf.push(c); + } + last_tok = Some(c); + } + + if let Ok(f) = lexical::parse(buf.as_str()) { + Some(f) + } else { + None + } +} + +pub fn is_integer(v: f64) -> bool { + (v - v.round()).abs() < std::f64::EPSILON +} + +pub fn to_string(value: f64) -> String { + let lit = format!("{:e}", value); + if let Some(position) = lit.find('e') { + let significand = &lit[..position]; + let exponent = &lit[position + 1..]; + let exponent = exponent.parse::().unwrap(); + if exponent < 16 && exponent > -5 { + if is_integer(value) { + format!("{:.1?}", value) + } else { + value.to_string() + } + } else { + format!("{}e{:+#03}", significand, exponent) + } + } else { + value.to_string() + } +} + +pub fn from_hex(s: &str) -> Option { + if let Ok(f) = hexf_parse::parse_hexf64(s, false) { + return Some(f); + } + match s.to_ascii_lowercase().as_str() { + "nan" => Some(f64::NAN), + "+nan" => Some(f64::NAN), + "-nan" => Some(f64::NAN), + "inf" => Some(f64::INFINITY), + "infinity" => Some(f64::INFINITY), + "+inf" => Some(f64::INFINITY), + "+infinity" => Some(f64::INFINITY), + "-inf" => Some(f64::NEG_INFINITY), + "-infinity" => Some(f64::NEG_INFINITY), + value => { + let mut hex = String::with_capacity(value.len()); + let has_0x = value.contains("0x"); + let has_p = value.contains('p'); + let has_dot = value.contains('.'); + let mut start = 0; + + if !has_0x && value.starts_with('-') { + hex.push_str("-0x"); + start += 1; + } else if !has_0x { + hex.push_str("0x"); + if value.starts_with('+') { + start += 1; + } + } + + for (index, ch) in value.chars().enumerate() { + if ch == 'p' && has_dot { + hex.push_str("p"); + } else if ch == 'p' && !has_dot { + hex.push_str(".p"); + } else if index >= start { + hex.push(ch); + } + } + + if !has_p && has_dot { + hex.push_str("p0"); + } else if !has_p && !has_dot { + hex.push_str(".p0") + } + + hexf_parse::parse_hexf64(hex.as_str(), false).ok() + } + } +} + +pub fn to_hex(value: f64) -> String { + let (mantissa, exponent, sign) = value.integer_decode(); + let sign_fmt = if sign < 0 { "-" } else { "" }; + match value { + value if value.is_zero() => format!("{}0x0.0p+0", sign_fmt), + value if value.is_infinite() => format!("{}inf", sign_fmt), + value if value.is_nan() => "nan".to_owned(), + _ => { + const BITS: i16 = 52; + const FRACT_MASK: u64 = 0xf_ffff_ffff_ffff; + format!( + "{}0x{:x}.{:013x}p{:+}", + sign_fmt, + mantissa >> BITS, + mantissa & FRACT_MASK, + exponent + BITS + ) + } + } +} + +#[test] +fn test_to_hex() { + use rand::Rng; + for _ in 0..20000 { + let bytes = rand::thread_rng().gen::<[u64; 1]>(); + let f = f64::from_bits(bytes[0]); + if !f.is_finite() { + continue; + } + let hex = to_hex(f); + // println!("{} -> {}", f, hex); + let roundtrip = hexf_parse::parse_hexf64(&hex, false).unwrap(); + // println!(" -> {}", roundtrip); + assert!(f == roundtrip, "{} {} {}", f, hex, roundtrip); + } +} diff --git a/vm/src/pyhash.rs b/common/src/hash.rs similarity index 59% rename from vm/src/pyhash.rs rename to common/src/hash.rs index 598bde2a0..12b858e5b 100644 --- a/vm/src/pyhash.rs +++ b/common/src/hash.rs @@ -1,12 +1,8 @@ use num_bigint::BigInt; use num_traits::ToPrimitive; +use std::collections::hash_map::DefaultHasher; use std::hash::{Hash, Hasher}; -use crate::obj::objfloat; -use crate::pyobject::PyObjectRef; -use crate::pyobject::PyResult; -use crate::vm::VirtualMachine; - pub type PyHash = i64; pub type PyUHash = u64; @@ -18,6 +14,12 @@ pub const MODULUS: PyUHash = (1 << BITS) - 1; pub const INF: PyHash = 314_159; pub const NAN: PyHash = 0; pub const IMAG: PyHash = MULTIPLIER; +pub const ALGO: &str = "siphasher13"; +pub const HASH_BITS: usize = std::mem::size_of::() * 8; +// internally DefaultHasher uses 2 u64s as the seed, but +// that's not guaranteed to be consistent across Rust releases +// TODO: use something like the siphasher crate as our hash algorithm +pub const SEED_BITS: usize = std::mem::size_of::() * 2 * 8; // pub const CUTOFF: usize = 7; @@ -35,7 +37,7 @@ pub fn hash_float(value: f64) -> PyHash { }; } - let frexp = objfloat::ufrexp(value); + let frexp = super::float_ops::ufrexp(value); // process 28 bits at a time; this should work well both for binary // and hexadecimal floating point. @@ -67,30 +69,32 @@ pub fn hash_float(value: f64) -> PyHash { } pub fn hash_value(data: &T) -> PyHash { - let mut hasher = std::collections::hash_map::DefaultHasher::new(); + let mut hasher = DefaultHasher::new(); data.hash(&mut hasher); hasher.finish() as PyHash } -pub fn hash_iter<'a, I: std::iter::Iterator>( - iter: I, - vm: &VirtualMachine, -) -> PyResult { - let mut hasher = std::collections::hash_map::DefaultHasher::new(); +pub fn hash_iter<'a, T: 'a, I, F, E>(iter: I, hashf: F) -> Result +where + I: IntoIterator, + F: Fn(&'a T) -> Result, +{ + let mut hasher = DefaultHasher::new(); for element in iter { - let item_hash = vm._hash(&element)?; + let item_hash = hashf(element)?; item_hash.hash(&mut hasher); } Ok(hasher.finish() as PyHash) } -pub fn hash_iter_unordered<'a, I: std::iter::Iterator>( - iter: I, - vm: &VirtualMachine, -) -> PyResult { +pub fn hash_iter_unordered<'a, T: 'a, I, F, E>(iter: I, hashf: F) -> Result +where + I: IntoIterator, + F: Fn(&'a T) -> Result, +{ let mut hash: PyHash = 0; for element in iter { - let item_hash = vm._hash(element)?; + let item_hash = hashf(element)?; // xor is commutative and hash should be independent of order hash ^= item_hash; } @@ -103,31 +107,3 @@ pub fn hash_bigint(value: &BigInt) -> PyHash { None => (value % MODULUS).to_i64().unwrap(), } } - -#[pystruct_sequence(module = "sys", name = "hash_info")] -#[derive(Debug)] -pub(crate) struct PyHashInfo { - width: usize, - modulus: PyUHash, - inf: PyHash, - nan: PyHash, - imag: PyHash, - algorithm: &'static str, - hash_bits: usize, - seed_bits: usize, -} -impl PyHashInfo { - pub const INFO: Self = PyHashInfo { - width: BITS, - modulus: MODULUS, - inf: INF, - nan: NAN, - imag: IMAG, - algorithm: "siphash13", - hash_bits: std::mem::size_of::() * 8, - // internally hash_map::DefaultHasher uses 2 u64s as the seed, but - // that's not guaranteed to be consistent across Rust releases - // TODO: use something like the siphasher crate as our hash algorithm - seed_bits: std::mem::size_of::() * 2 * 8, - }; -} diff --git a/common/src/lib.rs b/common/src/lib.rs new file mode 100644 index 000000000..f6d704744 --- /dev/null +++ b/common/src/lib.rs @@ -0,0 +1,6 @@ +//! A crate to hold types and functions common to all rustpython components. + +pub mod cell; +pub mod float_ops; +pub mod hash; +pub mod rc; diff --git a/common/src/rc.rs b/common/src/rc.rs new file mode 100644 index 000000000..8021b6112 --- /dev/null +++ b/common/src/rc.rs @@ -0,0 +1,14 @@ +#[cfg(not(feature = "threading"))] +use std::rc::{Rc, Weak}; +#[cfg(feature = "threading")] +use std::sync::{Arc, Weak}; + +// type aliases instead of newtypes because you can't do `fn method(self: PyRc)` with a +// newtype; requires the arbitrary_self_types unstable feature + +#[cfg(feature = "threading")] +pub type PyRc = Arc; +#[cfg(not(feature = "threading"))] +pub type PyRc = Rc; + +pub type PyWeak = Weak; diff --git a/parser/Cargo.toml b/parser/Cargo.toml index 8d3aa4b09..da88a7586 100644 --- a/parser/Cargo.toml +++ b/parser/Cargo.toml @@ -12,8 +12,8 @@ edition = "2018" lalrpop="0.17" [dependencies] -lalrpop-util="0.17" -log="0.4.1" +lalrpop-util = "0.17" +log = "0.4.1" num-bigint = "0.3" num-traits = "0.2" unic-emoji-char = "0.9" diff --git a/vm/Cargo.toml b/vm/Cargo.toml index 66c08aa9b..9279eadae 100644 --- a/vm/Cargo.toml +++ b/vm/Cargo.toml @@ -9,10 +9,12 @@ edition = "2018" include = ["src/**/*.rs", "Cargo.toml", "build.rs", "Lib/**/*.py"] [features] -default = ["rustpython-parser", "rustpython-compiler"] +default = ["compile-parse", "threading"] vm-tracing-logging = [] flame-it = ["flame", "flamer"] freeze-stdlib = ["rustpython-pylib"] +threading = ["rustpython-common/threading"] +compile-parse = ["rustpython-parser", "rustpython-compiler"] ssl = ["openssl", "openssl-sys", "openssl-probe"] @@ -91,6 +93,7 @@ unic-ucd-ident = "0.9" flame = { version = "0.2", optional = true } flamer = { version = "0.3", optional = true } +rustpython-common = { path = "../common" } [target.'cfg(unix)'.dependencies] exitcode = "1.1.2" diff --git a/vm/pylib-crate/Cargo.toml b/vm/pylib-crate/Cargo.toml index b49379f27..21e41087e 100644 --- a/vm/pylib-crate/Cargo.toml +++ b/vm/pylib-crate/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rustpython-pylib" version = "0.1.0" -authors = ["Noah <33094578+coolreader18@users.noreply.github.com>"] +authors = ["RustPython Team"] edition = "2018" [dependencies] diff --git a/vm/src/builtins.rs b/vm/src/builtins.rs index c6a073ebe..896fa8b9d 100644 --- a/vm/src/builtins.rs +++ b/vm/src/builtins.rs @@ -27,7 +27,6 @@ mod decl { use crate::obj::objsequence; use crate::obj::objstr::{PyString, PyStringRef}; use crate::obj::objtype::{self, PyClassRef}; - use crate::pyhash; use crate::pyobject::{ Either, IdProtocol, ItemProtocol, PyCallable, PyIterable, PyObjectRef, PyResult, PyValue, TryFromObject, TypeProtocol, @@ -37,6 +36,7 @@ mod decl { #[cfg(feature = "rustpython-parser")] use crate::stdlib::ast; use crate::vm::VirtualMachine; + use rustpython_common::hash::PyHash; #[pyfunction] fn abs(x: PyObjectRef, vm: &VirtualMachine) -> PyResult { @@ -329,7 +329,7 @@ mod decl { } #[pyfunction] - fn hash(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult { + fn hash(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult { vm._hash(&obj) } diff --git a/vm/src/dictdatatype.rs b/vm/src/dictdatatype.rs index 7ff9cb7db..6116af321 100644 --- a/vm/src/dictdatatype.rs +++ b/vm/src/dictdatatype.rs @@ -1,9 +1,9 @@ +use crate::common::cell::{PyRwLock, PyRwLockReadGuard, PyRwLockWriteGuard}; use crate::obj::objstr::{PyString, PyStringRef}; -use crate::pyhash; use crate::pyobject::{IdProtocol, IntoPyObject, PyObjectRef, PyResult}; use crate::vm::VirtualMachine; use num_bigint::ToBigInt; -use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard}; +use rustpython_common::hash; /// Ordered dictionary implementation. /// Inspired by: https://morepypy.blogspot.com/2015/01/faster-more-memory-efficient-and-more.html /// And: https://www.youtube.com/watch?v=p33CVV29OG8 @@ -13,14 +13,14 @@ use std::hash::{Hash, Hasher}; use std::mem::size_of; /// hash value of an object returned by __hash__ -type HashValue = pyhash::PyHash; +type HashValue = hash::PyHash; /// index calculated by resolving collision -type HashIndex = pyhash::PyHash; +type HashIndex = hash::PyHash; /// entry index mapped in indices type EntryIndex = usize; pub struct Dict { - inner: RwLock>, + inner: PyRwLock>, } struct InnerDict { @@ -42,7 +42,7 @@ impl Clone for InnerDict { impl Clone for Dict { fn clone(&self) -> Self { Dict { - inner: RwLock::new(self.inner.read().clone()), + inner: PyRwLock::new(self.inner.read().clone()), } } } @@ -50,7 +50,7 @@ impl Clone for Dict { impl Default for Dict { fn default() -> Self { Dict { - inner: RwLock::new(InnerDict { + inner: PyRwLock::new(InnerDict { size: 0, indices: HashMap::new(), entries: Vec::new(), @@ -82,11 +82,11 @@ pub struct DictSize { } impl Dict { - fn borrow_value(&self) -> RwLockReadGuard<'_, InnerDict> { + fn borrow_value(&self) -> PyRwLockReadGuard<'_, InnerDict> { self.inner.read() } - fn borrow_value_mut(&self) -> RwLockWriteGuard<'_, InnerDict> { + fn borrow_value_mut(&self) -> PyRwLockWriteGuard<'_, InnerDict> { self.inner.write() } @@ -463,8 +463,8 @@ impl DictKey for &PyStringRef { impl DictKey for &str { fn do_hash(self, _vm: &VirtualMachine) -> PyResult { // follow a similar route as the hashing of PyStringRef - let raw_hash = pyhash::hash_value(&self.to_owned()).to_bigint().unwrap(); - let raw_hash = pyhash::hash_bigint(&raw_hash); + let raw_hash = hash::hash_value(&self.to_owned()).to_bigint().unwrap(); + let raw_hash = hash::hash_bigint(&raw_hash); let mut hasher = DefaultHasher::new(); raw_hash.hash(&mut hasher); Ok(hasher.finish() as HashValue) diff --git a/vm/src/exceptions.rs b/vm/src/exceptions.rs index 5f4e6b4a9..7f5d4d242 100644 --- a/vm/src/exceptions.rs +++ b/vm/src/exceptions.rs @@ -1,3 +1,4 @@ +use crate::common::cell::PyRwLock; use crate::function::PyFuncArgs; use crate::obj::objnone::PyNone; use crate::obj::objstr::{PyString, PyStringRef}; @@ -14,7 +15,6 @@ use crate::types::create_type; use crate::VirtualMachine; use itertools::Itertools; -use parking_lot::RwLock; use std::fmt; use std::fs::File; use std::io::{self, BufRead, BufReader, Write}; @@ -23,11 +23,11 @@ use crossbeam_utils::atomic::AtomicCell; #[pyclass] pub struct PyBaseException { - traceback: RwLock>, - cause: RwLock>, - context: RwLock>, + traceback: PyRwLock>, + cause: PyRwLock>, + context: PyRwLock>, suppress_context: AtomicCell, - args: RwLock, + args: PyRwLock, } impl fmt::Debug for PyBaseException { @@ -51,11 +51,11 @@ impl PyValue for PyBaseException { impl PyBaseException { pub(crate) fn new(args: Vec, vm: &VirtualMachine) -> PyBaseException { PyBaseException { - traceback: RwLock::new(None), - cause: RwLock::new(None), - context: RwLock::new(None), + traceback: PyRwLock::new(None), + cause: PyRwLock::new(None), + context: PyRwLock::new(None), suppress_context: AtomicCell::new(false), - args: RwLock::new(PyTuple::from(args).into_ref(vm)), + args: PyRwLock::new(PyTuple::from(args).into_ref(vm)), } } diff --git a/vm/src/frame.rs b/vm/src/frame.rs index 35fef5315..02f036b62 100644 --- a/vm/src/frame.rs +++ b/vm/src/frame.rs @@ -3,10 +3,10 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use indexmap::IndexMap; use itertools::Itertools; -use parking_lot::Mutex; use crate::builtins::builtin_isinstance; use crate::bytecode; +use crate::common::cell::PyMutex; use crate::exceptions::{self, ExceptionCtor, PyBaseExceptionRef}; use crate::function::PyFuncArgs; use crate::obj::objasyncgenerator::PyAsyncGenWrappedValue; @@ -92,7 +92,7 @@ pub struct Frame { pub scope: Scope, /// index of last instruction ran pub lasti: AtomicUsize, - state: Mutex, + state: PyMutex, } impl PyValue for Frame { @@ -163,7 +163,7 @@ impl Frame { code, scope, lasti: AtomicUsize::new(0), - state: Mutex::new(FrameState { + state: PyMutex::new(FrameState { stack: Vec::new(), blocks: Vec::new(), }), diff --git a/vm/src/lib.rs b/vm/src/lib.rs index e775ce25d..80724fd85 100644 --- a/vm/src/lib.rs +++ b/vm/src/lib.rs @@ -68,7 +68,6 @@ pub mod function; pub mod import; pub mod obj; pub mod py_serde; -mod pyhash; pub mod pyobject; pub mod readline; pub mod scope; @@ -84,6 +83,7 @@ mod vm; // pub use self::pyobject::Executor; pub use self::vm::{InitParameter, PySettings, VirtualMachine}; pub use rustpython_bytecode::*; +pub use rustpython_common as common; #[doc(hidden)] pub mod __exports { diff --git a/vm/src/obj/objbytearray.rs b/vm/src/obj/objbytearray.rs index da7a47551..1be33d24f 100644 --- a/vm/src/obj/objbytearray.rs +++ b/vm/src/obj/objbytearray.rs @@ -1,8 +1,8 @@ //! Implementation of the python bytearray object. +use crate::common::cell::{PyRwLock, PyRwLockReadGuard, PyRwLockWriteGuard}; use bstr::ByteSlice; use crossbeam_utils::atomic::AtomicCell; use num_traits::cast::ToPrimitive; -use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard}; use std::mem::size_of; use super::objbyteinner::{ @@ -36,7 +36,7 @@ use crate::vm::VirtualMachine; #[pyclass(name = "bytearray")] #[derive(Debug)] pub struct PyByteArray { - inner: RwLock, + inner: PyRwLock, } pub type PyByteArrayRef = PyRef; @@ -44,21 +44,21 @@ pub type PyByteArrayRef = PyRef; impl PyByteArray { pub fn new(data: Vec) -> Self { PyByteArray { - inner: RwLock::new(PyByteInner { elements: data }), + inner: PyRwLock::new(PyByteInner { elements: data }), } } fn from_inner(inner: PyByteInner) -> Self { PyByteArray { - inner: RwLock::new(inner), + inner: PyRwLock::new(inner), } } - pub fn borrow_value(&self) -> RwLockReadGuard<'_, PyByteInner> { + pub fn borrow_value(&self) -> PyRwLockReadGuard<'_, PyByteInner> { self.inner.read() } - pub fn borrow_value_mut(&self) -> RwLockWriteGuard<'_, PyByteInner> { + pub fn borrow_value_mut(&self) -> PyRwLockWriteGuard<'_, PyByteInner> { self.inner.write() } } @@ -98,8 +98,8 @@ impl PyByteArray { } #[pymethod(name = "__repr__")] - fn repr(&self) -> PyResult { - Ok(format!("bytearray(b'{}')", self.borrow_value().repr()?)) + fn repr(&self) -> String { + format!("bytearray(b'{}')", self.borrow_value().repr()) } #[pymethod(name = "__len__")] diff --git a/vm/src/obj/objbyteinner.rs b/vm/src/obj/objbyteinner.rs index b4ef38139..4e5428d29 100644 --- a/vm/src/obj/objbyteinner.rs +++ b/vm/src/obj/objbyteinner.rs @@ -14,11 +14,11 @@ use super::objslice::PySliceRef; use super::objstr::{self, PyString, PyStringRef}; use super::pystr::{self, PyCommonString, PyCommonStringContainer, PyCommonStringWrapper}; use crate::function::{OptionalArg, OptionalOption}; -use crate::pyhash; use crate::pyobject::{ Either, PyComparisonValue, PyIterable, PyObjectRef, PyResult, TryFromObject, TypeProtocol, }; use crate::vm::VirtualMachine; +use rustpython_common::hash; #[derive(Debug, Default, Clone)] pub struct PyByteInner { @@ -253,7 +253,7 @@ impl ByteInnerSplitlinesOptions { #[allow(clippy::len_without_is_empty)] impl PyByteInner { - pub fn repr(&self) -> PyResult { + pub fn repr(&self) -> String { let mut res = String::with_capacity(self.elements.len()); for i in self.elements.iter() { match i { @@ -266,7 +266,7 @@ impl PyByteInner { _ => res.push_str(&format!("\\x{:x}", i)), } } - Ok(res) + res } pub fn len(&self) -> usize { @@ -303,8 +303,8 @@ impl PyByteInner { self.cmp(other, |a, b| a < b, vm) } - pub fn hash(&self) -> pyhash::PyHash { - pyhash::hash_value(&self.elements) + pub fn hash(&self) -> hash::PyHash { + hash::hash_value(&self.elements) } pub fn add(&self, other: PyByteInner) -> Vec { diff --git a/vm/src/obj/objbytes.rs b/vm/src/obj/objbytes.rs index ffeea4c05..529ae1674 100644 --- a/vm/src/obj/objbytes.rs +++ b/vm/src/obj/objbytes.rs @@ -14,7 +14,6 @@ use super::objstr::{PyString, PyStringRef}; use super::objtype::PyClassRef; use super::pystr::{self, PyCommonString}; use crate::function::{OptionalArg, OptionalOption}; -use crate::pyhash; use crate::pyobject::{ Either, IntoPyObject, PyArithmaticValue::{self, *}, @@ -22,6 +21,7 @@ use crate::pyobject::{ TryFromObject, TypeProtocol, }; use crate::vm::VirtualMachine; +use rustpython_common::hash::PyHash; /// "bytes(iterable_of_ints) -> bytes\n\ /// bytes(string, encoding[, errors]) -> bytes\n\ @@ -102,8 +102,8 @@ impl PyBytes { } #[pymethod(name = "__repr__")] - fn repr(&self, vm: &VirtualMachine) -> PyResult { - Ok(vm.new_str(format!("b'{}'", self.inner.repr()?))) + pub(crate) fn repr(&self) -> String { + format!("b'{}'", self.inner.repr()) } #[pymethod(name = "__len__")] @@ -133,7 +133,7 @@ impl PyBytes { } #[pymethod(name = "__hash__")] - fn hash(&self) -> pyhash::PyHash { + fn hash(&self) -> PyHash { self.inner.hash() } diff --git a/vm/src/obj/objcomplex.rs b/vm/src/obj/objcomplex.rs index 4b7f04de0..367db543b 100644 --- a/vm/src/obj/objcomplex.rs +++ b/vm/src/obj/objcomplex.rs @@ -8,11 +8,11 @@ use super::objint::{self, PyInt}; use super::objstr::PyString; use super::objtype::PyClassRef; use crate::function::OptionalArg; -use crate::pyhash; use crate::pyobject::{ IntoPyObject, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol, }; use crate::vm::VirtualMachine; +use rustpython_common::hash; /// Create a complex number from a real part and an optional imaginary part. /// @@ -267,10 +267,10 @@ impl PyComplex { } #[pymethod(name = "__hash__")] - fn hash(&self) -> pyhash::PyHash { - let re_hash = pyhash::hash_float(self.value.re); - let im_hash = pyhash::hash_float(self.value.im); - let ret = Wrapping(re_hash) + Wrapping(im_hash) * Wrapping(pyhash::IMAG); + fn hash(&self) -> hash::PyHash { + let re_hash = hash::hash_float(self.value.re); + let im_hash = hash::hash_float(self.value.im); + let ret = Wrapping(re_hash) + Wrapping(im_hash) * Wrapping(hash::IMAG); ret.0 } diff --git a/vm/src/obj/objcoroinner.rs b/vm/src/obj/objcoroinner.rs index 61a43357d..11d4515ab 100644 --- a/vm/src/obj/objcoroinner.rs +++ b/vm/src/obj/objcoroinner.rs @@ -4,8 +4,8 @@ use crate::frame::{ExecutionResult, FrameRef}; use crate::pyobject::{PyObjectRef, PyResult}; use crate::vm::VirtualMachine; +use crate::common::cell::PyRwLock; use crossbeam_utils::atomic::AtomicCell; -use parking_lot::RwLock; #[derive(Debug, PartialEq, Clone, Copy)] pub enum Variant { @@ -37,7 +37,7 @@ pub struct Coro { frame: FrameRef, pub closed: AtomicCell, running: AtomicCell, - exceptions: RwLock>, + exceptions: PyRwLock>, started: AtomicCell, variant: Variant, } @@ -48,7 +48,7 @@ impl Coro { frame, closed: AtomicCell::new(false), running: AtomicCell::new(false), - exceptions: RwLock::new(vec![]), + exceptions: PyRwLock::new(vec![]), started: AtomicCell::new(false), variant, } diff --git a/vm/src/obj/objenumerate.rs b/vm/src/obj/objenumerate.rs index 4adbfda78..e36e35ec7 100644 --- a/vm/src/obj/objenumerate.rs +++ b/vm/src/obj/objenumerate.rs @@ -1,4 +1,4 @@ -use parking_lot::RwLock; +use crate::common::cell::PyRwLock; use std::ops::AddAssign; use num_bigint::BigInt; @@ -14,7 +14,7 @@ use crate::vm::VirtualMachine; #[pyclass] #[derive(Debug)] pub struct PyEnumerate { - counter: RwLock, + counter: PyRwLock, iterator: PyObjectRef, } type PyEnumerateRef = PyRef; @@ -41,7 +41,7 @@ impl PyEnumerate { let iterator = objiter::get_iter(vm, &iterable)?; PyEnumerate { - counter: RwLock::new(counter), + counter: PyRwLock::new(counter), iterator, } .into_ref_with_type(vm, cls) diff --git a/vm/src/obj/objfloat.rs b/vm/src/obj/objfloat.rs index 8b30ade4d..dab3fe265 100644 --- a/vm/src/obj/objfloat.rs +++ b/vm/src/obj/objfloat.rs @@ -1,20 +1,19 @@ use num_bigint::{BigInt, ToBigInt}; use num_rational::Ratio; -use num_traits::{float::Float, pow, sign::Signed, ToPrimitive, Zero}; +use num_traits::{pow, ToPrimitive, Zero}; use super::objbytes::PyBytes; use super::objint::{self, PyInt, PyIntRef}; use super::objstr::{PyString, PyStringRef}; use super::objtype::PyClassRef; -use crate::exceptions::PyBaseExceptionRef; use crate::format::FormatSpec; use crate::function::{OptionalArg, OptionalOption}; -use crate::pyhash; use crate::pyobject::{ IntoPyObject, PyArithmaticValue::*, PyClassImpl, PyComparisonValue, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TypeProtocol, }; use crate::vm::VirtualMachine; +use rustpython_common::{float_ops, hash}; /// Convert a string or number to a floating point number, if possible. #[pyclass(name = "float")] @@ -135,32 +134,6 @@ fn inner_divmod(v1: f64, v2: f64, vm: &VirtualMachine) -> PyResult<(f64, f64)> { } } -fn inner_lt_int(value: f64, other_int: &BigInt) -> bool { - match (value.to_bigint(), other_int.to_f64()) { - (Some(self_int), Some(other_float)) => value < other_float || self_int < *other_int, - // finite float, other_int too big for float, - // the result depends only on other_int’s sign - (Some(_), None) => other_int.is_positive(), - // infinite float must be bigger or lower than any int, depending on its sign - _ if value.is_infinite() => value.is_sign_negative(), - // NaN, always false - _ => false, - } -} - -fn inner_gt_int(value: f64, other_int: &BigInt) -> bool { - match (value.to_bigint(), other_int.to_f64()) { - (Some(self_int), Some(other_float)) => value > other_float || self_int > *other_int, - // finite float, other_int too big for float, - // the result depends only on other_int’s sign - (Some(_), None) => other_int.is_negative(), - // infinite float must be bigger or lower than any int, depending on its sign - _ if value.is_infinite() => value.is_sign_positive(), - // NaN, always false - _ => false, - } -} - pub fn float_pow(v1: f64, v2: f64, vm: &VirtualMachine) -> PyResult { if v1.is_zero() { let msg = format!("{} cannot be raised to a negative power", v1); @@ -170,14 +143,6 @@ pub fn float_pow(v1: f64, v2: f64, vm: &VirtualMachine) -> PyResult { } } -fn int_eq(value: f64, other: &BigInt) -> bool { - if let (Some(self_int), Some(other_float)) = (value.to_bigint(), other.to_f64()) { - value == other_float && self_int == *other - } else { - false - } -} - #[pyimpl(flags(BASETYPE))] #[allow(clippy::trivially_copy_pass_by_ref)] impl PyFloat { @@ -227,7 +192,7 @@ impl PyFloat { #[pymethod(name = "__eq__")] fn eq(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyComparisonValue { - self.cmp(other, |a, b| a == b, int_eq, vm) + self.cmp(other, |a, b| a == b, float_ops::eq_int, vm) } #[pymethod(name = "__ne__")] @@ -237,7 +202,7 @@ impl PyFloat { #[pymethod(name = "__lt__")] fn lt(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyComparisonValue { - self.cmp(other, |a, b| a < b, inner_lt_int, vm) + self.cmp(other, |a, b| a < b, float_ops::lt_int, vm) } #[pymethod(name = "__le__")] @@ -249,7 +214,7 @@ impl PyFloat { if let (Some(a_int), Some(b_float)) = (a.to_bigint(), b.to_f64()) { a <= b_float && a_int <= *b } else { - inner_lt_int(a, b) + float_ops::lt_int(a, b) } }, vm, @@ -258,7 +223,7 @@ impl PyFloat { #[pymethod(name = "__gt__")] fn gt(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyComparisonValue { - self.cmp(other, |a, b| a > b, inner_gt_int, vm) + self.cmp(other, |a, b| a > b, float_ops::gt_int, vm) } #[pymethod(name = "__ge__")] @@ -270,7 +235,7 @@ impl PyFloat { if let (Some(a_int), Some(b_float)) = (a.to_bigint(), b.to_f64()) { a >= b_float && a_int >= *b } else { - inner_gt_int(a, b) + float_ops::gt_int(a, b) } }, vm, @@ -386,23 +351,7 @@ impl PyFloat { #[pymethod(name = "__repr__")] fn repr(&self) -> String { - let value = format!("{:e}", self.value); - if let Some(position) = value.find('e') { - let significand = &value[..position]; - let exponent = &value[position + 1..]; - let exponent = exponent.parse::().unwrap(); - if exponent < 16 && exponent > -5 { - if self.is_integer() { - format!("{:.1?}", self.value) - } else { - self.value.to_string() - } - } else { - format!("{}e{:+#03}", significand, exponent) - } - } else { - self.value.to_string() - } + float_ops::to_string(self.value) } #[pymethod(name = "__truediv__")] @@ -499,8 +448,8 @@ impl PyFloat { } #[pymethod(name = "__hash__")] - fn hash(&self) -> pyhash::PyHash { - pyhash::hash_float(self.value) + fn hash(&self) -> hash::PyHash { + hash::hash_float(self.value) } #[pyproperty] @@ -520,8 +469,7 @@ impl PyFloat { #[pymethod(name = "is_integer")] fn is_integer(&self) -> bool { - let v = self.value; - (v - v.round()).abs() < std::f64::EPSILON + float_ops::is_integer(self.value) } #[pymethod(name = "as_integer_ratio")] @@ -544,116 +492,33 @@ impl PyFloat { #[pymethod] fn fromhex(repr: PyStringRef, vm: &VirtualMachine) -> PyResult { - hexf_parse::parse_hexf64(repr.as_str().trim(), false).or_else(|_| { - match repr.as_str().to_lowercase().trim() { - "nan" => Ok(std::f64::NAN), - "+nan" => Ok(std::f64::NAN), - "-nan" => Ok(std::f64::NAN), - "inf" => Ok(std::f64::INFINITY), - "infinity" => Ok(std::f64::INFINITY), - "+inf" => Ok(std::f64::INFINITY), - "+infinity" => Ok(std::f64::INFINITY), - "-inf" => Ok(std::f64::NEG_INFINITY), - "-infinity" => Ok(std::f64::NEG_INFINITY), - value => { - let mut hex = String::new(); - let has_0x = value.contains("0x"); - let has_p = value.contains('p'); - let has_dot = value.contains('.'); - let mut start = 0; - - if !has_0x && value.starts_with('-') { - hex.push_str("-0x"); - start += 1; - } else if !has_0x { - hex.push_str("0x"); - if value.starts_with('+') { - start += 1; - } - } - - for (index, ch) in value.chars().enumerate() { - if ch == 'p' && has_dot { - hex.push_str("p"); - } else if ch == 'p' && !has_dot { - hex.push_str(".p"); - } else if index >= start { - hex.push(ch); - } - } - - if !has_p && has_dot { - hex.push_str("p0"); - } else if !has_p && !has_dot { - hex.push_str(".p0") - } - - hexf_parse::parse_hexf64(hex.as_str(), false).map_err(|_| { - vm.new_value_error("invalid hexadecimal floating-point string".to_owned()) - }) - } - } + float_ops::from_hex(repr.as_str().trim()).ok_or_else(|| { + vm.new_value_error("invalid hexadecimal floating-point string".to_owned()) }) } #[pymethod] fn hex(&self) -> String { - to_hex(self.value) + float_ops::to_hex(self.value) } } -fn str_to_float(vm: &VirtualMachine, literal: &str) -> PyResult { - if literal.starts_with('_') || literal.ends_with('_') { - return Err(invalid_convert(vm, literal)); - } - - let mut buf = String::with_capacity(literal.len()); - let mut last_tok: Option = None; - for c in literal.chars() { - if !(c.is_ascii_alphanumeric() || c == '_' || c == '+' || c == '-' || c == '.') { - return Err(invalid_convert(vm, literal)); - } - - if !c.is_ascii_alphanumeric() { - if let Some(l) = last_tok { - if !l.is_ascii_alphanumeric() && !(c == '.' && (l == '-' || l == '+')) { - return Err(invalid_convert(vm, literal)); - } - } - } - - if c != '_' { - buf.push(c); - } - last_tok = Some(c); - } - - if let Ok(f) = lexical::parse(buf.as_str()) { - Ok(f) - } else { - Err(invalid_convert(vm, literal)) - } -} - -fn invalid_convert(vm: &VirtualMachine, literal: &str) -> PyBaseExceptionRef { - vm.new_value_error(format!("could not convert string to float: '{}'", literal)) -} - fn to_float(vm: &VirtualMachine, obj: &PyObjectRef) -> PyResult { let value = if let Some(float) = obj.payload_if_subclass::(vm) { float.value } else if let Some(int) = obj.payload_if_subclass::(vm) { objint::try_float(int.as_bigint(), vm)? } else if let Some(s) = obj.payload_if_subclass::(vm) { - str_to_float(vm, s.as_str().trim())? + float_ops::parse_str(s.as_str().trim()).ok_or_else(|| { + vm.new_value_error(format!("could not convert string to float: '{}'", s)) + })? } else if let Some(bytes) = obj.payload_if_subclass::(vm) { - match lexical::parse(bytes.get_value()) { - Ok(f) => f, - Err(_) => { - let arg_repr = vm.to_pystr(obj)?; - return Err(invalid_convert(vm, arg_repr.as_str())); - } - } + lexical::parse(bytes.get_value()).map_err(|_| { + vm.new_value_error(format!( + "could not convert string to float: '{}'", + bytes.repr() + )) + })? } else { let method = vm.get_method_or_type_error(obj.clone(), "__float__", || { format!( @@ -667,55 +532,6 @@ fn to_float(vm: &VirtualMachine, obj: &PyObjectRef) -> PyResult { Ok(value) } -fn to_hex(value: f64) -> String { - let (mantissa, exponent, sign) = value.integer_decode(); - let sign_fmt = if sign < 0 { "-" } else { "" }; - match value { - value if value.is_zero() => format!("{}0x0.0p+0", sign_fmt), - value if value.is_infinite() => format!("{}inf", sign_fmt), - value if value.is_nan() => "nan".to_owned(), - _ => { - const BITS: i16 = 52; - const FRACT_MASK: u64 = 0xf_ffff_ffff_ffff; - format!( - "{}0x{:x}.{:013x}p{:+}", - sign_fmt, - mantissa >> BITS, - mantissa & FRACT_MASK, - exponent + BITS - ) - } - } -} - -#[test] -fn test_to_hex() { - use rand::Rng; - for _ in 0..20000 { - let bytes = rand::thread_rng().gen::<[u64; 1]>(); - let f = f64::from_bits(bytes[0]); - if !f.is_finite() { - continue; - } - let hex = to_hex(f); - // println!("{} -> {}", f, hex); - let roundtrip = hexf_parse::parse_hexf64(&hex, false).unwrap(); - // println!(" -> {}", roundtrip); - assert!(f == roundtrip, "{} {} {}", f, hex, roundtrip); - } -} - -pub fn ufrexp(value: f64) -> (f64, i32) { - if 0.0 == value { - (0.0, 0i32) - } else { - let bits = value.to_bits(); - let exponent: i32 = ((bits >> 52) & 0x7ff) as i32 - 1022; - let mantissa_bits = bits & (0x000f_ffff_ffff_ffff) | (1022 << 52); - (f64::from_bits(mantissa_bits), exponent) - } -} - pub type PyFloatRef = PyRef; // Retrieve inner float value: diff --git a/vm/src/obj/objint.rs b/vm/src/obj/objint.rs index 780b7ebd2..e011f23c0 100644 --- a/vm/src/obj/objint.rs +++ b/vm/src/obj/objint.rs @@ -15,13 +15,13 @@ use super::objstr::{PyString, PyStringRef}; use super::objtype::{self, PyClassRef}; use crate::format::FormatSpec; use crate::function::{OptionalArg, PyFuncArgs}; -use crate::pyhash; use crate::pyobject::{ IdProtocol, IntoPyObject, PyArithmaticValue, PyClassImpl, PyComparisonValue, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TypeProtocol, }; use crate::stdlib::array::PyArray; use crate::vm::VirtualMachine; +use rustpython_common::hash; /// int(x=0) -> integer /// int(x, base=10) -> integer @@ -419,8 +419,8 @@ impl PyInt { } #[pymethod(name = "__hash__")] - pub fn hash(&self) -> pyhash::PyHash { - pyhash::hash_bigint(&self.value) + pub fn hash(&self) -> hash::PyHash { + hash::hash_bigint(&self.value) } #[pymethod(name = "__abs__")] diff --git a/vm/src/obj/objlist.rs b/vm/src/obj/objlist.rs index 70139ab45..6c48f3b6c 100644 --- a/vm/src/obj/objlist.rs +++ b/vm/src/obj/objlist.rs @@ -2,10 +2,10 @@ use std::fmt; use std::mem::size_of; use std::ops::{DerefMut, Range}; +use crate::common::cell::{PyRwLock, PyRwLockReadGuard, PyRwLockWriteGuard}; use crossbeam_utils::atomic::AtomicCell; use num_bigint::{BigInt, ToBigInt}; use num_traits::{One, Signed, ToPrimitive, Zero}; -use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard}; use super::objbool; use super::objbyteinner; @@ -29,7 +29,7 @@ use crate::vm::{ReprGuard, VirtualMachine}; #[pyclass] #[derive(Default)] pub struct PyList { - elements: RwLock>, + elements: PyRwLock>, } impl fmt::Debug for PyList { @@ -42,7 +42,7 @@ impl fmt::Debug for PyList { impl From> for PyList { fn from(elements: Vec) -> Self { PyList { - elements: RwLock::new(elements), + elements: PyRwLock::new(elements), } } } @@ -54,11 +54,11 @@ impl PyValue for PyList { } impl PyList { - pub fn borrow_elements(&self) -> RwLockReadGuard<'_, Vec> { + pub fn borrow_elements(&self) -> PyRwLockReadGuard<'_, Vec> { self.elements.read() } - pub fn borrow_elements_mut(&self) -> RwLockWriteGuard<'_, Vec> { + pub fn borrow_elements_mut(&self) -> PyRwLockWriteGuard<'_, Vec> { self.elements.write() } @@ -315,7 +315,7 @@ impl PyList { } fn _set_slice( - mut elements: RwLockWriteGuard<'_, Vec>, + mut elements: PyRwLockWriteGuard<'_, Vec>, range: Range, items: Vec, vm: &VirtualMachine, @@ -327,7 +327,7 @@ impl PyList { } fn _set_stepped_slice( - elements: RwLockWriteGuard<'_, Vec>, + elements: PyRwLockWriteGuard<'_, Vec>, range: Range, step: usize, items: Vec, @@ -365,7 +365,7 @@ impl PyList { } fn _set_stepped_slice_reverse( - elements: RwLockWriteGuard<'_, Vec>, + elements: PyRwLockWriteGuard<'_, Vec>, range: Range, step: usize, items: Vec, @@ -403,7 +403,7 @@ impl PyList { } fn _replace_indexes( - mut elements: RwLockWriteGuard<'_, Vec>, + mut elements: PyRwLockWriteGuard<'_, Vec>, indexes: I, items: &[PyObjectRef], ) where @@ -673,12 +673,12 @@ impl PyList { } } - fn _del_slice(mut elements: RwLockWriteGuard<'_, Vec>, range: Range) { + fn _del_slice(mut elements: PyRwLockWriteGuard<'_, Vec>, range: Range) { elements.drain(range); } fn _del_stepped_slice( - mut elements: RwLockWriteGuard<'_, Vec>, + mut elements: PyRwLockWriteGuard<'_, Vec>, range: Range, step: usize, ) { @@ -702,7 +702,7 @@ impl PyList { } fn _del_stepped_slice_reverse( - mut elements: RwLockWriteGuard<'_, Vec>, + mut elements: PyRwLockWriteGuard<'_, Vec>, range: Range, step: usize, ) { diff --git a/vm/src/obj/objobject.rs b/vm/src/obj/objobject.rs index c64fa6883..4c1149681 100644 --- a/vm/src/obj/objobject.rs +++ b/vm/src/obj/objobject.rs @@ -5,7 +5,6 @@ use super::objstr::PyStringRef; use super::objtype::PyClassRef; use crate::function::{OptionalArg, PyFuncArgs}; use crate::obj::objtype::PyClass; -use crate::pyhash; use crate::pyobject::{ IdProtocol, ItemProtocol, PyArithmaticValue::*, PyAttributes, PyClassImpl, PyComparisonValue, PyContext, PyObject, PyObjectRef, PyResult, PyValue, TryFromObject, TypeProtocol, @@ -85,8 +84,8 @@ impl PyBaseObject { } #[pymethod(magic)] - fn hash(zelf: PyObjectRef) -> pyhash::PyHash { - zelf.get_id() as pyhash::PyHash + fn hash(zelf: PyObjectRef) -> rustpython_common::hash::PyHash { + zelf.get_id() as _ } #[pymethod(magic)] diff --git a/vm/src/obj/objproperty.rs b/vm/src/obj/objproperty.rs index 909ca4321..737f7e8cf 100644 --- a/vm/src/obj/objproperty.rs +++ b/vm/src/obj/objproperty.rs @@ -1,7 +1,7 @@ /*! Python `property` descriptor class. */ -use parking_lot::RwLock; +use crate::common::cell::PyRwLock; use super::objtype::PyClassRef; use crate::function::OptionalArg; @@ -49,7 +49,7 @@ pub struct PyProperty { getter: Option, setter: Option, deleter: Option, - doc: RwLock>, + doc: PyRwLock>, } impl PyValue for PyProperty { @@ -98,7 +98,7 @@ impl PyProperty { getter: args.fget, setter: args.fset, deleter: args.fdel, - doc: RwLock::new(args.doc), + doc: PyRwLock::new(args.doc), } .into_ref_with_type(vm, cls) } @@ -160,7 +160,7 @@ impl PyProperty { getter: getter.or_else(|| zelf.getter.clone()), setter: zelf.setter.clone(), deleter: zelf.deleter.clone(), - doc: RwLock::new(None), + doc: PyRwLock::new(None), } .into_ref_with_type(vm, TypeProtocol::class(&zelf)) } @@ -175,7 +175,7 @@ impl PyProperty { getter: zelf.getter.clone(), setter: setter.or_else(|| zelf.setter.clone()), deleter: zelf.deleter.clone(), - doc: RwLock::new(None), + doc: PyRwLock::new(None), } .into_ref_with_type(vm, TypeProtocol::class(&zelf)) } @@ -190,7 +190,7 @@ impl PyProperty { getter: zelf.getter.clone(), setter: zelf.setter.clone(), deleter: deleter.or_else(|| zelf.deleter.clone()), - doc: RwLock::new(None), + doc: PyRwLock::new(None), } .into_ref_with_type(vm, TypeProtocol::class(&zelf)) } diff --git a/vm/src/obj/objrange.rs b/vm/src/obj/objrange.rs index ef93ee230..ac8668f9c 100644 --- a/vm/src/obj/objrange.rs +++ b/vm/src/obj/objrange.rs @@ -10,11 +10,12 @@ use super::objtuple::PyTuple; use super::objtype::PyClassRef; use crate::function::{OptionalArg, PyFuncArgs}; -use crate::pyhash; use crate::pyobject::{ - PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TypeProtocol, + self, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, + TypeProtocol, }; use crate::vm::VirtualMachine; +use rustpython_common::hash::PyHash; /// range(stop) -> range object /// range(start, stop[, step]) -> range object @@ -363,7 +364,7 @@ impl PyRange { } #[pymethod(name = "__hash__")] - fn hash(zelf: PyRef, vm: &VirtualMachine) -> PyResult { + fn hash(zelf: PyRef, vm: &VirtualMachine) -> PyResult { let length = zelf.length(); let elements = if length.is_zero() { vec![vm.ctx.new_int(length), vm.get_none(), vm.get_none()] @@ -380,7 +381,7 @@ impl PyRange { zelf.step().into_object(), ] }; - pyhash::hash_iter(elements.iter(), vm) + pyobject::hash_iter(&elements, vm) } #[pyslot] diff --git a/vm/src/obj/objset.rs b/vm/src/obj/objset.rs index 7577933e6..019f00b9a 100644 --- a/vm/src/obj/objset.rs +++ b/vm/src/obj/objset.rs @@ -7,12 +7,12 @@ use super::objlist::PyListIterator; use super::objtype::{self, PyClassRef}; use crate::dictdatatype; use crate::function::{Args, OptionalArg}; -use crate::pyhash; use crate::pyobject::{ - PyClassImpl, PyContext, PyIterable, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, + self, PyClassImpl, PyContext, PyIterable, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TypeProtocol, }; use crate::vm::{ReprGuard, VirtualMachine}; +use rustpython_common::hash::PyHash; pub type SetContentType = dictdatatype::Dict<()>; @@ -329,8 +329,8 @@ impl PySetInner { Ok(()) } - fn hash(&self, vm: &VirtualMachine) -> PyResult { - pyhash::hash_iter_unordered(self.content.keys().iter(), vm) + fn hash(&self, vm: &VirtualMachine) -> PyResult { + pyobject::hash_iter_unordered(self.content.keys().iter(), vm) } } @@ -787,7 +787,7 @@ impl PyFrozenSet { } #[pymethod(name = "__hash__")] - fn hash(&self, vm: &VirtualMachine) -> PyResult { + fn hash(&self, vm: &VirtualMachine) -> PyResult { self.inner.hash(vm) } } diff --git a/vm/src/obj/objstr.rs b/vm/src/obj/objstr.rs index 02acf5d04..dd905416c 100644 --- a/vm/src/obj/objstr.rs +++ b/vm/src/obj/objstr.rs @@ -24,12 +24,12 @@ use super::pystr::{ }; use crate::format::{FormatParseError, FormatSpec, FormatString, FromTemplate}; use crate::function::{OptionalArg, OptionalOption, PyFuncArgs}; -use crate::pyhash; use crate::pyobject::{ IdProtocol, IntoPyObject, ItemProtocol, PyClassImpl, PyContext, PyIterable, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TryIntoRef, TypeProtocol, }; use crate::vm::VirtualMachine; +use rustpython_common::hash; /// str(object='') -> str /// str(bytes_or_buffer[, encoding[, errors]]) -> str @@ -45,7 +45,7 @@ use crate::vm::VirtualMachine; #[derive(Debug)] pub struct PyString { value: String, - hash: AtomicCell>, + hash: AtomicCell>, len: AtomicCell>, } @@ -280,9 +280,9 @@ impl PyString { } #[pymethod(name = "__hash__")] - pub(crate) fn hash(&self) -> pyhash::PyHash { + pub(crate) fn hash(&self) -> hash::PyHash { self.hash.load().unwrap_or_else(|| { - let hash = pyhash::hash_value(&self.value); + let hash = hash::hash_value(&self.value); self.hash.store(Some(hash)); hash }) diff --git a/vm/src/obj/objtuple.rs b/vm/src/obj/objtuple.rs index 43570b386..92e591f46 100644 --- a/vm/src/obj/objtuple.rs +++ b/vm/src/obj/objtuple.rs @@ -5,14 +5,14 @@ use super::objiter; use super::objsequence::get_item; use super::objtype::PyClassRef; use crate::function::OptionalArg; -use crate::pyhash; use crate::pyobject::{ - IntoPyObject, + self, IntoPyObject, PyArithmaticValue::{self, *}, PyClassImpl, PyComparisonValue, PyContext, PyObjectRef, PyRef, PyResult, PyValue, }; use crate::sequence::{self, SimpleSeq}; use crate::vm::{ReprGuard, VirtualMachine}; +use rustpython_common::hash::PyHash; /// tuple() -> empty tuple /// tuple(iterable) -> tuple initialized from iterable's items @@ -156,8 +156,8 @@ impl PyTuple { } #[pymethod(name = "__hash__")] - fn hash(&self, vm: &VirtualMachine) -> PyResult { - pyhash::hash_iter(self.elements.iter(), vm) + fn hash(&self, vm: &VirtualMachine) -> PyResult { + pyobject::hash_iter(self.elements.iter(), vm) } #[pymethod(name = "__iter__")] diff --git a/vm/src/obj/objtype.rs b/vm/src/obj/objtype.rs index 1dff7f790..236c76216 100644 --- a/vm/src/obj/objtype.rs +++ b/vm/src/obj/objtype.rs @@ -1,4 +1,4 @@ -use parking_lot::RwLock; +use crate::common::cell::PyRwLock; use std::collections::{HashMap, HashSet}; use std::fmt; @@ -29,9 +29,9 @@ pub struct PyClass { pub name: String, pub bases: Vec, pub mro: Vec, - pub subclasses: RwLock>, - pub attributes: RwLock, - pub slots: RwLock, + pub subclasses: PyRwLock>, + pub attributes: PyRwLock, + pub slots: PyRwLock, } impl fmt::Display for PyClass { @@ -595,12 +595,12 @@ pub fn new( name: String::from(name), bases, mro, - subclasses: RwLock::default(), - attributes: RwLock::new(dict), - slots: RwLock::default(), + subclasses: PyRwLock::default(), + attributes: PyRwLock::new(dict), + slots: PyRwLock::default(), }, dict: None, - typ: RwLock::new(typ.into_typed_pyobj()), + typ: PyRwLock::new(typ.into_typed_pyobj()), } .into_ref(); diff --git a/vm/src/obj/objweakref.rs b/vm/src/obj/objweakref.rs index d50fc378a..f67233eb8 100644 --- a/vm/src/obj/objweakref.rs +++ b/vm/src/obj/objweakref.rs @@ -6,10 +6,10 @@ use crate::pyobject::{ }; use crate::slots::SlotCall; use crate::vm::VirtualMachine; +use rustpython_common::hash::PyHash; +use rustpython_common::rc::{PyRc, PyWeak as Weak}; -use crate::pyhash::PyHash; use crossbeam_utils::atomic::AtomicCell; -use std::sync::{Arc, Weak}; #[pyclass] #[derive(Debug)] @@ -21,7 +21,7 @@ pub struct PyWeak { impl PyWeak { pub fn downgrade(obj: &PyObjectRef) -> PyWeak { PyWeak { - referent: Arc::downgrade(obj), + referent: PyRc::downgrade(obj), hash: AtomicCell::new(None), } } diff --git a/vm/src/pyobject.rs b/vm/src/pyobject.rs index cfd2df03e..639fd85d8 100644 --- a/vm/src/pyobject.rs +++ b/vm/src/pyobject.rs @@ -3,7 +3,6 @@ use std::collections::HashMap; use std::fmt; use std::marker::PhantomData; use std::ops::Deref; -use std::sync::Arc; use indexmap::IndexMap; use num_bigint::BigInt; @@ -40,7 +39,8 @@ use crate::scope::Scope; use crate::slots::PyTpFlags; use crate::types::{create_type, initialize_types, TypeZoo}; use crate::vm::VirtualMachine; -use parking_lot::{RwLock, RwLockReadGuard}; +use rustpython_common::cell::{PyRwLock, PyRwLockReadGuard}; +use rustpython_common::rc::PyRc; /* Python objects and references. @@ -61,7 +61,7 @@ Basically reference counting, but then done by rust. /// this reference counting is accounted for by this type. Use the `.clone()` /// method to create a new reference and increment the amount of references /// to the python object by 1. -pub type PyObjectRef = Arc>; +pub type PyObjectRef = PyRc>; /// Use this type for functions which return a python object or an exception. /// Both the python object and the python exception are `PyObjectRef` types @@ -586,8 +586,8 @@ impl PyContext { pub fn new_base_object(&self, class: PyClassRef, dict: Option) -> PyObjectRef { PyObject { - typ: RwLock::new(class.into_typed_pyobj()), - dict: dict.map(|d| RwLock::new(d.into_typed_pyobj())), + typ: PyRwLock::new(class.into_typed_pyobj()), + dict: dict.map(|d| PyRwLock::new(d.into_typed_pyobj())), payload: objobject::PyBaseObject, } .into_ref() @@ -643,8 +643,8 @@ pub struct PyObject where T: ?Sized + PyObjectPayload, { - pub(crate) typ: RwLock>>, // __class__ member - pub(crate) dict: Option>>>, // __dict__ member + pub(crate) typ: PyRwLock>>, // __class__ member + pub(crate) dict: Option>>>, // __dict__ member pub payload: T, } @@ -653,7 +653,7 @@ impl PyObject { /// /// If the downcast fails, the original ref is returned in as `Err` so /// another downcast can be attempted without unnecessary cloning. - pub fn downcast(self: Arc) -> Result, PyObjectRef> { + pub fn downcast(self: PyRc) -> Result, PyObjectRef> { if self.payload_is::() { Ok(PyRef { obj: self, @@ -664,15 +664,15 @@ impl PyObject { } } - /// Downcast this PyObjectRef to an `Arc>`. The [`downcast`](#method.downcast) method + /// Downcast this PyObjectRef to an `PyRc>`. The [`downcast`](#method.downcast) method /// is generally preferred, as the `PyRef` it returns implements `Deref`, and /// therefore can be used similarly to an `&T`. pub fn downcast_generic( - self: Arc, - ) -> Result>, PyObjectRef> { + self: PyRc, + ) -> Result>, PyObjectRef> { if self.payload_is::() { - let ptr = Arc::into_raw(self) as *const PyObject; - let ret = unsafe { Arc::from_raw(ptr) }; + let ptr = PyRc::into_raw(self) as *const PyObject; + let ret = unsafe { PyRc::from_raw(ptr) }; Ok(ret) } else { Err(self) @@ -738,7 +738,7 @@ impl PyRef { self.obj } - pub fn into_typed_pyobj(self) -> Arc> { + pub fn into_typed_pyobj(self) -> PyRc> { self.into_object().downcast_generic().unwrap() } } @@ -850,7 +850,7 @@ impl IdProtocol for PyObject { } } -impl IdProtocol for Arc { +impl IdProtocol for PyRc { fn get_id(&self) -> usize { (**self).get_id() } @@ -877,7 +877,7 @@ impl IdProtocol for &'_ T { /// A borrow of a reference to a Python object. This avoids having clone the `PyRef`/ /// `PyObjectRef`, which isn't that cheap as that increments the atomic reference counter. pub struct PyLease<'a, T: PyObjectPayload> { - inner: RwLockReadGuard<'a, Arc>>, + inner: PyRwLockReadGuard<'a, PyRc>>, } impl<'a, T: PyObjectPayload + PyValue> PyLease<'a, T> { @@ -1212,8 +1212,8 @@ where #[allow(clippy::new_ret_no_self)] pub fn new(payload: T, typ: PyClassRef, dict: Option) -> PyObjectRef { PyObject { - typ: RwLock::new(typ.into_typed_pyobj()), - dict: dict.map(|d| RwLock::new(d.into_typed_pyobj())), + typ: PyRwLock::new(typ.into_typed_pyobj()), + dict: dict.map(|d| PyRwLock::new(d.into_typed_pyobj())), payload, } .into_ref() @@ -1221,10 +1221,10 @@ where // Move this object into a reference object, transferring ownership. pub fn into_ref(self) -> PyObjectRef { - Arc::new(self) + PyRc::new(self) } - pub fn into_pyref(self: Arc) -> PyRef + pub fn into_pyref(self: PyRc) -> PyRef where T: PyValue, { @@ -1276,7 +1276,17 @@ impl PyObject { } } -pub trait PyValue: fmt::Debug + Send + Sync + Sized + 'static { +cfg_if::cfg_if! { + if #[cfg(feature = "threading")] { + pub trait PyThreadingConstraint: Send + Sync {} + impl PyThreadingConstraint for T {} + } else { + pub trait PyThreadingConstraint {} + impl PyThreadingConstraint for T {} + } +} + +pub trait PyValue: fmt::Debug + PyThreadingConstraint + Sized + 'static { const HAVE_DICT: bool = false; fn class(vm: &VirtualMachine) -> PyClassRef; @@ -1306,7 +1316,7 @@ pub trait PyValue: fmt::Debug + Send + Sync + Sized + 'static { } } -pub trait PyObjectPayload: Any + fmt::Debug + Send + Sync + 'static { +pub trait PyObjectPayload: Any + fmt::Debug + PyThreadingConstraint + 'static { fn as_any(&self) -> &dyn Any; } @@ -1452,6 +1462,20 @@ impl TryFromObject for PySequence { } } +pub fn hash_iter<'a, I: IntoIterator>( + iter: I, + vm: &VirtualMachine, +) -> PyResult { + rustpython_common::hash::hash_iter(iter, |obj| vm._hash(obj)) +} + +pub fn hash_iter_unordered<'a, I: IntoIterator>( + iter: I, + vm: &VirtualMachine, +) -> PyResult { + rustpython_common::hash::hash_iter_unordered(iter, |obj| vm._hash(obj)) +} + #[cfg(test)] mod tests { use super::*; diff --git a/vm/src/stdlib/array.rs b/vm/src/stdlib/array.rs index 0f6dde5f2..87c2afaa2 100644 --- a/vm/src/stdlib/array.rs +++ b/vm/src/stdlib/array.rs @@ -10,7 +10,7 @@ use crate::pyobject::{ }; use crate::VirtualMachine; -use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard}; +use crate::common::cell::{PyRwLock, PyRwLockReadGuard, PyRwLockWriteGuard}; use std::fmt; use crossbeam_utils::atomic::AtomicCell; @@ -239,7 +239,7 @@ def_array_enum!( #[pyclass(name = "array")] #[derive(Debug)] pub struct PyArray { - array: RwLock, + array: PyRwLock, } pub type PyArrayRef = PyRef; @@ -252,11 +252,11 @@ impl PyValue for PyArray { #[pyimpl(flags(BASETYPE))] impl PyArray { - fn borrow_value(&self) -> RwLockReadGuard<'_, ArrayContentType> { + fn borrow_value(&self) -> PyRwLockReadGuard<'_, ArrayContentType> { self.array.read() } - fn borrow_value_mut(&self) -> RwLockWriteGuard<'_, ArrayContentType> { + fn borrow_value_mut(&self) -> PyRwLockWriteGuard<'_, ArrayContentType> { self.array.write() } @@ -278,7 +278,7 @@ impl PyArray { let array = ArrayContentType::from_char(spec).map_err(|err| vm.new_value_error(err.to_string()))?; let zelf = PyArray { - array: RwLock::new(array), + array: PyRwLock::new(array), }; if let OptionalArg::Present(init) = init { zelf.extend(init, vm)?; diff --git a/vm/src/stdlib/collections.rs b/vm/src/stdlib/collections.rs index a959970b8..eabc0fce1 100644 --- a/vm/src/stdlib/collections.rs +++ b/vm/src/stdlib/collections.rs @@ -2,6 +2,7 @@ pub(crate) use _collections::make_module; #[pymodule] mod _collections { + use crate::common::cell::{PyRwLock, PyRwLockReadGuard, PyRwLockWriteGuard}; use crate::function::OptionalArg; use crate::obj::{objiter, objtype::PyClassRef}; use crate::pyobject::{ @@ -12,7 +13,6 @@ mod _collections { use crate::vm::ReprGuard; use crate::VirtualMachine; use itertools::Itertools; - use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard}; use std::collections::VecDeque; use crossbeam_utils::atomic::AtomicCell; @@ -20,7 +20,7 @@ mod _collections { #[pyclass(name = "deque")] #[derive(Debug)] struct PyDeque { - deque: RwLock>, + deque: PyRwLock>, maxlen: AtomicCell>, } type PyDequeRef = PyRef; @@ -38,16 +38,16 @@ mod _collections { } impl PyDeque { - fn borrow_deque(&self) -> RwLockReadGuard<'_, VecDeque> { + fn borrow_deque(&self) -> PyRwLockReadGuard<'_, VecDeque> { self.deque.read() } - fn borrow_deque_mut(&self) -> RwLockWriteGuard<'_, VecDeque> { + fn borrow_deque_mut(&self) -> PyRwLockWriteGuard<'_, VecDeque> { self.deque.write() } } - struct SimpleSeqDeque<'a>(RwLockReadGuard<'a, VecDeque>); + struct SimpleSeqDeque<'a>(PyRwLockReadGuard<'a, VecDeque>); impl sequence::SimpleSeq for SimpleSeqDeque<'_> { fn len(&self) -> usize { @@ -59,8 +59,8 @@ mod _collections { } } - impl<'a> From>> for SimpleSeqDeque<'a> { - fn from(from: RwLockReadGuard<'a, VecDeque>) -> Self { + impl<'a> From>> for SimpleSeqDeque<'a> { + fn from(from: PyRwLockReadGuard<'a, VecDeque>) -> Self { Self { 0: from } } } @@ -75,7 +75,7 @@ mod _collections { vm: &VirtualMachine, ) -> PyResult> { let py_deque = PyDeque { - deque: RwLock::default(), + deque: PyRwLock::default(), maxlen: AtomicCell::new(maxlen), }; if let OptionalArg::Present(iter) = iter { @@ -110,7 +110,7 @@ mod _collections { #[pymethod] fn copy(&self) -> Self { PyDeque { - deque: RwLock::new(self.borrow_deque().clone()), + deque: PyRwLock::new(self.borrow_deque().clone()), maxlen: AtomicCell::new(self.maxlen.load()), } } @@ -383,7 +383,7 @@ mod _collections { }; let deque = mul.skip(skipped).cloned().collect(); PyDeque { - deque: RwLock::new(deque), + deque: PyRwLock::new(deque), maxlen: AtomicCell::new(self.maxlen.load()), } } diff --git a/vm/src/stdlib/csv.rs b/vm/src/stdlib/csv.rs index bef432b00..452650c75 100644 --- a/vm/src/stdlib/csv.rs +++ b/vm/src/stdlib/csv.rs @@ -1,11 +1,10 @@ -use parking_lot::RwLock; use std::fmt::{self, Debug, Formatter}; use csv as rust_csv; use itertools::join; +use crate::common::cell::PyRwLock; use crate::function::PyFuncArgs; - use crate::obj::objiter; use crate::obj::objstr::{self, PyString}; use crate::obj::objtype::PyClassRef; @@ -126,7 +125,7 @@ impl ReadState { #[pyclass(name = "Reader")] struct Reader { - state: RwLock, + state: PyRwLock, } impl Debug for Reader { @@ -143,7 +142,7 @@ impl PyValue for Reader { impl Reader { fn new(iter: PyIterable, config: ReaderOption) -> Self { - let state = RwLock::new(ReadState::new(iter, config)); + let state = PyRwLock::new(ReadState::new(iter, config)); Reader { state } } } diff --git a/vm/src/stdlib/hashlib.rs b/vm/src/stdlib/hashlib.rs index 43f8442dc..262755279 100644 --- a/vm/src/stdlib/hashlib.rs +++ b/vm/src/stdlib/hashlib.rs @@ -1,10 +1,10 @@ +use crate::common::cell::{PyRwLock, PyRwLockReadGuard, PyRwLockWriteGuard}; use crate::function::{OptionalArg, PyFuncArgs}; use crate::obj::objbytes::{PyBytes, PyBytesRef}; use crate::obj::objstr::PyStringRef; use crate::obj::objtype::PyClassRef; use crate::pyobject::{PyClassImpl, PyObjectRef, PyResult, PyValue}; use crate::vm::VirtualMachine; -use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard}; use std::fmt; use blake2::{Blake2b, Blake2s}; @@ -17,7 +17,7 @@ use sha3::{Sha3_224, Sha3_256, Sha3_384, Sha3_512}; // TODO: , Shake128, Shake25 #[pyclass(name = "hasher")] struct PyHasher { name: String, - buffer: RwLock, + buffer: PyRwLock, } impl fmt::Debug for PyHasher { @@ -37,15 +37,15 @@ impl PyHasher { fn new(name: &str, d: HashWrapper) -> Self { PyHasher { name: name.to_owned(), - buffer: RwLock::new(d), + buffer: PyRwLock::new(d), } } - fn borrow_value(&self) -> RwLockReadGuard<'_, HashWrapper> { + fn borrow_value(&self) -> PyRwLockReadGuard<'_, HashWrapper> { self.buffer.read() } - fn borrow_value_mut(&self) -> RwLockWriteGuard<'_, HashWrapper> { + fn borrow_value_mut(&self) -> PyRwLockWriteGuard<'_, HashWrapper> { self.buffer.write() } diff --git a/vm/src/stdlib/io.rs b/vm/src/stdlib/io.rs index 26daec8d0..743e9955f 100644 --- a/vm/src/stdlib/io.rs +++ b/vm/src/stdlib/io.rs @@ -1,13 +1,13 @@ /* * I/O core tools. */ -use parking_lot::{RwLock, RwLockWriteGuard}; use std::fs; use std::io::{self, prelude::*, Cursor, SeekFrom}; use crossbeam_utils::atomic::AtomicCell; use num_traits::ToPrimitive; +use crate::common::cell::{PyRwLock, PyRwLockWriteGuard}; use crate::exceptions::PyBaseExceptionRef; use crate::function::{Args, KwArgs, OptionalArg, OptionalOption, PyFuncArgs}; use crate::obj::objbool; @@ -121,7 +121,7 @@ impl BufferedIO { #[derive(Debug)] struct PyStringIO { - buffer: RwLock, + buffer: PyRwLock, closed: AtomicCell, } @@ -134,7 +134,7 @@ impl PyValue for PyStringIO { } impl PyStringIORef { - fn buffer(&self, vm: &VirtualMachine) -> PyResult> { + fn buffer(&self, vm: &VirtualMachine) -> PyResult> { if !self.closed.load() { Ok(self.buffer.write()) } else { @@ -236,7 +236,7 @@ fn string_io_new( let input = flatten.map_or_else(Vec::new, |v| objstr::borrow_value(&v).as_bytes().to_vec()); PyStringIO { - buffer: RwLock::new(BufferedIO::new(Cursor::new(input))), + buffer: PyRwLock::new(BufferedIO::new(Cursor::new(input))), closed: AtomicCell::new(false), } .into_ref_with_type(vm, cls) @@ -244,7 +244,7 @@ fn string_io_new( #[derive(Debug)] struct PyBytesIO { - buffer: RwLock, + buffer: PyRwLock, closed: AtomicCell, } @@ -257,7 +257,7 @@ impl PyValue for PyBytesIO { } impl PyBytesIORef { - fn buffer(&self, vm: &VirtualMachine) -> PyResult> { + fn buffer(&self, vm: &VirtualMachine) -> PyResult> { if !self.closed.load() { Ok(self.buffer.write()) } else { @@ -341,7 +341,7 @@ fn bytes_io_new( }; PyBytesIO { - buffer: RwLock::new(BufferedIO::new(Cursor::new(raw_bytes))), + buffer: PyRwLock::new(BufferedIO::new(Cursor::new(raw_bytes))), closed: AtomicCell::new(false), } .into_ref_with_type(vm, cls) diff --git a/vm/src/stdlib/itertools.rs b/vm/src/stdlib/itertools.rs index b5ff02074..eb9752f5d 100644 --- a/vm/src/stdlib/itertools.rs +++ b/vm/src/stdlib/itertools.rs @@ -5,10 +5,9 @@ mod decl { use crossbeam_utils::atomic::AtomicCell; use num_bigint::BigInt; use num_traits::{One, Signed, ToPrimitive, Zero}; - use parking_lot::{RwLock, RwLockWriteGuard}; use std::iter; - use std::sync::Arc; + use crate::common::cell::{PyRwLock, PyRwLockWriteGuard}; use crate::function::{Args, OptionalArg, OptionalOption, PyFuncArgs}; use crate::obj::objbool; use crate::obj::objint::{self, PyInt, PyIntRef}; @@ -19,13 +18,14 @@ mod decl { IdProtocol, PyCallable, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol, }; use crate::vm::VirtualMachine; + use rustpython_common::rc::PyRc; #[pyclass(name = "chain")] #[derive(Debug)] struct PyItertoolsChain { iterables: Vec, cur_idx: AtomicCell, - cached_iter: RwLock>, + cached_iter: PyRwLock>, } impl PyValue for PyItertoolsChain { @@ -41,7 +41,7 @@ mod decl { PyItertoolsChain { iterables: args.args, cur_idx: AtomicCell::new(0), - cached_iter: RwLock::new(None), + cached_iter: PyRwLock::new(None), } .into_ref_with_type(vm, cls) } @@ -99,7 +99,7 @@ mod decl { PyItertoolsChain { iterables, cur_idx: AtomicCell::new(0), - cached_iter: RwLock::new(None), + cached_iter: PyRwLock::new(None), } .into_ref_with_type(vm, cls) } @@ -159,7 +159,7 @@ mod decl { #[pyclass(name = "count")] #[derive(Debug)] struct PyItertoolsCount { - cur: RwLock, + cur: PyRwLock, step: BigInt, } @@ -188,7 +188,7 @@ mod decl { }; PyItertoolsCount { - cur: RwLock::new(start), + cur: PyRwLock::new(start), step, } .into_ref_with_type(vm, cls) @@ -212,7 +212,7 @@ mod decl { #[derive(Debug)] struct PyItertoolsCycle { iter: PyObjectRef, - saved: RwLock>, + saved: PyRwLock>, index: AtomicCell, } @@ -234,7 +234,7 @@ mod decl { PyItertoolsCycle { iter: iter.clone(), - saved: RwLock::new(Vec::new()), + saved: PyRwLock::new(Vec::new()), index: AtomicCell::new(0), } .into_ref_with_type(vm, cls) @@ -273,7 +273,7 @@ mod decl { #[derive(Debug)] struct PyItertoolsRepeat { object: PyObjectRef, - times: Option>, + times: Option>, } impl PyValue for PyItertoolsRepeat { @@ -292,7 +292,7 @@ mod decl { vm: &VirtualMachine, ) -> PyResult> { let times = match times.into_option() { - Some(int) => Some(RwLock::new(int.as_bigint().clone())), + Some(int) => Some(PyRwLock::new(int.as_bigint().clone())), None => None, }; @@ -675,7 +675,7 @@ mod decl { struct PyItertoolsAccumulate { iterable: PyObjectRef, binop: PyObjectRef, - acc_value: RwLock>, + acc_value: PyRwLock>, } impl PyValue for PyItertoolsAccumulate { @@ -698,7 +698,7 @@ mod decl { PyItertoolsAccumulate { iterable: iter, binop: binop.unwrap_or_else(|| vm.get_none()), - acc_value: RwLock::new(None), + acc_value: PyRwLock::new(None), } .into_ref_with_type(vm, cls) } @@ -734,14 +734,14 @@ mod decl { #[derive(Debug)] struct PyItertoolsTeeData { iterable: PyObjectRef, - values: RwLock>, + values: PyRwLock>, } impl PyItertoolsTeeData { - fn new(iterable: PyObjectRef, vm: &VirtualMachine) -> PyResult> { - Ok(Arc::new(PyItertoolsTeeData { + fn new(iterable: PyObjectRef, vm: &VirtualMachine) -> PyResult> { + Ok(PyRc::new(PyItertoolsTeeData { iterable: get_iter(vm, &iterable)?, - values: RwLock::new(vec![]), + values: PyRwLock::new(vec![]), })) } @@ -757,7 +757,7 @@ mod decl { #[pyclass(name = "tee")] #[derive(Debug)] struct PyItertoolsTee { - tee_data: Arc, + tee_data: PyRc, index: AtomicCell, } @@ -812,7 +812,7 @@ mod decl { #[pymethod(name = "__copy__")] fn copy(&self, vm: &VirtualMachine) -> PyResult { Ok(PyItertoolsTee { - tee_data: Arc::clone(&self.tee_data), + tee_data: PyRc::clone(&self.tee_data), index: AtomicCell::new(self.index.load()), } .into_ref_with_type(vm, Self::class(vm))? @@ -836,7 +836,7 @@ mod decl { #[derive(Debug)] struct PyItertoolsProduct { pools: Vec>, - idxs: RwLock>, + idxs: PyRwLock>, cur: AtomicCell, stop: AtomicCell, } @@ -883,7 +883,7 @@ mod decl { PyItertoolsProduct { pools, - idxs: RwLock::new(vec![0; l]), + idxs: PyRwLock::new(vec![0; l]), cur: AtomicCell::new(l - 1), stop: AtomicCell::new(false), } @@ -920,7 +920,7 @@ mod decl { Ok(res.into_ref(vm).into_object()) } - fn update_idxs(&self, mut idxs: RwLockWriteGuard<'_, Vec>) { + fn update_idxs(&self, mut idxs: PyRwLockWriteGuard<'_, Vec>) { let cur = self.cur.load(); let lst_idx = &self.pools[cur].len() - 1; @@ -948,7 +948,7 @@ mod decl { #[derive(Debug)] struct PyItertoolsCombinations { pool: Vec, - indices: RwLock>, + indices: PyRwLock>, r: AtomicCell, exhausted: AtomicCell, } @@ -981,7 +981,7 @@ mod decl { PyItertoolsCombinations { pool, - indices: RwLock::new((0..r).collect()), + indices: PyRwLock::new((0..r).collect()), r: AtomicCell::new(r), exhausted: AtomicCell::new(r > n), } @@ -1047,7 +1047,7 @@ mod decl { #[derive(Debug)] struct PyItertoolsCombinationsWithReplacement { pool: Vec, - indices: RwLock>, + indices: PyRwLock>, r: AtomicCell, exhausted: AtomicCell, } @@ -1080,7 +1080,7 @@ mod decl { PyItertoolsCombinationsWithReplacement { pool, - indices: RwLock::new(vec![0; r]), + indices: PyRwLock::new(vec![0; r]), r: AtomicCell::new(r), exhausted: AtomicCell::new(n == 0 && r > 0), } @@ -1140,12 +1140,12 @@ mod decl { #[pyclass(name = "permutations")] #[derive(Debug)] struct PyItertoolsPermutations { - pool: Vec, // Collected input iterable - indices: RwLock>, // One index per element in pool - cycles: RwLock>, // One rollover counter per element in the result - result: RwLock>>, // Indexes of the most recently returned result - r: AtomicCell, // Size of result tuple - exhausted: AtomicCell, // Set when the iterator is exhausted + pool: Vec, // Collected input iterable + indices: PyRwLock>, // One index per element in pool + cycles: PyRwLock>, // One rollover counter per element in the result + result: PyRwLock>>, // Indexes of the most recently returned result + r: AtomicCell, // Size of result tuple + exhausted: AtomicCell, // Set when the iterator is exhausted } impl PyValue for PyItertoolsPermutations { @@ -1186,9 +1186,9 @@ mod decl { PyItertoolsPermutations { pool, - indices: RwLock::new((0..n).collect()), - cycles: RwLock::new((0..r).map(|i| n - i).collect()), - result: RwLock::new(None), + indices: PyRwLock::new((0..n).collect()), + cycles: PyRwLock::new((0..r).map(|i| n - i).collect()), + result: PyRwLock::new(None), r: AtomicCell::new(r), exhausted: AtomicCell::new(r > n), } diff --git a/vm/src/stdlib/math.rs b/vm/src/stdlib/math.rs index b0b957e02..4bda69436 100644 --- a/vm/src/stdlib/math.rs +++ b/vm/src/stdlib/math.rs @@ -15,6 +15,7 @@ use crate::obj::objint::{self, PyInt, PyIntRef}; use crate::obj::objtype; use crate::pyobject::{Either, PyObjectRef, PyResult, TypeProtocol}; use crate::vm::VirtualMachine; +use rustpython_common::float_ops; #[cfg(not(target_arch = "wasm32"))] use libc::c_double; @@ -253,7 +254,7 @@ fn math_floor(value: PyObjectRef, vm: &VirtualMachine) -> PyResult { fn math_frexp(value: IntoPyFloat) -> (f64, i32) { let value = value.to_f64(); if value.is_finite() { - let (m, e) = objfloat::ufrexp(value); + let (m, e) = float_ops::ufrexp(value); (m * value.signum(), e) } else { (value, 0) diff --git a/vm/src/stdlib/mod.rs b/vm/src/stdlib/mod.rs index 71ff0d8be..880c1f9f2 100644 --- a/vm/src/stdlib/mod.rs +++ b/vm/src/stdlib/mod.rs @@ -32,6 +32,7 @@ mod string; mod symtable; mod sysconfigdata; #[cfg(not(target_arch = "wasm32"))] +#[cfg(feature = "threading")] mod thread; mod time_module; #[cfg(feature = "rustpython-parser")] @@ -131,6 +132,7 @@ pub fn get_module_inits() -> HashMap { modules.insert("select".to_owned(), Box::new(select::make_module)); #[cfg(feature = "ssl")] modules.insert("_ssl".to_owned(), Box::new(ssl::make_module)); + #[cfg(feature = "threading")] modules.insert("_thread".to_owned(), Box::new(thread::make_module)); #[cfg(not(target_os = "redox"))] modules.insert("zlib".to_owned(), Box::new(zlib::make_module)); diff --git a/vm/src/stdlib/os.rs b/vm/src/stdlib/os.rs index a372ecc75..746e98d48 100644 --- a/vm/src/stdlib/os.rs +++ b/vm/src/stdlib/os.rs @@ -1,4 +1,3 @@ -use parking_lot::RwLock; use std::ffi; use std::fs::File; use std::fs::OpenOptions; @@ -26,6 +25,7 @@ use std::os::unix::io::RawFd; use std::os::windows::io::RawHandle; use super::errno::errors; +use crate::common::cell::PyRwLock; use crate::exceptions::PyBaseExceptionRef; use crate::function::{IntoPyNativeFunc, OptionalArg, PyFuncArgs}; use crate::obj::objbyteinner::PyBytesLike; @@ -726,7 +726,7 @@ impl DirEntryRef { #[pyclass] #[derive(Debug)] struct ScandirIterator { - entries: RwLock, + entries: PyRwLock, exhausted: AtomicCell, mode: OutputMode, } @@ -791,7 +791,7 @@ fn os_scandir(path: OptionalArg, vm: &VirtualMachine) -> PyResult { match fs::read_dir(path.path) { Ok(iter) => Ok(ScandirIterator { - entries: RwLock::new(iter), + entries: PyRwLock::new(iter), exhausted: AtomicCell::new(false), mode: path.mode, } diff --git a/vm/src/stdlib/random.rs b/vm/src/stdlib/random.rs index bbff45667..1cdab8ec3 100644 --- a/vm/src/stdlib/random.rs +++ b/vm/src/stdlib/random.rs @@ -4,6 +4,7 @@ pub(crate) use _random::make_module; #[pymodule] mod _random { + use crate::common::cell::PyMutex; use crate::function::OptionalOption; use crate::obj::objint::PyIntRef; use crate::obj::objtype::PyClassRef; @@ -13,8 +14,6 @@ mod _random { use num_traits::Signed; use rand::{rngs::StdRng, RngCore, SeedableRng}; - use parking_lot::Mutex; - #[derive(Debug)] enum PyRng { Std(Box), @@ -57,7 +56,7 @@ mod _random { #[pyclass(name = "Random")] #[derive(Debug)] struct PyRandom { - rng: Mutex, + rng: PyMutex, } impl PyValue for PyRandom { @@ -71,7 +70,7 @@ mod _random { #[pyslot(new)] fn new(cls: PyClassRef, vm: &VirtualMachine) -> PyResult> { PyRandom { - rng: Mutex::default(), + rng: PyMutex::default(), } .into_ref_with_type(vm, cls) } diff --git a/vm/src/stdlib/socket.rs b/vm/src/stdlib/socket.rs index 25f7ab9da..ad423d083 100644 --- a/vm/src/stdlib/socket.rs +++ b/vm/src/stdlib/socket.rs @@ -1,4 +1,4 @@ -use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard}; +use crate::common::cell::{PyRwLock, PyRwLockReadGuard, PyRwLockWriteGuard}; use std::io::{self, prelude::*}; use std::net::{Ipv4Addr, Shutdown, SocketAddr, ToSocketAddrs}; use std::time::Duration; @@ -62,7 +62,7 @@ pub struct PySocket { kind: AtomicCell, family: AtomicCell, proto: AtomicCell, - sock: RwLock, + sock: PyRwLock, } impl PyValue for PySocket { @@ -75,11 +75,11 @@ pub type PySocketRef = PyRef; #[pyimpl(flags(BASETYPE))] impl PySocket { - fn sock(&self) -> RwLockReadGuard<'_, Socket> { + fn sock(&self) -> PyRwLockReadGuard<'_, Socket> { self.sock.read() } - fn sock_mut(&self) -> RwLockWriteGuard<'_, Socket> { + fn sock_mut(&self) -> PyRwLockWriteGuard<'_, Socket> { self.sock.write() } @@ -89,7 +89,7 @@ impl PySocket { kind: AtomicCell::default(), family: AtomicCell::default(), proto: AtomicCell::default(), - sock: RwLock::new(invalid_sock()), + sock: PyRwLock::new(invalid_sock()), } .into_ref_with_type(vm, cls) } diff --git a/vm/src/stdlib/ssl.rs b/vm/src/stdlib/ssl.rs index 9601e3764..3386df8ce 100644 --- a/vm/src/stdlib/ssl.rs +++ b/vm/src/stdlib/ssl.rs @@ -11,7 +11,7 @@ use crate::pyobject::{ use crate::types::create_type; use crate::VirtualMachine; -use parking_lot::{RwLock, RwLockWriteGuard}; +use crate::common::cell::{PyRwLock, PyRwLockWriteGuard}; use std::convert::TryFrom; use std::ffi::{CStr, CString}; use std::fmt; @@ -230,7 +230,7 @@ fn ssl_rand_pseudo_bytes(n: i32, vm: &VirtualMachine) -> PyResult<(Vec, bool #[pyclass(name = "_SSLContext")] struct PySslContext { - ctx: RwLock, + ctx: PyRwLock, check_hostname: bool, } @@ -248,7 +248,7 @@ impl PyValue for PySslContext { #[pyimpl(flags(BASETYPE))] impl PySslContext { - fn builder(&self) -> RwLockWriteGuard<'_, SslContextBuilder> { + fn builder(&self) -> PyRwLockWriteGuard<'_, SslContextBuilder> { self.ctx.write() } fn exec_ctx(&self, func: F) -> R @@ -308,7 +308,7 @@ impl PySslContext { .map_err(|e| convert_openssl_error(vm, e))?; PySslContext { - ctx: RwLock::new(builder), + ctx: PyRwLock::new(builder), check_hostname, } .into_ref_with_type(vm, cls) @@ -471,10 +471,10 @@ impl PySslContext { Ok(PySslSocket { ctx: zelf, - stream: RwLock::new(Some(stream)), + stream: PyRwLock::new(Some(stream)), socket_type, server_hostname: args.server_hostname, - owner: RwLock::new(args.owner.as_ref().map(PyWeak::downgrade)), + owner: PyRwLock::new(args.owner.as_ref().map(PyWeak::downgrade)), }) } } @@ -507,10 +507,10 @@ struct LoadVerifyLocationsArgs { #[pyclass(name = "_SSLSocket")] struct PySslSocket { ctx: PyRef, - stream: RwLock>>, + stream: PyRwLock>>, socket_type: SslServerOrClient, server_hostname: Option, - owner: RwLock>, + owner: PyRwLock>, } impl fmt::Debug for PySslSocket { diff --git a/vm/src/stdlib/weakref.rs b/vm/src/stdlib/weakref.rs index 35e440af9..6f59eeb6b 100644 --- a/vm/src/stdlib/weakref.rs +++ b/vm/src/stdlib/weakref.rs @@ -7,10 +7,10 @@ use crate::pyobject::PyObjectRef; use crate::vm::VirtualMachine; -use std::sync::Arc; +use rustpython_common::rc::PyRc; fn weakref_getweakrefcount(obj: PyObjectRef) -> usize { - Arc::weak_count(&obj) + PyRc::weak_count(&obj) } fn weakref_getweakrefs(_obj: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef { diff --git a/vm/src/stdlib/winreg.rs b/vm/src/stdlib/winreg.rs index c5a70a7c0..550b99d05 100644 --- a/vm/src/stdlib/winreg.rs +++ b/vm/src/stdlib/winreg.rs @@ -1,5 +1,5 @@ #![allow(non_snake_case)] -use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard}; +use crate::common::cell::{PyRwLock, PyRwLockReadGuard, PyRwLockWriteGuard}; use std::convert::TryInto; use std::io; @@ -16,7 +16,7 @@ use winreg::{enums::RegType, RegKey, RegValue}; #[pyclass] #[derive(Debug)] struct PyHKEY { - key: RwLock, + key: PyRwLock, } type PyHKEYRef = PyRef; @@ -33,15 +33,15 @@ impl PyValue for PyHKEY { impl PyHKEY { fn new(key: RegKey) -> Self { Self { - key: RwLock::new(key), + key: PyRwLock::new(key), } } - fn key(&self) -> RwLockReadGuard<'_, RegKey> { + fn key(&self) -> PyRwLockReadGuard<'_, RegKey> { self.key.read() } - fn key_mut(&self) -> RwLockWriteGuard<'_, RegKey> { + fn key_mut(&self) -> PyRwLockWriteGuard<'_, RegKey> { self.key.write() } diff --git a/vm/src/stdlib/zlib.rs b/vm/src/stdlib/zlib.rs index b7ee1bdce..43feb1cc5 100644 --- a/vm/src/stdlib/zlib.rs +++ b/vm/src/stdlib/zlib.rs @@ -1,3 +1,4 @@ +use crate::common::cell::PyMutex; use crate::exceptions::PyBaseExceptionRef; use crate::function::OptionalArg; use crate::obj::objbyteinner::PyBytesLike; @@ -15,7 +16,6 @@ use flate2::{ }; use libz_sys as libz; -use parking_lot::Mutex; use std::io::Write; // copied from zlibmodule.c (commit 530f506ac91338) @@ -159,19 +159,19 @@ fn zlib_decompressobj( dict.with_ref(|d| decompress.set_dictionary(d).unwrap()); } PyDecompress { - decompress: Mutex::new(decompress), + decompress: PyMutex::new(decompress), eof: AtomicCell::new(false), - unused_data: Mutex::new(PyBytes::new(vec![]).into_ref(vm)), - unconsumed_tail: Mutex::new(PyBytes::new(vec![]).into_ref(vm)), + unused_data: PyMutex::new(PyBytes::new(vec![]).into_ref(vm)), + unconsumed_tail: PyMutex::new(PyBytes::new(vec![]).into_ref(vm)), } } #[pyclass(name = "Decompress")] #[derive(Debug)] struct PyDecompress { - decompress: Mutex, + decompress: PyMutex, eof: AtomicCell, - unused_data: Mutex, - unconsumed_tail: Mutex, + unused_data: PyMutex, + unconsumed_tail: PyMutex, } impl PyValue for PyDecompress { fn class(vm: &VirtualMachine) -> PyClassRef { @@ -359,7 +359,7 @@ fn zlib_compressobj( }; let compress = Compress::new_with_window_bits(Compression::new(level), header, wbits); Ok(PyCompress { - inner: Mutex::new(CompressInner { + inner: PyMutex::new(CompressInner { compress, unconsumed: Vec::new(), }), @@ -375,7 +375,7 @@ struct CompressInner { #[pyclass] #[derive(Debug)] struct PyCompress { - inner: Mutex, + inner: PyMutex, } impl PyValue for PyCompress { diff --git a/vm/src/sysmodule.rs b/vm/src/sysmodule.rs index ec3018e9e..8e8facb6f 100644 --- a/vm/src/sysmodule.rs +++ b/vm/src/sysmodule.rs @@ -1,16 +1,16 @@ -use std::sync::Arc; use std::{env, mem}; use crate::builtins; use crate::frame::FrameRef; use crate::function::{Args, OptionalArg, PyFuncArgs}; use crate::obj::objstr::PyStringRef; -use crate::pyhash::PyHashInfo; use crate::pyobject::{ IntoPyObject, ItemProtocol, PyClassImpl, PyContext, PyObjectRef, PyResult, TypeProtocol, }; use crate::version; use crate::vm::{PySettings, VirtualMachine}; +use rustpython_common::hash::{PyHash, PyUHash}; +use rustpython_common::rc::PyRc; /* * The magic sys module. @@ -110,7 +110,7 @@ impl SysFlags { } fn sys_getrefcount(obj: PyObjectRef) -> usize { - Arc::strong_count(&obj) + PyRc::strong_count(&obj) } fn sys_getsizeof(obj: PyObjectRef) -> usize { @@ -257,6 +257,34 @@ pub fn sysconfigdata_name() -> String { format!("_sysconfigdata_{}_{}_{}", ABIFLAGS, PLATFORM, MULTIARCH) } +#[pystruct_sequence(module = "sys", name = "hash_info")] +#[derive(Debug)] +struct PyHashInfo { + width: usize, + modulus: PyUHash, + inf: PyHash, + nan: PyHash, + imag: PyHash, + algorithm: &'static str, + hash_bits: usize, + seed_bits: usize, +} +impl PyHashInfo { + pub const INFO: Self = { + use rustpython_common::hash::*; + PyHashInfo { + width: BITS, + modulus: MODULUS, + inf: INF, + nan: NAN, + imag: IMAG, + algorithm: ALGO, + hash_bits: HASH_BITS, + seed_bits: SEED_BITS, + } + }; +} + pub fn make_module(vm: &VirtualMachine, module: PyObjectRef, builtins: PyObjectRef) { let ctx = &vm.ctx; diff --git a/vm/src/types.rs b/vm/src/types.rs index a59ccb844..54435411b 100644 --- a/vm/src/types.rs +++ b/vm/src/types.rs @@ -40,10 +40,9 @@ use crate::obj::objweakproxy; use crate::obj::objweakref; use crate::obj::objzip; use crate::pyobject::{PyAttributes, PyContext, PyObject}; -use parking_lot::RwLock; +use rustpython_common::{cell::PyRwLock, rc::PyRc}; use std::mem::MaybeUninit; use std::ptr; -use std::sync::Arc; /// Holder of references to builtin types. #[derive(Debug)] @@ -275,14 +274,16 @@ macro_rules! partially_init { ) => {{ // check all the fields are there but *don't* actually run it if false { - #[allow(invalid_value)] + #[allow(invalid_value, dead_code, unreachable_code)] let _ = {$ty { $($init_field: $init_value,)* - $($uninit_field: ::std::mem::MaybeUninit::uninit().assume_init(),)* + $($uninit_field: unreachable!(),)* }}; } let mut m = ::std::mem::MaybeUninit::<$ty>::uninit(); - $(::std::ptr::write(&mut (*m.as_mut_ptr()).$init_field, $init_value);)* + unsafe { + $(::std::ptr::write(&mut (*m.as_mut_ptr()).$init_field, $init_value);)* + } m }}; } @@ -292,61 +293,64 @@ fn init_type_hierarchy() -> (PyClassRef, PyClassRef) { // and both `type` and `object are instances of `type`. // to produce this circular dependency, we need an unsafe block. // (and yes, this will never get dropped. TODO?) - let (type_type, object_type) = unsafe { + let (type_type, object_type) = { type PyClassObj = PyObject; - type UninitRef = RwLock>>; + type UninitRef = PyRwLock>>; - let type_type: Arc> = Arc::new(partially_init!( + let type_type: PyRc> = PyRc::new(partially_init!( PyObject:: { dict: None, payload: PyClass { name: String::from("type"), bases: vec![], mro: vec![], - subclasses: RwLock::default(), - attributes: RwLock::new(PyAttributes::new()), - slots: RwLock::default(), + subclasses: PyRwLock::default(), + attributes: PyRwLock::new(PyAttributes::new()), + slots: PyRwLock::default(), }, }, Uninit { typ } )); - let object_type: Arc> = Arc::new(partially_init!( + let object_type: PyRc> = PyRc::new(partially_init!( PyObject:: { dict: None, payload: PyClass { name: String::from("object"), bases: vec![], mro: vec![], - subclasses: RwLock::default(), - attributes: RwLock::new(PyAttributes::new()), - slots: RwLock::default(), + subclasses: PyRwLock::default(), + attributes: PyRwLock::new(PyAttributes::new()), + slots: PyRwLock::default(), }, }, Uninit { typ }, )); let object_type_ptr = - Arc::into_raw(object_type) as *mut MaybeUninit as *mut PyClassObj; + PyRc::into_raw(object_type) as *mut MaybeUninit as *mut PyClassObj; let type_type_ptr = - Arc::into_raw(type_type.clone()) as *mut MaybeUninit as *mut PyClassObj; + PyRc::into_raw(type_type.clone()) as *mut MaybeUninit as *mut PyClassObj; - ptr::write( - &mut (*object_type_ptr).typ as *mut RwLock> - as *mut UninitRef, - RwLock::new(type_type.clone()), - ); - ptr::write( - &mut (*type_type_ptr).typ as *mut RwLock> as *mut UninitRef, - RwLock::new(type_type), - ); + unsafe { + ptr::write( + &mut (*object_type_ptr).typ as *mut PyRwLock> + as *mut UninitRef, + PyRwLock::new(type_type.clone()), + ); + ptr::write( + &mut (*type_type_ptr).typ as *mut PyRwLock> + as *mut UninitRef, + PyRwLock::new(type_type), + ); - let type_type = PyClassRef::from_obj_unchecked(Arc::from_raw(type_type_ptr)); - let object_type = PyClassRef::from_obj_unchecked(Arc::from_raw(object_type_ptr)); + let type_type = PyClassRef::from_obj_unchecked(PyRc::from_raw(type_type_ptr)); + let object_type = PyClassRef::from_obj_unchecked(PyRc::from_raw(object_type_ptr)); - (*type_type_ptr).payload.mro = vec![object_type.clone()]; - (*type_type_ptr).payload.bases = vec![object_type.clone()]; + (*type_type_ptr).payload.mro = vec![object_type.clone()]; + (*type_type_ptr).payload.bases = vec![object_type.clone()]; - (type_type, object_type) + (type_type, object_type) + } }; object_type diff --git a/vm/src/vm.rs b/vm/src/vm.rs index c629d8f23..c58486dcc 100644 --- a/vm/src/vm.rs +++ b/vm/src/vm.rs @@ -7,7 +7,6 @@ use std::cell::{Cell, Ref, RefCell}; use std::collections::hash_map::HashMap; use std::collections::hash_set::HashSet; -use std::sync::Arc; use std::{env, fmt}; use arr_macro::arr; @@ -40,7 +39,6 @@ use crate::obj::objobject; use crate::obj::objstr::{PyString, PyStringRef}; use crate::obj::objtuple::PyTuple; use crate::obj::objtype::{self, PyClassRef}; -use crate::pyhash; use crate::pyobject::{ IdProtocol, ItemProtocol, PyContext, PyObject, PyObjectRef, PyResult, PyValue, TryFromObject, TryIntoRef, TypeProtocol, @@ -48,6 +46,7 @@ use crate::pyobject::{ use crate::scope::Scope; use crate::stdlib; use crate::sysmodule; +use rustpython_common::rc::PyRc; // use objects::objects; @@ -58,7 +57,7 @@ use crate::sysmodule; pub struct VirtualMachine { pub builtins: PyObjectRef, pub sys_module: PyObjectRef, - pub ctx: Arc, + pub ctx: PyRc, pub frames: RefCell>, pub wasm_id: Option, pub exceptions: RefCell>, @@ -68,7 +67,7 @@ pub struct VirtualMachine { pub use_tracing: Cell, pub recursion_limit: Cell, pub signal_handlers: Option>>, - pub state: Arc, + pub state: PyRc, pub initialized: bool, } @@ -194,7 +193,7 @@ impl VirtualMachine { let mut vm = VirtualMachine { builtins: builtins.clone(), sys_module: sysmod.clone(), - ctx: Arc::new(ctx), + ctx: PyRc::new(ctx), frames: RefCell::new(vec![]), wasm_id: None, exceptions: RefCell::new(vec![]), @@ -204,7 +203,7 @@ impl VirtualMachine { use_tracing: Cell::new(false), recursion_limit: Cell::new(if cfg!(debug_assertions) { 256 } else { 512 }), signal_handlers: Some(Box::new(signal_handlers)), - state: Arc::new(PyGlobalState { + state: PyRc::new(PyGlobalState { settings, stdlib_inits, frozen, @@ -288,6 +287,7 @@ impl VirtualMachine { } } + #[cfg(feature = "threading")] pub(crate) fn new_thread(&self) -> VirtualMachine { VirtualMachine { builtins: self.builtins.clone(), @@ -753,7 +753,7 @@ impl VirtualMachine { pub fn isinstance(&self, obj: &PyObjectRef, cls: &PyClassRef) -> PyResult { // cpython first does an exact check on the type, although documentation doesn't state that // https://github.com/python/cpython/blob/a24107b04c1277e3c1105f98aff5bfa3a98b33a0/Objects/abstract.c#L2408 - if Arc::ptr_eq(&obj.class().into_object(), cls.as_object()) { + if PyRc::ptr_eq(&obj.class().into_object(), cls.as_object()) { Ok(true) } else { let ret = self.call_method(cls.as_object(), "__instancecheck__", vec![obj.clone()])?; @@ -1406,7 +1406,7 @@ impl VirtualMachine { }) } - pub fn _hash(&self, obj: &PyObjectRef) -> PyResult { + pub fn _hash(&self, obj: &PyObjectRef) -> PyResult { let hash_obj = self.call_method(obj, "__hash__", vec![])?; if let Some(hash_value) = hash_obj.payload_if_subclass::(self) { Ok(hash_value.hash()) diff --git a/wasm/lib/Cargo.lock b/wasm/lib/Cargo.lock deleted file mode 100644 index 9bad7eeba..000000000 --- a/wasm/lib/Cargo.lock +++ /dev/null @@ -1,1019 +0,0 @@ -[[package]] -name = "aho-corasick" -version = "0.6.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "memchr 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "arrayref" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "ascii-canvas" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "atty" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "atty" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", - "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "backtrace" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "backtrace-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "backtrace-sys" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "bit-set" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bit-vec 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "bit-vec" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "bitflags" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "block-buffer" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "byte-tools" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "byteorder" -version = "1.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "cc" -version = "1.0.25" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "cfg-if" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "cloudabi" -version = "0.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "diff" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "digest" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "docopt" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", - "strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "either" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "ena" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "env_logger" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", - "termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "failure" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "failure_derive" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.13 (registry+https://github.com/rust-lang/crates.io-index)", - "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "fake-simd" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "fixedbitset" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "fuchsia-zircon" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "fuchsia-zircon-sys" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "generic-array" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "heck" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "humantime" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "itertools" -version = "0.7.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "itoa" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "js-sys" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "wasm-bindgen 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "lalrpop" -version = "0.15.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "ascii-canvas 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "atty 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", - "digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", - "docopt 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", - "ena 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)", - "lalrpop-snap 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lalrpop-util 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", - "petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", - "sha2 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "string_cache 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", - "term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "lalrpop-snap" -version = "0.15.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "ascii-canvas 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "atty 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", - "ena 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)", - "lalrpop-util 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", - "petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "string_cache 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", - "term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "lalrpop-util" -version = "0.15.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "lazy_static" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "libc" -version = "0.2.43" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "log" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "log" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "memchr" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", - "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "new_debug_unreachable" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "nom" -version = "4.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "memchr 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "num-bigint" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "num-complex" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "num-integer" -version = "0.1.39" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "num-traits" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "ordermap" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "petgraph" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "fixedbitset 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "ordermap 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "phf_generator" -version = "0.7.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "phf_shared 0.7.23 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "phf_shared" -version = "0.7.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "precomputed-hash" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "proc-macro2" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "quick-error" -version = "1.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "quote" -version = "0.6.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rand" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rand_core" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rand_core" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "redox_syscall" -version = "0.1.43" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "redox_termios" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "redox_syscall 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "regex" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "aho-corasick 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", - "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "utf8-ranges 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "regex" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "aho-corasick 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "utf8-ranges 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "regex-syntax" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "regex-syntax" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "regex-syntax" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "rustpython_parser" -version = "0.0.1" -dependencies = [ - "lalrpop 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lalrpop-util 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "num-bigint 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rustpython_vm" -version = "0.1.0" -dependencies = [ - "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "num-bigint 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "num-complex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", - "rustpython_parser 0.0.1", - "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)", - "statrs 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rustpython_wasm" -version = "0.1.0" -dependencies = [ - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "js-sys 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rustpython_parser 0.0.1", - "rustpython_vm 0.1.0", - "wasm-bindgen 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", - "web-sys 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "ryu" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "serde" -version = "1.0.80" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "serde_derive" -version = "1.0.80" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.13 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "serde_json" -version = "1.0.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "sha2" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "block-buffer 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", - "fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "siphasher" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "sourcefile" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "statrs" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "string_cache" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "new_debug_unreachable 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "phf_shared 0.7.23 (registry+https://github.com/rust-lang/crates.io-index)", - "precomputed-hash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", - "string_cache_codegen 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "string_cache_shared 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "string_cache_codegen" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "phf_generator 0.7.23 (registry+https://github.com/rust-lang/crates.io-index)", - "phf_shared 0.7.23 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", - "string_cache_shared 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "string_cache_shared" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "strsim" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "syn" -version = "0.15.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "synstructure" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.13 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "term" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "termcolor" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "wincolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "termion" -version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "thread_local" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "typenum" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "ucd-util" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "unicode-segmentation" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "unicode-xid" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "unreachable" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "utf8-ranges" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "version_check" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "void" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "wasm-bindgen" -version = "0.2.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "wasm-bindgen-macro 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.13 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-shared 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-macro-support 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.13 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-backend 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-shared 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.29" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "wasm-bindgen-webidl" -version = "0.2.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.13 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-backend 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", - "weedle 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "web-sys" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "js-sys 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "sourcefile 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-webidl 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "weedle" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "nom 4.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "winapi" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "winapi-util" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "wincolor" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[metadata] -"checksum aho-corasick 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "68f56c7353e5a9547cbd76ed90f7bb5ffc3ba09d4ea9bd1d8c06c8b1142eeb5a" -"checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee" -"checksum ascii-canvas 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b385d69402821a1c254533a011a312531cbcc0e3e24f19bbb4747a5a2daf37e2" -"checksum atty 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d0fd4c0631f06448cc45a6bbb3b710ebb7ff8ccb96a0800c994afe23a70d5df2" -"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" -"checksum backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "89a47830402e9981c5c41223151efcced65a0510c13097c769cede7efb34782a" -"checksum backtrace-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)" = "c66d56ac8dabd07f6aacdaf633f4b8262f5b3601a810a0dcddffd5c22c69daa0" -"checksum bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d9bf6104718e80d7b26a68fdbacff3481cfc05df670821affc7e9cbc1884400c" -"checksum bit-vec 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "02b4ff8b16e6076c3e14220b39fbc1fabb6737522281a388998046859400895f" -"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" -"checksum block-buffer 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a076c298b9ecdb530ed9d967e74a6027d6a7478924520acddcddc24c1c8ab3ab" -"checksum byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "560c32574a12a89ecd91f5e742165893f86e3ab98d21f8ea548658eb9eef5f40" -"checksum byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "90492c5858dd7d2e78691cfb89f90d273a2800fc11d98f60786e5d87e2f83781" -"checksum cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "f159dfd43363c4d08055a07703eb7a3406b0dac4d0584d96965a3262db3c9d16" -"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4" -"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -"checksum diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "3c2b69f912779fbb121ceb775d74d51e915af17aaebc38d28a592843a2dd0a3a" -"checksum digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "03b072242a8cbaf9c145665af9d250c59af3b958f83ed6824e13533cf76d5b90" -"checksum docopt 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d8acd393692c503b168471874953a2531df0e9ab77d0b6bbc582395743300a4a" -"checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0" -"checksum ena 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cabe5a5078ac8c506d3e4430763b1ba9b609b1286913e7d08e581d1c2de9b7e5" -"checksum env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "afb070faf94c85d17d50ca44f6ad076bce18ae92f0037d350947240a36e9d42e" -"checksum failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6dd377bcc1b1b7ce911967e3ec24fa19c3224394ec05b54aa7b083d498341ac7" -"checksum failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "64c2d913fe8ed3b6c6518eedf4538255b989945c14c2a7d5cbff62a5e2120596" -"checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" -"checksum fixedbitset 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "86d4de0081402f5e88cdac65c8dcdcc73118c1a7a465e2a05f0da05843a8ea33" -"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" -"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" -"checksum generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef25c5683767570c2bbd7deba372926a55eaae9982d7726ee2a1050239d45b9d" -"checksum heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea04fa3ead4e05e51a7c806fc07271fdbde4e246a6c6d1efd52e72230b771b82" -"checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114" -"checksum itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)" = "f58856976b776fedd95533137617a02fb25719f40e7d9b01c7043cd65474f450" -"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b" -"checksum js-sys 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58cfec35fd4a94f3cf357d5cb7da71c71cd52720c2f2a7320090a8db5f06f655" -"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -"checksum lalrpop 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ba451f7bd819b7afc99d4cf4bdcd5a4861e64955ba9680ac70df3a50625ad6cf" -"checksum lalrpop-snap 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)" = "60013fd6be14317d43f47658b1440956a9ca48a9ed0257e0e0a59aac13e43a1f" -"checksum lalrpop-util 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)" = "60c6c48ba857cd700673ce88907cadcdd7e2cd7783ed02378537c5ffd4f6460c" -"checksum lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7" -"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d" -"checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" -"checksum log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fcce5fa49cc693c312001daf1d13411c4a5283796bac1084299ea3e567113f" -"checksum memchr 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4b3629fe9fdbff6daa6c33b90f7c08355c1aca05a3d01fa8063b822fcf185f3b" -"checksum new_debug_unreachable 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0cdc457076c78ab54d5e0d6fa7c47981757f1e34dc39ff92787f217dede586c4" -"checksum nom 4.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9c349f68f25f596b9f44cf0e7c69752a5c633b0550c3ff849518bfba0233774a" -"checksum num-bigint 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "10b8423ea72ec64751198856a853e07b37087cfc9b53a87ecb19bff67b6d1320" -"checksum num-complex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "107b9be86cd2481930688277b675b0114578227f034674726605b8a482d8baf8" -"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea" -"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" -"checksum ordermap 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063" -"checksum petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)" = "9c3659d1ee90221741f65dd128d9998311b0e40c5d3c23a62445938214abce4f" -"checksum phf_generator 0.7.23 (registry+https://github.com/rust-lang/crates.io-index)" = "03dc191feb9b08b0dc1330d6549b795b9d81aec19efe6b4a45aec8d4caee0c4b" -"checksum phf_shared 0.7.23 (registry+https://github.com/rust-lang/crates.io-index)" = "b539898d22d4273ded07f64a05737649dc69095d92cb87c7097ec68e3f150b93" -"checksum precomputed-hash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" -"checksum proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)" = "3d7b7eaaa90b4a90a932a9ea6666c95a389e424eff347f0f793979289429feee" -"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" -"checksum quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "dd636425967c33af890042c483632d33fa7a18f19ad1d7ea72e8998c6ef8dea5" -"checksum rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e464cd887e869cddcae8792a4ee31d23c7edd516700695608f5b98c67ee0131c" -"checksum rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1961a422c4d189dfb50ffa9320bf1f2a9bd54ecb92792fb9477f99a1045f3372" -"checksum rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0905b6b7079ec73b314d4c748701f6931eb79fd97c668caa3f1899b22b32c6db" -"checksum redox_syscall 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "679da7508e9a6390aeaf7fbd02a800fdc64b73fe2204dd2c8ae66d22d9d5ad5d" -"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" -"checksum regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9329abc99e39129fcceabd24cf5d85b4671ef7c29c50e972bc5afe32438ec384" -"checksum regex 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2069749032ea3ec200ca51e4a31df41759190a88edca0d2d86ee8bedf7073341" -"checksum regex-syntax 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8e931c58b93d86f080c734bfd2bce7dd0079ae2331235818133c8be7f422e20e" -"checksum regex-syntax 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7d707a4fa2637f2dca2ef9fd02225ec7661fe01a53623c1e6515b6916511f7a7" -"checksum regex-syntax 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "747ba3b235651f6e2f67dfa8bcdcd073ddb7c243cb21c442fc12395dfcac212d" -"checksum rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "bcfe5b13211b4d78e5c2cadfebd7769197d95c639c35a50057eb4c05de811395" -"checksum ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7153dd96dade874ab973e098cb62fcdbb89a03682e46b144fd09550998d4a4a7" -"checksum serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)" = "15c141fc7027dd265a47c090bf864cf62b42c4d228bbcf4e51a0c9e2b0d3f7ef" -"checksum serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)" = "225de307c6302bec3898c51ca302fc94a7a1697ef0845fcee6448f33c032249c" -"checksum serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)" = "43344e7ce05d0d8280c5940cabb4964bea626aa58b1ec0e8c73fa2a8512a38ce" -"checksum sha2 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9eb6be24e4c23a84d7184280d2722f7f2731fcdd4a9d886efbfe4413e4847ea0" -"checksum siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac" -"checksum sourcefile 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf77cb82ba8453b42b6ae1d692e4cdc92f9a47beaf89a847c8be83f4e328ad3" -"checksum statrs 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "10102ac8d55e35db2b3fafc26f81ba8647da2e15879ab686a67e6d19af2685e8" -"checksum string_cache 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "25d70109977172b127fe834e5449e5ab1740b9ba49fa18a2020f509174f25423" -"checksum string_cache_codegen 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1eea1eee654ef80933142157fdad9dd8bc43cf7c74e999e369263496f04ff4da" -"checksum string_cache_shared 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b1884d1bc09741d466d9b14e6d37ac89d6909cbcac41dd9ae982d4d063bbedfc" -"checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694" -"checksum syn 0.15.13 (registry+https://github.com/rust-lang/crates.io-index)" = "7b4439ee8325b4e4b57e59309c3724c9a4478eaeb4eb094b6f3fac180a3b2876" -"checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" -"checksum term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "fa63644f74ce96fbeb9b794f66aff2a52d601cbd5e80f4b97123e3899f4570f1" -"checksum termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4096add70612622289f2fdcdbd5086dc81c1e2675e6ae58d6c4f62a16c6d7f2f" -"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" -"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" -"checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169" -"checksum ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd2be2d6639d0f8fe6cdda291ad456e23629558d466e2789d2c3e9892bda285d" -"checksum unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "aa6024fc12ddfd1c6dbc14a80fa2324d4568849869b779f6bd37e5e4c03344d1" -"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" -"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" -"checksum utf8-ranges 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd70f467df6810094968e2fce0ee1bd0e87157aceb026a8c083bcf5e25b9efe4" -"checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" -"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" -"checksum wasm-bindgen 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)" = "91f95b8f30407b9ca0c2de157281d3828bbed1fc1f55bea6eb54f40c52ec75ec" -"checksum wasm-bindgen-backend 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)" = "ab7c242ebcb45bae45340986c48d1853eb2c1c52ff551f7724951b62a2c51429" -"checksum wasm-bindgen-macro 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)" = "6e353f83716dec9a3597b5719ef88cb6c9e461ec16528f38aa023d3224b4e569" -"checksum wasm-bindgen-macro-support 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)" = "3cc90b65fe69c3dd5a09684517dc79f42b847baa2d479c234d125e0a629d9b0a" -"checksum wasm-bindgen-shared 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)" = "a71a37df4f5845025f96f279d20bbe5b19cbcb77f5410a3a90c6c544d889a162" -"checksum wasm-bindgen-webidl 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)" = "b064b8b2336b5a6bf5f31bc95fc1310842395df29877d910cb6f8f791070f319" -"checksum web-sys 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7d7c588c2e5a091bc4532c5a87032955f9133b644e868b54d08ead0185dcc5b9" -"checksum weedle 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "26a4c67f132386d965390b8a734d5d10adbcd30eb5cc74bd9229af8b83f10044" -"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" -"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" -"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" -"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -"checksum winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "afc5508759c5bf4285e61feb862b6083c8480aec864fa17a81fdec6f69b461ab" -"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -"checksum wincolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "561ed901ae465d6185fa7864d63fbd5720d0ef718366c9a4dc83cf6170d7e9ba" diff --git a/wasm/lib/Cargo.toml b/wasm/lib/Cargo.toml index e9be7798d..9f74c5a98 100644 --- a/wasm/lib/Cargo.toml +++ b/wasm/lib/Cargo.toml @@ -17,7 +17,8 @@ freeze-stdlib = ["rustpython-vm/freeze-stdlib"] [dependencies] rustpython-compiler = { path = "../../compiler" } rustpython-parser = { path = "../../parser" } -rustpython-vm = { path = "../../vm" } +# no threading feature for rustpython-vm -- doesn't much matter anyway, but it might be more optimized +rustpython-vm = { path = "../../vm", default-features = false, features = ["compile-parse"] } cfg-if = "0.1.2" wasm-bindgen = "0.2" wasm-bindgen-futures = "0.3" @@ -26,6 +27,8 @@ serde = "1.0" js-sys = "0.3" futures = "0.1" generational-arena = "0.2" +# make parking_lot use wasm-bingden for instant +parking_lot = { version = "0.11", features = ["wasm-bindgen"] } [dependencies.web-sys] version = "0.3" diff --git a/wasm/lib/src/browser_module.rs b/wasm/lib/src/browser_module.rs index a58d3f11b..d3b14fa20 100644 --- a/wasm/lib/src/browser_module.rs +++ b/wasm/lib/src/browser_module.rs @@ -1,10 +1,10 @@ use futures::Future; use js_sys::Promise; -use std::sync::Arc; use wasm_bindgen::prelude::*; use wasm_bindgen::JsCast; use wasm_bindgen_futures::{future_to_promise, JsFuture}; +use rustpython_vm::common::rc::PyRc; use rustpython_vm::function::{OptionalArg, PyFuncArgs}; use rustpython_vm::import::import_file; use rustpython_vm::obj::{objdict::PyDictRef, objstr::PyStringRef, objtype::PyClassRef}; @@ -377,7 +377,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef { } pub fn setup_browser_module(vm: &mut VirtualMachine) { - let state = Arc::get_mut(&mut vm.state).unwrap(); + let state = PyRc::get_mut(&mut vm.state).unwrap(); state .stdlib_inits .insert("_browser".to_owned(), Box::new(make_module)); diff --git a/wasm/lib/src/js_module.rs b/wasm/lib/src/js_module.rs index 9e39e7296..d84a8cadd 100644 --- a/wasm/lib/src/js_module.rs +++ b/wasm/lib/src/js_module.rs @@ -1,11 +1,11 @@ use js_sys::{Array, Object, Reflect}; +use rustpython_vm::common::rc::PyRc; use rustpython_vm::exceptions::PyBaseExceptionRef; use rustpython_vm::function::Args; use rustpython_vm::obj::{objfloat::PyFloatRef, objstr::PyStringRef, objtype::PyClassRef}; use rustpython_vm::pyobject::{PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject}; use rustpython_vm::types::create_type; use rustpython_vm::VirtualMachine; -use std::sync::Arc; use wasm_bindgen::{prelude::*, JsCast}; #[wasm_bindgen(inline_js = " @@ -259,7 +259,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef { } pub fn setup_js_module(vm: &mut VirtualMachine) { - let state = Arc::get_mut(&mut vm.state).unwrap(); + let state = PyRc::get_mut(&mut vm.state).unwrap(); state .stdlib_inits .insert("_js".to_owned(), Box::new(make_module)); diff --git a/wasm/lib/src/vm_class.rs b/wasm/lib/src/vm_class.rs index afc6bb1a8..7e20a2bff 100644 --- a/wasm/lib/src/vm_class.rs +++ b/wasm/lib/src/vm_class.rs @@ -1,12 +1,12 @@ use std::cell::RefCell; use std::collections::HashMap; use std::rc::{Rc, Weak}; -use std::sync::Arc; use js_sys::{Object, TypeError}; use wasm_bindgen::prelude::*; use rustpython_compiler::compile; +use rustpython_vm::common::rc::{PyRc, PyWeak}; use rustpython_vm::pyobject::{ItemProtocol, PyObject, PyObjectPayload, PyObjectRef, PyValue}; use rustpython_vm::scope::{NameProtocol, Scope}; use rustpython_vm::{InitParameter, PySettings, VirtualMachine}; @@ -39,7 +39,7 @@ impl StoredVirtualMachine { js_module::setup_js_module(&mut vm); if inject_browser_module { - Arc::get_mut(&mut vm.state).unwrap().stdlib_inits.insert( + PyRc::get_mut(&mut vm.state).unwrap().stdlib_inits.insert( "_window".to_owned(), Box::new(|vm| { py_module!(vm, "_window", { @@ -177,9 +177,9 @@ impl WASMVirtualMachine { pub(crate) fn push_held_rc( &self, obj: PyObjectRef, - ) -> Result>, JsValue> { + ) -> Result>, JsValue> { self.with(|stored_vm| { - let weak = std::sync::Arc::downgrade(&obj); + let weak = PyRc::downgrade(&obj); stored_vm.held_objects.borrow_mut().push(obj); weak })