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

Refactor the recursive solver a bit #487

Merged
merged 8 commits into from
Jun 5, 2020

Conversation

jackh726
Copy link
Member

@jackh726 jackh726 commented Jun 3, 2020

This is about 95% of the work needed to put the recursive solver in a separate crate.

Everything in chalk_solve::recursive::* can get moved. recursive.rs is mostly the equivalent of the slg submodule.

/// Solves a given goal, producing the solution. This will do only
/// as much work towards `goal` as it has to (and that works is
/// cached for future attempts).
pub fn solve(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As sort of a drive-by change, I moved these two functions solve and solve_multiple out of Forest (and chalk-engine) and into chalk_solve::solve. For solve, it honestly just makes more sense, since this is the only place solution is needed. For solve_multiple, there's a little work done here, but really I think these are implementation details akin to aggregate.

pub(crate) infer: InferenceTable<I>,
}

impl<I: Interner> RecursiveInferenceTable<I> for RecursiveInferenceTableImpl<I> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started to wonder if maybe it's worth having this notion of an InferenceTable (as a trait) in chalk_ir. A lot of these functions are also used for slg. Notable differences include invert_then_canonicalize and actually using the free_vars from canonicalize

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the inference code itself should maybe move to chalk-ir, actually, but we should discuss, especially in light of your idea to "invert" the dependency layers.


/// A (possible) solution for a proposed goal.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Solution<I: Interner> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mostly just copied from chalk_solve::solve. But I didn't really think of a good way to handle this. We can make SearchGraph generic over Solution, but Fulfill:solve needs to know about these. I wish it was easier to split out solve from Fulfill (similar to how we split out aggregate from chalk-engine, but the solve function needs to know a lot about the internals of Fulfill that we would have to expose publicly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel.. hmm.. a bit confused about this. I guess I think I would expect this type to potentially be in chalk-ir -- is it really specific to the recursive solver? Don't we use a similar type for SLG? (I guess as the output from aggregation?)

I think my take is that aggregation probably belongs in with the SLG solver in the end, although it is definitely a distinct "layer".

@@ -57,100 +60,6 @@ impl<I: Interner> Solution<I> {
}
}

/// There are multiple candidate solutions, which may or may not agree on
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the other hand (continued from where these are copied to), the fact that several of these functions are only used in the recursive solver makes me wonder if this is mostly okay anyways.

}
#[cfg(feature = "recursive-solver")]
SolverImpl::Recursive(ctx) => ctx.solver(program).solve_root_goal(goal).ok(),
SolverImpl::Recursive(ctx) => {
ctx.solver(program)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But (continued from above still), this is a bit annoying.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.. that is indeed a bit annoying. Nevertheless if what you suggested happens (chalk engine + chalk_recursive depending on chalk solve), this one solver struct can go away correct?

@nikomatsakis nikomatsakis merged commit 93c844d into rust-lang:master Jun 5, 2020
@jackh726 jackh726 deleted the recursive_refactor branch June 5, 2020 21:54
@jackh726 jackh726 restored the recursive_refactor branch December 15, 2020 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants