diff --git a/.github/ISSUE_TEMPLATE/documentation.md b/.github/ISSUE_TEMPLATE/documentation.md new file mode 100644 index 0000000000000..1d93939e23360 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/documentation.md @@ -0,0 +1,16 @@ +--- +name: Documentation problem +about: Create a report for a documentation problem. +labels: A-docs +--- + + +### Location + +### Summary + diff --git a/.github/ISSUE_TEMPLATE/library_tracking_issue.md b/.github/ISSUE_TEMPLATE/library_tracking_issue.md index 32fccfcfb1696..91c06402ca10a 100644 --- a/.github/ISSUE_TEMPLATE/library_tracking_issue.md +++ b/.github/ISSUE_TEMPLATE/library_tracking_issue.md @@ -50,7 +50,7 @@ If the feature is changed later, please add those PRs here as well. --> - [ ] Implementation: #... -- [ ] Final comment period (FCP) +- [ ] Final comment period (FCP)[^1] - [ ] Stabilization PR - None yet. + +[^1]: https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a7be9978c0bc5..6d9e249ee44ef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -410,7 +410,7 @@ jobs: - name: dist-x86_64-msvc env: RUST_CONFIGURE_ARGS: "--build=x86_64-pc-windows-msvc --host=x86_64-pc-windows-msvc --target=x86_64-pc-windows-msvc --enable-full-tools --enable-profiler" - SCRIPT: python x.py dist + SCRIPT: PGO_HOST=x86_64-pc-windows-msvc src/ci/pgo.sh python x.py dist DIST_REQUIRE_ALL_TOOLS: 1 os: windows-latest-xl - name: dist-i686-msvc diff --git a/.gitignore b/.gitignore index ec6cb6ed2e4d3..a6625ac2ac4a1 100644 --- a/.gitignore +++ b/.gitignore @@ -46,8 +46,6 @@ no_llvm_build /unicode-downloads /target /src/tools/x/target -# Generated by compiletest for incremental -/tmp/ # Created by default with `src/ci/docker/run.sh` /obj/ diff --git a/.gitmodules b/.gitmodules index 21bce3c7fa06b..a524098845a48 100644 --- a/.gitmodules +++ b/.gitmodules @@ -34,7 +34,7 @@ [submodule "src/llvm-project"] path = src/llvm-project url = https://github.com/rust-lang/llvm-project.git - branch = rustc/14.0-2022-03-22 + branch = rustc/14.0-2022-06-20 [submodule "src/doc/embedded-book"] path = src/doc/embedded-book url = https://github.com/rust-embedded/book.git diff --git a/Cargo.lock b/Cargo.lock index 1108c1f4d4c20..e8081b5a6574d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -215,32 +215,6 @@ dependencies = [ "byte-tools", ] -[[package]] -name = "bootstrap" -version = "0.0.0" -dependencies = [ - "cc", - "cmake", - "filetime", - "getopts", - "hex 0.4.2", - "ignore", - "libc", - "num_cpus", - "once_cell", - "opener", - "pretty_assertions 0.7.2", - "serde", - "serde_json", - "sha2", - "sysinfo", - "tar", - "toml", - "walkdir", - "winapi", - "xz2", -] - [[package]] name = "bstr" version = "0.2.13" @@ -324,7 +298,7 @@ dependencies = [ [[package]] name = "cargo" -version = "0.64.0" +version = "0.65.0" dependencies = [ "anyhow", "atty", @@ -333,7 +307,7 @@ dependencies = [ "cargo-test-macro", "cargo-test-support", "cargo-util", - "clap 3.2.5", + "clap", "crates-io", "crossbeam-utils", "curl", @@ -471,7 +445,7 @@ dependencies = [ [[package]] name = "cargo-util" -version = "0.1.4" +version = "0.2.1" dependencies = [ "anyhow", "core-foundation", @@ -598,22 +572,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "clap" -version = "2.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" -dependencies = [ - "ansi_term", - "atty", - "bitflags", - "strsim 0.8.0", - "textwrap 0.11.0", - "unicode-width", - "vec_map", - "yaml-rust 0.3.5", -] - [[package]] name = "clap" version = "3.2.5" @@ -626,9 +584,9 @@ dependencies = [ "clap_lex", "indexmap", "once_cell", - "strsim 0.10.0", + "strsim", "termcolor", - "textwrap 0.15.0", + "textwrap", ] [[package]] @@ -637,7 +595,7 @@ version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df6f3613c0a3cddfd78b41b10203eb322cb29b600cbdf808a7d3db95691b8e25" dependencies = [ - "clap 3.2.5", + "clap", ] [[package]] @@ -664,7 +622,7 @@ dependencies = [ [[package]] name = "clippy" -version = "0.1.63" +version = "0.1.64" dependencies = [ "clippy_lints", "clippy_utils", @@ -687,6 +645,7 @@ dependencies = [ "termize", "tester", "tokio", + "toml", ] [[package]] @@ -694,7 +653,7 @@ name = "clippy_dev" version = "0.0.1" dependencies = [ "aho-corasick", - "clap 3.2.5", + "clap", "indoc", "itertools", "opener", @@ -705,10 +664,9 @@ dependencies = [ [[package]] name = "clippy_lints" -version = "0.1.63" +version = "0.1.64" dependencies = [ "cargo_metadata", - "clippy_dev", "clippy_utils", "if_chain", "itertools", @@ -728,22 +686,13 @@ dependencies = [ [[package]] name = "clippy_utils" -version = "0.1.63" +version = "0.1.64" dependencies = [ "arrayvec", "if_chain", "rustc-semver", ] -[[package]] -name = "cmake" -version = "0.1.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e56268c17a6248366d66d4a47a3381369d068cce8409bb1716ed77ea32163bb" -dependencies = [ - "cc", -] - [[package]] name = "colored" version = "2.0.0" @@ -1023,9 +972,9 @@ dependencies = [ [[package]] name = "ctor" -version = "0.1.15" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39858aa5bac06462d4dd4b9164848eb81ffc4aa5c479746393598fd193afa227" +checksum = "f877be4f7c9f246b183111634f75baa039715e3f46ce860677d3b19a69fb229c" dependencies = [ "quote", "syn", @@ -1277,7 +1226,7 @@ name = "expand-yaml-anchors" version = "0.1.0" dependencies = [ "yaml-merge-keys", - "yaml-rust 0.4.4", + "yaml-rust", ] [[package]] @@ -1709,9 +1658,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.12.0" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c21d40587b92fa6a6c6e3c1bdbf87d75511db5672f9c93175574b3a00df1758" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" dependencies = [ "ahash", "compiler_builtins", @@ -1873,12 +1822,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.8.2" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6012d540c5baa3589337a98ce73408de9b5a25ec9fc2c6fd6be8f0d39e0ca5a" +checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" dependencies = [ "autocfg", - "hashbrown 0.11.2", + "hashbrown 0.12.3", "rustc-rayon", "serde", ] @@ -1897,7 +1846,7 @@ name = "installer" version = "0.0.0" dependencies = [ "anyhow", - "clap 2.34.0", + "clap", "flate2", "lazy_static", "num_cpus", @@ -2345,7 +2294,7 @@ dependencies = [ "ammonia", "anyhow", "chrono", - "clap 3.2.5", + "clap", "clap_complete", "elasticlunr-rs", "env_logger 0.7.1", @@ -2365,20 +2314,6 @@ dependencies = [ "topological-sort", ] -[[package]] -name = "measureme" -version = "9.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78f7a41bc6f856a2cf0e95094ad5121f82500e2d9a0f3c0171d98f6566d8117d" -dependencies = [ - "log", - "memmap2", - "parking_lot 0.11.2", - "perf-event-open-sys", - "rustc-hash", - "smallvec", -] - [[package]] name = "measureme" version = "10.0.0" @@ -2477,7 +2412,7 @@ dependencies = [ "lazy_static", "libc", "log", - "measureme 9.1.2", + "measureme", "rand 0.8.5", "regex", "rustc-workspace-hack", @@ -2579,7 +2514,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53" dependencies = [ "crc32fast", - "hashbrown 0.12.0", + "hashbrown 0.12.3", "indexmap", "memchr", ] @@ -2666,9 +2601,9 @@ checksum = "dd20eec3dbe4376829cb7d80ae6ac45e0a766831dca50202ff2d40db46a8a024" [[package]] name = "os_info" -version = "3.0.7" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ac91020bfed8cc3f8aa450d4c3b5fa1d3373fc091c8a92009f3b27749d5a227" +checksum = "0eca3ecae1481e12c3d9379ec541b238a16f0b75c9a409942daa8ec20dbfdb62" dependencies = [ "log", "serde", @@ -2683,9 +2618,9 @@ checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" [[package]] name = "output_vt100" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53cdc5b785b7a58c5aad8216b3dfa114df64b0b06ae6e1501cef91df2fbdf8f9" +checksum = "628223faebab4e3e40667ee0b2336d34a5b960ff60ea743ddfdbcf7770bcfb66" dependencies = [ "winapi", ] @@ -2944,18 +2879,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" -[[package]] -name = "pretty_assertions" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cab0e7c02cf376875e9335e0ba1da535775beb5450d21e1dffca068818ed98b" -dependencies = [ - "ansi_term", - "ctor", - "diff", - "output_vt100", -] - [[package]] name = "pretty_assertions" version = "1.2.1" @@ -3101,7 +3024,6 @@ name = "racer" version = "2.2.2" dependencies = [ "bitflags", - "clap 2.34.0", "derive_more", "env_logger 0.7.1", "humantime 2.0.1", @@ -3325,7 +3247,7 @@ dependencies = [ "difference", "env_logger 0.9.0", "futures 0.3.19", - "heck 0.3.1", + "heck 0.4.0", "home", "itertools", "jsonrpc-core", @@ -3447,7 +3369,7 @@ dependencies = [ name = "rustbook" version = "0.1.0" dependencies = [ - "clap 2.34.0", + "clap", "env_logger 0.7.1", "mdbook", ] @@ -3535,13 +3457,14 @@ version = "1.0.0" dependencies = [ "bstr", "byteorder", - "clap 3.2.5", + "clap", "crossbeam-utils", "libc", "libz-sys", "proc-macro2", "quote", "rand_core 0.5.1", + "regex", "serde", "serde_json", "smallvec", @@ -3657,6 +3580,7 @@ dependencies = [ "rustc_index", "rustc_infer", "rustc_lexer", + "rustc_macros", "rustc_middle", "rustc_mir_dataflow", "rustc_serialize", @@ -3700,7 +3624,7 @@ dependencies = [ "cstr", "libc", "libloading", - "measureme 10.0.0", + "measureme", "rustc-demangle", "rustc_ast", "rustc_attr", @@ -3798,7 +3722,7 @@ dependencies = [ "indexmap", "jobserver", "libc", - "measureme 10.0.0", + "measureme", "memmap2", "parking_lot 0.11.2", "rustc-hash", @@ -3874,6 +3798,7 @@ dependencies = [ "atty", "rustc_data_structures", "rustc_error_messages", + "rustc_hir", "rustc_lint_defs", "rustc_macros", "rustc_serialize", @@ -3930,6 +3855,7 @@ name = "rustc_hir" version = "0.0.0" dependencies = [ "odht", + "rustc_arena", "rustc_ast", "rustc_data_structures", "rustc_error_messages", @@ -4043,7 +3969,6 @@ dependencies = [ "rustc_ty_utils", "rustc_typeck", "smallvec", - "tempfile", "tracing", "winapi", ] @@ -4070,6 +3995,7 @@ dependencies = [ "rustc_hir", "rustc_index", "rustc_infer", + "rustc_macros", "rustc_middle", "rustc_parse_format", "rustc_session", @@ -4153,6 +4079,7 @@ dependencies = [ "rustc_type_ir", "smallvec", "snap", + "tempfile", "tracing", ] @@ -4312,6 +4239,7 @@ dependencies = [ "rustc_hir", "rustc_index", "rustc_lexer", + "rustc_macros", "rustc_middle", "rustc_serialize", "rustc_session", @@ -4342,6 +4270,7 @@ dependencies = [ "rustc_data_structures", "rustc_errors", "rustc_hir", + "rustc_macros", "rustc_middle", "rustc_session", "rustc_span", @@ -4354,7 +4283,7 @@ dependencies = [ name = "rustc_query_impl" version = "0.0.0" dependencies = [ - "measureme 10.0.0", + "measureme", "rustc-rayon-core", "rustc_ast", "rustc_data_structures", @@ -4586,6 +4515,7 @@ dependencies = [ "rustc_data_structures", "rustc_errors", "rustc_hir", + "rustc_index", "rustc_infer", "rustc_middle", "rustc_session", @@ -4712,13 +4642,13 @@ dependencies = [ [[package]] name = "rustfmt-nightly" -version = "1.5.0" +version = "1.5.1" dependencies = [ "annotate-snippets 0.9.1", "anyhow", "bytecount", "cargo_metadata", - "clap 3.2.5", + "clap", "derive-new", "diff", "dirs", @@ -4968,9 +4898,9 @@ checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" [[package]] name = "smallvec" -version = "1.7.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309" +checksum = "cc88c725d61fc6c3132893370cac4a0200e3fedf5da8331c570664b1987f5ca2" [[package]] name = "snap" @@ -5048,7 +4978,7 @@ dependencies = [ "core", "dlmalloc", "fortanix-sgx-abi", - "hashbrown 0.12.0", + "hashbrown 0.12.3", "hermit-abi 0.2.0", "libc", "miniz_oxide", @@ -5109,12 +5039,6 @@ dependencies = [ "vte", ] -[[package]] -name = "strsim" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" - [[package]] name = "strsim" version = "0.10.0" @@ -5162,21 +5086,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "sysinfo" -version = "0.24.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a8e71535da31837213ac114531d31def75d7aebd133264e420a3451fa7f703" -dependencies = [ - "cfg-if 1.0.0", - "core-foundation-sys", - "libc", - "ntapi", - "once_cell", - "rayon", - "winapi", -] - [[package]] name = "tar" version = "0.4.38" @@ -5270,15 +5179,6 @@ dependencies = [ "term", ] -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - [[package]] name = "textwrap" version = "0.15.0" @@ -5553,7 +5453,7 @@ dependencies = [ "colored", "crossbeam", "lazy_static", - "pretty_assertions 1.2.1", + "pretty_assertions", "regex", "rustc_version", "serde", @@ -5799,12 +5699,6 @@ version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c" -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - [[package]] name = "vergen" version = "5.1.0" @@ -5963,15 +5857,9 @@ checksum = "fd236a7dc9bb598f349fe4a8754f49181fee50284daa15cd1ba652d722280004" dependencies = [ "lazy_static", "thiserror", - "yaml-rust 0.4.4", + "yaml-rust", ] -[[package]] -name = "yaml-rust" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e66366e18dc58b46801afbf2ca7661a9f59cc8c5962c29892b6039b4f86fa992" - [[package]] name = "yaml-rust" version = "0.4.4" diff --git a/Cargo.toml b/Cargo.toml index 4e78399606445..ed024192c1503 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,5 @@ [workspace] -default-members = ["src/bootstrap"] members = [ - "src/bootstrap", "compiler/rustc", "library/std", "library/test", @@ -44,6 +42,7 @@ exclude = [ "build", "compiler/rustc_codegen_cranelift", "compiler/rustc_codegen_gcc", + "src/bootstrap", "src/test/rustdoc-gui", # HACK(eddyb) This hardcodes the fact that our CI uses `/checkout/obj`. "obj", @@ -97,15 +96,6 @@ gimli.debug = 0 miniz_oxide.debug = 0 object.debug = 0 -# The only package that ever uses debug builds is bootstrap. -# We care a lot about bootstrap's compile times, so don't include debug info for -# dependencies, only bootstrap itself. -[profile.dev] -debug = 0 -[profile.dev.package] -# Only use debuginfo=1 to further reduce compile times. -bootstrap.debug = 1 - # We want the RLS to use the version of Cargo that we've got vendored in this # repository to ensure that the same exact version of Cargo is used by both the # RLS and the Cargo binary itself. The RLS depends on Cargo as a git repository diff --git a/RELEASES.md b/RELEASES.md index 3d88891ad215c..8154eab20599a 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -5,7 +5,7 @@ Language -------- - [Stabilize `#[derive(Default)]` on enums with a `#[default]` variant][94457] -- [Stop validating some checks in dead code after functions with uninhabited return types][93313] +- [Teach flow sensitive checks that visibly uninhabited call expressions never return][93313] - [Fix constants not getting dropped if part of a diverging expression][94775] - [Support unit struct/enum variant in destructuring assignment][95380] - [Remove mutable_borrow_reservation_conflict lint and allow the code pattern][96268] @@ -29,7 +29,6 @@ Compiler Libraries --------- -- [Move `CStr` to libcore, and `CString` to liballoc][94079] - [Windows: Use a pipe relay for chaining pipes][95841] - [Replace Linux Mutex and Condvar with futex based ones.][95035] - [Replace RwLock by a futex based one on Linux][95801] @@ -76,8 +75,11 @@ Compatibility Notes - `cargo test` now passes `--target` to `rustdoc` if the specified target is the same as the host target. [#10594](https://github.com/rust-lang/cargo/pull/10594) +- [rustdoc: doctests are now run on unexported `macro_rules!` macros, matching other private items][96630] - [rustdoc: Remove .woff font files][96279] - [Enforce Copy bounds for repeat elements while considering lifetimes][95819] +- [Windows: Fix potentinal unsoundness by aborting if `File` reads or writes cannot + complete synchronously][95469]. Internal Changes ---------------- @@ -90,7 +92,6 @@ and related tools. [93313]: https://github.com/rust-lang/rust/pull/93313/ [93969]: https://github.com/rust-lang/rust/pull/93969/ -[94079]: https://github.com/rust-lang/rust/pull/94079/ [94206]: https://github.com/rust-lang/rust/pull/94206/ [94457]: https://github.com/rust-lang/rust/pull/94457/ [94775]: https://github.com/rust-lang/rust/pull/94775/ @@ -100,6 +101,7 @@ and related tools. [95372]: https://github.com/rust-lang/rust/pull/95372/ [95380]: https://github.com/rust-lang/rust/pull/95380/ [95431]: https://github.com/rust-lang/rust/pull/95431/ +[95469]: https://github.com/rust-lang/rust/pull/95469/ [95705]: https://github.com/rust-lang/rust/pull/95705/ [95801]: https://github.com/rust-lang/rust/pull/95801/ [95819]: https://github.com/rust-lang/rust/pull/95819/ @@ -111,6 +113,7 @@ and related tools. [96393]: https://github.com/rust-lang/rust/pull/96393/ [96436]: https://github.com/rust-lang/rust/pull/96436/ [96557]: https://github.com/rust-lang/rust/pull/96557/ +[96630]: https://github.com/rust-lang/rust/pull/96630/ [`bool::then_some`]: https://doc.rust-lang.org/stable/std/primitive.bool.html#method.then_some [`f32::total_cmp`]: https://doc.rust-lang.org/stable/std/primitive.f32.html#method.total_cmp diff --git a/compiler/rustc/build.rs b/compiler/rustc/build.rs index 24c06c0ddbf6c..39cf3e094c823 100644 --- a/compiler/rustc/build.rs +++ b/compiler/rustc/build.rs @@ -5,6 +5,9 @@ fn main() { let target_env = env::var("CARGO_CFG_TARGET_ENV"); if Ok("windows") == target_os.as_deref() && Ok("msvc") == target_env.as_deref() { set_windows_exe_options(); + } else { + // Avoid rerunning the build script every time. + println!("cargo:rerun-if-changed=build.rs"); } } diff --git a/compiler/rustc_apfloat/Cargo.toml b/compiler/rustc_apfloat/Cargo.toml index bb01d4f51b899..98305201bc943 100644 --- a/compiler/rustc_apfloat/Cargo.toml +++ b/compiler/rustc_apfloat/Cargo.toml @@ -5,4 +5,4 @@ edition = "2021" [dependencies] bitflags = "1.2.1" -smallvec = { version = "1.6.1", features = ["union", "may_dangle"] } +smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } diff --git a/compiler/rustc_arena/Cargo.toml b/compiler/rustc_arena/Cargo.toml index ee3a7b51b699a..5c2aee6b47f9a 100644 --- a/compiler/rustc_arena/Cargo.toml +++ b/compiler/rustc_arena/Cargo.toml @@ -4,4 +4,4 @@ version = "0.0.0" edition = "2021" [dependencies] -smallvec = { version = "1.6.1", features = ["union", "may_dangle"] } +smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } diff --git a/compiler/rustc_arena/src/lib.rs b/compiler/rustc_arena/src/lib.rs index 62995dfd2e2f0..a5f1cbc96daa7 100644 --- a/compiler/rustc_arena/src/lib.rs +++ b/compiler/rustc_arena/src/lib.rs @@ -19,6 +19,7 @@ #![feature(rustc_attrs)] #![cfg_attr(test, feature(test))] #![feature(strict_provenance)] +#![feature(ptr_const_cast)] use smallvec::SmallVec; @@ -27,7 +28,7 @@ use std::cell::{Cell, RefCell}; use std::cmp; use std::marker::{PhantomData, Send}; use std::mem::{self, MaybeUninit}; -use std::ptr; +use std::ptr::{self, NonNull}; use std::slice; #[inline(never)] @@ -55,15 +56,24 @@ pub struct TypedArena { struct ArenaChunk { /// The raw storage for the arena chunk. - storage: Box<[MaybeUninit]>, + storage: NonNull<[MaybeUninit]>, /// The number of valid entries in the chunk. entries: usize, } +unsafe impl<#[may_dangle] T> Drop for ArenaChunk { + fn drop(&mut self) { + unsafe { Box::from_raw(self.storage.as_mut()) }; + } +} + impl ArenaChunk { #[inline] unsafe fn new(capacity: usize) -> ArenaChunk { - ArenaChunk { storage: Box::new_uninit_slice(capacity), entries: 0 } + ArenaChunk { + storage: NonNull::new(Box::into_raw(Box::new_uninit_slice(capacity))).unwrap(), + entries: 0, + } } /// Destroys this arena chunk. @@ -72,14 +82,15 @@ impl ArenaChunk { // The branch on needs_drop() is an -O1 performance optimization. // Without the branch, dropping TypedArena takes linear time. if mem::needs_drop::() { - ptr::drop_in_place(MaybeUninit::slice_assume_init_mut(&mut self.storage[..len])); + let slice = &mut *(self.storage.as_mut()); + ptr::drop_in_place(MaybeUninit::slice_assume_init_mut(&mut slice[..len])); } } // Returns a pointer to the first allocated object. #[inline] fn start(&mut self) -> *mut T { - MaybeUninit::slice_as_mut_ptr(&mut self.storage) + self.storage.as_ptr() as *mut T } // Returns a pointer to the end of the allocated space. @@ -90,7 +101,7 @@ impl ArenaChunk { // A pointer as large as possible for zero-sized elements. ptr::invalid_mut(!0) } else { - self.start().add(self.storage.len()) + self.start().add((*self.storage.as_ptr()).len()) } } } @@ -274,7 +285,7 @@ impl TypedArena { // If the previous chunk's len is less than HUGE_PAGE // bytes, then this chunk will be least double the previous // chunk's size. - new_cap = last_chunk.storage.len().min(HUGE_PAGE / elem_size / 2); + new_cap = (*last_chunk.storage.as_ptr()).len().min(HUGE_PAGE / elem_size / 2); new_cap *= 2; } else { new_cap = PAGE / elem_size; @@ -382,7 +393,7 @@ impl DroplessArena { // If the previous chunk's len is less than HUGE_PAGE // bytes, then this chunk will be least double the previous // chunk's size. - new_cap = last_chunk.storage.len().min(HUGE_PAGE / 2); + new_cap = (*last_chunk.storage.as_ptr()).len().min(HUGE_PAGE / 2); new_cap *= 2; } else { new_cap = PAGE; diff --git a/compiler/rustc_arena/src/tests.rs b/compiler/rustc_arena/src/tests.rs index 911e577c1edc7..ad61464343a4a 100644 --- a/compiler/rustc_arena/src/tests.rs +++ b/compiler/rustc_arena/src/tests.rs @@ -79,7 +79,11 @@ fn test_arena_alloc_nested() { #[test] pub fn test_copy() { let arena = TypedArena::default(); - for _ in 0..100000 { + #[cfg(not(miri))] + const N: usize = 100000; + #[cfg(miri)] + const N: usize = 1000; + for _ in 0..N { arena.alloc(Point { x: 1, y: 2, z: 3 }); } } @@ -106,7 +110,11 @@ struct Noncopy { #[test] pub fn test_noncopy() { let arena = TypedArena::default(); - for _ in 0..100000 { + #[cfg(not(miri))] + const N: usize = 100000; + #[cfg(miri)] + const N: usize = 1000; + for _ in 0..N { arena.alloc(Noncopy { string: "hello world".to_string(), array: vec![1, 2, 3, 4, 5] }); } } @@ -114,7 +122,11 @@ pub fn test_noncopy() { #[test] pub fn test_typed_arena_zero_sized() { let arena = TypedArena::default(); - for _ in 0..100000 { + #[cfg(not(miri))] + const N: usize = 100000; + #[cfg(miri)] + const N: usize = 1000; + for _ in 0..N { arena.alloc(()); } } @@ -124,7 +136,11 @@ pub fn test_typed_arena_clear() { let mut arena = TypedArena::default(); for _ in 0..10 { arena.clear(); - for _ in 0..10000 { + #[cfg(not(miri))] + const N: usize = 10000; + #[cfg(miri)] + const N: usize = 100; + for _ in 0..N { arena.alloc(Point { x: 1, y: 2, z: 3 }); } } diff --git a/compiler/rustc_ast/Cargo.toml b/compiler/rustc_ast/Cargo.toml index 58b967a370415..9822e9864e210 100644 --- a/compiler/rustc_ast/Cargo.toml +++ b/compiler/rustc_ast/Cargo.toml @@ -14,5 +14,5 @@ rustc_data_structures = { path = "../rustc_data_structures" } rustc_index = { path = "../rustc_index" } rustc_lexer = { path = "../rustc_lexer" } rustc_macros = { path = "../rustc_macros" } -smallvec = { version = "1.6.1", features = ["union", "may_dangle"] } +smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } bitflags = "1.2.1" diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index e5b61d7000a32..ac2328a582418 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -1390,7 +1390,7 @@ pub enum ExprKind { /// A closure (e.g., `move |a, b, c| a + b + c`). /// /// The final span is the span of the argument block `|...|`. - Closure(CaptureBy, Async, Movability, P, P, Span), + Closure(ClosureBinder, CaptureBy, Async, Movability, P, P, Span), /// A block (`'label: { ... }`). Block(P, Option