-
Notifications
You must be signed in to change notification settings - Fork 13.3k
proc_macro: don't pass a client-side function pointer through the server. #97461
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
Conversation
This comment was marked as off-topic.
This comment was marked as off-topic.
(rust-highfive has picked a reviewer for you, use r? to override) |
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit ba869ade7c9da9b487be4457f3826b33a4fa2f20 with merge 3fd3bd768ea1fe15e6ae0e911231ff515283a2d0... |
This comment has been minimized.
This comment has been minimized.
(I have a fix for the tidy error but I'll only push it after the try build hopefully succeeds, to avoid confusing it - IIRC in the past the bot forgot to post any updates if the |
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.
Overall approach makes sense to me.
LL | pub const fn custom_derive( | ||
| ^^^^^^^^^^^^^ | ||
LL | expand: impl Fn(crate::TokenStream) -> crate::TokenStream + Copy, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ProcMacro::custom_derive` |
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.
This is a diagnostic regression to the point where I think it becomes next to useless for many people.
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.
Taking a look again on my desktop as opposed to my phone, I guess it is not too bad.
☀️ Try build successful - checks-actions |
Queued 3fd3bd768ea1fe15e6ae0e911231ff515283a2d0 with parent 56fd680, future comparison URL. |
Finished benchmarking commit (3fd3bd768ea1fe15e6ae0e911231ff515283a2d0): comparison url. Instruction count
Max RSS (memory usage)Results
CyclesResults
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Footnotes |
ba869ad
to
78a83b0
Compare
r? @bjorn3 |
@bors r+ |
📌 Commit 78a83b0 has been approved by |
☀️ Test successful - checks-actions |
Finished benchmarking commit (116201e): comparison url. Instruction count
Max RSS (memory usage)Results
CyclesResults
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Footnotes |
Visiting for rustc-perf triage.
@rustbot label: +perf-regression-triaged |
@pnkfelix Sorry, didn't see this at first - the explanation is that a lot of (Note, however, that since Cargo doesn't even build proc macro crates with optimizations, the effect is not as drastic as it could otherwise be) |
Before this PR,
proc_macro::bridge::Client<F>
contained both:run
, that the server can call to start the clientf: F
passed to that entry-pointfn
pointer to the actual function the proc macro author wrote, i.e.#[proc_macro] fn foo(input: TokenStream) -> TokenStream
In other words, the client was passing one of its (Rust)
fn
pointers to the server, which was passing it back to the client, for the client to call (see later below for why that was ever needed).I was inspired by @nnethercote's attempt to remove the
get_handle_counters
field fromClient
(see #97004 (comment)), which combined with removing thef
("payload") field, could theoretically allow for a#[repr(transparent)]
Client
that mostly just newtypes the C ABI entry-pointfn
pointer (and in the context of e.g. wasm isolation, that's all you want, since you can reason about it from outside the wasm VM, as just a 32-bit "function table index", that you can pass to the wasm VM to call that function).So this PR removes that "payload". But it's not a simple refactor: the reason the field existed in the first place is because monomorphizing over a function type doesn't let you call the function without having a value of that type, because function types don't implement anything like
Default
, i.e.:That could be solved with something like this, if it was allowed:
Instead, this PR contains a workaround in
proc_macro::bridge::selfless_reify
(see its module-level comment for more details) that can provide something similar to theffi_wrapper
example above, but limited toF
beingCopy
and ZST (and requiring anF
value to prove the caller actually can create values ofF
and it's not uninhabited or some other unsound situation).Hopefully this time we don't have a performance regression, and this has a chance to land.
cc @mystor @bjorn3