Skip to content

Commit 8e10496

Browse files
Merge remote-tracking branch 'origin/main' into katei/merge-main-2022-08-19
2 parents e36b8ea + df66f27 commit 8e10496

File tree

582 files changed

+9246
-5515
lines changed

Some content is hidden

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

582 files changed

+9246
-5515
lines changed

docs/CppInteroperability/UserGuide-CallingSwiftFromC++.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ enum value will abort the program.
595595
A resilient Swift enumeration value could represent a case that's unknown to the client.
596596
Swift forces the client to check if the value is `@uknown default` when switching over
597597
the enumeration to account for that. C++ follows a similar principle,
598-
by exposing an `unknown_default` case that can then be matched in a switch.
598+
by exposing an `unknownDefault` case that can then be matched in a switch.
599599

600600
For example, given the following resilient enumeration:
601601

@@ -620,14 +620,14 @@ void test(const DateFormatStyle &style) {
620620
case DateFormatStyle::full:
621621
...
622622
break;
623-
case DateFormatStyle::unknown_default: // just like Swift's @unknown default
623+
case DateFormatStyle::unknownDefault: // just like Swift's @unknown default
624624
// Some case value added in a future version of enum.
625625
break;
626626
}
627627
}
628628
```
629629
630-
The `unknown_default` case value is not a constructible case and you will get a compiler error if you try to construct it in C++.
630+
The `unknownDefault` case value is not a constructible case and you will get a compiler error if you try to construct it in C++.
631631
632632
## Using Swift Class Types
633633

docs/ReferenceGuides/UnderscoredAttributes.md

Lines changed: 48 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ the Swift ABI. This attribute is intended for the SIMD types in the standard
2323
library which use it to increase the alignment of their internal storage to at
2424
least 16 bytes.
2525

26+
## `@_alwaysEmitConformanceMetadata`
27+
28+
Forces conformances of the attributed protocol to always have their Type Metadata get emitted into the binary and prevents it from being optimized away or stripped by the linker.
29+
2630
## `@_alwaysEmitIntoClient`
2731

2832
Forces the body of a function to be emitted into client code.
@@ -39,6 +43,14 @@ Most notably, default argument expressions are implicitly
3943
`@_alwaysEmitIntoClient`, which means that adding a default argument to a
4044
function which did not have one previously does not break ABI.
4145

46+
## `@_assemblyVision`
47+
48+
Forces emission of assembly vision remarks for a function or method, showing
49+
where various runtime calls and performance impacting hazards are in the code
50+
at source level after optimization.
51+
52+
Adding this attribute to a type leads to remarks being emitted for all methods.
53+
4254
## `@_backDeploy(before: ...)`
4355

4456
Causes the body of a function to be emitted into the module interface to be
@@ -53,14 +65,6 @@ client is called instead.
5365
For more details, see the [pitch thread](https://forums.swift.org/t/pitch-function-back-deployment/55769/)
5466
in the forums.
5567

56-
## `@_assemblyVision`
57-
58-
Forces emission of assembly vision remarks for a function or method, showing
59-
where various runtime calls and performance impacting hazards are in the code
60-
at source level after optimization.
61-
62-
Adding this attribute to a type leads to remarks being emitted for all methods.
63-
6468
## `@_borrowed`
6569

6670
Indicates that the [conservative access pattern](/docs/Lexicon.md#access-pattern)
@@ -482,6 +486,19 @@ Fun fact: Rust has a very similar concept called
482486
including one called `Send`,
483487
which inspired the design of `Sendable`.
484488

489+
## `@_noAllocation`, `@_noLocks`
490+
491+
These attributes are performance annotations. If a function is annotated with
492+
such an attribute, the compiler issues a diagnostic message if the function
493+
calls a runtime function which allocates memory or locks, respectively.
494+
The `@_noLocks` attribute implies `@_noAllocation` because a memory allocation
495+
also locks.
496+
497+
## `@_noImplicitCopy`
498+
499+
Marks a var decl as a variable that must be copied explicitly using the builtin
500+
function Builtin.copy.
501+
485502
## `@_nonEphemeral`
486503

487504
Marks a function parameter that cannot accept a temporary pointer produced from
@@ -755,6 +772,14 @@ Clients can access SPI by marking the import as `@_spi(spiName) import Module`.
755772
This design makes it easy to find out which clients are using certain SPIs by
756773
doing a textual search.
757774

775+
## `@_spi_available(platform, version)`
776+
777+
Like `@available`, this attribute indicates a decl is available only as an SPI.
778+
This implies several behavioral changes comparing to regular `@available`:
779+
1. Type checker diagnoses when a client accidently exposes such a symbol in library APIs.
780+
2. When emitting public interfaces, `@_spi_available` is printed as `@available(platform, unavailable)`.
781+
3. ClangImporter imports ObjC macros `SPI_AVAILABLE` and `__SPI_AVAILABLE` to this attribute.
782+
758783
## `@_staticInitializeObjCMetadata`
759784

760785
Indicates that a static initializer should be emitted to register the
@@ -789,19 +814,11 @@ A type eraser has the following restrictions:
789814
This feature was designed to be used for compiler-driven type erasure for
790815
dynamic replacement of functions with an opaque return type.
791816

792-
## `@_weakLinked`
793-
794-
Allows a declaration to be weakly-referenced, i.e., any references emitted by
795-
client modules to the declaration's symbol will have weak linkage. This means
796-
that client code will compile without the guarantee that the symbol will be
797-
available at runtime. This requires a dynamic safety check (such as using
798-
`dlsym (3)`); otherwise, accessing the symbol when it is unavailable leads
799-
to a runtime crash.
817+
## `@_unavailableFromAsync`
800818

801-
This is an unsafe alternative to using `@available`, which is statically checked.
802-
If the availability of a library symbol is newer than the deployment target of
803-
the client, the symbol will be weakly linked, but checking for `@available` and
804-
`#(un)available` ensures that a symbol is not accessed when it is unavailable.
819+
Marks a synchronous API as being unavailable from asynchronous contexts. Direct
820+
usage of annotated API from asynchronous contexts will result in a warning from
821+
the compiler.
805822

806823
## `@_unsafeMainActor`, `@_unsafeSendable`
807824

@@ -812,38 +829,23 @@ within Swift 5 code that has adopted concurrency, but non-`@MainActor`
812829
See the forum post on [Concurrency in Swift 5 and 6](https://forums.swift.org/t/concurrency-in-swift-5-and-6/49337)
813830
for more details.
814831

815-
## `@_noImplicitCopy`
816-
817-
Marks a var decl as a variable that must be copied explicitly using the builtin
818-
function Builtin.copy.
819-
820-
## `@_noAllocation`, `@_noLocks`
821-
822-
These attributes are performance annotations. If a function is annotated with
823-
such an attribute, the compiler issues a diagnostic message if the function
824-
calls a runtime function which allocates memory or locks, respectively.
825-
The `@_noLocks` attribute implies `@_noAllocation` because a memory allocation
826-
also locks.
827-
828-
## `@_unavailableFromAsync`
829-
830-
Marks a synchronous API as being unavailable from asynchronous contexts. Direct
831-
usage of annotated API from asynchronous contexts will result in a warning from
832-
the compiler.
833-
834832
## `@_unsafeInheritExecutor`
835833

836834
This `async` function uses the pre-SE-0338 semantics of unsafely inheriting the caller's executor. This is an underscored feature because the right way of inheriting an executor is to pass in the required executor and switch to it. Unfortunately, there are functions in the standard library which need to inherit their caller's executor but cannot change their ABI because they were not defined as `@_alwaysEmitIntoClient` in the initial release.
837835

836+
## `@_weakLinked`
838837

839-
## `@_spi_available(platform, version)`
840-
841-
Like `@available`, this attribute indicates a decl is available only as an SPI.
842-
This implies several behavioral changes comparing to regular `@available`:
843-
1. Type checker diagnoses when a client accidently exposes such a symbol in library APIs.
844-
2. When emitting public interfaces, `@_spi_available` is printed as `@available(platform, unavailable)`.
845-
3. ClangImporter imports ObjC macros `SPI_AVAILABLE` and `__SPI_AVAILABLE` to this attribute.
838+
Allows a declaration to be weakly-referenced, i.e., any references emitted by
839+
client modules to the declaration's symbol will have weak linkage. This means
840+
that client code will compile without the guarantee that the symbol will be
841+
available at runtime. This requires a dynamic safety check (such as using
842+
`dlsym (3)`); otherwise, accessing the symbol when it is unavailable leads
843+
to a runtime crash.
846844

845+
This is an unsafe alternative to using `@available`, which is statically checked.
846+
If the availability of a library symbol is newer than the deployment target of
847+
the client, the symbol will be weakly linked, but checking for `@available` and
848+
`#(un)available` ensures that a symbol is not accessed when it is unavailable.
847849

848850
## `_local`
849851

@@ -852,8 +854,3 @@ the distributed actor isolation checks. This is used for things like `whenLocal`
852854
where the actor passed to the closure is known-to-be-local, and similarly a
853855
`self` of obtained from an _isolated_ function inside a distributed actor is
854856
also guaranteed to be local by construction.
855-
856-
857-
## `@_alwaysEmitConformanceMetadata`
858-
859-
Forces conformances of the attributed protocol to always have their Type Metadata get emitted into the binary and prevents it from being optimized away or stripped by the linker.

include/swift/ABI/Metadata.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,7 @@ struct TargetMetadata {
429429
#endif
430430

431431
#ifndef NDEBUG
432-
LLVM_ATTRIBUTE_DEPRECATED(void dump() const,
433-
"Only meant for use in the debugger");
432+
[[deprecated("Only meant for use in the debugger")]] void dump() const;
434433
#endif
435434

436435
protected:
@@ -2710,8 +2709,7 @@ struct TargetContextDescriptor {
27102709
}
27112710

27122711
#ifndef NDEBUG
2713-
LLVM_ATTRIBUTE_DEPRECATED(void dump() const,
2714-
"only for use in the debugger");
2712+
[[deprecated("Only meant for use in the debugger")]] void dump() const;
27152713
#endif
27162714

27172715
private:
@@ -2976,8 +2974,7 @@ struct TargetProtocolDescriptor final
29762974
}
29772975

29782976
#ifndef NDEBUG
2979-
LLVM_ATTRIBUTE_DEPRECATED(void dump() const,
2980-
"only for use in the debugger");
2977+
[[deprecated("Only meant for use in the debugger")]] void dump() const;
29812978
#endif
29822979

29832980
static bool classof(const TargetContextDescriptor<Runtime> *cd) {
@@ -4449,8 +4446,7 @@ class TargetEnumDescriptor final
44494446
}
44504447

44514448
#ifndef NDEBUG
4452-
LLVM_ATTRIBUTE_DEPRECATED(void dump() const,
4453-
"Only meant for use in the debugger");
4449+
[[deprecated("Only meant for use in the debugger")]] void dump() const;
44544450
#endif
44554451
};
44564452

include/swift/ABI/MetadataValues.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "swift/ABI/KeyPath.h"
2323
#include "swift/ABI/ProtocolDispatchStrategy.h"
2424
#include "swift/AST/Ownership.h"
25+
#include "swift/Basic/Debug.h"
2526
#include "swift/Basic/LLVM.h"
2627
#include "swift/Basic/FlagSet.h"
2728
#include "llvm/ADT/ArrayRef.h"
@@ -531,8 +532,7 @@ class ProtocolDescriptorFlags {
531532
}
532533

533534
#ifndef NDEBUG
534-
LLVM_ATTRIBUTE_DEPRECATED(void dump() const LLVM_ATTRIBUTE_USED,
535-
"Only for use in the debugger");
535+
SWIFT_DEBUG_DUMP;
536536
#endif
537537
};
538538

include/swift/AST/Attr.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2632,6 +2632,10 @@ inline SourceLoc extractNearestSourceLoc(const DeclAttribute *attr) {
26322632
return attr->getLocation();
26332633
}
26342634

2635+
/// Determine whether the given attribute is available, looking up the
2636+
/// attribute by name.
2637+
bool hasAttribute(const LangOptions &langOpts, llvm::StringRef attributeName);
2638+
26352639
} // end namespace swift
26362640

26372641
#endif

include/swift/AST/AutoDiff.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ using swift::SILFunctionType;
705705
using swift::DifferentiabilityKind;
706706
using swift::SILDifferentiabilityWitnessKey;
707707

708-
template <typename T> struct DenseMapInfo;
708+
template <typename T, typename Enable> struct DenseMapInfo;
709709

710710
template <> struct DenseMapInfo<AutoDiffConfig> {
711711
static AutoDiffConfig getEmptyKey() {

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ WARNING(warning_cannot_find_locale_file,none,
9999
"cannot find translations for '%0' at '%1': no such file", (StringRef, StringRef))
100100
WARNING(warning_cannot_multithread_batch_mode,none,
101101
"ignoring -num-threads argument; cannot multithread batch mode", ())
102-
ERROR(error_cannot_ignore_interface_options_in_mode,none,
103-
"'-ignore-interface-provided-options' only supported when building a module from interface ('-compile-module-from-interface')'", ())
102+
ERROR(error_cannot_explicit_interface_build_in_mode,none,
103+
"'-explicit-interface-module-build' only supported when building a module from interface ('-compile-module-from-interface')'", ())
104104
ERROR(error_unsupported_option_argument,none,
105105
"unsupported argument '%1' to option '%0'", (StringRef, StringRef))
106106
ERROR(error_immediate_mode_missing_stdlib,none,

include/swift/AST/DiagnosticsSema.def

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3779,7 +3779,11 @@ ERROR(should_use_empty_dictionary_literal,none,
37793779
// Dictionary literals
37803780
ERROR(type_is_not_dictionary,none,
37813781
"contextual type %0 cannot be used with dictionary literal", (Type))
3782-
3782+
WARNING(duplicated_literal_keys_in_dictionary_literal, none,
3783+
"dictionary literal of type %0 has duplicate entries for %1 literal key%select{ %3|}2",
3784+
(Type, StringRef, bool, StringRef))
3785+
NOTE(duplicated_key_declared_here, none,
3786+
"duplicate key declared here", ())
37833787

37843788
// Generic specializations
37853789
ERROR(cannot_explicitly_specialize_generic_function,none,
@@ -5234,7 +5238,7 @@ ERROR(objc_extension_not_class,none,
52345238
"'@objc' can only be applied to an extension of a class", ())
52355239

52365240
// If you change this, also change enum ObjCReason
5237-
#define OBJC_ATTR_SELECT "select{marked @_cdecl|marked dynamic|marked @objc|marked @IBOutlet|marked @IBAction|marked @IBSegueAction|marked @NSManaged|a member of an @objc protocol|implicitly @objc|an @objc override|an implementation of an @objc requirement|marked @IBInspectable|marked @GKInspectable|in an @objc extension of a class (without @nonobjc)|marked @objc by an access note}"
5241+
#define OBJC_ATTR_SELECT "select{marked @_cdecl|marked dynamic|marked @objc|marked @objcMembers|marked @IBOutlet|marked @IBAction|marked @IBSegueAction|marked @NSManaged|a member of an @objc protocol|implicitly @objc|an @objc override|an implementation of an @objc requirement|marked @IBInspectable|marked @GKInspectable|in an @objc extension of a class (without @nonobjc)|marked @objc by an access note}"
52385242

52395243
WARNING(attribute_meaningless_when_nonobjc,none,
52405244
"'@%0' attribute is meaningless on a property that cannot be "

include/swift/AST/Expr.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,9 @@ class LiteralExpr : public Expr {
617617
void setInitializer(ConcreteDeclRef initializer) {
618618
Initializer = initializer;
619619
}
620+
621+
/// Get description string for the literal expression.
622+
StringRef getLiteralKindDescription() const;
620623
};
621624

622625
/// BuiltinLiteralExpr - Common base class between all literals

include/swift/AST/GenericEnvironment.h

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class QueryInterfaceTypeSubstitutions {
5454
/// Extra data in a generic environment for an opened existential.
5555
struct OpenedGenericEnvironmentData {
5656
Type existential;
57+
GenericSignature parentSig;
5758
UUID uuid;
5859
};
5960

@@ -73,7 +74,7 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
7374
enum class Kind {
7475
/// A normal generic environment, determined only by its generic
7576
/// signature.
76-
Normal,
77+
Primary,
7778
/// A generic environment describing an opened existential archetype.
7879
OpenedExistential,
7980
/// A generic environment describing an opaque type archetype.
@@ -84,7 +85,7 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
8485

8586
private:
8687
mutable llvm::PointerIntPair<GenericSignature, 2, Kind> SignatureAndKind{
87-
GenericSignature(), Kind::Normal};
88+
GenericSignature(), Kind::Primary};
8889
NestedTypeStorage *nestedTypeStorage = nullptr;
8990

9091
friend TrailingObjects;
@@ -110,7 +111,8 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
110111

111112
explicit GenericEnvironment(GenericSignature signature);
112113
explicit GenericEnvironment(
113-
GenericSignature signature, Type existential, UUID uuid);
114+
GenericSignature signature,
115+
Type existential, GenericSignature parentSig, UUID uuid);
114116
explicit GenericEnvironment(
115117
GenericSignature signature, OpaqueTypeDecl *opaque, SubstitutionMap subs);
116118

@@ -143,6 +145,9 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
143145
/// Retrieve the UUID for an opened existential environment.
144146
UUID getOpenedExistentialUUID() const;
145147

148+
/// Retrieve the parent signature for an opened existential environment.
149+
GenericSignature getOpenedExistentialParentSignature() const;
150+
146151
/// Retrieve the opaque type declaration for a generic environment describing
147152
/// opaque types.
148153
OpaqueTypeDecl *getOpaqueTypeDecl() const;
@@ -151,36 +156,17 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
151156
/// create a generic environment.
152157
SubstitutionMap getOpaqueSubstitutions() const;
153158

154-
/// Create a new, "incomplete" generic environment that will be populated
155-
/// by calls to \c addMapping().
156-
static
157-
GenericEnvironment *getIncomplete(GenericSignature signature);
159+
/// Create a new, primary generic environment.
160+
static GenericEnvironment *forPrimary(GenericSignature signature);
158161

159162
/// Create a new generic environment for an opened existential.
160163
///
161-
/// This function uses the provided parent signature to construct a new
162-
/// signature suitable for use with an opened archetype. If you have an
163-
/// existing generic signature from e.g. deserialization use
164-
/// \c GenericEnvironment::forOpenedArchetypeSignature instead.
165-
///
166164
/// \param existential The subject existential type
167165
/// \param parentSig The signature of the context where this existential type is being opened
168166
/// \param uuid The unique identifier for this opened existential
169167
static GenericEnvironment *
170168
forOpenedExistential(Type existential, GenericSignature parentSig, UUID uuid);
171169

172-
/// Create a new generic environment for an opened existential.
173-
///
174-
/// It is unlikely you want to use this function.
175-
/// Call \c GenericEnvironment::forOpenedExistential instead.
176-
///
177-
/// \param existential The subject existential type
178-
/// \param signature The signature of the opened archetype
179-
/// \param uuid The unique identifier for this opened existential
180-
static GenericEnvironment *
181-
forOpenedArchetypeSignature(Type existential,
182-
GenericSignature signature, UUID uuid);
183-
184170
/// Create a new generic environment for an opaque type with the given set of
185171
/// outer substitutions.
186172
static GenericEnvironment *forOpaqueType(

0 commit comments

Comments
 (0)