Skip to content

Commit 451b8a6

Browse files
authored
Merge branch 'main' into wip-distributed-private
2 parents 79a3b58 + d899dfd commit 451b8a6

File tree

140 files changed

+1975
-780
lines changed

Some content is hidden

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

140 files changed

+1975
-780
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ docs/_build
4040
# Visual Studio metadata
4141
.vs
4242

43+
# Visual Studio Code Configurations
44+
.vscode
45+
4346
# clangd
4447
.cache
4548
.clangd

include/swift/AST/DiagnosticsSema.def

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4505,22 +4505,31 @@ ERROR(distributed_actor_isolated_method,none,
45054505
"only 'distributed' instance methods can be called on a potentially remote distributed actor",
45064506
())
45074507
ERROR(distributed_actor_func_param_not_codable,none,
4508-
"distributed instance method parameter '%0' of type %1 does not conform to 'Codable'",
4509-
(StringRef, Type))
4508+
"parameter '%0' of type %1 in %2 does not conform to '%3'",
4509+
(StringRef, Type, DescriptiveDeclKind, StringRef))
45104510
ERROR(distributed_actor_func_result_not_codable,none,
4511-
"distributed instance method result type %0 does not conform to 'Codable'",
4512-
(Type))
4511+
"result type %0 of %1 does not conform to '%2'",
4512+
(Type, DescriptiveDeclKind, StringRef))
45134513
ERROR(distributed_actor_remote_func_implemented_manually,none,
4514-
"distributed function's %0 remote counterpart %1 cannot not be implemented manually.",
4514+
"distributed instance method's %0 remote counterpart %1 cannot not be implemented manually.",
45154515
(Identifier, Identifier))
45164516
ERROR(nonisolated_distributed_actor_storage,none,
45174517
"'nonisolated' can not be applied to distributed actor stored properties",
45184518
())
45194519
ERROR(distributed_actor_func_nonisolated, none,
4520-
"function %0 cannot be both 'nonisolated' and 'distributed'",
4520+
"cannot declare method %0 as both 'nonisolated' and 'distributed'",
45214521
(DeclName))
4522+
ERROR(distributed_actor_func_inout, none,
4523+
"cannot declare 'inout' argument %0 in %1 %2",
4524+
(DeclName, DescriptiveDeclKind, DeclName))
4525+
ERROR(distributed_actor_func_closure, none,
4526+
"%0 %1 cannot declare closure arguments, as they cannot be serialized",
4527+
(DescriptiveDeclKind, DeclName))
4528+
ERROR(distributed_actor_func_variadic, none,
4529+
"cannot declare variadic argument %0 in %1 %2",
4530+
(DeclName, DescriptiveDeclKind, DeclName))
45224531
ERROR(distributed_actor_remote_func_is_not_static,none,
4523-
"remote function %0 must be static.",
4532+
"remote function %0 must be static",
45244533
(DeclName))
45254534
ERROR(distributed_actor_remote_func_is_not_async_throws,none,
45264535
"remote function %0 must be 'async throws'.",
@@ -4651,7 +4660,7 @@ ERROR(distributed_actor_func_static,none,
46514660
"'distributed' method cannot be 'static'",
46524661
())
46534662
ERROR(distributed_actor_func_not_in_distributed_actor,none,
4654-
"'distributed' function can only be declared within 'distributed actor'",
4663+
"'distributed' method can only be declared within 'distributed actor'",
46554664
())
46564665
ERROR(distributed_actor_designated_ctor_must_have_one_transport_param,none,
46574666
"designated distributed actor initializer %0 must accept exactly one "

include/swift/AST/Expr.h

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5562,24 +5562,43 @@ class KeyPathExpr : public Expr {
55625562
private:
55635563
llvm::MutableArrayRef<Component> Components;
55645564

5565-
public:
5566-
/// Create a new #keyPath expression.
5567-
KeyPathExpr(ASTContext &C,
5568-
SourceLoc keywordLoc, SourceLoc lParenLoc,
5569-
ArrayRef<Component> components,
5570-
SourceLoc rParenLoc,
5571-
bool isImplicit = false);
5565+
KeyPathExpr(SourceLoc startLoc, Expr *parsedRoot, Expr *parsedPath,
5566+
SourceLoc endLoc, bool hasLeadingDot, bool isObjC,
5567+
bool isImplicit);
55725568

5569+
/// Create a key path with unresolved root and path expressions.
55735570
KeyPathExpr(SourceLoc backslashLoc, Expr *parsedRoot, Expr *parsedPath,
5574-
bool hasLeadingDot, bool isImplicit = false)
5575-
: Expr(ExprKind::KeyPath, isImplicit), StartLoc(backslashLoc),
5576-
EndLoc(parsedPath ? parsedPath->getEndLoc() : parsedRoot->getEndLoc()),
5577-
ParsedRoot(parsedRoot), ParsedPath(parsedPath),
5578-
HasLeadingDot(hasLeadingDot) {
5579-
assert((parsedRoot || parsedPath) &&
5580-
"keypath must have either root or path");
5581-
Bits.KeyPathExpr.IsObjC = false;
5582-
}
5571+
bool hasLeadingDot, bool isImplicit);
5572+
5573+
/// Create a key path with components.
5574+
KeyPathExpr(ASTContext &ctx, SourceLoc startLoc,
5575+
ArrayRef<Component> components, SourceLoc endLoc, bool isObjC,
5576+
bool isImplicit);
5577+
5578+
public:
5579+
/// Create a new parsed Swift key path expression.
5580+
static KeyPathExpr *createParsed(ASTContext &ctx, SourceLoc backslashLoc,
5581+
Expr *parsedRoot, Expr *parsedPath,
5582+
bool hasLeadingDot);
5583+
5584+
/// Create a new parsed #keyPath expression.
5585+
static KeyPathExpr *createParsedPoundKeyPath(ASTContext &ctx,
5586+
SourceLoc keywordLoc,
5587+
SourceLoc lParenLoc,
5588+
ArrayRef<Component> components,
5589+
SourceLoc rParenLoc);
5590+
5591+
/// Create an implicit Swift key path expression with a set of resolved
5592+
/// components.
5593+
static KeyPathExpr *createImplicit(ASTContext &ctx, SourceLoc backslashLoc,
5594+
ArrayRef<Component> components,
5595+
SourceLoc endLoc);
5596+
5597+
/// Create an implicit Swift key path expression with a root and path
5598+
/// expression to be resolved.
5599+
static KeyPathExpr *createImplicit(ASTContext &ctx, SourceLoc backslashLoc,
5600+
Expr *parsedRoot, Expr *parsedPath,
5601+
bool hasLeadingDot);
55835602

55845603
SourceLoc getLoc() const { return StartLoc; }
55855604
SourceRange getSourceRange() const { return SourceRange(StartLoc, EndLoc); }
@@ -5592,10 +5611,9 @@ class KeyPathExpr : public Expr {
55925611
return Components;
55935612
}
55945613

5595-
/// Resolve the components of an un-type-checked expr. This copies over the
5596-
/// components from the argument array.
5597-
void resolveComponents(ASTContext &C,
5598-
ArrayRef<Component> resolvedComponents);
5614+
/// Set the key path components. This copies over the components from the
5615+
/// argument array.
5616+
void setComponents(ASTContext &C, ArrayRef<Component> newComponents);
55995617

56005618
/// Indicates if the key path expression is composed by a single invalid
56015619
/// component. e.g. missing component `\Root`

include/swift/AST/TypeNodes.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ ABSTRACT_TYPE(Substitutable, Type)
148148
ALWAYS_CANONICAL_TYPE(OpaqueTypeArchetype, ArchetypeType)
149149
ALWAYS_CANONICAL_TYPE(OpenedArchetype, ArchetypeType)
150150
ALWAYS_CANONICAL_TYPE(NestedArchetype, ArchetypeType)
151-
TYPE_RANGE(Archetype, PrimaryArchetype, NestedArchetype)
151+
ALWAYS_CANONICAL_TYPE(SequenceArchetype, ArchetypeType)
152+
TYPE_RANGE(Archetype, PrimaryArchetype, SequenceArchetype)
152153
TYPE(GenericTypeParam, SubstitutableType)
153154
TYPE_RANGE(Substitutable, PrimaryArchetype, GenericTypeParam)
154155
TYPE(DependentMember, Type)

include/swift/AST/Types.h

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ class RecursiveTypeProperties {
124124
HasTypeVariable = 0x01,
125125

126126
/// This type expression contains a context-dependent archetype, either a
127-
/// PrimaryArchetypeType or OpenedArchetypeType.
127+
/// \c PrimaryArchetypeType, \c OpenedArchetypeType, or
128+
/// \c SequenceArchetype.
128129
HasArchetype = 0x02,
129130

130131
/// This type expression contains a GenericTypeParamType.
@@ -5683,6 +5684,50 @@ CanArchetypeType getParent() const {
56835684
}
56845685
END_CAN_TYPE_WRAPPER(NestedArchetypeType, ArchetypeType)
56855686

5687+
/// An archetype that represents an opaque element of a type sequence in context.
5688+
///
5689+
/// \code
5690+
/// struct Foo<@_typeSequence Ts> { var xs: @_typeSequence Ts }
5691+
/// func foo<@_typeSequence T>(_ xs: T...) where T: P { }
5692+
/// \endcode
5693+
class SequenceArchetypeType final
5694+
: public ArchetypeType,
5695+
private ArchetypeTrailingObjects<SequenceArchetypeType> {
5696+
friend TrailingObjects;
5697+
friend ArchetypeType;
5698+
5699+
GenericEnvironment *Environment;
5700+
5701+
public:
5702+
/// getNew - Create a new sequence archetype with the given name.
5703+
///
5704+
/// The ConformsTo array will be minimized then copied into the ASTContext
5705+
/// by this routine.
5706+
static CanTypeWrapper<SequenceArchetypeType>
5707+
get(const ASTContext &Ctx, GenericEnvironment *GenericEnv,
5708+
GenericTypeParamType *InterfaceType,
5709+
SmallVectorImpl<ProtocolDecl *> &ConformsTo, Type Superclass,
5710+
LayoutConstraint Layout);
5711+
5712+
/// Retrieve the generic environment in which this archetype resides.
5713+
GenericEnvironment *getGenericEnvironment() const { return Environment; }
5714+
5715+
GenericTypeParamType *getInterfaceType() const {
5716+
return cast<GenericTypeParamType>(InterfaceType.getPointer());
5717+
}
5718+
5719+
static bool classof(const TypeBase *T) {
5720+
return T->getKind() == TypeKind::SequenceArchetype;
5721+
}
5722+
5723+
private:
5724+
SequenceArchetypeType(const ASTContext &Ctx, GenericEnvironment *GenericEnv,
5725+
Type InterfaceType, ArrayRef<ProtocolDecl *> ConformsTo,
5726+
Type Superclass, LayoutConstraint Layout);
5727+
};
5728+
BEGIN_CAN_TYPE_WRAPPER(SequenceArchetypeType, ArchetypeType)
5729+
END_CAN_TYPE_WRAPPER(SequenceArchetypeType, ArchetypeType)
5730+
56865731
template<typename Type>
56875732
const Type *ArchetypeType::getSubclassTrailingObjects() const {
56885733
if (auto contextTy = dyn_cast<PrimaryArchetypeType>(this)) {
@@ -5697,6 +5742,9 @@ const Type *ArchetypeType::getSubclassTrailingObjects() const {
56975742
if (auto childTy = dyn_cast<NestedArchetypeType>(this)) {
56985743
return childTy->getTrailingObjects<Type>();
56995744
}
5745+
if (auto childTy = dyn_cast<SequenceArchetypeType>(this)) {
5746+
return childTy->getTrailingObjects<Type>();
5747+
}
57005748
llvm_unreachable("unhandled ArchetypeType subclass?");
57015749
}
57025750

include/swift/Basic/LangOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ namespace swift {
682682

683683
/// Enable experimental support for type inference through multi-statement
684684
/// closures.
685-
bool EnableMultiStatementClosureInference = false;
685+
bool EnableMultiStatementClosureInference = true;
686686

687687
/// See \ref FrontendOptions.PrintFullConvention
688688
bool PrintFullConvention = false;

include/swift/Reflection/ReflectionContext.h

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ class ReflectionContext
131131
ChunkKind Kind;
132132
};
133133

134+
struct AsyncTaskSlabInfo {
135+
StoredPointer NextSlab;
136+
StoredSize SlabSize;
137+
std::vector<AsyncTaskAllocationChunk> Chunks;
138+
};
139+
134140
explicit ReflectionContext(std::shared_ptr<MemoryReader> reader)
135141
: super(std::move(reader), *this)
136142
{}
@@ -1346,44 +1352,45 @@ class ReflectionContext
13461352
return llvm::None;
13471353
}
13481354

1349-
llvm::Optional<std::string> iterateAsyncTaskAllocations(
1350-
StoredPointer AsyncTaskPtr,
1351-
std::function<void(StoredPointer, unsigned, AsyncTaskAllocationChunk[])>
1352-
Call) {
1353-
using AsyncTask = AsyncTask<Runtime>;
1355+
std::pair<llvm::Optional<std::string>, AsyncTaskSlabInfo>
1356+
asyncTaskSlabAllocations(StoredPointer SlabPtr) {
13541357
using StackAllocator = StackAllocator<Runtime>;
1358+
auto SlabBytes = getReader().readBytes(
1359+
RemoteAddress(SlabPtr), sizeof(typename StackAllocator::Slab));
1360+
auto Slab = reinterpret_cast<const typename StackAllocator::Slab *>(
1361+
SlabBytes.get());
1362+
if (!Slab)
1363+
return {std::string("failure reading slab"), {}};
1364+
1365+
// For now, we won't try to walk the allocations in the slab, we'll just
1366+
// provide the whole thing as one big chunk.
1367+
size_t HeaderSize =
1368+
llvm::alignTo(sizeof(*Slab), llvm::Align(alignof(std::max_align_t)));
1369+
AsyncTaskAllocationChunk Chunk;
1370+
1371+
Chunk.Start = SlabPtr + HeaderSize;
1372+
Chunk.Length = Slab->CurrentOffset;
1373+
Chunk.Kind = AsyncTaskAllocationChunk::ChunkKind::Unknown;
1374+
1375+
// Total slab size is the slab's capacity plus the slab struct itself.
1376+
StoredPointer SlabSize = Slab->Capacity + sizeof(*Slab);
1377+
1378+
return {llvm::None, {Slab->Next, SlabSize, {Chunk}}};
1379+
}
1380+
1381+
std::pair<llvm::Optional<std::string>, StoredPointer>
1382+
asyncTaskSlabPtr(StoredPointer AsyncTaskPtr) {
1383+
using AsyncTask = AsyncTask<Runtime>;
13551384

13561385
auto AsyncTaskBytes =
13571386
getReader().readBytes(RemoteAddress(AsyncTaskPtr), sizeof(AsyncTask));
13581387
auto *AsyncTaskObj =
13591388
reinterpret_cast<const AsyncTask *>(AsyncTaskBytes.get());
13601389
if (!AsyncTaskObj)
1361-
return std::string("failure reading async task");
1390+
return {std::string("failure reading async task"), 0};
13621391

13631392
StoredPointer SlabPtr = AsyncTaskObj->PrivateStorage.Allocator.FirstSlab;
1364-
while (SlabPtr) {
1365-
auto SlabBytes = getReader().readBytes(
1366-
RemoteAddress(SlabPtr), sizeof(typename StackAllocator::Slab));
1367-
auto Slab = reinterpret_cast<const typename StackAllocator::Slab *>(
1368-
SlabBytes.get());
1369-
if (!Slab)
1370-
return std::string("failure reading slab");
1371-
1372-
// For now, we won't try to walk the allocations in the slab, we'll just
1373-
// provide the whole thing as one big chunk.
1374-
size_t HeaderSize =
1375-
llvm::alignTo(sizeof(*Slab), llvm::Align(alignof(std::max_align_t)));
1376-
AsyncTaskAllocationChunk Chunk;
1377-
1378-
Chunk.Start = SlabPtr + HeaderSize;
1379-
Chunk.Length = Slab->CurrentOffset;
1380-
Chunk.Kind = AsyncTaskAllocationChunk::ChunkKind::Unknown;
1381-
Call(SlabPtr, 1, &Chunk);
1382-
1383-
SlabPtr = Slab->Next;
1384-
}
1385-
1386-
return llvm::None;
1393+
return {llvm::None, SlabPtr};
13871394
}
13881395

13891396
private:

include/swift/Reflection/RuntimeInternals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ struct StackAllocator {
8686
bool FirstSlabIsPreallocated;
8787

8888
struct Slab {
89+
typename Runtime::StoredPointer Metadata;
8990
typename Runtime::StoredPointer Next;
9091
uint32_t Capacity;
9192
uint32_t CurrentOffset;

include/swift/Remote/MetadataReader.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,25 +2242,21 @@ class MetadataReader {
22422242
return false;
22432243
};
22442244

2245-
bool isTypeContext = false;
22462245
switch (auto contextKind = descriptor->getKind()) {
22472246
case ContextDescriptorKind::Class:
22482247
if (!getContextName())
22492248
return nullptr;
22502249
nodeKind = Demangle::Node::Kind::Class;
2251-
isTypeContext = true;
22522250
break;
22532251
case ContextDescriptorKind::Struct:
22542252
if (!getContextName())
22552253
return nullptr;
22562254
nodeKind = Demangle::Node::Kind::Structure;
2257-
isTypeContext = true;
22582255
break;
22592256
case ContextDescriptorKind::Enum:
22602257
if (!getContextName())
22612258
return nullptr;
22622259
nodeKind = Demangle::Node::Kind::Enum;
2263-
isTypeContext = true;
22642260
break;
22652261
case ContextDescriptorKind::Protocol: {
22662262
if (!getContextName())

include/swift/Runtime/Concurrency.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,8 +670,11 @@ void swift_task_enqueue(Job *job, ExecutorRef executor);
670670
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
671671
void swift_task_enqueueGlobal(Job *job);
672672

673+
/// A count in nanoseconds.
674+
using JobDelay = unsigned long long;
675+
673676
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
674-
void swift_task_enqueueGlobalWithDelay(unsigned long long delay, Job *job);
677+
void swift_task_enqueueGlobalWithDelay(JobDelay delay, Job *job);
675678

676679
/// Enqueue the given job on the main executor.
677680
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)

0 commit comments

Comments
 (0)