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

Re-implement case set as a macro #1293

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Re-implement case set as a macro #1293

wants to merge 1 commit into from

Conversation

rinon
Copy link
Collaborator

@rinon rinon commented Jul 9, 2024

No description provided.

@rinon
Copy link
Collaborator Author

rinon commented Jul 9, 2024

Still need to address some comments from #1292

@kkysen kkysen self-assigned this Jul 9, 2024
@kkysen
Copy link
Collaborator

kkysen commented Jul 9, 2024

Still need to address some comments from #1292

Let me know when this is ready to review.

@rinon
Copy link
Collaborator Author

rinon commented Jul 9, 2024

Ready. Performance is neutral, unfortunately this whole thing didn't make anything faster even though the micro-benchmarks showed improvement. We only need to land this if it is an improvement to readability (which I think it is, personally).

Copy link
Collaborator

@kkysen kkysen left a comment

Choose a reason for hiding this comment

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

Still reviewing some more, but I'm going to sleep, so here's some initial comments.

lib.rs Outdated Show resolved Hide resolved
src/ctx.rs Outdated Show resolved Hide resolved
src/ctx.rs Outdated Show resolved Hide resolved
src/ctx.rs Outdated Show resolved Hide resolved
src/ctx.rs Show resolved Hide resolved
src/decode.rs Outdated Show resolved Hide resolved
src/ctx.rs Outdated
buf.fill(val)
/// [`DisjointMut`]: crate::src::disjoint_mut::DisjointMut
macro_rules! case_set {
($UP_TO:literal, $(@DEFAULT=$WITH_DEFAULT:literal,)? $ctx:ident=[$($ctx_expr:expr),* $(,)?], $len:ident=[$($len_expr:expr),* $(,)?], $offset:ident=[$($offset_expr:expr),* $(,)?], $body:block) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the @ in @DEFAULT for? And can we just name it WITH_DEFAULT?

Copy link
Collaborator Author

@rinon rinon Jul 10, 2024

Choose a reason for hiding this comment

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

The @ distinguishes it from $ctx:ident (@ is not a valid identifier, or anything else in prefix position for that matter). Users should not use this version.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What I really wanted was a way to pass in the boolean to unify the implementations but have two different macros for this (case_set! and case_set_with_default! or whatever).

Copy link
Collaborator

Choose a reason for hiding this comment

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

It might work if you put it at the end of the args? Especially if len and offset are not caller named. This way is okay, too, though, just funny looking I guess.

src/decode.rs Outdated Show resolved Hide resolved
src/recon.rs Outdated Show resolved Hide resolved
src/recon.rs Outdated Show resolved Hide resolved
Comment on lines +152 to +168
let $len = $len_expr;
let $offset = $offset_expr;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do these need to be variable names set by the caller? I don't think they're accessed in any $body:block.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Then we don't have to worry about name collisions like offset and case_offset.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Only $ctx is accessed by the caller IIUC.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see this now, good point. I figured somewhere we access it somewhere from looking at the original C macro, but I guess we don't. It's a bit confusing that the body can access the context variable but not the others. I think I'd prefer to keep it consistent even if we don't use it right now.

I guess we could use let ctx = ... instead to indicate that it creates a new variable name, if we really want to make them different.

Copy link
Collaborator

Choose a reason for hiding this comment

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

In the old API, though, ctx was explicitly the only extra variable passed to the closure. I don't think it's confusing that the others aren't accessible. ctx is special in this way. It's more confusing to me that there's all these other variables the caller defines.

@rinon rinon force-pushed the sjc/case_set_macro branch 3 times, most recently from 53d3c2a to 0b8324b Compare July 10, 2024 19:57
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