Swift: make monostate explicit

This commit is contained in:
Paolo Tranquilli
2022-05-16 15:51:43 +02:00
parent 1b9dcac2dd
commit 16e3b5bfc4
2 changed files with 6 additions and 5 deletions

View File

@@ -87,9 +87,9 @@ class SwiftDispatcher {
TrapLabelOf<E> fetchLabel(E* e) {
// this is required so we avoid any recursive loop: a `fetchLabel` during the visit of `e` might
// end up calling `fetchLabel` on `e` itself, so we want the visit of `e` to call `fetchLabel`
// only after having called `assignNewLabel` on `e`. `index() == 0` indicates the monostate of
// `Store::Handle`, i.e. its default construction
assert(waitingForNewLabel.index() == 0 && "fetchLabel called before assignNewLabel");
// only after having called `assignNewLabel` on `e`.
assert(holds_alternative<std::monostate>(waitingForNewLabel) &&
"fetchLabel called before assignNewLabel");
if (auto l = store.get(e)) {
return *l;
}
@@ -114,7 +114,7 @@ class SwiftDispatcher {
auto label = getLabel<TrapTagOf<E>>();
trap.assignStar(label);
store.insert(e, label);
waitingForNewLabel = {};
waitingForNewLabel = std::monostate{};
return label;
}
@@ -177,7 +177,7 @@ class SwiftDispatcher {
TrapArena& arena;
TrapOutput& trap;
Store store;
Store::Handle waitingForNewLabel{};
Store::Handle waitingForNewLabel{std::monostate{}};
};
} // namespace codeql

View File

@@ -21,6 +21,7 @@ template <typename... Ts>
class TrapLabelStore {
public:
using Handle = std::variant<std::monostate, const Ts*...>;
template <typename T>
std::optional<TrapLabelOf<T>> get(const T* e) {
if (auto found = store_.find(e); found != store_.end()) {