Skip to content

Commit 2e8db5e

Browse files
committed
Auto merge of #130281 - matthiaskrgr:rollup-1b2ibs8, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #130101 (some const cleanup: remove unnecessary attributes, add const-hack indications) - #130208 (Introduce `'ra` lifetime name.) - #130263 (coverage: Simplify creation of sum counters) - #130273 (more eagerly discard constraints on overflow) - #130276 (Add test for nalgebra hang in coherence) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8c0ec05 + ed1602e commit 2e8db5e

File tree

42 files changed

+596
-621
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+596
-621
lines changed

compiler/rustc_mir_transform/src/coverage/counters.rs

+27-33
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,14 @@ impl CoverageCounters {
155155
BcbCounter::Expression { id }
156156
}
157157

158-
/// Variant of `make_expression` that makes `lhs` optional and assumes [`Op::Add`].
158+
/// Creates a counter that is the sum of the given counters.
159159
///
160-
/// This is useful when using [`Iterator::fold`] to build an arbitrary-length sum.
161-
fn make_sum_expression(&mut self, lhs: Option<BcbCounter>, rhs: BcbCounter) -> BcbCounter {
162-
let Some(lhs) = lhs else { return rhs };
163-
self.make_expression(lhs, Op::Add, rhs)
160+
/// Returns `None` if the given list of counters was empty.
161+
fn make_sum(&mut self, counters: &[BcbCounter]) -> Option<BcbCounter> {
162+
counters
163+
.iter()
164+
.copied()
165+
.reduce(|accum, counter| self.make_expression(accum, Op::Add, counter))
164166
}
165167

166168
pub(super) fn num_counters(&self) -> usize {
@@ -315,20 +317,17 @@ impl<'a> MakeBcbCounters<'a> {
315317
// For each out-edge other than the one that was chosen to get an expression,
316318
// ensure that it has a counter (existing counter/expression or a new counter),
317319
// and accumulate the corresponding counters into a single sum expression.
318-
let sum_of_all_other_out_edges: BcbCounter = {
319-
let _span = debug_span!("sum_of_all_other_out_edges", ?expression_to_bcb).entered();
320-
successors
321-
.iter()
322-
.copied()
323-
// Skip the chosen edge, since we'll calculate its count from this sum.
324-
.filter(|&to_bcb| to_bcb != expression_to_bcb)
325-
.fold(None, |accum, to_bcb| {
326-
let _span = debug_span!("to_bcb", ?accum, ?to_bcb).entered();
327-
let edge_counter = self.get_or_make_edge_counter(from_bcb, to_bcb);
328-
Some(self.coverage_counters.make_sum_expression(accum, edge_counter))
329-
})
330-
.expect("there must be at least one other out-edge")
331-
};
320+
let other_out_edge_counters = successors
321+
.iter()
322+
.copied()
323+
// Skip the chosen edge, since we'll calculate its count from this sum.
324+
.filter(|&to_bcb| to_bcb != expression_to_bcb)
325+
.map(|to_bcb| self.get_or_make_edge_counter(from_bcb, to_bcb))
326+
.collect::<Vec<_>>();
327+
let sum_of_all_other_out_edges: BcbCounter = self
328+
.coverage_counters
329+
.make_sum(&other_out_edge_counters)
330+
.expect("there must be at least one other out-edge");
332331

333332
// Now create an expression for the chosen edge, by taking the counter
334333
// for its source node and subtracting the sum of its sibling out-edges.
@@ -375,20 +374,15 @@ impl<'a> MakeBcbCounters<'a> {
375374

376375
// A BCB with multiple incoming edges can compute its count by ensuring that counters
377376
// exist for each of those edges, and then adding them up to get a total count.
378-
let sum_of_in_edges: BcbCounter = {
379-
let _span = debug_span!("sum_of_in_edges", ?bcb).entered();
380-
// We avoid calling `self.bcb_predecessors` here so that we can
381-
// call methods on `&mut self` inside the fold.
382-
self.basic_coverage_blocks.predecessors[bcb]
383-
.iter()
384-
.copied()
385-
.fold(None, |accum, from_bcb| {
386-
let _span = debug_span!("from_bcb", ?accum, ?from_bcb).entered();
387-
let edge_counter = self.get_or_make_edge_counter(from_bcb, bcb);
388-
Some(self.coverage_counters.make_sum_expression(accum, edge_counter))
389-
})
390-
.expect("there must be at least one in-edge")
391-
};
377+
let in_edge_counters = self.basic_coverage_blocks.predecessors[bcb]
378+
.iter()
379+
.copied()
380+
.map(|from_bcb| self.get_or_make_edge_counter(from_bcb, bcb))
381+
.collect::<Vec<_>>();
382+
let sum_of_in_edges: BcbCounter = self
383+
.coverage_counters
384+
.make_sum(&in_edge_counters)
385+
.expect("there must be at least one in-edge");
392386

393387
debug!("{bcb:?} gets a new counter (sum of predecessor counters): {sum_of_in_edges:?}");
394388
self.coverage_counters.set_bcb_counter(bcb, sum_of_in_edges)

compiler/rustc_mir_transform/src/pass_manager.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn to_profiler_name(type_name: &'static str) -> &'static str {
4242

4343
// const wrapper for `if let Some((_, tail)) = name.rsplit_once(':') { tail } else { name }`
4444
const fn c_name(name: &'static str) -> &'static str {
45-
// FIXME Simplify the implementation once more `str` methods get const-stable.
45+
// FIXME(const-hack) Simplify the implementation once more `str` methods get const-stable.
4646
// and inline into call site
4747
let bytes = name.as_bytes();
4848
let mut i = bytes.len();
@@ -61,7 +61,7 @@ const fn c_name(name: &'static str) -> &'static str {
6161
/// loop that goes over each available MIR and applies `run_pass`.
6262
pub(super) trait MirPass<'tcx> {
6363
fn name(&self) -> &'static str {
64-
// FIXME Simplify the implementation once more `str` methods get const-stable.
64+
// FIXME(const-hack) Simplify the implementation once more `str` methods get const-stable.
6565
// See copypaste in `MirLint`
6666
const {
6767
let name = std::any::type_name::<Self>();
@@ -89,7 +89,7 @@ pub(super) trait MirPass<'tcx> {
8989
/// disabled (via the `Lint` adapter).
9090
pub(super) trait MirLint<'tcx> {
9191
fn name(&self) -> &'static str {
92-
// FIXME Simplify the implementation once more `str` methods get const-stable.
92+
// FIXME(const-hack) Simplify the implementation once more `str` methods get const-stable.
9393
// See copypaste in `MirPass`
9494
const {
9595
let name = std::any::type_name::<Self>();

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/canonical.rs

+15
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,21 @@ where
122122
(certainty, NestedNormalizationGoals::empty())
123123
};
124124

125+
if let Certainty::Maybe(cause @ MaybeCause::Overflow { .. }) = certainty {
126+
// If we have overflow, it's probable that we're substituting a type
127+
// into itself infinitely and any partial substitutions in the query
128+
// response are probably not useful anyways, so just return an empty
129+
// query response.
130+
//
131+
// This may prevent us from potentially useful inference, e.g.
132+
// 2 candidates, one ambiguous and one overflow, which both
133+
// have the same inference constraints.
134+
//
135+
// Changing this to retain some constraints in the future
136+
// won't be a breaking change, so this is good enough for now.
137+
return Ok(self.make_ambiguous_response_no_constraints(cause));
138+
}
139+
125140
let external_constraints =
126141
self.compute_external_query_constraints(certainty, normalization_nested_goals);
127142
let (var_values, mut external_constraints) = (self.var_values, external_constraints)

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs

+7-26
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::delegate::SolverDelegate;
1717
use crate::solve::inspect::{self, ProofTreeBuilder};
1818
use crate::solve::search_graph::SearchGraph;
1919
use crate::solve::{
20-
CanonicalInput, CanonicalResponse, Certainty, Goal, GoalEvaluationKind, GoalSource, MaybeCause,
20+
CanonicalInput, CanonicalResponse, Certainty, Goal, GoalEvaluationKind, GoalSource,
2121
NestedNormalizationGoals, NoSolution, PredefinedOpaquesData, QueryResult, SolverMode,
2222
FIXPOINT_STEP_LIMIT,
2323
};
@@ -370,20 +370,19 @@ where
370370
canonical_goal,
371371
&mut goal_evaluation,
372372
);
373-
let canonical_response = match canonical_response {
373+
let response = match canonical_response {
374374
Err(e) => {
375375
self.inspect.goal_evaluation(goal_evaluation);
376376
return Err(e);
377377
}
378378
Ok(response) => response,
379379
};
380380

381-
let (normalization_nested_goals, certainty, has_changed) = self
382-
.instantiate_response_discarding_overflow(
383-
goal.param_env,
384-
orig_values,
385-
canonical_response,
386-
);
381+
let has_changed = !response.value.var_values.is_identity_modulo_regions()
382+
|| !response.value.external_constraints.opaque_types.is_empty();
383+
384+
let (normalization_nested_goals, certainty) =
385+
self.instantiate_and_apply_query_response(goal.param_env, orig_values, response);
387386
self.inspect.goal_evaluation(goal_evaluation);
388387
// FIXME: We previously had an assert here that checked that recomputing
389388
// a goal after applying its constraints did not change its response.
@@ -398,24 +397,6 @@ where
398397
Ok((normalization_nested_goals, has_changed, certainty))
399398
}
400399

401-
fn instantiate_response_discarding_overflow(
402-
&mut self,
403-
param_env: I::ParamEnv,
404-
original_values: Vec<I::GenericArg>,
405-
response: CanonicalResponse<I>,
406-
) -> (NestedNormalizationGoals<I>, Certainty, bool) {
407-
if let Certainty::Maybe(MaybeCause::Overflow { .. }) = response.value.certainty {
408-
return (NestedNormalizationGoals::empty(), response.value.certainty, false);
409-
}
410-
411-
let has_changed = !response.value.var_values.is_identity_modulo_regions()
412-
|| !response.value.external_constraints.opaque_types.is_empty();
413-
414-
let (normalization_nested_goals, certainty) =
415-
self.instantiate_and_apply_query_response(param_env, original_values, response);
416-
(normalization_nested_goals, certainty, has_changed)
417-
}
418-
419400
fn compute_goal(&mut self, goal: Goal<I, I::Predicate>) -> QueryResult<I> {
420401
let Goal { param_env, predicate } = goal;
421402
let kind = predicate.kind();

0 commit comments

Comments
 (0)