Merge branch 'main' into rebranch

Conflicts:
	include/swift/Basic/AnyValue.h
This commit is contained in:
Nate Chandler
2021-01-12 16:30:02 -08:00
97 changed files with 1467 additions and 2100 deletions

View File

@@ -1,4 +1,4 @@
//===--- AnyValue.h - Any Value Existential ---------------------*- C++ -*-===//
//===--- AnyValue.h ---------------------------------------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
@@ -10,8 +10,8 @@
//
//===----------------------------------------------------------------------===//
//
// This file defines the AnyValue class, which is used to store an
// immutable value of any type.
// This file defines some miscellaneous overloads of hash_value() and
// simple_display().
//
//===----------------------------------------------------------------------===//
@@ -29,125 +29,7 @@ namespace llvm {
hash_code hash_value(const llvm::PointerUnion<PT1, PT2> &ptr) {
return hash_value(ptr.getOpaqueValue());
}
}
namespace swift {
/// Stores a value of any type that satisfies a small set of requirements.
///
/// Requirements on the values stored within an AnyValue:
///
/// - Copy constructor
/// - Equality operator (==)
/// - TypeID support (see swift/Basic/TypeID.h)
/// - Display support (free function):
/// void simple_display(llvm::raw_ostream &, const T &);
class AnyValue {
/// Abstract base class used to hold on to a value.
class HolderBase {
public:
/// Type ID number.
const uint64_t typeID;
HolderBase() = delete;
HolderBase(const HolderBase &) = delete;
HolderBase(HolderBase &&) = delete;
HolderBase &operator=(const HolderBase &) = delete;
HolderBase &operator=(HolderBase &&) = delete;
/// Initialize base with type ID.
HolderBase(uint64_t typeID) : typeID(typeID) { }
virtual ~HolderBase();
/// Determine whether this value is equivalent to another.
///
/// The caller guarantees that the type IDs are the same.
virtual bool equals(const HolderBase &other) const = 0;
/// Display.
virtual void display(llvm::raw_ostream &out) const = 0;
};
/// Holds a value that can be used as a request input/output.
template<typename T>
class Holder final : public HolderBase {
public:
const T value;
Holder(T &&value)
: HolderBase(TypeID<T>::value),
value(std::move(value)) { }
Holder(const T &value) : HolderBase(TypeID<T>::value), value(value) { }
virtual ~Holder() { }
/// Determine whether this value is equivalent to another.
///
/// The caller guarantees that the type IDs are the same.
virtual bool equals(const HolderBase &other) const override {
assert(typeID == other.typeID && "Caller should match type IDs");
return value == static_cast<const Holder<T> &>(other).value;
}
/// Display.
virtual void display(llvm::raw_ostream &out) const override {
simple_display(out, value);
}
};
/// The data stored in this value.
std::shared_ptr<HolderBase> stored;
public:
/// Construct a new instance with the given value.
template<typename T>
AnyValue(T&& value) {
using ValueType = typename std::remove_reference<T>::type;
stored.reset(new Holder<ValueType>(std::forward<T>(value)));
}
/// Cast to a specific (known) type.
template<typename T>
const T &castTo() const {
assert(stored->typeID == TypeID<T>::value);
return static_cast<const Holder<T> *>(stored.get())->value;
}
/// Try casting to a specific (known) type, returning \c nullptr on
/// failure.
template<typename T>
const T *getAs() const {
if (stored->typeID != TypeID<T>::value)
return nullptr;
return &static_cast<const Holder<T> *>(stored.get())->value;
}
/// Compare two instances for equality.
friend bool operator==(const AnyValue &lhs, const AnyValue &rhs) {
if (lhs.stored->typeID != rhs.stored->typeID)
return false;
return lhs.stored->equals(*rhs.stored);
}
friend bool operator!=(const AnyValue &lhs, const AnyValue &rhs) {
return !(lhs == rhs);
}
friend void simple_display(llvm::raw_ostream &out, const AnyValue &value) {
value.stored->display(out);
}
/// Return the result of calling simple_display as a string.
std::string getAsString() const;
};
} // end namespace swift
namespace llvm {
template<typename T>
bool operator==(const TinyPtrVector<T> &lhs, const TinyPtrVector<T> &rhs) {
if (lhs.size() != rhs.size())

View File

@@ -221,16 +221,9 @@ namespace swift {
/// Whether to record request references for incremental builds.
bool RecordRequestReferences = true;
/// The path to which we should emit GraphViz output for the complete
/// request-evaluator graph.
std::string RequestEvaluatorGraphVizPath;
/// Whether to dump debug info for request evaluator cycles.
bool DebugDumpCycles = false;
/// Whether to build a request dependency graph for debugging.
bool BuildRequestDependencyGraph = false;
/// Enable SIL type lowering
bool EnableSubstSILFunctionTypesForFunctionValues = true;

View File

@@ -43,7 +43,7 @@ static_assert(std::is_same<std::underlying_type<Zone>::type, uint8_t>::value,
///
/// This template needs to be specialized for every type that can
/// participate in this kind of run-time type information, e.g., so
/// that it can be stored in \c AnyValue.
/// that it can be stored in a request.
template<typename T>
struct TypeID;