Skip to content

Commit 64d6417

Browse files
committed
Merge branch 'main' of github.com:apple/swift into maxd/main-merge
# Conflicts: # test/Concurrency/Runtime/checked_continuation.swift
2 parents 0233449 + d578fac commit 64d6417

File tree

405 files changed

+6982
-2286
lines changed

Some content is hidden

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

405 files changed

+6982
-2286
lines changed

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,18 @@ if(SWIFT_ENABLE_DISPATCH AND NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
530530
endif()
531531
endif()
532532

533+
set(SWIFT_STDLIB_AVAILABILITY_DEFINITIONS
534+
"SwiftStdlib 5.0:macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2"
535+
"SwiftStdlib 5.1:macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0"
536+
"SwiftStdlib 5.2:macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4"
537+
"SwiftStdlib 5.3:macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0"
538+
"SwiftStdlib 5.4:macOS 11.3, iOS 14.5, watchOS 7.4, tvOS 14.5"
539+
"SwiftStdlib 5.5:macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0"
540+
"SwiftStdlib 5.6:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999"
541+
"SwiftStdlib 9999:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999" # Unknown future release
542+
CACHE STRING
543+
"Availability macros for stdlib versions")
544+
533545
#
534546
# Include CMake modules
535547
#
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
set(SWIFT_HOST_VARIANT_SDK WINDOWS 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+

docs/StandardLibraryProgrammersManual.md

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,34 +298,63 @@ Just like access control modifiers, we prefer to put `@available` attributes on
298298
299299
```swift
300300
// 😢👎
301-
@available(macOS 10.6, iOS 10, watchOS 3, tvOS 12, *)
301+
@available(SwiftStdlib 5.2, *)
302302
extension String {
303303
public func blanch() { ... }
304304
public func roast() { ... }
305305
}
306306
307307
// 🥲👍
308308
extension String {
309-
@available(macOS 10.6, iOS 10, watchOS 3, tvOS 12, *)
309+
@available(SwiftStdlib 5.2, *)
310310
public func blanch() { ... }
311311
312-
@available(macOS 10.6, iOS 10, watchOS 3, tvOS 12, *)
312+
@available(SwiftStdlib 5.2, *)
313313
public func roast() { ... }
314314
}
315315
```
316316
317317
This coding style is enforced by the ABI checker -- it will complain if an extension member declaration that needs an availability doesn't have it directly attached.
318318
319-
Features under development that haven't been released yet must be marked with the placeholder version number `9999`. This special version is always considered available in custom builds of the Swift toolchain (including development snapshots), but not in any ABI-stable production release.
319+
This repository defines a set of availability macros (of the form `SwiftStdlib x.y`) that map Swift Stdlib releases to the OS versions that shipped them, for all ABI stable platforms. The following two definitions are equivalent, but the second one is less error-prone, so we prefer that:
320320
321321
```swift
322+
extension String {
323+
// 😵‍💫👎
324+
@available(macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4, *)
325+
public func fiddle() { ... }
326+
327+
// 😎👍
328+
@available(SwiftStdlib 5.2, *)
329+
public func fiddle() { ... }
330+
}
331+
```
332+
333+
(Mistakes in the OS version number list are very easy to miss during review, but can have major ABI consequences.)
334+
335+
This is especially important for newly introduced APIs, where the corresponding OS releases may not even be known yet.
336+
337+
Features under development that haven't shipped yet must be marked as available in the placeholder OS version `9999`. This special version is always considered available in custom builds of the Swift toolchain (including development snapshots), but not in any ABI-stable production release.
338+
339+
Never explicitly spell out such placeholder availability -- instead, use the `SwiftStdlib` macro corresponding to the Swift version we're currently working on:
340+
341+
```swift
342+
// 😵‍💫👎
322343
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
323344
public struct FutureFeature {
324345
...
325346
}
347+
348+
// 😎👍
349+
@available(SwiftStdlib 6.3, *) // Or whatever
350+
public struct FutureFeature {
351+
...
352+
}
326353
```
327354
328-
On these platforms, the Swift Standard Library ships as an integrated part of the operating system; as such, it is the platform owners' responsibility to update these placeholder version numbers to actual versions as part of their release process.
355+
This way, platform owners can easily update declarations to the correct set of version numbers by simply changing the definition of the macro, rather than having to update each individual declaration.
356+
357+
If we haven't defined a version number for the "next" Swift release yet, please use the special placeholder version `SwiftStdlib 9999`, which always expands to 9999 versions. Declarations that use this version will need to be manually updated once we decide on the corresponding Swift version number.
329358
330359
## Internals
331360

include/swift/AST/ASTContext.h

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,14 @@ class ASTContext final {
350350
/// Cache of module names that fail the 'canImport' test in this context.
351351
mutable llvm::SmallPtrSet<Identifier, 8> FailedModuleImportNames;
352352

353-
/// Mapping between aliases and real (physical) names of imported or referenced modules.
354-
mutable llvm::DenseMap<Identifier, Identifier> ModuleAliasMap;
353+
/// Set if a `-module-alias` was passed. Used to store mapping between module aliases and
354+
/// their corresponding real names, and vice versa for a reverse lookup, which is needed to check
355+
/// if the module names appearing in source files are aliases or real names.
356+
/// \see ASTContext::getRealModuleName.
357+
///
358+
/// The boolean in the value indicates whether or not the entry is keyed by an alias vs real name,
359+
/// i.e. true if the entry is [key: alias_name, value: (real_name, true)].
360+
mutable llvm::DenseMap<Identifier, std::pair<Identifier, bool>> ModuleAliasMap;
355361

356362
/// Retrieve the allocator for the given arena.
357363
llvm::BumpPtrAllocator &
@@ -483,9 +489,23 @@ class ASTContext final {
483489
/// are the real (physical) module names on disk.
484490
void setModuleAliases(const llvm::StringMap<StringRef> &aliasMap);
485491

486-
/// Retrieve the actual module name if a module alias is used via '-module-alias Foo=X', where Foo is
487-
/// a module alias and X is the real (physical) name. Returns \p key if no aliasing is used.
488-
Identifier getRealModuleName(Identifier key) const;
492+
/// Look up the module alias map by the given \p key.
493+
///
494+
/// \param key A module alias or real name to look up the map by
495+
/// \param alwaysReturnRealName Indicates whether it should always retrieve the real module name
496+
/// given \p key. Defaults to true. This takes a higher precedence than
497+
/// \p lookupAliasFromReal.
498+
/// \param lookupAliasFromReal Indicates whether to look up an alias by treating \p key
499+
/// as a real name. Defaults to false.
500+
/// \return The real name or alias mapped to the key.
501+
/// If \p alwaysReturnRealName is true, return the real module name if \p key is an alias
502+
/// or the key itself since that's the real name.
503+
/// If \p lookupAliasFromReal is true, and \p alwaysReturnRealName is false, return
504+
/// only if \p key is a real name, else an empty Identifier.
505+
/// If no aliasing is used, return \p key.
506+
Identifier getRealModuleName(Identifier key,
507+
bool alwaysReturnRealName = true,
508+
bool lookupAliasFromReal = false) const;
489509

490510
/// Decide how to interpret two precedence groups.
491511
Associativity associateInfixOperators(PrecedenceGroupDecl *left,

include/swift/AST/Attr.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ SIMPLE_DECL_ATTR(_noImplicitCopy, NoImplicitCopy,
676676
UserInaccessible |
677677
ABIStableToAdd | ABIBreakingToRemove |
678678
APIStableToAdd | APIBreakingToRemove |
679-
OnVar,
679+
OnParam | OnVar,
680680
122)
681681

682682
SIMPLE_DECL_ATTR(_noLocks, NoLocks,

include/swift/AST/Decl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4168,6 +4168,7 @@ class ProtocolDecl final : public NominalTypeDecl {
41684168
friend class StructuralRequirementsRequest;
41694169
friend class ProtocolDependenciesRequest;
41704170
friend class RequirementSignatureRequest;
4171+
friend class RequirementSignatureRequestRQM;
41714172
friend class ProtocolRequiresClassRequest;
41724173
friend class ExistentialConformsToSelfRequest;
41734174
friend class InheritedProtocolsRequest;
@@ -5371,6 +5372,10 @@ class ParamDecl : public VarDecl {
53715372
Bits.ParamDecl.defaultArgumentKind = static_cast<unsigned>(K);
53725373
}
53735374

5375+
bool isNoImplicitCopy() const {
5376+
return getAttrs().hasAttribute<NoImplicitCopyAttr>();
5377+
}
5378+
53745379
/// Whether this parameter has a default argument expression available.
53755380
///
53765381
/// Note that this will return false for deserialized declarations, which only

include/swift/AST/DiagnosticsParse.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,9 @@ ERROR(getset_cannot_be_implied,none,
302302
// Import
303303
ERROR(decl_expected_module_name,none,
304304
"expected module name in import declaration", ())
305+
ERROR(expected_module_alias,none,
306+
"cannot refer to module as %0 because it has been aliased; use %1 "
307+
"instead", (Identifier, Identifier))
305308

306309
// Extension
307310
ERROR(expected_lbrace_extension,PointsToFirstBadToken,

include/swift/AST/DiagnosticsSema.def

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2912,7 +2912,7 @@ WARNING(warn_implementation_only_conflict,none,
29122912
(Identifier))
29132913
NOTE(implementation_only_conflict_here,none,
29142914
"imported as implementation-only here", ())
2915-
WARNING(warn_public_import_of_private_module,none,
2915+
ERROR(error_public_import_of_private_module,none,
29162916
"private module %0 is imported publicly from the public module %1",
29172917
(Identifier, Identifier))
29182918

@@ -4351,6 +4351,10 @@ NOTE(note_add_async_to_function,none,
43514351
NOTE(note_add_nonisolated_to_decl,none,
43524352
"add 'nonisolated' to %0 to make this %1 not isolated to the actor",
43534353
(DeclName, DescriptiveDeclKind))
4354+
NOTE(note_add_async_and_throws_to_decl,none,
4355+
"mark the protocol requirement %0 '%select{|async|throws|async throws}1' "
4356+
"in order witness it with 'distributed' function declared in distributed actor %2",
4357+
(DeclName, unsigned, DeclName))
43544358
NOTE(note_add_distributed_to_decl,none,
43554359
"add 'distributed' to %0 to make this %1 witness the protocol requirement",
43564360
(DeclName, DescriptiveDeclKind))
@@ -4484,11 +4488,11 @@ NOTE(actor_isolated_sync_func,none,
44844488
"calls to %0 %1 from outside of its actor context are "
44854489
"implicitly asynchronous",
44864490
(DescriptiveDeclKind, DeclName))
4487-
NOTE(distributed_actor_isolated_method_note,none,
4488-
"only 'distributed' functions can be called from outside the distributed actor", // TODO(distributed): improve error message
4489-
())
4491+
NOTE(note_distributed_actor_isolated_method,none,
4492+
"distributed actor-isolated %0 %1 declared here",
4493+
(DescriptiveDeclKind, DeclName))
44904494
ERROR(distributed_actor_isolated_method,none,
4491-
"only 'distributed' functions can be called from outside the distributed actor", // TODO(distributed): improve error message to be more like 'non-distributed' ... defined here
4495+
"only 'distributed' functions can be called on a potentially remote distributed actor",
44924496
())
44934497
ERROR(distributed_actor_func_param_not_codable,none,
44944498
"distributed function parameter '%0' of type %1 does not conform to 'Codable'",
@@ -4497,7 +4501,7 @@ ERROR(distributed_actor_func_result_not_codable,none,
44974501
"distributed function result type %0 does not conform to 'Codable'",
44984502
(Type))
44994503
ERROR(distributed_actor_remote_func_implemented_manually,none,
4500-
"Distributed function's %0 remote counterpart %1 cannot not be implemented manually.",
4504+
"distributed function's %0 remote counterpart %1 cannot not be implemented manually.",
45014505
(Identifier, Identifier))
45024506
ERROR(nonisolated_distributed_actor_storage,none,
45034507
"'nonisolated' can not be applied to distributed actor stored properties",
@@ -4523,6 +4527,9 @@ WARNING(shared_mutable_state_access,none,
45234527
ERROR(actor_isolated_witness,none,
45244528
"actor-isolated %0 %1 cannot be used to satisfy a protocol requirement",
45254529
(DescriptiveDeclKind, DeclName))
4530+
ERROR(distributed_actor_isolated_witness,none,
4531+
"distributed actor-isolated %0 %1 cannot be used to satisfy a protocol requirement",
4532+
(DescriptiveDeclKind, DeclName))
45264533
ERROR(global_actor_isolated_requirement,none,
45274534
"%0 %1 must be isolated to the global actor %2 to satisfy corresponding "
45284535
"requirement from protocol %3",
@@ -6040,8 +6047,8 @@ ERROR(experimental_moveonly_feature_can_only_be_used_when_enabled,
60406047
none, "Can not use feature when experimental move only is disabled! Pass"
60416048
" the frontend flag -enable-experimental-move-only to swift to enable "
60426049
"the usage of this language feature", ())
6043-
ERROR(noimplicitcopy_attr_valid_only_on_local_let,
6044-
none, "'@_noImplicitCopy' attribute can only be applied to local lets", ())
6050+
ERROR(noimplicitcopy_attr_valid_only_on_local_let_params,
6051+
none, "'@_noImplicitCopy' attribute can only be applied to local lets and params", ())
60456052
ERROR(noimplicitcopy_attr_invalid_in_generic_context,
60466053
none, "'@_noImplicitCopy' attribute cannot be applied to entities in generic contexts", ())
60476054

include/swift/AST/IRGenOptions.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ class IRGenOptions {
311311
/// Used on Windows to avoid cross-module references.
312312
unsigned LazyInitializeClassMetadata : 1;
313313
unsigned LazyInitializeProtocolConformances : 1;
314+
unsigned IndirectAsyncFunctionPointer : 1;
314315

315316
/// Normally if the -read-legacy-type-info flag is not specified, we look for
316317
/// a file named "legacy-<arch>.yaml" in SearchPathOpts.RuntimeLibraryPath.
@@ -417,7 +418,8 @@ class IRGenOptions {
417418
ValueNames(false), EnableReflectionMetadata(true),
418419
EnableReflectionNames(true), EnableAnonymousContextMangledNames(false),
419420
ForcePublicLinkage(false), LazyInitializeClassMetadata(false),
420-
LazyInitializeProtocolConformances(false), DisableLegacyTypeInfo(false),
421+
LazyInitializeProtocolConformances(false),
422+
IndirectAsyncFunctionPointer(false), DisableLegacyTypeInfo(false),
421423
PrespecializeGenericMetadata(false), UseIncrementalLLVMCodeGen(true),
422424
UseTypeLayoutValueHandling(true), ForceStructTypeLayouts(false),
423425
GenerateProfile(false), EnableDynamicReplacementChaining(false),

include/swift/AST/KnownSDKTypes.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ KNOWN_SDK_TYPE_DECL(Concurrency, TaskLocal, ClassDecl, 1)
4545

4646
// Distributed actors
4747
KNOWN_SDK_TYPE_DECL(Distributed, DistributedActor, ProtocolDecl, 0)
48-
KNOWN_SDK_TYPE_DECL(Distributed, ActorTransport, ProtocolDecl, 0)
4948
KNOWN_SDK_TYPE_DECL(Distributed, ActorIdentity, ProtocolDecl, 0)
5049
KNOWN_SDK_TYPE_DECL(Distributed, AnyActorIdentity, StructDecl, 0)
5150

include/swift/AST/SILOptions.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ class SILOptions {
198198
/// Are we parsing the stdlib, i.e. -parse-stdlib?
199199
bool ParseStdlib = false;
200200

201+
/// If true, check for leaking instructions when the SILModule is destructed.
202+
///
203+
/// Warning: this is not thread safe. It can only be enabled in case there
204+
/// is a single SILModule in a single thread.
205+
bool checkSILModuleLeaks = false;
206+
201207
/// The name of the file to which the backend should save optimization
202208
/// records.
203209
std::string OptRecordFile;

include/swift/AST/TypeCheckRequests.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,26 @@ class ProtocolDependenciesRequest :
406406
bool isCached() const { return true; }
407407
};
408408

409+
/// Compute the requirements that describe a protocol using the
410+
/// RequirementMachine.
411+
class RequirementSignatureRequestRQM :
412+
public SimpleRequest<RequirementSignatureRequestRQM,
413+
ArrayRef<Requirement>(ProtocolDecl *),
414+
RequestFlags::Cached> {
415+
public:
416+
using SimpleRequest::SimpleRequest;
417+
418+
private:
419+
friend SimpleRequest;
420+
421+
// Evaluation.
422+
ArrayRef<Requirement>
423+
evaluate(Evaluator &evaluator, ProtocolDecl *proto) const;
424+
425+
public:
426+
bool isCached() const { return true; }
427+
};
428+
409429
/// Compute the requirements that describe a protocol.
410430
class RequirementSignatureRequest :
411431
public SimpleRequest<RequirementSignatureRequest,

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ SWIFT_REQUEST(TypeChecker, StructuralRequirementsRequest,
225225
SWIFT_REQUEST(TypeChecker, ProtocolDependenciesRequest,
226226
ArrayRef<ProtocolDecl *>(ProtocolDecl *), Cached,
227227
HasNearestLocation)
228+
SWIFT_REQUEST(TypeChecker, RequirementSignatureRequestRQM,
229+
ArrayRef<Requirement>(ProtocolDecl *), Cached,
230+
NoLocationInfo)
228231
SWIFT_REQUEST(TypeChecker, RequirementSignatureRequest,
229232
ArrayRef<Requirement>(ProtocolDecl *), SeparatelyCached,
230233
NoLocationInfo)

include/swift/Option/FrontendOptions.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ def disable_typo_correction : Flag<["-"], "disable-typo-correction">,
181181
def disable_implicit_swift_modules: Flag<["-"], "disable-implicit-swift-modules">,
182182
HelpText<"Disable building Swift modules implicitly by the compiler">;
183183

184-
def explict_swift_module_map
184+
def explicit_swift_module_map
185185
: Separate<["-"], "explicit-swift-module-map-file">, MetaVarName<"<path>">,
186-
HelpText<"Specify a JSON file containing information of explict Swift modules">;
186+
HelpText<"Specify a JSON file containing information of explicit Swift modules">;
187187

188188
def placeholder_dependency_module_map
189189
: Separate<["-"], "placeholder-dependency-module-map-file">, MetaVarName<"<path>">,
@@ -194,7 +194,7 @@ def batch_scan_input_file
194194
HelpText<"Specify a JSON file containing modules to perform batch dependencies scanning">;
195195

196196
def import_prescan : Flag<["-"], "import-prescan">,
197-
HelpText<"When performing a dependency scan, only dentify all imports of the main Swift module sources">;
197+
HelpText<"When performing a dependency scan, only identify all imports of the main Swift module sources">;
198198

199199
def serialize_dependency_scan_cache : Flag<["-"], "serialize-dependency-scan-cache">,
200200
HelpText<"After performing a dependency scan, serialize the scanner's internal state.">;
@@ -816,7 +816,7 @@ def enable_verify_exclusivity : Flag<["-"], "enable-verify-exclusivity">,
816816
HelpText<"Enable verification of access markers used to enforce exclusivity.">;
817817

818818
def disable_verify_exclusivity : Flag<["-"], "disable-verify-exclusivity">,
819-
HelpText<"Diable verification of access markers used to enforce exclusivity.">;
819+
HelpText<"Disable verification of access markers used to enforce exclusivity.">;
820820

821821
def disable_legacy_type_info : Flag<["-"], "disable-legacy-type-info">,
822822
HelpText<"Completely disable legacy type layout">;

include/swift/Option/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ def save_optimization_record_path :
708708
def save_optimization_record_passes :
709709
Separate<["-"], "save-optimization-record-passes">,
710710
Flags<[FrontendOption]>,
711-
HelpText<"Only include passes which match a specified regular expression in"
711+
HelpText<"Only include passes which match a specified regular expression in "
712712
"the generated optimization record "
713713
"(by default, include all passes)">, MetaVarName<"<regex>">;
714714

0 commit comments

Comments
 (0)