Skip to content

Commit a744b45

Browse files
authored
Merge pull request #6493 from jckarter/abstraction-terms-in-glossary
Define "abstraction pattern" and "reabstraction" in the Lexicon.
2 parents 1edb2ba + 645a470 commit a744b45

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

docs/Lexicon.rst

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,46 @@ source code, tests, and commit messages. See also the `LLVM lexicon`_.
1818

1919
.. glossary::
2020

21+
abstraction pattern
22+
The unsubstituted generic type of a property or function parameter, which
23+
sets constraints on its representation in memory. For example, given the
24+
following definitions::
25+
26+
struct Foo<T> {
27+
var value: T
28+
// Foo.value has abstraction pattern <T> T
29+
30+
struct Bar<T, U> {
31+
var value: (T) -> U
32+
// Bar.value has abstraction pattern <T, U> (T) -> U
33+
}
34+
struct Bas {
35+
var value: (Int) -> String
36+
// Bas.value has abstraction pattern (Int) -> String
37+
}
38+
let transform: (Int) -> String = { "\($0)" }
39+
let foo = Foo<(Int) -> String>(value: transform)
40+
let bar = Bar<Int, String>(value: transform)
41+
let bas = Bas(value: transform)
42+
43+
although ``foo.value``, ``bar.value``, and ``bas.value`` all have the same
44+
function type ``(Int) -> String``, they have different *abstraction
45+
patterns*. Because a value of type ``Foo`` or ``Bar`` may be used in a
46+
generic context and invoke ``value`` with a parameter or result type
47+
of unknown size, the compiler has to pick a more conservative representation
48+
for the closure that uses indirect argument passing, whereas ``Bas.value``
49+
has a fully concrete closure type so can always use a more specialized
50+
direct register-based calling convention. The compiler transparently
51+
introduces `reabstraction` conversions when a value is used with a
52+
different abstraction pattern. (This is where the infamous "reabstraction
53+
thunk helpers" sometimes seen in Swift backtraces come from.)
54+
2155
archetype
2256
A placeholder for a generic parameter or an associated type within a
2357
generic context. Sometimes known as a "rigid type variable" in formal
2458
CS literature. Directly stores its conforming protocols and nested
2559
archetypes, if any.
26-
60+
2761
AST
2862
"Abstract syntax tree", although in practice it's more of a directed graph.
2963
A parsed representation of code used by a compiler.
@@ -235,6 +269,10 @@ source code, tests, and commit messages. See also the `LLVM lexicon`_.
235269
IR generation.
236270
See `mandatory passes <mandatory passes / mandatory optimizations>`.
237271

272+
reabstraction
273+
An implicit representation change that occurs when a value is used with
274+
a different `abstraction pattern` from its current representation.
275+
238276
resilient
239277
Describes a type or function where making certain changes will not break
240278
binary compatibility. See :doc:`LibraryEvolution.rst <LibraryEvolution>`.

0 commit comments

Comments
 (0)