Skip to content

Commit c39da37

Browse files
authored
Merge pull request #3474 from CodaFi/postminimalist-abstract-expressionism
[SE-0115] Rename *LiteralConvertible protocols to ExpressibleBy*…
2 parents 297853a + f97e5dc commit c39da37

File tree

104 files changed

+603
-536
lines changed

Some content is hidden

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

104 files changed

+603
-536
lines changed

docs/GenericsManifesto.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ extension Collection {
110110

111111
`let` constants could be allowed to have generic parameters, such that they produce differently-typed values depending on how they are used. For example, this is particularly useful for named literal values, e.g.,
112112

113-
```let π<T : FloatLiteralConvertible>: T = 3.141592653589793238462643383279502884197169399```
113+
```let π<T : ExpressibleByFloatLiteral>: T = 3.141592653589793238462643383279502884197169399```
114114

115115
The Clang importer could make particularly good use of this when importing macros.
116116

docs/Literals.rst

+15-15
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ is an NSWindow, there will only be one possible method named ``setTitle``,
2323
which takes an NSString. Therefore, we want the string literal expression to
2424
end up being an NSString.
2525

26-
Fortunately, NSString implements StringLiteralConvertible, so the type checker
26+
Fortunately, NSString implements ExpressibleByStringLiteral, so the type checker
2727
will indeed be able to choose NSString as the type of the string literal. All
2828
is well.
2929

@@ -32,41 +32,41 @@ infinite precision. Once the type has been chosen, the value is checked to see
3232
if it is in range for that type.
3333

3434

35-
The StringLiteralConvertible Protocol
35+
The ExpressibleByStringLiteral Protocol
3636
-------------------------------------
3737

38-
Here is the StringLiteralConvertible protocol as defined in the standard
38+
Here is the ExpressibleByStringLiteral protocol as defined in the standard
3939
library's CompilerProtocols.swift::
4040

4141
// NOTE: the compiler has builtin knowledge of this protocol
4242
// Conforming types can be initialized with arbitrary string literals.
43-
public protocol StringLiteralConvertible
44-
: ExtendedGraphemeClusterLiteralConvertible {
43+
public protocol ExpressibleByStringLiteral
44+
: ExpressibleByExtendedGraphemeClusterLiteral {
4545
46-
typealias StringLiteralType : _BuiltinStringLiteralConvertible
46+
typealias StringLiteralType : _ExpressibleByBuiltinStringLiteral
4747
// Create an instance initialized to `value`.
4848
init(stringLiteral value: StringLiteralType)
4949
}
5050

5151
Curiously, the protocol is not defined in terms of primitive types, but in
5252
terms of any StringLiteralType that the implementer chooses. In most cases,
5353
this will be Swift's own native String type, which means users can implement
54-
their own StringLiteralConvertible types while still dealing with a high-level
54+
their own ExpressibleByStringLiteral types while still dealing with a high-level
5555
interface.
5656

5757
(Why is this not hardcoded? A String *must* be a valid Unicode string, but
5858
if the string literal contains escape sequences, an invalid series of code
5959
points could be constructed...which may be what's desired in some cases.)
6060

6161

62-
The _BuiltinStringLiteralConvertible Protocol
62+
The _ExpressibleByBuiltinStringLiteral Protocol
6363
---------------------------------------------
6464

6565
CompilerProtocols.swift contains a second protocol::
6666

6767
// NOTE: the compiler has builtin knowledge of this protocol
68-
public protocol _BuiltinStringLiteralConvertible
69-
: _BuiltinExtendedGraphemeClusterLiteralConvertible {
68+
public protocol _ExpressibleByBuiltinStringLiteral
69+
: _ExpressibleByBuiltinExtendedGraphemeClusterLiteral {
7070

7171
init(
7272
_builtinStringLiteral start: Builtin.RawPointer,
@@ -82,9 +82,9 @@ data from the literal, and the arguments describe that raw data.
8282
So, the general runtime behavior is now clear:
8383

8484
1. The compiler generates raw string data.
85-
2. Some type conforming to _BuiltinStringLiteralConvertible is constructed from
85+
2. Some type conforming to _ExpressibleByBuiltinStringLiteral is constructed from
8686
the raw string data. This will be a standard library type.
87-
3. Some type conforming to StringLiteralConvertible is constructed from the
87+
3. Some type conforming to ExpressibleByStringLiteral is constructed from the
8888
object constructed in step 2. This may be a user-defined type. This is the
8989
result.
9090

@@ -101,7 +101,7 @@ This algorithm can go forwards or backwards, since it's actually defined in
101101
terms of constraints, but it's easiest to understand as a linear process.
102102

103103
1. Filter the types provided by the context to only include those that are
104-
StringLiteralConvertible.
104+
ExpressibleByStringLiteral.
105105
2. Using the associated StringLiteralType, find the appropriate
106106
``_convertFromBuiltinStringLiteral``.
107107
3. Using the type from step 1, find the appropriate
@@ -114,7 +114,7 @@ How about cases where there is no context? ::
114114

115115
Here we have nothing to go on, so instead the type checker looks for a global
116116
type named ``StringLiteralType`` in the current module-scope context, and uses
117-
that type if it is actually a StringLiteralConvertible type. This both allows
117+
that type if it is actually a ExpressibleByStringLiteral type. This both allows
118118
different standard libraries to set different default literal types, and allows
119119
a user to *override* the default type in their own source file.
120120

@@ -138,6 +138,6 @@ literal type is always Dictionary.
138138

139139
String interpolations are a bit different: they try to individually convert
140140
each element of the interpolation to the type that adopts
141-
StringInterpolationConvertible, then calls the variadic
141+
ExpressibleByStringInterpolation, then calls the variadic
142142
``convertFromStringInterpolation`` to put them all together. The default type
143143
for an interpolated literal without context is also ``StringLiteralType``.

docs/TextFormatting.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ used for ``Int``. It represents an example of how a relatively
259259
complicated ``format(…)`` might be written::
260260

261261
protocol CustomStringConvertibleInteger
262-
: IntegerLiteralConvertible, Comparable, SignedNumber, CustomStringConvertible {
262+
: ExpressibleByIntegerLiteral, Comparable, SignedNumber, CustomStringConvertible {
263263
func %(lhs: Self, rhs: Self) -> Self
264264
func /(lhs: Self, rhs: Self) -> Self
265265
constructor(x: Int)

docs/TypeChecker.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ can be converted [#]_.
638638
Default Literal Types
639639
..........................................
640640
If a type variable is bound by a conformance constraint to one of the
641-
literal protocols, "``T0`` conforms to ``IntegerLiteralConvertible``",
641+
literal protocols, "``T0`` conforms to ``ExpressibleByIntegerLiteral``",
642642
then the constraint solver will guess that the type variable can be
643643
bound to the default literal type for that protocol. For example,
644644
``T0`` would get the default integer literal type ``Int``, allowing
@@ -738,18 +738,18 @@ checking problem::
738738
This constraint system generates the constraints "``T(f)`` ==Fn ``T0
739739
-> T1``" (for fresh variables ``T0`` and ``T1``), "``(T2, X) <c
740740
T0``" (for fresh variable ``T2``) and "``T2`` conforms to
741-
``FloatLiteralConvertible``". As part of the solution, after ``T0`` is
741+
``ExpressibleByFloatLiteral``". As part of the solution, after ``T0`` is
742742
replaced with ``(i : Int, s : String)``, the second of
743743
these constraints is broken down into "``T2 <c Int``" and "``X <c
744744
String``". These two constraints are interesting for different
745745
reasons: the first will fail, because ``Int`` does not conform to
746-
``FloatLiteralConvertible``. The second will succeed by selecting one
746+
``ExpressibleByFloatLiteral``. The second will succeed by selecting one
747747
of the (overloaded) conversion functions.
748748

749749
In both of these cases, we need to map the actual constraint of
750750
interest back to the expressions they refer to. In the first case, we
751751
want to report not only that the failure occurred because ``Int`` is
752-
not ``FloatLiteralConvertible``, but we also want to point out where
752+
not ``ExpressibleByFloatLiteral``, but we also want to point out where
753753
the ``Int`` type actually came from, i.e., in the parameter. In the
754754
second case, we want to determine which of the overloaded conversion
755755
functions was selected to perform the conversion, so that conversion
@@ -816,7 +816,7 @@ important decisions made by the solver. However, the locators
816816
determined by the solver may not directly refer to the most specific
817817
expression for the purposes of identifying the corresponding source
818818
location. For example, the failed constraint "``Int`` conforms to
819-
``FloatLiteralConvertible``" can most specifically by centered on the
819+
``ExpressibleByFloatLiteral``" can most specifically by centered on the
820820
floating-point literal ``10.5``, but its locator is::
821821

822822
function application -> apply argument -> tuple element #0

docs/proposals/Enums.rst

+6-6
Original file line numberDiff line numberDiff line change
@@ -276,17 +276,17 @@ An enum can obtain a compiler-derived 'RawRepresentable' conformance by
276276
declaring "inheritance" from its raw type in the following
277277
circumstances:
278278

279-
- The inherited raw type must be IntegerLiteralConvertible,
280-
FloatLiteralConvertible, CharLiteralConvertible, and/or
281-
StringLiteralConvertible.
279+
- The inherited raw type must be ExpressibleByIntegerLiteral,
280+
ExpressibleByExtendedGraphemeClusterLiteral, ExpressibleByFloatLiteral,
281+
and/or ExpressibleByStringLiteral.
282282
- None of the cases of the enum may have non-void payloads.
283283

284284
If an enum declares a raw type, then its cases may declare raw
285285
values. raw values must be integer, float, character, or string
286286
literals, and must be unique within the enum. If the raw type is
287-
IntegerLiteralConvertible, then the raw values default to
287+
ExpressibleByIntegerLiteral, then the raw values default to
288288
auto-incrementing integer literal values starting from '0', as in C. If the
289-
raw type is not IntegerLiteralConvertible, the raw values must
289+
raw type is not ExpressibleByIntegerLiteral, the raw values must
290290
all be explicitly declared::
291291

292292
enum Color : Int {
@@ -302,7 +302,7 @@ all be explicitly declared::
302302

303303
enum NSChangeDictionaryKey : String {
304304
// All raw values are required because String is not
305-
// IntegerLiteralConvertible
305+
// ExpressibleByIntegerLiteral
306306
case NSKeyValueChangeKindKey = "NSKeyValueChangeKindKey"
307307
case NSKeyValueChangeNewKey = "NSKeyValueChangeNewKey"
308308
case NSKeyValueChangeOldKey = "NSKeyValueChangeOldKey"

include/swift/AST/DiagnosticsSema.def

+21-21
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,7 @@ ERROR(circular_enum_inheritance,none,
16111611
ERROR(raw_type_not_first,none,
16121612
"raw type %0 must appear first in the enum inheritance clause", (Type))
16131613
ERROR(raw_type_not_literal_convertible,none,
1614-
"raw type %0 is not convertible from any literal",
1614+
"raw type %0 is not expressible by any literal",
16151615
(Type))
16161616
ERROR(enum_raw_type_not_equatable,none,
16171617
"RawRepresentable 'init' cannot be synthesized because raw type %0 is not "
@@ -1639,8 +1639,8 @@ ERROR(objc_enum_raw_type_not_integer,none,
16391639
ERROR(enum_non_integer_raw_value_auto_increment,none,
16401640
"enum case must declare a raw value when the preceding raw value is not an integer", ())
16411641
ERROR(enum_non_integer_convertible_raw_type_no_value,none,
1642-
"enum cases require explicit raw values when the raw type is not integer "
1643-
"or string literal convertible", ())
1642+
"enum cases require explicit raw values when the raw type is not "
1643+
"expressible by integer or string literal", ())
16441644
ERROR(enum_raw_value_not_unique,none,
16451645
"raw value for enum case is not unique", ())
16461646
NOTE(enum_raw_value_used_here,none,
@@ -1663,7 +1663,7 @@ ERROR(broken_errortype_requirement,none,
16631663
ERROR(broken_int_hashable_conformance,none,
16641664
"Int type is broken: does not conform to Hashable", ())
16651665
ERROR(broken_int_integer_literal_convertible_conformance,none,
1666-
"Int type is broken: does not conform to IntegerLiteralConvertible", ())
1666+
"Int type is broken: does not conform to ExpressibleByIntegerLiteral", ())
16671667
ERROR(broken_equatable_eq_operator,none,
16681668
"Equatable protocol is broken: no infix operator declaration for '=='", ())
16691669
ERROR(no_equal_overload_for_int,none,
@@ -2014,10 +2014,10 @@ ERROR(optional_used_as_true_boolean,none,
20142014
"test for '== nil' instead", (Type))
20152015

20162016
ERROR(interpolation_missing_proto,none,
2017-
"string interpolation requires the protocol 'StringInterpolationConvertible' to be defined",
2017+
"string interpolation requires the protocol 'ExpressibleByStringInterpolation' to be defined",
20182018
())
20192019
ERROR(interpolation_broken_proto,none,
2020-
"protocol 'StringInterpolationConvertible' is broken",
2020+
"protocol 'ExpressibleByStringInterpolation' is broken",
20212021
())
20222022

20232023
ERROR(object_literal_broken_proto,none,
@@ -2049,44 +2049,44 @@ ERROR(specific_type_of_expression_is_ambiguous,none,
20492049
ERROR(missing_protocol,none,
20502050
"missing protocol %0", (Identifier))
20512051
ERROR(nil_literal_broken_proto,none,
2052-
"protocol 'NilLiteralConvertible' is broken", ())
2052+
"protocol 'ExpressibleByNilLiteral' is broken", ())
20532053

20542054
ERROR(builtin_integer_literal_broken_proto,none,
2055-
"protocol '_BuiltinIntegerLiteralConvertible' is broken", ())
2055+
"protocol '_ExpressibleByBuiltinIntegerLiteral' is broken", ())
20562056
ERROR(integer_literal_broken_proto,none,
2057-
"protocol 'IntegerLiteralConvertible' is broken", ())
2057+
"protocol 'ExpressibleByIntegerLiteral' is broken", ())
20582058

20592059
ERROR(builtin_float_literal_broken_proto,none,
2060-
"protocol '_BuiltinFloatLiteralConvertible' is broken", ())
2060+
"protocol '_ExpressibleByBuiltinFloatLiteral' is broken", ())
20612061
ERROR(float_literal_broken_proto,none,
2062-
"protocol 'FloatLiteralConvertible' is broken", ())
2062+
"protocol 'ExpressibleByFloatLiteral' is broken", ())
20632063

20642064
ERROR(builtin_boolean_literal_broken_proto,none,
2065-
"protocol '_BuiltinBooleanLiteralConvertible' is broken", ())
2065+
"protocol '_ExpressibleByBuiltinBooleanLiteral' is broken", ())
20662066
ERROR(boolean_literal_broken_proto,none,
2067-
"protocol 'BooleanLiteralConvertible' is broken", ())
2067+
"protocol 'ExpressibleByBooleanLiteral' is broken", ())
20682068

20692069
ERROR(builtin_unicode_scalar_literal_broken_proto,none,
2070-
"protocol '_BuiltinUnicodeScalarLiteralConvertible' is broken", ())
2070+
"protocol '_ExpressibleByBuiltinUnicodeScalarLiteral' is broken", ())
20712071
ERROR(unicode_scalar_literal_broken_proto,none,
2072-
"protocol 'UnicodeScalarLiteralConvertible' is broken", ())
2072+
"protocol 'ExpressibleByUnicodeScalarLiteral' is broken", ())
20732073

20742074
ERROR(builtin_extended_grapheme_cluster_literal_broken_proto,none,
2075-
"protocol '_BuiltinExtendedGraphemeClusterLiteralConvertible' is broken", ())
2075+
"protocol '_ExpressibleByBuiltinExtendedGraphemeClusterLiteral' is broken", ())
20762076
ERROR(extended_grapheme_cluster_literal_broken_proto,none,
2077-
"protocol 'ExtendedGraphemeClusterLiteralConvertible' is broken", ())
2077+
"protocol 'ExpressibleByExtendedGraphemeClusterLiteral' is broken", ())
20782078

20792079
ERROR(builtin_string_literal_broken_proto,none,
2080-
"protocol '_BuiltinStringLiteralConvertible' is broken", ())
2080+
"protocol '_ExpressibleByBuiltinStringLiteral' is broken", ())
20812081
ERROR(string_literal_broken_proto,none,
2082-
"protocol 'StringLiteralConvertible' is broken", ())
2082+
"protocol 'ExpressibleByStringLiteral' is broken", ())
20832083

20842084
ERROR(bool_type_broken,none,
20852085
"could not find a Bool type defined for 'is'", ())
20862086

20872087
// Array literals
20882088
ERROR(array_protocol_broken,none,
2089-
"ArrayLiteralConvertible protocol definition is broken", ())
2089+
"ExpressibleByArrayLiteral protocol definition is broken", ())
20902090
ERROR(type_is_not_array,none,
20912091
"contextual type %0 cannot be used with array literal", (Type))
20922092
NOTE(meant_dictionary_lit,none,
@@ -2096,7 +2096,7 @@ ERROR(should_use_empty_dictionary_literal,none,
20962096

20972097
// Dictionary literals
20982098
ERROR(dictionary_protocol_broken,none,
2099-
"DictionaryLiteralConvertible protocol definition is broken", ())
2099+
"ExpressibleByDictionaryLiteral protocol definition is broken", ())
21002100
ERROR(type_is_not_dictionary,none,
21012101
"contextual type %0 cannot be used with dictionary literal", (Type))
21022102

0 commit comments

Comments
 (0)