Commit Graph

12 Commits

Author SHA1 Message Date
Doug Gregor
e87505cb34 Merge pull request #36986 from DougGregor/data-race-checking-flags
[SILGen] Put actor data-race checking behind a flag.
2021-04-21 08:55:17 -07:00
Doug Gregor
19a7fa6625 [SILGen] Put actor data-race checking behind a flag.
Introduce flags `-enable-actor-data-race-checks` and
`-disable-actor-data-race-checks` to enable/disable emission of code
that checks that we are on the correct actor. Default to `false` for
now but make it easy to enable in the future.
2021-04-20 22:30:53 -07:00
Nate Chandler
30ea9324a5 [Test] Disabled two Concurrency tests for back deploy. 2021-04-20 12:50:39 -07:00
Doug Gregor
6839086142 Fix data-race detection test to not need @MainActor async main 2021-04-16 00:26:39 -07:00
Doug Gregor
4e306bb8ab Revert "[Test] Disable failing concurrency tests on Linux."
This reverts commit 766bf78eea.
2021-04-14 23:33:51 -07:00
Doug Gregor
8db916c973 Revert "[Tests] NFC: Disable concurrency data race detection test on all platforms"
This reverts commit 6139a4fea4.
2021-04-14 23:33:51 -07:00
Pavel Yaskevich
6139a4fea4 [Tests] NFC: Disable concurrency data race detection test on all platforms 2021-04-14 13:22:45 -07:00
Holly Borla
766bf78eea [Test] Disable failing concurrency tests on Linux. 2021-04-14 10:44:46 -07:00
Doug Gregor
78cb4fff7e Fix iOS availability 2021-04-13 18:16:47 -07:00
Doug Gregor
f25369d69b Minor fixes 2021-04-13 08:35:44 -07:00
Doug Gregor
ea666db5d5 Import Glibc or Darwin as appropriate 2021-04-13 00:45:02 -07:00
Doug Gregor
e77a27e8ed [Concurrency] Introduce runtime detection of data races.
Through various means, it is possible for a synchronous actor-isolated
function to escape to another concurrency domain and be called from
outside the actor. The problem existed previously, but has become far
easier to trigger now that `@escaping` closures and local functions
can be actor-isolated.

Introduce runtime detection of such data races, where a synchronous
actor-isolated function ends up being called from the wrong executor.
Do this by emitting an executor check in actor-isolated synchronous
functions, where we query the executor in thread-local storage and
ensure that it is what we expect. If it isn't, the runtime complains.
The runtime's complaints can be controlled with the environment
variable `SWIFT_UNEXPECTED_EXECUTOR_LOG_LEVEL`:

  0 - disable checking
  1 - warn when a data race is detected
  2 - error and abort when a data race is detected

At an implementation level, this introduces a new concurrency runtime
entry point `_checkExpectedExecutor` that checks the given executor
(on which the function should always have been called) against the
executor on which is called (which is in thread-local storage). There
is a special carve-out here for `@MainActor` code, where we check
against the OS's notion of "main thread" as well, so that `@MainActor`
code can be called via (e.g.) the Dispatch library's
`DispatchQueue.main.async`.

The new SIL instruction `extract_executor` performs the lowering of an
actor down to its executor, which is implicit in the `hop_to_executor`
instruction. Extend the LowerHopToExecutor pass to perform said
lowering.
2021-04-12 15:19:51 -07:00