-
Notifications
You must be signed in to change notification settings - Fork 666
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a base class for the interface of a value in a map
Summary: All our map containers expect a `ValueInterface` template parameter that must implement specific members. This diff adds a base class for this interface, which allows us to check statically if it properly implements all members. Reviewed By: arnaudvenet Differential Revision: D50013140 fbshipit-source-id: 8621b664db2a4b4d1b93ac0eb1a6a59d683cb204
- Loading branch information
1 parent
c9d491e
commit eb70b21
Showing
15 changed files
with
260 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <type_traits> | ||
|
||
#include <sparta/AbstractDomain.h> | ||
#include <sparta/TypeTraits.h> | ||
|
||
namespace sparta { | ||
|
||
namespace { | ||
SPARTA_HAS_STATIC_MEMBER_FUNCTION(leq, has_static_leq_member_function) | ||
} | ||
|
||
/* | ||
* This describes the `ValueInterface` structure required for abstract maps. | ||
*/ | ||
template <typename Derived> | ||
class AbstractMapValue { | ||
public: | ||
/* | ||
* Check that `Derived` implements the `AbstractMapValue` interface, using | ||
* static assertions. This must be called from a method that is instantiated, | ||
* for instance the destructor of the map. | ||
*/ | ||
constexpr static void check_interface() { | ||
static_assert(std::is_base_of<AbstractMapValue<Derived>, Derived>::value, | ||
"Derived doesn't inherit from AbstractMapValue"); | ||
static_assert(std::is_final<Derived>::value, "Derived is not final"); | ||
|
||
// Derived::type | ||
using type = typename Derived::type; | ||
|
||
/* | ||
* Returns the default value. | ||
*/ | ||
// static type default_value(); | ||
static_assert(std::is_same<decltype(Derived::default_value()), type>::value, | ||
"Derived::default_value() does not exist"); | ||
|
||
/* | ||
* Tests whether a value is the default value. | ||
*/ | ||
// static bool is_default_value(const type& x); | ||
static_assert(std::is_same<decltype(Derived::is_default_value( | ||
std::declval<const type>())), | ||
bool>::value, | ||
"Derived::is_default_value(const type&) does not exist"); | ||
|
||
/* | ||
* The equality predicate for values. | ||
*/ | ||
// static bool equals(const type& x, const type& y); | ||
static_assert( | ||
std::is_same<decltype(Derived::equals(std::declval<const type>(), | ||
std::declval<const type>())), | ||
bool>::value, | ||
"Derived::equals(const type&, const type&) does not exist"); | ||
|
||
if constexpr (has_static_leq_member_function<Derived>::value) { | ||
/* | ||
* A partial order relation over values. In order to use the lifted | ||
* partial order relation over maps PatriciaTreeMap::leq(), this method | ||
* must be implemented. Additionally, value::type must be an | ||
* implementation of an AbstractDomain. | ||
*/ | ||
// static bool leq(const type& x, const type& y); | ||
static_assert( | ||
std::is_same<decltype(Derived::leq(std::declval<const type>(), | ||
std::declval<const type>())), | ||
bool>::value, | ||
"Derived::leq(const type&, const type&) does not exist"); | ||
} | ||
|
||
/* | ||
* Whether the default value is top, bottom, or an arbitrary value. | ||
*/ | ||
// constexpr static AbstractValueKind default_value_kind; | ||
static_assert(std::is_same<decltype(Derived::default_value_kind), | ||
const AbstractValueKind>::value, | ||
"Derived::default_value_kind does not exist"); | ||
} | ||
}; | ||
|
||
} // namespace sparta |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.