Skip to content

Commit a3ebc9a

Browse files
committed
Merge remote-tracking branch 'origin/main' into rebranch
2 parents 13e0ba6 + a34d757 commit a3ebc9a

File tree

83 files changed

+3022
-1403
lines changed

Some content is hidden

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

83 files changed

+3022
-1403
lines changed

cmake/modules/Libdispatch.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ foreach(sdk ${DISPATCH_SDKS})
110110
${CMAKE_COMMAND} -E copy
111111
<INSTALL_DIR>/${LIBDISPATCH_RUNTIME_DIR}/${SWIFT_SDK_${sdk}_SHARED_LIBRARY_PREFIX}BlocksRuntime${SWIFT_SDK_${sdk}_SHARED_LIBRARY_SUFFIX}
112112
${SWIFTLIB_DIR}/${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}/${SWIFT_SDK_${sdk}_SHARED_LIBRARY_PREFIX}BlocksRuntime${SWIFT_SDK_${sdk}_SHARED_LIBRARY_SUFFIX}
113+
COMMAND
114+
${CMAKE_COMMAND} -E copy
115+
<INSTALL_DIR>/${LIBDISPATCH_RUNTIME_DIR}/${SWIFT_SDK_${sdk}_SHARED_LIBRARY_PREFIX}dispatch${SWIFT_SDK_${sdk}_SHARED_LIBRARY_SUFFIX}
116+
${SWIFTLIB_DIR}/${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${SWIFT_SDK_${sdk}_SHARED_LIBRARY_PREFIX}dispatch${SWIFT_SDK_${sdk}_SHARED_LIBRARY_SUFFIX}
117+
COMMAND
118+
${CMAKE_COMMAND} -E copy
119+
<INSTALL_DIR>/${LIBDISPATCH_RUNTIME_DIR}/${SWIFT_SDK_${sdk}_SHARED_LIBRARY_PREFIX}BlocksRuntime${SWIFT_SDK_${sdk}_SHARED_LIBRARY_SUFFIX}
120+
${SWIFTLIB_DIR}/${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${SWIFT_SDK_${sdk}_SHARED_LIBRARY_PREFIX}BlocksRuntime${SWIFT_SDK_${sdk}_SHARED_LIBRARY_SUFFIX}
113121
STEP_TARGETS
114122
install
115123
BUILD_BYPRODUCTS

include/swift/AST/ASTContext.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,8 @@ class ASTContext final {
10191019
ProtocolDecl *protocol,
10201020
SourceLoc loc,
10211021
DeclContext *dc,
1022-
ProtocolConformanceState state);
1022+
ProtocolConformanceState state,
1023+
bool isUnchecked);
10231024

10241025
/// Produce a self-conformance for the given protocol.
10251026
SelfProtocolConformance *

include/swift/AST/ASTPrinter.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "swift/Basic/QuotedString.h"
1818
#include "swift/Basic/UUID.h"
1919
#include "swift/AST/Identifier.h"
20+
#include "swift/AST/Decl.h"
2021
#include "llvm/ADT/SmallString.h"
2122
#include "llvm/ADT/StringRef.h"
2223
#include "llvm/ADT/DenseSet.h"
@@ -351,8 +352,9 @@ void printEnumElementsAsCases(
351352
llvm::DenseSet<EnumElementDecl *> &UnhandledElements,
352353
llvm::raw_ostream &OS);
353354

354-
void getInheritedForPrinting(const Decl *decl, const PrintOptions &options,
355-
llvm::SmallVectorImpl<TypeLoc> &Results);
355+
void getInheritedForPrinting(
356+
const Decl *decl, const PrintOptions &options,
357+
llvm::SmallVectorImpl<InheritedEntry> &Results);
356358

357359
StringRef getAccessorKindString(AccessorKind value);
358360

include/swift/AST/Attr.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ TYPE_ATTR(differentiable)
5555
TYPE_ATTR(noDerivative)
5656
TYPE_ATTR(async)
5757
TYPE_ATTR(Sendable)
58+
TYPE_ATTR(unchecked)
5859

5960
// SIL-specific attributes
6061
TYPE_ATTR(block_storage)

include/swift/AST/Decl.h

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,17 @@ class ImportDecl final : public Decl,
12091209
}
12101210
};
12111211

1212+
/// An entry in the "inherited" list of a type or extension.
1213+
struct InheritedEntry : public TypeLoc {
1214+
/// Whether there was an @unchecked attribute.
1215+
bool isUnchecked = false;
1216+
1217+
InheritedEntry(const TypeLoc &typeLoc);
1218+
1219+
InheritedEntry(const TypeLoc &typeLoc, bool isUnchecked)
1220+
: TypeLoc(typeLoc), isUnchecked(isUnchecked) { }
1221+
};
1222+
12121223
/// ExtensionDecl - This represents a type extension containing methods
12131224
/// associated with the type. This is not a ValueDecl and has no Type because
12141225
/// there are no runtime values of the Extension's type.
@@ -1227,7 +1238,7 @@ class ExtensionDecl final : public GenericContext, public Decl,
12271238
/// extended nominal.
12281239
llvm::PointerIntPair<NominalTypeDecl *, 1, bool> ExtendedNominal;
12291240

1230-
ArrayRef<TypeLoc> Inherited;
1241+
ArrayRef<InheritedEntry> Inherited;
12311242

12321243
/// The next extension in the linked list of extensions.
12331244
///
@@ -1246,7 +1257,7 @@ class ExtensionDecl final : public GenericContext, public Decl,
12461257
friend class IterableDeclContext;
12471258

12481259
ExtensionDecl(SourceLoc extensionLoc, TypeRepr *extendedType,
1249-
ArrayRef<TypeLoc> inherited,
1260+
ArrayRef<InheritedEntry> inherited,
12501261
DeclContext *parent,
12511262
TrailingWhereClause *trailingWhereClause);
12521263

@@ -1271,7 +1282,7 @@ class ExtensionDecl final : public GenericContext, public Decl,
12711282
/// Create a new extension declaration.
12721283
static ExtensionDecl *create(ASTContext &ctx, SourceLoc extensionLoc,
12731284
TypeRepr *extendedType,
1274-
ArrayRef<TypeLoc> inherited,
1285+
ArrayRef<InheritedEntry> inherited,
12751286
DeclContext *parent,
12761287
TrailingWhereClause *trailingWhereClause,
12771288
ClangNode clangNode = ClangNode());
@@ -1326,9 +1337,9 @@ class ExtensionDecl final : public GenericContext, public Decl,
13261337

13271338
/// Retrieve the set of protocols that this type inherits (i.e,
13281339
/// explicitly conforms to).
1329-
ArrayRef<TypeLoc> getInherited() const { return Inherited; }
1340+
ArrayRef<InheritedEntry> getInherited() const { return Inherited; }
13301341

1331-
void setInherited(ArrayRef<TypeLoc> i) { Inherited = i; }
1342+
void setInherited(ArrayRef<InheritedEntry> i) { Inherited = i; }
13321343

13331344
bool hasDefaultAccessLevel() const {
13341345
return Bits.ExtensionDecl.DefaultAndMaxAccessLevel != 0;
@@ -2538,12 +2549,12 @@ class ValueDecl : public Decl {
25382549

25392550
/// This is a common base class for declarations which declare a type.
25402551
class TypeDecl : public ValueDecl {
2541-
ArrayRef<TypeLoc> Inherited;
2552+
ArrayRef<InheritedEntry> Inherited;
25422553

25432554
protected:
25442555
TypeDecl(DeclKind K, llvm::PointerUnion<DeclContext *, ASTContext *> context,
25452556
Identifier name, SourceLoc NameLoc,
2546-
ArrayRef<TypeLoc> inherited) :
2557+
ArrayRef<InheritedEntry> inherited) :
25472558
ValueDecl(K, context, name, NameLoc), Inherited(inherited) {}
25482559

25492560
public:
@@ -2561,9 +2572,9 @@ class TypeDecl : public ValueDecl {
25612572

25622573
/// Retrieve the set of protocols that this type inherits (i.e,
25632574
/// explicitly conforms to).
2564-
ArrayRef<TypeLoc> getInherited() const { return Inherited; }
2575+
ArrayRef<InheritedEntry> getInherited() const { return Inherited; }
25652576

2566-
void setInherited(ArrayRef<TypeLoc> i) { Inherited = i; }
2577+
void setInherited(ArrayRef<InheritedEntry> i) { Inherited = i; }
25672578

25682579
static bool classof(const Decl *D) {
25692580
return D->getKind() >= DeclKind::First_TypeDecl &&
@@ -2588,7 +2599,7 @@ class GenericTypeDecl : public GenericContext, public TypeDecl {
25882599
public:
25892600
GenericTypeDecl(DeclKind K, DeclContext *DC,
25902601
Identifier name, SourceLoc nameLoc,
2591-
ArrayRef<TypeLoc> inherited,
2602+
ArrayRef<InheritedEntry> inherited,
25922603
GenericParamList *GenericParams);
25932604

25942605
// Resolve ambiguity due to multiple base classes.
@@ -3115,7 +3126,7 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
31153126

31163127
NominalTypeDecl(DeclKind K, DeclContext *DC, Identifier name,
31173128
SourceLoc NameLoc,
3118-
ArrayRef<TypeLoc> inherited,
3129+
ArrayRef<InheritedEntry> inherited,
31193130
GenericParamList *GenericParams) :
31203131
GenericTypeDecl(K, DC, name, NameLoc, inherited, GenericParams),
31213132
IterableDeclContext(IterableDeclContextKind::NominalTypeDecl)
@@ -3269,6 +3280,9 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
32693280
/// it is either a distributed actor.
32703281
bool isDistributedActor() const;
32713282

3283+
/// Whether this nominal type qualifies as any actor (plain or distributed).
3284+
bool isAnyActor() const;
3285+
32723286
/// Return the range of semantics attributes attached to this NominalTypeDecl.
32733287
auto getSemanticsAttrs() const
32743288
-> decltype(getAttrs().getSemanticsAttrs()) {
@@ -3411,7 +3425,7 @@ class EnumDecl final : public NominalTypeDecl {
34113425

34123426
public:
34133427
EnumDecl(SourceLoc EnumLoc, Identifier Name, SourceLoc NameLoc,
3414-
ArrayRef<TypeLoc> Inherited,
3428+
ArrayRef<InheritedEntry> Inherited,
34153429
GenericParamList *GenericParams, DeclContext *DC);
34163430

34173431
SourceLoc getStartLoc() const { return EnumLoc; }
@@ -3579,7 +3593,7 @@ class StructDecl final : public NominalTypeDecl {
35793593

35803594
public:
35813595
StructDecl(SourceLoc StructLoc, Identifier Name, SourceLoc NameLoc,
3582-
ArrayRef<TypeLoc> Inherited,
3596+
ArrayRef<InheritedEntry> Inherited,
35833597
GenericParamList *GenericParams, DeclContext *DC);
35843598

35853599
SourceLoc getStartLoc() const { return StructLoc; }
@@ -3725,7 +3739,7 @@ class ClassDecl final : public NominalTypeDecl {
37253739

37263740
public:
37273741
ClassDecl(SourceLoc ClassLoc, Identifier Name, SourceLoc NameLoc,
3728-
ArrayRef<TypeLoc> Inherited,
3742+
ArrayRef<InheritedEntry> Inherited,
37293743
GenericParamList *GenericParams, DeclContext *DC,
37303744
bool isActor);
37313745

@@ -4160,7 +4174,7 @@ class ProtocolDecl final : public NominalTypeDecl {
41604174

41614175
public:
41624176
ProtocolDecl(DeclContext *DC, SourceLoc ProtocolLoc, SourceLoc NameLoc,
4163-
Identifier Name, ArrayRef<TypeLoc> Inherited,
4177+
Identifier Name, ArrayRef<InheritedEntry> Inherited,
41644178
TrailingWhereClause *TrailingWhere);
41654179

41664180
using Decl::getASTContext;

include/swift/AST/DiagnosticsSema.def

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4441,7 +4441,7 @@ NOTE(distributed_actor_isolated_method_note,none,
44414441
"only 'distributed' functions can be called from outside the distributed actor",
44424442
())
44434443
ERROR(distributed_actor_isolated_method,none,
4444-
"only 'distributed' functions can be called from outside the distributed actor", // TODO: more like 'non-distributed' ... defined here
4444+
"only 'distributed' functions can be called from outside the distributed actor", // TODO: improve error message to be more like 'non-distributed' ... defined here
44454445
())
44464446
ERROR(distributed_actor_func_param_not_codable,none,
44474447
"distributed function parameter '%0' of type %1 does not conform to 'Codable'",
@@ -4452,6 +4452,12 @@ ERROR(distributed_actor_func_result_not_codable,none,
44524452
ERROR(distributed_actor_remote_func_implemented_manually,none,
44534453
"Distributed function's %0 remote counterpart %1 cannot not be implemented manually.",
44544454
(Identifier, Identifier))
4455+
ERROR(nonisolated_distributed_actor_storage,none,
4456+
"'nonisolated' can not be applied to distributed actor stored properties",
4457+
())
4458+
ERROR(distributed_actor_func_nonisolated, none,
4459+
"function %0 cannot be both 'nonisolated' and 'distributed'",
4460+
(DeclName))
44554461
ERROR(distributed_actor_remote_func_is_not_static,none,
44564462
"remote function %0 must be static.",
44574463
(DeclName))
@@ -4516,16 +4522,23 @@ ERROR(concurrent_value_class_mutable_property,none,
45164522
(DeclName, DescriptiveDeclKind, DeclName))
45174523
ERROR(concurrent_value_outside_source_file,none,
45184524
"conformance to 'Sendable' must occur in the same source file as "
4519-
"%0 %1; use 'UnsafeSendable' for retroactive conformance",
4525+
"%0 %1; use '@unchecked Sendable' for retroactive conformance",
45204526
(DescriptiveDeclKind, DeclName))
45214527
ERROR(concurrent_value_nonfinal_class,none,
45224528
"non-final class %0 cannot conform to `Sendable`; "
4523-
"use `UnsafeSendable`", (DeclName))
4529+
"use `@unchecked Sendable`", (DeclName))
45244530
ERROR(concurrent_value_inherit,none,
45254531
"`Sendable` class %1 cannot inherit from another class"
45264532
"%select{| other than 'NSObject'}0",
45274533
(bool, DeclName))
45284534

4535+
WARNING(unchecked_conformance_not_special,none,
4536+
"@unchecked conformance to %0 has no meaning", (Type))
4537+
ERROR(unchecked_not_inheritance_clause,none,
4538+
"'unchecked' attribute only applies in inheritance clauses", ())
4539+
ERROR(unchecked_not_existential,none,
4540+
"'unchecked' attribute cannot apply to non-protocol type %0", (Type))
4541+
45294542
ERROR(nonisolated_let,none,
45304543
"'nonisolated' is meaningless on 'let' declarations because "
45314544
"they are immutable",
@@ -4593,7 +4606,7 @@ ERROR(distributed_actor_independent_property_must_be_let,none,
45934606
"_distributedActorIndependent can be applied to properties, however they must be 'let'",
45944607
())
45954608
NOTE(distributed_actor_isolated_property,none,
4596-
"distributed actor state is only available within the actor instance",
4609+
"distributed actor state is only available within the actor instance", // TODO: reword in terms of isolation
45974610
())
45984611

45994612
ERROR(concurrency_lib_missing,none,

include/swift/AST/NameLookup.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,19 @@ void filterForDiscriminator(SmallVectorImpl<Result> &results,
503503

504504
} // end namespace namelookup
505505

506+
/// Describes an inherited nominal entry.
507+
struct InheritedNominalEntry : Located<NominalTypeDecl *> {
508+
/// The location of the "unchecked" attribute, if present.
509+
SourceLoc uncheckedLoc;
510+
511+
InheritedNominalEntry() { }
512+
513+
InheritedNominalEntry(
514+
NominalTypeDecl *item, SourceLoc loc,
515+
SourceLoc uncheckedLoc
516+
) : Located(item, loc), uncheckedLoc(uncheckedLoc) { }
517+
};
518+
506519
/// Retrieve the set of nominal type declarations that are directly
507520
/// "inherited" by the given declaration at a particular position in the
508521
/// list of "inherited" types.
@@ -511,15 +524,15 @@ void filterForDiscriminator(SmallVectorImpl<Result> &results,
511524
/// AnyObject type, set \c anyObject true.
512525
void getDirectlyInheritedNominalTypeDecls(
513526
llvm::PointerUnion<const TypeDecl *, const ExtensionDecl *> decl,
514-
unsigned i, llvm::SmallVectorImpl<Located<NominalTypeDecl *>> &result,
527+
unsigned i, llvm::SmallVectorImpl<InheritedNominalEntry> &result,
515528
bool &anyObject);
516529

517530
/// Retrieve the set of nominal type declarations that are directly
518531
/// "inherited" by the given declaration, looking through typealiases
519532
/// and splitting out the components of compositions.
520533
///
521534
/// If we come across the AnyObject type, set \c anyObject true.
522-
SmallVector<Located<NominalTypeDecl *>, 4> getDirectlyInheritedNominalTypeDecls(
535+
SmallVector<InheritedNominalEntry, 4> getDirectlyInheritedNominalTypeDecls(
523536
llvm::PointerUnion<const TypeDecl *, const ExtensionDecl *> decl,
524537
bool &anyObject);
525538

include/swift/AST/ProtocolConformance.h

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -412,11 +412,20 @@ class NormalProtocolConformance : public RootProtocolConformance,
412412
/// The location of this protocol conformance in the source.
413413
SourceLoc Loc;
414414

415+
// Flag bits used in ContextAndBits.
416+
enum {
417+
/// The conformance is invalid.
418+
InvalidFlag = 0x01,
419+
420+
/// The conformance was labeled with @unchecked.
421+
UncheckedFlag = 0x02,
422+
};
423+
415424
/// The declaration context containing the ExtensionDecl or
416425
/// NominalTypeDecl that declared the conformance.
417426
///
418-
/// Also stores the "invalid" bit.
419-
llvm::PointerIntPair<DeclContext *, 1, bool> ContextAndInvalid;
427+
/// Also stores the "invalid" and "unchecked" bits.
428+
llvm::PointerIntPair<DeclContext *, 2, unsigned> ContextAndBits;
420429

421430
/// The reason that this conformance exists.
422431
///
@@ -457,11 +466,12 @@ class NormalProtocolConformance : public RootProtocolConformance,
457466
public:
458467
NormalProtocolConformance(Type conformingType, ProtocolDecl *protocol,
459468
SourceLoc loc, DeclContext *dc,
460-
ProtocolConformanceState state)
469+
ProtocolConformanceState state,
470+
bool isUnchecked)
461471
: RootProtocolConformance(ProtocolConformanceKind::Normal,
462472
conformingType),
463473
ProtocolAndState(protocol, state), Loc(loc),
464-
ContextAndInvalid(dc, false) {
474+
ContextAndBits(dc, isUnchecked ? UncheckedFlag : 0) {
465475
assert(!conformingType->hasArchetype() &&
466476
"ProtocolConformances should store interface types");
467477
}
@@ -475,7 +485,7 @@ class NormalProtocolConformance : public RootProtocolConformance,
475485
/// Get the declaration context that contains the conforming extension or
476486
/// nominal type declaration.
477487
DeclContext *getDeclContext() const {
478-
return ContextAndInvalid.getPointer();
488+
return ContextAndBits.getPointer();
479489
}
480490

481491
/// Get any additional requirements that are required for this conformance to
@@ -497,15 +507,20 @@ class NormalProtocolConformance : public RootProtocolConformance,
497507

498508
/// Determine whether this conformance is invalid.
499509
bool isInvalid() const {
500-
return ContextAndInvalid.getInt();
510+
return ContextAndBits.getInt() & InvalidFlag;
501511
}
502512

503513
/// Mark this conformance as invalid.
504514
void setInvalid() {
505-
ContextAndInvalid.setInt(true);
515+
ContextAndBits.setInt(ContextAndBits.getInt() | InvalidFlag);
506516
SignatureConformances = {};
507517
}
508518

519+
/// Whether this is an "unchecked" conformance.
520+
bool isUnchecked() const {
521+
return ContextAndBits.getInt() & UncheckedFlag;
522+
}
523+
509524
/// Get the kind of source from which this conformance comes.
510525
ConformanceEntryKind getSourceKind() const {
511526
return SourceKindAndImplyingConformance.getInt();

include/swift/AST/TypeLoc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class TypeRepr;
2929

3030
/// TypeLoc - Provides source location information for a parsed type.
3131
/// A TypeLoc is stored in AST nodes which use an explicitly written type.
32-
class alignas(1 << TypeReprAlignInBits) TypeLoc final {
32+
class alignas(1 << TypeReprAlignInBits) TypeLoc {
3333
Type Ty;
3434
TypeRepr *TyR = nullptr;
3535

include/swift/AST/TypeRepr.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ class alignas(1 << TypeReprAlignInBits) TypeRepr {
135135
SourceLoc getEndLoc() const;
136136
SourceRange getSourceRange() const;
137137

138+
/// Find an @unchecked attribute and return its source location, or return
139+
/// an invalid source location if there is no such attribute.
140+
SourceLoc findUncheckedAttrLoc() const;
141+
138142
/// Is this type grammatically a type-simple?
139143
inline bool isSimple() const; // bottom of this file
140144

0 commit comments

Comments
 (0)