Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Compute always-storage-liveness more efficiently #99025

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 55 additions & 12 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ dependencies = [
"cargo-test-macro",
"cargo-test-support",
"cargo-util",
"clap",
"clap 3.2.5",
"crates-io",
"crossbeam-utils",
"curl",
Expand Down Expand Up @@ -572,6 +572,22 @@ 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"
Expand All @@ -584,9 +600,9 @@ dependencies = [
"clap_lex",
"indexmap",
"once_cell",
"strsim",
"strsim 0.10.0",
"termcolor",
"textwrap",
"textwrap 0.15.0",
]

[[package]]
Expand All @@ -595,7 +611,7 @@ version = "3.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df6f3613c0a3cddfd78b41b10203eb322cb29b600cbdf808a7d3db95691b8e25"
dependencies = [
"clap",
"clap 3.2.5",
]

[[package]]
Expand Down Expand Up @@ -653,7 +669,7 @@ name = "clippy_dev"
version = "0.0.1"
dependencies = [
"aho-corasick",
"clap",
"clap 3.2.5",
"indoc",
"itertools",
"opener",
Expand Down Expand Up @@ -1226,7 +1242,7 @@ name = "expand-yaml-anchors"
version = "0.1.0"
dependencies = [
"yaml-merge-keys",
"yaml-rust",
"yaml-rust 0.4.4",
]

[[package]]
Expand Down Expand Up @@ -1846,7 +1862,7 @@ name = "installer"
version = "0.0.0"
dependencies = [
"anyhow",
"clap",
"clap 2.34.0",
"flate2",
"lazy_static",
"num_cpus",
Expand Down Expand Up @@ -2294,7 +2310,7 @@ dependencies = [
"ammonia",
"anyhow",
"chrono",
"clap",
"clap 3.2.5",
"clap_complete",
"elasticlunr-rs",
"env_logger 0.7.1",
Expand Down Expand Up @@ -3369,7 +3385,7 @@ dependencies = [
name = "rustbook"
version = "0.1.0"
dependencies = [
"clap",
"clap 3.2.5",
"env_logger 0.7.1",
"mdbook",
]
Expand Down Expand Up @@ -3457,7 +3473,7 @@ version = "1.0.0"
dependencies = [
"bstr",
"byteorder",
"clap",
"clap 3.2.5",
"crossbeam-utils",
"libc",
"libz-sys",
Expand Down Expand Up @@ -4646,7 +4662,7 @@ dependencies = [
"anyhow",
"bytecount",
"cargo_metadata",
"clap",
"clap 3.2.5",
"derive-new",
"diff",
"dirs",
Expand Down Expand Up @@ -5037,6 +5053,12 @@ 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"
Expand Down Expand Up @@ -5177,6 +5199,15 @@ 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"
Expand Down Expand Up @@ -5697,6 +5728,12 @@ 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"
Expand Down Expand Up @@ -5855,9 +5892,15 @@ checksum = "fd236a7dc9bb598f349fe4a8754f49181fee50284daa15cd1ba652d722280004"
dependencies = [
"lazy_static",
"thiserror",
"yaml-rust",
"yaml-rust 0.4.4",
]

[[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"
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,10 @@ pub struct LocalDecl<'tcx> {
/// │ │← `drop(x)` // This accesses `x: u32`.
/// ```
pub source_info: SourceInfo,

/// `true` if the local has a fixed storage for the duration of the body
/// (that is, it does not have `StorageLive`/`StorageDead` annotations).
pub always_storage_live: bool,
}

// `LocalDecl` is used a lot. Make sure it doesn't unintentionally get bigger.
Expand Down Expand Up @@ -949,6 +953,7 @@ impl<'tcx> LocalDecl<'tcx> {
ty,
user_ty: None,
source_info,
always_storage_live: false,
}
}

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,7 @@ macro_rules! make_mir_visitor {
internal: _,
local_info: _,
is_block_tail: _,
always_storage_live: _,
} = local_decl;

self.visit_ty($(& $mutability)? *ty, TyContext::LocalDecl {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_mir_build/src/build/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2241,6 +2241,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
pat_span,
},
))))),
always_storage_live: false,
};
let for_arm_body = self.local_decls.push(local);
self.var_debug_info.push(VarDebugInfo {
Expand All @@ -2261,6 +2262,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
local_info: Some(Box::new(LocalInfo::User(ClearCrossCrate::Set(
BindingForm::RefForGuard,
)))),
always_storage_live: false,
});
self.var_debug_info.push(VarDebugInfo {
name,
Expand Down
19 changes: 7 additions & 12 deletions compiler/rustc_mir_dataflow/src/storage.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
use rustc_index::bit_set::BitSet;
use rustc_middle::mir::{self, Local};
use rustc_middle::mir::{self, HasLocalDecls, Local};

/// The set of locals in a MIR body that do not have `StorageLive`/`StorageDead` annotations.
/// Returns the set of locals in a MIR body that do not have `StorageLive`/`StorageDead`
/// annotations.
///
/// These locals have fixed storage for the duration of the body.
//
// FIXME: Currently, we need to traverse the entire MIR to compute this. We should instead store it
// as a field in the `LocalDecl` for each `Local`.
pub fn always_storage_live_locals(body: &mir::Body<'_>) -> BitSet<Local> {
pub fn always_live_locals(body: &mir::Body<'_>) -> BitSet<Local> {
let mut always_live_locals = BitSet::new_filled(body.local_decls.len());

for block in body.basic_blocks() {
for statement in &block.statements {
use mir::StatementKind::{StorageDead, StorageLive};
if let StorageLive(l) | StorageDead(l) = statement.kind {
always_live_locals.remove(l);
}
for (local, local_decl) in body.local_decls().iter_enumerated() {
if !local_decl.always_storage_live {
always_live_locals.remove(local);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri
Submodule miri updated 100 files
2 changes: 1 addition & 1 deletion src/tools/rust-installer