Skip to content

Commit 426b0e0

Browse files
authored
Merge branch 'swiftlang:main' into eng/statics-const-extract
2 parents c2ca7b0 + fc52f2f commit 426b0e0

File tree

448 files changed

+8635
-4691
lines changed

Some content is hidden

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

448 files changed

+8635
-4691
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,10 @@ option(SWIFT_STDLIB_ENABLE_SIB_TARGETS
463463
"Should we generate sib targets for the stdlib or not?"
464464
FALSE)
465465

466+
option(SWIFT_STDLIB_BUILD_SYMBOL_GRAPHS
467+
"Whether to build symbol graphs for the stdlib, for use in documentation."
468+
FALSE)
469+
466470

467471
set(SWIFT_DARWIN_SUPPORTED_ARCHS "" CACHE STRING
468472
"Semicolon-separated list of architectures to configure on Darwin platforms. \

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
| **Ubuntu 20.04** | AArch64 |[![Build Status](https://ci.swift.org/job/oss-swift-package-ubuntu-20_04-aarch64/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-ubuntu-20_04-aarch64)|
1414
| **Ubuntu 22.04** | x86_64 |[![Build Status](https://ci.swift.org/job/oss-swift-package-ubuntu-22_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-ubuntu-22_04)|
1515
| **Ubuntu 22.04** | AArch64 |[![Build Status](https://ci.swift.org/job/oss-swift-package-ubuntu-22_04-aarch64/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-ubuntu-22_04-aarch64)|
16-
| **CentOS 7** | x86_64 |[![Build Status](https://ci.swift.org/job/oss-swift-package-centos-7/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-centos-7)|
16+
| **Ubuntu 24.04** | x86_64 |[![Build Status](https://ci.swift.org/job/oss-swift-package-ubuntu-24_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-ubuntu-24_04)|
17+
| **Ubuntu 24.04** | AArch64 |[![Build Status](https://ci.swift.org/job/oss-swift-package-ubuntu-24_04-aarch64/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-ubuntu-24_04-aarch64)|
1718
| **Amazon Linux 2** | x86_64 |[![Build Status](https://ci.swift.org/job/oss-swift-package-amazon-linux-2/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-amazon-linux-2)|
1819
| **Amazon Linux 2** | AArch64 |[![Build Status](https://ci.swift.org/job/oss-swift-package-amazon-linux-2-aarch64/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-amazon-linux-2-aarch64)|
1920
| **Universal Base Image 9** | x86_64 |[![Build Status](https://ci.swift.org/job/oss-swift-package-ubi-9/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-ubi-9)|

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ComputeSideEffects.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ let computeSideEffects = FunctionPass(name: "compute-side-effects") {
5757
// instruction the argument might have escaped.
5858
for argument in function.arguments {
5959
collectedEffects.addEffectsForEscapingArgument(argument: argument)
60+
collectedEffects.addEffectsForConsumingArgument(argument: argument)
6061
}
6162

6263
// Don't modify the effects if they didn't change. This avoids sending a change notification
@@ -236,7 +237,17 @@ private struct CollectedEffects {
236237
addEffects(.destroy, to: argument)
237238
}
238239
}
239-
240+
241+
mutating func addEffectsForConsumingArgument(argument: FunctionArgument) {
242+
if argument.convention == .indirectIn {
243+
// Usually there _must_ be a read from a consuming in-argument, because the function has to consume the argument.
244+
// But in the special case if all control paths end up in an `unreachable`, the consuming read might have been
245+
// dead-code eliminated. Therefore make sure to add the read-effect in any case. Otherwise it can result
246+
// in memory lifetime failures at a call site.
247+
addEffects(.read, to: argument)
248+
}
249+
}
250+
240251
private mutating func handleApply(_ apply: ApplySite) {
241252
let callees = calleeAnalysis.getCallees(callee: apply.callee)
242253
let args = apply.argumentOperands.lazy.map {

benchmark/Package.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ targets.append(
127127
dependencies: swiftBenchDeps,
128128
path: "utils",
129129
sources: ["main.swift"],
130-
swiftSettings: [.unsafeFlags(["-Xfrontend",
131-
"-enable-experimental-cxx-interop",
130+
swiftSettings: [.unsafeFlags(["-cxx-interoperability-mode=default",
132131
"-I",
133132
"utils/CxxTests"])]))
134133

@@ -166,8 +165,7 @@ targets += cxxSingleSourceLibraries.map { name in
166165
dependencies: singleSourceDeps,
167166
path: "cxx-source",
168167
sources: ["\(name).swift"],
169-
swiftSettings: [.unsafeFlags(["-Xfrontend",
170-
"-enable-experimental-cxx-interop",
168+
swiftSettings: [.unsafeFlags(["-cxx-interoperability-mode=default",
171169
"-I",
172170
"utils/CxxTests",
173171
// FIXME: https://github.com/apple/swift/issues/61453

cmake/modules/AddPureSwift.cmake

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,31 @@ function(_set_pure_swift_profile_flags target_name)
120120
endif()
121121
endfunction()
122122

123+
function(_set_pure_swift_package_options target_name package_name)
124+
if(NOT package_name OR NOT Swift_COMPILER_PACKAGE_CMO_SUPPORT)
125+
return()
126+
endif()
127+
128+
# Enable package CMO if possible.
129+
# NOTE: '-enable-library-evolution' is required for package CMO even when we
130+
# don't need '.swiftinterface'. E.g. executables.
131+
if(Swift_COMPILER_PACKAGE_CMO_SUPPORT STREQUAL "IMPLEMENTED")
132+
target_compile_options("${target_name}" PRIVATE
133+
"-enable-library-evolution"
134+
"SHELL:-package-name ${package_name}"
135+
"SHELL:-Xfrontend -package-cmo"
136+
"SHELL:-Xfrontend -allow-non-resilient-access"
137+
)
138+
elseif(Swift_COMPILER_PACKAGE_CMO_SUPPORT STREQUAL "EXPERIMENTAL")
139+
target_compile_options("${target_name}" PRIVATE
140+
"-enable-library-evolution"
141+
"SHELL:-package-name ${package_name}"
142+
"SHELL:-Xfrontend -experimental-package-cmo"
143+
"SHELL:-Xfrontend -experimental-allow-non-resilient-access"
144+
"SHELL:-Xfrontend -experimental-package-bypass-resilience"
145+
)
146+
endif()
147+
endfunction()
123148

124149
# Add a new "pure" Swift host library.
125150
#
@@ -149,6 +174,9 @@ endfunction()
149174
# EMIT_MODULE
150175
# Emit '.swiftmodule' to
151176
#
177+
# PACKAGE_NAME
178+
# Name of the Swift package this library belongs to.
179+
#
152180
# DEPENDENCIES
153181
# Target names to pass target_link_library
154182
#
@@ -169,7 +197,8 @@ function(add_pure_swift_host_library name)
169197
SHARED
170198
STATIC
171199
EMIT_MODULE)
172-
set(single_parameter_options)
200+
set(single_parameter_options
201+
PACKAGE_NAME)
173202
set(multiple_parameter_options
174203
DEPENDENCIES
175204
SWIFT_DEPENDENCIES)
@@ -193,6 +222,7 @@ function(add_pure_swift_host_library name)
193222
# Create the library.
194223
add_library(${name} ${libkind} ${APSHL_SOURCES})
195224
_add_host_swift_compile_options(${name})
225+
_set_pure_swift_package_options(${name} "${APSHL_PACKAGE_NAME}")
196226

197227
set_property(TARGET ${name}
198228
PROPERTY BUILD_WITH_INSTALL_RPATH YES)
@@ -315,6 +345,9 @@ endfunction()
315345
# name
316346
# Name of the tool (e.g., swift-frontend).
317347
#
348+
# PACKAGE_NAME
349+
# Name of the Swift package this executable belongs to.
350+
#
318351
# DEPENDENCIES
319352
# Target names to pass target_link_library
320353
#
@@ -333,7 +366,8 @@ function(add_pure_swift_host_tool name)
333366
# Option handling
334367
set(options)
335368
set(single_parameter_options
336-
SWIFT_COMPONENT)
369+
SWIFT_COMPONENT
370+
PACKAGE_NAME)
337371
set(multiple_parameter_options
338372
DEPENDENCIES
339373
SWIFT_DEPENDENCIES)
@@ -349,6 +383,7 @@ function(add_pure_swift_host_tool name)
349383
add_executable(${name} ${APSHT_SOURCES})
350384
_add_host_swift_compile_options(${name})
351385
_set_pure_swift_link_flags(${name} "../lib/")
386+
_set_pure_swift_package_options(${name} "${APSHT_PACKAGE_NAME}")
352387

353388
if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
354389
set_property(TARGET ${name}

cmake/modules/macCatalystUtils.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function(get_target_triple target_out_var target_variant_out_var sdk arch)
7878
elseif(maccatalyst_build_flavor STREQUAL "macos-like")
7979
# Use the default macOS triple.
8080
elseif(maccatalyst_build_flavor STREQUAL "zippered")
81-
set(target "${arch}-apple-macosx${SWIFT_DARWIN_DEPLOYMENT_VERSION_OSX}")
81+
set(target "${arch}-apple-macosx${deployment_version}")
8282
set(target_variant "${arch}-apple-ios${SWIFT_DARWIN_DEPLOYMENT_VERSION_MACCATALYST}-macabi")
8383
elseif(maccatalyst_build_flavor STREQUAL "unzippered-twin")
8484
# Use the default triple for now

docs/ABI/Mangling.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,14 +1265,17 @@ Function Specializations
12651265

12661266
::
12671267

1268-
specialization ::= type '_' type* 'Tg' SPEC-INFO // Generic re-abstracted specialization
1269-
specialization ::= type '_' type* 'TB' SPEC-INFO // Alternative mangling for generic re-abstracted specializations,
1270-
// used for functions with re-abstracted resilient parameter types.
1268+
specialization ::= type '_' type* 'T' dropped-arg* 'g' SPEC-INFO // Generic re-abstracted specialization
1269+
specialization ::= type '_' type* 'T' dropped-arg* 'B' SPEC-INFO // Alternative mangling for generic re-abstracted specializations,
1270+
// used for functions with re-abstracted resilient parameter types.
1271+
specialization ::= type '_' type* 'T' dropped-arg* 'G' SPEC-INFO // Generic not re-abstracted specialization
12711272
specialization ::= type '_' type* 'Ts' SPEC-INFO // Generic re-abstracted prespecialization
1272-
specialization ::= type '_' type* 'TG' SPEC-INFO // Generic not re-abstracted specialization
12731273
specialization ::= type '_' type* 'Ti' SPEC-INFO // Inlined function with generic substitutions.
12741274
specialization ::= type '_' type* 'Ta' SPEC-INFO // Non-async specialization
12751275

1276+
dropped-arg ::= 't' // The first argument is dropped
1277+
dropped-arg ::= 't' NATURAL // The `N+1`th argument is dropped
1278+
12761279
The types are the replacement types of the substitution list.
12771280

12781281
::
@@ -1294,7 +1297,7 @@ Some kinds need arguments, which precede ``Tf``.
12941297
spec-arg ::= identifier
12951298
spec-arg ::= type
12961299

1297-
SPEC-INFO ::= MT-REMOVED? FRAGILE? ASYNC-REMOVED? PASSID
1300+
SPEC-INFO ::= FRAGILE? ASYNC-REMOVED? PASSID
12981301

12991302
PASSID ::= '0' // AllocBoxToStack,
13001303
PASSID ::= '1' // ClosureSpecializer,
@@ -1305,8 +1308,6 @@ Some kinds need arguments, which precede ``Tf``.
13051308
PASSID ::= '6' // MoveDiagnosticInOutToOut,
13061309
PASSID ::= '7' // AsyncDemotion,
13071310

1308-
MT-REMOVED ::= 'm' // non-generic metatype arguments are removed in the specialized function
1309-
13101311
FRAGILE ::= 'q'
13111312

13121313
ASYNC-REMOVED ::= 'a' // async effect removed

docs/EmbeddedSwift/UserManual.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Segment __TEXT: 16384
100100

101101
## Strings
102102

103-
Both StaticString and String types are available in Embedded Swift. As is the case in desktop Swift, certain operations on strings require Unicode data tables for strict Unicode compliance. In Embedded Swift. these data tables are provided as a separate static library (libUnicodeDataTables.a) that users need to link in manually – if they need to use these string operations. If the library is required, linking will fail due to missing on one or more of the following symbols:
103+
Both StaticString and String types are available in Embedded Swift. As is the case in desktop Swift, certain operations on strings require Unicode data tables for strict Unicode compliance. In Embedded Swift these data tables are provided as a separate static library (libUnicodeDataTables.a) that users need to link in manually – if they need to use these string operations. If the library is required, linking will fail due to missing on one or more of the following symbols:
104104

105105
```
106106
_swift_stdlib_getAge

docs/Generics/README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Compiling Swift Generics
2+
3+
This is a book about the *implementation* of generic programming--also known as parametric polymorphism--in the Swift compiler. The first four chapters also give an overview of the Swift compiler architecture in general.
4+
5+
## Downloading the PDF
6+
7+
A periodically-updated PDF is available here:
8+
9+
> https://download.swift.org/docs/assets/generics.pdf
10+
11+
## Typesetting the PDF
12+
13+
It's written in TeX, so to typeset the PDF yourself, you need a TeX distribution:
14+
15+
- [MacTeX](https://www.tug.org/mactex/mactex-download.html): macOS
16+
- [TeX Live](https://www.tug.org/texlive/): Linux, Windows
17+
- [MikTeX](https://miktex.org): another alternative for macOS, Linux, Windows
18+
19+
### Using `make`
20+
21+
Running `make` in `docs/Generics/` will run `pdflatex` and `bibtex` in the right order to generate the final document with bibliography, index and cross-references:
22+
23+
```
24+
cd docs/Generics/
25+
make
26+
```
27+
28+
### Using `latexmk`
29+
30+
A more modern alternative is to use `latexmk`, which runs `pdflatex` and `bibtex` until fixed point:
31+
32+
```
33+
cd docs/Generics/
34+
latexmk -pdf generics.tex
35+
```
36+
37+
### Manually
38+
39+
You can also just do this:
40+
41+
```
42+
cd docs/Generics/
43+
pdflatex generics
44+
bibtex generics
45+
pdflatex generics
46+
pdflatex generics
47+
```
48+
49+
## Reading the PDF
50+
51+
The book makes use of internal hyperlinks so it is is best to use PDF reader with support for PDF bookmarks and back/forward history:
52+
53+
- Preview.app on macOS fits the bill; you can add Back/Forward buttons to the toolbar with **View** > **Customize Toolbar**.
54+
- [Skim.app](https://skim-app.sourceforge.io) is a BSD-licensed open source PDF reader for macOS.
55+
56+
The font size and link targets are probably too small for a smartphone display, so I recommend using something bigger.
57+
58+
## Current Status
59+
60+
This is a work in progress.
61+
62+
The following chapters need some editing:
63+
64+
- Part II:
65+
- Substitution Maps
66+
- Conformances
67+
- Part III:
68+
- Conformance Paths
69+
- Part V:
70+
- Symbols, Terms, and Rules
71+
- Completion
72+
- Type Substitution Summary
73+
74+
The following chapters are not yet written:
75+
76+
- Part IV:
77+
- Opaque Return Types
78+
- Existential Types
79+
- Subclassing
80+
- Part V:
81+
- The Property Map
82+
- Concrete Conformances
83+
- Rule Minimization

docs/Generics/chapters/archetypes.tex

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,16 @@ \section{Local Requirements}\label{local requirements}
155155
Recall that with a type parameter, global conformance lookup returns an abstract conformance without being able to check if the conformance actually holds (\SecRef{abstract conformances}). With archetypes, we implement a more useful behavior that distinguishes several cases. Let $\archetype{T}$ be an archetype with generic signature $G$, and let \texttt{P} be a protocol:
156156
\begin{enumerate}
157157
\item If $G\vdash\TC$ for some class type~\texttt{C}, and \texttt{C} conforms to \texttt{P}, then the archetype \emph{conforms concretely} to \texttt{P}. The class type \texttt{C} may contain type parameters, so global conformance lookup recursively calls itself on~$\MapIn(\texttt{C})$:
158-
\[\protosym{P}\otimes\archetype{T}=\protosym{P}\otimes\MapIn(\texttt{C})=\ConfReq{$\MapIn(\texttt{C})$}{P}\]
158+
\[\pP \otimes \archetype{T}=\pP \otimes \MapIn(\texttt{C})=\ConfReq{$\MapIn(\texttt{C})$}{P}\]
159159
The result is actually wrapped in an \index{inherited conformance}\emph{inherited conformance}, which doesn't do much except report the conforming type as $\archetype{T}$ rather than $\MapIn(\texttt{C})$ (\SecRef{inheritedconformance}).
160160
\item If $G\vdash\TP$, the archetype \emph{conforms abstractly}, and thus global conformance lookup returns an abstract conformance:
161-
\[\protosym{P}\otimes\archetype{T}=\ConfReq{$\archetype{T}$}{P}\]
161+
\[\pP\otimes\archetype{T}=\ConfReq{$\archetype{T}$}{P}\]
162162
\item Otherwise, $\archetype{T}$ does not conform to \texttt{P}, and global conformance lookup returns an invalid conformance.
163163
\end{enumerate}
164164
In (2), we return an abstract conformance whose subject type is an archetype. We need to explain what this means. To recap, when the original type of an abstract conformance is a type parameter~\tT, the type witness for \texttt{[P]A} is a dependent member type~\texttt{T.[P]A}. Similarly, the associated conformance for $\AssocConfReq{Self.U}{Q}{P}$ is the abstract conformance $\ConfReq{T.U}{Q}$. So, when the original type is an \index{abstract conformance!with archetype}archetype $\archetype{T}$, we must also map this \index{type witness!of abstract conformance}type witness or \index{associated conformance!of abstract conformance}associated conformance into the environment:
165165
\begin{align*}
166166
\AssocType{[P]A}\otimes \ConfReq{$\archetype{T}$}{P} &=\archetype{T.[P]A}= \MapIn(\texttt{T.[P]A})\\
167-
\AssocConf{Self.U}{Q}\otimes \ConfReq{$\archetype{T}$}{P} &=\ConfReq{$\archetype{T.U}$}{Q}= \protosym{Q}\otimes\MapIn(\texttt{T.U})
167+
\AssocConf{Self.U}{Q}\otimes \ConfReq{$\archetype{T}$}{P} &=\ConfReq{$\archetype{T.U}$}{Q}= \pQ\otimes\MapIn(\texttt{T.U})
168168
\end{align*}
169169

170170
\section{Archetype Substitution}\label{archetypesubst}
@@ -173,7 +173,7 @@ \section{Archetype Substitution}\label{archetypesubst}
173173
\[
174174
\TypeObj{\EquivClass{G}}\otimes\SubMapObj{G}{H}\longrightarrow\TypeObj{H}
175175
\]
176-
To apply a substitution map $\Sigma$ to a contextual type $\tT^\prime\in\TypeObj{\EquivClass{G}}$, we first map the the contextual type out of its environment, and then apply the substitution map to this interface type:
176+
To apply a substitution map $\Sigma$ to a contextual type $\tT^\prime\in\TypeObj{\EquivClass{G}}$, we first map the contextual type out of its environment, and then apply the substitution map to this interface type:
177177
\[\tT^\prime\otimes \Sigma = \MapOut(\tT^\prime)\otimes \Sigma\]
178178
If the replacement types of $\Sigma$ are interface types, we always get an interface type back, regardless of whether the original type was an interface type or a contextual type.
179179

@@ -415,7 +415,7 @@ \section{The Type Parameter Graph}\label{type parameter graph}
415415
\node (TA) [interior, right=of T] {\texttt{\rT.A}};
416416
\node (TAA) [interior, right=of TA] {\texttt{\rT.A.A}};
417417
\node (TAAA) [interior, right=of TAA] {\texttt{\rT.A.A.A}};
418-
\node (Rest) [interior, right=of TAAA] {\texttt{\vphantom{Ty}...}};
418+
\node (Rest) [right=of TAAA] {$\cdots$};
419419

420420
\path [arrow] (T) edge [above] node {\tiny{\texttt{.A}}} (TA);
421421
\path [arrow] (TA) edge [above] node {\tiny{\texttt{.A}}} (TAA);
@@ -597,14 +597,14 @@ \section{The Archetype Builder}\label{archetype builder}
597597
\item If $\PAForward(t)$ is non-null, load $t\leftarrow\PAForward(t)$, and repeat if necessary.
598598
\item If $\texttt{P}\in\PAConforms(t)$, return.
599599
\item Otherwise, set $\PAConforms(t)\leftarrow \PAConforms(t)\cup\{\texttt{P}\}$.
600-
\item For each protocol~\texttt{Q} appearing in the inheritance clause of the declaration of \texttt{P}, recursively apply this algorithm to $t$ and \texttt{Q}.
600+
\item For each protocol~\tQ\ appearing in the inheritance clause of the declaration of \texttt{P}, recursively apply this algorithm to $t$ and \tQ.
601601
\item Let $\tT:=\PAType(t)$.
602602
\item For each associated type declaration \texttt{A} of \texttt{P}:
603603
\begin{enumerate}
604604
\item If $\PAMembers(t)$ does not have an entry for \texttt{A}, create a new potential archetype~$v$ with $\PAType(v)=\texttt{T.A}$. Add the ordered pair $(\texttt{A}, v)$ to $\PAMembers(t)$.
605605

606606
Otherwise, $\PAMembers(t)$ contains an existing entry~$(\texttt{A}, v)$ with $\PAType(v)=\texttt{T.A}$.
607-
\item For each protocol $\texttt{Q}$ listed in the inheritance clause of the declaration of \texttt{A}, first check if \texttt{Q} already appears among the set of all protocols we've visited in prior recursive calls; if so, emit a diagnostic. Otherwise, add \texttt{Q} to the visited set, and recursively apply this algorithm to $v$ and \texttt{Q}.
607+
\item For each protocol \tQ\ listed in the inheritance clause of the declaration of \texttt{A}, first check if \tQ\ already appears among the set of all protocols we've visited in prior recursive calls; if so, emit a diagnostic. Otherwise, add \tQ\ to the visited set, and recursively apply this algorithm to $v$ and \tQ.
608608
\end{enumerate}
609609
\end{enumerate}
610610
\end{algorithm}

0 commit comments

Comments
 (0)