Skip to content

Commit e2cdc5e

Browse files
authored
Merge pull request #33196 from DougGregor/concurrency-lib
[Concurrency] Stub out an experimental concurrency support library.
2 parents afb5736 + 3339f18 commit e2cdc5e

File tree

14 files changed

+148
-3
lines changed

14 files changed

+148
-3
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@ option(SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING
402402
"Enable experimental Swift differentiable programming features"
403403
FALSE)
404404

405+
option(SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY
406+
"Enable experimental Swift concurrency model"
407+
FALSE)
408+
405409
#
406410
# End of user-configurable options.
407411
#
@@ -852,6 +856,7 @@ if(SWIFT_BUILD_STDLIB OR SWIFT_BUILD_SDK_OVERLAY)
852856
message(STATUS "")
853857

854858
message(STATUS "Differentiable Programming Support: ${SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING}")
859+
message(STATUS "Concurrency Support: ${SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY}")
855860
message(STATUS "")
856861
else()
857862
message(STATUS "Not building Swift standard library, SDK overlays, and runtime")

stdlib/public/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ if(SWIFT_BUILD_STDLIB)
8989
if(SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING)
9090
add_subdirectory(Differentiation)
9191
endif()
92+
93+
if(SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY)
94+
add_subdirectory(Concurrency)
95+
endif()
9296
endif()
9397

9498
if(SWIFT_BUILD_STDLIB OR SWIFT_BUILD_REMOTE_MIRROR)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#===--- CMakeLists.txt - Concurrency support library ---------------------===#
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2019 - 2020 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See https://swift.org/LICENSE.txt for license information
9+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
#
11+
#===----------------------------------------------------------------------===#
12+
13+
add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB
14+
PartialAsyncTask.swift
15+
16+
SWIFT_MODULE_DEPENDS_OSX Darwin
17+
SWIFT_MODULE_DEPENDS_IOS Darwin
18+
SWIFT_MODULE_DEPENDS_TVOS Darwin
19+
SWIFT_MODULE_DEPENDS_WATCHOS Darwin
20+
SWIFT_MODULE_DEPENDS_LINUX Glibc
21+
SWIFT_MODULE_DEPENDS_FREEBSD Glibc
22+
SWIFT_MODULE_DEPENDS_OPENBSD Glibc
23+
SWIFT_MODULE_DEPENDS_CYGWIN Glibc
24+
SWIFT_MODULE_DEPENDS_HAIKU Glibc
25+
SWIFT_MODULE_DEPENDS_WINDOWS MSVCRT
26+
27+
SWIFT_COMPILE_FLAGS
28+
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
29+
-parse-stdlib
30+
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
31+
DARWIN_INSTALL_NAME_DIR "@rpath"
32+
INSTALL_IN_COMPONENT stdlib)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import Swift
14+
@_implementationOnly import _SwiftConcurrencyShims
15+
16+
public struct PartialAsyncTask {
17+
private var context: UnsafeMutablePointer<_SwiftContext>
18+
19+
public func run() { }
20+
}

stdlib/public/SwiftShims/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ set(sources
2020
ThreadLocalStorage.h
2121
UnicodeShims.h
2222
Visibility.h
23+
_SwiftConcurrency.h
2324

2425
CoreMediaOverlayShims.h
2526
DispatchOverlayShims.h
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===--- _SwiftConcurrency.h - Swift Concurrency Support --------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// Defines types and support functions for the Swift concurrency model.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
#ifndef SWIFT_CONCURRENCY_H
17+
#define SWIFT_CONCURRENCY_H
18+
19+
#ifdef __cplusplus
20+
namespace swift {
21+
extern "C" {
22+
#endif
23+
24+
typedef struct _SwiftContext {
25+
struct _SwiftContext *parentContext;
26+
} _SwiftContext;
27+
28+
#ifdef __cplusplus
29+
} // extern "C"
30+
} // namespace swift
31+
#endif
32+
33+
#endif // SWIFT_CONCURRENCY_H

stdlib/public/SwiftShims/module.modulemap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,7 @@ module _SwiftClockKitOverlayShims {
8080
module _SwiftCoreMediaOverlayShims {
8181
header "CoreMediaOverlayShims.h"
8282
}
83+
84+
module _SwiftConcurrencyShims {
85+
header "_SwiftConcurrency.h"
86+
}

test/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ normalize_boolean_spelling(SWIFT_ASAN_BUILD)
163163
normalize_boolean_spelling(SWIFT_BUILD_SYNTAXPARSERLIB)
164164
normalize_boolean_spelling(SWIFT_ENABLE_SOURCEKIT_TESTS)
165165
normalize_boolean_spelling(SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING)
166+
normalize_boolean_spelling(SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY)
166167
is_build_type_optimized("${SWIFT_STDLIB_BUILD_TYPE}" SWIFT_OPTIMIZED)
167168

168169
set(profdata_merge_worker
@@ -363,6 +364,10 @@ _Block_release(void) { }\n")
363364
list(APPEND LIT_ARGS "--param" "differentiable_programming")
364365
endif()
365366

367+
if(SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY)
368+
list(APPEND LIT_ARGS "--param" "concurrency")
369+
endif()
370+
366371
foreach(test_subset ${TEST_SUBSETS})
367372
set(directories)
368373
set(dependencies ${test_dependencies})

test/lit.site.cfg.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ if '@SWIFT_INCLUDE_TOOLS@' == 'TRUE':
125125

126126
if "@SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING@" == "TRUE":
127127
config.available_features.add('differentiable_programming')
128+
if "@SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY@" == "TRUE":
129+
config.available_features.add('concurrency')
128130

129131
# Let the main config do the real work.
130132
if config.test_exec_root is None:

test/stdlib/Concurrency.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %target-typecheck-verify-swift
2+
// REQUIRES: concurrency
3+
4+
// Make sure the import succeeds
5+
import _Concurrency
6+
7+
// Make sure the type shows up
8+
extension PartialAsyncTask {
9+
}

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,10 @@ def create_argument_parser():
10891089
help='Enable experimental Swift differentiable programming language'
10901090
' features.')
10911091

1092+
option('--enable-experimental-concurrency', toggle_true,
1093+
default=True,
1094+
help='Enable experimental Swift concurrency model.')
1095+
10921096
# -------------------------------------------------------------------------
10931097
in_group('Unsupported options')
10941098

utils/build_swift/tests/expected_options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
'dry_run': False,
142142
'enable_asan': False,
143143
'enable_experimental_differentiable_programming': True,
144+
'enable_experimental_concurrency': True,
144145
'enable_lsan': False,
145146
'enable_sanitize_coverage': False,
146147
'disable_guaranteed_normal_arguments': False,
@@ -497,6 +498,7 @@ class BuildScriptImplOption(_BaseOption):
497498
EnableOption('--distcc'),
498499
EnableOption('--enable-asan'),
499500
EnableOption('--enable-experimental-differentiable-programming'),
501+
EnableOption('--enable-experimental-concurrency'),
500502
EnableOption('--enable-lsan'),
501503
EnableOption('--enable-sanitize-coverage'),
502504
EnableOption('--enable-tsan'),

utils/swift_build_support/swift_build_support/products/swift.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ def __init__(self, args, toolchain, source_dir, build_dir):
4949
self.cmake_options.extend(
5050
self._enable_experimental_differentiable_programming)
5151

52+
# Add experimental concurrency flag.
53+
self.cmake_options.extend(self._enable_experimental_concurrency)
54+
5255
@classmethod
5356
def is_build_script_impl_product(cls):
5457
"""is_build_script_impl_product -> bool
@@ -134,6 +137,11 @@ def _enable_experimental_differentiable_programming(self):
134137
return [('SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING:BOOL',
135138
self.args.enable_experimental_differentiable_programming)]
136139

140+
@property
141+
def _enable_experimental_concurrency(self):
142+
return [('SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY:BOOL',
143+
self.args.enable_experimental_concurrency)]
144+
137145
@classmethod
138146
def get_dependencies(cls):
139147
return [cmark.CMark,

utils/swift_build_support/tests/products/test_swift.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ def setUp(self):
5858
disable_guaranteed_normal_arguments=True,
5959
force_optimized_typechecker=False,
6060
enable_stdlibcore_exclusivity_checking=False,
61-
enable_experimental_differentiable_programming=False)
61+
enable_experimental_differentiable_programming=False,
62+
enable_experimental_concurrency=False)
6263

6364
# Setup shell
6465
shell.dry_run = True
@@ -89,7 +90,8 @@ def test_by_default_no_cmake_options(self):
8990
'-DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE',
9091
'-DSWIFT_FORCE_OPTIMIZED_TYPECHECKER:BOOL=FALSE',
9192
'-DSWIFT_STDLIB_ENABLE_STDLIBCORE_EXCLUSIVITY_CHECKING:BOOL=FALSE',
92-
'-DSWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING:BOOL=FALSE'
93+
'-DSWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING:BOOL=FALSE',
94+
'-DSWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY:BOOL=FALSE',
9395
]
9496
self.assertEqual(set(swift.cmake_options), set(expected))
9597

@@ -105,7 +107,8 @@ def test_swift_runtime_tsan(self):
105107
'-DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE',
106108
'-DSWIFT_FORCE_OPTIMIZED_TYPECHECKER:BOOL=FALSE',
107109
'-DSWIFT_STDLIB_ENABLE_STDLIBCORE_EXCLUSIVITY_CHECKING:BOOL=FALSE',
108-
'-DSWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING:BOOL=FALSE'
110+
'-DSWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING:BOOL=FALSE',
111+
'-DSWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY:BOOL=FALSE'
109112
]
110113
self.assertEqual(set(swift.cmake_options), set(flags_set))
111114

@@ -318,3 +321,16 @@ def test_experimental_differentiable_programming_flags(self):
318321
'TRUE'],
319322
[x for x in swift.cmake_options
320323
if 'DSWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING' in x])
324+
325+
def test_experimental_concurrency_flags(self):
326+
self.args.enable_experimental_concurrency = True
327+
swift = Swift(
328+
args=self.args,
329+
toolchain=self.toolchain,
330+
source_dir='/path/to/src',
331+
build_dir='/path/to/build')
332+
self.assertEqual(
333+
['-DSWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY:BOOL='
334+
'TRUE'],
335+
[x for x in swift.cmake_options
336+
if 'DSWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY' in x])

0 commit comments

Comments
 (0)