Skip to content

Commit 01a915e

Browse files
Merge pull request #4522 from swiftwasm/main
[pull] swiftwasm from main
2 parents f9c920f + dd5d2f4 commit 01a915e

File tree

22 files changed

+1089
-37
lines changed

22 files changed

+1089
-37
lines changed

include/swift/Runtime/Heap.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@
2222
#include <utility>
2323

2424
#include "swift/Runtime/Config.h"
25+
#include "../../../stdlib/public/SwiftShims/Visibility.h"
2526

2627
namespace swift {
2728
// Allocate plain old memory. This is the generalized entry point
2829
// Never returns nil. The returned memory is uninitialized.
2930
//
3031
// An "alignment mask" is just the alignment (a power of 2) minus 1.
31-
SWIFT_RUNTIME_EXPORT
32+
SWIFT_RETURNS_NONNULL SWIFT_RUNTIME_EXPORT
3233
void *swift_slowAlloc(size_t bytes, size_t alignMask);
3334

3435
// If the caller cannot promise to zero the object during destruction,
@@ -52,6 +53,7 @@ void swift_slowDealloc(void *ptr, size_t bytes, size_t alignMask);
5253
/// This function is capable of returning well-aligned memory even on platforms
5354
/// that do not implement the C++17 "over-aligned new" feature.
5455
template <typename T, typename... Args>
56+
SWIFT_RETURNS_NONNULL
5557
static inline T *swift_cxx_newObject(Args &&... args) {
5658
auto result = reinterpret_cast<T *>(swift_slowAlloc(sizeof(T),
5759
alignof(T) - 1));

include/swift/Runtime/HeapObject.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
// Bring in the definition of HeapObject
3030
#include "../../../stdlib/public/SwiftShims/HeapObject.h"
31+
#include "../../../stdlib/public/SwiftShims/Visibility.h"
3132

3233
namespace swift {
3334

@@ -60,7 +61,7 @@ struct OpaqueValue;
6061
///
6162
/// POSSIBILITIES: The argument order is fair game. It may be useful
6263
/// to have a variant which guarantees zero-initialized memory.
63-
SWIFT_RUNTIME_EXPORT
64+
SWIFT_RETURNS_NONNULL SWIFT_RUNTIME_EXPORT
6465
HeapObject *swift_allocObject(HeapMetadata const *metadata,
6566
size_t requiredSize,
6667
size_t requiredAlignmentMask);
@@ -116,7 +117,7 @@ BoxPair swift_makeBoxUnique(OpaqueValue *buffer, Metadata const *type,
116117
size_t alignMask);
117118

118119
/// Returns the address of a heap object representing all empty box types.
119-
SWIFT_RUNTIME_EXPORT
120+
SWIFT_RETURNS_NONNULL SWIFT_RUNTIME_EXPORT
120121
HeapObject* swift_allocEmptyBox();
121122

122123
/// Atomically increments the retain count of an object.

include/swift/Runtime/Metadata.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "swift/ABI/Metadata.h"
2121
#include "swift/Reflection/Records.h"
2222
#include "swift/Runtime/Once.h"
23+
#include "../../../stdlib/public/SwiftShims/Visibility.h"
2324

2425
namespace swift {
2526

@@ -306,7 +307,7 @@ swift_getGenericMetadata(MetadataRequest request,
306307
/// - installing new v-table entries and overrides; and
307308
/// - registering the class with the runtime under ObjC interop.
308309
/// Most of this work can be achieved by calling swift_initClassMetadata.
309-
SWIFT_RUNTIME_EXPORT
310+
SWIFT_RETURNS_NONNULL SWIFT_RUNTIME_EXPORT
310311
ClassMetadata *
311312
swift_allocateGenericClassMetadata(const ClassDescriptor *description,
312313
const void *arguments,
@@ -315,7 +316,7 @@ swift_allocateGenericClassMetadata(const ClassDescriptor *description,
315316
/// Allocate a generic value metadata object. This is intended to be
316317
/// called by the metadata instantiation function of a generic struct or
317318
/// enum.
318-
SWIFT_RUNTIME_EXPORT
319+
SWIFT_RETURNS_NONNULL SWIFT_RUNTIME_EXPORT
319320
ValueMetadata *
320321
swift_allocateGenericValueMetadata(const ValueTypeDescriptor *description,
321322
const void *arguments,

include/swift/SIL/DebugUtils.h

+20-8
Original file line numberDiff line numberDiff line change
@@ -237,24 +237,26 @@ bool hasNonTrivialNonDebugTransitiveUsers(
237237
/// operators to access functionality from the underlying instruction when
238238
/// needed.
239239
struct DebugVarCarryingInst {
240-
enum class Kind {
240+
enum class Kind : uint8_t {
241241
Invalid = 0,
242242
DebugValue,
243243
AllocStack,
244244
AllocBox,
245245
};
246246

247-
Kind kind;
248247
SILInstruction *inst;
248+
Kind kind;
249+
uintptr_t spareBits : (sizeof(uintptr_t) - sizeof(Kind)) * 8;
249250

250-
DebugVarCarryingInst() : kind(Kind::Invalid), inst(nullptr) {}
251+
DebugVarCarryingInst() : inst(nullptr), kind(Kind::Invalid), spareBits(0) {}
251252
DebugVarCarryingInst(DebugValueInst *dvi)
252-
: kind(Kind::DebugValue), inst(dvi) {}
253+
: inst(dvi), kind(Kind::DebugValue), spareBits(0) {}
253254
DebugVarCarryingInst(AllocStackInst *asi)
254-
: kind(Kind::AllocStack), inst(asi) {}
255-
DebugVarCarryingInst(AllocBoxInst *abi) : kind(Kind::AllocBox), inst(abi) {}
255+
: inst(asi), kind(Kind::AllocStack), spareBits(0) {}
256+
DebugVarCarryingInst(AllocBoxInst *abi)
257+
: inst(abi), kind(Kind::AllocBox), spareBits(0) {}
256258
DebugVarCarryingInst(SILInstruction *newInst)
257-
: kind(Kind::Invalid), inst(nullptr) {
259+
: inst(nullptr), kind(Kind::Invalid), spareBits(0) {
258260
switch (newInst->getKind()) {
259261
default:
260262
return;
@@ -280,6 +282,15 @@ struct DebugVarCarryingInst {
280282
/// '->'. This keeps the wrapper light weight.
281283
SILInstruction *operator->() const { return inst; }
282284

285+
bool operator==(const DebugVarCarryingInst &other) const {
286+
return kind == other.kind && inst == other.inst &&
287+
spareBits == other.spareBits;
288+
}
289+
290+
bool operator!=(const DebugVarCarryingInst &other) const {
291+
return !(*this == other);
292+
}
293+
283294
/// Add support for this struct in `if` statement.
284295
explicit operator bool() const { return bool(kind); }
285296

@@ -351,7 +362,8 @@ struct DebugVarCarryingInst {
351362
case Kind::AllocStack:
352363
return cast<AllocStackInst>(inst)->getWasMoved();
353364
case Kind::AllocBox:
354-
llvm_unreachable("Not implemented");
365+
// We do not support moving alloc box today, so we always return false.
366+
return false;
355367
}
356368
}
357369

include/swift/SILOptimizer/PassManager/Passes.def

+2
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,8 @@ PASS(DebugInfoCanonicalizer, "sil-onone-debuginfo-canonicalizer",
448448
"Canonicalize debug info at -Onone by propagating debug info into coroutine funclets")
449449
PASS(PartialApplySimplification, "partial-apply-simplification",
450450
"Transform partial_apply instructions into explicit closure box constructions")
451+
PASS(MovedAsyncVarDebugInfoPropagator, "sil-moved-async-var-dbginfo-propagator",
452+
"Propagate debug info from moved async vars after coroutine funclet boundaries")
451453
PASS(PruneVTables, "prune-vtables",
452454
"Mark class methods that do not require vtable dispatch")
453455
PASS_RANGE(AllPasses, AADumper, PruneVTables)

lib/SIL/IR/SILFunctionBuilder.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,11 @@ SILFunction *SILFunctionBuilder::getOrCreateFunction(
270270

271271
IsTransparent_t IsTrans =
272272
constant.isTransparent() ? IsTransparent : IsNotTransparent;
273+
273274
IsSerialized_t IsSer = constant.isSerialized();
275+
// Don't create a [serialized] function after serialization has happened.
276+
if (IsSer == IsSerialized && mod.isSerialized())
277+
IsSer = IsNotSerialized;
274278

275279
Inline_t inlineStrategy = InlineDefault;
276280
if (constant.isNoinline())

lib/SILOptimizer/Mandatory/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ target_sources(swiftSILOptimizer PRIVATE
2121
LexicalLifetimeEliminator.cpp
2222
LowerHopToActor.cpp
2323
MandatoryInlining.cpp
24+
MovedAsyncVarDebugInfoPropagator.cpp
2425
MoveFunctionCanonicalization.cpp
2526
MoveKillsCopyableAddressesChecker.cpp
2627
MoveKillsCopyableValuesChecker.cpp

0 commit comments

Comments
 (0)