Skip to content

Conversation

@matklad
Copy link
Contributor

@matklad matklad commented Jan 13, 2020

r? @flodiebold

Trying to paper-over panicking chalk. Not sure if this'll make situation better or worse, but I hope it'll be better, as we won't be tearing down type-inference as a whole

@flodiebold
Copy link
Member

bors r+

bors bot added a commit that referenced this pull request Jan 13, 2020
2818: Don't panic if chalk panics r=flodiebold a=matklad

r? @flodiebold 

Trying to paper-over panicking chalk. Not sure if this'll make situation better or worse, but I hope it'll be better, as we won't be tearing down type-inference as a whole

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
@flodiebold
Copy link
Member

bors r-

@bors
Copy link
Contributor

bors bot commented Jan 13, 2020

Canceled

// chalk sometimes panics, so let's treat this as a no-solution
// situation.
let db = panic::AssertUnwindSafe(db);
match panic::catch_unwind(|| solver.solve(db.0, &u_canonical)) {
Copy link
Member

Choose a reason for hiding this comment

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

hmm, I'm confused, why are we doing the panic handling twice? isn't this just calling the solve method above which already catches panics?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

match self.inner.lock() handles poisoning, panic::catch_unwind handles panics.

Overall, there are four cases here:

  • happy path: everyting works, no cancellation happens
  • cancellation: solution is Err(cancelled), and we need to re-raise this panic (panic::resume_unwind(err))
  • an already cancelled request: we try to lock chalk, but the mutex is poisoned. It is poisoned because some other thread got cancelled, and unwound past the mutex guard. Here, we need to initiate unwinding on the current thread Err(_) => ra_db::Canceled::throw()
  • chalk panicked. We need to reset the solver *solver = create_chalk_solver();

At least, I think this is what happens here, I've re-written this like five times, putting catch_unwind in different places. One invariant we have here is that if the mutex is poisoned, it is poisoned because of the cancellation.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, but there's two catch_unwinds -- the one here and the one above in TraitSolver::solve, which is just what we're calling here, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤦‍♂️ that's... actually the remains of one of those five attempts.

Excellent catch!

@flodiebold
Copy link
Member

bors r+

@lnicola
Copy link
Member

lnicola commented Jan 13, 2020

bors seems stuck again.

@matklad
Copy link
Contributor Author

matklad commented Jan 13, 2020

bors r+

bors bot added a commit that referenced this pull request Jan 13, 2020
2818: Don't panic if chalk panics r=matklad a=matklad

r? @flodiebold 

Trying to paper-over panicking chalk. Not sure if this'll make situation better or worse, but I hope it'll be better, as we won't be tearing down type-inference as a whole

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
@bors
Copy link
Contributor

bors bot commented Jan 13, 2020

Build succeeded

  • Rust (macos-latest)
  • Rust (ubuntu-latest)
  • Rust (windows-latest)
  • TypeScript

@bors bors bot merged commit 5654387 into rust-lang:master Jan 13, 2020
@matklad matklad deleted the dont-panic branch January 29, 2020 10:24
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