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

chore!: remove Opcode::Brillig from ACIR #5995

Merged
merged 21 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
385 changes: 128 additions & 257 deletions barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions noir/noir-repo/acvm-repo/acir/benches/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ fn sample_program(num_opcodes: usize) -> Program {
assert_messages: Vec::new(),
recursive: false,
}],
unconstrained_functions: Vec::new(),
}
}

Expand Down
364 changes: 128 additions & 236 deletions noir/noir-repo/acvm-repo/acir/codegen/acir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,134 @@ namespace Program {
static BrilligInputs bincodeDeserialize(std::vector<uint8_t>);
};

struct BrilligOutputs {

struct Simple {
Program::Witness value;

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

struct Array {
std::vector<Program::Witness> value;

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

std::variant<Simple, Array> value;

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

struct Directive {

struct ToLeRadix {
Program::Expression a;
std::vector<Program::Witness> b;
uint32_t radix;

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

std::variant<ToLeRadix> value;

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

struct MemOp {
Program::Expression operation;
Program::Expression index;
Program::Expression value;

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

struct Opcode {

struct AssertZero {
Program::Expression value;

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

struct BlackBoxFuncCall {
Program::BlackBoxFuncCall value;

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

struct Directive {
Program::Directive value;

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

struct MemoryOp {
Program::BlockId block_id;
Program::MemOp op;
std::optional<Program::Expression> predicate;

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

struct MemoryInit {
Program::BlockId block_id;
std::vector<Program::Witness> init;

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

struct BrilligCall {
uint32_t id;
std::vector<Program::BrilligInputs> inputs;
std::vector<Program::BrilligOutputs> outputs;
std::optional<Program::Expression> predicate;

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

struct Call {
uint32_t id;
std::vector<Program::Witness> inputs;
std::vector<Program::Witness> outputs;
std::optional<Program::Expression> predicate;

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

std::variant<AssertZero, BlackBoxFuncCall, Directive, MemoryOp, MemoryInit, BrilligCall, Call> value;

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

struct BinaryFieldOp {

struct Add {
Expand Down Expand Up @@ -946,153 +1074,6 @@ namespace Program {
static BrilligOpcode bincodeDeserialize(std::vector<uint8_t>);
};

struct BrilligOutputs {

struct Simple {
Program::Witness value;

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

struct Array {
std::vector<Program::Witness> value;

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

std::variant<Simple, Array> value;

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

struct Brillig {
std::vector<Program::BrilligInputs> inputs;
std::vector<Program::BrilligOutputs> outputs;
std::vector<Program::BrilligOpcode> bytecode;
std::optional<Program::Expression> predicate;

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

struct Directive {

struct ToLeRadix {
Program::Expression a;
std::vector<Program::Witness> b;
uint32_t radix;

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

std::variant<ToLeRadix> value;

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

struct MemOp {
Program::Expression operation;
Program::Expression index;
Program::Expression value;

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

struct Opcode {

struct AssertZero {
Program::Expression value;

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

struct BlackBoxFuncCall {
Program::BlackBoxFuncCall value;

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

struct Directive {
Program::Directive value;

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

struct Brillig {
Program::Brillig value;

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

struct MemoryOp {
Program::BlockId block_id;
Program::MemOp op;
std::optional<Program::Expression> predicate;

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

struct MemoryInit {
Program::BlockId block_id;
std::vector<Program::Witness> init;

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

struct BrilligCall {
uint32_t id;
std::vector<Program::BrilligInputs> inputs;
std::vector<Program::BrilligOutputs> outputs;
std::optional<Program::Expression> predicate;

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

struct Call {
uint32_t id;
std::vector<Program::Witness> inputs;
std::vector<Program::Witness> outputs;
std::optional<Program::Expression> predicate;

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

std::variant<AssertZero, BlackBoxFuncCall, Directive, Brillig, MemoryOp, MemoryInit, BrilligCall, Call> value;

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

struct ExpressionWidth {

struct Unbounded {
Expand Down Expand Up @@ -4043,57 +4024,6 @@ Program::BlockId serde::Deserializable<Program::BlockId>::deserialize(Deserializ
return obj;
}

namespace Program {

inline bool operator==(const Brillig &lhs, const Brillig &rhs) {
if (!(lhs.inputs == rhs.inputs)) { return false; }
if (!(lhs.outputs == rhs.outputs)) { return false; }
if (!(lhs.bytecode == rhs.bytecode)) { return false; }
if (!(lhs.predicate == rhs.predicate)) { return false; }
return true;
}

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

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

} // end of namespace Program

template <>
template <typename Serializer>
void serde::Serializable<Program::Brillig>::serialize(const Program::Brillig &obj, Serializer &serializer) {
serializer.increase_container_depth();
serde::Serializable<decltype(obj.inputs)>::serialize(obj.inputs, serializer);
serde::Serializable<decltype(obj.outputs)>::serialize(obj.outputs, serializer);
serde::Serializable<decltype(obj.bytecode)>::serialize(obj.bytecode, serializer);
serde::Serializable<decltype(obj.predicate)>::serialize(obj.predicate, serializer);
serializer.decrease_container_depth();
}

template <>
template <typename Deserializer>
Program::Brillig serde::Deserializable<Program::Brillig>::deserialize(Deserializer &deserializer) {
deserializer.increase_container_depth();
Program::Brillig obj;
obj.inputs = serde::Deserializable<decltype(obj.inputs)>::deserialize(deserializer);
obj.outputs = serde::Deserializable<decltype(obj.outputs)>::deserialize(deserializer);
obj.bytecode = serde::Deserializable<decltype(obj.bytecode)>::deserialize(deserializer);
obj.predicate = serde::Deserializable<decltype(obj.predicate)>::deserialize(deserializer);
deserializer.decrease_container_depth();
return obj;
}

namespace Program {

inline bool operator==(const BrilligBytecode &lhs, const BrilligBytecode &rhs) {
Expand Down Expand Up @@ -6066,44 +5996,6 @@ Program::Opcode::Directive serde::Deserializable<Program::Opcode::Directive>::de
return obj;
}

namespace Program {

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

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

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

} // end of namespace Program

template <>
template <typename Serializer>
void serde::Serializable<Program::Opcode::Brillig>::serialize(const Program::Opcode::Brillig &obj, Serializer &serializer) {
serde::Serializable<decltype(obj.value)>::serialize(obj.value, serializer);
}

template <>
template <typename Deserializer>
Program::Opcode::Brillig serde::Deserializable<Program::Opcode::Brillig>::deserialize(Deserializer &deserializer) {
Program::Opcode::Brillig obj;
obj.value = serde::Deserializable<decltype(obj.value)>::deserialize(deserializer);
return obj;
}

namespace Program {

inline bool operator==(const Opcode::MemoryOp &lhs, const Opcode::MemoryOp &rhs) {
Expand Down
Loading
Loading