Skip to content

Commit d68cd3f

Browse files
authored
Merge pull request swiftlang#933 from swiftwasm/master
[pull] swiftwasm from master
2 parents 868f858 + 43cbf36 commit d68cd3f

File tree

109 files changed

+359
-153
lines changed

Some content is hidden

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

109 files changed

+359
-153
lines changed

benchmark/cmake/modules/AddSwiftBenchmarkSuite.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ function (add_swift_benchmark_library objfile_out sibfile_out swiftmodule_out)
189189
DEPENDS ${stdlib_dependencies} ${sources} ${BENCHLIB_DEPENDS}
190190
COMMAND "${SWIFT_EXEC}"
191191
${BENCHLIB_LIBRARY_FLAGS}
192-
"-force-single-frontend-invocation"
192+
"-whole-module-optimization"
193193
"-parse-as-library"
194194
"-module-name" "${module_name}"
195195
"-emit-module" "-emit-module-path" "${swiftmodule}"
@@ -209,7 +209,7 @@ function (add_swift_benchmark_library objfile_out sibfile_out swiftmodule_out)
209209
${stdlib_dependencies} ${sources} ${BENCHLIB_DEPENDS}
210210
COMMAND "${SWIFT_EXEC}"
211211
${BENCHLIB_LIBRARY_FLAGS}
212-
"-force-single-frontend-invocation"
212+
"-whole-module-optimization"
213213
"-parse-as-library"
214214
"-module-name" "${module_name}"
215215
"-emit-sib"
@@ -574,7 +574,7 @@ function (swift_benchmark_compile_archopts)
574574
${SWIFT_BENCH_SIBFILES} "${source}"
575575
COMMAND "${SWIFT_EXEC}"
576576
${common_swift4_options}
577-
"-force-single-frontend-invocation"
577+
"-whole-module-optimization"
578578
"-emit-module" "-module-name" "${module_name}"
579579
"-I" "${objdir}"
580580
"-o" "${objdir}/${module_name}.o"

benchmark/single-source/ProtocolDispatch2.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import TestsUtils
1919
public let ProtocolDispatch2 = BenchmarkInfo(
2020
name: "ProtocolDispatch2",
2121
runFunction: run_ProtocolDispatch2,
22-
tags: [.validation, .abstraction])
22+
tags: [.validation, .abstraction, .cpubench])
2323

2424
protocol Pingable { func ping() -> Int; func pong() -> Int}
2525

docs/CompilerPerformance.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ running in, and often to perform separate analysis for each mode. The
100100
significant modes are:
101101

102102
- **Primary-file** vs. **whole-module**: this varies depending on whether the
103-
driver is run with the flag `-wmo`, `-whole-module-optimization` or
104-
`-force-single-frontend-invocation` (all these options are synonymous).
103+
driver is run with the flag `-wmo` (a.k.a. `-whole-module-optimization`).
105104

106105
- **Batch** vs. **single-file** primary-file mode. This distinction refines
107106
the behaviour of primary-file mode, with the new batch mode added in the

docs/SIL.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,16 @@ generic constraints:
686686
* Class protocol types
687687
* Archetypes constrained by a class protocol
688688

689+
Values of loadable types are loaded and stored by loading and storing
690+
individual components of their representation. As a consequence:
691+
692+
* values of loadable types can be loaded into SIL SSA values and stored
693+
from SSA values into memory without running any user-written code,
694+
although compiler-generated reference counting operations can happen.
695+
696+
* values of loadable types can be take-initialized (moved between
697+
memory locations) with a bitwise copy.
698+
689699
A *loadable aggregate type* is a tuple or struct type that is loadable.
690700

691701
A *trivial type* is a loadable type with trivial value semantics.
@@ -706,6 +716,25 @@ generic constraints:
706716
* Runtime-sized types
707717
* Non-class protocol types
708718
* @weak types
719+
* Types that can't satisfy the requirements for being loadable because they
720+
care about the exact location of their value in memory and need to run some
721+
user-written code when they are copied or moved. Most commonly, types "care"
722+
about the addresses of values because addresses of values are registered in
723+
some global data structure, or because values may contain pointers into
724+
themselves. For example:
725+
726+
* Addresses of values of Swift ``@weak`` types are registered in a global
727+
table. That table needs to be adjusted when a ``@weak`` value is copied
728+
or moved to a new address.
729+
730+
* A non-COW collection type with a heap allocation (like ``std::vector`` in
731+
C++) needs to allocate memory and copy the collection elements when the
732+
collection is copied.
733+
734+
* A non-COW string type that implements a small string optimization (like
735+
many implementations of ``std::string`` in C++) can contain a pointer
736+
into the value itself. That pointer needs to be recomputed when the
737+
string is copied or moved.
709738

710739
Values of address-only type ("address-only values") must reside in
711740
memory and can only be referenced in SIL by address. Addresses of

include/swift/AST/SourceFile.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,6 @@ class SourceFile final : public FileUnit {
595595

596596
bool canBeParsedInFull() const;
597597

598-
bool isSuitableForASTScopes() const { return canBeParsedInFull(); }
599-
600598
/// Whether the bodies of types and functions within this file can be lazily
601599
/// parsed.
602600
bool hasDelayedBodyParsing() const;

include/swift/SILOptimizer/Analysis/EpilogueARCAnalysis.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,11 @@ class EpilogueARCContext {
200200
// We are checking for retain. If this is a self-recursion. call
201201
// to the function (which returns an owned value) can be treated as
202202
// the retain instruction.
203-
if (auto *AI = dyn_cast<ApplyInst>(II))
204-
if (AI->getCalleeFunction() == II->getParent()->getParent())
205-
return true;
203+
if (auto *AI = dyn_cast<ApplyInst>(II)) {
204+
return AI->getCalleeFunction() == II->getParent()->getParent() &&
205+
RCFI->getRCIdentityRoot(AI) ==
206+
RCFI->getRCIdentityRoot(getArg(AI->getParent()));
207+
}
206208
// Check whether this is a retain instruction and the argument it
207209
// retains.
208210
return isRetainInstruction(II) &&

lib/AST/ASTScopeCreation.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -768,8 +768,7 @@ bool ASTScope::areInactiveIfConfigClausesSupported() {
768768

769769
void ASTScope::expandFunctionBody(AbstractFunctionDecl *AFD) {
770770
auto *const SF = AFD->getParentSourceFile();
771-
if (SF->isSuitableForASTScopes())
772-
SF->getScope().expandFunctionBodyImpl(AFD);
771+
SF->getScope().expandFunctionBodyImpl(AFD);
773772
}
774773

775774
void ASTScope::expandFunctionBodyImpl(AbstractFunctionDecl *AFD) {

lib/AST/Decl.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3519,7 +3519,10 @@ static bool checkAccess(const DeclContext *useDC, const ValueDecl *VD,
35193519
case AccessLevel::Public:
35203520
case AccessLevel::Open: {
35213521
if (useDC && VD->isSPI()) {
3522-
auto *useSF = dyn_cast<SourceFile>(useDC->getModuleScopeContext());
3522+
auto useModuleScopeContext = useDC->getModuleScopeContext();
3523+
if (useModuleScopeContext == sourceDC->getModuleScopeContext()) return true;
3524+
3525+
auto *useSF = dyn_cast<SourceFile>(useModuleScopeContext);
35233526
return !useSF || useSF->isImportedAsSPI(VD);
35243527
}
35253528
return true;

lib/AST/Module.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2566,7 +2566,6 @@ StringRef SourceFile::getFilename() const {
25662566
}
25672567

25682568
ASTScope &SourceFile::getScope() {
2569-
assert(isSuitableForASTScopes() && "Should not be creating scope tree");
25702569
if (!Scope)
25712570
Scope = std::unique_ptr<ASTScope>(new (getASTContext()) ASTScope(this));
25722571
return *Scope.get();
@@ -2640,7 +2639,7 @@ SourceFile::getConfiguredReferencedNameTracker() const {
26402639
}
26412640

26422641
ArrayRef<OpaqueTypeDecl *> SourceFile::getOpaqueReturnTypeDecls() {
2643-
for (auto *vd : UnvalidatedDeclsWithOpaqueReturnTypes) {
2642+
for (auto *vd : UnvalidatedDeclsWithOpaqueReturnTypes.takeVector()) {
26442643
if (auto opaqueDecl = vd->getOpaqueResultTypeDecl()) {
26452644
auto inserted = ValidatedOpaqueReturnTypes.insert(
26462645
{opaqueDecl->getOpaqueReturnTypeIdentifier().str(),
@@ -2651,7 +2650,6 @@ ArrayRef<OpaqueTypeDecl *> SourceFile::getOpaqueReturnTypeDecls() {
26512650
}
26522651
}
26532652

2654-
UnvalidatedDeclsWithOpaqueReturnTypes.clear();
26552653
return OpaqueReturnTypes;
26562654
}
26572655

lib/AST/UnqualifiedLookup.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,7 @@ bool UnqualifiedLookupFactory::wouldUseASTScopesForLookupIfItWereEnabled()
571571
const {
572572
if (!Loc.isValid())
573573
return false;
574-
const auto *const SF = DC->getParentSourceFile();
575-
return SF && SF->isSuitableForASTScopes();
574+
return (bool) DC->getParentSourceFile();
576575
}
577576

578577
#pragma mark context-based lookup definitions

lib/ClangImporter/ImportDecl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3348,8 +3348,8 @@ namespace {
33483348

33493349
auto member = Impl.importDecl(nd, getActiveSwiftVersion());
33503350
if (!member) {
3351-
if (!isa<clang::TypeDecl>(nd)) {
3352-
// We don't know what this field is.
3351+
if (!isa<clang::TypeDecl>(nd) && !isa<clang::FunctionDecl>(nd)) {
3352+
// We don't know what this member is.
33533353
// Assume it may be important in C.
33543354
hasUnreferenceableStorage = true;
33553355
hasMemberwiseInitializer = false;

lib/Driver/FrontendUtil.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ bool swift::driver::getSingleFrontendInvocationFromDriverArguments(
3232

3333
// When creating a CompilerInvocation, ensure that the driver creates a single
3434
// frontend command.
35-
Args.push_back("-force-single-frontend-invocation");
35+
Args.push_back("-whole-module-optimization");
3636

3737
// Explictly disable batch mode to avoid a spurious warning when combining
38-
// -enable-batch-mode with -force-single-frontend-invocation. This is an
38+
// -enable-batch-mode with -whole-module-optimization. This is an
3939
// implementation detail.
4040
Args.push_back("-disable-batch-mode");
4141

lib/SIL/IR/AbstractionPattern.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -765,22 +765,13 @@ void AbstractionPattern::print(raw_ostream &out) const {
765765
case Kind::CurriedCFunctionAsMethodType:
766766
case Kind::PartialCurriedCFunctionAsMethodType:
767767
case Kind::CFunctionAsMethodType:
768-
case Kind::CXXMethodType:
769-
case Kind::CurriedCXXMethodType:
770-
case Kind::PartialCurriedCXXMethodType:
771768
out << (getKind() == Kind::ClangType
772769
? "AP::ClangType(" :
773770
getKind() == Kind::CurriedCFunctionAsMethodType
774771
? "AP::CurriedCFunctionAsMethodType(" :
775-
getKind() == Kind::CFunctionAsMethodType
776-
? "AP::CFunctionAsMethodType(" :
777-
getKind() == Kind::CXXMethodType
778-
? "AP::CXXMethodType(" :
779-
getKind() == Kind::CurriedCXXMethodType
780-
? "AP::CurriedCXXMethodType(" :
781-
getKind() == Kind::PartialCurriedCXXMethodType
782-
? "AP::PartialCurriedCXXMethodType("
783-
: "AP::PartialCurriedCFunctionAsMethodType(");
772+
getKind() == Kind::PartialCurriedCFunctionAsMethodType
773+
? "AP::PartialCurriedCFunctionAsMethodType("
774+
: "AP::CFunctionAsMethodType(");
784775
if (auto sig = getGenericSignature()) {
785776
sig->print(out);
786777
}
@@ -800,6 +791,23 @@ void AbstractionPattern::print(raw_ostream &out) const {
800791
}
801792
out << ")";
802793
return;
794+
case Kind::CXXMethodType:
795+
case Kind::CurriedCXXMethodType:
796+
case Kind::PartialCurriedCXXMethodType:
797+
out << (getKind() == Kind::CXXMethodType
798+
? "AP::CXXMethodType(" :
799+
getKind() == Kind::CurriedCXXMethodType
800+
? "AP::CurriedCXXMethodType("
801+
: "AP::PartialCurriedCXXMethodType");
802+
if (auto sig = getGenericSignature()) {
803+
sig->print(out);
804+
}
805+
getType().dump(out);
806+
out << ", ";
807+
getCXXMethod()->dump();
808+
assert(!hasImportAsMemberStatus());
809+
out << ")";
810+
return;
803811
case Kind::CurriedObjCMethodType:
804812
case Kind::PartialCurriedObjCMethodType:
805813
case Kind::ObjCMethodType:

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@ namespace {
184184
std::function<void(Type)> ParsedTypeCallback;
185185

186186
bool performTypeLocChecking(TypeLoc &T, bool IsSILType,
187-
GenericEnvironment *GenericEnv = nullptr,
188-
DeclContext *DC = nullptr);
187+
GenericEnvironment *GenericEnv = nullptr);
189188

190189
void convertRequirements(SILFunction *F, ArrayRef<RequirementRepr> From,
191190
SmallVectorImpl<Requirement> &To);
@@ -1105,19 +1104,13 @@ static bool parseDeclSILOptional(bool *isTransparent,
11051104
}
11061105

11071106
bool SILParser::performTypeLocChecking(TypeLoc &T, bool IsSILType,
1108-
GenericEnvironment *GenericEnv,
1109-
DeclContext *DC) {
1107+
GenericEnvironment *GenericEnv) {
11101108
if (GenericEnv == nullptr)
11111109
GenericEnv = ContextGenericEnv;
11121110

1113-
if (!DC)
1114-
DC = &P.SF;
1115-
else if (!GenericEnv)
1116-
GenericEnv = DC->getGenericEnvironmentOfContext();
1117-
11181111
return swift::performTypeLocChecking(P.Context, T,
11191112
/*isSILMode=*/true, IsSILType,
1120-
GenericEnv, DC);
1113+
GenericEnv, &P.SF);
11211114
}
11221115

11231116
/// Find the top-level ValueDecl or Module given a name.
@@ -1712,8 +1705,7 @@ bool SILParser::parseSubstitutions(SmallVectorImpl<ParsedSubstitution> &parsed,
17121705
TypeLoc Ty = TyR.get();
17131706
if (defaultForProto)
17141707
bindProtocolSelfInTypeRepr(Ty, defaultForProto);
1715-
if (performTypeLocChecking(Ty, /*IsSILType=*/ false, GenericEnv,
1716-
defaultForProto))
1708+
if (performTypeLocChecking(Ty, /*IsSILType=*/ false, GenericEnv))
17171709
return true;
17181710
parsed.push_back({Loc, Ty.getType()});
17191711
} while (P.consumeIf(tok::comma));
@@ -6268,6 +6260,8 @@ ProtocolConformanceRef SILParser::parseProtocolConformance(
62686260
auto *genericParams = P.maybeParseGenericParams().getPtrOrNull();
62696261
if (genericParams) {
62706262
genericEnv = handleSILGenericParams(genericParams, &P.SF);
6263+
} else if (defaultForProto) {
6264+
genericEnv = defaultForProto->getGenericEnvironment();
62716265
}
62726266

62736267
auto retVal = parseProtocolConformanceHelper(proto, genericEnv, context,
@@ -6291,8 +6285,7 @@ ProtocolConformanceRef SILParser::parseProtocolConformanceHelper(
62916285
bindProtocolSelfInTypeRepr(Ty, defaultForProto);
62926286
}
62936287

6294-
if (performTypeLocChecking(Ty, /*IsSILType=*/ false, witnessEnv,
6295-
defaultForProto))
6288+
if (performTypeLocChecking(Ty, /*IsSILType=*/ false, witnessEnv))
62966289
return ProtocolConformanceRef();
62976290
auto ConformingTy = Ty.getType();
62986291

lib/SILOptimizer/Transforms/DeadStoreElimination.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ static bool isDeadStoreInertInstruction(SILInstruction *Inst) {
161161
case SILInstructionKind::DeallocRefInst:
162162
case SILInstructionKind::CondFailInst:
163163
case SILInstructionKind::FixLifetimeInst:
164+
case SILInstructionKind::EndAccessInst:
165+
case SILInstructionKind::SetDeallocatingInst:
164166
return true;
165167
default:
166168
return false;

lib/SILOptimizer/Transforms/RedundantLoadElimination.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ static bool isRLEInertInstruction(SILInstruction *Inst) {
160160
case SILInstructionKind::IsEscapingClosureInst:
161161
case SILInstructionKind::IsUniqueInst:
162162
case SILInstructionKind::FixLifetimeInst:
163+
case SILInstructionKind::EndAccessInst:
164+
case SILInstructionKind::SetDeallocatingInst:
165+
case SILInstructionKind::DeallocRefInst:
163166
return true;
164167
default:
165168
return false;

lib/Sema/ConstraintSystem.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3505,6 +3505,12 @@ void constraints::simplifyLocator(ASTNode &anchor,
35053505
continue;
35063506
}
35073507

3508+
case ConstraintLocator::KeyPathDynamicMember: {
3509+
// Key path dynamic member lookup should be completely transparent.
3510+
path = path.slice(1);
3511+
continue;
3512+
}
3513+
35083514
default:
35093515
// FIXME: Lots of other cases to handle.
35103516
break;

lib/Sema/TypeChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ TypeCheckSourceFileRequest::evaluate(Evaluator &eval, SourceFile *SF) const {
320320
// scope-based lookups. Only the top-level scopes because extensions have not
321321
// been bound yet.
322322
auto &Ctx = SF->getASTContext();
323-
if (Ctx.LangOpts.EnableASTScopeLookup && SF->isSuitableForASTScopes())
323+
if (Ctx.LangOpts.EnableASTScopeLookup)
324324
SF->getScope()
325325
.buildEnoughOfTreeForTopLevelExpressionsButDontRequestGenericsOrExtendedNominals();
326326

stdlib/cmake/modules/SwiftSource.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function(handle_swift_sources
9090

9191
# FIXME: We shouldn't /have/ to build things in a single process.
9292
# <rdar://problem/15972329>
93-
list(APPEND swift_compile_flags "-force-single-frontend-invocation")
93+
list(APPEND swift_compile_flags "-whole-module-optimization")
9494

9595
_compile_swift_files(
9696
dependency_target

stdlib/public/SwiftShims/RefCount.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ class RefCountBitsT {
546546
// Returns true if the increment is a fast-path result.
547547
// Returns false if the increment should fall back to some slow path
548548
// (for example, because UseSlowRC is set or because the refcount overflowed).
549-
LLVM_NODISCARD SWIFT_ALWAYS_INLINE bool
549+
SWIFT_NODISCARD SWIFT_ALWAYS_INLINE bool
550550
incrementStrongExtraRefCount(uint32_t inc) {
551551
// This deliberately overflows into the UseSlowRC field.
552552
bits += BitsType(inc) << Offsets::StrongExtraRefCountShift;
@@ -557,7 +557,7 @@ class RefCountBitsT {
557557
// Returns false if the decrement should fall back to some slow path
558558
// (for example, because UseSlowRC is set
559559
// or because the refcount is now zero and should deinit).
560-
LLVM_NODISCARD SWIFT_ALWAYS_INLINE bool
560+
SWIFT_NODISCARD SWIFT_ALWAYS_INLINE bool
561561
decrementStrongExtraRefCount(uint32_t dec) {
562562
#ifndef NDEBUG
563563
if (!hasSideTable() && !isImmortal(false)) {
@@ -1409,8 +1409,8 @@ class HeapObjectSideTableEntry {
14091409

14101410

14111411
// WEAK
1412-
1413-
LLVM_NODISCARD
1412+
1413+
SWIFT_NODISCARD
14141414
HeapObjectSideTableEntry* incrementWeak() {
14151415
// incrementWeak need not be atomic w.r.t. concurrent deinit initiation.
14161416
// The client can't actually get a reference to the object without

stdlib/public/SwiftShims/Visibility.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,14 @@
149149
#define SWIFT_FALLTHROUGH
150150
#endif
151151

152+
#if __cplusplus >= 201402l && __has_cpp_attribute(nodiscard)
153+
#define SWIFT_NODISCARD [[nodiscard]]
154+
#elif __has_cpp_attribute(clang::warn_unused_result)
155+
#define SWIFT_NODISCARD [[clang::warn_unused_result]]
156+
#else
157+
#define SWIFT_NODISCARD
158+
#endif
159+
152160

153161
/// Attributes for runtime-stdlib interfaces.
154162
/// Use these for C implementations that are imported into Swift via SwiftShims

0 commit comments

Comments
 (0)