Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,18 @@ namespace hpx::server {
};
} // namespace hpx::server

#if !defined(HPX_PARTITIONED_VECTOR_MODULE_EXPORTS) && \
!defined(HPX_HAVE_STATIC_LINKING)
HPX_COMPONENT_REGISTERED_ELSEWHERE(
hpx::server::partitioned_vector<double, std::vector<double>>)
HPX_COMPONENT_REGISTERED_ELSEWHERE(
hpx::server::partitioned_vector<int, std::vector<int>>)
HPX_COMPONENT_REGISTERED_ELSEWHERE(
hpx::server::partitioned_vector<long long, std::vector<long long>>)
HPX_COMPONENT_REGISTERED_ELSEWHERE(
hpx::server::partitioned_vector<std::string, std::vector<std::string>>)
#endif

///////////////////////////////////////////////////////////////////////////////
#if 0
#define HPX_REGISTER_PARTITIONED_VECTOR_DECLARATION(...)
Expand Down
1 change: 1 addition & 0 deletions libs/full/components_base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ set(components_base_headers
hpx/components_base/traits/component_config_data.hpp
hpx/components_base/traits/component_heap_type.hpp
hpx/components_base/traits/component_pin_support.hpp
hpx/components_base/traits/component_registered_elsewhere.hpp
hpx/components_base/traits/component_supports_migration.hpp
hpx/components_base/traits/component_type_is_compatible.hpp
hpx/components_base/traits/component_type_database.hpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <hpx/assert.hpp>
#include <hpx/modules/preprocessor.hpp>

#include <type_traits>

///////////////////////////////////////////////////////////////////////////////
// from hpx/component_base/component_commandline.hpp
#define HPX_DEFINE_COMPONENT_COMMANDLINE_OPTIONS(add_options_function) \
Expand Down Expand Up @@ -263,3 +265,25 @@
} \
} \
/**/

///////////////////////////////////////////////////////////////////////////////
// from hpx/components_base/traits/component_registered_elsewhere.hpp

/// Mark a component type as registered by another module. This has to be
/// visible before any registration of the component type, i.e. in the header
/// declaring it, hidden from the sources of the module that registers it.
#define HPX_COMPONENT_REGISTERED_ELSEWHERE(...) \
namespace hpx::traits { \
template <> \
struct component_registered_elsewhere<__VA_ARGS__> : std::true_type \
{ \
}; \
} \
/**/

#define HPX_ASSERT_COMPONENT_NOT_REGISTERED_ELSEWHERE(Component) \
static_assert(!hpx::traits::component_registered_elsewhere_v<Component>, \
"this component type is already registered by the library that " \
"declares it; a component type must be registered in exactly one " \
"module, remove this registration and use the declaration only"); \
/**/
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2026 Nithurshen
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#pragma once

#include <hpx/config.hpp>

#include <type_traits>

namespace hpx::traits {

/// Evaluates to true if the component type is registered by another
/// module than the one being compiled. A library that registers a
/// component specializes this trait for its consumers (see
/// \a HPX_COMPONENT_REGISTERED_ELSEWHERE), which turns a second
/// registration of the component into a compile time error.
HPX_CXX_EXPORT template <typename Component, typename Enable = void>
struct component_registered_elsewhere : std::false_type
{
};

HPX_CXX_EXPORT template <typename Component>
inline constexpr bool component_registered_elsewhere_v =
component_registered_elsewhere<Component>::value;
} // namespace hpx::traits
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
/**/
#define HPX_REGISTER_MINIMAL_COMPONENT_REGISTRY_3( \
ComponentType, componentname, state) \
HPX_ASSERT_COMPONENT_NOT_REGISTERED_ELSEWHERE(ComponentType::type_holder) \
HPX_DEFINE_COMPONENT_MODULE_NAME(ComponentType) \
using componentname##_component_registry_type = \
hpx::components::component_registry<ComponentType, state>; \
Expand Down Expand Up @@ -191,6 +192,7 @@
/**/
#define HPX_REGISTER_MINIMAL_COMPONENT_REGISTRY_DYNAMIC_3( \
ComponentType, componentname, state) \
HPX_ASSERT_COMPONENT_NOT_REGISTERED_ELSEWHERE(ComponentType::type_holder) \
HPX_DEFINE_COMPONENT_MODULE_NAME(ComponentType) \
using componentname##_component_registry_type = \
hpx::components::component_registry<ComponentType, state>; \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,26 @@ if(HPX_WITH_NETWORKING AND HPX_WITH_PARCELPORT_TCP)
tests.unit.modules.runtime_components.launch_process launched_process_test
)
endif()

if(HPX_WITH_COMPILE_ONLY_TESTS)
set(compile_tests component_registered_elsewhere)

if(HPX_WITH_FAIL_COMPILE_TESTS)
set(fail_compile_component_registered_elsewhere_FLAGS FAILURE_EXPECTED)
set(compile_tests ${compile_tests}
fail_compile_component_registered_elsewhere
)
endif()

foreach(compile_test ${compile_tests})
set(sources ${compile_test}.cpp)

source_group("Source Files" FILES ${sources})

add_hpx_unit_compile_test(
"modules.runtime_components" ${compile_test}
SOURCES ${sources} ${${compile_test}_FLAGS}
FOLDER "Tests/Unit/Modules/Full/Components/CompileOnly"
)
endforeach()
endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2026 Nithurshen
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <hpx/config.hpp>
#if !defined(HPX_COMPUTE_DEVICE_CODE)
#include <hpx/include/components.hpp>

struct registered_here : hpx::components::component_base<registered_here>
{
};

struct registered_elsewhere
: hpx::components::component_base<registered_elsewhere>
{
};

HPX_COMPONENT_REGISTERED_ELSEWHERE(registered_elsewhere)

static_assert(!hpx::traits::component_registered_elsewhere_v<registered_here>);
static_assert(
hpx::traits::component_registered_elsewhere_v<registered_elsewhere>);

using registered_here_type = hpx::components::component<registered_here>;
HPX_REGISTER_COMPONENT(registered_here_type, registered_here)
#endif

int main()
{
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2026 Nithurshen
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

// Registering a component marked as registered by another module must fail.

#include <hpx/config.hpp>
#if !defined(HPX_COMPUTE_DEVICE_CODE)
#include <hpx/include/components.hpp>

struct registered_elsewhere
: hpx::components::component_base<registered_elsewhere>
{
};

HPX_COMPONENT_REGISTERED_ELSEWHERE(registered_elsewhere)

using registered_elsewhere_type =
hpx::components::component<registered_elsewhere>;
HPX_REGISTER_COMPONENT(registered_elsewhere_type, registered_elsewhere)
#endif

int main()
{
return 0;
}
Loading