Skip to content

Commit

Permalink
Remove Either struct. Now all messages send as ref to cell
Browse files Browse the repository at this point in the history
  • Loading branch information
Zerg1996 committed Apr 3, 2024
1 parent e433232 commit ae491ca
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 101 deletions.
8 changes: 4 additions & 4 deletions llvm/projects/ton-compiler/cpp-sdk/tvm/contract_handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ void contract_deploy_impl(address addr, StateInit init,
auto chain_tup = make_chain_tuple(hdr_plus_args);
message_relaxed<decltype(chain_tup)> out_msg;
out_msg.info = out_info;
Either<StateInit, ref<StateInit>> init_ref = ref<StateInit>{init};
ref<StateInit> init_ref = ref<StateInit>{init};
out_msg.init = init_ref;
out_msg.body = ref<decltype(chain_tup)>{chain_tup};
tvm_sendmsg(build(out_msg).endc(), flags);
Expand All @@ -378,7 +378,7 @@ void contract_deploy_noop_impl(address addr, StateInit init,
auto chain_tup = make_chain_tuple(to_std_tuple(hdr));
message_relaxed<decltype(chain_tup)> out_msg;
out_msg.info = out_info;
Either<StateInit, ref<StateInit>> init_ref = ref<StateInit>{init};
ref<StateInit> init_ref = ref<StateInit>{init};
out_msg.init = init_ref;
out_msg.body = ref<decltype(chain_tup)>{chain_tup};
tvm_sendmsg(build(out_msg).endc(), flags);
Expand Down Expand Up @@ -418,7 +418,7 @@ void contract_deploy_ext_noop_impl(address addr, uint256 pubkey,
auto chain_tup = make_chain_tuple(hdr_and_id);
message_relaxed<decltype(chain_tup)> out_msg;
out_msg.info = msg_info;
Either<StateInit, ref<StateInit>> init_ref = ref<StateInit>{init};
ref<StateInit> init_ref = ref<StateInit>{init};
out_msg.init = init_ref;
out_msg.body = ref<decltype(chain_tup)>{chain_tup};
tvm_sendmsg(build(out_msg).endc(), flags);
Expand Down Expand Up @@ -459,7 +459,7 @@ void contract_deploy_ext_impl(address addr, uint256 pubkey,
auto chain_tup = make_chain_tuple(hdr_plus_args);
message_relaxed<decltype(chain_tup)> out_msg;
out_msg.info = msg_info;
Either<StateInit, ref<StateInit>> init_ref = ref<StateInit>{init};
ref<StateInit> init_ref = ref<StateInit>{init};
out_msg.init = init_ref;
out_msg.body = ref<decltype(chain_tup)>{chain_tup};
tvm_sendmsg(build(out_msg).endc(), flags);
Expand Down
57 changes: 0 additions & 57 deletions llvm/projects/ton-compiler/cpp-sdk/tvm/schema/basics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,63 +620,6 @@ struct anydict {
};
using optcell = anydict;

template<class X>
struct EitherLeft {
bitconst<1, 0b0> tag;
X val;

DEFAULT_EQUAL(EitherLeft)
};
template<class Y>
struct EitherRight {
bitconst<1, 0b1> tag;
Y val;

DEFAULT_EQUAL(EitherRight)
};
template<typename X, typename Y>
struct Either {
using base_t = std::variant<EitherLeft<X>, EitherRight<Y>>;

Either() {}
Either(X left) : val_(EitherLeft<X>{ {}, left }) {}
Either(Y right) : val_(EitherRight<Y>{ {}, right }) {}

Either& operator=(X left) {
val_ = EitherLeft<X>{ {}, left };
return *this;
}
Either& operator=(Y right) {
val_ = EitherRight<Y>{ {}, right };
return *this;
}

bool operator == (const Either& v) const {
return val_ == v.val_;
}
template<class T>
__always_inline bool isa() const {
if constexpr (std::is_same_v<T, X>)
return std::holds_alternative<EitherLeft<X>>(val_);
else if constexpr (std::is_same_v<T, Y>)
return std::holds_alternative<EitherRight<Y>>(val_);
else
return false;
}
template<class T>
__always_inline T get() const {
if constexpr (std::is_same_v<T, X>)
return std::get<EitherLeft<X>>(val_).val;
else if constexpr (std::is_same_v<T, Y>)
return std::get<EitherRight<Y>>(val_).val;
else
static_assert(std::is_same_v<T, X> || std::is_same_v<T, Y>,
"bad get in Either variant");
}
base_t operator()() const { return val_; }
base_t val_;
};

template<typename _Tp>
struct ref {
_Tp operator()() const { return val_; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,6 @@ struct estimate_element<std::variant<Types...>> {
static constexpr unsigned min_refs = std::min({estimate_element<Types>::min_refs ... });
static constexpr unsigned max_refs = std::max({estimate_element<Types>::max_refs ... });
};
template<class X>
struct estimate_element<EitherLeft<X>> : detail::chain_to< to_std_tuple_t<EitherLeft<X>> > {};
template<class Y>
struct estimate_element<EitherRight<Y>> : detail::chain_to< to_std_tuple_t<EitherRight<Y>> > {};

template<class X, class Y>
struct estimate_element<Either<X, Y>> : detail::chain_to< to_std_tuple_t<Either<X, Y>> > {};

template<class _Tp>
struct estimate_element<lazy<_Tp>> : detail::chain_to<_Tp> {};
Expand Down
12 changes: 0 additions & 12 deletions llvm/projects/ton-compiler/cpp-sdk/tvm/schema/get_bitsize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,6 @@ struct get_bitsize<std::variant<Types...>> {
static constexpr bool all_calculated = (get_bitsize<Types>::value && ...);
static constexpr unsigned value = all_calculated ? std::max({get_bitsize<Types>::value ... }) : 0;
};
template<class X>
struct get_bitsize<EitherLeft<X>> {
static constexpr unsigned value = get_bitsize< to_std_tuple_t<EitherLeft<X>> >::value;
};
template<class Y>
struct get_bitsize<EitherRight<Y>> {
static constexpr unsigned value = get_bitsize< to_std_tuple_t<EitherRight<Y>> >::value;
};
template<class X, class Y>
struct get_bitsize<Either<X, Y>> {
static constexpr unsigned value = get_bitsize< to_std_tuple_t<Either<X, Y>> >::value;
};
template<class T>
struct get_bitsize<lazy<T>> {
static constexpr unsigned value = get_bitsize<T>::value;
Expand Down
8 changes: 4 additions & 4 deletions llvm/projects/ton-compiler/cpp-sdk/tvm/schema/message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ struct StateInit {
template<typename X>
struct message {
CommonMsgInfo info;
optional<Either<StateInit, ref<StateInit>>> init;
Either<X, ref<X>> body;
optional<ref<StateInit>> init;
ref<X> body;
};

template<typename X>
struct message_relaxed {
CommonMsgInfoRelaxed info;
optional<Either<StateInit, ref<StateInit>>> init;
Either<X, ref<X>> body;
optional<ref<StateInit>> init;
ref<X> body;
};

struct addr_std_fixed {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,4 @@ struct make_parser_impl<std::variant<Types...>> {
}
};

template<class X, class Y>
struct make_parser_impl<Either<X, Y>> {
using value_type = Either<X, Y>;
using base_t = typename value_type::base_t;

template<class _Ctx>
inline static std::tuple<optional<value_type>, parser, _Ctx> parse(parser p, _Ctx ctx) {
auto [opt_rv, new_p, new_ctx] = make_parser_impl<base_t>::parse(p, ctx);
if (opt_rv) {
value_type rv;
rv.val_ = *opt_rv;
return { rv, new_p, new_ctx };
}
return { {}, p, ctx };
}
};

}} // namespace tvm::schema

0 comments on commit ae491ca

Please sign in to comment.