@@ -1246,14 +1246,6 @@ int foo(in int x, out int y, ref int z, int q);
1246
1246
The parameter must not escape the function call
1247
1247
(e.g. by being assigned to a global variable).
1248
1248
Ignored for any parameter that is not a reference type.
1249
- `scope` escape analysis is only done for `@safe` functions. For other functions `scope`
1250
- semantics must be manually enforced.)
1251
- $(P $(B Note): `scope` escape analysis is currently only done by `dmd`
1252
- when the `-dip1000` switch is passed.)
1253
- $(P As the parameter must not escape, the compiler can potentially avoid heap-allocation of a
1254
- unique argument to a `scope` parameter. Due to this, passing an array literal, delegate
1255
- literal or a $(GLINK2 expression, NewExpression) to a scope parameter may be used in a
1256
- `@nogc` context, depending on the compiler implementation.)
1257
1249
))
1258
1250
$(TROW $(D return), $(ARGS Parameter may be returned or copied to the first parameter,
1259
1251
but otherwise does not escape from the function.
@@ -1545,35 +1537,60 @@ inout(int)* neptune(inout ref int i)
1545
1537
}
1546
1538
---
1547
1539
1548
- $(H3 $(LNAME2 return- scope-parameters, Return Scope Parameters))
1540
+ $(H3 $(LNAME2 scope-parameters, Scope Parameters))
1549
1541
1550
- $(P Parameters marked as `return scope` that contain indirections
1551
- can only escape those indirections via the function's return value.)
1542
+ $(P A `scope` parameter of reference type must not escape the function call
1543
+ (e.g. by being assigned to a global variable). It has no effect for non-reference types.
1544
+ `scope` escape analysis is only done for `@safe` functions. For other functions `scope`
1545
+ semantics must be manually enforced.)
1546
+ $(P $(B Note): `scope` escape analysis is currently only done by `dmd`
1547
+ when the `-dip1000` switch is passed.)
1552
1548
1553
1549
---
1554
1550
@safe:
1555
1551
1556
1552
int* gp;
1557
1553
void thorin(scope int*);
1558
1554
void gloin(int*);
1559
- int* balin(return scope int* p, scope int* q, int* r)
1555
+ int* balin(scope int* q, int* r)
1560
1556
{
1561
- gp = p; // error, p escapes to global gp
1562
1557
gp = q; // error, q escapes to global gp
1563
1558
gp = r; // ok
1564
1559
1565
- thorin(p); // ok, p does not escape thorin()
1566
- thorin(q); // ok
1560
+ thorin(q); // ok, q does not escape thorin()
1567
1561
thorin(r); // ok
1568
1562
1569
- gloin(p); // error, gloin() escapes p
1570
1563
gloin(q); // error, gloin() escapes q
1571
1564
gloin(r); // ok that gloin() escapes r
1572
1565
1573
- return p; // ok
1574
1566
return q; // error, cannot return 'scope' q
1575
1567
return r; // ok
1576
1568
}
1569
+ ---
1570
+
1571
+ $(P As a `scope` parameter must not escape, the compiler can potentially avoid heap-allocating a
1572
+ unique argument to a `scope` parameter. Due to this, passing an array literal, delegate
1573
+ literal or a $(GLINK2 expression, NewExpression) to a scope parameter may be allowed in a
1574
+ `@nogc` context, depending on the compiler implementation.)
1575
+
1576
+ $(H4 $(LNAME2 return-scope-parameters, Return Scope Parameters))
1577
+
1578
+ $(P Parameters marked as `return scope` that contain indirections
1579
+ can only escape those indirections via the function's return value.)
1580
+
1581
+ ---
1582
+ @safe:
1583
+
1584
+ int* gp;
1585
+ void thorin(scope int*);
1586
+ void gloin(int*);
1587
+ int* balin(return scope int* p)
1588
+ {
1589
+ gp = p; // error, p escapes to global gp
1590
+ thorin(p); // ok, p does not escape thorin()
1591
+ gloin(p); // error, gloin() escapes p
1592
+ return p; // ok
1593
+ }
1577
1594
---
1578
1595
1579
1596
$(P Class references are considered pointers that are subject to `scope`.)
@@ -1617,10 +1634,7 @@ class C
1617
1634
$(P Template functions, auto functions, nested functions and lambdas can deduce
1618
1635
the `return scope` attribute.)
1619
1636
1620
- $(P $(B Note:) Checks for `scope` parameters are currently enabled
1621
- only for $(D @safe) functions when compiled with the $(D -dip1000) flag.)
1622
-
1623
- $(H3 $(LNAME2 ref-return-scope-parameters, Ref Return Scope Parameters))
1637
+ $(H4 $(LNAME2 ref-return-scope-parameters, Ref Return Scope Parameters))
1624
1638
1625
1639
$(P Parameters marked as `ref return scope` come in two forms:)
1626
1640
0 commit comments