Skip to content

Commit e18c0c4

Browse files
committed
docs: Update Lexicon.md to clarify 'canonical type', and add 'reduced type'
1 parent a8cef44 commit e18c0c4

File tree

1 file changed

+88
-22
lines changed

1 file changed

+88
-22
lines changed

docs/Lexicon.md

Lines changed: 88 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,14 @@ This can be used as input to IRGen to generate LLVM IR or object files.
106106

107107
## canonical type
108108

109-
A unique representation of a type, with any [sugar](#sugared-type) removed.
110-
These can usually be directly compared to test whether two types are the
111-
same; the exception is when generics get involved. In this case you'll need
112-
a [generic environment](#generic-environment). Contrast with [sugared type](#sugared-type).
109+
A type with [sugar](#sugared-type) removed. These can be compared for
110+
pointer equality to test whether two types are equivalent in the language
111+
semantics.
112+
113+
Note that canonical types are independent of the generic signature, so
114+
two [type parameters](#type-parameter) that are spelled differently but
115+
related by a same-type requirement are not canonically equal. However,
116+
they will have the same [reduced type](#reduced-type).
113117

114118
## Clang importer
115119

@@ -120,17 +124,19 @@ running inside the Swift compiler, which is also used during IRGen.
120124
## conformance
121125

122126
A construct detailing how a particular type conforms to a particular
123-
protocol. Represented in the compiler by the ProtocolConformance type at
124-
the AST level. See also [witness table](#witness-table).
127+
protocol. Represented in the compiler by the `ProtocolConformanceRef` type`.
128+
See also [witness table](#witness-table).
125129

126130
## contextual type
127131

132+
This has two unrelated meanings:
133+
128134
1. The expected type for a Swift sub-expression based on the rest of the
129135
statement. For example, in the statement `print(6 * 9)`, the contextual
130136
type of the expression `6 * 9` is `Any`.
131-
2. The type of a value or declaration from inside a potentially generic
132-
context. This type may contain [archetypes](#archetype) and cannot be
133-
used directly from outside the context. Compare with [interface type](#interface-type).
137+
2. A type that does not contain [type parameters](#type-parameters), but may
138+
contain [archetypes](#archetype). Compare with
139+
[interface type](#interface-type).
134140

135141
## critical edge
136142

@@ -176,7 +182,14 @@ one half of the necessary information to complete a full dependency edge.
176182
The other half is provided by corresponding
177183
[dependency sink](#dependency-sink) requests.
178184

179-
## DI (definite initialization / definitive initialization)
185+
## dependent member type
186+
187+
One of the two kinds of [type parameters](#type-parameters). Consists of a
188+
base type, together with the name of an associated type. The base type is
189+
some other type parameter, and the associated type must be declared in some
190+
protocol that the base type conforms to.
191+
192+
## DI (definite initialization)
180193

181194
The feature that no uninitialized variables, constants, or properties will
182195
be read by a program, or the analysis pass that operates on [SIL](#sil) to
@@ -202,6 +215,30 @@ the same bug ("I have a dup of this"); as a verb, the act of marking a bug
202215
written "dupe". Pronounced the same way as the first syllable of
203216
"duplicate", which for most American English speakers is "doop".
204217

218+
## equivalence class
219+
220+
Given an [equivalence relation](#equivalence-relation) over some set, together
221+
with an element of that set, the equivalence class of that element is the subset
222+
of all elements equivalent to this element.
223+
224+
A fact of mathematics is that every element of the set belongs to exactly one
225+
equivalence class, so the equivalence classes form a disjoint partition of the set.
226+
227+
## equivalence relation
228+
229+
A relation `R` over some set `S` is an _equivalence relation_ if:
230+
231+
1. It is _reflexive_, which means that for all `x` in `S`, we have `x R x`.
232+
2. It is _symmetric_, which means that any `x` and `y` in `S` that satisfy `x R y`
233+
also satisfy `y R x`.
234+
3. It is _transitive_, which means that for any `x`, `y`, and `z` in `S` that
235+
satisfy `x R y` and `y R z`, we have `x R z`.
236+
237+
Most of the time, the notion of value equality in programming defines an
238+
equivalence relation over the values of some type. A notable exception is
239+
floating point equality, which fails to be reflexive, because under the
240+
rules of IEEE floating point arithmetic, a NaN value is not equal to itself.
241+
205242
## existential type
206243

207244
A type that is a protocol composition (including a single protocol and *zero* protocols; the latter is the `Any` type).
@@ -217,6 +254,13 @@ passed to the compiler explicitly by an external build system, including
217254
any modules in caches. See also: [implicit module build](#implicit-module-build)
218255
and [fast dependency scanner](#fast-dependency-scanner).
219256

257+
## generic parameter type
258+
259+
One of the two kinds of [type parameters](#type-parameters). Declared within a
260+
generic parameter list, like `<T, U>`, attached to a generic declaration like
261+
`struct Pair<T, U> {...}`. Uniquely identified within its lexical scope by two
262+
integers, called the _depth_ and the _index_ of the generic parameter type.
263+
220264
## fast dependency scanner
221265

222266
A Swift compiler mode that scans a Swift module for import declarations and
@@ -242,19 +286,16 @@ Describes contributions which fix code that is not executed
242286

243287
## generic environment
244288

245-
Provides context for interpreting a type that may have generic parameters
246-
in it. Generic parameter types are normally just represented as "first
247-
generic parameter in the outermost context" (or similar), so it's up to the
248-
generic environment to note that type must be a Collection. (Another
249-
way of looking at it is that the generic environment connects
250-
[interface types](#interface-type) with
251-
[contextual types](#contextual-type)).
289+
A mapping from [type parameters](#type-parameter) to [archetypes](#archetypes).
290+
Every generic signature has a _primary_ generic environment associated with it.
291+
292+
Other kinds of generic environments exist for instantiating archetypes that
293+
represent opaque return types, and opened existentials.
252294

253295
## generic signature
254296

255-
A representation of all generic parameters and their requirements. Like
256-
types, generic signatures can be [canonicalized](#canonical-type) to be
257-
compared directly.
297+
A representation of all generic parameters and the requirements imposed upon
298+
them within the lexical scope of a declaration.
258299

259300
## GOT
260301

@@ -270,7 +311,8 @@ to describe the way it forms references to global objects that may or may not be
270311

271312
## iff
272313

273-
["if and only if"](https://en.wikipedia.org/wiki/If_and_only_if). This term comes from mathematics.
314+
["if and only if"](https://en.wikipedia.org/wiki/If_and_only_if).
315+
This term comes from mathematics.
274316

275317
## implicit module build
276318

@@ -558,6 +600,18 @@ See also: Mike Ash's blog post on
558600
[Objective-C Class Loading and Initialization](https://www.mikeash.com/pyblog/friday-qa-2009-05-22-objective-c-class-loading-and-initialization.html),
559601
which covers `+load` and `+initialize` in more detail.
560602

603+
## reduced type
604+
605+
A [canonical type](#canonical-type) which has been further simplified with
606+
respect to a [generic signature](#generic-signature), by performing two
607+
transformations until fixed point:
608+
1. Replacing type parameters fixed to concrete types with those concrete type.s
609+
2. Replacing all other type parameters with the smallest member of their
610+
[equivalence class](#equivalence-class), chosen according to a well-founded
611+
linear order.
612+
613+
See also [sugared type](#sugared-type).
614+
561615
## refutable pattern
562616

563617
A pattern that may not always match. These include patterns such as:
@@ -620,7 +674,9 @@ A type that may have been written in a more convenient way, using special
620674
language syntax or a typealias. (For example, `Int?` is the sugared form
621675
of `Optional<Int>`.) Sugared types preserve information about the form
622676
and use of the type even though the behavior usually does not change
623-
(except for things like access control). Contrast with [canonical type](#canonical-type).
677+
(except for things like access control).
678+
679+
See also [canonical type](#canonical-type), [reduced type](#reduced-type).
624680

625681
## TBD
626682

@@ -651,6 +707,16 @@ out-of-bounds index on an Array results in a trap") and a verb
651707
The runtime representation of a type, and everything you can do with it.
652708
Like a `Class` in Objective-C, but for any type.
653709

710+
## type parameter
711+
712+
A type that can be used within the body of a generic declaration, that
713+
abstracts over a concrete replacement type provided by the caller of a
714+
generic declaration.
715+
716+
More specifically, a type parameter is either a
717+
[generic parameter type](#generic-parameter-type), or a
718+
[dependent member type](#dependent-member-type).
719+
654720
## USR
655721

656722
A Unified Symbol Resolution (USR) is a string that identifies a particular

0 commit comments

Comments
 (0)