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

API: Wrap *Kind enums in *Kind enums #244

Merged
merged 7 commits into from Sep 17, 2023

Conversation

xFrednet
Copy link
Member

@xFrednet xFrednet commented Sep 15, 2023

The current API has a few spots where a *Kind enum directly wraps a *Kind enum, like: PatKind::Lit. This is cool, for matching but causes a bunch of problems when it comes to common data shared among the outer *Kind enum. To be future-proof and have this consistent in the entire API, I've now wrapped the inner *Kind values in new structs.

These structs are often just wrappers, but will help us in the future. This will help me a lot with #242

Most of the changes are just uilint tests.

@xFrednet xFrednet added C-documentation Category: Improvements or additions to documentation A-api Area: Stable API D-rustc-driver Driver: Rustc Driver A-driver Area: Driver or something related to the internal working of a driver. I-api-break Issue: This change will break the public API labels Sep 15, 2023
@xFrednet xFrednet added this to the v0.3.0 milestone Sep 15, 2023
marker_api/src/ast/expr.rs Outdated Show resolved Hide resolved
marker_api/src/ast/pat/lit_pat.rs Outdated Show resolved Hide resolved
marker_api/src/ast/stmt.rs Show resolved Hide resolved
marker_api/src/ast/stmt.rs Show resolved Hide resolved
Comment on lines 193 to 198
#[cfg(feature = "driver-api")]
impl<'ast> ItemStmt<'ast> {
pub fn new(data: CommonStmtData<'ast>, item: ItemKind<'ast>) -> Self {
Self { data, item }
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could it make sense to just mark the fields of the structs conditionally pub instead?

Copy link
Member Author

@xFrednet xFrednet Sep 16, 2023

Choose a reason for hiding this comment

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

The visibility crate sadly doesn't work on field structs. Otherwise, that could be an option. I considered adding something like impl_new to cfg derive these things. I was a bit hesitant with Marker's FFI types, but I just saw that it uses impl Into<Ty> that could actually work 🤔

Edit: https://docs.rs/derive-new/0.5.9/derive_new/ is probably the safer choice, since impl_new is very new. Let's hope that one also has the Into<> thing 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't add a proc macro dependency to marker_api. I love the fact that it can be a zero dependency crate, meaning the lint crates can also be effectively zero-dep (except for marker_api), and compile blazingly fast

Copy link
Member Author

Choose a reason for hiding this comment

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

The macro would only be needed when it's compiled with the driver-api feature, so it would remain zero-dep :D

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, right!

Copy link
Member Author

@xFrednet xFrednet Sep 16, 2023

Choose a reason for hiding this comment

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

I'm undecided on this one. impl_new looks great but only has a total of 102 downloads. derive-new is from @nrc but doesn't seem to support Into<X> parameters, which is important for marker. It also doesn't seem like the crate isn't actively maintained, when I look at the issue tracker 🤔

Created: nrc/derive-new#62

Copy link
Contributor

@Veetaha Veetaha Sep 17, 2023

Choose a reason for hiding this comment

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

I'd recommend you to use either typed-builder, for more elaborate cases: buildstructor.

typed-builder has support for impl Into via #[builder(setter(into))] (opt-in), and buildstructor just slaps impl Into automatically (opt-out).

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'll try using typed-builder instead of the newly added constructors, wish me luck!

Copy link
Member Author

@xFrednet xFrednet Sep 17, 2023

Choose a reason for hiding this comment

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

It seems to work quite well. I won't update everything rn, but I'll keep the dependency and use it for new types :)

Here are the changes: 367cfb5

Looks like Clippy doesn't like it though :/ I'll allow the lint and create an issue

idanarye/rust-typed-builder#112

Copy link
Member Author

Choose a reason for hiding this comment

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

There was also another lint that caused problems clippy::used_underscore_binding (idanarye/rust-typed-builder#113)

Let's hope everything works now :)

marker_rustc_driver/src/conversion/marker/stmts.rs Outdated Show resolved Hide resolved
Co-authored-by: Veetaha <gersoh3@gmail.com>
@xFrednet
Copy link
Member Author

Thank you for the review @Veetaha, I highly appreciate it ❤️

@xFrednet xFrednet added this pull request to the merge queue Sep 17, 2023
Merged via the queue into rust-marker:master with commit cfe7199 Sep 17, 2023
14 checks passed
@xFrednet xFrednet deleted the 244-no-kind-in-kind branch September 17, 2023 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-api Area: Stable API A-driver Area: Driver or something related to the internal working of a driver. C-documentation Category: Improvements or additions to documentation D-rustc-driver Driver: Rustc Driver I-api-break Issue: This change will break the public API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants