Skip to content

Comments

Remove visiblity and lookup deprecation (Take 2)#9636

Merged
RazvanN7 merged 25 commits intodlang:masterfrom
JinShil:dep_visible
Apr 27, 2019
Merged

Remove visiblity and lookup deprecation (Take 2)#9636
RazvanN7 merged 25 commits intodlang:masterfrom
JinShil:dep_visible

Conversation

@JinShil
Copy link
Contributor

@JinShil JinShil commented Apr 17, 2019

Reboot of #7241
Credit to @MartinNowak

** This is not ready yet **

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @JinShil! 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 annotated coverage diff directly on GitHub with CodeCov's browser extension
  • 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

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

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

dub fetch digger
dub run digger -- build "master + dmd#9636"

@thewilsonator thewilsonator added the Review:WIP Work In Progress - not ready for review or pulling label Apr 17, 2019
@thewilsonator
Copy link
Contributor

@atilaneves
Copy link
Contributor

@thewilsonator Not entirely sure why I was cc'ed.

@wilzbach
Copy link
Contributor

Because excel-d is failing with this PR:

source/xlld/wrap/wrap.d(607,24): Error: `test.d_funcs.shouldNotBeAProblem` is not visible from module `wrap`

@jacob-carlborg
Copy link
Contributor

** This is not ready yet **

Next time try creating a draft PR: https://github.blog/2019-02-14-introducing-draft-pull-requests.

@thewilsonator
Copy link
Contributor

Because excel-d is failing with this PR:

Yep. Sorry I should have put that in the ping.

@JinShil
Copy link
Contributor Author

JinShil commented Apr 17, 2019

I believe all the failures in buildkite are legitimate. The only thing I have left (I think) is to improve some of the error messages and prevent duplicate error messages. In other words, I think the applications that are failing need to be fixed.

Copy link
Member

@Geod24 Geod24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this. A few comments on error messages, but looks like you're still working on it.

---
fail_compilation/fail18979.d(13): Deprecation: `imports.imp18979.Foo.__ctor(A)(A a)` is not visible from module `fail18979`
---
fail_compilation/fail18979.d(14): Error: `imports.imp18979.Foo.__ctor(A)(A a)` is not visible from module `fail18979`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be an "undefined identifier" error ?
Also, in a perfect world, we shouldn't show "__ctor" to the user (or any symbol which is not defined in code), but that was already the case before.

Copy link
Contributor Author

@JinShil JinShil Apr 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about now?

Edit: Actually I don't think the suggestion "did you mean imports.imp18979.Foo.__ctor(A)(A a)" shouldn't appear at all because it is private. I'll have to look into it.

src/dmd/access.d Outdated
return true;
}
// Access checks have been removed in favor of visibility checks.
// See https://github.com/dlang/DIPs/blob/master/DIPs/archive/DIP22.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this whole function be reworked as a result ?
Not necessarily now tho.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'm hoping I can delete the entire function when I'm done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't get rid of it. It is called for some safety checks, specifically https://github.com/dlang/dmd/blob/master/test/fail_compilation/test18554.d

@wilzbach
Copy link
Contributor

wilzbach commented Apr 19, 2019

@wilzbach
Copy link
Contributor

The Azure failure is pretty weird:

"D:\a\1\s\generated\Windows\Release\Win32\dmd.exe" -conf= -g -m32mscoff -O -w -dip25 -I../druntime\import -unittest -c  -ofunittest2.obj std\range\package.d  std\range\primitives.d  std\range\interfaces.d
Error: out of memory

I guess we split up building Phobos even more for win32 :/

@rainers
Copy link
Member

rainers commented Apr 19, 2019

The Azure failure is pretty weird:
I guess we split up building Phobos even more for win32 :/

BTW: the autotester uses posix.mak to build the phobos unittests in parallel and per file compilation on windows, too. See target auto-tester-test.

@atilaneves
Copy link
Contributor

I've fixed excel-d in the meanwhile.

@wilzbach
Copy link
Contributor

The Azure failure is pretty weird:
I guess we split up building Phobos even more for win32 :/

BTW: the autotester uses posix.mak to build the phobos unittests in parallel and per file compilation on windows, too. See target auto-tester-test.

Yeah, but I guess the auto-tester machines have more memory?
Do you have a better idea/solution to fixing this out of memory error on Azure?

@rainers
Copy link
Member

rainers commented Apr 19, 2019

Yeah, but I guess the auto-tester machines have more memory?

Might be, but single file compilation will likely need less memory and is what posix.mak does. If parallel builds are a problem due to memory resources, it could be used with JOBS=1.

@rainers
Copy link
Member

rainers commented Apr 19, 2019

Do you have a better idea/solution to fixing this out of memory error on Azure?

This might also help: #9650

@JinShil
Copy link
Contributor Author

JinShil commented Apr 20, 2019

I have done as much as I can with this. There is one bug remaining:

Given the following files:

├── fail313.d
└── imports
    ├── a313.d
    └── b313.d
module fail313;
import imports.a313;
void main()
{
    imports.b313.bug();
}
module imports.a313;
private import imports.b313;
module imports.b313;
void bug() { }
dmd fail313.d
fail313.d(b): Error: module `imports.b313` is not accessible here, perhaps add `static import imports.b313;`

The error is emitted from the call to checkAccess at the bottom of this code block:

dmd/src/dmd/expressionsem.d

Lines 10993 to 11008 in a147141

if (ie.sds.isModule() && ie.sds != sc._module)
flags |= IgnorePrivateImports;
if (sc.flags & SCOPE.ignoresymbolvisibility)
flags |= IgnoreSymbolVisibility;
Dsymbol s = ie.sds.search(exp.loc, exp.ident, flags);
/* Check for visibility before resolving aliases because public
* aliases to private symbols are public.
*/
if (s && !(sc.flags & SCOPE.ignoresymbolvisibility) && !symbolIsVisible(sc._module, s))
{
s = null;
}
if (s)
{
if (auto p = s.isPackage())
checkAccess(exp.loc, sc, p);

The problem is it should have never gotten that far. The call to ie.sds.search() should not have returned imports.b313 or the call to symbolIsVisible should not have returned true (Preferrablly the former).

It's an existing bug in symbol lookup/visibility that is being masked by the now deprecated access checks. I need to fix that, and remove the call to checkAccess. I've been working on it for 2 days and can't figure it out. I could use some help.

@SSoulaimane
Copy link
Member

@JinShil isn't removing checkAccess() out of the scope of this PR?

@JinShil
Copy link
Contributor Author

JinShil commented Apr 22, 2019

isn't removing checkAccess() out of the scope of this PR?

No, I don't believe so. When DIP22 was implemented, it had to keep both visibility checks and access checks working until the deprecation of access checks (this PR) was finished. With visibility checks implemented, and access checks now fully deprecated, access checks are no longer needed.

The problem, as the bug above illustrates, is that the visibility checks were not fully implemented; the original authors missed the one case illustrated in my previous comment.. After that case is resolved, search will no longer return symbols that are not visible, and the code will never reach the call to checkAccess.

We could pull this PR as is, since the call to accessCheck is preventing the incorrect code from compiling, but it is not a proper solution. We need to fix search so that it doesn't return symbols that aren't visible. Maybe I can move some of the accessCheck code to search, but I'm not sure if that's the right fix. I'll have to think about it.

@SSoulaimane
Copy link
Member

SSoulaimane commented Apr 22, 2019

I'm not sure you can remove that specific checkAccess() call. when calling search() on the package imports it should find the module b313 since it is a child module and symbolIsVisible() doesn't decide whether you can access a module.

@rainers
Copy link
Member

rainers commented Apr 22, 2019

I hit a related problem just yesterday: https://issues.dlang.org/show_bug.cgi?id=19816

src/dmd/access.d Outdated
}
}
if (!result && (!(sc.flags & SCOPE.onlysafeaccess) || sc.func.setUnsafe()))

Copy link
Member

@SSoulaimane SSoulaimane Apr 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what you need for the buildkite fails.

+    if (smember.toParent().isTemplateInstance())
+    {
+        return false; // for backward compatibility
+    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I'd still like to do the refactoring as a followup after this PR is merged. This PR is already quite large, and I'd like to keep the friction low.

@JinShil
Copy link
Contributor Author

JinShil commented Apr 25, 2019

Yeah!!! All Green!!! What a relief!!!

This PR is as good as I know how to make it at this time. As @Geod24 mentioned there are 2 error messages that are imperfect. They are not incorrect, but they could be better, which is like many error messages in D today. I did my best to improve them, but it appears they will require some refactoring of DMD to get the information needed. I don't know how to do that yet, and I think it would just add more difficulty to the review of this PR.

I will follow up this PR with @SSoulaimane's suggestion to refactor access.d. This PR is already rather large and I would prefer not to cloud things with a refactoring.

From my point of view, this is good to go.

If you do choose to merge this, please be sure to close #7241.

Thanks @MartinNowak for the initial work, and thanks everyone else for your help along the way.

Copy link
Contributor

@wilzbach wilzbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good! How about not removing the now failing tests, but just updating their error message with AUTO_UPDATE?

@JinShil
Copy link
Contributor Author

JinShil commented Apr 25, 2019

I don't believe I removed any tests, but the diff doesn't show what really happened. Some tests were just consolidated into one (e.g. the checkImports tests). Others were moved (e.g. test15925.d), but the diff shows them as a deletion and an addition, rather than a rename. Please identify a specific test if I'm missing something.

Edit: Also the reason the checkImports tests were consolidated is because this PR removes the -transition=checkimports flags. After doing that, the different tests we all just testing the same thing. So it made sense to only have one.

@JinShil
Copy link
Contributor Author

JinShil commented Apr 25, 2019

BTW, this is no longer a WIP

@jacob-carlborg jacob-carlborg removed the Review:WIP Work In Progress - not ready for review or pulling label Apr 25, 2019
@wilzbach
Copy link
Contributor

Edit: Also the reason the checkImports tests were consolidated is because this PR removes the -transition=checkimports flags. After doing that, the different tests we all just testing the same thing. So it made sense to only have one.

All good. Thanks! Sorry for not seeing this immediately.

@wilzbach
Copy link
Contributor

BTW another nice thing about this PR is that we finally can convert the existing module imports to selective ones Phobos. In other words, we can all these selective comments:

https://github.com/dlang/phobos/blob/eb38e8e6307f2b3c27b86d2d25ddeac1b400beb5/std/algorithm/iteration.d#L74

@wilzbach wilzbach added the Merge:72h no objection -> merge The PR will be merged if there are no objections raised. label Apr 25, 2019
@RazvanN7 RazvanN7 merged commit d511353 into dlang:master Apr 27, 2019
@RazvanN7
Copy link
Contributor

Thanks for this awesome work!

@JinShil JinShil deleted the dep_visible branch April 27, 2019 12:32
@JinShil
Copy link
Contributor Author

JinShil commented Apr 27, 2019

And thanks to all of you for you reviews and ferrying this through the process. It feels so good to have this done. 👍

@JinShil
Copy link
Contributor Author

JinShil commented Apr 27, 2019

@SSoulaimane If you want to submit a PR to refactor access.d, please do. It was your work, so it would be nice if it were signed with your handle.

@SSoulaimane
Copy link
Member

@JinShil no it's yours just do it. I'll assist you if I can.

@FeepingCreature
Copy link
Contributor

This, specifically 8e9b2ca , seems to have accidentally fixed https://issues.dlang.org/show_bug.cgi?id=19536 . You can now pass a private symbol to a template alias and call it from the template without running into errors.

I'm very happy about this, but is it intentional?

@JinShil
Copy link
Contributor Author

JinShil commented Jun 28, 2019

is it intentional?

No, that was not intentional, but I don't see why something like that should be prevented. There is currently an open question about whether we should support public aliases to private symbols. The compiler's behavior is currently inconsistent (some work -- e.g. templates -- and some don't). I don't have a way to force design decisions from the powers that be except through the DIP process, and the DIP process is quite disproportionate when all you want is a thoughtful decision. I think @Geod24 was going to follow up on this topic, but I'm not sure if that happened or will happen.

The current implementation proactively prevents public aliases to private symbols, so a PR to allow it should only involve deleting code. Just by that alone, it seems like we're trying to enforce an arbitrary limitation, and I think it might be best to just to allow it, but that's not really my call to make. I could propose it by submitting a PR, but I'm not sure if I'm prepared to fight the battle that may ensue.

ntrel added a commit to ntrel/phobos that referenced this pull request Jun 20, 2020
This issue seems to have actually been fixed in:
c2eefb0d8d850715f492197b0b1a033d9ad5411a
dlang/dmd#9636

Add very basic test facility for independent test files.
ntrel added a commit to ntrel/phobos that referenced this pull request Jun 20, 2020
b17712_c13.d was apparently fixed in:
c2eefb0d8d850715f492197b0b1a033d9ad5411a
dlang/dmd#9636

Add very basic test facility for independent test files.
ntrel added a commit to ntrel/phobos that referenced this pull request Jun 21, 2020
b17712.d is not fixed in dmd, Phobos workaround:
2f20661
dlang#6659

b17712_c13.d was apparently fixed in dmd:
c2eefb0d8d850715f492197b0b1a033d9ad5411a
dlang/dmd#9636

Add very basic test facility for independent test files.
@CyberShadow
Copy link
Member

This pull request introduced a regression:
https://issues.dlang.org/show_bug.cgi?id=23991

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merge:72h no objection -> merge The PR will be merged if there are no objections raised.

Projects

None yet

Development

Successfully merging this pull request may close these issues.