Skip to content

Commit d906ecd

Browse files
Merge pull request #4628 from swiftwasm/katei/merge-main-2022-06-06
Merge main 2022-06-06
2 parents b844711 + 0753ee4 commit d906ecd

File tree

237 files changed

+8344
-1960
lines changed

Some content is hidden

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

237 files changed

+8344
-1960
lines changed

CHANGELOG.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
112112

113113
* [SE-0346][]:
114114

115-
Protocols can now declare a list of one or more primary associated types:
115+
Protocols can now declare a list of one or more _primary associated types_, which enable writing same-type requirements on those associated types using angle bracket syntax:
116116

117117
```swift
118118
protocol Graph<Vertex, Edge> {
@@ -121,31 +121,30 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
121121
}
122122
```
123123

124-
A protocol-constrained type like `Graph<Int>` can now be written anywhere that
125-
expects the right-hand side of a protocol conformance requirement:
124+
You can now write a protocol name followed by type arguments in angle brackets, like
125+
`Graph<Int, String>`, anywhere that a protocol conformance requirement may appear:
126126

127127
```swift
128-
func shortestPath<V, E>(_: some Graph<V>, from: V, to: V) -> [E]
128+
func shortestPath<V, E>(_: some Graph<V, E>, from: V, to: V) -> [E]
129129

130-
extension Graph<Int> {...}
130+
extension Graph<Int, String> {...}
131131

132-
func build() -> some Graph<String> {}
132+
func build() -> some Graph<Int, String> {}
133133
```
134134

135-
A protocol-constrained type is equivalent to a conformance requirement to the protocol
136-
itself together with a same-type requirement constraining the primary associated type.
135+
A protocol name followed by angle brackets is shorthand for a conformance requirement,
136+
together with a same-type requirement for the protocol's primary associated types.
137137
The first two examples above are equivalent to the following:
138138

139139
```swift
140140
func shortestPath<V, E, G>(_: G, from: V, to: V) -> [E]
141-
where G: Graph, G.Vertex == V, G.Edge == V
141+
where G: Graph, G.Vertex == V, G.Edge == E
142142

143-
extension Graph where Vertex == Int {...}
143+
extension Graph where Vertex == Int, Edge == String {...}
144144
```
145145

146-
The `build()` function returning `some Graph<String>` cannot be written using a `where`
147-
clause; this is an example of a constrained opaque result type, which could not be written
148-
before.
146+
The `build()` function returning `some Graph<Int, String>` can't be written using a
147+
`where` clause; this is an example of a constrained opaque result type, which is new expressivity in Swift 5.7.
149148

150149
* [SE-0353][]:
151150

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
set(SWIFT_HOST_VARIANT_SDK ANDROID CACHE STRING "")
3+
set(SWIFT_HOST_VARIANT_ARCH aarch64 CACHE STRING "")
4+
5+
# NOTE(compnerd) disable the tools, we are trying to build just the standard
6+
# library.
7+
set(SWIFT_INCLUDE_TOOLS NO CACHE BOOL "")
8+
9+
# NOTE(compnerd) cannot build tests since the tests require the toolchain
10+
set(SWIFT_INCLUDE_TESTS NO CACHE BOOL "")
11+
12+
# NOTE(compnerd) cannot build docs since that requires perl
13+
set(SWIFT_INCLUDE_DOCS NO CACHE BOOL "")
14+
15+
# NOTE(compnerd) these are part of the toolchain, not the runtime.
16+
set(SWIFT_BUILD_SYNTAXPARSERLIB NO CACHE BOOL "")
17+
set(SWIFT_BUILD_SOURCEKIT NO CACHE BOOL "")
18+
19+
# NOTE(compnerd) build with the compiler specified, not a just built compiler.
20+
set(SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER YES CACHE BOOL "")
21+
22+
set(SWIFT_SDK_ANDROID_ARCHITECTURES aarch64 CACHE STRING "")
23+
24+
# NOTE(compnerd) this is lollipop, which seems to still have decent usage.
25+
set(SWIFT_ANDROID_API_LEVEL 21 CACHE STRING "")
26+
# NOTE(compnerd) this matches the value from the NDK r24.
27+
set(SWIFT_ANDROID_NDK_CLANG_VERSION 14.0.1 CACHE STRING "" FORCE)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
set(SWIFT_HOST_VARIANT_SDK ANDROID CACHE STRING "")
3+
set(SWIFT_HOST_VARIANT_ARCH armv7 CACHE STRING "")
4+
5+
# NOTE(compnerd) disable the tools, we are trying to build just the standard
6+
# library.
7+
set(SWIFT_INCLUDE_TOOLS NO CACHE BOOL "")
8+
9+
# NOTE(compnerd) cannot build tests since the tests require the toolchain
10+
set(SWIFT_INCLUDE_TESTS NO CACHE BOOL "")
11+
12+
# NOTE(compnerd) cannot build docs since that requires perl
13+
set(SWIFT_INCLUDE_DOCS NO CACHE BOOL "")
14+
15+
# NOTE(compnerd) these are part of the toolchain, not the runtime.
16+
set(SWIFT_BUILD_SYNTAXPARSERLIB NO CACHE BOOL "")
17+
set(SWIFT_BUILD_SOURCEKIT NO CACHE BOOL "")
18+
19+
# NOTE(compnerd) build with the compiler specified, not a just built compiler.
20+
set(SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER YES CACHE BOOL "")
21+
22+
set(SWIFT_SDK_ANDROID_ARCHITECTURES armv7 CACHE STRING "")
23+
24+
# NOTE(compnerd) this is lollipop, which seems to still have decent usage.
25+
set(SWIFT_ANDROID_API_LEVEL 21 CACHE STRING "")
26+
# NOTE(compnerd) this matches the value from the NDK r24.
27+
set(SWIFT_ANDROID_NDK_CLANG_VERSION 14.0.1 CACHE STRING "" FORCE)
28+

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ TYPE_ATTR(yields)
8585
TYPE_ATTR(yield_once)
8686
TYPE_ATTR(yield_many)
8787
TYPE_ATTR(captures_generics)
88+
// Used at the SIL level to mark a type as moveOnly.
89+
TYPE_ATTR(moveOnly)
8890

8991
// SIL metatype attributes.
9092
TYPE_ATTR(thin)

include/swift/AST/Attr.h

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,8 @@ class SPIAccessControlAttr final : public DeclAttribute,
11561156
SourceRange range,
11571157
ArrayRef<Identifier> spiGroups);
11581158

1159+
SPIAccessControlAttr *clone(ASTContext &C, bool implicit) const;
1160+
11591161
/// Name of SPIs declared by the attribute.
11601162
///
11611163
/// Note: A single SPI name per attribute is currently supported but this
@@ -1269,6 +1271,13 @@ class EffectsAttr : public DeclAttribute {
12691271
static bool classof(const DeclAttribute *DA) {
12701272
return DA->getKind() == DAK_Effects;
12711273
}
1274+
1275+
EffectsAttr *clone(ASTContext &ctx) const {
1276+
if (getKind() == EffectsKind::Custom) {
1277+
return new (ctx) EffectsAttr(customString);
1278+
}
1279+
return new (ctx) EffectsAttr(getKind());
1280+
}
12721281
};
12731282

12741283

@@ -1712,12 +1721,15 @@ class ProjectedValuePropertyAttr : public DeclAttribute {
17121721
}
17131722
};
17141723

1715-
/// Describe a symbol was originally defined in another module. For example, given
1724+
/// Describes a symbol that was originally defined in another module. For
1725+
/// example, given the following declaration:
1726+
///
17161727
/// \code
17171728
/// @_originallyDefinedIn(module: "Original", OSX 10.15) var foo: Int
17181729
/// \endcode
17191730
///
1720-
/// Where variable Foo has originally defined in another module called Original prior to OSX 10.15
1731+
/// The variable \p foo was originally defined in another module called
1732+
/// \p Original prior to OSX 10.15
17211733
class OriginallyDefinedInAttr: public DeclAttribute {
17221734
public:
17231735
OriginallyDefinedInAttr(SourceLoc AtLoc, SourceRange Range,
@@ -1730,6 +1742,8 @@ class OriginallyDefinedInAttr: public DeclAttribute {
17301742
Platform(Platform),
17311743
MovedVersion(MovedVersion) {}
17321744

1745+
OriginallyDefinedInAttr *clone(ASTContext &C, bool implicit) const;
1746+
17331747
// The original module name.
17341748
const StringRef OriginalModuleName;
17351749

@@ -2303,6 +2317,13 @@ class DeclAttributes {
23032317
DeclAttrs = Attr;
23042318
}
23052319

2320+
/// Add multiple constructed DeclAttributes to this list.
2321+
void add(DeclAttributes &Attrs) {
2322+
for (auto attr : Attrs) {
2323+
add(attr);
2324+
}
2325+
}
2326+
23062327
// Iterator interface over DeclAttribute objects.
23072328
class iterator : public iterator_base<DeclAttribute, iterator> {
23082329
public:

include/swift/AST/DiagnosticsModuleDiffer.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ ERROR(type_witness_change,APIDigesterBreakage,"%0 has type witness type for %1 c
7676

7777
ERROR(decl_new_witness_table_entry,APIDigesterBreakage,"%0 now requires%select{| no}1 new witness table entry", (StringRef, bool))
7878

79+
ERROR(class_member_moved_to_extension,APIDigesterBreakage,"Non-final class member %0 is moved to extension", (StringRef))
80+
7981
WARNING(new_decl_without_intro,APIDigesterBreakage,"%0 is a new API without @available attribute", (StringRef))
8082

8183
ERROR(objc_name_change,APIDigesterBreakage,"%0 has ObjC name change from %1 to %2", (StringRef, StringRef, StringRef))

include/swift/AST/DiagnosticsParse.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,6 +1353,11 @@ ERROR(expected_type_after_as,none,
13531353
ERROR(string_interpolation_extra,none,
13541354
"extra tokens after interpolated string expression", ())
13551355

1356+
// String interpolation isnt closed by a )
1357+
// ie: `let west = "ye \("`
1358+
ERROR(string_interpolation_unclosed, none,
1359+
"cannot find ')' to match opening '(' in string interpolation", ())
1360+
13561361
// Interpolations with parameter labels or multiple values
13571362
WARNING(string_interpolation_list_changing,none,
13581363
"interpolating multiple values will not form a tuple in Swift 5", ())

include/swift/AST/DiagnosticsSema.def

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,8 @@ ERROR(cannot_find_in_scope,none,
905905
ERROR(cannot_find_in_scope_corrected,none,
906906
"cannot %select{find|find operator}1 %0 in scope; did you mean '%2'?",
907907
(DeclNameRef, bool, StringRef))
908+
ERROR(cannot_find_self_in_scope,none,
909+
"cannot find 'self' in scope; did you mean to use it in a type or extension context?", ())
908910
NOTE(confusable_character,none,
909911
"%select{identifier|operator}0 '%1' contains possibly confused characters; "
910912
"did you mean to use '%2'?",
@@ -1406,8 +1408,6 @@ ERROR(transparent_in_protocols_not_supported,none,
14061408
ERROR(transparent_in_classes_not_supported,none,
14071409
"'@_transparent' attribute is not supported on declarations within classes", ())
14081410

1409-
ERROR(invalid_iboutlet,none,
1410-
"only instance properties can be declared @IBOutlet", ())
14111411
ERROR(iboutlet_nonobjc_class,none,
14121412
"@IBOutlet property cannot %select{have|be an array of}0 "
14131413
"non-'@objc' class type %1", (bool, Type))
@@ -1429,8 +1429,8 @@ NOTE(note_make_implicitly_unwrapped_optional,none,
14291429
ERROR(invalid_ibdesignable_extension,none,
14301430
"@IBDesignable can only be applied to classes and extensions "
14311431
"of classes", ())
1432-
ERROR(invalid_ibinspectable,none,
1433-
"only instance properties can be declared @%0", (StringRef))
1432+
ERROR(attr_must_be_used_on_class_instance,none,
1433+
"only class instance properties can be declared @%0", (StringRef))
14341434
ERROR(invalid_ibaction_decl,none,
14351435
"only instance methods can be declared @%0", (StringRef))
14361436
ERROR(invalid_ibaction_result,none,
@@ -3748,8 +3748,6 @@ ERROR(protocol_declares_unknown_primary_assoc_type,none,
37483748
(Identifier, Type))
37493749
ERROR(protocol_declares_duplicate_primary_assoc_type,none,
37503750
"duplicate primary associated type name %0", (Identifier))
3751-
ERROR(parameterized_protocol_not_supported,none,
3752-
"protocol type with type arguments can only be used as a generic constraint", ())
37533751
ERROR(protocol_does_not_have_primary_assoc_type,none,
37543752
"cannot specialize protocol type %0", (Type))
37553753
ERROR(parameterized_protocol_type_argument_count_mismatch,none,
@@ -5490,6 +5488,9 @@ NOTE(type_eraser_init_not_accessible,none,
54905488
"cannot have more restrictive access than protocol %1 "
54915489
"(which is %select{private|fileprivate|internal|public|open}2)",
54925490
(AccessLevel, Type, AccessLevel))
5491+
NOTE(type_eraser_init_spi,none,
5492+
"'init(erasing:)' is SPI, but protocol %0 is not"
5493+
"%select{| in the same SPI groups as 'init(erasing:)'}1", (Type, bool))
54935494

54945495
//------------------------------------------------------------------------------
54955496
// MARK: @available

0 commit comments

Comments
 (0)