Commit Graph

111 Commits

Author SHA1 Message Date
Alexis Laferrière
aa75341b20 Sema: Accessors's SPI are tied to the attributes on the storage
Recent changes started using SPIGroupRequest on accessors specifically
to verify access to the wrappedValue of PropertyWrappers within the
direct access logic on variables using the property wrapper. Update
SPIGroupRequest to support this request and the type-checking logic to
accept the @_spi attribute on internal usable from inline accessors.

rdar://141964200
2025-01-13 17:02:40 -08:00
Alexis Laferrière
24a74af40c Tests: Clarify entity naming in spi_members.swift 2025-01-07 11:20:26 -08:00
Steven Wu
8150fb001d [InterfaceFile] Improve flag extraction from interface file
Improve the version/flags extract from interface file by moving away
from using Regex and limiting the search to the beginning of the file.

Switch away from Regex will give 5-10% improvement in time and
instruction counts, and limiting the search lines can save a lot of time
if the swiftinterface is large. For example, the extract time for Swift
stdlib is 10x faster after the patch.

Current strategey for limiting the line to search is by only parsing the
first comment block.
2024-10-31 12:46:05 -07:00
Allan Shortlidge
ac8aec32ea Sema: Correct the decl kind in a resilience diagnostic.
Not everything is a type, type checker.
2024-10-26 09:26:39 -07:00
Allan Shortlidge
7e6e8ed7b5 Sema: Fully check the availability of wrappedValue.
Call `checkDeclarationAvailability()`, instead of just diagnosing
unavailability.
2024-10-25 16:50:20 -07:00
Allan Shortlidge
9e93b7b730 Frontend: Remove support for -experimental-spi-imports flag.
Its functionality has been superseded by `@_spiOnly import`. There are no
longer any known clients and the flag was already unsupported in Swift 6, so
the functionality is now removed (but the flag is only deprecated for Swift 5).

Resolves rdar://136867210.
2024-10-01 17:27:22 -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
Alexis Laferrière
915b1e3def Sema: Update more tests with more precise message about exported conformances 2024-06-13 15:20:18 -07:00
Alexis Laferrière
3d611e2a85 Sema: Simplify warning about @_implementationOnly being deprecated 2024-04-22 14:44:44 -07:00
Alexis Laferrière
0a25248e4b Test: Expect warning on deprecated @_implementationOnly in tests 2024-04-22 13:08:20 -07:00
Allan Shortlidge
865c26c519 Tests: Use split-file to clean up client_reuse_spi.swift.
This results in clearer source locations for diagnostics.
2024-04-16 16:29:51 -07:00
Doug Gregor
61b19c8fbf Merge branch 'main' into import-extension-visibility 2024-04-03 21:43:21 -07:00
Alexis Laferrière
fb59f1fb11 Frontend: Enable @_spiOnly by default in Swift 6
Enabling `@_spiOnly` also enables stronger type-checking of SPI decls.
As this could be source breaking, it has always been opt-in. Turn it on
by default in Swift 6 mode where the stronger type-checking will also
become expected.

At the same time, disable the old alternative to `@_spiOnly` which was
designed to be compatible with old compilers. Any user of that feature
should move to `@_spiOnly` or `package import` instead.
2024-03-14 07:06:36 -07:00
Doug Gregor
fa88348afc Only emit error about missing import when we're missing the import
This eliminates some diagnostics that incorrectly refer to a missin
`@_spi` import as an outright missing import, which is incorrect. The
one test case changed here really is a case of a missing import that
happens to be SPI.
2024-03-04 11:47:15 -08:00
Alexis Laferrière
91c62de72d Merge pull request #70566 from xymus/spi-reexport-swift-only
Sema: Reexport SPI via Swift exported imports but not clang's
2024-01-03 09:33:34 -08:00
Alexis Laferrière
d7e39ff570 Sema: Reexport SPI via Swift exported imports but not clang exported imports
This is a new attempt at a reexport feature for SPI decls. The previous
behavior was to reexport SPIs only between modules with both `@_exported` and
an export-as relationship. The limitation on export-as turned out to be too
restrictive in some cases.

We may be tempted to reexport SPIs through all exported imports. However,
the exported imports are very common between clang module and it can lead
to surprises if dependencies between clang modules end up exporting SPIs from
unexpected modules.

As a middle ground, reexport SPI only through Swift `@_exported` dependencies,
and not through clang reexports. While this is a new distinction between Swift
and clang dependencies, I believe it provides the expected behavior and
the result is more straightforward than the current logic.

rdar://115901208
2023-12-20 15:34:19 -08:00
Alexis Laferrière
bd4e5e7615 Sema: Add test guarding against accidental SPI reexport via clang modules
Exported imports are common between clang modules. Make sure we test
against accidently reexporting Swift SPIs through these exported
imports.
2023-12-20 13:15:59 -08:00
Cyndy Ishida
f869bd7e8a [TBDGen] Write tbd-v5 files by default
* Fixup tests to handle new json based output.
* Use llvm-nm & readtapi to verify tbd file outputs.

resolves: rdar://117604275
2023-11-14 08:06:24 -08:00
Alexis Laferrière
011222da16 [AST] Fix source module correction logic to support @_spiOnly imports
This logic may override the module considered as the source of a decl to
ensure that only visible modules are printed in the swiftinterface. This
change updates it to consider @_spiOnly imported modules from the local
module as visible when printing the private swiftinterface only.

rdar://103325332
2023-08-16 16:40:57 -07:00
Alexis Laferrière
69493d1f4a [Sema] @_private imports brings is all SPI of the imported module
Within one module, SPI decls are always visible. Conceptually we want
the same behavior for `@_private` imports where the client pretends it's
part of the same module.

rdar://81240984
2023-08-04 10:30:36 -07:00
Becca Royal-Gordon
3732c75e97 Adopt %kind for certain access control diagnostics
These particular changes slightly alter some diagnostics.
2023-07-19 13:06:51 -07:00
Alexis Laferrière
635ddf5e64 [Test] Delete commented out check from report-ioi-in-spi 2023-07-06 10:04:17 -07:00
Alexis Laferrière
d221c1310f [Tests] Update tests using @_implementationOnly imports to use library-evolution 2023-07-05 16:20:42 -07:00
Ellie Shin
4fd67b20c1 Merge pull request #66291 from apple/es-rdar56
Add a test for extension of a public type conforming to SPI protocol
2023-06-02 12:27:58 -07:00
Ellie Shin
acabced779 Add a test for extension of a public type conforming to SPI protocol
Ref: rdar://63470756
2023-06-01 17:02:10 -07:00
Ellie Shin
32f53d1eb8 Add implicit SPI import feature
API development sometimes requires a redesign while supporting early
adopters. Currently this is done by adding @_spi(name) to the API but
that requires adding the attribute in import statements as well, causing
manual overhead of adding and then removing when the redesign is done.

This PR introduces a special spi group name '_' and allows an implicit
spi import of a module containing API attributed with '@_spi(_)'

Resolves rdar://109797632
2023-06-01 15:33:04 -07:00
Allan Shortlidge
93a96e81c2 Sema: Suppress explicit availability diagnostics on non-Darwin targets.
Suggesting the addition of an `@available` attribute on Linux and Windows is
inapprorpriate given that Swift is not ABI stable on those platforms.

Resolves rdar://107387133
2023-05-08 14:53:12 -07:00
Allan Shortlidge
f11eaf16eb Sema: Diagnose accessor exportability.
Properties may have `@_spi` setters and therefore the exportability of a
referenced accessor may differ from the exportability of the storage.
2023-05-01 15:34:08 -07:00
Allan Shortlidge
aef5e42457 Sema: Inherit SPI groups when synthesizing modify accessor.
Resolves rdar://108069565
2023-05-01 15:34:08 -07:00
Ellie Shin
ef321c9fd2 Allow @usableFromInline and @inlinable to package decls
Add tests for packgae inline
Add more package acl tests

Resolves rdar://104617133
2023-03-16 11:21:11 -07:00
Alexis Laferrière
ab3bf3260f [ModuleInterface] Print the @_spiOnly attribute without comments
This attribute was commented out in the private swiftinterface for
backwards compatibility with older compilers unaware of the attribute.
This scenario shouldn't be a problem anymore and without that attribute
some imports can raise errors. Let's print the attribute as it was
written in the sources without commenting it out.
2023-03-09 15:34:49 -08:00
Allan Shortlidge
8e5988e5fc NFC: Increase test coverage for SPI enum elements.
These tests identified a gap in type checking the exportability of case statements. Unfortunately this gap is not simple to close, since exportability is usually checked during availability checking but availability checking isn't appropriate for case statements and there isn't existing infrastructure to check exportability independently.
2022-11-29 22:11:02 -08:00
Allan Shortlidge
49ce27acae Sema: Diagnose @_spi on elements of @frozen enums.
rdar://72873771
2022-11-29 22:11:02 -08:00
Allan Shortlidge
2b0807d021 ModuleInterface: Avoid printing @_spi enum case decls in public swiftinterfaces.
rdar://72873771
2022-11-29 22:11:02 -08:00
Alexis Laferrière
552d3a4984 [Sema] Restrict reexported SPIs to modules with an export_as relationship
@_exported exports SPIs only when the exported module defines export_as
pointing to the exporter module. Other reexports do not reexport SPIs.
This is to prevent SPI reexporting to get out of hands with the wide
reexports of the Objective-C world.

rdar://102335473
2022-11-14 13:17:55 -08:00
Alexis Laferrière
c0abde01a2 [Sema] @_exported imports export @_spi decls too
Enable transitive imports of all SPI groups through @_exported imports.
This brings to SPI the same behavior that we have for API.

```
// Module A
@_spi(S) public func foo() {}

// Module B
@_exported import A

// Module C
@_spi(S) import B

foo() // SPI imported through the reexport of A from B
```

rdar://101566534
2022-11-10 16:46:14 -08:00
Allan Shortlidge
c54689bf49 Test: Fix copy-pasta in spi_helper.swift by making SPIStruct type a struct instead of a class. 2022-10-21 20:59:13 -07:00
Alexis Laferrière
7aff9c1bd0 [Sema|Tests] Update users of library-level=api to expect new diagnostics 2022-09-19 09:06:30 -07:00
Alexis Laferrière
4e3e07b241 Revert "[Sema|Tests] Update users of library-level=api to expect new diagnostics"
This reverts commit d4a5cb2e71.
2022-09-16 09:50:08 -07:00
Alexis Laferrière
d4a5cb2e71 [Sema|Tests] Update users of library-level=api to expect new diagnostics 2022-09-14 17:00:05 -07:00
Alexis Laferrière
47d2f1acc4 [Sema] Check inconsistent @_spiOnly imports within one source file 2022-09-12 17:17:23 -07:00
Alexis Laferrière
bc4efe518f [Sema] Always error on public uses of conformance from @_spiOnly import 2022-09-09 09:50:56 -07:00
Alexis Laferrière
d1e36b0a12 [Sema|lit] Intro lit substitution for generating the 2 swiftinterfaces
Intro the lit substitution
`%target-swift-emit-module-interfaces(Main.swiftinterface,
Main.private.swiftinterface` to generate both the public and private
swiftinterface. And use it in spi-only-import-exportability.swift.

To verify the generated interfaces I would recommend to keep two calls
to `%target-swift-typecheck-module-from-interface` as each is a
different invocation likely to fail.
2022-09-09 09:20:51 -07:00
Alexis Laferrière
021dc8e416 [Sema] Error on implementation-only imported types in SPI with @_spiOnly
This used to be just a warning because it happened to work when clients
used only swiftmodules. Some projects have been using it as an
alternative to @_spiOnly imports. Now that we have an official feature
we can complete the diagnositc and error on implementation-only imports
types used in SPI.
2022-09-09 09:20:51 -07:00
Alexis Laferrière
6d396b4834 [Sema] Check @_spiOnly imported decls exportability
Decls imported via an @_spiOnly import can only be used in @_spi decls
signatures, internal decl signatures and non-inlinable function bodies.
2022-09-09 09:20:51 -07:00
Alexis Laferrière
67e35c3b3e [ModuleInterface] Print @_spiOnly imports in the private swiftinterface 2022-09-02 12:30:47 -07:00
Alexis Laferrière
a530e3841a [Sema] Always accept @_spiOnly in a swiftinterface
Let's not print the -experimental-spi-only-imports flag in the
swiftinterface and always consider it available there. This is a more
backwards and forwards compatible way to handle swiftinterfaces
evolution.
2022-09-02 09:37:32 -07:00
Alexis Laferrière
b680084748 [Sema] @_spiOnly needs to be enabled with a flag 2022-09-01 15:16:46 -07:00
Allan Shortlidge
c13dd18ef8 Sema: Diagnose the availability of global actor attributes. This includes SPI and resilience diagnostics. 2022-08-20 17:57:25 -07:00
Alexis Laferrière
4d9c8ee5eb [Sema] Generalize the downgraded warning for exportability check
This warning will be used more generally so let's make bring back the
diagnostic in line with the error version.
2022-06-29 16:09:42 -07:00