Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace boost::optional with std::optional. #3942

Merged
merged 2 commits into from
Mar 28, 2023
Merged
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
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build --action_env=BAZEL_CXXOPTS="-std=c++17"
18 changes: 9 additions & 9 deletions backends/bmv2/common/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ struct RegisterTraits<Arch::V1MODEL> {
// the index of the type parameter for the data stored in the register, in
// the type parameter list of the extern type declaration
static size_t dataTypeParamIdx() { return 0; }
static boost::optional<size_t> indexTypeParamIdx() { return boost::none; }
static std::optional<size_t> indexTypeParamIdx() { return std::nullopt; }
};

template <>
struct RegisterTraits<Arch::V1MODEL2020> : public RegisterTraits<Arch::V1MODEL> {
static boost::optional<size_t> indexTypeParamIdx() { return 1; }
static std::optional<size_t> indexTypeParamIdx() { return 1; }
};

template <>
Expand All @@ -142,7 +142,7 @@ struct RegisterTraits<Arch::PSA> {
static size_t dataTypeParamIdx() { return 0; }
// the index of the type parameter for the register index, in the type
// parameter list of the extern type declaration.
static boost::optional<size_t> indexTypeParamIdx() { return 1; }
static std::optional<size_t> indexTypeParamIdx() { return 1; }
};

template <Arch arch>
Expand Down Expand Up @@ -181,7 +181,7 @@ struct CounterlikeTraits<Standard::CounterExtern<Standard::Arch::V1MODEL>> {
static const cstring typeName() { return P4V1::V1Model::instance.counter.name; }
static const cstring directTypeName() { return P4V1::V1Model::instance.directCounter.name; }
static const cstring sizeParamName() { return "size"; }
static boost::optional<size_t> indexTypeParamIdx() { return boost::none; }
static std::optional<size_t> indexTypeParamIdx() { return std::nullopt; }
};

template <>
Expand All @@ -193,7 +193,7 @@ struct CounterlikeTraits<Standard::CounterExtern<Standard::Arch::V1MODEL2020>> {
static const cstring typeName() { return P4V1::V1Model::instance.counter.name; }
static const cstring directTypeName() { return P4V1::V1Model::instance.directCounter.name; }
static const cstring sizeParamName() { return "size"; }
static boost::optional<size_t> indexTypeParamIdx() { return 0; }
static std::optional<size_t> indexTypeParamIdx() { return 0; }
};

/// @ref CounterlikeTraits<> specialization for @ref CounterExtern for PSA
Expand All @@ -206,7 +206,7 @@ struct CounterlikeTraits<Standard::CounterExtern<Standard::Arch::PSA>> {
static const cstring sizeParamName() { return "n_counters"; }
// the index of the type parameter for the counter index, in the type
// parameter list of the extern type declaration.
static boost::optional<size_t> indexTypeParamIdx() { return 1; }
static std::optional<size_t> indexTypeParamIdx() { return 1; }
};

/// @ref CounterlikeTraits<> specialization for @ref MeterExtern for v1model
Expand All @@ -219,7 +219,7 @@ struct CounterlikeTraits<Standard::MeterExtern<Standard::Arch::V1MODEL>> {
static const cstring typeName() { return P4V1::V1Model::instance.meter.name; }
static const cstring directTypeName() { return P4V1::V1Model::instance.directMeter.name; }
static const cstring sizeParamName() { return "size"; }
static boost::optional<size_t> indexTypeParamIdx() { return boost::none; }
static std::optional<size_t> indexTypeParamIdx() { return std::nullopt; }
};

template <>
Expand All @@ -231,7 +231,7 @@ struct CounterlikeTraits<Standard::MeterExtern<Standard::Arch::V1MODEL2020>> {
static const cstring typeName() { return P4V1::V1Model::instance.meter.name; }
static const cstring directTypeName() { return P4V1::V1Model::instance.directMeter.name; }
static const cstring sizeParamName() { return "size"; }
static boost::optional<size_t> indexTypeParamIdx() { return 0; }
static std::optional<size_t> indexTypeParamIdx() { return 0; }
};

/// @ref CounterlikeTraits<> specialization for @ref MeterExtern for PSA
Expand All @@ -244,7 +244,7 @@ struct CounterlikeTraits<Standard::MeterExtern<Standard::Arch::PSA>> {
static const cstring sizeParamName() { return "n_meters"; }
// the index of the type parameter for the meter index, in the type
// parameter list of the extern type declaration.
static boost::optional<size_t> indexTypeParamIdx() { return 0; }
static std::optional<size_t> indexTypeParamIdx() { return 0; }
};

} // namespace Helpers
Expand Down
9 changes: 4 additions & 5 deletions backends/dpdk/control-plane/bfruntime_arch_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ limitations under the License.
#define DPDK_CONTROL_PLANE_BFRUNTIME_ARCH_HANDLER_H_

#include <iostream>
#include <optional>
#include <set>
#include <unordered_map>
#include <vector>

#include <boost/optional.hpp>

#include "control-plane/bfruntime.h"
#include "control-plane/p4RuntimeArchHandler.h"
#include "control-plane/p4RuntimeArchStandard.h"
Expand Down Expand Up @@ -163,7 +162,7 @@ class BFRuntimeArchHandler : public P4RuntimeArchHandlerCommon<arch> {
externInstance->mutable_info()->PackFrom(message);
}

boost::optional<ActionSelector> getActionSelector(const IR::ExternBlock *instance) {
std::optional<ActionSelector> getActionSelector(const IR::ExternBlock *instance) {
auto actionSelDecl = instance->node->to<IR::IDeclaration>();
// to be deleted, used to support deprecated ActionSelector constructor.
auto size = instance->getParameterValue("size");
Expand Down Expand Up @@ -295,8 +294,8 @@ class BFRuntimeArchHandler : public P4RuntimeArchHandlerCommon<arch> {
}

/// @return serialization information for the Digest extern instacne @decl
boost::optional<Digest> getDigest(const IR::Declaration_Instance *decl,
p4configv1::P4TypeInfo *p4RtTypeInfo) {
std::optional<Digest> getDigest(const IR::Declaration_Instance *decl,
p4configv1::P4TypeInfo *p4RtTypeInfo) {
BUG_CHECK(decl->type->is<IR::Type_Specialized>(), "%1%: expected Type_Specialized",
decl->type);
auto type = decl->type->to<IR::Type_Specialized>();
Expand Down
16 changes: 8 additions & 8 deletions backends/dpdk/control-plane/bfruntime_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ struct BFRuntimeSchemaGenerator::ActionSelector {
std::vector<P4Id> tableIds;
Util::JsonArray *annotations;

static boost::optional<ActionSelector> fromDPDK(
static std::optional<ActionSelector> fromDPDK(
const p4configv1::P4Info &p4info, const p4configv1::ExternInstance &externInstance) {
const auto &pre = externInstance.preamble();
::dpdk::ActionSelector actionSelector;
if (!externInstance.info().UnpackTo(&actionSelector)) {
::error(ErrorType::ERR_NOT_FOUND,
"Extern instance %1% does not pack an ActionSelector object", pre.name());
return boost::none;
return std::nullopt;
}
auto selectorId = makeBFRuntimeId(pre.id(), ::dpdk::P4Ids::ACTION_SELECTOR);
auto selectorGetMemId =
Expand Down Expand Up @@ -163,7 +163,7 @@ bool BFRuntimeSchemaGenerator::addActionProfIds(const p4configv1::Table &table,
auto actProfId = static_cast<P4Id>(0);
if (implementationId > 0) {
auto hasSelector = actProfHasSelector(implementationId);
if (hasSelector == boost::none) {
if (hasSelector == std::nullopt) {
::error(ErrorType::ERR_INVALID, "Invalid implementation id in p4info: %1%",
implementationId);
return false;
Expand All @@ -187,20 +187,20 @@ bool BFRuntimeSchemaGenerator::addActionProfIds(const p4configv1::Table &table,
void BFRuntimeSchemaGenerator::addActionProfs(Util::JsonArray *tablesJson) const {
for (const auto &actionProf : p4info.action_profiles()) {
auto actionProfInstance = ActionProf::from(p4info, actionProf);
if (actionProfInstance == boost::none) continue;
if (actionProfInstance == std::nullopt) continue;
addActionProfCommon(tablesJson, *actionProfInstance);
}
}

boost::optional<bool> BFRuntimeSchemaGenerator::actProfHasSelector(P4Id actProfId) const {
std::optional<bool> BFRuntimeSchemaGenerator::actProfHasSelector(P4Id actProfId) const {
if (isOfType(actProfId, p4configv1::P4Ids::ACTION_PROFILE)) {
auto *actionProf = Standard::findActionProf(p4info, actProfId);
if (actionProf == nullptr) return boost::none;
if (actionProf == nullptr) return std::nullopt;
return actionProf->with_selector();
} else if (isOfType(actProfId, ::dpdk::P4Ids::ACTION_SELECTOR)) {
return true;
}
return boost::none;
return std::nullopt;
}

const Util::JsonObject *BFRuntimeSchemaGenerator::genSchema() const {
Expand Down Expand Up @@ -249,7 +249,7 @@ void BFRuntimeSchemaGenerator::addDPDKExterns(Util::JsonArray *tablesJson,
if (externTypeId == ::dpdk::P4Ids::ACTION_SELECTOR) {
for (const auto &externInstance : externType.instances()) {
auto actionSelector = ActionSelector::fromDPDK(p4info, externInstance);
if (actionSelector != boost::none) {
if (actionSelector != std::nullopt) {
addActionSelectorCommon(tablesJson, *actionSelector);
addActionSelectorGetMemberCommon(tablesJson, *actionSelector);
}
Expand Down
6 changes: 3 additions & 3 deletions backends/dpdk/control-plane/bfruntime_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@ class BFRuntimeSchemaGenerator : public BFRuntimeGenerator {
void addMatchActionData(const p4configv1::Table &table, Util::JsonObject *tableJson,
Util::JsonArray *dataJson, P4Id maxActionParamId) const;

boost::optional<bool> actProfHasSelector(P4Id actProfId) const override;
std::optional<bool> actProfHasSelector(P4Id actProfId) const override;

static boost::optional<ActionProf> fromDPDKActionProfile(
static std::optional<ActionProf> fromDPDKActionProfile(
const p4configv1::P4Info &p4info, const p4configv1::ExternInstance &externInstance) {
const auto &pre = externInstance.preamble();
p4configv1::ActionProfile actionProfile;
if (!externInstance.info().UnpackTo(&actionProfile)) {
::error(ErrorType::ERR_NOT_FOUND,
"Extern instance %1% does not pack an ActionProfile object", pre.name());
return boost::none;
return std::nullopt;
}
auto tableIds = collectTableIds(p4info, actionProfile.table_ids().begin(),
actionProfile.table_ids().end());
Expand Down
10 changes: 5 additions & 5 deletions backends/dpdk/dpdkArch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1719,16 +1719,16 @@ const IR::Node *CopyMatchKeysToSingleStruct::doStatement(const IR::Statement *st

namespace Helpers {

boost::optional<P4::ExternInstance> getExternInstanceFromProperty(
std::optional<P4::ExternInstance> getExternInstanceFromProperty(
const IR::P4Table *table, const cstring &propertyName, P4::ReferenceMap *refMap,
P4::TypeMap *typeMap, bool *isConstructedInPlace, cstring &externName) {
auto property = table->properties->getProperty(propertyName);
if (property == nullptr) return boost::none;
if (property == nullptr) return std::nullopt;
if (!property->value->is<IR::ExpressionValue>()) {
::error(ErrorType::ERR_EXPECTED,
"Expected %1% property value for table %2% to be an expression: %3%", propertyName,
table->controlPlaneName(), property);
return boost::none;
return std::nullopt;
}

auto expr = property->value->to<IR::ExpressionValue>()->expression;
Expand All @@ -1740,7 +1740,7 @@ boost::optional<P4::ExternInstance> getExternInstanceFromProperty(
"Table '%1%' has an anonymous table property '%2%' with no name annotation, "
"which is not supported by P4Runtime",
table->controlPlaneName(), propertyName);
return boost::none;
return std::nullopt;
}
auto name = property->controlPlaneName();
auto externInstance = P4::ExternInstance::resolve(expr, refMap, typeMap, name);
Expand All @@ -1749,7 +1749,7 @@ boost::optional<P4::ExternInstance> getExternInstanceFromProperty(
"Expected %1% property value for table %2% to resolve to an "
"extern instance: %3%",
propertyName, table->controlPlaneName(), property);
return boost::none;
return std::nullopt;
}
return externInstance;
}
Expand Down
22 changes: 11 additions & 11 deletions backends/dpdk/dpdkProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,43 +545,43 @@ bool ConvertToDpdkControl::checkTableValid(const IR::P4Table *a) {
return true;
}

boost::optional<const IR::Member *> ConvertToDpdkControl::getMemExprFromProperty(
std::optional<const IR::Member *> ConvertToDpdkControl::getMemExprFromProperty(
const IR::P4Table *table, cstring propertyName) {
auto property = table->properties->getProperty(propertyName);
if (property == nullptr) return boost::none;
if (property == nullptr) return std::nullopt;
if (!property->value->is<IR::ExpressionValue>()) {
::error(ErrorType::ERR_EXPECTED,
"Expected %1% property value for table %2% to be an expression: %3%", propertyName,
table->controlPlaneName(), property);
return boost::none;
return std::nullopt;
}
auto expr = property->value->to<IR::ExpressionValue>()->expression;
if (!expr->is<IR::Member>()) {
::error(ErrorType::ERR_EXPECTED,
"Exprected %1% property value for table %2% to be a member", propertyName,
table->controlPlaneName());
return boost::none;
return std::nullopt;
}

return expr->to<IR::Member>();
}

boost::optional<int> ConvertToDpdkControl::getNumberFromProperty(const IR::P4Table *table,
cstring propertyName) {
std::optional<int> ConvertToDpdkControl::getNumberFromProperty(const IR::P4Table *table,
cstring propertyName) {
auto property = table->properties->getProperty(propertyName);
if (property == nullptr) return boost::none;
if (property == nullptr) return std::nullopt;
if (!property->value->is<IR::ExpressionValue>()) {
::error(ErrorType::ERR_EXPECTED,
"Expected %1% property value for table %2% to be an expression: %3%", propertyName,
table->controlPlaneName(), property);
return boost::none;
return std::nullopt;
}
auto expr = property->value->to<IR::ExpressionValue>()->expression;
if (!expr->is<IR::Constant>()) {
::error(ErrorType::ERR_EXPECTED,
"Exprected %1% property value for table %2% to be a constant", propertyName,
table->controlPlaneName());
return boost::none;
return std::nullopt;
}

return expr->to<IR::Constant>()->asInt();
Expand All @@ -597,8 +597,8 @@ bool ConvertToDpdkControl::preorder(const IR::P4Table *t) {
auto n_groups_max = getNumberFromProperty(t, "n_groups_max");
auto n_members_per_group_max = getNumberFromProperty(t, "n_members_per_group_max");

if (group_id == boost::none || member_id == boost::none || n_groups_max == boost::none ||
n_members_per_group_max == boost::none)
if (group_id == std::nullopt || member_id == std::nullopt || n_groups_max == std::nullopt ||
n_members_per_group_max == std::nullopt)
return false;

auto selector = new IR::DpdkSelector(t->name, (*group_id)->clone(), (*member_id)->clone(),
Expand Down
4 changes: 2 additions & 2 deletions backends/dpdk/dpdkProgram.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ class ConvertToDpdkControl : public Inspector {
void add_table(const IR::DpdkLearner *s) { learners.push_back(s); }
void add_action(const IR::DpdkAction *a) { actions.push_back(a); }

boost::optional<const IR::Member *> getMemExprFromProperty(const IR::P4Table *, cstring);
boost::optional<int> getNumberFromProperty(const IR::P4Table *, cstring);
std::optional<const IR::Member *> getMemExprFromProperty(const IR::P4Table *, cstring);
std::optional<int> getNumberFromProperty(const IR::P4Table *, cstring);
};

class CollectActionUses : public Inspector {
Expand Down
8 changes: 4 additions & 4 deletions backends/graphs/controls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ bool ControlGraphs::preorder(const IR::PackageBlock *block) {

Graph *g_ = new Graph();
g = g_;
instanceName = boost::none;
instanceName = std::nullopt;
boost::get_property(*g_, boost::graph_name) = name;
BUG_CHECK(controlStack.isEmpty(), "Invalid control stack state");
g = controlStack.pushBack(*g_, "");
Expand Down Expand Up @@ -111,9 +111,9 @@ bool ControlGraphs::preorder(const IR::ControlBlock *block) {

bool ControlGraphs::preorder(const IR::P4Control *cont) {
bool doPop = false;
// instanceName == boost::none <=> top level
if (instanceName != boost::none) {
g = controlStack.pushBack(*g, instanceName.get());
// instanceName == std::nullopt <=> top level
if (instanceName != std::nullopt) {
g = controlStack.pushBack(*g, instanceName.value());
doPop = true;
}
return_parents.clear();
Expand Down
2 changes: 1 addition & 1 deletion backends/graphs/controls.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ControlGraphs : public Graphs {
// new subgraph and push it to the stack; this new graph becomes the
// "current graph" to which we add vertices (e.g. tables).
ControlStack controlStack{};
boost::optional<cstring> instanceName{};
std::optional<cstring> instanceName{};
};

} // namespace graphs
Expand Down
4 changes: 2 additions & 2 deletions backends/graphs/graphs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ void Graphs::limitStringSize(std::stringstream &sstream, std::stringstream &help
helper_sstream.clear();
}

boost::optional<Graphs::vertex_t> Graphs::merge_other_statements_into_vertex() {
if (statementsStack.empty()) return boost::none;
std::optional<Graphs::vertex_t> Graphs::merge_other_statements_into_vertex() {
if (statementsStack.empty()) return std::nullopt;
std::stringstream sstream;
std::stringstream helper_sstream; // to limit line width

Expand Down
4 changes: 2 additions & 2 deletions backends/graphs/graphs.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ limitations under the License.
#endif

#include <map>
#include <optional>
#include <utility> // std::pair
#include <vector>

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/graphviz.hpp>
#include <boost/optional.hpp>

#include "frontends/p4/parserCallGraph.h"
#include "ir/ir.h"
Expand Down Expand Up @@ -135,7 +135,7 @@ class Graphs : public Inspector {

// merge misc control statements (action calls, extern method calls,
// assignments) into a single vertex to reduce graph complexity
boost::optional<vertex_t> merge_other_statements_into_vertex();
std::optional<vertex_t> merge_other_statements_into_vertex();

vertex_t add_vertex(const cstring &name, VertexType type);
vertex_t add_and_connect_vertex(const cstring &name, VertexType type);
Expand Down
2 changes: 1 addition & 1 deletion backends/graphs/parsers.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ParserGraphs : public Graphs {
private:
P4::ReferenceMap *refMap;
const cstring graphsDir;
boost::optional<cstring> instanceName{};
std::optional<cstring> instanceName{};
};

} // namespace graphs
Expand Down
Loading