Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f9be7b6
feat(model)!: validate identifiers and drop empty-name defaults
marcpaterno Nov 13, 2026
5da8941
perf!: make identifier moves noexcept and non-copying
marcpaterno Nov 14, 2026
0875540
fix(plugins): use checked access for provider selector optionals
marcpaterno Nov 14, 2026
ebfe153
test(model): cover default product store source
marcpaterno Nov 14, 2026
ed7a81c
refactor(core): remove unreachable suffix fallback in producer log
marcpaterno Nov 14, 2026
f07fa97
test(model): cover empty algorithm name error
marcpaterno Nov 14, 2026
d7fe7d0
add: cover product specification hash and equality
marcpaterno Nov 14, 2026
e5ccd97
add: cover leading-slash product specification without creator
marcpaterno Nov 14, 2026
538b0ab
add tests for provider routing and product creator validation
marcpaterno Nov 14, 2026
5d6188b
style: reformat finalize and product spec calls in tests
marcpaterno Nov 14, 2026
09fd8db
style: sort product store test includes and wrap product spec check
marcpaterno Nov 15, 2026
2da74a3
chore: Allow unguarded optional value() calls in clang-tidy
marcpaterno Nov 16, 2026
82be2d9
refactor(model): make identifier_or_empty move constructor noexcept
marcpaterno Nov 16, 2026
fcbeaba
refactor(model): use optional identifier for algorithm_name plugin
marcpaterno Nov 16, 2026
2b45c00
refactor(model)!: require a creator in product_specification
marcpaterno Nov 16, 2026
8f979d9
refactor(model)!: validate algorithm names once with uniform errors
marcpaterno Nov 17, 2026
24b17c0
refactor(test): prefer optional::value() over operator*
marcpaterno Nov 19, 2026
4f5eb3d
fix(model): clarify identifier validation error messages
marcpaterno Nov 20, 2026
1bd60fa
refactor(core): drop redundant creator guard in product match
marcpaterno Nov 20, 2026
1d0ecc5
chore(model): assert layer path depth matches index depth
marcpaterno Nov 20, 2026
78aaa5f
test(identifier): split constructor and embedded NUL tests
marcpaterno Nov 20, 2026
5788acc
refactor: replace text create factories with constructors
marcpaterno Nov 20, 2026
985b7b4
refactor(model): move excerpt definition into source file
marcpaterno Nov 20, 2026
bf806ff
test: rename invalid-identifier test fixtures
marcpaterno Nov 20, 2026
fe6cc45
test: remove make_child empty-name throw assertion
marcpaterno Nov 20, 2026
50a5eac
test: move product specification tests to their own file
marcpaterno Nov 20, 2026
468c225
test: verify product specification hash via set deduplication
marcpaterno Nov 20, 2026
79b6a9f
refactor: Generalize product selector field conversion
marcpaterno Nov 20, 2026
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
4 changes: 4 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ WarningsAsErrors: ''
HeaderFilterRegex: '.*/(phlex|form)/.*\.(h|hpp)$'

CheckOptions:
# Allow calls to optional::value() without guards
- key: bugprone-unchecked-optional-access.IgnoreValueCalls
value: 'true'

# Naming conventions
- key: readability-identifier-naming.NamespaceCase
value: lower_case
Expand Down
2 changes: 1 addition & 1 deletion form/form_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ namespace {
std::cout << " Product: " << product_spec.to_string() << "\n";

// Create FORM product with metadata
products.emplace_back(product_spec.suffix().trans_get_string(), // label, from map key
products.emplace_back(std::string{product_spec.suffix().text()}, // label, from map key
product_ptr->address(), // data, from phlex product_base
&product_ptr->type() // type, from phlex product_base
);
Expand Down
19 changes: 13 additions & 6 deletions form/form_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace {
form_input_source(form::experimental::config::item_config const& input_cfg,
form::experimental::config::tech_setting_config const& tech_cfg,
std::string actual_creator,
std::string advertised_creator,
phlex::experimental::algorithm_name advertised_creator,
std::string stage,
std::vector<std::string> const& products) :
reader_(std::make_shared<form::experimental::form_reader_interface>(input_cfg, tech_cfg)),
Expand All @@ -102,8 +102,7 @@ namespace {
}

for (auto const& name : products_) {
product_specification spec{
algorithm_name::create(advertised_creator_), identifier{name}, selector.type};
product_specification spec{advertised_creator_, suffix_t{name}, selector.type};

// Read and provide products at the configured stage.
identifier const selector_layer = selector.layer;
Expand Down Expand Up @@ -167,7 +166,7 @@ namespace {
private:
std::shared_ptr<form::experimental::form_reader_interface> reader_;
std::string actual_creator_;
std::string advertised_creator_;
phlex::experimental::algorithm_name advertised_creator_;
std::string stage_;
std::vector<std::string> products_;
};
Expand All @@ -178,12 +177,20 @@ PHLEX_REGISTER_SOURCE(s, config)
std::cout << "Registering FORM input source...\n";

auto const input_file = config.get<std::string>("input_file");
auto const advertised_creator = config.get<std::string>("creator");
auto const creator_text = config.get<std::string>("creator");
// Parse the creator once, here, where its parameter name is known.
auto const advertised_creator = [&creator_text] {
try {
return phlex::experimental::algorithm_name{creator_text};
} catch (std::invalid_argument const& e) {
throw std::invalid_argument{std::string{"Invalid parameter 'creator': "} + e.what()};
}
}();
auto const module_label = config.get<std::string>("module_label", "form_source");
auto const products = config.get<std::vector<std::string>>("products");
auto const stage = config.get<std::string>("stage");

std::string actual_creator = advertised_creator;
std::string actual_creator = creator_text;
auto const algorithm = config.get_if_present<std::string>("algorithm");
auto const plugin = config.get_if_present<std::string>("plugin");
if (algorithm && plugin && !algorithm->empty() && !plugin->empty()) {
Expand Down
16 changes: 16 additions & 0 deletions phlex/app/plugin_loading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "phlex/core/graph_proxy.hpp"
#include "phlex/driver.hpp"
#include "phlex/metaprogramming/type_deduction.hpp"
#include "phlex/model/identifier.hpp"
#include "phlex/module.hpp"
#include "phlex/resource.hpp"
#include "phlex/source.hpp"
Expand Down Expand Up @@ -32,6 +33,19 @@ namespace phlex::detail {
namespace {
constexpr std::string_view pymodule_name{"pymodule"};

// The label of a module or source becomes the plugin label of every algorithm that it
// registers. Checking it where the user wrote it lets the message name the configuration
// section, which the algorithm-name error raised later could not.
void verify_label(std::string_view section, std::string const& label)
{
try {
experimental::identifier const checked{label};
} catch (std::invalid_argument const&) {
throw std::invalid_argument{fmt::format(
"Invalid label {:?} for an entry in \"{}\": it {}", label, section, identifier_rule)};
}
}

// The shared_library member in each wrapper struct keeps the loaded .so
// alive for the lifetime of the wrapper. If it goes out of scope, the
// library is unloaded and the stored function pointer becomes invalid.
Expand Down Expand Up @@ -143,6 +157,7 @@ namespace phlex::detail {

void load_module(framework_graph& g, std::string const& label, boost::json::object raw_config)
{
verify_label("modules", label);
auto const adjusted_config = internal::adjust_config(label, std::move(raw_config));

auto const& spec = value_to<std::string>(adjusted_config.at("cpp"));
Expand Down Expand Up @@ -173,6 +188,7 @@ namespace phlex::detail {

void load_source(framework_graph& g, std::string const& label, boost::json::object raw_config)
{
verify_label("sources", label);
auto const adjusted_config = internal::adjust_config(label, std::move(raw_config));

auto const& spec = value_to<std::string>(adjusted_config.at("cpp"));
Expand Down
55 changes: 36 additions & 19 deletions phlex/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <boost/json/conversion.hpp>
#include <boost/json/object.hpp>
#include <boost/json/value.hpp>
#include <boost/json/value_to.hpp>
#include <fmt/format.h>
#include <fmt/ranges.h>

Expand All @@ -17,23 +16,37 @@
#include <stdexcept>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

namespace phlex::detail {
std::optional<experimental::identifier> value_if_exists(
boost::json::object const& obj, // will be used later for new product_selector
std::string_view parameter)
{
if (!obj.contains(parameter)) {
return std::nullopt;
namespace phlex::experimental {
// The unnamed namespace gives this helper internal linkage. It is inline so that its members
// are still found by argument-dependent lookup in phlex::experimental.
inline namespace {
// Boost.JSON conversion to suffix_t, used when reading a product selector's "suffix" field.
// boost::json::value_to finds tag_invoke overloads by argument-dependent lookup, which
// searches phlex::experimental, the namespace of suffix_t, and its inline namespaces.
suffix_t tag_invoke(boost::json::value_to_tag<suffix_t> const&, boost::json::value const& jv)
{
return suffix_t{std::string_view{jv.as_string()}};
}
auto const& val = obj.at(parameter);
return boost::json::value_to<experimental::identifier>(val);
}
}

namespace phlex {
namespace {
// Returns the product selector field named `field` converted to T, or std::nullopt when it is
// absent. A malformed value is reported together with the name of the field that held it.
template <typename T>
std::optional<T> in_selector_field(boost::json::object const& query_object,
std::string_view field)
try {
return detail::value_if_exists<T>(query_object, field);
} catch (std::invalid_argument const& e) {
throw std::invalid_argument{
fmt::format("Invalid product selector field \"{}\": {}", field, e.what())};
}
}

std::vector<std::string> configuration::keys() const
{
std::vector<std::string> result;
Expand All @@ -52,11 +65,13 @@ namespace phlex {
product_selector tag_invoke(boost::json::value_to_tag<product_selector> const&,
boost::json::value const& jv)
{
using detail::value_if_exists;
using experimental::identifier;
using experimental::suffix_t;
using namespace std::string_view_literals;
static std::set<std::string_view> const valid_keys = {
"creator"sv, "layer"sv, "suffix"sv, "stage"sv};
auto query_object = jv.as_object();
// A reference into `jv`: the selector is only read here, so no copy of the object is needed.
auto const& query_object = jv.as_object();
std::set<std::string_view> unrecognized_keys = {};
for (auto const& [key, _] : query_object) {
if (!valid_keys.contains(key)) {
Expand All @@ -67,12 +82,14 @@ namespace phlex {
throw std::runtime_error(
fmt::format("Product selector contains unrecognized keys: {}", unrecognized_keys));
}
auto creator = value_if_exists(query_object, "creator");
auto layer = value_if_exists(query_object, "layer");
auto suffix = value_if_exists(query_object, "suffix");
auto stage = value_if_exists(query_object, "stage");
return product_selector{
.creator = std::move(creator), .layer = std::move(layer), .suffix = suffix, .stage = stage};
// Each field is initialized directly from the value returned by in_selector_field, so no
// field value is copied or moved through a named local. The initializers of a braced list are
// evaluated in order, so fields are read in declaration order and the first malformed field
// in that order is the one reported.
return product_selector{.creator = in_selector_field<identifier>(query_object, "creator"),
.layer = in_selector_field<identifier>(query_object, "layer"),
.suffix = in_selector_field<suffix_t>(query_object, "suffix"),
.stage = in_selector_field<identifier>(query_object, "stage")};
}

experimental::identifier experimental::tag_invoke(boost::json::value_to_tag<identifier> const&,
Expand Down
15 changes: 12 additions & 3 deletions phlex/configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <optional>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

Expand All @@ -23,9 +24,17 @@ namespace phlex {
throw std::runtime_error("Error retrieving parameter '" + key + "':\n" + e.what());
}

// Used later for product_selector
PHLEX_CONFIGURATION_INTERNAL_EXPORT std::optional<experimental::identifier> value_if_exists(
boost::json::object const& obj, std::string_view parameter);
// Returns the value stored under `parameter` in `obj` converted to T with
// boost::json::value_to, or std::nullopt when `obj` has no such key. Exceptions thrown by the
// conversion propagate unchanged.
template <typename T>
std::optional<T> value_if_exists(boost::json::object const& obj, std::string_view parameter)
{
if (!obj.contains(parameter)) {
return std::nullopt;
}
return boost::json::value_to<T>(obj.at(parameter));
}

// helper for unpacking json array
template <typename T, std::size_t... I>
Expand Down
1 change: 0 additions & 1 deletion phlex/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ cet_make_library(
detail/repeater_node.cpp
filter.cpp
framework_graph.cpp
glue.cpp
index_router.cpp
make_computational_edges.cpp
message.cpp
Expand Down
3 changes: 0 additions & 3 deletions phlex/core/consumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@
namespace {
std::vector<phlex::experimental::identifier> layers_from(phlex::product_selectors const& queries)
{
using namespace phlex::experimental::literals;
std::vector<phlex::experimental::identifier> result;
result.reserve(queries.size());
for (auto const& query : queries) {
if (query.layer) {
result.push_back(query.layer);
} else {
result.push_back("*"_id);
}
}
return result;
Expand Down
9 changes: 6 additions & 3 deletions phlex/core/detail/make_algorithm_name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

#include "phlex/configuration.hpp"
#include "phlex/model/algorithm_name.hpp"
#include "phlex/model/identifier.hpp"

#include <optional>
#include <string_view>

namespace phlex::experimental::internal {
algorithm_name make_algorithm_name(configuration const* config, std::string_view name)
{
return {config ? identifier(config->get<std::string_view>("module_label")) : ""_id,
identifier(name)};
std::optional<std::string_view> plugin_label;
if (config) {
plugin_label = config->get<std::string_view>("module_label");
}
return algorithm_name::create(plugin_label, name);
Comment thread
marcpaterno marked this conversation as resolved.
Resolved
}
}
25 changes: 0 additions & 25 deletions phlex/core/glue.cpp

This file was deleted.

9 changes: 0 additions & 9 deletions phlex/core/glue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ namespace phlex {

namespace phlex::detail {
struct node_catalog;
namespace internal {
PHLEX_CORE_EXPORT void verify_name(std::string_view name, configuration const* config);
}

// ==============================================================================
// Registering user functions
Expand Down Expand Up @@ -73,7 +70,6 @@ namespace phlex::detail {
std::string partition,
InitArgs&&... init_args)
{
internal::verify_name(name, config_);
return fold_api{config_,
name,
stage_,
Expand All @@ -94,7 +90,6 @@ namespace phlex::detail {
FT f, // NOLINT(performance-unnecessary-value-param)
concurrency c)
{
internal::verify_name(name, config_);
return make_registration<observer_node, declared_observer_ptr>(
config_,
name,
Expand All @@ -114,7 +109,6 @@ namespace phlex::detail {
FT f, // NOLINT(performance-unnecessary-value-param)
concurrency c)
{
internal::verify_name(name, config_);
return provider_api{config_,
name,
stage_,
Expand All @@ -133,7 +127,6 @@ namespace phlex::detail {
FT f, // NOLINT(performance-unnecessary-value-param)
concurrency c)
{
internal::verify_name(name, config_);
return make_registration<transform_node, declared_transform_ptr>(
config_,
name,
Expand All @@ -153,7 +146,6 @@ namespace phlex::detail {
FT f, // NOLINT(performance-unnecessary-value-param)
concurrency c)
{
internal::verify_name(name, config_);
return make_registration<predicate_node, declared_predicate_ptr>(
config_,
name,
Expand All @@ -173,7 +165,6 @@ namespace phlex::detail {
std::string destination_data_layer)
{
assert(!bound_obj_);
internal::verify_name(name, config_);
return unfold_api<T, decltype(predicate), decltype(unfold)>{
config_,
name,
Expand Down
11 changes: 9 additions & 2 deletions phlex/core/index_router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,14 @@ namespace phlex::detail {
provider_input_ports_t provider_input_ports)
{
for (auto& [input_product, provider_port] : provider_input_ports | std::views::values) {
auto [it, _] = index_set_nodes_.emplace(input_product.layer ? *input_product.layer : "*"_id,
if (!input_product.layer) {
if (!unresolved_index_set_node_) {
unresolved_index_set_node_ = std::make_shared<internal::index_set_node>(g);
}
make_edge(*unresolved_index_set_node_, *provider_port);
continue;
}
auto [it, _] = index_set_nodes_.emplace(*input_product.layer,
std::make_shared<internal::index_set_node>(g));
make_edge(*it->second, *provider_port);
}
Expand Down Expand Up @@ -302,7 +309,7 @@ namespace phlex::detail {
node_slots.flush_specs.push_back(
{.counting_layer = effective_counting_layer, .flush_port = flush_port});
}
multilayer_join_slots_.emplace(identifier{node_name}, std::move(node_slots));
multilayer_join_slots_.emplace(node_name, std::move(node_slots));
}
}

Expand Down
Loading
Loading