Skip to content

avoid constraint recursion in __basic_any#8121

Merged
ericniebler merged 3 commits intoNVIDIA:mainfrom
ericniebler:constraint-depends-on-self-in-basic-any
Mar 22, 2026
Merged

avoid constraint recursion in __basic_any#8121
ericniebler merged 3 commits intoNVIDIA:mainfrom
ericniebler:constraint-depends-on-self-in-basic-any

Conversation

@ericniebler
Copy link
Copy Markdown
Contributor

@ericniebler ericniebler commented Mar 20, 2026

Description

closes #8037

as described in #8037, it is too easy when using any_resource and resource_ref to encounter mysterious compiler errors about recursive constraints. For example, the following code triggers the error:

struct derived_resource
{
  explicit derived_resource(cuda::mr::resource_ref<cuda::mr::device_accessible>);

  void* allocate(cuda::stream_ref, ::cuda::std::size_t, ::cuda::std::size_t);
  void deallocate(cuda::stream_ref, void*, ::cuda::std::size_t, ::cuda::std::size_t) noexcept;
  void* allocate_sync(::cuda::std::size_t, ::cuda::std::size_t);
  void deallocate_sync(void*, ::cuda::std::size_t, ::cuda::std::size_t) noexcept;
  bool operator==(derived_resource const&) const;
  bool operator!=(derived_resource const&) const;
  friend void get_property(derived_resource const&, cuda::mr::device_accessible) noexcept {}
};
static_assert(cuda::std::move_constructible<derived_resource>);

when asking if derived_resource is move-constructible, we check if there is a derived_resource constructor that accepts (an rvalue) derived_resource. there are two constructors that can take a derived_resource as an argument: the compiler-generated move constructor (the one we wanted to be used), and the constructor that takes a resource_ref because derived_resource is-a resource.

when checking if the derived_resource(resource_ref) constructor is viable, we instantiate the resource_ref(T&) constructor with T=derived_resource1. that constructor checks, among other things, that the type T is move-constructible, completing the cycle in the type system.

the fix is to change __basic_any, the guts of resource_ref, to not constrain its constructor with checks for copyability or moveability. instead, we move those checks into the body of the constructor as static_asserts.

Checklist

  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

Footnotes

  1. we shouldn't though because rvalues don't bind to lvalue references. i think that's a compiler bug.

@copy-pr-bot
Copy link
Copy Markdown
Contributor

copy-pr-bot bot commented Mar 20, 2026

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@cccl-authenticator-app cccl-authenticator-app bot moved this from Todo to In Progress in CCCL Mar 20, 2026
@ericniebler ericniebler force-pushed the constraint-depends-on-self-in-basic-any branch from 27b7d10 to 90e3973 Compare March 20, 2026 17:05
@ericniebler ericniebler marked this pull request as ready for review March 20, 2026 17:06
@ericniebler ericniebler requested a review from a team as a code owner March 20, 2026 17:06
@ericniebler ericniebler requested a review from griwes March 20, 2026 17:06
@cccl-authenticator-app cccl-authenticator-app bot moved this from In Progress to In Review in CCCL Mar 20, 2026
@ericniebler ericniebler force-pushed the constraint-depends-on-self-in-basic-any branch from 95c89a1 to 2037216 Compare March 20, 2026 21:23
@github-actions
Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 1h 33m: Pass: 100%/99 | Total: 1d 11h | Max: 1h 15m | Hits: 93%/257836

See results here.

@ericniebler ericniebler requested review from miscco and pciolkosz March 21, 2026 21:05
Copy link
Copy Markdown
Contributor

@pciolkosz pciolkosz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into it!

@ericniebler ericniebler merged commit 47db866 into NVIDIA:main Mar 22, 2026
117 of 119 checks passed
@github-project-automation github-project-automation bot moved this from In Review to Done in CCCL Mar 22, 2026
@ericniebler ericniebler deleted the constraint-depends-on-self-in-basic-any branch March 22, 2026 04:18
bdice added a commit to rapidsai/rmm that referenced this pull request Apr 1, 2026
## Description

Delete `cccl_adaptors.hpp` and replace RMM's wrapper types
(`cccl_resource_ref`, `cccl_async_resource_ref`) with direct aliases to
CCCL's `resource_ref` and `synchronous_resource_ref`. This eliminates
the 480-line adaptor layer that was originally needed to work around the
CCCL [#8037](NVIDIA/cccl#8037) recursive
constraint satisfaction issue, which has since been fixed upstream in
CCCL [#8121](NVIDIA/cccl#8121).

Additional changes:
- `per_device_resource`: `static_cast<any_device_resource>(ref)`
replaced with `any_device_resource{ref}` (wrapper had `operator
any_resource`)
- Add missing `cuda_stream_view.hpp` include to three impl headers that
previously got it transitively through `cccl_adaptors.hpp`

## Checklist
- [x] I am familiar with the [Contributing
Guidelines](https://github.com/rapidsai/rmm/blob/HEAD/CONTRIBUTING.md).
- [x] New or existing tests cover these changes.
- [x] The documentation is up to date with these changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Recursive constraint satisfaction when constructing resource_ref from shared_resource-derived type with resource_ref constructor

2 participants