Skip to content

Commit f79fd45

Browse files
Merge pull request #1411 from swiftwasm/master
[pull] swiftwasm from master
2 parents 7ba2f72 + 241c5d9 commit f79fd45

File tree

84 files changed

+1386
-1233
lines changed

Some content is hidden

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

84 files changed

+1386
-1233
lines changed

include/swift/AST/SILOptions.h

-5
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ class SILOptions {
4040
/// Controls the aggressiveness of the loop unroller.
4141
int UnrollThreshold = 250;
4242

43-
/// Controls whether to pull in SIL from partial modules during the
44-
/// merge modules step. Could perhaps be merged with the link mode
45-
/// above but the interactions between all the flags are tricky.
46-
bool MergePartialModules = false;
47-
4843
/// Remove all runtime assertions during optimizations.
4944
bool RemoveRuntimeAsserts = false;
5045

include/swift/AST/TypeCheckRequests.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -2444,7 +2444,7 @@ class HasImplementationOnlyImportsRequest
24442444

24452445
class ResolveTypeRequest
24462446
: public SimpleRequest<ResolveTypeRequest,
2447-
Type(TypeResolution *, TypeRepr *),
2447+
Type(const TypeResolution *, TypeRepr *),
24482448
RequestFlags::Uncached> {
24492449
public:
24502450
using SimpleRequest::SimpleRequest;
@@ -2457,7 +2457,7 @@ class ResolveTypeRequest
24572457
friend SimpleRequest;
24582458

24592459
// Evaluation.
2460-
Type evaluate(Evaluator &evaluator, TypeResolution *resolution,
2460+
Type evaluate(Evaluator &evaluator, const TypeResolution *resolution,
24612461
TypeRepr *repr) const;
24622462
};
24632463

include/swift/AST/TypeCheckerTypeIDZone.def

+2-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ SWIFT_REQUEST(TypeChecker, ResolveTypeEraserTypeRequest,
240240
Type(ProtocolDecl *, TypeEraserAttr *),
241241
SeparatelyCached, NoLocationInfo)
242242
SWIFT_REQUEST(TypeChecker, ResolveTypeRequest,
243-
Type (TypeResolution *, TypeRepr *), Uncached, NoLocationInfo)
243+
Type (const TypeResolution *, TypeRepr *),
244+
Uncached, NoLocationInfo)
244245
SWIFT_REQUEST(TypeChecker, SPIGroupsRequest,
245246
llvm::ArrayRef<Identifier>(Decl *),
246247
Cached, NoLocationInfo)

include/swift/ClangImporter/BuiltinMappedTypes.def

+14-5
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,32 @@
2121
// - CLANG_BUILTIN_KIND is the kind of builtin type, clang::BuiltinType
2222
// - SWIFT_TYPE_NAME is the name of the corresponding stdlib type.
2323
//
24+
// MAP_BUILTIN_CCHAR_TYPE(CLANG_BUILTIN_KIND, SWIFT_TYPE_NAME)
25+
// - CLANG_BUILTIN_KIND is the kind of builtin type, clang::BuiltinType
26+
// - SWIFT_TYPE_NAME is the name of the corresponding stdlib type.
27+
//
2428
//===----------------------------------------------------------------------===//
2529

2630
#ifndef MAP_BUILTIN_INTEGER_TYPE
2731
#define MAP_BUILTIN_INTEGER_TYPE(CLANG, SWIFT) MAP_BUILTIN_TYPE(CLANG, SWIFT)
2832
#endif
2933

34+
#ifndef MAP_BUILTIN_CCHAR_TYPE
35+
#define MAP_BUILTIN_CCHAR_TYPE(CLANG, SWIFT) MAP_BUILTIN_TYPE(CLANG, SWIFT)
36+
#endif
37+
38+
MAP_BUILTIN_CCHAR_TYPE(Char_U, CChar)
39+
MAP_BUILTIN_CCHAR_TYPE(Char_S, CChar)
40+
MAP_BUILTIN_CCHAR_TYPE(WChar_S, CWideChar)
41+
MAP_BUILTIN_CCHAR_TYPE(WChar_U, CWideChar)
42+
3043
MAP_BUILTIN_TYPE(Bool, CBool)
31-
MAP_BUILTIN_INTEGER_TYPE(Char_U, CChar)
32-
MAP_BUILTIN_INTEGER_TYPE(Char_S, CChar)
3344
MAP_BUILTIN_INTEGER_TYPE(UChar, CUnsignedChar)
3445
MAP_BUILTIN_INTEGER_TYPE(UShort, CUnsignedShort)
3546
MAP_BUILTIN_INTEGER_TYPE(UInt, CUnsignedInt)
3647
MAP_BUILTIN_INTEGER_TYPE(ULong, CUnsignedLong)
3748
MAP_BUILTIN_INTEGER_TYPE(ULongLong, CUnsignedLongLong)
3849
MAP_BUILTIN_INTEGER_TYPE(UInt128, CUnsignedInt128)
39-
MAP_BUILTIN_INTEGER_TYPE(WChar_S, CWideChar)
40-
MAP_BUILTIN_INTEGER_TYPE(WChar_U, CWideChar)
4150
MAP_BUILTIN_INTEGER_TYPE(Char16, CChar16)
4251
MAP_BUILTIN_INTEGER_TYPE(Char32, CChar32)
4352
MAP_BUILTIN_INTEGER_TYPE(SChar, CSignedChar)
@@ -54,4 +63,4 @@ MAP_BUILTIN_TYPE(LongDouble, CLongDouble)
5463

5564
#undef MAP_BUILTIN_TYPE
5665
#undef MAP_BUILTIN_INTEGER_TYPE
57-
66+
#undef MAP_BUILTIN_CCHAR_TYPE

include/swift/Option/FrontendOptions.td

+2-1
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,9 @@ def sil_unroll_threshold : Separate<["-"], "sil-unroll-threshold">,
554554
MetaVarName<"<250>">,
555555
HelpText<"Controls the aggressiveness of loop unrolling">;
556556

557+
// FIXME: This option is now redundant and should eventually be removed.
557558
def sil_merge_partial_modules : Flag<["-"], "sil-merge-partial-modules">,
558-
HelpText<"Merge SIL from all partial swiftmodules into the final module">;
559+
Alias<merge_modules>;
559560

560561
def sil_verify_all : Flag<["-"], "sil-verify-all">,
561562
HelpText<"Verify SIL after each transform">;

include/swift/SIL/SILModule.h

-4
Original file line numberDiff line numberDiff line change
@@ -561,10 +561,6 @@ class SILModule {
561561
/// i.e. it can be linked by linkFunction.
562562
bool hasFunction(StringRef Name);
563563

564-
/// Link all definitions in all segments that are logically part of
565-
/// the same AST module.
566-
void linkAllFromCurrentModule();
567-
568564
/// Look up the SILWitnessTable representing the lowering of a protocol
569565
/// conformance, and collect the substitutions to apply to the referenced
570566
/// witnesses, if any.

include/swift/Serialization/SerializedSILLoader.h

-4
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@ class SerializedSILLoader {
7474

7575
bool invalidateFunction(SILFunction *F);
7676

77-
/// Deserialize all SILFunctions, VTables, and WitnessTables in all
78-
/// SILModules.
79-
void getAll();
80-
8177
/// Deserialize all SILFunctions, VTables, and WitnessTables for
8278
/// a given Module.
8379
///

lib/ClangImporter/ClangImporter.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -2908,11 +2908,12 @@ void ClangModuleUnit::lookupValue(DeclName name, NLKind lookupKind,
29082908
bool ClangImporter::Implementation::isVisibleClangEntry(
29092909
const clang::NamedDecl *clangDecl) {
29102910
// For a declaration, check whether the declaration is hidden.
2911-
if (!clangDecl->isHidden()) return true;
2911+
clang::Sema &clangSema = getClangSema();
2912+
if (clangSema.isVisible(clangDecl)) return true;
29122913

29132914
// Is any redeclaration visible?
29142915
for (auto redecl : clangDecl->redecls()) {
2915-
if (!cast<clang::NamedDecl>(redecl)->isHidden()) return true;
2916+
if (clangSema.isVisible(cast<clang::NamedDecl>(redecl))) return true;
29162917
}
29172918

29182919
return false;
@@ -3023,8 +3024,10 @@ void ClangImporter::loadExtensions(NominalTypeDecl *nominal,
30233024
SmallVector<clang::NamedDecl *, 4> DelayedCategories;
30243025

30253026
// Simply importing the categories adds them to the list of extensions.
3026-
for (const auto *Cat : objcClass->visible_categories()) {
3027-
Impl.importDeclReal(Cat, Impl.CurrentVersion);
3027+
for (const auto *Cat : objcClass->known_categories()) {
3028+
if (getClangSema().isVisible(Cat)) {
3029+
Impl.importDeclReal(Cat, Impl.CurrentVersion);
3030+
}
30283031
}
30293032
}
30303033

lib/ClangImporter/ImportDecl.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -7097,9 +7097,12 @@ void SwiftDeclConverter::importMirroredProtocolMembers(
70977097
return;
70987098

70997099
bool inNearbyCategory =
7100-
std::any_of(interfaceDecl->visible_categories_begin(),
7101-
interfaceDecl->visible_categories_end(),
7100+
std::any_of(interfaceDecl->known_categories_begin(),
7101+
interfaceDecl->known_categories_end(),
71027102
[=](const clang::ObjCCategoryDecl *category) -> bool {
7103+
if (!Impl.getClangSema().isVisible(category)) {
7104+
return false;
7105+
}
71037106
if (category != decl) {
71047107
auto *categoryModule =
71057108
Impl.getClangModuleForDecl(category);

lib/ClangImporter/ImportType.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,9 @@ namespace {
236236
case clang::BuiltinType::CLANG_BUILTIN_KIND: \
237237
return unwrapCType(Impl.getNamedSwiftType(Impl.getStdlibModule(), \
238238
#SWIFT_TYPE_NAME));
239-
239+
#define MAP_BUILTIN_CCHAR_TYPE(CLANG_BUILTIN_KIND, SWIFT_TYPE_NAME) \
240+
case clang::BuiltinType::CLANG_BUILTIN_KIND: \
241+
return Impl.getNamedSwiftType(Impl.getStdlibModule(), #SWIFT_TYPE_NAME);
240242
#include "swift/ClangImporter/BuiltinMappedTypes.def"
241243

242244
// Types that cannot be mapped into Swift, and probably won't ever be.

lib/Frontend/CompilerInvocation.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -1036,9 +1036,6 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
10361036
if (FEOpts.RequestedAction == FrontendOptions::ActionType::EmitModuleOnly)
10371037
Opts.StopOptimizationAfterSerialization = true;
10381038

1039-
if (Args.hasArg(OPT_sil_merge_partial_modules))
1040-
Opts.MergePartialModules = true;
1041-
10421039
// Propagate the typechecker's understanding of
10431040
// -experimental-skip-non-inlinable-function-bodies to SIL.
10441041
Opts.SkipNonInlinableFunctionBodies = TCOpts.SkipNonInlinableFunctionBodies;

lib/Frontend/Frontend.cpp

+6-11
Original file line numberDiff line numberDiff line change
@@ -982,22 +982,17 @@ void CompilerInstance::freeASTContext() {
982982
/// Perform "stable" optimizations that are invariant across compiler versions.
983983
static bool performMandatorySILPasses(CompilerInvocation &Invocation,
984984
SILModule *SM) {
985+
// Don't run diagnostic passes at all when merging modules.
985986
if (Invocation.getFrontendOptions().RequestedAction ==
986987
FrontendOptions::ActionType::MergeModules) {
987-
// Don't run diagnostic passes at all.
988-
} else if (!Invocation.getDiagnosticOptions().SkipDiagnosticPasses) {
989-
if (runSILDiagnosticPasses(*SM))
990-
return true;
991-
} else {
988+
return false;
989+
}
990+
if (Invocation.getDiagnosticOptions().SkipDiagnosticPasses) {
992991
// Even if we are not supposed to run the diagnostic passes, we still need
993992
// to run the ownership evaluator.
994-
if (runSILOwnershipEliminatorPass(*SM))
995-
return true;
993+
return runSILOwnershipEliminatorPass(*SM);
996994
}
997-
998-
if (Invocation.getSILOptions().MergePartialModules)
999-
SM->linkAllFromCurrentModule();
1000-
return false;
995+
return runSILDiagnosticPasses(*SM);
1001996
}
1002997

1003998
/// Perform SIL optimization passes if optimizations haven't been disabled.

lib/SIL/IR/SILModule.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -427,11 +427,6 @@ bool SILModule::hasFunction(StringRef Name) {
427427
return getSILLoader()->hasSILFunction(Name);
428428
}
429429

430-
void SILModule::linkAllFromCurrentModule() {
431-
getSILLoader()->getAllForModule(getSwiftModule()->getName(),
432-
/*PrimaryFile=*/nullptr);
433-
}
434-
435430
void SILModule::invalidateSILLoaderCaches() {
436431
getSILLoader()->invalidateCaches();
437432
}

lib/SIL/Verifier/SILVerifier.cpp

+4-10
Original file line numberDiff line numberDiff line change
@@ -1751,8 +1751,9 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
17511751
"[dynamically_replaceable] function");
17521752

17531753
// In canonical SIL, direct reference to a shared_external declaration
1754-
// is an error; we should have deserialized a body. In raw SIL, we may
1755-
// not have deserialized the body yet.
1754+
// is an error; we should have deserialized a body. In raw SIL, including
1755+
// the merge-modules phase, we may not have deserialized the body yet as we
1756+
// may not have run the SILLinker pass.
17561757
if (F.getModule().getStage() >= SILStage::Canonical) {
17571758
if (RefF->isExternalDeclaration()) {
17581759
require(SingleFunction ||
@@ -5560,20 +5561,13 @@ void SILModule::verify() const {
55605561
// Uniquing set to catch symbol name collisions.
55615562
llvm::DenseSet<StringRef> symbolNames;
55625563

5563-
// When merging partial modules, we only link functions from the current
5564-
// module, without enabling "LinkAll" mode or running the SILLinker pass;
5565-
// in this case, we need to relax some of the checks.
5566-
bool SingleFunction = false;
5567-
if (getOptions().MergePartialModules)
5568-
SingleFunction = true;
5569-
55705564
// Check all functions.
55715565
for (const SILFunction &f : *this) {
55725566
if (!symbolNames.insert(f.getName()).second) {
55735567
llvm::errs() << "Symbol redefined: " << f.getName() << "!\n";
55745568
assert(false && "triggering standard assertion failure routine");
55755569
}
5576-
f.verify(SingleFunction);
5570+
f.verify(/*singleFunction*/ false);
55775571
}
55785572

55795573
// Check all globals.

lib/SILGen/SILGen.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -1928,12 +1928,12 @@ ASTLoweringRequest::evaluate(Evaluator &evaluator,
19281928
}
19291929

19301930
// Also make sure to process any intermediate files that may contain SIL.
1931-
bool hasSIB = llvm::any_of(desc.getFiles(), [](const FileUnit *File) -> bool {
1932-
auto *SASTF = dyn_cast<SerializedASTFile>(File);
1933-
return SASTF && SASTF->isSIB();
1934-
});
1935-
if (hasSIB) {
1936-
auto primary = desc.context.dyn_cast<FileUnit *>();
1931+
bool shouldDeserialize =
1932+
llvm::any_of(desc.getFiles(), [](const FileUnit *File) -> bool {
1933+
return isa<SerializedASTFile>(File);
1934+
});
1935+
if (shouldDeserialize) {
1936+
auto *primary = desc.context.dyn_cast<FileUnit *>();
19371937
silMod->getSILLoader()->getAllForModule(silMod->getSwiftModule()->getName(),
19381938
primary);
19391939
}

lib/SILOptimizer/IPO/EagerSpecializer.cpp

+21-14
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212
///
13+
/// \file
14+
///
1315
/// Eager Specializer
1416
/// -----------------
1517
///
@@ -25,8 +27,11 @@
2527
///
2628
/// TODO: We have not determined whether to support inexact type checks. It
2729
/// will be a tradeoff between utility of the attribute vs. cost of the check.
30+
///
31+
//===----------------------------------------------------------------------===//
2832

2933
#define DEBUG_TYPE "eager-specializer"
34+
3035
#include "swift/AST/GenericEnvironment.h"
3136
#include "swift/AST/Type.h"
3237
#include "swift/SIL/SILFunction.h"
@@ -36,7 +41,6 @@
3641
#include "llvm/Support/Debug.h"
3742

3843
using namespace swift;
39-
using llvm::dbgs;
4044

4145
// Temporary flag.
4246
llvm::cl::opt<bool> EagerSpecializeFlag(
@@ -650,7 +654,8 @@ emitArgumentConversion(SmallVectorImpl<SILValue> &CallArgs) {
650654
unsigned ArgIdx = OrigArg->getIndex();
651655

652656
auto CastArg = emitArgumentCast(SubstitutedType, OrigArg, ArgIdx);
653-
LLVM_DEBUG(dbgs() << " Cast generic arg: "; CastArg->print(dbgs()));
657+
LLVM_DEBUG(llvm::dbgs() << " Cast generic arg: ";
658+
CastArg->print(llvm::dbgs()));
654659

655660
if (!substConv.useLoweredAddresses()) {
656661
CallArgs.push_back(CastArg);
@@ -710,16 +715,15 @@ static SILFunction *eagerSpecialize(SILOptFunctionBuilder &FuncBuilder,
710715
SILFunction *GenericFunc,
711716
const SILSpecializeAttr &SA,
712717
const ReabstractionInfo &ReInfo) {
713-
LLVM_DEBUG(dbgs() << "Specializing " << GenericFunc->getName() << "\n");
718+
LLVM_DEBUG(llvm::dbgs() << "Specializing " << GenericFunc->getName() << "\n");
714719

715720
LLVM_DEBUG(auto FT = GenericFunc->getLoweredFunctionType();
716-
dbgs() << " Generic Sig:";
717-
dbgs().indent(2); FT->getInvocationGenericSignature()->print(dbgs());
718-
dbgs() << " Generic Env:";
719-
dbgs().indent(2);
720-
GenericFunc->getGenericEnvironment()->dump(dbgs());
721-
dbgs() << " Specialize Attr:";
722-
SA.print(dbgs()); dbgs() << "\n");
721+
llvm::dbgs() << " Generic Sig:"; llvm::dbgs().indent(2);
722+
FT->getInvocationGenericSignature()->print(llvm::dbgs());
723+
llvm::dbgs() << " Generic Env:"; llvm::dbgs().indent(2);
724+
GenericFunc->getGenericEnvironment()->dump(llvm::dbgs());
725+
llvm::dbgs() << " Specialize Attr:"; SA.print(llvm::dbgs());
726+
llvm::dbgs() << "\n");
723727

724728
GenericFuncSpecializer
725729
FuncSpecializer(FuncBuilder, GenericFunc,
@@ -728,7 +732,7 @@ static SILFunction *eagerSpecialize(SILOptFunctionBuilder &FuncBuilder,
728732

729733
SILFunction *NewFunc = FuncSpecializer.trySpecialization();
730734
if (!NewFunc)
731-
LLVM_DEBUG(dbgs() << " Failed. Cannot specialize function.\n");
735+
LLVM_DEBUG(llvm::dbgs() << " Failed. Cannot specialize function.\n");
732736
return NewFunc;
733737
}
734738

@@ -744,11 +748,12 @@ void EagerSpecializerTransform::run() {
744748
// TODO: we should support ownership here but first we'll have to support
745749
// ownership in GenericFuncSpecializer.
746750
if (!F.shouldOptimize() || F.hasOwnership()) {
747-
LLVM_DEBUG(dbgs() << " Cannot specialize function " << F.getName()
748-
<< " because it has ownership or is marked to be "
749-
"excluded from optimizations.\n");
751+
LLVM_DEBUG(llvm::dbgs() << " Cannot specialize function " << F.getName()
752+
<< " because it has ownership or is marked to be "
753+
"excluded from optimizations.\n");
750754
continue;
751755
}
756+
752757
// Only specialize functions in their home module.
753758
if (F.isExternalDeclaration() || F.isAvailableExternally())
754759
continue;
@@ -786,11 +791,13 @@ void EagerSpecializerTransform::run() {
786791
EagerDispatch(&F, ReInfo).emitDispatchTo(NewFunc);
787792
}
788793
});
794+
789795
// Invalidate everything since we delete calls as well as add new
790796
// calls and branches.
791797
if (Changed) {
792798
invalidateAnalysis(&F, SILAnalysis::InvalidationKind::Everything);
793799
}
800+
794801
// As specializations are created, the attributes should be removed.
795802
F.clearSpecializeAttrs();
796803
}

0 commit comments

Comments
 (0)