Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f1920f4

Browse files
committedFeb 9, 2025
Incomplete rebase
1 parent 43ca9d1 commit f1920f4

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed
 

‎compiler/rustc_middle/src/thir.rs

+1
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ pub struct Arm<'tcx> {
568568
pub lint_level: LintLevel,
569569
pub scope: region::Scope,
570570
pub span: Span,
571+
pub is_cold: bool,
571572
}
572573

573574
#[derive(Copy, Clone, Debug, HashStable)]

‎compiler/rustc_mir_build/src/builder/matches/mod.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
369369
let arm = &self.thir[arm];
370370
let has_match_guard =
371371
if arm.guard.is_some() { HasMatchGuard::Yes } else { HasMatchGuard::No };
372-
(&*arm.pattern, has_match_guard)
372+
(&*arm.pattern, has_match_guard, arm.is_cold)
373373
})
374374
.collect();
375375
let built_tree = self.lower_match_tree(
@@ -467,6 +467,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
467467
EmitStorageLive::Yes,
468468
);
469469

470+
// TODO - make arm_block cold
471+
470472
this.fixed_temps_scope = old_dedup_scope;
471473

472474
if let Some(source_scope) = scope {
@@ -676,7 +678,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
676678
irrefutable_pat.span,
677679
&initializer,
678680
irrefutable_pat.span,
679-
vec![(irrefutable_pat, HasMatchGuard::No)],
681+
vec![(irrefutable_pat, HasMatchGuard::No, false)],
680682
false,
681683
);
682684
let [branch] = built_tree.branches.try_into().unwrap();
@@ -1072,6 +1074,9 @@ struct Candidate<'tcx> {
10721074
/// whether the enclosing match arm has a guard.
10731075
has_guard: bool,
10741076

1077+
/// Whether this 'Candidate' comes from a cold arm.
1078+
is_cold: bool,
1079+
10751080
/// Holds extra pattern data that was prepared by [`FlatPat`], including bindings and
10761081
/// ascriptions that must be established if this candidate succeeds.
10771082
extra_data: PatternExtraData<'tcx>,
@@ -1103,22 +1108,25 @@ impl<'tcx> Candidate<'tcx> {
11031108
place: PlaceBuilder<'tcx>,
11041109
pattern: &Pat<'tcx>,
11051110
has_guard: HasMatchGuard,
1111+
is_cold: bool,
11061112
cx: &mut Builder<'_, 'tcx>,
11071113
) -> Self {
11081114
// Use `FlatPat` to build simplified match pairs, then immediately
11091115
// incorporate them into a new candidate.
11101116
Self::from_flat_pat(
11111117
FlatPat::new(place, pattern, cx),
11121118
matches!(has_guard, HasMatchGuard::Yes),
1119+
is_cold,
11131120
)
11141121
}
11151122

11161123
/// Incorporates an already-simplified [`FlatPat`] into a new candidate.
1117-
fn from_flat_pat(flat_pat: FlatPat<'tcx>, has_guard: bool) -> Self {
1124+
fn from_flat_pat(flat_pat: FlatPat<'tcx>, has_guard: bool, is_cold: bool) -> Self {
11181125
Candidate {
11191126
match_pairs: flat_pat.match_pairs,
11201127
extra_data: flat_pat.extra_data,
11211128
has_guard,
1129+
is_cold,
11221130
subcandidates: Vec::new(),
11231131
or_span: None,
11241132
otherwise_block: None,
@@ -1484,7 +1492,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
14841492
scrutinee_span: Span,
14851493
scrutinee_place_builder: &PlaceBuilder<'tcx>,
14861494
match_start_span: Span,
1487-
patterns: Vec<(&Pat<'tcx>, HasMatchGuard)>,
1495+
patterns: Vec<(&Pat<'tcx>, HasMatchGuard, bool)>,
14881496
refutable: bool,
14891497
) -> BuiltMatchTree<'tcx> {
14901498
// Assemble the initial list of candidates. These top-level candidates are 1:1 with the
@@ -1493,8 +1501,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
14931501
// match arms directly.
14941502
let mut candidates: Vec<Candidate<'_>> = patterns
14951503
.into_iter()
1496-
.map(|(pat, has_guard)| {
1497-
Candidate::new(scrutinee_place_builder.clone(), pat, has_guard, self)
1504+
.map(|(pat, has_guard, is_cold)| {
1505+
Candidate::new(scrutinee_place_builder.clone(), pat, has_guard, is_cold, self)
14981506
})
14991507
.collect();
15001508

@@ -1866,7 +1874,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
18661874
candidate.subcandidates = pats
18671875
.into_vec()
18681876
.into_iter()
1869-
.map(|flat_pat| Candidate::from_flat_pat(flat_pat, candidate.has_guard))
1877+
.map(|flat_pat| {
1878+
Candidate::from_flat_pat(flat_pat, candidate.has_guard, candidate.is_cold)
1879+
})
18701880
.collect();
18711881
candidate.subcandidates[0].false_edge_start_block = candidate.false_edge_start_block;
18721882
}
@@ -2346,7 +2356,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
23462356
expr_span,
23472357
&scrutinee,
23482358
pat.span,
2349-
vec![(pat, HasMatchGuard::No)],
2359+
vec![(pat, HasMatchGuard::No, false)],
23502360
true,
23512361
);
23522362
let [branch] = built_tree.branches.try_into().unwrap();

‎compiler/rustc_mir_build/src/thir/cx/expr.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1005,13 +1005,15 @@ impl<'tcx> ThirBuildCx<'tcx> {
10051005
}
10061006

10071007
fn convert_arm(&mut self, arm: &'tcx hir::Arm<'tcx>) -> ArmId {
1008+
let attrs = self.tcx.hir().attrs(arm.hir_id);
10081009
let arm = Arm {
10091010
pattern: self.pattern_from_hir(&arm.pat),
10101011
guard: arm.guard.as_ref().map(|g| self.mirror_expr(g)),
10111012
body: self.mirror_expr(arm.body),
10121013
lint_level: LintLevel::Explicit(arm.hir_id),
10131014
scope: region::Scope { local_id: arm.hir_id.local_id, data: region::ScopeData::Node },
10141015
span: arm.span,
1016+
is_cold: attrs.iter().any(|a| a.name_or_empty() == sym::cold),
10151017
};
10161018
self.thir.arms.push(arm)
10171019
}

‎compiler/rustc_mir_build/src/thir/print.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ impl<'a, 'tcx> ThirPrinter<'a, 'tcx> {
623623
print_indented!(self, "Arm {", depth_lvl);
624624

625625
let arm = &self.thir.arms[arm_id];
626-
let Arm { pattern, guard, body, lint_level, scope, span } = arm;
626+
let Arm { pattern, guard, body, lint_level, scope, span, is_cold } = arm;
627627

628628
print_indented!(self, "pattern: ", depth_lvl + 1);
629629
self.print_pat(pattern, depth_lvl + 2);
@@ -640,6 +640,7 @@ impl<'a, 'tcx> ThirPrinter<'a, 'tcx> {
640640
print_indented!(self, format!("lint_level: {:?}", lint_level), depth_lvl + 1);
641641
print_indented!(self, format!("scope: {:?}", scope), depth_lvl + 1);
642642
print_indented!(self, format!("span: {:?}", span), depth_lvl + 1);
643+
print_indented!(self, format!("is_cold: {:?}", is_cold), depth_lvl + 1);
643644
print_indented!(self, "}", depth_lvl);
644645
}
645646

0 commit comments

Comments
 (0)
Failed to load comments.