Skip to content

Commit e17334b

Browse files
authored
Merge pull request #3763 from swiftwasm/maxd/main-merge
Resolve conflicts with upstream `main`
2 parents 4b4a7db + dd7c8b0 commit e17334b

File tree

62 files changed

+1537
-1124
lines changed

Some content is hidden

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

62 files changed

+1537
-1124
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,21 @@ Swift 5.5
8484

8585
### 2021-09-20 (Xcode 13.0)
8686

87+
* [SE-0323][]:
88+
89+
The main function is executed with `MainActor` isolation applied, so functions
90+
and variables with `MainActor` isolation may be called and modified
91+
synchronously from the main function. If the main function is annotated with a
92+
global actor explicitly, it must be the main actor or an error is emitted. If
93+
no global actor annotation is present, the main function is implicitly run on
94+
the main actor.
95+
96+
The main function is executed synchronously up to the first suspension point.
97+
Any tasks enqueued by initializers in Objective-C or C++ will run after the
98+
main function runs to the first suspension point. At the suspension point, the
99+
main function suspends and the tasks are executed according to the Swift
100+
concurrency mechanisms.
101+
87102
* [SE-0313][]:
88103

89104
Parameters of actor type can be declared as `isolated`, which means that they
@@ -8745,6 +8760,7 @@ Swift 1.0
87458760
[SE-0315]: <https://github.com/apple/swift-evolution/blob/main/proposals/0315-placeholder-types.md>
87468761
[SE-0316]: <https://github.com/apple/swift-evolution/blob/main/proposals/0316-global-actors.md>
87478762
[SE-0324]: <https://github.com/apple/swift-evolution/blob/main/proposals/0324-c-lang-pointer-arg-conversion.md>
8763+
[SE-0323]: <https://github.com/apple/swift-evolution/blob/main/proposals/0323-async-main-semantics.md>
87488764

87498765
[SR-75]: <https://bugs.swift.org/browse/SR-75>
87508766
[SR-106]: <https://bugs.swift.org/browse/SR-106>

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,18 @@ option(SWIFT_REPORT_STATISTICS
405405
"Create json files which contain internal compilation statistics"
406406
FALSE)
407407

408+
# Only Darwin platforms enable ObjC interop by default.
409+
if("${SWIFT_HOST_VARIANT_SDK}" MATCHES "(OSX|IOS*|TVOS*|WATCHOS*)")
410+
set(SWIFT_STDLIB_ENABLE_OBJC_INTEROP_default TRUE)
411+
else()
412+
set(SWIFT_STDLIB_ENABLE_OBJC_INTEROP_default FALSE)
413+
endif()
414+
415+
# Used by stdlib/toolchain as well, so this cannot be in stdlib/CMakeLists.txt
416+
option(SWIFT_STDLIB_ENABLE_OBJC_INTEROP
417+
"Should stdlib be built with Obj-C interop."
418+
"${SWIFT_STDLIB_ENABLE_OBJC_INTEROP_default}")
419+
408420
# FIXME(wasm) Reflection tests are temporalily disabled due to lack of linker features
409421
option(SWIFTWASM_DISABLE_REFLECTION_TEST
410422
"Disable building swift-reflection-test for WebAssembly build"

include/swift/ABI/Task.h

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -480,27 +480,42 @@ class AsyncTask : public Job {
480480
return resultType;
481481
}
482482

483-
/// Retrieve a pointer to the storage of result.
483+
/// Retrieve a pointer to the storage of the result.
484484
OpaqueValue *getStoragePtr() {
485-
return reinterpret_cast<OpaqueValue *>(
486-
reinterpret_cast<char *>(this) + storageOffset(resultType));
485+
// The result storage starts at the first aligned offset following
486+
// the fragment header. This offset will agree with the abstract
487+
// calculation for `resultOffset` in the fragmentSize function below
488+
// because the entire task is aligned to at least the target
489+
// alignment (because it's aligned to MaxAlignment), which means
490+
// `this` must have the same value modulo that alignment as
491+
// `fragmentOffset` has in that function.
492+
char *fragmentAddr = reinterpret_cast<char *>(this);
493+
uintptr_t alignment = resultType->vw_alignment();
494+
char *resultAddr = fragmentAddr + sizeof(FutureFragment);
495+
uintptr_t unalignedResultAddrInt =
496+
reinterpret_cast<uintptr_t>(resultAddr);
497+
uintptr_t alignedResultAddrInt =
498+
(unalignedResultAddrInt + alignment - 1) & ~(alignment - 1);
499+
// We could just cast alignedResultAddrInt back to a pointer, but
500+
// doing pointer arithmetic is more strictly conformant and less
501+
// likely to annoy the optimizer.
502+
resultAddr += (alignedResultAddrInt - unalignedResultAddrInt);
503+
return reinterpret_cast<OpaqueValue *>(resultAddr);
487504
}
488505

489506
/// Retrieve the error.
490507
SwiftError *&getError() { return error; }
491508

492-
/// Compute the offset of the storage from the base of the future
493-
/// fragment.
494-
static size_t storageOffset(const Metadata *resultType) {
495-
size_t offset = sizeof(FutureFragment);
509+
/// Determine the size of the future fragment given the result type
510+
/// of the future.
511+
static size_t fragmentSize(size_t fragmentOffset,
512+
const Metadata *resultType) {
513+
assert((fragmentOffset & (alignof(FutureFragment) - 1)) == 0);
496514
size_t alignment = resultType->vw_alignment();
497-
return (offset + alignment - 1) & ~(alignment - 1);
498-
}
499-
500-
/// Determine the size of the future fragment given a particular future
501-
/// result type.
502-
static size_t fragmentSize(const Metadata *resultType) {
503-
return storageOffset(resultType) + resultType->vw_size();
515+
size_t resultOffset = fragmentOffset + sizeof(FutureFragment);
516+
resultOffset = (resultOffset + alignment - 1) & ~(alignment - 1);
517+
size_t endOffset = resultOffset + resultType->vw_size();
518+
return (endOffset - fragmentOffset);
504519
}
505520
};
506521

include/swift/AST/Decl.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6265,14 +6265,6 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
62656265
Optional<unsigned> findPotentialCompletionHandlerParam(
62666266
const AbstractFunctionDecl *asyncAlternative = nullptr) const;
62676267

6268-
/// Determine whether this function is implicitly known to have its
6269-
/// parameters of function type be @_unsafeSendable.
6270-
///
6271-
/// This hard-codes knowledge of a number of functions that will
6272-
/// eventually have @_unsafeSendable and, eventually, @Sendable,
6273-
/// on their parameters of function type.
6274-
bool hasKnownUnsafeSendableFunctionParams() const;
6275-
62766268
using DeclContext::operator new;
62776269
using DeclContext::operator delete;
62786270
using Decl::getASTContext;

include/swift/AST/DiagnosticsDriver.def

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,14 @@ ERROR(error_darwin_only_supports_libcxx, none,
166166
"The only C++ standard library supported on Apple platforms is libc++",
167167
())
168168

169+
ERROR(error_hermetic_seal_cannot_have_library_evolution, none,
170+
"Cannot use -experimental-hermetic-seal-at-link with -enable-library-evolution",
171+
())
172+
173+
ERROR(error_hermetic_seal_requires_lto, none,
174+
"-experimental-hermetic-seal-at-link requires -lto=llvm-full or -lto=llvm-thin",
175+
())
176+
169177
WARNING(warn_drv_darwin_sdk_invalid_settings, none,
170178
"SDK settings were ignored because 'SDKSettings.json' could not be parsed",
171179
())

include/swift/AST/Expr.h

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3683,12 +3683,6 @@ class ClosureExpr : public AbstractClosureExpr {
36833683
SeparatelyTypeChecked,
36843684
};
36853685

3686-
/// Bits used to indicate contextual information that is concurrency-specific.
3687-
enum UnsafeConcurrencyBits {
3688-
Sendable = 1 << 0,
3689-
MainActor = 1 << 1
3690-
};
3691-
36923686
private:
36933687
/// The attributes attached to the closure.
36943688
DeclAttributes Attributes;
@@ -3703,10 +3697,7 @@ class ClosureExpr : public AbstractClosureExpr {
37033697
/// the CaptureListExpr which would normally maintain this sort of
37043698
/// information about captured variables), we need to have some way to access
37053699
/// this information directly on the ClosureExpr.
3706-
///
3707-
/// The integer indicates how the closure is contextually concurrent.
3708-
llvm::PointerIntPair<VarDecl *, 2, uint8_t>
3709-
CapturedSelfDeclAndUnsafeConcurrent;
3700+
VarDecl *CapturedSelfDecl;
37103701

37113702
/// The location of the "async", if present.
37123703
SourceLoc AsyncLoc;
@@ -3736,7 +3727,7 @@ class ClosureExpr : public AbstractClosureExpr {
37363727
: AbstractClosureExpr(ExprKind::Closure, Type(), /*Implicit=*/false,
37373728
discriminator, parent),
37383729
Attributes(attributes), BracketRange(bracketRange),
3739-
CapturedSelfDeclAndUnsafeConcurrent(capturedSelfDecl, 0),
3730+
CapturedSelfDecl(capturedSelfDecl),
37403731
AsyncLoc(asyncLoc), ThrowsLoc(throwsLoc), ArrowLoc(arrowLoc),
37413732
InLoc(inLoc),
37423733
ExplicitResultTypeAndBodyState(explicitResultType, BodyState::Parsed),
@@ -3864,27 +3855,7 @@ class ClosureExpr : public AbstractClosureExpr {
38643855

38653856
/// VarDecl captured by this closure under the literal name \c self , if any.
38663857
VarDecl *getCapturedSelfDecl() const {
3867-
return CapturedSelfDeclAndUnsafeConcurrent.getPointer();
3868-
}
3869-
3870-
bool isUnsafeSendable() const {
3871-
return CapturedSelfDeclAndUnsafeConcurrent.getInt() &
3872-
UnsafeConcurrencyBits::Sendable;
3873-
}
3874-
3875-
bool isUnsafeMainActor() const {
3876-
return CapturedSelfDeclAndUnsafeConcurrent.getInt() &
3877-
UnsafeConcurrencyBits::MainActor;
3878-
}
3879-
3880-
void setUnsafeConcurrent(bool sendable, bool forMainActor) {
3881-
uint8_t bits = 0;
3882-
if (sendable)
3883-
bits |= UnsafeConcurrencyBits::Sendable;
3884-
if (forMainActor)
3885-
bits |= UnsafeConcurrencyBits::MainActor;
3886-
3887-
CapturedSelfDeclAndUnsafeConcurrent.setInt(bits);
3858+
return CapturedSelfDecl;
38883859
}
38893860

38903861
/// Get the type checking state of this closure's body.

include/swift/AST/GenericParamList.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,6 @@ class RequirementRepr {
203203
void print(ASTPrinter &Printer) const;
204204
};
205205

206-
using GenericParamSource = PointerUnion<GenericContext *, GenericParamList *>;
207-
208206
/// GenericParamList - A list of generic parameters that is part of a generic
209207
/// function or type, along with extra requirements placed on those generic
210208
/// parameters and types derived from them.

include/swift/AST/TypeCheckRequests.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,8 @@ struct WhereClauseOwner {
459459
SpecializeAttr *, DifferentiableAttr *>
460460
source;
461461

462+
WhereClauseOwner() : dc(nullptr) {}
463+
462464
WhereClauseOwner(GenericContext *genCtx);
463465
WhereClauseOwner(AssociatedTypeDecl *atd);
464466

@@ -480,6 +482,10 @@ struct WhereClauseOwner {
480482
return llvm::hash_value(owner.source.getOpaqueValue());
481483
}
482484

485+
operator bool() const {
486+
return dc != nullptr;
487+
}
488+
483489
friend bool operator==(const WhereClauseOwner &lhs,
484490
const WhereClauseOwner &rhs) {
485491
return lhs.source.getOpaqueValue() == rhs.source.getOpaqueValue();
@@ -1437,11 +1443,12 @@ class AbstractGenericSignatureRequest :
14371443
class InferredGenericSignatureRequest :
14381444
public SimpleRequest<InferredGenericSignatureRequest,
14391445
GenericSignature (ModuleDecl *,
1440-
const GenericSignatureImpl *,
1441-
GenericParamSource,
1442-
SmallVector<Requirement, 2>,
1443-
SmallVector<TypeLoc, 2>,
1444-
bool),
1446+
const GenericSignatureImpl *,
1447+
GenericParamList *,
1448+
WhereClauseOwner,
1449+
SmallVector<Requirement, 2>,
1450+
SmallVector<TypeLoc, 2>,
1451+
bool),
14451452
RequestFlags::Cached> {
14461453
public:
14471454
using SimpleRequest::SimpleRequest;
@@ -1452,9 +1459,10 @@ class InferredGenericSignatureRequest :
14521459
// Evaluation.
14531460
GenericSignature
14541461
evaluate(Evaluator &evaluator,
1455-
ModuleDecl *module,
1462+
ModuleDecl *parentModule,
14561463
const GenericSignatureImpl *baseSignature,
1457-
GenericParamSource paramSource,
1464+
GenericParamList *genericParams,
1465+
WhereClauseOwner whereClause,
14581466
SmallVector<Requirement, 2> addedRequirements,
14591467
SmallVector<TypeLoc, 2> inferenceSources,
14601468
bool allowConcreteGenericParams) const;

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,12 @@ SWIFT_REQUEST(TypeChecker, HasImplementationOnlyImportsRequest,
131131
SWIFT_REQUEST(TypeChecker, ModuleLibraryLevelRequest,
132132
LibraryLevel(ModuleDecl *), Cached, NoLocationInfo)
133133
SWIFT_REQUEST(TypeChecker, InferredGenericSignatureRequest,
134-
GenericSignature (ModuleDecl *, const GenericSignatureImpl *,
135-
GenericParamSource,
136-
SmallVector<Requirement, 2>,
137-
SmallVector<TypeLoc, 2>, bool),
134+
GenericSignature (ModuleDecl *,
135+
const GenericSignatureImpl *,
136+
GenericParamList *,
137+
WhereClauseOwner,
138+
SmallVector<Requirement, 2>,
139+
SmallVector<TypeLoc, 2>, bool),
138140
Cached, NoLocationInfo)
139141
SWIFT_REQUEST(TypeChecker, DistributedModuleIsAvailableRequest,
140142
bool(ModuleDecl *), Cached, NoLocationInfo)

include/swift/AST/Types.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3395,8 +3395,6 @@ struct ParameterListInfo {
33953395
SmallBitVector defaultArguments;
33963396
SmallBitVector acceptsUnlabeledTrailingClosures;
33973397
SmallBitVector propertyWrappers;
3398-
SmallBitVector unsafeSendable;
3399-
SmallBitVector unsafeMainActor;
34003398
SmallBitVector implicitSelfCapture;
34013399
SmallBitVector inheritActorContext;
34023400

@@ -3417,16 +3415,6 @@ struct ParameterListInfo {
34173415
/// property wrapper.
34183416
bool hasExternalPropertyWrapper(unsigned paramIdx) const;
34193417

3420-
/// Whether the given parameter is unsafe Sendable, meaning that
3421-
/// we will treat it as Sendable in a context that has adopted concurrency
3422-
/// features.
3423-
bool isUnsafeSendable(unsigned paramIdx) const;
3424-
3425-
/// Whether the given parameter is unsafe MainActor, meaning that
3426-
/// we will treat it as being part of the main actor but that it is not
3427-
/// part of the type system.
3428-
bool isUnsafeMainActor(unsigned paramIdx) const;
3429-
34303418
/// Whether the given parameter is a closure that should allow capture of
34313419
/// 'self' to be implicit, without requiring "self.".
34323420
bool isImplicitSelfCapture(unsigned paramIdx) const;

include/swift/Option/Options.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,11 @@ def requirement_machine_protocol_signatures_EQ : Joined<["-"], "requirement-mach
620620
Flags<[FrontendOption]>,
621621
HelpText<"Control usage of experimental protocol requirement signature minimization: 'on', 'off', or 'verify'">;
622622

623+
def experimental_hermetic_seal_at_link:
624+
Flag<["-"], "experimental-hermetic-seal-at-link">,
625+
Flags<[FrontendOption, HelpHidden]>,
626+
HelpText<"Library code can assume that all clients are visible at linktime, and aggressively strip unused code">;
627+
623628
// Diagnostic control options
624629
def suppress_warnings : Flag<["-"], "suppress-warnings">,
625630
Flags<[FrontendOption]>,

include/swift/SILOptimizer/Analysis/DifferentiableActivityAnalysis.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
#define SWIFT_SILOPTIMIZER_ANALYSIS_DIFFERENTIABLEACTIVITYANALYSIS_H_
5050

5151
#include "swift/AST/GenericEnvironment.h"
52-
#include "swift/AST/GenericSignatureBuilder.h"
5352
#include "swift/SIL/SILFunction.h"
5453
#include "swift/SIL/SILModule.h"
5554
#include "swift/SIL/SILValue.h"

lib/AST/ASTDumper.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -578,11 +578,6 @@ namespace {
578578
void printAbstractTypeParamCommon(AbstractTypeParamDecl *decl,
579579
const char *name) {
580580
printCommon(decl, name);
581-
if (decl->getDeclContext()->getGenericEnvironmentOfContext()) {
582-
if (auto superclassTy = decl->getSuperclass()) {
583-
OS << " superclass='" << superclassTy->getString() << "'";
584-
}
585-
}
586581
}
587582

588583
void visitGenericTypeParamDecl(GenericTypeParamDecl *decl) {

lib/AST/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ add_swift_host_library(swiftAST STATIC
7878
RequirementMachine/GeneratingConformances.cpp
7979
RequirementMachine/GenericSignatureQueries.cpp
8080
RequirementMachine/PropertyMap.cpp
81+
RequirementMachine/PropertyUnification.cpp
8182
RequirementMachine/ProtocolGraph.cpp
8283
RequirementMachine/RequirementMachine.cpp
8384
RequirementMachine/RequirementMachineRequests.cpp

lib/AST/Decl.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7733,27 +7733,6 @@ void AbstractFunctionDecl::addDerivativeFunctionConfiguration(
77337733
DerivativeFunctionConfigs->insert(config);
77347734
}
77357735

7736-
bool AbstractFunctionDecl::hasKnownUnsafeSendableFunctionParams() const {
7737-
auto nominal = getDeclContext()->getSelfNominalTypeDecl();
7738-
if (!nominal)
7739-
return false;
7740-
7741-
// DispatchQueue operations.
7742-
auto nominalName = nominal->getName().str();
7743-
if (nominalName == "DispatchQueue") {
7744-
auto name = getBaseName().userFacingName();
7745-
return llvm::StringSwitch<bool>(name)
7746-
.Case("sync", true)
7747-
.Case("async", true)
7748-
.Case("asyncAndWait", true)
7749-
.Case("asyncAfter", true)
7750-
.Case("concurrentPerform", true)
7751-
.Default(false);
7752-
}
7753-
7754-
return false;
7755-
}
7756-
77577736
void FuncDecl::setResultInterfaceType(Type type) {
77587737
getASTContext().evaluator.cacheOutput(ResultTypeRequest{this},
77597738
std::move(type));

0 commit comments

Comments
 (0)