Commit Graph

14355 Commits

Author SHA1 Message Date
Doug Gregor
1f1f703afe Drop @concurrent from parameter to @asyncHandler entry point.
The async handler code doesn't really run concurrently with where it is
launched, despite the implementation currently using `runDetached`
internally. Drop the @concurrent and bitcase it back on when needed.
2021-01-29 09:53:22 -08:00
Doug Gregor
581e6662b7 Adopt @concurrent in withCancellationHandler. 2021-01-28 13:20:18 -08:00
Doug Gregor
9efb44fde8 Adopt @concurrent in Task APIs 2021-01-28 10:03:09 -08:00
Doug Gregor
ba8819eb58 [Concurrent] Introduce concurrent function types.
Introduce `@concurrent` attribute on function types, including:
* Parsing as a type attribute
* (De-/re-/)mangling for concurrent function types
* Implicit conversion from @concurrent to non-@concurrent
- (De-)serialization for concurrent function types
- AST printing and dumping support
2021-01-27 14:22:32 -08:00
Arnold Schwaighofer
b0d31730de Merge pull request #35303 from aschwaighofer/introduce_swiftasync_lowering
Add llvm::Attribute::SwiftAsync to the context parameter
2021-01-26 06:03:19 -08:00
Saleem Abdulrasool
62f9050158 Merge pull request #35584 from compnerd/single-threaded-drain
Concurrency: support draining the main queue in single threaded mode
2021-01-25 20:06:32 -08:00
Philippe Hausler
6e05240426 AsyncSequence and protocol conformance rethrows (#35224)
* Initial draft of async sequences

* Adjust AsyncSequence associated type requirements

* Add a draft implementation of AsyncSequence and associated functionality

* Correct merge damage and rename from GeneratorProtocol to AsyncIteratorProtocol

* Add AsyncSequence types to the cmake lists

* Add cancellation support

* [DRAFT] Implementation of protocol conformance rethrowing

* Account for ASTVerifier passes to ensure throwing and by conformance rethrowing verifies appropriately

* Remove commented out code

* OtherConstructorDeclRefExpr can also be a source of a rethrowing kind function

* Re-order the checkApply logic to account for existing throwing calculations better

* Extract rethrowing calculation into smaller functions

* Allow for closures and protocol conformances to contribute to throwing

* Add unit tests for conformance based rethrowing

* Restrict rethrowing requirements to only protocols marked with @rethrows

* Correct logic for gating of `@rethrows` and adjust the determinates to be based upon throws and not rethrows spelling

* Attempt to unify the async sequence features together

* Reorder try await to latest syntax

* revert back to the inout diagnosis

* House mutations in local scope

* Revert "House mutations in local scope"

This reverts commit d91f1b25b59fff8e4be107c808895ff3f293b394.

* Adjust for inout diagnostics and fall back to original mutation strategy

* Convert async flag to source locations and add initial try support to for await in syntax

* Fix case typo of MinMax.swift

* Adjust rethrowing tests to account for changes associated with @rethrows

* Allow parsing and diagnostics associated with try applied to for await in syntax

* Correct the code-completion for @rethrows

* Additional corrections for the code-completion for @rethrows this time for the last in the list

* Handle throwing cases of iteration of async sequences

* restore building XCTest

* First wave of feedback fixes

* Rework constraints checking for async sequence for-try-await-in checking

* Allow testing of for-await-in parsing and silgen testing and add unit tests for both

* Remove async sequence operators for now

* Back out cancellation of AsyncIteratorProtocols

* Restructure protocol conformance throws checking and cache results

* remove some stray whitespaces

* Correct some merge damage

* Ensure the throwing determinate for applying for-await-in always has a valid value and adjust the for-await-in silgen test to reflect the cancel changes

* Squelch the python linter for line length
2021-01-25 18:48:50 -08:00
Saleem Abdulrasool
4f740a4784 Concurrency: support draining the main queue in single threaded mode
When built in single threaded mode, the runtime does not use dispatch to
queue the tasks.  As a result, pumping the dispatch main queue will
simply wait indefinitely.  In the single threaded mode, simply halt
execution and drain all pending tasks before returning.  This allows
forward progress in the single threaded mode.
2021-01-25 09:23:04 -08:00
Saleem Abdulrasool
bbe3d4fb18 Merge pull request #35576 from compnerd/hlsl
Platform: add HLSL compiler to the WinSDK modulemap
2021-01-24 20:03:46 -08:00
Saleem Abdulrasool
682eeb4be7 Merge pull request #35578 from 3405691582/ReflectionTestDependsOnGlibc
[stdlib] Add missing Glibc dependency for OpenBSD.
2021-01-24 20:02:44 -08:00
3405691582
6adaf48e96 [stdlib] Add missing Glibc dependency for OpenBSD.
Otherwise, the build may fail as the build attempts to build
SwiftReflectionTest before Glibc has been built.
2021-01-24 18:10:02 -05:00
Saleem Abdulrasool
3c9e76d5fe Concurrency: attempt to handle Windows draining
Rather than just simply invoking abort on Windows, attempt to load
dispatch and execute the main loop by looking up `dispatch_main` in the
module.  Assuming that dispatch was used already, the `LoadLibraryW`
will provide the handle to the module currently mapped in.  This still
is not correct, since we do not link to libdispatch, so we cannot have
invoked any dispatch queuing methods.  However, this is better than the
previous behaviour of simply aborting.

This resolves the symptom in SR-14086, but not the underlying problem.
2021-01-24 14:44:11 -08:00
Saleem Abdulrasool
997cb0f671 Platform: add HLSL compiler to the WinSDK modulemap
The DirectX subsystem may require access to the HLSL compiler for
building the shaders before uploading to the GPU.  This is adds to the
modulemap the D3DCompiler module to get access to the compiler.
2021-01-24 13:10:54 -08:00
Saleem Abdulrasool
4084f7a5a6 Platform: add dxgi1_6 to the Direct3D module
There is no usermode header which has the DXGI1.6 interfaces included
unfortunately.  This adds the interfaces to the module which is required
for IDXGIAdapter4 interface.
2021-01-23 12:41:20 -08:00
Konrad `ktoso` Malawski
80ee936a72 Revert "[Concurrency] isCanceled spelling to follow guidance" 2021-01-23 07:27:34 +09:00
Mike Ash
4988127e99 Merge pull request #35525 from mikeash/swift_asprintf-static-checking
[Runtime] Mark swift_asprintf with __attribute__((__format__))
2021-01-22 15:04:39 -05:00
Arnold Schwaighofer
daa72d3cc5 Add llvm::Attribute::SwiftAsync to the context parameter
* Adds support for generating code that uses swiftasync parameter lowering.

* Currently only arm64's llvm lowering supports the swift_async_context_addr intrinsic.

* Add arm64e pointer signing of updated swift_async_context_addr.

This commit needs the PR llvm-project#2291.

* [runtime] unittests should use just-built compiler if the runtime did

This will start to matter with the introduction of usage of swiftasync parameters which only very recent compilers support.

rdar://71499498
2021-01-22 10:01:55 -08:00
Mike Ash
216e555ad6 [Runtime] Mark swift_asprintf with __attribute__((__format__))
This gives us build-time warnings about format string mistakes, like we would get if we called the built-in asprintf directly.

Make TypeLookupError's format string constructor a macro instead so that its callers can get these build-time warnings.

This reveals various mistakes in format strings and arguments in the runtime, which are now fixed.

rdar://73417805
2021-01-22 10:54:45 -05:00
Konrad `ktoso` Malawski
8b37455774 [Concurrency] isCanceled spelling to follow guidance 2021-01-22 12:09:19 +09:00
Saleem Abdulrasool
e508b1ab14 Platform: extend the D3D v10 module
Add the extensions for the Direct3D v10 API to enable access to the
newer DXGISwapChain interfaces.  Additionally, correct the linking to
ensure that we pick up the v10 version of the import library.
2021-01-21 08:46:47 -08:00
Saleem Abdulrasool
b6893384c1 Merge pull request #35526 from compnerd/dxgi
Platform: add Direct3D11 module
2021-01-20 18:01:50 -08:00
Saleem Abdulrasool
86a8b1b4dc Platform: add Direct3D11 module
This adds the Direct3D v11 module for Windows.  This is required to gain
access to the DXGI interfaces, which homes the DXGISwapChain interface.
2021-01-20 15:28:27 -08:00
swift-ci
e27578b1e1 Merge pull request #35506 from 3405691582/OpenBSDSwiftStdint 2021-01-20 12:39:35 -08:00
Richard Wei
e3db926e0c [AutoDiff] Remove '_Differentiable.zeroTangentVectorInitializer'. (#35329)
Remove `_Differentiable.zeroTangentVectorInitializer` to address the feedback on the [proposal thread](https://forums.swift.org/t/differentiable-programming-for-gradient-based-machine-learning/42147). The corresponding change has already been made in the [proposal](https://github.com/rxwei/swift-evolution/blob/autodiff/proposals/0000-differentiable-programming.md).

Removed components:
- `zeroTangentVectorInitializer` and `zeroTangentVector` in `Differentiable`, `Array`, `Optional`, `Float`, `Double`, `Float80`, and SIMD types.
- `zeroTangentVectorInitializer` synthesis logic in `Differentiable` derived conformances.
2021-01-20 10:45:03 -08:00
Dave Lee
e843c72ff9 Merge pull request #35433 from apple/Reflection-Support-OpaqueExistential-in-RecordTypeInfo-readExtraInhabitantIndex
[Reflection] Support OpaqueExistential in RecordTypeInfo::readExtraInhabitantIndex
2021-01-19 20:17:52 -08:00
Mike Ash
22f15dd10a Merge pull request #35489 from mikeash/protocol-conformance-iteration-order-workaround2
[Runtime] Scan backwards within conformance sections when scanSectionsBackwards is true.
2021-01-19 23:10:42 -05:00
3405691582
4f24d895fc [stdlib] Use Clang type macros on OpenBSD.
Per the code comment, stdint.h is provided by clang and therefore
conflicts with Glibc; additionally, clang defines some particular
type macros for making the appropriate `typedef`s.

OpenBSD uses clang-10, so we can also use these types on this platform.
This also addresses a test case that has gone awry.
2021-01-19 21:58:29 -05:00
David Zarzycki
58625d2576 Merge pull request #35459 from davezarzycki/pr35459
[stdlib] NFC: Fix three unused function warnings
2021-01-19 17:12:36 -05:00
Mike Ash
32d1c22057 [Runtime] Scan backwards within conformance sections when scanSectionsBackwards is true.
This more closely matches the previous behavior.

rdar://73362732
2021-01-19 16:07:28 -05:00
swift-ci
7993697cff Merge pull request #35462 from rxwei/remove-valueWithGradientOf 2021-01-17 19:56:54 -08:00
Richard Wei
cdf9b037ac [AutoDiff] Remove 'valueWithDerivative(of:)' and 'valueWithGradient(of:)'.
`valueWithDerivative(of:)` and `valueWithGradient(of:)` are the curried version of `valueWithDerivative(at:in:)` and `valueWithGradient(at:in:)`, respectively. They are not included the proposal and are not being used by any client that I know of. This patch removes them.
2021-01-16 17:30:58 -08:00
David Zarzycki
df9b2d0b5d [stdlib] NFC: Fix three unused function warnings 2021-01-16 06:04:28 -05:00
Joe Groff
bd85d8308d Merge pull request #35392 from jckarter/checked-continuation-trap
Concurrency: Have CheckedContinuation trap on double resume.
2021-01-15 16:07:12 -08:00
Evan
4f708fad7e Merge pull request #35215 from etcwilde/ewilde/async-main
Adding async-main support

Resolves: rdar://71828636
2021-01-15 10:57:14 -08:00
Kavon Farvardin
91e2246c19 quick-and-dirty implementation of MainActor in the runtime system
it is "dirty" in the sense that we don't have proper support for
custom executors right now.
2021-01-14 17:43:58 -08:00
Dave Lee
1e5838792d [Reflection] Support OpaqueExistential in RecordTypeInfo::readExtraInhabitantIndex 2021-01-14 17:03:48 -08:00
Evan Wilde
13cc56b85c Build on Windows
Windows doesn't have dlsym. Since I don't have a Windows box, I'm just
if-def'ing it out for the time being. Since we don't want Windows going
off and doing dangerous things, I threw in an abort just to be safe.
2021-01-14 15:47:08 -08:00
Evan Wilde
81ae9d663f More tests and cleanup
Adding execution and death test to ensure that we crash appropriately
when the main function throws an uncaught exception, and that the async
main runs correctly.

Also switching to doing the CFRunLoopRun lookup with `RTLD_DEFAULT`
since `RTLD_SELF` isn't available on Linux.

Switching to `try await` since `await try` is no longer the right way to
do that.

Using exit(0) instead of EXIT_SUCCESS since the C++ importer doesn't
mark imported macros with @actorIndependent yet.
2021-01-14 13:28:58 -08:00
Brent Royal-Gordon
377a2253b8 Merge pull request #35399 from brentdax/free-as-a-null/main
[NFC-ish] Correct nullability of free() redeclaration
2021-01-13 16:51:55 -08:00
Evan Wilde
6b16657922 Explode on uncaught error thrown in main
This patch has two desirable effects for the price of one.
 1. An uncaught error thrown from main will now explode
 2. Move us off of using runAsyncAndBlock

The issue with runAsyncAndBlock is that it blocks the main thread
outright. UI and the main actor need to run on the main thread or bad
things happen, so blocking the main thread results in a bad day for
them.

Instead, we're using CFRunLoopRun to run the core-foundation run loop on
the main thread, or, dispatch_main if CFRunLoopRun isn't available.
The issue with just using dispatch_main is that it doesn't actually
guarantee that it will run the tasks on the main thread either, just
that it clears the main queue. We don't want to require everything that
uses concurrency to have to include CoreFoundation either, but dispatch
is already required, which supplies dispatch_main, which just empties
out the main queue.
2021-01-13 15:49:28 -08:00
Robert Widmann
58f7a1021c Merge pull request #35406 from CodaFi/versionilitude
Trade Usages of -m${platform}-version-min For -target
2021-01-13 13:30:02 -08:00
Evan Wilde
c01b9f000e Adding async-main support
This patch adds the async-main start-point for programs.
When a `static func main() async` is inserted into the main program, it
gets called through `_runAsyncMain` instead of calling directly. This
starts the program in an async context, which is good because then we
can do async stuff from there.

The following code

```
@main struct MyProgram {
  static func main() async {
    // async code
  }
}
```

is turned into

```
@main struct MyProgram {
  static func $main() {
    _runAsyncMain(main)
  }

  static func main() async {
    // async code
  }
}
```

_runAsyncMain code-gen's to the same thing as runAsyncAndBlock, which
emits a call to `swift_task_runAndBlockThread`.
2021-01-13 13:17:35 -08:00
Victor Guerra
6298351ad5 [AutoDiff] Registers VJPs for FloatingPoint.[maximum|minimum] (#35379)
Resolves TF-1134.
2021-01-13 11:40:46 -08:00
Robert Widmann
b436825948 Trade Usages of -m${platform}-version-min For -target
There's no reason to use -m${platform}-version-min as of clang-11/Xcode 11. Clang is now smart enough to parse -target and provide Apple's ld with the appropriate -platform_version argument string.
2021-01-13 11:00:39 -08:00
Robert Widmann
1f116aed84 Merge pull request #35223 from masters3d/patch-2
[gardening] precondition message wording in stdlib/public/core/Misc.swift
2021-01-12 21:40:51 -08:00
Brent Royal-Gordon
e3e434f7bf Correct nullability of free() redeclaration
In the new clang, this declaration ends up influencing the redeclaration chain, altering the nullability of the `free(_:)` function imported into Swift.

Fixes rdar://71269128. Note that tests may fail unless a clean build is performed.
2021-01-12 17:31:45 -08:00
Richard Wei
c8cd24afa0 Merge pull request #35366 from rxwei/remove-differentiable-function-ctor
[AutoDiff] Remove 'differentiableFunction(from:)' and 'linearFunction(from:)'
2021-01-12 16:09:25 -08:00
Joe Groff
49d4299ae0 Concurrency: Have CheckedContinuation trap on double resume. 2021-01-12 16:08:41 -08:00
Saleem Abdulrasool
cc45a700b1 Merge pull request #35337 from egorzhdan/winsdk-export-crt
WinSDK: explicitly re-export ucrt
2021-01-12 12:12:17 -08:00
Richard Wei
f79391b684 [AutoDiff] Remove 'differentiableFunction(from:)' and 'linearFunction(from:)'.
Remove unused APIs `differentiableFunction(from:)` and `linearFunction(from:)`. They were never official APIs, are not included in the [initial proposal](https://github.com/rxwei/swift-evolution/blob/autodiff/proposals/0000-differentiable-programming.md#make-a-function-differentiable-using-derivative), and are unused by existing supported client libraries (SwiftFusion and S4TF). Most importantly, they block crucial optimizations on linear map closures (#34935) and would need nontrivial work in SILGen to support.
2021-01-12 11:58:48 -08:00