Skip to content

Commit 785f2e1

Browse files
authored
Merge branch 'main' into wip-impl-execute-swift
2 parents 69e7fed + 3de701f commit 785f2e1

File tree

129 files changed

+2977
-1505
lines changed

Some content is hidden

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

129 files changed

+2977
-1505
lines changed

cmake/modules/StandaloneOverlay.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ set(SWIFT_DARWIN_MODULE_ARCHS "" CACHE STRING
9292
targets on Darwin platforms. These targets are in addition to the full \
9393
library targets.")
9494

95+
option(SWIFT_STDLIB_HAS_LOCALE
96+
"Build stdlib assuming the platform has locale support."
97+
TRUE)
98+
9599
# -----------------------------------------------------------------------------
96100
# Constants
97101

include/swift/ABI/TaskGroup.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define SWIFT_ABI_TASK_GROUP_H
1919

2020
#include "swift/ABI/Task.h"
21+
#include "swift/ABI/TaskStatus.h"
2122
#include "swift/ABI/HeapObject.h"
2223
#include "swift/Runtime/Concurrency.h"
2324
#include "swift/Runtime/Config.h"
@@ -46,6 +47,9 @@ class alignas(Alignment_TaskGroup) TaskGroup {
4647
// Add a child task to the group. Always called with the status record lock of
4748
// the parent task held
4849
void addChildTask(AsyncTask *task);
50+
51+
// Provide accessor for task group's status record
52+
TaskGroupTaskStatusRecord *getTaskRecord();
4953
};
5054

5155
} // end namespace swift

include/swift/AST/ASTTypeIDZone.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
SWIFT_TYPEID(ActorIsolation)
1919
SWIFT_TYPEID(AncestryFlags)
20+
SWIFT_TYPEID(BodyAndFingerprint)
2021
SWIFT_TYPEID(BodyInitKind)
2122
SWIFT_TYPEID(BodyInitKindAndExpr)
2223
SWIFT_TYPEID(CtorInitializerKind)

include/swift/AST/ASTTypeIDs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ enum class AncestryFlags : uint8_t;
8181
enum class ImplicitMemberAction : uint8_t;
8282
struct FingerprintAndMembers;
8383
class Identifier;
84+
class BodyAndFingerprint;
8485

8586
// Define the AST type zone (zone 1)
8687
#define SWIFT_TYPEID_ZONE AST

include/swift/AST/Attr.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ SIMPLE_DECL_ATTR(_noAllocation, NoAllocation,
690690

691691
SIMPLE_DECL_ATTR(_predatesConcurrency, PredatesConcurrency,
692692
OnFunc | OnConstructor | OnProtocol | OnGenericType | OnVar | OnSubscript |
693-
OnEnumElement | UserInaccessible |
693+
OnEnumElement | OnImport | UserInaccessible |
694694
ABIBreakingToAdd | ABIBreakingToRemove | APIBreakingToAdd | APIBreakingToRemove,
695695
125)
696696

include/swift/AST/Attr.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ class SILGenNameAttr : public DeclAttribute {
491491
Name(Name) {}
492492

493493
SILGenNameAttr(StringRef Name, bool Implicit)
494-
: SILGenNameAttr(Name, SourceLoc(), SourceRange(), /*Implicit=*/true) {}
494+
: SILGenNameAttr(Name, SourceLoc(), SourceRange(), Implicit) {}
495495

496496
/// The symbol name.
497497
const StringRef Name;
@@ -509,7 +509,7 @@ class CDeclAttr : public DeclAttribute {
509509
Name(Name) {}
510510

511511
CDeclAttr(StringRef Name, bool Implicit)
512-
: CDeclAttr(Name, SourceLoc(), SourceRange(), /*Implicit=*/true) {}
512+
: CDeclAttr(Name, SourceLoc(), SourceRange(), Implicit) {}
513513

514514
/// The symbol name.
515515
const StringRef Name;
@@ -528,7 +528,7 @@ class SemanticsAttr : public DeclAttribute {
528528
Value(Value) {}
529529

530530
SemanticsAttr(StringRef Value, bool Implicit)
531-
: SemanticsAttr(Value, SourceLoc(), SourceRange(), /*Implicit=*/true) {}
531+
: SemanticsAttr(Value, SourceLoc(), SourceRange(), Implicit) {}
532532

533533
/// The semantics tag value.
534534
const StringRef Value;

include/swift/AST/Decl.h

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5904,6 +5904,38 @@ class ImportAsMemberStatus {
59045904
}
59055905
};
59065906

5907+
class BodyAndFingerprint {
5908+
llvm::PointerIntPair<BraceStmt *, 1, bool> BodyAndHasFp;
5909+
Fingerprint Fp;
5910+
5911+
public:
5912+
BodyAndFingerprint(BraceStmt *body, Optional<Fingerprint> fp)
5913+
: BodyAndHasFp(body, fp.hasValue()),
5914+
Fp(fp.hasValue() ? *fp : Fingerprint::ZERO()) {}
5915+
BodyAndFingerprint() : BodyAndFingerprint(nullptr, None) {}
5916+
5917+
BraceStmt *getBody() const { return BodyAndHasFp.getPointer(); }
5918+
5919+
Optional<Fingerprint> getFingerprint() const {
5920+
if (BodyAndHasFp.getInt())
5921+
return Fp;
5922+
else
5923+
return None;
5924+
}
5925+
5926+
void setFingerprint(Optional<Fingerprint> fp) {
5927+
if (fp.hasValue()) {
5928+
Fp = *fp;
5929+
BodyAndHasFp.setInt(true);
5930+
} else {
5931+
Fp = Fingerprint::ZERO();
5932+
BodyAndHasFp.setInt(false);
5933+
}
5934+
}
5935+
};
5936+
5937+
void simple_display(llvm::raw_ostream &out, BodyAndFingerprint value);
5938+
59075939
/// Base class for function-like declarations.
59085940
class AbstractFunctionDecl : public GenericContext, public ValueDecl {
59095941
friend class NeedsNewVTableEntryRequest;
@@ -5986,7 +6018,7 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
59866018
union {
59876019
/// This enum member is active if getBodyKind() is BodyKind::Parsed or
59886020
/// BodyKind::TypeChecked.
5989-
BraceStmt *Body;
6021+
BodyAndFingerprint BodyAndFP;
59906022

59916023
/// This enum member is active if getBodyKind() is BodyKind::Deserialized.
59926024
StringRef BodyStringRepresentation;
@@ -6022,9 +6054,10 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
60226054
bool Throws, SourceLoc ThrowsLoc,
60236055
bool HasImplicitSelfDecl,
60246056
GenericParamList *GenericParams)
6025-
: GenericContext(DeclContextKind::AbstractFunctionDecl, Parent, GenericParams),
6026-
ValueDecl(Kind, Parent, Name, NameLoc),
6027-
Body(nullptr), AsyncLoc(AsyncLoc), ThrowsLoc(ThrowsLoc) {
6057+
: GenericContext(DeclContextKind::AbstractFunctionDecl, Parent,
6058+
GenericParams),
6059+
ValueDecl(Kind, Parent, Name, NameLoc), BodyAndFP(), AsyncLoc(AsyncLoc),
6060+
ThrowsLoc(ThrowsLoc) {
60286061
setBodyKind(BodyKind::None);
60296062
Bits.AbstractFunctionDecl.HasImplicitSelfDecl = HasImplicitSelfDecl;
60306063
Bits.AbstractFunctionDecl.Overridden = false;
@@ -6195,8 +6228,9 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
61956228
void setBodyToBeReparsed(SourceRange bodyRange);
61966229

61976230
/// Provide the parsed body for the function.
6198-
void setBodyParsed(BraceStmt *S) {
6231+
void setBodyParsed(BraceStmt *S, Optional<Fingerprint> fp = None) {
61996232
setBody(S, BodyKind::Parsed);
6233+
BodyAndFP.setFingerprint(fp);
62006234
}
62016235

62026236
/// Was there a nested type declaration detected when parsing this
@@ -6286,6 +6320,15 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
62866320
/// itself.
62876321
void keepOriginalBodySourceRange();
62886322

6323+
/// Retrieve the fingerprint of the body. Note that this is not affected by
6324+
/// the body of the local functions or the members of the local types in this
6325+
/// function.
6326+
Optional<Fingerprint> getBodyFingerprint() const;
6327+
6328+
/// Retrieve the fingerprint of the body including the local type members and
6329+
/// the local funcition bodies.
6330+
Optional<Fingerprint> getBodyFingerprintIncludingLocalTypeMembers() const;
6331+
62896332
/// Retrieve the source range of the *original* function body.
62906333
///
62916334
/// This may be different from \c getBodySourceRange() that returns the source

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ ERROR(error_immediate_mode_primary_file,none,
102102
"immediate mode is incompatible with -primary-file", ())
103103
ERROR(error_missing_frontend_action,none,
104104
"no frontend action was selected", ())
105+
ERROR(error_unsupported_frontend_action, none,
106+
"unsupported action: %0", (StringRef))
105107
ERROR(error_invalid_source_location_str,none,
106108
"invalid source location string '%0'", (StringRef))
107109
ERROR(error_no_source_location_scope_map,none,

include/swift/AST/DiagnosticsSema.def

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,6 +1952,12 @@ NOTE(non_sendable_nominal,none,
19521952
NOTE(add_nominal_sendable_conformance,none,
19531953
"consider making %0 %1 conform to the 'Sendable' protocol",
19541954
(DescriptiveDeclKind, DeclName))
1955+
REMARK(add_predates_concurrency_import,none,
1956+
"add '@_predatesConcurrency' to %select{suppress|treat}0 "
1957+
"'Sendable'-related %select{warnings|errors}0 from module %1"
1958+
"%select{| as warnings}0", (bool, Identifier))
1959+
REMARK(remove_predates_concurrency_import,none,
1960+
"'@_predatesConcurrency' attribute on module %0 is unused", (Identifier))
19551961
WARNING(public_decl_needs_sendable,none,
19561962
"public %0 %1 does not specify whether it is 'Sendable' or not",
19571963
(DescriptiveDeclKind, DeclName))
@@ -3185,6 +3191,7 @@ ERROR(nscopying_doesnt_conform,none,
31853191
#define SELECT_APPLICATION_DELEGATE "select{'UIApplicationDelegate'|'NSApplicationDelegate'}"
31863192
#define SELECT_APPLICATION_TYPE "select{class|class|type}"
31873193
#define SELECT_APPLICATION_TYPES "select{classes|classes|types}"
3194+
#define SELECT_APPLICATION_MAIN_TYPES "select{() -> Void or () throws -> Void|() -> Void, () throws -> Void, () async -> Void, or () async throws -> Void}"
31883195

31893196
ERROR(attr_ApplicationMain_not_ApplicationDelegate,none,
31903197
"%" SELECT_APPLICATION_MAIN "0 class must conform to the %" SELECT_APPLICATION_DELEGATE "0 protocol",
@@ -3204,9 +3211,11 @@ NOTE(attr_ApplicationMain_script_here,none,
32043211
())
32053212

32063213
ERROR(attr_MainType_without_main,none,
3207-
"%0 is annotated with @main and must provide a main static function of type () -> Void or () throws -> Void.",
3208-
(DeclName))
3214+
"%0 is annotated with @main and must provide a main static function of type %"
3215+
SELECT_APPLICATION_MAIN_TYPES "1",
3216+
(DeclName, bool))
32093217

3218+
#undef SELECT_APPLICATION_MAIN_TYPES
32103219
#undef SELECT_APPLICATION_MAIN
32113220
#undef SELECT_APPLICATION_DELEGATE
32123221

@@ -4430,9 +4439,6 @@ ERROR(distributed_actor_protocol_illegal_inheritance,none,
44304439
ERROR(broken_distributed_actor_requirement,none,
44314440
"DistributedActor protocol is broken: unexpected requirement", ())
44324441

4433-
ERROR(unowned_executor_outside_actor,none,
4434-
"'unownedExecutor' can only be implemented within the main "
4435-
"definition of an actor", ())
44364442
ERROR(override_implicit_unowned_executor,none,
44374443
"cannot override an actor's 'unownedExecutor' property that wasn't "
44384444
"explicitly defined", ())

include/swift/AST/Import.h

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ enum class ImportFlags {
8080
/// implementation detail of this file.
8181
SPIAccessControl = 0x10,
8282

83+
/// The module is imported assuming that the module itself predates
84+
/// concurrency.
85+
PredatesConcurrency = 0x20,
86+
8387
/// Used for DenseMap.
8488
Reserved = 0x80
8589
};
@@ -533,6 +537,9 @@ struct AttributedImport {
533537
/// Information about the module and access path being imported.
534538
ModuleInfo module;
535539

540+
/// The location of the 'import' keyword, for an explicit import.
541+
SourceLoc importLoc;
542+
536543
/// Flags indicating which attributes of this import are present.
537544
ImportOptions options;
538545

@@ -543,19 +550,27 @@ struct AttributedImport {
543550
/// Names of explicitly imported SPI groups.
544551
ArrayRef<Identifier> spiGroups;
545552

546-
AttributedImport(ModuleInfo module, ImportOptions options = ImportOptions(),
547-
StringRef filename = {}, ArrayRef<Identifier> spiGroups = {})
548-
: module(module), options(options), sourceFileArg(filename),
549-
spiGroups(spiGroups) {
553+
/// When the import declaration has a `@_predatesConcurrency` annotation, this
554+
/// is the source range covering the annotation.
555+
SourceRange predatesConcurrencyRange;
556+
557+
AttributedImport(ModuleInfo module, SourceLoc importLoc = SourceLoc(),
558+
ImportOptions options = ImportOptions(),
559+
StringRef filename = {}, ArrayRef<Identifier> spiGroups = {},
560+
SourceRange predatesConcurrencyRange = {})
561+
: module(module), importLoc(importLoc), options(options),
562+
sourceFileArg(filename), spiGroups(spiGroups),
563+
predatesConcurrencyRange(predatesConcurrencyRange) {
550564
assert(!(options.contains(ImportFlags::Exported) &&
551565
options.contains(ImportFlags::ImplementationOnly)) ||
552566
options.contains(ImportFlags::Reserved));
553567
}
554568

555569
template<class OtherModuleInfo>
556570
AttributedImport(ModuleInfo module, AttributedImport<OtherModuleInfo> other)
557-
: AttributedImport(module, other.options, other.sourceFileArg,
558-
other.spiGroups) { }
571+
: AttributedImport(module, other.importLoc, other.options,
572+
other.sourceFileArg, other.spiGroups,
573+
other.predatesConcurrencyRange) { }
559574

560575
friend bool operator==(const AttributedImport<ModuleInfo> &lhs,
561576
const AttributedImport<ModuleInfo> &rhs) {
@@ -705,17 +720,20 @@ struct DenseMapInfo<swift::AttributedImport<ModuleInfo>> {
705720
using ModuleInfoDMI = DenseMapInfo<ModuleInfo>;
706721
using ImportOptionsDMI = DenseMapInfo<swift::ImportOptions>;
707722
using StringRefDMI = DenseMapInfo<StringRef>;
723+
using SourceLocDMI = DenseMapInfo<swift::SourceLoc>;
708724
// We can't include spiGroups in the hash because ArrayRef<Identifier> is not
709725
// DenseMapInfo-able, but we do check that the spiGroups match in isEqual().
710726

711727
static inline AttributedImport getEmptyKey() {
712728
return AttributedImport(ModuleInfoDMI::getEmptyKey(),
729+
SourceLocDMI::getEmptyKey(),
713730
ImportOptionsDMI::getEmptyKey(),
714731
StringRefDMI::getEmptyKey(),
715732
{});
716733
}
717734
static inline AttributedImport getTombstoneKey() {
718735
return AttributedImport(ModuleInfoDMI::getTombstoneKey(),
736+
SourceLocDMI::getEmptyKey(),
719737
ImportOptionsDMI::getTombstoneKey(),
720738
StringRefDMI::getTombstoneKey(),
721739
{});
@@ -724,8 +742,8 @@ struct DenseMapInfo<swift::AttributedImport<ModuleInfo>> {
724742
return detail::combineHashValue(
725743
ModuleInfoDMI::getHashValue(import.module),
726744
detail::combineHashValue(
727-
ImportOptionsDMI::getHashValue(import.options),
728-
StringRefDMI::getHashValue(import.sourceFileArg)));
745+
ImportOptionsDMI::getHashValue(import.options),
746+
StringRefDMI::getHashValue(import.sourceFileArg)));
729747
}
730748
static bool isEqual(const AttributedImport &a,
731749
const AttributedImport &b) {

include/swift/AST/ParseRequests.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,25 @@ class ParseMembersRequest
6363
};
6464

6565
/// Parse the body of a function, initializer, or deinitializer.
66-
class ParseAbstractFunctionBodyRequest :
67-
public SimpleRequest<ParseAbstractFunctionBodyRequest,
68-
BraceStmt *(AbstractFunctionDecl *),
69-
RequestFlags::SeparatelyCached>
70-
{
66+
class ParseAbstractFunctionBodyRequest
67+
: public SimpleRequest<ParseAbstractFunctionBodyRequest,
68+
BodyAndFingerprint(AbstractFunctionDecl *),
69+
RequestFlags::SeparatelyCached> {
7170
public:
7271
using SimpleRequest::SimpleRequest;
7372

7473
private:
7574
friend SimpleRequest;
7675

7776
// Evaluation.
78-
BraceStmt *evaluate(Evaluator &evaluator, AbstractFunctionDecl *afd) const;
77+
BodyAndFingerprint evaluate(Evaluator &evaluator,
78+
AbstractFunctionDecl *afd) const;
7979

8080
public:
8181
// Caching
8282
bool isCached() const { return true; }
83-
Optional<BraceStmt *> getCachedResult() const;
84-
void cacheResult(BraceStmt *value) const;
83+
Optional<BodyAndFingerprint> getCachedResult() const;
84+
void cacheResult(BodyAndFingerprint value) const;
8585
};
8686

8787
struct SourceFileParsingResult {

include/swift/AST/ParseTypeIDZone.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ SWIFT_REQUEST(Parse, CodeCompletionSecondPassRequest,
2020
SWIFT_REQUEST(Parse, ParseMembersRequest,
2121
FingerprintAndMembers(IterableDeclContext *), Cached, NoLocationInfo)
2222
SWIFT_REQUEST(Parse, ParseAbstractFunctionBodyRequest,
23-
BraceStmt *(AbstractFunctionDecl *), SeparatelyCached,
23+
BodyAndFingerprint(AbstractFunctionDecl *), SeparatelyCached,
2424
NoLocationInfo)
2525
SWIFT_REQUEST(Parse, ParseSourceFileRequest,
2626
SourceFileParsingResult(SourceFile *), SeparatelyCached,

include/swift/AST/SourceFile.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ class SourceFile final : public FileUnit {
8484
/// This is \c None until it is filled in by the import resolution phase.
8585
Optional<ArrayRef<AttributedImport<ImportedModule>>> Imports;
8686

87+
/// Which imports have made use of @_predatesConcurrency.
88+
llvm::SmallDenseSet<AttributedImport<ImportedModule>>
89+
PredatesConcurrencyImportsUsed;
90+
8791
/// A unique identifier representing this file; used to mark private decls
8892
/// within the file to keep them from conflicting with other files in the
8993
/// same module.
@@ -293,6 +297,14 @@ class SourceFile final : public FileUnit {
293297
/// resolution.
294298
void setImports(ArrayRef<AttributedImport<ImportedModule>> imports);
295299

300+
/// Whether the given import has used @_predatesConcurrency.
301+
bool hasImportUsedPredatesConcurrency(
302+
AttributedImport<ImportedModule> import) const;
303+
304+
/// Note that the given import has used @_predatesConcurrency/
305+
void setImportUsedPredatesConcurrency(
306+
AttributedImport<ImportedModule> import);
307+
296308
enum ImportQueryKind {
297309
/// Return the results for testable or private imports.
298310
TestableAndPrivate,

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,6 @@ LANGUAGE_FEATURE(BuiltinMove, 0, "Builtin.move()", true)
5858
LANGUAGE_FEATURE(BuiltinCopy, 0, "Builtin.copy()", true)
5959
LANGUAGE_FEATURE(BuiltinStackAlloc, 0, "Builtin.stackAlloc", true)
6060
LANGUAGE_FEATURE(SpecializeAttributeWithAvailability, 0, "@_specialize attribute with availability", true)
61+
LANGUAGE_FEATURE(BuiltinAssumeAlignment, 0, "Builtin.assumeAlignment", true)
6162

6263
#undef LANGUAGE_FEATURE

0 commit comments

Comments
 (0)