Commit Graph

35 Commits

Author SHA1 Message Date
Allan Shortlidge
49b594100f 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-06-02 07:27:22 -07:00
Allan Shortlidge
b4376a9bd3 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-24 21:26:34 -07:00
Allan Shortlidge
a020cf8367 Revert "AST: Filter out some Obj-C overrides when MemberImportVisibility is enabled."
This reverts commit 324fa235b0.
2025-04-21 17:08:01 -07:00
Allan Shortlidge
324fa235b0 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-06 09:52:58 -07: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
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
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
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
10a2cde5b4 Tests: Add package access level test cases to MemberImportVisibility tests. 2024-07-10 18:26:01 -07: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
Allan Shortlidge
d43816567f AST: Rename ExtensionImportVisibility to MemberImportVisibility.
This feature controls lookup behavior for members in general, not just
extension members.

Resolves rdar://126491324
2024-04-16 16:29:51 -07:00
Allan Shortlidge
0cf2428038 Tests: Add a clang submodule test to extensions_transitive_objc.swift. 2024-04-10 18:16:49 -07:00
Allan Shortlidge
6ebd4af883 Tests: Add operator lookup tests to extensions_transitive.swift. 2024-04-10 11:27:30 -07:00
Allan Shortlidge
d0571af983 Tests: Add Obj-C interop tests for ExtensionImportVisibility. 2024-04-05 09:22:02 -07:00
Allan Shortlidge
2af24b2f69 Tests: Verify ExtensionImportVisibility works for @_exported imports. 2024-04-05 09:22:02 -07:00
Allan Shortlidge
77c0aae55e Tests: Remove unnecessary public modifier on extensions. 2024-04-05 09:22:02 -07:00
Doug Gregor
61b19c8fbf Merge branch 'main' into import-extension-visibility 2024-04-03 21:43:21 -07:00
Becca Royal-Gordon
54fd4b01b6 Add workaround flag for lazy import-as-member
In rdar://123649082, a project failed to build because of the lazy import-as-member loading changes in #71320. That project was configured in a way that broke modularization and the correct solution is to fix it, but out of an abundance of caution, add a `-disable-named-lazy-import-as-member-loading` frontend flag in case a project needs to temporarily restore the old behavior.

As a bonus, this lets us write a test to verify that lazy import-as-member loading has positive performance impact.
2024-03-05 11:09:17 -08:00
Doug Gregor
cff918428a Implement proper visibility rules for imported extensions
If an extension isn't imported either directly or via a transitive
(`@_exported`) import, its members should not be visible to name
lookup. Implement this behavior behind the experimental flag
ExtensionImportVisibility.
2024-03-04 07:43:54 -08:00
Becca Royal-Gordon
db19c19e19 Let module lookups ignore access control
…at least for declarations in the current module. We continue to pretend that inaccessible declarations in other modules do not exist.
2023-12-13 11:09:49 -08:00
Doug Gregor
6265f0c542 [SE-0395] Rename _Observation module to Observation
The review of SE-0395 is down to small details at this point that won't
affect the overall shape of the API much. Rename the model in
anticipation of that.
2023-06-30 11:01:02 -07:00
Doug Gregor
81acd82cf7 [Name lookup] Shadow the _Observation model as we do with other stdlib modules
Fixes rdar://111464071.
2023-06-28 14:30:03 -07:00
Pavel Yaskevich
6b323f1663 [BuilderTransform] Verify that builder type has at least one accessible build{Partial}Block
Check accessibility of all build{Partial}Block overloads and
diagnose if none of them are as accessible as type, otherwise
swift interfaces could end up with invalid result builder
declarations when type is public and all builder methods are
internal.

Resolves: rdar://104384604
2023-03-08 12:46:50 -08:00
Josh Soref
8f300ab884 spelling: that
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-05-01 04:32:22 -04:00
Doug Gregor
6a40a3a8aa [SE-0289] Add support for @resultBuilder.
"Function builders" are being renamed to "result builders". Add the
corresponding `@resultBuilder` attribute, with `@_functionBuilder` as
an alias for it, Update test cases to use @resultBuilder.
2020-10-20 13:24:51 -07:00
Brent Royal-Gordon
806125d6f8 Favor private imports during name lookup
Private imports are intended to make the file performing the import more or less source-compatible with the file being imported from, so that code from the original file can be modified by relatively simple syntactic transformations. However, their name shadowing behavior was very different from the original file. In the original file, other declarations in the same module would have shadowed declarations imported from any other module; in a file using a @_private import, they would all be considered imports, and thus all would be preferred equally. This could cause ambiguity in a file using a @_private import that was not present in the original file.

This commit changes that behavior by favoring @_private imports over other imports, so that if a name is visible through both a private and a non-private import, the one visible through the private import will shadow the other. This shadowing takes a higher priority than a scoped import, but a lower priority than the check for whether one of the modules is only visible through the other.

Fixes rdar://68312053.
2020-09-23 14:04:17 -07:00
Suyash Srijan
172c4be02d [Sema] Diagnose use of ambiguous property wrappers (#33688) 2020-08-29 02:38:42 +01:00
Robert Widmann
8aede31c2c [Gardening] Reshuffle Some Tests
Move reference dependency tests out of NameLookup and into
Incremental/Dependencies. These tests will need to be specialized for
the upcoming private dependencies code.
2020-05-05 10:55:58 -07:00
Varun Gandhi
a1716fe2a6 [Diagnostics] Update compiler diagnostics to use less jargon. (#31315)
Fixes rdar://problem/62375243.
2020-04-28 14:11:39 -07:00
Hamish Knight
5b99c2020f NFC: Re-organize NameBinding tests
The directory currently seems to have a mix of
tests for import resolution and name lookup.
Therefore split it into two directories;
ImportResolution and NameLookup.
2020-03-29 18:51:09 -07:00