Skip to content

Commit f42bde3

Browse files
[docs] Add documentation for underscored attributes. (swiftlang#37854)
Fixes rdar://65258964.
1 parent 08169c3 commit f42bde3

File tree

3 files changed

+657
-0
lines changed

3 files changed

+657
-0
lines changed

Diff for: docs/Lexicon.md

+43
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ and the combination of module path + access path is an "import path".)
6767

6868
See `ImportPath` and the types nested inside it for more on this.
6969

70+
## access pattern
71+
72+
Defines how some particular storage (a property or a subscript) is accessed.
73+
For example, when accessing a property `let y = a.x`, the compiler could potentially
74+
use `get` accessor or the `_read` accessor. Similarly, for a modification like
75+
`a.x += 1`, the compiler could use `get` + `set` or it could use `_modify`.
76+
77+
The access pattern can differ for call-sites which can/cannot see the underlying
78+
implementation. Clients which cannot see the underlying implementation are said
79+
to use the conservative access pattern.
80+
7081
## archetype
7182

7283
A placeholder for a generic parameter or an associated type within a
@@ -476,6 +487,38 @@ See [mandatory passes](#mandatory-passes--mandatory-optimizations).
476487
An implicit representation change that occurs when a value is used with
477488
a different [abstraction pattern](#abstraction-pattern) from its current representation.
478489

490+
## realization
491+
492+
The process of initializing an ObjC class for use by the ObjC runtime.
493+
This consists of allocating runtime tracking data, fixing up method lists
494+
and attaching categories.
495+
496+
This is distinct from the initialization performed by `+initialize`, which
497+
happens only when the first message (other than `+load`) is sent to the class.
498+
499+
The order of operations is: realization, followed by `+load` (if present),
500+
followed by `+initialize`. There are few cases where these can happen
501+
at different times.
502+
503+
- Common case (no `+load` or special attributes): Realization is lazy and
504+
happens when the first message is sent to a class. After that, `+initialize`
505+
is run.
506+
- If the class has a `+load` method: `+load`, as the name suggests, runs at
507+
load time; it is the ObjC equivalent of a static initializer in C++. For
508+
such a class, realization eagerly happens at load time before `+load` runs.
509+
(Fun aside: C++ static initializers run after `+load`.) `+initialize` still
510+
runs lazily on the first message.
511+
- If the class is marked [`@_objc_non_lazy_realization`](/docs/ReferenceGuides/UnderscoredAttributes.md#_objc_non_lazy_realization):
512+
Realization happens at load time. `+initialize` still runs lazily on the first
513+
message.
514+
515+
It's possible to create a class that is realized but not initialized by
516+
using a runtime function like `objc_getClass` before the class has been used.
517+
518+
See also: Mike Ash's blog post on
519+
[Objective-C Class Loading and Initialization](https://www.mikeash.com/pyblog/friday-qa-2009-05-22-objective-c-class-loading-and-initialization.html),
520+
which covers `+load` and `+initialize` in more detail.
521+
479522
## refutable pattern
480523

481524
A pattern that may not always match. These include patterns such as:

Diff for: docs/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ documentation, please create a thread on the Swift forums under the
177177
<!-- NOTE: Outdated -->
178178
- [Lexicon.md](/docs/Lexicon.md):
179179
Canonical reference for terminology used throughout the project.
180+
- [UnderscoredAttributes.md](/docs/ReferenceGuides/UnderscoredAttributes.md):
181+
Documents semantics for underscored (unstable) attributes.
180182

181183
### ABI
182184

0 commit comments

Comments
 (0)