Skip to content

Commit 55f9bb7

Browse files
authored
Merge pull request #1616 from apple/abi-stability-rewrite
Update the ABI stability section of the proposal template
2 parents b7913e2 + b20f3b3 commit 55f9bb7

File tree

1 file changed

+63
-18
lines changed

1 file changed

+63
-18
lines changed

proposal-templates/0000-swift-template.md

Lines changed: 63 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,69 @@ aid in migration?
6565

6666
## Effect on ABI stability
6767

68-
Does the proposal change the ABI of existing language features? The
69-
ABI comprises all aspects of the code generation model and interaction
70-
with the Swift runtime, including such things as calling conventions,
71-
the layout of data types, and the behavior of dynamic features in the
72-
language (reflection, dynamic dispatch, dynamic casting via `as?`,
73-
etc.). Purely syntactic changes rarely change existing ABI. Additive
74-
features may extend the ABI but, unless they extend some fundamental
75-
runtime behavior (such as the aforementioned dynamic features), they
76-
won't change the existing ABI.
77-
78-
Features that don't change the existing ABI are considered out of
79-
scope for [Swift 4 stage 1](README.md). However, additive features
80-
that would reshape the standard library in a way that changes its ABI,
81-
such as [where clauses for associated
82-
types](https://github.com/apple/swift-evolution/blob/master/proposals/0142-associated-types-constraints.md),
83-
can be in scope. If this proposal could be used to improve the
84-
standard library in ways that would affect its ABI, describe them
85-
here.
68+
The ABI comprises all aspects of how code is generated for the
69+
language, how that code interacts with other code that has been
70+
compiled separately, and how that code interacts with the Swift
71+
runtime library. It includes the basic rules of the language ABI,
72+
such as calling conventions, the layout of data types, and the
73+
behavior of dynamic features in the language like reflection,
74+
dynamic dispatch, and dynamic casting. It also includes applications
75+
of those basic rules to ABI-exposed declarations, such as the `public`
76+
functions and types of ABI-stable libraries like the Swift standard
77+
library.
78+
79+
Many language proposals have no direct impact on the ABI. For
80+
example, a proposal to add the `typealias` declaration to Swift
81+
would have no effect on the ABI because type aliases are not
82+
represented dynamically and uses of them in code can be
83+
straightforwardly translated into uses of the aliased type.
84+
Proposals like this can simply state in this section that they
85+
have no impact on the ABI. However, if *using* the feature in code
86+
that must maintain a stable ABI can have a surprising ABI impact,
87+
for example by changing a function signature to be different from
88+
how it would be without using the feature, that should be discussed
89+
in this section.
90+
91+
Because Swift has a stable ABI on some platforms, proposals are
92+
generally not acceptable if they would require changes to the ABI
93+
of existing language features or declarations. Proposals must be
94+
designed to avoid the need for this.
95+
96+
For example, Swift could not accept a proposal for a feature which,
97+
in order to work, would require parameters of certain (existing)
98+
types to always be passed as owned values, because parameters are
99+
not always passed as owned values in the ABI. This feature could
100+
be fixed by only enabling it for parameters marked a special new way.
101+
Adding that marking to an existing function parameter would change
102+
the ABI of that specific function, which programmers can make good,
103+
context-aware decisions about: adding the marking to an existing
104+
function with a stable ABI would not be acceptable, but adding it
105+
to a new function or to a function with no stable ABI restrictions
106+
would be fine.
107+
108+
Proposals that change the ABI may be acceptable if they can be thought
109+
of as merely *adding* to the ABI, such as by adding new kinds of
110+
declarations, adding new modifiers or attributes, or adding new types
111+
or methods to the Swift standard library. The key principle is
112+
that the ABI must not change for code that does not use the new
113+
feature. On platforms with stable ABIs, uses of such features will
114+
by default require a new release of the platform in order to work,
115+
and so their use in code that may deploy to older releases will have
116+
to be availability-guarded. If this limitation applies to any part
117+
of this proposal, that should be discussed in this section.
118+
119+
Adding a function to the standard library does not always require
120+
an addition to the ABI if it can be implemented using existing
121+
functions. Library maintainers may be able to help you with this
122+
during the code review of your implementation. Adding a type or
123+
protocol currently always requires an addition to the ABI.
124+
125+
If a feature does require additions to the ABI, platforms with
126+
stable ABIs may sometimes be able to back-deploy those additions
127+
to existing releases of the platform. This is not always possible,
128+
and in any case, it is outside the scope of the evolution process.
129+
Proposals should usually discuss ABI stability concerns as if
130+
it was not possible to back-deploy the necessary ABI additions.
86131

87132
## Effect on API resilience
88133

0 commit comments

Comments
 (0)