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

Return Result in accessors instead of panic #286

Merged
merged 5 commits into from
Aug 18, 2023

Conversation

Danacus
Copy link
Contributor

@Danacus Danacus commented Aug 17, 2023

As previously suggested in #274, I replaced the .expect with returning a Result in the operation accessors of ODS generated dialects.

I also added some variants to the Error enum to support this. The Infallible variant was added to allow using TryInto to convert Attribute into itself, such that we avoid needing to handle Attribute differently from StringAttribute, IntAttribute, etc. But if you prefer, I can change the macro code to deal with this case instead, I'm honestly not a big fan of my Infallible hack either.

Copy link
Member

@raviqqe raviqqe left a comment

Choose a reason for hiding this comment

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

Thank you for the changes! I just put a few comments. I think it's fine to use the Infallible type as long as we can remove the glue code in the future version of Rust.

Comment on lines 76 to 78
Self::Infallible => {
write!(formatter, "infallible")
}
Copy link
Member

Choose a reason for hiding this comment

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

Can we emulate type Infallible = ! as described in the std library documentation by removing this and panic on conversion?

Suggested change
Self::Infallible => {
write!(formatter, "infallible")
}

RunPass,
TypeExpected(&'static str, String),
UnknownDiagnosticSeverity(u32),
Utf8(Utf8Error),
Infallible,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Infallible,


impl From<Infallible> for Error {
fn from(_: Infallible) -> Self {
Self::Infallible
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Self::Infallible
unreachable!()

@raviqqe raviqqe enabled auto-merge (squash) August 18, 2023 10:40
@raviqqe
Copy link
Member

raviqqe commented Aug 18, 2023

Thank you for the changes again!

@raviqqe raviqqe merged commit a5f68f8 into mlir-rs:main Aug 18, 2023
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.

2 participants