Commit Graph

14787 Commits

Author SHA1 Message Date
Evan Wilde
8f974c1a79 Merge pull request #36524 from etcwilde/ewilde/fix-after-main-crash
[Concurrency] Make asyncMainDrainQueue noreturn
2021-03-22 23:00:33 -07:00
Doug Gregor
591bd6ab18 Merge pull request #36541 from jckarter/actor-tsan-release-edges
Concurrency runtime: Fix location of tsan_release edges for actors.
2021-03-22 22:53:04 -07:00
Karoy Lorentey
390cebe88b Merge pull request #36004 from lorentey/document-copyContents
[stdlib] Document a fatal surprise with `Sequence._copyContents`
2021-03-22 16:49:18 -07:00
Joe Groff
1a9dc145a6 Concurrency runtime: Fix location of tsan_release edges for actors.
The TSAN release edge should appear before the actual cmpxchg-release.
2021-03-22 14:35:48 -07:00
Stephen Canon
7e326063c5 Concrete SIMD operations, part 1 (#36172)
Adds concrete overloads of the following SIMD operations:
- Comparisons: .==, .!=, .<, .<=, .>, .>=
- Logical operations on masks: .!, .&, .^, .|
- Integer arithmetic: &+, &-, &, &+=, &-=, &=
This makes some simple benchmarks 10-100x faster, which is basically a no-brainer, while staying away from the most heavily used operators, so hopefully doesn't impact compilation performance too badly.
2021-03-22 16:48:21 -04:00
tbkka
26ab27648e Casting from AnyHashable to AnyHashable should never create another wrapper (#36470)
* Casting from AnyHashable to AnyHashable should never create another wrapper

This adds a conformance for _HasCustomAnyHashableRepresentation to
AnyHashable that simply returns self.  This ensures that anytime
you try to create a new AnyHashable wrapper for an existing
AnyHashable, you just get back the original.

Resolves rdar://75180619

* Move the `Struct AnyHashable` change to `without-asserts` list

As suggested by @lorentey
2021-03-22 09:03:29 -07:00
Mike Ash
6aab257c33 [Concurrency] Add compatibility overrides to Concurrency library.
Take the existing CompatibilityOverride mechanism and generalize it so it can be used in both the runtime and Concurrency libraries. The mechanism is preprocessor-heavy, so this requires some tricks. Use the SWIFT_TARGET_LIBRARY_NAME define to distinguish the libraries, and use a different .def file and mach-o section name accordingly.

We want the global/main executor functions to be a little more flexible. Instead of using the override mechanism, we expose function pointers that can be set by the compatibility library, or by any other code that wants to use a custom implementation.

rdar://73726764
2021-03-22 11:09:06 -04:00
Robert Widmann
c5a751212d Merge pull request #36446 from wonhee009/Result 2021-03-21 09:58:14 -07:00
Konrad `ktoso` Malawski
92933a17f2 Merge pull request #36297 from apple/ktoso-patch-3
[Concurrency] remove Task.hasTaskLocalValues, they all do
2021-03-21 22:58:24 +09:00
swift-ci
e0b84da912 Merge pull request #36527 from vojtamolda/main 2021-03-19 20:50:15 -07:00
Vojta Molda
9697dd8905 [AutoDiff] Add .zero tangent vector handling to Array.DifferentiableView.+ and .move
Implement correct zero tangent vector, i.e. empty array [], handling during the backward pass of Array.DifferentiableView.+ and move methods. The precondition is no longer triggered by .zero/empty arrays.

Fixes SR-14297
2021-03-19 19:16:40 -05:00
swift-ci
2f6fb2dd45 Merge pull request #36507 from Catfish-Man/theres-a-hole-at-the-end-where-the-bits-fall-out 2021-03-19 16:35:32 -07:00
Arnold Schwaighofer
98a674bf12 Merge pull request #36518 from aschwaighofer/fix_pushAsyncContext_assert
Fix pushAsyncContext
2021-03-19 15:17:01 -07:00
David Smith
e793e0e0e4 Always ask Cocoa for terminated char*s
(cherry picked from commit b7ce22ba1525dccd47f4095a9bf8a640b238a5fa)
2021-03-19 13:01:23 -07:00
Evan Wilde
b0b4cb67a1 Make asyncMainDrainQueue noreturn
CFRunLoopRun returns once it finishes, though the kernel may clean us up
before we get there. We effectively have a race condition between the
kernel cleaning us up and returning from a never returning function.

Small programs likely get cleaned up before reaching the ud2 instruction
emitted after the never returning function in swift, so they don't
notice, but programs of a sufficient size do. At that size, the program
will crash after what the programmer expects to be the end of their
program.
2021-03-19 12:33:26 -07:00
swift-ci
bdc048e541 Merge pull request #36511 from DougGregor/main-actor-run 2021-03-19 10:19:13 -07:00
Doug Gregor
cfa07b60ee Merge pull request #36477 from jckarter/executor-hop-back
Concurrency: Hop back to the previous executor after actor calls.
2021-03-19 10:17:20 -07:00
Arnold Schwaighofer
fc91036bf7 Fix pushAsyncContext
We no longer store arguments in the async context (like the closure context). The assert is no longer true
2021-03-19 09:25:46 -07:00
Saleem Abdulrasool
817a005f2e Merge pull request #36498 from compnerd/user 2021-03-19 07:35:06 -07:00
swift-ci
4255a670c4 Merge pull request #36510 from DougGregor/se-0302-rename 2021-03-19 02:19:45 -07:00
Doug Gregor
3aa4fbec51 Add MainActor.run to execute a synchronous closure on the main thread.
It's important to be able to execute a synchronous closure on the main
thread to perform various main-thread updates. This is the async equivalent
to DispatchQueue.main.sync.
2021-03-18 23:52:58 -07:00
Doug Gregor
52096a640e SE-0302: Rename ConcurrentValue/@concurrent to Sendable/@Sendable. 2021-03-18 23:48:21 -07:00
Doug Gregor
9579390024 [SE-0304] Rename ConcurrentValue to Sendable 2021-03-18 22:48:20 -07:00
Richard Wei
e9f82d138d Conform 'AnyDifferentiable' and 'AnyDerivative' to 'CustomReflectable'.
'AnyDifferentiable' and 'AnyDerivative' should conform to 'CustomReflectable' to prevent leaking implementation details. The mirror should reflect its underlying value directly.

Resolves rdar://75496334.
2021-03-18 18:51:11 -07:00
Arnold Schwaighofer
ec2d78677e Merge pull request #36490 from aschwaighofer/remove_unused_resume_parent_executor
Remove unused resume parent executor
2021-03-18 18:30:22 -07:00
Joe Groff
b9ee090605 Add tsan edges when actors transition in and out of running state. 2021-03-18 18:16:33 -07:00
Meghana Gupta
dbea482085 Refactor FixedWidthInteger init (#36485) 2021-03-18 13:47:12 -07:00
Joe Groff
79fb05b362 Concurrency: Hop back to the previous executor after actor calls.
Tasks shouldn't normally hog the actor context indefinitely after making a call that's bound to
that actor, since that prevents the actor from potentially taking on other jobs it needs to
be able to address. Set up SILGen so that it saves the current executor (using a new runtime
entry point) and hops back to it after every actor call, not only ones where the caller context
is also actor-bound.

The added executor hopping here also exposed a bug in the runtime implementation while processing
DefaultActor jobs, where if an actor job returned to the processing loop having already yielded
the thread back to a generic executor, we would still attempt to make the actor give up the thread
again, corrupting its state.

rdar://71905765
2021-03-18 11:47:50 -07:00
Saleem Abdulrasool
73edf071b5 Platform: correct link dependency for WinSDK.User
Add the User32 link dependency for uses of the User module.
2021-03-18 11:06:27 -07:00
Arnold Schwaighofer
cf55973973 Remove unused ResumeParentExecutor 2021-03-18 09:05:45 -07:00
Arnold Schwaighofer
3bdd5cb99a IRGen: async error ABI
Throwing functions pass the error result in `swiftself` to the resume
partial function.
Therefore, `() async -> ()` to `() async throws -> ()` is not ABI compatible.

TODO: go through remaining failing IRGen async tests and replace the
illegal convert_functions.
2021-03-17 17:17:12 -07:00
Mike Ash
15b83e1bd0 Merge pull request #36468 from mikeash/fix-shared-cache-subclass-conformance
[Runtime] Fixed shared cache protocol conformance lookup with subclasses.
2021-03-17 16:53:48 -04:00
Mike Ash
5193d76c74 [Runtime] Fixed shared cache protocol conformance lookup with subclasses.
Match the logic used in the non-shared-cache case, where we walk up the class hierarchy to find the class where the conformance actually applies. This is important in cases like:

  class Super<T> : Proto {}
  class Sub: Super<Int> {}

Looking up the conformance `Sub: Proto` without this logic causes it to attempt to find the witness table for `Sub<Int>`, which fails. The correct logic looks up the witness table for `Super<Int>`.

While we're in there, fix a bug in the shared cache validation code (std::find wasn't checked for failure correctly) and add a `SWIFT_DEBUG_ENABLE_SHARED_CACHE_PROTOCOL_CONFORMANCES` environment variable to allow us to turn the shared cache integration off at runtime.

rdar://75431771
2021-03-17 11:46:11 -04:00
Arnold Schwaighofer
f75fbb7594 IRGen: Async ABI passing parameter and results directly
The error is still passed in the async context. I will fix this in a
follow-up.
2021-03-17 07:41:01 -07:00
John McCall
6c879d6fd3 Change the async ABI to not pass the active task and executor.
Most of the async runtime functions have been changed to not
expect the task and executor to be passed in.  When knowing the
task and executor is necessary, there are runtime functions
available to recover them.

The biggest change I had to make to a runtime function signature
was to swift_task_switch, which has been altered to expect to be
passed the context and resumption function instead of requiring
the caller to park the task.  This has the pleasant consequence
of allowing the implementation to very quickly turn around when
it recognizes that the current executor is satisfactory.  It does
mean that on arm64e we have to sign the continuation function
pointer as an argument and then potentially resign it when
assigning into the task's resume slot.

rdar://70546948
2021-03-16 22:52:54 -04:00
swift-ci
549923513a Merge pull request #36216 from apple/tsan-swift-concurrency2 2021-03-16 19:11:20 -07:00
Julian Lettner
8abf12fbe6 Add swift_task_set_tsan_hooks()
This change will be sequenced:
  1. Call this hook from the TSan runtime
  2. Remove `dlsym()` lookup from Swift runtime
2021-03-16 13:43:55 -07:00
wonhee
09971acf8c fix Result flatMapError remark 2021-03-16 14:03:18 +09:00
Nate Chandler
ee63777332 [IRGen] Fix ABI for thick async functions.
Previously, thick async functions were represented sometimes as a pair
of (AsyncFunctionPointer, nullptr)--when the thick function was produced
via a thin_to_thick_function, e.g.--and sometimes as a pair of
(FunctionPointer, ThickContext)--when the thick function was produced by
a partial_apply--with the size stored in the slot of the ThickContext.

That optimized for the wrong case: partial applies of dynamic async
functions; in that case, there is no appropriate AsyncFunctionPointer to
form when lowering the partial_apply instruction.  The far more common
case is to know exactly which function is being partially applied.  In
that case, we can form the appropriate AsyncFunctionPointer.

Furthermore, the previous representation made calling a thick function
more complex: it was always necessary to check whether the context was
in fact null and then proceed along two different paths depending.

Here, that behavior is corrected by creating a thunk in a mandatory
IRGen SIL pass in the case that the function that is being partially
applied is dynamic.  That new thunk is then partially applied in place
of the original partial_apply of the dynamic function.
2021-03-15 13:37:40 -07:00
Nate Chandler
dbe689a3f2 [AST] De/mangling for functions with generic sigs. 2021-03-15 13:37:40 -07:00
Andrew Trick
e7cbf1d8ba Add SWIFT_ABI_DEFAULT_REFERENCE_POISON_DEBUG_VALUE
Poison sentinel value recognized by LLDB as a former reference to a
potentially deinitialized object. It uses no spare bits and cannot point to
readable memory.

This is not ABI per-se but does stay in-sync with LLDB. If it becomes
out-of-sync, then users won't see a friendly diagnostic when
inspecting references past their lifetime.
2021-03-12 19:32:55 -08:00
Julian Lettner
99bcd87af6 Use swift_once instead of C++ static initializers 2021-03-12 14:52:56 -08:00
Mike Ash
bedca5ed61 Merge pull request #36139 from mikeash/async-task-dispatch-integration
[Concurrency] Make Job/AsyncTask minimally compatible with dispatch object layout
2021-03-11 18:04:04 -05:00
Arnold Schwaighofer
48e74c8276 Merge pull request #36397 from aschwaighofer/fix_create_async_task_future_silgen
SILGen: Fix emitBuiltinCreateAsyncTaskFuture
2021-03-11 13:17:59 -08:00
Robert Widmann
f9e54068ac Merge pull request #36116 from CodaFi/members-only-club
Use Member Operators in StdlibUnitTest
2021-03-11 13:14:45 -08:00
Arnold Schwaighofer
a17de090b6 SILGen: Fix emitBuiltinCreateAsyncTaskFuture
We need to re-abstract the function argument.
I think this should fix rdar://74957357.
2021-03-11 06:44:02 -08:00
Xiaodi Wu
4c7059f59a [stdlib][SR-13883] Avoid advancing past representable bounds when striding (#34860)
* [stdlib][SR-13883] Avoid advancing past representable bounds when striding.

* [stdlib] Expand a test and add a comment to ensure correct floating-point stride bounds checking.

* [stdlib][NFC] Clarify a comment in a test.

* [stdlib][NFC] Adjust copyright notices, clarify comments, delete '-swift-version=3' for tests.

* [stdlib] Add implementations for fixed-width integer strides for performance.

* [stdlib] Document `Strideable._step` and modify overflow checking behavior of `Stride*Iterator`.

* [stdlib] Address reviewer comments, postpone documentation changes

* [stdlib][NFC] Update documentation for '_step(after:from:by:)'

* [stdlib][NFC] Use 'nil' instead of an arbitrary value for integer striding '_step' index
2021-03-11 08:18:28 -05:00
Doug Gregor
031ffc06cb Merge pull request #36359 from kavon/actor-lifetimes 2021-03-11 01:01:43 -08:00
Mike Ash
bd62fdb2db [Concurrency] Make Job/AsyncTask minimally compatible with dispatch object layout
Create a TargetDispatchClassMetadata for Swift metadata that also has a dispatch-compatible vtable. Dispatch leaves room for ObjC class metadata so the two regions don't overlap. (The vtable currently consists of a single dummy entry; this will be filled out later.)

Rearrange the Job and AsyncTask hierarchy so that AsyncTask inherits only from Job, which in turn inherits from HeapObject. This gives all Job instances a dispatch-compatible isa field. It also gives them a refcount word, which is wasted on instances that aren't AsyncTask instances. Maybe we can find some use for that space in the future.

rdar://75227953
2021-03-10 10:04:30 -05:00
eeckstein
38efe16ad5 Merge pull request #36355 from eeckstein/fix-arrayslice
stdlib: fix ARC for getting an ArraySlice of an CocoaArray with non-contiguous storage.
2021-03-10 09:12:50 +01:00