Skip to content

Commit d9daf49

Browse files
authored
Merge pull request #2384 from swiftwasm/main
[pull] swiftwasm from main
2 parents 3161ac8 + 6efd52d commit d9daf49

27 files changed

+283
-203
lines changed

include/swift/SIL/SILFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ class SILFunction
11061106
/// NOTE: The ownership verifier is always run when performing normal IR
11071107
/// verification, so this verification can be viewed as a subset of
11081108
/// SILFunction::verify.
1109-
void verifyOwnership(DeadEndBlocks *deadEndBlocks = nullptr) const;
1109+
void verifyOwnership(DeadEndBlocks *deadEndBlocks) const;
11101110

11111111
/// Verify that all non-cond-br critical edges have been split.
11121112
///

include/swift/SIL/SILValue.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ class SILValue {
571571
ValueOwnershipKind getOwnershipKind() const;
572572

573573
/// Verify that this SILValue and its uses respects ownership invariants.
574-
void verifyOwnership(DeadEndBlocks *DEBlocks = nullptr) const;
574+
void verifyOwnership(DeadEndBlocks *DEBlocks) const;
575575
};
576576

577577
inline bool ValueOwnershipKind::isCompatibleWith(SILValue other) const {

lib/AST/ASTDumper.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -772,14 +772,14 @@ namespace {
772772
}
773773

774774
auto VarD = dyn_cast<VarDecl>(VD);
775-
if (VD->isFinal() && !(VarD && VarD->isLet()))
775+
const auto &attrs = VD->getAttrs();
776+
if (attrs.hasAttribute<FinalAttr>() && !(VarD && VarD->isLet()))
776777
OS << " final";
777-
if (VD->getAttrs().hasAttribute<ObjCAttr>())
778+
if (attrs.hasAttribute<ObjCAttr>())
778779
OS << " @objc";
779-
if (VD->getAttrs().hasAttribute<DynamicAttr>())
780+
if (attrs.hasAttribute<DynamicAttr>())
780781
OS << " dynamic";
781-
if (auto *attr =
782-
VD->getAttrs().getAttribute<DynamicReplacementAttr>()) {
782+
if (auto *attr = attrs.getAttribute<DynamicReplacementAttr>()) {
783783
OS << " @_dynamicReplacement(for: \"";
784784
OS << attr->getReplacedFunctionName();
785785
OS << "\")";

lib/SIL/Verifier/SILOwnershipVerifier.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -772,16 +772,9 @@ verifySILValueHelper(const SILFunction *f, SILValue value,
772772
return;
773773

774774
SmallPtrSet<SILBasicBlock *, 32> liveBlocks;
775-
if (deadEndBlocks) {
776-
SILValueOwnershipChecker(*deadEndBlocks, value, errorBuilder, liveBlocks,
777-
reborrowVerifier)
778-
.check();
779-
} else {
780-
DeadEndBlocks deadEndBlocks(f);
781-
SILValueOwnershipChecker(deadEndBlocks, value, errorBuilder, liveBlocks,
782-
reborrowVerifier)
783-
.check();
784-
}
775+
SILValueOwnershipChecker(*deadEndBlocks, value, errorBuilder, liveBlocks,
776+
reborrowVerifier)
777+
.check();
785778
}
786779

787780
void SILValue::verifyOwnership(DeadEndBlocks *deadEndBlocks) const {

lib/SILOptimizer/SILCombiner/SILCombine.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class SILCombineCanonicalize final : CanonicalizeInstruction {
138138
changed = true;
139139
}
140140

141-
bool tryCanonicalize(SILInstruction *inst, DeadEndBlocks &deadEndBlocks) {
141+
bool tryCanonicalize(SILInstruction *inst) {
142142
changed = false;
143143
canonicalize(inst);
144144
return changed;
@@ -178,7 +178,7 @@ bool SILCombiner::doOneIteration(SILFunction &F, unsigned Iteration) {
178178
}
179179

180180
// Canonicalize the instruction.
181-
if (scCanonicalize.tryCanonicalize(I, deadEndBlocks)) {
181+
if (scCanonicalize.tryCanonicalize(I)) {
182182
MadeChange = true;
183183
continue;
184184
}

lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,17 +1849,17 @@ SILInstruction *SILCombiner::visitTupleExtractInst(TupleExtractInst *TEI) {
18491849
return nullptr;
18501850
}
18511851

1852-
SILInstruction *SILCombiner::visitFixLifetimeInst(FixLifetimeInst *FLI) {
1853-
if (FLI->getFunction()->hasOwnership())
1854-
return nullptr;
1855-
1852+
SILInstruction *SILCombiner::visitFixLifetimeInst(FixLifetimeInst *fli) {
18561853
// fix_lifetime(alloc_stack) -> fix_lifetime(load(alloc_stack))
1857-
Builder.setCurrentDebugScope(FLI->getDebugScope());
1858-
if (auto *AI = dyn_cast<AllocStackInst>(FLI->getOperand())) {
1859-
if (FLI->getOperand()->getType().isLoadable(*FLI->getFunction())) {
1860-
auto Load = Builder.createLoad(FLI->getLoc(), AI,
1861-
LoadOwnershipQualifier::Unqualified);
1862-
return Builder.createFixLifetime(FLI->getLoc(), Load);
1854+
Builder.setCurrentDebugScope(fli->getDebugScope());
1855+
if (auto *ai = dyn_cast<AllocStackInst>(fli->getOperand())) {
1856+
if (fli->getOperand()->getType().isLoadable(*fli->getFunction())) {
1857+
// load when ossa is disabled
1858+
auto load = Builder.emitLoadBorrowOperation(fli->getLoc(), ai);
1859+
Builder.createFixLifetime(fli->getLoc(), load);
1860+
// no-op when ossa is disabled
1861+
Builder.emitEndBorrowOperation(fli->getLoc(), load);
1862+
return eraseInstFromFunction(*fli);
18631863
}
18641864
}
18651865
return nullptr;

stdlib/public/SwiftShims/RefCount.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,7 @@ class RefCounts {
793793
}
794794

795795
// Increment the reference count.
796+
SWIFT_ALWAYS_INLINE
796797
void increment(uint32_t inc = 1) {
797798
auto oldbits = refCounts.load(SWIFT_MEMORY_ORDER_CONSUME);
798799

@@ -815,6 +816,7 @@ class RefCounts {
815816
std::memory_order_relaxed));
816817
}
817818

819+
SWIFT_ALWAYS_INLINE
818820
void incrementNonAtomic(uint32_t inc = 1) {
819821
auto oldbits = refCounts.load(SWIFT_MEMORY_ORDER_CONSUME);
820822

@@ -835,6 +837,7 @@ class RefCounts {
835837
}
836838

837839
// Increment the reference count, unless the object is deiniting.
840+
SWIFT_ALWAYS_INLINE
838841
bool tryIncrement() {
839842
auto oldbits = refCounts.load(SWIFT_MEMORY_ORDER_CONSUME);
840843
RefCountBits newbits;
@@ -854,6 +857,7 @@ class RefCounts {
854857
return true;
855858
}
856859

860+
SWIFT_ALWAYS_INLINE
857861
bool tryIncrementNonAtomic() {
858862
auto oldbits = refCounts.load(SWIFT_MEMORY_ORDER_CONSUME);
859863
if (!oldbits.hasSideTable() && oldbits.getIsDeiniting())
@@ -896,6 +900,7 @@ class RefCounts {
896900
// object as deiniting.
897901
//
898902
// Precondition: the reference count must be 1
903+
SWIFT_ALWAYS_INLINE
899904
void decrementFromOneNonAtomic() {
900905
auto bits = refCounts.load(SWIFT_MEMORY_ORDER_CONSUME);
901906
if (bits.isImmortal(true)) {
@@ -1078,6 +1083,7 @@ class RefCounts {
10781083
// Deinit is optionally handled directly instead of always deferring to
10791084
// the caller because the compiler can optimize this arrangement better.
10801085
template <PerformDeinit performDeinit>
1086+
SWIFT_ALWAYS_INLINE
10811087
bool doDecrement(uint32_t dec) {
10821088
auto oldbits = refCounts.load(SWIFT_MEMORY_ORDER_CONSUME);
10831089
RefCountBits newbits;

stdlib/public/SwiftShims/SwiftStddef.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,22 @@
1717
// result, using stddef.h here would pull in Darwin module (which includes
1818
// libc). This creates a dependency cycle, so we can't use stddef.h in
1919
// SwiftShims.
20+
//
2021
// On Linux, the story is different. We get the error message
2122
// "/usr/include/x86_64-linux-gnu/sys/types.h:146:10: error: 'stddef.h' file not
2223
// found"
2324
// This is a known Clang/Ubuntu bug.
24-
#if !defined(__APPLE__) && !defined(__linux__)
25+
//
26+
// On Windows, the complicated setup between clang and MSVC causes a cicular
27+
// dependency between `ucrt` and `SwiftShims`, preventing a successful build of
28+
// the module.
29+
//
30+
// Opt to use teh compiler vended type whenever possible.
31+
#if defined(__clang__)
32+
typedef __SIZE_TYPE__ __swift_size_t;
33+
#else
2534
#include <stddef.h>
2635
typedef size_t __swift_size_t;
27-
#else
28-
typedef __SIZE_TYPE__ __swift_size_t;
2936
#endif
3037

3138
// This selects the signed equivalent of the unsigned type chosen for size_t.

stdlib/public/runtime/HeapObject.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ using namespace swift;
6060

6161
/// Returns true if the pointer passed to a native retain or release is valid.
6262
/// If false, the operation should immediately return.
63+
SWIFT_ALWAYS_INLINE
6364
static inline bool isValidPointerForNativeRetain(const void *p) {
6465
#if defined(__x86_64__) || defined(__arm64__) || defined(__aarch64__) || defined(_M_ARM64) || defined(__s390x__) || (defined(__powerpc64__) && defined(__LITTLE_ENDIAN__))
6566
// On these platforms, except s390x, the upper half of address space is reserved for the
@@ -332,6 +333,7 @@ HeapObject *swift::swift_allocEmptyBox() {
332333
extern "C" SWIFT_LIBRARY_VISIBILITY SWIFT_NOINLINE SWIFT_USED void
333334
_swift_release_dealloc(HeapObject *object);
334335

336+
SWIFT_ALWAYS_INLINE
335337
static HeapObject *_swift_retain_(HeapObject *object) {
336338
SWIFT_RT_TRACK_INVOCATION(object, swift_retain);
337339
if (isValidPointerForNativeRetain(object))
@@ -358,6 +360,7 @@ HeapObject *swift::swift_nonatomic_retain(HeapObject *object) {
358360
return object;
359361
}
360362

363+
SWIFT_ALWAYS_INLINE
361364
static HeapObject *_swift_retain_n_(HeapObject *object, uint32_t n) {
362365
SWIFT_RT_TRACK_INVOCATION(object, swift_retain_n);
363366
if (isValidPointerForNativeRetain(object))
@@ -384,6 +387,7 @@ HeapObject *swift::swift_nonatomic_retain_n(HeapObject *object, uint32_t n) {
384387
return object;
385388
}
386389

390+
SWIFT_ALWAYS_INLINE
387391
static void _swift_release_(HeapObject *object) {
388392
SWIFT_RT_TRACK_INVOCATION(object, swift_release);
389393
if (isValidPointerForNativeRetain(object))
@@ -408,6 +412,7 @@ void swift::swift_nonatomic_release(HeapObject *object) {
408412
object->refCounts.decrementAndMaybeDeinitNonAtomic(1);
409413
}
410414

415+
SWIFT_ALWAYS_INLINE
411416
static void _swift_release_n_(HeapObject *object, uint32_t n) {
412417
SWIFT_RT_TRACK_INVOCATION(object, swift_release_n);
413418
if (isValidPointerForNativeRetain(object))
@@ -567,6 +572,7 @@ void swift::swift_nonatomic_unownedRelease_n(HeapObject *object, int n) {
567572
}
568573
}
569574

575+
SWIFT_ALWAYS_INLINE
570576
static HeapObject *_swift_tryRetain_(HeapObject *object) {
571577
SWIFT_RT_TRACK_INVOCATION(object, swift_tryRetain);
572578
if (!isValidPointerForNativeRetain(object))
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
# Dependencies after compilation:
2-
depends-nominal: [z]
1+

0 commit comments

Comments
 (0)