Skip to content

Commit

Permalink
Change f7819c8 to not hide behind a switch
Browse files Browse the repository at this point in the history
Such bug fix is hard to hide behind a deprecation warning as
it affects runtime behaviour without causing direct compilation
failure, thus extra migration help is provided via -transition=safe.
  • Loading branch information
Dicebot committed Oct 8, 2016
1 parent 748549e commit f55b4d9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
27 changes: 27 additions & 0 deletions changelog.dd
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,39 @@ $(BUGSTITLE Language Changes,
)

$(BUGSTITLE Compiler Changes,
$(LI $(RELATIVE_LINK2 iteration_closure, Assumes opApply delegate parameter escapes unless marked `scope`))
)

$(BUGSTITLE Language Changes,
)

$(BUGSTITLE Compiler Changes,
$(LI $(LNAME2 iteration_closure, Assumes opApply delegate parameter escapes unless marked `scope`)

$(P This breaking change was required to fix bug with `@safe` violation: $(BUGZILLA 16193).)

$(P To list all places where closure may be allocated after the change, use `-transition=safe`
compiler switch.)

$(P Example:)

---
struct S1 {
int opApply(int delegate(int) dg);
}

struct S2 {
int opApply(scope int delegate(int) dg);
}

void foo() {
foreach(i; S1.init) { // will allocate closure
}
foreach(i; S2.init) { // won't allocate closure
}
}
---
)
)

Macros:
Expand Down
11 changes: 10 additions & 1 deletion src/statementsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,16 @@ private extern (C++) final class StatementSemanticVisitor : Visitor
else
{
if (global.params.safe)
fld.tookAddressOf = 1; // allocate a closure unless the opApply() uses 'scope'
{
fprintf(
global.stdmsg,
"%s: To enforce @safe compiler allocates a closure unless the opApply() uses 'scope'\n",
loc.toChars()
);
fflush(global.stdmsg);
}
fld.tookAddressOf = 1;

assert(tab.ty == Tstruct || tab.ty == Tclass);
assert(sapply);
/* Call:
Expand Down
7 changes: 5 additions & 2 deletions test/fail_compilation/test16193.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ REQUIRED_ARGS: -transition=safe
PERMUTE_ARGS:
TEST_OUTPUT:
---
fail_compilation/test16193.d(36): Error: function test16193.abc is @nogc yet allocates closures with the GC
fail_compilation/test16193.d(38): test16193.abc.__foreachbody1 closes over variable x at fail_compilation/test16193.d(37)
fail_compilation/test16193.d(22): To enforce @safe compiler allocates a closure unless the opApply() uses 'scope'
fail_compilation/test16193.d(34): To enforce @safe compiler allocates a closure unless the opApply() uses 'scope'
fail_compilation/test16193.d(41): To enforce @safe compiler allocates a closure unless the opApply() uses 'scope'
fail_compilation/test16193.d(39): Error: function test16193.abc is @nogc yet allocates closures with the GC
fail_compilation/test16193.d(41): test16193.abc.__foreachbody1 closes over variable x at fail_compilation/test16193.d(40)
---
*/

Expand Down

0 comments on commit f55b4d9

Please sign in to comment.