Skip to content

Conversation

@sepy97
Copy link
Contributor

@sepy97 sepy97 commented Dec 4, 2025

Private member witnessing a public constraint should be deprecated. With this change compiler emits an error when access check is not passed in library evolution mode (emits a warning otherwise).

rdar://74904373

@sepy97
Copy link
Contributor Author

sepy97 commented Dec 4, 2025

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.

@sepy97
Copy link
Contributor Author

sepy97 commented Dec 4, 2025

These fail due to the warning:
Swift(macosx-arm64) :: Compatibility/accessibility.swift
Swift(macosx-arm64) :: Compatibility/optional_visibility.swift
Swift(macosx-arm64) :: Distributed/distributed_actor_system_missing_adhoc_requirement_impls.swift
Swift(macosx-arm64) :: Generics/rdar123013710.swift
Swift(macosx-arm64) :: Interop/Cxx/class/access/access-inversion-typechecker.swift
Swift(macosx-arm64) :: NameLookup/accessibility.swift
Swift(macosx-arm64) :: SILGen/internal_protocol_refines_public_protocol_with_public_default_implementation.swift
Swift(macosx-arm64) :: Sema/accessibility.swift
Swift(macosx-arm64) :: Sema/accessibility_private.swift
Swift(macosx-arm64) :: attr/accessibility_proto.swift
Swift(macosx-arm64) :: attr/global_actor.swift
Swift(macosx-arm64) :: decl/protocol/conforms/access_corner_case.swift
Swift(macosx-arm64) :: decl/protocol/req/optional_visibility.swift

These fail due to the error:
Swift(macosx-arm64) :: Profiler/samplepgo.swift
Swift(macosx-arm64) :: Interop/Cxx/function/default-arguments-multifile.swift
Swift(macosx-arm64) :: embedded/synchronization.swift
Swift(macosx-arm64) :: SILGen/protocol_resilience.swift
Swift(macosx-arm64) :: IRGen/mangle-opaque-return-type.swift

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,
Copy link
Contributor

Choose a reason for hiding this comment

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

witness->diagnose(...)

return 42
}
}

Copy link
Contributor

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 {

Copy link
Contributor

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,
Copy link
Contributor

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()

@sepy97 sepy97 force-pushed the public-decl-internal-protocol branch 2 times, most recently from 8d1eebe to 48c1267 Compare December 5, 2025 00:42
Private member witnessing a public constraint should be deprecated. If StrictSemaForTextualInterface is set, compiler emits a warning (in future versions -- an error) when access check is not passed.

rdar://74904373
@sepy97 sepy97 force-pushed the public-decl-internal-protocol branch from 48c1267 to 3340009 Compare December 6, 2025 00:43
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.

2 participants