Skip to content

Commit 28da4b5

Browse files
authored
Merge pull request #2959 from swiftwasm/main
[pull] swiftwasm from main
2 parents 60d0187 + f85633a commit 28da4b5

33 files changed

+278
-103
lines changed

docs/ABI/Mangling.rst

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -514,13 +514,17 @@ Types
514514

515515
type ::= 'Bb' // Builtin.BridgeObject
516516
type ::= 'BB' // Builtin.UnsafeValueBuffer
517-
type ::= 'Bc' // Builtin.RawUnsafeContinuation
518-
type ::= 'BD' // Builtin.DefaultActorStorage
519-
type ::= 'Be' // Builtin.Executor
517+
#if SWIFT_RUNTIME_VERSION >= 5.5
518+
type ::= 'Bc' // Builtin.RawUnsafeContinuation
519+
type ::= 'BD' // Builtin.DefaultActorStorage
520+
type ::= 'Be' // Builtin.Executor
521+
#endif
520522
type ::= 'Bf' NATURAL '_' // Builtin.Float<n>
521523
type ::= 'Bi' NATURAL '_' // Builtin.Int<n>
522524
type ::= 'BI' // Builtin.IntLiteral
523-
type ::= 'Bj' // Builtin.Job
525+
#if SWIFT_RUNTIME_VERSION >= 5.5
526+
type ::= 'Bj' // Builtin.Job
527+
#endif
524528
type ::= 'BO' // Builtin.UnknownObject (no longer a distinct type, but still used for AnyObject)
525529
type ::= 'Bo' // Builtin.NativeObject
526530
type ::= 'Bp' // Builtin.RawPointer
@@ -570,8 +574,10 @@ Types
570574
// they are mangled separately as part of the entity.
571575
params-type ::= empty-list // shortcut for no parameters
572576

573-
async ::= 'Ya' // 'async' annotation on function types
574-
sendable ::= 'Yb' // @Sendable on function types
577+
#if SWIFT_RUNTIME_VERSION >= 5.5
578+
async ::= 'Ya' // 'async' annotation on function types
579+
sendable ::= 'Yb' // @Sendable on function types
580+
#endif
575581
throws ::= 'K' // 'throws' annotation on function types
576582
differentiable ::= 'Yjf' // @differentiable(_forward) on function type
577583
differentiable ::= 'Yjr' // @differentiable(reverse) on function type
@@ -666,8 +672,10 @@ mangled in to disambiguate.
666672
COROUTINE-KIND ::= 'A' // yield-once coroutine
667673
COROUTINE-KIND ::= 'G' // yield-many coroutine
668674

669-
SENDABLE ::= 'h' // @Sendable
670-
ASYNC ::= 'H' // @async
675+
#if SWIFT_RUNTIME_VERSION >= 5.5
676+
SENDABLE ::= 'h' // @Sendable
677+
ASYNC ::= 'H' // @async
678+
#endif
671679

672680
PARAM-CONVENTION ::= 'i' // indirect in
673681
PARAM-CONVENTION ::= 'c' // indirect in constant

include/swift/Option/Options.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ def help_hidden : Flag<["-", "--"], "help-hidden">,
187187
Flags<[HelpHidden, FrontendOption]>,
188188
HelpText<"Display available options, including hidden options">;
189189

190-
def v : Flag<["-"], "v">, Flags<[DoesNotAffectIncrementalBuild]>,
190+
def v : Flag<["-"], "v">,
191+
Flags<[DoesNotAffectIncrementalBuild, SwiftSymbolGraphExtractOption]>,
191192
HelpText<"Show commands to run and use verbose output">;
192193
def version : Flag<["-", "--"], "version">, Flags<[FrontendOption]>,
193194
HelpText<"Print version information and exit">;

include/swift/Runtime/BuiltinTypes.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ BUILTIN_TYPE(BB, "Builtin.UnsafeValueBuffer")
6060
// shaped like AnyObject (normal mangling yXl).
6161
BUILTIN_POINTER_TYPE(BO, "Builtin.UnknownObject")
6262

63+
BUILTIN_POINTER_TYPE(Bc, "Builtin.RawUnsafeContinuation")
64+
BUILTIN_TYPE(BD, "Builtin.DefaultActorStorage")
65+
BUILTIN_TYPE(Be, "Builtin.Executor")
66+
BUILTIN_POINTER_TYPE(Bj, "Builtin.Job")
67+
6368
// Int8 vector types
6469
BUILTIN_VECTOR_TYPE(Bi8_, Int8, 2)
6570
BUILTIN_VECTOR_TYPE(Bi8_, Int8, 3)

include/swift/Runtime/Concurrent.h

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,35 @@ class ConcurrentMap
416416
}
417417
};
418418

419+
/// A simple linked list representing pointers that need to be freed. This is
420+
/// not a concurrent data structure, just a bit of support used in the types
421+
/// below.
422+
struct ConcurrentFreeListNode {
423+
ConcurrentFreeListNode *Next;
424+
void *Ptr;
425+
426+
static void add(ConcurrentFreeListNode **head, void *ptr) {
427+
auto *newNode = reinterpret_cast<ConcurrentFreeListNode *>(
428+
malloc(sizeof(ConcurrentFreeListNode)));
429+
newNode->Next = *head;
430+
newNode->Ptr = ptr;
431+
*head = newNode;
432+
}
433+
434+
/// Free all nodes in the free list, resetting `head` to `NULL`. Calls
435+
/// `FreeFn` on the Ptr field of every node.
436+
template <typename FreeFn>
437+
static void freeAll(ConcurrentFreeListNode **head, const FreeFn &freeFn) {
438+
auto *node = *head;
439+
while (node) {
440+
auto *next = node->Next;
441+
freeFn(node->Ptr);
442+
free(node);
443+
node = next;
444+
}
445+
*head = nullptr;
446+
}
447+
};
419448

420449
/// An append-only array that can be read without taking locks. Writes
421450
/// are still locked and serialized, but only with respect to other
@@ -454,8 +483,8 @@ template <class ElemTy> struct ConcurrentReadableArray {
454483
std::atomic<size_t> ReaderCount;
455484
std::atomic<Storage *> Elements;
456485
Mutex WriterLock;
457-
std::vector<Storage *> FreeList;
458-
486+
ConcurrentFreeListNode *FreeList{nullptr};
487+
459488
void incrementReaders() {
460489
ReaderCount.fetch_add(1, std::memory_order_acquire);
461490
}
@@ -465,10 +494,9 @@ template <class ElemTy> struct ConcurrentReadableArray {
465494
}
466495

467496
void deallocateFreeList() {
468-
for (Storage *storage : FreeList)
469-
storage->deallocate();
470-
FreeList.clear();
471-
FreeList.shrink_to_fit();
497+
ConcurrentFreeListNode::freeAll(&FreeList, [](void *ptr) {
498+
reinterpret_cast<Storage *>(ptr)->deallocate();
499+
});
472500
}
473501

474502
public:
@@ -522,7 +550,7 @@ template <class ElemTy> struct ConcurrentReadableArray {
522550
if (storage) {
523551
std::copy(storage->data(), storage->data() + count, newStorage->data());
524552
newStorage->Count.store(count, std::memory_order_release);
525-
FreeList.push_back(storage);
553+
ConcurrentFreeListNode::add(&FreeList, storage);
526554
}
527555

528556
storage = newStorage;
@@ -797,28 +825,6 @@ struct ConcurrentReadableHashMap {
797825
ElemTy *data() { return &Elem; }
798826
};
799827

800-
/// A simple linked list representing pointers that need to be freed.
801-
struct FreeListNode {
802-
FreeListNode *Next;
803-
void *Ptr;
804-
805-
static void add(FreeListNode **head, void *ptr) {
806-
auto *newNode = new FreeListNode{*head, ptr};
807-
*head = newNode;
808-
}
809-
810-
static void freeAll(FreeListNode **head) {
811-
auto *node = *head;
812-
while (node) {
813-
auto *next = node->Next;
814-
free(node->Ptr);
815-
delete node;
816-
node = next;
817-
}
818-
*head = nullptr;
819-
}
820-
};
821-
822828
/// The number of readers currently active, equal to the number of snapshot
823829
/// objects currently alive.
824830
std::atomic<uint32_t> ReaderCount{0};
@@ -840,7 +846,7 @@ struct ConcurrentReadableHashMap {
840846
MutexTy WriterLock;
841847

842848
/// The list of pointers to be freed once no readers are active.
843-
FreeListNode *FreeList{nullptr};
849+
ConcurrentFreeListNode *FreeList{nullptr};
844850

845851
void incrementReaders() {
846852
ReaderCount.fetch_add(1, std::memory_order_acquire);
@@ -854,7 +860,7 @@ struct ConcurrentReadableHashMap {
854860
/// there are active readers, do nothing.
855861
void deallocateFreeListIfSafe() {
856862
if (ReaderCount.load(std::memory_order_seq_cst) == 0)
857-
FreeListNode::freeAll(&FreeList);
863+
ConcurrentFreeListNode::freeAll(&FreeList, free);
858864
}
859865

860866
/// Grow the elements array, adding the old array to the free list and
@@ -868,7 +874,7 @@ struct ConcurrentReadableHashMap {
868874
if (elements) {
869875
memcpy(newElements->data(), elements->data(),
870876
elementCount * sizeof(ElemTy));
871-
FreeListNode::add(&FreeList, elements);
877+
ConcurrentFreeListNode::add(&FreeList, elements);
872878
}
873879

874880
// Use seq_cst here to ensure that the subsequent load of ReaderCount is
@@ -916,7 +922,7 @@ struct ConcurrentReadableHashMap {
916922
Indices.store(newIndices.Value, std::memory_order_seq_cst);
917923

918924
if (auto *ptr = indices.pointer())
919-
FreeListNode::add(&FreeList, ptr);
925+
ConcurrentFreeListNode::add(&FreeList, ptr);
920926

921927
return newIndices;
922928
}
@@ -1122,8 +1128,8 @@ struct ConcurrentReadableHashMap {
11221128
Elements.store(nullptr, std::memory_order_relaxed);
11231129

11241130
if (auto *ptr = indices.pointer())
1125-
FreeListNode::add(&FreeList, ptr);
1126-
FreeListNode::add(&FreeList, elements);
1131+
ConcurrentFreeListNode::add(&FreeList, ptr);
1132+
ConcurrentFreeListNode::add(&FreeList, elements);
11271133

11281134
deallocateFreeListIfSafe();
11291135
}

include/swift/SymbolGraphGen/SymbolGraphOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ struct SymbolGraphOptions {
3535
/// Emit members gotten through class inheritance or protocol default
3636
/// implementations with compound, "SYNTHESIZED" USRs.
3737
bool EmitSynthesizedMembers;
38+
39+
/// Whether to print informational messages when rendering
40+
/// a symbol graph.
41+
bool PrintMessages;
3842
};
3943

4044
} // end namespace symbolgraphgen

lib/Demangling/Demangler.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,10 @@ NodePointer Demangler::demangleBuiltinType() {
11461146
Ty = createNode(Node::Kind::BuiltinTypeName,
11471147
BUILTIN_TYPE_NAME_UNSAFEVALUEBUFFER);
11481148
break;
1149+
case 'e':
1150+
Ty = createNode(Node::Kind::BuiltinTypeName,
1151+
BUILTIN_TYPE_NAME_EXECUTOR);
1152+
break;
11491153
case 'f': {
11501154
int size = demangleIndex() - 1;
11511155
if (size <= 0 || size > maxTypeSize)

lib/Demangling/Remangler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,8 @@ void Remangler::mangleBuiltinTypeName(Node *node) {
753753
Buffer << 'j';
754754
} else if (text == BUILTIN_TYPE_NAME_DEFAULTACTORSTORAGE) {
755755
Buffer << 'D';
756+
} else if (text == BUILTIN_TYPE_NAME_EXECUTOR) {
757+
Buffer << 'e';
756758
} else if (text == BUILTIN_TYPE_NAME_SILTOKEN) {
757759
Buffer << 't';
758760
} else if (text == BUILTIN_TYPE_NAME_INTLITERAL) {

lib/IDE/ExprContextAnalysis.cpp

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,22 @@ static bool getPositionInArgs(DeclContext &DC, Expr *Args, Expr *CCExpr,
745745
return false;
746746
}
747747

748+
/// For function call arguments \p Args, return the argument at \p Position
749+
/// computed by \c getPositionInArgs
750+
static Expr *getArgAtPosition(Expr *Args, unsigned Position) {
751+
if (isa<ParenExpr>(Args)) {
752+
assert(Position == 0);
753+
return Args;
754+
}
755+
756+
if (auto *tuple = dyn_cast<TupleExpr>(Args)) {
757+
return tuple->getElement(Position);
758+
} else {
759+
llvm_unreachable("Unable to retrieve arg at position returned by "
760+
"getPositionInArgs?");
761+
}
762+
}
763+
748764
/// Get index of \p CCExpr in \p Params. Note that the position in \p Params may
749765
/// be different than the position in \p Args if there are defaulted arguments
750766
/// in \p Params which don't occur in \p Args.
@@ -848,15 +864,15 @@ class ExprContextAnalyzer {
848864
bool analyzeApplyExpr(Expr *E) {
849865
// Collect parameter lists for possible func decls.
850866
SmallVector<FunctionTypeAndDecl, 2> Candidates;
851-
Expr *Arg = nullptr;
867+
Expr *Args = nullptr;
852868
if (auto *applyExpr = dyn_cast<ApplyExpr>(E)) {
853869
if (!collectPossibleCalleesForApply(*DC, applyExpr, Candidates))
854870
return false;
855-
Arg = applyExpr->getArg();
871+
Args = applyExpr->getArg();
856872
} else if (auto *subscriptExpr = dyn_cast<SubscriptExpr>(E)) {
857873
if (!collectPossibleCalleesForSubscript(*DC, subscriptExpr, Candidates))
858874
return false;
859-
Arg = subscriptExpr->getIndex();
875+
Args = subscriptExpr->getIndex();
860876
} else {
861877
llvm_unreachable("unexpected expression kind");
862878
}
@@ -866,14 +882,43 @@ class ExprContextAnalyzer {
866882
// Determine the position of code completion token in call argument.
867883
unsigned PositionInArgs;
868884
bool HasName;
869-
if (!getPositionInArgs(*DC, Arg, ParsedExpr, PositionInArgs, HasName))
885+
if (!getPositionInArgs(*DC, Args, ParsedExpr, PositionInArgs, HasName))
870886
return false;
871887

872888
// Collect possible types (or labels) at the position.
873889
{
874-
bool MayNeedName = !HasName && !E->isImplicit() &&
875-
(isa<CallExpr>(E) | isa<SubscriptExpr>(E) ||
876-
isa<UnresolvedMemberExpr>(E));
890+
bool MayBeArgForLabeledParam =
891+
HasName || E->isImplicit() ||
892+
(!isa<CallExpr>(E) && !isa<SubscriptExpr>(E) &&
893+
!isa<UnresolvedMemberExpr>(E));
894+
895+
// If the completion position cannot be the actual argument, it must be
896+
// able to be an argument label.
897+
bool MayBeLabel = !MayBeArgForLabeledParam;
898+
899+
// Alternatively, the code completion position may complete to an argument
900+
// label if we are currently completing variadic args.
901+
// E.g.
902+
// func foo(x: Int..., y: Int...) {}
903+
// foo(x: 1, #^COMPLETE^#)
904+
// #^COMPLETE^# may complete to either an additional variadic arg or to
905+
// the argument label `y`.
906+
//
907+
// Varargs are represented by a VarargExpansionExpr that contains an
908+
// ArrayExpr on the call side.
909+
if (auto Vararg = dyn_cast<VarargExpansionExpr>(
910+
getArgAtPosition(Args, PositionInArgs))) {
911+
if (auto Array = dyn_cast_or_null<ArrayExpr>(Vararg->getSubExpr())) {
912+
if (Array->getNumElements() > 0 &&
913+
!isa<CodeCompletionExpr>(Array->getElement(0))) {
914+
// We can only complete as argument label if we have at least one
915+
// proper vararg before the code completion token. We shouldn't be
916+
// suggesting labels for:
917+
// foo(x: #^COMPLETE^#)
918+
MayBeLabel = true;
919+
}
920+
}
921+
}
877922
SmallPtrSet<CanType, 4> seenTypes;
878923
llvm::SmallSet<std::pair<Identifier, CanType>, 4> seenArgs;
879924
for (auto &typeAndDecl : Candidates) {
@@ -883,7 +928,7 @@ class ExprContextAnalyzer {
883928

884929
auto Params = typeAndDecl.Type->getParams();
885930
unsigned PositionInParams;
886-
if (!getPositionInParams(*DC, Arg, ParsedExpr, Params,
931+
if (!getPositionInParams(*DC, Args, ParsedExpr, Params,
887932
PositionInParams)) {
888933
// If the argument doesn't have a matching position in the parameters,
889934
// indicate that with optional nullptr param.
@@ -907,11 +952,13 @@ class ExprContextAnalyzer {
907952
paramList && (paramList->get(Pos)->isDefaultArgument() ||
908953
paramList->get(Pos)->isVariadic());
909954

910-
if (paramType.hasLabel() && MayNeedName) {
955+
if (MayBeLabel && paramType.hasLabel()) {
911956
if (seenArgs.insert({paramType.getLabel(), ty->getCanonicalType()})
912957
.second)
913958
recordPossibleParam(&paramType, !canSkip);
914-
} else {
959+
}
960+
961+
if (MayBeArgForLabeledParam || !paramType.hasLabel()) {
915962
auto argTy = ty;
916963
if (paramType.isInOut())
917964
argTy = InOutType::get(argTy);

lib/IRGen/GenObjC.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,10 +1185,11 @@ irgen::emitObjCMethodDescriptorParts(IRGenModule &IGM,
11851185
/// with numbers that used to represent stack offsets for each of these
11861186
/// elements.
11871187
CanSILFunctionType methodType = getObjCMethodType(IGM, method);
1188-
descriptor.typeEncoding =
1189-
getObjCEncodingForMethod(IGM, methodType, /*extended*/ method->hasAsync(),
1190-
method);
11911188

1189+
bool useExtendedEncoding =
1190+
method->hasAsync() && !isa<ProtocolDecl>(method->getDeclContext());
1191+
descriptor.typeEncoding = getObjCEncodingForMethod(
1192+
IGM, methodType, /*extended*/ useExtendedEncoding, method);
11921193
/// The third element is the method implementation pointer.
11931194
if (!concrete) {
11941195
descriptor.impl = nullptr;

lib/IRGen/MetadataRequest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1745,7 +1745,7 @@ namespace {
17451745
llvm_unreachable("error type should not appear in IRGen");
17461746
}
17471747

1748-
// These types are artificial types used for for internal purposes and
1748+
// These types are artificial types used for internal purposes and
17491749
// should never appear in a metadata request.
17501750
#define INTERNAL_ONLY_TYPE(ID) \
17511751
MetadataResponse visit##ID##Type(Can##ID##Type type, \

0 commit comments

Comments
 (0)