Skip to content

Commit a02c617

Browse files
authored
Merge pull request #2618 from swiftwasm/katei/merge-main-2021-01-30
Merge main 2021-01-30
2 parents 0b7eae6 + bd1b966 commit a02c617

File tree

149 files changed

+2648
-1852
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+2648
-1852
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -437,14 +437,15 @@ function(add_swift_host_library name)
437437
endif()
438438

439439
if(XCODE)
440-
get_filename_component(dir ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY)
441-
440+
get_filename_component(base_dir ${CMAKE_CURRENT_SOURCE_DIR} NAME)
441+
442442
file(GLOB_RECURSE ASHL_HEADERS
443-
${SWIFT_SOURCE_DIR}/include/swift${dir}/*.h
444-
${SWIFT_SOURCE_DIR}/include/swift${dir}/*.def
443+
${SWIFT_SOURCE_DIR}/include/swift/${base_dir}/*.h
444+
${SWIFT_SOURCE_DIR}/include/swift/${base_dir}/*.def
445+
${CMAKE_CURRENT_SOURCE_DIR}/*.h
445446
${CMAKE_CURRENT_SOURCE_DIR}/*.def)
446447
file(GLOB_RECURSE ASHL_TDS
447-
${SWIFT_SOURCE_DIR}/include/swift${dir}/*.td)
448+
${SWIFT_SOURCE_DIR}/include/swift${base_dir}/*.td)
448449

449450
set_source_files_properties(${ASHL_HEADERS} ${ASHL_TDS} PROPERTIES
450451
HEADER_FILE_ONLY true)

docs/ABI/Mangling.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,13 +556,14 @@ Types
556556
C-TYPE is mangled according to the Itanium ABI, and prefixed with the length.
557557
Non-ASCII identifiers are preserved as-is; we do not use Punycode.
558558

559-
function-signature ::= params-type params-type async? throws? // results and parameters
559+
function-signature ::= params-type params-type async? concurrent? throws? // results and parameters
560560

561561
params-type ::= type 'z'? 'h'? // tuple in case of multiple parameters or a single parameter with a single tuple type
562562
// with optional inout convention, shared convention. parameters don't have labels,
563563
// they are mangled separately as part of the entity.
564564
params-type ::= empty-list // shortcut for no parameters
565565

566+
concurrent ::= 'J' // @concurrent on function types
566567
async ::= 'Y' // 'async' annotation on function types
567568
throws ::= 'K' // 'throws' annotation on function types
568569

@@ -624,7 +625,7 @@ mangled in to disambiguate.
624625
impl-function-type ::= type* 'I' FUNC-ATTRIBUTES '_'
625626
impl-function-type ::= type* generic-signature 'I' FUNC-ATTRIBUTES '_'
626627

627-
FUNC-ATTRIBUTES ::= PATTERN-SUBS? INVOCATION-SUBS? PSEUDO-GENERIC? CALLEE-ESCAPE? DIFFERENTIABILITY-KIND? CALLEE-CONVENTION FUNC-REPRESENTATION? COROUTINE-KIND? ASYNC? (PARAM-CONVENTION PARAM-DIFFERENTIABILITY?)* RESULT-CONVENTION* ('Y' PARAM-CONVENTION)* ('z' RESULT-CONVENTION RESULT-DIFFERENTIABILITY?)?
628+
FUNC-ATTRIBUTES ::= PATTERN-SUBS? INVOCATION-SUBS? PSEUDO-GENERIC? CALLEE-ESCAPE? DIFFERENTIABILITY-KIND? CALLEE-CONVENTION FUNC-REPRESENTATION? COROUTINE-KIND? CONCURRENT? ASYNC? (PARAM-CONVENTION PARAM-DIFFERENTIABILITY?)* RESULT-CONVENTION* ('Y' PARAM-CONVENTION)* ('z' RESULT-CONVENTION RESULT-DIFFERENTIABILITY?)?
628629

629630
PATTERN-SUBS ::= 's' // has pattern substitutions
630631
INVOCATION-SUB ::= 'I' // has invocation substitutions
@@ -653,6 +654,7 @@ mangled in to disambiguate.
653654
COROUTINE-KIND ::= 'A' // yield-once coroutine
654655
COROUTINE-KIND ::= 'G' // yield-many coroutine
655656

657+
CONCURRENT ::= 'h' // @concurrent
656658
ASYNC ::= 'H' // @async
657659

658660
PARAM-CONVENTION ::= 'i' // indirect in

include/swift/ABI/Metadata.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,6 +1637,7 @@ struct TargetFunctionTypeMetadata : public TargetMetadata<Runtime> {
16371637
}
16381638
bool isAsync() const { return Flags.isAsync(); }
16391639
bool isThrowing() const { return Flags.isThrowing(); }
1640+
bool isConcurrent() const { return Flags.isConcurrent(); }
16401641
bool hasParameterFlags() const { return Flags.hasParameterFlags(); }
16411642
bool isEscaping() const { return Flags.isEscaping(); }
16421643

include/swift/ABI/MetadataValues.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,7 @@ class TargetFunctionTypeFlags {
779779
DifferentiableMask = 0x08000000U,
780780
LinearMask = 0x10000000U,
781781
AsyncMask = 0x20000000U,
782+
ConcurrentMask = 0x40000000U,
782783
};
783784
int_type Data;
784785

@@ -831,6 +832,13 @@ class TargetFunctionTypeFlags {
831832
(isEscaping ? EscapingMask : 0));
832833
}
833834

835+
constexpr TargetFunctionTypeFlags<int_type>
836+
withConcurrent(bool isConcurrent) const {
837+
return TargetFunctionTypeFlags<int_type>(
838+
(Data & ~ConcurrentMask) |
839+
(isConcurrent ? ConcurrentMask : 0));
840+
}
841+
834842
unsigned getNumParameters() const { return Data & NumParametersMask; }
835843

836844
FunctionMetadataConvention getConvention() const {
@@ -845,6 +853,10 @@ class TargetFunctionTypeFlags {
845853
return bool (Data & EscapingMask);
846854
}
847855

856+
bool isConcurrent() const {
857+
return bool (Data & ConcurrentMask);
858+
}
859+
848860
bool hasParameterFlags() const { return bool(Data & ParamFlagsMask); }
849861

850862
bool isDifferentiable() const {

include/swift/AST/AnyFunctionRef.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,17 @@ class AnyFunctionRef {
181181
return false;
182182
}
183183

184+
/// Whether this function is @concurrent.
185+
bool isConcurrent() const {
186+
if (!hasType())
187+
return false;
188+
189+
if (auto *fnType = getType()->getAs<AnyFunctionType>())
190+
return fnType->isConcurrent();
191+
192+
return false;
193+
}
194+
184195
bool isObjC() const {
185196
if (auto afd = TheFunction.dyn_cast<AbstractFunctionDecl *>()) {
186197
return afd->isObjC();

include/swift/AST/Attr.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ TYPE_ATTR(escaping)
5454
TYPE_ATTR(differentiable)
5555
TYPE_ATTR(noDerivative)
5656
TYPE_ATTR(async)
57+
TYPE_ATTR(concurrent)
5758

5859
// SIL-specific attributes
5960
TYPE_ATTR(block_storage)
@@ -599,6 +600,12 @@ CONTEXTUAL_SIMPLE_DECL_ATTR(async, Async,
599600
APIBreakingToAdd | APIBreakingToRemove,
600601
106)
601602

603+
SIMPLE_DECL_ATTR(concurrent, Concurrent,
604+
OnFunc | OnConstructor | OnAccessor | ConcurrencyOnly |
605+
ABIStableToAdd | ABIStableToRemove |
606+
APIBreakingToAdd | APIBreakingToRemove,
607+
107)
608+
602609
#undef TYPE_ATTR
603610
#undef DECL_ATTR_ALIAS
604611
#undef CONTEXTUAL_DECL_ATTR_ALIAS

include/swift/AST/Decl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5773,6 +5773,11 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
57735773
/// type of the function will be `async` as well.
57745774
bool hasAsync() const { return Bits.AbstractFunctionDecl.Async; }
57755775

5776+
/// Determine whether the given function is concurrent.
5777+
///
5778+
/// A function is concurrent if it has the @concurrent attribute.
5779+
bool isConcurrent() const;
5780+
57765781
/// Returns true if the function is a suitable 'async' context.
57775782
///
57785783
/// Functions that are an 'async' context can make calls to 'async' functions.

include/swift/AST/DiagnosticsSema.def

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3727,26 +3727,30 @@ NOTE(silence_debug_description_in_interpolation_segment_call,none,
37273727
"use 'String(describing:)' to silence this warning", ())
37283728

37293729
NOTE(noescape_parameter,none,
3730-
"parameter %0 is implicitly non-escaping",
3731-
(Identifier))
3730+
"parameter %1 is implicitly %select{non-escaping|non-concurrent}0",
3731+
(unsigned, Identifier))
37323732
NOTE(generic_parameters_always_escaping,none,
37333733
"generic parameters are always considered '@escaping'", ())
37343734

3735-
ERROR(passing_noescape_to_escaping,none,
3736-
"passing non-escaping parameter %0 to function expecting an @escaping closure",
3737-
(Identifier))
3735+
ERROR(passing_noattrfunc_to_attrfunc,none,
3736+
"passing %select{non-escaping|non-concurrent}0 parameter %1 to function "
3737+
"expecting %select{an @escaping|a @concurrent}0 closure",
3738+
(unsigned, Identifier))
37383739
ERROR(converting_noespace_param_to_generic_type,none,
37393740
"converting non-escaping parameter %0 to generic parameter %1 may allow it to escape",
37403741
(Identifier, Type))
3741-
ERROR(assigning_noescape_to_escaping,none,
3742-
"assigning non-escaping parameter %0 to an @escaping closure",
3743-
(Identifier))
3744-
ERROR(general_noescape_to_escaping,none,
3745-
"using non-escaping parameter %0 in a context expecting an @escaping closure",
3746-
(Identifier))
3747-
ERROR(converting_noescape_to_type,none,
3748-
"converting non-escaping value to %0 may allow it to escape",
3749-
(Type))
3742+
ERROR(assigning_noattrfunc_to_attrfunc,none,
3743+
"assigning %select{non-escaping|non-concurrent}0 parameter %1 to "
3744+
"%select{an @escaping|a @concurrent}0 closure",
3745+
(unsigned, Identifier))
3746+
ERROR(general_noattrfunc_to_attr,none,
3747+
"using %select{non-escaping|non-concurrent}0 parameter %1 in a context "
3748+
"expecting %select{an @escaping|a @concurrent}0 closure",
3749+
(unsigned, Identifier))
3750+
ERROR(converting_noattrfunc_to_type,none,
3751+
"converting %select{non-escaping|non-concurrent function}0 value to %1 "
3752+
"may %select{allow it to escape|introduce data races}0",
3753+
(unsigned, Type))
37503754

37513755
ERROR(capture_across_type_decl,none,
37523756
"%0 declaration cannot close over value %1 defined in outer scope",
@@ -4252,14 +4256,29 @@ ERROR(global_actor_from_nonactor_context,none,
42524256
ERROR(actor_isolated_partial_apply,none,
42534257
"actor-isolated %0 %1 can not be partially applied",
42544258
(DescriptiveDeclKind, DeclName))
4255-
WARNING(concurrent_access_local,none,
4256-
"local %0 %1 is unsafe to reference in code that may execute "
4257-
"concurrently",
4259+
ERROR(concurrent_access_local,none,
4260+
"use of local %0 %1 in concurrently-executing code",
42584261
(DescriptiveDeclKind, DeclName))
4259-
ERROR(actor_isolated_concurrent_access,none,
4260-
"actor-isolated %0 %1 is unsafe to reference in code "
4261-
"that may execute concurrently",
4262+
ERROR(actor_isolated_from_concurrent_closure,none,
4263+
"actor-isolated %0 %1 cannot be referenced from a concurrent closure",
42624264
(DescriptiveDeclKind, DeclName))
4265+
ERROR(actor_isolated_from_concurrent_function,none,
4266+
"actor-isolated %0 %1 cannot be referenced from a concurrent function",
4267+
(DescriptiveDeclKind, DeclName))
4268+
ERROR(actor_isolated_from_async_let,none,
4269+
"actor-isolated %0 %1 cannot be referenced from 'async let' initializer",
4270+
(DescriptiveDeclKind, DeclName))
4271+
ERROR(actor_isolated_from_escaping_closure,none,
4272+
"actor-isolated %0 %1 cannot be referenced from an '@escaping' closure",
4273+
(DescriptiveDeclKind, DeclName))
4274+
ERROR(local_function_executed_concurrently,none,
4275+
"concurrently-executed %0 %1 must be marked as '@concurrent'",
4276+
(DescriptiveDeclKind, DeclName))
4277+
ERROR(concurrent_mutation_of_local_capture,none,
4278+
"mutation of captured %0 %1 in concurrently-executing code",
4279+
(DescriptiveDeclKind, DeclName))
4280+
NOTE(concurrent_access_here,none,
4281+
"access in concurrently-executed code here", ())
42634282
NOTE(actor_isolated_sync_func,none,
42644283
"calls to %0 %1 from outside of its actor context are "
42654284
"implicitly asynchronous",

0 commit comments

Comments
 (0)