Skip to content

Turn a few generics into dynamic dispatch. #592

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

Merged
merged 2 commits into from
Aug 8, 2020

Conversation

crlf0710
Copy link
Member

@crlf0710 crlf0710 commented Aug 5, 2020

Copy link
Member

@jackh726 jackh726 left a comment

Choose a reason for hiding this comment

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

There's a couple different bit here:

  1. The changes to CoherenceSolver and WfSolver, I need to think more about and look at the goals we're generating. We can remove the generics and just take a &dyn Fn "into_solver" with a return of Box<dyn Solver>.
  2. The switch from impl Fn to &dyn Fn to me feels like a necessary evil. It obviously a little less ergonomic, overall the changes are fine.

@@ -131,7 +130,7 @@ impl<I: Interner, S: Solver<I>, SC: Into<S> + Copy> CoherenceSolver<'_, I, S, SC
.negate(interner);

let canonical_goal = &goal.into_closed_goal(interner);
let solution = self.solver_choice.into().solve(self.db, canonical_goal);
let solution = self.solver.solve(self.db, canonical_goal);
Copy link
Member

Choose a reason for hiding this comment

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

So...this is not the same things semantically. Before, we use a fresh solver for each goal. Now, we use a single solver for all goals. Importantly, the solver can (and does) keep some state between goals. It's a bit surprising to me that nothing fails here. (Really, I think the only thing we have to be careful about is placeholders). I think this needs to stay as creating a new solver for each goal, but with some convincing (from myself or otherwise), this could be changed now or later.

@crlf0710
Copy link
Member Author

crlf0710 commented Aug 8, 2020

Updated to make coherence and wf solvers create fresh inner solver every time.

@@ -11,11 +11,10 @@ use std::sync::Arc;
pub mod orphan;
mod solve;

pub struct CoherenceSolver<'db, I: Interner, S, SC: Into<S> + Copy> {
pub struct CoherenceSolver<'db, 'sb, I: Interner> {
Copy link
Member

Choose a reason for hiding this comment

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

I think this (and WfSolver) could just have a single 'a lifetime.

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed! Done.

}
}

pub fn specialization_priorities(
&self,
&mut self,
Copy link
Member

Choose a reason for hiding this comment

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

Why do these need &mut self now?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's no longer needed now. I have changed them back.

@@ -132,12 +132,9 @@ fn orphan_check(db: &dyn LoweringDatabase) -> Result<(), ChalkError> {

tls::set_current_program(&program, || -> Result<(), ChalkError> {
let local_impls = program.local_impl_ids();
let mut solver = db.solver_choice().into_solver();
Copy link
Member

Choose a reason for hiding this comment

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

So to be semantically the same, this should be inside the loop (and then you could just pass the solver by value). But I think we only generate a LocalImplAllowed goal with no placeholders, so this should be fine to reuse.

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've moved it inside the loop for consistency.

pub(super) fn visit_specializations_of_trait(
&self,
&mut self,
Copy link
Member

Choose a reason for hiding this comment

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

Same here: Why now &mut self

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@crlf0710 crlf0710 force-pushed the trait_object_solver branch from 580f89e to 7adf0dc Compare August 8, 2020 05:29
@crlf0710 crlf0710 force-pushed the trait_object_solver branch from 7adf0dc to 251026c Compare August 8, 2020 05:35
@jackh726
Copy link
Member

jackh726 commented Aug 8, 2020

Thanks! @bors r+

@bors
Copy link
Contributor

bors commented Aug 8, 2020

📌 Commit 251026c has been approved by jackh726

@bors
Copy link
Contributor

bors commented Aug 8, 2020

⌛ Testing commit 251026c with merge 35dda89...

@bors
Copy link
Contributor

bors commented Aug 8, 2020

☀️ Test successful - checks-actions
Approved by: jackh726
Pushing 35dda89 to master...

@bors bors merged commit 35dda89 into rust-lang:master Aug 8, 2020
@crlf0710 crlf0710 deleted the trait_object_solver branch August 8, 2020 05:45
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.

Use dyn Solver instead of S: Solver in chalk_solve
3 participants