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

Remove absl dependency #123

Merged
merged 1 commit into from
Dec 20, 2020
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
8 changes: 0 additions & 8 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ def proxy_wasm_cpp_host_repositories():
url = "https://github.com/WebAssembly/wasm-c-api/archive/d9a80099d496b5cdba6f3fe8fc77586e0e505ddc.tar.gz",
)

http_archive(
name = "com_google_absl",
sha256 = "19391fb4882601a65cb648d638c11aa301ce5f525ef02da1a9eafd22f72d7c59",
strip_prefix = "abseil-cpp-37dd2562ec830d547a1524bb306be313ac3f2556",
# 2020-01-29
urls = ["https://github.com/abseil/abseil-cpp/archive/37dd2562ec830d547a1524bb306be313ac3f2556.tar.gz"],
)

http_archive(
name = "io_bazel_rules_rust",
sha256 = "442a102e2a6f6c75e10d43f21c0c30218947a3e827d91529ced7380c5fec05f0",
Expand Down
24 changes: 11 additions & 13 deletions src/v8/v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
#include <memory>
#include <optional>
#include <sstream>
#include <unordered_map>
#include <utility>
#include <vector>

#include "v8-version.h"
#include "wasm-api/wasm.hh"

// TODO remove absl dependency
#include "absl/container/flat_hash_map.h"

namespace proxy_wasm {
namespace {

Expand Down Expand Up @@ -114,10 +112,10 @@ class V8 : public WasmVm {
wasm::own<wasm::Memory> memory_;
wasm::own<wasm::Table> table_;

absl::flat_hash_map<std::string, FuncDataPtr> host_functions_;
absl::flat_hash_map<std::string, wasm::own<wasm::Func>> module_functions_;
std::unordered_map<std::string, FuncDataPtr> host_functions_;
std::unordered_map<std::string, wasm::own<wasm::Func>> module_functions_;

absl::flat_hash_map<uint32_t, std::string> function_names_index_;
std::unordered_map<uint32_t, std::string> function_names_index_;
};

// Helper functions.
Expand Down Expand Up @@ -235,17 +233,17 @@ template <> constexpr auto convertArgToValKind<uint64_t>() { return wasm::I64; }
template <> constexpr auto convertArgToValKind<double>() { return wasm::F64; };

template <typename T, std::size_t... I>
constexpr auto convertArgsTupleToValTypesImpl(absl::index_sequence<I...>) {
constexpr auto convertArgsTupleToValTypesImpl(std::index_sequence<I...>) {
return wasm::ownvec<wasm::ValType>::make(
wasm::ValType::make(convertArgToValKind<typename std::tuple_element<I, T>::type>())...);
}

template <typename T> constexpr auto convertArgsTupleToValTypes() {
return convertArgsTupleToValTypesImpl<T>(absl::make_index_sequence<std::tuple_size<T>::value>());
return convertArgsTupleToValTypesImpl<T>(std::make_index_sequence<std::tuple_size<T>::value>());
}

template <typename T, typename U, std::size_t... I>
constexpr T convertValTypesToArgsTupleImpl(const U &arr, absl::index_sequence<I...>) {
constexpr T convertValTypesToArgsTupleImpl(const U &arr, std::index_sequence<I...>) {
return std::make_tuple(
(arr[I]
.template get<
Expand All @@ -254,7 +252,7 @@ constexpr T convertValTypesToArgsTupleImpl(const U &arr, absl::index_sequence<I.

template <typename T, typename U> constexpr T convertValTypesToArgsTuple(const U &arr) {
return convertValTypesToArgsTupleImpl<T>(arr,
absl::make_index_sequence<std::tuple_size<T>::value>());
std::make_index_sequence<std::tuple_size<T>::value>());
}

// V8 implementation.
Expand Down Expand Up @@ -568,7 +566,7 @@ bool V8::link(std::string_view debug_name) {

case wasm::EXTERN_FUNC: {
assert(export_item->func() != nullptr);
module_functions_.insert_or_assign(name, export_item->func()->copy());
module_functions_.insert_or_assign(std::string(name), export_item->func()->copy());
} break;

case wasm::EXTERN_GLOBAL: {
Expand Down Expand Up @@ -648,7 +646,7 @@ void V8::registerHostFunctionImpl(std::string_view module_name, std::string_view
auto args_tuple = convertValTypesToArgsTuple<std::tuple<Args...>>(params);
auto args = std::tuple_cat(std::make_tuple(current_context_), args_tuple);
auto function = reinterpret_cast<void (*)(void *, Args...)>(func_data->raw_func_);
absl::apply(function, args);
std::apply(function, args);
if (func_data->vm_->cmpLogLevel(LogLevel::trace)) {
func_data->vm_->integration()->trace("[vm<-host] " + func_data->name_ + " return: void");
}
Expand Down Expand Up @@ -681,7 +679,7 @@ void V8::registerHostFunctionImpl(std::string_view module_name, std::string_view
auto args_tuple = convertValTypesToArgsTuple<std::tuple<Args...>>(params);
auto args = std::tuple_cat(std::make_tuple(current_context_), args_tuple);
auto function = reinterpret_cast<R (*)(void *, Args...)>(func_data->raw_func_);
R rvalue = absl::apply(function, args);
R rvalue = std::apply(function, args);
results[0] = makeVal(rvalue);
if (func_data->vm_->cmpLogLevel(LogLevel::trace)) {
func_data->vm_->integration()->trace("[vm<-host] " + func_data->name_ +
Expand Down