Skip to content

[Gardening] SE-0169 PR Feedback #9465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from

Conversation

KingOfBrian
Copy link
Contributor

@KingOfBrian KingOfBrian commented May 10, 2017

This PR addresses some of the feedback from #9098:

  • Add SE-0169 to the changelog
  • Update old Comments
  • Test SE-0169 behavior in single file and WMO mode
  • Move checkAccessibility to use AccessScopes

The last change of checkAccessibility was a bit more of a change than I was hoping for. It turns out that the method for determining the AccessScope is a bit different than what checkAccessibility was doing. Basically getFormalAccessScope restricts visibility by the access of the extension's type, and checkAccessibility does not want to do that when performing some protocol conformance checks. I added a useNominalTypeAccessibility flag to make the AccessScope creation work in both cases. If this change turns out to be a bad idea, I'm glad to split the commit and keep any of the style changes (allowsAccess -> isAccessibleChildOf) and revert checkAccessibility back to it's original form.

@jrose-apple jrose-apple self-assigned this May 10, 2017
Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

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

Early feedback, not counting the final commit (which has the real content)

return getFormalAccessImpl(useDC);
return result;
}
Accessibility getFormalAccess(const DeclContext *useDC = nullptr) const;
Copy link
Contributor

Choose a reason for hiding this comment

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

This split was deliberate, so that an already-computed access could be inlined into the caller. It might not be worth it, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, no real reason to change this. I'll roll it back.

@@ -34,7 +34,7 @@ class AccessScope {
/// Check if private access is allowed. This is a lexical scope check in Swift
Copy link
Contributor

Choose a reason for hiding this comment

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

Missed the comment?

@@ -44,13 +51,14 @@ extension Outer.Middle.Inner {
}
}

// Padded to start on line 55 to make @LINE-55 work
Copy link
Contributor

Choose a reason for hiding this comment

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

You could avoid this by using the split version as the input to FileCheck (and running FileCheck twice for the WMO case).

@@ -52,12 +47,15 @@ class AccessScope {
/// Returns true if this is a child scope of the specified other access scope.
bool isChildOf(AccessScope AS) const {
if (!isPublic() && !AS.isPublic())
return allowsAccess(getDeclContext(), AS.getDeclContext());
return getDeclContext()->isAccessibleChildOf(AS.getDeclContext());
Copy link
Contributor

Choose a reason for hiding this comment

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

This was a helper method because DeclContext really shouldn't know about access. Can you put it back?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good -- Keeping things isolated was my original instinct, but I mis-interpreted your original feedback. I see what your saying now though!

@jrose-apple
Copy link
Contributor

Everything else about the other commits looks good.

return setterAccess >= Accessibility::Public;

auto scope = getDeclContext()->getAccessScope(DC, setterAccess,
/* useNominalTypeAccessibility */ false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is false for the scenario of extending public protocols with private subtypes. The test that caught the behavior is test/SILGen/witness_accessibility.swift.

In this test, an extension on a private protocol implements a default requirement for a parent public protocol. The current access scope lookup would restrict the visibility of the extension method R.publicRequirement to fileprivate since the type of R is fileprivate. But with this level of visibility struct S: R doesn't conform to protocol P.

Now with all that said, I'm realizing that you might just be referring to why is this false just in the case of the setter, and that's a good catch -- I don't think there's a need for that. I'll add a test to confirm.

Copy link
Contributor

@jrose-apple jrose-apple May 19, 2017

Choose a reason for hiding this comment

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

You're giving me more credit than I deserve; I was indeed asking about both cases.

For what it's worth, test/SILGen/witness_accessibility.swift is wrong—you can't (today) satisfy a public requirement with something that depends on a private protocol, and most times the compiler will reject it (SR-697). But fixing that will probably break code, so okay.

if (!useDC)
bool ValueDecl::isAccessibleFrom(const DeclContext *DC) const {
auto access = getFormalAccess(DC);
if (!DC)
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems backwards to me. The only use for the formal-access-as-seen-from-DC at this point is when DC is null.

Copy link
Contributor Author

@KingOfBrian KingOfBrian May 19, 2017

Choose a reason for hiding this comment

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

Yea, this confuses me as well, but this behavior is documented in the .h and a number of things break without it. I can dig in a bit more as to why.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I just meant you can skip the "as-seen-from-the-DC" part. A null DC represents access from anywhere.

@CodaFi
Copy link
Contributor

CodaFi commented Dec 6, 2019

@KingOfBrian Do you still wish to pursue this pull request? If so, could you please rebase it and address Jordan's review feedback?

@CodaFi
Copy link
Contributor

CodaFi commented Feb 10, 2020

Alright, since this has gone a while without any new activity, I'm going to close it. Please feel free to reopen this or send us another pull request with any updated changes.

@CodaFi CodaFi closed this Feb 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants