Skip to content

Commit 7535cca

Browse files
Merge remote-tracking branch 'apple/release/5.7' into maxd/5.7-merge
2 parents f81144e + 3445d04 commit 7535cca

File tree

144 files changed

+2535
-486
lines changed

Some content is hidden

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

144 files changed

+2535
-486
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,18 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
401401
the result type provides a generalization where the callee chooses the
402402
resulting type and value.
403403

404+
* The compiler now correctly emits errors for `@available` attributes on stored properties with the `lazy` modifier or with attached property wrappers. Previously, the attribute was accepted on this subset of stored properties but the resulting binary would crash at runtime when type metadata was unavailable.
405+
406+
```swift
407+
struct S {
408+
@available(macOS 99, *) // error: stored properties cannot be marked potentially unavailable with '@available'
409+
lazy var a: Int = 42
410+
411+
@available(macOS 99, *) // error: stored properties cannot be marked potentially unavailable with '@available'
412+
@Wrapper var b: Int
413+
}
414+
```
415+
404416
* The compiler now correctly emits warnings for more kinds of expressions where a protocol conformance is used and may be unavailable at runtime. Previously, member reference expressions and type erasing expressions that used potentially unavailable conformances were not diagnosed, leading to potential crashes at runtime.
405417

406418
```swift

include/swift/ABI/MetadataValues.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,7 @@ class ExtendedExistentialTypeShapeFlags {
899899
SpecialKind getSpecialKind() const {
900900
return SpecialKind((Data & SpecialKindMask) >> SpecialKindShift);
901901
}
902+
bool isOpaque() const { return getSpecialKind() == SpecialKind::None; }
902903
bool isClassConstrained() const {
903904
return getSpecialKind() == SpecialKind::Class;
904905
}

include/swift/AST/ASTContext.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ class ASTContext final {
537537
/// Retrieve the declaration of Swift.Error.
538538
ProtocolDecl *getErrorDecl() const;
539539
CanType getErrorExistentialType() const;
540-
540+
541541
#define KNOWN_STDLIB_TYPE_DECL(NAME, DECL_CLASS, NUM_GENERIC_PARAMS) \
542542
/** Retrieve the declaration of Swift.NAME. */ \
543543
DECL_CLASS *get##NAME##Decl() const; \
@@ -561,7 +561,13 @@ class ASTContext final {
561561
/// Retrieve the declaration of the "pointee" property of a pointer type.
562562
VarDecl *getPointerPointeePropertyDecl(PointerTypeKind ptrKind) const;
563563

564-
/// Retrieve the type Swift.AnyObject.
564+
/// Retrieve the type Swift.Any as an existential type.
565+
CanType getAnyExistentialType() const;
566+
567+
/// Retrieve the type Swift.AnyObject as a constraint.
568+
CanType getAnyObjectConstraint() const;
569+
570+
/// Retrieve the type Swift.AnyObject as an existential type.
565571
CanType getAnyObjectType() const;
566572

567573
#define KNOWN_SDK_TYPE_DECL(MODULE, NAME, DECL_CLASS, NUM_GENERIC_PARAMS) \

include/swift/AST/ASTSynthesis.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ enum SingletonTypeSynthesizer {
5454
inline Type synthesizeType(SynthesisContext &SC,
5555
SingletonTypeSynthesizer kind) {
5656
switch (kind) {
57-
case _any: return SC.Context.TheAnyType;
57+
case _any: return SC.Context.getAnyExistentialType();
5858
case _bridgeObject: return SC.Context.TheBridgeObjectType;
5959
case _error: return SC.Context.getErrorExistentialType();
6060
case _executor: return SC.Context.TheExecutorType;

include/swift/AST/Decl.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6393,6 +6393,9 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
63936393
/// A function is concurrent if it has the @Sendable attribute.
63946394
bool isSendable() const;
63956395

6396+
/// Determine if function has 'nonisolated' attribute
6397+
bool isNonisolated() const;
6398+
63966399
/// Returns true if the function is a suitable 'async' context.
63976400
///
63986401
/// Functions that are an 'async' context can make calls to 'async' functions.
@@ -6740,7 +6743,7 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
67406743
bool hasDynamicSelfResult() const;
67416744

67426745
/// The async function marked as the alternative to this function, if any.
6743-
AbstractFunctionDecl *getAsyncAlternative() const;
6746+
AbstractFunctionDecl *getAsyncAlternative(bool isKnownObjC = false) const;
67446747

67456748
/// If \p asyncAlternative is set, then compare its parameters to this
67466749
/// (presumed synchronous) function's parameters to find the index of the

include/swift/AST/DiagnosticEngine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1390,7 +1390,7 @@ namespace swift {
13901390
DiagnosticEngine &getDiags() { return QueueEngine; }
13911391

13921392
/// Retrieve the underlying engine which will receive the diagnostics.
1393-
DiagnosticEngine &getUnderlyingDiags() { return UnderlyingEngine; }
1393+
DiagnosticEngine &getUnderlyingDiags() const { return UnderlyingEngine; }
13941394

13951395
/// Clear this queue and erase all diagnostics recorded.
13961396
void clear() {

include/swift/AST/DiagnosticsSema.def

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4527,8 +4527,8 @@ ERROR(actor_inheritance,none,
45274527
(bool))
45284528

45294529
ERROR(actor_protocol_illegal_inheritance,none,
4530-
"non-actor type %0 cannot conform to the 'Actor' protocol",
4531-
(DeclName))
4530+
"non-actor type %0 cannot conform to the %1 protocol",
4531+
(DeclName, DeclName))
45324532
ERROR(distributed_actor_conformance_missing_system_type,none,
45334533
"distributed actor %0 does not declare ActorSystem it can be used with.",
45344534
(DeclName))
@@ -4759,6 +4759,9 @@ ERROR(unchecked_not_inheritance_clause,none,
47594759
ERROR(unchecked_not_existential,none,
47604760
"'unchecked' attribute cannot apply to non-protocol type %0", (Type))
47614761

4762+
ERROR(redundant_any_in_existential,none,
4763+
"redundant 'any' has no effect on existential type %0",
4764+
(Type))
47624765
ERROR(any_not_existential,none,
47634766
"'any' has no effect on %select{concrete type|type parameter}0 %1",
47644767
(bool, Type))
@@ -6196,6 +6199,10 @@ ERROR(result_builder_requires_explicit_var_initialization,none,
61966199
ERROR(cannot_declare_computed_var_in_result_builder,none,
61976200
"cannot declare local %select{lazy|wrapped|computed|observed}0 variable "
61986201
"in result builder", (unsigned))
6202+
ERROR(cannot_convert_result_builder_result_to_return_type,none,
6203+
"cannot convert result builder result type %0 to return type %1",
6204+
(Type,Type))
6205+
61996206

62006207
//------------------------------------------------------------------------------
62016208
// MARK: Tuple Shuffle Diagnostics

include/swift/AST/KnownProtocols.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
BUILTIN_EXPRESSIBLE_BY_LITERAL_PROTOCOL_WITH_NAME(name, "_" #name)
6060

6161
PROTOCOL(Actor)
62+
PROTOCOL(AnyActor)
6263
PROTOCOL(Sequence)
6364
PROTOCOL(Identifiable)
6465
PROTOCOL(IteratorProtocol)

include/swift/AST/ModuleLoader.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,11 @@ class ModuleLoader {
226226
virtual void loadExtensions(NominalTypeDecl *nominal,
227227
unsigned previousGeneration) { }
228228

229-
/// Load the methods within the given class that produce
229+
/// Load the methods within the given type that produce
230230
/// Objective-C class or instance methods with the given selector.
231231
///
232-
/// \param classDecl The class in which we are searching for @objc methods.
233-
/// The search only considers this class and its extensions; not any
232+
/// \param typeDecl The type in which we are searching for @objc methods.
233+
/// The search only considers this type and its extensions; not any
234234
/// superclasses.
235235
///
236236
/// \param selector The selector to search for.
@@ -246,7 +246,7 @@ class ModuleLoader {
246246
/// selector and are instance/class methods as requested. This list will be
247247
/// extended with any methods found in subsequent generations.
248248
virtual void loadObjCMethods(
249-
ClassDecl *classDecl,
249+
NominalTypeDecl *typeDecl,
250250
ObjCSelector selector,
251251
bool isInstanceMethod,
252252
unsigned previousGeneration,

include/swift/AST/SourceFile.h

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "swift/AST/Import.h"
1818
#include "swift/AST/SynthesizedFileUnit.h"
1919
#include "swift/Basic/Debug.h"
20+
#include "llvm/ADT/Hashing.h"
2021
#include "llvm/ADT/SetVector.h"
2122
#include "llvm/ADT/SmallPtrSet.h"
2223

@@ -243,11 +244,20 @@ class SourceFile final : public FileUnit {
243244
std::vector<ObjCUnsatisfiedOptReq> ObjCUnsatisfiedOptReqs;
244245

245246
/// A selector that is used by two different declarations in the same class.
246-
/// Fields: typeDecl, selector, isInstanceMethod.
247-
using ObjCMethodConflict = std::tuple<NominalTypeDecl *, ObjCSelector, bool>;
247+
struct ObjCMethodConflict {
248+
NominalTypeDecl *typeDecl;
249+
ObjCSelector selector;
250+
bool isInstanceMethod;
251+
252+
ObjCMethodConflict(NominalTypeDecl *typeDecl, ObjCSelector selector,
253+
bool isInstanceMethod)
254+
: typeDecl(typeDecl), selector(selector),
255+
isInstanceMethod(isInstanceMethod)
256+
{}
257+
};
248258

249259
/// List of Objective-C member conflicts we have found during type checking.
250-
std::vector<ObjCMethodConflict> ObjCMethodConflicts;
260+
llvm::SetVector<ObjCMethodConflict> ObjCMethodConflicts;
251261

252262
/// List of attributes added by access notes, used to emit remarks for valid
253263
/// ones.
@@ -636,4 +646,30 @@ inline void simple_display(llvm::raw_ostream &out, const SourceFile *SF) {
636646
}
637647
} // end namespace swift
638648

649+
namespace llvm {
650+
651+
template<>
652+
struct DenseMapInfo<swift::SourceFile::ObjCMethodConflict> {
653+
using ObjCMethodConflict = swift::SourceFile::ObjCMethodConflict;
654+
655+
static inline ObjCMethodConflict getEmptyKey() {
656+
return ObjCMethodConflict(nullptr, {}, false);
657+
}
658+
static inline ObjCMethodConflict getTombstoneKey() {
659+
return ObjCMethodConflict(nullptr, {}, true);
660+
}
661+
static inline unsigned getHashValue(ObjCMethodConflict a) {
662+
return hash_combine(hash_value(a.typeDecl),
663+
DenseMapInfo<swift::ObjCSelector>::getHashValue(a.selector),
664+
hash_value(a.isInstanceMethod));
665+
}
666+
static bool isEqual(ObjCMethodConflict a, ObjCMethodConflict b) {
667+
return a.typeDecl == b.typeDecl && a.selector == b.selector &&
668+
a.isInstanceMethod == b.isInstanceMethod;
669+
}
670+
};
671+
672+
}
673+
674+
639675
#endif

0 commit comments

Comments
 (0)