-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Diagnose public protocol requirements witnessed by internal protocol extensions #85846
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
Conversation
|
There is still work to be done here (since a draft PR). This change breaks 18 tests, most of them due to the warning that is generated. One approach is to introduce a new UPCOMING_FEATURE flag and hide the diagnose behind it. |
|
These fail due to the warning: These fail due to the error: |
lib/Sema/TypeCheckProtocol.cpp
Outdated
| if (!witness->isAccessibleFrom(actualScopeToCheck.getDeclContext())) { | ||
| if (dc->getParentModule()->isResilient()) { | ||
| // This module was built with -enable-library-evolution | ||
| dc->getASTContext().Diags.diagnose(witness->getLoc(), diag::err_private_member_witness_public_protocol, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
witness->diagnose(...)
| return 42 | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too many blank lines
| protocol InternalProtocol: PublicProtocol {} | ||
|
|
||
| extension InternalProtocol { | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
| ERROR(err_private_member_witness_public_protocol,none, | ||
| "%0 is private and should not witness public protocol %1", | ||
| (const ValueDecl *,const ProtocolDecl *)) | ||
| WARNING(warn_private_member_witness_public_protocol,none, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's already a mechanism to emit something as a warning or error, with warnUntilFutureSwiftVersionIf()
3340009 to
b2a7b32
Compare
lib/Sema/TypeCheckProtocol.cpp
Outdated
| auto actualScopeToCheck = requiredAccessScope.first; | ||
|
|
||
| // without StrictTextualInterfaceChecking feature forConformance is set true | ||
| bool forConformance = not dc->getASTContext().LangOpts.hasFeature( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Please use
!instead ofnot - Can you extract a local variable for
dc->getASTContext()
lib/Sema/TypeCheckProtocol.cpp
Outdated
|
|
||
| auto actualScopeToCheck = requiredAccessScope.first; | ||
|
|
||
| // without StrictTextualInterfaceChecking feature forConformance is set true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is unnecessary in my opinion
lib/Sema/TypeCheckProtocol.cpp
Outdated
| diagKind, getProtocolRequirementKind(requirement), | ||
| witness, isSetter, requiredAccess, | ||
| protoAccessScope.accessLevelForDiagnostics(), proto) | ||
| .warnUntilFutureSwiftVersionIf( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this change, all access control errors from conformance checking now become warnings, we don't want that
dee5723 to
40e5c52
Compare
40e5c52 to
5d9d8b6
Compare
|
@swift-ci please smoke test |
|
@swift-ci please smoke test Windows |
include/swift/AST/RequirementMatch.h
Outdated
| ASSERT(kind != CheckKind::Availability); | ||
| } | ||
|
|
||
| RequirementCheck(AccessScope requiredAccessScope, bool forSetter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can probably remove the old overload then
include/swift/AST/RequirementMatch.h
Outdated
| // Exists specifically for AccessStrict | ||
| RequirementCheck(CheckKind accessKind, AccessScope requiredAccessScope, | ||
| bool forSetter) | ||
| : Kind(accessKind), Access{requiredAccessScope, forSetter} {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ASSERT() here that the kind is either Access or AccessStrict
lib/Sema/TypeCheckProtocol.cpp
Outdated
| if (match.Witness->isAccessibleFrom(requiredAccessLevel.getDeclContext(), | ||
| true) && | ||
| !match.Witness->isAccessibleFrom(requiredAccessLevel.getDeclContext(), | ||
| false)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We write /*forConformance=*/true and /*forConformance=*/false to make this clearer
| return RequirementCheck(CheckKind::AccessStrict, requiredAccessLevel, | ||
| isSetter); | ||
| } | ||
| if (checkWitnessAccess(DC, requirement, match.Witness, &isSetter)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could sink your new check down into checkWitnessAccess() if you change the return type of checkWitnessAccess(). That would avoid repeating the /*forConformance=*/true check twice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to keep checkWitnessAccess() as is? Since the end goal is to get rid of forConformance altogether (then the check will only occur once).
| @@ -0,0 +1,30 @@ | |||
| // RUN: %empty-directory(%t) | |||
| // RUN: %target-typecheck-verify-swift -enable-library-evolution | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is -enable-library-evolution required for the test?
| func privateRequirement() | ||
| func privateRequirementCannotWork() | ||
| // expected-note@-1 {{protocol requires function 'privateRequirementCannotWork()' with type '() -> ()'}} | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this file already covers this behavior, so it probably suffices to just update the expectations here as you did. Maybe you can add some new test cases here instead of adding a new file to test/Sema?
Private member witnessing a public constraint should be deprecated. Previously existing workaround is checked and compiler emits a warning when strict access check is not passed. Test files were fixed to expect the corresponding warning. rdar://74904373
5d9d8b6 to
6280a70
Compare
|
@swift-ci please smoke test |
|
@swift-ci please test windows |
|
cc: @slavapestov to take another round of review🙏 |
Private member witnessing a public constraint should be deprecated. Previously existing workaround is checked and compiler emits a warning when strict access check is not passed. Test files were fixed to expect the corresponding warning.
rdar://74904373