Commit Graph

48 Commits

Author SHA1 Message Date
Zixu Wang
18a9d7002f [APIGen] Handle SPI availability for nested decls (#85048)
- Add SPI availability information to `APIAvailability` from attribute
`@_spi_available`.
- Correctly obtain effective availability for nested declarations
without immediate availability attributes.

Resolves rdar://159702280

<!--
If this pull request is targeting a release branch, please fill out the
following form:

https://github.com/swiftlang/.github/blob/main/PULL_REQUEST_TEMPLATE/release.md?plain=1

Otherwise, replace this comment with a description of your changes and
rationale. Provide links to external references/discussions if
appropriate.
If this pull request resolves any GitHub issues, link them like so:

  Resolves <link to issue>, resolves <link to another issue>.

For more information about linking a pull request to an issue, see:

https://docs.github.com/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
-->

<!--
Before merging this pull request, you must run the Swift continuous
integration tests.
For information about triggering CI builds via @swift-ci, see:

https://github.com/apple/swift/blob/main/docs/ContinuousIntegration.md#swift-ci

Thank you for your contribution to Swift!
-->
2025-11-04 11:34:05 -08:00
Allan Shortlidge
92227ad1cf AST: Introduce the Swift, anyAppleOS, and DriverKit platform kinds.
This change just stages in a few new platform kinds, without fully adding
support for them yet.

- The `Swift` platform represents availability of the Swift runtime across all
  platforms that support an ABI stable Swift runtime (see the pitch at
  https://forums.swift.org/t/pitch-swift-runtime-availability/82742).
- The `anyAppleOS` platform is an experimental platform that represents all of
  Apple's operating systems. This is intended to simplify writing availability
  for Apple's platforms by taking advantage of the new unified OS versioning
  system announced at WWDC 2025.
- The `DriverKit` platform corresponds to Apple DriverKit which is already
  supported by LLVM.
2025-10-27 19:15:04 -07:00
Doug Gregor
45fa67020e Merge pull request #85065 from DougGregor/c-sil-mangled-name
[SIL] Use mangled names + asmname for `@c` functions
2025-10-22 21:38:48 -07:00
Doug Gregor
fad8b24dbb [SIL] Use mangled names + asmname for @c functions
Instead of using the C name for `@c` functions in SIL, retain mangled
names and apply the `asmname` attribute, so we retain more type
information until later in the pipeline and avoid collisions.

Another part of rdar://137014448.
2025-10-22 10:54:42 -07:00
Mads Odgaard
c92e5b47f3 Merge pull request #84574 from madsodgaard/android-availability 2025-10-20 10:40:37 +09:00
Zixu Wang
d652100c3c [APIGen] Account for access scopes of declarations (#84116)
Correctly account for access scopes of declarations visited by APIGen:
Mark declarations with non-public access scopes as private SPIs.

Resolves rdar://159701853
2025-10-14 11:05:43 -07:00
(null)
cf041b126e address pltaform orders and other nits 2025-06-17 15:37:49 -04:00
michael-yuji
9a948a9c3b Merge branch 'main' into mchiu/freebsd 2025-05-21 16:29:16 -07:00
Zixu Wang
cd545300bf [APIGen] Don't record declarations from clang header files (#81086)
When Swift visits an `ExtensionDecl` from an `@objc @implementation`
extension, it fetches the implemented Objective-C interface declaration
from the header file and adds to the visitor.
We don't want these API records from `APIGenRecorder` for Swift API
descriptor, because we cannot correctly reason about their API access as
they depend on the header group which Swift doesn't know about.

Resolves rdar://148943382

<!--
If this pull request is targeting a release branch, please fill out the
following form:

https://github.com/swiftlang/.github/blob/main/PULL_REQUEST_TEMPLATE/release.md?plain=1

Otherwise, replace this comment with a description of your changes and
rationale. Provide links to external references/discussions if
appropriate.
If this pull request resolves any GitHub issues, link them like so:

  Resolves <link to issue>, resolves <link to another issue>.

For more information about linking a pull request to an issue, see:

https://docs.github.com/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
-->

<!--
Before merging this pull request, you must run the Swift continuous
integration tests.
For information about triggering CI builds via @swift-ci, see:

https://github.com/apple/swift/blob/main/docs/ContinuousIntegration.md#swift-ci

Thank you for your contribution to Swift!
-->
2025-04-30 15:37:06 -07:00
Slava Pestov
0155b41b50 AST: Extend @_originallyDefinedIn to allow specifying module name for linker directive purposes
The module name changes the symbol mangling, and also causes
TBDGen to emit linker directives. To separate out these two
behaviors, introduce a terrible hack. If the module name
contains a semicolon (`;`), the part before the semicolon
is the module name for mangling, and the part after the
semicolon is the module name for linker directives.

If there is no semicolon, both module names are identical,
and the behavior is the same as before.
2025-03-24 17:56:45 -04:00
Michael Chiu
7f0f2ac4dd Merge swiftlang#38335 2025-03-14 02:15:15 -04:00
Nate Chandler
35d06c325d [CoroutineAccessors] Witness and vtable dispatch.
And thunking.
2025-03-07 11:46:50 -08:00
Allan Shortlidge
d4d9c9e70a TBDGen: Adopt SemanticAvailableAttr. 2025-01-08 08:17:27 -08:00
Allan Shortlidge
d0f63a0753 AST: Split Availability.h into multiple headers.
Put AvailabilityRange into its own header with very few dependencies so that it
can be included freely in other headers that need to use it as a complete type.

NFC.
2025-01-03 18:36:04 -08:00
Kuba Mracek
6f4ae28520 [ASTMangler] Pass ASTContext to all instantiations of ASTMangler 2024-12-02 15:01:04 -08:00
Allan Shortlidge
36230cd9c6 AST: Use an accessor to get the PlatformKind from an AvailableAttr. 2024-11-21 09:10:36 -08:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Becca Royal-Gordon
07b9fe9ce6 Support @objc(CustomName) on extensions
This now specifies a category name that’s used in TBDGen, IRGen, and PrintAsClang. There are also now category name conflict diagnostics; these subsume some @implementation diagnostics.

(It turns out there was already a check for @objc(CustomName) to make sure it wasn’t a selector!)
2024-05-16 13:40:13 -07:00
Cyndy Ishida
84d36181a7 [TBDGen] Track unavailable declarations against the active platform for (#73284)
api generation

This resolves the bug where apijson files recorded declarations as
unavailable purely because it was unavailable on a unrelated platforms.

Resolves: rdar://113552185
2024-05-01 06:50:30 -07:00
Artem Chikin
1f14158a1d Introduce VisionOS Platform
This change introduces a new compilation target platform to the Swift compiler - visionOS.

- Changes to the compiler build infrastrucuture to support building compiler-adjacent artifacts and test suites for the new target.
- Addition of the new platform kind definition.
- Support for the new platform in language constructs such as compile-time availability annotations or runtime OS version queries.
- Utilities to read out Darwin platform SDK info containing platform mapping data.
- Utilities to support re-mapping availability annotations from iOS to visionOS (e.g. 'updateIntroducedPlatformForFallback', 'updateDeprecatedPlatformForFallback', 'updateObsoletedPlatformForFallback').
- Additional tests exercising platform-specific availability handling and availability re-mapping fallback code-path.
- Changes to existing test suite to accomodate the new platform.
2024-04-10 09:38:02 -07:00
Arnold Schwaighofer
9639e007d8 Teach TBD that in fragile resilient protocol mode the protocol table is visible 2024-03-11 09:49:38 -07:00
Allan Shortlidge
f49dbb06b6 TBDGen: Specify the correct macCatalyst platform ID in $ld$previous directives.
Resolves rdar://123491072
2024-03-05 19:05:19 -08:00
Allan Shortlidge
9a0598cda7 TBDGen: Use LinkerPlatformId enum type instead of casting to uint8_t.
Increase type safety by consistently using the `LinkerPlatformId` enum type,
instead of casting to/from `uint8_t` unnecessarily.

NFC.
2024-03-05 14:51:38 -08:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Slava Pestov
06b1aee360 Evaluator: Cache circular evaluation to avoid redundant diagnostics
Previously, if a request R evaluated itself N times, we would emit N
"circular reference" diagnostics. These add no value, so instead let's
cache the user-provided default value on the first circular evaluation.

This changes things slightly so that instead of returning an
llvm::Expected<Request::OutputType>, various evaluator methods take
a callback which can produce the default value.

The existing evaluateOrDefault() interface is unchanged, and a new
evaluateOrFatal() entry point replaces
llvm::cantFail(ctx.evaluator(...)).

Direct callers of the evaluator's operator() were updated to pass in
the callback. The benefit of the callback over evaluateOrDefault() is
that if the default value is expensive to constuct, like a dummy
generic signature, we will only construct it in the case where a
cycle actually happened, otherwise we just delete the callback.

(cherry picked from commit b8fcf1c709efa6cd28e1217bd0efe876f7c0d2b7)
2024-02-09 16:02:24 -08:00
Ellie Shin
72a7760027 Support package SIL linkage.
Decls with a package access level are currently set to public SIL
linkages. This limits the ability to have more fine-grained control
and optimize around resilience and serialization.
This PR introduces a separate SIL linkage and FormalLinkage for
package decls, pipes them down to IRGen, and updates linkage checks
at call sites to include package linkage.

Resolves rdar://121409846
2024-02-06 01:23:14 -08:00
Cyndy Ishida
7e5f39312d [TBDGen] update usages of MachO::SymbolKind -> MachO::EncodeKind, NFC (#71247) 2024-01-31 07:45:07 -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
Cyndy Ishida
331b11f39c [TBDGen] Determine whether symbols belong in TEXT/DATA to record in tbd
files
2023-11-10 08:48:28 -08:00
Allan Shortlidge
e91580bf0e TBDGen: Teach APIGenRecorder to emit API descriptors during -emit-module.
Make the changes to APIGenRecorder that are necessary to make it capable of
emitting API descriptors during -emit-module jobs. The output in this mode
differs from the output when run on an existing module in a couple of important
ways:

- The value for the `file` key in the descriptor JSON is now the path to the
  source file that defines the declaration responsible for the symbol. In
  `swift-api-extract` mode, the value for this key is the path to the module or
  swiftinterface which is unavailable during an -emit-module job since the module
  is usually not being emitted to its final installed location.
- Some additional symbols may be included in the API descriptor JSON because
  more of the AST is available when emitting the module.

Resolves rdar://110916764
2023-10-05 11:40:53 -07:00
Allan Shortlidge
80b1f4c1c2 TBDGen: Improve correctness of API symbol visibility and availability.
By plumbing the currently visited Decl through to APIRecorder we can improve
the correctness of API symbol visibility and availability in swift-api-extract
output.
2023-10-04 22:06:34 -07:00
Allan Shortlidge
6f1f0b0e17 TBDGen: Use isSPI() wrapper more consistently.
This ensures that different kinds of declarations with the `@_spi_available`
attribute are handled consistently.
2023-10-04 21:46:23 -07:00
Allan Shortlidge
0bc3fd3635 TBDGen: Introduce SymbolSource::getDecl() and adopt it.
By adopting this new utility, swift-api-extract more reliably gets the
ValueDecl associated with a symbol and therefore reports more accurate
availability info.
2023-10-04 21:46:23 -07:00
Zak Kent
6aafeec181 [Immediate] [SILGen] Implement on-demand compilation of globals 2023-08-17 11:03:11 -07:00
Zak Kent
a6eb4b44c7 [TBD] Refactored SymbolSourceMap to be a typedef 2023-08-17 09:55:49 -07:00
Allan Shortlidge
ca8bf981a4 NFC: Hoist queries for unavailable decl optimizations into the AST library.
Moving the query implementation up to the AST library from SIL will allow
conveniences to be written on specific AST element classes. For instance, this
will allow `EnumDecl` to expose a convenience that enumerates element decls
that are available during lowering.

Also, improve naming and documentation for these queries.
2023-08-04 17:39:26 -07:00
Cyndy Ishida
4f0e866061 [TBDGen] Ensure symbols listed include maccatalyst when library is built (#67160)
zippered.

This also introduces a dependency on new testing tool
llvm-tapi-diff. This allows for a structural difference check on tbd
files.

resolves: rdar://107368040
2023-07-07 08:40:07 -07:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Saleem Abdulrasool
0301e03cc3 TDBGen: add a workaround for a workaround for async PWT
When a protocol witness thunk is formed to a serialised protocol
containing an `async` function, the async function pointer to the
conformance needs to be made public due to a SIL Verifier check failure
(reference to a non-fragile function from within a public fragile
function).  Add a stop-gap solution of rolling an extra emission for a
private symbol as a public symbol to avoid the error (the underlying
issue has been open for ~6y and counting as of this commit).

This was identified by swift-package-manager (#64900).

Thanks to @DougGregor and @aschwaighofer for the discussion on this!
2023-04-06 09:01:55 -07:00
Allan Shortlidge
98b4e79d62 IRGen: Implement 'complete' unavailable decl optimization.
Part of rdar://106674022
2023-03-27 11:40:54 -07:00
Cyndy Ishida
ec4deafcfa [TBDGen] Remove InstalLAPI Flag logic (#64070)
The linker & TAPI doesnt use it anymore.
2023-03-03 17:54:01 -08:00
Xi Ge
b3dd80fc96 IRGen: consider deployment target when emitting $ld$previous symbols
Deployment target can be set before the introduction of a moved symbol. When that
happens, using the introductory version in the $ld$previous symbol could lead to ld
not redirecting the linkage path to the original dylib, which is a mistake when running
the App on newer OSs when the original dylib does exist.

rdar://105181824
2023-02-17 13:13:26 -08:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Cyndy Ishida
98fa58408f [swift][TBDGen] Stop adding redundant ObjC Classes (#62068)
TBD files contain a section reserved for obj-c classes. Previously,
TBDGen was adding symbols with this + normal globals with objc class
prefixes. This patch removes the extra globals being added.

This also accounts for this behavior for `validate-tbd-against-ir`
checking.

Resolves: rdar://101442087
2022-11-11 20:36:31 -08:00
Allan Shortlidge
38779f32c1 SILGen/IRGen: Delegate decision to skip @_silgen_name functions to TBDGenVisitor.
This allows SILGen for `#_hasSymbol` conditions to visit them and emit a declaration of the function appropriately.
2022-11-02 21:38:33 -07:00
Allan Shortlidge
fc20262009 TBDGen: Reimplement TBDGenVisitor using IRSymbolVisitor. 2022-10-30 09:14:29 -07:00
Allan Shortlidge
41269e6895 TBDGen: Merge TBDGen library into IRGen.
The relationship between the code in these two libraries was fundamentally circular, indicating that they should not have been split. With other changes that I'm making to remove circular dependencies from the CMake build graph I eventually uncovered that these two libraries were required to link each other circularly, but that had been hidden by other cycles in the build graph previously.
2022-10-27 11:28:02 -07:00