Skip to content

Commit 6e1144d

Browse files
Merge pull request #4474 from swiftwasm/main
[pull] swiftwasm from main
2 parents da8d70b + f0e8fcb commit 6e1144d

File tree

432 files changed

+3109
-1640
lines changed

Some content is hidden

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

432 files changed

+3109
-1640
lines changed

CHANGELOG.md

Lines changed: 92 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,88 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
55

66
## Swift 5.7
77

8+
* References to `optional` methods on a protocol metatype, as well as references to dynamically looked up methods on the `AnyObject` metatype are now supported. These references always have the type of a function that accepts a single argument and returns an optional value of function type:
9+
10+
```swift
11+
class Object {
12+
@objc func getTag() -> Int
13+
}
14+
15+
@objc protocol P {
16+
@objc optional func didUpdateObject(withTag tag: Int)
17+
}
18+
19+
let getTag: (AnyObject) -> (() -> Int)? = AnyObject.getTag
20+
21+
let didUpdateObject: (any P) -> ((Int) -> Void)? = P.didUpdateObject
22+
```
23+
24+
* [SE-0349][]:
25+
26+
Loading data from raw memory represented by `UnsafeRawPointer`,
27+
`UnsafeRawBufferPointer` and their mutable counterparts now supports unaligned
28+
accesses. This previously required a workaround involving an intermediate
29+
copy:
30+
31+
```swift
32+
let result = unalignedData.withUnsafeBytes { buffer -> UInt32 in
33+
var storage = UInt32.zero
34+
withUnsafeMutableBytes(of: &storage) {
35+
$0.copyBytes(from: buffer.prefix(MemoryLayout<UInt32>.size))
36+
}
37+
return storage
38+
}
39+
```
40+
Now:
41+
```swift
42+
let result = unalignedData.withUnsafeBytes { $0.loadUnaligned(as: UInt32.self) }
43+
```
44+
Additionally, the counterpart `storeBytes(of:toByteOffset:as:)` had its
45+
alignment restriction lifted, so that storing to arbitrary offsets of raw
46+
memory can now succeed.
47+
48+
* [SE-0334][]:
49+
50+
- `UnsafeRawPointer` and `UnsafeMutableRawPointer` have new functionality for
51+
pointer arithmetic, adding functions to obtain a pointer advanced to the next
52+
or previous alignment boundary:
53+
54+
```swift
55+
extension UnsafeRawPointer {
56+
public func alignedUp<T>(for: T.type) -> UnsafeRawPointer
57+
public func alignedDown<T>(for: T.type) -> UnsafeRawPointer
58+
public func alignedUp(toMultipleOf alignment: Int) -> UnsafeRawPointer
59+
public func alignedDown(toMultipleOf alignment: Int) -> UnsafeRawPointer
60+
}
61+
```
62+
- It is now possible to use a pointer to `struct` to obtain a pointer to one
63+
of its stored properties:
64+
65+
```swift
66+
withUnsafeMutablePointer(to: &myStruct) {
67+
let interiorPointer = $0.pointer(to: \.myProperty)!
68+
return myCFunction(interiorPointer)
69+
}
70+
```
71+
- Comparisons between pointers have been simplified by being more permissive.
72+
Since pointers are representations of memory locations within a single pool of
73+
underlying memory, Swift now allows comparing pointers without requiring type
74+
conversions with the `==`, `!=`, `<`,`<=`,`>`, and `>=` operators.
75+
76+
* [SE-0333][]:
77+
78+
It is now possible to use the `withMemoryRebound<T>()` method on raw memory,
79+
that is `UnsafeRawPointer` , `UnsafeRawBufferPointer` and their mutable
80+
counterparts. Additionally, we clarified the semantics of
81+
`withMemoryRebound<T>()` when used on typed memory (`UnsafePointer<Pointee>`,
82+
`UnsafeBufferPointer<Pointee>` and their mutable counterparts). Whereas
83+
`Pointee` and `T` were previously required to have the same stride, you can
84+
now rebind in cases where `Pointee` is an aggregate of `T` or vice-versa. For
85+
example, given an `UnsafeMutableBufferPointer<CGPoint>`, you can now use
86+
`withMemoryRebound` to operate temporarily on a
87+
`UnsafeMutableBufferPointer<CGFloat>`, because `CGPoint` is an aggregate of
88+
`CGFloat`.
89+
890
* [SE-0352][]:
991

1092
It's now possible to call a generic function with a value of protocol type
@@ -32,7 +114,7 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
32114
It's now possible to use a default value expression with a generic parameter type
33115
to default the argument and its type:
34116

35-
```
117+
```swift
36118
func compute<C: Collection>(_ values: C = [0, 1, 2]) {
37119
...
38120
}
@@ -128,7 +210,7 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
128210

129211
Distributed actors provide stronger isolation guarantees than "local" actors, and enable additional checks to be made on return types and parameters of distributed methods, e.g. checking if they conform to `Codable`. Distributed methods can be called on "remote" references of distributed actors, turning those invocations into remote procedure calls, by means of pluggable and user extensible distributed actor system implementations.
130212

131-
Swift does not provide any specific distributed actor system by itself, however, packages in the ecosystem fulfil the role of providing those implementations.
213+
Swift does not provide any specific distributed actor system by itself, however, packages in the ecosystem fulfill the role of providing those implementations.
132214

133215
```swift
134216
distributed actor Greeter {
@@ -9170,20 +9252,23 @@ Swift 1.0
91709252
[SE-0316]: <https://github.com/apple/swift-evolution/blob/main/proposals/0316-global-actors.md>
91719253
[SE-0320]: <https://github.com/apple/swift-evolution/blob/main/proposals/0320-codingkeyrepresentable.md>
91729254
[SE-0322]: <https://github.com/apple/swift-evolution/blob/main/proposals/0322-temporary-buffers.md>
9173-
[SE-0324]: <https://github.com/apple/swift-evolution/blob/main/proposals/0324-c-lang-pointer-arg-conversion.md>
91749255
[SE-0323]: <https://github.com/apple/swift-evolution/blob/main/proposals/0323-async-main-semantics.md>
9256+
[SE-0324]: <https://github.com/apple/swift-evolution/blob/main/proposals/0324-c-lang-pointer-arg-conversion.md>
9257+
[SE-0326]: <https://github.com/apple/swift-evolution/blob/main/proposals/0326-extending-multi-statement-closure-inference.md>
91759258
[SE-0327]: <https://github.com/apple/swift-evolution/blob/main/proposals/0327-actor-initializers.md>
91769259
[SE-0328]: <https://github.com/apple/swift-evolution/blob/main/proposals/0328-structural-opaque-result-types.md>
91779260
[SE-0331]: <https://github.com/apple/swift-evolution/blob/main/proposals/0331-remove-sendable-from-unsafepointer.md>
9178-
[SE-0337]: <https://github.com/apple/swift-evolution/blob/main/proposals/0337-support-incremental-migration-to-concurrency-checking.md>
9261+
[SE-0333]: <https://github.com/apple/swift-evolution/blob/main/proposals/0333-with-memory-rebound.md>
9262+
[SE-0334]: <https://github.com/apple/swift-evolution/blob/main/proposals/0334-pointer-usability-improvements.md>
91799263
[SE-0335]: <https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md>
9180-
[SE-0341]: <https://github.com/apple/swift-evolution/blob/main/proposals/0341-opaque-parameters.md>
91819264
[SE-0336]: <https://github.com/apple/swift-evolution/blob/main/proposals/0336-distributed-actor-isolation.md>
9182-
[SE-0343]: <https://github.com/apple/swift-evolution/blob/main/proposals/0343-top-level-concurrency.md>
9265+
[SE-0337]: <https://github.com/apple/swift-evolution/blob/main/proposals/0337-support-incremental-migration-to-concurrency-checking.md>
91839266
[SE-0340]: <https://github.com/apple/swift-evolution/blob/main/proposals/0340-swift-noasync.md>
9267+
[SE-0341]: <https://github.com/apple/swift-evolution/blob/main/proposals/0341-opaque-parameters.md>
9268+
[SE-0343]: <https://github.com/apple/swift-evolution/blob/main/proposals/0343-top-level-concurrency.md>
91849269
[SE-0345]: <https://github.com/apple/swift-evolution/blob/main/proposals/0345-if-let-shorthand.md>
9185-
[SE-0326]: <https://github.com/apple/swift-evolution/blob/main/proposals/0326-extending-multi-statement-closure-inference.md>
91869270
[SE-0347]: <https://github.com/apple/swift-evolution/blob/main/proposals/0347-type-inference-from-default-exprs.md>
9271+
[SE-0349]: <https://github.com/apple/swift-evolution/blob/main/proposals/0349-unaligned-loads-and-stores.md>
91879272
[SE-0352]: <https://github.com/apple/swift-evolution/blob/main/proposals/0352-implicit-open-existentials.md>
91889273

91899274
[SR-75]: <https://bugs.swift.org/browse/SR-75>

SwiftCompilerSources/Sources/AST/DiagnosticEngine.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public struct DiagnosticEngine {
8282
// Build a higher-order function to wrap every 'withBridgedXXX { ... }'
8383
// calls, so we don't escape anything from the closure. 'bridgedArgs' and
8484
// 'bridgedFixIts' are temporary storage to store bridged values. So they
85-
// should not be used after the closue is executed.
85+
// should not be used after the closure is executed.
8686

8787
var closure: () -> Void = {
8888
bridgedArgs.withBridgedArrayRef { bridgedArgsRef in

SwiftCompilerSources/Sources/Optimizer/Utilities/EscapeInfo.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -953,12 +953,12 @@ struct EscapeInfo {
953953
case let mvr as MultipleValueInstructionResult:
954954
let inst = mvr.instruction
955955
switch inst {
956-
case is DestructureStructInst, is DestructureTupleInst:
957-
val = inst.operands[0].value
958-
// TODO: only push the specific result index.
959-
// But currently there is no O(0) method to get the result index
960-
// from a result value.
961-
p = p.popAllValueFields().push(.anyValueFields)
956+
case let dsi as DestructureStructInst:
957+
p = p.push(.structField, index: mvr.index)
958+
val = dsi.operand
959+
case let dti as DestructureTupleInst:
960+
p = p.push(.tupleField, index: mvr.index)
961+
val = dti.operand
962962
case let bcm as BeginCOWMutationInst:
963963
val = bcm.operand
964964
default:

SwiftCompilerSources/Sources/SIL/Effects.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ public struct ArgumentEffect : CustomStringConvertible, CustomReflectable {
9393
public enum Kind {
9494
/// The selected argument value does not escape.
9595
///
96-
/// Synatx examples:
96+
/// Syntax examples:
9797
/// !%0 // argument 0 does not escape
9898
/// !%0.** // argument 0 and all transitively contained values do not escape
9999
///
100100
case notEscaping
101101

102102
/// The selected argument value escapes to the specified selection (= first payload).
103103
///
104-
/// Synatx examples:
104+
/// Syntax examples:
105105
/// %0.s1 => %r // field 2 of argument 0 exclusively escapes via return.
106106
/// %0.s1 -> %1 // field 2 of argument 0 - and other values - escape to argument 1.
107107
///
@@ -262,7 +262,7 @@ extension StringParser {
262262
}
263263
if function.numIndirectResultArguments > 0 {
264264
if function.numIndirectResultArguments != 1 {
265-
try throwError("mutli-value returns not supported yet")
265+
try throwError("multi-value returns not supported yet")
266266
}
267267
value = .argument(0)
268268
} else {
@@ -274,7 +274,7 @@ extension StringParser {
274274
}
275275
value = .argument(argIdx + function.numIndirectResultArguments)
276276
} else {
277-
try throwError("paramter name or return expected")
277+
try throwError("parameter name or return expected")
278278
}
279279

280280
let valueType: Type

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ public final class MultipleValueInstructionResult : Value {
144144

145145
public var definingInstruction: Instruction? { instruction }
146146

147+
public var index: Int { MultiValueInstResult_getIndex(bridged) }
148+
147149
var bridged: BridgedMultiValueResult {
148150
BridgedMultiValueResult(obj: SwiftObject(self))
149151
}
@@ -568,10 +570,10 @@ final public class BeginCOWMutationInst : MultipleValueInstruction,
568570
public var bufferResult: Value { return getResult(index: 1) }
569571
}
570572

571-
final public class DestructureStructInst : MultipleValueInstruction {
573+
final public class DestructureStructInst : MultipleValueInstruction, UnaryInstruction {
572574
}
573575

574-
final public class DestructureTupleInst : MultipleValueInstruction {
576+
final public class DestructureTupleInst : MultipleValueInstruction, UnaryInstruction {
575577
}
576578

577579
final public class BeginApplyInst : MultipleValueInstruction, FullApplySite {

SwiftCompilerSources/Sources/SIL/SubstitutionMap.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- PassUtils.swift - Utilities for optimzation passes ---------------===//
1+
//===--- PassUtils.swift - Utilities for optimization passes ---------------===//
22
//
33
// This source file is part of the Swift.org open source project
44
//

docs/ABI/Mangling.rst

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ Types
637637
type ::= protocol-list 'p' // existential type
638638
type ::= protocol-list superclass 'Xc' // existential type with superclass
639639
type ::= protocol-list 'Xl' // existential type with AnyObject
640-
type ::= protocol-list 'y' (type* '_')* type* retroactive-conformance* 'Xp' // parameterized protocol type
640+
type ::= protocol-list 'y' (type* '_')* type* retroactive-conformance* 'XP' // parameterized protocol type
641641
type ::= type-list 't' // tuple
642642
type ::= type generic-signature 'u' // generic type
643643
type ::= 'x' // generic param, depth=0, idx=0
@@ -918,21 +918,9 @@ root protocol conformance, and the suffix 'g'.
918918

919919
::
920920

921-
// No generalization signature, no type expression.
922-
extended-existential-shape ::= generic-signature 'Xg' extended-existential-value-storage
923-
924-
// Generalization signature (the second one), no type expression.
925-
extended-existential-shape ::= generic-signature generic-signature 'XG' extended-existential-value-storage
926-
927-
// No generalization signature, type expression.
928-
extended-existential-shape ::= generic-signature type 'Xh' extended-existential-value-storage
929-
930-
// Generalization signature (the second one), type expression.
931-
extended-existential-shape ::= generic-signature generic-signature type 'Xh' extended-existential-value-storage
932-
933-
extended-existential-value-storage ::= 'o' // opaque
934-
extended-existential-value-storage ::= 'c' // class
935-
extended-existential-value-storage ::= 'm' // metatype
921+
// No generalization signature.
922+
extended-existential-shape ::= type 'Xg' // no generalization signature
923+
extended-existential-shape ::= generic-signature type 'XG'
936924

937925
Identifiers
938926
~~~~~~~~~~~

include/swift/ABI/Metadata.h

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,6 +1855,32 @@ struct TargetExtendedExistentialTypeShape
18551855
/// Flags for the existential shape.
18561856
ExtendedExistentialTypeShapeFlags Flags;
18571857

1858+
/// The mangling of the generalized existential type, expressed
1859+
/// (if necessary) in terms of the type parameters of the
1860+
/// generalization signature.
1861+
///
1862+
/// If this shape is non-unique, this is always a flat string, not a
1863+
/// "symbolic" mangling which can contain relative references. This
1864+
/// allows uniquing to simply compare the string content.
1865+
///
1866+
/// In principle, the content of the requirement signature and type
1867+
/// expression are derivable from this type. We store them separately
1868+
/// so that code which only needs to work with the logical content of
1869+
/// the type doesn't have to break down the existential type string.
1870+
/// This both (1) allows those operations to work substantially more
1871+
/// efficiently (and without needing code to produce a requirement
1872+
/// signature from an existential type to exist in the runtime) and
1873+
/// (2) potentially allows old runtimes to support new existential
1874+
/// types without as much invasive code.
1875+
///
1876+
/// The content of this string is *not* necessarily derivable from
1877+
/// the requirement signature. This is because there may be multiple
1878+
/// existential types that have equivalent logical content but which
1879+
/// we nonetheless distinguish at compile time. Storing this also
1880+
/// allows us to far more easily produce a formal type from this
1881+
/// shape reflectively.
1882+
RelativeStringPointer ExistentialType;
1883+
18581884
/// The header describing the requirement signature of the existential.
18591885
TargetGenericContextDescriptorHeader<Runtime> ReqSigHeader;
18601886

@@ -2024,6 +2050,9 @@ struct UniqueHash {
20242050

20252051
/// A descriptor for an extended existential type descriptor which
20262052
/// needs to be uniqued at runtime.
2053+
///
2054+
/// Uniquing is performed by comparing the existential type strings
2055+
/// of the shapes.
20272056
template <typename Runtime>
20282057
struct TargetNonUniqueExtendedExistentialTypeShape {
20292058
/// A reference to memory that can be used to cache a globally-unique
@@ -2032,10 +2061,12 @@ struct TargetNonUniqueExtendedExistentialTypeShape {
20322061
std::atomic<ConstTargetMetadataPointer<Runtime,
20332062
TargetExtendedExistentialTypeShape>>> UniqueCache;
20342063

2035-
/// A hash of the mangling of the existential shape.
2036-
///
2037-
/// TODO: describe that mangling here
2038-
UniqueHash Hash;
2064+
llvm::StringRef getExistentialTypeStringForUniquing() const {
2065+
// When we have a non-unique shape, we're guaranteed that
2066+
// ExistentialType contains no symbolic references, so we can just
2067+
// recover it this way rather than having to parse it.
2068+
return LocalCopy.ExistentialType.get();
2069+
}
20392070

20402071
/// The local copy of the existential shape descriptor.
20412072
TargetExtendedExistentialTypeShape<Runtime> LocalCopy;

include/swift/APIDigester/ModuleAnalyzerNodes.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- ModuleAnaluzerNodes.h - Nodes for API differ tool ---------------====//
1+
//===--- ModuleAnalyzerNodes.h - Nodes for API differ tool ---------------====//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -142,7 +142,7 @@ class UpdatedNodesMap {
142142
};
143143

144144
// Describing some attributes with ABI/API impact. The addition or removal of these
145-
// attributes is considerred breakage.
145+
// attributes is considered breakage.
146146
struct BreakingAttributeInfo {
147147
const DeclAttrKind Kind;
148148
const StringRef Content;
@@ -357,7 +357,7 @@ class SDKNodeDecl: public SDKNode {
357357
uint8_t ReferenceOwnership;
358358
StringRef GenericSig;
359359
// In ABI mode, this field is populated as a user-friendly version of GenericSig.
360-
// Dignostic preferes the sugared versions if they differ as well.
360+
// Diagnostic preferes the sugared versions if they differ as well.
361361
StringRef SugaredGenericSig;
362362
Optional<uint8_t> FixedBinaryOrder;
363363
PlatformIntroVersion introVersions;
@@ -571,7 +571,7 @@ class SDKNodeDeclType: public SDKNodeDecl {
571571

572572
Optional<SDKNodeDeclType*> getSuperclass() const;
573573

574-
/// Finding the node through all children, including the inheritted ones,
574+
/// Finding the node through all children, including the inherited ones,
575575
/// whose printed name matches with the given name.
576576
Optional<SDKNodeDecl*> lookupChildByPrintedName(StringRef Name) const;
577577
SDKNodeType *getRawValueType() const;
@@ -797,22 +797,22 @@ class SwiftDeclCollector: public VisibleDeclConsumer {
797797

798798
void detectRename(SDKNode *L, SDKNode *R);
799799

800-
int dumpSwiftModules(const CompilerInvocation &InitInvok,
800+
int dumpSwiftModules(const CompilerInvocation &InitInvoke,
801801
const llvm::StringSet<> &ModuleNames,
802802
StringRef OutputDir,
803803
const std::vector<std::string> PrintApis,
804804
CheckerOptions Opts);
805805

806806
SDKNodeRoot *getSDKNodeRoot(SDKContext &SDKCtx,
807-
const CompilerInvocation &InitInvok,
807+
const CompilerInvocation &InitInvoke,
808808
const llvm::StringSet<> &ModuleNames);
809809

810810
SDKNodeRoot *getEmptySDKNodeRoot(SDKContext &SDKCtx);
811811

812812
void dumpSDKRoot(SDKNodeRoot *Root, PayLoad load, StringRef OutputFile);
813813
void dumpSDKRoot(SDKNodeRoot *Root, StringRef OutputFile);
814814

815-
int dumpSDKContent(const CompilerInvocation &InitInvok,
815+
int dumpSDKContent(const CompilerInvocation &InitInvoke,
816816
const llvm::StringSet<> &ModuleNames,
817817
StringRef OutputFile, CheckerOptions Opts);
818818

0 commit comments

Comments
 (0)