Skip to content

Commit 159bdc1

Browse files
committed
Auto merge of rust-lang#108359 - Zoxc:side-effects-tweak, r=cjgillot
Avoid code generation for ThinVec<Diagnostic>'s destructor in the query system This avoids 2 instances of the destructor of `ThinVec<Diagnostic>` from being included in `execute_job`. It also outlines the cold branch in `store_side_effects` / `store_side_effects_for_anon_node`.
2 parents 6745c60 + 862011e commit 159bdc1

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

Diff for: Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -5344,9 +5344,9 @@ dependencies = [
53445344

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

53515351
[[package]]
53525352
name = "thiserror"

Diff for: compiler/rustc_query_system/src/dep_graph/graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ impl<D: Deps> DepGraphData<D> {
891891
insertion for {dep_node:?}"
892892
);
893893

894-
if !side_effects.is_empty() {
894+
if side_effects.maybe_any() {
895895
qcx.dep_context().dep_graph().with_query_deserialization(|| {
896896
self.emit_side_effects(qcx, dep_node_index, side_effects)
897897
});

Diff for: compiler/rustc_query_system/src/query/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,13 @@ pub struct QuerySideEffects {
9393
}
9494

9595
impl QuerySideEffects {
96+
/// Returns true if there might be side effects.
9697
#[inline]
97-
pub fn is_empty(&self) -> bool {
98+
pub fn maybe_any(&self) -> bool {
9899
let QuerySideEffects { diagnostics } = self;
99-
diagnostics.is_empty()
100+
// Use `has_capacity` so that the destructor for `self.diagnostics` can be skipped
101+
// if `maybe_any` is known to be false.
102+
diagnostics.has_capacity()
100103
}
101104
pub fn append(&mut self, other: QuerySideEffects) {
102105
let QuerySideEffects { diagnostics } = self;

Diff for: compiler/rustc_query_system/src/query/plumbing.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -538,10 +538,9 @@ where
538538

539539
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
540540

541-
let diagnostics = diagnostics.into_inner();
542-
let side_effects = QuerySideEffects { diagnostics };
541+
let side_effects = QuerySideEffects { diagnostics: diagnostics.into_inner() };
543542

544-
if std::intrinsics::unlikely(!side_effects.is_empty()) {
543+
if std::intrinsics::unlikely(side_effects.maybe_any()) {
545544
if query.anon() {
546545
qcx.store_side_effects_for_anon_node(dep_node_index, side_effects);
547546
} else {

0 commit comments

Comments
 (0)