Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Box<[T]> for ProcessResult::Changed #121355

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_data_structures/src/obligation_forest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ pub trait ObligationProcessor {
#[derive(Debug)]
pub enum ProcessResult<O, E> {
Unchanged,
Changed(Vec<O>),
Changed(Box<[O]>),
Error(E),
}

Expand Down Expand Up @@ -463,7 +463,7 @@ impl<O: ForestObligation> ObligationForest<O> {
has_changed = true;
node.state.set(NodeState::Success);

for child in children {
for child in children.into_vec() {
let st = self.register_obligation_at(child, Some(index));
if let Err(()) = st {
// Error already reported - propagate it
Expand Down
66 changes: 34 additions & 32 deletions compiler/rustc_data_structures/src/obligation_forest/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ fn push_pop() {
// |-> A.3
let TestOutcome { completed: ok, errors: err, .. } = forest.process_obligations(&mut C(
|obligation| match *obligation {
"A" => ProcessResult::Changed(vec!["A.1", "A.2", "A.3"]),
"A" => ProcessResult::Changed(Box::new(["A.1", "A.2", "A.3"])),
"B" => ProcessResult::Error("B is for broken"),
"C" => ProcessResult::Changed(vec![]),
"C" => ProcessResult::Changed(Box::new([])),
"A.1" | "A.2" | "A.3" => ProcessResult::Unchanged,
_ => unreachable!(),
},
Expand All @@ -123,8 +123,8 @@ fn push_pop() {
|obligation| match *obligation {
"A.1" => ProcessResult::Unchanged,
"A.2" => ProcessResult::Unchanged,
"A.3" => ProcessResult::Changed(vec!["A.3.i"]),
"D" => ProcessResult::Changed(vec!["D.1", "D.2"]),
"A.3" => ProcessResult::Changed(Box::new(["A.3.i"])),
"D" => ProcessResult::Changed(Box::new(["D.1", "D.2"])),
"A.3.i" | "D.1" | "D.2" => ProcessResult::Unchanged,
_ => unreachable!(),
},
Expand All @@ -139,11 +139,11 @@ fn push_pop() {
// |-> D.2 |-> D.2.i
let TestOutcome { completed: ok, errors: err, .. } = forest.process_obligations(&mut C(
|obligation| match *obligation {
"A.1" => ProcessResult::Changed(vec![]),
"A.1" => ProcessResult::Changed(Box::new([])),
"A.2" => ProcessResult::Error("A is for apple"),
"A.3.i" => ProcessResult::Changed(vec![]),
"D.1" => ProcessResult::Changed(vec!["D.1.i"]),
"D.2" => ProcessResult::Changed(vec!["D.2.i"]),
"A.3.i" => ProcessResult::Changed(Box::new([])),
"D.1" => ProcessResult::Changed(Box::new(["D.1.i"])),
"D.2" => ProcessResult::Changed(Box::new(["D.2.i"])),
"D.1.i" | "D.2.i" => ProcessResult::Unchanged,
_ => unreachable!(),
},
Expand All @@ -158,7 +158,7 @@ fn push_pop() {
let TestOutcome { completed: ok, errors: err, .. } = forest.process_obligations(&mut C(
|obligation| match *obligation {
"D.1.i" => ProcessResult::Error("D is for dumb"),
"D.2.i" => ProcessResult::Changed(vec![]),
"D.2.i" => ProcessResult::Changed(Box::new([])),
_ => panic!("unexpected obligation {:?}", obligation),
},
|_| {},
Expand All @@ -184,10 +184,10 @@ fn success_in_grandchildren() {

let TestOutcome { completed: ok, errors: err, .. } = forest.process_obligations(&mut C(
|obligation| match *obligation {
"A" => ProcessResult::Changed(vec!["A.1", "A.2", "A.3"]),
"A.1" => ProcessResult::Changed(vec![]),
"A.2" => ProcessResult::Changed(vec!["A.2.i", "A.2.ii"]),
"A.3" => ProcessResult::Changed(vec![]),
"A" => ProcessResult::Changed(Box::new(["A.1", "A.2", "A.3"])),
"A.1" => ProcessResult::Changed(Box::new([])),
"A.2" => ProcessResult::Changed(Box::new(["A.2.i", "A.2.ii"])),
"A.3" => ProcessResult::Changed(Box::new([])),
"A.2.i" | "A.2.ii" => ProcessResult::Unchanged,
_ => unreachable!(),
},
Expand All @@ -201,7 +201,7 @@ fn success_in_grandchildren() {
let TestOutcome { completed: ok, errors: err, .. } = forest.process_obligations(&mut C(
|obligation| match *obligation {
"A.2.i" => ProcessResult::Unchanged,
"A.2.ii" => ProcessResult::Changed(vec![]),
"A.2.ii" => ProcessResult::Changed(Box::new([])),
_ => unreachable!(),
},
|_| {},
Expand All @@ -211,7 +211,7 @@ fn success_in_grandchildren() {

let TestOutcome { completed: ok, errors: err, .. } = forest.process_obligations(&mut C(
|obligation| match *obligation {
"A.2.i" => ProcessResult::Changed(vec!["A.2.i.a"]),
"A.2.i" => ProcessResult::Changed(Box::new(["A.2.i.a"])),
"A.2.i.a" => ProcessResult::Unchanged,
_ => unreachable!(),
},
Expand All @@ -222,7 +222,7 @@ fn success_in_grandchildren() {

let TestOutcome { completed: ok, errors: err, .. } = forest.process_obligations(&mut C(
|obligation| match *obligation {
"A.2.i.a" => ProcessResult::Changed(vec![]),
"A.2.i.a" => ProcessResult::Changed(Box::new([])),
_ => unreachable!(),
},
|_| {},
Expand All @@ -247,7 +247,7 @@ fn to_errors_no_throw() {
forest.register_obligation("A");
let TestOutcome { completed: ok, errors: err, .. } = forest.process_obligations(&mut C(
|obligation| match *obligation {
"A" => ProcessResult::Changed(vec!["A.1", "A.2", "A.3"]),
"A" => ProcessResult::Changed(Box::new(["A.1", "A.2", "A.3"])),
"A.1" | "A.2" | "A.3" => ProcessResult::Unchanged,
_ => unreachable!(),
},
Expand All @@ -269,7 +269,7 @@ fn diamond() {
forest.register_obligation("A");
let TestOutcome { completed: ok, errors: err, .. } = forest.process_obligations(&mut C(
|obligation| match *obligation {
"A" => ProcessResult::Changed(vec!["A.1", "A.2"]),
"A" => ProcessResult::Changed(Box::new(["A.1", "A.2"])),
"A.1" | "A.2" => ProcessResult::Unchanged,
_ => unreachable!(),
},
Expand All @@ -280,8 +280,8 @@ fn diamond() {

let TestOutcome { completed: ok, errors: err, .. } = forest.process_obligations(&mut C(
|obligation| match *obligation {
"A.1" => ProcessResult::Changed(vec!["D"]),
"A.2" => ProcessResult::Changed(vec!["D"]),
"A.1" => ProcessResult::Changed(Box::new(["D"])),
"A.2" => ProcessResult::Changed(Box::new(["D"])),
"D" => ProcessResult::Unchanged,
_ => unreachable!(),
},
Expand All @@ -295,7 +295,7 @@ fn diamond() {
|obligation| match *obligation {
"D" => {
d_count += 1;
ProcessResult::Changed(vec![])
ProcessResult::Changed(Box::new([]))
}
_ => unreachable!(),
},
Expand All @@ -313,7 +313,7 @@ fn diamond() {
forest.register_obligation("A'");
let TestOutcome { completed: ok, errors: err, .. } = forest.process_obligations(&mut C(
|obligation| match *obligation {
"A'" => ProcessResult::Changed(vec!["A'.1", "A'.2"]),
"A'" => ProcessResult::Changed(Box::new(["A'.1", "A'.2"])),
"A'.1" | "A'.2" => ProcessResult::Unchanged,
_ => unreachable!(),
},
Expand All @@ -324,8 +324,8 @@ fn diamond() {

let TestOutcome { completed: ok, errors: err, .. } = forest.process_obligations(&mut C(
|obligation| match *obligation {
"A'.1" => ProcessResult::Changed(vec!["D'", "A'"]),
"A'.2" => ProcessResult::Changed(vec!["D'"]),
"A'.1" => ProcessResult::Changed(Box::new(["D'", "A'"])),
"A'.2" => ProcessResult::Changed(Box::new(["D'"])),
"D'" | "A'" => ProcessResult::Unchanged,
_ => unreachable!(),
},
Expand Down Expand Up @@ -366,7 +366,7 @@ fn done_dependency() {

let TestOutcome { completed: ok, errors: err, .. } = forest.process_obligations(&mut C(
|obligation| match *obligation {
"A: Sized" | "B: Sized" | "C: Sized" => ProcessResult::Changed(vec![]),
"A: Sized" | "B: Sized" | "C: Sized" => ProcessResult::Changed(Box::new([])),
_ => unreachable!(),
},
|_| {},
Expand All @@ -379,7 +379,9 @@ fn done_dependency() {
forest.register_obligation("(A,B,C): Sized");
let TestOutcome { completed: ok, errors: err, .. } = forest.process_obligations(&mut C(
|obligation| match *obligation {
"(A,B,C): Sized" => ProcessResult::Changed(vec!["A: Sized", "B: Sized", "C: Sized"]),
"(A,B,C): Sized" => {
ProcessResult::Changed(Box::new(["A: Sized", "B: Sized", "C: Sized"]))
}
_ => unreachable!(),
},
|_| {},
Expand All @@ -399,10 +401,10 @@ fn orphan() {

let TestOutcome { completed: ok, errors: err, .. } = forest.process_obligations(&mut C(
|obligation| match *obligation {
"A" => ProcessResult::Changed(vec!["D", "E"]),
"A" => ProcessResult::Changed(Box::new(["D", "E"])),
"B" => ProcessResult::Unchanged,
"C1" => ProcessResult::Changed(vec![]),
"C2" => ProcessResult::Changed(vec![]),
"C1" => ProcessResult::Changed(Box::new([])),
"C2" => ProcessResult::Changed(Box::new([])),
"D" | "E" => ProcessResult::Unchanged,
_ => unreachable!(),
},
Expand All @@ -416,7 +418,7 @@ fn orphan() {
let TestOutcome { completed: ok, errors: err, .. } = forest.process_obligations(&mut C(
|obligation| match *obligation {
"D" | "E" => ProcessResult::Unchanged,
"B" => ProcessResult::Changed(vec!["D"]),
"B" => ProcessResult::Changed(Box::new(["D"])),
_ => unreachable!(),
},
|_| {},
Expand Down Expand Up @@ -459,7 +461,7 @@ fn simultaneous_register_and_error() {
let TestOutcome { completed: ok, errors: err, .. } = forest.process_obligations(&mut C(
|obligation| match *obligation {
"A" => ProcessResult::Error("An error"),
"B" => ProcessResult::Changed(vec!["A"]),
"B" => ProcessResult::Changed(Box::new(["A"])),
_ => unreachable!(),
},
|_| {},
Expand All @@ -474,7 +476,7 @@ fn simultaneous_register_and_error() {
let TestOutcome { completed: ok, errors: err, .. } = forest.process_obligations(&mut C(
|obligation| match *obligation {
"A" => ProcessResult::Error("An error"),
"B" => ProcessResult::Changed(vec!["A"]),
"B" => ProcessResult::Changed(Box::new(["A"])),
_ => unreachable!(),
},
|_| {},
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_trait_selection/src/traits/fulfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> {
) -> ProcessResult<PendingPredicateObligation<'tcx>, !> {
assert!(self.needs_process_obligation(pending_obligation));
self.removed_predicates.push(pending_obligation.obligation.clone());
ProcessResult::Changed(vec![])
ProcessResult::Changed(Box::new([]))
}

fn process_backedge<'c, I>(
Expand All @@ -207,7 +207,7 @@ struct FulfillProcessor<'a, 'tcx> {
selcx: SelectionContext<'a, 'tcx>,
}

fn mk_pending(os: Vec<PredicateObligation<'_>>) -> Vec<PendingPredicateObligation<'_>> {
fn mk_pending(os: Vec<PredicateObligation<'_>>) -> Box<[PendingPredicateObligation<'_>]> {
os.into_iter()
.map(|o| PendingPredicateObligation { obligation: o, stalled_on: vec![] })
.collect()
Expand Down Expand Up @@ -386,7 +386,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
infcx.region_outlives_predicate(&obligation.cause, Binder::dummy(data));
}

ProcessResult::Changed(vec![])
ProcessResult::Changed(Box::new([]))
}

ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(
Expand All @@ -396,7 +396,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
if infcx.considering_regions {
infcx.register_region_obligation_with_cause(t_a, r_b, &obligation.cause);
}
ProcessResult::Changed(vec![])
ProcessResult::Changed(Box::new([]))
}

ty::PredicateKind::Clause(ty::ClauseKind::Projection(ref data)) => {
Expand All @@ -413,7 +413,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
if !self.selcx.tcx().check_is_object_safe(trait_def_id) {
ProcessResult::Error(FulfillmentErrorCode::SelectionError(Unimplemented))
} else {
ProcessResult::Changed(vec![])
ProcessResult::Changed(Box::new([]))
}
}

Expand Down Expand Up @@ -535,7 +535,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
obligation.param_env,
obligation.cause.span,
) {
Ok(()) => ProcessResult::Changed(vec![]),
Ok(()) => ProcessResult::Changed(Box::new([])),
Err(NotConstEvaluatable::MentionsInfer) => {
pending_obligation.stalled_on.clear();
pending_obligation.stalled_on.extend(
Expand Down Expand Up @@ -706,7 +706,7 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
"selecting trait at depth {} evaluated to holds",
obligation.recursion_depth
);
return ProcessResult::Changed(vec![]);
return ProcessResult::Changed(Box::new([]));
}
}

Expand Down Expand Up @@ -770,7 +770,7 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
.projection_cache()
.complete(key, EvaluationResult::EvaluatedToOk);
}
return ProcessResult::Changed(vec![]);
return ProcessResult::Changed(Box::new([]));
} else {
debug!("Does NOT hold: {:?}", obligation);
}
Expand Down