Skip to content

Commit

Permalink
Auto merge of #645 - LeSeulArtichaut:visitor-controlflow, r=jackh726
Browse files Browse the repository at this point in the history
Use `ControlFlow` in `Visitor`

This PR (almost) resolves one of the differences between rustc's `TypeVisitor` and chalk's `Visitor` by adopting rustc's design with `std::ops::ControlFlow`.

However as `std::ops::ControlFlow` is still unstable, this PR defines a duplicate of `ControlFlow` in `chalk_ir` along with a `try_break!` macro which behaves like `try!`.
  • Loading branch information
bors committed Nov 5, 2020
2 parents 1c91d87 + c3d0a61 commit f2e3fd9
Show file tree
Hide file tree
Showing 14 changed files with 331 additions and 358 deletions.
14 changes: 5 additions & 9 deletions chalk-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,7 @@ fn derive_any_visit(

let body = s.each(|bi| {
quote! {
result = result.combine(::chalk_ir::visit::Visit::visit_with(#bi, visitor, outer_binder));
if result.return_early() {
return result;
}
::chalk_ir::try_break!(::chalk_ir::visit::Visit::visit_with(#bi, visitor, outer_binder));
}
});

Expand All @@ -178,19 +175,18 @@ fn derive_any_visit(
s.bound_impl(
quote!(::chalk_ir::visit:: #trait_name <#interner>),
quote! {
fn #method_name <'i, R: ::chalk_ir::visit::VisitResult>(
fn #method_name <'i>(
&self,
visitor: &mut dyn ::chalk_ir::visit::Visitor < 'i, #interner, Result = R >,
visitor: &mut dyn ::chalk_ir::visit::Visitor < 'i, #interner >,
outer_binder: ::chalk_ir::DebruijnIndex,
) -> R
) -> ::chalk_ir::visit::ControlFlow<()>
where
#interner: 'i
{
let mut result = R::new();
match *self {
#body
}
return result;
::chalk_ir::visit::ControlFlow::CONTINUE
}
},
)
Expand Down
2 changes: 1 addition & 1 deletion chalk-engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ use std::usize;

use chalk_derive::{Fold, HasInterner, Visit};
use chalk_ir::interner::Interner;
use chalk_ir::visit::VisitResult;
use chalk_ir::visit::ControlFlow;
use chalk_ir::{
AnswerSubst, Canonical, ConstrainedSubst, Constraint, DebruijnIndex, Goal, InEnvironment,
Substitution,
Expand Down
2 changes: 1 addition & 1 deletion chalk-ir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern crate self as chalk_ir;
use crate::cast::{Cast, CastTo, Caster};
use crate::fold::shift::Shift;
use crate::fold::{Fold, Folder, Subst, SuperFold};
use crate::visit::{SuperVisit, Visit, VisitExt, VisitResult, Visitor};
use crate::visit::{ControlFlow, SuperVisit, Visit, VisitExt, Visitor};
use chalk_derive::{Fold, HasInterner, SuperVisit, Visit, Zip};
use std::marker::PhantomData;

Expand Down
Loading

0 comments on commit f2e3fd9

Please sign in to comment.