Skip to content

Commit 4171522

Browse files
authored
Merge branch 'main' into tsan-actor_counters.swift
2 parents 22cec7b + 16f3306 commit 4171522

File tree

122 files changed

+3175
-849
lines changed

Some content is hidden

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

122 files changed

+3175
-849
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,36 @@ function(_set_target_prefix_and_suffix target kind sdk)
7575
endif()
7676
endfunction()
7777

78+
function(_add_host_variant_swift_sanitizer_flags target)
79+
if(LLVM_USE_SANITIZER)
80+
if(LLVM_USE_SANITIZER STREQUAL "Address")
81+
set(_Swift_SANITIZER_FLAGS "-sanitize=address")
82+
elseif(LLVM_USE_SANITIZER STREQUAL "HWAddress")
83+
# Not supported?
84+
elseif(LLVM_USE_SANITIZER MATCHES "Memory(WithOrigins)?")
85+
# Not supported
86+
if(LLVM_USE_SANITIZER STREQUAL "MemoryWithOrigins")
87+
# Not supported
88+
endif()
89+
elseif(LLVM_USE_SANITIZER STREQUAL "Undefined")
90+
set(_Swift_SANITIZER_FLAGS "-sanitize=undefined")
91+
elseif(LLVM_USE_SANITIZER STREQUAL "Thread")
92+
set(_Swift_SANITIZER_FLAGS "-sanitize=thread")
93+
elseif(LLVM_USE_SANITIZER STREQUAL "DataFlow")
94+
# Not supported
95+
elseif(LLVM_USE_SANITIZER STREQUAL "Address;Undefined" OR
96+
LLVM_USE_SANITIZER STREQUAL "Undefined;Address")
97+
set(_Swift_SANITIZER_FLAGS "-sanitize=address -sanitize=undefined")
98+
elseif(LLVM_USE_SANITIZER STREQUAL "Leaks")
99+
# Not supported
100+
else()
101+
message(SEND_ERROR "unsupported value for LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}")
102+
endif()
103+
104+
target_compile_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:Swift>:${_Swift_SANITIZER_FLAGS}>)
105+
endif()
106+
endfunction()
107+
78108
# Usage:
79109
# _add_host_variant_c_compile_link_flags(name)
80110
function(_add_host_variant_c_compile_link_flags name)
@@ -100,6 +130,8 @@ function(_add_host_variant_c_compile_link_flags name)
100130
MACCATALYST_BUILD_FLAVOR ""
101131
DEPLOYMENT_VERSION "${DEPLOYMENT_VERSION}")
102132
target_compile_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:Swift>:-target;${target}>)
133+
134+
_add_host_variant_swift_sanitizer_flags(${name})
103135
endif()
104136

105137
set(_sysroot

docs/ABI/OldMangling.rst

Lines changed: 548 additions & 0 deletions
Large diffs are not rendered by default.

docs/Diagnostics.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Clang also has a kind of diagnostic called a "remark", which represents informat
5151
- "...to silence this warning"
5252
- "...here" (for a purely locational note)
5353

54+
- If possible, it is best to include the name of the type or function that has the error, e.g. "non-actor type 'Nope' cannot ..." is better than "non-actor type cannot ...". It helps developers relate the error message to the specific type the error is about, even if the error would highlight the appropriate line / function in other ways.
5455

5556
### Locations and Highlights ###
5657

docs/HowToGuides/GettingStarted.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ Phew, that's a lot to digest! Now let's proceed to the actual build itself!
246246
[using both Ninja and Xcode](#using-both-ninja-and-xcode).
247247
3. Build the toolchain with optimizations, debuginfo, and assertions and run
248248
the tests.
249+
macOS:
249250
- Via Ninja:
250251
```sh
251252
utils/build-script --skip-build-benchmarks \
@@ -259,10 +260,14 @@ Phew, that's a lot to digest! Now let's proceed to the actual build itself!
259260
--sccache --release-debuginfo --swift-disable-dead-stripping --test \
260261
--xcode
261262
```
263+
Linux (uses Ninja):
264+
```sh
265+
utils/build-script --release-debuginfo --test --skip-early-swift-driver
266+
```
262267
This will create a directory
263268
`swift-project/build/Ninja-RelWithDebInfoAssert`
264269
(with `Xcode` instead of `Ninja` if you used `--xcode`)
265-
containing the build artifacts.
270+
containing the Swift compiler and standard library and clang/LLVM build artifacts.
266271
- If the build succeeds: Once the build is complete, the tests will run.
267272
- If the tests are passing: Great! We can go to the next step.
268273
- If some tests are failing:
@@ -272,6 +277,10 @@ Phew, that's a lot to digest! Now let's proceed to the actual build itself!
272277
- If the build fails:
273278
See [Troubleshooting build issues](#troubleshooting-build-issues).
274279

280+
If you would like to additionally build the Swift corelibs,
281+
ie swift-corelibs-libdispatch, swift-corelibs-foundation, and swift-corelibs-xctest,
282+
on Linux, add the `--xctest` flag to `build-script`.
283+
275284
In the following sections, for simplicity, we will assume that you are using a
276285
`Ninja-RelWithDebInfoAssert` build on macOS running on an Intel-based Mac,
277286
unless explicitly mentioned otherwise. You will need to slightly tweak the paths

docs/WindowsBuild.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ ninja -C S:\b\1
140140
## Running Swift tests on Windows
141141

142142
```cmd
143-
path S:\Library\icu-67\usr\bin;S:\b\1\bin;S:\b\1\tools\swift\libdispatch-prefix\bin;%PATH%;%ProgramFiles%\Git\usr\bin
143+
path S:\Library\icu-67\usr\bin;S:\b\1\bin;S:\b\1\tools\swift\libdispatch-windows-x86_64-prefix\bin;%PATH%;%ProgramFiles%\Git\usr\bin
144144
ninja -C S:\b\1 check-swift
145145
```
146146

include/swift/ABI/MetadataValues.h

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,6 +2022,43 @@ enum class JobPriority : size_t {
20222022
Unspecified = 0x00,
20232023
};
20242024

2025+
/// Flags for task creation.
2026+
class TaskCreateFlags : public FlagSet<size_t> {
2027+
public:
2028+
enum {
2029+
Priority = 0,
2030+
Priority_width = 8,
2031+
2032+
Task_IsChildTask = 8,
2033+
// bit 9 is unused
2034+
Task_CopyTaskLocals = 10,
2035+
Task_InheritContext = 11,
2036+
Task_EnqueueJob = 12,
2037+
Task_AddPendingGroupTaskUnconditionally = 13,
2038+
};
2039+
2040+
explicit constexpr TaskCreateFlags(size_t bits) : FlagSet(bits) {}
2041+
constexpr TaskCreateFlags() {}
2042+
2043+
FLAGSET_DEFINE_FIELD_ACCESSORS(Priority, Priority_width, JobPriority,
2044+
getPriority, setPriority)
2045+
FLAGSET_DEFINE_FLAG_ACCESSORS(Task_IsChildTask,
2046+
isChildTask,
2047+
setIsChildTask)
2048+
FLAGSET_DEFINE_FLAG_ACCESSORS(Task_CopyTaskLocals,
2049+
copyTaskLocals,
2050+
setCopyTaskLocals)
2051+
FLAGSET_DEFINE_FLAG_ACCESSORS(Task_InheritContext,
2052+
inheritContext,
2053+
setInheritContext)
2054+
FLAGSET_DEFINE_FLAG_ACCESSORS(Task_EnqueueJob,
2055+
enqueueJob,
2056+
setEnqueueJob)
2057+
FLAGSET_DEFINE_FLAG_ACCESSORS(Task_AddPendingGroupTaskUnconditionally,
2058+
addPendingGroupTaskUnconditionally,
2059+
setAddPendingGroupTaskUnconditionally)
2060+
};
2061+
20252062
/// Flags for schedulable jobs.
20262063
class JobFlags : public FlagSet<uint32_t> {
20272064
public:
@@ -2039,7 +2076,7 @@ class JobFlags : public FlagSet<uint32_t> {
20392076
Task_IsChildTask = 24,
20402077
Task_IsFuture = 25,
20412078
Task_IsGroupChildTask = 26,
2042-
Task_IsContinuingAsyncTask = 27,
2079+
// 27 is currently unused
20432080
Task_IsAsyncLetTask = 28,
20442081
};
20452082

@@ -2070,9 +2107,6 @@ class JobFlags : public FlagSet<uint32_t> {
20702107
FLAGSET_DEFINE_FLAG_ACCESSORS(Task_IsGroupChildTask,
20712108
task_isGroupChildTask,
20722109
task_setIsGroupChildTask)
2073-
FLAGSET_DEFINE_FLAG_ACCESSORS(Task_IsContinuingAsyncTask,
2074-
task_isContinuingAsyncTask,
2075-
task_setIsContinuingAsyncTask)
20762110
FLAGSET_DEFINE_FLAG_ACCESSORS(Task_IsAsyncLetTask,
20772111
task_isAsyncLetTask,
20782112
task_setIsAsyncLetTask)
@@ -2111,6 +2145,8 @@ enum class TaskOptionRecordKind : uint8_t {
21112145
Executor = 0,
21122146
/// Request a child task to be part of a specific task group.
21132147
TaskGroup = 1,
2148+
/// Request a child task for an 'async let'.
2149+
AsyncLet = 2,
21142150
};
21152151

21162152
/// Flags for cancellation records.

include/swift/ABI/TaskGroup.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class alignas(Alignment_TaskGroup) TaskGroup {
3939

4040
/// Upon a future task's completion, offer it to the task group it belongs to.
4141
void offer(AsyncTask *completed, AsyncContext *context);
42+
43+
/// Checks the cancellation status of the group.
44+
bool isCancelled();
4245
};
4346

4447
} // end namespace swift

include/swift/ABI/TaskOptions.h

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "swift/ABI/MetadataValues.h"
2525
#include "swift/Runtime/Config.h"
2626
#include "swift/Basic/STLExtras.h"
27+
#include "llvm/Support/Casting.h"
2728

2829
namespace swift {
2930

@@ -34,14 +35,12 @@ namespace swift {
3435
/// to configure a newly spawned task.
3536
class TaskOptionRecord {
3637
public:
37-
TaskOptionRecordFlags Flags;
38+
const TaskOptionRecordFlags Flags;
3839
TaskOptionRecord *Parent;
3940

4041
TaskOptionRecord(TaskOptionRecordKind kind,
4142
TaskOptionRecord *parent = nullptr)
42-
: Flags(kind) {
43-
Parent = parent;
44-
}
43+
: Flags(kind), Parent(parent) { }
4544

4645
TaskOptionRecord(const TaskOptionRecord &) = delete;
4746
TaskOptionRecord &operator=(const TaskOptionRecord &) = delete;
@@ -53,15 +52,14 @@ class TaskOptionRecord {
5352
TaskOptionRecord *getParent() const {
5453
return Parent;
5554
}
56-
5755
};
5856

5957
/******************************************************************************/
6058
/****************************** TASK OPTIONS **********************************/
6159
/******************************************************************************/
6260

6361
class TaskGroupTaskOptionRecord : public TaskOptionRecord {
64-
TaskGroup *Group;
62+
TaskGroup * const Group;
6563

6664
public:
6765
TaskGroupTaskOptionRecord(TaskGroup *group)
@@ -71,6 +69,10 @@ class TaskGroupTaskOptionRecord : public TaskOptionRecord {
7169
TaskGroup *getGroup() const {
7270
return Group;
7371
}
72+
73+
static bool classof(const TaskOptionRecord *record) {
74+
return record->getKind() == TaskOptionRecordKind::TaskGroup;
75+
}
7476
};
7577

7678

@@ -80,16 +82,38 @@ class TaskGroupTaskOptionRecord : public TaskOptionRecord {
8082
/// executor should be used instead, most often this may mean the global
8183
/// concurrent executor, or the enclosing actor's executor.
8284
class ExecutorTaskOptionRecord : public TaskOptionRecord {
83-
ExecutorRef *Executor;
85+
const ExecutorRef Executor;
8486

8587
public:
86-
ExecutorTaskOptionRecord(ExecutorRef *executor)
88+
ExecutorTaskOptionRecord(ExecutorRef executor)
8789
: TaskOptionRecord(TaskOptionRecordKind::Executor),
8890
Executor(executor) {}
8991

90-
ExecutorRef *getExecutor() const {
92+
ExecutorRef getExecutor() const {
9193
return Executor;
9294
}
95+
96+
static bool classof(const TaskOptionRecord *record) {
97+
return record->getKind() == TaskOptionRecordKind::Executor;
98+
}
99+
};
100+
101+
/// Task option to specify that the created task is for an 'async let'.
102+
class AsyncLetTaskOptionRecord : public TaskOptionRecord {
103+
AsyncLet *asyncLet;
104+
105+
public:
106+
AsyncLetTaskOptionRecord(AsyncLet *asyncLet)
107+
: TaskOptionRecord(TaskOptionRecordKind::AsyncLet),
108+
asyncLet(asyncLet) {}
109+
110+
AsyncLet *getAsyncLet() const {
111+
return asyncLet;
112+
}
113+
114+
static bool classof(const TaskOptionRecord *record) {
115+
return record->getKind() == TaskOptionRecordKind::AsyncLet;
116+
}
93117
};
94118

95119
} // end namespace swift

include/swift/AST/Builtins.def

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -805,28 +805,26 @@ BUILTIN_MISC_OPERATION(StartAsyncLet, "startAsyncLet", "", Special)
805805
/// until the endAsyncLet.
806806
BUILTIN_MISC_OPERATION_WITH_SILGEN(EndAsyncLet, "endAsyncLet", "", Special)
807807

808-
/// createAsyncTaskFuture(): (
809-
/// Int, // flags
810-
/// Builtin.RawPointer?, // options (TaskOptionRecord*)
808+
/// createAsyncTask(): (
809+
/// Int, // task-creation flags
811810
/// @escaping () async throws -> T // function
812811
/// ) -> Builtin.NativeObject
813812
///
814-
/// Create a new asynchronous task future, given flags, an (optional) parent
815-
/// task and a function to execute.
816-
BUILTIN_MISC_OPERATION_WITH_SILGEN(CreateAsyncTaskFuture,
817-
"createAsyncTaskFuture", "", Special)
813+
/// Create a new asynchronous task, given flags, options, and a function to
814+
/// execute.
815+
BUILTIN_MISC_OPERATION_WITH_SILGEN(CreateAsyncTask,
816+
"createAsyncTask", "", Special)
818817

819-
/// createAsyncTaskGroupFuture(): (
818+
/// createAsyncTaskInGroup(): (
820819
/// Int, // flags
821-
/// Builtin.RawPointer?, // group
822-
/// Builtin.RawPointer?, // options (TaskOptionRecord*)
820+
/// Builtin.RawPointer, // group
823821
/// @escaping () async throws -> T // function
824822
/// ) -> Builtin.NativeObject
825823
///
826824
/// Create a new asynchronous task future, given flags, a parent task,
827825
/// task group and a function to execute.
828-
BUILTIN_MISC_OPERATION_WITH_SILGEN(CreateAsyncTaskGroupFuture,
829-
"createAsyncTaskGroupFuture", "", Special)
826+
BUILTIN_MISC_OPERATION_WITH_SILGEN(CreateAsyncTaskInGroup,
827+
"createAsyncTaskInGroup", "", Special)
830828

831829
/// globalStringTablePointer has type String -> Builtin.RawPointer.
832830
/// It returns an immortal, global string table pointer for strings constructed

include/swift/AST/DiagnosticsSIL.def

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,18 @@ ERROR(variable_defer_use_uninit,none,
168168
ERROR(self_closure_use_uninit,none,
169169
"'self' captured by a closure before all members were initialized", ())
170170

171+
/// false == sync; true == global-actor isolated
172+
ERROR(self_use_actor_init,none,
173+
"this use of actor 'self' %select{can only|cannot}0 appear in "
174+
"%select{an async|a global-actor isolated}0 initializer",
175+
(bool))
176+
ERROR(self_disallowed_actor_init,none,
177+
"actor 'self' %select{can only|cannot}0 %1 from "
178+
"%select{an async|a global-actor isolated}0 initializer",
179+
(bool, StringRef))
180+
181+
182+
171183

172184
ERROR(variable_addrtaken_before_initialized,none,
173185
"address of %select{variable|constant}1 '%0' taken before it is"

include/swift/AST/DiagnosticsSema.def

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4349,7 +4349,15 @@ ERROR(async_objc_dynamic_self,none,
43494349
"asynchronous method returning 'Self' cannot be '@objc'", ())
43504350

43514351
ERROR(actor_inheritance,none,
4352-
"actor types do not support inheritance", ())
4352+
"%select{actor|distributed actor}0 types do not support inheritance",
4353+
(bool))
4354+
4355+
ERROR(actor_protocol_illegal_inheritance,none,
4356+
"non-actor type %0 cannot conform to the 'Actor' protocol",
4357+
(DeclName))
4358+
ERROR(distributed_actor_protocol_illegal_inheritance,none,
4359+
"non-distributed actor type %0 cannot conform to the 'DistributedActor' protocol",
4360+
(DeclName))
43534361

43544362
// FIXME: This diagnostic was temporarily downgraded from an error because
43554363
// it spuriously triggers when building the Foundation module from its textual

include/swift/AST/TypeCheckRequests.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ class IsDefaultActorRequest :
915915
bool isCached() const { return true; }
916916
};
917917

918-
/// Determine whether the given class is an distributed actor.
918+
/// Determine whether the given class is a distributed actor.
919919
class IsDistributedActorRequest :
920920
public SimpleRequest<IsDistributedActorRequest,
921921
bool(NominalTypeDecl *),

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@ LANGUAGE_FEATURE(InheritActorContext, 0, "@_inheritActorContext attribute", true
5252
LANGUAGE_FEATURE(ImplicitSelfCapture, 0, "@_implicitSelfCapture attribute", true)
5353
LANGUAGE_FEATURE(BuiltinBuildExecutor, 0, "Executor-building builtins", true)
5454
LANGUAGE_FEATURE(BuiltinBuildMainExecutor, 0, "MainActor executor building builtin", true)
55+
LANGUAGE_FEATURE(BuiltinCreateAsyncTaskInGroup, 0, "MainActor executor building builtin", true)
5556

5657
#undef LANGUAGE_FEATURE

include/swift/Basic/SourceLoc.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ class SourceRange {
123123
/// includes both this range and the other one.
124124
void widen(SourceRange Other);
125125

126+
/// Checks whether this range contains the given location. Note that the given
127+
/// location should correspond to the start of a token, since locations inside
128+
/// the last token may be considered outside the range by this function.
129+
bool contains(SourceLoc Loc) const;
130+
131+
/// Checks whether this range overlaps with the given range.
132+
bool overlaps(SourceRange Other) const;
133+
126134
bool operator==(const SourceRange &other) const {
127135
return Start == other.Start && End == other.End;
128136
}

include/swift/ClangImporter/ClangImporter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ namespace llvm {
2525
class Triple;
2626
class FileCollectorBase;
2727
template<typename Fn> class function_ref;
28+
namespace vfs {
29+
class FileSystem;
30+
}
2831
}
2932

3033
namespace clang {
@@ -158,6 +161,7 @@ class ClangImporter final : public ClangModuleLoader {
158161
static std::unique_ptr<clang::CompilerInvocation>
159162
createClangInvocation(ClangImporter *importer,
160163
const ClangImporterOptions &importerOpts,
164+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
161165
ArrayRef<std::string> invocationArgStrs,
162166
std::vector<std::string> *CC1Args = nullptr);
163167
ClangImporter(const ClangImporter &) = delete;

0 commit comments

Comments
 (0)