Skip to content

Commit

Permalink
Fix clang-15 build and WAVM (#2011)
Browse files Browse the repository at this point in the history
* Fix clang-15 build and WAVM
  • Loading branch information
Harrm authored Mar 20, 2024
1 parent e77b7dd commit c66e411
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 42 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ jobs:
options:
- name: "Self-hosted: Linux: gcc-12 ASAN"
run: ./housekeeping/make_build.sh -DCLEAR_OBJS=ON -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/gcc-12_cxx20.cmake -DASAN=ON
- name: "Self-hosted: Linux: clang-15 TSAN"
run: ./housekeeping/make_build.sh -DCLEAR_OBJS=ON -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/clang-15_cxx20.cmake -DTSAN=ON
- name: "Self-hosted: Linux: clang-15 TSAN WAVM"
run: ./housekeeping/make_build.sh -DCLEAR_OBJS=ON -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/clang-15_cxx20.cmake -DTSAN=ON -DWASM_COMPILER=WAVM
- name: "Self-hosted: Linux: clang-15 UBSAN"
run: ./housekeeping/make_build.sh -DCLEAR_OBJS=ON -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/clang-15_cxx20.cmake -DUBSAN=ON
- name: "Self-hosted: Linux: clang-15 External Project"
Expand Down Expand Up @@ -124,8 +124,8 @@ jobs:
options:
- name: "Self-hosted: Linux: gcc-12 ASAN"
run: ./housekeeping/make_build.sh -DCLEAR_OBJS=ON -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/gcc-12_cxx20.cmake -DASAN=ON
- name: "Self-hosted: Linux: clang-15 TSAN"
run: ./housekeeping/make_build.sh -DCLEAR_OBJS=ON -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/clang-15_cxx20.cmake -DTSAN=ON
- name: "Self-hosted: Linux: clang-15 TSAN WAVM"
run: ./housekeeping/make_build.sh -DCLEAR_OBJS=ON -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/clang-15_cxx20.cmake -DTSAN=ON -DWASM_COMPILER=WAVM
- name: "Self-hosted: Linux: clang-15 UBSAN"
run: ./housekeeping/make_build.sh -DCLEAR_OBJS=ON -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/clang-15_cxx20.cmake -DUBSAN=ON
- name: "Self-hosted: Linux: clang-15 External Project"
Expand Down
14 changes: 7 additions & 7 deletions core/host_api/impl/storage_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#include "clock/impl/clock_impl.hpp"
#include "common/monadic_utils.hpp"
#include "common/outcome_throw.hpp"
#include "crypto/hasher.hpp"
#include "crypto/blake2/blake2b.h"
#include "crypto/hasher.hpp"
#include "crypto/keccak/keccak.hpp"
#include "host_api/impl/storage_util.hpp"
#include "log/trace_macros.hpp"
Expand Down Expand Up @@ -193,7 +193,7 @@ namespace kagome::host_api {
auto &memory = memory_provider_->getCurrentMemory()->get();
auto prefix = memory.loadN(prefix_ptr, prefix_size);
SL_TRACE_VOID_FUNC_CALL(logger_, prefix);
(void)clearPrefix(prefix, std::nullopt);
std::ignore = clearPrefix(prefix, std::nullopt);
}

runtime::WasmSpan StorageExtension::ext_storage_clear_prefix_version_2(
Expand Down Expand Up @@ -407,11 +407,11 @@ namespace kagome::host_api {

const auto &values = values_res.value();

auto ordered_hash = storage::trie::calculateOrderedTrieHash(
detail::toStateVersion(version),
values.begin(),
values.end(),
crypto::blake2b<32>);
auto ordered_hash =
storage::trie::calculateOrderedTrieHash(detail::toStateVersion(version),
values.begin(),
values.end(),
crypto::blake2b<32>);
common::raise_on_err(ordered_hash);

SL_TRACE_FUNC_CALL(logger_, ordered_hash.value());
Expand Down
18 changes: 15 additions & 3 deletions core/parachain/validator/fragment_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,14 @@ namespace kagome::parachain::fragment {
}

std::vector<CandidateHash> getCandidates() const {
auto kv = std::views::keys(candidates);
return {kv.begin(), kv.end()};
// doesn't compile in clang-15 due to a bug
// std::views::keys(candidates)
std::vector<CandidateHash> res;
res.reserve(candidates.size());
for (auto &pair : candidates) {
res.push_back(pair.first);
}
return res;
}

template <typename Func>
Expand Down Expand Up @@ -659,7 +665,13 @@ namespace kagome::parachain::fragment {
hasher_->blake2b_256(child_constraints.required_parent);

storage.iterParaChildren(
required_head_hash, [&](const CandidateEntry &candidate) {
required_head_hash,
// clang-15 doesn't like capturing structured bindings into
// lambdas
[&,
earliest_rp = earliest_rp,
child_depth = child_depth,
modifications = modifications](const CandidateEntry &candidate) {
auto pending =
scope.getPendingAvailability(candidate.candidate_hash);
Option<RelayChainBlockInfo> relay_parent_opt;
Expand Down
13 changes: 11 additions & 2 deletions core/runtime/wavm/intrinsics/intrinsic_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ namespace kagome::runtime::wavm {
return WAVM::IR::ValueType::i64;
}

template <>
WAVM::IR::ValueType get_wavm_type<uint32_t>() {
return WAVM::IR::ValueType::i32;
}

template <>
WAVM::IR::ValueType get_wavm_type<uint64_t>() {
return WAVM::IR::ValueType::i64;
}

template <auto Method, typename... Args>
auto host_method_thunk(WAVM::Runtime::ContextRuntimeData *, Args... args) {
return std::invoke(Method, peekHostApi(), args...);
Expand All @@ -77,10 +87,9 @@ namespace kagome::runtime::wavm {
}
#define REGISTER_HOST_METHOD(Ret, name, ...) \
registerMethod<&host_api::HostApi::name, Ret __VA_OPT__(, ) __VA_ARGS__>( \
module, #name); \
module, #name);

REGISTER_HOST_METHODS

}

} // namespace kagome::runtime::wavm
44 changes: 24 additions & 20 deletions test/core/parachain/prospective_parachains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ class ProspectiveParachainsTest : public testing::Test {
EXPECT_CALL(*block_tree_, getBlockHeader(hash))
.WillRepeatedly(Return(header));

BlockNumber min_min = [&]() -> BlockNumber {
BlockNumber min_min = [&, number = number]() -> BlockNumber {
std::optional<BlockNumber> min_min;
for (const auto &[_, data] : leaf.para_data) {
min_min = min_min ? std::min(*min_min, data.min_relay_parent)
Expand Down Expand Up @@ -438,10 +438,11 @@ class ProspectiveParachainsTest : public testing::Test {
}
}

prospective_parachain_->onActiveLeavesUpdate(network::ExViewRef{
.new_head = {update.new_head},
.lost = update.lost,
});
std::ignore =
prospective_parachain_->onActiveLeavesUpdate(network::ExViewRef{
.new_head = {update.new_head},
.lost = update.lost,
});
auto resp = prospective_parachain_->answerMinimumRelayParentsRequest(hash);
std::sort(resp.begin(), resp.end(), [](const auto &l, const auto &r) {
return l.first < r.first;
Expand Down Expand Up @@ -568,10 +569,11 @@ class ProspectiveParachainsTest : public testing::Test {
.new_head = {},
.lost = {hash},
};
prospective_parachain_->onActiveLeavesUpdate(network::ExViewRef{
.new_head = {},
.lost = update.lost,
});
std::ignore =
prospective_parachain_->onActiveLeavesUpdate(network::ExViewRef{
.new_head = {},
.lost = update.lost,
});
}

auto get_pvd(
Expand Down Expand Up @@ -608,7 +610,7 @@ TEST_F(ProspectiveParachainsTest, shouldDoNoWorkIfAsyncBackingDisabledForLeaf) {
.WillRepeatedly(
Return(outcome::failure(ParachainProcessorImpl::Error::NO_STATE)));

prospective_parachain_->onActiveLeavesUpdate(network::ExViewRef{
std::ignore = prospective_parachain_->onActiveLeavesUpdate(network::ExViewRef{
.new_head = {update.new_head},
.lost = update.lost,
});
Expand Down Expand Up @@ -1348,7 +1350,7 @@ TEST_F(ProspectiveParachainsTest, FragmentTree_usesAncestryOnlyWithinSession) {
}
}

prospective_parachain_->onActiveLeavesUpdate(network::ExViewRef{
std::ignore = prospective_parachain_->onActiveLeavesUpdate(network::ExViewRef{
.new_head = {update.new_head},
.lost = update.lost,
});
Expand Down Expand Up @@ -1393,7 +1395,7 @@ TEST_F(ProspectiveParachainsTest, FragmentTree_correctlyUpdatesLeaves) {
activate_leaf(leaf_b, test_state, async_backing_params);
activate_leaf(leaf_b, test_state, async_backing_params);

prospective_parachain_->onActiveLeavesUpdate(network::ExViewRef{
std::ignore = prospective_parachain_->onActiveLeavesUpdate(network::ExViewRef{
.new_head = {},
.lost = {},
});
Expand Down Expand Up @@ -1429,10 +1431,11 @@ TEST_F(ProspectiveParachainsTest, FragmentTree_correctlyUpdatesLeaves) {
};
// handle_leaf_activation_2(update2, leaf_c, test_state,
// async_backing_params);
prospective_parachain_->onActiveLeavesUpdate(network::ExViewRef{
.new_head = {},
.lost = update2.lost,
});
std::ignore =
prospective_parachain_->onActiveLeavesUpdate(network::ExViewRef{
.new_head = {},
.lost = update2.lost,
});
}

{
Expand Down Expand Up @@ -1465,10 +1468,11 @@ TEST_F(ProspectiveParachainsTest, FragmentTree_correctlyUpdatesLeaves) {
.new_head = {},
.lost = {leaf_a.hash, leaf_b.hash, leaf_c.hash},
};
prospective_parachain_->onActiveLeavesUpdate(network::ExViewRef{
.new_head = {},
.lost = update2.lost,
});
std::ignore =
prospective_parachain_->onActiveLeavesUpdate(network::ExViewRef{
.new_head = {},
.lost = update2.lost,
});
}
ASSERT_EQ(prospective_parachain_->view.active_leaves.size(), 0);
ASSERT_EQ(prospective_parachain_->view.candidate_storage.size(), 0);
Expand Down
8 changes: 2 additions & 6 deletions test/core/runtime/wavm/wavm_runtime_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class WavmRuntimeTest : public RuntimeTestBase {
std::shared_ptr<kagome::runtime::wavm::IntrinsicModuleInstance>
intrinsic_module_instance = intrinsic_module->instantiate();
resolver_ = std::make_shared<kagome::runtime::wavm::IntrinsicResolverImpl>(
intrinsic_module_instance);
compartment, intrinsic_module_instance);

auto module_factory =
std::make_shared<kagome::runtime::wavm::ModuleFactoryImpl>(
Expand All @@ -53,13 +53,9 @@ class WavmRuntimeTest : public RuntimeTestBase {
std::nullopt,
hasher_);


auto instance_env_factory =
std::make_shared<kagome::runtime::wavm::InstanceEnvironmentFactory>(
trie_storage_,
serializer_,
host_api_factory_,
module_factory);
trie_storage_, serializer_, host_api_factory_, module_factory);

return module_factory;
}
Expand Down

0 comments on commit c66e411

Please sign in to comment.