Skip to content

Avoid code generation for ThinVec<Diagnostic>'s destructor in the query system #108359

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

Merged
merged 1 commit into from
Jan 20, 2024
Merged
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
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5353,9 +5353,9 @@ dependencies = [

[[package]]
name = "thin-vec"
version = "0.2.12"
version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aac81b6fd6beb5884b0cf3321b8117e6e5d47ecb6fc89f414cfdcca8b2fe2dd8"
checksum = "a38c90d48152c236a3ab59271da4f4ae63d678c5d7ad6b7714d7cb9760be5e4b"

[[package]]
name = "thiserror"
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_query_system/src/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ impl<D: Deps> DepGraphData<D> {
insertion for {dep_node:?}"
);

if !side_effects.is_empty() {
if side_effects.maybe_any() {
qcx.dep_context().dep_graph().with_query_deserialization(|| {
self.emit_side_effects(qcx, dep_node_index, side_effects)
});
Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_query_system/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,13 @@ pub struct QuerySideEffects {
}

impl QuerySideEffects {
/// Returns true if there might be side effects.
#[inline]
pub fn is_empty(&self) -> bool {
pub fn maybe_any(&self) -> bool {
let QuerySideEffects { diagnostics } = self;
diagnostics.is_empty()
// Use `has_capacity` so that the destructor for `self.diagnostics` can be skipped
// if `maybe_any` is known to be false.
diagnostics.has_capacity()
}
pub fn append(&mut self, other: QuerySideEffects) {
let QuerySideEffects { diagnostics } = self;
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_query_system/src/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,10 +538,9 @@ where

prof_timer.finish_with_query_invocation_id(dep_node_index.into());

let diagnostics = diagnostics.into_inner();
let side_effects = QuerySideEffects { diagnostics };
let side_effects = QuerySideEffects { diagnostics: diagnostics.into_inner() };

if std::intrinsics::unlikely(!side_effects.is_empty()) {
if std::intrinsics::unlikely(side_effects.maybe_any()) {
if query.anon() {
qcx.store_side_effects_for_anon_node(dep_node_index, side_effects);
} else {
Expand Down