Skip to content

Commit 0134a1d

Browse files
authored
Merge branch 'release/6.0' into async-sequence-fixes-6.0
2 parents de0288a + a2a80f3 commit 0134a1d

File tree

83 files changed

+1658
-456
lines changed

Some content is hidden

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

83 files changed

+1658
-456
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# For the release branch @apple/swift5-branch-managers needs to approve the changes
2-
* @apple/swift5-branch-managers
1+
# For the release branch @apple/swift-branch-managers needs to approve the changes
2+
* @apple/swift-branch-managers

include/swift/ABI/Executor.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,12 @@ class SerialExecutorRef {
155155
return reinterpret_cast<DefaultActor*>(Identity);
156156
}
157157

158+
bool hasSerialExecutorWitnessTable() const {
159+
return !isGeneric() && !isDefaultActor();
160+
}
161+
158162
const SerialExecutorWitnessTable *getSerialExecutorWitnessTable() const {
159-
assert(!isGeneric() && !isDefaultActor());
163+
assert(hasSerialExecutorWitnessTable());
160164
auto table = Implementation & WitnessTableMask;
161165
return reinterpret_cast<const SerialExecutorWitnessTable*>(table);
162166
}

include/swift/AST/Decl.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,6 +1864,32 @@ class ExtensionDecl final : public GenericContext, public Decl,
18641864
/// the original nominal type context.
18651865
bool isInSameDefiningModule() const;
18661866

1867+
/// Determine whether this extension is equivalent to one that requires at
1868+
/// at least some constraints to be written in the source.
1869+
///
1870+
/// This result will differ from `isConstrainedExtension()` when any of
1871+
/// the generic parameters of the type are invertible, e.g.,
1872+
/// \code
1873+
/// struct X<T: ~Copyable>: ~Copyable { }
1874+
///
1875+
/// // Implies `T: Copyable`. This extension `!isWrittenWithConstraints()`
1876+
/// // and `isConstrainedExtension()`.
1877+
/// extension X { }
1878+
///
1879+
/// // This extension `isWrittenWithConstraints()`
1880+
/// // and `!isConstrainedExtension()`.
1881+
/// extension X where T: ~Copyable { }
1882+
///
1883+
/// // Implies `T: Copyable`. This extension `isWrittenWithConstraints()`
1884+
/// // and `isConstrainedExtension()`.
1885+
/// extension X where T: P { }
1886+
///
1887+
/// // This extension `isWrittenWithConstraints()`
1888+
/// // and `isConstrainedExtension()`.
1889+
/// extension X where T: Q, T: ~Copyable { }
1890+
/// \endcode
1891+
bool isWrittenWithConstraints() const;
1892+
18671893
/// Returns the name of the category specified by the \c \@_objcImplementation
18681894
/// attribute, or \c None if the name is invalid or
18691895
/// \c isObjCImplementation() is false.

include/swift/AST/DiagnosticsSema.def

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7833,25 +7833,31 @@ ERROR(lifetime_dependence_invalid_param_name, none,
78337833
"invalid parameter name specified %0", (Identifier))
78347834
ERROR(lifetime_dependence_invalid_param_index, none,
78357835
"invalid parameter index specified %0", (unsigned))
7836-
ERROR(lifetime_dependence_invalid_self, none,
7837-
"invalid lifetime dependence specifier, self is valid in non-static "
7838-
"methods only", ())
7836+
ERROR(lifetime_dependence_invalid_self_in_static, none,
7837+
"invalid lifetime dependence specifier on non-existent self", ())
7838+
ERROR(lifetime_dependence_invalid_self_in_init, none,
7839+
"invalid lifetime dependence on self in an initializer", ())
78397840
ERROR(lifetime_dependence_duplicate_param_id, none,
78407841
"duplicate lifetime dependence specifier", ())
78417842
ERROR(lifetime_dependence_cannot_use_kind, none,
78427843
"invalid use of %0 lifetime dependence for %1 ownership",
78437844
(StringRef, StringRef))
7845+
ERROR(lifetime_dependence_cannot_use_parsed_scoped_consuming, none,
7846+
"invalid use of scoped lifetime dependence with consuming ownership",
7847+
())
7848+
ERROR(lifetime_dependence_cannot_use_inferred_scoped_consuming, none,
7849+
"invalid use of lifetime dependence on an Escapable parameter with "
7850+
"consuming ownership",
7851+
())
7852+
ERROR(lifetime_dependence_invalid_self_ownership, none,
7853+
"invalid scoped lifetime dependence on an Escapable self with consuming "
7854+
"ownership",
7855+
())
78447856
ERROR(lifetime_dependence_only_on_function_method_init_result, none,
78457857
"lifetime dependence specifiers may only be used on result of "
78467858
"functions, methods, initializers", ())
78477859
ERROR(lifetime_dependence_invalid_return_type, none,
78487860
"lifetime dependence can only be specified on ~Escapable results", ())
7849-
ERROR(lifetime_dependence_missing_ownership_modifier, none,
7850-
"lifetime dependence can only be specified on parameters with ownership "
7851-
"modifiers (borrowing, consuming, inout)", ())
7852-
ERROR(lifetime_dependence_cannot_infer_wo_ownership_modifier_on_method, none,
7853-
"cannot infer lifetime dependence, specify ownership modifier for the "
7854-
"method", ())
78557861
ERROR(lifetime_dependence_cannot_infer_ambiguous_candidate, none,
78567862
"cannot infer lifetime dependence, multiple ~Escapable or ~Copyable "
78577863
"parameters with ownership modifiers, specify explicit lifetime "
@@ -7862,9 +7868,6 @@ ERROR(lifetime_dependence_cannot_infer_no_candidates, none,
78627868
ERROR(lifetime_dependence_ctor_non_self_or_nil_return, none,
78637869
"expected nil or self as return values in an initializer with "
78647870
"lifetime dependent specifiers", ())
7865-
ERROR(lifetime_dependence_cannot_use_infer, none,
7866-
"invalid use of %0 lifetime dependence on Escapable type",
7867-
(StringRef))
78687871
ERROR(lifetime_dependence_on_bitwise_copyable, none,
78697872
"invalid lifetime dependence on bitwise copyable type", ())
78707873
ERROR(lifetime_dependence_cannot_infer_implicit_init, none,

include/swift/AST/LifetimeDependence.h

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,22 @@ class AbstractFunctionDecl;
3232
class LifetimeDependentReturnTypeRepr;
3333
class SILParameterInfo;
3434

35-
enum class LifetimeDependenceKind : uint8_t {
36-
Copy = 0,
37-
Consume,
38-
Borrow,
39-
Mutate
35+
enum class ParsedLifetimeDependenceKind : uint8_t {
36+
Default = 0,
37+
Scope,
38+
Inherit // Only used with deserialized decls
4039
};
4140

41+
enum class LifetimeDependenceKind : uint8_t { Inherit = 0, Scope };
42+
4243
class LifetimeDependenceSpecifier {
4344
public:
4445
enum class SpecifierKind { Named, Ordered, Self };
4546

4647
private:
4748
SourceLoc loc;
4849
SpecifierKind specifierKind;
49-
LifetimeDependenceKind lifetimeDependenceKind;
50+
ParsedLifetimeDependenceKind parsedLifetimeDependenceKind;
5051
union Value {
5152
struct {
5253
Identifier name;
@@ -61,35 +62,36 @@ class LifetimeDependenceSpecifier {
6162
Value() {}
6263
} value;
6364

64-
LifetimeDependenceSpecifier(SourceLoc loc, SpecifierKind specifierKind,
65-
LifetimeDependenceKind lifetimeDependenceKind,
66-
Value value)
65+
LifetimeDependenceSpecifier(
66+
SourceLoc loc, SpecifierKind specifierKind,
67+
ParsedLifetimeDependenceKind parsedLifetimeDependenceKind, Value value)
6768
: loc(loc), specifierKind(specifierKind),
68-
lifetimeDependenceKind(lifetimeDependenceKind), value(value) {}
69+
parsedLifetimeDependenceKind(parsedLifetimeDependenceKind),
70+
value(value) {}
6971

7072
public:
7173
static LifetimeDependenceSpecifier getNamedLifetimeDependenceSpecifier(
72-
SourceLoc loc, LifetimeDependenceKind kind, Identifier name) {
74+
SourceLoc loc, ParsedLifetimeDependenceKind kind, Identifier name) {
7375
return {loc, SpecifierKind::Named, kind, name};
7476
}
7577

7678
static LifetimeDependenceSpecifier getOrderedLifetimeDependenceSpecifier(
77-
SourceLoc loc, LifetimeDependenceKind kind, unsigned index) {
79+
SourceLoc loc, ParsedLifetimeDependenceKind kind, unsigned index) {
7880
return {loc, SpecifierKind::Ordered, kind, index};
7981
}
8082

8183
static LifetimeDependenceSpecifier
8284
getSelfLifetimeDependenceSpecifier(SourceLoc loc,
83-
LifetimeDependenceKind kind) {
85+
ParsedLifetimeDependenceKind kind) {
8486
return {loc, SpecifierKind::Self, kind, {}};
8587
}
8688

8789
SourceLoc getLoc() const { return loc; }
8890

8991
SpecifierKind getSpecifierKind() const { return specifierKind; }
9092

91-
LifetimeDependenceKind getLifetimeDependenceKind() const {
92-
return lifetimeDependenceKind;
93+
ParsedLifetimeDependenceKind getParsedLifetimeDependenceKind() const {
94+
return parsedLifetimeDependenceKind;
9395
}
9496

9597
Identifier getName() const {
@@ -114,19 +116,17 @@ class LifetimeDependenceSpecifier {
114116
llvm_unreachable("Invalid LifetimeDependenceSpecifier::SpecifierKind");
115117
}
116118

117-
StringRef getLifetimeDependenceKindString() const {
118-
switch (lifetimeDependenceKind) {
119-
case LifetimeDependenceKind::Borrow:
120-
return "_borrow";
121-
case LifetimeDependenceKind::Consume:
122-
return "_consume";
123-
case LifetimeDependenceKind::Copy:
124-
return "_copy";
125-
case LifetimeDependenceKind::Mutate:
126-
return "_mutate";
119+
std::string getLifetimeDependenceSpecifierString() const {
120+
switch (parsedLifetimeDependenceKind) {
121+
case ParsedLifetimeDependenceKind::Default:
122+
return "dependsOn(" + getParamString() + ")";
123+
case ParsedLifetimeDependenceKind::Scope:
124+
return "dependsOn(scoped " + getParamString() + ")";
125+
case ParsedLifetimeDependenceKind::Inherit:
126+
return "dependsOn(inherited " + getParamString() + ")";
127127
}
128128
llvm_unreachable(
129-
"Invalid LifetimeDependenceSpecifier::LifetimeDependenceKind");
129+
"Invalid LifetimeDependenceSpecifier::ParsedLifetimeDependenceKind");
130130
}
131131
};
132132

@@ -137,7 +137,7 @@ class LifetimeDependenceInfo {
137137

138138
static LifetimeDependenceInfo getForParamIndex(AbstractFunctionDecl *afd,
139139
unsigned index,
140-
ValueOwnership ownership);
140+
LifetimeDependenceKind kind);
141141

142142
public:
143143
LifetimeDependenceInfo()

include/swift/Basic/LangOptions.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,14 @@ namespace swift {
593593
/// type-checking, SIL verification, and IR emission,
594594
bool BypassResilienceChecks = false;
595595

596+
/// Whether or not to allow experimental features that are only available
597+
/// in "production".
598+
#ifdef NDEBUG
599+
bool RestrictNonProductionExperimentalFeatures = true;
600+
#else
601+
bool RestrictNonProductionExperimentalFeatures = false;
602+
#endif
603+
596604
bool isConcurrencyModelTaskToThread() const {
597605
return ActiveConcurrencyModel == ConcurrencyModel::TaskToThread;
598606
}

include/swift/Parse/Parser.h

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,7 @@ class Parser {
12131213
return true;
12141214
if (Context.LangOpts.hasFeature(Feature::NonescapableTypes) &&
12151215
(Tok.isContextualKeyword("_resultDependsOn") ||
1216-
Tok.isLifetimeDependenceToken(isInSILMode())))
1216+
isLifetimeDependenceToken()))
12171217
return true;
12181218
return false;
12191219
}
@@ -1225,23 +1225,26 @@ class Parser {
12251225
consumeToken();
12261226
}
12271227

1228+
bool isLifetimeDependenceToken() {
1229+
if (!isInSILMode()) {
1230+
return Tok.isContextualKeyword("dependsOn");
1231+
}
1232+
return Tok.isContextualKeyword("_inherit") ||
1233+
Tok.isContextualKeyword("_scope");
1234+
}
1235+
12281236
bool canHaveParameterSpecifierContextualKeyword() {
12291237
// The parameter specifiers like `isolated`, `consuming`, `borrowing` are
12301238
// also valid identifiers and could be the name of a type. Check whether
12311239
// the following token is something that can introduce a type. Thankfully
12321240
// none of these tokens overlap with the set of tokens that can follow an
12331241
// identifier in a type production.
1234-
return Tok.is(tok::identifier)
1235-
&& peekToken().isAny(tok::at_sign,
1236-
tok::kw_inout,
1237-
tok::l_paren,
1238-
tok::identifier,
1239-
tok::l_square,
1240-
tok::kw_Any,
1241-
tok::kw_Self,
1242-
tok::kw__,
1243-
tok::kw_var,
1244-
tok::kw_let);
1242+
return (Tok.is(tok::identifier) &&
1243+
peekToken().isAny(tok::at_sign, tok::kw_inout, tok::l_paren,
1244+
tok::identifier, tok::l_square, tok::kw_Any,
1245+
tok::kw_Self, tok::kw__, tok::kw_var,
1246+
tok::kw_let)) ||
1247+
isLifetimeDependenceToken();
12451248
}
12461249

12471250
struct ParsedTypeAttributeList {

include/swift/Parse/Token.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -267,16 +267,6 @@ class Token {
267267
return MultilineString;
268268
}
269269

270-
bool isLifetimeDependenceToken(bool isInSILMode) const {
271-
return isContextualKeyword("_copy") || isContextualKeyword("_consume") ||
272-
isContextualKeyword("_borrow") || isContextualKeyword("_mutate") ||
273-
// SIL tests are currently written with _inherit/_scope
274-
// Once we have dependsOn()/dependsOn(borrowed:) other tokens go
275-
// away.
276-
(isInSILMode &&
277-
(isContextualKeyword("_inherit") || isContextualKeyword("_scope")));
278-
}
279-
280270
/// Count of extending escaping '#'.
281271
unsigned getCustomDelimiterLen() const {
282272
return CustomDelimiterLen;

include/swift/Runtime/Bincompat.h

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -47,6 +47,38 @@ bool useLegacySwiftValueUnboxingInCasting();
4747
/// if present.
4848
bool useLegacySwiftObjCHashing();
4949

50+
/// Legacy semantics allowed for the `swift_task_reportUnexpectedExecutor` to
51+
/// only log a warning. This changes in future releases and this function
52+
/// will fatal error always.
53+
///
54+
/// Similarly, the internal runtime function
55+
/// `swift_task_isCurrentExecutor(expected)` was previously allowed to return
56+
/// `false`. In future releases it will call into `checkIsolated`, and CRASH
57+
/// when previously it would have returned false.
58+
///
59+
/// Because some applications were running with "isolation warnings" and
60+
/// those call into the `isCurrentExecutor` API and expected warnings to be
61+
/// logged, but they ignored those warnings we cannot make them crashing,
62+
/// and must check if the app was built against a new.
63+
///
64+
/// Old behavior:
65+
/// - `swift_task_isCurrentExecutorImpl` cannot crash and does NOT invoke
66+
/// `SerialExecutor.checkIsolated`
67+
/// - `swift_task_isCurrentExecutorImpl` does not invoke `checkIsolated`
68+
/// - logging a warning on concurrency violation is allowed
69+
///
70+
/// New behavior:
71+
/// - always fatal error in `swift_task_reportUnexpectedExecutor`
72+
/// - `swift_task_isCurrentExecutorImpl` will crash when it would have returned
73+
/// false
74+
/// - `swift_task_isCurrentExecutorImpl` does invoke `checkIsolated` when other
75+
/// checks failed
76+
///
77+
/// This can be overridden by using `SWIFT_UNEXPECTED_EXECUTOR_LOG_LEVEL=1`
78+
/// or `SWIFT_IS_CURRENT_EXECUTOR_LEGACY_MODE_OVERRIDE=crash|nocrash`
79+
SWIFT_RUNTIME_STDLIB_SPI
80+
bool swift_bincompat_useLegacyNonCrashingExecutorChecks();
81+
5082
} // namespace bincompat
5183

5284
} // namespace runtime

include/swift/Runtime/Concurrency.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,11 @@ void swift_task_enqueue(Job *job, SerialExecutorRef executor);
715715
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
716716
void swift_task_enqueueGlobal(Job *job);
717717

718+
/// Invoke an executor's `checkIsolated` or otherwise equivalent API,
719+
/// that will crash if the current executor is NOT the passed executor.
720+
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
721+
void swift_task_checkIsolated(SerialExecutorRef executor);
722+
718723
/// A count in nanoseconds.
719724
using JobDelay = unsigned long long;
720725

@@ -729,6 +734,9 @@ void swift_task_enqueueGlobalWithDeadline(long long sec, long long nsec,
729734
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
730735
void swift_task_enqueueMainExecutor(Job *job);
731736

737+
/// WARNING: This method is expected to CRASH when caller is not on the
738+
/// expected executor.
739+
///
732740
/// Return true if the caller is running in a Task on the passed Executor.
733741
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
734742
bool swift_task_isOnExecutor(
@@ -781,6 +789,12 @@ SWIFT_CC(swift) void (*swift_task_enqueueGlobalWithDeadline_hook)(
781789
int clock, Job *job,
782790
swift_task_enqueueGlobalWithDeadline_original original);
783791

792+
typedef SWIFT_CC(swift) void (*swift_task_checkIsolated_original)(SerialExecutorRef executor);
793+
SWIFT_EXPORT_FROM(swift_Concurrency)
794+
SWIFT_CC(swift) void (*swift_task_checkIsolated_hook)(
795+
SerialExecutorRef executor, swift_task_checkIsolated_original original);
796+
797+
784798
typedef SWIFT_CC(swift) bool (*swift_task_isOnExecutor_original)(
785799
HeapObject *executor,
786800
const Metadata *selfType,

lib/AST/ASTDemangler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,9 @@ ASTBuilder::findDeclContext(NodePointer node) {
12981298
continue;
12991299
}
13001300

1301+
if (!ext->isWrittenWithConstraints() && !genericSig)
1302+
return ext;
1303+
13011304
auto extSig = ext->getGenericSignature().getCanonicalSignature();
13021305
if (extSig == genericSig) {
13031306
return ext;

lib/AST/ASTDumper.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3535,8 +3535,7 @@ class PrintTypeRepr : public TypeReprVisitor<PrintTypeRepr, void, StringRef>,
35353535
for (auto &dep : T->getLifetimeDependencies()) {
35363536
printFieldRaw(
35373537
[&](raw_ostream &out) {
3538-
out << dep.getLifetimeDependenceKindString() << "(";
3539-
out << dep.getParamString() << ")";
3538+
out << " " << dep.getLifetimeDependenceSpecifierString() << " ";
35403539
},
35413540
"");
35423541
}

0 commit comments

Comments
 (0)