From b9622d9197596cbe50e444222362779d9737773d Mon Sep 17 00:00:00 2001 From: Stuart Pernsteiner Date: Fri, 3 Jun 2022 14:53:32 -0700 Subject: [PATCH 01/35] fix most import errors --- Cargo.lock | 846 +++++++++++++++++++++--------------------- src/analyz/mod.rs | 32 +- src/analyz/to_json.rs | 6 +- src/analyz/ty_json.rs | 77 ++-- src/lib.rs | 8 +- 5 files changed, 486 insertions(+), 483 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a30f8e9..0740a7c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,1245 +1,1245 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "adler32" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d2e7343e7fc9de883d1b0341e0b13970f764c14101234857d2ddafa1cb1cac2" [[package]] name = "aho-corasick" version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d" dependencies = [ - "memchr 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr", ] [[package]] name = "ansi_term" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" dependencies = [ - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi", ] [[package]] name = "anyhow" version = "1.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b602bfe940d21c130f3895acd65221e8a61270debe89d628b9cb4e3ccb8569b" [[package]] name = "atty" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "hermit-abi", + "libc", + "winapi", ] [[package]] name = "autocfg" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" [[package]] name = "bitflags" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] name = "bitmaps" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "031043d04099746d8db04daf1fa424b2bc8bd69d92b25962dcde24da39ab64a2" dependencies = [ - "typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)", + "typenum", ] [[package]] name = "bstr" version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ede750122d9d1f87919570cb2cccee38c84fbc8c5599b25c289af40625b7030" dependencies = [ - "memchr 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr", ] [[package]] name = "bytesize" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "716960a18f978640f25101b5cbf1c6f6b0d3192fab36a2d98ca96f0ecbe41010" [[package]] name = "c2-chacha" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "214238caa1bf3a496ec3392968969cab8549f96ff30652c9e56885329315f6bb" dependencies = [ - "ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "ppv-lite86", ] [[package]] name = "cargo" version = "0.43.1" source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "anyhow 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)", - "atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", - "bytesize 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cargo-platform 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", - "core-foundation 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "crates-io 0.31.1 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "crypto-hash 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "curl 0.4.25 (registry+https://github.com/rust-lang/crates.io-index)", - "curl-sys 0.4.25 (registry+https://github.com/rust-lang/crates.io-index)", - "env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "filetime 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "flate2 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", - "fs2 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fwdansi 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "git2 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "git2-curl 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", - "glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hex 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "home 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "humantime 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "ignore 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", - "im-rc 14.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "jobserver 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", - "libgit2-sys 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "miow 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", - "opener 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl 0.10.26 (registry+https://github.com/rust-lang/crates.io-index)", - "percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-workspace-hack 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustfix 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "same-file 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_ignored 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", - "shell-escape 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "strip-ansi-escapes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tar 0.4.26 (registry+https://github.com/rust-lang/crates.io-index)", - "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "termcolor 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "toml 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "walkdir 2.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +checksum = "91de5749ddcea3c283a042b67b77e2bdf68f28374cdcbfbe54e91368810d92e5" +dependencies = [ + "anyhow", + "atty", + "bytesize", + "cargo-platform", + "clap", + "core-foundation", + "crates-io", + "crossbeam-utils", + "crypto-hash", + "curl", + "curl-sys", + "env_logger", + "filetime", + "flate2", + "fs2", + "fwdansi", + "git2", + "git2-curl", + "glob", + "hex 0.4.0", + "home", + "humantime 2.0.1", + "ignore", + "im-rc", + "jobserver", + "lazy_static", + "lazycell", + "libc", + "libgit2-sys", + "log", + "memchr", + "miow", + "num_cpus", + "opener", + "openssl", + "percent-encoding", + "remove_dir_all", + "rustc-workspace-hack", + "rustfix", + "same-file", + "semver", + "serde", + "serde_ignored", + "serde_json", + "shell-escape", + "strip-ansi-escapes", + "tar", + "tempfile", + "termcolor", + "toml", + "unicode-width", + "url", + "walkdir", + "winapi", ] [[package]] name = "cargo-platform" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0226944a63d1bf35a3b5f948dd7c59e263db83695c9e8bffc4037de02e30f1d7" dependencies = [ - "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", + "serde", ] [[package]] name = "cargo_metadata" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be1057b8462184f634c3a208ee35b0f935cfd94b694b26deadccd98732088d7b" dependencies = [ - "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", + "serde", + "serde_derive", + "serde_json", ] [[package]] name = "cc" version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95e28fa049fda1c330bcf9d723be7663a899c4679724b34c81e9f5a326aab8cd" dependencies = [ - "jobserver 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", + "jobserver", ] [[package]] name = "cfg-if" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" [[package]] name = "clap" version = "2.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" dependencies = [ - "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", + "ansi_term", + "atty", + "bitflags", + "strsim", + "textwrap", + "unicode-width", + "vec_map", ] [[package]] name = "commoncrypto" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d056a8586ba25a1e4d61cb090900e495952c7886786fc55f909ab2f819b69007" dependencies = [ - "commoncrypto-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "commoncrypto-sys", ] [[package]] name = "commoncrypto-sys" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fed34f46747aa73dfaa578069fd8279d2818ade2b55f38f22a9401c7f4083e2" dependencies = [ - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", ] [[package]] name = "core-foundation" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171" dependencies = [ - "core-foundation-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "core-foundation-sys", + "libc", ] [[package]] name = "core-foundation-sys" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" [[package]] name = "crates-io" version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09f977948a46e9edf93eb3dc2d7a8dd4ce3105d36de63300befed37cdf051d4a" dependencies = [ - "anyhow 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)", - "curl 0.4.25 (registry+https://github.com/rust-lang/crates.io-index)", - "percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", - "url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "anyhow", + "curl", + "percent-encoding", + "serde", + "serde_derive", + "serde_json", + "url", ] [[package]] name = "crc32fast" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if", ] [[package]] name = "crossbeam-channel" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acec9a3b0b3559f15aee4f90746c4e5e293b701c0f7d3925d24e01645267b68c" dependencies = [ - "crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils", ] [[package]] name = "crossbeam-utils" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce446db02cdc3165b94ae73111e570793400d0794e46125cc4056c81cbb039f4" dependencies = [ - "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg", + "cfg-if", + "lazy_static", ] [[package]] name = "crypto-hash" version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a77162240fd97248d19a564a565eb563a3f592b386e4136fb300909e67dddca" dependencies = [ - "commoncrypto 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl 0.10.26 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "commoncrypto", + "hex 0.3.2", + "openssl", + "winapi", ] [[package]] name = "curl" version = "0.4.25" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06aa71e9208a54def20792d877bc663d6aae0732b9852e612c4a933177c31283" dependencies = [ - "curl-sys 0.4.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys 0.9.53 (registry+https://github.com/rust-lang/crates.io-index)", - "schannel 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", - "socket2 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "curl-sys", + "libc", + "openssl-probe", + "openssl-sys", + "schannel", + "socket2", + "winapi", ] [[package]] name = "curl-sys" version = "0.4.25" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c38ca47d60b86d0cc9d42caa90a0885669c2abc9791f871c81f58cdf39e979b" dependencies = [ - "cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", - "libnghttp2-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys 0.9.53 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", - "vcpkg 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "cc", + "libc", + "libnghttp2-sys", + "libz-sys", + "openssl-sys", + "pkg-config", + "vcpkg", + "winapi", ] [[package]] name = "env_logger" version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" dependencies = [ - "atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", - "humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "termcolor 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "atty", + "humantime 1.3.0", + "log", + "regex", + "termcolor", ] [[package]] name = "filetime" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ff6d4dab0aa0c8e6346d46052e93b13a16cf847b54ed357087c35011048cc7d" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if", + "libc", + "redox_syscall", + "winapi", ] [[package]] name = "flate2" version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bd6d6f4752952feb71363cffc9ebac9411b75b87c6ab6058c40c8900cf43c0f" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", - "libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", - "miniz_oxide 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if", + "crc32fast", + "libc", + "libz-sys", + "miniz_oxide", ] [[package]] name = "fnv" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" [[package]] name = "foreign-types" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" dependencies = [ - "foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "foreign-types-shared", ] [[package]] name = "foreign-types-shared" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "fs2" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" dependencies = [ - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", + "winapi", ] [[package]] name = "fwdansi" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c1f5787fe85505d1f7777268db5103d80a7a374d2316a7ce262e57baf8f208" dependencies = [ - "memchr 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "termcolor 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr", + "termcolor", ] [[package]] name = "getrandom" version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", - "wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if", + "libc", + "wasi", ] [[package]] name = "git2" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77519ef7c5beee314d0804d4534f01e0f9e8d9acdee2b7a48627e590b27e0ec4" dependencies = [ - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", - "libgit2-sys 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys 0.9.53 (registry+https://github.com/rust-lang/crates.io-index)", - "url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags", + "libc", + "libgit2-sys", + "log", + "openssl-probe", + "openssl-sys", + "url", ] [[package]] name = "git2-curl" version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2559abb1d87d27668d31bd868a000f0e2e0065d10e78961b62da95d7a7f1cc7" dependencies = [ - "curl 0.4.25 (registry+https://github.com/rust-lang/crates.io-index)", - "git2 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "curl", + "git2", + "log", + "url", ] [[package]] name = "glob" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[package]] name = "globset" version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925aa2cac82d8834e2b2a4415b6f6879757fb5c0928fc445ae76461a12eed8f2" dependencies = [ - "aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", - "bstr 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", - "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "aho-corasick", + "bstr", + "fnv", + "log", + "regex", ] [[package]] name = "half" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ff54597ea139063f4225f1ec47011b03c9de4a486957ff3fc506881dac951d0" [[package]] name = "hermit-abi" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eff2656d88f158ce120947499e971d743c05dbcbed62e5bd2f38f1698bbc3772" dependencies = [ - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", ] [[package]] name = "hex" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" [[package]] name = "hex" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "023b39be39e3a2da62a94feb433e91e8bcd37676fbc8bea371daf52b7a769a3e" [[package]] name = "home" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2456aef2e6b6a9784192ae780c0f15bc57df0e918585282325e8c8ac27737654" dependencies = [ - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi", ] [[package]] name = "humantime" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" dependencies = [ - "quick-error 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "quick-error", ] [[package]] name = "humantime" version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c1ad908cc71012b7bea4d0c53ba96a8cba9962f048fa68d143376143d863b7a" [[package]] name = "idna" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" dependencies = [ - "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-normalization 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", + "matches", + "unicode-bidi", + "unicode-normalization", ] [[package]] name = "ignore" version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "522daefc3b69036f80c7d2990b28ff9e0471c683bad05ca258e0a01dd22c5a1e" dependencies = [ - "crossbeam-channel 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "globset 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "same-file 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "walkdir 2.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-channel", + "globset", + "lazy_static", + "log", + "memchr", + "regex", + "same-file", + "thread_local", + "walkdir", + "winapi-util", ] [[package]] name = "im-rc" version = "14.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "303f7e6256d546e01979071417432425f15c1891fb309a5f2d724ee908fabd6e" dependencies = [ - "bitmaps 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_xoshiro 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sized-chunks 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)", - "version_check 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", + "bitmaps", + "rand_core", + "rand_xoshiro", + "sized-chunks", + "typenum", + "version_check", ] [[package]] name = "itoa" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b" [[package]] name = "jobserver" version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b06c1b455f1cf4269a8cfc320ab930a810e2375a42af5075eb8a8b36405ce0" dependencies = [ - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", ] [[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "lazycell" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" [[package]] name = "libc" version = "0.2.65" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a31a0627fdf1f6a39ec0dd577e101440b7db22672c0901fe00a9a6fbb5c24e8" [[package]] name = "libgit2-sys" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9ec6bca50549d34a392611dde775123086acbd994e3fff64954777ce2dc2e51" dependencies = [ - "cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", - "libssh2-sys 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", - "libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys 0.9.53 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", + "cc", + "libc", + "libssh2-sys", + "libz-sys", + "openssl-sys", + "pkg-config", ] [[package]] name = "libnghttp2-sys" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02254d44f4435dd79e695f2c2b83cd06a47919adea30216ceaf0c57ca0a72463" dependencies = [ - "cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "cc", + "libc", ] [[package]] name = "libssh2-sys" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36aa6e813339d3a063292b77091dfbbb6152ff9006a459895fa5bebed7d34f10" dependencies = [ - "cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", - "libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys 0.9.53 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", - "vcpkg 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "cc", + "libc", + "libz-sys", + "openssl-sys", + "pkg-config", + "vcpkg", ] [[package]] name = "libz-sys" version = "1.0.25" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2eb5e43362e38e2bca2fd5f5134c4d4564a23a5c28e9b95411652021a8675ebe" dependencies = [ - "cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", - "vcpkg 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "cc", + "libc", + "pkg-config", + "vcpkg", ] [[package]] name = "log" version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if", ] [[package]] name = "matches" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" [[package]] name = "memchr" version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3197e20c7edb283f87c071ddfc7a2cca8f8e0b888c242959846a6fce03c72223" [[package]] name = "miniz_oxide" version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f3f74f726ae935c3f514300cc6773a0c9492abc5e972d42ba0c0ebb88757625" dependencies = [ - "adler32 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "adler32", ] [[package]] name = "miow" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "396aa0f2003d7df8395cb93e09871561ccc3e785f0acb369170e8cc74ddf9226" dependencies = [ - "socket2 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "socket2", + "winapi", ] [[package]] name = "mir-json" version = "0.1.0" dependencies = [ - "cargo 0.43.1 (registry+https://github.com/rust-lang/crates.io-index)", - "cargo_metadata 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_cbor 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", - "tar 0.4.26 (registry+https://github.com/rust-lang/crates.io-index)", - "toml 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cargo", + "cargo_metadata", + "clap", + "serde", + "serde_cbor", + "serde_derive", + "serde_json", + "tar", + "toml", ] [[package]] name = "num_cpus" version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76dac5ed2a876980778b8b85f75a71b6cbf0db0b1232ee12f826bccb00d09d72" dependencies = [ - "hermit-abi 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "hermit-abi", + "libc", ] [[package]] name = "opener" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13117407ca9d0caf3a0e74f97b490a7e64c0ae3aa90a8b7085544d0c37b6f3ae" dependencies = [ - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi", ] [[package]] name = "openssl" version = "0.10.26" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a3cc5799d98e1088141b8e01ff760112bbd9f19d850c124500566ca6901a585" dependencies = [ - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys 0.9.53 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags", + "cfg-if", + "foreign-types", + "lazy_static", + "libc", + "openssl-sys", ] [[package]] name = "openssl-probe" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" [[package]] name = "openssl-src" version = "111.6.1+1.1.1d" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c91b04cb43c1a8a90e934e0cd612e2a5715d976d2d6cff4490278a0cddf35005" dependencies = [ - "cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)", + "cc", ] [[package]] name = "openssl-sys" version = "0.9.53" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "465d16ae7fc0e313318f7de5cecf57b2fbe7511fd213978b457e1c96ff46736f" dependencies = [ - "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-src 111.6.1+1.1.1d (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", - "vcpkg 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg", + "cc", + "libc", + "openssl-src", + "pkg-config", + "vcpkg", ] [[package]] name = "percent-encoding" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] name = "pkg-config" version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" [[package]] name = "ppv-lite86" version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" [[package]] name = "proc-macro2" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0319972dcae462681daf4da1adeeaa066e3ebd29c69be96c6abb1259d2ee2bcc" dependencies = [ - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid", ] [[package]] name = "quick-error" version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" dependencies = [ - "proc-macro2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", ] [[package]] name = "rand" version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ - "getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "getrandom", + "libc", + "rand_chacha", + "rand_core", + "rand_hc", ] [[package]] name = "rand_chacha" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853" dependencies = [ - "c2-chacha 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "c2-chacha", + "rand_core", ] [[package]] name = "rand_core" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" dependencies = [ - "getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "getrandom", ] [[package]] name = "rand_hc" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" dependencies = [ - "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core", ] [[package]] name = "rand_xoshiro" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9fcdd2e881d02f1d9390ae47ad8e5696a9e4be7b547a1da2afbc61973217004" dependencies = [ - "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core", ] [[package]] name = "redox_syscall" version = "0.1.56" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" [[package]] name = "regex" version = "1.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5508c1941e4e7cb19965abef075d35a9a8b5cdf0846f30b4050e9b55dc55e87" dependencies = [ - "aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", - "thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "aho-corasick", + "memchr", + "regex-syntax", + "thread_local", ] [[package]] name = "regex-syntax" version = "0.6.13" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e734e891f5b408a29efbf8309e656876276f49ab6a6ac208600b4419bd893d90" [[package]] name = "remove_dir_all" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" dependencies = [ - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi", ] [[package]] name = "rustc-workspace-hack" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc71d2faa173b74b232dedc235e3ee1696581bb132fc116fa3626d6151a1a8fb" [[package]] name = "rustfix" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2c50b74badcddeb8f7652fa8323ce440b95286f8e4b64ebfd871c609672704e" dependencies = [ - "anyhow 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", + "anyhow", + "log", + "serde", + "serde_json", ] [[package]] name = "ryu" version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7" [[package]] name = "same-file" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" dependencies = [ - "winapi-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-util", ] [[package]] name = "schannel" version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f550b06b6cba9c8b8be3ee73f391990116bf527450d2556e9b9ce263b9a021" dependencies = [ - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static", + "winapi", ] [[package]] name = "semver" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" dependencies = [ - "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", + "semver-parser", + "serde", ] [[package]] name = "semver-parser" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449" dependencies = [ - "serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive", ] [[package]] name = "serde_cbor" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e18acfa2f90e8b735b2836ab8d538de304cbb6729a7360729ea5a895d15a622" dependencies = [ - "half 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", + "half", + "serde", ] [[package]] name = "serde_derive" version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64" dependencies = [ - "proc-macro2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", + "quote", + "syn", ] [[package]] name = "serde_ignored" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7248fdcbd17d3f2604fc2a02d0ecc844d9a7bf52bf95fc196d9f0a38f6da6a0e" dependencies = [ - "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", + "serde", ] [[package]] name = "serde_json" version = "1.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a23aa71d4a4d43fdbfaac00eff68ba8a06a51759a89ac3304323e800c4dd40d" dependencies = [ - "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa", + "ryu", + "serde", ] [[package]] name = "shell-escape" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "170a13e64f2a51b77a45702ba77287f5c6829375b04a69cf2222acd17d0cfab9" [[package]] name = "sized-chunks" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d59044ea371ad781ff976f7b06480b9f0180e834eda94114f2afb4afc12b7718" dependencies = [ - "bitmaps 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)", + "bitmaps", + "typenum", ] [[package]] name = "smallvec" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44e59e0c9fa00817912ae6e4e6e3c4fe04455e75699d06eedc7d85917ed8e8f4" [[package]] name = "socket2" version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8b74de517221a2cb01a53349cf54182acdc31a074727d3079068448c0676d85" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if", + "libc", + "redox_syscall", + "winapi", ] [[package]] name = "strip-ansi-escapes" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d63676e2abafa709460982ddc02a3bb586b6d15a49b75c212e06edd3933acee" dependencies = [ - "vte 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "vte", ] [[package]] name = "strsim" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "syn" version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e4ff033220a41d1a57d8125eab57bf5263783dfdcc18688b1dacc6ce9651ef8" dependencies = [ - "proc-macro2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", + "quote", + "unicode-xid", ] [[package]] name = "tar" version = "0.4.26" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3196bfbffbba3e57481b6ea32249fbaf590396a52505a2615adbb79d9d826d3" dependencies = [ - "filetime 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", - "xattr 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "filetime", + "libc", + "redox_syscall", + "xattr", ] [[package]] name = "tempfile" version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", - "remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if", + "libc", + "rand", + "redox_syscall", + "remove_dir_all", + "winapi", ] [[package]] name = "termcolor" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" dependencies = [ - "winapi-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-util", ] [[package]] name = "textwrap" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" dependencies = [ - "unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width", ] [[package]] name = "thread_local" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" dependencies = [ - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static", ] [[package]] name = "toml" version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01d1404644c8b12b16bfcffa4322403a91a451584daaaa7c28d3152e6cbc98cf" dependencies = [ - "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", + "serde", ] [[package]] name = "typenum" version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" [[package]] name = "unicode-bidi" version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" dependencies = [ - "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "matches", ] [[package]] name = "unicode-normalization" version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b561e267b2326bb4cebfc0ef9e68355c7abe6c6f522aeac2f5bf95d56c59bdcf" dependencies = [ - "smallvec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec", ] [[package]] name = "unicode-width" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" [[package]] name = "unicode-xid" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" [[package]] name = "url" version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb" dependencies = [ - "idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "idna", + "matches", + "percent-encoding", ] [[package]] name = "utf8parse" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8772a4ccbb4e89959023bc5b7cb8623a795caa7092d99f3aa9501b9484d4557d" [[package]] name = "vcpkg" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fc439f2794e98976c88a2a2dafce96b930fe8010b0a256b3c2199a773933168" [[package]] name = "vec_map" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" [[package]] name = "version_check" version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" [[package]] name = "vte" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f42f536e22f7fcbb407639765c8fd78707a33109301f834a594758bedd6e8cf" dependencies = [ - "utf8parse 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "utf8parse", ] [[package]] name = "walkdir" version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d" dependencies = [ - "same-file 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "same-file", + "winapi", + "winapi-util", ] [[package]] name = "wasi" version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "winapi" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" 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)", + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", ] [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ccfbf554c6ad11084fb7517daca16cfdcaccbdadba4fc336f032a8b12c2ad80" dependencies = [ - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi", ] [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "xattr" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "244c3741f4240ef46274860397c7c74e50eb23624996930e484c16679633a54c" dependencies = [ - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[metadata] -"checksum adler32 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5d2e7343e7fc9de883d1b0341e0b13970f764c14101234857d2ddafa1cb1cac2" -"checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d" -"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" -"checksum anyhow 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)" = "6b602bfe940d21c130f3895acd65221e8a61270debe89d628b9cb4e3ccb8569b" -"checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -"checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" -"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" -"checksum bitmaps 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "031043d04099746d8db04daf1fa424b2bc8bd69d92b25962dcde24da39ab64a2" -"checksum bstr 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3ede750122d9d1f87919570cb2cccee38c84fbc8c5599b25c289af40625b7030" -"checksum bytesize 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "716960a18f978640f25101b5cbf1c6f6b0d3192fab36a2d98ca96f0ecbe41010" -"checksum c2-chacha 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "214238caa1bf3a496ec3392968969cab8549f96ff30652c9e56885329315f6bb" -"checksum cargo 0.43.1 (registry+https://github.com/rust-lang/crates.io-index)" = "91de5749ddcea3c283a042b67b77e2bdf68f28374cdcbfbe54e91368810d92e5" -"checksum cargo-platform 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0226944a63d1bf35a3b5f948dd7c59e263db83695c9e8bffc4037de02e30f1d7" -"checksum cargo_metadata 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "be1057b8462184f634c3a208ee35b0f935cfd94b694b26deadccd98732088d7b" -"checksum cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)" = "95e28fa049fda1c330bcf9d723be7663a899c4679724b34c81e9f5a326aab8cd" -"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" -"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" -"checksum commoncrypto 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d056a8586ba25a1e4d61cb090900e495952c7886786fc55f909ab2f819b69007" -"checksum commoncrypto-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1fed34f46747aa73dfaa578069fd8279d2818ade2b55f38f22a9401c7f4083e2" -"checksum core-foundation 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171" -"checksum core-foundation-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" -"checksum crates-io 0.31.1 (registry+https://github.com/rust-lang/crates.io-index)" = "09f977948a46e9edf93eb3dc2d7a8dd4ce3105d36de63300befed37cdf051d4a" -"checksum crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" -"checksum crossbeam-channel 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "acec9a3b0b3559f15aee4f90746c4e5e293b701c0f7d3925d24e01645267b68c" -"checksum crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ce446db02cdc3165b94ae73111e570793400d0794e46125cc4056c81cbb039f4" -"checksum crypto-hash 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8a77162240fd97248d19a564a565eb563a3f592b386e4136fb300909e67dddca" -"checksum curl 0.4.25 (registry+https://github.com/rust-lang/crates.io-index)" = "06aa71e9208a54def20792d877bc663d6aae0732b9852e612c4a933177c31283" -"checksum curl-sys 0.4.25 (registry+https://github.com/rust-lang/crates.io-index)" = "0c38ca47d60b86d0cc9d42caa90a0885669c2abc9791f871c81f58cdf39e979b" -"checksum env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" -"checksum filetime 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "1ff6d4dab0aa0c8e6346d46052e93b13a16cf847b54ed357087c35011048cc7d" -"checksum flate2 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6bd6d6f4752952feb71363cffc9ebac9411b75b87c6ab6058c40c8900cf43c0f" -"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" -"checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -"checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" -"checksum fs2 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" -"checksum fwdansi 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "08c1f5787fe85505d1f7777268db5103d80a7a374d2316a7ce262e57baf8f208" -"checksum getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" -"checksum git2 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "77519ef7c5beee314d0804d4534f01e0f9e8d9acdee2b7a48627e590b27e0ec4" -"checksum git2-curl 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d2559abb1d87d27668d31bd868a000f0e2e0065d10e78961b62da95d7a7f1cc7" -"checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" -"checksum globset 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "925aa2cac82d8834e2b2a4415b6f6879757fb5c0928fc445ae76461a12eed8f2" -"checksum half 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9ff54597ea139063f4225f1ec47011b03c9de4a486957ff3fc506881dac951d0" -"checksum hermit-abi 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "eff2656d88f158ce120947499e971d743c05dbcbed62e5bd2f38f1698bbc3772" -"checksum hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" -"checksum hex 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "023b39be39e3a2da62a94feb433e91e8bcd37676fbc8bea371daf52b7a769a3e" -"checksum home 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2456aef2e6b6a9784192ae780c0f15bc57df0e918585282325e8c8ac27737654" -"checksum humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" -"checksum humantime 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3c1ad908cc71012b7bea4d0c53ba96a8cba9962f048fa68d143376143d863b7a" -"checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" -"checksum ignore 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "522daefc3b69036f80c7d2990b28ff9e0471c683bad05ca258e0a01dd22c5a1e" -"checksum im-rc 14.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "303f7e6256d546e01979071417432425f15c1891fb309a5f2d724ee908fabd6e" -"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b" -"checksum jobserver 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)" = "67b06c1b455f1cf4269a8cfc320ab930a810e2375a42af5075eb8a8b36405ce0" -"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -"checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" -"checksum libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "1a31a0627fdf1f6a39ec0dd577e101440b7db22672c0901fe00a9a6fbb5c24e8" -"checksum libgit2-sys 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d9ec6bca50549d34a392611dde775123086acbd994e3fff64954777ce2dc2e51" -"checksum libnghttp2-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "02254d44f4435dd79e695f2c2b83cd06a47919adea30216ceaf0c57ca0a72463" -"checksum libssh2-sys 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "36aa6e813339d3a063292b77091dfbbb6152ff9006a459895fa5bebed7d34f10" -"checksum libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "2eb5e43362e38e2bca2fd5f5134c4d4564a23a5c28e9b95411652021a8675ebe" -"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" -"checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" -"checksum memchr 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3197e20c7edb283f87c071ddfc7a2cca8f8e0b888c242959846a6fce03c72223" -"checksum miniz_oxide 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6f3f74f726ae935c3f514300cc6773a0c9492abc5e972d42ba0c0ebb88757625" -"checksum miow 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "396aa0f2003d7df8395cb93e09871561ccc3e785f0acb369170e8cc74ddf9226" -"checksum num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "76dac5ed2a876980778b8b85f75a71b6cbf0db0b1232ee12f826bccb00d09d72" -"checksum opener 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "13117407ca9d0caf3a0e74f97b490a7e64c0ae3aa90a8b7085544d0c37b6f3ae" -"checksum openssl 0.10.26 (registry+https://github.com/rust-lang/crates.io-index)" = "3a3cc5799d98e1088141b8e01ff760112bbd9f19d850c124500566ca6901a585" -"checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" -"checksum openssl-src 111.6.1+1.1.1d (registry+https://github.com/rust-lang/crates.io-index)" = "c91b04cb43c1a8a90e934e0cd612e2a5715d976d2d6cff4490278a0cddf35005" -"checksum openssl-sys 0.9.53 (registry+https://github.com/rust-lang/crates.io-index)" = "465d16ae7fc0e313318f7de5cecf57b2fbe7511fd213978b457e1c96ff46736f" -"checksum percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" -"checksum pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" -"checksum ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" -"checksum proc-macro2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "0319972dcae462681daf4da1adeeaa066e3ebd29c69be96c6abb1259d2ee2bcc" -"checksum quick-error 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" -"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" -"checksum rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" -"checksum rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853" -"checksum rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" -"checksum rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" -"checksum rand_xoshiro 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a9fcdd2e881d02f1d9390ae47ad8e5696a9e4be7b547a1da2afbc61973217004" -"checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" -"checksum regex 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b5508c1941e4e7cb19965abef075d35a9a8b5cdf0846f30b4050e9b55dc55e87" -"checksum regex-syntax 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "e734e891f5b408a29efbf8309e656876276f49ab6a6ac208600b4419bd893d90" -"checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" -"checksum rustc-workspace-hack 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc71d2faa173b74b232dedc235e3ee1696581bb132fc116fa3626d6151a1a8fb" -"checksum rustfix 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f2c50b74badcddeb8f7652fa8323ce440b95286f8e4b64ebfd871c609672704e" -"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7" -"checksum same-file 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" -"checksum schannel 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "87f550b06b6cba9c8b8be3ee73f391990116bf527450d2556e9b9ce263b9a021" -"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" -"checksum serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449" -"checksum serde_cbor 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1e18acfa2f90e8b735b2836ab8d538de304cbb6729a7360729ea5a895d15a622" -"checksum serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64" -"checksum serde_ignored 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7248fdcbd17d3f2604fc2a02d0ecc844d9a7bf52bf95fc196d9f0a38f6da6a0e" -"checksum serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)" = "5a23aa71d4a4d43fdbfaac00eff68ba8a06a51759a89ac3304323e800c4dd40d" -"checksum shell-escape 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "170a13e64f2a51b77a45702ba77287f5c6829375b04a69cf2222acd17d0cfab9" -"checksum sized-chunks 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d59044ea371ad781ff976f7b06480b9f0180e834eda94114f2afb4afc12b7718" -"checksum smallvec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44e59e0c9fa00817912ae6e4e6e3c4fe04455e75699d06eedc7d85917ed8e8f4" -"checksum socket2 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "e8b74de517221a2cb01a53349cf54182acdc31a074727d3079068448c0676d85" -"checksum strip-ansi-escapes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9d63676e2abafa709460982ddc02a3bb586b6d15a49b75c212e06edd3933acee" -"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" -"checksum syn 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1e4ff033220a41d1a57d8125eab57bf5263783dfdcc18688b1dacc6ce9651ef8" -"checksum tar 0.4.26 (registry+https://github.com/rust-lang/crates.io-index)" = "b3196bfbffbba3e57481b6ea32249fbaf590396a52505a2615adbb79d9d826d3" -"checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" -"checksum termcolor 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" -"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -"checksum thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" -"checksum toml 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "01d1404644c8b12b16bfcffa4322403a91a451584daaaa7c28d3152e6cbc98cf" -"checksum typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" -"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" -"checksum unicode-normalization 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b561e267b2326bb4cebfc0ef9e68355c7abe6c6f522aeac2f5bf95d56c59bdcf" -"checksum unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" -"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" -"checksum url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb" -"checksum utf8parse 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8772a4ccbb4e89959023bc5b7cb8623a795caa7092d99f3aa9501b9484d4557d" -"checksum vcpkg 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3fc439f2794e98976c88a2a2dafce96b930fe8010b0a256b3c2199a773933168" -"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" -"checksum version_check 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" -"checksum vte 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4f42f536e22f7fcbb407639765c8fd78707a33109301f834a594758bedd6e8cf" -"checksum walkdir 2.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d" -"checksum wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)" = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" -"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" -"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -"checksum winapi-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4ccfbf554c6ad11084fb7517daca16cfdcaccbdadba4fc336f032a8b12c2ad80" -"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -"checksum xattr 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "244c3741f4240ef46274860397c7c74e50eb23624996930e484c16679633a54c" + "libc", +] diff --git a/src/analyz/mod.rs b/src/analyz/mod.rs index 35449c5..d98dbc6 100644 --- a/src/analyz/mod.rs +++ b/src/analyz/mod.rs @@ -1,20 +1,18 @@ #![macro_use] -use rustc::ty::{self, TyCtxt, List}; -use rustc::mir::{self, Body}; use rustc_ast::{ast, token, tokenstream, visit}; use rustc_hir::def::DefKind; use rustc_hir::def_id::{self, DefId, LOCAL_CRATE}; -use rustc::mir::mono::MonoItem; -use rustc_session::config::OutputType; -use rustc_session; use rustc_index::vec::Idx; use rustc_interface::Queries; -use rustc_mir::monomorphize::collector::{self, MonoItemCollectionMode}; -use rustc_target::spec::abi; -use rustc_session::Session; -use rustc_span::symbol::Symbol; +use rustc_middle::ty::{self, TyCtxt, List}; +use rustc_middle::mir::{self, Body}; +use rustc_middle::mir::mono::MonoItem; +use rustc_session::{self, Session}; +use rustc_session::config::OutputType; use rustc_span::Span; +use rustc_span::symbol::{Symbol, Ident}; +use rustc_target::abi; use std::cell::RefCell; use std::collections::HashMap; use std::fmt::Write as FmtWrite; @@ -39,7 +37,7 @@ basic_json_enum_impl!(mir::BinOp); basic_json_enum_impl!(mir::NullOp); basic_json_enum_impl!(mir::UnOp); -impl<'tcx> ToJson<'tcx> for ty::layout::VariantIdx { +impl<'tcx> ToJson<'tcx> for abi::VariantIdx { fn to_json(&self, _: &mut MirState) -> serde_json::Value { self.as_usize().into() } @@ -619,6 +617,9 @@ fn emit_trait<'tcx>( /// Emit all statics defined in the current crate. fn emit_statics(ms: &mut MirState, out: &mut impl JsonOutput) -> io::Result<()> { + // Now uses tcx.collect_and_partition_mono_items() + todo!() + /* let tcx = ms.state.tcx; let (mono_items, _) = collector::collect_crate_mono_items(tcx, MonoItemCollectionMode::Lazy); for mono_item in mono_items { @@ -629,6 +630,7 @@ fn emit_statics(ms: &mut MirState, out: &mut impl JsonOutput) -> io::Result<()> } } Ok(()) + */ } fn emit_static(ms: &mut MirState, out: &mut impl JsonOutput, def_id: DefId) -> io::Result<()> { @@ -683,6 +685,9 @@ fn init_instances(ms: &mut MirState, out: &mut impl JsonOutput) -> io::Result<() /// Add every `MonoItem::Fn` to `ms.used.instances`. fn init_instances_from_mono_items(ms: &mut MirState) -> io::Result<()> { + // Now uses tcx.collect_and_partition_mono_items() + todo!() + /* let tcx = ms.state.tcx; let (mono_items, _) = collector::collect_crate_mono_items(tcx, MonoItemCollectionMode::Lazy); for mono_item in mono_items { @@ -693,6 +698,7 @@ fn init_instances_from_mono_items(ms: &mut MirState) -> io::Result<()> { } } Ok(()) + */ } /// Initialize the set of needed instances. Returns a list of root instances. @@ -777,7 +783,7 @@ fn emit_instance<'tcx>( let mir = tcx.instance_mir(inst.def); let mir: Body = tcx.subst_and_normalize_erasing_regions( inst.substs, ty::ParamEnv::reveal_all(), &mir as &Body); - let mir = tcx.arena.alloc(mir::BodyAndCache::new(mir)); + let mir = tcx.arena.alloc(mir); emit_fn(ms, out, &name, Some(inst), mir)?; if let ty::InstanceDef::Item(def_id) = inst.def { @@ -1082,13 +1088,13 @@ pub use self::analyze_streaming as analyze; fn make_attr(key: &str, value: &str) -> ast::Attribute { ast::Attribute { kind: ast::AttrKind::Normal(ast::AttrItem { - path: ast::Path::from_ident(ast::Ident::from_str(key)), + path: ast::Path::from_ident(Ident::from_str(key)), args: ast::MacArgs::Delimited( tokenstream::DelimSpan::dummy(), ast::MacDelimiter::Parenthesis, iter::once( tokenstream::TokenTree::token( - token::TokenKind::Ident(ast::Name::intern(value), false), + token::TokenKind::Ident(Symbol::intern(value), false), Span::default(), ), ).collect(), diff --git a/src/analyz/to_json.rs b/src/analyz/to_json.rs index e22d78e..fbd6fe5 100644 --- a/src/analyz/to_json.rs +++ b/src/analyz/to_json.rs @@ -1,7 +1,7 @@ use rustc_hir::def_id::DefId; -use rustc::mir::Body; +use rustc_middle::mir::Body; +use rustc_middle::ty::{self, TyCtxt}; use rustc_session::Session; -use rustc::ty::{self, TyCtxt}; use rustc_span::Span; use rustc_span::symbol::Symbol; use serde_json; @@ -154,7 +154,7 @@ impl<'tcx> TraitInst<'tcx> { #[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] pub struct AdtInst<'tcx> { - pub adt: &'tcx ty::AdtDef, + pub adt: ty::AdtDef<'tcx>, pub substs: ty::subst::SubstsRef<'tcx>, } diff --git a/src/analyz/ty_json.rs b/src/analyz/ty_json.rs index 4e3041c..41f5308 100644 --- a/src/analyz/ty_json.rs +++ b/src/analyz/ty_json.rs @@ -1,12 +1,12 @@ +use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_hir as hir; use rustc_hir::def_id::DefId; -use rustc::mir; -use rustc_mir::interpret; -use rustc::ty; -use rustc::ty::{TyCtxt, TypeFoldable}; -use rustc::ich::StableHashingContext; use rustc_index::vec::{IndexVec, Idx}; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_middle::mir; +use rustc_const_eval::interpret; +use rustc_middle::ty; +use rustc_middle::ty::{TyCtxt, TypeFoldable}; +use rustc_query_system::ich::StableHashingContext; use rustc_target::spec::abi; use rustc_ast::ast; use rustc_span::DUMMY_SP; @@ -749,6 +749,34 @@ fn render_constant<'tcx>( scalar_bits: Option<(u8, u128)>, slice: Option<(&'tcx mir::interpret::Allocation, usize, usize)>, ) -> Option { + + // Special cases: &str and &[u8; _] + if let ty::TyKind::Ref(_, inner_ty, hir::Mutability::Not) = ty.kind() { + if let ty::TyKind::Str = inner_ty.kind() { + // String literal + let (alloc, start, end) = slice.expect("string const had non-slice value"); + let mem = read_static_memory(alloc, start, end); + return Some(json!({ + "kind": "str", + "val": mem, + })); + } + + if let ty::TyKind::Array(elem_ty, len_const) = inner_ty.kind() { + if let ty::TyKind::Uint(ast::UintTy::U8) = elem_ty.kind() { + // Bytestring literal + let len = eval_array_len(mir.state.tcx, len_const); + let (alloc, start, _) = slice.expect("string const had non-slice value"); + let end = start + len; + let mem = read_static_memory(alloc, start, end); + return Some(json!({ + "kind": "bstr", + "val": mem, + })); + } + } + } + Some(match ty.kind { ty::TyKind::Int(_) => { let (size, bits) = scalar_bits.expect("int const had non-scalar value?"); @@ -802,37 +830,6 @@ fn render_constant<'tcx>( }) }, - // &str - for string literals - ty::TyKind::Ref(_, &ty::TyS { - kind: ty::TyKind::Str, - .. - }, hir::Mutability::Not) => { - let (alloc, start, end) = slice.expect("string const had non-slice value"); - let mem = read_static_memory(alloc, start, end); - json!({ - "kind": "str", - "val": mem, - }) - }, - - // &[u8; _] - for bytestring literals - ty::TyKind::Ref(_, &ty::TyS { - kind: ty::TyKind::Array(&ty::TyS { - kind: ty::TyKind::Uint(ast::UintTy::U8), - .. - }, len_const), - .. - }, hir::Mutability::Not) => { - let len = eval_array_len(mir.state.tcx, len_const); - let (alloc, start, _) = slice.expect("string const had non-slice value"); - let end = start + len; - let mem = read_static_memory(alloc, start, end); - json!({ - "kind": "bstr", - "val": mem, - }) - }, - ty::TyKind::RawPtr(_) => { let (_size, bits) = scalar_bits.expect("raw_ptr const had non-scalar value?"); json!({ @@ -952,10 +949,10 @@ struct RenderConstMachine; mod machine { use std::borrow::Cow; use super::*; - use rustc_mir::interpret::*; - use rustc::ty::*; - use rustc::mir::*; use rustc_data_structures::fx::FxHashMap; + use rustc_middle::mir::interpret::*; + use rustc_middle::ty::*; + use rustc_middle::mir::*; use rustc_span::Span; impl<'mir, 'tcx> Machine<'mir, 'tcx> for RenderConstMachine { diff --git a/src/lib.rs b/src/lib.rs index 4423b80..220ecb3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,19 +7,19 @@ extern crate serde_cbor; #[macro_use] extern crate serde_derive; extern crate tar; -extern crate rustc; extern crate rustc_ast; -//extern crate rustc_codegen_utils; +extern crate rustc_const_eval; extern crate rustc_driver; extern crate rustc_data_structures; extern crate rustc_hir; extern crate rustc_index; extern crate rustc_interface; -extern crate rustc_mir; +extern crate rustc_middle; +extern crate rustc_monomorphize; +extern crate rustc_query_system; extern crate rustc_session; extern crate rustc_span; extern crate rustc_target; -//extern crate syntax; pub mod analyz; pub mod lib_util; From 9d103349799038c6b5a175f05c139ab95dcd40ab Mon Sep 17 00:00:00 2001 From: Stuart Pernsteiner Date: Fri, 3 Jun 2022 17:12:34 -0700 Subject: [PATCH 02/35] update Machine trait implementation --- src/analyz/ty_json.rs | 178 +++++++++++++++++++++++++++--------------- 1 file changed, 117 insertions(+), 61 deletions(-) diff --git a/src/analyz/ty_json.rs b/src/analyz/ty_json.rs index 41f5308..8a27e2a 100644 --- a/src/analyz/ty_json.rs +++ b/src/analyz/ty_json.rs @@ -866,7 +866,8 @@ fn render_constant<'tcx>( let scalar = scalar.expect("adt had non-scalar value (NYI)"); let icx = interpret::InterpCx::new( - mir.state.tcx.at(DUMMY_SP), + mir.state.tcx, + DUMMY_SP, ty::ParamEnv::reveal_all(), RenderConstMachine, (), @@ -931,7 +932,7 @@ fn render_constant_variant<'tcx>( Ok(_mpl) => None, Err(imm) => match *imm { interpret::Immediate::Scalar(maybe_scalar) => match maybe_scalar { - interpret::ScalarMaybeUndef::Scalar(s) => { + interpret::ScalarMaybeUninit::Scalar(s) => { render_constant_scalar(mir, field.layout.ty, s) }, _ => None, @@ -949,39 +950,58 @@ struct RenderConstMachine; mod machine { use std::borrow::Cow; use super::*; + use rustc_const_eval::interpret::*; use rustc_data_structures::fx::FxHashMap; - use rustc_middle::mir::interpret::*; use rustc_middle::ty::*; use rustc_middle::mir::*; use rustc_span::Span; + use rustc_target::abi::Size; + use rustc_target::spec::abi::Abi; impl<'mir, 'tcx> Machine<'mir, 'tcx> for RenderConstMachine { - type MemoryKinds = !; - type PointerTag = (); + type MemoryKind = !; + type PointerTag = AllocId; + type TagExtra = (); type ExtraFnVal = !; type FrameExtra = (); - type MemoryExtra = (); type AllocExtra = (); type MemoryMap = FxHashMap< AllocId, (MemoryKind, Allocation), >; - const STATIC_KIND: Option = None; - const CHECK_ALIGN: bool = false; + const GLOBAL_KIND: Option = None; + const PANIC_ON_ALLOC_FAIL: bool = false; - fn enforce_validity(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool { + fn enforce_alignment(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool { + false + } + + fn force_int_for_alignment_check(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool { + false + } + + fn enforce_validity(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool { + false + } + + fn enforce_number_init(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool { + false + } + + fn enforce_number_no_provenance(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool { false } fn find_mir_or_eval_fn( - _ecx: &mut InterpCx<'mir, 'tcx, Self>, - _span: Span, - _instance: Instance<'tcx>, - _args: &[OpTy<'tcx>], - _ret: Option<(PlaceTy<'tcx>, BasicBlock)>, - _unwind: Option, // unwinding is not supported in consts - ) -> InterpResult<'tcx, Option<&'mir Body<'tcx>>> { + ecx: &mut InterpCx<'mir, 'tcx, Self>, + instance: ty::Instance<'tcx>, + abi: Abi, + args: &[OpTy<'tcx, Self::PointerTag>], + destination: &PlaceTy<'tcx, Self::PointerTag>, + target: Option, + unwind: StackPopUnwind, + ) -> InterpResult<'tcx, Option<(&'mir mir::Body<'tcx>, ty::Instance<'tcx>)>> { Err(InterpError::Unsupported( UnsupportedOpInfo::Unsupported( "find_mir_or_eval_fn".into(), @@ -990,11 +1010,13 @@ mod machine { } fn call_extra_fn( - _ecx: &mut InterpCx<'mir, 'tcx, Self>, - _fn_val: Self::ExtraFnVal, - _args: &[OpTy<'tcx, Self::PointerTag>], - _ret: Option<(PlaceTy<'tcx, Self::PointerTag>, BasicBlock)>, - _unwind: Option + ecx: &mut InterpCx<'mir, 'tcx, Self>, + fn_val: Self::ExtraFnVal, + abi: Abi, + args: &[OpTy<'tcx, Self::PointerTag>], + destination: &PlaceTy<'tcx, Self::PointerTag>, + target: Option, + unwind: StackPopUnwind, ) -> InterpResult<'tcx> { Err(InterpError::Unsupported( UnsupportedOpInfo::Unsupported( @@ -1004,12 +1026,12 @@ mod machine { } fn call_intrinsic( - _ecx: &mut InterpCx<'mir, 'tcx, Self>, - _span: Span, - _instance: Instance<'tcx>, - _args: &[OpTy<'tcx, Self::PointerTag>], - _ret: Option<(PlaceTy<'tcx, Self::PointerTag>, BasicBlock)>, - _unwind: Option + ecx: &mut InterpCx<'mir, 'tcx, Self>, + instance: ty::Instance<'tcx>, + args: &[OpTy<'tcx, Self::PointerTag>], + destination: &PlaceTy<'tcx, Self::PointerTag>, + target: Option, + unwind: StackPopUnwind, ) -> InterpResult<'tcx> { Err(InterpError::Unsupported( UnsupportedOpInfo::Unsupported( @@ -1019,9 +1041,9 @@ mod machine { } fn assert_panic( - _ecx: &mut InterpCx<'mir, 'tcx, Self>, - _msg: &AssertMessage<'tcx>, - _unwind: Option + ecx: &mut InterpCx<'mir, 'tcx, Self>, + msg: &mir::AssertMessage<'tcx>, + unwind: Option, ) -> InterpResult<'tcx> { Err(InterpError::Unsupported( UnsupportedOpInfo::Unsupported( @@ -1031,10 +1053,10 @@ mod machine { } fn binary_ptr_op( - _ecx: &InterpCx<'mir, 'tcx, Self>, - _bin_op: BinOp, - _left: ImmTy<'tcx, Self::PointerTag>, - _right: ImmTy<'tcx, Self::PointerTag> + ecx: &InterpCx<'mir, 'tcx, Self>, + bin_op: mir::BinOp, + left: &ImmTy<'tcx, Self::PointerTag>, + right: &ImmTy<'tcx, Self::PointerTag>, ) -> InterpResult<'tcx, (Scalar, bool, Ty<'tcx>)> { Err(InterpError::Unsupported( UnsupportedOpInfo::Unsupported( @@ -1043,52 +1065,86 @@ mod machine { ).into()) } - fn tag_static_base_pointer( - _memory_extra: &Self::MemoryExtra, - _id: AllocId, - ) -> Self::PointerTag { - () + fn extern_static_base_pointer( + ecx: &InterpCx<'mir, 'tcx, Self>, + def_id: DefId, + ) -> InterpResult<'tcx, Pointer> { + Err(InterpError::Unsupported( + UnsupportedOpInfo::Unsupported( + "extern_static_base_pointer".into(), + ), + ).into()) + } + + fn tag_alloc_base_pointer( + ecx: &InterpCx<'mir, 'tcx, Self>, + ptr: Pointer, + ) -> Pointer { + unimplemented!("tag_alloc_base_pointer") + } + + fn ptr_from_addr_cast( + ecx: &InterpCx<'mir, 'tcx, Self>, + addr: u64, + ) -> Pointer> { + unimplemented!("ptr_from_addr_cast") + } + + fn ptr_from_addr_transmute( + ecx: &InterpCx<'mir, 'tcx, Self>, + addr: u64, + ) -> Pointer> { + unimplemented!("ptr_from_addr_transmute") } - fn box_alloc( - _ecx: &mut InterpCx<'mir, 'tcx, Self>, - _dest: PlaceTy<'tcx, Self::PointerTag> + fn expose_ptr( + ecx: &mut InterpCx<'mir, 'tcx, Self>, + ptr: Pointer, ) -> InterpResult<'tcx> { Err(InterpError::Unsupported( UnsupportedOpInfo::Unsupported( - "box_alloc".into(), + "expose_ptr".into(), ), ).into()) } + fn ptr_get_alloc( + ecx: &InterpCx<'mir, 'tcx, Self>, + ptr: Pointer, + ) -> Option<(AllocId, Size, Self::TagExtra)> { + None + } + fn init_allocation_extra<'b>( - _memory_extra: &Self::MemoryExtra, - _id: AllocId, + ecx: &InterpCx<'mir, 'tcx, Self>, + id: AllocId, alloc: Cow<'b, Allocation>, - _kind: Option> - ) -> (Cow<'b, Allocation>, Self::PointerTag) { - (alloc, ()) + kind: Option>, + ) -> Cow<'b, Allocation> { + alloc } - fn stack_push( - _ecx: &mut InterpCx<'mir, 'tcx, Self> - ) -> InterpResult<'tcx, Self::FrameExtra> { + fn init_frame_extra( + ecx: &mut InterpCx<'mir, 'tcx, Self>, + frame: Frame<'mir, 'tcx, Self::PointerTag>, + ) -> InterpResult<'tcx, Frame<'mir, 'tcx, Self::PointerTag, Self::FrameExtra>> { Err(InterpError::Unsupported( UnsupportedOpInfo::Unsupported( - "stack_push".into(), + "init_frame_extra".into(), ), ).into()) } - fn ptr_to_int( - _mem: &Memory<'mir, 'tcx, Self>, - _ptr: Pointer - ) -> InterpResult<'tcx, u64> { - Err(InterpError::Unsupported( - UnsupportedOpInfo::Unsupported( - "ptr_to_int".into(), - ), - ).into()) + fn stack<'a>( + ecx: &'a InterpCx<'mir, 'tcx, Self>, + ) -> &'a [Frame<'mir, 'tcx, Self::PointerTag, Self::FrameExtra>] { + unimplemented!("stack") + } + + fn stack_mut<'a>( + ecx: &'a mut InterpCx<'mir, 'tcx, Self>, + ) -> &'a mut Vec> { + unimplemented!("stack_mut") } } } From 5527c578f3b2f902a4d9f1e5a1a5739a8141db84 Mon Sep 17 00:00:00 2001 From: Stuart Pernsteiner Date: Mon, 6 Jun 2022 10:14:38 -0700 Subject: [PATCH 03/35] fix build errors in analyz/mod.rs --- src/analyz/mod.rs | 133 ++++++++++++++++++++++++------------------ src/analyz/to_json.rs | 2 +- src/analyz/ty_json.rs | 36 ++++++++---- 3 files changed, 104 insertions(+), 67 deletions(-) diff --git a/src/analyz/mod.rs b/src/analyz/mod.rs index d98dbc6..f5e3e14 100644 --- a/src/analyz/mod.rs +++ b/src/analyz/mod.rs @@ -13,6 +13,7 @@ use rustc_session::config::OutputType; use rustc_span::Span; use rustc_span::symbol::{Symbol, Ident}; use rustc_target::abi; +use rustc_target::spec; use std::cell::RefCell; use std::collections::HashMap; use std::fmt::Write as FmtWrite; @@ -92,12 +93,12 @@ fn vtable_descriptor_for_cast<'tcx>( } // Relevant code: rustc_codegen_ssa::base::unsized_info, and other functions in that file. - let old_pointee = match old_ty.kind { + let old_pointee = match *old_ty.kind() { ty::TyKind::Ref(_, ty, _) => ty, ty::TyKind::RawPtr(ref tm) => tm.ty, _ => return None, }; - let new_pointee = match new_ty.kind { + let new_pointee = match *new_ty.kind() { ty::TyKind::Ref(_, ty, _) => ty, ty::TyKind::RawPtr(ref tm) => tm.ty, _ => return None, @@ -109,7 +110,7 @@ fn vtable_descriptor_for_cast<'tcx>( } // Relevant code: rustc_codegen_ssa::meth::get_vtable - let trait_ref = match new_pointee.kind { + let trait_ref = match *new_pointee.kind() { ty::TyKind::Dynamic(ref preds, _) => preds.principal().map(|pred| pred.with_self_ty(tcx, old_pointee)), _ => return None, @@ -137,7 +138,7 @@ impl<'tcx> ToJson<'tcx> for mir::Rvalue<'tcx> { json!({ "kind": "Repeat", "op": op.to_json(mir), - "len": s + "len": s.to_json(mir), }) } &mir::Rvalue::Ref(_, ref bk, ref l) => { @@ -158,7 +159,7 @@ impl<'tcx> ToJson<'tcx> for mir::Rvalue<'tcx> { &mir::Rvalue::Len(ref l) => { json!({"kind": "Len", "lv": l.to_json(mir)}) } - &mir::Rvalue::Cast(ref ck, ref op, ref ty) => { + &mir::Rvalue::Cast(ref ck, ref op, ty) => { let mut j = json!({ "kind": "Cast", "type": ck.to_json(mir), @@ -176,20 +177,20 @@ impl<'tcx> ToJson<'tcx> for mir::Rvalue<'tcx> { } j } - &mir::Rvalue::BinaryOp(ref binop, ref op1, ref op2) => { + &mir::Rvalue::BinaryOp(ref binop, ref ops) => { json!({ "kind": "BinaryOp", "op": binop.to_json(mir), - "L": op1.to_json(mir), - "R": op2.to_json(mir) + "L": ops.0.to_json(mir), + "R": ops.1.to_json(mir) }) } - &mir::Rvalue::CheckedBinaryOp(ref binop, ref op1, ref op2) => { + &mir::Rvalue::CheckedBinaryOp(ref binop, ref ops) => { json!({ "kind": "CheckedBinaryOp", "op": binop.to_json(mir), - "L": op1.to_json(mir), - "R": op2.to_json(mir) + "L": ops.0.to_json(mir), + "R": ops.1.to_json(mir) }) } &mir::Rvalue::NullaryOp(ref no, ref t) => { @@ -307,7 +308,10 @@ impl<'tcx> ToJson<'tcx> for mir::Operand<'tcx> { impl<'tcx> ToJson<'tcx> for mir::Constant<'tcx> { fn to_json(&self, mir: &mut MirState<'_, 'tcx>) -> serde_json::Value { - self.literal.to_json(mir) + match self.literal { + mir::ConstantKind::Ty(c) => c.to_json(mir), + mir::ConstantKind::Val(cv, _) => cv.to_json(mir), + } } } @@ -354,10 +358,6 @@ impl<'tcx> ToJson<'tcx> for mir::Statement<'tcx> { &mir::StatementKind::StorageDead(l) => { json!({"kind": "StorageDead", "sdvar": local_json(mir, l)}) } - &mir::StatementKind::InlineAsm { .. } => { - // TODO - json!({"kind": "InlineAsm"}) - } &mir::StatementKind::Retag { .. } => { // TODO json!({"kind": "Retag"}) @@ -385,12 +385,13 @@ impl ToJson<'_> for Span { let source_map = mir.state.session.source_map(); let callsite = self.source_callsite(); let s = if callsite == *self { - source_map.span_to_string(*self) + // Use `span_to_diagnostic_string` to get a string with full file paths. + source_map.span_to_diagnostic_string(*self) } else { format!( "{} !{}", - source_map.span_to_string(*self), - source_map.span_to_string(callsite), + source_map.span_to_diagnostic_string(*self), + source_map.span_to_diagnostic_string(callsite), ) }; s.into() @@ -406,11 +407,10 @@ impl<'tcx> ToJson<'tcx> for mir::Terminator<'tcx> { &mir::TerminatorKind::SwitchInt { ref discr, ref switch_ty, - ref values, ref targets, } => { let vals: Vec = - values.iter().map(|&c| c.to_string()).collect(); + targets.iter().map(|(c, _)| c.to_string()).collect(); let discr_span = mir.match_span_map.get(&self.source_info.span).cloned() .or_else(|| operand_span(mir, discr)) .unwrap_or(self.source_info.span); @@ -420,7 +420,8 @@ impl<'tcx> ToJson<'tcx> for mir::Terminator<'tcx> { "discr_span": discr_span.to_json(mir), "switch_ty": switch_ty.to_json(mir), "values": vals, - "targets": targets.to_json(mir) + "targets": targets.all_targets().iter().map(|x| x.to_json(mir)) + .collect::>(), }) } &mir::TerminatorKind::Resume => { @@ -433,7 +434,7 @@ impl<'tcx> ToJson<'tcx> for mir::Terminator<'tcx> { json!({"kind": "Unreachable"}) } &mir::TerminatorKind::Drop { - ref location, + place: ref location, ref target, ref unwind, } => { @@ -447,7 +448,7 @@ impl<'tcx> ToJson<'tcx> for mir::Terminator<'tcx> { }) } &mir::TerminatorKind::DropAndReplace { - ref location, + place: ref location, ref value, ref target, ref unwind, @@ -465,15 +466,23 @@ impl<'tcx> ToJson<'tcx> for mir::Terminator<'tcx> { &mir::TerminatorKind::Call { ref func, ref args, - ref destination, + destination: ref dest_place, + target: ref dest_block, ref cleanup, - ref from_hir_call + ref from_hir_call, + fn_span: _, } => { + let destination = dest_block.as_ref().map(|dest_block| { + json!([ + dest_place.to_json(mir), + dest_block.to_json(mir), + ]) + }); json!({ "kind": "Call", "func": func.to_json(mir), "args": args.to_json(mir), - "destination": destination.to_json(mir), + "destination": destination, "cleanup": cleanup.to_json(mir), "from_hir_call": from_hir_call }) @@ -503,10 +512,10 @@ impl<'tcx> ToJson<'tcx> for mir::Terminator<'tcx> { "kind": "Yield" }) } - &mir::TerminatorKind::FalseEdges { .. } => { + &mir::TerminatorKind::FalseEdge { .. } => { // TODO json!({ - "kind": "FalseEdges" + "kind": "FalseEdge" }) } &mir::TerminatorKind::FalseUnwind { .. } => { @@ -518,6 +527,10 @@ impl<'tcx> ToJson<'tcx> for mir::Terminator<'tcx> { &mir::TerminatorKind::GeneratorDrop => { json!({ "kind": "GeneratorDrop" }) } + &mir::TerminatorKind::InlineAsm { .. } => { + // TODO + json!({"kind": "InlineAsm"}) + } }; j["pos"] = self.source_info.span.to_json(mir); j @@ -580,7 +593,7 @@ fn emit_trait<'tcx>( ) -> io::Result<()> { let tcx = ms.state.tcx; let methods = if let Some(tref) = ti.concrete_trait_ref(tcx) { - tcx.vtable_methods(ty::Binder::dummy(tref)) + tcx.vtable_entries(ty::Binder::dummy(tref)) } else { &[] }; @@ -589,12 +602,12 @@ fn emit_trait<'tcx>( // `m` is `None` for methods with `where Self: Sized`. We omit these from the vtable, and // adjust `InstanceDef::Virtual` indices accordingly. let (def_id, substs) = match m { - Some(x) => x, - None => continue, + ty::vtable::VtblEntry::Method(inst) => (inst.def.def_id(), inst.substs), + _ => continue, }; let sig = tcx.subst_and_normalize_erasing_regions( - substs, ty::ParamEnv::reveal_all(), &tcx.fn_sig(def_id)); - let sig = tcx.erase_late_bound_regions(&sig); + substs, ty::ParamEnv::reveal_all(), tcx.fn_sig(def_id)); + let sig = tcx.erase_late_bound_regions(sig); items.push(json!({ "kind": "Method", @@ -704,12 +717,13 @@ fn init_instances_from_mono_items(ms: &mut MirState) -> io::Result<()> { /// Initialize the set of needed instances. Returns a list of root instances. fn init_instances_from_tests(ms: &mut MirState, out: &mut impl JsonOutput) -> io::Result<()> { let tcx = ms.state.tcx; - for &def_id in tcx.mir_keys(def_id::LOCAL_CRATE) { + for &local_def_id in tcx.mir_keys(()) { + let def_id = local_def_id.to_def_id(); if !has_test_attr(tcx, def_id) { continue; } - if tcx.def_kind(def_id) != Some(DefKind::Fn) { + if tcx.def_kind(def_id) != DefKind::Fn { tcx.sess.span_err( tcx.def_span(def_id), "#[test] can only be applied to functions", @@ -725,8 +739,11 @@ fn init_instances_from_tests(ms: &mut MirState, out: &mut impl JsonOutput) -> io } let inst = ty::Instance::resolve(tcx, ty::ParamEnv::reveal_all(), def_id, List::empty()) - .unwrap_or_else(|| { + .unwrap_or_else(|_| { panic!("Instance::resolve failed to find test function {:?}?", def_id); + }) + .unwrap_or_else(|| { + panic!("ambiguous Instance::resolve for find test function {:?}?", def_id); }); ms.used.instances.insert(inst); @@ -758,6 +775,7 @@ fn emit_instance<'tcx>( match inst.def { ty::InstanceDef::Item(def_id) => { // Foreign items and non-generics have no MIR available. + let def_id = def_id.did; if tcx.is_foreign_item(def_id) { return Ok(()); } @@ -782,14 +800,15 @@ fn emit_instance<'tcx>( // Look up and monomorphize the MIR for this instance. let mir = tcx.instance_mir(inst.def); let mir: Body = tcx.subst_and_normalize_erasing_regions( - inst.substs, ty::ParamEnv::reveal_all(), &mir as &Body); + inst.substs, ty::ParamEnv::reveal_all(), mir.clone()); let mir = tcx.arena.alloc(mir); emit_fn(ms, out, &name, Some(inst), mir)?; if let ty::InstanceDef::Item(def_id) = inst.def { + let def_id = def_id.did; for (idx, mir) in tcx.promoted_mir(def_id).iter_enumerated() { let mir = tcx.subst_and_normalize_erasing_regions( - inst.substs, ty::ParamEnv::reveal_all(), mir); + inst.substs, ty::ParamEnv::reveal_all(), mir.clone()); let mir = tcx.arena.alloc(mir); emit_promoted(ms, out, &name, idx, mir)?; } @@ -817,7 +836,7 @@ fn emit_vtable<'tcx>( out: &mut impl JsonOutput, trait_ref: ty::PolyTraitRef<'tcx>, ) -> io::Result<()> { - let ti = TraitInst::from_trait_ref(ms.state.tcx, *trait_ref.skip_binder()); + let ti = TraitInst::from_trait_ref(ms.state.tcx, trait_ref.skip_binder()); out.emit(EntryKind::Vtable, json!({ "trait_id": trait_inst_id_str(ms.state.tcx, &ti), "name": vtable_name(ms, trait_ref), @@ -838,15 +857,15 @@ fn build_vtable_items<'tcx>( trait_ref: ty::PolyTraitRef<'tcx>, ) -> serde_json::Value { let tcx = mir.state.tcx; - let methods = tcx.vtable_methods(trait_ref); + let methods = tcx.vtable_entries(trait_ref); let mut parts = Vec::with_capacity(methods.len()); for &m in methods { // `m` is `None` for methods with `where Self: Sized`. We omit these from the vtable, and // adjust `InstanceDef::Virtual` indices accordingly. let (def_id, substs) = match m { - Some(x) => x, - None => continue, + ty::vtable::VtblEntry::Method(inst) => (inst.def.def_id(), inst.substs), + _ => continue, }; parts.push(json!({ "item_id": def_id.to_json(mir), @@ -893,7 +912,7 @@ fn emit_fn<'tcx>( }; let ms = &mut ms; - let abi = inst.map(|i| inst_abi(ms.state.tcx, i)).unwrap_or(abi::Abi::Rust); + let abi = inst.map(|i| inst_abi(ms.state.tcx, i)).unwrap_or(spec::abi::Abi::Rust); out.emit(EntryKind::Fn, json!({ "name": &name, @@ -920,20 +939,21 @@ fn emit_new_types( fn inst_abi<'tcx>( tcx: TyCtxt<'tcx>, inst: ty::Instance<'tcx>, -) -> abi::Abi { +) -> spec::abi::Abi { match inst.def { ty::InstanceDef::Item(def_id) => { + let def_id = def_id.did; let ty = tcx.type_of(def_id); - match ty.kind { + match *ty.kind() { ty::TyKind::FnDef(_, _) => ty.fn_sig(tcx).skip_binder().abi, - ty::TyKind::Closure(_, _) => abi::Abi::RustCall, - _ => abi::Abi::Rust, + ty::TyKind::Closure(_, _) => spec::abi::Abi::RustCall, + _ => spec::abi::Abi::Rust, } }, - ty::InstanceDef::Intrinsic(_) => abi::Abi::RustIntrinsic, - ty::InstanceDef::ClosureOnceShim { .. } => abi::Abi::RustCall, - _ => abi::Abi::Rust, + ty::InstanceDef::Intrinsic(_) => spec::abi::Abi::RustIntrinsic, + ty::InstanceDef::ClosureOnceShim { .. } => spec::abi::Abi::RustCall, + _ => spec::abi::Abi::Rust, } } @@ -957,20 +977,20 @@ fn analyze_inner<'tcx, O: JsonOutput, F: FnOnce(&Path) -> io::Result>( let mut extern_mir_paths = Vec::new(); let output = queries.global_ctxt().unwrap().peek_mut().enter(|tcx| -> io::Result<_> { - let outputs = tcx.output_filenames(LOCAL_CRATE); + let outputs = tcx.output_filenames(()); if !outputs.outputs.contains_key(&OutputType::Exe) { return Ok(None); } let mir_path_ = rustc_session::output::out_filename( sess, - sess.crate_types.get().first().unwrap().clone(), + sess.crate_types().first().unwrap().clone(), &outputs, - &tcx.crate_name.to_string(), + &tcx.crate_name(LOCAL_CRATE).to_string(), ).with_extension("mir"); let mut out = mk_output(&mir_path_)?; mir_path = Some(mir_path_); - for &cnum in tcx.all_crate_nums(LOCAL_CRATE) { + for &cnum in tcx.crates(()) { let src = tcx.used_crate_source(cnum); let it = src.dylib.iter() .chain(src.rlib.iter()) @@ -1099,7 +1119,8 @@ fn make_attr(key: &str, value: &str) -> ast::Attribute { ), ).collect(), ), - }), + tokens: None, + }, None), id: ast::AttrId::new(0), style: ast::AttrStyle::Inner, span: Span::default(), diff --git a/src/analyz/to_json.rs b/src/analyz/to_json.rs index fbd6fe5..20fd215 100644 --- a/src/analyz/to_json.rs +++ b/src/analyz/to_json.rs @@ -178,7 +178,7 @@ pub struct TyIntern<'tcx> { /// Info for describing a type. The `String` indicates (at minimum) the `TyKind`, and the `bool` /// is `true` if a hash of the type should be included when forming the type's unique ID. fn ty_desc(ty: ty::Ty) -> (String, bool) { - let kind_str = match ty.kind { + let kind_str = match *ty.kind() { // Special case: primitive types print as themselves and don't require a hash. ty::TyKind::Bool | ty::TyKind::Char | diff --git a/src/analyz/ty_json.rs b/src/analyz/ty_json.rs index 8a27e2a..c7169e4 100644 --- a/src/analyz/ty_json.rs +++ b/src/analyz/ty_json.rs @@ -265,7 +265,7 @@ impl<'tcx> ToJson<'tcx> for ty::Instance<'tcx> { ty::InstanceDef::Virtual(did, idx) => { let self_ty = substs.types().next() .unwrap_or_else(|| panic!("expected self type in substs for {:?}", self)); - let preds = match self_ty.kind { + let preds = match *self_ty.kind() { ty::TyKind::Dynamic(ref preds, _region) => preds, _ => panic!("expected `dyn` self type, but got {:?}", self_ty), }; @@ -299,7 +299,7 @@ impl<'tcx> ToJson<'tcx> for ty::Instance<'tcx> { "ty": ty.to_json(mir), }), ty::InstanceDef::CloneShim(did, ty) => { - let sub_tys = match ty.kind { + let sub_tys = match *ty.kind() { ty::TyKind::Array(t, _) => vec![t], ty::TyKind::Tuple(substs) => substs.types().collect(), ty::TyKind::Closure(closure_did, substs) => @@ -347,7 +347,7 @@ impl<'tcx> ToJson<'tcx> for ty::Ty<'tcx> { } // Otherwise, convert the type to JSON and add the new entry to the interning table. - let j = match &self.kind { + let j = match self.kind() { &ty::TyKind::Bool => { json!({"kind": "Bool"}) } @@ -751,8 +751,8 @@ fn render_constant<'tcx>( ) -> Option { // Special cases: &str and &[u8; _] - if let ty::TyKind::Ref(_, inner_ty, hir::Mutability::Not) = ty.kind() { - if let ty::TyKind::Str = inner_ty.kind() { + if let ty::TyKind::Ref(_, inner_ty, hir::Mutability::Not) = *ty.kind() { + if let ty::TyKind::Str = *inner_ty.kind() { // String literal let (alloc, start, end) = slice.expect("string const had non-slice value"); let mem = read_static_memory(alloc, start, end); @@ -762,8 +762,8 @@ fn render_constant<'tcx>( })); } - if let ty::TyKind::Array(elem_ty, len_const) = inner_ty.kind() { - if let ty::TyKind::Uint(ast::UintTy::U8) = elem_ty.kind() { + if let ty::TyKind::Array(elem_ty, len_const) = *inner_ty.kind() { + if let ty::TyKind::Uint(ast::UintTy::U8) = *elem_ty.kind() { // Bytestring literal let len = eval_array_len(mir.state.tcx, len_const); let (alloc, start, _) = slice.expect("string const had non-slice value"); @@ -777,7 +777,7 @@ fn render_constant<'tcx>( } } - Some(match ty.kind { + Some(match *ty.kind() { ty::TyKind::Int(_) => { let (size, bits) = scalar_bits.expect("int const had non-scalar value?"); let mut val = bits as i128; @@ -786,7 +786,7 @@ fn render_constant<'tcx>( val |= -1_i128 << (size * 8); } json!({ - "kind": match ty.kind { + "kind": match *ty.kind() { ty::TyKind::Int(ast::IntTy::Isize) => "isize", ty::TyKind::Int(_) => "int", _ => unreachable!(), @@ -800,7 +800,7 @@ fn render_constant<'tcx>( ty::TyKind::Uint(_) => { let (size, bits) = scalar_bits.expect("uint const had non-scalar value?"); json!({ - "kind": match ty.kind { + "kind": match *ty.kind() { ty::TyKind::Bool => "bool", ty::TyKind::Char => "char", ty::TyKind::Uint(ast::UintTy::Usize) => "usize", @@ -1188,6 +1188,22 @@ impl<'tcx> ToJson<'tcx> for ty::Const<'tcx> { } } +impl<'tcx> ToJson<'tcx> for interpret::ConstValue<'tcx> { + fn to_json(&self, mir: &mut MirState<'_, 'tcx>) -> serde_json::Value { + match *self { + interpret::ConstValue::Scalar(s) => { + render_constant_scalar(mir, self.ty, s) + .unwrap_or_else(|| json!({"type": "unknown_scalar"})) + }, + interpret::ConstValue::Slice { data, start, end } => { + render_constant(mir, self.ty, None, None, Some((data, start, end))) + .unwrap_or_else(|| json!({"type": "unknown_slice"})) + }, + interpret::ConstValue::ByRef { .. } => json!({"kind": "unknown_by_ref"}), + }; + } +} + fn iter_tojson<'a, 'tcx, I, V: 'a>( it: I, mir: &mut MirState<'_, 'tcx>, From a5809e181cb0de4136df2f2ff9b9f3a0f60e530f Mon Sep 17 00:00:00 2001 From: Stuart Pernsteiner Date: Mon, 6 Jun 2022 10:47:28 -0700 Subject: [PATCH 04/35] fix build errors in analyz/to_json.rs --- src/analyz/to_json.rs | 33 +++++++++++++++++---------------- src/analyz/ty_json.rs | 4 ++-- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/analyz/to_json.rs b/src/analyz/to_json.rs index 20fd215..c681a88 100644 --- a/src/analyz/to_json.rs +++ b/src/analyz/to_json.rs @@ -89,11 +89,12 @@ pub struct TraitInst<'tcx> { impl<'tcx> TraitInst<'tcx> { pub fn from_dynamic_predicates( tcx: TyCtxt<'tcx>, - preds: ty::Binder<&'tcx ty::List>>, + preds: &'tcx ty::List>>, ) -> TraitInst<'tcx> { - let preds = tcx.erase_late_bound_regions(&preds); - let trait_ref = preds.principal(); - let mut projs = preds.projection_bounds().collect::>(); + let trait_ref = preds.principal().map(|tr| tcx.erase_late_bound_regions(tr)); + let mut projs = preds.projection_bounds() + .map(|proj| tcx.erase_late_bound_regions(proj)) + .collect::>(); projs.sort_by_key(|p| p.item_def_id); TraitInst { trait_ref, projs } } @@ -111,7 +112,7 @@ impl<'tcx> TraitInst<'tcx> { // FIXME: build projs for supertrait trait_refs as well for ai in tcx.associated_items(trait_ref.def_id).in_definition_order() { match ai.kind { - ty::AssocKind::Type | ty::AssocKind::OpaqueTy => {}, + ty::AssocKind::Type => {}, _ => continue, } let proj_ty = tcx.mk_projection(ai.def_id, trait_ref.substs); @@ -119,7 +120,7 @@ impl<'tcx> TraitInst<'tcx> { projs.push(ty::ExistentialProjection { item_def_id: ai.def_id, substs: ex_trait_ref.substs, - ty: actual_ty, + term: ty::Term::Ty(actual_ty), }); } projs.sort_by_key(|p| p.item_def_id); @@ -133,10 +134,12 @@ impl<'tcx> TraitInst<'tcx> { pub fn dyn_ty(&self, tcx: TyCtxt<'tcx>) -> Option> { let trait_ref = self.trait_ref?; let mut preds = Vec::with_capacity(self.projs.len() + 1); - preds.push(ty::ExistentialPredicate::Trait(trait_ref)); - preds.extend(self.projs.iter().map(|p| ty::ExistentialPredicate::Projection(*p))); - let preds = tcx.intern_existential_predicates(&preds); - Some(tcx.mk_dynamic(ty::Binder::bind(preds), tcx.mk_region(ty::RegionKind::ReErased))) + preds.push(ty::Binder::dummy(ty::ExistentialPredicate::Trait(trait_ref))); + preds.extend( + self.projs.iter().map(|p| ty::Binder::dummy(ty::ExistentialPredicate::Projection(*p))), + ); + let preds = tcx.intern_poly_existential_predicates(&preds); + Some(tcx.mk_dynamic(preds, tcx.mk_region(ty::RegionKind::ReErased))) } /// Build a concrete, non-existential TraitRef, filling in the `Self` parameter with the `dyn` @@ -159,12 +162,12 @@ pub struct AdtInst<'tcx> { } impl<'tcx> AdtInst<'tcx> { - pub fn new(adt: &'tcx ty::AdtDef, substs: ty::subst::SubstsRef<'tcx>) -> AdtInst<'tcx> { + pub fn new(adt: ty::AdtDef<'tcx>, substs: ty::subst::SubstsRef<'tcx>) -> AdtInst<'tcx> { AdtInst { adt, substs } } pub fn def_id(&self) -> DefId { - self.adt.did + self.adt.did() } } @@ -187,9 +190,6 @@ fn ty_desc(ty: ty::Ty) -> (String, bool) { ty::TyKind::Float(_) | ty::TyKind::Str => return (format!("{:?}", ty), false), - ty::TyKind::Never | - ty::TyKind::Error => return (format!("{:?}", ty.kind), false), - ty::TyKind::Adt(..) => "Adt", ty::TyKind::Foreign(..) => "Foreign", ty::TyKind::Array(..) => "Array", @@ -202,14 +202,15 @@ fn ty_desc(ty: ty::Ty) -> (String, bool) { ty::TyKind::Closure(..) => "Closure", ty::TyKind::Generator(..) => "Generator", ty::TyKind::GeneratorWitness(..) => "GeneratorWitness", + ty::TyKind::Never => "Never", ty::TyKind::Tuple(..) => "Tuple", ty::TyKind::Projection(..) => "Projection", - ty::TyKind::UnnormalizedProjection(..) => "UnnormalizedProjection", ty::TyKind::Opaque(..) => "Opaque", ty::TyKind::Param(..) => "Param", ty::TyKind::Bound(..) => "Bound", ty::TyKind::Placeholder(..) => "Placeholder", ty::TyKind::Infer(..) => "Infer", + ty::TyKind::Error(..) => "Error", }; (kind_str.to_owned(), true) } diff --git a/src/analyz/ty_json.rs b/src/analyz/ty_json.rs index c7169e4..4b71ae6 100644 --- a/src/analyz/ty_json.rs +++ b/src/analyz/ty_json.rs @@ -418,8 +418,8 @@ impl<'tcx> ToJson<'tcx> for ty::Ty<'tcx> { // tuples, so no additional information is needed. }) } - &ty::TyKind::Dynamic(ref preds, _region) => { - let ti = TraitInst::from_dynamic_predicates(mir.state.tcx, *preds); + &ty::TyKind::Dynamic(preds, _region) => { + let ti = TraitInst::from_dynamic_predicates(mir.state.tcx, preds); let trait_name = trait_inst_id_str(mir.state.tcx, &ti); mir.used.traits.insert(ti); json!({ From b36fe5663daf96ef906422300a59741ecd95ec40 Mon Sep 17 00:00:00 2001 From: Stuart Pernsteiner Date: Mon, 6 Jun 2022 13:31:49 -0700 Subject: [PATCH 05/35] fix build errors in analyz/ty_json.rs --- src/analyz/mod.rs | 2 +- src/analyz/ty_json.rs | 230 +++++++++++++++++++----------------------- 2 files changed, 104 insertions(+), 128 deletions(-) diff --git a/src/analyz/mod.rs b/src/analyz/mod.rs index f5e3e14..b125130 100644 --- a/src/analyz/mod.rs +++ b/src/analyz/mod.rs @@ -310,7 +310,7 @@ impl<'tcx> ToJson<'tcx> for mir::Constant<'tcx> { fn to_json(&self, mir: &mut MirState<'_, 'tcx>) -> serde_json::Value { match self.literal { mir::ConstantKind::Ty(c) => c.to_json(mir), - mir::ConstantKind::Val(cv, _) => cv.to_json(mir), + mir::ConstantKind::Val(cv, ty) => (cv, ty).to_json(mir), } } } diff --git a/src/analyz/ty_json.rs b/src/analyz/ty_json.rs index 4b71ae6..d8bed57 100644 --- a/src/analyz/ty_json.rs +++ b/src/analyz/ty_json.rs @@ -22,16 +22,16 @@ impl<'tcx, T> ToJson<'tcx> for ty::List { fn to_json(&self, mir: &mut MirState<'_, 'tcx>) -> serde_json::Value { let mut j = Vec::new(); - for v in self { + for v in self.iter() { j.push(v.to_json(mir)); } json!(j) } } -basic_json_enum_impl!(ast::FloatTy); -basic_json_enum_impl!(ast::IntTy); -basic_json_enum_impl!(ast::UintTy); +basic_json_enum_impl!(ty::FloatTy); +basic_json_enum_impl!(ty::IntTy); +basic_json_enum_impl!(ty::UintTy); basic_json_enum_impl!(hir::Mutability); basic_json_enum_impl!(hir::def::CtorKind); basic_json_enum_impl!(mir::CastKind); @@ -66,18 +66,15 @@ impl ToJson<'_> for ty::VariantDiscr { pub fn def_id_str(tcx: TyCtxt, def_id: hir::def_id::DefId) -> String { // Based on rustc/ty/context.rs.html TyCtxt::def_path_debug_str - let crate_name = if def_id.is_local() { - tcx.crate_name.clone() - } else { - tcx.crate_name(def_id.krate) - }; - let disambig = if def_id.is_local() { - tcx.sess.local_crate_disambiguator() - } else { - tcx.crate_disambiguator(def_id.krate) - }; + let crate_name = tcx.crate_name(def_id.krate); + let disambig = tcx.crate_hash(def_id.krate); let defpath = tcx.def_path(def_id); - format!("{}/{}{}", crate_name, &disambig.to_string()[..8], defpath.to_string_no_crate()) + format!( + "{}/{}{}", + crate_name, + &disambig.to_string()[..8], + defpath.to_string_no_crate_verbose(), + ) } pub fn ext_def_id_str<'tcx, T>( @@ -103,7 +100,7 @@ pub fn adt_inst_id_str<'tcx>( ai: AdtInst<'tcx>, ) -> String { // Erase all early-bound regions. - let substs = tcx.erase_regions(&ai.substs); + let substs = tcx.erase_regions(ai.substs); ext_def_id_str(tcx, ai.def_id(), "_adt", substs) } @@ -119,7 +116,7 @@ pub fn inst_id_str<'tcx>( assert!(!substs.needs_subst()); match inst.def { - ty::InstanceDef::Item(def_id) | + ty::InstanceDef::Item(ty::WithOptConstParam { did: def_id, .. }) | ty::InstanceDef::Intrinsic(def_id) => { if substs.len() == 0 { def_id_str(tcx, def_id) @@ -136,7 +133,7 @@ pub fn inst_id_str<'tcx>( ty::InstanceDef::DropGlue(def_id, _) => ext_def_id_str(tcx, def_id, "_drop", substs), ty::InstanceDef::FnPtrShim(def_id, _) | - ty::InstanceDef::ClosureOnceShim { call_once: def_id } => + ty::InstanceDef::ClosureOnceShim { call_once: def_id, .. } => ext_def_id_str(tcx, def_id, "_callonce", substs), ty::InstanceDef::CloneShim(def_id, _) => ext_def_id_str(tcx, def_id, "_shim", substs), @@ -171,7 +168,7 @@ pub fn get_fn_def_name<'tcx>( ); // Compute the mangled name of the monomorphized instance being called. - if let Some(inst) = inst { + if let Ok(Some(inst)) = inst { mir.used.instances.insert(inst); inst_id_str(mir.state.tcx, inst) } else { @@ -221,11 +218,13 @@ impl ToJson<'_> for hir::def_id::DefId { /// of counting to ours. fn adjust_method_index<'tcx>( tcx: TyCtxt<'tcx>, - tref: ty::Binder>, + tref: ty::Binder<'tcx, ty::TraitRef<'tcx>>, raw_idx: usize, ) -> usize { - let methods = tcx.vtable_methods(tref); - methods.iter().take(raw_idx).filter(|m| m.is_some()).count() + let methods = tcx.vtable_entries(tref); + methods.iter().take(raw_idx) + .filter(|m| matches!(m, ty::vtable::VtblEntry::Method(_))) + .count() } impl<'tcx> ToJson<'tcx> for ty::Instance<'tcx> { @@ -238,7 +237,7 @@ impl<'tcx> ToJson<'tcx> for ty::Instance<'tcx> { match self.def { ty::InstanceDef::Item(did) => json!({ "kind": "Item", - "def_id": did.to_json(mir), + "def_id": did.did.to_json(mir), "substs": substs.to_json(mir), }), ty::InstanceDef::Intrinsic(did) => json!({ @@ -275,7 +274,7 @@ impl<'tcx> ToJson<'tcx> for ty::Instance<'tcx> { }; let tref = ex_tref.with_self_ty(mir.state.tcx, self_ty); - let erased_tref = mir.state.tcx.erase_late_bound_regions(&tref); + let erased_tref = mir.state.tcx.erase_late_bound_regions(tref); let ti = TraitInst::from_trait_ref(mir.state.tcx, erased_tref); let trait_name = trait_inst_id_str(mir.state.tcx, &ti); mir.used.traits.insert(ti); @@ -287,7 +286,7 @@ impl<'tcx> ToJson<'tcx> for ty::Instance<'tcx> { "index": adjust_method_index(mir.state.tcx, tref, idx), }) }, - ty::InstanceDef::ClosureOnceShim { call_once } => json!({ + ty::InstanceDef::ClosureOnceShim { call_once, .. } => json!({ "kind": "ClosureOnceShim", "call_once": call_once.to_json(mir), "substs": substs.to_json(mir), @@ -301,9 +300,9 @@ impl<'tcx> ToJson<'tcx> for ty::Instance<'tcx> { ty::InstanceDef::CloneShim(did, ty) => { let sub_tys = match *ty.kind() { ty::TyKind::Array(t, _) => vec![t], - ty::TyKind::Tuple(substs) => substs.types().collect(), + ty::TyKind::Tuple(ts) => ts[..].to_owned(), ty::TyKind::Closure(closure_did, substs) => - substs.as_closure().upvar_tys(closure_did, mir.state.tcx).collect(), + substs.as_closure().upvar_tys().collect(), _ => { eprintln!("warning: don't know how to build clone shim for {:?}", ty); vec![] @@ -316,7 +315,9 @@ impl<'tcx> ToJson<'tcx> for ty::Instance<'tcx> { ty::ParamEnv::reveal_all(), did, mir.state.tcx.intern_substs(&[ty.into()]), - ); + ).unwrap_or_else(|_| { + panic!("failed to resolve instance: {:?}, {:?}", did, ty); + }); if let Some(inst) = inst { // Add the callee to `used.insances`, so we'll emit code for it even if // it's otherwise unused. If `inst` is itself a `CloneShim`, its own @@ -354,10 +355,10 @@ impl<'tcx> ToJson<'tcx> for ty::Ty<'tcx> { &ty::TyKind::Char => { json!({"kind": "Char"}) } - &ty::TyKind::Int(ref t) => { + &ty::TyKind::Int(t) => { json!({"kind": "Int", "intkind": t.to_json(mir)}) } - &ty::TyKind::Uint(ref t) => { + &ty::TyKind::Uint(t) => { json!({"kind": "Uint", "uintkind": t.to_json(mir)}) } &ty::TyKind::Tuple(ref sl) => { @@ -369,7 +370,7 @@ impl<'tcx> ToJson<'tcx> for ty::Ty<'tcx> { &ty::TyKind::Str => { json!({"kind": "Str"}) } - &ty::TyKind::Float(ref sz) => { + &ty::TyKind::Float(sz) => { json!({"kind": "Float", "size": sz.to_json(mir)}) } &ty::TyKind::Array(ref t, ref size) => { @@ -395,7 +396,7 @@ impl<'tcx> ToJson<'tcx> for ty::Ty<'tcx> { json!({ "kind": "Adt", "name": adt_inst_id_str(mir.state.tcx, ai), - "orig_def_id": adtdef.did.to_json(mir), + "orig_def_id": adtdef.did().to_json(mir), "substs": substs.to_json(mir), }) } @@ -412,7 +413,7 @@ impl<'tcx> ToJson<'tcx> for ty::Ty<'tcx> { &ty::TyKind::Closure(defid, ref substs) => { json!({ "kind": "Closure", - "upvar_tys": substs.as_closure().upvar_tys(defid, mir.state.tcx) + "upvar_tys": substs.as_closure().upvar_tys() .collect::>().to_json(mir), // mir-verifier uses the same representation for closures as it does for // tuples, so no additional information is needed. @@ -425,22 +426,20 @@ impl<'tcx> ToJson<'tcx> for ty::Ty<'tcx> { json!({ "kind": "Dynamic", "trait_id": trait_name, - "predicates": preds.skip_binder().to_json(mir), + "predicates": preds.iter().map(|p| p.skip_binder().to_json(mir)) + .collect::>(), }) } &ty::TyKind::Projection(..) => unreachable!( "no TyKind::Projection should remain after monomorphization" ), - &ty::TyKind::UnnormalizedProjection(..) => unreachable!( - "no TyKind::UnnormalizedProjection should remain after monomorphization" - ), &ty::TyKind::FnPtr(ref sig) => { json!({"kind": "FnPtr", "signature": sig.to_json(mir)}) } &ty::TyKind::Never => { json!({"kind": "Never"}) } - &ty::TyKind::Error => { + &ty::TyKind::Error(_) => { json!({"kind": "Error"}) } &ty::TyKind::Infer(_) => { @@ -486,7 +485,7 @@ impl ToJson<'_> for ty::ParamTy { impl<'tcx> ToJson<'tcx> for ty::PolyFnSig<'tcx> { fn to_json(&self, ms: &mut MirState<'_, 'tcx>) -> serde_json::Value { - let sig = ms.state.tcx.erase_late_bound_regions(self); + let sig = ms.state.tcx.erase_late_bound_regions(*self); sig.to_json(ms) } } @@ -525,16 +524,18 @@ impl<'tcx> ToJson<'tcx> for ty::ProjectionTy<'tcx> { impl<'tcx> ToJson<'tcx> for ty::Predicate<'tcx> { fn to_json(&self, ms: &mut MirState<'_, 'tcx>) -> serde_json::Value { - match self { - &ty::Predicate::Trait(ref ptp, _constness) => { + match self.kind().skip_binder() { + ty::PredicateKind::Trait(tp) => { json!({ - "trait_pred": ptp.to_json(ms) + "trait_pred": tp.trait_ref.to_json(ms) }) } - &ty::Predicate::Projection(ref ppp) => { - json!({ - "trait_proj": ppp.skip_binder().to_json(ms) - }) + ty::PredicateKind::Projection(pp) => match pp.term { + ty::Term::Ty(ty) => json!({ + "projection_ty": pp.projection_ty.to_json(ms), + "ty": ty.to_json(ms), + }), + ty::Term::Const(_) => json!("unknown_const_projection"), } _ => { json!("unknown_pred") @@ -543,22 +544,6 @@ impl<'tcx> ToJson<'tcx> for ty::Predicate<'tcx> { } } -impl<'tcx> ToJson<'tcx> for ty::PolyTraitPredicate<'tcx> { - fn to_json(&self, ms: &mut MirState<'_, 'tcx>) -> serde_json::Value { - let pred = ms.state.tcx.erase_late_bound_regions(self); - pred.trait_ref.to_json(ms) - } -} - -impl<'tcx> ToJson<'tcx> for ty::ProjectionPredicate<'tcx> { - fn to_json(&self, ms: &mut MirState<'_, 'tcx>) -> serde_json::Value { - json!({ - "projection_ty": self.projection_ty.to_json(ms), - "ty": self.ty.to_json(ms) - }) - } -} - // Existential predicate (dynamic / trait object version of `ty::Predicate`) impl<'tcx> ToJson<'tcx> for ty::ExistentialPredicate<'tcx> { @@ -571,13 +556,16 @@ impl<'tcx> ToJson<'tcx> for ty::ExistentialPredicate<'tcx> { "substs": trait_ref.substs.to_json(ms), }) }, - &ty::ExistentialPredicate::Projection(ref proj) => { - json!({ + &ty::ExistentialPredicate::Projection(ref proj) => match proj.term { + ty::Term::Ty(ty) => json!({ "kind": "Projection", "proj": proj.item_def_id.to_json(ms), "substs": proj.substs.to_json(ms), - "rhs_ty": proj.ty.to_json(ms), - }) + "rhs_ty": ty.to_json(ms), + }), + ty::Term::Const(_) => json!({ + "kind": "Projection_Const", + }), }, &ty::ExistentialPredicate::AutoTrait(ref did) => { json!({ @@ -662,34 +650,20 @@ impl<'tcx> ToJson<'tcx> for ty::subst::GenericArg<'tcx> { } } -fn do_const_eval<'tcx>( - tcx: TyCtxt<'tcx>, - def_id: DefId, - substs: ty::subst::SubstsRef<'tcx>, - promoted: Option, -) -> mir::interpret::ConstValue<'tcx> { - let param_env = ty::ParamEnv::reveal_all(); - let instance = ty::Instance::resolve(tcx, param_env, def_id, substs).unwrap(); - let cid = interpret::GlobalId { - instance, - promoted, - }; - tcx.const_eval_validated(param_env.and(cid)).unwrap() -} - fn eval_array_len<'tcx>( tcx: TyCtxt<'tcx>, - c: &'tcx ty::Const<'tcx>, + c: ty::Const<'tcx>, ) -> usize { - let evaluated = match c.val { - ty::ConstKind::Unevaluated(def_id, substs, promoted) => { - do_const_eval(tcx, def_id, substs, promoted) + let evaluated = match c.val() { + ty::ConstKind::Unevaluated(un) => { + tcx.const_eval_resolve(ty::ParamEnv::reveal_all(), un, None).unwrap() }, ty::ConstKind::Value(val) => val, - _ => panic!("don't know how to translate ConstKind::{:?}", c.val), + ref val => panic!("don't know how to translate ConstKind::{:?}", val), }; match evaluated { - interpret::ConstValue::Scalar(interpret::Scalar::Raw { size: _, data }) => { + interpret::ConstValue::Scalar(interpret::Scalar::Int( + ty::ScalarInt { size: _, data })) => { assert!(data <= usize::MAX as u128); data as usize }, @@ -703,7 +677,7 @@ fn read_static_memory<'tcx>( end: usize, ) -> &'tcx [u8] { assert!(alloc.relocations().len() == 0); - alloc.inspect_with_undef_and_ptr_outside_interpreter(start .. end) + alloc.inspect_with_uninit_and_ptr_outside_interpreter(start .. end) } fn render_constant_scalar<'tcx>( @@ -712,24 +686,24 @@ fn render_constant_scalar<'tcx>( s: interpret::Scalar, ) -> Option { match s { - interpret::Scalar::Raw { size, data } => { + interpret::Scalar::Int(ty::ScalarInt { size, data }) => { render_constant(mir, ty, Some(s), Some((size, data)), None) }, - interpret::Scalar::Ptr(ptr) => { - match mir.state.tcx.alloc_map.lock().get(ptr.alloc_id) { + interpret::Scalar::Ptr(ptr, _) => { + match mir.state.tcx.get_global_alloc(ptr.provenance) { Some(ga) => match ga { interpret::GlobalAlloc::Static(def_id) => Some(json!({ "kind": "static_ref", "def_id": def_id.to_json(mir), })), interpret::GlobalAlloc::Memory(alloc) => { - let start = ptr.offset.bytes() as usize; + let start = ptr.into_parts().1.bytes() as usize; render_constant( mir, ty, Some(s), None, - Some((alloc, start, start)), + Some((alloc.inner(), start, start)), ) }, _ => None, @@ -763,7 +737,7 @@ fn render_constant<'tcx>( } if let ty::TyKind::Array(elem_ty, len_const) = *inner_ty.kind() { - if let ty::TyKind::Uint(ast::UintTy::U8) = *elem_ty.kind() { + if let ty::TyKind::Uint(ty::UintTy::U8) = *elem_ty.kind() { // Bytestring literal let len = eval_array_len(mir.state.tcx, len_const); let (alloc, start, _) = slice.expect("string const had non-slice value"); @@ -787,7 +761,7 @@ fn render_constant<'tcx>( } json!({ "kind": match *ty.kind() { - ty::TyKind::Int(ast::IntTy::Isize) => "isize", + ty::TyKind::Int(ty::IntTy::Isize) => "isize", ty::TyKind::Int(_) => "int", _ => unreachable!(), }, @@ -803,7 +777,7 @@ fn render_constant<'tcx>( "kind": match *ty.kind() { ty::TyKind::Bool => "bool", ty::TyKind::Char => "char", - ty::TyKind::Uint(ast::UintTy::Usize) => "usize", + ty::TyKind::Uint(ty::UintTy::Usize) => "usize", ty::TyKind::Uint(_) => "uint", _ => unreachable!(), }, @@ -811,7 +785,7 @@ fn render_constant<'tcx>( "val": bits.to_string(), }) }, - ty::TyKind::Float(ast::FloatTy::F32) => { + ty::TyKind::Float(ty::FloatTy::F32) => { let (size, bits) = scalar_bits.expect("f32 const had non-scalar value?"); let val = f32::from_bits(bits as u32); json!({ @@ -820,7 +794,7 @@ fn render_constant<'tcx>( "val": val.to_string(), }) }, - ty::TyKind::Float(ast::FloatTy::F64) => { + ty::TyKind::Float(ty::FloatTy::F64) => { let (size, bits) = scalar_bits.expect("f64 const had non-scalar value?"); let val = f64::from_bits(bits as u64); json!({ @@ -870,21 +844,20 @@ fn render_constant<'tcx>( DUMMY_SP, ty::ParamEnv::reveal_all(), RenderConstMachine, - (), ); let op_ty = interpret::ImmTy::from_scalar(scalar, tyl).into(); - let (_discr, variant_idx) = icx.read_discriminant(op_ty).unwrap_or_else(|e| { + let (_discr, variant_idx) = icx.read_discriminant(&op_ty).unwrap_or_else(|e| { panic!("failed to access discriminant of {:?}: {}", op_ty.layout.ty, e) }); - let variant = &adt_def.variants[variant_idx]; + let variant = &adt_def.variants()[variant_idx]; json!({ "kind": "enum", "variant": variant_idx.as_u32(), "fields": render_constant_variant( mir, variant, - icx.operand_downcast(op_ty, variant_idx).unwrap_or_else(|e| { + icx.operand_downcast(&op_ty, variant_idx).unwrap_or_else(|e| { panic!("failed to downcast {:?} to variant {:?}: {}", op_ty.layout.ty, variant_idx, e) }), @@ -910,25 +883,26 @@ fn render_constant_variant<'tcx>( op_ty: interpret::OpTy<'tcx>, ) -> Option { let icx = interpret::InterpCx::new( - mir.state.tcx.at(DUMMY_SP), + mir.state.tcx, + DUMMY_SP, ty::ParamEnv::reveal_all(), RenderConstMachine, - (), ); let mut vals = Vec::with_capacity(variant.fields.len()); for i in 0 .. variant.fields.len() { - let field = icx.operand_field(op_ty, i as u64).unwrap_or_else(|e| { + let field = icx.operand_field(&op_ty, i).unwrap_or_else(|e| { panic!("failed to access field {} of {:?}: {}", i, op_ty.layout.ty, e) }); // `try_as_mplace` always "succeeds" (returns an `MPlace`, dangling) for ZSTs. We want it // to be an immediate instead. if field.layout.is_zst() { - vals.push(render_constant_scalar(mir, field.layout.ty, interpret::Scalar::zst())?); + let zst_scalar = interpret::Scalar::Int(ty::ScalarInt::ZST); + vals.push(render_constant_scalar(mir, field.layout.ty, zst_scalar)?); continue; } - let val = match field.try_as_mplace(&icx) { + let val = match field.try_as_mplace() { Ok(_mpl) => None, Err(imm) => match *imm { interpret::Immediate::Scalar(maybe_scalar) => match maybe_scalar { @@ -1152,31 +1126,31 @@ mod machine { impl<'tcx> ToJson<'tcx> for ty::Const<'tcx> { fn to_json(&self, mir: &mut MirState<'_, 'tcx>) -> serde_json::Value { let mut map = serde_json::Map::new(); - map.insert("ty".to_owned(), self.ty.to_json(mir)); + map.insert("ty".to_owned(), self.ty().to_json(mir)); - match self.val { - ty::ConstKind::Unevaluated(def_id, substs, promoted) => { + match self.val() { + ty::ConstKind::Unevaluated(un) => { map.insert("initializer".to_owned(), json!({ - "def_id": get_promoted_name(mir, def_id, substs, promoted), + "def_id": get_promoted_name(mir, un.def.did, un.substs, un.promoted), })); }, _ => {}, } - let evaluated = match self.val { - ty::ConstKind::Unevaluated(def_id, substs, promoted) => { - do_const_eval(mir.state.tcx, def_id, substs, promoted) + let evaluated = match self.val() { + ty::ConstKind::Unevaluated(un) => { + mir.state.tcx.const_eval_resolve(ty::ParamEnv::reveal_all(), un, None).unwrap() }, ty::ConstKind::Value(val) => val, - _ => panic!("don't know how to translate ConstKind::{:?}", self.val), + _ => panic!("don't know how to translate ConstKind::{:?}", self.val()), }; let rendered = match evaluated { interpret::ConstValue::Scalar(s) => { - render_constant_scalar(mir, self.ty, s) + render_constant_scalar(mir, self.ty(), s) }, interpret::ConstValue::Slice { data, start, end } => { - render_constant(mir, self.ty, None, None, Some((data, start, end))) + render_constant(mir, self.ty(), None, None, Some((data.inner(), start, end))) }, _ => None, }; @@ -1188,19 +1162,20 @@ impl<'tcx> ToJson<'tcx> for ty::Const<'tcx> { } } -impl<'tcx> ToJson<'tcx> for interpret::ConstValue<'tcx> { +impl<'tcx> ToJson<'tcx> for (interpret::ConstValue<'tcx>, ty::Ty<'tcx>) { fn to_json(&self, mir: &mut MirState<'_, 'tcx>) -> serde_json::Value { - match *self { + let (val, ty) = *self; + match val { interpret::ConstValue::Scalar(s) => { - render_constant_scalar(mir, self.ty, s) + render_constant_scalar(mir, ty, s) .unwrap_or_else(|| json!({"type": "unknown_scalar"})) }, interpret::ConstValue::Slice { data, start, end } => { - render_constant(mir, self.ty, None, None, Some((data, start, end))) + render_constant(mir, ty, None, None, Some((data.inner(), start, end))) .unwrap_or_else(|| json!({"type": "unknown_slice"})) }, interpret::ConstValue::ByRef { .. } => json!({"kind": "unknown_by_ref"}), - }; + } } } @@ -1275,10 +1250,10 @@ impl<'tcx> ToJson<'tcx> for AdtInst<'tcx> { json!({ "name": adt_inst_id_str(mir.state.tcx, *self), "kind": format!("{:?}", self.adt.adt_kind()), - "variants": self.adt.variants.tojson(mir, self.substs), + "variants": self.adt.variants().tojson(mir, self.substs), "size": tyl.size.bytes(), - "repr_transparent": self.adt.repr.transparent(), - "orig_def_id": self.adt.did.to_json(mir), + "repr_transparent": self.adt.repr().transparent(), + "orig_def_id": self.adt.did().to_json(mir), "orig_substs": self.substs.to_json(mir), }) } @@ -1307,7 +1282,7 @@ impl ToJsonAg for ty::FieldDef { ) -> serde_json::Value { let unsubst_ty = mir.state.tcx.type_of(self.did); let ty = mir.state.tcx.subst_and_normalize_erasing_regions( - substs, ty::ParamEnv::reveal_all(), &unsubst_ty); + substs, ty::ParamEnv::reveal_all(), unsubst_ty); json!({ "name": self.did.to_json(mir), "ty": ty.to_json(mir), @@ -1321,7 +1296,8 @@ pub fn handle_adt_ag<'tcx>( opv: &Vec>, ) -> serde_json::Value { match ak { - &mir::AggregateKind::Adt(ref adt, variant, substs, _, _) => { + &mir::AggregateKind::Adt(adt_did, variant, substs, _, _) => { + let adt = mir.state.tcx.adt_def(adt_did); json!({ "adt": AdtInst::new(adt, substs).to_json(mir), "variant": variant.to_json(mir), From 893c30ab99a748084969a61c9b2bbc4fcf4b9a60 Mon Sep 17 00:00:00 2001 From: Stuart Pernsteiner Date: Mon, 6 Jun 2022 16:44:03 -0700 Subject: [PATCH 06/35] fix remaining build errors in library --- src/analyz/mod.rs | 25 +++++++++++++++++++++++++ src/analyz/ty_json.rs | 9 +++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/analyz/mod.rs b/src/analyz/mod.rs index b125130..cb072dd 100644 --- a/src/analyz/mod.rs +++ b/src/analyz/mod.rs @@ -149,6 +149,12 @@ impl<'tcx> ToJson<'tcx> for mir::Rvalue<'tcx> { "refvar": l.to_json(mir) }) } + &mir::Rvalue::ThreadLocalRef(did) => { + json!({ + "kind": "ThreadLocalRef", + "def_id": did.to_json(mir) + }) + } &mir::Rvalue::AddressOf(mutbl, ref l) => { json!({ "kind": "AddressOf", @@ -224,6 +230,13 @@ impl<'tcx> ToJson<'tcx> for mir::Rvalue<'tcx> { }) } } + &mir::Rvalue::ShallowInitBox(ref op, ty) => { + json!({ + "kind": "ShallowInitBox", + "ptr": op.to_json(mir), + "ty": ty.to_json(mir) + }) + } } } } @@ -342,6 +355,10 @@ impl<'tcx> ToJson<'tcx> for mir::Statement<'tcx> { // TODO json!({"kind": "FakeRead"}) } + &mir::StatementKind::Deinit { .. } => { + // TODO + json!({"kind": "Deinit"}) + } &mir::StatementKind::SetDiscriminant { ref place, ref variant_index, @@ -366,6 +383,14 @@ impl<'tcx> ToJson<'tcx> for mir::Statement<'tcx> { // TODO json!({"kind": "AscribeUserType"}) } + &mir::StatementKind::Coverage { .. } => { + // TODO + json!({"kind": "Coverage"}) + } + &mir::StatementKind::CopyNonOverlapping { .. } => { + // TODO + json!({"kind": "CopyNonOverlapping"}) + } &mir::StatementKind::Nop => { json!({"kind": "Nop"}) } diff --git a/src/analyz/ty_json.rs b/src/analyz/ty_json.rs index d8bed57..30efe1f 100644 --- a/src/analyz/ty_json.rs +++ b/src/analyz/ty_json.rs @@ -662,8 +662,8 @@ fn eval_array_len<'tcx>( ref val => panic!("don't know how to translate ConstKind::{:?}", val), }; match evaluated { - interpret::ConstValue::Scalar(interpret::Scalar::Int( - ty::ScalarInt { size: _, data })) => { + interpret::ConstValue::Scalar(interpret::Scalar::Int(sint)) => { + let data = sint.to_bits(sint.size()).unwrap(); assert!(data <= usize::MAX as u128); data as usize }, @@ -686,8 +686,9 @@ fn render_constant_scalar<'tcx>( s: interpret::Scalar, ) -> Option { match s { - interpret::Scalar::Int(ty::ScalarInt { size, data }) => { - render_constant(mir, ty, Some(s), Some((size, data)), None) + interpret::Scalar::Int(sint) => { + let data = sint.to_bits(sint.size()).unwrap(); + render_constant(mir, ty, Some(s), Some((sint.size().bytes() as u8, data)), None) }, interpret::Scalar::Ptr(ptr, _) => { match mir.state.tcx.get_global_alloc(ptr.provenance) { From 1ab307424fb0fb7e2e5523dc529eea385334e53c Mon Sep 17 00:00:00 2001 From: Stuart Pernsteiner Date: Mon, 6 Jun 2022 16:44:13 -0700 Subject: [PATCH 07/35] fix build errors in binaries --- build.rs | 15 +++++++++++++++ src/bin/cargo-crux-test.rs | 2 +- src/bin/mir-json-callgraph.rs | 1 - src/bin/mir-json-dce.rs | 4 ++-- src/bin/mir-json-rustc-wrapper.rs | 23 +++++------------------ src/bin/mir-json.rs | 10 ++-------- 6 files changed, 25 insertions(+), 30 deletions(-) create mode 100644 build.rs diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..ef32190 --- /dev/null +++ b/build.rs @@ -0,0 +1,15 @@ +use std::path::Path; +use std::process::Command; +use std::str; + +fn main() { + // Add the toolchain lib/ directory to `-L`. This fixes the linker error "cannot find + // -lLLVM-13-rust-1.60.0-nightly". + let out = Command::new("rustup") + .args(&["which", "rustc"]) + .output().unwrap(); + assert!(out.status.success()); + let rustc_path = Path::new(str::from_utf8(&out.stdout).unwrap().trim_end()); + let lib_dir = rustc_path.parent().unwrap().parent().unwrap().join("lib"); + println!("cargo:rustc-link-search={}", lib_dir.display()); +} diff --git a/src/bin/cargo-crux-test.rs b/src/bin/cargo-crux-test.rs index 3d3fc0b..12a0b56 100644 --- a/src/bin/cargo-crux-test.rs +++ b/src/bin/cargo-crux-test.rs @@ -15,7 +15,6 @@ #![feature(rustc_private)] extern crate cargo; extern crate clap; -extern crate rustc; extern crate rustc_session; extern crate serde_json; @@ -26,6 +25,7 @@ use rustc_session::config::host_triple; use cargo::util::command_prelude::*; fn cli() -> App { + todo!("update to match recent cargo-test cli"); // Copy-pasted from cargo/src/bin/cargo/commands/test.rs, with minor edits to the text. subcommand("crux-test") .setting(AppSettings::TrailingVarArg) diff --git a/src/bin/mir-json-callgraph.rs b/src/bin/mir-json-callgraph.rs index 22eca7b..3dd3daa 100644 --- a/src/bin/mir-json-callgraph.rs +++ b/src/bin/mir-json-callgraph.rs @@ -8,7 +8,6 @@ extern crate serde; extern crate serde_cbor; #[macro_use] extern crate serde_json; -extern crate env_logger; extern crate mir_json; use std::collections::{HashMap, HashSet}; diff --git a/src/bin/mir-json-dce.rs b/src/bin/mir-json-dce.rs index 57c83ca..3467ce7 100644 --- a/src/bin/mir-json-dce.rs +++ b/src/bin/mir-json-dce.rs @@ -9,9 +9,9 @@ extern crate serde; extern crate serde_cbor; -extern crate env_logger; #[macro_use] extern crate log; extern crate mir_json; +extern crate rustc_log; use std::env; use std::fs::File; @@ -22,7 +22,7 @@ use mir_json::link; fn main() { - env_logger::init(); + rustc_log::init_env_logger("RUST_LOG").unwrap(); let mut last_time = Instant::now(); let mut measure = || { diff --git a/src/bin/mir-json-rustc-wrapper.rs b/src/bin/mir-json-rustc-wrapper.rs index cdf010b..f0ebff3 100644 --- a/src/bin/mir-json-rustc-wrapper.rs +++ b/src/bin/mir-json-rustc-wrapper.rs @@ -3,7 +3,6 @@ //! as specified by `--extern` and/or `#![no_std]` and run `mir-verifier` on the result. #![feature(rustc_private)] -extern crate rustc; extern crate rustc_codegen_ssa; extern crate rustc_driver; extern crate rustc_interface; @@ -68,7 +67,7 @@ impl rustc_driver::Callbacks for GetOutputPathCallbacks { let outputs = queries.prepare_outputs().unwrap().peek(); self.output_path = Some(rustc_session::output::out_filename( sess, - sess.crate_types.get().first().unwrap().clone(), + sess.crate_types().first().unwrap().clone(), &outputs, &crate_name, )); @@ -81,12 +80,7 @@ fn get_output_path(args: &[String], use_override_crates: &HashSet) -> Pa output_path: None, use_override_crates: use_override_crates.clone(), }; - rustc_driver::run_compiler( - &args, - &mut callbacks, - None, - None, - ).unwrap(); + rustc_driver::RunCompiler::new(&args, &mut callbacks).run().unwrap(); callbacks.output_path.unwrap() } @@ -202,15 +196,13 @@ fn go() { eprintln!("normal build - {:?}", args); // This is a normal, non-test build. Just run the build, generating a `.mir` file // alongside the normal output. - rustc_driver::run_compiler( + rustc_driver::RunCompiler::new( &args, &mut MirJsonCallbacks { analysis_data: None, use_override_crates: use_override_crates.clone(), }, - None, - None, - ).unwrap(); + ).run().unwrap(); return; }, Some(x) => x, @@ -243,12 +235,7 @@ fn go() { analysis_data: None, use_override_crates: use_override_crates.clone(), }; - rustc_driver::run_compiler( - &args, - &mut callbacks, - None, - None, - ).unwrap(); + rustc_driver::RunCompiler::new(&args, &mut callbacks).run().unwrap(); let data = callbacks.analysis_data .expect("failed to find main MIR path"); diff --git a/src/bin/mir-json.rs b/src/bin/mir-json.rs index 3e23f4d..b62c4d3 100644 --- a/src/bin/mir-json.rs +++ b/src/bin/mir-json.rs @@ -1,6 +1,5 @@ #![feature(rustc_private)] -extern crate rustc; extern crate rustc_codegen_ssa; extern crate rustc_driver; extern crate rustc_interface; @@ -15,8 +14,8 @@ extern crate mir_json; use mir_json::analyz; use rustc_driver::Compilation; -use rustc_interface::interface::Compiler; use rustc_interface::Queries; +use rustc_interface::interface::Compiler; struct MirJsonCallbacks; @@ -54,12 +53,7 @@ impl rustc_driver::Callbacks for MirJsonCallbacks { fn go() { let args: Vec = std::env::args().collect(); - rustc_driver::run_compiler( - &args, // args: &[String] - &mut MirJsonCallbacks, - None, - None, - ).unwrap(); + rustc_driver::RunCompiler::new(&args, &mut MirJsonCallbacks).run().unwrap(); } fn main() { From 636cad6edc8d24ef8079a50b51de12e09b25b9a1 Mon Sep 17 00:00:00 2001 From: Stuart Pernsteiner Date: Fri, 10 Jun 2022 09:41:15 -0700 Subject: [PATCH 08/35] update code for enumerating MonoItems --- src/analyz/mod.rs | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/src/analyz/mod.rs b/src/analyz/mod.rs index cb072dd..dd24171 100644 --- a/src/analyz/mod.rs +++ b/src/analyz/mod.rs @@ -655,20 +655,17 @@ fn emit_trait<'tcx>( /// Emit all statics defined in the current crate. fn emit_statics(ms: &mut MirState, out: &mut impl JsonOutput) -> io::Result<()> { - // Now uses tcx.collect_and_partition_mono_items() - todo!() - /* - let tcx = ms.state.tcx; - let (mono_items, _) = collector::collect_crate_mono_items(tcx, MonoItemCollectionMode::Lazy); - for mono_item in mono_items { - match mono_item { - MonoItem::Static(def_id) => emit_static(ms, out, def_id)?, - MonoItem::Fn(_) | - MonoItem::GlobalAsm(_) => {}, + let (_, cgus) = ms.state.tcx.collect_and_partition_mono_items(()); + for cgu in cgus { + for mono_item in cgu.items().keys() { + match *mono_item { + MonoItem::Static(def_id) => emit_static(ms, out, def_id)?, + MonoItem::Fn(_) | + MonoItem::GlobalAsm(_) => {}, + } } } Ok(()) - */ } fn emit_static(ms: &mut MirState, out: &mut impl JsonOutput, def_id: DefId) -> io::Result<()> { @@ -723,20 +720,17 @@ fn init_instances(ms: &mut MirState, out: &mut impl JsonOutput) -> io::Result<() /// Add every `MonoItem::Fn` to `ms.used.instances`. fn init_instances_from_mono_items(ms: &mut MirState) -> io::Result<()> { - // Now uses tcx.collect_and_partition_mono_items() - todo!() - /* - let tcx = ms.state.tcx; - let (mono_items, _) = collector::collect_crate_mono_items(tcx, MonoItemCollectionMode::Lazy); - for mono_item in mono_items { - match mono_item { - MonoItem::Fn(inst) => ms.used.instances.insert(inst), - MonoItem::Static(_) | - MonoItem::GlobalAsm(_) => {}, + let (_, cgus) = ms.state.tcx.collect_and_partition_mono_items(()); + for cgu in cgus { + for mono_item in cgu.items().keys() { + match *mono_item { + MonoItem::Fn(inst) => ms.used.instances.insert(inst), + MonoItem::Static(_) | + MonoItem::GlobalAsm(_) => {}, + } } } Ok(()) - */ } /// Initialize the set of needed instances. Returns a list of root instances. From 5921066b2fe3138cfdc2595ed53c7426c8d07cea Mon Sep 17 00:00:00 2001 From: Stuart Pernsteiner Date: Fri, 10 Jun 2022 11:23:08 -0700 Subject: [PATCH 09/35] update cargo integration --- Cargo.lock | 486 +++++++++++++++++++++++-------------- Cargo.toml | 8 +- src/bin/cargo-crux-test.rs | 27 ++- src/bin/cargo-mir-json.rs | 16 +- 4 files changed, 329 insertions(+), 208 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0740a7c..63c8de7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,20 +17,11 @@ dependencies = [ "memchr", ] -[[package]] -name = "ansi_term" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" -dependencies = [ - "winapi", -] - [[package]] name = "anyhow" -version = "1.0.32" +version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b602bfe940d21c130f3895acd65221e8a61270debe89d628b9cb4e3ccb8569b" +checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc" [[package]] name = "atty" @@ -49,6 +40,12 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + [[package]] name = "bitflags" version = "1.2.1" @@ -70,9 +67,17 @@ version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ede750122d9d1f87919570cb2cccee38c84fbc8c5599b25c289af40625b7030" dependencies = [ + "lazy_static", "memchr", + "regex-automata", ] +[[package]] +name = "bytes" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" + [[package]] name = "bytesize" version = "1.0.0" @@ -88,36 +93,44 @@ dependencies = [ "ppv-lite86", ] +[[package]] +name = "camino" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "869119e97797867fd90f5e22af7d0bd274bd4635ebb9eb68c04f3f513ae6c412" +dependencies = [ + "serde", +] + [[package]] name = "cargo" -version = "0.43.1" +version = "0.62.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91de5749ddcea3c283a042b67b77e2bdf68f28374cdcbfbe54e91368810d92e5" +checksum = "79bc435c2de37f164b5c36420d9e1dd65cd5acbd41b2df10fdc02dbf75ed9efc" dependencies = [ "anyhow", "atty", "bytesize", "cargo-platform", + "cargo-util", "clap", - "core-foundation", "crates-io", - "crossbeam-utils", - "crypto-hash", + "crossbeam-utils 0.8.8", "curl", "curl-sys", "env_logger", "filetime", "flate2", - "fs2", "fwdansi", "git2", "git2-curl", "glob", - "hex 0.4.0", + "hex 0.4.3", "home", - "humantime 2.0.1", + "humantime", "ignore", "im-rc", + "itertools", "jobserver", "lazy_static", "lazycell", @@ -125,15 +138,12 @@ dependencies = [ "libgit2-sys", "log", "memchr", - "miow", - "num_cpus", "opener", "openssl", + "os_info", "percent-encoding", - "remove_dir_all", "rustc-workspace-hack", "rustfix", - "same-file", "semver", "serde", "serde_ignored", @@ -143,8 +153,9 @@ dependencies = [ "tar", "tempfile", "termcolor", - "toml", + "toml_edit", "unicode-width", + "unicode-xid", "url", "walkdir", "winapi", @@ -152,21 +163,45 @@ dependencies = [ [[package]] name = "cargo-platform" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0226944a63d1bf35a3b5f948dd7c59e263db83695c9e8bffc4037de02e30f1d7" +checksum = "cbdb825da8a5df079a43676dbe042702f1707b1109f713a01420fbb4cc71fa27" dependencies = [ "serde", ] +[[package]] +name = "cargo-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a51c783163bdf4549820b80968d386c94ed45ed23819c93f59cca7ebd97fe0eb" +dependencies = [ + "anyhow", + "core-foundation", + "crypto-hash", + "filetime", + "hex 0.4.3", + "jobserver", + "libc", + "log", + "miow", + "same-file", + "shell-escape", + "tempfile", + "walkdir", + "winapi", +] + [[package]] name = "cargo_metadata" -version = "0.2.3" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be1057b8462184f634c3a208ee35b0f935cfd94b694b26deadccd98732088d7b" +checksum = "4acbb09d9ee8e23699b9634375c72795d095bf268439da88562cf9b501f181fa" dependencies = [ + "camino", + "cargo-platform", + "semver", "serde", - "serde_derive", "serde_json", ] @@ -185,19 +220,44 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + [[package]] name = "clap" -version = "2.33.0" +version = "3.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" +checksum = "d2dbdf4bdacb33466e854ce889eee8dfd5729abf7ccd7664d0a2d60cd384440b" dependencies = [ - "ansi_term", "atty", "bitflags", + "clap_lex", + "indexmap", "strsim", + "termcolor", "textwrap", - "unicode-width", - "vec_map", +] + +[[package]] +name = "clap_lex" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a37c35f1112dad5e6e0b1adaff798507497a18fceeb30cceb3bae7d1427b9213" +dependencies = [ + "os_str_bytes", +] + +[[package]] +name = "combine" +version = "4.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a604e93b79d1808327a6fca85a6f2d69de66461e7620f5a4cbf5fb4d1d7c948" +dependencies = [ + "bytes", + "memchr", ] [[package]] @@ -220,9 +280,9 @@ dependencies = [ [[package]] name = "core-foundation" -version = "0.7.0" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" dependencies = [ "core-foundation-sys", "libc", @@ -230,21 +290,20 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.7.0" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" [[package]] name = "crates-io" -version = "0.31.1" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09f977948a46e9edf93eb3dc2d7a8dd4ce3105d36de63300befed37cdf051d4a" +checksum = "6b4a87459133b2e708195eaab34be55039bc30e0d120658bd40794bb00b6328d" dependencies = [ "anyhow", "curl", "percent-encoding", "serde", - "serde_derive", "serde_json", "url", ] @@ -255,7 +314,7 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", ] [[package]] @@ -264,7 +323,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acec9a3b0b3559f15aee4f90746c4e5e293b701c0f7d3925d24e01645267b68c" dependencies = [ - "crossbeam-utils", + "crossbeam-utils 0.7.0", ] [[package]] @@ -273,8 +332,18 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce446db02cdc3165b94ae73111e570793400d0794e46125cc4056c81cbb039f4" dependencies = [ - "autocfg", - "cfg-if", + "autocfg 0.1.7", + "cfg-if 0.1.10", + "lazy_static", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38" +dependencies = [ + "cfg-if 1.0.0", "lazy_static", ] @@ -292,9 +361,9 @@ dependencies = [ [[package]] name = "curl" -version = "0.4.25" +version = "0.4.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06aa71e9208a54def20792d877bc663d6aae0732b9852e612c4a933177c31283" +checksum = "37d855aeef205b43f65a5001e0997d81f8efca7badad4fad7d897aa7f0d0651f" dependencies = [ "curl-sys", "libc", @@ -307,9 +376,9 @@ dependencies = [ [[package]] name = "curl-sys" -version = "0.4.25" +version = "0.4.55+curl-7.83.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c38ca47d60b86d0cc9d42caa90a0885669c2abc9791f871c81f58cdf39e979b" +checksum = "23734ec77368ec583c2e61dd3f0b0e5c98b93abe6d2a004ca06b91dd7e3e2762" dependencies = [ "cc", "libc", @@ -321,14 +390,20 @@ dependencies = [ "winapi", ] +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + [[package]] name = "env_logger" -version = "0.7.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" +checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" dependencies = [ "atty", - "humantime 1.3.0", + "humantime", "log", "regex", "termcolor", @@ -336,13 +411,13 @@ dependencies = [ [[package]] name = "filetime" -version = "0.2.8" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ff6d4dab0aa0c8e6346d46052e93b13a16cf847b54ed357087c35011048cc7d" +checksum = "c0408e2626025178a6a7f7ffc05a25bc47103229f19c113755de7bf63816290c" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", - "redox_syscall", + "redox_syscall 0.2.13", "winapi", ] @@ -352,7 +427,7 @@ version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6bd6d6f4752952feb71363cffc9ebac9411b75b87c6ab6058c40c8900cf43c0f" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "crc32fast", "libc", "libz-sys", @@ -381,13 +456,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] -name = "fs2" -version = "0.4.3" +name = "form_urlencoded" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" dependencies = [ - "libc", - "winapi", + "matches", + "percent-encoding", ] [[package]] @@ -406,16 +481,16 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "libc", "wasi", ] [[package]] name = "git2" -version = "0.11.0" +version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77519ef7c5beee314d0804d4534f01e0f9e8d9acdee2b7a48627e590b27e0ec4" +checksum = "d0155506aab710a86160ddb504a480d2964d7ab5b9e62419be69e0032bc5931c" dependencies = [ "bitflags", "libc", @@ -428,9 +503,9 @@ dependencies = [ [[package]] name = "git2-curl" -version = "0.12.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2559abb1d87d27668d31bd868a000f0e2e0065d10e78961b62da95d7a7f1cc7" +checksum = "1ee51709364c341fbb6fe2a385a290fb9196753bdde2fc45447d27cd31b11b13" dependencies = [ "curl", "git2", @@ -463,6 +538,12 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ff54597ea139063f4225f1ec47011b03c9de4a486957ff3fc506881dac951d0" +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" + [[package]] name = "hermit-abi" version = "0.1.6" @@ -480,9 +561,9 @@ checksum = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" [[package]] name = "hex" -version = "0.4.0" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "023b39be39e3a2da62a94feb433e91e8bcd37676fbc8bea371daf52b7a769a3e" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "home" @@ -493,15 +574,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "humantime" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" -dependencies = [ - "quick-error", -] - [[package]] name = "humantime" version = "2.0.1" @@ -539,33 +611,61 @@ dependencies = [ [[package]] name = "im-rc" -version = "14.3.0" +version = "15.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "303f7e6256d546e01979071417432425f15c1891fb309a5f2d724ee908fabd6e" +checksum = "af1955a75fa080c677d3972822ec4bad316169ab1cfc6c257a942c2265dbe5fe" dependencies = [ "bitmaps", - "rand_core", + "rand_core 0.6.3", "rand_xoshiro", "sized-chunks", "typenum", "version_check", ] +[[package]] +name = "indexmap" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6012d540c5baa3589337a98ce73408de9b5a25ec9fc2c6fd6be8f0d39e0ca5a" +dependencies = [ + "autocfg 1.1.0", + "hashbrown", +] + +[[package]] +name = "itertools" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" +dependencies = [ + "either", +] + [[package]] name = "itoa" -version = "0.4.3" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b" +checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" [[package]] name = "jobserver" -version = "0.1.19" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67b06c1b455f1cf4269a8cfc320ab930a810e2375a42af5075eb8a8b36405ce0" +checksum = "af25a77299a7f711a01975c35a6a424eb6862092cc2d6c72c4ed6cbc56dfc1fa" dependencies = [ "libc", ] +[[package]] +name = "kstring" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b310ccceade8121d7d77fee406160e457c2f4e7c7982d589da3499bc7ea4526" +dependencies = [ + "serde", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -580,15 +680,15 @@ checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" [[package]] name = "libc" -version = "0.2.65" +version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a31a0627fdf1f6a39ec0dd577e101440b7db22672c0901fe00a9a6fbb5c24e8" +checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" [[package]] name = "libgit2-sys" -version = "0.10.0" +version = "0.13.4+1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9ec6bca50549d34a392611dde775123086acbd994e3fff64954777ce2dc2e51" +checksum = "d0fa6563431ede25f5cc7f6d803c6afbc1c5d3ad3d4925d12c882bf2b526f5d1" dependencies = [ "cc", "libc", @@ -600,9 +700,9 @@ dependencies = [ [[package]] name = "libnghttp2-sys" -version = "0.1.2" +version = "0.1.7+1.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02254d44f4435dd79e695f2c2b83cd06a47919adea30216ceaf0c57ca0a72463" +checksum = "57ed28aba195b38d5ff02b9170cbff627e336a20925e43b4945390401c5dc93f" dependencies = [ "cc", "libc", @@ -610,9 +710,9 @@ dependencies = [ [[package]] name = "libssh2-sys" -version = "0.2.14" +version = "0.2.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36aa6e813339d3a063292b77091dfbbb6152ff9006a459895fa5bebed7d34f10" +checksum = "b094a36eb4b8b8c8a7b4b8ae43b2944502be3e59cd87687595cf6b0a71b3f4ca" dependencies = [ "cc", "libc", @@ -624,9 +724,9 @@ dependencies = [ [[package]] name = "libz-sys" -version = "1.0.25" +version = "1.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2eb5e43362e38e2bca2fd5f5134c4d4564a23a5c28e9b95411652021a8675ebe" +checksum = "9702761c3935f8cc2f101793272e202c72b99da8f4224a19ddcf1279a6450bbf" dependencies = [ "cc", "libc", @@ -640,7 +740,7 @@ version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", ] [[package]] @@ -666,11 +766,10 @@ dependencies = [ [[package]] name = "miow" -version = "0.3.3" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "396aa0f2003d7df8395cb93e09871561ccc3e785f0acb369170e8cc74ddf9226" +checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" dependencies = [ - "socket2", "winapi", ] @@ -686,25 +785,16 @@ dependencies = [ "serde_derive", "serde_json", "tar", - "toml", -] - -[[package]] -name = "num_cpus" -version = "1.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76dac5ed2a876980778b8b85f75a71b6cbf0db0b1232ee12f826bccb00d09d72" -dependencies = [ - "hermit-abi", - "libc", + "toml_edit", ] [[package]] name = "opener" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13117407ca9d0caf3a0e74f97b490a7e64c0ae3aa90a8b7085544d0c37b6f3ae" +checksum = "4ea3ebcd72a54701f56345f16785a6d3ac2df7e986d273eb4395c0b01db17952" dependencies = [ + "bstr", "winapi", ] @@ -715,7 +805,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a3cc5799d98e1088141b8e01ff760112bbd9f19d850c124500566ca6901a585" dependencies = [ "bitflags", - "cfg-if", + "cfg-if 0.1.10", "foreign-types", "lazy_static", "libc", @@ -743,7 +833,7 @@ version = "0.9.53" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "465d16ae7fc0e313318f7de5cecf57b2fbe7511fd213978b457e1c96ff46736f" dependencies = [ - "autocfg", + "autocfg 0.1.7", "cc", "libc", "openssl-src", @@ -751,6 +841,23 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "os_info" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eca3ecae1481e12c3d9379ec541b238a16f0b75c9a409942daa8ec20dbfdb62" +dependencies = [ + "log", + "serde", + "winapi", +] + +[[package]] +name = "os_str_bytes" +version = "6.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21326818e99cfe6ce1e524c2a805c189a99b5ae555a35d19f9a284b427d86afa" + [[package]] name = "percent-encoding" version = "2.1.0" @@ -771,19 +878,13 @@ checksum = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" [[package]] name = "proc-macro2" -version = "1.0.7" +version = "1.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0319972dcae462681daf4da1adeeaa066e3ebd29c69be96c6abb1259d2ee2bcc" +checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" dependencies = [ - "unicode-xid", + "unicode-ident", ] -[[package]] -name = "quick-error" -version = "1.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" - [[package]] name = "quote" version = "1.0.2" @@ -802,7 +903,7 @@ dependencies = [ "getrandom", "libc", "rand_chacha", - "rand_core", + "rand_core 0.5.1", "rand_hc", ] @@ -813,7 +914,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853" dependencies = [ "c2-chacha", - "rand_core", + "rand_core 0.5.1", ] [[package]] @@ -825,22 +926,28 @@ dependencies = [ "getrandom", ] +[[package]] +name = "rand_core" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" + [[package]] name = "rand_hc" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" dependencies = [ - "rand_core", + "rand_core 0.5.1", ] [[package]] name = "rand_xoshiro" -version = "0.4.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9fcdd2e881d02f1d9390ae47ad8e5696a9e4be7b547a1da2afbc61973217004" +checksum = "6f97cdb2a36ed4183de61b2f824cc45c9f1037f28afe0a322e9fff4c108b5aaa" dependencies = [ - "rand_core", + "rand_core 0.6.3", ] [[package]] @@ -849,6 +956,15 @@ version = "0.1.56" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" +[[package]] +name = "redox_syscall" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" +dependencies = [ + "bitflags", +] + [[package]] name = "regex" version = "1.3.3" @@ -861,6 +977,12 @@ dependencies = [ "thread_local", ] +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" + [[package]] name = "regex-syntax" version = "0.6.13" @@ -884,9 +1006,9 @@ checksum = "fc71d2faa173b74b232dedc235e3ee1696581bb132fc116fa3626d6151a1a8fb" [[package]] name = "rustfix" -version = "0.5.1" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2c50b74badcddeb8f7652fa8323ce440b95286f8e4b64ebfd871c609672704e" +checksum = "ecd2853d9e26988467753bd9912c3a126f642d05d229a4b53f5752ee36c56481" dependencies = [ "anyhow", "log", @@ -896,9 +1018,9 @@ dependencies = [ [[package]] name = "ryu" -version = "0.2.7" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7" +checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" [[package]] name = "same-file" @@ -921,25 +1043,18 @@ dependencies = [ [[package]] name = "semver" -version = "0.9.0" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +checksum = "a41d061efea015927ac527063765e73601444cdc344ba855bc7bd44578b25e1c" dependencies = [ - "semver-parser", "serde", ] -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" - [[package]] name = "serde" -version = "1.0.104" +version = "1.0.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449" +checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" dependencies = [ "serde_derive", ] @@ -956,9 +1071,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.104" +version = "1.0.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64" +checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be" dependencies = [ "proc-macro2", "quote", @@ -976,9 +1091,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.39" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a23aa71d4a4d43fdbfaac00eff68ba8a06a51759a89ac3304323e800c4dd40d" +checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c" dependencies = [ "itoa", "ryu", @@ -993,9 +1108,9 @@ checksum = "170a13e64f2a51b77a45702ba77287f5c6829375b04a69cf2222acd17d0cfab9" [[package]] name = "sized-chunks" -version = "0.5.3" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59044ea371ad781ff976f7b06480b9f0180e834eda94114f2afb4afc12b7718" +checksum = "16d69225bde7a69b235da73377861095455d298f2b970996eec25ddbb42b3d1e" dependencies = [ "bitmaps", "typenum", @@ -1009,13 +1124,11 @@ checksum = "44e59e0c9fa00817912ae6e4e6e3c4fe04455e75699d06eedc7d85917ed8e8f4" [[package]] name = "socket2" -version = "0.3.11" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8b74de517221a2cb01a53349cf54182acdc31a074727d3079068448c0676d85" +checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" dependencies = [ - "cfg-if", "libc", - "redox_syscall", "winapi", ] @@ -1030,30 +1143,29 @@ dependencies = [ [[package]] name = "strsim" -version = "0.8.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.13" +version = "1.0.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e4ff033220a41d1a57d8125eab57bf5263783dfdcc18688b1dacc6ce9651ef8" +checksum = "0748dd251e24453cb8717f0354206b91557e4ec8703673a4b30208f2abaf1ebf" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-ident", ] [[package]] name = "tar" -version = "0.4.26" +version = "0.4.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3196bfbffbba3e57481b6ea32249fbaf590396a52505a2615adbb79d9d826d3" +checksum = "4b55807c0344e1e6c04d7c965f5289c39a8d94ae23ed5c0b57aabac549f871c6" dependencies = [ "filetime", "libc", - "redox_syscall", "xattr", ] @@ -1063,31 +1175,28 @@ version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "libc", "rand", - "redox_syscall", + "redox_syscall 0.1.56", "remove_dir_all", "winapi", ] [[package]] name = "termcolor" -version = "1.1.0" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" dependencies = [ "winapi-util", ] [[package]] name = "textwrap" -version = "0.11.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] +checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" [[package]] name = "thread_local" @@ -1099,19 +1208,23 @@ dependencies = [ ] [[package]] -name = "toml" -version = "0.5.5" +name = "toml_edit" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01d1404644c8b12b16bfcffa4322403a91a451584daaaa7c28d3152e6cbc98cf" +checksum = "744e9ed5b352340aa47ce033716991b5589e23781acb97cad37d4ea70560f55b" dependencies = [ + "combine", + "indexmap", + "itertools", + "kstring", "serde", ] [[package]] name = "typenum" -version = "1.11.2" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" +checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" [[package]] name = "unicode-bidi" @@ -1122,6 +1235,12 @@ dependencies = [ "matches", ] +[[package]] +name = "unicode-ident" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" + [[package]] name = "unicode-normalization" version = "0.1.11" @@ -1145,10 +1264,11 @@ checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" [[package]] name = "url" -version = "2.1.1" +version = "2.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb" +checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" dependencies = [ + "form_urlencoded", "idna", "matches", "percent-encoding", @@ -1166,12 +1286,6 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fc439f2794e98976c88a2a2dafce96b930fe8010b0a256b3c2199a773933168" -[[package]] -name = "vec_map" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" - [[package]] name = "version_check" version = "0.9.2" @@ -1206,9 +1320,9 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[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", diff --git a/Cargo.toml b/Cargo.toml index 05281f7..f0726df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,10 +11,10 @@ serde_derive = "1.0" serde_json = "1.0" serde_cbor = "0.11" tar = "0.4" -cargo_metadata = { version = "0.2" } -cargo = { version = "0.43", features = [ "vendored-openssl" ] } -toml = "0.5" -clap = "2.33" +cargo_metadata = { version = "0.14.2" } +cargo = { version = "0.62", features = [ "vendored-openssl" ] } +toml_edit = { version = "0.13.4", features = [ "easy" ] } +clap = "3.1.0" [[bin]] name = "cargo-crux-test" diff --git a/src/bin/cargo-crux-test.rs b/src/bin/cargo-crux-test.rs index 12a0b56..4bdf647 100644 --- a/src/bin/cargo-crux-test.rs +++ b/src/bin/cargo-crux-test.rs @@ -17,27 +17,30 @@ extern crate cargo; extern crate clap; extern crate rustc_session; extern crate serde_json; +extern crate toml_edit; use std::env; use std::path::PathBuf; use std::process::{self, Command}; use rustc_session::config::host_triple; use cargo::util::command_prelude::*; +use toml_edit::easy::value::Value as TomlValue; fn cli() -> App { - todo!("update to match recent cargo-test cli"); // Copy-pasted from cargo/src/bin/cargo/commands/test.rs, with minor edits to the text. - subcommand("crux-test") - .setting(AppSettings::TrailingVarArg) + subcommand("test") + // Subcommand aliases are handled in `aliased_command()`. + // .alias("t") + .trailing_var_arg(true) .about("Execute all symbolic unit tests of a local package") .arg( - Arg::with_name("TESTNAME") + Arg::new("TESTNAME") .help("If specified, only run tests containing this string in their names"), ) .arg( - Arg::with_name("args") + Arg::new("args") .help("Arguments for the test binary") - .multiple(true) + .multiple_values(true) .last(true), ) .arg( @@ -45,7 +48,7 @@ fn cli() -> App { "quiet", "Display one character per test instead of one line", ) - .short("q"), + .short('q'), ) .arg_targets_all( "Test only this package's library unit tests", @@ -74,7 +77,11 @@ fn cli() -> App { .arg_target_triple("Build for the target triple") .arg_target_dir() .arg_manifest_path() + .arg_ignore_rust_version() .arg_message_format() + .arg_unit_graph() + .arg_future_incompat_report() + .arg_timings() .after_help("See `cargo test --help` for more information on these options.") } @@ -98,7 +105,7 @@ fn get_override_crates() -> String { &config, CompileMode::Test, Some(&ws), - ProfileChecking::Unchecked, + ProfileChecking::Custom, ).unwrap_or_else(|e| panic!("error reading compile options: {}", e)); let pkgs = opts.spec.get_packages(&ws) .unwrap_or_else(|e| panic!("error listing packages: {}", e)); @@ -130,12 +137,12 @@ fn get_override_crates() -> String { overrides } -fn get_package_override_crates(v: Option<&toml::Value>) -> String { +fn get_package_override_crates(v: Option<&TomlValue>) -> String { get_package_override_crates_opt(v) .unwrap_or_else(String::new) } -fn get_package_override_crates_opt(v: Option<&toml::Value>) -> Option { +fn get_package_override_crates_opt(v: Option<&TomlValue>) -> Option { // The `crux` key is allowed to be missing, but if present, it must be an object. let crux = v?.get("crux")?; assert!(crux.is_table(), "expected `package.metadata.crux` to be an object"); diff --git a/src/bin/cargo-mir-json.rs b/src/bin/cargo-mir-json.rs index 21c77c8..717d28c 100644 --- a/src/bin/cargo-mir-json.rs +++ b/src/bin/cargo-mir-json.rs @@ -47,11 +47,15 @@ fn main() { let manifest_path_arg = env::args().skip(skip).find(|val| { val.starts_with("--manifest-path=") }); + let manifest_path = manifest_path_arg.map(|arg| { + PathBuf::from(Path::new(&arg["--manifest-path=".len()..])) + }); - let mut metadata = if let Ok(metadata) = cargo_metadata::metadata( - manifest_path_arg.as_ref().map(AsRef::as_ref), - ) - { + let mut metadata_command = cargo_metadata::MetadataCommand::new(); + if let Some(manifest_path) = manifest_path.as_ref() { + metadata_command.manifest_path(manifest_path); + } + let mut metadata = if let Ok(metadata) = metadata_command.exec() { metadata } else { let _ = std::io::stderr().write_fmt(format_args!( @@ -60,10 +64,6 @@ fn main() { process::exit(101); }; - let manifest_path = manifest_path_arg.map(|arg| { - PathBuf::from(Path::new(&arg["--manifest-path=".len()..])) - }); - let current_dir = std::env::current_dir(); let package_index = metadata From 5a592ad7f83ef12e4ccd2b46b9c2ce4d69f662e7 Mon Sep 17 00:00:00 2001 From: Stuart Pernsteiner Date: Fri, 10 Jun 2022 11:47:31 -0700 Subject: [PATCH 10/35] fix some warnings --- src/analyz/mod.rs | 2 +- src/analyz/ty_json.rs | 3 --- src/bin/cargo-crux-test.rs | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/analyz/mod.rs b/src/analyz/mod.rs index dd24171..a0f5e01 100644 --- a/src/analyz/mod.rs +++ b/src/analyz/mod.rs @@ -2,7 +2,7 @@ use rustc_ast::{ast, token, tokenstream, visit}; use rustc_hir::def::DefKind; -use rustc_hir::def_id::{self, DefId, LOCAL_CRATE}; +use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_index::vec::Idx; use rustc_interface::Queries; use rustc_middle::ty::{self, TyCtxt, List}; diff --git a/src/analyz/ty_json.rs b/src/analyz/ty_json.rs index 30efe1f..f5ad95f 100644 --- a/src/analyz/ty_json.rs +++ b/src/analyz/ty_json.rs @@ -8,7 +8,6 @@ use rustc_middle::ty; use rustc_middle::ty::{TyCtxt, TypeFoldable}; use rustc_query_system::ich::StableHashingContext; use rustc_target::spec::abi; -use rustc_ast::ast; use rustc_span::DUMMY_SP; use serde_json; use std::fmt::Write as FmtWrite; @@ -928,8 +927,6 @@ mod machine { use rustc_const_eval::interpret::*; use rustc_data_structures::fx::FxHashMap; use rustc_middle::ty::*; - use rustc_middle::mir::*; - use rustc_span::Span; use rustc_target::abi::Size; use rustc_target::spec::abi::Abi; diff --git a/src/bin/cargo-crux-test.rs b/src/bin/cargo-crux-test.rs index 4bdf647..63c0f2a 100644 --- a/src/bin/cargo-crux-test.rs +++ b/src/bin/cargo-crux-test.rs @@ -95,7 +95,7 @@ fn get_override_crates() -> String { // test. let config = cargo::Config::default() .unwrap_or_else(|e| panic!("error initializing cargo config: {}", e)); - let app = clap::App::new("cargo-crux-test").subcommand(cli()); + let app = App::new("cargo-crux-test").subcommand(cli()); let args = app.get_matches(); let args = args.subcommand_matches("crux-test") .unwrap_or_else(|| panic!("expected crux-test subcommand")); From 9c27e846177394e663981fad6bf4cd6a8410e2c8 Mon Sep 17 00:00:00 2001 From: Stuart Pernsteiner Date: Tue, 16 Aug 2022 11:23:47 -0700 Subject: [PATCH 11/35] be more consistent about erasing late-bound regions --- src/analyz/mod.rs | 11 +++++++---- src/analyz/to_json.rs | 8 ++++++++ src/analyz/ty_json.rs | 8 ++++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/analyz/mod.rs b/src/analyz/mod.rs index a0f5e01..5d02ac1 100644 --- a/src/analyz/mod.rs +++ b/src/analyz/mod.rs @@ -330,6 +330,8 @@ impl<'tcx> ToJson<'tcx> for mir::Constant<'tcx> { impl<'tcx> ToJson<'tcx> for mir::LocalDecl<'tcx> { fn to_json(&self, mir: &mut MirState<'_, 'tcx>) -> serde_json::Value { + use rustc_middle::ty::fold::TypeFoldable; + assert!(!self.ty.has_escaping_bound_vars(), "local ty = {:?}", self.ty); json!({ "mut": self.mutability.to_json(mir), "ty": self.ty.to_json(mir), @@ -853,13 +855,14 @@ fn emit_promoted<'tcx>( fn emit_vtable<'tcx>( ms: &mut MirState<'_, 'tcx>, out: &mut impl JsonOutput, - trait_ref: ty::PolyTraitRef<'tcx>, + poly_trait_ref: ty::PolyTraitRef<'tcx>, ) -> io::Result<()> { - let ti = TraitInst::from_trait_ref(ms.state.tcx, trait_ref.skip_binder()); + let trait_ref = ms.state.tcx.erase_late_bound_regions(poly_trait_ref); + let ti = TraitInst::from_trait_ref(ms.state.tcx, trait_ref); out.emit(EntryKind::Vtable, json!({ "trait_id": trait_inst_id_str(ms.state.tcx, &ti), - "name": vtable_name(ms, trait_ref), - "items": build_vtable_items(ms, trait_ref), + "name": vtable_name(ms, poly_trait_ref), + "items": build_vtable_items(ms, poly_trait_ref), }))?; emit_new_types(ms, out) } diff --git a/src/analyz/to_json.rs b/src/analyz/to_json.rs index c681a88..f65aedb 100644 --- a/src/analyz/to_json.rs +++ b/src/analyz/to_json.rs @@ -91,7 +91,9 @@ impl<'tcx> TraitInst<'tcx> { tcx: TyCtxt<'tcx>, preds: &'tcx ty::List>>, ) -> TraitInst<'tcx> { + use rustc_middle::ty::fold::TypeFoldable; let trait_ref = preds.principal().map(|tr| tcx.erase_late_bound_regions(tr)); + assert!(!trait_ref.has_escaping_bound_vars(), "escaping: {:?}", trait_ref); let mut projs = preds.projection_bounds() .map(|proj| tcx.erase_late_bound_regions(proj)) .collect::>(); @@ -106,6 +108,8 @@ impl<'tcx> TraitInst<'tcx> { tcx: TyCtxt<'tcx>, trait_ref: ty::TraitRef<'tcx>, ) -> TraitInst<'tcx> { + use rustc_middle::ty::fold::TypeFoldable; + assert!(!trait_ref.has_escaping_bound_vars(), "escaping: {:?}", trait_ref); let ex_trait_ref = ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref); let mut projs = Vec::new(); @@ -133,6 +137,8 @@ impl<'tcx> TraitInst<'tcx> { pub fn dyn_ty(&self, tcx: TyCtxt<'tcx>) -> Option> { let trait_ref = self.trait_ref?; + use rustc_middle::ty::fold::TypeFoldable; + assert!(!trait_ref.has_escaping_bound_vars(), "escaping: {:?}", trait_ref); let mut preds = Vec::with_capacity(self.projs.len() + 1); preds.push(ty::Binder::dummy(ty::ExistentialPredicate::Trait(trait_ref))); preds.extend( @@ -163,6 +169,8 @@ pub struct AdtInst<'tcx> { impl<'tcx> AdtInst<'tcx> { pub fn new(adt: ty::AdtDef<'tcx>, substs: ty::subst::SubstsRef<'tcx>) -> AdtInst<'tcx> { + use rustc_middle::ty::fold::TypeFoldable; + assert!(!substs.has_escaping_bound_vars(), "bad substs: {:?}, {:?}", adt, substs); AdtInst { adt, substs } } diff --git a/src/analyz/ty_json.rs b/src/analyz/ty_json.rs index f5ad95f..7a99ee5 100644 --- a/src/analyz/ty_json.rs +++ b/src/analyz/ty_json.rs @@ -341,6 +341,8 @@ impl<'tcx> ToJson<'tcx> for ty::Instance<'tcx> { // For type _references_. To translate ADT defintions, do it explicitly. impl<'tcx> ToJson<'tcx> for ty::Ty<'tcx> { fn to_json(&self, mir: &mut MirState<'_, 'tcx>) -> serde_json::Value { + let tcx = mir.state.tcx; + // If this type has already been interned, just return its ID. if let Some(id) = mir.tys.get(*self) { return json!(id); @@ -425,8 +427,10 @@ impl<'tcx> ToJson<'tcx> for ty::Ty<'tcx> { json!({ "kind": "Dynamic", "trait_id": trait_name, - "predicates": preds.iter().map(|p| p.skip_binder().to_json(mir)) - .collect::>(), + "predicates": preds.iter().map(|p|{ + let p = tcx.erase_late_bound_regions(p); + p.to_json(mir) + }).collect::>(), }) } &ty::TyKind::Projection(..) => unreachable!( From 072df6816279328dd9dab24cfe791f40bbd3da11 Mon Sep 17 00:00:00 2001 From: Stuart Pernsteiner Date: Tue, 16 Aug 2022 11:24:52 -0700 Subject: [PATCH 12/35] remove some has_escaping_bound_vars() checks (may be slow) --- src/analyz/mod.rs | 2 -- src/analyz/to_json.rs | 8 -------- 2 files changed, 10 deletions(-) diff --git a/src/analyz/mod.rs b/src/analyz/mod.rs index 5d02ac1..62cf102 100644 --- a/src/analyz/mod.rs +++ b/src/analyz/mod.rs @@ -330,8 +330,6 @@ impl<'tcx> ToJson<'tcx> for mir::Constant<'tcx> { impl<'tcx> ToJson<'tcx> for mir::LocalDecl<'tcx> { fn to_json(&self, mir: &mut MirState<'_, 'tcx>) -> serde_json::Value { - use rustc_middle::ty::fold::TypeFoldable; - assert!(!self.ty.has_escaping_bound_vars(), "local ty = {:?}", self.ty); json!({ "mut": self.mutability.to_json(mir), "ty": self.ty.to_json(mir), diff --git a/src/analyz/to_json.rs b/src/analyz/to_json.rs index f65aedb..c681a88 100644 --- a/src/analyz/to_json.rs +++ b/src/analyz/to_json.rs @@ -91,9 +91,7 @@ impl<'tcx> TraitInst<'tcx> { tcx: TyCtxt<'tcx>, preds: &'tcx ty::List>>, ) -> TraitInst<'tcx> { - use rustc_middle::ty::fold::TypeFoldable; let trait_ref = preds.principal().map(|tr| tcx.erase_late_bound_regions(tr)); - assert!(!trait_ref.has_escaping_bound_vars(), "escaping: {:?}", trait_ref); let mut projs = preds.projection_bounds() .map(|proj| tcx.erase_late_bound_regions(proj)) .collect::>(); @@ -108,8 +106,6 @@ impl<'tcx> TraitInst<'tcx> { tcx: TyCtxt<'tcx>, trait_ref: ty::TraitRef<'tcx>, ) -> TraitInst<'tcx> { - use rustc_middle::ty::fold::TypeFoldable; - assert!(!trait_ref.has_escaping_bound_vars(), "escaping: {:?}", trait_ref); let ex_trait_ref = ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref); let mut projs = Vec::new(); @@ -137,8 +133,6 @@ impl<'tcx> TraitInst<'tcx> { pub fn dyn_ty(&self, tcx: TyCtxt<'tcx>) -> Option> { let trait_ref = self.trait_ref?; - use rustc_middle::ty::fold::TypeFoldable; - assert!(!trait_ref.has_escaping_bound_vars(), "escaping: {:?}", trait_ref); let mut preds = Vec::with_capacity(self.projs.len() + 1); preds.push(ty::Binder::dummy(ty::ExistentialPredicate::Trait(trait_ref))); preds.extend( @@ -169,8 +163,6 @@ pub struct AdtInst<'tcx> { impl<'tcx> AdtInst<'tcx> { pub fn new(adt: ty::AdtDef<'tcx>, substs: ty::subst::SubstsRef<'tcx>) -> AdtInst<'tcx> { - use rustc_middle::ty::fold::TypeFoldable; - assert!(!substs.has_escaping_bound_vars(), "bad substs: {:?}, {:?}", adt, substs); AdtInst { adt, substs } } From 8965006c1ab8086b3fb70c1626cf88fadae21b53 Mon Sep 17 00:00:00 2001 From: Stuart Pernsteiner Date: Tue, 16 Aug 2022 11:25:57 -0700 Subject: [PATCH 13/35] collect assoc types from supertraits Previously, we would incorrectly produce types like `dyn Fn<((),)>`, where no `Output` type is specified, causing a panic later due to an unnormalized projection. Now we correctly look at supertraits (in this case, `FnOnce`, where `Output` is defined) to make sure we don't miss any associated type predicates. --- src/analyz/to_json.rs | 45 +++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/src/analyz/to_json.rs b/src/analyz/to_json.rs index c681a88..3f61052 100644 --- a/src/analyz/to_json.rs +++ b/src/analyz/to_json.rs @@ -108,20 +108,41 @@ impl<'tcx> TraitInst<'tcx> { ) -> TraitInst<'tcx> { let ex_trait_ref = ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref); + let mut all_super_traits = HashSet::new(); + let mut pending = vec![trait_ref.def_id]; + all_super_traits.insert(trait_ref.def_id); + while let Some(def_id) = pending.pop() { + let super_preds = tcx.super_predicates_of(def_id); + for &(ref pred, _) in super_preds.predicates { + let tpred = match tcx.erase_late_bound_regions(pred.kind()) { + ty::PredicateKind::Trait(x) => x, + ty::PredicateKind::TypeOutlives(..) => continue, + _ => panic!("unexpected predicate kind: {:?}", pred), + }; + assert_eq!(tpred.polarity, ty::ImplPolarity::Positive); + if all_super_traits.insert(tpred.trait_ref.def_id) { + pending.push(tpred.trait_ref.def_id); + } + } + } + let mut all_super_traits = all_super_traits.into_iter().collect::>(); + all_super_traits.sort(); + let mut projs = Vec::new(); - // FIXME: build projs for supertrait trait_refs as well - for ai in tcx.associated_items(trait_ref.def_id).in_definition_order() { - match ai.kind { - ty::AssocKind::Type => {}, - _ => continue, + for super_trait_def_id in all_super_traits { + for ai in tcx.associated_items(super_trait_def_id).in_definition_order() { + match ai.kind { + ty::AssocKind::Type => {}, + _ => continue, + } + let proj_ty = tcx.mk_projection(ai.def_id, trait_ref.substs); + let actual_ty = tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), proj_ty); + projs.push(ty::ExistentialProjection { + item_def_id: ai.def_id, + substs: ex_trait_ref.substs, + term: ty::Term::Ty(actual_ty), + }); } - let proj_ty = tcx.mk_projection(ai.def_id, trait_ref.substs); - let actual_ty = tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), proj_ty); - projs.push(ty::ExistentialProjection { - item_def_id: ai.def_id, - substs: ex_trait_ref.substs, - term: ty::Term::Ty(actual_ty), - }); } projs.sort_by_key(|p| p.item_def_id); From 8808caccd6f19c685afa771a1b3abc7b9f4785da Mon Sep 17 00:00:00 2001 From: Stuart Pernsteiner Date: Tue, 16 Aug 2022 11:29:15 -0700 Subject: [PATCH 14/35] fix rendering of zero-sized constants --- src/analyz/ty_json.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/analyz/ty_json.rs b/src/analyz/ty_json.rs index 7a99ee5..a0c5c0e 100644 --- a/src/analyz/ty_json.rs +++ b/src/analyz/ty_json.rs @@ -1,3 +1,4 @@ +use std::convert::TryFrom; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_hir as hir; use rustc_hir::def_id::DefId; @@ -690,8 +691,13 @@ fn render_constant_scalar<'tcx>( ) -> Option { match s { interpret::Scalar::Int(sint) => { - let data = sint.to_bits(sint.size()).unwrap(); - render_constant(mir, ty, Some(s), Some((sint.size().bytes() as u8, data)), None) + let data = if sint.size() == Size::ZERO { + 0 + } else { + sint.to_bits(sint.size()).unwrap() + }; + let size = u8::try_from(sint.size().bytes()).unwrap(); + render_constant(mir, ty, Some(s), Some((size, data)), None) }, interpret::Scalar::Ptr(ptr, _) => { match mir.state.tcx.get_global_alloc(ptr.provenance) { From c13957d2d3017f28a0299d03b385cac88436de4d Mon Sep 17 00:00:00 2001 From: James LaMar Date: Tue, 21 Feb 2023 14:57:57 -0800 Subject: [PATCH 15/35] Update compiler plugin to 1.69.0-nightly (5e37043d6 2023-01-22) --- src/analyz/mod.rs | 73 +++++--- src/analyz/to_json.rs | 16 +- src/analyz/ty_json.rs | 271 +++++++++++++++++------------- src/bin/cargo-crux-test.rs | 1 + src/bin/crux-rustc.rs | 1 + src/bin/mir-json-rustc-wrapper.rs | 11 +- 6 files changed, 218 insertions(+), 155 deletions(-) diff --git a/src/analyz/mod.rs b/src/analyz/mod.rs index dd24171..0d06354 100644 --- a/src/analyz/mod.rs +++ b/src/analyz/mod.rs @@ -1,6 +1,6 @@ #![macro_use] -use rustc_ast::{ast, token, tokenstream, visit}; +use rustc_ast::{ast, token, tokenstream, visit, ptr, Crate}; use rustc_hir::def::DefKind; use rustc_hir::def_id::{self, DefId, LOCAL_CRATE}; use rustc_index::vec::Idx; @@ -111,7 +111,8 @@ fn vtable_descriptor_for_cast<'tcx>( // Relevant code: rustc_codegen_ssa::meth::get_vtable let trait_ref = match *new_pointee.kind() { - ty::TyKind::Dynamic(ref preds, _) => + // NB nightly-2023-01-23 dyntype + ty::TyKind::Dynamic(ref preds, _, _) => preds.principal().map(|pred| pred.with_self_ty(tcx, old_pointee)), _ => return None, }; @@ -237,6 +238,12 @@ impl<'tcx> ToJson<'tcx> for mir::Rvalue<'tcx> { "ty": ty.to_json(mir) }) } + &mir::Rvalue::CopyForDeref(ref l) => { + json!({ + "kind": "CopyForDeref", + "place": l.to_json(mir) + }) + } } } } @@ -289,6 +296,9 @@ impl<'tcx> ToJson<'tcx> for mir::PlaceElem<'tcx> { &mir::ProjectionElem::Downcast(ref _adt, ref variant) => { json!({"kind": "Downcast", "variant": variant.to_json(mir)}) } + &mir::ProjectionElem::OpaqueCast(ref ty) => { + json!({"kind": "OpaqueCast", "variant": ty.to_json(mir) }) + } } } } @@ -324,6 +334,9 @@ impl<'tcx> ToJson<'tcx> for mir::Constant<'tcx> { match self.literal { mir::ConstantKind::Ty(c) => c.to_json(mir), mir::ConstantKind::Val(cv, ty) => (cv, ty).to_json(mir), + // nightly-20203-01-22 evaluate? + mir::ConstantKind::Unevaluated(val, ty) => + panic!("unevaluated const in mir::constant serializer") } } } @@ -387,13 +400,13 @@ impl<'tcx> ToJson<'tcx> for mir::Statement<'tcx> { // TODO json!({"kind": "Coverage"}) } - &mir::StatementKind::CopyNonOverlapping { .. } => { - // TODO - json!({"kind": "CopyNonOverlapping"}) - } &mir::StatementKind::Nop => { json!({"kind": "Nop"}) } + &mir::StatementKind::Intrinsic { .. } => { + // TODO + json!({"kind": "Intrinsic" }) + } }; j["pos"] = self.source_info.span.to_json(mir); j @@ -431,7 +444,6 @@ impl<'tcx> ToJson<'tcx> for mir::Terminator<'tcx> { } &mir::TerminatorKind::SwitchInt { ref discr, - ref switch_ty, ref targets, } => { let vals: Vec = @@ -443,7 +455,6 @@ impl<'tcx> ToJson<'tcx> for mir::Terminator<'tcx> { "kind": "SwitchInt", "discr": discr.to_json(mir), "discr_span": discr_span.to_json(mir), - "switch_ty": switch_ty.to_json(mir), "values": vals, "targets": targets.all_targets().iter().map(|x| x.to_json(mir)) .collect::>(), @@ -596,7 +607,7 @@ fn mir_body( } let mut blocks = Vec::new(); - for bb in mir.basic_blocks().indices() { + for bb in mir.basic_blocks.indices() { blocks.push( json!({ "blockid": bb.to_json(ms), @@ -995,7 +1006,7 @@ fn analyze_inner<'tcx, O: JsonOutput, F: FnOnce(&Path) -> io::Result>( let mut mir_path = None; let mut extern_mir_paths = Vec::new(); - let output = queries.global_ctxt().unwrap().peek_mut().enter(|tcx| -> io::Result<_> { + let output = queries.global_ctxt().unwrap().enter(|tcx| -> io::Result<_> { let outputs = tcx.output_filenames(()); if !outputs.outputs.contains_key(&OutputType::Exe) { return Ok(None); @@ -1004,7 +1015,8 @@ fn analyze_inner<'tcx, O: JsonOutput, F: FnOnce(&Path) -> io::Result>( sess, sess.crate_types().first().unwrap().clone(), &outputs, - &tcx.crate_name(LOCAL_CRATE).to_string(), + // nightly-2023-01-22 call symbol constructor + tcx.crate_name(LOCAL_CRATE), ).with_extension("mir"); let mut out = mk_output(&mir_path_)?; mir_path = Some(mir_path_); @@ -1126,20 +1138,25 @@ pub use self::analyze_streaming as analyze; fn make_attr(key: &str, value: &str) -> ast::Attribute { ast::Attribute { - kind: ast::AttrKind::Normal(ast::AttrItem { - path: ast::Path::from_ident(Ident::from_str(key)), - args: ast::MacArgs::Delimited( - tokenstream::DelimSpan::dummy(), - ast::MacDelimiter::Parenthesis, - iter::once( - tokenstream::TokenTree::token( - token::TokenKind::Ident(Symbol::intern(value), false), - Span::default(), - ), - ).collect(), - ), - tokens: None, - }, None), + kind: ast::AttrKind::Normal( + ptr::P(ast::NormalAttr { + item: ast::AttrItem { + path: ast::Path::from_ident(Ident::from_str(key)), + args: ast::AttrArgs::Delimited( + ast::DelimArgs { + dspan: tokenstream::DelimSpan::dummy(), + delim: ast::MacDelimiter::Parenthesis, + tokens: iter::once( + tokenstream::TokenTree::token_alone( + token::TokenKind::Ident(Symbol::intern(value), false), + Span::default(), + ), + ).collect(), + }), + tokens: None, + }, + tokens: None, + })), id: ast::AttrId::new(0), style: ast::AttrStyle::Inner, span: Span::default(), @@ -1147,7 +1164,8 @@ fn make_attr(key: &str, value: &str) -> ast::Attribute { } pub fn inject_attrs<'tcx>(queries: &'tcx Queries<'tcx>) { - let mut krate = queries.parse().unwrap().peek_mut(); + let mut k = queries.parse().unwrap(); // need to call `get_mut`? + let krate: &mut Crate = k.get_mut(); krate.attrs.push(make_attr("feature", "register_attr")); krate.attrs.push(make_attr("register_attr", "crux_test")); } @@ -1217,7 +1235,8 @@ thread_local! { } pub fn gather_match_spans<'tcx>(queries: &'tcx Queries<'tcx>) { - let krate = &queries.expansion().unwrap().peek().0; + let k = queries.expansion().unwrap(); + let krate = &k.borrow().0; let mut v = GatherMatchSpans::default(); visit::walk_crate(&mut v, krate); MATCH_SPAN_MAP.with(|m| m.replace(Some(Rc::new(v.match_span_map)))); diff --git a/src/analyz/to_json.rs b/src/analyz/to_json.rs index c681a88..bdadbfd 100644 --- a/src/analyz/to_json.rs +++ b/src/analyz/to_json.rs @@ -1,6 +1,6 @@ use rustc_hir::def_id::DefId; use rustc_middle::mir::Body; -use rustc_middle::ty::{self, TyCtxt}; +use rustc_middle::ty::{self, TyCtxt, DynKind}; use rustc_session::Session; use rustc_span::Span; use rustc_span::symbol::Symbol; @@ -95,7 +95,7 @@ impl<'tcx> TraitInst<'tcx> { let mut projs = preds.projection_bounds() .map(|proj| tcx.erase_late_bound_regions(proj)) .collect::>(); - projs.sort_by_key(|p| p.item_def_id); + projs.sort_by_key(|p| p.def_id); TraitInst { trait_ref, projs } } @@ -118,12 +118,12 @@ impl<'tcx> TraitInst<'tcx> { let proj_ty = tcx.mk_projection(ai.def_id, trait_ref.substs); let actual_ty = tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), proj_ty); projs.push(ty::ExistentialProjection { - item_def_id: ai.def_id, + def_id: ai.def_id, substs: ex_trait_ref.substs, - term: ty::Term::Ty(actual_ty), + term: actual_ty.into(), // TO REVIEW: structure of Term has changed }); } - projs.sort_by_key(|p| p.item_def_id); + projs.sort_by_key(|p| p.def_id); TraitInst { trait_ref: Some(ex_trait_ref), @@ -139,7 +139,8 @@ impl<'tcx> TraitInst<'tcx> { self.projs.iter().map(|p| ty::Binder::dummy(ty::ExistentialPredicate::Projection(*p))), ); let preds = tcx.intern_poly_existential_predicates(&preds); - Some(tcx.mk_dynamic(preds, tcx.mk_region(ty::RegionKind::ReErased))) + // TO REVIEW: DynKind? + Some(tcx.mk_dynamic(preds, tcx.mk_region(ty::RegionKind::ReErased), DynKind::Dyn)) } /// Build a concrete, non-existential TraitRef, filling in the `Self` parameter with the `dyn` @@ -204,8 +205,7 @@ fn ty_desc(ty: ty::Ty) -> (String, bool) { ty::TyKind::GeneratorWitness(..) => "GeneratorWitness", ty::TyKind::Never => "Never", ty::TyKind::Tuple(..) => "Tuple", - ty::TyKind::Projection(..) => "Projection", - ty::TyKind::Opaque(..) => "Opaque", + ty::TyKind::Alias(..) => "Alias", // NB: nightly-2023-01-22 - Projection and Opaque subsumed into Alias ty::TyKind::Param(..) => "Param", ty::TyKind::Bound(..) => "Bound", ty::TyKind::Placeholder(..) => "Placeholder", diff --git a/src/analyz/ty_json.rs b/src/analyz/ty_json.rs index 30efe1f..dc8ccca 100644 --- a/src/analyz/ty_json.rs +++ b/src/analyz/ty_json.rs @@ -4,10 +4,12 @@ use rustc_hir::def_id::DefId; use rustc_index::vec::{IndexVec, Idx}; use rustc_middle::mir; use rustc_const_eval::interpret; +use rustc_const_eval::const_eval::CheckAlignment; use rustc_middle::ty; -use rustc_middle::ty::{TyCtxt, TypeFoldable}; +use rustc_middle::ty::{TyCtxt, TypeFoldable, TypeVisitable}; use rustc_query_system::ich::StableHashingContext; use rustc_target::spec::abi; +use rustc_target::abi::Align; use rustc_ast::ast; use rustc_span::DUMMY_SP; use serde_json; @@ -83,15 +85,15 @@ pub fn ext_def_id_str<'tcx, T>( prefix: &str, extra: T, ) -> String -where T: HashStable> { +where T: for<'a> HashStable> { let base = def_id_str(tcx, def_id); // Based on librustc_codegen_utils/symbol_names/legacy.rs get_symbol_hash - let mut hasher = StableHasher::new(); - let mut hcx = tcx.create_stable_hashing_context(); - extra.hash_stable(&mut hcx, &mut hasher); - let hash: u64 = hasher.finish(); - + let hash: u64 = tcx.with_stable_hashing_context(|mut hcx| { + let mut hasher = StableHasher::new(); + extra.hash_stable(&mut hcx, &mut hasher); + hasher.finish() + }); format!("{}::{}{:016x}[0]", base, prefix, hash) } @@ -124,7 +126,7 @@ pub fn inst_id_str<'tcx>( ext_def_id_str(tcx, def_id, "_inst", substs) } }, - ty::InstanceDef::VtableShim(def_id) => + ty::InstanceDef::VTableShim(def_id) => ext_def_id_str(tcx, def_id, "_vtshim", substs), ty::InstanceDef::ReifyShim(def_id) => ext_def_id_str(tcx, def_id, "_reify", substs), @@ -245,8 +247,8 @@ impl<'tcx> ToJson<'tcx> for ty::Instance<'tcx> { "def_id": did.to_json(mir), "substs": substs.to_json(mir), }), - ty::InstanceDef::VtableShim(did) => json!({ - "kind": "VtableShim", + ty::InstanceDef::VTableShim(did) => json!({ + "kind": "VTableShim", // NB nightly-2023-01-22 - case change "def_id": did.to_json(mir), "substs": substs.to_json(mir), }), @@ -265,7 +267,8 @@ impl<'tcx> ToJson<'tcx> for ty::Instance<'tcx> { let self_ty = substs.types().next() .unwrap_or_else(|| panic!("expected self type in substs for {:?}", self)); let preds = match *self_ty.kind() { - ty::TyKind::Dynamic(ref preds, _region) => preds, + // NB nightly-2022-01-23 - is the addition of dynkind here relevant? + ty::TyKind::Dynamic(ref preds, _region, _dynkind) => preds, _ => panic!("expected `dyn` self type, but got {:?}", self_ty), }; let ex_tref = match preds.principal() { @@ -419,7 +422,8 @@ impl<'tcx> ToJson<'tcx> for ty::Ty<'tcx> { // tuples, so no additional information is needed. }) } - &ty::TyKind::Dynamic(preds, _region) => { + // NB nightly-2022-01-23 - is the addition of dynkind here relevant? + &ty::TyKind::Dynamic(preds, _region, _dynkind) => { let ti = TraitInst::from_dynamic_predicates(mir.state.tcx, preds); let trait_name = trait_inst_id_str(mir.state.tcx, &ti); mir.used.traits.insert(ti); @@ -430,8 +434,8 @@ impl<'tcx> ToJson<'tcx> for ty::Ty<'tcx> { .collect::>(), }) } - &ty::TyKind::Projection(..) => unreachable!( - "no TyKind::Projection should remain after monomorphization" + &ty::TyKind::Alias(ty::AliasKind::Projection, _) => unreachable!( + "no TyKind::Alias with AliasKind Projection should remain after monomorphization" ), &ty::TyKind::FnPtr(ref sig) => { json!({"kind": "FnPtr", "signature": sig.to_json(mir)}) @@ -466,9 +470,10 @@ impl<'tcx> ToJson<'tcx> for ty::Ty<'tcx> { // TODO json!({"kind": "GeneratorWitness"}) } - &ty::TyKind::Opaque(_, _) => { + // NB nightly-2023-01-22 - is this correct? + &ty::TyKind::Alias(ty::AliasKind::Opaque, _) => { // TODO - json!({"kind": "Opaque"}) + json!({"kind": "Alias"}) } }; @@ -511,11 +516,11 @@ impl<'tcx> ToJson<'tcx> for ty::TraitRef<'tcx> { } } -impl<'tcx> ToJson<'tcx> for ty::ProjectionTy<'tcx> { +impl<'tcx> ToJson<'tcx> for ty::AliasTy<'tcx> { fn to_json(&self, ms: &mut MirState<'_, 'tcx>) -> serde_json::Value { json!({ "substs": self.substs.to_json(ms), - "item_def_id": self.item_def_id.to_json(ms) + "def_id": self.def_id.to_json(ms) // NB nightly-2023-01-22 - field name change }) } } @@ -525,17 +530,18 @@ impl<'tcx> ToJson<'tcx> for ty::ProjectionTy<'tcx> { impl<'tcx> ToJson<'tcx> for ty::Predicate<'tcx> { fn to_json(&self, ms: &mut MirState<'_, 'tcx>) -> serde_json::Value { match self.kind().skip_binder() { - ty::PredicateKind::Trait(tp) => { + // NB: nightly-2023-01-23 is this right? + ty::PredicateKind::Clause(ty::Clause::Trait(tp)) => { json!({ "trait_pred": tp.trait_ref.to_json(ms) }) } - ty::PredicateKind::Projection(pp) => match pp.term { - ty::Term::Ty(ty) => json!({ + ty::PredicateKind::Clause(ty::Clause::Projection(pp)) => match pp.term.unpack() { + ty::TermKind::Ty(ty) => json!({ "projection_ty": pp.projection_ty.to_json(ms), "ty": ty.to_json(ms), }), - ty::Term::Const(_) => json!("unknown_const_projection"), + ty::TermKind::Const(_) => json!("unknown_const_projection"), } _ => { json!("unknown_pred") @@ -556,14 +562,14 @@ impl<'tcx> ToJson<'tcx> for ty::ExistentialPredicate<'tcx> { "substs": trait_ref.substs.to_json(ms), }) }, - &ty::ExistentialPredicate::Projection(ref proj) => match proj.term { - ty::Term::Ty(ty) => json!({ + &ty::ExistentialPredicate::Projection(ref proj) => match proj.term.unpack() { + ty::TermKind::Ty(ty) => json!({ "kind": "Projection", - "proj": proj.item_def_id.to_json(ms), + "proj": proj.def_id.to_json(ms), "substs": proj.substs.to_json(ms), "rhs_ty": ty.to_json(ms), }), - ty::Term::Const(_) => json!({ + ty::TermKind::Const(_) => json!({ "kind": "Projection_Const", }), }, @@ -654,21 +660,23 @@ fn eval_array_len<'tcx>( tcx: TyCtxt<'tcx>, c: ty::Const<'tcx>, ) -> usize { - let evaluated = match c.val() { - ty::ConstKind::Unevaluated(un) => { - tcx.const_eval_resolve(ty::ParamEnv::reveal_all(), un, None).unwrap() - }, - ty::ConstKind::Value(val) => val, + match c.kind() { + // ty::ConstKind::Unevaluated(un) => { + // tcx.const_eval_resolve(ty::ParamEnv::reveal_all(), un.expand(), None).unwrap() + // }, + // NB: the type of "val" changed to valtree - try to get the size out of that + ty::ConstKind::Value(ty::ValTree::Leaf(val)) => + val.try_to_machine_usize(tcx).expect("expecting usize value from constant") as usize, ref val => panic!("don't know how to translate ConstKind::{:?}", val), - }; - match evaluated { - interpret::ConstValue::Scalar(interpret::Scalar::Int(sint)) => { - let data = sint.to_bits(sint.size()).unwrap(); - assert!(data <= usize::MAX as u128); - data as usize - }, - _ => panic!("impossible: array size is not a scalar?"), } + // match evaluated { + // interpret::ConstValue::Scalar(interpret::Scalar::Int(sint)) => { + // let data = sint.to_bits(sint.size()).unwrap(); + // assert!(data <= usize::MAX as u128); + // data as usize + // }, + // _ => panic!("impossible: array size is not a scalar?"), + // } } fn read_static_memory<'tcx>( @@ -676,7 +684,8 @@ fn read_static_memory<'tcx>( start: usize, end: usize, ) -> &'tcx [u8] { - assert!(alloc.relocations().len() == 0); + // NB: nightly-2023-01-22 - is this correct? + assert!(alloc.provenance().ptrs().len() == 0); alloc.inspect_with_uninit_and_ptr_outside_interpreter(start .. end) } @@ -691,7 +700,7 @@ fn render_constant_scalar<'tcx>( render_constant(mir, ty, Some(s), Some((sint.size().bytes() as u8, data)), None) }, interpret::Scalar::Ptr(ptr, _) => { - match mir.state.tcx.get_global_alloc(ptr.provenance) { + match mir.state.tcx.try_get_global_alloc(ptr.provenance) { Some(ga) => match ga { interpret::GlobalAlloc::Static(def_id) => Some(json!({ "kind": "static_ref", @@ -715,6 +724,12 @@ fn render_constant_scalar<'tcx>( } } +fn render_zst<'tcx>() -> serde_json::Value { + json!({ + "kind": "zst", + }) +} + // TODO: migrate all constant rendering to use InterpCx + OpTy. This should reduce special cases // and let us handle both in-memory and immediate constants. fn render_constant<'tcx>( @@ -868,9 +883,7 @@ fn render_constant<'tcx>( _ => { if let Some((0, _)) = scalar_bits { - json!({ - "kind": "zst", - }) + render_zst() } else { return None; } @@ -898,22 +911,20 @@ fn render_constant_variant<'tcx>( // `try_as_mplace` always "succeeds" (returns an `MPlace`, dangling) for ZSTs. We want it // to be an immediate instead. if field.layout.is_zst() { - let zst_scalar = interpret::Scalar::Int(ty::ScalarInt::ZST); - vals.push(render_constant_scalar(mir, field.layout.ty, zst_scalar)?); + // NB nightly-2022-01-23 : ZST is gone? + // call render_constant directly such that it returns a zst value + vals.push(render_zst()); continue; } - let val = match field.try_as_mplace() { - Ok(_mpl) => None, - Err(imm) => match *imm { - interpret::Immediate::Scalar(maybe_scalar) => match maybe_scalar { - interpret::ScalarMaybeUninit::Scalar(s) => { - render_constant_scalar(mir, field.layout.ty, s) - }, + let val = match field.as_mplace_or_imm().into() { + Err(_mpl) => None, + Ok(imm) => + match *imm { + interpret::Immediate::Scalar(s) => + render_constant_scalar(mir, field.layout.ty, s), _ => None, - }, - _ => None, - }, + } }?; vals.push(val); } @@ -926,7 +937,7 @@ mod machine { use std::borrow::Cow; use super::*; use rustc_const_eval::interpret::*; - use rustc_data_structures::fx::FxHashMap; + use rustc_data_structures::fx::FxIndexMap; use rustc_middle::ty::*; use rustc_middle::mir::*; use rustc_span::Span; @@ -935,12 +946,12 @@ mod machine { impl<'mir, 'tcx> Machine<'mir, 'tcx> for RenderConstMachine { type MemoryKind = !; - type PointerTag = AllocId; - type TagExtra = (); + type Provenance = AllocId; + type ProvenanceExtra = (); type ExtraFnVal = !; type FrameExtra = (); type AllocExtra = (); - type MemoryMap = FxHashMap< + type MemoryMap = FxIndexMap< AllocId, (MemoryKind, Allocation), >; @@ -948,32 +959,46 @@ mod machine { const GLOBAL_KIND: Option = None; const PANIC_ON_ALLOC_FAIL: bool = false; - fn enforce_alignment(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool { - false + fn enforce_alignment(ecx: &InterpCx<'mir, 'tcx, Self>) -> CheckAlignment { + CheckAlignment::No } - fn force_int_for_alignment_check(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool { - false + fn alignment_check_failed( + ecx: &InterpCx<'mir, 'tcx, Self>, + has: Align, + required: Align, + check: CheckAlignment, + ) -> InterpResult<'tcx, ()> { + panic!("not implemented: alignment_check_failed"); } - fn enforce_validity(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool { + fn use_addr_for_alignment_check(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool { false } - fn enforce_number_init(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool { - false + #[inline(always)] + fn checked_binop_checks_overflow(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool { + true } - fn enforce_number_no_provenance(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool { + fn enforce_validity(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool { false } + // fn enforce_number_init(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool { + // false + // } + + // fn enforce_number_no_provenance(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool { + // false + // } + fn find_mir_or_eval_fn( ecx: &mut InterpCx<'mir, 'tcx, Self>, instance: ty::Instance<'tcx>, abi: Abi, - args: &[OpTy<'tcx, Self::PointerTag>], - destination: &PlaceTy<'tcx, Self::PointerTag>, + args: &[OpTy<'tcx, Self::Provenance>], + destination: &PlaceTy<'tcx, Self::Provenance>, target: Option, unwind: StackPopUnwind, ) -> InterpResult<'tcx, Option<(&'mir mir::Body<'tcx>, ty::Instance<'tcx>)>> { @@ -988,8 +1013,8 @@ mod machine { ecx: &mut InterpCx<'mir, 'tcx, Self>, fn_val: Self::ExtraFnVal, abi: Abi, - args: &[OpTy<'tcx, Self::PointerTag>], - destination: &PlaceTy<'tcx, Self::PointerTag>, + args: &[OpTy<'tcx, Self::Provenance>], + destination: &PlaceTy<'tcx, Self::Provenance>, target: Option, unwind: StackPopUnwind, ) -> InterpResult<'tcx> { @@ -1003,8 +1028,8 @@ mod machine { fn call_intrinsic( ecx: &mut InterpCx<'mir, 'tcx, Self>, instance: ty::Instance<'tcx>, - args: &[OpTy<'tcx, Self::PointerTag>], - destination: &PlaceTy<'tcx, Self::PointerTag>, + args: &[OpTy<'tcx, Self::Provenance>], + destination: &PlaceTy<'tcx, Self::Provenance>, target: Option, unwind: StackPopUnwind, ) -> InterpResult<'tcx> { @@ -1030,9 +1055,9 @@ mod machine { fn binary_ptr_op( ecx: &InterpCx<'mir, 'tcx, Self>, bin_op: mir::BinOp, - left: &ImmTy<'tcx, Self::PointerTag>, - right: &ImmTy<'tcx, Self::PointerTag>, - ) -> InterpResult<'tcx, (Scalar, bool, Ty<'tcx>)> { + left: &ImmTy<'tcx, Self::Provenance>, + right: &ImmTy<'tcx, Self::Provenance>, + ) -> InterpResult<'tcx, (Scalar, bool, Ty<'tcx>)> { Err(InterpError::Unsupported( UnsupportedOpInfo::Unsupported( "binary_ptr_op".into(), @@ -1043,7 +1068,7 @@ mod machine { fn extern_static_base_pointer( ecx: &InterpCx<'mir, 'tcx, Self>, def_id: DefId, - ) -> InterpResult<'tcx, Pointer> { + ) -> InterpResult<'tcx, Pointer> { Err(InterpError::Unsupported( UnsupportedOpInfo::Unsupported( "extern_static_base_pointer".into(), @@ -1051,30 +1076,23 @@ mod machine { ).into()) } - fn tag_alloc_base_pointer( + fn adjust_alloc_base_pointer( ecx: &InterpCx<'mir, 'tcx, Self>, ptr: Pointer, - ) -> Pointer { + ) -> Pointer { unimplemented!("tag_alloc_base_pointer") } fn ptr_from_addr_cast( ecx: &InterpCx<'mir, 'tcx, Self>, addr: u64, - ) -> Pointer> { + ) -> InterpResult<'tcx, Pointer>> { unimplemented!("ptr_from_addr_cast") } - fn ptr_from_addr_transmute( - ecx: &InterpCx<'mir, 'tcx, Self>, - addr: u64, - ) -> Pointer> { - unimplemented!("ptr_from_addr_transmute") - } - fn expose_ptr( ecx: &mut InterpCx<'mir, 'tcx, Self>, - ptr: Pointer, + ptr: Pointer, ) -> InterpResult<'tcx> { Err(InterpError::Unsupported( UnsupportedOpInfo::Unsupported( @@ -1085,24 +1103,24 @@ mod machine { fn ptr_get_alloc( ecx: &InterpCx<'mir, 'tcx, Self>, - ptr: Pointer, - ) -> Option<(AllocId, Size, Self::TagExtra)> { + ptr: Pointer, + ) -> Option<(AllocId, Size, Self::ProvenanceExtra)> { None } - fn init_allocation_extra<'b>( + fn adjust_allocation<'b>( ecx: &InterpCx<'mir, 'tcx, Self>, id: AllocId, alloc: Cow<'b, Allocation>, kind: Option>, - ) -> Cow<'b, Allocation> { - alloc + ) -> InterpResult<'tcx, Cow<'b, Allocation>> { + Ok(alloc) } fn init_frame_extra( ecx: &mut InterpCx<'mir, 'tcx, Self>, - frame: Frame<'mir, 'tcx, Self::PointerTag>, - ) -> InterpResult<'tcx, Frame<'mir, 'tcx, Self::PointerTag, Self::FrameExtra>> { + frame: Frame<'mir, 'tcx, Self::Provenance>, + ) -> InterpResult<'tcx, Frame<'mir, 'tcx, Self::Provenance, Self::FrameExtra>> { Err(InterpError::Unsupported( UnsupportedOpInfo::Unsupported( "init_frame_extra".into(), @@ -1112,13 +1130,13 @@ mod machine { fn stack<'a>( ecx: &'a InterpCx<'mir, 'tcx, Self>, - ) -> &'a [Frame<'mir, 'tcx, Self::PointerTag, Self::FrameExtra>] { + ) -> &'a [Frame<'mir, 'tcx, Self::Provenance, Self::FrameExtra>] { unimplemented!("stack") } fn stack_mut<'a>( ecx: &'a mut InterpCx<'mir, 'tcx, Self>, - ) -> &'a mut Vec> { + ) -> &'a mut Vec> { unimplemented!("stack_mut") } } @@ -1129,31 +1147,47 @@ impl<'tcx> ToJson<'tcx> for ty::Const<'tcx> { let mut map = serde_json::Map::new(); map.insert("ty".to_owned(), self.ty().to_json(mir)); - match self.val() { + match self.kind() { + // remove? should probably not show up? ty::ConstKind::Unevaluated(un) => { map.insert("initializer".to_owned(), json!({ - "def_id": get_promoted_name(mir, un.def.did, un.substs, un.promoted), + // TODO nightly-2023-01-22 promoted has been removed? + // change `get_promoted_name` to the "get non-promoted name" version + // if we even need this case + "def_id": get_fn_def_name(mir, un.def.did, un.substs), })); }, _ => {}, } - let evaluated = match self.val() { - ty::ConstKind::Unevaluated(un) => { - mir.state.tcx.const_eval_resolve(ty::ParamEnv::reveal_all(), un, None).unwrap() - }, - ty::ConstKind::Value(val) => val, - _ => panic!("don't know how to translate ConstKind::{:?}", self.val()), - }; - - let rendered = match evaluated { - interpret::ConstValue::Scalar(s) => { - render_constant_scalar(mir, self.ty(), s) - }, - interpret::ConstValue::Slice { data, start, end } => { - render_constant(mir, self.ty(), None, None, Some((data.inner(), start, end))) - }, - _ => None, + // let evaluated = match self.kind() { + // // nightly-2023-01-22 remove? probably should not show up + // ty::ConstKind::Unevaluated(un) => { + // // TODO nightly-2023-01-22 unevaluatedconst changed + // // use `const_eval_resolve_for_typecheck` ? + // mir.state.tcx.const_eval_resolve(ty::ParamEnv::reveal_all(), un, None).unwrap() + // }, + // // TODO nightly-2023-01-22 ConstKind value is now a valtree (assume leaf only?) + // // Remove other cases besides Value(Leaf(x)) - this means we might remove slice below + // // might have to see if we panic + // ty::ConstKind::Value(val) => val, + // _ => panic!("don't know how to translate ConstKind::{:?}", self.kind()), + // }; + + // let rendered = match evaluated { + // interpret::ConstValue::Scalar(s) => { + // render_constant_scalar(mir, self.ty(), s) + // }, + // interpret::ConstValue::Slice { data, start, end } => { + // render_constant(mir, self.ty(), None, None, Some((data.inner(), start, end))) + // }, + // _ => None, + // }; + + let rendered = match self.kind() { + ty::ConstKind::Value(ty::ValTree::Leaf(val)) => + render_constant(mir, self.ty(), None, Some((val.size().bytes() as u8, val.try_to_u128().unwrap())), None), + _ => panic!("don't know how to translate ConstKind::{:?}", self.kind()) }; if let Some(rendered) = rendered { map.insert("rendered".to_owned(), rendered); @@ -1175,6 +1209,9 @@ impl<'tcx> ToJson<'tcx> for (interpret::ConstValue<'tcx>, ty::Ty<'tcx>) { render_constant(mir, ty, None, None, Some((data.inner(), start, end))) .unwrap_or_else(|| json!({"type": "unknown_slice"})) }, + interpret::ConstValue::ZeroSized => { + render_zst() + }, interpret::ConstValue::ByRef { .. } => json!({"kind": "unknown_by_ref"}), } } @@ -1270,7 +1307,7 @@ impl ToJsonAg for ty::VariantDef { "name": self.def_id.to_json(mir), "discr": self.discr.to_json(mir), "fields": self.fields.tojson(mir, substs), - "ctor_kind": self.ctor_kind.to_json(mir) + "ctor_kind": self.ctor_kind().to_json(mir) }) } } diff --git a/src/bin/cargo-crux-test.rs b/src/bin/cargo-crux-test.rs index 4bdf647..71e5f4b 100644 --- a/src/bin/cargo-crux-test.rs +++ b/src/bin/cargo-crux-test.rs @@ -15,6 +15,7 @@ #![feature(rustc_private)] extern crate cargo; extern crate clap; +extern crate rustc_driver; extern crate rustc_session; extern crate serde_json; extern crate toml_edit; diff --git a/src/bin/crux-rustc.rs b/src/bin/crux-rustc.rs index b0befcc..35be75e 100644 --- a/src/bin/crux-rustc.rs +++ b/src/bin/crux-rustc.rs @@ -2,6 +2,7 @@ //! crux-test`. Useful for testing a single file, with `crux-rustc --test foo.rs`. #![feature(rustc_private)] +extern crate rustc_driver; extern crate rustc_session; use std::env; diff --git a/src/bin/mir-json-rustc-wrapper.rs b/src/bin/mir-json-rustc-wrapper.rs index f0ebff3..49fa341 100644 --- a/src/bin/mir-json-rustc-wrapper.rs +++ b/src/bin/mir-json-rustc-wrapper.rs @@ -63,14 +63,19 @@ impl rustc_driver::Callbacks for GetOutputPathCallbacks { queries: &'tcx Queries<'tcx>, ) -> Compilation { let sess = compiler.session(); - let crate_name = queries.crate_name().unwrap().peek(); - let outputs = queries.prepare_outputs().unwrap().peek(); + // rustc_session::find_crate_name - get the crate with queries.expansion? + let krate = queries.parse().unwrap(); + let krate = krate.borrow(); + let crate_name = rustc_session::output::find_crate_name(&sess, &krate.attrs); + // get global ctxt then call methods inside of enter() to get + let outputs = compiler.build_output_filenames(&sess, &krate.attrs); //queries.prepare_outputs().unwrap().peek(); self.output_path = Some(rustc_session::output::out_filename( sess, sess.crate_types().first().unwrap().clone(), &outputs, - &crate_name, + crate_name, )); + let ctx = queries.global_ctxt().unwrap(); Compilation::Stop } } From e979aae8f91ff20ba42aa657138b23d85ed4a4d7 Mon Sep 17 00:00:00 2001 From: James LaMar Date: Fri, 3 Mar 2023 17:25:58 -0800 Subject: [PATCH 16/35] More fixes --- src/analyz/mod.rs | 38 ++++++++++++++++++++-------------- src/analyz/ty_json.rs | 48 ++++++++++++++++++++++++++++++++++++++++--- src/bin/wrapper.rs | 2 +- 3 files changed, 69 insertions(+), 19 deletions(-) diff --git a/src/analyz/mod.rs b/src/analyz/mod.rs index 0d06354..e7c2a45 100644 --- a/src/analyz/mod.rs +++ b/src/analyz/mod.rs @@ -331,13 +331,14 @@ impl<'tcx> ToJson<'tcx> for mir::Operand<'tcx> { impl<'tcx> ToJson<'tcx> for mir::Constant<'tcx> { fn to_json(&self, mir: &mut MirState<'_, 'tcx>) -> serde_json::Value { - match self.literal { - mir::ConstantKind::Ty(c) => c.to_json(mir), - mir::ConstantKind::Val(cv, ty) => (cv, ty).to_json(mir), - // nightly-20203-01-22 evaluate? - mir::ConstantKind::Unevaluated(val, ty) => - panic!("unevaluated const in mir::constant serializer") - } + (eval_mir_constant(mir.state.tcx, self), self.ty()).to_json(mir) + // match self.literal { + // mir::ConstantKind::Ty(c) => c.to_json(mir), + // mir::ConstantKind::Val(cv, ty) => (cv, ty).to_json(mir), + // // nightly-2023-01-22 evaluate? + // mir::ConstantKind::Unevaluated(val, ty) => + // panic!("unevaluated const in mir::constant serializer val:{:?} ty:{:?}", val, ty) + // } } } @@ -683,7 +684,8 @@ fn emit_static(ms: &mut MirState, out: &mut impl JsonOutput, def_id: DefId) -> i let tcx = ms.state.tcx; let name = def_id_str(tcx, def_id); - let mir = tcx.optimized_mir(def_id); + // let mir = tcx.optimized_mir(def_id); + let mir = tcx.mir_for_ctfe(def_id); emit_fn(ms, out, &name, None, mir)?; emit_static_decl(ms, out, &name, mir.return_ty(), tcx.is_mutable_static(def_id))?; @@ -1166,8 +1168,8 @@ fn make_attr(key: &str, value: &str) -> ast::Attribute { pub fn inject_attrs<'tcx>(queries: &'tcx Queries<'tcx>) { let mut k = queries.parse().unwrap(); // need to call `get_mut`? let krate: &mut Crate = k.get_mut(); - krate.attrs.push(make_attr("feature", "register_attr")); - krate.attrs.push(make_attr("register_attr", "crux_test")); + krate.attrs.push(make_attr("feature", "register_tool")); + krate.attrs.push(make_attr("register_tool", "crux")); } #[derive(Default)] @@ -1235,11 +1237,17 @@ thread_local! { } pub fn gather_match_spans<'tcx>(queries: &'tcx Queries<'tcx>) { - let k = queries.expansion().unwrap(); - let krate = &k.borrow().0; - let mut v = GatherMatchSpans::default(); - visit::walk_crate(&mut v, krate); - MATCH_SPAN_MAP.with(|m| m.replace(Some(Rc::new(v.match_span_map)))); + queries.global_ctxt().unwrap().enter(|tcx| { + let resolver = tcx.resolver_for_lowering(()); + let krate = &resolver.borrow().1; + let mut v = GatherMatchSpans::default(); + visit::walk_crate(&mut v, krate); + MATCH_SPAN_MAP.with(|m| m.replace(Some(Rc::new(v.match_span_map)))); + }); + // let k = queries.expansion().unwrap(); + // let krate: &ast::Crate = &k.borrow().0; + + } fn get_match_spans() -> Rc> { diff --git a/src/analyz/ty_json.rs b/src/analyz/ty_json.rs index dc8ccca..85719f5 100644 --- a/src/analyz/ty_json.rs +++ b/src/analyz/ty_json.rs @@ -739,7 +739,6 @@ fn render_constant<'tcx>( scalar_bits: Option<(u8, u128)>, slice: Option<(&'tcx mir::interpret::Allocation, usize, usize)>, ) -> Option { - // Special cases: &str and &[u8; _] if let ty::TyKind::Ref(_, inner_ty, hir::Mutability::Not) = *ty.kind() { if let ty::TyKind::Str = *inner_ty.kind() { @@ -821,7 +820,12 @@ fn render_constant<'tcx>( }, ty::TyKind::RawPtr(_) => { - let (_size, bits) = scalar_bits.expect("raw_ptr const had non-scalar value?"); + let (_size, bits) = + match scalar_bits { + Some(s) => s, + None => return None + }; + json!({ "kind": "raw_ptr", "val": bits.to_string(), @@ -1186,7 +1190,7 @@ impl<'tcx> ToJson<'tcx> for ty::Const<'tcx> { let rendered = match self.kind() { ty::ConstKind::Value(ty::ValTree::Leaf(val)) => - render_constant(mir, self.ty(), None, Some((val.size().bytes() as u8, val.try_to_u128().unwrap())), None), + render_constant(mir, self.ty(), None, Some((val.size().bytes() as u8, val.try_to_uint(val.size()).unwrap())), None), _ => panic!("don't know how to translate ConstKind::{:?}", self.kind()) }; if let Some(rendered) = rendered { @@ -1345,3 +1349,41 @@ pub fn handle_adt_ag<'tcx>( _ => unreachable!("bad"), } } + +pub fn eval_mir_constant<'tcx>( + tcx: TyCtxt<'tcx>, + constant: &mir::Constant<'tcx>, +) -> interpret::ConstValue<'tcx> { + // let ct = self.monomorphize(constant.literal); + let uv = match constant.literal { + mir::ConstantKind::Ty(ct) => match ct.kind() { + ty::ConstKind::Unevaluated(uv) => uv.expand(), + ty::ConstKind::Value(val) => { + return tcx.valtree_to_const_val((ct.ty(), val)); + } + err => panic!( + // constant.span, + "encountered bad ConstKind after monomorphizing: {:?} span:{:?}", + err, constant.span + ), + }, + mir::ConstantKind::Unevaluated(uv, _) => uv, + mir::ConstantKind::Val(val, _) => return val, + }; + + tcx.const_eval_resolve(ty::ParamEnv::reveal_all(), uv, None).unwrap() // .map_err(|err| { + // match err { + // ErrorHandled::Reported(_) => { + // self.cx.tcx().sess.emit_err(errors::ErroneousConstant { span: constant.span }); + // } + // ErrorHandled::TooGeneric => { + // self.cx + // .tcx() + // .sess + // .diagnostic() + // .emit_bug(errors::PolymorphicConstantTooGeneric { span: constant.span }); + // } + // } + // err + // }).unwrap() +} \ No newline at end of file diff --git a/src/bin/wrapper.rs b/src/bin/wrapper.rs index a593384..1b86c7b 100644 --- a/src/bin/wrapper.rs +++ b/src/bin/wrapper.rs @@ -26,7 +26,7 @@ const LIB_PATH_VAR: &str = "LD_LIBRARY_PATH"; #[cfg(target_os = "macos")] const LIB_PATH_VAR: &str = "DYLD_LIBRARY_PATH"; -const TOOLCHAIN: &str = "nightly-2020-03-22"; +const TOOLCHAIN: &str = "nightly-2023-01-23"; fn find_lib_dir() -> PathBuf { let output = Command::new("rustc") From 79950fe1fa8decf2b5250b2041074e523b0da317 Mon Sep 17 00:00:00 2001 From: James LaMar Date: Thu, 16 Mar 2023 12:52:55 -0700 Subject: [PATCH 17/35] cleanup --- Cargo.toml | 3 + rust-toolchain.toml | 2 + src/analyz/mod.rs | 92 +++-- src/analyz/to_json.rs | 31 +- src/analyz/ty_json.rs | 773 ++++++++++++++++++++++++------------------ 5 files changed, 550 insertions(+), 351 deletions(-) create mode 100644 rust-toolchain.toml diff --git a/Cargo.toml b/Cargo.toml index f0726df..d08dc29 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,9 @@ authors = ["Joshua Gancher "] repository = "https://github.com/GaloisInc/mir-json.git" license = "MIT/Apache-2.0" +[package.metadata.rust-analyzer] +rustc_private=true + [dependencies] serde = "1.0" serde_derive = "1.0" diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..35f3e1c --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly-2023-01-23" \ No newline at end of file diff --git a/src/analyz/mod.rs b/src/analyz/mod.rs index 70ca7dc..fab18c4 100644 --- a/src/analyz/mod.rs +++ b/src/analyz/mod.rs @@ -111,7 +111,6 @@ fn vtable_descriptor_for_cast<'tcx>( // Relevant code: rustc_codegen_ssa::meth::get_vtable let trait_ref = match *new_pointee.kind() { - // NB nightly-2023-01-23 dyntype ty::TyKind::Dynamic(ref preds, _, _) => preds.principal().map(|pred| pred.with_self_ty(tcx, old_pointee)), _ => return None, @@ -139,7 +138,7 @@ impl<'tcx> ToJson<'tcx> for mir::Rvalue<'tcx> { json!({ "kind": "Repeat", "op": op.to_json(mir), - "len": s.to_json(mir), + "len": get_const_usize(mir.state.tcx, s) }) } &mir::Rvalue::Ref(_, ref bk, ref l) => { @@ -332,13 +331,6 @@ impl<'tcx> ToJson<'tcx> for mir::Operand<'tcx> { impl<'tcx> ToJson<'tcx> for mir::Constant<'tcx> { fn to_json(&self, mir: &mut MirState<'_, 'tcx>) -> serde_json::Value { (eval_mir_constant(mir.state.tcx, self), self.ty()).to_json(mir) - // match self.literal { - // mir::ConstantKind::Ty(c) => c.to_json(mir), - // mir::ConstantKind::Val(cv, ty) => (cv, ty).to_json(mir), - // // nightly-2023-01-22 evaluate? - // mir::ConstantKind::Unevaluated(val, ty) => - // panic!("unevaluated const in mir::constant serializer val:{:?} ty:{:?}", val, ty) - // } } } @@ -404,9 +396,25 @@ impl<'tcx> ToJson<'tcx> for mir::Statement<'tcx> { &mir::StatementKind::Nop => { json!({"kind": "Nop"}) } - &mir::StatementKind::Intrinsic { .. } => { + &mir::StatementKind::Intrinsic(ref ndi) => { + match **ndi { + mir::NonDivergingIntrinsic::Assume(ref a) => + json!({ + "kind": "Intrinsic", + "intrinsic_kind": "Assume", + "operand": a.to_json(mir), + }), + mir::NonDivergingIntrinsic::CopyNonOverlapping(ref cno) => + json!({ + "kind": "Intrinsic", + "intrinsic_kind": "CopyNonOverlapping", + "src": cno.src.to_json(mir), + "dst": cno.dst.to_json(mir), + "count": cno.count.to_json(mir), + }) + } // TODO - json!({"kind": "Intrinsic" }) + //json!({"kind": "Intrinsic" }) } }; j["pos"] = self.source_info.span.to_json(mir); @@ -459,6 +467,7 @@ impl<'tcx> ToJson<'tcx> for mir::Terminator<'tcx> { "values": vals, "targets": targets.all_targets().iter().map(|x| x.to_json(mir)) .collect::>(), + "switch_ty": discr.ty(mir.mir.unwrap(), mir.state.tcx).to_json(mir) }) } &mir::TerminatorKind::Resume => { @@ -660,7 +669,7 @@ fn emit_trait<'tcx>( "name": trait_inst_id_str(ms.state.tcx, &ti), "items": items, }))?; - emit_new_types(ms, out)?; + emit_new_defs(ms, out)?; Ok(()) } @@ -708,14 +717,50 @@ fn emit_static_decl<'tcx>( "name": name, "ty": ty.to_json(ms), "mutable": mutable, + "kind": "body", }); out.emit(EntryKind::Static, j)?; - emit_new_types(ms, out) + emit_new_defs(ms, out) } fn has_test_attr(tcx: TyCtxt, def_id: DefId) -> bool { - def_id.is_local() && tcx.has_attr(def_id, Symbol::intern("crux_test")) + if !def_id.is_local() { + return false; + } + + for attr in tcx.get_attrs_unchecked(def_id) { + let crux = Symbol::intern("crux"); + let test = Symbol::intern("test"); + match &attr.kind { + rustc_ast::AttrKind::Normal(na) => { + let segs = &na.item.path.segments; + if segs.len() == 2 && segs[0].ident.name == crux && segs[1].ident.name == test { + return true; + } + } + _ => { } + } + } + return false; + + // let mut file = + // std::fs::OpenOptions::new() + // .create(true) + // .append(true) + // .open("/tmp/attrs") + // .unwrap(); + + + // writeln!(file, "has crux::test attr:{}", tcx.has_attr(def_id, Symbol::intern("crux::test"))).unwrap(); + // for a in attrs { + // writeln!(file, "attr: {:?}", a).unwrap(); + // } + // file.flush().unwrap(); + + // for + + // def_id.is_local() && tcx.has_attr(def_id, Symbol::intern("crux::test")) } /// Process the initial/root instances in the current crate. This adds entries to `ms.used`, and @@ -802,7 +847,7 @@ fn emit_instance<'tcx>( "name": &name, "inst": inst.to_json(ms), }))?; - emit_new_types(ms, out)?; + emit_new_defs(ms, out)?; match inst.def { ty::InstanceDef::Item(def_id) => { @@ -875,7 +920,7 @@ fn emit_vtable<'tcx>( "name": vtable_name(ms, poly_trait_ref), "items": build_vtable_items(ms, poly_trait_ref), }))?; - emit_new_types(ms, out) + emit_new_defs(ms, out) } fn vtable_name<'tcx>( @@ -921,7 +966,7 @@ fn emit_adt<'tcx>( tcx.sess.note_without_error( format!("Emitting ADT definition for {}", adt_name).as_str()); out.emit(EntryKind::Adt, ai.to_json(ms))?; - emit_new_types(ms, out)?; + emit_new_defs(ms, out)?; Ok(()) } @@ -942,6 +987,7 @@ fn emit_fn<'tcx>( state: ms.state, tys: ms.tys, match_span_map: ms.match_span_map, + allocs: ms.allocs, }; let ms = &mut ms; @@ -955,16 +1001,19 @@ fn emit_fn<'tcx>( "abi": abi.to_json(ms), "spread_arg": mir.spread_arg.map(|x| x.as_usize()), }))?; - emit_new_types(ms, out) + emit_new_defs(ms, out) } -fn emit_new_types( +fn emit_new_defs( ms: &mut MirState, out: &mut impl JsonOutput, ) -> io::Result<()> { for j in ms.tys.take_new_types() { out.emit(EntryKind::Ty, j)?; } + for j in ms.allocs.take_new_allocs() { + out.emit(EntryKind::Static, j)?; + } assert!(ms.tys.take_new_types().is_empty()); Ok(()) } @@ -1018,7 +1067,6 @@ fn analyze_inner<'tcx, O: JsonOutput, F: FnOnce(&Path) -> io::Result>( sess, sess.crate_types().first().unwrap().clone(), &outputs, - // nightly-2023-01-22 call symbol constructor tcx.crate_name(LOCAL_CRATE), ).with_extension("mir"); let mut out = mk_output(&mir_path_)?; @@ -1043,6 +1091,7 @@ fn analyze_inner<'tcx, O: JsonOutput, F: FnOnce(&Path) -> io::Result>( let mut used = Used::default(); let mut tys = TyIntern::default(); + let mut allocs = AllocIntern::default(); let state = CompileState { session: sess, tcx, @@ -1053,6 +1102,7 @@ fn analyze_inner<'tcx, O: JsonOutput, F: FnOnce(&Path) -> io::Result>( state: &state, tys: &mut tys, match_span_map: &get_match_spans(), + allocs: &mut allocs, }; // Traits and top-level statics can be enumerated directly. @@ -1079,7 +1129,7 @@ fn analyze_inner<'tcx, O: JsonOutput, F: FnOnce(&Path) -> io::Result>( // Any referenced types should normally be emitted immediately after the entry that // references them, but we check again here just in case. - emit_new_types(&mut ms, &mut out)?; + emit_new_defs(&mut ms, &mut out)?; Ok(Some(out)) })?; diff --git a/src/analyz/to_json.rs b/src/analyz/to_json.rs index 04687ca..dd44608 100644 --- a/src/analyz/to_json.rs +++ b/src/analyz/to_json.rs @@ -1,5 +1,5 @@ use rustc_hir::def_id::DefId; -use rustc_middle::mir::Body; +use rustc_middle::mir::{Body, interpret}; use rustc_middle::ty::{self, TyCtxt, DynKind}; use rustc_session::Session; use rustc_span::Span; @@ -226,7 +226,7 @@ fn ty_desc(ty: ty::Ty) -> (String, bool) { ty::TyKind::GeneratorWitness(..) => "GeneratorWitness", ty::TyKind::Never => "Never", ty::TyKind::Tuple(..) => "Tuple", - ty::TyKind::Alias(..) => "Alias", // NB: nightly-2023-01-22 - Projection and Opaque subsumed into Alias + ty::TyKind::Alias(..) => "Alias", ty::TyKind::Param(..) => "Param", ty::TyKind::Bound(..) => "Bound", ty::TyKind::Placeholder(..) => "Placeholder", @@ -269,6 +269,32 @@ impl<'tcx> TyIntern<'tcx> { } } + +#[derive(Default, Debug)] +pub struct AllocIntern<'tcx> { + map: HashMap, String>, + new_vals: Vec, +} + +impl<'tcx> AllocIntern<'tcx> { + pub fn get(&self, alloc: interpret::ConstAllocation<'tcx>) -> Option<&str> { + self.map.get(&alloc).map(|x| x as &str) + } + + pub fn insert(&mut self, alloc: interpret::ConstAllocation<'tcx>, mut static_def: serde_json::Value) -> String { + let id = format!("alloc${}", self.map.len()); + static_def["name"] = id.clone().into(); + self.new_vals.push(static_def); + let old = self.map.insert(alloc, id.clone()); + assert!(old.is_none(), "duplicate insert for type {:?}", alloc); + id + } + + pub fn take_new_allocs(&mut self) -> Vec { + mem::replace(&mut self.new_vals, Vec::new()) + } +} + pub struct MirState<'a, 'tcx : 'a> { pub mir: Option<&'tcx Body<'tcx>>, pub used: &'a mut Used<'tcx>, @@ -285,6 +311,7 @@ pub struct MirState<'a, 'tcx : 'a> { /// rewritten. This seems okay for now since the user is mostly interested in coverage in /// their own top-level crate anyway. pub match_span_map: &'a HashMap, + pub allocs: &'a mut AllocIntern<'tcx>, } /// Trait for converting MIR elements to JSON. diff --git a/src/analyz/ty_json.rs b/src/analyz/ty_json.rs index 55a374c..4f0d503 100644 --- a/src/analyz/ty_json.rs +++ b/src/analyz/ty_json.rs @@ -4,14 +4,13 @@ use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_index::vec::{IndexVec, Idx}; use rustc_middle::mir; -use rustc_const_eval::interpret; +use rustc_const_eval::interpret::{self, InterpCx}; use rustc_const_eval::const_eval::CheckAlignment; use rustc_middle::ty; use rustc_middle::ty::{TyCtxt, TypeFoldable, TypeVisitable}; use rustc_query_system::ich::StableHashingContext; use rustc_target::spec::abi; -use rustc_target::abi::Align; -use rustc_ast::ast; +use rustc_target::abi::{Align, Size}; use rustc_span::DUMMY_SP; use serde_json; use std::fmt::Write as FmtWrite; @@ -249,7 +248,7 @@ impl<'tcx> ToJson<'tcx> for ty::Instance<'tcx> { "substs": substs.to_json(mir), }), ty::InstanceDef::VTableShim(did) => json!({ - "kind": "VTableShim", // NB nightly-2023-01-22 - case change + "kind": "VTableShim", "def_id": did.to_json(mir), "substs": substs.to_json(mir), }), @@ -268,7 +267,6 @@ impl<'tcx> ToJson<'tcx> for ty::Instance<'tcx> { let self_ty = substs.types().next() .unwrap_or_else(|| panic!("expected self type in substs for {:?}", self)); let preds = match *self_ty.kind() { - // NB nightly-2022-01-23 - is the addition of dynkind here relevant? ty::TyKind::Dynamic(ref preds, _region, _dynkind) => preds, _ => panic!("expected `dyn` self type, but got {:?}", self_ty), }; @@ -425,7 +423,6 @@ impl<'tcx> ToJson<'tcx> for ty::Ty<'tcx> { // tuples, so no additional information is needed. }) } - // NB nightly-2022-01-23 - is the addition of dynkind here relevant? &ty::TyKind::Dynamic(preds, _region, _dynkind) => { let ti = TraitInst::from_dynamic_predicates(mir.state.tcx, preds); let trait_name = trait_inst_id_str(mir.state.tcx, &ti); @@ -475,7 +472,6 @@ impl<'tcx> ToJson<'tcx> for ty::Ty<'tcx> { // TODO json!({"kind": "GeneratorWitness"}) } - // NB nightly-2023-01-22 - is this correct? &ty::TyKind::Alias(ty::AliasKind::Opaque, _) => { // TODO json!({"kind": "Alias"}) @@ -525,7 +521,7 @@ impl<'tcx> ToJson<'tcx> for ty::AliasTy<'tcx> { fn to_json(&self, ms: &mut MirState<'_, 'tcx>) -> serde_json::Value { json!({ "substs": self.substs.to_json(ms), - "def_id": self.def_id.to_json(ms) // NB nightly-2023-01-22 - field name change + "def_id": self.def_id.to_json(ms) }) } } @@ -535,7 +531,6 @@ impl<'tcx> ToJson<'tcx> for ty::AliasTy<'tcx> { impl<'tcx> ToJson<'tcx> for ty::Predicate<'tcx> { fn to_json(&self, ms: &mut MirState<'_, 'tcx>) -> serde_json::Value { match self.kind().skip_binder() { - // NB: nightly-2023-01-23 is this right? ty::PredicateKind::Clause(ty::Clause::Trait(tp)) => { json!({ "trait_pred": tp.trait_ref.to_json(ms) @@ -684,266 +679,7 @@ fn eval_array_len<'tcx>( // } } -fn read_static_memory<'tcx>( - alloc: &'tcx mir::interpret::Allocation, - start: usize, - end: usize, -) -> &'tcx [u8] { - // NB: nightly-2023-01-22 - is this correct? - assert!(alloc.provenance().ptrs().len() == 0); - alloc.inspect_with_uninit_and_ptr_outside_interpreter(start .. end) -} - -fn render_constant_scalar<'tcx>( - mir: &mut MirState<'_, 'tcx>, - ty: ty::Ty<'tcx>, - s: interpret::Scalar, -) -> Option { - match s { - interpret::Scalar::Int(sint) => { - let data = sint.to_bits(sint.size()).unwrap(); - render_constant(mir, ty, Some(s), Some((sint.size().bytes() as u8, data)), None) - // let size = u8::try_from(sint.size().bytes()).unwrap(); - // render_constant(mir, ty, Some(s), Some((size, data)), None) - }, - interpret::Scalar::Ptr(ptr, _) => { - match mir.state.tcx.try_get_global_alloc(ptr.provenance) { - Some(ga) => match ga { - interpret::GlobalAlloc::Static(def_id) => Some(json!({ - "kind": "static_ref", - "def_id": def_id.to_json(mir), - })), - interpret::GlobalAlloc::Memory(alloc) => { - let start = ptr.into_parts().1.bytes() as usize; - render_constant( - mir, - ty, - Some(s), - None, - Some((alloc.inner(), start, start)), - ) - }, - _ => None, - }, - None => None, - } - }, - } -} - -fn render_zst<'tcx>() -> serde_json::Value { - json!({ - "kind": "zst", - }) -} - -// TODO: migrate all constant rendering to use InterpCx + OpTy. This should reduce special cases -// and let us handle both in-memory and immediate constants. -fn render_constant<'tcx>( - mir: &mut MirState<'_, 'tcx>, - ty: ty::Ty<'tcx>, - scalar: Option, - scalar_bits: Option<(u8, u128)>, - slice: Option<(&'tcx mir::interpret::Allocation, usize, usize)>, -) -> Option { - // Special cases: &str and &[u8; _] - if let ty::TyKind::Ref(_, inner_ty, hir::Mutability::Not) = *ty.kind() { - if let ty::TyKind::Str = *inner_ty.kind() { - // String literal - let (alloc, start, end) = slice.expect("string const had non-slice value"); - let mem = read_static_memory(alloc, start, end); - return Some(json!({ - "kind": "str", - "val": mem, - })); - } - - if let ty::TyKind::Array(elem_ty, len_const) = *inner_ty.kind() { - if let ty::TyKind::Uint(ty::UintTy::U8) = *elem_ty.kind() { - // Bytestring literal - let len = eval_array_len(mir.state.tcx, len_const); - let (alloc, start, _) = slice.expect("string const had non-slice value"); - let end = start + len; - let mem = read_static_memory(alloc, start, end); - return Some(json!({ - "kind": "bstr", - "val": mem, - })); - } - } - } - - Some(match *ty.kind() { - ty::TyKind::Int(_) => { - let (size, bits) = scalar_bits.expect("int const had non-scalar value?"); - let mut val = bits as i128; - if bits & (1 << (size * 8 - 1)) != 0 && size < 128 / 8 { - // Sign-extend to 128 bits - val |= -1_i128 << (size * 8); - } - json!({ - "kind": match *ty.kind() { - ty::TyKind::Int(ty::IntTy::Isize) => "isize", - ty::TyKind::Int(_) => "int", - _ => unreachable!(), - }, - "size": size, - "val": val.to_string(), - }) - }, - ty::TyKind::Bool | - ty::TyKind::Char | - ty::TyKind::Uint(_) => { - let (size, bits) = scalar_bits.expect("uint const had non-scalar value?"); - json!({ - "kind": match *ty.kind() { - ty::TyKind::Bool => "bool", - ty::TyKind::Char => "char", - ty::TyKind::Uint(ty::UintTy::Usize) => "usize", - ty::TyKind::Uint(_) => "uint", - _ => unreachable!(), - }, - "size": size, - "val": bits.to_string(), - }) - }, - ty::TyKind::Float(ty::FloatTy::F32) => { - let (size, bits) = scalar_bits.expect("f32 const had non-scalar value?"); - let val = f32::from_bits(bits as u32); - json!({ - "kind": "float", - "size": size, - "val": val.to_string(), - }) - }, - ty::TyKind::Float(ty::FloatTy::F64) => { - let (size, bits) = scalar_bits.expect("f64 const had non-scalar value?"); - let val = f64::from_bits(bits as u64); - json!({ - "kind": "float", - "size": size, - "val": val.to_string(), - }) - }, - - ty::TyKind::RawPtr(_) => { - let (_size, bits) = - match scalar_bits { - Some(s) => s, - None => return None - }; - - json!({ - "kind": "raw_ptr", - "val": bits.to_string(), - }) - }, - - ty::TyKind::FnDef(defid, ref substs) => { - json!({ - "kind": "fndef", - "def_id": get_fn_def_name(mir, defid, substs), - }) - }, - - ty::TyKind::Adt(adt_def, _substs) if adt_def.is_struct() => { - let tyl = mir.state.tcx.layout_of(ty::ParamEnv::reveal_all().and(ty)) - .unwrap_or_else(|e| panic!("failed to get layout of {:?}: {}", ty, e)); - let scalar = scalar.expect("adt had non-scalar value (NYI)"); - let variant = adt_def.non_enum_variant(); - json!({ - "kind": "struct", - "fields": render_constant_variant( - mir, - variant, - interpret::ImmTy::from_scalar(scalar, tyl).into(), - ), - }) - }, - - ty::TyKind::Adt(adt_def, _substs) if adt_def.is_enum() => { - let tyl = mir.state.tcx.layout_of(ty::ParamEnv::reveal_all().and(ty)) - .unwrap_or_else(|e| panic!("failed to get layout of {:?}: {}", ty, e)); - let scalar = scalar.expect("adt had non-scalar value (NYI)"); - - let icx = interpret::InterpCx::new( - mir.state.tcx, - DUMMY_SP, - ty::ParamEnv::reveal_all(), - RenderConstMachine, - ); - let op_ty = interpret::ImmTy::from_scalar(scalar, tyl).into(); - let (_discr, variant_idx) = icx.read_discriminant(&op_ty).unwrap_or_else(|e| { - panic!("failed to access discriminant of {:?}: {}", op_ty.layout.ty, e) - }); - - let variant = &adt_def.variants()[variant_idx]; - json!({ - "kind": "enum", - "variant": variant_idx.as_u32(), - "fields": render_constant_variant( - mir, - variant, - icx.operand_downcast(&op_ty, variant_idx).unwrap_or_else(|e| { - panic!("failed to downcast {:?} to variant {:?}: {}", - op_ty.layout.ty, variant_idx, e) - }), - ), - }) - }, - - _ => { - if let Some((0, _)) = scalar_bits { - render_zst() - } else { - return None; - } - }, - }) -} - -fn render_constant_variant<'tcx>( - mir: &mut MirState<'_, 'tcx>, - variant: &'tcx ty::VariantDef, - op_ty: interpret::OpTy<'tcx>, -) -> Option { - let icx = interpret::InterpCx::new( - mir.state.tcx, - DUMMY_SP, - ty::ParamEnv::reveal_all(), - RenderConstMachine, - ); - let mut vals = Vec::with_capacity(variant.fields.len()); - for i in 0 .. variant.fields.len() { - let field = icx.operand_field(&op_ty, i).unwrap_or_else(|e| { - panic!("failed to access field {} of {:?}: {}", i, op_ty.layout.ty, e) - }); - - // `try_as_mplace` always "succeeds" (returns an `MPlace`, dangling) for ZSTs. We want it - // to be an immediate instead. - if field.layout.is_zst() { - // NB nightly-2022-01-23 : ZST is gone? - // call render_constant directly such that it returns a zst value - vals.push(render_zst()); - continue; - } - - let val = match field.as_mplace_or_imm().into() { - Err(_mpl) => None, - Ok(imm) => - match *imm { - interpret::Immediate::Scalar(s) => - render_constant_scalar(mir, field.layout.ty, s), - _ => None, - } - }?; - vals.push(val); - } - Some(vals.into()) -} - -struct RenderConstMachine; - +use self::machine::RenderConstMachine; mod machine { use std::borrow::Cow; use super::*; @@ -952,8 +688,19 @@ mod machine { use rustc_middle::ty::*; use rustc_target::abi::Size; use rustc_target::spec::abi::Abi; + pub struct RenderConstMachine<'mir, 'tcx> { + stack: Vec>, + } + + impl<'mir, 'tcx> RenderConstMachine<'mir, 'tcx> { + pub fn new() -> RenderConstMachine<'mir, 'tcx> { + RenderConstMachine { + stack: Vec::new() + } + } + } - impl<'mir, 'tcx> Machine<'mir, 'tcx> for RenderConstMachine { + impl<'mir, 'tcx> Machine<'mir, 'tcx> for RenderConstMachine<'mir, 'tcx> { type MemoryKind = !; type Provenance = AllocId; type ProvenanceExtra = (); @@ -1089,7 +836,7 @@ mod machine { ecx: &InterpCx<'mir, 'tcx, Self>, ptr: Pointer, ) -> Pointer { - unimplemented!("tag_alloc_base_pointer") + ptr } fn ptr_from_addr_cast( @@ -1114,7 +861,8 @@ mod machine { ecx: &InterpCx<'mir, 'tcx, Self>, ptr: Pointer, ) -> Option<(AllocId, Size, Self::ProvenanceExtra)> { - None + let (prov, offset) = ptr.into_parts(); + Some((prov, offset, ())) } fn adjust_allocation<'b>( @@ -1140,7 +888,8 @@ mod machine { fn stack<'a>( ecx: &'a InterpCx<'mir, 'tcx, Self>, ) -> &'a [Frame<'mir, 'tcx, Self::Provenance, Self::FrameExtra>] { - unimplemented!("stack") + &ecx.machine.stack + // unimplemented!("stack") } fn stack_mut<'a>( @@ -1160,42 +909,21 @@ impl<'tcx> ToJson<'tcx> for ty::Const<'tcx> { // remove? should probably not show up? ty::ConstKind::Unevaluated(un) => { map.insert("initializer".to_owned(), json!({ - // TODO nightly-2023-01-22 promoted has been removed? - // change `get_promoted_name` to the "get non-promoted name" version - // if we even need this case "def_id": get_fn_def_name(mir, un.def.did, un.substs), })); }, _ => {}, } - // let evaluated = match self.kind() { - // // nightly-2023-01-22 remove? probably should not show up - // ty::ConstKind::Unevaluated(un) => { - // // TODO nightly-2023-01-22 unevaluatedconst changed - // // use `const_eval_resolve_for_typecheck` ? - // mir.state.tcx.const_eval_resolve(ty::ParamEnv::reveal_all(), un, None).unwrap() - // }, - // // TODO nightly-2023-01-22 ConstKind value is now a valtree (assume leaf only?) - // // Remove other cases besides Value(Leaf(x)) - this means we might remove slice below - // // might have to see if we panic - // ty::ConstKind::Value(val) => val, - // _ => panic!("don't know how to translate ConstKind::{:?}", self.kind()), - // }; - - // let rendered = match evaluated { - // interpret::ConstValue::Scalar(s) => { - // render_constant_scalar(mir, self.ty(), s) - // }, - // interpret::ConstValue::Slice { data, start, end } => { - // render_constant(mir, self.ty(), None, None, Some((data.inner(), start, end))) - // }, - // _ => None, - // }; - let rendered = match self.kind() { - ty::ConstKind::Value(ty::ValTree::Leaf(val)) => - render_constant(mir, self.ty(), None, Some((val.size().bytes() as u8, val.try_to_uint(val.size()).unwrap())), None), + ty::ConstKind::Value(ty::ValTree::Leaf(val)) => { + let sz = val.size(); + Some(json!({ + "kind": "usize", + "size": sz.bytes(), + "val": get_const_usize(mir.state.tcx, *self).to_string(), + })) + } _ => panic!("don't know how to translate ConstKind::{:?}", self.kind()) }; if let Some(rendered) = rendered { @@ -1209,20 +937,368 @@ impl<'tcx> ToJson<'tcx> for ty::Const<'tcx> { impl<'tcx> ToJson<'tcx> for (interpret::ConstValue<'tcx>, ty::Ty<'tcx>) { fn to_json(&self, mir: &mut MirState<'_, 'tcx>) -> serde_json::Value { let (val, ty) = *self; - match val { - interpret::ConstValue::Scalar(s) => { - render_constant_scalar(mir, ty, s) - .unwrap_or_else(|| json!({"type": "unknown_scalar"})) - }, - interpret::ConstValue::Slice { data, start, end } => { - render_constant(mir, ty, None, None, Some((data.inner(), start, end))) - .unwrap_or_else(|| json!({"type": "unknown_slice"})) - }, - interpret::ConstValue::ZeroSized => { - render_zst() - }, - interpret::ConstValue::ByRef { .. } => json!({"kind": "unknown_by_ref"}), + let op_ty = as_opty(mir.state.tcx, val, ty); + let mut icx = mk_interp(mir.state.tcx); + json!({ + "ty": ty.to_json(mir), + "rendered": render_opty(mir, &mut icx, &op_ty), + }) + } +} + +pub fn get_const_usize<'tcx>(tcx: ty::TyCtxt<'tcx>, c: ty::Const<'tcx>) -> usize { + match c.kind() { + ty::ConstKind::Value(ty::ValTree::Leaf(val)) => { + let v = val.try_to_machine_usize(tcx).unwrap(); + v as usize } + _ => panic!("don't know how to translate ConstKind::{:?}", c.kind()) + } +} + +// fn eval_op<'tcx>(op_ty: interpret::OpTy<'tcx>) -> interpret::Scalar { +// match *op_ty { +// interpret::Operand::Immediate(imm) => imm.to_scalar(), +// interpret::Operand::Indirect(place) => place., +// } +// } + +pub fn render_opty<'mir, 'tcx>( + mir: &mut MirState<'_, 'tcx>, + icx: &mut interpret::InterpCx<'mir, 'tcx, RenderConstMachine<'mir, 'tcx>>, + op_ty: &interpret::OpTy<'tcx>, +) -> serde_json::Value { + try_render_opty(mir, icx, op_ty).unwrap_or_else(|| { + json!({ + "kind": "unsupported_const", + "debug_val": format!("{:?}", op_ty), + }) + }) +} + +pub fn try_render_opty<'mir, 'tcx>( + mir: &mut MirState<'_, 'tcx>, + icx: &mut interpret::InterpCx<'mir, 'tcx, RenderConstMachine<'mir, 'tcx>>, + op_ty: &interpret::OpTy<'tcx>, +) -> Option { + let ty = op_ty.layout.ty; + let layout = op_ty.layout.layout; + let tcx = mir.state.tcx; + + Some(match *ty.kind() { + ty::TyKind::Bool | + ty::TyKind::Char | + ty::TyKind::Uint(_) => + { + let s = icx.read_immediate(op_ty).unwrap().to_scalar(); + let size = layout.size(); + let bits = s.to_bits(size).unwrap(); + + json!({ + "kind": match *ty.kind() { + ty::TyKind::Bool => "bool", + ty::TyKind::Char => "char", + ty::TyKind::Uint(ty::UintTy::Usize) => "usize", + ty::TyKind::Uint(_) => "uint", + _ => unreachable!(), + }, + "size": size.bytes(), + "val": bits.to_string(), + }) + } + ty::TyKind::Int(i) => { + let s = icx.read_immediate(op_ty).unwrap().to_scalar(); + let size = layout.size(); + let bits = s.to_bits(size).unwrap(); + let mut val = bits as i128; + if bits & (1 << (size.bits() - 1)) != 0 && size.bits() < 128 { + // Sign-extend to 128 bits + val |= -1_i128 << size.bits(); + } + + json!({ + "kind": match *ty.kind() { + ty::TyKind::Int(ty::IntTy::Isize) => "isize", + ty::TyKind::Int(_) => "int", + _ => unreachable!(), + }, + "size": size.bytes(), + "val": val.to_string(), + }) + } + ty::TyKind::Float(fty) => { + let s = icx.read_immediate(op_ty).unwrap().to_scalar(); + let size = layout.size(); + let val_str = match fty { + ty::FloatTy::F32 => s.to_f32().unwrap().to_string(), + ty::FloatTy::F64 => s.to_f64().unwrap().to_string(), + }; + + json!({ + "kind": "float", + "size": size.bytes(), + "val": val_str, + }) + } + ty::TyKind::Adt(adt_def, _substs) if adt_def.is_struct() => { + let variant = adt_def.non_enum_variant(); + let mut field_vals = Vec::new(); + for field_idx in 0..variant.fields.len() { + let field = icx.operand_field(&op_ty, field_idx).unwrap(); + field_vals.push(try_render_opty(mir, icx, &field)?) + } + + let val: serde_json::Value = field_vals.into(); + + json!({ + "kind": "struct", + "fields": val, + }) + }, + ty::TyKind::Adt(adt_def, _substs) if adt_def.is_enum() => { + let (_, variant_idx) = icx.read_discriminant(&op_ty).unwrap(); + let val = icx.operand_downcast(op_ty, variant_idx).unwrap(); + let mut field_vals = Vec::with_capacity(val.layout.fields.count()); + for idx in 0 .. val.layout.fields.count() { + let field_opty = icx.operand_field(&val, idx).unwrap(); + field_vals.push(try_render_opty(mir, icx, &field_opty)?); + } + + json!({ + "kind": "enum", + "variant": variant_idx.as_u32(), + "fields": field_vals, + }) + }, + + ty::TyKind::Adt(_, _) => { + panic!("Adt is not enum or struct!") + }, + + ty::TyKind::Foreign(_) => todo!("foreign is unimplemented"), // can't do this + ty::TyKind::Str => unreachable!("str type should not occur here"), + ty::TyKind::Array(ety, sz) => { + let sz = get_const_usize(tcx, sz); + let mut vals = Vec::with_capacity(sz); + for field in icx.operand_array_fields(op_ty).unwrap() { + let f_json = try_render_opty(mir, icx, &field.unwrap()); + vals.push(f_json); + } + + json!({ + "kind": "array", + "element_ty": ety.to_json(mir), + "elements": vals + }) + + } + ty::TyKind::Slice(slice_ty) => { + eprintln!("slice op_ty: {:?}", op_ty); + let mb_slice_len = op_ty.len(icx); + match mb_slice_len { + Ok(slice_len) => { + let mut elt_values = Vec::with_capacity(slice_len as usize); + for idx in 0..slice_len { + let elt = icx.operand_index(op_ty, idx).unwrap(); + elt_values.push(try_render_opty(mir, icx, &elt)); + } + + json!({ + "kind": "slice", + "element_ty": slice_ty.to_json(mir), + "elements": elt_values + }) + } + Err(err) => { + panic!("Cannot get slice length: {:?}", op_ty) + } + } + } + + // similar to ref in some ways + ty::TyKind::RawPtr(m_ty) => + try_render_ref_opty(mir, icx, op_ty, m_ty.ty, m_ty.mutbl)?, + + ty::TyKind::Ref(_, rty, mutability) => + try_render_ref_opty(mir, icx, op_ty, rty, mutability)?, + + ty::TyKind::FnDef(_, _) => json!({"kind": "zst"}), + ty::TyKind::FnPtr(_sig) => { + let ptr = icx.read_pointer(op_ty).unwrap(); + let (prov, _offset) = ptr.into_parts(); + let alloc = tcx.try_get_global_alloc(prov?)?; + match alloc { + interpret::GlobalAlloc::Function(i) => + json!({ + "kind": "fn_ptr", + "instance": i.to_json(mir), + + }), + _ => unreachable!("Function pointer doesn't point to a function"), + } + } + ty::TyKind::Dynamic(_, _, _) => unreachable!("dynamic should not occur here"), + + ty::TyKind::Closure(_, _) => todo!("closure not supported yet"), // not supported in haskell + ty::TyKind::Generator(_, _, _) => todo!("generator not supported yet"), // not supported in haskell + ty::TyKind::GeneratorWitness(_) => todo!("generatorwitness not supported yet"), // not supported in haskell + ty::TyKind::Never => unreachable!("never type should be uninhabited"), + + ty::TyKind::Tuple(elts) => { + let mut vals = Vec::with_capacity(elts.len()); + for i in 0..elts.len() { + let fld: interpret::OpTy<'tcx> = icx.operand_field(&op_ty, i).unwrap(); + vals.push(render_opty(mir, icx, &fld)); + } + json!({ + "kind": "tuple", + "elements": vals + }) + } + + // should go away during monomorphiszation but could in theory be resolvable to a real type + ty::TyKind::Alias(_, _) => unreachable!("alias should not occur after monomorphization"), + ty::TyKind::Param(_) => unreachable!("param should not occur after monomorphization"), + + ty::TyKind::Bound(_, _) => unreachable!("bound is not a real type?"), + ty::TyKind::Placeholder(_) => unreachable!("placeholder is not a real type?"), + ty::TyKind::Infer(_) => unreachable!("infer is not a real type?"), + ty::TyKind::Error(_) => unreachable!("error is not a real type?"), + }) +} + +fn try_render_ref_opty<'mir, 'tcx>( + mir: &mut MirState<'_, 'tcx>, + icx: &mut interpret::InterpCx<'mir, 'tcx, RenderConstMachine<'mir, 'tcx>>, + op_ty: &interpret::OpTy<'tcx>, + rty: ty::Ty<'tcx>, + mutability: hir::Mutability, +) -> Option { + let tcx = mir.state.tcx; + + // Special case for nullptr + let val = icx.read_immediate(op_ty).unwrap(); + let mplace = icx.ref_to_mplace(&val).unwrap(); + let (prov, offset) = mplace.ptr.into_parts(); + if prov.is_none() { + assert!(!mplace.meta.has_meta(), "not expecting meta for nullptr"); + + return Some(json!({ + "kind": "raw_ptr", + "val": offset.bytes().to_string(), + })); + } + + let d = icx.deref_operand(op_ty).unwrap(); + let is_mut = mutability == hir::Mutability::Mut; + + // Special case for &str + if !is_mut && *rty.kind() == ty::TyKind::Str { + let mem = icx.read_bytes_ptr_strip_provenance(d.ptr, d.layout.size).unwrap(); + return Some(json!({ + "kind": "str", + "val": mem + })) + } + + // Special case for &u8 + if !is_mut { + if let ty::TyKind::Array(elem_ty, _) = *rty.kind() { + if let ty::TyKind::Uint(ty::UintTy::U8) = *elem_ty.kind() { + let mem = icx.read_bytes_ptr_strip_provenance(d.ptr, d.layout.size).unwrap(); + return Some(json!({ + "kind": "bstr", + "val": mem, + })); + } + } + } + + let (prov, _offset) = d.ptr.into_parts(); + let alloc = tcx.try_get_global_alloc(prov?)?; + match alloc { + interpret::GlobalAlloc::Static(def_id) => + return Some(json!({ + "kind": "static_ref", + "def_id": def_id.to_json(mir), + })), + interpret::GlobalAlloc::Memory(ca) => { + let aid = match mir.allocs.get(ca) { + Some(alloc_id) => alloc_id.to_owned(), + None => { + let ma = tcx.create_memory_alloc(ca); + let rlayout = tcx.layout_of(ty::ParamEnv::reveal_all().and(rty)).unwrap(); + let ptr = interpret::Pointer::new(Some(ma), Size::ZERO); + + let mpty = interpret::MPlaceTy::from_aligned_ptr_with_meta(ptr, rlayout, d.meta); + let rendered = try_render_opty(mir, icx, &mpty.into()); + + let static_ref = json!({ + "kind": "constant", + "mutable": false, + "ty": rty.to_json(mir), + "rendered": rendered, + }); + + mir.allocs.insert(ca, static_ref) + } + }; + + return Some(json!({ + "kind": "static_ref", + "def_id": aid, + })); + } + _ => return None + } +} + + +// TODO: move +pub fn mk_interp<'mir, 'tcx>(tcx: TyCtxt<'tcx>) -> interpret::InterpCx<'mir, 'tcx, RenderConstMachine<'mir, 'tcx>> { + interpret::InterpCx::new( + tcx, + DUMMY_SP, + ty::ParamEnv::reveal_all(), + RenderConstMachine::new(), + ) +} + +pub fn as_opty<'tcx>(tcx: TyCtxt<'tcx>, cv: interpret::ConstValue<'tcx>, ty: ty::Ty<'tcx>) + -> interpret::OpTy<'tcx, interpret::AllocId> +{ + use rustc_const_eval::interpret::{Operand, Pointer, MemPlace, ConstValue, Immediate, Scalar, OpTy, ImmTy, MPlaceTy}; + use rustc_target::abi::Size; + let op = match cv { + ConstValue::ByRef { alloc, offset } => { + let id = tcx.create_memory_alloc(alloc); + // We rely on mutability being set correctly in that allocation to prevent writes + // where none should happen. + let ptr = Pointer::new(id, offset); + Operand::Indirect(MemPlace::from_ptr(ptr.into())) + } + ConstValue::Scalar(x) => Operand::Immediate(x.into()), + ConstValue::ZeroSized => Operand::Immediate(Immediate::Uninit), + ConstValue::Slice { data, start, end } => { + // We rely on mutability being set correctly in `data` to prevent writes + // where none should happen. + let ptr = Pointer::new( + tcx.create_memory_alloc(data), + Size::from_bytes(start), // offset: `start` + ); + Operand::Immediate(Immediate::new_slice( + Scalar::from_pointer(ptr, &tcx), + u64::try_from(end.checked_sub(start).unwrap()).unwrap(), // len: `end - start` + &tcx, + )) + } + }; + + let layout = tcx.layout_of(ty::ParamEnv::reveal_all().and(ty)).unwrap(); + + match op { + Operand::Immediate(imm) => ImmTy::from_immediate(imm, layout).into() , + Operand::Indirect(ind) => MPlaceTy::from_aligned_ptr(ind.ptr, layout).into(), } } @@ -1294,10 +1370,22 @@ impl<'tcx> ToJson<'tcx> for AdtInst<'tcx> { let ty = mir.state.tcx.mk_adt(self.adt, self.substs); let tyl = mir.state.tcx.layout_of(ty::ParamEnv::reveal_all().and(ty)) .unwrap_or_else(|e| panic!("failed to get layout of {:?}: {}", ty, e)); + + let variants = + if self.adt.is_enum() { + render_enum_variants(mir, &self) + } else { + self.adt.variants() + .iter() + .map(|v| render_variant(mir, &self, v, &None)) + .collect::>() + .into() + }; + json!({ "name": adt_inst_id_str(mir.state.tcx, *self), "kind": format!("{:?}", self.adt.adt_kind()), - "variants": self.adt.variants().tojson(mir, self.substs), + "variants": variants, "size": tyl.size.bytes(), "repr_transparent": self.adt.repr().transparent(), "orig_def_id": self.adt.did().to_json(mir), @@ -1306,19 +1394,39 @@ impl<'tcx> ToJson<'tcx> for AdtInst<'tcx> { } } -impl ToJsonAg for ty::VariantDef { - fn tojson<'tcx>( - &self, - mir: &mut MirState<'_, 'tcx>, - substs: ty::subst::SubstsRef<'tcx>, - ) -> serde_json::Value { - json!({ - "name": self.def_id.to_json(mir), - "discr": self.discr.to_json(mir), - "fields": self.fields.tojson(mir, substs), - "ctor_kind": self.ctor_kind().to_json(mir) - }) +fn render_enum_variants<'tcx>( + mir: &mut MirState<'_, 'tcx>, + adt: &AdtInst<'tcx>, +) -> serde_json::Value { + let mut variants = Vec::with_capacity(adt.adt.variants().len()); + for (idx, d_value) in adt.adt.discriminants(mir.state.tcx) { + let v = adt.adt.variant(idx); + let rendered = render_variant(mir, adt, v, &Some(d_value.to_string())); + variants.push(rendered); } + + variants.into() +} + +fn render_variant<'tcx>( + mir: &mut MirState<'_, 'tcx>, + adt: &AdtInst<'tcx>, + v: &ty::VariantDef, + mb_discr: &Option +) -> serde_json::Value { + let tcx = mir.state.tcx; + let inhabited = v.inhabited_predicate(tcx, adt.adt) + .subst(tcx, adt.substs) + .apply_ignore_module(tcx, ty::ParamEnv::reveal_all()); + + json!({ + "name": v.def_id.to_json(mir), + "discr": v.discr.to_json(mir), + "fields": v.fields.tojson(mir, adt.substs), + "ctor_kind": v.ctor_kind().to_json(mir), + "discr_value": mb_discr, + "inhabited": inhabited, + }) } impl ToJsonAg for ty::FieldDef { @@ -1355,6 +1463,15 @@ pub fn handle_adt_ag<'tcx>( } } +pub fn eval_mir_constant2<'mir, 'tcx>( + icx: &InterpCx<'mir, 'tcx, RenderConstMachine<'mir, 'tcx>>, + tcx: ty::TyCtxt<'tcx>, + constant: &mir::Constant<'tcx>, +) -> interpret::OpTy<'tcx> { + let layout = tcx.layout_of(ty::ParamEnv::reveal_all().and(constant.ty())).unwrap(); + icx.eval_mir_constant(&constant.literal, Some(constant.span), Some(layout)).unwrap() +} + pub fn eval_mir_constant<'tcx>( tcx: TyCtxt<'tcx>, constant: &mir::Constant<'tcx>, From 5d697d5f37e8a041c7010e47776b6cb02be940d9 Mon Sep 17 00:00:00 2001 From: James LaMar Date: Thu, 16 Mar 2023 12:55:00 -0700 Subject: [PATCH 18/35] Update verison numbers in readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6e3471d..973f31c 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,9 @@ book](https://doc.rust-lang.org/book/2018-edition/ch01-01-installation.html)). 2. Next, install a version of `rustc` that works with mir-json. - $ rustup toolchain install nightly-2020-03-22 --force - $ rustup component add --toolchain nightly-2020-03-22 rustc-dev - $ rustup default nightly-2020-03-22 + $ rustup toolchain install nightly-2023-01-23 --force + $ rustup component add --toolchain nightly-2023-01-23 rustc-dev + $ rustup default nightly-2023-01-23 From 64c0fc7635347d796736c35b0c8ce3eec6ab4e3e Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Tue, 4 Apr 2023 16:00:41 -0400 Subject: [PATCH 19/35] Work around #36 for static allocations --- src/analyz/to_json.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/analyz/to_json.rs b/src/analyz/to_json.rs index dd44608..5f2f464 100644 --- a/src/analyz/to_json.rs +++ b/src/analyz/to_json.rs @@ -282,7 +282,10 @@ impl<'tcx> AllocIntern<'tcx> { } pub fn insert(&mut self, alloc: interpret::ConstAllocation<'tcx>, mut static_def: serde_json::Value) -> String { - let id = format!("alloc${}", self.map.len()); + // NB: The use of :: in "alloc::${}" is important, as mir-json's dead + // code elimination relies on it. + // See https://github.com/GaloisInc/mir-json/issues/36. + let id = format!("alloc::${}", self.map.len()); static_def["name"] = id.clone().into(); self.new_vals.push(static_def); let old = self.map.insert(alloc, id.clone()); From f9b4e2799a5108cdd8f430075b491dad7a5c9097 Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Wed, 26 Apr 2023 14:54:47 -0400 Subject: [PATCH 20/35] Disambiguate static allocation names Without the disambiguation, allocations from different crates can clash, leading to inexplicable errors. --- src/analyz/to_json.rs | 11 +++++++---- src/analyz/ty_json.rs | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/analyz/to_json.rs b/src/analyz/to_json.rs index 5f2f464..7429ae9 100644 --- a/src/analyz/to_json.rs +++ b/src/analyz/to_json.rs @@ -1,4 +1,4 @@ -use rustc_hir::def_id::DefId; +use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_middle::mir::{Body, interpret}; use rustc_middle::ty::{self, TyCtxt, DynKind}; use rustc_session::Session; @@ -281,11 +281,14 @@ impl<'tcx> AllocIntern<'tcx> { self.map.get(&alloc).map(|x| x as &str) } - pub fn insert(&mut self, alloc: interpret::ConstAllocation<'tcx>, mut static_def: serde_json::Value) -> String { - // NB: The use of :: in "alloc::${}" is important, as mir-json's dead + pub fn insert(&mut self, tcx: TyCtxt<'tcx>, + alloc: interpret::ConstAllocation<'tcx>, mut static_def: serde_json::Value) -> String { + let crate_name = tcx.crate_name(LOCAL_CRATE); + let disambig = tcx.crate_hash(LOCAL_CRATE); + // NB: The use of :: here is important, as mir-json's dead // code elimination relies on it. // See https://github.com/GaloisInc/mir-json/issues/36. - let id = format!("alloc::${}", self.map.len()); + let id = format!("{}/{}::{{{{alloc}}}}[{}]", crate_name, disambig, self.map.len()); static_def["name"] = id.clone().into(); self.new_vals.push(static_def); let old = self.map.insert(alloc, id.clone()); diff --git a/src/analyz/ty_json.rs b/src/analyz/ty_json.rs index 4f0d503..73199a1 100644 --- a/src/analyz/ty_json.rs +++ b/src/analyz/ty_json.rs @@ -1240,7 +1240,7 @@ fn try_render_ref_opty<'mir, 'tcx>( "rendered": rendered, }); - mir.allocs.insert(ca, static_ref) + mir.allocs.insert(tcx, ca, static_ref) } }; @@ -1508,4 +1508,4 @@ pub fn eval_mir_constant<'tcx>( // } // err // }).unwrap() -} \ No newline at end of file +} From 1d0f2f55e5d7788c5bb59fb9cf1433da1a46a37a Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Mon, 1 May 2023 10:40:00 -0400 Subject: [PATCH 21/35] mir-json-callgraph: Remove ty:: hack This hack is responsible for `mir-json-callgraph`'s results excluding some important information. It is unclear why this hack was necessary in the first place, so let's just remove it. --- src/bin/mir-json-callgraph.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/bin/mir-json-callgraph.rs b/src/bin/mir-json-callgraph.rs index 3dd3daa..5014ce2 100644 --- a/src/bin/mir-json-callgraph.rs +++ b/src/bin/mir-json-callgraph.rs @@ -29,11 +29,6 @@ fn main() { if a == b { continue; } - // Don't trace outgoing edges from `ty` nodes to non-`ty` nodes. We still keep the - // incoming edges, so it's possible to trace back all uses of a particular type. - if it.name(a).starts_with("ty::") && !it.name(b).starts_with("ty::") { - continue; - } map.entry(b).or_insert_with(HashSet::new).insert(a); } From 4a1ff30120b5d8e10c104211e9e8233c6357f926 Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Wed, 10 May 2023 13:55:00 -0400 Subject: [PATCH 22/35] Encode enum discriminant types --- src/analyz/mod.rs | 9 ++++++++- src/analyz/ty_json.rs | 19 +++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/analyz/mod.rs b/src/analyz/mod.rs index ef9982a..9725b2e 100644 --- a/src/analyz/mod.rs +++ b/src/analyz/mod.rs @@ -214,7 +214,14 @@ impl<'tcx> ToJson<'tcx> for mir::Rvalue<'tcx> { }) } &mir::Rvalue::Discriminant(ref lv) => { - json!({"kind": "Discriminant", "val": lv.to_json(mir)}) + json!({ + "kind": "Discriminant", + "val": lv.to_json(mir), + "ty": lv.ty(mir.mir.unwrap(), mir.state.tcx) + .ty + .discriminant_ty(mir.state.tcx) + .to_json(mir), + }) } &mir::Rvalue::Aggregate(ref ak, ref opv) => { if ty_json::is_adt_ak(ak) { diff --git a/src/analyz/ty_json.rs b/src/analyz/ty_json.rs index ee4826d..9ce85fa 100644 --- a/src/analyz/ty_json.rs +++ b/src/analyz/ty_json.rs @@ -7,7 +7,8 @@ use rustc_middle::mir; use rustc_const_eval::interpret::{self, InterpCx}; use rustc_const_eval::const_eval::CheckAlignment; use rustc_middle::ty; -use rustc_middle::ty::{TyCtxt, TypeFoldable, TypeVisitable}; +use rustc_middle::ty::{AdtKind, TyCtxt, TypeFoldable, TypeVisitable}; +use rustc_middle::ty::util::{IntTypeExt}; use rustc_query_system::ich::StableHashingContext; use rustc_target::spec::abi; use rustc_target::abi::{Align, Size}; @@ -1371,6 +1372,20 @@ impl<'tcx> ToJson<'tcx> for AdtInst<'tcx> { let tyl = mir.state.tcx.layout_of(ty::ParamEnv::reveal_all().and(ty)) .unwrap_or_else(|e| panic!("failed to get layout of {:?}: {}", ty, e)); + let kind = match self.adt.adt_kind() { + AdtKind::Struct => json!({"kind": "Struct"}), + AdtKind::Enum => + json!({ + "kind": "Enum", + "discr_ty": self.adt + .repr() + .discr_type() + .to_ty(mir.state.tcx) + .to_json(mir) + }), + AdtKind::Union => json!({"kind": "Union"}), + }; + let variants = if self.adt.is_enum() { render_enum_variants(mir, &self) @@ -1384,7 +1399,7 @@ impl<'tcx> ToJson<'tcx> for AdtInst<'tcx> { json!({ "name": adt_inst_id_str(mir.state.tcx, *self), - "kind": format!("{:?}", self.adt.adt_kind()), + "kind": kind, "variants": variants, "size": tyl.size.bytes(), "repr_transparent": self.adt.repr().transparent(), From 1b84d7113d3f2116e91ee8a9af3a00dc5a171c30 Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Wed, 17 May 2023 11:26:27 -0400 Subject: [PATCH 23/35] Compute lengths of &str constants properly `&str` is an unsized type, and the `Layout` for an unsized type has a `size` of `0`, which isn't what we want. As far as I can tell, the proper way to compute the size of an unsized type is to use `MPlaceTy`'s `len` function, which sadly isn't exported. I have copied it here and used it. --- src/analyz/ty_json.rs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/analyz/ty_json.rs b/src/analyz/ty_json.rs index 9ce85fa..d38c33f 100644 --- a/src/analyz/ty_json.rs +++ b/src/analyz/ty_json.rs @@ -4,14 +4,15 @@ use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_index::vec::{IndexVec, Idx}; use rustc_middle::mir; -use rustc_const_eval::interpret::{self, InterpCx}; +use rustc_const_eval::interpret::{self, InterpCx, InterpResult, MPlaceTy, Provenance}; use rustc_const_eval::const_eval::CheckAlignment; +use rustc_middle::bug; use rustc_middle::ty; use rustc_middle::ty::{AdtKind, TyCtxt, TypeFoldable, TypeVisitable}; use rustc_middle::ty::util::{IntTypeExt}; use rustc_query_system::ich::StableHashingContext; use rustc_target::spec::abi; -use rustc_target::abi::{Align, Size}; +use rustc_target::abi::{Align, FieldsShape, HasDataLayout, Size}; use rustc_span::DUMMY_SP; use serde_json; use std::fmt::Write as FmtWrite; @@ -1195,7 +1196,8 @@ fn try_render_ref_opty<'mir, 'tcx>( // Special case for &str if !is_mut && *rty.kind() == ty::TyKind::Str { - let mem = icx.read_bytes_ptr_strip_provenance(d.ptr, d.layout.size).unwrap(); + let len = mplace_ty_len(&d, icx).unwrap(); + let mem = icx.read_bytes_ptr_strip_provenance(d.ptr, Size::from_bytes(len)).unwrap(); return Some(json!({ "kind": "str", "val": mem @@ -1254,6 +1256,25 @@ fn try_render_ref_opty<'mir, 'tcx>( } } +// A copied version of MPlaceTy::len, which (sadly) isn't exported. See +// https://github.com/rust-lang/rust/blob/56ee85274e5a3a4dda92f3bf73d1664c74ff9c15/compiler/rustc_const_eval/src/interpret/place.rs#L227C5-L243 +#[inline] +pub fn mplace_ty_len<'tcx, Tag: Provenance>(mplace_ty: &MPlaceTy<'tcx, Tag>, cx: &impl HasDataLayout) -> InterpResult<'tcx, u64> { + if mplace_ty.layout.is_unsized() { + // We need to consult `meta` metadata + match mplace_ty.layout.ty.kind() { + ty::Slice(..) | ty::Str => mplace_ty.meta.unwrap_meta().to_machine_usize(cx), + _ => bug!("len not supported on unsized type {:?}", mplace_ty.layout.ty), + } + } else { + // Go through the layout. There are lots of types that support a length, + // e.g., SIMD types. (But not all repr(simd) types even have FieldsShape::Array!) + match mplace_ty.layout.fields { + FieldsShape::Array { count, .. } => Ok(count), + _ => bug!("len not supported on sized type {:?}", mplace_ty.layout.ty), + } + } +} // TODO: move pub fn mk_interp<'mir, 'tcx>(tcx: TyCtxt<'tcx>) -> interpret::InterpCx<'mir, 'tcx, RenderConstMachine<'mir, 'tcx>> { From 819fa0392d36bf49bed7eff52acd3d9bc4c5b515 Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Tue, 16 May 2023 16:26:59 -0400 Subject: [PATCH 24/35] Special-case &[T] rendering --- src/analyz/ty_json.rs | 79 +++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 40 deletions(-) diff --git a/src/analyz/ty_json.rs b/src/analyz/ty_json.rs index d38c33f..e1327e4 100644 --- a/src/analyz/ty_json.rs +++ b/src/analyz/ty_json.rs @@ -1094,28 +1094,7 @@ pub fn try_render_opty<'mir, 'tcx>( }) } - ty::TyKind::Slice(slice_ty) => { - eprintln!("slice op_ty: {:?}", op_ty); - let mb_slice_len = op_ty.len(icx); - match mb_slice_len { - Ok(slice_len) => { - let mut elt_values = Vec::with_capacity(slice_len as usize); - for idx in 0..slice_len { - let elt = icx.operand_index(op_ty, idx).unwrap(); - elt_values.push(try_render_opty(mir, icx, &elt)); - } - - json!({ - "kind": "slice", - "element_ty": slice_ty.to_json(mir), - "elements": elt_values - }) - } - Err(err) => { - panic!("Cannot get slice length: {:?}", op_ty) - } - } - } + ty::TyKind::Slice(_) => unreachable!("slice type should not occur here"), // similar to ref in some ways ty::TyKind::RawPtr(m_ty) => @@ -1194,26 +1173,46 @@ fn try_render_ref_opty<'mir, 'tcx>( let d = icx.deref_operand(op_ty).unwrap(); let is_mut = mutability == hir::Mutability::Mut; - // Special case for &str - if !is_mut && *rty.kind() == ty::TyKind::Str { - let len = mplace_ty_len(&d, icx).unwrap(); - let mem = icx.read_bytes_ptr_strip_provenance(d.ptr, Size::from_bytes(len)).unwrap(); - return Some(json!({ - "kind": "str", - "val": mem - })) - } - - // Special case for &u8 if !is_mut { - if let ty::TyKind::Array(elem_ty, _) = *rty.kind() { - if let ty::TyKind::Uint(ty::UintTy::U8) = *elem_ty.kind() { - let mem = icx.read_bytes_ptr_strip_provenance(d.ptr, d.layout.size).unwrap(); + match *rty.kind() { + // Special case for &str + ty::TyKind::Str => { + let len = mplace_ty_len(&d, icx).unwrap(); + let mem = icx.read_bytes_ptr_strip_provenance(d.ptr, Size::from_bytes(len)).unwrap(); return Some(json!({ - "kind": "bstr", - "val": mem, - })); - } + "kind": "str", + "val": mem + })) + }, + // Special case for &u8 + ty::TyKind::Array(elem_ty, _) => { + if let ty::TyKind::Uint(ty::UintTy::U8) = *elem_ty.kind() { + let mem = icx.read_bytes_ptr_strip_provenance(d.ptr, d.layout.size).unwrap(); + return Some(json!({ + "kind": "bstr", + "val": mem, + })) + } else { + () + } + }, + // Special case for &[T] + ty::TyKind::Slice(slice_ty) => { + eprintln!("slice op_ty: {:?}", op_ty); + let slice_len = mplace_ty_len(&d, icx).unwrap(); + let mut elt_values = Vec::with_capacity(slice_len as usize); + for idx in 0..slice_len { + let elt = icx.operand_index(&d.into(), idx).unwrap(); + elt_values.push(try_render_opty(mir, icx, &elt)); + } + + return Some(json!({ + "kind": "slice", + "element_ty": slice_ty.to_json(mir), + "elements": elt_values + })) + }, + _ => () } } From 0e988288342da6320a2e38ea31e7b42020dd3caf Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Wed, 24 May 2023 16:06:55 -0400 Subject: [PATCH 25/35] Render closure constants --- src/analyz/ty_json.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/analyz/ty_json.rs b/src/analyz/ty_json.rs index e1327e4..658ad12 100644 --- a/src/analyz/ty_json.rs +++ b/src/analyz/ty_json.rs @@ -1120,7 +1120,19 @@ pub fn try_render_opty<'mir, 'tcx>( } ty::TyKind::Dynamic(_, _, _) => unreachable!("dynamic should not occur here"), - ty::TyKind::Closure(_, _) => todo!("closure not supported yet"), // not supported in haskell + ty::TyKind::Closure(_defid, substs) => { + let upvars_count = substs.as_closure().upvar_tys().count(); + let mut upvar_vals = Vec::with_capacity(upvars_count); + for idx in 0 .. upvars_count { + let upvar_opty = icx.operand_field(&op_ty, idx).unwrap(); + upvar_vals.push(try_render_opty(mir, icx, &upvar_opty)?); + } + + json!({ + "kind": "closure", + "upvars": upvar_vals, + }) + } ty::TyKind::Generator(_, _, _) => todo!("generator not supported yet"), // not supported in haskell ty::TyKind::GeneratorWitness(_) => todo!("generatorwitness not supported yet"), // not supported in haskell ty::TyKind::Never => unreachable!("never type should be uninhabited"), From 3b0f12244ef993e108f348bdbd3e1829543fc7a1 Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Thu, 25 May 2023 12:25:29 -0400 Subject: [PATCH 26/35] Emit function instances for FnPtrs --- src/analyz/ty_json.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/analyz/ty_json.rs b/src/analyz/ty_json.rs index 658ad12..cc568f6 100644 --- a/src/analyz/ty_json.rs +++ b/src/analyz/ty_json.rs @@ -1109,12 +1109,14 @@ pub fn try_render_opty<'mir, 'tcx>( let (prov, _offset) = ptr.into_parts(); let alloc = tcx.try_get_global_alloc(prov?)?; match alloc { - interpret::GlobalAlloc::Function(i) => + interpret::GlobalAlloc::Function(i) => { + mir.used.instances.insert(i); json!({ "kind": "fn_ptr", "instance": i.to_json(mir), - }), + }) + }, _ => unreachable!("Function pointer doesn't point to a function"), } } From 861d52a74048e93edd139b48ffe576adbf516218 Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Thu, 1 Jun 2023 15:53:05 -0400 Subject: [PATCH 27/35] Include types for ThreadLocalRefs --- src/analyz/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/analyz/mod.rs b/src/analyz/mod.rs index 9725b2e..6bb1b87 100644 --- a/src/analyz/mod.rs +++ b/src/analyz/mod.rs @@ -152,7 +152,8 @@ impl<'tcx> ToJson<'tcx> for mir::Rvalue<'tcx> { &mir::Rvalue::ThreadLocalRef(did) => { json!({ "kind": "ThreadLocalRef", - "def_id": did.to_json(mir) + "def_id": did.to_json(mir), + "ty": mir.state.tcx.static_ptr_ty(did).to_json(mir), }) } &mir::Rvalue::AddressOf(mutbl, ref l) => { From a65ab670394e90feb84650f82868a7bbdaed71c8 Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Fri, 2 Jun 2023 13:12:48 -0400 Subject: [PATCH 28/35] Key AllocIntern's map by Tys as well as ConstAllocations --- src/analyz/to_json.rs | 15 ++++++++++----- src/analyz/ty_json.rs | 5 +++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/analyz/to_json.rs b/src/analyz/to_json.rs index 1a2e539..3cea0ee 100644 --- a/src/analyz/to_json.rs +++ b/src/analyz/to_json.rs @@ -286,17 +286,22 @@ impl Default for ExportStyle { #[derive(Default, Debug)] pub struct AllocIntern<'tcx> { - map: HashMap, String>, + /// We key this map on both ConstAllocations and their Tys. Keying the map + /// on ConstAllocations alone is not sufficient, as two ConstAllocations + /// with different types can share the same underlying memory representation + /// (e.g., `0: u8` and `Ok(()) : Result<(), ()>`). + map: HashMap<(interpret::ConstAllocation<'tcx>, ty::Ty<'tcx>), String>, new_vals: Vec, } impl<'tcx> AllocIntern<'tcx> { - pub fn get(&self, alloc: interpret::ConstAllocation<'tcx>) -> Option<&str> { - self.map.get(&alloc).map(|x| x as &str) + pub fn get(&self, alloc: interpret::ConstAllocation<'tcx>, ty: ty::Ty<'tcx>) -> Option<&str> { + self.map.get(&(alloc, ty)).map(|x| x as &str) } pub fn insert(&mut self, tcx: TyCtxt<'tcx>, - alloc: interpret::ConstAllocation<'tcx>, mut static_def: serde_json::Value) -> String { + alloc: interpret::ConstAllocation<'tcx>, ty: ty::Ty<'tcx>, + mut static_def: serde_json::Value) -> String { let crate_name = tcx.crate_name(LOCAL_CRATE); let disambig = tcx.crate_hash(LOCAL_CRATE); // NB: The use of :: here is important, as mir-json's dead @@ -305,7 +310,7 @@ impl<'tcx> AllocIntern<'tcx> { let id = format!("{}/{}::{{{{alloc}}}}[{}]", crate_name, disambig, self.map.len()); static_def["name"] = id.clone().into(); self.new_vals.push(static_def); - let old = self.map.insert(alloc, id.clone()); + let old = self.map.insert((alloc, ty), id.clone()); assert!(old.is_none(), "duplicate insert for type {:?}", alloc); id } diff --git a/src/analyz/ty_json.rs b/src/analyz/ty_json.rs index cc568f6..3629ba8 100644 --- a/src/analyz/ty_json.rs +++ b/src/analyz/ty_json.rs @@ -1239,7 +1239,8 @@ fn try_render_ref_opty<'mir, 'tcx>( "def_id": def_id.to_json(mir), })), interpret::GlobalAlloc::Memory(ca) => { - let aid = match mir.allocs.get(ca) { + let ty = op_ty.layout.ty; + let aid = match mir.allocs.get(ca, ty) { Some(alloc_id) => alloc_id.to_owned(), None => { let ma = tcx.create_memory_alloc(ca); @@ -1256,7 +1257,7 @@ fn try_render_ref_opty<'mir, 'tcx>( "rendered": rendered, }); - mir.allocs.insert(tcx, ca, static_ref) + mir.allocs.insert(tcx, ca, ty, static_ref) } }; From a1c27347ee721031828699d5da735f63db6a9c07 Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Thu, 29 Jun 2023 15:25:06 -0400 Subject: [PATCH 29/35] mir-json-rustc-wrapper: Emit --sysroot argument --- src/bin/mir-json-rustc-wrapper.rs | 35 ++++++++++++++++--------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/bin/mir-json-rustc-wrapper.rs b/src/bin/mir-json-rustc-wrapper.rs index cde5911..4cd92b9 100644 --- a/src/bin/mir-json-rustc-wrapper.rs +++ b/src/bin/mir-json-rustc-wrapper.rs @@ -24,7 +24,8 @@ use rustc_interface::Queries; use rustc_session::config::ExternLocation; use std::collections::HashSet; use std::env; -use std::fs::{File, OpenOptions}; +use std::ffi::OsStr; +use std::fs::{File, OpenOptions, read_dir}; use std::io::{self, Write}; use std::iter; use std::os::unix::fs::OpenOptionsExt; @@ -48,34 +49,31 @@ impl rustc_driver::Callbacks for GetOutputPathCallbacks { fn after_parsing<'tcx>( &mut self, - _compiler: &Compiler, + compiler: &Compiler, queries: &'tcx Queries<'tcx>, ) -> Compilation { // This phase runs with `--cfg crux`, so some `#[crux_test]` attrs may be visible. Even // the limited amount of compilation we do will fail without the injected `register_attr`. analyz::inject_attrs(queries); - Compilation::Continue - } - fn after_analysis<'tcx>( - &mut self, - compiler: &Compiler, - queries: &'tcx Queries<'tcx>, - ) -> Compilation { let sess = compiler.session(); - // rustc_session::find_crate_name - get the crate with queries.expansion? - let krate = queries.parse().unwrap(); - let krate = krate.borrow(); - let crate_name = rustc_session::output::find_crate_name(&sess, &krate.attrs); - // get global ctxt then call methods inside of enter() to get - let outputs = compiler.build_output_filenames(&sess, &krate.attrs); //queries.prepare_outputs().unwrap().peek(); + let (crate_name, outputs) = { + // rustc_session::find_crate_name - get the crate with queries.expansion? + let krate = queries.parse().unwrap(); + let krate = krate.borrow(); + let crate_name = rustc_session::output::find_crate_name(&sess, &krate.attrs); + // get global ctxt then call methods inside of enter() to get + let outputs = compiler.build_output_filenames(&sess, &krate.attrs); //queries.prepare_outputs().unwrap().peek(); + (crate_name, outputs) + }; + // Advance the state slightly further, initializing crate_types() + queries.register_plugins(); self.output_path = Some(rustc_session::output::out_filename( sess, sess.crate_types().first().unwrap().clone(), &outputs, crate_name, )); - let ctx = queries.global_ctxt().unwrap(); Compilation::Stop } } @@ -186,7 +184,10 @@ fn go() { if let Ok(s) = env::var("CRUX_RUST_LIBRARY_PATH") { args.push("-L".into()); - args.push(s); + args.push(s.clone()); + + args.push("--sysroot".into()); + args.push(s.clone()); } let mut use_override_crates = HashSet::new(); From fe2f2bad6b08dda25ae18ff6fdf9d03ef190669e Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Thu, 29 Jun 2023 15:31:46 -0400 Subject: [PATCH 30/35] Don't emit #[test] attribute for AnonConsts `AnonConst`s are like `Fn`s in that they have `DefId`s and MIR boies, but they aren't actual functions. As such, we don't want to emit `#[test]` for `AnonConst`s. Fixes #47. --- src/analyz/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/analyz/mod.rs b/src/analyz/mod.rs index 6bb1b87..22d869e 100644 --- a/src/analyz/mod.rs +++ b/src/analyz/mod.rs @@ -808,7 +808,7 @@ fn init_instances_from_tests(ms: &mut MirState, out: &mut impl JsonOutput) -> io continue; } - if tcx.def_kind(def_id) != DefKind::Fn { + if !([DefKind::Fn, DefKind::AnonConst].contains(&tcx.def_kind(def_id))) { tcx.sess.span_err( tcx.def_span(def_id), "#[test] can only be applied to functions", From 9f1997edb6e25353d741f1ca0872c48111ec3f5a Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Fri, 7 Jul 2023 15:48:07 -0400 Subject: [PATCH 31/35] Docs: use crux::test instead of crux_test --- doc/rustc.md | 4 ++-- src/analyz/to_json.rs | 2 +- src/bin/cargo-crux-test.rs | 2 +- src/bin/mir-json-dce.rs | 2 +- src/bin/mir-json-rustc-wrapper.rs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/rustc.md b/doc/rustc.md index d1c93ec..863cdf9 100644 --- a/doc/rustc.md +++ b/doc/rustc.md @@ -72,7 +72,7 @@ internal environment variables, which most users will not need to care about: overrides should be used. * `EXPORT_ALL`: If this environment variable is set, then the MIR JSON file will export all top-level functions. Otherwise, it will only export those - functions with a `#[crux_test]` attribute. + functions with a `#[crux::test]` attribute. ## Other binaries @@ -125,7 +125,7 @@ in the following ways: representation required by the `crux-mir` backend. * Miscellaneous: `has_attr` for identifying symbolic tests (marked with the - `#[crux_test]` attribute); `all_crate_nums` and related queries to identify + `#[crux::test]` attribute); `all_crate_nums` and related queries to identify dependencies; `output_filenames` to get the path of the normal `rustc` output (`mir-json` stores the `.mir` files it generates alongside the normal `.rlib` library output). diff --git a/src/analyz/to_json.rs b/src/analyz/to_json.rs index 3cea0ee..e5ceb61 100644 --- a/src/analyz/to_json.rs +++ b/src/analyz/to_json.rs @@ -272,7 +272,7 @@ impl<'tcx> TyIntern<'tcx> { /// How many functions should be exported in the JSON output? #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] pub enum ExportStyle { - /// Only export functions annotated with the `#[crux_test]` attribute. + /// Only export functions annotated with the `#[crux::test]` attribute. ExportCruxTests, /// Export all functions. ExportAll diff --git a/src/bin/cargo-crux-test.rs b/src/bin/cargo-crux-test.rs index ecbcb67..49fb7f6 100644 --- a/src/bin/cargo-crux-test.rs +++ b/src/bin/cargo-crux-test.rs @@ -1,6 +1,6 @@ //! `cargo crux-test`: Run symbolic tests of the current crate. //! -//! Symbolic tests are identified by the `#[crux_test]` attribute, analogous to the `#[test]` +//! Symbolic tests are identified by the `#[crux::test]` attribute, analogous to the `#[test]` //! attribute used with `cargo test`. Symbolic tests often need to use the `crucible` crate, which //! is unavailable when building normally, and thus should be conditionally compiled using //! `#[cfg(crux)]`. diff --git a/src/bin/mir-json-dce.rs b/src/bin/mir-json-dce.rs index 06deeab..3deafd3 100644 --- a/src/bin/mir-json-dce.rs +++ b/src/bin/mir-json-dce.rs @@ -1,7 +1,7 @@ //! Crude dead code elimination for .mir JSON files. //! //! This program takes in several .mir files, combines them, then runs dead code elimination with -//! `#[crux_test]`s as the roots. This is useful because library .mir files contain entries for +//! `#[crux::test]`s as the roots. This is useful because library .mir files contain entries for //! all "reachable non-generic" items in the library crate, but some of those items are not //! actually used by the top-level crate. We run this pass on the raw JSON in hopes of removing //! constructs that `crucible-mir` can't yet parse. diff --git a/src/bin/mir-json-rustc-wrapper.rs b/src/bin/mir-json-rustc-wrapper.rs index 40b6ea9..20cbee3 100644 --- a/src/bin/mir-json-rustc-wrapper.rs +++ b/src/bin/mir-json-rustc-wrapper.rs @@ -52,7 +52,7 @@ impl rustc_driver::Callbacks for GetOutputPathCallbacks { compiler: &Compiler, queries: &'tcx Queries<'tcx>, ) -> Compilation { - // This phase runs with `--cfg crux`, so some `#[crux_test]` attrs may be visible. Even + // This phase runs with `--cfg crux`, so some `#[crux::test]` attrs may be visible. Even // the limited amount of compilation we do will fail without the injected `register_attr`. analyz::inject_attrs(queries); From 1adc931868c1856ead95dfc8ffc86ab722fb545d Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Thu, 13 Jul 2023 12:10:25 -0400 Subject: [PATCH 32/35] Apply suggestions from code review Co-authored-by: spernsteiner --- src/analyz/mod.rs | 28 +++----------------- src/analyz/to_json.rs | 2 +- src/analyz/ty_json.rs | 44 +++---------------------------- src/bin/mir-json-rustc-wrapper.rs | 3 +-- 4 files changed, 8 insertions(+), 69 deletions(-) diff --git a/src/analyz/mod.rs b/src/analyz/mod.rs index 22d869e..dbaef1d 100644 --- a/src/analyz/mod.rs +++ b/src/analyz/mod.rs @@ -737,9 +737,9 @@ fn has_test_attr(tcx: TyCtxt, def_id: DefId) -> bool { return false; } + let crux = Symbol::intern("crux"); + let test = Symbol::intern("test"); for attr in tcx.get_attrs_unchecked(def_id) { - let crux = Symbol::intern("crux"); - let test = Symbol::intern("test"); match &attr.kind { rustc_ast::AttrKind::Normal(na) => { let segs = &na.item.path.segments; @@ -751,24 +751,6 @@ fn has_test_attr(tcx: TyCtxt, def_id: DefId) -> bool { } } return false; - - // let mut file = - // std::fs::OpenOptions::new() - // .create(true) - // .append(true) - // .open("/tmp/attrs") - // .unwrap(); - - - // writeln!(file, "has crux::test attr:{}", tcx.has_attr(def_id, Symbol::intern("crux::test"))).unwrap(); - // for a in attrs { - // writeln!(file, "attr: {:?}", a).unwrap(); - // } - // file.flush().unwrap(); - - // for - - // def_id.is_local() && tcx.has_attr(def_id, Symbol::intern("crux::test")) } /// Process the initial/root instances in the current crate. This adds entries to `ms.used`, and @@ -1231,7 +1213,7 @@ fn make_attr(key: &str, value: &str) -> ast::Attribute { } pub fn inject_attrs<'tcx>(queries: &'tcx Queries<'tcx>) { - let mut k = queries.parse().unwrap(); // need to call `get_mut`? + let mut k = queries.parse().unwrap(); let krate: &mut Crate = k.get_mut(); krate.attrs.push(make_attr("feature", "register_tool")); krate.attrs.push(make_attr("register_tool", "crux")); @@ -1309,10 +1291,6 @@ pub fn gather_match_spans<'tcx>(queries: &'tcx Queries<'tcx>) { visit::walk_crate(&mut v, krate); MATCH_SPAN_MAP.with(|m| m.replace(Some(Rc::new(v.match_span_map)))); }); - // let k = queries.expansion().unwrap(); - // let krate: &ast::Crate = &k.borrow().0; - - } fn get_match_spans() -> Rc> { diff --git a/src/analyz/to_json.rs b/src/analyz/to_json.rs index e5ceb61..4ba772f 100644 --- a/src/analyz/to_json.rs +++ b/src/analyz/to_json.rs @@ -160,7 +160,7 @@ impl<'tcx> TraitInst<'tcx> { self.projs.iter().map(|p| ty::Binder::dummy(ty::ExistentialPredicate::Projection(*p))), ); let preds = tcx.intern_poly_existential_predicates(&preds); - // TO REVIEW: DynKind? + // Always emit `DynKind::Dyn`. We don't support `dyn*` (`DynKind::DynStar`) yet. Some(tcx.mk_dynamic(preds, tcx.mk_region(ty::RegionKind::ReErased), DynKind::Dyn)) } diff --git a/src/analyz/ty_json.rs b/src/analyz/ty_json.rs index 3629ba8..48eaf2a 100644 --- a/src/analyz/ty_json.rs +++ b/src/analyz/ty_json.rs @@ -671,14 +671,6 @@ fn eval_array_len<'tcx>( val.try_to_machine_usize(tcx).expect("expecting usize value from constant") as usize, ref val => panic!("don't know how to translate ConstKind::{:?}", val), } - // match evaluated { - // interpret::ConstValue::Scalar(interpret::Scalar::Int(sint)) => { - // let data = sint.to_bits(sint.size()).unwrap(); - // assert!(data <= usize::MAX as u128); - // data as usize - // }, - // _ => panic!("impossible: array size is not a scalar?"), - // } } use self::machine::RenderConstMachine; @@ -743,14 +735,6 @@ mod machine { false } - // fn enforce_number_init(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool { - // false - // } - - // fn enforce_number_no_provenance(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool { - // false - // } - fn find_mir_or_eval_fn( ecx: &mut InterpCx<'mir, 'tcx, Self>, instance: ty::Instance<'tcx>, @@ -958,13 +942,6 @@ pub fn get_const_usize<'tcx>(tcx: ty::TyCtxt<'tcx>, c: ty::Const<'tcx>) -> usize } } -// fn eval_op<'tcx>(op_ty: interpret::OpTy<'tcx>) -> interpret::Scalar { -// match *op_ty { -// interpret::Operand::Immediate(imm) => imm.to_scalar(), -// interpret::Operand::Indirect(place) => place., -// } -// } - pub fn render_opty<'mir, 'tcx>( mir: &mut MirState<'_, 'tcx>, icx: &mut interpret::InterpCx<'mir, 'tcx, RenderConstMachine<'mir, 'tcx>>, @@ -1198,7 +1175,7 @@ fn try_render_ref_opty<'mir, 'tcx>( "val": mem })) }, - // Special case for &u8 + // Special case for &[u8; N] ty::TyKind::Array(elem_ty, _) => { if let ty::TyKind::Uint(ty::UintTy::U8) = *elem_ty.kind() { let mem = icx.read_bytes_ptr_strip_provenance(d.ptr, d.layout.size).unwrap(); @@ -1522,11 +1499,11 @@ pub fn eval_mir_constant2<'mir, 'tcx>( icx.eval_mir_constant(&constant.literal, Some(constant.span), Some(layout)).unwrap() } +// Based on `rustc_codegen_ssa::mir::FunctionCx::eval_mir_constant` pub fn eval_mir_constant<'tcx>( tcx: TyCtxt<'tcx>, constant: &mir::Constant<'tcx>, ) -> interpret::ConstValue<'tcx> { - // let ct = self.monomorphize(constant.literal); let uv = match constant.literal { mir::ConstantKind::Ty(ct) => match ct.kind() { ty::ConstKind::Unevaluated(uv) => uv.expand(), @@ -1534,7 +1511,6 @@ pub fn eval_mir_constant<'tcx>( return tcx.valtree_to_const_val((ct.ty(), val)); } err => panic!( - // constant.span, "encountered bad ConstKind after monomorphizing: {:?} span:{:?}", err, constant.span ), @@ -1543,19 +1519,5 @@ pub fn eval_mir_constant<'tcx>( mir::ConstantKind::Val(val, _) => return val, }; - tcx.const_eval_resolve(ty::ParamEnv::reveal_all(), uv, None).unwrap() // .map_err(|err| { - // match err { - // ErrorHandled::Reported(_) => { - // self.cx.tcx().sess.emit_err(errors::ErroneousConstant { span: constant.span }); - // } - // ErrorHandled::TooGeneric => { - // self.cx - // .tcx() - // .sess - // .diagnostic() - // .emit_bug(errors::PolymorphicConstantTooGeneric { span: constant.span }); - // } - // } - // err - // }).unwrap() + tcx.const_eval_resolve(ty::ParamEnv::reveal_all(), uv, None).unwrap() } diff --git a/src/bin/mir-json-rustc-wrapper.rs b/src/bin/mir-json-rustc-wrapper.rs index 20cbee3..ae8850c 100644 --- a/src/bin/mir-json-rustc-wrapper.rs +++ b/src/bin/mir-json-rustc-wrapper.rs @@ -62,8 +62,7 @@ impl rustc_driver::Callbacks for GetOutputPathCallbacks { let krate = queries.parse().unwrap(); let krate = krate.borrow(); let crate_name = rustc_session::output::find_crate_name(&sess, &krate.attrs); - // get global ctxt then call methods inside of enter() to get - let outputs = compiler.build_output_filenames(&sess, &krate.attrs); //queries.prepare_outputs().unwrap().peek(); + let outputs = compiler.build_output_filenames(&sess, &krate.attrs); (crate_name, outputs) }; // Advance the state slightly further, initializing crate_types() From be4359a4e4361dd2c403e30b51fccc421f8304e4 Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Thu, 13 Jul 2023 14:22:58 -0400 Subject: [PATCH 33/35] Inline mk_interp --- src/analyz/ty_json.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/analyz/ty_json.rs b/src/analyz/ty_json.rs index 48eaf2a..ada56d4 100644 --- a/src/analyz/ty_json.rs +++ b/src/analyz/ty_json.rs @@ -924,7 +924,13 @@ impl<'tcx> ToJson<'tcx> for (interpret::ConstValue<'tcx>, ty::Ty<'tcx>) { fn to_json(&self, mir: &mut MirState<'_, 'tcx>) -> serde_json::Value { let (val, ty) = *self; let op_ty = as_opty(mir.state.tcx, val, ty); - let mut icx = mk_interp(mir.state.tcx); + let mut icx = interpret::InterpCx::new( + mir.state.tcx, + DUMMY_SP, + ty::ParamEnv::reveal_all(), + RenderConstMachine::new(), + ); + json!({ "ty": ty.to_json(mir), "rendered": render_opty(mir, &mut icx, &op_ty), @@ -1267,16 +1273,6 @@ pub fn mplace_ty_len<'tcx, Tag: Provenance>(mplace_ty: &MPlaceTy<'tcx, Tag>, cx: } } -// TODO: move -pub fn mk_interp<'mir, 'tcx>(tcx: TyCtxt<'tcx>) -> interpret::InterpCx<'mir, 'tcx, RenderConstMachine<'mir, 'tcx>> { - interpret::InterpCx::new( - tcx, - DUMMY_SP, - ty::ParamEnv::reveal_all(), - RenderConstMachine::new(), - ) -} - pub fn as_opty<'tcx>(tcx: TyCtxt<'tcx>, cv: interpret::ConstValue<'tcx>, ty: ty::Ty<'tcx>) -> interpret::OpTy<'tcx, interpret::AllocId> { From 117ec97f971171cfac3eea37e5009e1f6bfa9ae8 Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Thu, 13 Jul 2023 19:04:17 -0400 Subject: [PATCH 34/35] Split Dynamic case into Dyn/DynStar subcases --- src/analyz/ty_json.rs | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/analyz/ty_json.rs b/src/analyz/ty_json.rs index ada56d4..3617846 100644 --- a/src/analyz/ty_json.rs +++ b/src/analyz/ty_json.rs @@ -8,7 +8,7 @@ use rustc_const_eval::interpret::{self, InterpCx, InterpResult, MPlaceTy, Proven use rustc_const_eval::const_eval::CheckAlignment; use rustc_middle::bug; use rustc_middle::ty; -use rustc_middle::ty::{AdtKind, TyCtxt, TypeFoldable, TypeVisitable}; +use rustc_middle::ty::{AdtKind, DynKind, TyCtxt, TypeFoldable, TypeVisitable}; use rustc_middle::ty::util::{IntTypeExt}; use rustc_query_system::ich::StableHashingContext; use rustc_target::spec::abi; @@ -425,18 +425,26 @@ impl<'tcx> ToJson<'tcx> for ty::Ty<'tcx> { // tuples, so no additional information is needed. }) } - &ty::TyKind::Dynamic(preds, _region, _dynkind) => { - let ti = TraitInst::from_dynamic_predicates(mir.state.tcx, preds); - let trait_name = trait_inst_id_str(mir.state.tcx, &ti); - mir.used.traits.insert(ti); - json!({ - "kind": "Dynamic", - "trait_id": trait_name, - "predicates": preds.iter().map(|p|{ - let p = tcx.erase_late_bound_regions(p); - p.to_json(mir) - }).collect::>(), - }) + &ty::TyKind::Dynamic(preds, _region, dynkind) => { + match dynkind { + DynKind::Dyn => { + let ti = TraitInst::from_dynamic_predicates(mir.state.tcx, preds); + let trait_name = trait_inst_id_str(mir.state.tcx, &ti); + mir.used.traits.insert(ti); + json!({ + "kind": "Dynamic", + "trait_id": trait_name, + "predicates": preds.iter().map(|p|{ + let p = tcx.erase_late_bound_regions(p); + p.to_json(mir) + }).collect::>(), + }) + }, + DynKind::DynStar => + json!({ + "kind": "DynamicStar", + }), + } } &ty::TyKind::Alias(ty::AliasKind::Projection, _) => unreachable!( "no TyKind::Alias with AliasKind Projection should remain after monomorphization" From 11e4d1afb7349d0c539c7c9b35733dfdc20dffd9 Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Fri, 14 Jul 2023 14:09:37 -0400 Subject: [PATCH 35/35] to_json.rs: Remove resolved TO REVIEW comment This is a valid way to convert from a `Ty` to a `Term`, as the commit which changed `Term` to a struct does the same thing here: https://github.com/rust-lang/rust/commit/79db32b64ec946afbef2ed50282f03b71d933480#diff-ea6f9d55e90333a1f5fc5e202d46862a6a031410831f2df42317ac024f821162R352 --- src/analyz/to_json.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/analyz/to_json.rs b/src/analyz/to_json.rs index 4ba772f..b4c1cd6 100644 --- a/src/analyz/to_json.rs +++ b/src/analyz/to_json.rs @@ -140,7 +140,7 @@ impl<'tcx> TraitInst<'tcx> { projs.push(ty::ExistentialProjection { def_id: ai.def_id, substs: ex_trait_ref.substs, - term: actual_ty.into(), // TO REVIEW: structure of Term has changed + term: actual_ty.into(), }); } }