Skip to content

Commit 48d8ebd

Browse files
authored
Merge pull request #21606 from compnerd/you-may-not-assert
stdlib: remove some static assertions which may not hold
2 parents e64b514 + 0983ea6 commit 48d8ebd

File tree

4 files changed

+5
-14
lines changed

4 files changed

+5
-14
lines changed

stdlib/public/SwiftShims/GlobalObjects.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,6 @@ static_assert(
102102
4 * sizeof(__swift_intptr_t) + sizeof(__swift_int64_t),
103103
"_SwiftSetBodyStorage has unexpected size");
104104

105-
static_assert(std::is_pod<_SwiftEmptyArrayStorage>::value,
106-
"empty array type should be POD");
107-
static_assert(std::is_pod<_SwiftEmptyDictionarySingleton>::value,
108-
"empty dictionary type should be POD");
109-
static_assert(std::is_pod<_SwiftEmptySetSingleton>::value,
110-
"empty set type should be POD");
111-
112105
}} // extern "C", namespace swift
113106
#endif
114107

stdlib/public/SwiftShims/HeapObject.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ __swift_size_t swift_weakRetainCount(HeapObject *obj);
9393
#endif
9494

9595
#ifdef __cplusplus
96-
static_assert(swift::IsTriviallyConstructible<HeapObject>::value,
97-
"HeapObject must be trivially initializable");
9896
static_assert(std::is_trivially_destructible<HeapObject>::value,
9997
"HeapObject must be trivially destructible");
10098

stdlib/public/SwiftShims/RefCount.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,8 +1188,6 @@ class RefCounts {
11881188
typedef RefCounts<InlineRefCountBits> InlineRefCounts;
11891189
typedef RefCounts<SideTableRefCountBits> SideTableRefCounts;
11901190

1191-
static_assert(swift::IsTriviallyConstructible<InlineRefCounts>::value,
1192-
"InlineRefCounts must be trivially initializable");
11931191
static_assert(std::is_trivially_destructible<InlineRefCounts>::value,
11941192
"InlineRefCounts must be trivially destructible");
11951193

stdlib/public/runtime/HeapObject.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,11 @@ static HeapObject *_swift_allocObject_(HeapMetadata const *metadata,
8484
assert(isAlignmentMask(requiredAlignmentMask));
8585
auto object = reinterpret_cast<HeapObject *>(
8686
swift_slowAlloc(requiredSize, requiredAlignmentMask));
87-
// FIXME: this should be a placement new but that adds a null check
88-
object->metadata = metadata;
89-
object->refCounts.init();
87+
88+
// NOTE: this relies on the C++17 guaranteed semantics of no null-pointer
89+
// check on the placement new allocator which we have observed on Windows,
90+
// Linux, and macOS.
91+
new (object) HeapObject(metadata);
9092

9193
// If leak tracking is enabled, start tracking this object.
9294
SWIFT_LEAKS_START_TRACKING_OBJECT(object);

0 commit comments

Comments
 (0)