Skip to content

Commit

Permalink
feat!: Add expression width into acir (#4014)
Browse files Browse the repository at this point in the history
Resolves Noir issue noir-lang/noir#4012, by
adding ExpressionWidth into acir.
The PR simply account for this new field and update the serialisation.
It also set the width during csat transformation phase.

---------

Co-authored-by: kevaundray <kevtheappdev@gmail.com>
  • Loading branch information
2 people authored and AztecBot committed Feb 6, 2024
1 parent 291cdfe commit ce6f451
Showing 1 changed file with 167 additions and 0 deletions.
167 changes: 167 additions & 0 deletions cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,29 @@ struct Opcode {
static Opcode bincodeDeserialize(std::vector<uint8_t>);
};

struct ExpressionWidth {

struct Unbounded {
friend bool operator==(const Unbounded&, const Unbounded&);
std::vector<uint8_t> bincodeSerialize() const;
static Unbounded bincodeDeserialize(std::vector<uint8_t>);
};

struct Bounded {
uint64_t width;

friend bool operator==(const Bounded&, const Bounded&);
std::vector<uint8_t> bincodeSerialize() const;
static Bounded bincodeDeserialize(std::vector<uint8_t>);
};

std::variant<Unbounded, Bounded> value;

friend bool operator==(const ExpressionWidth&, const ExpressionWidth&);
std::vector<uint8_t> bincodeSerialize() const;
static ExpressionWidth bincodeDeserialize(std::vector<uint8_t>);
};

struct OpcodeLocation {

struct Acir {
Expand Down Expand Up @@ -1115,6 +1138,7 @@ struct PublicInputs {
struct Circuit {
uint32_t current_witness_index;
std::vector<Opcode> opcodes;
ExpressionWidth expression_width;
std::vector<Witness> private_parameters;
PublicInputs public_parameters;
PublicInputs return_values;
Expand Down Expand Up @@ -5933,6 +5957,9 @@ inline bool operator==(const Circuit& lhs, const Circuit& rhs)
if (!(lhs.opcodes == rhs.opcodes)) {
return false;
}
if (!(lhs.expression_width == rhs.expression_width)) {
return false;
}
if (!(lhs.private_parameters == rhs.private_parameters)) {
return false;
}
Expand Down Expand Up @@ -5977,6 +6004,7 @@ void serde::Serializable<Circuit::Circuit>::serialize(const Circuit::Circuit& ob
serializer.increase_container_depth();
serde::Serializable<decltype(obj.current_witness_index)>::serialize(obj.current_witness_index, serializer);
serde::Serializable<decltype(obj.opcodes)>::serialize(obj.opcodes, serializer);
serde::Serializable<decltype(obj.expression_width)>::serialize(obj.expression_width, serializer);
serde::Serializable<decltype(obj.private_parameters)>::serialize(obj.private_parameters, serializer);
serde::Serializable<decltype(obj.public_parameters)>::serialize(obj.public_parameters, serializer);
serde::Serializable<decltype(obj.return_values)>::serialize(obj.return_values, serializer);
Expand All @@ -5993,6 +6021,7 @@ Circuit::Circuit serde::Deserializable<Circuit::Circuit>::deserialize(Deserializ
Circuit::Circuit obj;
obj.current_witness_index = serde::Deserializable<decltype(obj.current_witness_index)>::deserialize(deserializer);
obj.opcodes = serde::Deserializable<decltype(obj.opcodes)>::deserialize(deserializer);
obj.expression_width = serde::Deserializable<decltype(obj.expression_width)>::deserialize(deserializer);
obj.private_parameters = serde::Deserializable<decltype(obj.private_parameters)>::deserialize(deserializer);
obj.public_parameters = serde::Deserializable<decltype(obj.public_parameters)>::deserialize(deserializer);
obj.return_values = serde::Deserializable<decltype(obj.return_values)>::deserialize(deserializer);
Expand Down Expand Up @@ -6231,6 +6260,144 @@ Circuit::Expression serde::Deserializable<Circuit::Expression>::deserialize(Dese

namespace Circuit {

inline bool operator==(const ExpressionWidth& lhs, const ExpressionWidth& rhs)
{
if (!(lhs.value == rhs.value)) {
return false;
}
return true;
}

inline std::vector<uint8_t> ExpressionWidth::bincodeSerialize() const
{
auto serializer = serde::BincodeSerializer();
serde::Serializable<ExpressionWidth>::serialize(*this, serializer);
return std::move(serializer).bytes();
}

inline ExpressionWidth ExpressionWidth::bincodeDeserialize(std::vector<uint8_t> input)
{
auto deserializer = serde::BincodeDeserializer(input);
auto value = serde::Deserializable<ExpressionWidth>::deserialize(deserializer);
if (deserializer.get_buffer_offset() < input.size()) {
throw_or_abort("Some input bytes were not read");
}
return value;
}

} // end of namespace Circuit

template <>
template <typename Serializer>
void serde::Serializable<Circuit::ExpressionWidth>::serialize(const Circuit::ExpressionWidth& obj,
Serializer& serializer)
{
serializer.increase_container_depth();
serde::Serializable<decltype(obj.value)>::serialize(obj.value, serializer);
serializer.decrease_container_depth();
}

template <>
template <typename Deserializer>
Circuit::ExpressionWidth serde::Deserializable<Circuit::ExpressionWidth>::deserialize(Deserializer& deserializer)
{
deserializer.increase_container_depth();
Circuit::ExpressionWidth obj;
obj.value = serde::Deserializable<decltype(obj.value)>::deserialize(deserializer);
deserializer.decrease_container_depth();
return obj;
}

namespace Circuit {

inline bool operator==(const ExpressionWidth::Unbounded& lhs, const ExpressionWidth::Unbounded& rhs)
{
return true;
}

inline std::vector<uint8_t> ExpressionWidth::Unbounded::bincodeSerialize() const
{
auto serializer = serde::BincodeSerializer();
serde::Serializable<ExpressionWidth::Unbounded>::serialize(*this, serializer);
return std::move(serializer).bytes();
}

inline ExpressionWidth::Unbounded ExpressionWidth::Unbounded::bincodeDeserialize(std::vector<uint8_t> input)
{
auto deserializer = serde::BincodeDeserializer(input);
auto value = serde::Deserializable<ExpressionWidth::Unbounded>::deserialize(deserializer);
if (deserializer.get_buffer_offset() < input.size()) {
throw_or_abort("Some input bytes were not read");
}
return value;
}

} // end of namespace Circuit

template <>
template <typename Serializer>
void serde::Serializable<Circuit::ExpressionWidth::Unbounded>::serialize(const Circuit::ExpressionWidth::Unbounded& obj,
Serializer& serializer)
{}

template <>
template <typename Deserializer>
Circuit::ExpressionWidth::Unbounded serde::Deserializable<Circuit::ExpressionWidth::Unbounded>::deserialize(
Deserializer& deserializer)
{
Circuit::ExpressionWidth::Unbounded obj;
return obj;
}

namespace Circuit {

inline bool operator==(const ExpressionWidth::Bounded& lhs, const ExpressionWidth::Bounded& rhs)
{
if (!(lhs.width == rhs.width)) {
return false;
}
return true;
}

inline std::vector<uint8_t> ExpressionWidth::Bounded::bincodeSerialize() const
{
auto serializer = serde::BincodeSerializer();
serde::Serializable<ExpressionWidth::Bounded>::serialize(*this, serializer);
return std::move(serializer).bytes();
}

inline ExpressionWidth::Bounded ExpressionWidth::Bounded::bincodeDeserialize(std::vector<uint8_t> input)
{
auto deserializer = serde::BincodeDeserializer(input);
auto value = serde::Deserializable<ExpressionWidth::Bounded>::deserialize(deserializer);
if (deserializer.get_buffer_offset() < input.size()) {
throw_or_abort("Some input bytes were not read");
}
return value;
}

} // end of namespace Circuit

template <>
template <typename Serializer>
void serde::Serializable<Circuit::ExpressionWidth::Bounded>::serialize(const Circuit::ExpressionWidth::Bounded& obj,
Serializer& serializer)
{
serde::Serializable<decltype(obj.width)>::serialize(obj.width, serializer);
}

template <>
template <typename Deserializer>
Circuit::ExpressionWidth::Bounded serde::Deserializable<Circuit::ExpressionWidth::Bounded>::deserialize(
Deserializer& deserializer)
{
Circuit::ExpressionWidth::Bounded obj;
obj.width = serde::Deserializable<decltype(obj.width)>::deserialize(deserializer);
return obj;
}

namespace Circuit {

inline bool operator==(const FunctionInput& lhs, const FunctionInput& rhs)
{
if (!(lhs.witness == rhs.witness)) {
Expand Down

0 comments on commit ce6f451

Please sign in to comment.