Commit Graph

252 Commits

Author SHA1 Message Date
Konrad `ktoso` Malawski
95920b2570 [Concurrency] Fix init task group with flags availability
resolves rdar://112469076
2023-08-02 12:02:27 +09:00
Mike Ash
2d238bcea5 Merge pull request #67168 from mikeash/ptrauth-struct-context-descriptors
[Runtime][IRGen] Sign type context descriptor pointers.
2023-07-11 17:03:53 -04:00
Mike Ash
fe7e13bba5 [Runtime][IRGen] Sign type context descriptor pointers.
Ensure that context descriptor pointers are signed in the runtime by putting the ptrauth_struct attribute on the types.

We use the new __builtin_ptrauth_struct_key/disc to conditionally apply ptrauth_struct to TrailingObjects based on the signing of the base type, so that pointers to TrailingObjects get signed when used with a context descriptor pointer.

We add new runtime entrypoints that take signed pointers where appropriate, and have the compiler emit calls to the new entrypoints when targeting a sufficiently new OS.

rdar://111480914
2023-07-07 18:10:35 -04:00
Slava Pestov
3f45c17336 AST: Fill in ASTContext::getSwift59Availability() 2023-07-07 13:57:13 -04: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
Allan Shortlidge
40648b7617 AST: Handle malformed PatternBindingDecls in parentDeclForInferredAvailability().
Unfortunately, I don't have reduced reproduction for the crash that motivated
this fix, but similar precautions are taken elsewhere when handling
PatternBindingDecls.
2023-05-31 18:23:43 -07:00
Slava Pestov
4318a36be6 Sema: Availability checking for variadic generic types 2023-05-12 22:50:25 -04: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
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