Skip to content
Draft
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
13 changes: 13 additions & 0 deletions form/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

Prototype development for I/O infrastructure supporting Phlex

## Product suffix text

The Phlex FORM writer copies the textual value of each product specification's
`suffix_t` into FORM's product label. An explicit empty suffix (`empty_string{}`)
is written as `""`; a named suffix is written with its original spelling, including
case and underscores (for example, `Hits_2`). Empty text is a concrete product
suffix, not an omitted product or an unrestricted selector.

The persisted representation is unchanged: the product dictionary retains that
suffix text in `product_name`, and its `container_name` remains `row_space/suffix`.
An empty suffix therefore retains the trailing `/`, while a named suffix retains
its text after `/`. No placeholder name or file-format migration is introduced.

## build

`cmake -DUSE_FORM_ALONE=ON -DFORM_USE_ROOT_STORAGE=ON ../phlex/ ; make`
Expand Down
7 changes: 7 additions & 0 deletions phlex/core/consumer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@

namespace phlex::detail {
enum class require_layers : char { multi_input_only, always };

/// Base class of nodes that consume data products.
///
/// Accessor contract: `name()` is the complete node name. `name().plugin()` is its plugin
/// component, which is absent (`std::nullopt`) for an unqualified name, such as one registered
/// without a configuration; it is never an invalid empty `identifier`.
/// `name().algorithm()` is the non-empty algorithm component.
class PHLEX_CORE_EXPORT consumer {
using layer_check_node_t = tbb::flow::multifunction_node<message, message_tuple<1UZ>>;

Expand Down
4 changes: 4 additions & 0 deletions phlex/core/detail/make_algorithm_name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include <string_view>

namespace phlex::experimental::internal {
// The plugin component is absent only when there is no configuration. A
// configuration must supply a non-empty 'module_label': a missing label is an error reported by
// the configuration, and an empty label is rejected by algorithm_name::create rather than
// treated as an absent plugin.
algorithm_name make_algorithm_name(configuration const* config, std::string_view name)
{
std::optional<std::string_view> plugin_label;
Expand Down
3 changes: 3 additions & 0 deletions phlex/core/producer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include <oneapi/tbb/flow_graph.h>

namespace phlex::detail {
/// Independent producer interface used by the catalog, including translators.
/// Outputs carry explicit empty or named `suffix_t` values; `name()` retains the creator's
/// plugin component. The producer must outlive edges using its borrowed output port.
class PHLEX_CORE_EXPORT producer {
public:
virtual ~producer() = default;
Expand Down
2 changes: 1 addition & 1 deletion phlex/core/producer_catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace {
using named_output_port = producer_catalog::named_output_port;

bool providers_only(product_selector const& query,
std::multimap<product_suffix_t, named_output_port> const& producers,
std::multimap<suffix_t, named_output_port> const& producers,
identifier const& stage)
{
if (query.stage.has_value() && query.stage.value() != "CURRENT"_idq &&
Expand Down
5 changes: 4 additions & 1 deletion phlex/core/producer_catalog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ namespace phlex::detail {
class producer;
using product_suffix_t = phlex::experimental::suffix_t;

/// Catalogs independent producers by their explicit empty or named `suffix_t` outputs.
/// An omitted selector suffix searches all keys; an explicit suffix searches only that key.
/// Creator values retain both plugin and algorithm components, and output ports are borrowed.
class PHLEX_CORE_EXPORT producer_catalog {
public:
explicit producer_catalog(std::span<producer* const> producers);
Expand All @@ -36,7 +39,7 @@ namespace phlex::detail {
auto values() const { return producers_ | std::views::values; }

private:
std::multimap<product_suffix_t, named_output_port> producers_;
std::multimap<phlex::experimental::suffix_t, named_output_port> producers_;
};
}

Expand Down
2 changes: 1 addition & 1 deletion phlex/core/product_selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace phlex {
bool product_selector::creator_match(experimental::algorithm_name const& alg) const
{
if (!creator) {
return true; // empty creator matches everything
return true; // an omitted creator criterion matches everything
}
experimental::identifier const& creator{*(this->creator)};
return alg.plugin() == creator || alg.algorithm() == creator;
Expand Down
5 changes: 5 additions & 0 deletions phlex/core/product_selector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,16 @@ namespace phlex {
/// from a configuration object with @c config.get<product_selector>(key).
struct PHLEX_CORE_EXPORT product_selector {
/// Plugin label (configuration key) or algorithm name of the product's creator.
/// An omitted creator is unrestricted.
/// A supplied name matches either the plugin or the algorithm of a specification's creator.
detail::creator_name creator;
/// Data layer of the product. Required for every input of multi-input algorithms,
/// folds and unfolds; products from other layers are not delivered.
detail::layer_name layer;
/// Product suffix, as given to @c output_product_suffixes(...).
/// Omitted matches any suffix; empty matches only empty; named matches only that name.
/// C-string literals convert implicitly; runtime strings require explicit suffix_t construction.
/// Equality, ordering, and diagnostics distinguish all three states.
std::optional<experimental::suffix_t> suffix;
/// Stage that created the product; @c "CURRENT" means the job's own stage.
std::optional<experimental::identifier> stage;
Expand Down
4 changes: 4 additions & 0 deletions phlex/core/upstream_predicates.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ namespace phlex::detail {
return experimental_when({std::forward<decltype(names)>(names)...});
}

// Fluent suffix registration is textual: the strings given here, including the empty string
// and the default used when no suffixes are registered, stay strings in the registrar. They
// become `suffix_t` values (empty text as `empty_string`, non-empty text as a named
// identifier) when `to_product_specifications()` creates the product specifications.
template <std::size_t M>
requires(NumberOutputProducts > 0)
void output_product_suffixes(std::array<std::string, M> outputs)
Expand Down
18 changes: 17 additions & 1 deletion phlex/model/algorithm_name.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,25 @@
#include <string_view>

namespace phlex::experimental {
/// The creator of a product or the name of an algorithm.
///
/// An algorithm name always has a non-empty algorithm component. Its plugin component is
/// optional: either a non-empty plugin name or absent (for an unqualified name). A
/// default-constructed algorithm name is not valid, so one must always be constructed from a
/// name.
class PHLEX_MODEL_EXPORT algorithm_name {
public:
/// Parse text that is either `algorithm` or `plugin_label:algorithm`.
algorithm_name() = delete;

/// Parses a creator name, which is either `algorithm` or `plugin_label:algorithm`.
///
/// Accepted forms:
/// - `algorithm`: the plugin component is absent.
/// - `plugin_label:algorithm`: both components are non-empty identifiers.
///
/// Each component must satisfy the character rules of `identifier`. Rejected inputs include
/// the empty string, a leading colon (`:algorithm`), a trailing colon (`plugin_label:`), and
/// any empty component.
///
/// Throws `std::invalid_argument` if `spec` is malformed. The message quotes the offending
/// text and says which part of the name is invalid and why. Only the first problem found is
Expand Down
10 changes: 9 additions & 1 deletion phlex/model/handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <gsl/pointers>

#include <string>
#include <string_view>
#include <type_traits>
#include <utility>
Expand Down Expand Up @@ -54,6 +55,10 @@ namespace phlex {
using const_reference = value_type const&;
using const_pointer = value_type const*;

/// Borrowed textual views of the creator's components. Each view refers to the text owned
/// by the product specification that the handle references, so it is valid only while that
/// specification (and thus the handle's source) is alive. No copy is stored. A component that
/// is absent (the plugin of an unqualified creator) is an empty view.
struct algorithm_name_view {
std::string_view plugin;
std::string_view algorithm;
Expand Down Expand Up @@ -87,14 +92,17 @@ namespace phlex {
// NOLINTEND(google-explicit-constructor)
auto const& data_cell_index() const noexcept { return *index_; }

// Product specification information
// Product specification information. The handle exposes borrowed textual views, not the
// domain types (`suffix_t`, `identifier`), so callers need not depend on them.
/// Views of the creator's plugin and algorithm names. Absent components are empty views.
algorithm_name_view creator() const noexcept
{
auto const& creator = spec_->creator();
auto const& plugin = creator.plugin();
return {plugin ? std::string_view(*plugin) : std::string_view{},
std::string_view(creator.algorithm())};
}
/// View of the suffix text; empty for the explicit empty suffix.
std::string_view suffix() const noexcept { return spec_->suffix().text(); }
std::string_view layer() const noexcept { return std::string_view(index_->layer_name()); }
std::string_view stage() const noexcept { return std::string_view(*stage_); }
Expand Down
2 changes: 2 additions & 0 deletions phlex/model/product_specification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ namespace phlex::detail {
{
static std::string const default_product_suffix;

// Fluent suffix registration is textual; empty text becomes `empty_string` and non-empty
// text a named identifier here, when the specifications are created.
if (output_suffixes.empty()) {
// This happens whenever the user does not specify output_product_suffixes(...), so we
// assign the default suffix to all output data products.
Expand Down
34 changes: 31 additions & 3 deletions phlex/model/product_specification.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,51 @@
namespace phlex::experimental {
/// Describes a product supplied by an algorithm.
///
/// A product specification is a partial label: it carries the creator, suffix, and type of a
/// product. Its metadata combines with a concrete data-cell/provider layer to form the complete
/// label of a created product, so the layer is deliberately not a member of this class.
///
/// The creator is a required `algorithm_name`; there is no default or creator-less
/// construction. Equality, ordering, and hashing cover the creator, suffix, and type. A
/// specification whose type is unspecified is an exact key, not a wildcard.
///
/// The suffix is a `suffix_t`: either the explicit empty value (`empty_string`) or a named
/// `identifier`. Parsing, defaulting, formatting, equality, ordering, and hashing all preserve
/// that representation without manufacturing an empty `identifier`. The default suffix is
/// explicitly empty. It is never an omitted selection criterion, which is `std::nullopt` in a
/// product selector.
///
/// Textual boundary: specifications supplied as text (the `creator/suffix` text accepted by
/// the text constructors, and the strings given to the fluent `output_product_suffixes(...)`
/// registration
/// API, which `phlex::detail::to_product_specifications()` converts) remain strings. Empty
/// suffix text becomes `empty_string` and non-empty suffix text becomes a named `identifier`,
/// when the specification is created. Non-empty text that is not a valid name is rejected rather
/// than stored as an empty suffix.
///
/// This source-provider construction API is experimental and may change before it is
/// promoted to the stable phlex namespace.
class PHLEX_MODEL_EXPORT product_specification {
public:
// There is no default or creator-less construction: every specification names its creator.

// Text constructors parse the `creator/suffix` form, which must contain the slash. Structural
// errors throw `std::runtime_error`; an invalid creator or suffix throws
// `std::invalid_argument`.
/// Parses `creator/suffix` text, which must contain the slash; `creator/` has an empty
/// suffix. Text without a slash, with an empty creator part (`/hits`, `/`), or empty is
/// invalid and throws `std::runtime_error`; an invalid creator or suffix throws
/// `std::invalid_argument`. Empty suffix text yields an explicit `empty_string` suffix;
/// non-empty suffix text yields a named `identifier`.
// NOLINTBEGIN(google-explicit-constructor) - Implicit conversion is intentional
product_specification(char const* name);
product_specification(std::string const& name);
product_specification(std::string_view name);
// NOLINTEND(google-explicit-constructor)
product_specification(algorithm_name creator, suffix_t suffix, type_id type);

/// Text of the specification in the form `creator/suffix`; the type is not part of the text.
std::string to_string() const;
/// The creator; always present.
algorithm_name const& creator() const noexcept { return creator_; }
/// The suffix: `empty_string` or a named `identifier`.
suffix_t const& suffix() const noexcept { return suffix_; }
type_id type() const noexcept { return type_id_; }

Expand Down Expand Up @@ -65,6 +92,7 @@ template <>
struct std::hash<phlex::experimental::product_specification> {
std::size_t operator()(phlex::experimental::product_specification const& spec) const noexcept
{
// Hash the same components that equality compares, including whether the plugin is present.
std::size_t hash = 0;
auto const& plugin = spec.creator_.plugin();
boost::hash_combine(hash, plugin.has_value());
Expand Down
2 changes: 1 addition & 1 deletion phlex/model/product_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace phlex::experimental {

algorithm_name product_store::default_source()
{
static algorithm_name const def = algorithm_name{"Source"};
static algorithm_name const def = algorithm_name{"phlex_source"};
return def;
}
}
5 changes: 4 additions & 1 deletion phlex/model/product_store.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ namespace phlex::experimental {
template <typename T>
void add_product(product_specification const& key, std::unique_ptr<product<T>>&& t);

// default Source identifier
/// The creator used by default for products supplied by a source.
///
/// This is the valid internal creator name `phlex_source`: an unqualified algorithm name
/// with no plugin component.
static experimental::algorithm_name default_source();

private:
Expand Down
2 changes: 2 additions & 0 deletions phlex/model/products.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace phlex::detail {

gsl::not_null<product_base const*> products::find_product(product_specification const& spec) const
{
// Lookup is exact: product_specification equality covers the creator, suffix, and type, so a
// specification matches only a product stored under all three.
auto it =
std::ranges::find(products_, spec, [](auto const& p) -> auto const& { return p.first; });
if (it == products_.end()) {
Expand Down
52 changes: 38 additions & 14 deletions test/core_misc_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <stdexcept>
#include <string>
#include <string_view>
#include <type_traits>
#include <utility>
#include <vector>

Expand All @@ -27,35 +28,38 @@ TEST_CASE("algorithm_name tests", "[model]")
using namespace phlex::experimental;
using namespace phlex::experimental::literals;

SECTION("Empty creator name is rejected")
{
STATIC_CHECK_FALSE(std::is_default_constructible_v<algorithm_name>);
CHECK_THROWS_AS(algorithm_name{""}, std::invalid_argument);
}
SECTION("Create from string with colon")
{
auto an = algorithm_name{"plugin:algo"};
CHECK(an.to_string() == "plugin:algo");
REQUIRE(an.plugin().has_value());
CHECK(an.plugin().value() == "plugin"_id);
CHECK(an.algorithm() == "algo"_id);
}
SECTION("Create from string without colon")
SECTION("Create from string without colon has an absent plugin")
{
auto an = algorithm_name{"algo"};
// For 'either' cases, the word is stored as algorithm_
CHECK(an.to_string() == "algo");
CHECK_FALSE(an.plugin().has_value());
CHECK(an.algorithm() == "algo"_id);
}
SECTION("Create rejects an empty plugin or algorithm")
{
CHECK_THROWS_AS(algorithm_name{":find_hits"}, std::invalid_argument);
CHECK_THROWS_AS(algorithm_name{"reco:"}, std::invalid_argument);
CHECK_THROWS_AS(algorithm_name{":"}, std::invalid_argument);
}
SECTION("Create from char pointer")
{
auto an = algorithm_name{"ptr:algo"};
CHECK(an.to_string() == "ptr:algo");
}
SECTION("Unqualified name has no plugin")
{
auto const an = algorithm_name{"algo"};
CHECK_FALSE(an.plugin().has_value());
CHECK(an.algorithm() == "algo"_id);
}
SECTION("Qualified name has plugin and algorithm")
{
auto const an = algorithm_name{"plugin:algo"};
REQUIRE(an.plugin().has_value());
CHECK(an.plugin().value() == "plugin"_id);
CHECK(an.algorithm() == "algo"_id);
}
SECTION("Construct from typed components")
{
algorithm_name const unqualified{std::nullopt, "algo"_id};
Expand Down Expand Up @@ -155,6 +159,7 @@ TEST_CASE("make_algorithm_name tests", "[core]")
auto const name = make_algorithm_name(nullptr, "my_algorithm");
CHECK_FALSE(name.plugin().has_value());
CHECK(name.algorithm() == "my_algorithm"_id);
CHECK(name.to_string() == "my_algorithm");
}

SECTION("With configuration the module label is the plugin")
Expand All @@ -166,6 +171,7 @@ TEST_CASE("make_algorithm_name tests", "[core]")
auto const name = make_algorithm_name(&config, "my_algorithm");
REQUIRE(name.plugin().has_value());
CHECK(name.plugin().value() == "my_module"_id);
CHECK(name.algorithm() == "my_algorithm"_id);
CHECK(name.to_string() == "my_module:my_algorithm");
}

Expand All @@ -185,6 +191,24 @@ TEST_CASE("make_algorithm_name tests", "[core]")
"Invalid algorithm name \"my_module:\": the algorithm after ':' is missing"));
}

SECTION("A configuration without a module label is an error, not an absent plugin")
{
phlex::configuration const config{boost::json::object{}};
CHECK_THROWS_AS(make_algorithm_name(&config, "my_algorithm"), std::runtime_error);
}

SECTION("A configured empty module label is an error, not an absent plugin")
{
boost::json::object obj;
obj["module_label"] = "";
phlex::configuration const config{obj};
CHECK_THROWS_AS(make_algorithm_name(&config, "my_algorithm"), std::invalid_argument);
CHECK_THROWS_WITH(
make_algorithm_name(&config, "my_algorithm"),
Catch::Matchers::ContainsSubstring(
"Invalid algorithm name \":my_algorithm\": the plugin label before ':' is missing"));
}

SECTION("A malformed algorithm name is reported with the composed name")
{
boost::json::object obj;
Expand Down
Loading
Loading