Skip to content

Commit 6e525d7

Browse files
committed
Merge branch 'main' into wip-no-escape-group
2 parents 22283d9 + 16d3f78 commit 6e525d7

File tree

86 files changed

+6162
-625
lines changed

Some content is hidden

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

86 files changed

+6162
-625
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ option(USE_SWIFT_ASYNC_LOWERING
201201
functions if it is supported for the target. The runtime also checks
202202
this setting before using async-specific attributes. This only applies
203203
to the async calling convention and not to the async context attribute."
204-
FALSE)
204+
TRUE)
205205

206206
#
207207
# User-configurable Swift Standard Library specific options.

benchmark/single-source/Substring.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public let SubstringTest = [
2929
BenchmarkInfo(name: "SubstringEquatable", runFunction: run_SubstringEquatable, tags: [.validation, .api, .String]),
3030
BenchmarkInfo(name: "SubstringFromLongString", runFunction: run_SubstringFromLongString, tags: [.validation, .api, .String]),
3131
BenchmarkInfo(name: "SubstringFromLongStringGeneric", runFunction: run_SubstringFromLongStringGeneric, tags: [.validation, .api, .String]),
32+
BenchmarkInfo(name: "SubstringTrimmingASCIIWhitespace", runFunction: run_SubstringTrimmingASCIIWhitespace, tags: [.validation, .api, .String]),
3233
]
3334

3435
// A string that doesn't fit in small string storage and doesn't fit in Latin-1
@@ -267,6 +268,38 @@ public func run_SubstringComparable(_ N: Int) {
267268
CheckResults(count == N*500)
268269
}
269270

271+
extension Character {
272+
fileprivate var isASCIIWhitespace: Bool {
273+
return self == " " || self == "\t" || self == "\r" || self == "\n" || self == "\r\n"
274+
}
275+
}
276+
277+
extension Substring {
278+
fileprivate func trimWhitespace() -> Substring {
279+
var me = self
280+
while me.first?.isASCIIWhitespace == .some(true) {
281+
me = me.dropFirst()
282+
}
283+
while me.last?.isASCIIWhitespace == .some(true) {
284+
me = me.dropLast()
285+
}
286+
return me
287+
}
288+
}
289+
290+
let _trimmableSubstrings = "pineapple,🍍, pineapple\t,\r\n\r\n\r\n, 🍍 ,".split(separator: ",")
291+
292+
@inline(never)
293+
public func run_SubstringTrimmingASCIIWhitespace(_ N: Int) {
294+
let substrings = _trimmableSubstrings // bringing this alias from above
295+
var count = 0
296+
for _ in 1...N*100 {
297+
for substring in substrings {
298+
blackHole(substring.trimWhitespace())
299+
}
300+
}
301+
}
302+
270303
/*
271304
func checkLess<T, U>(_ x: T, _ y: U)
272305
where T : StringProtocol, U : StringProtocol {

docs/SIL.rst

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3540,43 +3540,57 @@ load_borrow
35403540
%1 = load_borrow %0 : $*T
35413541
// $T must be a loadable type
35423542

3543-
Loads the value ``%1`` from the memory location ``%0``. The ``load_borrow``
3543+
Loads the value ``%1`` from the memory location ``%0``. The `load_borrow`_
35443544
instruction creates a borrowed scope in which a read-only borrow value ``%1``
35453545
can be used to read the value stored in ``%0``. The end of scope is delimited
3546-
by an ``end_borrow`` instruction. All ``load_borrow`` instructions must be
3547-
paired with exactly one ``end_borrow`` instruction along any path through the
3548-
program. Until ``end_borrow``, it is illegal to invalidate or store to ``%0``.
3546+
by an `end_borrow`_ instruction. All `load_borrow`_ instructions must be
3547+
paired with exactly one `end_borrow`_ instruction along any path through the
3548+
program. Until `end_borrow`_, it is illegal to invalidate or store to ``%0``.
35493549

35503550
begin_borrow
35513551
````````````
35523552

3553-
TODO
3553+
::
3554+
3555+
sil-instruction ::= 'begin_borrow' sil-operand
3556+
3557+
%1 = begin_borrow %0 : $T
3558+
3559+
Given a value ``%0`` with `Owned`_ or `Guaranteed`_ ownership, produces a new
3560+
same typed value with `Guaranteed`_ ownership: ``%1``. ``%1`` is guaranteed to
3561+
have a lifetime ending use (e.x.: `end_borrow`_) along all paths that do not end
3562+
in `Dead End Blocks`_. This `begin_borrow`_ and the lifetime ending uses of
3563+
``%1`` are considered to be liveness requiring uses of ``%0`` and as such in the
3564+
region in between this borrow and its lifetime ending use, ``%0`` must be
3565+
live. This makes sense semantically since ``%1`` is modeling a new value with a
3566+
dependent lifetime on ``%0``.
3567+
3568+
This instruction is only valid in functions in Ownership SSA form.
35543569

35553570
end_borrow
35563571
``````````
35573572

35583573
::
35593574

3560-
sil-instruction ::= 'end_borrow' sil-value 'from' sil-value : sil-type, sil-type
3575+
sil-instruction ::= 'end_borrow' sil-operand
35613576

3562-
end_borrow %1 from %0 : $T, $T
3563-
end_borrow %1 from %0 : $T, $*T
3564-
end_borrow %1 from %0 : $*T, $T
3565-
end_borrow %1 from %0 : $*T, $*T
3566-
// We allow for end_borrow to be specified in between values and addresses
3567-
// all of the same type T.
3577+
// somewhere earlier
3578+
// %1 = begin_borrow %0
3579+
end_borrow %1 : $T
35683580

3569-
Ends the scope for which the SILValue ``%1`` is borrowed from the SILValue
3570-
``%0``. Must be paired with at most 1 borrowing instruction (like
3571-
``load_borrow``) along any path through the program. In the region in between
3572-
the borrow instruction and the ``end_borrow``, the original SILValue can not be
3573-
modified. This means that:
3581+
Ends the scope for which the `Guaranteed`_ ownership possessing SILValue ``%1``
3582+
is borrowed from the SILValue ``%0``. Must be paired with at most 1 borrowing
3583+
instruction (like `load_borrow`_, `begin_borrow`_) along any path through the
3584+
program. In the region in between the borrow instruction and the `end_borrow`_,
3585+
the original SILValue can not be modified. This means that:
35743586

35753587
1. If ``%0`` is an address, ``%0`` can not be written to.
35763588
2. If ``%0`` is a non-trivial value, ``%0`` can not be destroyed.
35773589

35783590
We require that ``%1`` and ``%0`` have the same type ignoring SILValueCategory.
35793591

3592+
This instruction is only valid in functions in Ownership SSA form.
3593+
35803594
assign
35813595
``````
35823596
::
@@ -3592,12 +3606,12 @@ The type of %1 is ``*T`` and the type of ``%0`` is ``T``, which must be a
35923606
loadable type. This will overwrite the memory at ``%1`` and destroy the value
35933607
currently held there.
35943608

3595-
The purpose of the ``assign`` instruction is to simplify the
3609+
The purpose of the `assign`_ instruction is to simplify the
35963610
definitive initialization analysis on loadable variables by removing
35973611
what would otherwise appear to be a load and use of the current value.
35983612
It is produced by SILGen, which cannot know which assignments are
35993613
meant to be initializations. If it is deemed to be an initialization,
3600-
it can be replaced with a ``store``; otherwise, it must be replaced
3614+
it can be replaced with a `store`_; otherwise, it must be replaced
36013615
with a sequence that also correctly destroys the current value.
36023616

36033617
This instruction is only valid in Raw SIL and is rewritten as appropriate
@@ -3615,7 +3629,7 @@ assign_by_wrapper
36153629
// $F must be a function type, taking $S as a single argument (or multiple arguments in case of a tuple) and returning $T
36163630
// $G must be a function type, taking $S as a single argument (or multiple arguments in case of a tuple) and without a return value
36173631

3618-
Similar to the ``assign`` instruction, but the assignment is done via a
3632+
Similar to the `assign`_ instruction, but the assignment is done via a
36193633
delegate.
36203634

36213635
In case of an initialization, the function ``%2`` is called with ``%0`` as
@@ -4245,7 +4259,9 @@ object. Returns 1 if the strong reference count is 1, and 0 if the
42454259
strong reference count is greater than 1.
42464260

42474261
A discussion of the semantics can be found here:
4248-
:ref:`arcopts.is_unique`.
4262+
`is_unique instruction <arcopts_is_unique_>`_
4263+
4264+
.. _arcopts_is_unique: https://github.com/apple/swift/blob/main/docs/ARCOptimization.md#is_unique-instruction
42494265

42504266
begin_cow_mutation
42514267
``````````````````

include/swift/AST/DiagnosticsParse.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ ERROR(computed_property_no_accessors, none,
248248
"%select{computed property|subscript}0 must have accessors specified", (bool))
249249
ERROR(expected_getset_in_protocol,none,
250250
"expected get or set in a protocol property", ())
251+
ERROR(unexpected_getset_implementation_in_protocol,none,
252+
"protocol property %0 cannot have a default implementation specified here; use extension instead", (StringRef))
251253
ERROR(computed_property_missing_type,none,
252254
"computed property must have an explicit type", ())
253255
ERROR(getset_nontrivial_pattern,none,

include/swift/AST/DiagnosticsSema.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,6 +1902,12 @@ ERROR(type_does_not_conform_owner,none,
19021902
ERROR(type_does_not_conform_in_decl_ref,none,
19031903
"referencing %0 %1 on %2 requires that %3 conform to %4",
19041904
(DescriptiveDeclKind, DeclName, Type, Type, Type))
1905+
ERROR(contextual_member_ref_on_protocol_requires_self_requirement,none,
1906+
"contextual member reference to %0 %1 requires "
1907+
"'Self' constraint in the protocol extension",
1908+
(DescriptiveDeclKind, DeclName))
1909+
NOTE(missing_sametype_requirement_on_self,none,
1910+
"missing same-type requirement on 'Self'", ())
19051911
ERROR(type_does_not_conform_anyobject_in_decl_ref,none,
19061912
"referencing %0 %1 on %2 requires that %3 be a class type",
19071913
(DescriptiveDeclKind, DeclName, Type, Type, Type))

include/swift/AST/GenericSignature.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,6 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
234234
mutable llvm::PointerUnion<const GenericSignatureImpl *, ASTContext *>
235235
CanonicalSignatureOrASTContext;
236236

237-
void buildConformanceAccessPath(
238-
SmallVectorImpl<ConformanceAccessPath::Entry> &path,
239-
ArrayRef<Requirement> reqs,
240-
const void /*GenericSignatureBuilder::RequirementSource*/ *source,
241-
ProtocolDecl *conformingProto, Type rootType,
242-
ProtocolDecl *requirementSignatureProto) const;
243-
244237
friend class ArchetypeType;
245238

246239
public:

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,6 @@ class GenericSignatureBuilder {
626626
/// After this point, one cannot introduce new requirements, and the
627627
/// generic signature builder no longer has valid state.
628628
GenericSignature computeGenericSignature(
629-
SourceLoc loc,
630629
bool allowConcreteGenericParams = false,
631630
bool allowBuilderToMove = true) &&;
632631

@@ -639,8 +638,7 @@ class GenericSignatureBuilder {
639638
///
640639
/// \param allowConcreteGenericParams If true, allow generic parameters to
641640
/// be made concrete.
642-
void finalize(SourceLoc loc,
643-
TypeArrayView<GenericTypeParamType> genericParams,
641+
void finalize(TypeArrayView<GenericTypeParamType> genericParams,
644642
bool allowConcreteGenericParams=false);
645643

646644
public:
@@ -923,10 +921,6 @@ class GenericSignatureBuilder::RequirementSource final
923921
/// Whether there is a trailing written requirement location.
924922
const bool hasTrailingWrittenRequirementLoc;
925923

926-
public:
927-
/// Whether a protocol requirement came from the requirement signature.
928-
const bool usesRequirementSignature;
929-
930924
private:
931925
/// The actual storage, described by \c storageKind.
932926
union {
@@ -1022,7 +1016,7 @@ class GenericSignatureBuilder::RequirementSource final
10221016
WrittenRequirementLoc writtenReqLoc)
10231017
: kind(kind), storageKind(StorageKind::StoredType),
10241018
hasTrailingWrittenRequirementLoc(!writtenReqLoc.isNull()),
1025-
usesRequirementSignature(false), parent(nullptr) {
1019+
parent(nullptr) {
10261020
assert(isAcceptableStorageKind(kind, storageKind) &&
10271021
"RequirementSource kind/storageKind mismatch");
10281022

@@ -1038,7 +1032,6 @@ class GenericSignatureBuilder::RequirementSource final
10381032
WrittenRequirementLoc writtenReqLoc)
10391033
: kind(kind), storageKind(StorageKind::StoredType),
10401034
hasTrailingWrittenRequirementLoc(!writtenReqLoc.isNull()),
1041-
usesRequirementSignature(!protocol->isComputingRequirementSignature()),
10421035
parent(parent) {
10431036
assert((static_cast<bool>(parent) != isRootKind(kind)) &&
10441037
"Root RequirementSource should not have parent (or vice versa)");
@@ -1055,8 +1048,7 @@ class GenericSignatureBuilder::RequirementSource final
10551048
RequirementSource(Kind kind, const RequirementSource *parent,
10561049
ProtocolConformanceRef conformance)
10571050
: kind(kind), storageKind(StorageKind::ProtocolConformance),
1058-
hasTrailingWrittenRequirementLoc(false),
1059-
usesRequirementSignature(false), parent(parent) {
1051+
hasTrailingWrittenRequirementLoc(false), parent(parent) {
10601052
assert((static_cast<bool>(parent) != isRootKind(kind)) &&
10611053
"Root RequirementSource should not have parent (or vice versa)");
10621054
assert(isAcceptableStorageKind(kind, storageKind) &&
@@ -1068,8 +1060,7 @@ class GenericSignatureBuilder::RequirementSource final
10681060
RequirementSource(Kind kind, const RequirementSource *parent,
10691061
AssociatedTypeDecl *assocType)
10701062
: kind(kind), storageKind(StorageKind::AssociatedTypeDecl),
1071-
hasTrailingWrittenRequirementLoc(false),
1072-
usesRequirementSignature(false), parent(parent) {
1063+
hasTrailingWrittenRequirementLoc(false), parent(parent) {
10731064
assert((static_cast<bool>(parent) != isRootKind(kind)) &&
10741065
"Root RequirementSource should not have parent (or vice versa)");
10751066
assert(isAcceptableStorageKind(kind, storageKind) &&
@@ -1080,8 +1071,7 @@ class GenericSignatureBuilder::RequirementSource final
10801071

10811072
RequirementSource(Kind kind, const RequirementSource *parent)
10821073
: kind(kind), storageKind(StorageKind::None),
1083-
hasTrailingWrittenRequirementLoc(false),
1084-
usesRequirementSignature(false), parent(parent) {
1074+
hasTrailingWrittenRequirementLoc(false), parent(parent) {
10851075
assert((static_cast<bool>(parent) != isRootKind(kind)) &&
10861076
"Root RequirementSource should not have parent (or vice versa)");
10871077
assert(isAcceptableStorageKind(kind, storageKind) &&
@@ -1091,8 +1081,7 @@ class GenericSignatureBuilder::RequirementSource final
10911081
RequirementSource(Kind kind, const RequirementSource *parent,
10921082
Type newType)
10931083
: kind(kind), storageKind(StorageKind::StoredType),
1094-
hasTrailingWrittenRequirementLoc(false),
1095-
usesRequirementSignature(false), parent(parent) {
1084+
hasTrailingWrittenRequirementLoc(false), parent(parent) {
10961085
assert((static_cast<bool>(parent) != isRootKind(kind)) &&
10971086
"Root RequirementSource should not have parent (or vice versa)");
10981087
assert(isAcceptableStorageKind(kind, storageKind) &&

include/swift/AST/RawComment.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ struct BasicDeclLocs {
9898

9999
struct BasicSourceFileInfo {
100100
StringRef FilePath;
101-
Fingerprint InterfaceHash = Fingerprint::ZERO();
101+
/// Used for completion; factors in hashes from type-bodies in order to be sensitive to changes in
102+
/// the intefaces of top-level type members.
103+
Fingerprint InterfaceHashIncludingTypeMembers = Fingerprint::ZERO();
102104
llvm::sys::TimePoint<> LastModified = {};
103105
uint64_t FileSize = 0;
104106

include/swift/Runtime/Concurrency.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ void swift_task_cancel(AsyncTask *task);
121121
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
122122
void swift_task_cancel_group_child_tasks(AsyncTask *task, TaskGroup *group);
123123

124+
/// Get 'active' AsyncTask, depending on platform this may use thread local storage.
125+
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
126+
AsyncTask* swift_task_get_active();
127+
124128
/// Escalate the priority of a task and all of its child tasks.
125129
///
126130
/// This can be called from any thread.

include/swift/SIL/SILInstruction.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,16 @@ class OwnershipForwardingMixin {
10251025
}
10261026

10271027
public:
1028+
/// Forwarding ownership is determined by the forwarding instruction's
1029+
/// constant ownership attribute. If forwarding ownership is owned, then the
1030+
/// instruction moves an owned operand to its result, ending its lifetime. If
1031+
/// forwarding ownership is guaranteed, then the instruction propagates the
1032+
/// lifetime of its borrows operand through its result.
1033+
///
1034+
/// The resulting forwarded value's ownership, returned by getOwnershipKind(),
1035+
/// is not identical to the forwarding ownership. It differs when the result
1036+
/// is trivial type. e.g. an owned or guaranteed value can be cast to a
1037+
/// trivial type using owned or guaranteed forwarding.
10281038
ValueOwnershipKind getForwardingOwnershipKind() const {
10291039
return ownershipKind;
10301040
}

0 commit comments

Comments
 (0)