Skip to content

Commit f4a6556

Browse files
authored
Merge branch 'main' into member-macro-conformances
2 parents f34dda5 + c48836c commit f4a6556

File tree

520 files changed

+9141
-8005
lines changed

Some content is hidden

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

520 files changed

+9141
-8005
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
/include/swift/IDE/ @ahoppen @bnbarham @rintaro @hamishknight
6969
/include/swift/Index/ @bnbarham
7070
/include/swift/Refactoring @ahoppen @bnbarham
71+
/include/swift/Option/*Options* @tshortli
7172
/include/swift/Parse/ @ahoppen @bnbarham @CodaFi @DougGregor @rintaro
7273
/include/swift/PrintAsClang @zoecarver @hyp @egorzhdan
7374
# TODO: /include/swift/SIL/

SwiftCompilerSources/Package.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ private extension Target {
2626
path: path ?? "Sources/\(name)",
2727
exclude: ["CMakeLists.txt"],
2828
sources: sources,
29-
cxxSettings: [
30-
.headerSearchPath("../include"),
31-
.headerSearchPath("../../llvm-project/llvm/include"),
32-
.headerSearchPath("../../llvm-project/clang/include"),
33-
],
3429
swiftSettings: [
3530
.interoperabilityMode(.Cxx),
36-
.unsafeFlags(["-cross-module-optimization"]),
31+
.unsafeFlags([
32+
"-Xcc", "-I../include",
33+
"-Xcc", "-I../../llvm-project/llvm/include",
34+
"-Xcc", "-I../../llvm-project/clang/include",
35+
"-cross-module-optimization",
36+
]),
3737
] + swiftSettings)
3838
}
3939
}

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ComputeSideEffects.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,24 @@ private struct CollectedEffects {
142142
handleApply(pa)
143143
checkedIfDeinitBarrier = true
144144
}
145+
// In addition to the effects of the apply, also consider the
146+
// effects of the capture, which reads the captured value in
147+
// order to move it into the context. This only applies to
148+
// addressible values, because capturing does not dereference
149+
// any class objects.
150+
//
151+
// Ignore captures for on-stack partial applies. They only
152+
// bitwise-move or capture by address, so the call to
153+
// handleApply above is sufficient. And, if they are not applied
154+
// in this function, then they are never applied.
155+
if !pa.isOnStack {
156+
// the callee and its arguments are all captured...
157+
for operand in pa.operands {
158+
if operand.value.type.isAddress {
159+
addEffects(.read, to: operand.value)
160+
}
161+
}
162+
}
145163

146164
case let fl as FixLifetimeInst:
147165
// A fix_lifetime instruction acts like a read on the operand to prevent

docs/ABI/Mangling.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ Globals
150150
#endif
151151
global ::= protocol-conformance 'Hc' // protocol conformance runtime record
152152
global ::= global 'HF' // accessible function runtime record
153-
global ::= global 'Ha' // runtime discoverable attribute record
154153

155154
global ::= nominal-type 'Mo' // class metadata immediate member base offset
156155

docs/Generics/chapters/basic-operation.tex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ \chapter{Basic Operation}\label{rqm basic operation}
4444
\end{enumerate}
4545
Note that we have all four combinations of domain and ``purpose.'' In case (1) and (2) above, the domain is a list of generic parameters. In case (3)~and~(4), the domain is a list of protocols in a protocol component (which will be introduced shortly). In case (1)~and~(3), our goal is to build a requirement machine and use its rewrite system and property map, so we don't record rewrite loops. In case (2)~and~(4), we're also computing a list of minimal requirements, so we \emph{do} record rewrite loops. Let's now take a closer look at each of these four possibilities.
4646

47-
\paragraph{Generic signature}
47+
\paragraph{Generic signature.}
4848
\index{generic signature query}%
4949
\IndexDefinition{rewrite context}%
5050
\index{rewrite rule}%
@@ -132,7 +132,7 @@ \chapter{Basic Operation}\label{rqm basic operation}
132132
\end{center}
133133
\end{figure}
134134

135-
\paragraph{Generic signature minimization}
135+
\paragraph{Generic signature minimization.}
136136
\index{inferred generic signature request}%
137137
\index{abstract generic signature request}%
138138
\index{minimal requirement}%
@@ -159,7 +159,7 @@ \chapter{Basic Operation}\label{rqm basic operation}
159159
\end{itemize}
160160
The \texttt{-disable-requirement-machine-reuse} frontend flag forces the rewrite context to always just discard the requirement machine after minimization. If you're lucky enough to discover a new scenario not covered by one of the above cases, then this flag might address the problem; it would certainly make for an interesting bug report!
161161

162-
\paragraph{Protocol component}
162+
\paragraph{Protocol component.}
163163
\index{protocol component}%
164164
A requirement machine for a protocol component is built in a similar way to Figure~\ref{rqm flowchart generic signature}. We take with the requirement signature of each protocol in the component, build rewrite rules, run completion, and construct the property map. Protocol component machines are never directly used for queries; we only issue queries against generic signature machines. Instead, protocol component machines only have one purpose in life: to have their rewrite rules imported into other requirement machines.
165165
\eject
@@ -170,7 +170,7 @@ \chapter{Basic Operation}\label{rqm basic operation}
170170
\index{main module}%
171171
Typically, protocol component requirement machines are created for protocols that were deserialized from another module, where the requirement signatures were previously computed and serialized as well. For protocols in the main module (that is, written in source) we use the fourth and final kind of requirement machine to compute their requirement signatures first; this requirement machine is then installed in the rewrite context so that those rules can be imported later. However, just as the generic signature minimization requirement machine cannot be installed under some circumstances, the same edge cases can force us to discard the protocol component minimization requirement machine instead of installing it, in which case we will build a new protocol component requirement machine from the requirement signatures we just built.
172172

173-
\paragraph{Protocol component minimization}
173+
\paragraph{Protocol component minimization.}
174174
\index{structural requirements request}%
175175
\index{type alias requirements request}%
176176
\index{requirement signature request}%
@@ -186,7 +186,7 @@ \section{Protocol Components}\label{protocol component}
186186

187187
TODO: mention domain
188188

189-
\paragraph{Derived requirements}
189+
\paragraph{Derived requirements.}
190190
There is a link between the protocol dependency graph and the \index{derived requirement}derived requirements formalism. Define a relation \index{$\prec$}\index{$\prec$!z@\igobble|seealso{reachability relation}}$\prec$ between protocols, where $\texttt{P}\prec\texttt{Q}$ if $G_\texttt{P}\vDash\ConfReq{T}{Q}$ for some type parameter \texttt{T}; that is, $\texttt{P}\prec\texttt{Q}$ means that we can derive a conformance requirement mentioning \texttt{Q} starting from the requirements of \texttt{P}. Now, this conformance requirement has a conformance path, to which we can apply our graph homomorphism and get a path from \texttt{P} to \texttt{Q}. Thus, $\texttt{P}\prec\texttt{Q}$ can also be understood as the reachability relation in the protocol dependency graph. In Chapter~\ref{rqm basic operation}, we make use of this fact when building the rewrite system for a generic signature, by pulling in the requirements of protocols reachable via the protocol dependency graph.
191191

192192
\index{protocol dependency graph}%

docs/Generics/chapters/building-generic-signatures.tex

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ \chapter{Building Generic Signatures}\label{building generic signatures}
119119
The inferred generic signature request emits diagnostics at the source location of the generic context in the following circumstances:
120120
\begin{enumerate}
121121
\item If the compiler is able to prove that no substitution map can ever simultaneously satisfy all of the requirements in the generic signature, the signature is said to contain \emph{conflicting requirements}. These will diagnose an error.
122-
\item If some requirement can be shown to be a consequence of other requirements, the requirement is called a \emph{redundant requirement}. By default, redundant requirements are silently dropped, but if the \texttt{-Xfrontend -warn-redundant-requirements} flag is passed they are diagnosed as warnings.
122+
\item If some requirement can be shown to be a consequence of other requirements, the requirement is called a \emph{redundant requirement}. By default, redundant requirements are silently dropped, but if the \texttt{-Xfrontend -warn-redundant-requirements} flag is passed they are diagnosed as \index{warning}warnings.
123123
\end{enumerate}
124124

125125
\begin{figure}\captionabove{Overview of the abstract generic signature request}\label{abstract generic signature request figure}
@@ -169,7 +169,7 @@ \chapter{Building Generic Signatures}\label{building generic signatures}
169169
\index{inheritance clause}
170170
Recall from Section~\ref{protocols} that a constraint type written in a protocol's inheritance clause declares a conformance requirement with a subject type of \texttt{Self}. Qualified name lookup must be aware of protocol inheritance relationships, since a lookup into a protocol can also find members of inherited protocols. However, qualified lookup sits ``below'' generics. Building a protocol's requirement signature performs type resolution, which queries name lookup; those name lookups cannot in turn depend on the requirement signature having already been constructed. Thus, qualified name lookup can only look at syntactic constructs and cannot query the requirement signature.
171171

172-
The practical consequence of this design is that protocol inheritance must be explicitly stated, and cannot be implied as a non-trivial consequence of same-type requirements. After building a protocol's requirement signature, we ensure that any conformance requirements known to be satisfied by \texttt{Self} are actually explicit requirements written in the protocol's inheritance clause, or \texttt{where} clause entires with a subject type of \texttt{Self}. Anything else is diagnosed with a warning.
172+
The practical consequence of this design is that protocol inheritance must be explicitly stated, and cannot be implied as a non-trivial consequence of same-type requirements. After building a protocol's requirement signature, we ensure that any conformance requirements known to be satisfied by \texttt{Self} are actually explicit requirements written in the protocol's inheritance clause, or \texttt{where} clause entires with a subject type of \texttt{Self}. Anything else is diagnosed with a \index{warning}warning.
173173

174174
\begin{listing}\captionabove{Example showing non-obvious protocol inheritance relationship}\label{badinheritance}
175175
\begin{Verbatim}
@@ -196,7 +196,7 @@ \chapter{Building Generic Signatures}\label{building generic signatures}
196196
\begin{example}
197197
In Listing~\ref{badinheritance}, the \texttt{Self} type of the \texttt{Bad} protocol is equivalent to the type parameter \texttt{Self.Tricky.Other} via a same-type requirement. The \texttt{Tricky} associated type conforms to \texttt{Base}, and the \texttt{Other} associated type of \texttt{Base} also conforms to \texttt{Base}. For this reason, the \texttt{Self} type of \texttt{Bad} actually conforms to \texttt{Base}.
198198

199-
However, this inheritance relationship is invisible to name lookup, so resolution of the underlying type of \texttt{Income} fails to find the declaration of \texttt{Salary}. After building the protocol's requirement signature, the type checker discovers the unexpected conformance requirement on \texttt{Self}, but at this stage, it is too late to attempt the failed name lookup again! The compiler instead emits a warning suggesting the user explicitly states the inheritance relationship in the declaration of \texttt{Bad}.
199+
However, this inheritance relationship is invisible to name lookup, so resolution of the underlying type of \texttt{Income} fails to find the declaration of \texttt{Salary}. After building the protocol's requirement signature, the type checker discovers the unexpected conformance requirement on \texttt{Self}, but at this stage, it is too late to attempt the failed name lookup again! The compiler instead emits a \index{warning}warning suggesting the user explicitly states the inheritance relationship in the declaration of \texttt{Bad}.
200200
\end{example}
201201

202202
\section{Requirement Inference}\label{requirementinference}
@@ -217,7 +217,7 @@ \section{Requirement Inference}\label{requirementinference}
217217
\end{Verbatim}
218218
The type \verb|Set<S.Element>| only makes sense if \texttt{S.Element} conforms to \texttt{Hashable}. This is checked by type resolution in the interface resolution stage, after the generic signature has been built. However this requirement is not explicitly stated here. Instead, requirement inference \emph{adds} this requirement during the structural resolution stage when the generic signature is being built, ensuring that the type representation \verb|Set<S.Element>| can successfully resolve later.
219219

220-
You can always state an inferred requirement explicitly instead. Since this is useful for documentation purposes, the \verb|-warn-redundant-requirements| flag will not emit a warning if an explicit requirement is made redundant by an inferred requirement.
220+
You can always state an inferred requirement explicitly instead. Since this is useful for documentation purposes, the \verb|-warn-redundant-requirements| flag will not emit a \index{warning}warning if an explicit requirement is made redundant by an inferred requirement.
221221
\begin{Verbatim}
222222
func uniqueElements<S: Sequence>(_ seq: S) -> Set<S.Element>
223223
where S.Element: Hashable {...}
@@ -678,17 +678,17 @@ \section{Requirement Validity}\label{generic signature validity}
678678
Having done that, we argue that for all other derivation steps in our given derivation, the formal substitution alone is sufficient and preserves validity. For example, suppose we have the following derivation in a protocol generic signature \verb|<Self where Self: P>|:
679679
\begin{gather}
680680
\vdash\ConfReq{Self}{P}\tag{1}\\
681-
\vdash\FormalReq{Self.A == Self.B}\qquad\mbox{(in \texttt{P})}\tag{2}\\
682-
\vdash\FormalReq{Self.B == Self.C}\qquad\mbox{(in \texttt{P})}\tag{3}\\
681+
\vdash\FormalReq{Self.A == Self.B}_\texttt{P}\tag{2}\\
682+
\vdash\FormalReq{Self.B == Self.C}_\texttt{P}\tag{3}\\
683683
(1),\,(2)\vdash\FormalReq{Self.A == Self.B}\tag{4}\\
684684
(1),\,(3)\vdash\FormalReq{Self.B == Self.C}\tag{5}\\
685685
(1),\,(5)\vdash\FormalReq{Self.A == Self.C}\tag{6}
686686
\end{gather}
687687
After replacing the initial derivation step with a derivation of \texttt{T} and substituting \texttt{T} for \texttt{Self} in all other derivation steps, we get a derivation in $G$:
688688
\begin{gather}
689689
\ldots \vdash\ConfReq{T}{P}\tag{1}\\
690-
\vdash\FormalReq{Self.A == Self.B}\qquad\mbox{(in \texttt{P})}\tag{2}\\
691-
\vdash\FormalReq{Self.B == Self.C}\qquad\mbox{(in \texttt{P})}\tag{3}\\
690+
\vdash\FormalReq{Self.A == Self.B}_\texttt{P}\tag{2}\\
691+
\vdash\FormalReq{Self.B == Self.C}_\texttt{P}\tag{3}\\
692692
(1),\,(2)\vdash\FormalReq{T.A == T.B}\tag{4}\\
693693
(1),\,(3)\vdash\FormalReq{T.B == T.C}\tag{5}\\
694694
(1),\,(5)\vdash\FormalReq{T.A == T.C}\tag{6}

docs/Generics/chapters/compilation-model.tex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ \chapter{Compilation Model}\label{compilation model}
5656
\begin{itemize}
5757
\item \IndexDefinition{parser}\textbf{Parse:} First, all source files are parsed to form the \IndexDefinition{abstract syntax tree}\index{AST|see{abstract syntax tree}}\index{syntax tree|see{abstract syntax tree}}abstract syntax \index{tree}tree.
5858
\item \IndexDefinition{Sema}\textbf{Sema:} Semantic analysis type-checks and validates the abstract syntax tree.
59-
\item \IndexDefinition{SILGen}\textbf{SILGen:} The type-checked syntax tree is lowered to \IndexDefinition{raw SIL}``raw SIL.'' SIL is the Swift Intermediate Language, described in \cite{sil}.
59+
\item \IndexDefinition{SILGen}\textbf{SILGen:} The type-checked syntax tree is lowered to \IndexDefinition{raw SIL}``raw SIL.'' SIL is the Swift Intermediate Language, described in \cite{sil} and \cite{siltalk}.
6060
\item \IndexDefinition{SIL optimizer}\textbf{SILOptimizer:} The raw SIL is transformed into \IndexDefinition{canonical SIL}``canonical SIL'' by a series of \IndexDefinition{SIL mandatory pass}\emph{mandatory passes}, which analyze the control flow graph and emit diagnostics; for example, \IndexDefinition{definite initialization}\emph{definite initialization} ensures that all storage locations are initialized.
6161

6262
When the \IndexFlag{O}\texttt{-O} command line flag is specified, the canonical SIL is further optimized by a series of \IndexDefinition{SIL performance pass}\emph{performance passes} with the goal of improving run-time performance and reducing code size.
@@ -500,7 +500,7 @@ \section{Module System}\label{module system}
500500
\IndexFlag{import-objc-header}
501501
Invoking the compiler with the \texttt{-import-objc-header} flag followed by a header file name specifies a \emph{bridging header}. This is a shortcut for making C declarations in the bridging header visible to all other source files in the main module, without having to define a separate Clang module first. This is implemented by adding a Clang file unit corresponding to the bridging header to the main module. For this reason, compiler code should not assume that all file units in the main module are necessarily source files.
502502

503-
\paragraph{Textual interfaces} \IndexFlag{emit-module-interface}The Swift serialized module format depends on compiler internals and no attempt is made to preserve compatibility across compiler releases. When building a shared library for distribution, it is better to generate a \IndexDefinition{textual interface}\emph{textual interface}:
503+
\paragraph{Textual interfaces} \IndexFlag{emit-module-interface}The Swift serialized module format depends on compiler internals and no attempt is made to preserve compatibility across compiler releases. When building a shared library for distribution, it is better to generate a \IndexDefinition{textual interface}\emph{textual interface}:\index{horse}
504504
\begin{Verbatim}
505505
$ swiftc Horse.swift -enable-library-evolution -emit-module-interface
506506
\end{Verbatim}
@@ -723,4 +723,4 @@ \subsection*{Module System}
723723
\item \SourceFile{lib/AST/ASTPrinter.cpp}
724724
\end{itemize}
725725

726-
\end{document}
726+
\end{document}

0 commit comments

Comments
 (0)