dmd icon indicating copy to clipboard operation
dmd copied to clipboard

Fix issue 21737: shared opApply does not compile

Open thewilsonator opened this issue 4 years ago • 7 comments

cc @TurkeyMan

thewilsonator avatar Mar 20 '21 00:03 thewilsonator

Thanks for your pull request and interest in making D better, @thewilsonator! We are looking forward to reviewing it, and you should be hearing from a maintainer soon. Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Auto-close Bugzilla Severity Description
21737 enhancement shared opApply does not compile

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#12290"

dlang-bot avatar Mar 20 '21 00:03 dlang-bot

This seems to work:

diff --git a/src/dmd/statementsem.d b/src/dmd/statementsem.d
index c2e83c58c..dc4b788be 100644
--- a/src/dmd/statementsem.d
+++ b/src/dmd/statementsem.d
@@ -2036,6 +2036,8 @@ else
         fs.cases = new Statements();
         fs.gotos = new ScopeStatements();
         auto fld = new FuncLiteralDeclaration(fs.loc, fs.endloc, tf, TOK.delegate_, fs);
+        if (tfld && tfld.isShared())
+             fld.storage_class |= STC.shared_;
         fld.fbody = fs._body;
         Expression flde = new FuncExp(fs.loc, fld);
         flde = flde.expressionSemantic(sc);

BorisCarvajal avatar Mar 20 '21 17:03 BorisCarvajal

Indeed it does. Thanks. FYI when pasting diffs after the three ` put diff to get the syntax highlights (i've done that for you here).

thewilsonator avatar Mar 21 '21 02:03 thewilsonator

Lightbulb: function (as opposed to function pointers) are immutable.

thewilsonator avatar Apr 05 '21 01:04 thewilsonator

I'm not so sure making this compile is a good idea. Many very reasonable shared access ideas turned out to be fundamentally broken years later.

WalterBright avatar Apr 05 '21 06:04 WalterBright

Honestly, I'd wish we could deprecate the entire opApply thing.

RazvanN7 avatar Apr 08 '21 11:04 RazvanN7

The error is:

Test 'compilable/issue21737.d' failed. The logged output:
dmd -conf= -m64 -Icompilable -preview=nosharedaccess  -fPIC  -odgenerated/compilable -ofgenerated/compilable/issue21737_0.o  -c compilable/issue21737.d 
druntime/import/core/atomic.d(582): Error: direct access to shared `val` is not allowed, see `core.atomic`
compilable/issue21737.d(9): Error: template instance `core.atomic.atomicOp!("+=", int, int)` error instantiating
compilable/issue21737.d(47): Error: direct access to shared `s` is not allowed, see `core.atomic`
compilable/issue21737.d(50): Error: direct access to shared `s` is not allowed, see `core.atomic`
compilable/issue21737.d(53): Error: direct access to shared `s` is not allowed, see `core.atomic`
compilable/issue21737.d(62): Error: direct access to shared `s.result` is not allowed, see `core.atomic`

WalterBright avatar Feb 23 '22 07:02 WalterBright