Commit Graph

244 Commits

Author SHA1 Message Date
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
Konrad `ktoso` Malawski
10b49bcb85 [Executors] Ensure we treat DA older than 5.9 always as DefaultActor (#64800) 2023-04-04 11:04:53 +09:00
Allan Shortlidge
367dbd069d IRGen: Skip lowering unavailable opaque type descriptors.
Part of rdar://107425181
2023-03-31 09:36:42 -07:00
Allan Shortlidge
6f5b804224 AST: Pattern binding decls inherit their var decl's availability.
This ensures SIL lowering will avoid generating code for unavailable global
vars when `-unavailable-decl-optimization=complete` is specfied.

Part of rdar://106674022
2023-03-27 11:40:54 -07:00
Allan Shortlidge
620462ddf6 Sema: Don't diagnose declarations more available than unavailable container.
It turns out that we must allow declarations with `introduced:` availability
nested inside of other declarations that are `unavailable` in order to
influence weak linking. Stop diagnosing declarations as being more available
than their unavailable containers and revert some changes to availability
inference that were designed to avoid creating these nestings but caused
regressions for declarations marked `@_spi_available.`

Reverts parts of https://github.com/apple/swift/pull/64310,
https://github.com/apple/swift/pull/64015, and
https://github.com/apple/swift/pull/62900.
2023-03-21 13:55:05 -07:00
Allan Shortlidge
4058ad1421 AST: Improved inferred availability accuracy.
Previously, when creating availability attributes for synthesized declarations
we would identify some set of reference declarations that the synthesized
declaration should be as-available-as. The availability attributes of the
reference declarations would then be merged together to create the attributes
for the synthesized declaration. The problem with this approach is that the
reference declarations themselves may implicitly inherit availability from their
enclosing scopes, so the resulting merged attributes could be incomplete. The
fix is to walk though the enclosing scopes of the reference declarations,
merging the availability attributes found at each level.

Additionally, the merging algorithm that produces inferred availability
attributes failed to deal with conflicts between platform specific and platform
agnostic availability. Now the merging algorithm notices when platform agnostic
availability should take precedence and avoids generating conflicting platform
specific attributes.

Resolves rdar://106575142
2023-03-13 18:27:03 -07:00
Mike Ash
a5765abfa9 Merge pull request #61918 from mikeash/future-version-consistency
Standardize "future" OS versions on 99.99.
2023-03-07 12:15:02 -05:00
Allan Shortlidge
9c76e0d1bf AST: Emit correct synthesized availability attributes for unownedExecutor property.
When synthesizing a declaration and inferring its availability, the synthesized attribute should factor in unavailability of the parent declarations. This recently regressed with https://github.com/apple/swift/pull/63361. However, the previous implementation did not produce correct results, either, because the logic for merging availability attributes produced a non-sensical result when both `unavailable` and `introduced:` availability attributes were merged. For example, this was the result for the synthesized `unownedExecutor` property of an actor when the actor was marked unavailable:

```
@available(macOS, unavailable)
actor A {
  // Incorrectly synthesized availability for `unownedExecutor` which results from merging
  // the unavailability of the parent and the availability of the UnownedSerialExecutor type.
  @available(macOS, unavailable, introduced: macOS 10.15)
  @_semantics("defaultActor") nonisolated final var unownedExecutor: UnownedSerialExecutor { get }
}
```

This is fixed by omitting all version components from the synthesized attribute when the overall attribute kind is "unavailable".

Additionally, I discovered that the `concurrency_availability.swift` test case was no longer testing what it intended to test. The conformances to `Actor` for each `actor` in the test were no longer being synthesized and therefore `unownedExecutor` was not being synthesized. That was fixed by importing the `_Concurrency` module directly, which seems to be necessary because of the `-parse-stdlib` flag in the test.

Resolves rdar://106055566
2023-03-02 10:09:30 -08:00
Allan Shortlidge
b53eba02b7 Merge pull request #58545 from cbjeukendrup/fixit_deprec_self_init
Fix #57354: Fix-it for deprecated initializers removes the `.init` part from `self.init`
2023-01-24 09:09:06 -08:00
Allan Shortlidge
3024feb8d1 AST: Consolidate instantiation of AvailabilityContext from AvailabilityAttr.
Related to rdar://104398146
2023-01-18 16:44:07 -08:00
Casper Jeukendrup
7f9885b791 Let generated availability attributes of initializers of subclasses inherit the message and renaming from the initializer of the superclass 2023-01-12 22:35:33 +01:00
Allan Shortlidge
76d1565a9d Sema: Lift restriction that declarations with @_backDeploy must have explicit availability.
Resolves rdar://103880356
2023-01-06 08:18:00 -08:00
Allan Shortlidge
04b37ab163 Sema: Allow AnyColorBox in SwiftUI to derive from a less available base class.
Resolves rdar://101915368
2022-11-30 14:17:27 -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
Mike Ash
98b9d3ddc4 Standardize "future" OS versions on 99.99.
We had multiple different "future" versions for different OSes. Make them all the same for consistency.

rdar://101929999
2022-11-03 17:01:19 -04:00
Hamish Knight
20830cc2fb [Profiler] Avoid profiling unavailable decls
Such decls don't provide useful coverage info.

rdar://83253091
2022-09-19 10:06:36 +01:00
Erik Eckstein
24d077e78b IRGen: re-enable generate static arrays in read-only data sections.
So far, static arrays had to be put into a writable section, because the isa pointer and the (immortal) ref count field were initialized dynamically at the first use of such an array.

But with a new runtime library, which exports the symbols for the (immortal) ref count field and the isa pointer, it's possible to put the whole array into a read-only section. I.e. make it a constant global.

rdar://94185998

This reverts the revert commit df353ff3c0.
Also, I added a frontend option to disable this optimization: `-disable-readonly-static-objects`
2022-06-21 18:30:42 +02:00
Nate Chandler
0a2c3ec7a8 Use platform versions in getSwift57Availability. 2022-06-17 17:25:37 -07:00
Erik Eckstein
df353ff3c0 Revert "IRGen: generate static arrays in read-only data sections."
This reverts commit aca0d8358b.

I need to fix a problem before this can actually land.
2022-06-17 20:32:32 +02:00
Erik Eckstein
aca0d8358b IRGen: generate static arrays in read-only data sections.
So far, static arrays had to be put into a writable section, because the isa pointer and the (immortal) ref count field were initialized dynamically at the first use of such an array.

But with a new runtime library, which exports the symbols for the (immortal) ref count field and the isa pointer, it's possible to put the whole array into a read-only section. I.e. make it a constant global.

rdar://94185998
2022-06-17 11:21:29 +02:00
Robert Widmann
967896c8f6 Availability Bounds for Parameterized Existential Runtime Metadata Functions 2022-05-03 20:01:16 -07:00
Allan Shortlidge
e25b822f7a Merge pull request #41673 from tshortli/inlining-availability-checking
Add -target-min-inlining-version to aid type checking for inlinable functions in resilient libraries
2022-03-07 17:30:59 -08:00
Xi Ge
ce07ce2dbc frontend: add basic support for @_spi_available 2022-03-04 21:26:56 -08:00
Becca Royal-Gordon
c67804902f Add resilience boundary around non-inlinable bodies
Previously, the availability checker has assumed that no code in a module is available on less than the minimum deployment target. In modules using library evolution, this is not actually true--certain function bodies can be inlined into modules with lower minimum deployment targets, where they can run against versions of the library that had lower minimum deployment targets. By failing to check for availability violations in these function bodies that relate to versions below the minimum deployment target, we can end up allowing inlinable code that doesn't compile with the correct runtime linkage or has other serious problems.

This commit lowers the root type refinement context's avialability to the value of the -target-min-inlining-version option (if provided) and then raises it again inside the bodies of functions whose implementations are not exposed to clients. This introduces some incorrect typechecking of declaration signatures, but we'll fix that in another commit.
2022-03-04 10:56:01 -08:00
Arnold Schwaighofer
34bde99d20 Add getSwift57Availability() with a future platform version 2022-02-17 07:37:15 -08:00
Arnold Schwaighofer
1ffcaf4440 Update getSwift56Availability() with platform versions 2022-02-17 07:22:35 -08:00
Ben Barham
2c10d4971e Fix ambiguous call to report_fatal_error
report_fatal_error added a `const Twine &` overload a while ago, which
was fine since `const std::string &` was a better match.
`const std::string &` was recently removed, however, which then caused
an ambiguous match between `const Twine &` and `StringRef` overloads.
2021-11-12 15:30:13 +10:00
Arnold Schwaighofer
0bb29449bd Fix spelling of accessor to getAvailabeAttrs -> getAvailableAttrs 2021-10-30 06:16:30 -07:00
Arnold Schwaighofer
c2b2f1331f SIL representation 2021-10-06 04:54:49 -07:00
Kuba Mracek
b073df2c6d 64-bit watchOS should imply a 5.3 minimum version of the Swift runtime 2021-09-23 18:02:56 -07:00
swift-ci
29e26eb71a Merge pull request #39044 from DougGregor/back-deploy-flag 2021-08-25 12:14:07 -07:00
Doug Gregor
76c4ac8263 Add a temporary flag to stage in back-deployment of concurrency.
Add a frontend-only flag `-enable-experimental-back-deploy-concurrency`
to be used to stage in the back deployment of concurrency. At present,
all it does is lower the availability minimums for use of concurrency
features.
2021-08-23 12:55:58 -07:00
Varun Gandhi
98e81cd5c9 [IRGen] De-duplicate implementations of minimum OS versions supporting mangling.
This makes it easier to add handling for new types with special mangling,
as only one place needs to be changed instead of two.
2021-08-20 16:02:40 -07:00
Alastair Houghton
ad147308af Merge pull request #38309 from al45tair/problem/47902425
[Runtime] Add ObjC support to isKnownUniquelyReferenced.
2021-08-02 17:39:49 +01:00
Alastair Houghton
abec55f432 [Runtime] Add ObjC support to isKnownUniquelyReferenced.
Add code to support detecting uniquely referenced Objective-C and Core
Foundation objects.

rdar://47902425
rdar://66805490
2021-07-29 16:29:48 +01:00
Ben Barham
e7e9b57051 Replace @completionHandlerAsync with @available(*, renamed:)
Instead of a new attribute `@completionHandlerAsync`, allow the use of
the existing `renamed` parameter of `@available` to specify the
asynchronous alternative of a synchronous function.

No errors will be output from invalid names as `@completionHandlerAsync`
had, but if a function is correctly matched then it will be used to
output warnings when using the synchronous function in an asynchronous
context (as before).

Resolves rdar://80612731
2021-07-29 09:14:44 +10:00
nate-chandler
5e0d0fb91b Merge pull request #36765 from nate-chandler/generic-metadata-prespecialization-components/generic-value-witnesses
[IRGen] Use generic value witnesses for prespecialized types.
2021-06-30 07:03:40 -07:00
Nate Chandler
07ba7a6f3c [runtime] Exported multi payload enum witnesses.
When witness tables for enums are instantiated at runtime via

    swift::swift_initEnumMetadataMultiPayload

the witnesses

    getEnumTagSinglePayload
    storeEnumTagSinglePayload

are filled with swift_getMultiPayloadEnumTagSinglePayload (previously
getMultiPayloadEnumTagSinglePayload) and
swift_storeMultiPayloadEnumTagSinglePayload (previously
storeMultiPayloadEnumTagSinglePayload).  Concretely, that occurs when
instantiating the value witness table for a generic enum which has more
than one case with a payload, like Result<T>.  To enable the compiler to
do the same work, those functions need to be visible to it.

Here, those functions are made visible to the compiler.  Doing so
requires changing the way they are declared and adding them to
RuntimeFunctions.def which in turn requires the definition of some
functions to describe the availability of those functions.
2021-06-25 21:03:56 -07:00
Mishal Shah
23c3b15f5f Support Xcode 13 beta
* Updating availability versions
* Remove all remaining overlays in stdlib/public/Darwin/*:
   - ObjectiveC
   - Dispatch
   - CoreFoundation
   - CoreGraphics
   - Foundation
2021-06-07 12:04:31 -07:00
Mishal Shah
b5a01ba5e0 Support for x86_64 watchOS simulator
* Start testing watchOS simulator x86_64 and i386 by default

Users will require to install watchOS 6.2 or older simulator to support i386.

1. Install watchOS 6.2 or older simulator (Xcode -> Preferences -> Components -> Simulators).
2. Create a 32-bit watchOS device.
3. Run:
`xcrun simctl create 'Apple Watch Series 2 - 42mm' com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-2-42mm com.apple.CoreSimulator.SimRuntime.watchOS-6-2`
2021-04-22 20:06:17 -07:00
Mike Ash
1173b737aa [Concurrency] Add availability to Concurrency APIs.
This allows programs to target older OSes while using Concurrency behind an availability check. When targeting older OSes, the symbols are weak-linked and the compiler will require the use of Concurrency features to be guarded by an availability check.

rdar://75850003
2021-04-01 10:42:08 -04:00
Nate Chandler
f605cacfeb Filled out platforms for Swift 5.4 availability.
Previously, the availability was "Future", meaning that any features
that were gated to be available in "Swift 5.4" would only be used if the
target were the highest possible version number (like iOS 99).  Here
that is fixed by using the OS versions that actually shipped with Swift
5.4.

rdar://75978438
2021-03-30 10:14:35 -07:00
Richard Wei
de2dbe57ed [AutoDiff] Bump-pointer allocate pullback structs in loops. (#34886)
In derivatives of loops, no longer allocate boxes for indirect case payloads. Instead, use a custom pullback context in the runtime which contains a bump-pointer allocator.

When a function contains a differentiated loop, the closure context is a `Builtin.NativeObject`, which contains a `swift::AutoDiffLinearMapContext` and a tail-allocated top-level linear map struct (which represents the linear map struct that was previously directly partial-applied into the pullback). In branching trace enums, the payloads of previously indirect cases will be allocated by `swift::AutoDiffLinearMapContext::allocate` and stored as a `Builtin.RawPointer`.
2020-11-30 15:49:38 -08:00
Alexis Laferrière
e509d6883a Revert "[Sema] Fix availability checking in inlinable code" 2020-10-14 10:52:11 -07:00
Alexis Laferrière
2f182c2b78 [Sema] Consider unavailable functions as being unreachable
This has the effect of rejecting unavailable overrides to available
methods in a similar way as overrides that are less available than the
introduction are rejected.
2020-10-09 10:40:21 -07:00
Nate Chandler
607772aaa2 [Runtime] Stubbed entry points for task de/alloc. 2020-09-30 18:57:48 -07:00
Nate Chandler
3edf8e16de [metadata prespecialization] Bump availability.
Previously, the availability was 5.3.  Since
compareProtocolConformanceDescriptors was added in 5.4 and was used by
metadata accessors with baked-in checks for arguments which matched
prespecializations, 5.3 was incorrect.  Moreover, now that the searching
for matches is done by getGenericMetadata, the metadata accessors no
longer contain the early exits, so running against a 5.3 runtime would
entail the metadata accessor failing to produce canonical prespecialized
records.

Here, the availability is bumped to 5.4 which includes the runtime
changes to support the metadata accessors not having early exits to
return prespecialized records.
2020-08-14 11:24:41 -07:00
Nate Chandler
b0fc8daa83 [Runtime] Add entry point to canonicalize metadata.
The new function swift_getCanonicalSpecializedMetadata takes a metadata
request, a prespecialized non-canonical metadata, and a cache as its
arguments.  The idea of the function is either to bless the provided
prespecialized metadata as canonical if there is not currently a
canonical metadata record for the type it describes or else to return
the actual canonical metadata.

When called, the metadata cache checks for a preexisting entry for this
metadata.  If none is found, the passed-in prespecialized metadata is
added to the cache.  Otherwise, the metadata record found in the cache
is returned.

rdar://problem/56995359
2020-07-15 15:27:36 -07:00
Nathan Hawes
244dc4a768 [AST] Rename PlatformKind::OSX to PlatformKind::macOS
Because the names are coming from a .def file used for printing too, this
simplifies the printing logic as well.
2020-07-08 16:29:31 -07:00
Mishal Shah
60d996f060 [Apple Silicon] Add support for triple and availability canonicalization 2020-07-02 19:26:25 -07:00