Skip to content

Commit cb40c25

Browse files
committed
Auto merge of #156139 - inq:minimize-reshell-perf, r=lcnr
Short-circuit `calculate_fallback_to_f32` when no float vars Sharing a small fix. When no unresolved variable is a `float_vid`, no f32 fallback can apply, so we can skip `from_float_for_f32_root_vids` (which walks the proof tree of every pending obligation under the new solver — O(N × M) on crates with many large obligations). On ReShell: stage1 wall-clock 2m35s → 1m46s (-49s, ~31%). Context + profile breakdown will be linked at rust-lang/trait-system-refactor-initiative#254 after this PR opens. r? @lcnr
2 parents 1d72d7e + 55ff2e1 commit cb40c25

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

compiler/rustc_hir_typeck/src/fallback.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
147147
/// foo(1.0);
148148
/// ```
149149
fn calculate_fallback_to_f32(&self, unresolved_variables: &[Ty<'tcx>]) -> UnordSet<FloatVid> {
150+
// Short-circuit: if no unresolved variable is a float, no f32 fallback can apply,
151+
// so we can skip the (potentially very expensive) work in `from_float_for_f32_root_vids`.
152+
// Under the new solver, that function walks `visit_proof_tree` for every pending
153+
// obligation, which is O(N × proof_tree_size) and can dominate type-checking on crates
154+
// with many large pending obligations and no f32 involvement.
155+
if unresolved_variables.iter().all(|ty| ty.float_vid().is_none()) {
156+
return UnordSet::new();
157+
}
150158
let roots: UnordSet<ty::FloatVid> = self.from_float_for_f32_root_vids();
151159
if roots.is_empty() {
152160
// Most functions have no `f32: From<{float}>` predicates, so short-circuit and return

0 commit comments

Comments
 (0)