Skip to content

Commit 92fecfb

Browse files
authored
Rollup merge of #57719 - nnethercote:expand_node-FIDDLING, r=nikomatsakis
Tweak `expand_node` These commits speed up the `unicode_normalization` benchmark a little.
2 parents e78bde4 + 92fd6f9 commit 92fecfb

File tree

1 file changed

+20
-16
lines changed
  • src/librustc/infer/lexical_region_resolve

1 file changed

+20
-16
lines changed

src/librustc/infer/lexical_region_resolve/mod.rs

+20-16
Original file line numberDiff line numberDiff line change
@@ -186,34 +186,39 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
186186
}
187187

188188
fn expansion(&self, var_values: &mut LexicalRegionResolutions<'tcx>) {
189-
self.iterate_until_fixed_point("Expansion", |constraint, origin| {
190-
debug!("expansion: constraint={:?} origin={:?}", constraint, origin);
191-
match *constraint {
189+
self.iterate_until_fixed_point("Expansion", |constraint| {
190+
debug!("expansion: constraint={:?}", constraint);
191+
let (a_region, b_vid, b_data, retain) = match *constraint {
192192
Constraint::RegSubVar(a_region, b_vid) => {
193193
let b_data = var_values.value_mut(b_vid);
194-
(self.expand_node(a_region, b_vid, b_data), false)
194+
(a_region, b_vid, b_data, false)
195195
}
196196
Constraint::VarSubVar(a_vid, b_vid) => match *var_values.value(a_vid) {
197-
VarValue::ErrorValue => (false, false),
197+
VarValue::ErrorValue => return (false, false),
198198
VarValue::Value(a_region) => {
199-
let b_node = var_values.value_mut(b_vid);
200-
let changed = self.expand_node(a_region, b_vid, b_node);
201-
let retain = match *b_node {
199+
let b_data = var_values.value_mut(b_vid);
200+
let retain = match *b_data {
202201
VarValue::Value(ReStatic) | VarValue::ErrorValue => false,
203202
_ => true
204203
};
205-
(changed, retain)
204+
(a_region, b_vid, b_data, retain)
206205
}
207206
},
208207
Constraint::RegSubReg(..) | Constraint::VarSubReg(..) => {
209208
// These constraints are checked after expansion
210209
// is done, in `collect_errors`.
211-
(false, false)
210+
return (false, false)
212211
}
213-
}
212+
};
213+
214+
let changed = self.expand_node(a_region, b_vid, b_data);
215+
(changed, retain)
214216
})
215217
}
216218

219+
// This function is very hot in some workloads. There's a single callsite
220+
// so always inlining is ok even though it's large.
221+
#[inline(always)]
217222
fn expand_node(
218223
&self,
219224
a_region: Region<'tcx>,
@@ -722,18 +727,17 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
722727
}
723728

724729
fn iterate_until_fixed_point<F>(&self, tag: &str, mut body: F)
725-
where
726-
F: FnMut(&Constraint<'tcx>, &SubregionOrigin<'tcx>) -> (bool, bool),
730+
where F: FnMut(&Constraint<'tcx>) -> (bool, bool),
727731
{
728-
let mut constraints: SmallVec<[_; 16]> = self.data.constraints.iter().collect();
732+
let mut constraints: SmallVec<[_; 16]> = self.data.constraints.keys().collect();
729733
let mut iteration = 0;
730734
let mut changed = true;
731735
while changed {
732736
changed = false;
733737
iteration += 1;
734738
debug!("---- {} Iteration {}{}", "#", tag, iteration);
735-
constraints.retain(|(constraint, origin)| {
736-
let (edge_changed, retain) = body(constraint, origin);
739+
constraints.retain(|constraint| {
740+
let (edge_changed, retain) = body(constraint);
737741
if edge_changed {
738742
debug!("Updated due to constraint {:?}", constraint);
739743
changed = true;

0 commit comments

Comments
 (0)