diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 00000000..169d291b --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[env] +AWS_LC_SYS_PREBUILT_NASM = "1" diff --git a/.config/nextest.toml b/.config/nextest.toml new file mode 100644 index 00000000..952d0e8b --- /dev/null +++ b/.config/nextest.toml @@ -0,0 +1,6 @@ +[test-groups.serial-algorithm] +max-threads = 1 + +[[profile.default.overrides]] +filter = "test(::test_f[0-9])" +test-group = "serial-algorithm" diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index bc8f18b4..9b723594 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -20,8 +20,9 @@ jobs: steps: - id: toolchains run: | + # Last 5 stable versions only TOOLCHAINS='["1.89.0", "1.90.0", "1.91.1", "1.92.0", "1.93.0"]' - echo "toolchains=$TOOLCHAINS" >> $GITHUB_OUTPUT + echo "toolchains=$TOOLCHAINS" >> "$GITHUB_OUTPUT" echo "latest=$(jq -r '.[-1]' <<< "$TOOLCHAINS")" >> "$GITHUB_OUTPUT" lint: @@ -75,28 +76,64 @@ jobs: test: name: Build & Test - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} needs: - define-matrix + + defaults: + run: + shell: bash + strategy: matrix: toolchain: ${{ fromJSON(needs.define-matrix.outputs.toolchains) }} + os: + - windows-latest + - windows-11-arm + - macos-15-intel + - macos-latest + - ubuntu-latest + - ubuntu-24.04-arm + env: TOOLCHAIN_CHANNEL: ${{ matrix.toolchain }} + steps: - name: Checkout uses: actions/checkout@v6 + # Using fat LTO causes failure to link on Windows + - name: Set build profile + run: | + if [[ "${{ matrix.os }}" == windows* ]]; then + echo "build_profile=windows-release" >> $GITHUB_ENV + else + echo "build_profile=release" >> $GITHUB_ENV + fi + - name: Cache dependencies uses: Swatinem/rust-cache@v2 with: save-if: ${{ github.ref == 'refs/heads/main' }} + - name: Install nextest + uses: taiki-e/install-action@cargo-nextest + + # uname on Windows on ARM returns "x86_64" + - name: Set ARCH flag for Windows on ARM + if: matrix.os == 'windows-11-arm' + run: echo "TOOLCHAIN_ARCH=aarch64" >> $GITHUB_ENV + - name: Build release - run: ./scripts/build/toolchain cargo build --release + run: ./scripts/build/toolchain cargo build --profile=${{ env.build_profile }} + + - name: Run tests + # MIR is still unstable, so this test can fail in other versions of Rust. + if: matrix.toolchain == needs.define-matrix.outputs.latest + run: ./scripts/build/toolchain cargo nextest run --no-fail-fast - name: Install binary - run: ./scripts/build/toolchain cargo install --path . + run: ./scripts/build/toolchain cargo install --path . --profile=${{ env.build_profile }} - name: Test rustowl check run: rustowl check ./perf-tests/dummy-package diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index a9506aa7..379a7e40 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -33,7 +33,6 @@ jobs: uses: actions-rust-lang/setup-rust-toolchain@v1 with: components: miri,rust-src,llvm-tools-preview,rustc-dev - # Automatically reads from rust-toolchain.toml cache: false - name: Install system dependencies (Linux) diff --git a/Cargo.lock b/Cargo.lock index f5a81b2f..7ab0e8a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -93,6 +93,12 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "anyhow" +version = "1.0.101" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f0e0fee31ef5ed1ba1316088939cea399010ed7731dba877ed44aeb407a75ea" + [[package]] name = "async-trait" version = "0.1.89" @@ -406,11 +412,23 @@ dependencies = [ "memchr", ] +[[package]] +name = "console" +version = "0.15.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "054ccb5b10f9f2cbf51eb355ca1d05c2d279ce1804688d0db74b4733a5aeafd8" +dependencies = [ + "encode_unicode", + "libc", + "once_cell", + "windows-sys 0.59.0", +] + [[package]] name = "constant_time_eq" -version = "0.3.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6" +checksum = "3d52eff69cd5e647efe296129160853a42795992097e8af39800e1060caeea9b" [[package]] name = "core-foundation" @@ -473,9 +491,9 @@ dependencies = [ [[package]] name = "criterion" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d883447757bb0ee46f233e9dc22eb84d93a9508c9b868687b274fc431d886bf" +checksum = "950046b2aa2492f9a536f5f4f9a3de7b9e2476e575e05bd6c333371add4d98f3" dependencies = [ "alloca", "anes", @@ -498,9 +516,9 @@ dependencies = [ [[package]] name = "criterion-plot" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed943f81ea2faa8dcecbbfa50164acf95d555afec96a27871663b300e387b2e4" +checksum = "d8d80a2f4f5b554395e47b5d8305bc3d27813bacb73493eb1001e8f76dae29ea" dependencies = [ "cast", "itertools", @@ -609,6 +627,12 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" +[[package]] +name = "encode_unicode" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" + [[package]] name = "encoding_rs" version = "0.8.35" @@ -674,6 +698,12 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + [[package]] name = "form_urlencoded" version = "1.2.2" @@ -803,6 +833,21 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "getrandom" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "139ef39800118c7683f2fd3c98c1b23c09ae076556b435f8e9064ae108aaeeec" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "r-efi", + "wasip2", + "wasip3", + "wasm-bindgen", +] + [[package]] name = "h2" version = "0.4.13" @@ -839,6 +884,15 @@ version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "foldhash", +] + [[package]] name = "hashbrown" version = "0.16.1" @@ -1043,6 +1097,12 @@ dependencies = [ "zerovec", ] +[[package]] +name = "id-arena" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" + [[package]] name = "idna" version = "1.1.0" @@ -1072,6 +1132,8 @@ checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" dependencies = [ "equivalent", "hashbrown 0.16.1", + "serde", + "serde_core", ] [[package]] @@ -1083,6 +1145,18 @@ dependencies = [ "generic-array", ] +[[package]] +name = "insta" +version = "1.46.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e82db8c87c7f1ccecb34ce0c24399b8a73081427f3c7c50a5d597925356115e4" +dependencies = [ + "console", + "once_cell", + "similar", + "tempfile", +] + [[package]] name = "ipnet" version = "2.11.0" @@ -1162,6 +1236,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" + [[package]] name = "libbz2-rs-sys" version = "0.2.2" @@ -1243,9 +1323,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.7.6" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" [[package]] name = "mime" @@ -1457,6 +1537,16 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn", +] + [[package]] name = "proc-macro2" version = "1.0.106" @@ -1645,9 +1735,9 @@ checksum = "a96887878f22d7bad8a3b6dc5b7440e0ada9a245242924394987b21cf2210a4c" [[package]] name = "reqwest" -version = "0.13.1" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04e9018c9d814e5f30cc16a0f03271aeab3571e609612d9fe78c1aa8d11c2f62" +checksum = "ab3f43e3283ab1488b624b44b0e988d0acea0b3214e694730a055cb6b2efa801" dependencies = [ "base64", "bytes", @@ -1807,6 +1897,7 @@ dependencies = [ "clap_mangen", "criterion", "flate2", + "insta", "log", "process_alive", "rayon", @@ -1819,7 +1910,6 @@ dependencies = [ "tar", "tempfile", "tikv-jemalloc-sys", - "tikv-jemallocator", "tokio", "tokio-util", "tower-lsp", @@ -1991,6 +2081,12 @@ version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e320a6c5ad31d271ad523dcf3ad13e2767ad8b1cb8f047f75a8aeaf8da139da2" +[[package]] +name = "similar" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbbb5d9659141646ae647b42fe094daf6c6192d1620870b449d9557f748b2daa" + [[package]] name = "simple_logger" version = "5.1.0" @@ -2175,21 +2271,11 @@ dependencies = [ "libc", ] -[[package]] -name = "tikv-jemallocator" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0359b4327f954e0567e69fb191cf1436617748813819c94b8cd4a431422d053a" -dependencies = [ - "libc", - "tikv-jemalloc-sys", -] - [[package]] name = "time" -version = "0.3.46" +version = "0.3.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9da98b7d9b7dad93488a84b8248efc35352b0b2657397d4167e7ad67e5d535e5" +checksum = "743bd48c283afc0388f9b8827b976905fb217ad9e647fae3a379a9283c4def2c" dependencies = [ "deranged", "itoa", @@ -2211,9 +2297,9 @@ checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca" [[package]] name = "time-macros" -version = "0.2.26" +version = "0.2.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78cc610bac2dcee56805c99642447d4c5dbde4d01f752ffea0199aee1f601dc4" +checksum = "2e70e4c5a0e0a8a4823ad65dfe1a6930e4f4d756dcd9dd7939022b5e8c501215" dependencies = [ "num-conv", "time-core", @@ -2494,6 +2580,12 @@ version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + [[package]] name = "untrusted" version = "0.9.0" @@ -2576,6 +2668,15 @@ dependencies = [ "wit-bindgen", ] +[[package]] +name = "wasip3" +version = "0.4.0+wasi-0.3.0-rc-2026-01-06" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" +dependencies = [ + "wit-bindgen", +] + [[package]] name = "wasm-bindgen" version = "0.2.108" @@ -2635,6 +2736,40 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "wasm-encoder" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" +dependencies = [ + "leb128fmt", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" +dependencies = [ + "anyhow", + "indexmap", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasmparser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" +dependencies = [ + "bitflags 2.10.0", + "hashbrown 0.15.5", + "indexmap", + "semver", +] + [[package]] name = "web-sys" version = "0.3.85" @@ -2748,6 +2883,15 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-sys" version = "0.60.2" @@ -2957,6 +3101,88 @@ name = "wit-bindgen" version = "0.51.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" +dependencies = [ + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" +dependencies = [ + "anyhow", + "heck", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "prettyplease", + "syn", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" +dependencies = [ + "anyhow", + "prettyplease", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" +dependencies = [ + "anyhow", + "bitflags 2.10.0", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] [[package]] name = "writeable" @@ -2999,18 +3225,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.38" +version = "0.8.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57cf3aa6855b23711ee9852dfc97dfaa51c45feaba5b645d0c777414d494a961" +checksum = "db6d35d663eadb6c932438e763b262fe1a70987f9ae936e60158176d710cae4a" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.38" +version = "0.8.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a616990af1a287837c4fe6596ad77ef57948f787e46ce28e166facc0cc1cb75" +checksum = "4122cd3169e94605190e77839c9a40d40ed048d305bfdc146e7df40ab0f3e517" dependencies = [ "proc-macro2", "quote", @@ -3093,9 +3319,9 @@ dependencies = [ [[package]] name = "zip" -version = "7.2.0" +version = "7.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42e33efc22a0650c311c2ef19115ce232583abbe80850bc8b66509ebef02de0" +checksum = "cc12baa6db2b15a140161ce53d72209dacea594230798c24774139b54ecaa980" dependencies = [ "aes", "bzip2", @@ -3103,8 +3329,7 @@ dependencies = [ "crc32fast", "deflate64", "flate2", - "generic-array", - "getrandom 0.3.4", + "getrandom 0.4.1", "hmac", "indexmap", "lzma-rust2", diff --git a/Cargo.toml b/Cargo.toml index 712165fe..450e4ce5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,6 +64,7 @@ uuid = { version = "1", features = ["v4"] } [dev-dependencies] criterion = { version = "0.8", features = ["html_reports"] } +insta = "1.46" [build-dependencies] clap = { version = "4", features = ["derive"] } @@ -72,9 +73,8 @@ clap_complete_nushell = "4" clap_mangen = "0.2" regex = "1" -[target.'cfg(not(target_env = "msvc"))'.dependencies] -tikv-jemalloc-sys = "0.6" -tikv-jemallocator = "0.6" +[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies] +tikv-jemalloc-sys = { version = "0.6", features = ["override_allocator_on_supported_platforms"] } [target.'cfg(target_os = "windows")'.dependencies] zip = "7.2.0" diff --git a/algo-tests/Cargo.lock b/algo-tests/Cargo.lock new file mode 100644 index 00000000..0a77931b --- /dev/null +++ b/algo-tests/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "algo-tests" +version = "0.1.0" diff --git a/algo-tests/Cargo.toml b/algo-tests/Cargo.toml new file mode 100644 index 00000000..b299f8e8 --- /dev/null +++ b/algo-tests/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "algo-tests" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/algo-tests/src/lib.rs b/algo-tests/src/lib.rs new file mode 100644 index 00000000..e06c662e --- /dev/null +++ b/algo-tests/src/lib.rs @@ -0,0 +1 @@ +mod vec; diff --git a/algo-tests/src/vec.rs b/algo-tests/src/vec.rs new file mode 100644 index 00000000..11161577 --- /dev/null +++ b/algo-tests/src/vec.rs @@ -0,0 +1,25 @@ +fn f1() { + let v1: Vec<_> = (0..100).collect(); + let v2: Vec<_> = (0..100).collect(); + println!("{v1:?} {v2:?}"); + println!("finish"); +} + +fn f2() { + let v1: Vec<_> = (0..100).collect(); + println!("{v1:?}"); + drop(v1); + let v2: Vec<_> = (0..100).collect(); + println!("{v2:?}"); + drop(v2); +} + +fn f3() { + let v1: Vec<_> = (0..100).collect(); + let mut r = &v1; + if 0 < v1.len() { + let v2: Vec<_> = (0..100).collect(); + r = &v2; + } + println!("{r:?}"); +} diff --git a/src/bin/rustowl.rs b/src/bin/rustowl.rs index 39220cc3..2cbf99cc 100644 --- a/src/bin/rustowl.rs +++ b/src/bin/rustowl.rs @@ -11,13 +11,11 @@ use tower_lsp::{LspService, Server}; use crate::cli::{Cli, Commands, ToolchainCommands}; -#[cfg(all(not(target_env = "msvc"), not(miri)))] -use tikv_jemallocator::Jemalloc; - -// Use jemalloc by default, but fall back to system allocator for Miri -#[cfg(all(not(target_env = "msvc"), not(miri)))] -#[global_allocator] -static GLOBAL: Jemalloc = Jemalloc; +// Cited from rustc +// https://github.com/rust-lang/rust/pull/148925 +// MIT License +#[cfg(all(any(target_os = "linux", target_os = "macos"), not(miri)))] +use tikv_jemalloc_sys as _; fn set_log_level(default: log::LevelFilter) { log::set_max_level( diff --git a/src/bin/rustowlc.rs b/src/bin/rustowlc.rs index 5f6b8f5d..f8b7d137 100644 --- a/src/bin/rustowlc.rs +++ b/src/bin/rustowlc.rs @@ -26,40 +26,13 @@ pub mod core; use std::process::exit; -fn main() { - // This is cited from [rustc](https://github.com/rust-lang/rust/blob/3014e79f9c8d5510ea7b3a3b70d171d0948b1e96/compiler/rustc/src/main.rs). - // MIT License - #[cfg(not(target_env = "msvc"))] - { - use std::os::raw::{c_int, c_void}; - - use tikv_jemalloc_sys as jemalloc_sys; - - #[used] - static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::calloc; - #[used] - static _F2: unsafe extern "C" fn(*mut *mut c_void, usize, usize) -> c_int = - jemalloc_sys::posix_memalign; - #[used] - static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::aligned_alloc; - #[used] - static _F4: unsafe extern "C" fn(usize) -> *mut c_void = jemalloc_sys::malloc; - #[used] - static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = jemalloc_sys::realloc; - #[used] - static _F6: unsafe extern "C" fn(*mut c_void) = jemalloc_sys::free; - - #[cfg(target_os = "macos")] - { - unsafe extern "C" { - fn _rjem_je_zone_register(); - } - - #[used] - static _F7: unsafe extern "C" fn() = _rjem_je_zone_register; - } - } +// Cited from rustc +// https://github.com/rust-lang/rust/pull/148925 +// MIT License +#[cfg(any(target_os = "linux", target_os = "macos"))] +use tikv_jemalloc_sys as _; +fn main() { simple_logger::SimpleLogger::new() .env() .with_colors(true) diff --git a/tests/algorithm.rs b/tests/algorithm.rs new file mode 100644 index 00000000..7dbf441a --- /dev/null +++ b/tests/algorithm.rs @@ -0,0 +1,106 @@ +use std::process::Command; +use std::sync::Once; + +static BUILD_ONCE: Once = Once::new(); + +fn ensure_rustowl_built() { + BUILD_ONCE.call_once(|| { + let mut cmd = Command::new("cargo"); + if cfg!(windows) { + cmd.args(["build", "--profile", "windows-release"]); + } else { + cmd.args(["build", "--release"]); + } + let output = cmd + .output() + .unwrap_or_else(|e| panic!("Failed to execute cargo build: {e}")); + assert!( + output.status.success(), + "Failed to build rustowl.\nstdout: {}\nstderr: {}", + String::from_utf8_lossy(&output.stdout), + String::from_utf8_lossy(&output.stderr) + ); + }); +} + +fn get_rustowl_output(function_path: &str, variable: &str) -> String { + ensure_rustowl_built(); + + let exe_name = if cfg!(windows) { + "rustowl.exe" + } else { + "rustowl" + }; + let profile_dir = if cfg!(windows) { + "windows-release" + } else { + "release" + }; + + let rustowl_path = format!( + "target{}{}{}{}", + std::path::MAIN_SEPARATOR, + profile_dir, + std::path::MAIN_SEPARATOR, + exe_name + ); + + let output = Command::new(&rustowl_path) + .args([ + "show", + "--path", + &format!( + "algo-tests{}src{}vec.rs", + std::path::MAIN_SEPARATOR, + std::path::MAIN_SEPARATOR + ), + function_path, + variable, + ]) + .output() + .unwrap_or_else(|e| panic!("Failed to execute {rustowl_path}: {e}")); + + assert!( + output.status.success(), + "{rustowl_path} command failed.\nstdout: {}\nstderr: {}", + String::from_utf8_lossy(&output.stdout), + String::from_utf8_lossy(&output.stderr) + ); + String::from_utf8(output.stdout).expect("Invalid UTF-8") +} + +#[test] +fn test_f1_v1() { + let output = get_rustowl_output("vec::f1", "v1"); + insta::assert_snapshot!(output); +} + +#[test] +fn test_f1_v2() { + let output = get_rustowl_output("vec::f1", "v2"); + insta::assert_snapshot!(output); +} + +#[test] +fn test_f2_v1() { + let output = get_rustowl_output("vec::f2", "v1"); + insta::assert_snapshot!(output); +} + +#[test] +fn test_f2_v2() { + let output = get_rustowl_output("vec::f2", "v2"); + insta::assert_snapshot!(output); +} + +#[test] +fn test_f3_v1() { + let output = get_rustowl_output("vec::f3", "v1"); + insta::assert_snapshot!(output); +} + +#[test] +fn test_f3_v2() { + let output = get_rustowl_output("vec::f3", "v2"); + insta::assert_snapshot!(output); +} diff --git a/tests/snapshots/algorithm__f1_v1.snap b/tests/snapshots/algorithm__f1_v1.snap new file mode 100644 index 00000000..6b6c1dd4 --- /dev/null +++ b/tests/snapshots/algorithm__f1_v1.snap @@ -0,0 +1,29 @@ +--- +source: tests/algorithm.rs +expression: output +--- + +=== Variable 'v1' (1/1) in function 'vec::f1' === + + 1 | fn f1() { + 2 | let v1: Vec<_> = (0..100).collect(); + l |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + c |  ~~~~~~~~~~ + 3 | let v2: Vec<_> = (0..100).collect(); + l | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 4 | println!("{v1:?} {v2:?}"); + l | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + i |  ~~~ + 5 | println!("finish"); + l | ~~~~~~~~~~~~~~~~~~~~~~~~ + 6 | } + l | ~~ + 7 | + 8 | fn f2() { + +Legend: + ~~~ lifetime (l) + ~~~ immutable borrow (i) + ~~~ mutable borrow (m) + ~~~ move (v) / call (c) + ~~~ outlive (o) / shared mutable (s) diff --git a/tests/snapshots/algorithm__f1_v2.snap b/tests/snapshots/algorithm__f1_v2.snap new file mode 100644 index 00000000..9dd23344 --- /dev/null +++ b/tests/snapshots/algorithm__f1_v2.snap @@ -0,0 +1,28 @@ +--- +source: tests/algorithm.rs +expression: output +--- + +=== Variable 'v2' (1/1) in function 'vec::f1' === + + 1 | fn f1() { + 2 | let v1: Vec<_> = (0..100).collect(); + 3 | let v2: Vec<_> = (0..100).collect(); + l |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + c |  ~~~~~~~~~~ + 4 | println!("{v1:?} {v2:?}"); + l | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + i |  ~~~ + 5 | println!("finish"); + l | ~~~~~~~~~~~~~~~~~~~~~~~~ + 6 | } + l | ~~ + 7 | + 8 | fn f2() { + +Legend: + ~~~ lifetime (l) + ~~~ immutable borrow (i) + ~~~ mutable borrow (m) + ~~~ move (v) / call (c) + ~~~ outlive (o) / shared mutable (s) diff --git a/tests/snapshots/algorithm__f2_v1.snap b/tests/snapshots/algorithm__f2_v1.snap new file mode 100644 index 00000000..388f3434 --- /dev/null +++ b/tests/snapshots/algorithm__f2_v1.snap @@ -0,0 +1,31 @@ +--- +source: tests/algorithm.rs +expression: output +--- + +=== Variable 'v1' (1/1) in function 'vec::f2' === + + 7 | + 8 | fn f2() { + 9 | let v1: Vec<_> = (0..100).collect(); + l |  ~~~ ~~~~~~~ ~~ + c |  ~~~~~~~~~~ + 10 | println!("{v1:?}"); + l |  ~~~~~~ + i |  ~~~ + 11 | drop(v1); + v |  ~~~ + 12 | let v2: Vec<_> = (0..100).collect(); + 13 | println!("{v2:?}"); + 14 | drop(v2); + 15 | } + l | ~~ + 16 | + 17 | fn f3() { + +Legend: + ~~~ lifetime (l) + ~~~ immutable borrow (i) + ~~~ mutable borrow (m) + ~~~ move (v) / call (c) + ~~~ outlive (o) / shared mutable (s) diff --git a/tests/snapshots/algorithm__f2_v2.snap b/tests/snapshots/algorithm__f2_v2.snap new file mode 100644 index 00000000..74d9ed5c --- /dev/null +++ b/tests/snapshots/algorithm__f2_v2.snap @@ -0,0 +1,28 @@ +--- +source: tests/algorithm.rs +expression: output +--- + +=== Variable 'v2' (1/1) in function 'vec::f2' === + + 10 | println!("{v1:?}"); + 11 | drop(v1); + 12 | let v2: Vec<_> = (0..100).collect(); + l |  ~~~ ~~~~~~~ ~~ + c |  ~~~~~~~~~~ + 13 | println!("{v2:?}"); + l |  ~~~~~~ + i |  ~~~ + 14 | drop(v2); + v |  ~~~ + 15 | } + l | ~~ + 16 | + 17 | fn f3() { + +Legend: + ~~~ lifetime (l) + ~~~ immutable borrow (i) + ~~~ mutable borrow (m) + ~~~ move (v) / call (c) + ~~~ outlive (o) / shared mutable (s) diff --git a/tests/snapshots/algorithm__f3_v1.snap b/tests/snapshots/algorithm__f3_v1.snap new file mode 100644 index 00000000..1e691e9b --- /dev/null +++ b/tests/snapshots/algorithm__f3_v1.snap @@ -0,0 +1,35 @@ +--- +source: tests/algorithm.rs +expression: output +--- + +=== Variable 'v1' (1/1) in function 'vec::f3' === + + 16 | + 17 | fn f3() { + 18 | let v1: Vec<_> = (0..100).collect(); + l |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + c |  ~~~~~~~~~~ + 19 | let mut r = &v1; + l | ~~~~~~~~~~~~~~~~~~~~~ + i |  ~~~~ + 20 | if 0 < v1.len() { + l | ~~~~~~~~~~~~~~~~~~~~~~ + i |  ~~~ + 21 | let v2: Vec<_> = (0..100).collect(); + l | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 22 | r = &v2; + l | ~~~~~~~~~~~~~~~~~ + 23 | } + l | ~~~~~~ + 24 | println!("{r:?}"); + l | ~~~~~~~~~~~~~~~~~~~~~~~ + 25 | } + l | ~~ + +Legend: + ~~~ lifetime (l) + ~~~ immutable borrow (i) + ~~~ mutable borrow (m) + ~~~ move (v) / call (c) + ~~~ outlive (o) / shared mutable (s) diff --git a/tests/snapshots/algorithm__f3_v2.snap b/tests/snapshots/algorithm__f3_v2.snap new file mode 100644 index 00000000..14fc6662 --- /dev/null +++ b/tests/snapshots/algorithm__f3_v2.snap @@ -0,0 +1,27 @@ +--- +source: tests/algorithm.rs +expression: output +--- + +=== Variable 'v2' (1/1) in function 'vec::f3' === + + 19 | let mut r = &v1; + 20 | if 0 < v1.len() { + 21 | let v2: Vec<_> = (0..100).collect(); + l |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + c |  ~~~~~~~~~~ + 22 | r = &v2; + l | ~~~~~~~~~~~~~~~~~ + i |  ~~~~ + 23 | } + l | ~~~~~~ + 24 | println!("{r:?}"); + o |  ~~~~~~ + 25 | } + +Legend: + ~~~ lifetime (l) + ~~~ immutable borrow (i) + ~~~ mutable borrow (m) + ~~~ move (v) / call (c) + ~~~ outlive (o) / shared mutable (s)