Skip to content

Commit ed3dd14

Browse files
Merge pull request #5406 from swiftwasm/main
[pull] swiftwasm from main
2 parents 877f9d8 + e1f2a20 commit ed3dd14

File tree

82 files changed

+3664
-720
lines changed

Some content is hidden

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

82 files changed

+3664
-720
lines changed

Diff for: include/swift/AST/Decl.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -3879,8 +3879,13 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
38793879
/// Find the 'RemoteCallArgument(label:name:value:)' initializer function.
38803880
ConstructorDecl *getDistributedRemoteCallArgumentInitFunction() const;
38813881

3882-
/// Get the move-only `enqueue(Job)` protocol requirement function on the `Executor` protocol.
3882+
/// Get the move-only `enqueue(ExecutorJob)` protocol requirement function on the `Executor` protocol.
38833883
AbstractFunctionDecl *getExecutorOwnedEnqueueFunction() const;
3884+
/// This method should be deprecated and removed
3885+
/// Get the move-only `enqueue(Job)` protocol requirement function on the `Executor` protocol.
3886+
AbstractFunctionDecl *getExecutorLegacyOwnedEnqueueFunction() const;
3887+
/// Get the move-only `enqueue(UnownedJob)` protocol requirement function on the `Executor` protocol.
3888+
AbstractFunctionDecl *getExecutorLegacyUnownedEnqueueFunction() const;
38843889

38853890
/// Collect the set of protocols to which this type should implicitly
38863891
/// conform, such as AnyObject (for classes).

Diff for: include/swift/AST/DiagnosticEngine.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -1169,8 +1169,7 @@ namespace swift {
11691169

11701170
/// Retrieve the set of child notes that describe how the generated
11711171
/// source buffer was derived, e.g., a macro expansion backtrace.
1172-
std::vector<Diagnostic> getGeneratedSourceBufferNotes(
1173-
SourceLoc loc, Optional<unsigned> &lastBufferID);
1172+
std::vector<Diagnostic> getGeneratedSourceBufferNotes(SourceLoc loc);
11741173

11751174
/// Handle a new diagnostic, which will either be emitted, or added to an
11761175
/// active transaction.

Diff for: include/swift/AST/DiagnosticsSema.def

+5-1
Original file line numberDiff line numberDiff line change
@@ -6526,7 +6526,11 @@ WARNING(hashvalue_implementation,Deprecation,
65266526

65276527
WARNING(executor_enqueue_unowned_implementation,Deprecation,
65286528
"'Executor.enqueue(UnownedJob)' is deprecated as a protocol requirement; "
6529-
"conform type %0 to 'Executor' by implementing 'func enqueue(Job)' instead",
6529+
"conform type %0 to 'Executor' by implementing 'func enqueue(ExecutorJob)' instead",
6530+
(Type))
6531+
WARNING(executor_enqueue_deprecated_owned_job_implementation,Deprecation,
6532+
"'Executor.enqueue(Job)' is deprecated as a protocol requirement; "
6533+
"conform type %0 to 'Executor' by implementing 'func enqueue(ExecutorJob)' instead",
65306534
(Type))
65316535

65326536
//------------------------------------------------------------------------------

Diff for: include/swift/SIL/PrunedLiveness.h

-25
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,6 @@ class PrunedLiveBlocks {
202202

203203
bool isInitialized() const { return initializedFlag; }
204204

205-
void invalidate() {
206-
initializedFlag = false;
207-
}
208-
209205
void initializeDiscoveredBlocks(
210206
SmallVectorImpl<SILBasicBlock *> *discoveredBlocks) {
211207
assert(!isInitialized() && "cannot reinitialize after blocks are live");
@@ -371,11 +367,6 @@ class PrunedLiveness {
371367

372368
bool empty() const { return users.empty(); }
373369

374-
void invalidate() {
375-
liveBlocks.invalidate();
376-
users.clear();
377-
}
378-
379370
void initializeDiscoveredBlocks(
380371
SmallVectorImpl<SILBasicBlock *> *discoveredBlocks) {
381372
liveBlocks.initializeDiscoveredBlocks(discoveredBlocks);
@@ -639,12 +630,6 @@ class SSAPrunedLiveness : public PrunedLiveRange<SSAPrunedLiveness> {
639630

640631
SILValue getDef() const { return def; }
641632

642-
void invalidate() {
643-
def = SILValue();
644-
defInst = nullptr;
645-
PrunedLiveRange::invalidate();
646-
}
647-
648633
void initializeDef(SILValue def) {
649634
assert(!this->def && "reinitialization");
650635

@@ -710,10 +695,6 @@ class MultiDefPrunedLiveness : public PrunedLiveRange<MultiDefPrunedLiveness> {
710695
: PrunedLiveRange(function, discoveredBlocks), defs(function),
711696
defBlocks(function) {}
712697

713-
void invalidate() {
714-
PrunedLiveRange::invalidate();
715-
}
716-
717698
void initializeDef(SILInstruction *defInst) {
718699
initializeDefNode(cast<SILNode>(defInst));
719700
}
@@ -800,12 +781,6 @@ class DiagnosticPrunedLiveness : public SSAPrunedLiveness {
800781
: SSAPrunedLiveness(function, discoveredBlocks),
801782
nonLifetimeEndingUsesInLiveOut(nonLifetimeEndingUsesInLiveOut) {}
802783

803-
void invalidate() {
804-
SSAPrunedLiveness::invalidate();
805-
if (nonLifetimeEndingUsesInLiveOut)
806-
nonLifetimeEndingUsesInLiveOut->clear();
807-
}
808-
809784
void updateForUse(SILInstruction *user, bool lifetimeEnding);
810785

811786
using NonLifetimeEndingUsesInLiveOutRange =

Diff for: include/swift/SIL/SILBitfield.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,16 @@ template <typename BitfieldContainer> struct BitfieldRef {
181181
return ref;
182182
}
183183

184+
explicit operator bool() { return ref; }
185+
184186
// Stack-allocated state must be nested relative to other node bitfields.
185187
struct StackState {
186188
BitfieldRef &ref;
187189
BitfieldContainer container;
188190

189-
StackState(BitfieldRef &ref, SILFunction *function)
190-
: ref(ref), container(function) {
191+
template <typename... ArgTypes>
192+
StackState(BitfieldRef &ref, ArgTypes &&...Args)
193+
: ref(ref), container(std::forward<ArgTypes>(Args)...) {
191194
ref.ref = &container;
192195
}
193196

Diff for: include/swift/SIL/SILUndef.h

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ class SILUndef : public ValueBase {
3030
void operator delete(void *, size_t) = delete;
3131

3232
static SILUndef *get(SILType ty, SILModule &m);
33+
34+
/// Return a SILUndef with the same type as the passed in value.
35+
static SILUndef *get(SILValue value) {
36+
return SILUndef::get(value->getType(), *value->getModule());
37+
}
38+
3339
static SILUndef *get(SILType ty, const SILFunction &f);
3440

3541
template <class OwnerTy>

Diff for: include/swift/SILOptimizer/Utils/CanonicalizeBorrowScope.h

+10-5
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,13 @@ class CanonicalizeBorrowScope {
6060
// The borrow that begins this scope.
6161
BorrowedValue borrowedValue;
6262

63+
/// The function containing this scope.
64+
SILFunction *function;
65+
6366
/// Pruned liveness for the extended live range including copies. For this
6467
/// purpose, only consuming instructions are considered "lifetime
6568
/// ending". end_borrows do not end a liverange that may include owned copies.
66-
SSAPrunedLiveness liveness;
69+
BitfieldRef<SSAPrunedLiveness> liveness;
6770

6871
InstructionDeleter &deleter;
6972

@@ -86,11 +89,11 @@ class CanonicalizeBorrowScope {
8689

8790
public:
8891
CanonicalizeBorrowScope(SILFunction *function, InstructionDeleter &deleter)
89-
: liveness(function), deleter(deleter) {}
92+
: function(function), deleter(deleter) {}
9093

9194
BorrowedValue getBorrowedValue() const { return borrowedValue; }
9295

93-
const SSAPrunedLiveness &getLiveness() const { return liveness; }
96+
const SSAPrunedLiveness &getLiveness() const { return *liveness; }
9497

9598
InstructionDeleter &getDeleter() { return deleter; }
9699

@@ -136,11 +139,13 @@ class CanonicalizeBorrowScope {
136139

137140
protected:
138141
void initBorrow(BorrowedValue borrow) {
139-
assert(borrow && liveness.empty() && persistentCopies.empty());
142+
assert(borrow && persistentCopies.empty() &&
143+
(!liveness || liveness->empty()));
140144

141145
updatedCopies.clear();
142146
borrowedValue = borrow;
143-
liveness.initializeDef(borrowedValue.value);
147+
if (liveness)
148+
liveness->initializeDef(borrowedValue.value);
144149
}
145150

146151
bool computeBorrowLiveness();

Diff for: include/swift/SILOptimizer/Utils/CanonicalizeOSSALifetime.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,9 @@ class CanonicalizeOSSALifetime final {
325325
liveness->initializeDef(getCurrentDef());
326326
}
327327

328-
void invalidateLiveness() {
328+
void clear() {
329329
consumingBlocks.clear();
330330
debugValues.clear();
331-
liveness->invalidate();
332331
discoveredBlocks.clear();
333332
}
334333

Diff for: include/swift/SILOptimizer/Utils/OwnershipOptUtils.h

-7
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,6 @@ class GuaranteedOwnershipExtension {
115115
: deleter(deleter), deBlocks(deBlocks),
116116
guaranteedLiveness(function), ownedLifetime(function) {}
117117

118-
void invalidate() {
119-
guaranteedLiveness.invalidate();
120-
ownedLifetime.invalidate();
121-
ownedConsumeBlocks.clear();
122-
beginBorrow = nullptr;
123-
}
124-
125118
/// Invalid indicates that the current guaranteed scope is insufficient, and
126119
/// it does not meet the precondition for scope extension.
127120
///

Diff for: lib/AST/Decl.cpp

+84-2
Original file line numberDiff line numberDiff line change
@@ -5318,6 +5318,48 @@ VarDecl *NominalTypeDecl::getGlobalActorInstance() const {
53185318
AbstractFunctionDecl *
53195319
NominalTypeDecl::getExecutorOwnedEnqueueFunction() const {
53205320
auto &C = getASTContext();
5321+
StructDecl *executorJobDecl = C.getExecutorJobDecl();
5322+
if (!executorJobDecl)
5323+
return nullptr;
5324+
5325+
auto proto = dyn_cast<ProtocolDecl>(this);
5326+
if (!proto)
5327+
return nullptr;
5328+
5329+
llvm::SmallVector<ValueDecl *, 2> results;
5330+
lookupQualified(getSelfNominalTypeDecl(),
5331+
DeclNameRef(C.Id_enqueue),
5332+
NL_ProtocolMembers,
5333+
results);
5334+
5335+
for (auto candidate: results) {
5336+
// we're specifically looking for the Executor protocol requirement
5337+
if (!isa<ProtocolDecl>(candidate->getDeclContext()))
5338+
continue;
5339+
5340+
if (auto *funcDecl = dyn_cast<AbstractFunctionDecl>(candidate)) {
5341+
auto params = funcDecl->getParameters();
5342+
5343+
if (params->size() != 1)
5344+
continue;
5345+
5346+
if ((params->get(0)->getSpecifier() == ParamSpecifier::LegacyOwned ||
5347+
params->get(0)->getSpecifier() == ParamSpecifier::Consuming) &&
5348+
params->get(0)->getInterfaceType()->isEqual(executorJobDecl->getDeclaredInterfaceType())) {
5349+
return funcDecl;
5350+
}
5351+
}
5352+
}
5353+
5354+
return nullptr;
5355+
}
5356+
5357+
AbstractFunctionDecl *
5358+
NominalTypeDecl::getExecutorLegacyOwnedEnqueueFunction() const {
5359+
auto &C = getASTContext();
5360+
StructDecl *legacyJobDecl = C.getJobDecl();
5361+
if (!legacyJobDecl)
5362+
return nullptr;
53215363

53225364
auto proto = dyn_cast<ProtocolDecl>(this);
53235365
if (!proto)
@@ -5335,11 +5377,51 @@ NominalTypeDecl::getExecutorOwnedEnqueueFunction() const {
53355377
continue;
53365378

53375379
if (auto *funcDecl = dyn_cast<AbstractFunctionDecl>(candidate)) {
5338-
if (funcDecl->getParameters()->size() != 1)
5380+
auto params = funcDecl->getParameters();
5381+
5382+
if (params->size() != 1)
53395383
continue;
53405384

5385+
if ((params->get(0)->getSpecifier() == ParamSpecifier::LegacyOwned ||
5386+
params->get(0)->getSpecifier() == ParamSpecifier::Consuming) &&
5387+
params->get(0)->getType()->isEqual(legacyJobDecl->getDeclaredInterfaceType())) {
5388+
return funcDecl;
5389+
}
5390+
}
5391+
}
5392+
5393+
return nullptr;
5394+
}
5395+
5396+
AbstractFunctionDecl *
5397+
NominalTypeDecl::getExecutorLegacyUnownedEnqueueFunction() const {
5398+
auto &C = getASTContext();
5399+
StructDecl *unownedJobDecl = C.getUnownedJobDecl();
5400+
if (!unownedJobDecl)
5401+
return nullptr;
5402+
5403+
auto proto = dyn_cast<ProtocolDecl>(this);
5404+
if (!proto)
5405+
return nullptr;
5406+
5407+
llvm::SmallVector<ValueDecl *, 2> results;
5408+
lookupQualified(getSelfNominalTypeDecl(),
5409+
DeclNameRef(C.Id_enqueue),
5410+
NL_ProtocolMembers,
5411+
results);
5412+
5413+
for (auto candidate: results) {
5414+
// we're specifically looking for the Executor protocol requirement
5415+
if (!isa<ProtocolDecl>(candidate->getDeclContext()))
5416+
continue;
5417+
5418+
if (auto *funcDecl = dyn_cast<AbstractFunctionDecl>(candidate)) {
53415419
auto params = funcDecl->getParameters();
5342-
if (params->get(0)->getSpecifier() == ParamSpecifier::LegacyOwned) { // TODO: make this Consuming
5420+
5421+
if (params->size() != 1)
5422+
continue;
5423+
5424+
if (params->get(0)->getType()->isEqual(unownedJobDecl->getDeclaredInterfaceType())) {
53435425
return funcDecl;
53445426
}
53455427
}

Diff for: lib/AST/DiagnosticEngine.cpp

+7-11
Original file line numberDiff line numberDiff line change
@@ -1272,9 +1272,8 @@ DiagnosticEngine::diagnosticInfoForDiagnostic(const Diagnostic &diagnostic) {
12721272
diagnostic.isChildNote());
12731273
}
12741274

1275-
std::vector<Diagnostic> DiagnosticEngine::getGeneratedSourceBufferNotes(
1276-
SourceLoc loc, Optional<unsigned> &lastBufferID
1277-
) {
1275+
std::vector<Diagnostic>
1276+
DiagnosticEngine::getGeneratedSourceBufferNotes(SourceLoc loc) {
12781277
// The set of child notes we're building up.
12791278
std::vector<Diagnostic> childNotes;
12801279

@@ -1285,12 +1284,6 @@ std::vector<Diagnostic> DiagnosticEngine::getGeneratedSourceBufferNotes(
12851284
// If we already emitted these notes for a prior part of the diagnostic,
12861285
// don't do so again.
12871286
auto currentBufferID = SourceMgr.findBufferContainingLoc(loc);
1288-
if (currentBufferID == lastBufferID)
1289-
return childNotes;
1290-
1291-
// Keep track of the last buffer ID we considered.
1292-
lastBufferID = currentBufferID;
1293-
12941287
SourceLoc currentLoc = loc;
12951288
do {
12961289
auto generatedInfo = SourceMgr.getGeneratedSourceInfo(currentBufferID);
@@ -1337,15 +1330,18 @@ std::vector<Diagnostic> DiagnosticEngine::getGeneratedSourceBufferNotes(
13371330
}
13381331

13391332
void DiagnosticEngine::emitDiagnostic(const Diagnostic &diagnostic) {
1340-
Optional<unsigned> lastBufferID;
13411333

13421334
ArrayRef<Diagnostic> childNotes = diagnostic.getChildNotes();
13431335
std::vector<Diagnostic> extendedChildNotes;
13441336

13451337
if (auto info = diagnosticInfoForDiagnostic(diagnostic)) {
13461338
// If the diagnostic location is within a buffer containing generated
13471339
// source code, add child notes showing where the generation occurred.
1348-
extendedChildNotes = getGeneratedSourceBufferNotes(info->Loc, lastBufferID);
1340+
// We need to avoid doing this if this is itself a child note, as otherwise
1341+
// we'd end up doubling up on notes.
1342+
if (!info->IsChildNote) {
1343+
extendedChildNotes = getGeneratedSourceBufferNotes(info->Loc);
1344+
}
13491345
if (!extendedChildNotes.empty()) {
13501346
extendedChildNotes.insert(extendedChildNotes.end(),
13511347
childNotes.begin(), childNotes.end());

Diff for: lib/ClangImporter/bridging

+25
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// -*- C++ -*-
12
//===------------------ bridging - C++ and Swift Interop --------*- C++ -*-===//
23
//
34
// This source file is part of the Swift.org open source project
@@ -17,6 +18,14 @@
1718
#ifndef SWIFT_CLANGIMPORTER_SWIFT_INTEROP_SUPPORT_H
1819
#define SWIFT_CLANGIMPORTER_SWIFT_INTEROP_SUPPORT_H
1920

21+
#ifdef __has_attribute
22+
#define _CXX_INTEROP_HAS_ATTRIBUTE(x) __has_attribute(x)
23+
#else
24+
#define _CXX_INTEROP_HAS_ATTRIBUTE(x) 0
25+
#endif
26+
27+
#if _CXX_INTEROP_HAS_ATTRIBUTE(swift_attr)
28+
2029
/// Specifies that a C++ `class` or `struct` owns and controls the lifetime of all
2130
/// of the objects it references. Such type should not reference any objects whose
2231
/// lifetime is controlled externally. This annotation allows Swift to import methods
@@ -124,4 +133,20 @@
124133
#define SWIFT_COMPUTED_PROPERTY \
125134
__attribute__((swift_attr("import_computed_property")))
126135

136+
#else // #if _CXX_INTEROP_HAS_ATTRIBUTE(swift_attr)
137+
138+
// Empty defines for compilers that don't support `attribute(swift_attr)`.
139+
#define SWIFT_SELF_CONTAINED
140+
#define SWIFT_RETURNS_INDEPENDENT_VALUE
141+
#define SWIFT_SHARED_REFERENCE(_retain, _release)
142+
#define SWIFT_IMMORTAL_REFERENCE
143+
#define SWIFT_UNSAFE_REFERENCE
144+
#define SWIFT_NAME(_name)
145+
#define SWIFT_CONFORMS_TO_PROTOCOL(_moduleName_protocolName)
146+
#define SWIFT_COMPUTED_PROPERTY
147+
148+
#endif // #if _CXX_INTEROP_HAS_ATTRIBUTE(swift_attr)
149+
150+
#undef _CXX_INTEROP_HAS_ATTRIBUTE
151+
127152
#endif // SWIFT_CLANGIMPORTER_SWIFT_INTEROP_SUPPORT_H

Diff for: lib/Frontend/SerializedDiagnosticConsumer.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ unsigned SerializedDiagnosticConsumer::getEmitFile(
231231
// NOTE: Using Filename.data() here relies on SourceMgr using
232232
// const char* as buffer identifiers. This is fast, but may
233233
// be brittle. We can always switch over to using a StringMap.
234+
// Note that the logic in EditorDiagConsumer::getBufferInfo
235+
// will also need changing.
234236
unsigned &existingEntry = State->Files[Filename.data()];
235237
if (existingEntry)
236238
return existingEntry;

0 commit comments

Comments
 (0)