Skip to content

Commit a034333

Browse files
Merge pull request #4651 from swiftwasm/maxd/5.7-merge
2 parents b1ea1ae + 977abeb commit a034333

File tree

445 files changed

+36264
-3811
lines changed

Some content is hidden

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

445 files changed

+36264
-3811
lines changed

CHANGELOG.md

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,33 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
9090
}
9191
```
9292

93-
* References to `optional` methods on a protocol metatype, as well as references to dynamically looked up methods on the `AnyObject` metatype are now supported. These references always have the type of a function that accepts a single argument and returns an optional value of function type:
93+
* References to `optional` methods on a protocol metatype, as well as references to dynamically looked up methods on `AnyObject` are now supported on par with other function references. The type of such a reference (formerly an immediate optional by mistake) has been altered to that of a function that takes a single argument and returns an optional value of function type:
9494

9595
```swift
9696
class Object {
97-
@objc func getTag() -> Int
97+
@objc func getTag() -> Int { ... }
9898
}
9999

100-
@objc protocol P {
100+
let getTag: (AnyObject) -> (() -> Int)? = AnyObject.getTag
101+
102+
@objc protocol Delegate {
101103
@objc optional func didUpdateObject(withTag tag: Int)
102104
}
103105

104-
let getTag: (AnyObject) -> (() -> Int)? = AnyObject.getTag
105-
106-
let didUpdateObject: (any P) -> ((Int) -> Void)? = P.didUpdateObject
106+
let didUpdateObjectWithTag: (Delegate) -> ((Int) -> Void)? = Delegate.didUpdateObject
107107
```
108108

109+
> **Warning**
110+
> Due to the type change, selectors for aforementioned method references that require writing out their type explicitly for disambiguation will no longer compile. To fix this, simply adjust the written type, or resort to a `#if swift(<5.7)` directive when compatibility with older compiler versions is warranted. For example:
111+
>
112+
> ```swift
113+
> #if swift(<5.7)
114+
> let decidePolicyForNavigationAction = #selector(WKNavigationDelegate.webView(_:decidePolicyFor:decisionHandler:) as ((WKNavigationDelegate) -> (WKWebView, WKNavigationAction, @escaping (WKNavigationActionPolicy) -> Void) -> Void)?)
115+
> #else
116+
> let decidePolicyForNavigationAction = #selector(WKNavigationDelegate.webView(_:decidePolicyFor:decisionHandler:) as (WKNavigationDelegate) -> ((WKWebView, WKNavigationAction, @escaping (WKNavigationActionPolicy) -> Void) -> Void)?)
117+
> #endif
118+
> ```
119+
109120
* [SE-0349][]:
110121
111122
Loading data from raw memory represented by `UnsafeRawPointer`,
@@ -390,6 +401,18 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
390401
the result type provides a generalization where the callee chooses the
391402
resulting type and value.
392403

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+
393416
* 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.
394417

395418
```swift

include/swift-c/SyntaxParser/SwiftSyntaxParser.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ swiftparse_parser_create(void);
9393
SWIFTPARSE_PUBLIC void
9494
swiftparse_parser_dispose(swiftparse_parser_t);
9595

96+
/// Set the language version that should be used to parse the Swift source file.
97+
SWIFTPARSE_PUBLIC void
98+
swiftparse_parser_set_language_version(swiftparse_parser_t c_parser,
99+
const char *version);
100+
101+
/// Set whether bare slash regex literals are enabled.
102+
SWIFTPARSE_PUBLIC void swiftparse_parser_set_enable_bare_slash_regex_literal(
103+
swiftparse_parser_t c_parser, bool enabled);
104+
96105
/// Invoked by the parser when a syntax node is parsed. The client should
97106
/// return a pointer to associate with that particular node.
98107
typedef swiftparse_client_node_t

include/swift/ABI/Metadata.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2839,6 +2839,9 @@ struct TargetAnonymousContextDescriptor final
28392839
};
28402840
using AnonymousContextDescriptor = TargetAnonymousContextDescriptor<InProcess>;
28412841

2842+
template<template <typename Runtime> class ObjCInteropKind, unsigned PointerSize>
2843+
using ExternalAnonymousContextDescriptor = TargetAnonymousContextDescriptor<External<ObjCInteropKind<RuntimeTarget<PointerSize>>>>;
2844+
28422845
/// A protocol descriptor.
28432846
///
28442847
/// Protocol descriptors contain information about the contents of a protocol:

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/APIDigester/ModuleAnalyzerNodes.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ namespace api {
6363
///
6464
/// When the json format changes in a way that requires version-specific handling, this number should be incremented.
6565
/// This ensures we could have backward compatibility so that version changes in the format won't stop the checker from working.
66-
const uint8_t DIGESTER_JSON_VERSION = 7; // push SDKNodeRoot to lower-level
66+
const uint8_t DIGESTER_JSON_VERSION = 8; // add isFromExtension
6767
const uint8_t DIGESTER_JSON_DEFAULT_VERSION = 0; // Use this version number for files before we have a version number in json.
6868
const StringRef ABIRootKey = "ABIRoot";
6969
const StringRef ConstValuesKey = "ConstValues";
@@ -161,6 +161,7 @@ struct CheckerOptions {
161161
bool Migrator;
162162
StringRef LocationFilter;
163163
std::vector<std::string> ToolArgs;
164+
llvm::StringSet<> SPIGroupNamesToIgnore;
164165
};
165166

166167
class SDKContext {
@@ -346,6 +347,7 @@ class SDKNodeDecl: public SDKNode {
346347
StringRef Location;
347348
StringRef ModuleName;
348349
std::vector<DeclAttrKind> DeclAttributes;
350+
std::vector<StringRef> SPIGroups;
349351
bool IsImplicit;
350352
bool IsStatic;
351353
bool IsDeprecated;
@@ -354,6 +356,7 @@ class SDKNodeDecl: public SDKNode {
354356
bool IsOpen;
355357
bool IsInternal;
356358
bool IsABIPlaceholder;
359+
bool IsFromExtension;
357360
uint8_t ReferenceOwnership;
358361
StringRef GenericSig;
359362
// In ABI mode, this field is populated as a user-friendly version of GenericSig.
@@ -372,6 +375,7 @@ class SDKNodeDecl: public SDKNode {
372375
StringRef getModuleName() const {return ModuleName;}
373376
StringRef getHeaderName() const;
374377
ArrayRef<DeclAttrKind> getDeclAttributes() const;
378+
ArrayRef<StringRef> getSPIGroups() const { return SPIGroups; }
375379
bool hasAttributeChange(const SDKNodeDecl &Another) const;
376380
swift::ReferenceOwnership getReferenceOwnership() const {
377381
return swift::ReferenceOwnership(ReferenceOwnership);
@@ -392,6 +396,7 @@ class SDKNodeDecl: public SDKNode {
392396
bool isOpen() const { return IsOpen; }
393397
bool isInternal() const { return IsInternal; }
394398
bool isABIPlaceholder() const { return IsABIPlaceholder; }
399+
bool isFromExtension() const { return IsFromExtension; }
395400
StringRef getGenericSignature() const { return GenericSig; }
396401
StringRef getSugaredGenericSignature() const { return SugaredGenericSig; }
397402
StringRef getScreenInfo() const;
@@ -413,6 +418,12 @@ class SDKNodeDecl: public SDKNode {
413418
if (isObjc())
414419
return;
415420
}
421+
// Don't emit SPIs if the group name is out-out.
422+
for (auto spi: getSPIGroups()) {
423+
if (Ctx.getOpts().SPIGroupNamesToIgnore.contains(spi)) {
424+
return;
425+
}
426+
}
416427
Ctx.getDiags(Loc).diagnose(Loc, ID, getScreenInfo(), std::move(Args)...);
417428
}
418429
};
@@ -710,6 +721,7 @@ class SDKNodeDeclConstructor: public SDKNodeDeclAbstractFunc {
710721
void jsonize(json::Output &Out) override;
711722
};
712723

724+
// Note: Accessor doesn't have Parent pointer.
713725
class SDKNodeDeclAccessor: public SDKNodeDeclAbstractFunc {
714726
SDKNodeDecl *Owner;
715727
AccessorKind AccKind;
@@ -828,6 +840,8 @@ int findDeclUsr(StringRef dumpPath, CheckerOptions Opts);
828840

829841
void nodeSetDifference(ArrayRef<SDKNode*> Left, ArrayRef<SDKNode*> Right,
830842
NodeVector &LeftMinusRight, NodeVector &RightMinusLeft);
843+
844+
bool hasValidParentPtr(SDKNodeKind kind);
831845
} // end of abi namespace
832846
} // end of ide namespace
833847
} // end of Swift namespace

include/swift/AST/ASTContext.h

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,13 @@ class ASTContext final {
223223
ASTContext(const ASTContext&) = delete;
224224
void operator=(const ASTContext&) = delete;
225225

226-
ASTContext(LangOptions &langOpts, TypeCheckerOptions &typeckOpts,
227-
SILOptions &silOpts, SearchPathOptions &SearchPathOpts,
228-
ClangImporterOptions &ClangImporterOpts,
229-
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts,
230-
SourceManager &SourceMgr, DiagnosticEngine &Diags);
226+
ASTContext(
227+
LangOptions &langOpts, TypeCheckerOptions &typeckOpts,
228+
SILOptions &silOpts, SearchPathOptions &SearchPathOpts,
229+
ClangImporterOptions &ClangImporterOpts,
230+
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts,
231+
SourceManager &SourceMgr, DiagnosticEngine &Diags,
232+
std::function<bool(llvm::StringRef, bool)> PreModuleImportCallback = {});
231233

232234
public:
233235
// Members that should only be used by ASTContext.cpp.
@@ -238,11 +240,13 @@ class ASTContext final {
238240

239241
void operator delete(void *Data) throw();
240242

241-
static ASTContext *get(LangOptions &langOpts, TypeCheckerOptions &typeckOpts,
242-
SILOptions &silOpts, SearchPathOptions &SearchPathOpts,
243-
ClangImporterOptions &ClangImporterOpts,
244-
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts,
245-
SourceManager &SourceMgr, DiagnosticEngine &Diags);
243+
static ASTContext *
244+
get(LangOptions &langOpts, TypeCheckerOptions &typeckOpts,
245+
SILOptions &silOpts, SearchPathOptions &SearchPathOpts,
246+
ClangImporterOptions &ClangImporterOpts,
247+
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts,
248+
SourceManager &SourceMgr, DiagnosticEngine &Diags,
249+
std::function<bool(llvm::StringRef, bool)> PreModuleImportCallback = {});
246250
~ASTContext();
247251

248252
/// Optional table of counters to report, nullptr when not collecting.
@@ -374,6 +378,10 @@ class ASTContext final {
374378
llvm::BumpPtrAllocator &
375379
getAllocator(AllocationArena arena = AllocationArena::Permanent) const;
376380

381+
/// An optional generic callback function invoked prior to importing a module.
382+
mutable std::function<bool(llvm::StringRef ModuleName, bool IsOverlay)>
383+
PreModuleImportCallback;
384+
377385
public:
378386
/// Allocate - Allocate memory from the ASTContext bump pointer.
379387
void *Allocate(unsigned long bytes, unsigned alignment,
@@ -529,7 +537,7 @@ class ASTContext final {
529537
/// Retrieve the declaration of Swift.Error.
530538
ProtocolDecl *getErrorDecl() const;
531539
CanType getErrorExistentialType() const;
532-
540+
533541
#define KNOWN_STDLIB_TYPE_DECL(NAME, DECL_CLASS, NUM_GENERIC_PARAMS) \
534542
/** Retrieve the declaration of Swift.NAME. */ \
535543
DECL_CLASS *get##NAME##Decl() const; \
@@ -553,7 +561,13 @@ class ASTContext final {
553561
/// Retrieve the declaration of the "pointee" property of a pointer type.
554562
VarDecl *getPointerPointeePropertyDecl(PointerTypeKind ptrKind) const;
555563

556-
/// 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.
557571
CanType getAnyObjectType() const;
558572

559573
#define KNOWN_SDK_TYPE_DECL(MODULE, NAME, DECL_CLASS, NUM_GENERIC_PARAMS) \
@@ -1107,6 +1121,9 @@ class ASTContext final {
11071121
/// If a module by this name has already been loaded, the existing module will
11081122
/// be returned.
11091123
///
1124+
/// \param ModulePath The module's \c ImportPath which describes
1125+
/// the name of the module being loaded, possibly including submodules.
1126+
11101127
/// \returns The requested module, or NULL if the module cannot be found.
11111128
ModuleDecl *getModule(ImportPath::Module ModulePath);
11121129

include/swift/AST/ASTMangler.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ASTMangler : public Mangler {
4343

4444
/// If enabled, non-canonical types are allowed and type alias types get a
4545
/// special mangling.
46-
bool DWARFMangling;
46+
bool DWARFMangling = false;
4747

4848
/// If enabled, entities that ought to have names but don't get a placeholder.
4949
///
@@ -72,6 +72,12 @@ class ASTMangler : public Mangler {
7272
/// function types.
7373
bool Preconcurrency = false;
7474

75+
/// If enabled, declarations annotated with @_originallyDefinedIn are mangled
76+
/// as if they're part of their original module. Disabled for debug mangling,
77+
/// because lldb wants to find declarations in the modules they're currently
78+
/// defined in.
79+
bool RespectOriginallyDefinedIn = true;
80+
7581
public:
7682
using SymbolicReferent = llvm::PointerUnion<const NominalTypeDecl *,
7783
const OpaqueTypeDecl *>;
@@ -110,8 +116,13 @@ class ASTMangler : public Mangler {
110116
BackDeploymentFallback,
111117
};
112118

113-
ASTMangler(bool DWARFMangling = false)
114-
: DWARFMangling(DWARFMangling) {}
119+
/// lldb overrides the defaulted argument to 'true'.
120+
ASTMangler(bool DWARFMangling = false) {
121+
if (DWARFMangling) {
122+
DWARFMangling = true;
123+
RespectOriginallyDefinedIn = false;
124+
}
125+
}
115126

116127
void addTypeSubstitution(Type type, GenericSignature sig) {
117128
type = dropProtocolsFromAssociatedTypes(type, sig);
@@ -286,7 +297,8 @@ class ASTMangler : public Mangler {
286297

287298
std::string mangleTypeAsContextUSR(const NominalTypeDecl *type);
288299

289-
std::string mangleAnyDecl(const ValueDecl *Decl, bool prefix);
300+
std::string mangleAnyDecl(const ValueDecl *Decl, bool prefix,
301+
bool respectOriginallyDefinedIn = false);
290302
std::string mangleDeclAsUSR(const ValueDecl *Decl, StringRef USRPrefix);
291303

292304
std::string mangleAccessorEntityAsUSR(AccessorKind kind,

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/Attr.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ SIMPLE_DECL_ATTR(objcMembers, ObjCMembers,
267267
34)
268268
CONTEXTUAL_SIMPLE_DECL_ATTR(_compilerInitialized, CompilerInitialized,
269269
OnVar |
270+
UserInaccessible |
270271
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
271272
35)
272273
CONTEXTUAL_SIMPLE_DECL_ATTR(__consuming, Consuming,
@@ -726,6 +727,7 @@ DECL_ATTR(_backDeploy, BackDeploy,
726727

727728
CONTEXTUAL_SIMPLE_DECL_ATTR(_local, KnownToBeLocal,
728729
DeclModifier | OnFunc | OnParam | OnVar |
730+
UserInaccessible |
729731
ABIBreakingToAdd | ABIBreakingToRemove |
730732
APIBreakingToAdd | APIBreakingToRemove,
731733
130)

include/swift/AST/Availability.h

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,18 @@ class VersionRange {
9393
return getLowerEndpoint() >= Other.getLowerEndpoint();
9494
}
9595

96+
// Returns true if all the versions in the Other range are versions in this
97+
// range and the ranges are not equal.
98+
bool isSupersetOf(const VersionRange &Other) const {
99+
if (isEmpty() || Other.isAll())
100+
return false;
101+
102+
if (isAll() || Other.isEmpty())
103+
return true;
104+
105+
return getLowerEndpoint() < Other.getLowerEndpoint();
106+
}
107+
96108
/// Mutates this range to be a best-effort underapproximation of
97109
/// the intersection of itself and Other. This is the
98110
/// meet operation (greatest lower bound) in the version range lattice.
@@ -244,10 +256,17 @@ class AvailabilityContext {
244256
/// Returns true if \p other makes stronger guarantees than this context.
245257
///
246258
/// That is, `a.isContainedIn(b)` implies `a.union(b) == b`.
247-
bool isContainedIn(AvailabilityContext other) const {
259+
bool isContainedIn(const AvailabilityContext &other) const {
248260
return OSVersion.isContainedIn(other.OSVersion);
249261
}
250262

263+
/// Returns true if \p other is a strict subset of this context.
264+
///
265+
/// That is, `a.isSupersetOf(b)` implies `a != b` and `a.union(b) == a`.
266+
bool isSupersetOf(const AvailabilityContext &other) const {
267+
return OSVersion.isSupersetOf(other.OSVersion);
268+
}
269+
251270
/// Returns true if this context has constraints that make it impossible to
252271
/// actually occur.
253272
///
@@ -272,7 +291,7 @@ class AvailabilityContext {
272291
///
273292
/// As an example, this is used when figuring out the required availability
274293
/// for a type that references multiple nominal decls.
275-
void intersectWith(AvailabilityContext other) {
294+
void intersectWith(const AvailabilityContext &other) {
276295
OSVersion.intersectWith(other.getOSVersion());
277296
}
278297

@@ -283,7 +302,7 @@ class AvailabilityContext {
283302
/// treating some invalid deployment environments as available.
284303
///
285304
/// As an example, this is used for the true branch of `#available`.
286-
void constrainWith(AvailabilityContext other) {
305+
void constrainWith(const AvailabilityContext &other) {
287306
OSVersion.constrainWith(other.getOSVersion());
288307
}
289308

@@ -295,7 +314,7 @@ class AvailabilityContext {
295314
///
296315
/// As an example, this is used for the else branch of a conditional with
297316
/// multiple `#available` checks.
298-
void unionWith(AvailabilityContext other) {
317+
void unionWith(const AvailabilityContext &other) {
299318
OSVersion.unionWith(other.getOSVersion());
300319
}
301320

0 commit comments

Comments
 (0)