Commit Graph

105 Commits

Author SHA1 Message Date
Kathy Gray
84ef25afbc Migrate to calling interfaceType and remove SelfParam
Migrate more tests
2025-10-10 17:46:22 +01:00
Allan Shortlidge
0c5eac5c3e Sema: Downgrade missing import diagnostics for key paths.
For now, downgrade the `MemberImportVisibility` diagnostics introduced in
https://github.com/swiftlang/swift/pull/83934 to warnings.

Resolves rdar://160146503.
2025-09-08 16:15:49 -07:00
Allan Shortlidge
ea714d246f Sema: Diagnose key paths when MemberImportVisibility is enabled.
The diagnostic pass that checks whether expressions reference member
declarations that have not been imported failed to handle key path expressions.

Resolves rdar://159093481.
2025-08-27 09:44:38 -07:00
Kavon Farvardin
da53b24d76 test: @_inlineable -> @inlinable
The Swift 4 spelling only should remain in specific tests that ensure it's still accepted in that mode.
2025-08-12 14:32:24 -07:00
Allan Shortlidge
aca604660f AST/Sema: Make MemberImportVisibility a migratable feature.
The migration to `MemberImportVisibility` can be performed mechanically by
adding missing import declarations, so offer automatic migration for the
feature.

Resolves rdar://151931597.
2025-05-30 15:34:08 -07:00
Allan Shortlidge
6ea2dd8fac AST/Sema: Remove code adding @_spi to suggested import fix-its.
The was never invoked because inaccessibility due to SPI protection level is
always diagnosed before missing imports are diagnosed. The functionality could
therefore not be tested and should be removed.
2025-05-30 15:34:08 -07:00
Allan Shortlidge
dbb1d783d9 Sema: Omit internal from MemberImportVisibility fix-its when appropriate.
Omit an explicit access level from `MemberImportVisibility` fix-its under the
following conditions:

- `InternalImportsByDefault` is enabled.
- The required import needs an `internal` access level or lower.
- The module is not yet imported explicitly in any other file.

Resolves rdar://149577615.
2025-05-26 22:56:47 -07:00
Allan Shortlidge
426f48dcd4 Tests: Rename test cases associated with MemberImportVisibility. 2025-05-26 22:56:47 -07:00
Allan Shortlidge
78faa1aad2 Tests: Verify MemberImportVisibility honors -public-module-name. 2025-05-22 13:49:16 -07:00
Becca Royal-Gordon
c3a61bee0e Add experimental feature for module selector 2025-05-14 11:16:02 -07:00
Allan Shortlidge
f3ef07083b AST: Filter out some Obj-C overrides when MemberImportVisibility is enabled.
Unlike in Swift, Obj-C allows method overrides to be declared in extensions
(categories), even outside of the module that defines the type that is being
extended. When MemberImportVisibility is enabled, these overrides must be
filtered out to prevent them from hijacking name lookup and causing the
compiler to insist that the module that defines the extension be imported.

Resolves rdar://145329988.
2025-04-25 08:05:32 -07:00
Allan Shortlidge
a8ce5462a0 Revert "AST: Filter out some Obj-C overrides when MemberImportVisibility is enabled."
This reverts commit eafb84713e.
2025-04-21 17:04:11 -07:00
Allan Shortlidge
374fc90b42 Merge pull request #80563 from tshortli/member-import-visibility-objc-overloads-in-extensions
AST: Filter out some Obj-C overrides when MemberImportVisibility is enabled
2025-04-06 03:26:38 -07:00
Allan Shortlidge
eafb84713e AST: Filter out some Obj-C overrides when MemberImportVisibility is enabled.
Unlike in Swift, Obj-C allows method overrides to be declared in extensions
(categories), even outside of the module that defines the type that is being
extended. When MemberImportVisibility is enabled, these overrides must be
filtered out to prevent them from hijacking name lookup and causing the
compiler to insist that the module that defines the extension be imported.

Resolves rdar://145329988.
2025-04-05 17:34:21 -07:00
Allan Shortlidge
3e9db90203 Tests: Add missing coverage to members_transitive_compiler_protocols.swift. 2025-04-05 09:48:21 -07:00
Allan Shortlidge
703126a3ce Parse: Improve MemberImportVisibility diags for appendLiteral(_:) calls.
Ensure compiler generated calls to `appendLiteral(_:)` have source locations for
diagnostics.

Partially resolves rdar://144535697.
2025-04-05 09:48:20 -07:00
Allan Shortlidge
b97ec5bbe5 Sema: Improve MemberImportVisibility diags for for-in loops.
Ensure that source locations are attached to the implicit calls to
`makeIterator()` and `next()` for diagnostics.

Partially resolves rdar://144535697.
2025-04-05 09:47:56 -07:00
Hamish Knight
738c70e8c8 [AST] Always walk folded SequenceExpr if available
Expand the special-cased ASTWalker behavior for folded SequenceExprs
such that we always walk the folded expression when available. This
ensures that we don't attempt to add the same node multiple times
when expanding ASTScopes during pre-checking.

rdar://147751795
2025-03-24 20:18:34 +00:00
Rintaro Ishizaki
a0d7068162 Revert "Merge pull request #78280 from swiftlang/revert-77140-swift-lexical-lookup-validation"
This reverts commit ae88aaca8f, reversing
changes made to b0123bca14.
2024-12-20 16:37:36 -08:00
Ben Barham
e06d0b9357 Revert "[SwiftLexicalLookup] New unqualified lookup implementation validation" 2024-12-18 15:04:16 -08:00
Allan Shortlidge
94e678da37 ClangImporter: Ignore missing imports in SwiftDeclConverter::recordObjCOverride().
`recordObjCOverride()` records semantic overrides for imported Obj-C methods.
Since these methods are imported from a different language, it doesn't make
sense to enforce Swift's member import visibility rules when performing lookups
to find overridden methods. Doing so caused the Constrain Solver to lack
important information needed to eliminate overloads, resulting in erroneous
ambiguities.

Resolves rdar://141636723.
2024-12-18 08:34:44 -08:00
Jakub Florek
39e4d15bb5 Add REQUIRES: swift_feature_UnqualifiedLookupValidation to the SwiftlexicalLookup test. 2024-12-13 12:40:18 +01:00
Jakub Florek
0ba7a5ea0b Add REQUIRES: UnqualifiedLookupValidation comment to unqualified lookup validation test. 2024-12-05 10:36:12 +01:00
Jakub Florek
866f1c1c04 Merge branch 'main' into swift-lexical-lookup-validation 2024-11-26 09:37:23 +01:00
Jakub Florek
024f6304b0 Add a basic SwiftLexicalLookup validation test. Add caching of ConfiguredRegions to unqualified lookup validation. 2024-11-26 09:34:33 +01:00
Rintaro Ishizaki
40c8d817fb [Diagnostics] Support "swift" style diagnostics at EOF
Adjust the valid position checking and special handle EOF position.
If the requested location is at EOF, use the last token, but still
emit the diagnostics at the specificied location.

rdar://138426038
2024-11-21 06:27:37 -08:00
Daniel Rodríguez Troitiño
ba68faaed5 [test] Mark tests that use experimental/upcoming features as such
Find all the usages of `--enable-experimental-feature` or
`--enable-upcoming-feature` in the tests and replace some of the
`REQUIRES: asserts` to use `REQUIRES: swift-feature-Foo` instead, which
should correctly apply to depending on the asserts/noasserts mode of the
toolchain for each feature.

Remove some comments that talked about enabling asserts since they don't
apply anymore (but I might had miss some).

All this was done with an automated script, so some formatting weirdness
might happen, but I hope I fixed most of those.

There might be some tests that were `REQUIRES: asserts` that might run
in `noasserts` toolchains now. This will normally be because their
feature went from experimental to upcoming/base and the tests were not
updated.
2024-11-02 11:46:46 -07:00
Tony Allevato
0fa07ba3fe Merge pull request #76793 from dylansturg/member_lookup_test
Add MemberImportVisibility tests for inherited members of classes.
2024-10-01 15:33:51 -04:00
Dylan Sturgeon
c2fa6744fa Add MemberImportVisibility tests for inherited members of classes.
Create some test cases that demonstrate MemberImportVisibility behavior with respect referencing inherited members. There are already tests that demonstrate overrides, but nothing seemed to show the behavior when referencing an inherted member through a derived type. I wanted to verify this behavior so I wrote a test to demonstrate it. It seems reasonable to check-in the test to ensure the behavior remains consistent.
2024-10-01 08:26:17 -07:00
Allan Shortlidge
d373036805 SE-0444: Promote MemberImportVisibility to an upcoming feature.
The proposal has been accepted, so `MemberImportVisibility` is no longer
experimental.

Resolves rdar://126284512.
2024-09-26 13:41:14 -07:00
Allan Shortlidge
c868378d96 ConstraintSystem: Use scoring to implement MemberImportVisibility.
Previously, the constraint solver would first attempt member lookup that
excluded members from transitively imported modules. If there were no viable
candidates, it would perform a second lookup that included the previously
excluded members, treating any candidates as unviable. This meant that if the
member reference did resolve to one of the unviable candidates the resulting
AST would be broken, which could cause unwanted knock-on diagnostics.

Now, members from transitively imported modules are always returned in the set
of viable candidates. However, scoring will always prioritize candidates from
directly imported modules over members from transitive imports. This solves the
ambiguities that `MemberImportVisibility` is designed to prevent. If the only
viable candidates are from transitively imported modules, though, then the
reference will be resolved successfully and diagnosed later in
`MiscDiagnostics.cpp`. The resulting AST will not contain any errors, which
ensures that necessary access levels can be computed correctly for the imports
suggested by `MemberImportVisibility` fix-its.

Resolves rdar://126637855.
2024-09-10 09:47:42 -07:00
Allan Shortlidge
317b0e7abd Sema: Only add @_spiOnly to import fix-its with a public access level.
It doesn't make sense to add the `@_spiOnly` attribute to an `internal` import.

Part of rdar://126637855.
2024-08-19 10:58:49 -07:00
Allan Shortlidge
304f9c4bf0 AST: Look through missing imports in OverriddenDeclsRequest.
If `OverriddenDeclsRequest` fails to find any overridden declarations, query
again ignoring missing imports to find declarations that were excluded due to the
`MemberImportVisibility` feature being enabled.
2024-08-12 18:32:16 -07:00
Allan Shortlidge
6e4e111d8a Merge pull request #75766 from tshortli/superfluous-not-imported-here-diags
Sema: Avoid emitting superfluous resilience diagnostics with `MemberImportVisibility`
2024-08-08 09:20:45 -07:00
Allan Shortlidge
7e1eac7f08 Sema: Avoid emitting superfluous resilience diagnostics with MemberImportVisibility.
When `MemberImportVisibility` is enabled, if the import that would bring a
member declaration into scope is missing it is diagnosed as an error. The
existing resilience diagnostics that would also diagnose the same problem in
contexts that are visible in the module interface are therefore superflous with
the feature enabled.
2024-08-07 18:17:10 -07:00
Alex Hoppen
8edb57c756 Merge pull request #75667 from ahoppen/build-issues-live-issues
[Sema/SourceKit] Emit same diagnostics for missing protocol requirements on the command line and in SourceKit
2024-08-07 17:24:47 -07:00
Alex Hoppen
66104395d7 [Sema/SourceKit] Emit same diagnostics for missing protocol requirements on the command line and in SourceKit
Some editors use diagnostics from SourceKit to replace build issues. This causes issues if the diagnostics from SourceKit are formatted differently than the build issues. Make sure they are rendered the same way, removing most uses of `DiagnosticsEditorMode`.

To do so, always emit the `add stubs for conformance` note (which previously was only emitted in editor mode) and remove all `; add <something>` suffixes from notes that state which requirements are missing.

rdar://129283608
2024-08-07 14:01:30 -07:00
Allan Shortlidge
178315ebed Sema: Look through missing imports during qualified type lookup.
To improve knock-on diagnostics, resolve qualified types to their matching
member type declarations regardless of whether an import is missing when the
`MemberImportVisibility` features is enabled.

Part of rdar://126637855.
2024-08-06 20:38:27 -07:00
Allan Shortlidge
0f09b3c9f5 Sema: Look through missing imports during unqualified type lookup.
To improve knock-on diagnostics, resolve unqualified types to their matching
member type declarations regardless of whether an import is missing when the
`MemberImportVisibility` features is enabled.

Part of rdar://126637855.
2024-08-06 20:38:27 -07:00
Allan Shortlidge
3ef1600747 Sema: Add an access level to the fix-its for missing imports when appropriate.
When emitting fix-its for missing imports, include an access level when the
module has been imported with an access level in other source files. For now,
the suggested access level for will always be `internal`, even when uses of
members in the file would actually require `public` or `package` visibility. In
order to suggest the correct access level, name lookup will need to be
refactored to repair references to inaccessible declarations, instead of
leaving error nodes in the AST. In anticipation of that refactoring of name
lookup, missing import diagnostics are now delayed until type checking a source
file is finished so that a consistent access level can be suggested for each
import fix-it for a given module.

Partially resolves rdar://126637855.
2024-08-05 11:33:35 -07:00
Allan Shortlidge
9aab6ef33e AST: Fix MemberImportVisibility handling of @_exported imports.
In existing Swift, an `@_exported import` in any source file makes the
declarations from the imported module visible in all source files. It's unclear
whether this is an explicit decision or is simply and unintended consequence of
effectively adding an implicit import to each source file for the module being
compiled.

Although it's not clear whether this behavior is desirable, the behavior of
member lookup when the MemberImportVisibility feature is enabled should align
with it in order to avoid causing unnecessary churn in required imports.

Resolves rdar://132525152.
2024-07-26 10:20:41 -07:00
Allan Shortlidge
d002da0ef2 AST: Add a IgnoreMissingImports option to name lookup.
Control enforcement of member import visibility requirements via a new option,
instead of piggy-backing on the existing IgnoreAccessControl option. Adopt the
option when doing fallback lookups for unviable members so that the compiler
can diagnose the reason that a member is inaccessible more reliably.
Previously, with MemberImportVisibility enabled decls with the package access
level could be mis-diagnosed as inaccessible due to their access level when
really they were inaccessible due to a missing import.

Resolves rdar://131501862.
2024-07-10 22:57:15 -07:00
Allan Shortlidge
10a2cde5b4 Tests: Add package access level test cases to MemberImportVisibility tests. 2024-07-10 18:26:01 -07:00
Slava Pestov
f747121080 Sema: Re-introduce the hack for re-using generic signature of extended protocol
In Swift 5.10 if you wrote `extension Foo {}` for some protocol Foo,
the extension would always re-use the generic signature of Foo, which
is <Self where Self: Foo>. In Swift 6 this no longer works because Foo
might be ~Copyable, in which case `extension Foo {}` adds default
requirements, so we changed GenericSignatureRequest to just always
build a new signature if we're given an extension.

However, to avoid a request cycle with a code example that really should
have never worked at all, I'm re-introducing the hack for re-using the
signature.

Fixes rdar://problem/129540617.
2024-06-19 13:25:09 -04:00
Allan Shortlidge
eba581eec2 AST: Add appropriate attributes to module import fix-its.
Make sure suggested imports are consistent with imports in other files. Also,
make sure the underlying clang module is always imported `@_exported`.
2024-04-16 16:29:51 -07:00
Allan Shortlidge
67b30652f1 Tests: Consolidate inputs for MemberImportVisibility tests.
NFC.
2024-04-16 16:29:51 -07:00
Allan Shortlidge
fa2c900e5b Sema: Diagnose missing imports in during type lookup. 2024-04-16 16:29:51 -07:00
Allan Shortlidge
5ef51d13c4 Sema: Diagnose missing imports in resolveDeclRefExpr(). 2024-04-16 16:29:51 -07:00
Allan Shortlidge
ee4a542ab1 Tests: Improve coverage in members_transitive*.swift.
- Reorganize test cases
- Add tests cases for multi-file and contextual base lookup
- Verify behavior without `MemberImportVisibility` feature

NFC.
2024-04-16 16:29:51 -07:00
Allan Shortlidge
1b6e4e004e AST: MemberImportVisibility should ignore bridging header modules. 2024-04-16 16:29:51 -07:00