Skip to content

Commit 6f4fca8

Browse files
committed
Merge branch 'main' into wip-no-escape-group
2 parents 9a08475 + ca0f638 commit 6f4fca8

File tree

207 files changed

+5096
-2644
lines changed

Some content is hidden

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

207 files changed

+5096
-2644
lines changed

docs/ABI/Mangling.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ types where the metadata itself has unknown layout.)
222222
global ::= global 'Tm' // merged function
223223
global ::= entity // some identifiable thing
224224
global ::= from-type to-type generic-signature? 'TR' // reabstraction thunk
225-
global ::= impl-function-type type 'Tz' // objc-to-swift-async completion handler block implementation
226-
global ::= impl-function-type type 'TZ' // objc-to-swift-async completion handler block implementation (predefined by runtime)
225+
global ::= impl-function-type type 'Tz' index? // objc-to-swift-async completion handler block implementation
226+
global ::= impl-function-type type 'TZ' index? // objc-to-swift-async completion handler block implementation (predefined by runtime)
227227
global ::= from-type to-type generic-signature? 'TR' // reabstraction thunk
228228
global ::= impl-function-type type generic-signature? 'Tz' // objc-to-swift-async completion handler block implementation
229229
global ::= impl-function-type type generic-signature? 'TZ' // objc-to-swift-async completion handler block implementation (predefined by runtime)

docs/SIL.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2320,6 +2320,54 @@ The current list of interior pointer SIL instructions are:
23202320
(*) We still need to finish adding support for project_box, but all other
23212321
interior pointers are guarded already.
23222322

2323+
Memory Lifetime
2324+
~~~~~~~~~~~~~~~
2325+
2326+
Similar to Ownership SSA, there are also lifetime rules for values in memory.
2327+
With "memory" we refer to memory which is addressed by SIL instruction with
2328+
address-type operands, like ``load``, ``store``, ``switch_enum_addr``, etc.
2329+
2330+
Each memory location which holds a non-trivial value is either uninitialized
2331+
or initialized. A memory location gets initialized by storing values into it
2332+
(except assignment, which expects a location to be already initialized).
2333+
A memory location gets de-initialized by "taking" from it or destroying it, e.g.
2334+
with ``destroy_addr``. It is illegal to re-initialize a memory location or to
2335+
use a location after it was de-initialized.
2336+
2337+
If a memory location holds a trivial value (e.g. an ``Int``), it is not
2338+
required to de-initialize the location.
2339+
2340+
The SIL verifier checks this rule for memory locations which can be uniquely
2341+
identified, for example and ``alloc_stack`` or an indirect parameter. The
2342+
verifier cannot check memory locations which are potentially aliased, e.g.
2343+
a ``ref_element_addr`` (a stored class property).
2344+
2345+
Lifetime of Enums in Memory
2346+
```````````````````````````
2347+
2348+
The situation is a bit more complicated with enums, because an enum can have
2349+
both, cases with non-trivial payloads and cases with no payload or trivial
2350+
payloads.
2351+
2352+
Even if an enum itself is not trivial (because it has at least on case with a
2353+
non-trivial payload), it is not required to de-initialize such an enum memory
2354+
location on paths where it's statically provable that the enum contains a
2355+
trivial or non-payload case.
2356+
2357+
That's the case if the destroy point is jointly dominated by:
2358+
2359+
* a ``store [trivial]`` to the enum memory location.
2360+
2361+
or
2362+
2363+
* an ``inject_enum_addr`` to the enum memory location with a non-trivial or
2364+
non-payload case.
2365+
2366+
or
2367+
2368+
* a successor of a ``switch_enum`` or ``switch_enum_addr`` for a non-trivial
2369+
or non-payload case.
2370+
23232371
Dead End Blocks
23242372
~~~~~~~~~~~~~~~
23252373

include/swift/ABI/Task.h

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,17 @@ class alignas(2 * alignof(void*)) Job {
8282
return Flags.getPriority();
8383
}
8484

85-
/// Run this job.
86-
void run(ExecutorRef currentExecutor);
85+
/// Given that we've fully established the job context in the current
86+
/// thread, actually start running this job. To establish the context
87+
/// correctly, call swift_job_run or runJobInExecutorContext.
88+
void runInFullyEstablishedContext(ExecutorRef currentExecutor);
89+
90+
/// Given that we've fully established the job context in the
91+
/// current thread, and that the job is a simple (non-task) job,
92+
/// actually start running this job.
93+
void runSimpleInFullyEstablishedContext(ExecutorRef currentExecutor) {
94+
RunJob(this, currentExecutor);
95+
}
8796
};
8897

8998
// The compiler will eventually assume these.
@@ -176,7 +185,11 @@ class AsyncTask : public HeapObject, public Job {
176185
assert(flags.isAsyncTask());
177186
}
178187

179-
void run(ExecutorRef currentExecutor) {
188+
/// Given that we've already fully established the job context
189+
/// in the current thread, start running this task. To establish
190+
/// the job context correctly, call swift_job_run or
191+
/// runInExecutorContext.
192+
void runInFullyEstablishedContext(ExecutorRef currentExecutor) {
180193
ResumeTask(this, currentExecutor, ResumeContext);
181194
}
182195

@@ -581,6 +594,10 @@ class AsyncTask : public HeapObject, public Job {
581594
/// Destroy the storage associated with the future.
582595
void destroy();
583596

597+
const Metadata *getResultType() const {
598+
return resultType;
599+
}
600+
584601
/// Retrieve a pointer to the storage of result.
585602
OpaqueValue *getStoragePtr() {
586603
return reinterpret_cast<OpaqueValue *>(
@@ -656,11 +673,11 @@ static_assert(sizeof(AsyncTask) == 12 * sizeof(void*),
656673
static_assert(alignof(AsyncTask) == 2 * alignof(void*),
657674
"AsyncTask alignment is wrong");
658675

659-
inline void Job::run(ExecutorRef currentExecutor) {
676+
inline void Job::runInFullyEstablishedContext(ExecutorRef currentExecutor) {
660677
if (auto task = dyn_cast<AsyncTask>(this))
661-
task->run(currentExecutor);
678+
task->runInFullyEstablishedContext(currentExecutor);
662679
else
663-
RunJob(this, currentExecutor);
680+
runSimpleInFullyEstablishedContext(currentExecutor);
664681
}
665682

666683
/// An asynchronous context within a task. Generally contexts are

include/swift/AST/ASTMangler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ class ASTMangler : public Mangler {
172172
std::string mangleObjCAsyncCompletionHandlerImpl(CanSILFunctionType BlockType,
173173
CanType ResultType,
174174
CanGenericSignature Sig,
175+
Optional<bool> FlagParamIsZeroOnError,
175176
bool predefined);
176177

177178
/// Mangle the derivative function (JVP/VJP), or optionally its vtable entry

include/swift/AST/Attr.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,12 @@ SIMPLE_DECL_ATTR(reasync, AtReasync,
624624
ABIBreakingToAdd | ABIBreakingToRemove | APIBreakingToAdd | APIBreakingToRemove,
625625
110)
626626

627+
DECL_ATTR(hasAsyncAlternative, HasAsyncAlternative,
628+
OnAbstractFunction | ConcurrencyOnly |
629+
ABIStableToAdd | ABIStableToRemove |
630+
APIStableToAdd | APIStableToRemove,
631+
111)
632+
627633
#undef TYPE_ATTR
628634
#undef DECL_ATTR_ALIAS
629635
#undef CONTEXTUAL_DECL_ATTR_ALIAS

include/swift/AST/Attr.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2140,6 +2140,30 @@ class TransposeAttr final
21402140
}
21412141
};
21422142

2143+
/// The `@hasAsyncAlternative` attribute marks a function as having an async
2144+
/// alternative, optionally providing a name (for cases when the alternative
2145+
/// has a different name).
2146+
class HasAsyncAlternativeAttr final : public DeclAttribute {
2147+
public:
2148+
/// An optional name of the async alternative function, where the name of the
2149+
/// attributed function is used otherwise.
2150+
const DeclNameRef Name;
2151+
2152+
HasAsyncAlternativeAttr(DeclNameRef Name, SourceLoc AtLoc, SourceRange Range)
2153+
: DeclAttribute(DAK_HasAsyncAlternative, AtLoc, Range, false),
2154+
Name(Name) {}
2155+
2156+
HasAsyncAlternativeAttr(SourceLoc AtLoc, SourceRange Range)
2157+
: DeclAttribute(DAK_HasAsyncAlternative, AtLoc, Range, false) {}
2158+
2159+
/// Determine whether this attribute has a name associated with it.
2160+
bool hasName() const { return !Name.getBaseName().empty(); }
2161+
2162+
static bool classof(const DeclAttribute *DA) {
2163+
return DA->getKind() == DAK_HasAsyncAlternative;
2164+
}
2165+
};
2166+
21432167
/// Attributes that may be applied to declarations.
21442168
class DeclAttributes {
21452169
/// Linked list of declaration attributes.

include/swift/AST/DiagnosticsParse.def

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,6 +1672,15 @@ ERROR(sil_inst_autodiff_invalid_witness_generic_signature,PointsToFirstBadToken,
16721672
"parameters as original function generic signature '%1'",
16731673
(StringRef, StringRef))
16741674

1675+
// hasAsyncAlternative
1676+
ERROR(requires_has_async_alternative, none,
1677+
"'%0' support is required to be explicitly enabled using "
1678+
"-experimental-has-async-alternative-attribute", (StringRef))
1679+
1680+
ERROR(has_async_alternative_invalid_name, none,
1681+
"argument of '%0' attribute must be an identifier or full function name",
1682+
(StringRef))
1683+
16751684
//------------------------------------------------------------------------------
16761685
// MARK: Generics parsing diagnostics
16771686
//------------------------------------------------------------------------------

include/swift/AST/DiagnosticsSema.def

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -779,9 +779,6 @@ NOTE(serialization_compatibility_version_mismatch,none,
779779
ERROR(serialization_allowing_invalid_decl,none,
780780
"allowing deserialization of invalid declaration %0 from module '%1'",
781781
(DeclName, StringRef))
782-
ERROR(serialization_invalid_decl,Fatal,
783-
"invalid declaration %0 read from module '%1'; "
784-
SWIFT_BUG_REPORT_MESSAGE, ())
785782

786783
ERROR(reserved_member_name,none,
787784
"type member must not be named %0, since it would conflict with the"
@@ -3546,6 +3543,9 @@ ERROR(generic_type_requires_arguments,none,
35463543
NOTE(descriptive_generic_type_declared_here,none,
35473544
"%0 declared here", (StringRef))
35483545

3546+
ERROR(placeholder_type_not_allowed,none,
3547+
"you cannot use a placeholder type here", ())
3548+
35493549
WARNING(use_of_void_pointer,none,
35503550
"Unsafe%0Pointer<Void> has been replaced by Unsafe%0RawPointer", (StringRef))
35513551

@@ -4319,24 +4319,45 @@ WARNING(non_concurrent_property_type,none,
43194319
"cannot use %0 %1 with a non-concurrent-value type %2 "
43204320
"%select{across actors|from concurrently-executed code}3",
43214321
(DescriptiveDeclKind, DeclName, Type, bool))
4322+
WARNING(non_concurrent_keypath_capture,none,
4323+
"cannot form key path that captures non-concurrent-value type %0",
4324+
(Type))
43224325
ERROR(non_concurrent_type_member,none,
43234326
"%select{stored property %1|associated value %1}0 of "
43244327
"'ConcurrentValue'-conforming %2 %3 has non-concurrent-value type %4",
43254328
(bool, DeclName, DescriptiveDeclKind, DeclName, Type))
4329+
WARNING(non_concurrent_type_member_warn,none,
4330+
"%select{stored property %1|associated value %1}0 of "
4331+
"'ConcurrentValue'-conforming %2 %3 has non-concurrent-value type %4",
4332+
(bool, DeclName, DescriptiveDeclKind, DeclName, Type))
43264333
ERROR(concurrent_value_class_mutable_property,none,
43274334
"stored property %0 of 'ConcurrentValue'-conforming %1 %2 is mutable",
43284335
(DeclName, DescriptiveDeclKind, DeclName))
4336+
WARNING(concurrent_value_class_mutable_property_warn,none,
4337+
"stored property %0 of 'ConcurrentValue'-conforming %1 %2 is mutable",
4338+
(DeclName, DescriptiveDeclKind, DeclName))
43294339
ERROR(concurrent_value_outside_source_file,none,
4330-
"conformance 'ConcurrentValue' must occur in the same source file as "
4340+
"conformance to 'ConcurrentValue' must occur in the same source file as "
4341+
"%0 %1; use 'UnsafeConcurrentValue' for retroactive conformance",
4342+
(DescriptiveDeclKind, DeclName))
4343+
WARNING(concurrent_value_outside_source_file_warn,none,
4344+
"conformance to 'ConcurrentValue' must occur in the same source file as "
43314345
"%0 %1; use 'UnsafeConcurrentValue' for retroactive conformance",
43324346
(DescriptiveDeclKind, DeclName))
43334347
ERROR(concurrent_value_open_class,none,
43344348
"open class %0 cannot conform to `ConcurrentValue`; "
43354349
"use `UnsafeConcurrentValue`", (DeclName))
4350+
WARNING(concurrent_value_open_class_warn,none,
4351+
"open class %0 cannot conform to `ConcurrentValue`; "
4352+
"use `UnsafeConcurrentValue`", (DeclName))
43364353
ERROR(concurrent_value_inherit,none,
43374354
"`ConcurrentValue` class %1 cannot inherit from another class"
43384355
"%select{| other than 'NSObject'}0",
43394356
(bool, DeclName))
4357+
WARNING(concurrent_value_inherit_warn,none,
4358+
"`ConcurrentValue` class %1 cannot inherit from another class"
4359+
"%select{| other than 'NSObject'}0",
4360+
(bool, DeclName))
43404361

43414362
ERROR(actorindependent_let,none,
43424363
"'@actorIndependent' is meaningless on 'let' declarations because "
@@ -5625,8 +5646,12 @@ ERROR(marker_protocol_requirement, none,
56255646
ERROR(marker_protocol_inherit_nonmarker, none,
56265647
"marker protocol %0 cannot inherit non-marker protocol %1",
56275648
(DeclName, DeclName))
5628-
ERROR(marker_protocol_value,none,
5629-
"marker protocol %0 can only be used in generic constraints", (DeclName))
5649+
ERROR(marker_protocol_cast,none,
5650+
"marker protocol %0 cannot be used in a conditional cast", (DeclName))
5651+
ERROR(marker_protocol_conditional_conformance,none,
5652+
"conditional conformance to non-marker protocol %0 cannot depend on "
5653+
"conformance of %1 to non-marker protocol %2",
5654+
(Identifier, Type, Identifier))
56305655

56315656
//------------------------------------------------------------------------------
56325657
// MARK: differentiable programming diagnostics

include/swift/AST/FineGrainedDependencies.h

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef SWIFT_AST_FINE_GRAINED_DEPENDENCIES_H
1414
#define SWIFT_AST_FINE_GRAINED_DEPENDENCIES_H
1515

16+
#include "swift/AST/EvaluatorDependencies.h"
1617
#include "swift/Basic/Debug.h"
1718
#include "swift/Basic/Fingerprint.h"
1819
#include "swift/Basic/LLVM.h"
@@ -57,11 +58,14 @@
5758
//==============================================================================
5859

5960
namespace swift {
61+
class Decl;
6062
class DependencyTracker;
6163
class DiagnosticEngine;
6264
class FrontendOptions;
6365
class ModuleDecl;
6466
class SourceFile;
67+
class NominalTypeDecl;
68+
class ValueDecl;
6569

6670
/// Use a new namespace to help keep the experimental code from clashing.
6771
namespace fine_grained_dependencies {
@@ -417,6 +421,57 @@ class DependencyKey {
417421
// For import/export
418422
friend ::llvm::yaml::MappingTraits<DependencyKey>;
419423

424+
public:
425+
class Builder {
426+
private:
427+
const NodeKind kind;
428+
const DeclAspect aspect;
429+
const NominalTypeDecl *context;
430+
StringRef name;
431+
432+
private:
433+
// A private copy constructor so our clients are forced to use the
434+
// move-only builder interface.
435+
explicit Builder(NodeKind kind, DeclAspect aspect,
436+
const NominalTypeDecl *context, StringRef name)
437+
: kind(kind), aspect(aspect), context(context), name(name) {}
438+
439+
public:
440+
/// Creates a DependencyKey::Builder from the given \p kind and \p aspect
441+
/// with a \c null context and empty name.
442+
explicit Builder(NodeKind kind, DeclAspect aspect)
443+
: kind(kind), aspect(aspect), context(nullptr), name("") {}
444+
445+
public:
446+
/// Consumes this builder and returns a dependency key created from its
447+
/// data.
448+
DependencyKey build() &&;
449+
450+
public:
451+
/// Extracts the data from the given \p ref into a this builder.
452+
Builder fromReference(const evaluator::DependencyCollector::Reference &ref);
453+
454+
public:
455+
/// Extracts the context data from the given declaration, if any.
456+
Builder withContext(const Decl *D) &&;
457+
/// Extracts the context data from the given decl-member pair, if any.
458+
Builder withContext(std::pair<const NominalTypeDecl *, const ValueDecl *>
459+
holderAndMember) &&;
460+
461+
public:
462+
/// Copies the name data for the given swiftdeps file into this builder.
463+
Builder withName(StringRef swiftDeps) &&;
464+
/// Copies the name of the given declaration into this builder, if any.
465+
Builder withName(const Decl *decl) &&;
466+
/// Extracts the name from the given decl-member pair, if any.
467+
Builder withName(std::pair<const NominalTypeDecl *, const ValueDecl *>
468+
holderAndMember) &&;
469+
470+
private:
471+
static StringRef getTopLevelName(const Decl *decl);
472+
};
473+
474+
private:
420475
NodeKind kind;
421476
DeclAspect aspect;
422477
/// The mangled context type name of the holder for \ref potentialMember, \ref
@@ -485,10 +540,6 @@ class DependencyKey {
485540
template <NodeKind kind, typename Entity>
486541
static DependencyKey createForProvidedEntityInterface(Entity);
487542

488-
/// Given some type of provided entity compute the context field of the key.
489-
template <NodeKind kind, typename Entity>
490-
static std::string computeContextForProvidedEntity(Entity);
491-
492543
DependencyKey correspondingImplementation() const {
493544
return withAspect(DeclAspect::implementation);
494545
}
@@ -497,10 +548,6 @@ class DependencyKey {
497548
return DependencyKey(kind, aspect, context, name);
498549
}
499550

500-
/// Given some type of provided entity compute the name field of the key.
501-
template <NodeKind kind, typename Entity>
502-
static std::string computeNameForProvidedEntity(Entity);
503-
504551
static DependencyKey createKeyForWholeSourceFile(DeclAspect,
505552
StringRef swiftDeps);
506553

include/swift/AST/SILOptions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ class SILOptions {
8989
/// and go from OSSA to non-ownership SIL.
9090
bool StopOptimizationBeforeLoweringOwnership = false;
9191

92+
/// Do we always serialize SIL in OSSA form?
93+
///
94+
/// If this is disabled we do not serialize in OSSA form when optimizing.
95+
bool EnableOSSAModules = false;
96+
9297
// The kind of function bodies to skip emitting.
9398
FunctionBodySkipping SkipFunctionBodies = FunctionBodySkipping::None;
9499

0 commit comments

Comments
 (0)