Commit Graph

31 Commits

Author SHA1 Message Date
Konrad `ktoso` Malawski
fda7f539fb Reapply "Task names" (#79562) (#79600) 2025-03-08 10:58:49 +09:00
Konrad `ktoso` Malawski
09003d6f11 Revert "Merge pull request #77609 from ktoso/wip-task-names" (#79562)
This reverts commit 4ab5d2604f.
2025-02-23 22:59:21 -08:00
Konrad `ktoso` Malawski
4ab5d2604f Merge pull request #77609 from ktoso/wip-task-names
[Concurrency] Task names
2025-02-21 22:28:33 +09:00
Erik Eckstein
7cceaff5f3 SIL: don't print operand types in textual SIL
Type annotations for instruction operands are omitted, e.g.

```
  %3 = struct $S(%1, %2)
```

Operand types are redundant anyway and were only used for sanity checking in the SIL parser.

But: operand types _are_ printed if the definition of the operand value was not printed yet.
This happens:

* if the block with the definition appears after the block where the operand's instruction is located

* if a block or instruction is printed in isolation, e.g. in a debugger

The old behavior can be restored with `-Xllvm -sil-print-types`.
This option is added to many existing test files which check for operand types in their check-lines.
2024-11-21 18:49:52 +01:00
Allan Shortlidge
c02fc4724d Tests: Remove -disable-availability-checking from many Concurrency tests.
Instead, use the `%target-swift-5.1-abi-triple` substitution to compile the tests
for deployment to the minimum OS versions required for use of _Concurrency APIs.
2024-10-18 16:21:51 -07:00
Michael Gottesman
43e1c5499f [sending] Make the operation of Builtin.createAsyncTask/friends a sending non-Sendable function instead of an @Sendable function.
This matches the interface of the public stdlib APIs that wrap these builtin calls.
2024-06-21 02:24:03 -07:00
Konrad `ktoso` Malawski
2ec717b115 [Concurrency] TaskExecutor ownership fixes (#74000) 2024-06-14 22:56:33 +09:00
John McCall
0901b2b0b3 Add builtin support for starting a task on a specific executor.
This should be close enough to the creation of this builtin that we don't
need a new feature for it specifically.
2024-03-11 19:44:50 -04:00
John McCall
0a282c044f Unify all of the task-creation builtins coming out of SILGen.
We've been building up this exponential explosion of task-creation
builtins because it's not currently possible to overload builtins.
As long as all of the operands are scalar, though, it's pretty easy
to peephole optional injections in IRGen, which means we can at
least just use a single builtin in SIL and then break it apart in
IRGen to decide which options to set.

I also eliminated the metadata argument, which can easily be recreated
from the substitutions.  I also added proper verification for the builtin,
which required (1) getting `@Sendable` right more consistently and (2)
updating a bunch of tests checking for things that are not actually
valid, like passing a function that returns an Int directly.
2024-03-06 22:21:12 -05:00
Allan Shortlidge
ac464f3d15 Revert "Disable some Concurrency tests on freestanding"
This reverts commit a8e79e7430.
2024-01-03 13:59:02 -08:00
Allan Shortlidge
9b6b4b956d SILGen: Consistently use the buildMainActorExecutorRef built-in.
SILGen and IRGen would disagree on the return type of the
`swift_task_getMainExecutor()` runtime function if
`SILGenModule::getGetMainExecutor()` had ever been called. To address this,
consistently use the `buildMainActorExecutorRef` built-in and get rid of
`SILGenModule::getGetMainExecutor()`.

Resolves rdar://116472583
2023-12-14 15:13:46 -08:00
Meghana Gupta
a8e79e7430 Disable some Concurrency tests on freestanding 2023-11-01 13:13:55 -07:00
Yuta Saito
0fd8f0b4bc [Concurrency] Hide async_Main from other object files 2023-10-11 04:00:18 +00:00
Erik Eckstein
70981cf95f tests: fix misspelled check prefixes
Fix the common error of using underscores instead of dashes.
In the rebranch this is an error (lit got more picky), but it also makes sense to fix the tests in the main branch
2022-11-08 17:27:48 +01:00
Kuba (Brecka) Mracek
7853184ed6 Enable running tests from test/Concurrency/ directory in freestanding/minimal presets (#61835)
* Enable running tests from test/Concurrency/ directory in freestanding/minimal presets

* Mark failing Concurrency tests as XFAIL/SKIP on freestanding/minimal
2022-11-04 09:07:27 -07:00
Holly Borla
8713d78704 [PrintOptions] Print explicit 'any' in SIL. 2022-08-18 01:15:12 -04:00
Duo Wang
72e0ac2819 [tests] fix missing codesign in test files 2022-07-28 13:59:44 -07:00
Evan Wilde
e125326f86 Require MainActor isolation on main function
This patch forces the main function to be protected behind MainActor
isolation. If no actor isolation is specified, the main function will
implicitly have MainActor isolation.
2021-10-04 15:18:48 -07:00
Evan Wilde
bb80f9f329 Replace reinterpret cast with struct
A single-element struct is structurally the same as the member type
itself.
2021-10-04 09:53:11 -07:00
Evan Wilde
493eca3272 Inherit main thread priority/context
This patch changes the main task to inherit the context of the main
thread. This should assign the appropriate priority based on how the
program was invoked. I've also updated the tests to reflect these
changes.
2021-10-02 16:53:06 -07:00
Evan Wilde
d376ee9989 Run first thunk of Async main synchronously
This patch updates the asynchronous main function to run the first thunk
of the function synchronously through a call to `swift_job_run`.

The runloop is killed by exiting or aborting the task that it is running
on. As such, we need to ensure that the task contains an async function
that either calls exit explicitly or aborts. The AsyncEntryPoint, that
contains this code, was added in the previous patch. This patch adds the
pieces for the actual implementation of this behaviour as well as adding
the necessary code to start the runloop.

There are now four layers of main functions before hitting the "real"
code.

@main: This is the actual main entrypoint of the program. This
constructs the task containing @async_main, grabs the main executor,
runs swift_job_run to run the first part synchronously, and finally
kicks off the runloop with a call to _asyncMainDrainQueue. This is
generated in the call to `emitAsyncMainThreadStart`.

@async_main: This thunk exists to ensure that the main function calls
`exit` at some point so that the runloop stops. It also handles emitting
an error if the user-written main function throws.

e.g:

```
func async_main() async -> () {
  do {
    try await Main.$main()
    exit(0)
  } catch {
    _errorInMain(error)
  }
}
```

Main.$main(): This still has the same behaviour as with the
synchronous case. It just calls `try await Main.main()` and exists to
simplify typechecking.

Main.main(): This is the actual user-specified main. It serves the same
purpose as in the synchronous, allowing the programmer to write code,
but it's async!

The control flow in `emitFunctionDefinition` is a little confusing (to
me anyway), so here it is spelled out:

If the main function is synchronous, the `constant.kind` will be a
`SILDeclRef::Kind::EntryPoint`, but the `decl` won't be async, so it
drops down to `emitArtificalTopLevel` anyway.

If the main function is async and we're generating `@main`, the
`constant.kind` will be `SILDeclRef::Kind::AsyncEntryPoint`, so we also
call `emitArtificalTopLevel`. `emitArtificalTopLevel` is responsible for
detecting whether the decl is async and deciding whether to emit code to
extract the argc/argv variables that get passed into the actual main
entrypoint to the program. If we're generating the `@async_main` body,
the kind will be `SILDeclRef::Kind::EntryPoint` and the `decl` will be
async, so we grab the mainEntryPoint decl and call
`emitAsyncMainThreadStart` to generate the wrapping code.

Note; there is a curious change in `SILLocation::getSourceLoc()`
where instead of simply checking `isFilenameAndLocation()`, I change it
to `getStorageKind() == FilenameAndLocationKind`. This is because the
SILLocation returned is to a FilenameAndLocationKind, but the actual
storage returns true for the call to `isNull()` inside of the
`isFilenameAndLocation()` call. This results in us incorrectly falling
through to the `getASTNode()` call below that, which asserts when asked
to get the AST node of a location.

I also did a little bit of refactoring in the SILGenModule for grabbing
intrinsics. Previously, there was only a `getConcurrencyIntrinsic`
function, which would only load FuncDecls out of the concurrency
module. The `exit` function is in the concurrency shims module, so I
refactored the load code to take a ModuleDecl to search from.

The emitBuiltinCreateAsyncTask function symbol is exposed from
SILGenBuiltin so that it is available from SILGenFunction. There is a
fair bit of work involved going from what is available at the SGF to
what is needed for actually calling the CreateAsyncTask builtin, so in
order to avoid additional maintenance, it's good to re-use that.
2021-10-02 16:53:06 -07:00
Doug Gregor
3ee09a2298 Switch concurrency runtime tests to "REQUIRES: concurrency_runtime"
Rather than blanket-disabling concurrency tests when we aren't using a
just-built concurrency library, enable them whenever we have a
suitable concurrency runtime, either just-built, in the OS, or via the
back-deployment libraries.
2021-09-13 12:34:20 -07:00
Hamish Knight
01a082a058 [AST] Adopt ArgumentList
Switch out the representation of argument lists
in various AST nodes with ArgumentList.
2021-09-01 18:40:23 +01:00
Doug Gregor
eeeea49764 Remove -enable-experimental-concurrency almost everywhere. 2021-07-26 21:24:43 -07:00
Doug Gregor
1e2012d816 Disable availability checking in tests that use concurrency 2021-07-20 12:46:26 -07:00
Nate Chandler
ff7c98123a [Test] Disabled several Concurrency tests for back_deployment_runtime.
rdar://76566598
2021-04-13 15:27:41 -07:00
Karoy Lorentey
24aca4072a [test] Skip concurrency tests during back deployment testing
rdar://76038845
2021-03-30 22:35:38 -07: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
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
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