Skip to content

avoid constraint recursion in __basic_any#8121

Open
ericniebler wants to merge 3 commits intoNVIDIA:mainfrom
ericniebler:constraint-depends-on-self-in-basic-any
Open

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

Conversation

@ericniebler
Copy link
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
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
Contributor

🥳 CI Workflow Results

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

See results here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Review

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

1 participant