Skip to content

Commit e7c4003

Browse files
authored
[spec] Update GC allocating operations (#3911)
Add link to scope parameters for array literals. Add preview caveat for scope slice initialization from array literal. Use IMPLEMENTATION_DEFINED for allowing @nogc scope arguments. garbage.dd: Link to array literal @nogc uses. Mention `@nogc`.
1 parent 0f7681b commit e7c4003

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

spec/expression.dd

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,8 +2203,12 @@ $(H4 $(LNAME2 array-literal-heap, GC Allocation))
22032203
$(P An array literal is not GC allocated if:)
22042204

22052205
* It initializes or assigns to a static array.
2206-
* It initializes a $(DDSUBLINK spec/attribute, scope, `scope`) slice.
2207-
* It is used on one side of a $(GLINK EqualExpression) or $(GLINK RelExpression).
2206+
* It is an argument to a $(DDSUBLINK spec/function, scope-parameters, `scope`
2207+
function parameter).
2208+
* It initializes a $(DDSUBLINK spec/attribute, scope, `scope`) slice (`-preview=dip1000`
2209+
$(LINK2 $(ROOT_DIR)changelog/2.102.0.html#dmd.scope-array-on-stack,
2210+
is required for this)).
2211+
* It is used on one side of an $(GLINK EqualExpression) or $(GLINK RelExpression).
22082212
* It is immediately $(RELATIVE_LINK2 index_operations, indexed) and used as an rvalue.
22092213
* It is used as a `foreach` aggregate where the element variable is not `ref`.
22102214

spec/function.dd

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,10 +1931,11 @@ int* balin(scope int* q, int* r)
19311931
}
19321932
---
19331933

1934-
$(P As a `scope` parameter must not escape, the compiler can potentially avoid heap-allocating a
1934+
$(IMPLEMENTATION_DEFINED
1935+
As a `scope` parameter must not escape, the compiler can potentially avoid heap-allocating a
19351936
unique argument to a `scope` parameter. Due to this, passing an array literal, delegate
19361937
literal or a $(GLINK2 expression, NewExpression) to a scope parameter may be allowed in a
1937-
`@nogc` context, depending on the compiler implementation.)
1938+
`@nogc` context.)
19381939

19391940
$(H3 $(LNAME2 return-scope-parameters, Return Scope Parameters))
19401941

spec/garbage.dd

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,17 +372,20 @@ $(H2 D $(LNAME2 op_involving_gc, Operations That Involve the Garbage Collector))
372372
$(LI $(GLINK2 expression, NewExpression))
373373
$(LI Array appending)
374374
$(LI Array concatenation)
375-
$(LI Array literals (except when used to initialize static data))
375+
$(LI Array literals (see $(DDSUBLINK spec/expression, array-literal-heap, exceptions)))
376376
$(LI Associative array literals)
377377
$(LI Any insertion or removal in an associative array)
378378
$(LI Extracting keys or values from an associative array)
379-
$(LI Taking the address of (i.e. making a delegate to) a nested function that
379+
$(LI Taking the address of (i.e. making a delegate to) a nested function that
380380
accesses variables in an outer scope)
381381
$(LI A function literal that accesses variables in an outer scope)
382-
383382
$(LI An $(GLINK2 expression, AssertExpression) that fails its condition)
384383
)
385384

385+
$(P There is a $(DDSUBLINK spec/function, nogc-functions, `@nogc` function attribute)
386+
which will error at compile-time if any construct is used which would make a GC
387+
allocation.)
388+
386389
$(H2 $(LNAME2 gc_config, Configuring the Garbage Collector))
387390

388391
$(P Since version 2.067, The garbage collector can now be configured

0 commit comments

Comments
 (0)