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

mod ipred: Use wrap_fn_ptr! to generate decl_fn!s and add type-safe wrappers #581

Merged
merged 12 commits into from
Dec 1, 2023

Conversation

kkysen
Copy link
Collaborator

@kkysen kkysen commented Nov 21, 2023

This also reworks wrap_fn_ptr! to declare Fn as a newtype struct inside the macro rather than a type alias to the generic WrappedFnPtr, which needed a type token for disambiguation. This results in mode code inside the macro vs. out of it, but the code is much simpler and easier to understand this way.

@kkysen kkysen requested a review from randomPoison November 21, 2023 22:25
@kkysen kkysen force-pushed the kkysen/macro-wrap_fn_ptr-decl_fn branch from fa0e67f to 5bda2e8 Compare November 27, 2023 06:27
@kkysen kkysen force-pushed the kkysen/mod-ipred-wrap_fn_ptr branch from 4a29b5d to 97662d8 Compare November 27, 2023 06:27
@rinon
Copy link
Collaborator

rinon commented Nov 29, 2023

What is the WrappedFnPtr type actually giving us here? It would be simpler to make Fn itself a newtype instead of making it a pub type. That would avoid the Token thing entirely, right?

@kkysen
Copy link
Collaborator Author

kkysen commented Nov 29, 2023

What is the WrappedFnPtr type actually giving us here? It would be simpler to make Fn itself a newtype instead of making it a pub type. That would avoid the Token thing entirely, right?

Yeah, the alternative to a token type is to just make a newtype, but since most of the rest besides that token type part can be a generic type, I thought it's easier that way as less code has to be inside the macro.

@rinon
Copy link
Collaborator

rinon commented Nov 29, 2023

The Token type is hard to understand, IMO. It took me a bit to figure out what the actual problem was, because I forgot that we were even using a pub type instead of a fresh newtype. I think the newtype is the way to go here, whether the code is inside or outside the macro doesn't matter here because we don't use WrappedFnPtr elsewhere.

@kkysen kkysen force-pushed the kkysen/macro-wrap_fn_ptr-decl_fn branch from 5bda2e8 to 336bb06 Compare November 29, 2023 06:00
@kkysen kkysen force-pushed the kkysen/mod-ipred-wrap_fn_ptr branch from 97662d8 to 0956cc2 Compare November 29, 2023 07:08
@kkysen
Copy link
Collaborator Author

kkysen commented Nov 29, 2023

The Token type is hard to understand, IMO. It took me a bit to figure out what the actual problem was, because I forgot that we were even using a pub type instead of a fresh newtype. I think the newtype is the way to go here, whether the code is inside or outside the macro doesn't matter here because we don't use WrappedFnPtr elsewhere.

I tried out declaring the newtype inside the macro and it is indeed a lot cleaner and simpler.

@kkysen kkysen requested a review from rinon November 29, 2023 07:11
src/wrap_fn_ptr.rs Outdated Show resolved Hide resolved
src/wrap_fn_ptr.rs Outdated Show resolved Hide resolved
kkysen and others added 11 commits November 30, 2023 01:50
…e copied when moved and compared for equality.
…uate different `fn` ptrs with the same signature.
… `decl_fn!`s with `wrap_fn_ptr!` and add type-safe wrappers.
… type with a newtype in the macro.

This puts more code inside the macro, but also simplifies a bunch of things.
It also lets us make the methods on `Fn` `pub(super)`,
as they only need to be called by the declaring module.
@kkysen kkysen force-pushed the kkysen/mod-ipred-wrap_fn_ptr branch from 0956cc2 to c1ee39a Compare November 30, 2023 07:00
@kkysen kkysen force-pushed the kkysen/mod-ipred-wrap_fn_ptr branch from c1ee39a to e885327 Compare November 30, 2023 07:01
@kkysen kkysen requested a review from rinon November 30, 2023 07:04
Base automatically changed from kkysen/macro-wrap_fn_ptr-decl_fn to main December 1, 2023 23:59
@kkysen kkysen merged commit d405bec into main Dec 1, 2023
18 checks passed
@kkysen kkysen deleted the kkysen/mod-ipred-wrap_fn_ptr branch December 1, 2023 23:59
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