Add non-template ref-to-value converting constructor to __basic_any#8320
Open
bdice wants to merge 3 commits intoNVIDIA:mainfrom
Open
Add non-template ref-to-value converting constructor to __basic_any#8320bdice wants to merge 3 commits intoNVIDIA:mainfrom
bdice wants to merge 3 commits intoNVIDIA:mainfrom
Conversation
The __basic_any value specialization inherits converting constructors from templates that accept __basic_any<_OtherInterface>. When a proxy type wraps a __basic_any reference type (e.g. __basic_any<I&>) and provides operator __basic_any<I&>&(), these template constructors cannot match: template argument deduction deduces the proxy type, not the underlying __basic_any, and implicit user-defined conversions are not considered during deduction. Add a non-template constructor __basic_any(__basic_any<_Interface&> const&) for the ref-to-value conversion case. Non-template parameters participate in implicit conversion sequences, allowing proxy types to convert through their user-defined conversion operator. This fixes any_resource construction from proxy-wrapped resource_ref and any_synchronous_resource from proxy-wrapped synchronous_resource_ref without requiring per-type overloads. Fixes NVIDIA#8316
…d refs Add regression tests for NVIDIA#8316 verifying that any_resource and any_synchronous_resource can be constructed from a value_proxy<T> that wraps resource_ref or synchronous_resource_ref via operator T&(), mimicking Cython's __Pyx_FakeReference proxy pattern.
ericniebler
approved these changes
Apr 7, 2026
libcudacxx/include/cuda/__utility/__basic_any/basic_any_value.h
Outdated
Show resolved
Hide resolved
Co-authored-by: Eric Niebler <eniebler@boost.org>
Contributor
😬 CI Workflow Results🟥 Finished in 2h 13m: Pass: 47%/108 | Total: 1d 06h | Max: 58m 54s | Hits: 94%/65024See results here. |
miscco
requested changes
Apr 8, 2026
Comment on lines
+171
to
+180
| //! @brief Non-template converting constructor from the corresponding | ||
| //! reference type `__basic_any<_Interface&>`. This enables implicit | ||
| //! conversion from proxy types (e.g. Cython's __Pyx_FakeReference) | ||
| //! that wrap a `__basic_any<_Interface&>` and provide | ||
| //! `operator __basic_any<_Interface&>&()`, since non-template parameters | ||
| //! participate in implicit conversion sequences. | ||
| _CCCL_API __basic_any(__basic_any<_Interface&> const& __other) | ||
| { | ||
| __convert_from(__other); | ||
| } |
Contributor
There was a problem hiding this comment.
Thanks for the fix, please also add the corresponding move constructor and test for rvalue proxy
bdice
added a commit
to bdice/rmm
that referenced
this pull request
Apr 9, 2026
Work around CCCL issue where any_resource cannot be constructed from Cython's __Pyx_FakeReference proxy type wrapping resource_ref. Declare any_resource and device_accessible in .pxd, add inline make_any_device_resource helper. Update all 12 constructor call sites in .pyx to use the helper. Ref: NVIDIA/cccl#8320
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Description
closes #8316
Add a non-template converting constructor
__basic_any(__basic_any<_Interface&> const&)to the__basic_anyvalue specialization, enabling implicit conversion from proxy types that wrap a__basic_anyreference type.The
__basic_anyvalue specialization provides a forwarding constructor__basic_any(_Tp&&)and template converting constructors__basic_any(__basic_any<_OtherInterface> const&). When a proxy type wraps a__basic_any<I&>(e.g. aresource_ref) and providesoperator __basic_any<I&>&(), neither path works: the forwarding constructor deduces the proxy type which doesn't satisfy the interface, and the template converting constructors can't deduce_OtherInterfacefrom the proxy since implicit user-defined conversions are not considered during template argument deduction.This occurs concretely with Cython's
__Pyx_FakeReference<T>, which wraps intermediate C++ expression results and providesoperator T&(). Constructingany_resource<P...>from a Cython-wrappedresource_ref<P...>fails at compile time.The fix adds a non-template constructor for the same-interface ref-to-value conversion. Because the parameter is non-template, the compiler considers implicit conversion sequences through the proxy's
operator T&(). The existing template converting constructor gains an additional!same_as<_OtherInterface, _Interface&>constraint to avoid ambiguity.This single fix in
__basic_anycovers all downstream types:any_resource,any_synchronous_resource, and any future__basic_any-based value types.Testing: A new test was added based on the minimal reproducer in the issue. RMM Cython bindings build and pass tests using direct
any_resourceconstruction fromresource_refwithout workaround helpers.Checklist