proc_macro: don't pass a client-side function pointer through the server.#97461
Merged
bors merged 1 commit intorust-lang:masterfrom May 28, 2022
Merged
proc_macro: don't pass a client-side function pointer through the server.#97461bors merged 1 commit intorust-lang:masterfrom
bors merged 1 commit intorust-lang:masterfrom
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before this PR,
proc_macro::bridge::Client<F>contained both:run, that the server can call to start the clientf: Fpassed to that entry-pointfnpointer to the actual function the proc macro author wrote, i.e.#[proc_macro] fn foo(input: TokenStream) -> TokenStreamIn other words, the client was passing one of its (Rust)
fnpointers 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_countersfield fromClient(see #97004 (comment)), which combined with removing thef("payload") field, could theoretically allow for a#[repr(transparent)]Clientthat mostly just newtypes the C ABI entry-pointfnpointer (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_wrapperexample above, but limited toFbeingCopyand ZST (and requiring anFvalue to prove the caller actually can create values ofFand 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