dmd
dmd copied to clipboard
Fix issue 21737: shared opApply does not compile
cc @TurkeyMan
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:andReturns:)
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"
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);
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).
Lightbulb: function (as opposed to function pointers) are immutable.
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.
Honestly, I'd wish we could deprecate the entire opApply thing.
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`