Skip to content

Use raw pointers for NonNull and cpp_type wrappers in callable invokers. - #3279

Open
copybara-service[bot] wants to merge 1 commit into
mainfrom
test_1035279474
Open

copybara-service[bot] wants to merge 1 commit into
mainfrom
test_1035279474

Conversation

@copybara-service

Copy link
Copy Markdown

Use raw pointers for NonNull and cpp_type wrappers in callable invokers.

Rust calls a C++ callable through __invoker. Cross-language CFI stops this call when a param or the return value is a NonNull<T> or a repr(transparent) wrapper with a pointer cpp_type (such as a proto view). Clang encodes the C++ type as a pointer. Rustc encodes the wrapper as its field and NonNull as a pattern type. Thus the two type IDs are different.

The invoker signature spells these types as raw pointers, as it does for &T. NonNull<T> becomes *mut T. A pointer cpp_type wrapper becomes *const c_void or *mut c_void, with the const qualifier from cpp_type, because the Rust field is always *const. Return values get the same change, because the return type is part of the type ID. Returned pointees use 'static lifetimes, which also fixes an old E0106 compile error for callables that return references with lifetimes.

This change does not apply to unsized pointees, to a cpp_type with more than one *, or to Pin<&T>.

@google-cla

google-cla Bot commented Dec 4, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Rust calls a C++ callable through `__invoker`. Cross-language CFI stops this call when a param or the return value is a `NonNull<T>` or a `repr(transparent)` wrapper with a pointer `cpp_type` (such as a proto view). Clang encodes the C++ type as a pointer. Rustc encodes the wrapper as its field and `NonNull` as a pattern type. Thus the two type IDs are different.

The invoker signature spells these types as raw pointers, as it does for `&T`. `NonNull<T>` becomes `*mut T`. A pointer `cpp_type` wrapper becomes `*const c_void` or `*mut c_void`, with the `const` qualifier from `cpp_type`, because the Rust field is always `*const`. Return values get the same change, because the return type is part of the type ID. Returned pointees use `'static` lifetimes, which also fixes an old E0106 compile error for callables that return references with lifetimes.

This change does not apply to unsized pointees, to a `cpp_type` with more than one `*`, or to `Pin<&T>`.

PiperOrigin-RevId: 1035279474

This branch has not been deployed

No deployments
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.

0 participants