Skip to content

Commit 3d4c125

Browse files
committed
Rename 'byref' attribute to 'inout'.
Swift SVN r8661
1 parent f109476 commit 3d4c125

Some content is hidden

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

70 files changed

+338
-336
lines changed

Diff for: docs/ABI.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ types where the metadata itself has unknown layout.)
255255
type ::= 'M' type // metatype
256256
type ::= 'P' protocol-list '_' // protocol type
257257
type ::= archetype
258-
type ::= 'R' type // byref
258+
type ::= 'R' type // inout
259259
type ::= 'T' tuple-element* '_' // tuple
260260
type ::= 't' tuple-element* '_' // variadic tuple
261261
type ::= 'U' generics '_' type // generic type

Diff for: docs/LangRef.html

+7-7
Original file line numberDiff line numberDiff line change
@@ -1451,7 +1451,7 @@ <h3 id="attribute-list">Attribute Lists</h3>
14511451

14521452
attribute ::= attribute-infix
14531453
attribute ::= attribute-resilience
1454-
attribute ::= attribute-byref
1454+
attribute ::= attribute-inout
14551455
attribute ::= attribute-auto_closure
14561456
attribute ::= attribute-noreturn
14571457
</pre>
@@ -1492,19 +1492,19 @@ <h4 id="attribute-resilence">Resilience Attribute</h4>
14921492
<p>See the resilience design.</p>
14931493

14941494
<!-- _____________________________________________________________________ -->
1495-
<h4 id="attribute-byref">By-Reference Attribute</h4>
1495+
<h4 id="attribute-inout">By-Reference Attribute</h4>
14961496

14971497
<pre class="grammar">
1498-
attribute-byref ::= 'byref'
1498+
attribute-inout ::= 'inout'
14991499
</pre>
15001500

1501-
<p><tt>byref</tt> is only valid in a <tt>type-annotation</tt> that
1501+
<p><tt>inout</tt> is only valid in a <tt>type-annotation</tt> that
15021502
appears within either a <a href="#pattern"><tt>pattern</tt></a> of
15031503
a <tt>function-signature</tt> or the input type of a function
15041504
type.
15051505
</p>
15061506

1507-
<p><tt>byref</tt> indicates that the argument will be passed "by
1507+
<p><tt>inout</tt> indicates that the argument will be passed "by
15081508
reference": the bound variable will be an l-value.</p>
15091509

15101510
<p>The type being annotated must be <a href="#materializable">materializable</a>.
@@ -1649,7 +1649,7 @@ <h3>Materializable Types</h3>
16491649

16501650
<p id="materializable">A type may be <i>materializable</i>. A type
16511651
is materializable unless it is 1) annotated with
1652-
a <a href="#attribute-byref"><tt>byref</tt></a> attribute or 2) a
1652+
a <a href="#attribute-inout"><tt>inout</tt></a> attribute or 2) a
16531653
tuple with a non-materializable element type. In general, variables
16541654
must have materializable type.</p>
16551655

@@ -2221,7 +2221,7 @@ <h3 id="pattern-var">'var' Patterns</h3>
22212221
<p>The type of a bound variable must be
22222222
<a href="#materializable">materializable</a> unless it appears in a
22232223
<a href="#function-signature">function-signature</a> and is directly of
2224-
a <a href="attribute-byref"><tt>byref</tt></a>-annotated type.</p>
2224+
a <a href="attribute-inout"><tt>inout</tt></a>-annotated type.</p>
22252225

22262226
<!-- ********************************************************************* -->
22272227
<h3 id="pattern-tuple">Tuple Patterns</h3>

Diff for: docs/LogicalObjects.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ ways.
4545
For example, methods on value types have a this parameter. Usually parameters
4646
are values, but this is actually an object: if I call a method on an object, and
4747
the method modifies the value of this, I expect it to modify the object I called
48-
the method on. This is the high-level perspective of what [byref] really means:
48+
the method on. This is the high-level perspective of what [inout] really means:
4949
that what we're really passing as a parameter is an object, not a value. With
50-
one exception, everything that follows applies to any sort of [byref] parameter,
50+
one exception, everything that follows applies to any sort of [inout] parameter,
5151
not just this on value types. More on that exception later.
5252

5353
How do you actually pass an object, though, given that even physical objects
@@ -73,12 +73,12 @@ means materialization: calling the getter, storing the result into temporary
7373
memory, passing the temporary, and then calling the setter with the new value in
7474
the temporary when the method call is done. This last step is called writeback.
7575

76-
(About that one exception to this all applying equally to [byref]: in addition
76+
(About that one exception to this all applying equally to [inout]: in addition
7777
to all this stuff about calling methods on different kinds of object, we also
7878
want to support calling a method on a value. This is also implemented with a
7979
form of materialization, which looks just like the logical-object kind except
8080
without writeback, because there's nothing to write back to. This is a special
8181
rule that only applies to passing this, because we assume that most types will
8282
have lots of useful methods that don't involve writing to this, whereas we
83-
assume that a function with an explicit [byref] parameter is almost certain to
83+
assume that a function with an explicit [inout] parameter is almost certain to
8484
want to write to it.)

Diff for: docs/Objective-C Interoperability.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ Output Parameters
435435
here: with ARC, the tuple owns the objects in it, and the caller owns the
436436
tuple.
437437

438-
Swift currently also has ``[byref]`` arguments. Whether or not these will be
438+
Swift currently also has ``[inout]`` arguments. Whether or not these will be
439439
exposed to users and/or used for Objective-C out parameters is still
440440
undecided.
441441

Diff for: docs/SIL.rst

+8-8
Original file line numberDiff line numberDiff line change
@@ -731,27 +731,27 @@ The types of the SIL entry points are as follows::
731731
sil @curried_2 : $((z:C), (y:B), (x:A)) -> (w:D) -> Int { ... }
732732
sil @curried_3 : $((w:D), (z:C), (y:B), (x:A)) -> Int { ... }
733733

734-
Byref Arguments
735-
```````````````
734+
[inout] Arguments
735+
`````````````````
736736

737-
``[byref]`` arguments are passed into the entry point by address. The callee
737+
``[inout]`` arguments are passed into the entry point by address. The callee
738738
does not take ownership of the referenced memory. The referenced memory must
739-
be initialized upon function entry and exit. If the ``[byref]`` argument
739+
be initialized upon function entry and exit. If the ``[inout]`` argument
740740
refers to a fragile physical variable, then the argument is the address of that
741-
variable. If the ``[byref]`` argument refers to a logical property, then the
741+
variable. If the ``[inout]`` argument refers to a logical property, then the
742742
argument is the address of a caller-owner writeback buffer. it is the caller's
743743
responsibility to initialize the buffer by storing the result of the property
744744
getter prior to calling the function and to write back to the property
745745
on return by loading from the buffer and invoking the setter with the final
746746
value. This Swift function::
747747

748-
func byref(x:[byref] Int) {
748+
func inout(x:[inout] Int) {
749749
x = 1
750750
}
751751

752752
gets lowered to SIL as::
753753

754-
sil @byref : $([byref] Int) -> () {
754+
sil @inout : $([inout] Int) -> () {
755755
entry(%x : $*Int):
756756
%1 = integer_literal 1 : $Int
757757
store %1 to %x
@@ -771,7 +771,7 @@ passed last::
771771
func method(x:Int) -> Int {}
772772
}
773773

774-
sil @Foo_method_1 : $((x : Int), [byref] Foo) -> Int { ... }
774+
sil @Foo_method_1 : $((x : Int), [inout] Foo) -> Int { ... }
775775

776776
C Calling Convention [cc(cdecl)]
777777
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Diff for: docs/StringDesign.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ Building
932932
:Swift:
933933
.. parsed-literal::
934934
func **+** (lhs: String, rhs: String) -> String
935-
func [infix,assignment] **+=** (lhs: [byref] String, rhs: String)
935+
func [infix,assignment] **+=** (lhs: [inout] String, rhs: String)
936936
func **append**\ (suffix: String)
937937
938938

Diff for: docs/TextFormatting.rst

+9-9
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ representation before writing an object to a stream, we provide a
200200
naturally ::
201201

202202
protocol Streamable : Printable {
203-
func writeTo<T: OutputStream>(target: [byref] T)
203+
func writeTo<T: OutputStream>(target: [inout] T)
204204

205205
// You'll never want to reimplement this
206206
func format() -> PrintRepresentation {
@@ -223,7 +223,7 @@ adds surrounding quotes and escapes special characters::
223223
struct EscapedStringRepresentation : Streamable {
224224
var _value: String
225225

226-
func writeTo<T: OutputStream>(target: [byref] T) {
226+
func writeTo<T: OutputStream>(target: [inout] T) {
227227
target.append("\"")
228228
for c in _value {
229229
target.append(c.escape())
@@ -236,7 +236,7 @@ Besides modeling ``OutputStream``, ``String`` also conforms to
236236
``Streamable``::
237237

238238
extension String : Streamable {
239-
func writeTo<T: OutputStream>(target: [byref] T) {
239+
func writeTo<T: OutputStream>(target: [inout] T) {
240240
target.append(self) // Append yourself to the stream
241241
}
242242

@@ -274,13 +274,13 @@ complicated ``format(…)`` might be written::
274274
struct RadixFormat<T: PrintableInteger> : Streamable {
275275
var value: T, radix = 10, fill = " ", width = 0
276276

277-
func writeTo<S: OutputStream>(target: [byref] S) {
277+
func writeTo<S: OutputStream>(target: [inout] S) {
278278
_writeSigned(value, &target)
279279
}
280280

281281
// Write the given positive value to stream
282282
func _writePositive<T:PrintableInteger, S: OutputStream>(
283-
value: T, stream: [byref] S
283+
value: T, stream: [inout] S
284284
) -> Int {
285285
if value == 0 { return 0 }
286286
var radix: T = T.fromInt(self.radix)
@@ -293,7 +293,7 @@ complicated ``format(…)`` might be written::
293293
}
294294

295295
func _writeSigned<T:PrintableInteger, S: OutputStream>(
296-
value: T, target: [byref] S
296+
value: T, target: [inout] S
297297
) {
298298
var width = 0
299299
var result = ""
@@ -371,7 +371,7 @@ For every conceivable ``OutputStream`` adaptor there's a corresponding
371371
struct UpperStreamable<UnderlyingStreamable:Streamable> {
372372
var base: UnderlyingStreamable
373373

374-
func writeTo<T: OutputStream>(target: [byref] T) {
374+
func writeTo<T: OutputStream>(target: [inout] T) {
375375
var adaptedStream = UpperStream(target)
376376
self.base.writeTo(&adaptedStream)
377377
target = adaptedStream.base
@@ -417,7 +417,7 @@ least until we do, we opt not to trade away any CPU, memory, and
417417
power.
418418

419419
If we were willing to say that only ``class``\ es can conform to
420-
``OutputStream``, we could eliminate the explicit ``[byref]`` where
420+
``OutputStream``, we could eliminate the explicit ``[inout]`` where
421421
``OutputStream``\ s are passed around. Then, we'd simply need a
422422
``class StringStream`` for creating ``String`` representations. It
423423
would also make ``OutputStream`` adapters a *bit* simpler to use
@@ -430,7 +430,7 @@ the underlying stream, which can then be “written back.” :
430430
431431
struct AdaptedStreamable<T:Streamable> {
432432
...
433-
func writeTo<Target: OutputStream>(target: [byref] Target) {
433+
func writeTo<Target: OutputStream>(target: [inout] Target) {
434434
// create the stream that transforms the representation
435435
var adaptedTarget = adapt(target, adapter);
436436
// write the Base object to the target stream

Diff for: docs/TypeChecker.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ the Swift type system:
7777
- Exact equality constraints, or "binding", written ``T0 := X``
7878
for some type variable ``T0`` and type ``X``, which requires
7979
that ``T0`` be exactly identical to ``X``;
80-
- Equality constraints, written ``X == Y`` for types ``X`` and ``Y``, which require ``X`` and ``Y`` to have the same type, ignoring lvalue types in the process. For example, the constraint ``T0 == X`` would be satisfied by assigning ``T0`` the type ``X`` and by assigning ``T0`` the type ``[byref] X``.
80+
- Equality constraints, written ``X == Y`` for types ``X`` and ``Y``, which require ``X`` and ``Y`` to have the same type, ignoring lvalue types in the process. For example, the constraint ``T0 == X`` would be satisfied by assigning ``T0`` the type ``X`` and by assigning ``T0`` the type ``[inout] X``.
8181

8282
**Subtyping**
8383
A subtype constraint requires the first type to be equivalent to or
@@ -150,7 +150,7 @@ and types generated from the primary expression kinds are:
150150
An expression that refers to a declaration ``x`` is assigned the
151151
type of a reference to ``x``. For example, if ``x`` is declared as
152152
``var x : Int``, the expression ``x`` is assigned the type
153-
``[byref(implicit)] Int``. No constraints are generated.
153+
``[inout(implicit)] Int``. No constraints are generated.
154154

155155
When a name refers to a set of overloaded declarations, the
156156
selection of the appropriate declaration is handled by the
@@ -256,9 +256,9 @@ and types generated from the primary expression kinds are:
256256
type.
257257

258258
**Address of**
259-
An address-of expression ``&a`` always returns a ``[byref]``
260-
type. Therefore, it is assigned the type ``[byref] T0`` for a fresh
261-
type variable ``T0``. The subtyping constraint ``[byref] T0 <
259+
An address-of expression ``&a`` always returns a ``[inout]``
260+
type. Therefore, it is assigned the type ``[inout] T0`` for a fresh
261+
type variable ``T0``. The subtyping constraint ``[inout] T0 <
262262
T(a)`` captures the requirement that input expression be an lvalue
263263
of some type.
264264

Diff for: docs/classes.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ type of this declaration is
261261
``(NSRect, owner : Id, withUserData : Id, assumeInside : Bool) -> Void``.
262262
This syntax is just sugar to allow giving arguments sane names for
263263
the implementation and possibly for documentation. Being able to rename
264-
for the implementation is particularly important for byref arguments,
264+
for the implementation is particularly important for inout arguments,
265265
because they can't easily be renamed with a var decl in the implementation.
266266

267267
The basic weakness here is that it requires a syntax extension to function

Diff for: docs/proposals/Inplace.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ boilerplate::
231231

232232
// ...without typing all this
233233
operator infix ☃= { assignment }
234-
func ☃=(x:[byref] Int, y:Int) {
234+
func ☃=(x:[inout] Int, y:Int) {
235235
x = x ☃ y
236236
}
237237

@@ -291,11 +291,11 @@ When an in-place relationship is created, a definition matching either the
291291
in-place or value-creating form introduces an implicit definition of the other
292292
form::
293293

294-
func += (x:[byref] String, y:String) { ... }
294+
func += (x:[inout] String, y:String) { ... }
295295
// Implicitly defines func + (x:String, y:String) -> String
296296

297297
func + (x:Int, y:Int) -> Int { ... }
298-
// Implicitly defines func += (x:[byref] Int, y:Int) -> ()
298+
// Implicitly defines func += (x:[inout] Int, y:Int) -> ()
299299

300300
struct String {
301301
func upper() -> String { ... }
@@ -329,7 +329,7 @@ in-place form, as if written::
329329
The implicit in-place form applies the value-creating form to its arguments and
330330
assigns the result to its left argument, as if written::
331331

332-
func += (x:[byref] Int, y:Int) {
332+
func += (x:[inout] Int, y:Int) {
333333
x = x + y
334334
}
335335

Diff for: docs/proposals/Memory and Concurrency Model.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ definition. These kinds are:
4848
compiler rejects) immutable data that is pointing to mutable data. For
4949
example::
5050

51-
struct [immutable,byref] IList { data : int, next : List }
51+
struct [immutable,inout] IList { data : int, next : List }
5252
...
5353
var a = IList(1, IList(2, IList(3, nil)))
5454
...
@@ -57,7 +57,7 @@ definition. These kinds are:
5757
a = IList(2, IList(3, nil)) // ok, "a" itself is mutable, it now points to something new.
5858
a = IList(1, a) // ok
5959

60-
Strings are a very important example of (byref) immutable data.
60+
Strings are a very important example of (inout) immutable data.
6161

6262

6363

@@ -68,7 +68,7 @@ definition. These kinds are:
6868
synchronization or atomic accesses are ever required for any mutable
6969
data. For example::
7070

71-
struct [byref] MEntry { x : int, y : int, list : IList }
71+
struct [inout] MEntry { x : int, y : int, list : IList }
7272
...
7373
var b = MEntry(4, 2, IList(1, nil))
7474
b.x = 4 // ok

Diff for: docs/proposals/ValueSemantics.rst

+7-7
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ Here’s a version of cycle_length that works when state is a mutable
177177
value type::
178178

179179
func cycle_length<State>(
180-
s : State, mutate : ( [byref] State )->()
180+
s : State, mutate : ( [inout] State )->()
181181
) -> Int
182182
requires State : EqualityComparable
183183
{
@@ -209,7 +209,7 @@ classes:
209209
}
210210
211211
func cycle_length<State>(
212-
s : State, mutate : ( [byref] State )->()
212+
s : State, mutate : ( [inout] State )->()
213213
) -> Int
214214
requires State : EqualityComparable, **Clonable**
215215
{
@@ -221,7 +221,7 @@ classes:
221221
222222
RandomNumberGenerator x = new MersenneTwister()
223223
println(
224-
cycle_length(x, (x : [byref] RandomNumberGenerator) { x.nextValue() })
224+
cycle_length(x, (x : [inout] RandomNumberGenerator) { x.nextValue() })
225225
)
226226
227227
You could also redefine the interface so that it works on both values and
@@ -232,7 +232,7 @@ clonable classes:
232232
func cycle_length<State>(
233233
s : State,
234234
**next : (x : State)->State,**
235-
**equal : ([byref] x : State, [byref] y : State)->Bool**
235+
**equal : ([inout] x : State, [inout] y : State)->Bool**
236236
) -> Int
237237
requires State : EqualityComparable
238238
{
@@ -270,7 +270,7 @@ linked list::
270270

271271
We can measure the length of a cycle in these nodes as follows::
272272

273-
cycle_length( someNode, (x: [byref] Node){ x = x.next } )
273+
cycle_length( someNode, (x: [inout] Node){ x = x.next } )
274274

275275
This is why so many generic algorithms seem to work on both
276276
``class``\ es and non-``class``\ es: ``class`` *identities*
@@ -293,7 +293,7 @@ to observe a difference in behavior:
293293
Take, for example, `swap`, which uses variable initialization and
294294
assignment to exchange two values::
295295

296-
func swap<T>(lhs : [byref] T, rhs : [byref] T)
296+
func swap<T>(lhs : [inout] T, rhs : [inout] T)
297297
{
298298
var tmp = lhs // big 3: initialization - ref copy in tmp
299299
lhs = rhs // big 3: assignment - ref copy in lhs
@@ -337,7 +337,7 @@ If we make `X` a `class`, we automatically get reference semantics, so
337337
its value must be copied before each mutation, which is tedious and
338338
error-prone. Its public mutating interface must be in terms of free
339339
functions (not methods), so that the original reference value can be
340-
passed `[byref]` and overwritten. Since there's no user access to the
340+
passed `[inout]` and overwritten. Since there's no user access to the
341341
reference count, we can't determine that we hold the only reference to
342342
the value, so we can't optimize copy-on-write, even in single-threaded
343343
programs. In multi-threaded programs, where each mutation implies

0 commit comments

Comments
 (0)