Bug 20195 – -preview=nosharedaccess has some access problems

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-09-08T03:14:45Z
Last change time
2020-09-18T10:57:04Z
Keywords
pull, rejects-valid
Assigned to
No Owner
Creator
Manu
See also
https://issues.dlang.org/show_bug.cgi?id=20908

Comments

Comment #0 by turkeyman — 2019-09-08T03:14:45Z
I'm trying to build some tooling using `-preview=nosharedaccess`, but there are some edges that are wrong. Try and compile this code: void test() { // shared locals (or struct members) should be able to be initialised: shared int x; // error : direct access to shared `x` is not allowed, see `core.atomic` ref shared(int) fun() { static shared(int) val = void; // init `void` to silence the error noted above // return by reference: return val; // error : direct access to shared `val` is not allowed, see `core.atomic` } ref shared(int) fun2() { static shared(int)* val; // transfer pointer to reference: return *val; // error : direct access to shared `*val` is not allowed, see `core.atomic` } } I think shared things need to be able to initialise, because they can't possibly have been shared around before they were constructed. There just seems to be some problems interacting with ref; I suspect every interaction with ref will yield the same issues.
Comment #1 by bugzilla — 2020-06-06T09:02:23Z
Partial fix: https://github.com/dlang/dmd/pull/11239 (not the ref issue)
Comment #2 by dlang-bot — 2020-06-06T21:07:30Z
@WalterBright updated dlang/dmd pull request #11239 "allow initialization of shared variables" mentioning this issue: - Issue 20195: allow initialization of shared variables (partial fix) https://github.com/dlang/dmd/pull/11239
Comment #3 by dlang-bot — 2020-06-06T22:05:25Z
dlang/dmd pull request #11239 "allow initialization of shared variables" was merged into master: - 9c79cb16c336244572d9578e3c3b1d7b4d9d20f2 by Walter Bright: Issue 20195: allow initialization of shared variables (partial fix) https://github.com/dlang/dmd/pull/11239
Comment #4 by dlang-bot — 2020-07-02T11:54:13Z
@UplinkCoder updated dlang/dmd pull request #10412 "Allow ref-returns of shared Variables" mentioning this issue: - Issue 20195 - Allow explicit ref-returns of shared Variables (partial fix) This is okay because we are passing a pointer and not the actual value. Currently excludes `ref` inferred from `auto ref`. https://github.com/dlang/dmd/pull/10412
Comment #5 by dlang-bot — 2020-07-03T12:05:35Z
dlang/dmd pull request #10412 "Allow ref-returns of shared Variables" was merged into master: - 02fd0cd4b88d6f166a6d3905487279d7c723c46d by Stefan Koch: Issue 20195 - Allow explicit ref-returns of shared Variables (partial fix) This is okay because we are passing a pointer and not the actual value. Currently excludes `ref` inferred from `auto ref`. https://github.com/dlang/dmd/pull/10412
Comment #6 by dlang-bot — 2020-07-03T23:46:08Z
@andralex updated dlang/dmd pull request #11368 "Flagpack" mentioning this issue: - Issue 20195 - Allow explicit ref-returns of shared Variables (partial fix) This is okay because we are passing a pointer and not the actual value. Currently excludes `ref` inferred from `auto ref`. https://github.com/dlang/dmd/pull/11368
Comment #7 by dlang-bot — 2020-09-13T19:46:03Z
@Geod24 updated dlang/dmd pull request #11726 "Fix 20908 - Improve `shared` access detection" fixing this issue: - Fix 20195 - Improve `shared` access detection There were quite a few positives with the previous approach. Essentially, we cannot perform it during expression semantic, within things like `visit(PtrExp)` methods, because we need to be aware of our context. Instead of adding yet another flag to `Scope` (which would need to be flipped on and off), we use a visitor called from a higher level (namely, the unary / binary expression semantic). This should also make it easier to extend in the future, for example by adding support for bypassing the check if the constructor is `pure`. https://github.com/dlang/dmd/pull/11726
Comment #8 by dlang-bot — 2020-09-18T10:57:04Z
dlang/dmd pull request #11726 "Fix 20195 - Improve `shared` access detection" was merged into master: - 0257cec542a1fc17ba02b58a22337297463d69df by Geod24: Fix 20195 - Improve `shared` access detection There were quite a few positives with the previous approach. Essentially, we cannot perform it during expression semantic, within things like `visit(PtrExp)` methods, because we need to be aware of our context. Instead of adding yet another flag to `Scope` (which would need to be flipped on and off), we use a visitor called from a higher level (namely, the unary / binary expression semantic). This should also make it easier to extend in the future, for example by adding support for bypassing the check if the constructor is `pure`. https://github.com/dlang/dmd/pull/11726