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

Add integration test for unwind safety #407

Closed

Conversation

marmeladema
Copy link
Contributor

@marmeladema marmeladema commented Apr 19, 2020

This currently does not work because when the panic triggers, the solver lock is poisoned and i am not aware of a way to force un-poisoning it.

One approach that i've tried and that work, is to lock the solver outside of catch_unwind but this requires to use AssertUnwindSafe to use the lock guard inside catch_unwind and that kind of defeats the whole purpose of that test.

Fixes #260

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.

Some guidance


#[derive(Debug, Default)]
struct MockDatabase {
chalk_db: ChalkDatabase,
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we actually want to wrap an actual database.

}
}

impl RustIrDatabase<ChalkIr> for MockDatabase {
Copy link
Member

Choose a reason for hiding this comment

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

For these methods, I was thinking just hardcode what we want to return for trait Foo and struct Bar

use std::panic;

// lower program
let mut db = lower_program_with_db! {
Copy link
Member

Choose a reason for hiding this comment

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

So, we won't actually "lower" anything, it'll just be hardcoded.

let program = db.chalk_db.checked_program().unwrap();

// lower goal
let goal = lower_goal! {
Copy link
Member

Choose a reason for hiding this comment

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

Similarly here. We aren't going to "lower" this, we'll just manually create the UCanonicalGoalInEnvironment for Foo: Bar

Comment on lines +150 to +159
// solve goal but this will panic
db.panic = true;
let result = panic::catch_unwind(|| {
db.solve(&peeled_goal);
});
assert!(result.is_err() == true);

// solve again but without panicking this time
db.panic = false;
assert!(db.solve(&peeled_goal).is_some());
Copy link
Member

Choose a reason for hiding this comment

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

This is exactly what I was thinking :)

@@ -1,15 +1,35 @@
#![allow(unused_macros)]

macro_rules! lowering_success {
(program $program:tt) => {
macro_rules! lower_program_with_db {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we want to change/use anything here.

@jackh726
Copy link
Member

Closing in favor of #462

Thanks for the initial work here though :)

@jackh726 jackh726 closed this May 20, 2020
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.

Make chalk_solve::Solver UnwindSafe
2 participants