Skip to content

Commit e27e1c4

Browse files
Merge pull request #4669 from swiftwasm/katei/merge-main-2022-07-01
Merge main 2022-07-01
2 parents 02f6aff + bd25ee0 commit e27e1c4

File tree

358 files changed

+9850
-2502
lines changed

Some content is hidden

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

358 files changed

+9850
-2502
lines changed

CHANGELOG.md

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

66
## Swift 5.7
77

8+
* The Swift compiler no longer warns about redundant requirements in generic declarations. For example,
9+
the following code diagnosed a warning in Swift 5.6 about the `T.Iterator : IteratorProtocol`
10+
requirement being redundant, because it is implied by `T : Sequence`:
11+
12+
```swift
13+
func firstElement<T: Sequence>(_: T) -> T.Element where T.Iterator: IteratorProtocol {...}
14+
```
15+
16+
A redundant requirement does not indicate a coding error, and sometimes it is desirable to spell them
17+
out for documentation purposes. For this reason these warnings are now disabled by default.
18+
19+
To restore the previous behavior, pass the `-Xfrontend -warn-redundant-requirements`
20+
compiler flag.
21+
822
* [SE-0338][]:
923

1024
Non-isolated async functions now always execute on the global concurrent pool,
@@ -41,25 +55,29 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
4155
* [SE-0350][]:
4256

4357
The standard library has a new `Regex<Output>` type.
44-
58+
4559
This type represents an _extended regular expression_, allowing more fluent
4660
string processing operations. A `Regex` may be created by
4761
[initialization from a string][SE-0355]:
48-
```
62+
63+
```swift
4964
let pattern = "a[bc]+" // matches "a" followed by one or more instances
5065
// of either "b" or "c"
5166
let regex = try! Regex(pattern)
5267
```
68+
5369
Or via a [regex literal][SE-0354]:
54-
```
70+
71+
```swift
5572
let regex = #/a[bc]+/#
5673
```
74+
5775
In Swift 6, `/` will also be supported as a delimiter for `Regex` literals.
5876
You can enable this mode in Swift 5.7 with the `-enable-bare-slash-regex`
5977
flag. Doing so will cause some existing expressions that use `/` as an
6078
operator to no longer compile; you can add parentheses or line breaks as a
6179
workaround.
62-
80+
6381
There are [new string-processing algorithms][SE-0357] that support
6482
`String`, `Regex` and arbitrary `Collection` types.
6583

@@ -151,7 +169,7 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
151169
Protocols with primary associated types can now be used in existential types,
152170
enabling same-type constraints on those associated types.
153171

154-
```
172+
```swift
155173
let strings: any Collection<String> = [ "Hello" ]
156174
```
157175

@@ -494,12 +512,12 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
494512
struct S {
495513
@available(macOS 99, *) // error: stored properties cannot be marked potentially unavailable with '@available'
496514
lazy var a: Int = 42
497-
515+
498516
@available(macOS 99, *) // error: stored properties cannot be marked potentially unavailable with '@available'
499517
@Wrapper var b: Int
500518
}
501519
```
502-
520+
503521
* The compiler now correctly emits warnings for more kinds of expressions where a protocol conformance is used and may be unavailable at runtime. Previously, member reference expressions and type erasing expressions that used potentially unavailable conformances were not diagnosed, leading to potential crashes at runtime.
504522

505523
```swift

cmake/modules/SwiftConfigureSDK.cmake

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,21 @@ macro(configure_sdk_unix name architectures)
282282
endif()
283283
set(SWIFT_SDK_${prefix}_USE_ISYSROOT FALSE)
284284

285+
# GCC on Linux is usually located under `/usr`.
286+
# However, Ubuntu 20.04 ships with another GCC installation under `/`, which
287+
# does not include libstdc++. Swift build scripts pass `--sysroot=/` to
288+
# Clang. By default, Clang tries to find GCC installation under sysroot, and
289+
# if it doesn't exist, under `{sysroot}/usr`. On Ubuntu 20.04 and newer, it
290+
# attempts to use the GCC without the C++ stdlib, which causes a build
291+
# failure. To fix that, we tell Clang explicitly to use GCC from `/usr`.
292+
# FIXME: This is a compromise. The value might depend on the architecture
293+
# but add_swift_target_library does not allow passing different values
294+
# depending on the architecture, so having a single value is the only
295+
# possibility right now.
296+
set(SWIFT_SDK_${prefix}_CXX_OVERLAY_SWIFT_COMPILE_FLAGS
297+
-Xcc --gcc-toolchain=/usr
298+
CACHE STRING "Extra flags for compiling the C++ overlay")
299+
285300
foreach(arch ${architectures})
286301
if("${prefix}" STREQUAL "ANDROID")
287302
swift_android_sysroot(android_sysroot)

docs/ABI/Mangling.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ Types
638638
type ::= protocol-list 'p' // existential type
639639
type ::= protocol-list superclass 'Xc' // existential type with superclass
640640
type ::= protocol-list 'Xl' // existential type with AnyObject
641-
type ::= protocol-list 'y' (type* '_')* type* retroactive-conformance* 'XP' // parameterized protocol type
641+
type ::= protocol-list requirement* '_' 'XP' // constrained existential type
642642
type ::= type-list 't' // tuple
643643
type ::= type generic-signature 'u' // generic type
644644
type ::= 'x' // generic param, depth=0, idx=0
@@ -879,6 +879,7 @@ now codified into the ABI; the index 0 is therefore reserved.
879879
GENERIC-PARAM-INDEX ::= 'z' // depth = 0, idx = 0
880880
GENERIC-PARAM-INDEX ::= INDEX // depth = 0, idx = N+1
881881
GENERIC-PARAM-INDEX ::= 'd' INDEX INDEX // depth = M+1, idx = N
882+
GENERIC-PARAM-INDEX ::= 's' // depth = 0, idx = 0; Constrained existential 'Self' type
882883

883884
LAYOUT-CONSTRAINT ::= 'N' // NativeRefCountedObject
884885
LAYOUT-CONSTRAINT ::= 'R' // RefCountedObject

docs/HowToGuides/GettingStarted.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ In project settings, locate `Build, Execution, Deployment > CMake`. You will nee
376376
- `-D SWIFT_PATH_TO_CMARK_BUILD=SOME_PATH/swift-project/build/Ninja-RelWithDebInfoAssert/cmark-macosx-arm64 -D LLVM_DIR=SOME_PATH/swift-project/build/Ninja-RelWithDebInfoAssert/llvm-macosx-arm64/lib/cmake/llvm -D Clang_DIR=SOME_PATH/swift-project/build/Ninja-RelWithDebInfoAssert/llvm-macosx-arm64/lib/cmake/clang -D CMAKE_BUILD_TYPE=RelWithDebInfoAssert -G Ninja -S .`
377377
- replace the `SOME_PATH` to the path where your `swift-project` directory is
378378
- the CMAKE_BUILD_TYPE should match the build configuration name, so if you named this profile `RelWithDebInfo` the CMAKE_BUILD_TYPE should also be `RelWithDebInfo`
379-
- **Note**: If you're using an intel machine to build swift, you'll need to replace the architecture in the options. (ex: `arm64` with `x86_64`)
379+
- **Note**: If you're using an Intel machine to build swift, you'll need to replace the architecture in the options. (ex: `arm64` with `x86_64`)
380380
381381
With this done, CLion should be able to successfully import the project and have full autocomplete and code navigation powers.
382382

docs/SILInitializerConventions.md

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
# SIL Initializer Conventions
2+
3+
A nominal type can define a number of initializers, some of which may
4+
delegate initialization to another initializer. There are specific calling
5+
conventions for these initializers within SIL that make up a part of the ABI
6+
for a type. This document aims to summarize the key calling conventions for
7+
these initializers.
8+
9+
10+
# Structs and Enums
11+
12+
The delegation status for the initializer of a struct or enum is not encoded
13+
in the definitions of these initializers. Thus, all of these initializers
14+
have an implicit `metatype` argument for the instance to be passed in as the
15+
last argument to the initializer. Using `<...>` as a stand-in for other
16+
arguments that are part of the usual function calling convention, consider this
17+
example:
18+
19+
```swift
20+
// the non-delegating init MyStruct.init(final:)
21+
sil hidden [ossa] @$s4test8MyStructV5finalACSi_tcfC : $@convention(method) (<...>, @thin MyStruct.Type) -> MyStruct {
22+
bb0(<...>, %meta : $@thin MyStruct.Type):
23+
%a = alloc_box ${ var MyStruct }, var, name "self"
24+
%b = mark_uninitialized [rootself] %a : ${ var MyStruct }
25+
%c = begin_borrow [lexical] %b : ${ var MyStruct }
26+
%d = project_box %c : ${ var MyStruct }, 0
27+
28+
// ... initialize properties, etc ...
29+
30+
%end = load [trivial] %d : $*MyStruct
31+
end_borrow %c : ${ var MyStruct }
32+
destroy_value %b : ${ var MyStruct }
33+
return %end : $MyStruct
34+
}
35+
36+
37+
// the delegating init MyStruct.init(delegates:)
38+
sil hidden [ossa] @$s4test8MyStructV9delegatesACyt_tcfC : $@convention(method) (<...>, @thin MyStruct.Type) -> MyStruct {
39+
bb0(<...>, %meta : $@thin MyStruct.Type):
40+
// Same allocation as the non-delegating:
41+
%a = alloc_box ${ var MyStruct }, var, name "self"
42+
%b = mark_uninitialized [rootself] %a : ${ var MyStruct }
43+
%c = begin_borrow [lexical] %b : ${ var MyStruct }
44+
%d = project_box %c : ${ var MyStruct }, 0
45+
46+
// ... delegate to MyStruct.init(final:) ...
47+
48+
%ctor = function_ref @$s4test8MyStructV5finalACSi_tcfC : $@convention(method) (Int, @thin MyStruct.Type) -> MyStruct
49+
%ret = apply %ctor(<...>, %meta) : $@convention(method) (Int, @thin MyStruct.Type) -> MyStruct
50+
51+
assign %ret to %d : $*MyStruct
52+
%end = load [trivial] %d : $*MyStruct
53+
end_borrow %c : ${ var MyStruct }
54+
destroy_value %b : ${ var MyStruct }
55+
return %end : $MyStruct
56+
}
57+
```
58+
59+
It's important to note that all initializers take a metadata argument,
60+
regardless of whether it is a delegating initializer. There is also no
61+
separation between allocating and non-allocating initializer entrypoints.
62+
All initializers may perform allocation.
63+
64+
# Classes
65+
66+
Every designated initializer has two entry-points. One performs allocation
67+
(i.e., the "allocating" entry) before continuing at the second entrypoint
68+
which does the initialization (i.e., the "initializing" entrypoint).
69+
Here's an example of `MyClass.init(final:)`, which is a designated initializer,
70+
with its two entry-points:
71+
72+
```swift
73+
// MyClass.__allocating_init(final:)
74+
sil hidden [exact_self_class] [ossa] @$s4test7MyClassC5finalACSi_tcfC : $@convention(method) (<...>, @thick MyClass.Type) -> @owned MyClass {
75+
bb0(%0 : $Int, %1 : $@thick MyClass.Type):
76+
%2 = alloc_ref $MyClass
77+
// function_ref MyClass.init(final:)
78+
%3 = function_ref @$s4test7MyClassC5finalACSi_tcfc : $@convention(method) (Int, @owned MyClass) -> @owned MyClass
79+
%4 = apply %3(%0, %2) : $@convention(method) (Int, @owned MyClass) -> @owned MyClass // user: %5
80+
return %4 : $MyClass
81+
}
82+
83+
// MyClass.init(final:)
84+
sil hidden [ossa] @$s4test7MyClassC5finalACSi_tcfc : $@convention(method) (Int, @owned MyClass) -> @owned MyClass {
85+
bb0(<...>, %1 : @owned $MyClass):
86+
%4 = mark_uninitialized [rootself] %1 : $MyClass
87+
88+
// ... initialize MyClass ...
89+
90+
%11 = copy_value %4 : $MyClass
91+
destroy_value %4 : $MyClass
92+
return %11 : $MyClass
93+
}
94+
```
95+
96+
In the mangling of these entrypoint labels, the uppercase `C` suffix indicates
97+
that it's the allocating entrypoint, whereas the lowercase `c` is the
98+
initializing entrypoint. Only the allocating entrypoint is published in the
99+
type's vtable:
100+
101+
```swift
102+
sil_vtable MyClass {
103+
// ...
104+
#MyClass.init!allocator: (MyClass.Type) -> (<...>) -> MyClass : @$s4test7MyClassC5finalACSi_tcfC // MyClass.__allocating_init(final:)
105+
}
106+
```
107+
108+
The initializing entrypoint is only referenced by either it's corresponding
109+
allocating entrypoint, or by a sub-class that is delegating up in a `super.init`
110+
call. For example, if we had:
111+
112+
```swift
113+
class MyClass {
114+
var x: Int
115+
init(final x: Int) {
116+
self.x = x
117+
}
118+
}
119+
120+
class MyDerivedClass: MyClass {
121+
var y: Int
122+
init(subFinal y: Int) {
123+
self.y = y
124+
super.init(final: y)
125+
}
126+
}
127+
```
128+
129+
Then the `super.init(final: y)` call directly invokes `MyClass.init(final:)`'s
130+
initializing entrypoint, bypassing its allocating init. Here's what that looks
131+
like in SIL:
132+
133+
```
134+
// MyDerivedClass.__allocating_init(final:)
135+
sil hidden [exact_self_class] [ossa] @$s4test14MyDerivedClassC5finalACSi_tcfC : $@convention(method) (Int, @thick MyDerivedClass.Type) -> @owned MyDerivedClass {
136+
// ... calls $s4test14MyDerivedClassC5finalACSi_tcfc in the usual way ...
137+
}
138+
139+
// MyDerivedClass.init(final:)
140+
sil hidden [ossa] @$s4test14MyDerivedClassC5finalACSi_tcfc : $@convention(method) (Int, @owned MyDerivedClass) -> @owned MyDerivedClass {
141+
bb0(%0 : $Int, %1 : @owned $MyDerivedClass):
142+
%2 = alloc_box ${ var MyDerivedClass }, let, name "self"
143+
%3 = mark_uninitialized [derivedself] %2 : ${ var MyDerivedClass }
144+
%4 = begin_borrow [lexical] %3 : ${ var MyDerivedClass }
145+
%5 = project_box %4 : ${ var MyDerivedClass }, 0
146+
debug_value %0 : $Int, let, name "y", argno 1
147+
store %1 to [init] %5 : $*MyDerivedClass
148+
149+
// ... initialize self.y ...
150+
151+
// perform the super call. notice the ownership transfer to the super.init.
152+
%14 = load [take] %5 : $*MyDerivedClass
153+
%15 = upcast %14 : $MyDerivedClass to $MyClass
154+
// function_ref MyClass.init(final:)
155+
%16 = function_ref @$s4test7MyClassC5finalACSi_tcfc : $@convention(method) (Int, @owned MyClass) -> @owned MyClass // user: %17
156+
%17 = apply %16(%0, %15) : $@convention(method) (Int, @owned MyClass) -> @owned MyClass // user: %18
157+
%18 = unchecked_ref_cast %17 : $MyClass to $MyDerivedClass
158+
store %18 to [init] %5 : $*MyDerivedClass // id: %19
159+
160+
// return as usual
161+
%20 = load [copy] %5 : $*MyDerivedClass
162+
end_borrow %4 : ${ var MyDerivedClass }
163+
destroy_value %3 : ${ var MyDerivedClass }
164+
return %20 : $MyDerivedClass
165+
}
166+
```
167+
168+
# Actors
169+
170+
There does not exist a sub-actor that inherits from some other actor in the type
171+
system. As a result, the `convenience` keyword is not required for actor
172+
initializers in the source code. Without inheritance, only the allocating
173+
entry-points can ever be used by an actor.
174+
175+
Nevertheless, internally the compiler will still differentiate between
176+
convenience and designated initializers. So everything discussed
177+
earlier for classes also apply to actors. The body of the initializer determines
178+
whether the compiler internally treats it as `convenience` or not. For example,
179+
an internally designated initializer for an actor still emits two entry-points,
180+
but the initializing entrypoint is exclusively used by its corresponding
181+
allocating entrypoint.
182+
183+
184+

docs/WindowsBuild.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ Set up the `ucrt`, `visualc`, and `WinSDK` modules by:
102102

103103
- copying `ucrt.modulemap` located at `swift/stdlib/public/Platform/ucrt.modulemap` into
104104
`${UniversalCRTSdkDir}/Include/${UCRTVersion}/ucrt` as `module.modulemap`
105-
- copying `visualc.modulemap` located at `swift/stdlib/public/Platform/visualc.modulemap` into `${VCToolsInstallDir}/include` as `module.modulemap`
105+
- copying `vcruntime.modulemap` located at `swift/stdlib/public/Platform/vcruntime.modulemap` into `${VCToolsInstallDir}/include` as `module.modulemap`
106106
- copying `winsdk.modulemap` located at `swift/stdlib/public/Platform/winsdk.modulemap` into `${UniversalCRTSdkDir}/Include/${UCRTVersion}/um`
107-
- and setup the `visualc.apinotes` located at `swift/stdlib/public/Platform/visualc.apinotes` into `${VCToolsInstallDir}/include` as `visualc.apinotes`
107+
- and setup the `vcruntime.apinotes` located at `swift/stdlib/public/Platform/vcruntime.apinotes` into `${VCToolsInstallDir}/include` as `vcruntime.apinotes`
108108

109109
```cmd
110110
mklink "%UniversalCRTSdkDir%\Include\%UCRTVersion%\ucrt\module.modulemap" S:\swift\stdlib\public\Platform\ucrt.modulemap
111111
mklink "%UniversalCRTSdkDir%\Include\%UCRTVersion%\um\module.modulemap" S:\swift\stdlib\public\Platform\winsdk.modulemap
112-
mklink "%VCToolsInstallDir%\include\module.modulemap" S:\swift\stdlib\public\Platform\visualc.modulemap
113-
mklink "%VCToolsInstallDir%\include\visualc.apinotes" S:\swift\stdlib\public\Platform\visualc.apinotes
112+
mklink "%VCToolsInstallDir%\include\module.modulemap" S:\swift\stdlib\public\Platform\vcruntime.modulemap
113+
mklink "%VCToolsInstallDir%\include\vcruntime.apinotes" S:\swift\stdlib\public\Platform\vcruntime.apinotes
114114
```
115115

116116
Warning: Creating the above links usually requires administrator privileges. The quick and easy way to do this is to open a second developer prompt by right clicking whatever shortcut you used to open the first one, choosing Run As Administrator, and pasting the above commands into the resulting window. You can then close the privileged prompt; this is the only step which requires elevation.

include/swift/AST/ASTContext.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ class ASTContext final {
537537
/// Retrieve the declaration of Swift.Error.
538538
ProtocolDecl *getErrorDecl() const;
539539
CanType getErrorExistentialType() const;
540-
540+
541541
#define KNOWN_STDLIB_TYPE_DECL(NAME, DECL_CLASS, NUM_GENERIC_PARAMS) \
542542
/** Retrieve the declaration of Swift.NAME. */ \
543543
DECL_CLASS *get##NAME##Decl() const; \
@@ -561,7 +561,13 @@ class ASTContext final {
561561
/// Retrieve the declaration of the "pointee" property of a pointer type.
562562
VarDecl *getPointerPointeePropertyDecl(PointerTypeKind ptrKind) const;
563563

564-
/// Retrieve the type Swift.AnyObject.
564+
/// Retrieve the type Swift.Any as an existential type.
565+
CanType getAnyExistentialType() const;
566+
567+
/// Retrieve the type Swift.AnyObject as a constraint.
568+
CanType getAnyObjectConstraint() const;
569+
570+
/// Retrieve the type Swift.AnyObject as an existential type.
565571
CanType getAnyObjectType() const;
566572

567573
#define KNOWN_SDK_TYPE_DECL(MODULE, NAME, DECL_CLASS, NUM_GENERIC_PARAMS) \

include/swift/AST/ASTDemangler.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class ASTBuilder {
6464
using BuiltRequirement = swift::Requirement;
6565
using BuiltSubstitutionMap = swift::SubstitutionMap;
6666

67+
static constexpr bool needsToPrecomputeParentGenericContextShapes = false;
68+
6769
explicit ASTBuilder(ASTContext &ctx) : Ctx(ctx) {}
6870

6971
ASTContext &getASTContext() { return Ctx; }
@@ -119,7 +121,8 @@ class ASTBuilder {
119121

120122
Type createProtocolTypeFromDecl(ProtocolDecl *protocol);
121123

122-
Type createParameterizedProtocolType(Type base, ArrayRef<Type> args);
124+
Type createConstrainedExistentialType(Type base,
125+
ArrayRef<BuiltRequirement> constraints);
123126

124127
Type createExistentialMetatypeType(Type instance,
125128
Optional<Demangle::ImplMetatypeRepresentation> repr=None);

0 commit comments

Comments
 (0)