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

Use Abseil; remove fmt/span-lite/phmap #19

Merged
merged 2 commits into from
Nov 2, 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
12 changes: 3 additions & 9 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
[submodule "third_party/gtest"]
path = third_party/gtest
url = https://github.com/google/googletest
[submodule "third_party/fmt"]
path = third_party/fmt
url = https://github.com/fmtlib/fmt
[submodule "third_party/span-lite"]
path = third_party/span-lite
url = https://github.com/martinmoene/span-lite
[submodule "third_party/parallel-hashmap"]
path = third_party/parallel-hashmap
url = https://github.com/greg7mdp/parallel-hashmap
[submodule "third_party/gdtoa"]
path = third_party/gdtoa
url = https://github.com/jwiegley/gdtoa
[submodule "third_party/testsuite"]
path = third_party/testsuite
url = https://github.com/WebAssembly/testsuite
[submodule "third_party/abseil"]
path = third_party/abseil
url = https://github.com/abseil/abseil-cpp
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ else ()
set(warning_flags -W3)
endif ()


add_subdirectory(src/base)
add_subdirectory(src/binary)
add_subdirectory(src/valid)
Expand Down
65 changes: 65 additions & 0 deletions include/wasp/base/absl_hash_value_macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// Copyright 2020 WebAssembly Community Group participants
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#ifndef WASP_BASE_ABSL_HASH_VALUE_MACROS_H_
#define WASP_BASE_ABSL_HASH_VALUE_MACROS_H_

#define WASP_ABSL_HASH_VALUE_VARGS(Name, Count, ...) \
WASP_ABSL_HASH_VALUE_##Count(Name, __VA_ARGS__)

#define WASP_ABSL_HASH_VALUE_0(Name, ...) \
template <typename H> \
H AbslHashValue(H h, const ::wasp::Name&) { \
return h; \
}

#define WASP_ABSL_HASH_VALUE_1(Name, f1) \
template <typename H> \
H AbslHashValue(H h, const ::wasp::Name& v) { \
return H::combine(std::move(h), v.f1); \
}

#define WASP_ABSL_HASH_VALUE_2(Name, f1, f2) \
template <typename H> \
H AbslHashValue(H h, const ::wasp::Name& v) { \
return H::combine(std::move(h), v.f1, v.f2); \
}

#define WASP_ABSL_HASH_VALUE_3(Name, f1, f2, f3) \
template <typename H> \
H AbslHashValue(H h, const ::wasp::Name& v) { \
return H::combine(std::move(h), v.f1, v.f2, v.f3); \
}

#define WASP_ABSL_HASH_VALUE_4(Name, f1, f2, f3, f4) \
template <typename H> \
H AbslHashValue(H h, const ::wasp::Name& v) { \
return H::combine(std::move(h), v.f1, v.f2, v.f3, v.f4); \
}

#define WASP_ABSL_HASH_VALUE_5(Name, f1, f2, f3, f4, f5) \
template <typename H> \
H AbslHashValue(H h, const ::wasp::Name& v) { \
return H::combine(std::move(h), v.f1, v.f2, v.f3, v.f4, v.f5); \
}

#define WASP_ABSL_HASH_VALUE_CONTAINER(Name) \
template <typename H> \
H AbslHashValue(H h, const ::wasp::Name& v) { \
return H::combine(std::move(h), v); \
}

#endif // WASP_BASE_ABSL_HASH_VALUE_MACROS_H_
15 changes: 6 additions & 9 deletions include/wasp/base/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
#ifndef WASP_BASE_FEATURES_H_
#define WASP_BASE_FEATURES_H_

#include <functional> // for std::hash

#include "wasp/base/hash.h"
#include "wasp/base/types.h"

namespace wasp {
Expand Down Expand Up @@ -73,6 +72,11 @@ class Features {
friend bool operator==(const Features& lhs, const Features& rhs);
friend bool operator!=(const Features& lhs, const Features& rhs);

template <typename H>
friend H AbslHashValue(H h, const Features& f) {
return H::combine(std::move(h), f.bits_);
}

private:
void UpdateDependencies();

Expand All @@ -82,11 +86,4 @@ class Features {

} // namespace wasp

namespace std {
template <>
struct hash<::wasp::Features> {
size_t operator()(const ::wasp::Features&) const;
};
} // namespace std

#endif // WASP_BASE_FEATURES_H_
2 changes: 1 addition & 1 deletion include/wasp/base/formatters-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ std::ostream& operator<<(std::ostream& os, const ::std::array<T, N>& self) {

template <typename T>
std::ostream& operator<<(std::ostream& os, const ::std::vector<T>& self) {
return os << ::wasp::span{self};
return os << ::wasp::MakeSpan(self);
}

template <typename... Ts>
Expand Down
18 changes: 2 additions & 16 deletions include/wasp/base/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,11 @@

#include <iterator>

#include "parallel_hashmap/phmap_utils.h"
#include "absl/hash/hash.h"

namespace wasp {

using phmap::HashState;

template <typename T1, typename T2>
size_t HashRange(T1 begin, T2 end) {
size_t state = 0;
for (auto it = begin; it != end; ++it) {
state = HashState::combine(state, *it);
}
return state;
}

template <typename C>
size_t HashContainer(const C& c) {
return HashRange(std::begin(c), std::end(c));
}
using absl::HashState;

} // namespace wasp

Expand Down
13 changes: 8 additions & 5 deletions include/wasp/base/hashmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@
#ifndef WASP_BASE_HASHMAP_H_
#define WASP_BASE_HASHMAP_H_

#include "parallel_hashmap/phmap.h"
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "absl/container/node_hash_map.h"
#include "absl/container/node_hash_set.h"

namespace wasp {

using phmap::flat_hash_map;
using phmap::flat_hash_set;
using phmap::node_hash_map;
using phmap::node_hash_set;
using absl::flat_hash_map;
using absl::flat_hash_set;
using absl::node_hash_map;
using absl::node_hash_set;

} // namespace wasp

Expand Down
35 changes: 11 additions & 24 deletions include/wasp/base/span.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,25 @@

#include <functional>

#include "nonstd/span.hpp"
#include "absl/types/span.h"
#include "wasp/base/string_view.h"
#include "wasp/base/types.h"

namespace wasp {

using nonstd::span;
template <typename T>
using span = absl::Span<T>;

using nonstd::operator==;
using nonstd::operator!=;
using nonstd::operator<;
using nonstd::operator<=;
using nonstd::operator>;
using nonstd::operator>=;
using absl::operator==;
using absl::operator!=;
using absl::operator<;
using absl::operator<=;
using absl::operator>;
using absl::operator>=;

using span_extent_t = nonstd::span_lite::extent_t;
using absl::MakeSpan;

constexpr span_extent_t dynamic_extent = -1;

template <class T, span_extent_t Extent>
void remove_prefix(span<T, Extent>* s, span_extent_t offset) {
*s = s->subspan(offset);
}
using span_extent_t = size_t;

using SpanU8 = span<const u8>;
using Location = SpanU8;
Expand All @@ -61,13 +57,4 @@ inline string_view ToStringView(SpanU8 span) {

} // namespace wasp

namespace std {

template <>
struct hash<::wasp::SpanU8> {
size_t operator()(::wasp::SpanU8) const;
};

}

#endif // WASP_BASE_SPAN_H_
80 changes: 0 additions & 80 deletions include/wasp/base/std_hash_macros.h

This file was deleted.

15 changes: 6 additions & 9 deletions include/wasp/base/v128.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,18 @@ class v128 {
friend bool operator==(const v128&, const v128&);
friend bool operator!=(const v128&, const v128&);

template <typename H>
friend H AbslHashValue(H h, const v128& f) {
auto u = f.as<::wasp::u64x2>();
return H::combine(std::move(h), u[0], u[1]);
}

private:
u8x16 data_;
};

} // namespace wasp

namespace std {

template <>
struct hash<::wasp::v128> {
size_t operator()(const ::wasp::v128&) const;
};

} // namespace std

#include "wasp/base/v128-inl.h"

#endif // WASP_BASE_V128_H_
8 changes: 4 additions & 4 deletions include/wasp/base/wasm_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#include <iosfwd>
#include <vector>

#include "wasp/base/absl_hash_value_macros.h"
#include "wasp/base/at.h"
#include "wasp/base/operator_eq_ne_macros.h"
#include "wasp/base/std_hash_macros.h"
#include "wasp/base/types.h"

namespace wasp {
Expand Down Expand Up @@ -144,9 +144,9 @@ using ShuffleImmediate = std::array<u8, 16>;
WASP_BASE_WASM_STRUCTS(WASP_DECLARE_OPERATOR_EQ_NE)
WASP_BASE_WASM_CONTAINERS(WASP_DECLARE_OPERATOR_EQ_NE)

} // namespace wasp
WASP_BASE_WASM_STRUCTS(WASP_ABSL_HASH_VALUE_VARGS)
WASP_BASE_WASM_CONTAINERS(WASP_ABSL_HASH_VALUE_CONTAINER)

WASP_BASE_WASM_STRUCTS(WASP_DECLARE_STD_HASH)
WASP_BASE_WASM_CONTAINERS(WASP_DECLARE_STD_HASH)
} // namespace wasp

#endif // WASP_BASE_WASM_TYPES_H_
2 changes: 1 addition & 1 deletion include/wasp/binary/lazy_sequence-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void LazySequence<T>::NotifyRead(const u8* pos, bool ok) {
} else if (expected_count_ && count_ != *expected_count_) {
// Reached the end, but there was a mismatch.
LazySequenceBase::OnCountError(context_.errors,
SpanU8{last_pos_, data_.end()}, name_,
MakeSpan(last_pos_, data_.end()), name_,
*expected_count_, count_);
}
}
Expand Down
Loading