Skip to content

Commit 5585cac

Browse files
committed
AST: Remove AnyValue type eraser now that it's no longer needed
I'm keeping AnyValue.h around, since it has some useful overloads of hash_value() and simple_display() that don't have a good home at this time.
1 parent f601a6c commit 5585cac

File tree

7 files changed

+5
-173
lines changed

7 files changed

+5
-173
lines changed

include/swift/AST/GenericSignature.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "swift/AST/Requirement.h"
2222
#include "swift/AST/Type.h"
2323
#include "swift/AST/TypeAlignments.h"
24-
#include "swift/Basic/AnyValue.h"
2524
#include "swift/Basic/Debug.h"
2625
#include "llvm/ADT/ArrayRef.h"
2726
#include "llvm/ADT/FoldingSet.h"

include/swift/AST/Pattern.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef SWIFT_PATTERN_H
1818
#define SWIFT_PATTERN_H
1919

20+
#include "swift/Basic/AnyValue.h"
2021
#include "swift/Basic/SourceLoc.h"
2122
#include "swift/Basic/type_traits.h"
2223
#include "swift/AST/Decl.h"

include/swift/AST/TypeCheckRequests.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "swift/AST/SimpleRequest.h"
2828
#include "swift/AST/SourceFile.h"
2929
#include "swift/AST/TypeResolutionStage.h"
30-
#include "swift/Basic/AnyValue.h"
3130
#include "swift/Basic/Statistic.h"
3231
#include "llvm/ADT/Hashing.h"
3332
#include "llvm/ADT/STLExtras.h"
@@ -2757,25 +2756,6 @@ class SynthesizeMainFunctionRequest
27572756
bool isCached() const { return true; }
27582757
};
27592758

2760-
// Allow AnyValue to compare two Type values, even though Type doesn't
2761-
// support ==.
2762-
template<>
2763-
inline bool AnyValue::Holder<Type>::equals(const HolderBase &other) const {
2764-
assert(typeID == other.typeID && "Caller should match type IDs");
2765-
return value.getPointer() ==
2766-
static_cast<const Holder<Type> &>(other).value.getPointer();
2767-
}
2768-
2769-
// Allow AnyValue to compare two GenericSignature values.
2770-
template <>
2771-
inline bool
2772-
AnyValue::Holder<GenericSignature>::equals(const HolderBase &other) const {
2773-
assert(typeID == other.typeID && "Caller should match type IDs");
2774-
return value.getPointer() ==
2775-
static_cast<const Holder<GenericSignature> &>(other)
2776-
.value.getPointer();
2777-
}
2778-
27792759
void simple_display(llvm::raw_ostream &out, Type value);
27802760
void simple_display(llvm::raw_ostream &out, const TypeRepr *TyR);
27812761
void simple_display(llvm::raw_ostream &out, ImplicitMemberAction action);

include/swift/Basic/AnyValue.h

Lines changed: 3 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- AnyValue.h - Any Value Existential ---------------------*- C++ -*-===//
1+
//===--- AnyValue.h ---------------------------------------------*- C++ -*-===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -10,8 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212
//
13-
// This file defines the AnyValue class, which is used to store an
14-
// immutable value of any type.
13+
// This file defines some miscellaneous overloads of hash_value() and
14+
// simple_display().
1515
//
1616
//===----------------------------------------------------------------------===//
1717

@@ -37,125 +37,7 @@ namespace llvm {
3737
return 1;
3838
return hash_value(*opt);
3939
}
40-
}
4140

42-
namespace swift {
43-
44-
/// Stores a value of any type that satisfies a small set of requirements.
45-
///
46-
/// Requirements on the values stored within an AnyValue:
47-
///
48-
/// - Copy constructor
49-
/// - Equality operator (==)
50-
/// - TypeID support (see swift/Basic/TypeID.h)
51-
/// - Display support (free function):
52-
/// void simple_display(llvm::raw_ostream &, const T &);
53-
class AnyValue {
54-
/// Abstract base class used to hold on to a value.
55-
class HolderBase {
56-
public:
57-
/// Type ID number.
58-
const uint64_t typeID;
59-
60-
HolderBase() = delete;
61-
HolderBase(const HolderBase &) = delete;
62-
HolderBase(HolderBase &&) = delete;
63-
HolderBase &operator=(const HolderBase &) = delete;
64-
HolderBase &operator=(HolderBase &&) = delete;
65-
66-
/// Initialize base with type ID.
67-
HolderBase(uint64_t typeID) : typeID(typeID) { }
68-
69-
virtual ~HolderBase();
70-
71-
/// Determine whether this value is equivalent to another.
72-
///
73-
/// The caller guarantees that the type IDs are the same.
74-
virtual bool equals(const HolderBase &other) const = 0;
75-
76-
/// Display.
77-
virtual void display(llvm::raw_ostream &out) const = 0;
78-
};
79-
80-
/// Holds a value that can be used as a request input/output.
81-
template<typename T>
82-
class Holder final : public HolderBase {
83-
public:
84-
const T value;
85-
86-
Holder(T &&value)
87-
: HolderBase(TypeID<T>::value),
88-
value(std::move(value)) { }
89-
90-
Holder(const T &value) : HolderBase(TypeID<T>::value), value(value) { }
91-
92-
virtual ~Holder() { }
93-
94-
/// Determine whether this value is equivalent to another.
95-
///
96-
/// The caller guarantees that the type IDs are the same.
97-
virtual bool equals(const HolderBase &other) const override {
98-
assert(typeID == other.typeID && "Caller should match type IDs");
99-
return value == static_cast<const Holder<T> &>(other).value;
100-
}
101-
102-
/// Display.
103-
virtual void display(llvm::raw_ostream &out) const override {
104-
simple_display(out, value);
105-
}
106-
};
107-
108-
/// The data stored in this value.
109-
std::shared_ptr<HolderBase> stored;
110-
111-
public:
112-
/// Construct a new instance with the given value.
113-
template<typename T>
114-
AnyValue(T&& value) {
115-
using ValueType = typename std::remove_reference<T>::type;
116-
stored.reset(new Holder<ValueType>(std::forward<T>(value)));
117-
}
118-
119-
/// Cast to a specific (known) type.
120-
template<typename T>
121-
const T &castTo() const {
122-
assert(stored->typeID == TypeID<T>::value);
123-
return static_cast<const Holder<T> *>(stored.get())->value;
124-
}
125-
126-
/// Try casting to a specific (known) type, returning \c nullptr on
127-
/// failure.
128-
template<typename T>
129-
const T *getAs() const {
130-
if (stored->typeID != TypeID<T>::value)
131-
return nullptr;
132-
133-
return &static_cast<const Holder<T> *>(stored.get())->value;
134-
}
135-
136-
/// Compare two instances for equality.
137-
friend bool operator==(const AnyValue &lhs, const AnyValue &rhs) {
138-
if (lhs.stored->typeID != rhs.stored->typeID)
139-
return false;
140-
141-
return lhs.stored->equals(*rhs.stored);
142-
}
143-
144-
friend bool operator!=(const AnyValue &lhs, const AnyValue &rhs) {
145-
return !(lhs == rhs);
146-
}
147-
148-
friend void simple_display(llvm::raw_ostream &out, const AnyValue &value) {
149-
value.stored->display(out);
150-
}
151-
152-
/// Return the result of calling simple_display as a string.
153-
std::string getAsString() const;
154-
};
155-
156-
} // end namespace swift
157-
158-
namespace llvm {
15941
template<typename T>
16042
bool operator==(const TinyPtrVector<T> &lhs, const TinyPtrVector<T> &rhs) {
16143
if (lhs.size() != rhs.size())

include/swift/Basic/TypeID.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static_assert(std::is_same<std::underlying_type<Zone>::type, uint8_t>::value,
4343
///
4444
/// This template needs to be specialized for every type that can
4545
/// participate in this kind of run-time type information, e.g., so
46-
/// that it can be stored in \c AnyValue.
46+
/// that it can be stored in a request.
4747
template<typename T>
4848
struct TypeID;
4949

lib/Basic/AnyValue.cpp

Lines changed: 0 additions & 29 deletions
This file was deleted.

lib/Basic/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ generate_revision_inc(llvm_revision_inc LLVM "${LLVM_MAIN_SRC_DIR}")
4242
generate_revision_inc(swift_revision_inc Swift "${SWIFT_SOURCE_DIR}")
4343

4444
add_swift_host_library(swiftBasic STATIC
45-
AnyValue.cpp
4645
Cache.cpp
4746
ClusteredBitVector.cpp
4847
DiverseStack.cpp

0 commit comments

Comments
 (0)