Skip to content

Commit 1b5edc7

Browse files
authored
Merge pull request #2879 from swiftwasm/main
[pull] swiftwasm from main
2 parents 5be01d1 + 9aa2111 commit 1b5edc7

File tree

235 files changed

+2599
-1275
lines changed

Some content is hidden

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

235 files changed

+2599
-1275
lines changed

docs/ABI/Mangling.rst

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

570-
function-signature ::= params-type params-type async? concurrent? throws? // results and parameters
570+
function-signature ::= params-type params-type async? sendable? throws? // results and parameters
571571

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

577-
concurrent ::= 'J' // @concurrent on function types
577+
sendable ::= 'J' // @Sendable on function types
578578
async ::= 'Y' // 'async' annotation on function types
579579
throws ::= 'K' // 'throws' annotation on function types
580580

@@ -636,7 +636,7 @@ mangled in to disambiguate.
636636
impl-function-type ::= type* 'I' FUNC-ATTRIBUTES '_'
637637
impl-function-type ::= type* generic-signature 'I' FUNC-ATTRIBUTES '_'
638638

639-
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?)?
639+
FUNC-ATTRIBUTES ::= PATTERN-SUBS? INVOCATION-SUBS? PSEUDO-GENERIC? CALLEE-ESCAPE? DIFFERENTIABILITY-KIND? CALLEE-CONVENTION FUNC-REPRESENTATION? COROUTINE-KIND? SENDABLE? ASYNC? (PARAM-CONVENTION PARAM-DIFFERENTIABILITY?)* RESULT-CONVENTION* ('Y' PARAM-CONVENTION)* ('z' RESULT-CONVENTION RESULT-DIFFERENTIABILITY?)?
640640

641641
PATTERN-SUBS ::= 's' // has pattern substitutions
642642
INVOCATION-SUB ::= 'I' // has invocation substitutions
@@ -666,7 +666,7 @@ mangled in to disambiguate.
666666
COROUTINE-KIND ::= 'A' // yield-once coroutine
667667
COROUTINE-KIND ::= 'G' // yield-many coroutine
668668

669-
CONCURRENT ::= 'h' // @concurrent
669+
SENDABLE ::= 'h' // @Sendable
670670
ASYNC ::= 'H' // @async
671671

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

include/swift/ABI/Metadata.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1657,7 +1657,7 @@ struct TargetFunctionTypeMetadata : public TargetMetadata<Runtime> {
16571657
}
16581658
bool isAsync() const { return Flags.isAsync(); }
16591659
bool isThrowing() const { return Flags.isThrowing(); }
1660-
bool isConcurrent() const { return Flags.isConcurrent(); }
1660+
bool isSendable() const { return Flags.isSendable(); }
16611661
bool hasParameterFlags() const { return Flags.hasParameterFlags(); }
16621662
bool isEscaping() const { return Flags.isEscaping(); }
16631663

include/swift/ABI/MetadataValues.h

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ class MethodDescriptorFlags {
317317
KindMask = 0x0F, // 16 kinds should be enough for anybody
318318
IsInstanceMask = 0x10,
319319
IsDynamicMask = 0x20,
320+
IsSignedAsDataMask = 0x40,
320321
ExtraDiscriminatorShift = 16,
321322
ExtraDiscriminatorMask = 0xFFFF0000,
322323
};
@@ -345,6 +346,15 @@ class MethodDescriptorFlags {
345346
return copy;
346347
}
347348

349+
MethodDescriptorFlags withIsSignedAsData(bool isSignedAsData) const {
350+
auto copy = *this;
351+
if (isSignedAsData)
352+
copy.Value |= IsSignedAsDataMask;
353+
else
354+
copy.Value &= ~IsSignedAsDataMask;
355+
return copy;
356+
}
357+
348358
MethodDescriptorFlags withExtraDiscriminator(uint16_t value) const {
349359
auto copy = *this;
350360
copy.Value = (copy.Value & ~ExtraDiscriminatorMask)
@@ -362,6 +372,8 @@ class MethodDescriptorFlags {
362372
/// Note that 'init' is not considered an instance member.
363373
bool isInstance() const { return Value & IsInstanceMask; }
364374

375+
bool isSignedAsData() const { return Value & IsSignedAsDataMask; }
376+
365377
uint16_t getExtraDiscriminator() const {
366378
return (Value >> ExtraDiscriminatorShift);
367379
}
@@ -527,6 +539,7 @@ class ProtocolRequirementFlags {
527539
enum : int_type {
528540
KindMask = 0x0F, // 16 kinds should be enough for anybody
529541
IsInstanceMask = 0x10,
542+
IsSignedAsDataMask = 0x20,
530543
ExtraDiscriminatorShift = 16,
531544
ExtraDiscriminatorMask = 0xFFFF0000,
532545
};
@@ -546,6 +559,15 @@ class ProtocolRequirementFlags {
546559
return copy;
547560
}
548561

562+
ProtocolRequirementFlags withIsSignedAsData(bool isSignedAsData) const {
563+
auto copy = *this;
564+
if (isSignedAsData)
565+
copy.Value |= IsSignedAsDataMask;
566+
else
567+
copy.Value &= ~IsSignedAsDataMask;
568+
return copy;
569+
}
570+
549571
ProtocolRequirementFlags withExtraDiscriminator(uint16_t value) const {
550572
auto copy = *this;
551573
copy.Value = (copy.Value & ~ExtraDiscriminatorMask)
@@ -560,6 +582,8 @@ class ProtocolRequirementFlags {
560582
/// Note that 'init' is not considered an instance member.
561583
bool isInstance() const { return Value & IsInstanceMask; }
562584

585+
bool isSignedAsData() const { return Value & IsSignedAsDataMask; }
586+
563587
bool isSignedWithAddress() const {
564588
return getKind() != Kind::BaseProtocol;
565589
}
@@ -787,7 +811,7 @@ class TargetFunctionTypeFlags {
787811
DifferentiabilityMask = 0x98000000U,
788812
DifferentiabilityShift = 27U,
789813
AsyncMask = 0x20000000U,
790-
ConcurrentMask = 0x40000000U,
814+
SendableMask = 0x40000000U,
791815
};
792816
int_type Data;
793817

@@ -837,10 +861,10 @@ class TargetFunctionTypeFlags {
837861
}
838862

839863
constexpr TargetFunctionTypeFlags<int_type>
840-
withConcurrent(bool isConcurrent) const {
864+
withConcurrent(bool isSendable) const {
841865
return TargetFunctionTypeFlags<int_type>(
842-
(Data & ~ConcurrentMask) |
843-
(isConcurrent ? ConcurrentMask : 0));
866+
(Data & ~SendableMask) |
867+
(isSendable ? SendableMask : 0));
844868
}
845869

846870
unsigned getNumParameters() const { return Data & NumParametersMask; }
@@ -857,8 +881,8 @@ class TargetFunctionTypeFlags {
857881
return bool (Data & EscapingMask);
858882
}
859883

860-
bool isConcurrent() const {
861-
return bool (Data & ConcurrentMask);
884+
bool isSendable() const {
885+
return bool (Data & SendableMask);
862886
}
863887

864888
bool hasParameterFlags() const { return bool(Data & ParamFlagsMask); }

include/swift/ABI/Task.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -483,10 +483,6 @@ class alignas(MaximumAlignment) AsyncContext {
483483
TaskContinuationFunction * __ptrauth_swift_async_context_resume
484484
ResumeParent;
485485

486-
/// The executor that the parent needs to be resumed on.
487-
/// FIXME: remove this
488-
ExecutorRef ResumeParentExecutor;
489-
490486
/// Flags describing this context.
491487
///
492488
/// Note that this field is only 32 bits; any alignment padding
@@ -499,7 +495,6 @@ class alignas(MaximumAlignment) AsyncContext {
499495
TaskContinuationFunction *resumeParent,
500496
AsyncContext *parent)
501497
: Parent(parent), ResumeParent(resumeParent),
502-
ResumeParentExecutor(ExecutorRef::generic()),
503498
Flags(flags) {}
504499

505500
AsyncContext(const AsyncContext &) = delete;

include/swift/AST/AnyFunctionRef.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,13 @@ class AnyFunctionRef {
188188
return false;
189189
}
190190

191-
/// Whether this function is @concurrent.
192-
bool isConcurrent() const {
191+
/// Whether this function is @Sendable.
192+
bool isSendable() const {
193193
if (!hasType())
194194
return false;
195195

196196
if (auto *fnType = getType()->getAs<AnyFunctionType>())
197-
return fnType->isConcurrent();
197+
return fnType->isSendable();
198198

199199
return false;
200200
}

include/swift/AST/Attr.def

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

5959
// SIL-specific attributes
6060
TYPE_ATTR(block_storage)
@@ -601,7 +601,7 @@ CONTEXTUAL_SIMPLE_DECL_ATTR(async, Async,
601601
APIBreakingToAdd | APIBreakingToRemove,
602602
106)
603603

604-
SIMPLE_DECL_ATTR(concurrent, Concurrent,
604+
SIMPLE_DECL_ATTR(Sendable, Sendable,
605605
OnFunc | OnConstructor | OnAccessor |
606606
ABIBreakingToAdd | ABIBreakingToRemove |
607607
APIBreakingToAdd | APIBreakingToRemove,

include/swift/AST/Decl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5738,8 +5738,8 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
57385738

57395739
/// Determine whether the given function is concurrent.
57405740
///
5741-
/// A function is concurrent if it has the @concurrent attribute.
5742-
bool isConcurrent() const;
5741+
/// A function is concurrent if it has the @Sendable attribute.
5742+
bool isSendable() const;
57435743

57445744
/// Returns true if the function is a suitable 'async' context.
57455745
///

include/swift/AST/DeclContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ enum class ConformanceLookupKind : unsigned {
160160
/// All conformances except for inherited ones.
161161
NonInherited,
162162
/// All conformances except structurally-derived conformances, of which
163-
/// ConcurrentValue is the only one.
163+
/// Sendable is the only one.
164164
NonStructural,
165165
};
166166

include/swift/AST/DiagnosticEngine.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "llvm/Support/Allocator.h"
3030
#include "llvm/Support/FileSystem.h"
3131
#include "llvm/Support/Path.h"
32+
#include "llvm/Support/SaveAndRestore.h"
3233
#include "llvm/Support/VersionTuple.h"
3334

3435
namespace swift {
@@ -640,6 +641,8 @@ namespace swift {
640641
/// Track which diagnostics should be ignored.
641642
llvm::BitVector ignoredDiagnostics;
642643

644+
friend class DiagnosticStateRAII;
645+
643646
public:
644647
DiagnosticState();
645648

@@ -740,6 +743,7 @@ namespace swift {
740743
friend class InFlightDiagnostic;
741744
friend class DiagnosticTransaction;
742745
friend class CompoundDiagnosticTransaction;
746+
friend class DiagnosticStateRAII;
743747

744748
public:
745749
explicit DiagnosticEngine(SourceManager &SourceMgr)
@@ -1053,6 +1057,33 @@ namespace swift {
10531057
}
10541058
};
10551059

1060+
/// Remember details about the state of a diagnostic engine and restore them
1061+
/// when the object is destroyed.
1062+
///
1063+
/// Diagnostic engines contain state about the most recent diagnostic emitted
1064+
/// which influences subsequent emissions; in particular, if you try to emit
1065+
/// a note and the previous diagnostic was ignored, the note will be ignored
1066+
/// too. This can be a problem in code structured like:
1067+
///
1068+
/// D->diagnose(diag::an_error);
1069+
/// if (conditionWhichMightEmitDiagnostics())
1070+
/// D->diagnose(diag::a_note); // might be affected by diagnostics from
1071+
/// // conditionWhichMightEmitDiagnostics()!
1072+
///
1073+
/// To prevent this, functions which are called for their return values but
1074+
/// may emit diagnostics as a side effect can use \c DiagnosticStateRAII to
1075+
/// ensure that their changes to diagnostic engine state don't leak out and
1076+
/// affect the caller's diagnostics.
1077+
class DiagnosticStateRAII {
1078+
llvm::SaveAndRestore<DiagnosticBehavior> previousBehavior;
1079+
1080+
public:
1081+
DiagnosticStateRAII(DiagnosticEngine &diags)
1082+
: previousBehavior(diags.state.previousBehavior) {}
1083+
1084+
~DiagnosticStateRAII() {}
1085+
};
1086+
10561087
class BufferIndirectlyCausingDiagnosticRAII {
10571088
private:
10581089
DiagnosticEngine &Diags;

include/swift/AST/DiagnosticsSema.def

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3825,18 +3825,18 @@ NOTE(generic_parameters_always_escaping,none,
38253825

38263826
ERROR(passing_noattrfunc_to_attrfunc,none,
38273827
"passing %select{non-escaping|non-concurrent}0 parameter %1 to function "
3828-
"expecting %select{an @escaping|a @concurrent}0 closure",
3828+
"expecting %select{an @escaping|a @Sendable}0 closure",
38293829
(unsigned, Identifier))
38303830
ERROR(converting_noespace_param_to_generic_type,none,
38313831
"converting non-escaping parameter %0 to generic parameter %1 may allow it to escape",
38323832
(Identifier, Type))
38333833
ERROR(assigning_noattrfunc_to_attrfunc,none,
38343834
"assigning %select{non-escaping|non-concurrent}0 parameter %1 to "
3835-
"%select{an @escaping|a @concurrent}0 closure",
3835+
"%select{an @escaping|a @Sendable}0 closure",
38363836
(unsigned, Identifier))
38373837
ERROR(general_noattrfunc_to_attr,none,
38383838
"using %select{non-escaping|non-concurrent}0 parameter %1 in a context "
3839-
"expecting %select{an @escaping|a @concurrent}0 closure",
3839+
"expecting %select{an @escaping|a @Sendable}0 closure",
38403840
(unsigned, Identifier))
38413841
ERROR(converting_noattrfunc_to_type,none,
38423842
"converting %select{non-escaping|non-concurrent function}0 value to %1 "
@@ -4371,7 +4371,7 @@ ERROR(actor_isolated_keypath_component,none,
43714371
"cannot form key path to actor-isolated %0 %1",
43724372
(DescriptiveDeclKind, DeclName))
43734373
ERROR(local_function_executed_concurrently,none,
4374-
"concurrently-executed %0 %1 must be marked as '@concurrent'",
4374+
"concurrently-executed %0 %1 must be marked as '@Sendable'",
43754375
(DescriptiveDeclKind, DeclName))
43764376
ERROR(concurrent_access_of_local_capture,none,
43774377
"%select{mutation of|reference to}0 captured %1 %2 in "
@@ -4404,37 +4404,37 @@ ERROR(global_actor_isolated_requirement_witness_conflict,none,
44044404
(DescriptiveDeclKind, DeclName, Type, Identifier, Type))
44054405

44064406
WARNING(non_concurrent_param_type,none,
4407-
"cannot pass argument of non-concurrent-value type %0 across actors",
4407+
"cannot pass argument of non-sendable type %0 across actors",
44084408
(Type))
44094409
WARNING(non_concurrent_result_type,none,
4410-
"cannot call function returning non-concurrent-value type %0 across "
4410+
"cannot call function returning non-sendable type %0 across "
44114411
"actors", (Type))
44124412
WARNING(non_concurrent_property_type,none,
4413-
"cannot use %0 %1 with a non-concurrent-value type %2 "
4413+
"cannot use %0 %1 with a non-sendable type %2 "
44144414
"%select{across actors|from concurrently-executed code}3",
44154415
(DescriptiveDeclKind, DeclName, Type, bool))
44164416
WARNING(non_concurrent_keypath_capture,none,
4417-
"cannot form key path that captures non-concurrent-value type %0",
4417+
"cannot form key path that captures non-sendable type %0",
44184418
(Type))
44194419
WARNING(non_concurrent_keypath_access,none,
4420-
"cannot form key path that accesses non-concurrent-value type %0",
4420+
"cannot form key path that accesses non-sendable type %0",
44214421
(Type))
44224422
ERROR(non_concurrent_type_member,none,
44234423
"%select{stored property %1|associated value %1}0 of "
4424-
"'ConcurrentValue'-conforming %2 %3 has non-concurrent-value type %4",
4424+
"'Sendable'-conforming %2 %3 has non-sendable type %4",
44254425
(bool, DeclName, DescriptiveDeclKind, DeclName, Type))
44264426
ERROR(concurrent_value_class_mutable_property,none,
4427-
"stored property %0 of 'ConcurrentValue'-conforming %1 %2 is mutable",
4427+
"stored property %0 of 'Sendable'-conforming %1 %2 is mutable",
44284428
(DeclName, DescriptiveDeclKind, DeclName))
44294429
ERROR(concurrent_value_outside_source_file,none,
4430-
"conformance to 'ConcurrentValue' must occur in the same source file as "
4431-
"%0 %1; use 'UnsafeConcurrentValue' for retroactive conformance",
4430+
"conformance to 'Sendable' must occur in the same source file as "
4431+
"%0 %1; use 'UnsafeSendable' for retroactive conformance",
44324432
(DescriptiveDeclKind, DeclName))
44334433
ERROR(concurrent_value_nonfinal_class,none,
4434-
"non-final class %0 cannot conform to `ConcurrentValue`; "
4435-
"use `UnsafeConcurrentValue`", (DeclName))
4434+
"non-final class %0 cannot conform to `Sendable`; "
4435+
"use `UnsafeSendable`", (DeclName))
44364436
ERROR(concurrent_value_inherit,none,
4437-
"`ConcurrentValue` class %1 cannot inherit from another class"
4437+
"`Sendable` class %1 cannot inherit from another class"
44384438
"%select{| other than 'NSObject'}0",
44394439
(bool, DeclName))
44404440

0 commit comments

Comments
 (0)