Skip to content

Commit 1e9235c

Browse files
committed
Revert "Re-import LLVMSupport from llvm-project and enforce header includes only being used from the Swift fork when building stdlib (swiftlang#40173)"
This reverts commit 7e33575.
1 parent 2ab9941 commit 1e9235c

37 files changed

+714
-1880
lines changed

include/swift/AST/Decl.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,6 @@ enum class AssociatedValueCheck {
207207
/// Diagnostic printing of \c StaticSpellingKind.
208208
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, StaticSpellingKind SSK);
209209

210-
/// Diagnostic printing of \c ReferenceOwnership.
211-
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, ReferenceOwnership RO);
212-
213210
/// Encapsulation of the overload signature of a given declaration,
214211
/// which is used to determine uniqueness of a declaration within a
215212
/// given context.

include/swift/AST/LayoutConstraintKind.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//
1515
//===----------------------------------------------------------------------===//
1616

17-
#include <cstdint>
17+
#include "llvm/Support/DataTypes.h"
1818

1919
#ifndef SWIFT_LAYOUT_CONSTRAINTKIND_H
2020
#define SWIFT_LAYOUT_CONSTRAINTKIND_H

include/swift/AST/Ownership.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "llvm/ADT/StringRef.h"
2424
#include "llvm/Support/Compiler.h"
2525
#include "llvm/Support/ErrorHandling.h"
26+
#include "llvm/Support/raw_ostream.h"
2627
#include <assert.h>
2728
#include <limits.h>
2829
#include <stdint.h>
@@ -117,6 +118,9 @@ optionalityOf(ReferenceOwnership ownership) {
117118
llvm_unreachable("impossible");
118119
}
119120

121+
/// Diagnostic printing of \c StaticSpellingKind.
122+
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, ReferenceOwnership RO);
123+
120124
/// Different kinds of value ownership supported by Swift.
121125
enum class ValueOwnership : uint8_t {
122126
/// the context-dependent default ownership (sometimes shared,

stdlib/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,6 @@ set(SWIFT_CONCURRENCY_GLOBAL_EXECUTOR
178178
# End of user-configurable options.
179179
#
180180

181-
# Remove llvm-project/llvm/include directory from -I search part when building
182-
# the stdlib. We have our own fork of LLVM includes (Support, ADT) in
183-
# stdlib/include/llvm and we don't want to silently use headers from LLVM.
184-
get_property(stdlib_include_directories DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
185-
list(REMOVE_ITEM stdlib_include_directories "${LLVM_MAIN_INCLUDE_DIR}")
186-
set_property(DIRECTORY PROPERTY INCLUDE_DIRECTORIES ${stdlib_include_directories})
187-
188181
include(AddSwiftStdlib)
189182

190183
# Create convenience targets for the Swift standard library.

stdlib/include/llvm/ADT/ArrayRef.h

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
inline namespace __swift { inline namespace __runtime {
2828
namespace llvm {
2929

30-
template<typename T> struct DenseMapInfo;
31-
3230
/// ArrayRef - Represent a constant reference to an array (0 or more elements
3331
/// consecutively in memory), i.e. a start pointer and a length. It allows
3432
/// various APIs to take consecutive elements easily and conveniently.
@@ -43,17 +41,10 @@ namespace llvm {
4341
template<typename T>
4442
class LLVM_GSL_POINTER LLVM_NODISCARD ArrayRef {
4543
public:
46-
using value_type = T;
47-
using pointer = value_type *;
48-
using const_pointer = const value_type *;
49-
using reference = value_type &;
50-
using const_reference = const value_type &;
51-
using iterator = const_pointer;
52-
using const_iterator = const_pointer;
53-
using reverse_iterator = std::reverse_iterator<iterator>;
54-
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
44+
using iterator = const T *;
45+
using const_iterator = const T *;
5546
using size_type = size_t;
56-
using difference_type = ptrdiff_t;
47+
using reverse_iterator = std::reverse_iterator<iterator>;
5748

5849
private:
5950
/// The start of the array, in an external buffer.
@@ -307,17 +298,8 @@ namespace llvm {
307298
template<typename T>
308299
class LLVM_NODISCARD MutableArrayRef : public ArrayRef<T> {
309300
public:
310-
using value_type = T;
311-
using pointer = value_type *;
312-
using const_pointer = const value_type *;
313-
using reference = value_type &;
314-
using const_reference = const value_type &;
315-
using iterator = pointer;
316-
using const_iterator = const_pointer;
301+
using iterator = T *;
317302
using reverse_iterator = std::reverse_iterator<iterator>;
318-
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
319-
using size_type = size_t;
320-
using difference_type = ptrdiff_t;
321303

322304
/// Construct an empty MutableArrayRef.
323305
/*implicit*/ MutableArrayRef() = default;
@@ -572,35 +554,6 @@ namespace llvm {
572554
return hash_combine_range(S.begin(), S.end());
573555
}
574556

575-
// Provide DenseMapInfo for ArrayRefs.
576-
template <typename T> struct DenseMapInfo<ArrayRef<T>> {
577-
static inline ArrayRef<T> getEmptyKey() {
578-
return ArrayRef<T>(
579-
reinterpret_cast<const T *>(~static_cast<uintptr_t>(0)), size_t(0));
580-
}
581-
582-
static inline ArrayRef<T> getTombstoneKey() {
583-
return ArrayRef<T>(
584-
reinterpret_cast<const T *>(~static_cast<uintptr_t>(1)), size_t(0));
585-
}
586-
587-
static unsigned getHashValue(ArrayRef<T> Val) {
588-
assert(Val.data() != getEmptyKey().data() &&
589-
"Cannot hash the empty key!");
590-
assert(Val.data() != getTombstoneKey().data() &&
591-
"Cannot hash the tombstone key!");
592-
return (unsigned)(hash_value(Val));
593-
}
594-
595-
static bool isEqual(ArrayRef<T> LHS, ArrayRef<T> RHS) {
596-
if (RHS.data() == getEmptyKey().data())
597-
return LHS.data() == getEmptyKey().data();
598-
if (RHS.data() == getTombstoneKey().data())
599-
return LHS.data() == getTombstoneKey().data();
600-
return LHS == RHS;
601-
}
602-
};
603-
604557
} // end namespace llvm
605558
}} // namespace swift::runtime
606559

stdlib/include/llvm/ADT/DenseMap.h

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,8 @@ class DenseMapBase {
381381
setNumEntries(other.getNumEntries());
382382
setNumTombstones(other.getNumTombstones());
383383

384-
if (std::is_trivially_copyable<KeyT>::value &&
385-
std::is_trivially_copyable<ValueT>::value)
384+
if (is_trivially_copyable<KeyT>::value &&
385+
is_trivially_copyable<ValueT>::value)
386386
memcpy(reinterpret_cast<void *>(getBuckets()), other.getBuckets(),
387387
getNumBuckets() * sizeof(BucketT));
388388
else
@@ -667,7 +667,7 @@ class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
667667
unsigned NumBuckets;
668668

669669
public:
670-
/// Create a DenseMap with an optional \p InitialReserve that guarantee that
670+
/// Create a DenseMap wth an optional \p InitialReserve that guarantee that
671671
/// this number of elements can be inserted in the map without grow()
672672
explicit DenseMap(unsigned InitialReserve = 0) { init(InitialReserve); }
673673

@@ -864,9 +864,6 @@ class SmallDenseMap
864864
this->insert(I, E);
865865
}
866866

867-
SmallDenseMap(std::initializer_list<typename BaseT::value_type> Vals)
868-
: SmallDenseMap(Vals.begin(), Vals.end()) {}
869-
870867
~SmallDenseMap() {
871868
this->destroyAll();
872869
deallocateBuckets();
@@ -897,7 +894,7 @@ class SmallDenseMap
897894
std::swap(*LHSB, *RHSB);
898895
continue;
899896
}
900-
// Swap separately and handle any asymmetry.
897+
// Swap separately and handle any assymetry.
901898
std::swap(LHSB->getFirst(), RHSB->getFirst());
902899
if (hasLHSValue) {
903900
::new (&RHSB->getSecond()) ValueT(std::move(LHSB->getSecond()));
@@ -985,7 +982,7 @@ class SmallDenseMap
985982
if (Small) {
986983
// First move the inline buckets into a temporary storage.
987984
AlignedCharArrayUnion<BucketT[InlineBuckets]> TmpStorage;
988-
BucketT *TmpBegin = reinterpret_cast<BucketT *>(&TmpStorage);
985+
BucketT *TmpBegin = reinterpret_cast<BucketT *>(TmpStorage.buffer);
989986
BucketT *TmpEnd = TmpBegin;
990987

991988
// Loop over the buckets, moving non-empty, non-tombstones into the
@@ -1075,8 +1072,8 @@ class SmallDenseMap
10751072
assert(Small);
10761073
// Note that this cast does not violate aliasing rules as we assert that
10771074
// the memory's dynamic type is the small, inline bucket buffer, and the
1078-
// 'storage' is a POD containing a char buffer.
1079-
return reinterpret_cast<const BucketT *>(&storage);
1075+
// 'storage.buffer' static type is 'char *'.
1076+
return reinterpret_cast<const BucketT *>(storage.buffer);
10801077
}
10811078

10821079
BucketT *getInlineBuckets() {
@@ -1087,7 +1084,7 @@ class SmallDenseMap
10871084
const LargeRep *getLargeRep() const {
10881085
assert(!Small);
10891086
// Note, same rule about aliasing as with getInlineBuckets.
1090-
return reinterpret_cast<const LargeRep *>(&storage);
1087+
return reinterpret_cast<const LargeRep *>(storage.buffer);
10911088
}
10921089

10931090
LargeRep *getLargeRep() {
@@ -1133,6 +1130,8 @@ class DenseMapIterator {
11331130
friend class DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, true>;
11341131
friend class DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, false>;
11351132

1133+
using ConstIterator = DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, true>;
1134+
11361135
public:
11371136
using difference_type = ptrdiff_t;
11381137
using value_type =
@@ -1172,14 +1171,11 @@ class DenseMapIterator {
11721171
return Ptr;
11731172
}
11741173

1175-
friend bool operator==(const DenseMapIterator &LHS,
1176-
const DenseMapIterator &RHS) {
1177-
return LHS.Ptr == RHS.Ptr;
1174+
bool operator==(const ConstIterator &RHS) const {
1175+
return Ptr == RHS.Ptr;
11781176
}
1179-
1180-
friend bool operator!=(const DenseMapIterator &LHS,
1181-
const DenseMapIterator &RHS) {
1182-
return !(LHS == RHS);
1177+
bool operator!=(const ConstIterator &RHS) const {
1178+
return Ptr != RHS.Ptr;
11831179
}
11841180

11851181
inline DenseMapIterator& operator++() { // Preincrement

stdlib/include/llvm/ADT/DenseMapInfo.h

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
#ifndef LLVM_ADT_DENSEMAPINFO_H
1414
#define LLVM_ADT_DENSEMAPINFO_H
1515

16+
#include "llvm/ADT/ArrayRef.h"
1617
#include "llvm/ADT/Hashing.h"
18+
#include "llvm/ADT/StringRef.h"
1719
#include <cassert>
1820
#include <cstddef>
1921
#include <cstdint>
20-
#include <tuple>
2122
#include <utility>
2223

2324
inline namespace __swift { inline namespace __runtime {
@@ -256,7 +257,7 @@ template <typename... Ts> struct DenseMapInfo<std::tuple<Ts...>> {
256257
}
257258

258259
template <unsigned I>
259-
static unsigned getHashValueImpl(const Tuple &, std::true_type) {
260+
static unsigned getHashValueImpl(const Tuple &values, std::true_type) {
260261
return 0;
261262
}
262263

@@ -274,7 +275,7 @@ template <typename... Ts> struct DenseMapInfo<std::tuple<Ts...>> {
274275
}
275276

276277
template <unsigned I>
277-
static bool isEqualImpl(const Tuple &, const Tuple &, std::true_type) {
278+
static bool isEqualImpl(const Tuple &lhs, const Tuple &rhs, std::true_type) {
278279
return true;
279280
}
280281

@@ -284,6 +285,62 @@ template <typename... Ts> struct DenseMapInfo<std::tuple<Ts...>> {
284285
}
285286
};
286287

288+
// Provide DenseMapInfo for StringRefs.
289+
template <> struct DenseMapInfo<StringRef> {
290+
static inline StringRef getEmptyKey() {
291+
return StringRef(reinterpret_cast<const char *>(~static_cast<uintptr_t>(0)),
292+
0);
293+
}
294+
295+
static inline StringRef getTombstoneKey() {
296+
return StringRef(reinterpret_cast<const char *>(~static_cast<uintptr_t>(1)),
297+
0);
298+
}
299+
300+
static unsigned getHashValue(StringRef Val) {
301+
assert(Val.data() != getEmptyKey().data() && "Cannot hash the empty key!");
302+
assert(Val.data() != getTombstoneKey().data() &&
303+
"Cannot hash the tombstone key!");
304+
return (unsigned)(hash_value(Val));
305+
}
306+
307+
static bool isEqual(StringRef LHS, StringRef RHS) {
308+
if (RHS.data() == getEmptyKey().data())
309+
return LHS.data() == getEmptyKey().data();
310+
if (RHS.data() == getTombstoneKey().data())
311+
return LHS.data() == getTombstoneKey().data();
312+
return LHS == RHS;
313+
}
314+
};
315+
316+
// Provide DenseMapInfo for ArrayRefs.
317+
template <typename T> struct DenseMapInfo<ArrayRef<T>> {
318+
static inline ArrayRef<T> getEmptyKey() {
319+
return ArrayRef<T>(reinterpret_cast<const T *>(~static_cast<uintptr_t>(0)),
320+
size_t(0));
321+
}
322+
323+
static inline ArrayRef<T> getTombstoneKey() {
324+
return ArrayRef<T>(reinterpret_cast<const T *>(~static_cast<uintptr_t>(1)),
325+
size_t(0));
326+
}
327+
328+
static unsigned getHashValue(ArrayRef<T> Val) {
329+
assert(Val.data() != getEmptyKey().data() && "Cannot hash the empty key!");
330+
assert(Val.data() != getTombstoneKey().data() &&
331+
"Cannot hash the tombstone key!");
332+
return (unsigned)(hash_value(Val));
333+
}
334+
335+
static bool isEqual(ArrayRef<T> LHS, ArrayRef<T> RHS) {
336+
if (RHS.data() == getEmptyKey().data())
337+
return LHS.data() == getEmptyKey().data();
338+
if (RHS.data() == getTombstoneKey().data())
339+
return LHS.data() == getTombstoneKey().data();
340+
return LHS == RHS;
341+
}
342+
};
343+
287344
template <> struct DenseMapInfo<hash_code> {
288345
static inline hash_code getEmptyKey() { return hash_code(-1); }
289346
static inline hash_code getTombstoneKey() { return hash_code(-2); }

stdlib/include/llvm/ADT/DenseSet.h

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,8 @@ class DenseSetImpl {
131131

132132
Iterator& operator++() { ++I; return *this; }
133133
Iterator operator++(int) { auto T = *this; ++I; return T; }
134-
friend bool operator==(const Iterator &X, const Iterator &Y) {
135-
return X.I == Y.I;
136-
}
137-
friend bool operator!=(const Iterator &X, const Iterator &Y) {
138-
return X.I != Y.I;
139-
}
134+
bool operator==(const ConstIterator& X) const { return I == X.I; }
135+
bool operator!=(const ConstIterator& X) const { return I != X.I; }
140136
};
141137

142138
class ConstIterator {
@@ -160,12 +156,8 @@ class DenseSetImpl {
160156

161157
ConstIterator& operator++() { ++I; return *this; }
162158
ConstIterator operator++(int) { auto T = *this; ++I; return T; }
163-
friend bool operator==(const ConstIterator &X, const ConstIterator &Y) {
164-
return X.I == Y.I;
165-
}
166-
friend bool operator!=(const ConstIterator &X, const ConstIterator &Y) {
167-
return X.I != Y.I;
168-
}
159+
bool operator==(const ConstIterator& X) const { return I == X.I; }
160+
bool operator!=(const ConstIterator& X) const { return I != X.I; }
169161
};
170162

171163
using iterator = Iterator;
@@ -182,11 +174,6 @@ class DenseSetImpl {
182174
return ConstIterator(TheMap.find(V));
183175
}
184176

185-
/// Check if the set contains the given element.
186-
bool contains(const_arg_type_t<ValueT> V) const {
187-
return TheMap.find(V) != TheMap.end();
188-
}
189-
190177
/// Alternative version of find() which allows a different, and possibly less
191178
/// expensive, key type.
192179
/// The DenseMapInfo is responsible for supplying methods

0 commit comments

Comments
 (0)