File: reflect_task.swift

package info (click to toggle)
swiftlang 6.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,532 kB
  • sloc: cpp: 9,901,743; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (58 lines) | stat: -rw-r--r-- 2,078 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// RUN: %empty-directory(%t)
// RUN: %target-clang -x c %S/Inputs/reflect_task.c -o %t/reflect_task.c.o -c
// RUN: %target-build-swift -c -target %target-swift-5.1-abi-triple -parse-stdlib -parse-as-library -lswiftSwiftReflectionTest %s -o %t/reflect_task.swift.o -module-name reflect_task
// RUN: %target-build-swift %t/reflect_task.swift.o %t/reflect_task.c.o -o %t/reflect_task
// RUN: %target-codesign %t/reflect_task

// RUN: %target-run %target-swift-reflection-test %t/reflect_task | %FileCheck %s --dump-input=fail

// REQUIRES: reflection_test_support
// REQUIRES: executable_test
// REQUIRES: concurrency
// UNSUPPORTED: use_os_stdlib
// UNSUPPORTED: back_deployment_runtime
// UNSUPPORTED: asan

import Swift
import _Concurrency

import SwiftReflectionTest

// We do not use swift_task_getCurrent directly since we also can get a
// declaration (if we get unlucky) from _Concurrency with a differing type. So
// we instead just compile a shim in a .c file that actually calls
// swift_task_getCurrent and avoid the collision.
@_silgen_name("getCurrentTaskShim")
func _getCurrentTaskShim() -> UInt

func add(_ a: UInt, _ b: UInt) async -> UInt {
  if b == 0 {
    reflect(asyncTask: _getCurrentTaskShim())
    // CHECK: Reflecting an async task.
    // CHECK: Async task {{0x[0-9a-fA-F]*}}

    // The actual number of chunks we'll get depends on internal implementation
    // details that we don't want this test to depend on. We'll just make sure
    // we get at least two, and ignore the details.
    // CHECK:   Slab pointer {{0x[0-9a-fA-F]*}}
    // CHECK:     Slab size {{[0-9]{2,}()}}
    // CHECK:     Chunk at {{0x[0-9a-fA-F]*}} length {{[1-9][0-9]*}} kind {{[0-9]*}}
    // CHECK:   Slab pointer {{0x[0-9a-fA-F]*}}
    // CHECK:     Slab size {{[0-9]{2,}()}}
    // CHECK:     Chunk at {{0x[0-9a-fA-F]*}} length {{[1-9[[0-9]*}} kind {{[0-9]*}}
    return a
  } else {
    return await add(a, b - 1) + 1
  }
}

@main struct Main {
  static func main() async {
    let n = await add(100, 100)
    reflect(any: n)

    doneReflecting()
  }
}

// CHECK: Done.