Skip to content

Commit e2d2412

Browse files
authored
Merge pull request #4190 from swiftwasm/main
2 parents 0d66537 + 8c9f0f5 commit e2d2412

File tree

273 files changed

+9362
-3788
lines changed

Some content is hidden

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

273 files changed

+9362
-3788
lines changed

CHANGELOG.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,29 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
55

66
## Swift 5.7
77

8+
* 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.
9+
10+
```swift
11+
struct Pancake {}
12+
protocol Food {}
13+
14+
extension Food {
15+
var isGlutenFree: Bool { false }
16+
}
17+
18+
@available(macOS 12.0, *)
19+
extension Pancake: Food {}
20+
21+
@available(macOS 11.0, *)
22+
func eatPancake(_ pancake: Pancake) {
23+
if (pancake.isGlutenFree) { // warning: conformance of 'Pancake' to 'Food' is only available in macOS 12.0 or newer
24+
eatFood(pancake) // warning: conformance of 'Pancake' to 'Food' is only available in macOS 12.0 or newer
25+
}
26+
}
27+
28+
func eatFood(_ food: Food) {}
29+
```
30+
831
* [SE-0328][]:
932

1033
Opaque types (expressed with 'some') can now be used in structural positions
@@ -19,6 +42,27 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
1942
Swift 5.6
2043
---------
2144

45+
* [SE-0327][]:
46+
47+
In Swift 5 mode, a warning is now emitted if the default-value expression of an
48+
instance-member property requires global-actor isolation. For example:
49+
50+
```swift
51+
@MainActor
52+
func partyGenerator() -> [PartyMember] { fatalError("todo") }
53+
54+
class Party {
55+
@MainActor var members: [PartyMember] = partyGenerator()
56+
// ^~~~~~~~~~~~~~~~
57+
// warning: expression requiring global actor 'MainActor' cannot
58+
// appear in default-value expression of property 'members'
59+
}
60+
```
61+
62+
Previously, the isolation granted by the type checker matched the isolation of
63+
the property itself, but at runtime that is not guaranteed. In Swift 6,
64+
such default-value expressions will become an error if they require isolation.
65+
2266
* Actor isolation checking now understands that `defer` bodies share the isolation of their enclosing function.
2367

2468
```swift
@@ -8913,6 +8957,7 @@ Swift 1.0
89138957
[SE-0322]: <https://github.com/apple/swift-evolution/blob/main/proposals/0322-temporary-buffers.md>
89148958
[SE-0324]: <https://github.com/apple/swift-evolution/blob/main/proposals/0324-c-lang-pointer-arg-conversion.md>
89158959
[SE-0323]: <https://github.com/apple/swift-evolution/blob/main/proposals/0323-async-main-semantics.md>
8960+
[SE-0327]: <https://github.com/apple/swift-evolution/blob/main/proposals/0327-actor-initializers.md>
89168961
[SE-0328]: <https://github.com/apple/swift-evolution/blob/main/proposals/0328-structural-opaque-result-types.md>
89178962
[SE-0331]: <https://github.com/apple/swift-evolution/blob/main/proposals/0331-remove-sendable-from-unsafepointer.md>
89188963
[SE-0337]: <https://github.com/apple/swift-evolution/blob/main/proposals/0337-support-incremental-migration-to-concurrency-checking.md>

cmake/modules/AddSwift.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ function(_add_host_variant_c_compile_link_flags name)
162162
# side effects are introduced should a new search path be added.
163163
target_compile_options(${name} PRIVATE
164164
$<$<COMPILE_LANGUAGE:C,CXX,OBJC,OBJCXX>:
165-
-arch ${SWIFT_HOST_VARIANT_ARCH}
166165
"-F${SWIFT_SDK_${SWIFT_HOST_VARIANT_ARCH}_PATH}/../../../Developer/Library/Frameworks"
167166
>)
167+
set_property(TARGET ${name} PROPERTY OSX_ARCHITECTURES "${SWIFT_HOST_VARIANT_ARCH}")
168168
endif()
169169

170170
_compute_lto_flag("${SWIFT_TOOLS_ENABLE_LTO}" _lto_flag_out)

docs/ABI/Mangling.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,7 @@ Some kinds need arguments, which precede ``Tf``.
11391139
CONST-PROP ::= 'i' NATURAL_ZERO // 64-bit-integer
11401140
CONST-PROP ::= 'd' NATURAL_ZERO // float-as-64-bit-integer
11411141
CONST-PROP ::= 's' ENCODING // string literal. Consumes one identifier argument.
1142+
CONST-PROP ::= 'k' // keypath. Consumes one identifier - the SHA1 of the keypath and two types (root and value).
11421143

11431144
ENCODING ::= 'b' // utf8
11441145
ENCODING ::= 'w' // utf16

include/swift/ABI/Metadata.h

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,9 @@ namespace {
540540

541541
using TypeContextDescriptor = TargetTypeContextDescriptor<InProcess>;
542542

543+
template<template <typename Runtime> class ObjCInteropKind, unsigned PointerSize>
544+
using ExternalTypeContextDescriptor = TargetTypeContextDescriptor<External<ObjCInteropKind<RuntimeTarget<PointerSize>>>>;
545+
543546
// FIXME: https://bugs.swift.org/browse/SR-1155
544547
#pragma clang diagnostic push
545548
#pragma clang diagnostic ignored "-Winvalid-offsetof"
@@ -2106,7 +2109,10 @@ using ProtocolRequirement = TargetProtocolRequirement<InProcess>;
21062109

21072110
template<typename Runtime> struct TargetProtocolDescriptor;
21082111
using ProtocolDescriptor = TargetProtocolDescriptor<InProcess>;
2109-
2112+
2113+
template<template <typename Runtime> class ObjCInteropKind, unsigned PointerSize>
2114+
using ExternalProtocolDescriptor = TargetProtocolDescriptor<External<ObjCInteropKind<RuntimeTarget<PointerSize>>>>;
2115+
21102116
/// A witness table for a protocol.
21112117
///
21122118
/// With the exception of the initial protocol conformance descriptor,
@@ -2722,6 +2728,16 @@ struct TargetProtocolConformanceDescriptor final
27222728
return TypeRef.getTypeDescriptor(getTypeKind());
27232729
}
27242730

2731+
constexpr inline auto
2732+
getTypeRefDescriptorOffset() const -> typename Runtime::StoredSize {
2733+
return offsetof(typename std::remove_reference<decltype(*this)>::type, TypeRef);
2734+
}
2735+
2736+
constexpr inline auto
2737+
getProtocolDescriptorOffset() const -> typename Runtime::StoredSize {
2738+
return offsetof(typename std::remove_reference<decltype(*this)>::type, Protocol);
2739+
}
2740+
27252741
TargetContextDescriptor<Runtime> * __ptrauth_swift_type_descriptor *
27262742
_getTypeDescriptorLocation() const {
27272743
if (getTypeKind() != TypeReferenceKind::IndirectTypeDescriptor)
@@ -2840,6 +2856,12 @@ using TargetProtocolConformanceRecord =
28402856

28412857
using ProtocolConformanceRecord = TargetProtocolConformanceRecord<InProcess>;
28422858

2859+
template<template <typename Runtime> class ObjCInteropKind, unsigned PointerSize>
2860+
using ExternalProtocolConformanceDescriptor = TargetProtocolConformanceDescriptor<External<ObjCInteropKind<RuntimeTarget<PointerSize>>>>;
2861+
2862+
template<template <typename Runtime> class ObjCInteropKind, unsigned PointerSize>
2863+
using ExternalProtocolConformanceRecord = TargetProtocolConformanceRecord<External<ObjCInteropKind<RuntimeTarget<PointerSize>>>>;
2864+
28432865
template<typename Runtime>
28442866
struct TargetGenericContext;
28452867

@@ -2876,6 +2898,11 @@ struct TargetContextDescriptor {
28762898
: 0;
28772899
}
28782900

2901+
constexpr inline auto
2902+
getParentOffset() const -> typename Runtime::StoredSize {
2903+
return offsetof(typename std::remove_reference<decltype(*this)>::type, Parent);
2904+
}
2905+
28792906
#ifndef NDEBUG
28802907
LLVM_ATTRIBUTE_DEPRECATED(void dump() const,
28812908
"only for use in the debugger");
@@ -2889,6 +2916,8 @@ struct TargetContextDescriptor {
28892916
};
28902917

28912918
using ContextDescriptor = TargetContextDescriptor<InProcess>;
2919+
template<template <typename Runtime> class ObjCInteropKind, unsigned PointerSize>
2920+
using ExternalContextDescriptor = TargetContextDescriptor<External<ObjCInteropKind<RuntimeTarget<PointerSize>>>>;
28922921

28932922
inline bool isCImportedModuleName(llvm::StringRef name) {
28942923
// This does not include MANGLING_MODULE_CLANG_IMPORTER because that's
@@ -2908,13 +2937,21 @@ struct TargetModuleContextDescriptor final : TargetContextDescriptor<Runtime> {
29082937
return isCImportedModuleName(Name.get());
29092938
}
29102939

2940+
constexpr inline auto
2941+
getNameOffset() const -> typename Runtime::StoredSize {
2942+
return offsetof(typename std::remove_reference<decltype(*this)>::type, Name);
2943+
}
2944+
29112945
static bool classof(const TargetContextDescriptor<Runtime> *cd) {
29122946
return cd->getKind() == ContextDescriptorKind::Module;
29132947
}
29142948
};
29152949

29162950
using ModuleContextDescriptor = TargetModuleContextDescriptor<InProcess>;
29172951

2952+
template<template <typename Runtime> class ObjCInteropKind, unsigned PointerSize>
2953+
using ExternalModuleContextDescriptor = TargetModuleContextDescriptor<External<ObjCInteropKind<RuntimeTarget<PointerSize>>>>;
2954+
29182955
template<typename Runtime>
29192956
inline bool TargetContextDescriptor<Runtime>::isCImportedContext() const {
29202957
return getModuleContext()->isCImportedContext();
@@ -3415,6 +3452,11 @@ struct TargetProtocolDescriptor final
34153452
NumRequirements};
34163453
}
34173454

3455+
constexpr inline auto
3456+
getNameOffset() const -> typename Runtime::StoredSize {
3457+
return offsetof(typename std::remove_reference<decltype(*this)>::type, Name);
3458+
}
3459+
34183460
/// Retrieve the requirement base descriptor address.
34193461
ConstTargetPointer<Runtime, TargetProtocolRequirement<Runtime>>
34203462
getRequirementBaseDescriptor() const {
@@ -4079,6 +4121,11 @@ class TargetTypeContextDescriptor
40794121
/// type's metadata. The returned value is measured in sizeof(StoredPointer).
40804122
int32_t getGenericArgumentOffset() const;
40814123

4124+
constexpr inline auto
4125+
getNameOffset() const -> typename Runtime::StoredSize {
4126+
return offsetof(typename std::remove_reference<decltype(*this)>::type, Name);
4127+
}
4128+
40824129
/// Return the start of the generic arguments array in the nominal
40834130
/// type's metadata. The returned value is measured in sizeof(StoredPointer).
40844131
const TargetMetadata<Runtime> * const *getGenericArguments(

include/swift/ABI/ObjectFile.h

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212

1313
namespace swift {
1414

15-
/// Represents the six reflection sections used by Swift
15+
/// Represents the eight reflection sections used by Swift
1616
enum ReflectionSectionKind : uint8_t {
1717
fieldmd,
1818
assocty,
1919
builtin,
2020
capture,
2121
typeref,
22-
reflstr
22+
reflstr,
23+
conform,
24+
protocs
2325
};
2426

2527
/// Abstract base class responsible for providing the correct reflection section
@@ -31,6 +33,8 @@ class SwiftObjectFileFormat {
3133
virtual llvm::Optional<llvm::StringRef> getSegmentName() {
3234
return {};
3335
}
36+
/// Predicate to identify if the named section can contain reflection data.
37+
virtual bool sectionContainsReflectionData(llvm::StringRef sectionName) = 0;
3438
};
3539

3640
/// Responsible for providing the Mach-O reflection section identifiers.
@@ -50,12 +54,25 @@ class SwiftObjectFileFormatMachO : public SwiftObjectFileFormat {
5054
return "__swift5_typeref";
5155
case reflstr:
5256
return "__swift5_reflstr";
57+
case conform:
58+
return "__swift5_proto";
59+
case protocs:
60+
return "__swift5_protos";
5361
}
5462
llvm_unreachable("Section type not found.");
5563
}
5664
llvm::Optional<llvm::StringRef> getSegmentName() override {
5765
return {"__TEXT"};
5866
}
67+
68+
bool sectionContainsReflectionData(llvm::StringRef sectionName) override {
69+
// For Mach-O, the caller must call this function twice, once with just the
70+
// section name (ex `__swift5_fieldmd`), and again with the segment
71+
// qualified section name (ex `__DATA,__const`).
72+
return sectionName.startswith("__swift5_") ||
73+
sectionName == "__DATA_CONST,__const" ||
74+
sectionName == "__DATA,__const";
75+
}
5976
};
6077

6178
/// Responsible for providing the ELF reflection section identifiers.
@@ -75,9 +92,17 @@ class SwiftObjectFileFormatELF : public SwiftObjectFileFormat {
7592
return "swift5_typeref";
7693
case reflstr:
7794
return "swift5_reflstr";
95+
case conform:
96+
return "swift5_protocol_conformances";
97+
case protocs:
98+
return "swift5_protocols";
7899
}
79100
llvm_unreachable("Section type not found.");
80101
}
102+
103+
bool sectionContainsReflectionData(llvm::StringRef sectionName) override {
104+
return sectionName.startswith("swift5_");
105+
}
81106
};
82107

83108
/// Responsible for providing the COFF reflection section identifiers
@@ -97,9 +122,17 @@ class SwiftObjectFileFormatCOFF : public SwiftObjectFileFormat {
97122
return ".sw5tyrf";
98123
case reflstr:
99124
return ".sw5rfst";
125+
case conform:
126+
return ".sw5prtc$B";
127+
case protocs:
128+
return ".sw5prt$B";
100129
}
101130
llvm_unreachable("Section not found.");
102131
}
132+
133+
bool sectionContainsReflectionData(llvm::StringRef sectionName) override {
134+
return sectionName.startswith(".sw5");
135+
}
103136
};
104137
} // namespace swift
105138
#endif // SWIFT_ABI_OBJECTFILE_H

include/swift/AST/ASTContext.h

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,15 @@ class ASTContext final {
679679
FuncDecl *getMakeInvocationEncoderOnDistributedActorSystem(
680680
NominalTypeDecl *actorOrSystem) const;
681681

682+
// Retrieve the declaration of
683+
// DistributedInvocationEncoder.recordGenericSubstitution(_:).
684+
//
685+
// \param nominal optionally provide a 'NominalTypeDecl' from which the
686+
// function decl shall be extracted. This is useful to avoid witness calls
687+
// through the protocol which is looked up when nominal is null.
688+
FuncDecl *getRecordGenericSubstitutionOnDistributedInvocationEncoder(
689+
NominalTypeDecl *nominal) const;
690+
682691
// Retrieve the declaration of DistributedInvocationEncoder.recordArgument(_:).
683692
//
684693
// \param nominal optionally provide a 'NominalTypeDecl' from which the
@@ -1217,9 +1226,6 @@ class ASTContext final {
12171226
InheritedProtocolConformance *
12181227
getInheritedConformance(Type type, ProtocolConformance *inherited);
12191228

1220-
/// Check if \p decl is included in LazyContexts.
1221-
bool isLazyContext(const DeclContext *decl);
1222-
12231229
/// Get the lazy data for the given declaration.
12241230
///
12251231
/// \param lazyLoader If non-null, the lazy loader to use when creating the
@@ -1345,6 +1351,20 @@ class ASTContext final {
13451351
/// alternative specified via the -entry-point-function-name frontend flag.
13461352
std::string getEntryPointFunctionName() const;
13471353

1354+
/// Find the type of SerializationRequirement on the passed nominal.
1355+
///
1356+
/// This type exists as a typealias/associatedtype on all distributed actors,
1357+
/// actor systems, and related serialization types.
1358+
Type getDistributedSerializationRequirementType(NominalTypeDecl *);
1359+
1360+
/// Find the concrete invocation decoder associated with the given actor.
1361+
NominalTypeDecl *
1362+
getDistributedActorInvocationDecoder(NominalTypeDecl *);
1363+
1364+
/// Find `decodeNextArgument<T>(type: T.Type) -> T` method associated with
1365+
/// invocation decoder of the given distributed actor.
1366+
FuncDecl *getDistributedActorArgumentDecodingMethod(NominalTypeDecl *);
1367+
13481368
private:
13491369
friend Decl;
13501370

include/swift/AST/ClangModuleLoader.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,14 @@ class ClangModuleLoader : public ModuleLoader {
182182
/// Imports a clang decl directly, rather than looking up its name.
183183
virtual Decl *importDeclDirectly(const clang::NamedDecl *decl) = 0;
184184

185-
/// Emits any import diagnostics associated with the provided decl.
186-
virtual void diagnoseDeclDirectly(const clang::NamedDecl *decl) = 0;
185+
/// Emits diagnostics for any declarations named name
186+
/// whose direct declaration context is a TU.
187+
virtual void diagnoseTopLevelValue(const DeclName &name) = 0;
188+
189+
/// Emit diagnostics for declarations named name that are members
190+
/// of the provided baseType.
191+
virtual void diagnoseMemberValue(const DeclName &name,
192+
const Type &baseType) = 0;
187193

188194
/// Instantiate and import class template using given arguments.
189195
///

0 commit comments

Comments
 (0)