Skip to content

Commit 5549450

Browse files
committed
Merge branch 'main' of github.com:apple/swift into maxd/main-merge
# Conflicts: # CMakeLists.txt
2 parents 365efc2 + 136099b commit 5549450

File tree

95 files changed

+3588
-1593
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+3588
-1593
lines changed

CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,6 @@ option(SWIFT_REPORT_STATISTICS
405405
"Create json files which contain internal compilation statistics"
406406
FALSE)
407407

408-
option(SWIFT_DISABLE_OBJC_INTEROP
409-
"Disable Objective-C interoperability even on platforms what would normally have it"
410-
FALSE)
411-
412408
# FIXME(wasm) Reflection tests are temporalily disabled due to lack of linker features
413409
option(SWIFTWASM_DISABLE_REFLECTION_TEST
414410
"Disable building swift-reflection-test for WebAssembly build"

include/swift/AST/Decl.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3078,6 +3078,10 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
30783078
/// Prepare to traverse the list of extensions.
30793079
void prepareExtensions();
30803080

3081+
/// Add loaded members from all extensions. Eagerly load any members that we
3082+
/// can't lazily load.
3083+
void addLoadedExtensions();
3084+
30813085
/// Retrieve the conformance loader (if any), and removing it in the
30823086
/// same operation. The caller is responsible for loading the
30833087
/// conformances.
@@ -3200,6 +3204,11 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
32003204
/// Add a new extension to this nominal type.
32013205
void addExtension(ExtensionDecl *extension);
32023206

3207+
/// Add a member to this decl's lookup table.
3208+
///
3209+
/// Calls "prepareLookupTable" as a side effect.
3210+
void addMemberToLookupTable(Decl *member);
3211+
32033212
/// Retrieve the set of extensions of this type.
32043213
ExtensionRange getExtensions();
32053214

include/swift/Demangling/ManglingMacros.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@
1717
#define MANGLE_AS_STRING(M) STRINGIFY_MANGLING(M)
1818

1919
/// The mangling prefix for the new mangling.
20+
#if !defined(_MSC_VER) || _MSC_VER-0 >= 1926
2021
_Pragma("clang diagnostic push")
2122
_Pragma("clang diagnostic ignored \"-Wdollar-in-identifier-extension\"")
23+
#endif
2224
#define MANGLING_PREFIX $s
25+
#if !defined(_MSC_VER) || _MSC_VER-0 >= 1926
2326
_Pragma("clang diagnostic pop")
27+
#endif
2428

2529
#define MANGLING_PREFIX_STR MANGLE_AS_STRING(MANGLING_PREFIX)
2630

include/swift/Frontend/BackDeploymentLibs.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
BACK_DEPLOYMENT_LIB((5, 0), all, "swiftCompatibility50")
2828
BACK_DEPLOYMENT_LIB((5, 1), all, "swiftCompatibility51")
2929
BACK_DEPLOYMENT_LIB((5, 0), executable, "swiftCompatibilityDynamicReplacements")
30-
BACK_DEPLOYMENT_LIB((5, 5), all, "swiftCompatibilityConcurrency")
30+
BACK_DEPLOYMENT_LIB((5, 4), all, "swiftCompatibilityConcurrency")
3131

3232
#undef BACK_DEPLOYMENT_LIB

include/swift/SIL/OwnershipUtils.h

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ inline bool isForwardingConsume(SILValue value) {
7777
return canOpcodeForwardOwnedValues(value);
7878
}
7979

80-
/// Find all "use points" of \p guaranteedValue that determine its lifetime
81-
/// requirement.
80+
/// Find leaf "use points" of \p guaranteedValue that determine its lifetime
81+
/// requirement. If \p usePoints is nullptr, then the simply returns true if no
82+
/// PointerEscape use was found.
8283
///
8384
/// Precondition: \p guaranteedValue is not a BorrowedValue.
8485
///
@@ -99,10 +100,10 @@ inline bool isForwardingConsume(SILValue value) {
99100
/// When this is called on a value that does not introduce a new scope, none of
100101
/// the use points can be EndBorrows or Reborrows. Those uses are only allowed
101102
/// on borrow-introducing values.
102-
bool findInnerTransitiveGuaranteedUses(SILValue guaranteedValue,
103-
SmallVectorImpl<Operand *> &usePoints);
103+
bool findInnerTransitiveGuaranteedUses(
104+
SILValue guaranteedValue, SmallVectorImpl<Operand *> *usePoints = nullptr);
104105

105-
/// Find all "use points" of a guaranteed value within its enclosing borrow
106+
/// Find leaf "use points" of a guaranteed value within its enclosing borrow
106107
/// scope (without looking through reborrows). To find the use points of the
107108
/// extended borrow scope, after looking through reborrows, use
108109
/// findExtendedTransitiveGuaranteedUses() instead.
@@ -662,12 +663,19 @@ bool getAllBorrowIntroducingValues(SILValue value,
662663
/// introducer, then we return a .some(BorrowScopeIntroducingValue).
663664
BorrowedValue getSingleBorrowIntroducingValue(SILValue inputValue);
664665

666+
enum class AddressUseKind { NonEscaping, PointerEscape, Unknown };
667+
668+
inline AddressUseKind meet(AddressUseKind lhs, AddressUseKind rhs) {
669+
return (lhs > rhs) ? lhs : rhs;
670+
}
671+
665672
/// The algorithm that is used to determine what the verifier will consider to
666673
/// be transitive uses of the given address. Used to implement \see
667674
/// findTransitiveUses.
668-
bool findTransitiveUsesForAddress(
669-
SILValue address, SmallVectorImpl<Operand *> &foundUses,
670-
std::function<void(Operand *)> *onError = nullptr);
675+
AddressUseKind
676+
findTransitiveUsesForAddress(SILValue address,
677+
SmallVectorImpl<Operand *> *foundUses = nullptr,
678+
std::function<void(Operand *)> *onError = nullptr);
671679

672680
class InteriorPointerOperandKind {
673681
public:
@@ -834,15 +842,19 @@ struct InteriorPointerOperand {
834842
llvm_unreachable("Covered switch isn't covered?!");
835843
}
836844

837-
/// Transitively compute the list of uses that this interior pointer operand
838-
/// puts on its parent guaranted value.
845+
/// Transitively compute the list of leaf uses that this interior pointer
846+
/// operand puts on its parent guaranted value.
847+
///
848+
/// If \p foundUses is nullptr, this simply returns true if no PointerEscapes
849+
/// were found.
839850
///
840851
/// Example: Uses of a ref_element_addr can not occur outside of the lifetime
841852
/// of the instruction's operand. The uses of that address act as liveness
842853
/// requirements to ensure that the underlying class is alive at all use
843854
/// points.
844-
bool findTransitiveUses(SmallVectorImpl<Operand *> &foundUses,
845-
std::function<void(Operand *)> *onError = nullptr) {
855+
AddressUseKind
856+
findTransitiveUses(SmallVectorImpl<Operand *> *foundUses = nullptr,
857+
std::function<void(Operand *)> *onError = nullptr) {
846858
return findTransitiveUsesForAddress(getProjectedAddress(), foundUses,
847859
onError);
848860
}
@@ -912,8 +924,8 @@ struct AddressOwnership {
912924
}
913925

914926
/// Transitively compute uses of this base address.
915-
bool findTransitiveUses(SmallVectorImpl<Operand *> &foundUses) {
916-
return findTransitiveUsesForAddress(base.getBaseAddress(), foundUses);
927+
AddressUseKind findTransitiveUses(SmallVectorImpl<Operand *> &foundUses) {
928+
return findTransitiveUsesForAddress(base.getBaseAddress(), &foundUses);
917929
}
918930

919931
/// Return true of all \p uses occur before the end of the address' lifetime

include/swift/SIL/SILValue.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,12 @@ class Operand {
10581058
/// Returns true if this ends the lifetime of an owned operand.
10591059
bool isConsuming() const;
10601060

1061+
bool endsLocalBorrowScope() const {
1062+
auto ownership = getOperandOwnership();
1063+
return ownership == OperandOwnership::EndBorrow
1064+
|| ownership == OperandOwnership::Reborrow;
1065+
}
1066+
10611067
SILBasicBlock *getParentBlock() const;
10621068
SILFunction *getParentFunction() const;
10631069

include/swift/SILOptimizer/Utils/InstOptUtils.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,13 +647,35 @@ FullApplySite cloneFullApplySiteReplacingCallee(FullApplySite applySite,
647647
SILValue newCallee,
648648
SILBuilderContext &builderCtx);
649649

650+
/// Replace all uses of \p oldValue with \p newValue, notifying the callbacks
651+
/// of new uses and when end-of-scope instructions are deleted.
652+
SILBasicBlock::iterator replaceAllUses(SILValue oldValue, SILValue newValue,
653+
SILBasicBlock::iterator nextii,
654+
InstModCallbacks &callbacks);
655+
650656
/// This is a low level routine that makes all uses of \p svi uses of \p
651657
/// newValue (ignoring end scope markers) and then deletes \p svi and all end
652658
/// scope markers. Then returns the next inst to process.
653659
SILBasicBlock::iterator replaceAllUsesAndErase(SingleValueInstruction *svi,
654660
SILValue newValue,
655661
InstModCallbacks &callbacks);
656662

663+
/// Replace all uses of \p oldValue with \p newValue, delete the instruction
664+
/// that defines \p oldValue, and notify the callbacks of new uses and when
665+
/// the defining instruction and its end-of-scope instructions are deleted.
666+
///
667+
/// Precondition: \p oldValue must be a SingleValueInstruction or a terminator
668+
/// result. \p oldValue must be the only result with remaining uses. For
669+
/// terminators with multiple results, remove all other results for, e.g. via
670+
/// replaceAllUsesWithUndef().
671+
///
672+
/// If \p oldValue is a terminator result, a new branch instruction is inserted
673+
/// in place of the old terminator and all basic block successors become
674+
/// unreachable except for the successor containing the replaced result.
675+
SILBasicBlock::iterator replaceAllUsesAndErase(SILValue oldValue,
676+
SILValue newValue,
677+
InstModCallbacks &callbacks);
678+
657679
/// This API is equivalent to performing \p use->set(\p newValue) except that:
658680
///
659681
/// 1. If the user of \p use is an end scope, this API no-opts. This API is only

include/swift/SILOptimizer/Utils/OwnershipOptUtils.h

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,29 +104,46 @@ struct OwnershipFixupContext {
104104
}
105105
};
106106

107-
/// A utility composed ontop of OwnershipFixupContext that knows how to RAUW a
107+
/// A utility composed on top of OwnershipFixupContext that knows how to RAUW a
108108
/// value or a single value instruction with a new value and then fixup
109109
/// ownership invariants afterwards.
110110
class OwnershipRAUWHelper {
111+
public:
112+
/// Return true if \p oldValue can be replaced with \p newValue in terms of
113+
/// their value ownership. This ignores any current uses of \p oldValue. To
114+
/// determine whether \p oldValue can be replaced as-is with it's existing
115+
/// uses, create an instance of OwnershipRAUWHelper and check its validity.
116+
static bool hasValidRAUWOwnership(SILValue oldValue, SILValue newValue);
117+
118+
private:
111119
OwnershipFixupContext *ctx;
112-
SingleValueInstruction *oldValue;
120+
SILValue oldValue;
113121
SILValue newValue;
114122

115123
public:
116-
OwnershipRAUWHelper() : ctx(nullptr), oldValue(nullptr), newValue(nullptr) {}
124+
OwnershipRAUWHelper() : ctx(nullptr) {}
125+
126+
~OwnershipRAUWHelper() { if (ctx) ctx->clear(); }
117127

118128
/// Return an instance of this class if we can perform the specific RAUW
119129
/// operation ignoring if the types line up. Returns None otherwise.
120130
///
131+
/// \p oldValue may be either a SingleValueInstruction or a terminator result.
132+
///
133+
/// Precondition: If \p oldValue is a BorrowedValue that introduces a local
134+
/// borrow scope, then \p newValue must either be defined in the same block as
135+
/// \p oldValue, or it must dominate \p oldValue (rather than merely
136+
/// dominating its uses).
137+
///
121138
/// DISCUSSION: We do not check that the types line up here so that we can
122139
/// allow for our users to transform our new value in ways that preserve
123140
/// ownership at \p oldValue before we perform the actual RAUW. If \p newValue
124141
/// is an object, any instructions in the chain of transforming instructions
125142
/// from \p newValue at \p oldValue's must be forwarding. If \p newValue is an
126143
/// address, then these transforms can only transform the address into a
127144
/// derived address.
128-
OwnershipRAUWHelper(OwnershipFixupContext &ctx,
129-
SingleValueInstruction *oldValue, SILValue newValue);
145+
OwnershipRAUWHelper(OwnershipFixupContext &ctx, SILValue oldValue,
146+
SILValue newValue);
130147

131148
/// Returns true if this helper was initialized into a valid state.
132149
operator bool() const { return isValid(); }
@@ -149,7 +166,6 @@ class OwnershipRAUWHelper {
149166
SILValue newValue);
150167

151168
void invalidate() {
152-
ctx->clear();
153169
ctx = nullptr;
154170
}
155171
};
@@ -158,6 +174,9 @@ class OwnershipRAUWHelper {
158174
/// a single use of a value with another value with a different ownership. We
159175
/// allow for the values to have different types.
160176
///
177+
/// Precondition: if \p use ends a borrow scope, then \p newValue dominates the
178+
/// BorrowedValue that begins the scope.
179+
///
161180
/// NOTE: When not in OSSA, this just performs a normal set use, so this code is
162181
/// safe to use with all code.
163182
class OwnershipReplaceSingleUseHelper {
@@ -177,6 +196,8 @@ class OwnershipReplaceSingleUseHelper {
177196
OwnershipReplaceSingleUseHelper(OwnershipFixupContext &ctx, Operand *use,
178197
SILValue newValue);
179198

199+
~OwnershipReplaceSingleUseHelper() { if (ctx) ctx->clear(); }
200+
180201
/// Returns true if this helper was initialized into a valid state.
181202
operator bool() const { return isValid(); }
182203
bool isValid() const { return bool(ctx) && bool(use) && bool(newValue); }

lib/AST/DeclContext.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,10 @@ void IterableDeclContext::addMemberSilently(Decl *member, Decl *hint,
867867
if (d->isImplicit())
868868
return true;
869869

870+
// Imported decls won't have complete location info.
871+
if (d->hasClangNode())
872+
return true;
873+
870874
return false;
871875
};
872876

lib/AST/NameLookup.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,12 @@ void ExtensionDecl::addedMember(Decl *member) {
12201220
}
12211221
}
12221222

1223+
void NominalTypeDecl::addMemberToLookupTable(Decl *member) {
1224+
prepareLookupTable();
1225+
1226+
LookupTable->addMember(member);
1227+
}
1228+
12231229
// For lack of anywhere more sensible to put it, here's a diagram of the pieces
12241230
// involved in finding members and extensions of a NominalTypeDecl.
12251231
//
@@ -1332,7 +1338,9 @@ void NominalTypeDecl::prepareLookupTable() {
13321338
} else {
13331339
LookupTable->addMembers(getMembers());
13341340
}
1341+
}
13351342

1343+
void NominalTypeDecl::addLoadedExtensions() {
13361344
for (auto e : getExtensions()) {
13371345
// If we can lazy-load this extension, only take the members we've loaded
13381346
// so far.
@@ -1424,10 +1432,10 @@ DirectLookupRequest::evaluate(Evaluator &evaluator,
14241432

14251433
decl->prepareLookupTable();
14261434

1427-
// If we're allowed to load extensions, call prepareExtensions to ensure we
1435+
// If we're allowed to load extensions, call addLoadedExtensions to ensure we
14281436
// properly invalidate the lazily-complete cache for any extensions brought in
14291437
// by modules loaded after-the-fact. This can happen with the LLDB REPL.
1430-
decl->prepareExtensions();
1438+
decl->addLoadedExtensions();
14311439

14321440
auto &Table = *decl->LookupTable;
14331441
if (!useNamedLazyMemberLoading) {

0 commit comments

Comments
 (0)