From a0881856128d54ba8a60371954724de074f7950d Mon Sep 17 00:00:00 2001 From: Shunsuke Shibayama Date: Sun, 16 Jun 2024 21:30:11 +0900 Subject: [PATCH] feat: support slice --- Cargo.lock | 532 +++++++++++++++++++++++++++----------- Cargo.toml | 6 +- crates/py2erg/convert.rs | 80 ++++-- crates/py2erg/gen_decl.rs | 24 +- src/analyze.rs | 70 +++-- src/copy.rs | 5 +- src/lib.rs | 2 +- src/main.rs | 2 +- tests/list.py | 10 + tests/test.py | 10 - tests/test.rs | 7 +- 11 files changed, 539 insertions(+), 209 deletions(-) create mode 100644 tests/list.py diff --git a/Cargo.lock b/Cargo.lock index 6127a15..b53f14a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,9 +10,9 @@ checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" [[package]] name = "addr2line" -version = "0.21.0" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" dependencies = [ "gimli", ] @@ -37,21 +37,21 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.81" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "backtrace" -version = "0.3.69" +version = "0.3.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" dependencies = [ "addr2line", "cc", @@ -79,11 +79,17 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + [[package]] name = "cc" -version = "1.0.90" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" [[package]] name = "cfg-if" @@ -105,28 +111,39 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" [[package]] name = "derive_more" -version = "0.99.17" +version = "0.99.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" dependencies = [ "convert_case", "proc-macro2", "quote", "rustc_version", - "syn 1.0.109", + "syn 2.0.66", +] + +[[package]] +name = "displaydoc" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", ] [[package]] name = "either" -version = "1.10.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" +checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" [[package]] name = "els" -version = "0.1.48-nightly.2" +version = "0.1.51-nightly.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1160cfdc48996a3f0f1e8e5b2d060e48ab7245e3931eef154fe0afc4de6d55e" +checksum = "b04192697a66741e236778ae1e969ee96a1d8b6021869bd818ca367f05342885" dependencies = [ "erg_common", "erg_compiler", @@ -138,9 +155,9 @@ dependencies = [ [[package]] name = "erg_common" -version = "0.6.36-nightly.2" +version = "0.6.39-nightly.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f19dd94255e83e016cd6d7cd18e99e9c927e2144cf9d17e759271c40c6cf1dcd" +checksum = "0bd7174688ef70c26945be145d53dc768c91a51aa5e42ddbea1584f0c673c0a7" dependencies = [ "backtrace-on-stack-overflow", "erg_proc_macros", @@ -150,9 +167,9 @@ dependencies = [ [[package]] name = "erg_compiler" -version = "0.6.36-nightly.2" +version = "0.6.39-nightly.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4712faf4c949016d752e7d697dab1df44043eaf94bea5a2ada73b1ab70dfe0" +checksum = "2859dd10734790f7a7f11f947b3160f0a24a6e349890b67930ab00f2c9d7f9e1" dependencies = [ "erg_common", "erg_parser", @@ -160,9 +177,9 @@ dependencies = [ [[package]] name = "erg_parser" -version = "0.6.36-nightly.2" +version = "0.6.39-nightly.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "791e826192978d665e46aa30aa7330ef470b90e6e5ebe38c2b32a2a4141bc919" +checksum = "fb6d9dacfdeda2e2a3ef7aa0015fa1cae55f43d4f3dfcb355f58ad124ad0656a" dependencies = [ "erg_common", "erg_proc_macros", @@ -171,9 +188,9 @@ dependencies = [ [[package]] name = "erg_proc_macros" -version = "0.6.36-nightly.2" +version = "0.6.39-nightly.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "119857fa1bb184c6b2adba2e3b2a71797f6c7865bc6d4fdddac988fda9e55b77" +checksum = "d0cad59335dc9fb5888062993597e124e3f25413040ced1bb3e6ac6ddd2f3dba" dependencies = [ "quote", "syn 1.0.109", @@ -199,9 +216,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.12" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "libc", @@ -210,27 +227,147 @@ dependencies = [ [[package]] name = "gimli" -version = "0.28.1" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] name = "hashbrown" -version = "0.14.3" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" dependencies = [ "ahash", ] +[[package]] +name = "icu_collections" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locid" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_locid_transform" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_locid_transform_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locid_transform_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e" + +[[package]] +name = "icu_normalizer" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "utf16_iter", + "utf8_iter", + "write16", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516" + +[[package]] +name = "icu_properties" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f8ac670d7422d7f76b32e17a5db556510825b29ec9154f235977c9caba61036" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locid_transform", + "icu_properties_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569" + +[[package]] +name = "icu_provider" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_provider_macros", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_provider_macros" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + [[package]] name = "idna" -version = "0.5.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +checksum = "4716a3a0933a1d01c2f72450e89596eb51dd34ef3c211ccd875acdf1f8fe47ed" dependencies = [ - "unicode-bidi", - "unicode-normalization", + "icu_normalizer", + "icu_properties", + "smallvec", + "utf8_iter", ] [[package]] @@ -242,7 +379,7 @@ dependencies = [ "Inflector", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.66", ] [[package]] @@ -256,9 +393,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "lalrpop-util" @@ -268,9 +405,9 @@ checksum = "507460a910eb7b32ee961886ff48539633b788a36b65692b95f225b844c82553" [[package]] name = "libc" -version = "0.2.153" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "libm" @@ -278,11 +415,17 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +[[package]] +name = "litemap" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "643cb0b8d4fcc284004d5fd0d67ccf61dfffadb7f75e1e71bc420f4688a3a704" + [[package]] name = "lock_api" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", @@ -300,7 +443,7 @@ version = "0.93.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9be6e9c7e2d18f651974370d7aff703f9513e0df6e464fd795660edc77e6ca51" dependencies = [ - "bitflags", + "bitflags 1.3.2", "serde", "serde_json", "serde_repr", @@ -309,9 +452,9 @@ dependencies = [ [[package]] name = "malachite" -version = "0.4.5" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53ff327de42075f680ba15c5cb3c417687eb7241ce2063a91d0186ce5c5e77ee" +checksum = "7f65155c1c6ca06b3182b8c9a92b531eabf83aa2ac23fe1720672e02280d10c3" dependencies = [ "malachite-base", "malachite-nz", @@ -320,9 +463,9 @@ dependencies = [ [[package]] name = "malachite-base" -version = "0.4.5" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e960ee0e7e1b8eec9229f5b20d6b191762574225144ea638eb961d065c97b55d" +checksum = "a45b2c0c7a8e98471a785106e2eca885f32854287b767266eb6606ae9b80562a" dependencies = [ "hashbrown", "itertools", @@ -345,9 +488,9 @@ dependencies = [ [[package]] name = "malachite-nz" -version = "0.4.5" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "770aaf1a4d59a82ed3d8644eb66aff7492a6dd7476def275a922d04d77ca8e57" +checksum = "62c96d099d47d6fedf0b2d51c66488eac37a2b060ea752ecb46b6e8d53dab411" dependencies = [ "itertools", "libm", @@ -356,9 +499,9 @@ dependencies = [ [[package]] name = "malachite-q" -version = "0.4.5" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33a9dfca114f6b582595990ccfc287cace633aa95f890ade5b1fc099b7175d3b" +checksum = "d5d8768a4cd2d9bb1fbb48bba1d376fc8b605451d89e455ea71f04d215236023" dependencies = [ "itertools", "malachite-base", @@ -367,9 +510,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.7.1" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "memoffset" @@ -382,9 +525,9 @@ dependencies = [ [[package]] name = "miniz_oxide" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" dependencies = [ "adler", ] @@ -406,7 +549,7 @@ version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f3790c00a0150112de0f4cd161e3d7fc4b2d8a5542ffc35f099a2562aecb35c" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cc", "cfg-if", "libc", @@ -424,18 +567,18 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] [[package]] name = "object" -version = "0.32.2" +version = "0.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" dependencies = [ "memchr", ] @@ -448,9 +591,9 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "parking_lot" -version = "0.12.1" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" dependencies = [ "lock_api", "parking_lot_core", @@ -458,9 +601,9 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.9" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", @@ -471,9 +614,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.14" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] name = "percent-encoding" @@ -527,9 +670,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.79" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" dependencies = [ "unicode-ident", ] @@ -558,9 +701,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.35" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -597,18 +740,18 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.4.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +checksum = "c82cf8cff14456045f55ec4241383baeff27af886adb72ffb2162f99911de0fd" dependencies = [ - "bitflags", + "bitflags 2.5.0", ] [[package]] name = "rustc-demangle" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] name = "rustc-hash" @@ -628,7 +771,7 @@ dependencies = [ [[package]] name = "rustpython-ast" version = "0.3.1" -source = "git+https://github.com/RustPython/Parser#9ce55aefdeb35e2f706ce0b02d5a2dfe6295fc57" +source = "git+https://github.com/RustPython/Parser#51b5f80ae3080dfec2db815a299a69873fb9ca65" dependencies = [ "is-macro", "malachite-bigint", @@ -639,7 +782,7 @@ dependencies = [ [[package]] name = "rustpython-parser" version = "0.3.1" -source = "git+https://github.com/RustPython/Parser#9ce55aefdeb35e2f706ce0b02d5a2dfe6295fc57" +source = "git+https://github.com/RustPython/Parser#51b5f80ae3080dfec2db815a299a69873fb9ca65" dependencies = [ "anyhow", "is-macro", @@ -662,7 +805,7 @@ dependencies = [ [[package]] name = "rustpython-parser-core" version = "0.3.1" -source = "git+https://github.com/RustPython/Parser#9ce55aefdeb35e2f706ce0b02d5a2dfe6295fc57" +source = "git+https://github.com/RustPython/Parser#51b5f80ae3080dfec2db815a299a69873fb9ca65" dependencies = [ "is-macro", "memchr", @@ -672,7 +815,7 @@ dependencies = [ [[package]] name = "rustpython-parser-vendored" version = "0.3.1" -source = "git+https://github.com/RustPython/Parser#9ce55aefdeb35e2f706ce0b02d5a2dfe6295fc57" +source = "git+https://github.com/RustPython/Parser#51b5f80ae3080dfec2db815a299a69873fb9ca65" dependencies = [ "memchr", "once_cell", @@ -680,9 +823,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "scopeguard" @@ -692,35 +835,35 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "semver" -version = "1.0.22" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.197" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.197" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.66", ] [[package]] name = "serde_json" -version = "1.0.114" +version = "1.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" dependencies = [ "itoa", "ryu", @@ -729,13 +872,13 @@ dependencies = [ [[package]] name = "serde_repr" -version = "0.1.18" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b2e6b945e9d3df726b65d6ee24060aff8e3533d431f677a9695db04eff9dfdb" +checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.66", ] [[package]] @@ -746,9 +889,15 @@ checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" [[package]] name = "smallvec" -version = "1.13.1" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "static_assertions" @@ -769,15 +918,26 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.52" +version = "2.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] +[[package]] +name = "synstructure" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + [[package]] name = "thread_local" version = "1.1.8" @@ -798,20 +958,15 @@ dependencies = [ ] [[package]] -name = "tinyvec" -version = "1.6.0" +name = "tinystr" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" dependencies = [ - "tinyvec_macros", + "displaydoc", + "zerovec", ] -[[package]] -name = "tinyvec_macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" - [[package]] name = "unic-char-property" version = "0.9.0" @@ -864,32 +1019,17 @@ dependencies = [ "unic-common", ] -[[package]] -name = "unicode-bidi" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" - [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" -[[package]] -name = "unicode-normalization" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" -dependencies = [ - "tinyvec", -] - [[package]] name = "unicode-width" -version = "0.1.11" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" +checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" [[package]] name = "unicode-xid" @@ -921,9 +1061,9 @@ dependencies = [ [[package]] name = "url" -version = "2.5.0" +version = "2.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +checksum = "f7c25da092f0a868cdf09e8674cd3b7ef3a7d92a24253e663a2fb85e2496de56" dependencies = [ "form_urlencoded", "idna", @@ -931,6 +1071,18 @@ dependencies = [ "serde", ] +[[package]] +name = "utf16_iter" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + [[package]] name = "version_check" version = "0.9.4" @@ -945,13 +1097,14 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "windows-targets" -version = "0.48.5" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", + "windows_i686_gnullvm", "windows_i686_msvc", "windows_x86_64_gnu", "windows_x86_64_gnullvm", @@ -960,62 +1113,147 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.48.5" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" [[package]] name = "windows_aarch64_msvc" -version = "0.48.5" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" [[package]] name = "windows_i686_gnu" -version = "0.48.5" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" [[package]] name = "windows_i686_msvc" -version = "0.48.5" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" [[package]] name = "windows_x86_64_gnu" -version = "0.48.5" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" [[package]] name = "windows_x86_64_gnullvm" -version = "0.48.5" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" [[package]] name = "windows_x86_64_msvc" -version = "0.48.5" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" + +[[package]] +name = "write16" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" + +[[package]] +name = "writeable" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" + +[[package]] +name = "yoke" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c5b1314b079b0930c31e3af543d8ee1757b1951ae1e1565ec704403a7240ca5" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28cc31741b18cb6f1d5ff12f5b7523e3d6eb0852bbbad19d73905511d9849b95" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", + "synstructure", +] [[package]] name = "zerocopy" -version = "0.7.32" +version = "0.7.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.32" +version = "0.7.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + +[[package]] +name = "zerofrom" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ec111ce797d0e0784a1116d0ddcdbea84322cd79e5d5ad173daeba4f93ab55" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ea7b4a3637ea8669cedf0f1fd5c286a17f3de97b8dd5a70a6c167a1730e63a5" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", + "synstructure", +] + +[[package]] +name = "zerovec" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb2cc8827d6c0994478a15c53f374f46fbd41bea663d809b14744bc42e6b109c" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +checksum = "97cf56601ee5052b4417d90c8755c6683473c926039908196cf35d99f893ebe7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.66", ] diff --git a/Cargo.toml b/Cargo.toml index d519a7d..2420811 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,9 +22,9 @@ edition = "2021" repository = "https://github.com/mtshiba/pylyzer" [workspace.dependencies] -erg_common = { version = "0.6.36-nightly.2", features = ["py_compat", "els"] } -erg_compiler = { version = "0.6.36-nightly.2", features = ["py_compat", "els"] } -els = { version = "0.1.48-nightly.2", features = ["py_compat"] } +erg_common = { version = "0.6.39-nightly.0", features = ["py_compat", "els"] } +erg_compiler = { version = "0.6.39-nightly.0", features = ["py_compat", "els"] } +els = { version = "0.1.51-nightly.0", features = ["py_compat"] } # rustpython-parser = { version = "0.3.0", features = ["all-nodes-with-ranges", "location"] } # rustpython-ast = { version = "0.3.0", features = ["all-nodes-with-ranges", "location"] } rustpython-parser = { git = "https://github.com/RustPython/Parser", version = "0.3.1", features = ["all-nodes-with-ranges", "location"] } diff --git a/crates/py2erg/convert.rs b/crates/py2erg/convert.rs index e56221d..2cd9b02 100644 --- a/crates/py2erg/convert.rs +++ b/crates/py2erg/convert.rs @@ -8,15 +8,15 @@ use erg_common::traits::{Locational, Stream}; use erg_common::{log, set}; use erg_compiler::artifact::IncompleteArtifact; use erg_compiler::erg_parser::ast::{ - Accessor, Args, List, BinOp, Block, ClassAttr, ClassAttrs, ClassDef, ConstAccessor, ConstArgs, + Accessor, Args, BinOp, Block, ClassAttr, ClassAttrs, ClassDef, ConstAccessor, ConstArgs, ConstAttribute, ConstDict, ConstExpr, ConstKeyValue, ConstPosArg, Decorator, Def, DefBody, DefId, DefaultParamSignature, Dict, Dummy, Expr, Identifier, KeyValue, KwArg, Lambda, - LambdaSignature, Literal, Methods, Module, NonDefaultParamSignature, NormalList, NormalDict, - NormalRecord, NormalSet, NormalTuple, ParamPattern, ParamTySpec, Params, PosArg, - PreDeclTypeSpec, ReDef, Record, RecordAttrs, Set, Signature, SubrSignature, SubrTypeSpec, - Tuple, TupleTypeSpec, TypeAscription, TypeBoundSpecs, TypeSpec, TypeSpecWithOp, UnaryOp, - VarName, VarPattern, VarRecordAttr, VarRecordAttrs, VarRecordPattern, VarSignature, - VisModifierSpec, ListComprehension, SetComprehension, + LambdaSignature, List, ListComprehension, Literal, Methods, Module, NonDefaultParamSignature, + NormalDict, NormalList, NormalRecord, NormalSet, NormalTuple, ParamPattern, ParamTySpec, + Params, PosArg, PreDeclTypeSpec, ReDef, Record, RecordAttrs, Set, SetComprehension, Signature, + SubrSignature, SubrTypeSpec, Tuple, TupleTypeSpec, TypeAscription, TypeBoundSpecs, TypeSpec, + TypeSpecWithOp, UnaryOp, VarName, VarPattern, VarRecordAttr, VarRecordAttrs, VarRecordPattern, + VarSignature, VisModifierSpec, }; use erg_compiler::erg_parser::desugar::Desugarer; use erg_compiler::erg_parser::token::{Token, TokenKind, COLON, DOT, EQUAL}; @@ -102,6 +102,7 @@ fn escape_name(name: String) -> String { "bool" => "Bool".into(), "list" => "GenericList".into(), "bytes" => "Bytes".into(), + "bytearray" => "ByteArray!".into(), // "range" => "GenericRange".into(), "dict" => "GenericDict".into(), "set" => "GenericSet".into(), @@ -453,7 +454,9 @@ impl ASTConverter { fn convert_params(&mut self, params: Arguments) -> Params { #[allow(clippy::type_complexity)] - fn split_args(params: Arguments) -> (Vec, Option, Vec<(Arg, py_ast::Expr)>, Option) { + fn split_args( + params: Arguments, + ) -> (Vec, Option, Vec<(Arg, py_ast::Expr)>, Option) { let mut args = Vec::new(); let mut with_defaults = Vec::new(); let var_args = params.vararg.map(|x| *x); @@ -796,7 +799,10 @@ impl ASTConverter { global, Identifier::private("List!".into()), )); - TypeSpec::poly(acc, ConstArgs::new(vec![elem_t, len], None, vec![], None, None)) + TypeSpec::poly( + acc, + ConstArgs::new(vec![elem_t, len], None, vec![], None, None), + ) } "dict" => { let py_ast::Expr::Tuple(mut tuple) = args else { @@ -924,7 +930,11 @@ impl ASTConverter { }; let (line_end, c_end) = ( expr_range.end.unwrap_or(expr_range.start).row.get(), - expr_range.end.unwrap_or(expr_range.start).column.to_zero_indexed(), + expr_range + .end + .unwrap_or(expr_range.start) + .column + .to_zero_indexed(), ); let l_brace = Token::new( l_kind, @@ -1168,7 +1178,13 @@ impl ASTConverter { .next() .map(|ex| self.convert_expr(ex)); let generators = vec![(ident, iter)]; - let arr = Expr::List(List::Comprehension(ListComprehension::new(l_sqbr, r_sqbr, Some(layout), generators, guard))); + let arr = Expr::List(List::Comprehension(ListComprehension::new( + l_sqbr, + r_sqbr, + Some(layout), + generators, + guard, + ))); Self::mutate_expr(arr) } py_ast::Expr::Set(set) => { @@ -1199,7 +1215,13 @@ impl ASTConverter { .next() .map(|ex| self.convert_expr(ex)); let generators = vec![(ident, iter)]; - Expr::Set(Set::Comprehension(SetComprehension::new(l_brace, r_brace, Some(layout), generators, guard))) + Expr::Set(Set::Comprehension(SetComprehension::new( + l_brace, + r_brace, + Some(layout), + generators, + guard, + ))) // Self::mutate_expr(set) } py_ast::Expr::Dict(dict) => { @@ -1235,6 +1257,24 @@ impl ASTConverter { ); method.call1(self.convert_expr(*subs.slice)) } + py_ast::Expr::Slice(slice) => { + let loc = slice.location(); + let start = slice.lower.map(|ex| self.convert_expr(*ex)); + let stop = slice.upper.map(|ex| self.convert_expr(*ex)); + let step = slice.step.map(|ex| self.convert_expr(*ex)); + let mut args = Args::empty(); + if let Some(start) = start { + args.push_pos(PosArg::new(start)); + } + if let Some(stop) = stop { + args.push_pos(PosArg::new(stop)); + } + if let Some(step) = step { + args.push_pos(PosArg::new(step)); + } + let slice = self.convert_ident("slice".to_string(), loc); + slice.call(args).into() + } _other => { log!(err "unimplemented: {:?}", _other); Expr::Dummy(Dummy::new(None, vec![])) @@ -1302,14 +1342,18 @@ impl ASTConverter { init_def.ln_end().unwrap_or(0), init_def.col_end().unwrap_or(0), ); - let Signature::Subr(sig) = init_def.sig else { unreachable!() }; + let Signature::Subr(sig) = init_def.sig else { + unreachable!() + }; let mut fields = vec![]; let mut params = vec![]; for chunk in init_def.body.block { #[allow(clippy::single_match)] match chunk { Expr::ReDef(redef) => { - let Accessor::Attr(attr) = redef.attr else { continue; }; + let Accessor::Attr(attr) = redef.attr else { + continue; + }; // if `self.foo == ...` if attr.obj.get_name().map(|s| &s[..]) == Some("self") { let (param_typ_name, arg_typ_name) = if let Some(t_spec_op) = sig @@ -1517,7 +1561,13 @@ impl ASTConverter { let class_as_expr = Expr::Accessor(Accessor::Ident(ident)); let (base_type, attrs) = self.extract_method(body, inherit); self.block_id_counter += 1; - let methods = Methods::new(DefId(self.block_id_counter), class, class_as_expr, VisModifierSpec::Public(DOT), attrs); + let methods = Methods::new( + DefId(self.block_id_counter), + class, + class_as_expr, + VisModifierSpec::Public(DOT), + attrs, + ); (base_type, vec![methods]) } diff --git a/crates/py2erg/gen_decl.rs b/crates/py2erg/gen_decl.rs index d97be8c..bb6f27c 100644 --- a/crates/py2erg/gen_decl.rs +++ b/crates/py2erg/gen_decl.rs @@ -3,11 +3,12 @@ use std::io::{BufWriter, Write}; use std::path::Path; use erg_common::io::Input; -use erg_common::log; use erg_common::pathutil::mod_name; +use erg_common::set::Set; use erg_common::traits::LimitedDisplay; +use erg_common::{log, Str}; use erg_compiler::build_package::{CheckStatus, PylyzerStatus}; -use erg_compiler::hir::{Expr, HIR, ClassDef}; +use erg_compiler::hir::{ClassDef, Expr, HIR}; use erg_compiler::ty::value::{GenTypeObj, TypeObj}; use erg_compiler::ty::{HasType, Type}; @@ -23,6 +24,7 @@ fn escape_type(typ: String) -> String { pub struct DeclFileGenerator { filename: String, namespace: String, + imported: Set, code: String, } @@ -44,6 +46,7 @@ impl DeclFileGenerator { Self { filename: input.filename().replace(".py", ".d.er"), namespace: "".to_string(), + imported: Set::new(), code, } } @@ -77,10 +80,19 @@ impl DeclFileGenerator { name = name.split('.').next().unwrap().to_string(); let full_path_str = ref_t.typarams()[0].to_string_unabbreviated(); let mod_name = mod_name(Path::new(full_path_str.trim_matches('"'))); - format!( - "{}.{name} = pyimport \"{mod_name}\"", - self.namespace, - ) + let imported = if self.imported.insert(mod_name.clone()) { + format!("{}.{mod_name} = pyimport \"{mod_name}\"", self.namespace) + } else { + "".to_string() + }; + if self.imported.insert(name.clone().into()) { + format!( + "{}.{name} = pyimport \"{mod_name}\"\n{imported}", + self.namespace, + ) + } else { + imported + } } else { format!("{}.{name}: {typ}", self.namespace) }; diff --git a/src/analyze.rs b/src/analyze.rs index debf552..909af60 100644 --- a/src/analyze.rs +++ b/src/analyze.rs @@ -2,20 +2,21 @@ use erg_common::config::ErgConfig; use erg_common::error::{ErrorCore, ErrorKind, MultiErrorDisplay}; use erg_common::style::colors::{BLUE, GREEN, RED, YELLOW}; use erg_common::style::RESET; -use erg_common::traits::{New, ExitStatus, Runnable, Stream}; +use erg_common::traits::{ExitStatus, New, Runnable, Stream}; use erg_common::Str; -use erg_compiler::GenericHIRBuilder; use erg_compiler::artifact::{BuildRunnable, Buildable, CompleteArtifact, IncompleteArtifact}; use erg_compiler::build_package::{CheckStatus, GenericPackageBuilder}; use erg_compiler::context::ModuleContext; use erg_compiler::erg_parser::ast::{Module, AST}; use erg_compiler::erg_parser::build_ast::ASTBuildable; use erg_compiler::erg_parser::error::{ - CompleteArtifact as ParseArtifact, IncompleteArtifact as IncompleteParseArtifact, ParseErrors, ParserRunnerErrors, + CompleteArtifact as ParseArtifact, IncompleteArtifact as IncompleteParseArtifact, ParseErrors, + ParserRunnerErrors, }; use erg_compiler::erg_parser::parse::Parsable; use erg_compiler::error::{CompileError, CompileErrors}; use erg_compiler::module::SharedCompilerResource; +use erg_compiler::GenericHIRBuilder; use py2erg::{dump_decl_er, reserve_decl_er, ShadowingMode}; use rustpython_ast::source_code::{RandomLocator, SourceRange}; use rustpython_ast::{Fold, ModModule}; @@ -32,9 +33,7 @@ impl Parsable for SimplePythonParser { fn parse(code: String) -> Result> { let mut slf = Self::new(ErgConfig::string(code.clone())); slf.build_ast(code) - .map(|art| { - ParseArtifact::new(art.ast.module, art.warns.into()) - }) + .map(|art| ParseArtifact::new(art.ast.module, art.warns.into())) .map_err(|iart| { IncompleteParseArtifact::new( iart.ast.map(|art| art.module), @@ -55,7 +54,10 @@ impl ASTBuildable for SimplePythonParser { fn build_ast( &mut self, code: String, - ) -> Result, IncompleteParseArtifact> { + ) -> Result< + ParseArtifact, + IncompleteParseArtifact, + > { let filename = self.cfg.input.filename(); let py_program = self.parse_py_code(code)?; let shadowing = if cfg!(feature = "debug") { @@ -64,7 +66,14 @@ impl ASTBuildable for SimplePythonParser { ShadowingMode::Invisible }; let converter = py2erg::ASTConverter::new(ErgConfig::default(), shadowing); - let IncompleteArtifact{ object: Some(erg_module), errors, warns } = converter.convert_program(py_program) else { unreachable!() }; + let IncompleteArtifact { + object: Some(erg_module), + errors, + warns, + } = converter.convert_program(py_program) + else { + unreachable!() + }; let erg_ast = AST::new(erg_common::Str::rc(&filename), erg_module); if errors.is_empty() { Ok(ParseArtifact::new(erg_ast, warns.into())) @@ -79,7 +88,10 @@ impl ASTBuildable for SimplePythonParser { } impl SimplePythonParser { - pub fn parse_py_code(&self, code: String) -> Result, IncompleteParseArtifact>{ + pub fn parse_py_code( + &self, + code: String, + ) -> Result, IncompleteParseArtifact> { let py_program = ModModule::parse(&code, "").map_err(|err| { let mut locator = RandomLocator::new(&code); // let mut locator = LinearLocator::new(&py_code); @@ -99,7 +111,11 @@ impl SimplePythonParser { ), ); let err = CompileError::new(core, self.cfg.input.clone(), "".into()); - IncompleteParseArtifact::new(None, ParserRunnerErrors::from(err), ParserRunnerErrors::empty()) + IncompleteParseArtifact::new( + None, + ParserRunnerErrors::from(err), + ParserRunnerErrors::empty(), + ) })?; let mut locator = RandomLocator::new(&code); // let mut locator = LinearLocator::new(&code); @@ -118,7 +134,8 @@ pub struct PythonAnalyzer { impl New for PythonAnalyzer { fn new(cfg: ErgConfig) -> Self { - let checker = GenericPackageBuilder::new(cfg.clone(), SharedCompilerResource::new(cfg.clone())); + let checker = + GenericPackageBuilder::new(cfg.clone(), SharedCompilerResource::new(cfg.clone())); Self { checker, cfg } } } @@ -173,7 +190,8 @@ impl Buildable for PythonAnalyzer { &mut self, ast: AST, mode: &str, - ) -> Result, IncompleteArtifact> { + ) -> Result, IncompleteArtifact> + { self.check(ast, CompileErrors::empty(), CompileErrors::empty(), mode) } fn pop_context(&mut self) -> Option { @@ -191,7 +209,13 @@ impl PythonAnalyzer { New::new(cfg) } - fn check(&mut self, erg_ast: AST, mut errors: CompileErrors, mut warns: CompileErrors, mode: &str) -> Result { + fn check( + &mut self, + erg_ast: AST, + mut errors: CompileErrors, + mut warns: CompileErrors, + mode: &str, + ) -> Result { match self.checker.build_from_ast(erg_ast, mode) { Ok(mut artifact) => { artifact.warns.extend(warns); @@ -224,21 +248,23 @@ impl PythonAnalyzer { ) -> Result { let filename = self.cfg.input.filename(); let parser = SimplePythonParser::new(self.cfg.copy()); - let py_program = parser.parse_py_code(py_code) - .map_err(|iart| { - IncompleteArtifact::new( - None, - iart.errors.into(), - iart.warns.into(), - ) - })?; + let py_program = parser + .parse_py_code(py_code) + .map_err(|iart| IncompleteArtifact::new(None, iart.errors.into(), iart.warns.into()))?; let shadowing = if cfg!(feature = "debug") { ShadowingMode::Visible } else { ShadowingMode::Invisible }; let converter = py2erg::ASTConverter::new(self.cfg.copy(), shadowing); - let IncompleteArtifact{ object: Some(erg_module), errors, warns } = converter.convert_program(py_program) else { unreachable!() }; + let IncompleteArtifact { + object: Some(erg_module), + errors, + warns, + } = converter.convert_program(py_program) + else { + unreachable!() + }; let erg_ast = AST::new(erg_common::Str::rc(&filename), erg_module); erg_common::log!("AST:\n{erg_ast}"); self.check(erg_ast, errors, warns, mode) diff --git a/src/copy.rs b/src/copy.rs index 353c543..bb7145d 100644 --- a/src/copy.rs +++ b/src/copy.rs @@ -1,5 +1,5 @@ +use std::fs::{copy, create_dir_all, read_dir}; use std::path::Path; -use std::fs::{copy, read_dir, create_dir_all}; use erg_common::env::{erg_path, python_site_packages}; @@ -31,8 +31,7 @@ pub(crate) fn copy_dot_erg() { for site_packages in python_site_packages() { if site_packages.join(".erg").exists() { println!("Copying site-package/.erg to {}", erg_path().display()); - copy_dir(site_packages.join(".erg"), erg_path()) - .expect("Failed to copy .erg"); + copy_dir(site_packages.join(".erg"), erg_path()).expect("Failed to copy .erg"); } } } diff --git a/src/lib.rs b/src/lib.rs index ff4fa97..67e4046 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,6 @@ mod analyze; mod config; -mod handle_err; mod copy; +mod handle_err; pub use analyze::PythonAnalyzer; diff --git a/src/main.rs b/src/main.rs index 7b06c40..24fb89f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ mod analyze; mod config; -mod handle_err; mod copy; +mod handle_err; use analyze::{PythonAnalyzer, SimplePythonParser}; use els::Server; diff --git a/tests/list.py b/tests/list.py new file mode 100644 index 0000000..87e6150 --- /dev/null +++ b/tests/list.py @@ -0,0 +1,10 @@ +l = [1, 2, 3] +_ = l[1:2] +print(l[4]) # ERR + +# OK +for i in range(3): + print(l[i]) +# ERR +for i in range(4): + print(l[i]) diff --git a/tests/test.py b/tests/test.py index ca78a3b..da826ad 100644 --- a/tests/test.py +++ b/tests/test.py @@ -30,16 +30,6 @@ class C: dic = {"a": 1, "b": 2} print(dic["c"]) # ERR -arr = [1, 2, 3] -print(arr[4]) # ERR - -# OK -for i in range(3): - print(arr[i]) -# ERR -for i in range(4): - print(arr[i]) - def f(d1, d2: dict[str, int]): _ = d1["b"] # OK _ = d2["a"] # OK diff --git a/tests/test.rs b/tests/test.rs index 326e909..f339b26 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -55,7 +55,7 @@ pub fn expect(file_path: &'static str, warns: usize, errors: usize) -> Result<() #[test] fn exec_test() -> Result<(), String> { - expect("tests/test.py", 0, 15) + expect("tests/test.py", 0, 13) } #[test] @@ -107,6 +107,11 @@ fn exec_projection() -> Result<(), String> { expect("tests/projection.py", 0, 5) } +#[test] +fn exec_list() -> Result<(), String> { + expect("tests/list.py", 0, 2) +} + #[test] fn exec_narrowing() -> Result<(), String> { expect("tests/narrowing.py", 0, 1)