@@ -1767,16 +1767,16 @@ class Point {
1767
1767
return Math.Sqrt(dx * dx + dy * dy);
1768
1768
}
1769
1769
// Mutating method declaration
1770
- fn Offset[addr self: Self* ](dx: i32, dy: i32);
1770
+ fn Offset[ref self: Self](dx: i32, dy: i32);
1771
1771
1772
1772
var x: i32;
1773
1773
var y: i32;
1774
1774
}
1775
1775
1776
1776
// Out-of-line definition of method declared inline
1777
- fn Point.Offset[addr self: Self* ](dx: i32, dy: i32) {
1778
- self-> x += dx;
1779
- self-> y += dy;
1777
+ fn Point.Offset[ref self: Self](dx: i32, dy: i32) {
1778
+ self. x += dx;
1779
+ self. y += dy;
1780
1780
}
1781
1781
1782
1782
var origin: Point = {.x = 0, .y = 0};
@@ -1796,10 +1796,9 @@ two methods `Distance` and `Offset`:
1796
1796
- ` Distance ` computes and returns the distance to another point, without
1797
1797
modifying the ` Point ` . This is signified using ` [self: Self] ` in the method
1798
1798
declaration.
1799
- - ` origin.Offset( ` ...` ) ` does modify the value of ` origin ` . This is signified
1800
- using ` [addr self: Self*] ` in the method declaration. Since calling this
1801
- method requires taking the [ non-` const ` ] ( #const ) address of ` origin ` , it may
1802
- only be called on [ reference expressions] ( #expression-categories ) .
1799
+ - ` origin.Offset( ` ...` ) ` _ does_ modify the value of ` origin ` . This is
1800
+ signified using ` [ref self: Self] ` in the method declaration. It may only be
1801
+ called on [ reference expressions] ( #expression-categories ) .
1803
1802
- Methods may be declared lexically inline like ` Distance ` , or lexically out
1804
1803
of line like ` Offset ` .
1805
1804
@@ -1955,7 +1954,7 @@ names resolvable by the compiler, and don't act like forward declarations.
1955
1954
1956
1955
A destructor for a class is custom code executed when the lifetime of a value of
1957
1956
that type ends. They are defined with ` fn destroy ` followed by either
1958
- ` [self: Self] ` or ` [addr self: Self* ] ` (as is done with [ methods] ( #methods ) ) and
1957
+ ` [self: Self] ` or ` [ref self: Self] ` (as is done with [ methods] ( #methods ) ) and
1959
1958
the block of code in the class definition, as in:
1960
1959
1961
1960
``` carbon
@@ -1969,7 +1968,7 @@ or:
1969
1968
``` carbon
1970
1969
class MyClass {
1971
1970
// Can modify `self` in the body.
1972
- fn destroy[addr self: Self* ]() { ... }
1971
+ fn destroy[ref self: Self]() { ... }
1973
1972
}
1974
1973
```
1975
1974
@@ -2004,8 +2003,8 @@ For every type `MyClass`, there is the type `const MyClass` such that:
2004
2003
has type ` const T ` .
2005
2004
- While all of the member names in ` MyClass ` are also member names in
2006
2005
` const MyClass ` , the effective API of a ` const MyClass ` reference expression
2007
- is a subset of ` MyClass ` , because only ` addr ` methods accepting a
2008
- ` const Self* ` will be valid.
2006
+ is a subset of ` MyClass ` , because only ` ref ` methods accepting a
2007
+ ` const Self ` will be valid.
2009
2008
2010
2009
Note that ` const ` binds more tightly than postfix-` * ` for forming a pointer
2011
2010
type, so ` const MyClass* ` is equal to ` (const MyClass)* ` .
@@ -2996,8 +2995,8 @@ associated constant to represent the type of elements stored in the stack.
2996
2995
```
2997
2996
interface StackInterface {
2998
2997
let ElementType:! Movable;
2999
- fn Push[addr self: Self* ](value: ElementType);
3000
- fn Pop[addr self: Self* ]() -> ElementType;
2998
+ fn Push[ref self: Self](value: ElementType);
2999
+ fn Pop[ref self: Self]() -> ElementType;
3001
3000
fn IsEmpty[self: Self]() -> bool;
3002
3001
}
3003
3002
```
@@ -3008,14 +3007,14 @@ for the `ElementType` member of the interface using a `where` clause:
3008
3007
``` carbon
3009
3008
class IntStack {
3010
3009
extend impl as StackInterface where .ElementType = i32 {
3011
- fn Push[addr self: Self* ](value: i32);
3010
+ fn Push[ref self: Self](value: i32);
3012
3011
// ...
3013
3012
}
3014
3013
}
3015
3014
3016
3015
class FruitStack {
3017
3016
extend impl as StackInterface where .ElementType = Fruit {
3018
- fn Push[addr self: Self* ](value: Fruit);
3017
+ fn Push[ref self: Self](value: Fruit);
3019
3018
// ...
3020
3019
}
3021
3020
}
@@ -3043,8 +3042,8 @@ values of any type `T`:
3043
3042
3044
3043
``` carbon
3045
3044
class Stack(T:! type) {
3046
- fn Push[addr self: Self* ](value: T);
3047
- fn Pop[addr self: Self* ]() -> T;
3045
+ fn Push[ref self: Self](value: T);
3046
+ fn Pop[ref self: Self]() -> T;
3048
3047
3049
3048
var storage: Array(T);
3050
3049
}
0 commit comments