-
Notifications
You must be signed in to change notification settings - Fork 49
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
proc macro proof-of-concept #425
Conversation
a71aa52
to
3167015
Compare
e751cea
to
192b167
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick notes:
- Did you get around to checking the compilation-speed difference yet?
- To merge this, I would probably need one PR for each macro being replaced (where it makes sense,
ns_enum
,ns_options
,ns_error_enum
, ... can go in the same PR) - Ideally actually, I would prefer each macro being replaced by a function-like proc-macro that shares the exact same syntax, and then we can work on changing the syntax afterwards - but I recognize that may be a lot more work (and less glamorous), so it's okay if you don't want to do that.
- Wrt. the implementation, I would like it if we could start with a solid error reporting foundation using something like
proc-macro-error
, or perhaps manually usingcompile_error!
.
@@ -164,7 +164,7 @@ jobs: | |||
- name: Install Rust toolchain | |||
uses: actions-rs/toolchain@v1 | |||
with: | |||
toolchain: '1.60' | |||
toolchain: '1.62' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MSRV has to follow winit
(which is currently at 1.60
)
crates/objc2/tests/proc_macros.rs
Outdated
#[objc(interface)] | ||
struct C {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The macro syntax here is unsound, since there's no unsafe
marker to prevent the user from specifying the wrong superclass(es). We'd need to do something else, perhaps #[objc(interface, unsafe)]
or similar.
I haven't yet but hopefully will be able to start testing that in the upcoming week. I did notice this blog post, though, which you may also have seen. Although the comparison to proc-macros isn't explicitly made, it does suggest (I think) that there are some significant improvements to be had.
Okay, I will keep this in mind. Since I didn't start doing it this way, I would prefer to wait until after the underlying implementation stabilizes and then perhaps go back and reimplement the current macro syntax using that.
Understood. The main reason I am flattening the commit history right now is mostly because it's rather noisy. For the final PR I can provide more granularity there.
Right, I am currently using |
7aaee78
to
db65bd4
Compare
Ah, sorry, I should've checked the code if you were doing so already ;) |
0e43a31
to
42baa49
Compare
42baa49
to
4627667
Compare
ade42e3
to
554d293
Compare
ec4b745
to
314b920
Compare
@madsmtm I've gotten an initial implementation working and compiling With the enum macros, I copied the existing behavior (not the more advanced translation we've been discussing). The goal there was simply to avoid recursive Compile times seem several seconds faster, but not as significant as I was expecting. That surprised me a little but I haven't investigated further yet or done thorough testing. I did try compiling I think that even if it turns out that with proc-macros it isn't much faster with regard to There are also some other possibilities to explore that might actually have a bigger impact on performance, like switching from Another possibility could be to simply dispense with the macros altogether and use the underlying proc-macro code directly in Anyway, I probably won't do too much more work in this direction unless you think it's worth exploring further. |
Hmm, the part about non-improved performance is unfortunate. Did you try running e.g. There might also be improvements found by compiling the [profile.dev.build-override]
opt-level = 3
# OR
[profile.dev.package.objc2-proc-macros]
opt-level = 3
The possibility of doing the code-generation from the get-go inside I agree there's huge benefits to a proc-macro, especially improvements to
Understandable - I do think it's worth exploring further at some point, but as I've said before, my priorities do lie elsewhere right now. E.g. I'm more interested in getting the semantics / the output of the macros right first, and then we can always create the better user-interface proc-macros afterwards (and simply deprecate the old macros as aliases for the new ones). |
I started rewriting the proc-macro proof-of-concept from scratch based on ideas from #423 and from
objrs
and some things I learned from the first attempt. This is still just a sketch of course so pretty anything can be changed.I haven't added a lot of the class related machinery back in yet but will get back to that soon.
One thing I did try that was new this time was some ideas for more thoroughly handling the Objective-C enum macros (e.g.,
NS_ENUM
and related). I'm not entirely sure this approach will work but it seems like it might be a little nicer than what we currently have. See the test file for examples.