From 8b3cdb4b12c632ee430f4ad234cf2ff6e013463a Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Fri, 10 Jan 2020 11:31:35 -0800 Subject: [PATCH 01/27] Mention where LLVM commits should go to in the branches document --- docs/Branches.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/Branches.md b/docs/Branches.md index edd871fe00b..886345cf0b0 100644 --- a/docs/Branches.md +++ b/docs/Branches.md @@ -56,7 +56,13 @@ You can use any of the branch names as the argument to `--scheme`, such as `mast - Swift: new commits go to `master` -- LLVM Project: new commits go to `swift/master-next` +- LLVM Project (Non-lldb commits): New commits go to `master` in the upstream [llvm-project](https://github.com/llvm/llvm-project). + + ... then these commits can be cherry-picked to an appropriate, `swift/master` aligned `apple/stable/*` branch in Apple's fork of [llvm-project](https://github.com/apple/llvm-project). Please see + [Apple's branching scheme](https://github.com/apple/llvm-project/blob/apple/master/apple-docs/AppleBranchingScheme.md) + document to determine which `apple/stable/*` branch you should cherry-pick to. + +- LLVM Project (LLDB commits): new commits go to `swift/master-next` ...then cherry-pick to the release branch (`swift/swift-x.y-branch`) if necessary, following the appropriate release process. (Usually this means filling out a standard template, finding someone to review your code if that hasn't already happened, and getting approval from that repo's *release manager.)* From 9c9528ab1db02ea6ad94c447c14e336e957e83cf Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Fri, 10 Jan 2020 13:13:38 -0800 Subject: [PATCH 02/27] Mention specifically the Swift/vs non Swift llvm-project changes --- docs/Branches.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/Branches.md b/docs/Branches.md index 886345cf0b0..e533c3af5e3 100644 --- a/docs/Branches.md +++ b/docs/Branches.md @@ -56,15 +56,17 @@ You can use any of the branch names as the argument to `--scheme`, such as `mast - Swift: new commits go to `master` -- LLVM Project (Non-lldb commits): New commits go to `master` in the upstream [llvm-project](https://github.com/llvm/llvm-project). +- LLVM Project: the destination branch depends on the kind of change that must be made: + + 1) LLVM Project changes that don't depend on Swift: New commits go to `master` in the upstream [llvm-project](https://github.com/llvm/llvm-project). ... then these commits can be cherry-picked to an appropriate, `swift/master` aligned `apple/stable/*` branch in Apple's fork of [llvm-project](https://github.com/apple/llvm-project). Please see [Apple's branching scheme](https://github.com/apple/llvm-project/blob/apple/master/apple-docs/AppleBranchingScheme.md) document to determine which `apple/stable/*` branch you should cherry-pick to. -- LLVM Project (LLDB commits): new commits go to `swift/master-next` + 2) Changes that depend on Swift (this only applies to LLDB): new commits go to `swift/master-next` -...then cherry-pick to the release branch (`swift/swift-x.y-branch`) if necessary, following the appropriate release process. (Usually this means filling out a standard template, finding someone to review your code if that hasn't already happened, and getting approval from that repo's *release manager.)* + ...then cherry-pick to the release branch (`swift/swift-x.y-branch`) if necessary, following the appropriate release process. (Usually this means filling out a standard template, finding someone to review your code if that hasn't already happened, and getting approval from that repo's *release manager.)* ## Automerging From ec70a40205396a9bd9e0310b3b81b4b41838976a Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Mon, 13 Jan 2020 17:47:47 -0800 Subject: [PATCH 03/27] [CodeCompletion] Disable module system headers validation This validation may call many `stat(2)`. Since we don't expect system files are edited. Disable it for code completion, even if they are edited, they are validated when the user manually build the project. rdar://problem/58550697 --- lib/IDE/CompletionInstance.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/IDE/CompletionInstance.cpp b/lib/IDE/CompletionInstance.cpp index 632a3b5f654..44dbf98a3fa 100644 --- a/lib/IDE/CompletionInstance.cpp +++ b/lib/IDE/CompletionInstance.cpp @@ -324,6 +324,11 @@ bool swift::ide::CompletionInstance::performOperation( // source text. That breaks an invariant of syntax tree building. Invocation.getLangOptions().BuildSyntaxTree = false; + // This validation may call stat(2) many times. Disable it to prevent + // performance regression. + Invocation.getSearchPathOptions().DisableModulesValidateSystemDependencies = + true; + // FIXME: ASTScopeLookup doesn't support code completion yet. Invocation.disableASTScopeLookup(); From 61872fa948f83efe31b911f3277e271d672d8b0d Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Mon, 13 Jan 2020 23:57:50 -0500 Subject: [PATCH 04/27] IRGen: Don't use the demangler to realize imported Objective-C class metadata for now Recently we started using the runtime demangler to realize imported Objective-C class metadata, to save on code size since no metadata accessor function needs to be emitted in this case. This introduced a regression where OBJC_CLASSREF symbols were no longer being emitted in some cases, which breaks autolinking. The fix for this was tracked by rdar://56136123, but unfortunately had to be reverted because it caused other problems. Until the original fix can be re-applied, let's put in a temporary workaround where we avoid going through the runtime demangler for imported Objective-C classes. This regresses code size but unblocks everyone involved, until the fix for the demangling code path (824752547129f0cfdbbfd358a164031a9024972d) can be re-applied. Fixes . --- lib/IRGen/MetadataRequest.cpp | 5 +---- test/IRGen/access_type_metadata_by_mangled_name_objc.swift | 3 ++- test/IRGen/objc_types_as_member.sil | 6 ++++-- ...struct-inmodule-1argument-clang_node-1distinct_use.swift | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/IRGen/MetadataRequest.cpp b/lib/IRGen/MetadataRequest.cpp index 75926952f8a..3d8385d7db6 100644 --- a/lib/IRGen/MetadataRequest.cpp +++ b/lib/IRGen/MetadataRequest.cpp @@ -2137,10 +2137,7 @@ static bool shouldAccessByMangledName(IRGenModule &IGM, CanType type) { if (auto nom = dyn_cast(type)) { if (!isa(nom->getDecl()) && (!nom->getDecl()->isGenericContext() - || nom->getDecl()->getGenericSignature()->areAllParamsConcrete()) - && (!nom->getClassOrBoundGenericClass() - || !nom->getClassOrBoundGenericClass()->hasClangNode() - || nom->getClassOrBoundGenericClass()->isForeign())) { + || nom->getDecl()->getGenericSignature()->areAllParamsConcrete())) { return false; } } diff --git a/test/IRGen/access_type_metadata_by_mangled_name_objc.swift b/test/IRGen/access_type_metadata_by_mangled_name_objc.swift index 3322426d97d..68b1d646733 100644 --- a/test/IRGen/access_type_metadata_by_mangled_name_objc.swift +++ b/test/IRGen/access_type_metadata_by_mangled_name_objc.swift @@ -12,7 +12,8 @@ public func test() { var x: Any.Type // Access ObjC classes by mangled name. - // CHECK: @"$sSo8NSObjectCMD" + // FIXME: Disabled for now. + // CHECK: @"$sSo8NSObjectCMa" x = NSObject.self // Use the metadata accessor for CF classes that already has to exist. diff --git a/test/IRGen/objc_types_as_member.sil b/test/IRGen/objc_types_as_member.sil index 6d72b62786c..013f006b943 100644 --- a/test/IRGen/objc_types_as_member.sil +++ b/test/IRGen/objc_types_as_member.sil @@ -9,8 +9,10 @@ import gizmo sil @use_metatype : $@convention(thin) (@thin T.Type) -> () // CHECK-LABEL: define swiftcc void @test(%TSo014OuterTypeInnerB0C* swiftself, %swift.type* %Self, i8** %SelfWitnessTable) -// CHECK: [[TMP:%.*]] = call {{.*}}@"$sSo9OuterTypeCMD" -// CHECK: call swiftcc void @use_metatype(%swift.type* [[TMP]]) +// FIXME: Metadata realization via demangling is disabled for now +// CHECK: [[TMP:%.*]] = call swiftcc %swift.metadata_response @"$sSo9OuterTypeCMa" +// CHECK: [[METADATA:%.*]] = extractvalue %swift.metadata_response %1, 0 +// CHECK: call swiftcc void @use_metatype(%swift.type* [[METADATA]]) // CHECK: ret void sil @test : $@convention(witness_method: NSRuncing) (@guaranteed OuterType.InnerType) -> () { diff --git a/test/IRGen/prespecialized-metadata/struct-inmodule-1argument-clang_node-1distinct_use.swift b/test/IRGen/prespecialized-metadata/struct-inmodule-1argument-clang_node-1distinct_use.swift index 447889caac1..d8003b4b7e3 100644 --- a/test/IRGen/prespecialized-metadata/struct-inmodule-1argument-clang_node-1distinct_use.swift +++ b/test/IRGen/prespecialized-metadata/struct-inmodule-1argument-clang_node-1distinct_use.swift @@ -26,7 +26,7 @@ struct Value { // CHECK: define hidden swiftcc void @"$s4main4doityyF"() #{{[0-9]+}} { // CHECK: [[TYPE:%[0-9]+]] = call %swift.type* @__swift_instantiateConcreteTypeFromMangledName({ i32, i32 }* @"$s4main5ValueVySo12NSDictionaryCGMD") #{{[0-9]+}} -// CHECK: call swiftcc void @"$s4main7consumeyyxlF"(%swift.opaque* noalias nocapture %12, %swift.type* [[TYPE]]) +// CHECK: call swiftcc void @"$s4main7consumeyyxlF"(%swift.opaque* noalias nocapture {{%.*}}, %swift.type* [[TYPE]]) // CHECK: } func doit() { consume(Value(NSDictionary())) From d4976caa4ec1ddc874983eaf50e4355f91e0bdcd Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Fri, 10 Jan 2020 11:12:58 -0800 Subject: [PATCH 05/27] [Gardening] Const-qualify some logically const functions --- include/swift/AST/IRGenOptions.h | 2 +- include/swift/Frontend/Frontend.h | 2 +- lib/Frontend/Frontend.cpp | 2 +- lib/SILGen/SILGenFunction.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/swift/AST/IRGenOptions.h b/include/swift/AST/IRGenOptions.h index dc6cb89d402..f90830b78fa 100644 --- a/include/swift/AST/IRGenOptions.h +++ b/include/swift/AST/IRGenOptions.h @@ -272,7 +272,7 @@ public: /// Appends to \p os an arbitrary string representing all options which /// influence the llvm compilation but are not reflected in the llvm module /// itself. - void writeLLVMCodeGenOptionsTo(llvm::raw_ostream &os) { + void writeLLVMCodeGenOptionsTo(llvm::raw_ostream &os) const { // We put a letter between each value simply to keep them from running into // one another. There might be a vague correspondence between meaning and // letter, but don't sweat it. diff --git a/include/swift/Frontend/Frontend.h b/include/swift/Frontend/Frontend.h index a77186a52cb..4e690628a08 100644 --- a/include/swift/Frontend/Frontend.h +++ b/include/swift/Frontend/Frontend.h @@ -380,7 +380,7 @@ public: SerializationOptions computeSerializationOptions(const SupplementaryOutputPaths &outs, - bool moduleIsPublic); + bool moduleIsPublic) const; }; /// A class which manages the state and execution of the compiler. diff --git a/lib/Frontend/Frontend.cpp b/lib/Frontend/Frontend.cpp index a54f2852b7d..fedf409519e 100644 --- a/lib/Frontend/Frontend.cpp +++ b/lib/Frontend/Frontend.cpp @@ -142,7 +142,7 @@ CompilerInvocation::getModuleInterfaceOutputPathForWholeModule() const { } SerializationOptions CompilerInvocation::computeSerializationOptions( - const SupplementaryOutputPaths &outs, bool moduleIsPublic) { + const SupplementaryOutputPaths &outs, bool moduleIsPublic) const { const FrontendOptions &opts = getFrontendOptions(); SerializationOptions serializationOpts; diff --git a/lib/SILGen/SILGenFunction.h b/lib/SILGen/SILGenFunction.h index 1026c859ab0..f0a4c9d7646 100644 --- a/lib/SILGen/SILGenFunction.h +++ b/lib/SILGen/SILGenFunction.h @@ -492,7 +492,7 @@ public: SILFunction &getFunction() { return F; } SILModule &getModule() { return F.getModule(); } SILGenBuilder &getBuilder() { return B; } - SILOptions &getOptions() { return getModule().getOptions(); } + const SILOptions &getOptions() { return getModule().getOptions(); } // Returns the type expansion context for types in this function. TypeExpansionContext getTypeExpansionContext() { From fad29a306c6d05cd00b2d2578b4dd1012736d30e Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Fri, 10 Jan 2020 11:14:57 -0800 Subject: [PATCH 06/27] [NFC] Don't mutate SILOptions when Loading Profile Info Fails Use the presence or absence of the PGO reader instead. SILGen was wiping out this option then checking for it being wiped out anyways. --- lib/SILGen/SILGen.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/SILGen/SILGen.cpp b/lib/SILGen/SILGen.cpp index b87b9521dbf..0e261cca10c 100644 --- a/lib/SILGen/SILGen.cpp +++ b/lib/SILGen/SILGen.cpp @@ -49,15 +49,15 @@ using namespace Lowering; SILGenModule::SILGenModule(SILModule &M, ModuleDecl *SM) : M(M), Types(M.Types), SwiftModule(SM), TopLevelSGF(nullptr) { - SILOptions &Opts = M.getOptions(); + const SILOptions &Opts = M.getOptions(); if (!Opts.UseProfile.empty()) { auto ReaderOrErr = llvm::IndexedInstrProfReader::create(Opts.UseProfile); if (auto E = ReaderOrErr.takeError()) { diagnose(SourceLoc(), diag::profile_read_error, Opts.UseProfile, llvm::toString(std::move(E))); - Opts.UseProfile.erase(); + } else { + M.setPGOReader(std::move(ReaderOrErr.get())); } - M.setPGOReader(std::move(ReaderOrErr.get())); } } From eb619310122cb347854dac2f59720dcf64dc594c Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Fri, 10 Jan 2020 11:17:05 -0800 Subject: [PATCH 07/27] [NFC] Grab the private discriminator for a file in IRGenDebugInfo This was being done at an odd point in the frontend presumably because by that point the private discriminator had been fully computed. Instead, push the conditions for generating the prefix data down to debug info generation and stop mutating IRGenOptions::DebugFlag in the frontend. --- include/swift/AST/IRGenOptions.h | 10 ++++++++++ include/swift/IRGen/IRGenPublic.h | 1 + include/swift/Subsystems.h | 1 + lib/FrontendTool/FrontendTool.cpp | 18 +----------------- lib/IRGen/IRGen.cpp | 21 ++++++++++++++------- lib/IRGen/IRGenDebugInfo.cpp | 16 ++++++++++------ lib/IRGen/IRGenDebugInfo.h | 3 ++- lib/IRGen/IRGenModule.cpp | 15 +++++++++------ lib/IRGen/IRGenModule.h | 5 +++-- tools/sil-opt/SILOpt.cpp | 2 +- 10 files changed, 52 insertions(+), 40 deletions(-) diff --git a/include/swift/AST/IRGenOptions.h b/include/swift/AST/IRGenOptions.h index f90830b78fa..699385ad271 100644 --- a/include/swift/AST/IRGenOptions.h +++ b/include/swift/AST/IRGenOptions.h @@ -303,6 +303,16 @@ public: return OptMode == OptimizationMode::ForSize; } + std::string getDebugFlags(StringRef PrivateDiscriminator) const { + std::string Flags = DebugFlags; + if (!PrivateDiscriminator.empty()) { + if (!Flags.empty()) + Flags += " "; + Flags += ("-private-discriminator " + PrivateDiscriminator).str(); + } + return Flags; + } + /// Return a hash code of any components from these options that should /// contribute to a Swift Bridging PCH hash. llvm::hash_code getPCHHashComponents() const { diff --git a/include/swift/IRGen/IRGenPublic.h b/include/swift/IRGen/IRGenPublic.h index 3d1c11c4877..e92e85d18e1 100644 --- a/include/swift/IRGen/IRGenPublic.h +++ b/include/swift/IRGen/IRGenPublic.h @@ -31,6 +31,7 @@ class IRGenModule; std::pair createIRGenModule(SILModule *SILMod, StringRef OutputFilename, StringRef MainInputFilenameForDebugInfo, + StringRef PrivateDiscriminator, llvm::LLVMContext &LLVMContext); /// Delete the IRGenModule and IRGenerator obtained by the above call. diff --git a/include/swift/Subsystems.h b/include/swift/Subsystems.h index 57b4fd6e318..2ee1bde0247 100644 --- a/include/swift/Subsystems.h +++ b/include/swift/Subsystems.h @@ -284,6 +284,7 @@ namespace swift { performIRGeneration(IRGenOptions &Opts, SourceFile &SF, std::unique_ptr SILMod, StringRef ModuleName, const PrimarySpecificPaths &PSPs, + StringRef PrivateDiscriminator, llvm::LLVMContext &LLVMContext, llvm::GlobalVariable **outModuleHash = nullptr, llvm::StringSet<> *LinkerDirectives = nullptr); diff --git a/lib/FrontendTool/FrontendTool.cpp b/lib/FrontendTool/FrontendTool.cpp index 0d6c7f0c0f7..27e60c952ec 100644 --- a/lib/FrontendTool/FrontendTool.cpp +++ b/lib/FrontendTool/FrontendTool.cpp @@ -1371,21 +1371,6 @@ static bool performCompile(CompilerInstance &Instance, ReturnValue, observer, Stats); } -/// Get the main source file's private discriminator and attach it to -/// the compile unit's flags. -static void setPrivateDiscriminatorIfNeeded(IRGenOptions &IRGenOpts, - ModuleOrSourceFile MSF) { - if (IRGenOpts.DebugInfoLevel == IRGenDebugInfoLevel::None || - !MSF.is()) - return; - Identifier PD = MSF.get()->getPrivateDiscriminator(); - if (!PD.empty()) { - if (!IRGenOpts.DebugFlags.empty()) - IRGenOpts.DebugFlags += " "; - IRGenOpts.DebugFlags += ("-private-discriminator " + PD.str()).str(); - } -} - static bool serializeSIB(SILModule *SM, const PrimarySpecificPaths &PSPs, ASTContext &Context, ModuleOrSourceFile MSF) { const std::string &moduleOutputPath = @@ -1414,6 +1399,7 @@ static void generateIR(IRGenOptions &IRGenOpts, std::unique_ptr SM, IRModule = MSF.is() ? performIRGeneration(IRGenOpts, *MSF.get(), std::move(SM), OutputFilename, PSPs, + MSF.get()->getPrivateDiscriminator().str(), LLVMContext, &HashGlobal, &LinkerDirectives) : performIRGeneration(IRGenOpts, MSF.get(), @@ -1601,8 +1587,6 @@ static bool performCompileStepsPostSILGen( emitAnyWholeModulePostTypeCheckSupplementaryOutputs(Instance, Invocation, moduleIsPublic); - setPrivateDiscriminatorIfNeeded(IRGenOpts, MSF); - if (Action == FrontendOptions::ActionType::EmitSIB) return serializeSIB(SM.get(), PSPs, Instance.getASTContext(), MSF); diff --git a/lib/IRGen/IRGen.cpp b/lib/IRGen/IRGen.cpp index b8d10a5d860..c7202e73e31 100644 --- a/lib/IRGen/IRGen.cpp +++ b/lib/IRGen/IRGen.cpp @@ -808,6 +808,7 @@ static void initLLVMModule(const IRGenModule &IGM, ModuleDecl &M) { std::pair swift::irgen::createIRGenModule(SILModule *SILMod, StringRef OutputFilename, StringRef MainInputFilenameForDebugInfo, + StringRef PrivateDiscriminator, llvm::LLVMContext &LLVMContext) { IRGenOptions Opts; @@ -819,7 +820,8 @@ swift::irgen::createIRGenModule(SILModule *SILMod, StringRef OutputFilename, // Create the IR emitter. IRGenModule *IGM = new IRGenModule(*irgen, std::move(targetMachine), nullptr, LLVMContext, - "", OutputFilename, MainInputFilenameForDebugInfo); + "", OutputFilename, MainInputFilenameForDebugInfo, + PrivateDiscriminator); initLLVMModule(*IGM, *SILMod->getSwiftModule()); @@ -858,6 +860,7 @@ static std::unique_ptr performIRGeneration(IRGenOptions &Opts, ModuleDecl *M, std::unique_ptr SILMod, StringRef ModuleName, const PrimarySpecificPaths &PSPs, + StringRef PrivateDiscriminator, llvm::LLVMContext &LLVMContext, SourceFile *SF = nullptr, llvm::GlobalVariable **outModuleHash = nullptr, llvm::StringSet<> *linkerDirectives = nullptr) { @@ -872,7 +875,8 @@ performIRGeneration(IRGenOptions &Opts, ModuleDecl *M, // Create the IR emitter. IRGenModule IGM(irgen, std::move(targetMachine), nullptr, LLVMContext, ModuleName, PSPs.OutputFilename, - PSPs.MainInputFilenameForDebugInfo); + PSPs.MainInputFilenameForDebugInfo, + PrivateDiscriminator); initLLVMModule(IGM, *SILMod->getSwiftModule()); @@ -1119,7 +1123,8 @@ static void performParallelIRGeneration( // Create the IR emitter. IRGenModule *IGM = new IRGenModule(irgen, std::move(targetMachine), nextSF, *Context, - ModuleName, *OutputIter++, nextSF->getFilename()); + ModuleName, *OutputIter++, nextSF->getFilename(), + nextSF->getPrivateDiscriminator().str()); IGMcreated = true; initLLVMModule(*IGM, *SILMod->getSwiftModule()); @@ -1279,19 +1284,21 @@ std::unique_ptr swift::performIRGeneration( return nullptr; } return ::performIRGeneration(Opts, M, std::move(SILMod), ModuleName, PSPs, - LLVMContext, nullptr, outModuleHash, - LinkerDirectives); + "", LLVMContext, nullptr, + outModuleHash, LinkerDirectives); } std::unique_ptr swift:: performIRGeneration(IRGenOptions &Opts, SourceFile &SF, std::unique_ptr SILMod, StringRef ModuleName, const PrimarySpecificPaths &PSPs, + StringRef PrivateDiscriminator, llvm::LLVMContext &LLVMContext, llvm::GlobalVariable **outModuleHash, llvm::StringSet<> *LinkerDirectives) { return ::performIRGeneration(Opts, SF.getParentModule(), std::move(SILMod), - ModuleName, PSPs, LLVMContext, &SF, + ModuleName, PSPs, PrivateDiscriminator, + LLVMContext, &SF, outModuleHash, LinkerDirectives); } @@ -1311,7 +1318,7 @@ swift::createSwiftModuleObjectFile(SILModule &SILMod, StringRef Buffer, if (!targetMachine) return; IRGenModule IGM(irgen, std::move(targetMachine), nullptr, VMContext, - OutputPath, OutputPath, ""); + OutputPath, OutputPath, "", ""); initLLVMModule(IGM, *SILMod.getSwiftModule()); auto *Ty = llvm::ArrayType::get(IGM.Int8Ty, Buffer.size()); auto *Data = diff --git a/lib/IRGen/IRGenDebugInfo.cpp b/lib/IRGen/IRGenDebugInfo.cpp index bce7197bb5c..2a75f47fd89 100644 --- a/lib/IRGen/IRGenDebugInfo.cpp +++ b/lib/IRGen/IRGenDebugInfo.cpp @@ -143,7 +143,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo { public: IRGenDebugInfoImpl(const IRGenOptions &Opts, ClangImporter &CI, IRGenModule &IGM, llvm::Module &M, - StringRef MainOutputFilenameForDebugInfo); + StringRef MainOutputFilenameForDebugInfo, + StringRef PrivateDiscriminator); void finalize(); void setCurrentLoc(IRBuilder &Builder, const SILDebugScope *DS, @@ -1664,7 +1665,8 @@ private: IRGenDebugInfoImpl::IRGenDebugInfoImpl(const IRGenOptions &Opts, ClangImporter &CI, IRGenModule &IGM, llvm::Module &M, - StringRef MainOutputFilenameForDebugInfo) + StringRef MainOutputFilenameForDebugInfo, + StringRef PD) : Opts(Opts), CI(CI), SM(IGM.Context.SourceMgr), M(M), DBuilder(M), IGM(IGM), DebugPrefixMap(Opts.DebugPrefixMap) { assert(Opts.DebugInfoLevel > IRGenDebugInfoLevel::None && @@ -1678,7 +1680,6 @@ IRGenDebugInfoImpl::IRGenDebugInfoImpl(const IRGenOptions &Opts, unsigned Lang = llvm::dwarf::DW_LANG_Swift; std::string Producer = version::getSwiftFullVersion( IGM.Context.LangOpts.EffectiveLanguageVersion); - StringRef Flags = Opts.DebugFlags; unsigned Major, Minor; std::tie(Major, Minor) = version::getSwiftNumericVersion(); unsigned MajorRuntimeVersion = Major; @@ -1693,7 +1694,8 @@ IRGenDebugInfoImpl::IRGenDebugInfoImpl(const IRGenOptions &Opts, TheCU = DBuilder.createCompileUnit( Lang, MainFile, - Producer, Opts.shouldOptimize(), Flags, MajorRuntimeVersion, SplitName, + Producer, Opts.shouldOptimize(), Opts.getDebugFlags(PD), + MajorRuntimeVersion, SplitName, Opts.DebugInfoLevel > IRGenDebugInfoLevel::LineTables ? llvm::DICompileUnit::FullDebug : llvm::DICompileUnit::LineTablesOnly); @@ -2355,9 +2357,11 @@ SILLocation::DebugLoc IRGenDebugInfoImpl::decodeSourceLoc(SourceLoc SL) { std::unique_ptr IRGenDebugInfo::createIRGenDebugInfo( const IRGenOptions &Opts, ClangImporter &CI, IRGenModule &IGM, - llvm::Module &M, StringRef MainOutputFilenameForDebugInfo) { + llvm::Module &M, StringRef MainOutputFilenameForDebugInfo, + StringRef PrivateDiscriminator) { return llvm::make_unique(Opts, CI, IGM, M, - MainOutputFilenameForDebugInfo); + MainOutputFilenameForDebugInfo, + PrivateDiscriminator); } diff --git a/lib/IRGen/IRGenDebugInfo.h b/lib/IRGen/IRGenDebugInfo.h index 6b59daeaaf7..229a544b7ce 100644 --- a/lib/IRGen/IRGenDebugInfo.h +++ b/lib/IRGen/IRGenDebugInfo.h @@ -49,7 +49,8 @@ public: static std::unique_ptr createIRGenDebugInfo(const IRGenOptions &Opts, ClangImporter &CI, IRGenModule &IGM, llvm::Module &M, - StringRef MainOutputFilenameForDebugInfo); + StringRef MainOutputFilenameForDebugInfo, + StringRef PrivateDiscriminator); virtual ~IRGenDebugInfo(); /// Finalize the llvm::DIBuilder owned by this object. diff --git a/lib/IRGen/IRGenModule.cpp b/lib/IRGen/IRGenModule.cpp index 49ed490b884..768284dde78 100644 --- a/lib/IRGen/IRGenModule.cpp +++ b/lib/IRGen/IRGenModule.cpp @@ -88,7 +88,8 @@ static llvm::PointerType *createStructPointerType(IRGenModule &IGM, static clang::CodeGenerator *createClangCodeGenerator(ASTContext &Context, llvm::LLVMContext &LLVMContext, IRGenOptions &Opts, - StringRef ModuleName) { + StringRef ModuleName, + StringRef PD) { auto Loader = Context.getClangModuleLoader(); auto *Importer = static_cast(&*Loader); assert(Importer && "No clang module loader!"); @@ -119,13 +120,13 @@ static clang::CodeGenerator *createClangCodeGenerator(ASTContext &Context, case IRGenDebugInfoFormat::DWARF: CGO.DebugCompilationDir = Opts.DebugCompilationDir; CGO.DwarfVersion = Opts.DWARFVersion; - CGO.DwarfDebugFlags = Opts.DebugFlags; + CGO.DwarfDebugFlags = Opts.getDebugFlags(PD); break; case IRGenDebugInfoFormat::CodeView: CGO.EmitCodeView = true; CGO.DebugCompilationDir = Opts.DebugCompilationDir; // This actually contains the debug flags for codeview. - CGO.DwarfDebugFlags = Opts.DebugFlags; + CGO.DwarfDebugFlags = Opts.getDebugFlags(PD); break; } @@ -144,10 +145,11 @@ IRGenModule::IRGenModule(IRGenerator &irgen, std::unique_ptr &&target, SourceFile *SF, llvm::LLVMContext &LLVMContext, StringRef ModuleName, StringRef OutputFilename, - StringRef MainInputFilenameForDebugInfo) + StringRef MainInputFilenameForDebugInfo, + StringRef PrivateDiscriminator) : IRGen(irgen), Context(irgen.SIL.getASTContext()), ClangCodeGen(createClangCodeGenerator(Context, LLVMContext, irgen.Opts, - ModuleName)), + ModuleName, PrivateDiscriminator)), Module(*ClangCodeGen->GetModule()), LLVMContext(Module.getContext()), DataLayout(irgen.getClangDataLayout()), Triple(irgen.getEffectiveClangTriple()), TargetMachine(std::move(target)), @@ -491,7 +493,8 @@ IRGenModule::IRGenModule(IRGenerator &irgen, if (opts.DebugInfoLevel > IRGenDebugInfoLevel::None) DebugInfo = IRGenDebugInfo::createIRGenDebugInfo(IRGen.Opts, *CI, *this, Module, - MainInputFilenameForDebugInfo); + MainInputFilenameForDebugInfo, + PrivateDiscriminator); initClangTypeConverter(); diff --git a/lib/IRGen/IRGenModule.h b/lib/IRGen/IRGenModule.h index 7f7e4a78896..37590ba3602 100644 --- a/lib/IRGen/IRGenModule.h +++ b/lib/IRGen/IRGenModule.h @@ -1225,14 +1225,15 @@ public: IRGenModule(IRGenerator &irgen, std::unique_ptr &&target, SourceFile *SF, llvm::LLVMContext &LLVMContext, StringRef ModuleName, StringRef OutputFilename, - StringRef MainInputFilenameForDebugInfo); + StringRef MainInputFilenameForDebugInfo, + StringRef PrivateDiscriminator); /// The constructor used when we just need an IRGenModule for type lowering. IRGenModule(IRGenerator &irgen, std::unique_ptr &&target, llvm::LLVMContext &LLVMContext) : IRGenModule(irgen, std::move(target), /*SF=*/nullptr, LLVMContext, "", "", - "") {} + "", "") {} ~IRGenModule(); diff --git a/tools/sil-opt/SILOpt.cpp b/tools/sil-opt/SILOpt.cpp index 91e00140cd4..3cb447a9699 100644 --- a/tools/sil-opt/SILOpt.cpp +++ b/tools/sil-opt/SILOpt.cpp @@ -450,7 +450,7 @@ int main(int argc, char **argv) { auto T = irgen::createIRGenModule( SILMod, Invocation.getOutputFilenameForAtMostOnePrimary(), Invocation.getMainInputFilenameForDebugInfoForAtMostOnePrimary(), - getGlobalLLVMContext()); + "", getGlobalLLVMContext()); runCommandLineSelectedPasses(SILMod, T.second); irgen::deleteIRGenModule(T); } From 6407a4d36ff9ff4372c33627c9546c0883888b08 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Fri, 10 Jan 2020 11:18:17 -0800 Subject: [PATCH 08/27] [Gardening] Drop an unused parameter --- include/swift/Subsystems.h | 2 +- lib/IRGen/IRGen.cpp | 4 ++-- lib/Immediate/Immediate.cpp | 2 +- lib/Immediate/REPL.cpp | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/swift/Subsystems.h b/include/swift/Subsystems.h index 2ee1bde0247..cfd5c0ead68 100644 --- a/include/swift/Subsystems.h +++ b/include/swift/Subsystems.h @@ -263,7 +263,7 @@ namespace swift { /// Get the CPU, subtarget feature options, and triple to use when emitting code. std::tuple, std::string> - getIRTargetOptions(IRGenOptions &Opts, ASTContext &Ctx); + getIRTargetOptions(ASTContext &Ctx); /// Turn the given Swift module into either LLVM IR or native code /// and return the generated LLVM IR module. diff --git a/lib/IRGen/IRGen.cpp b/lib/IRGen/IRGen.cpp index c7202e73e31..c24cc912366 100644 --- a/lib/IRGen/IRGen.cpp +++ b/lib/IRGen/IRGen.cpp @@ -152,7 +152,7 @@ static void addSanitizerCoveragePass(const PassManagerBuilder &Builder, std::tuple, std::string> -swift::getIRTargetOptions(IRGenOptions &Opts, ASTContext &Ctx) { +swift::getIRTargetOptions(ASTContext &Ctx) { // Things that maybe we should collect from the command line: // - relocation model // - code model @@ -656,7 +656,7 @@ swift::createTargetMachine(IRGenOptions &Opts, ASTContext &Ctx) { std::string EffectiveClangTriple; std::vector targetFeaturesArray; std::tie(TargetOpts, CPU, targetFeaturesArray, EffectiveClangTriple) - = getIRTargetOptions(Opts, Ctx); + = getIRTargetOptions(Ctx); const llvm::Triple &EffectiveTriple = llvm::Triple(EffectiveClangTriple); std::string targetFeatures; if (!targetFeaturesArray.empty()) { diff --git a/lib/Immediate/Immediate.cpp b/lib/Immediate/Immediate.cpp index b6554d9ea45..3f9357fafe9 100644 --- a/lib/Immediate/Immediate.cpp +++ b/lib/Immediate/Immediate.cpp @@ -301,7 +301,7 @@ int swift::RunImmediately(CompilerInstance &CI, const ProcessCmdLine &CmdLine, std::string Triple; std::vector Features; std::tie(TargetOpt, CPU, Features, Triple) - = getIRTargetOptions(IRGenOpts, swiftModule->getASTContext()); + = getIRTargetOptions(swiftModule->getASTContext()); builder.setRelocationModel(llvm::Reloc::PIC_); builder.setTargetOptions(TargetOpt); builder.setMCPU(CPU); diff --git a/lib/Immediate/REPL.cpp b/lib/Immediate/REPL.cpp index 67c26f1c7d2..3db966820c4 100644 --- a/lib/Immediate/REPL.cpp +++ b/lib/Immediate/REPL.cpp @@ -984,7 +984,7 @@ public: std::string Triple; std::vector Features; std::tie(TargetOpt, CPU, Features, Triple) - = getIRTargetOptions(IRGenOpts, CI.getASTContext()); + = getIRTargetOptions(CI.getASTContext()); builder.setRelocationModel(llvm::Reloc::PIC_); builder.setTargetOptions(TargetOpt); From 5c746fafaafa6fa654d6a58342c1282c6da96765 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Fri, 10 Jan 2020 11:20:25 -0800 Subject: [PATCH 09/27] [NFC] Compute remaining IRGen options in the argument parser Add an extra phase after all the argument parsing has completed that sets inter-option-dependent flags. This allows for the const-qualification of IRGenOptions, and removes some weird state flipping in FrontendTool. --- lib/Frontend/CompilerInvocation.cpp | 48 +++++++++++++++++++++++++++++ lib/FrontendTool/FrontendTool.cpp | 37 +++------------------- 2 files changed, 52 insertions(+), 33 deletions(-) diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 3d36dbe0a7f..6243771b8ae 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -111,6 +111,49 @@ static void updateRuntimeLibraryPaths(SearchPathOptions &SearchPathOpts, } } +static void setIRGenOutputOptsFromFrontendOptions(IRGenOptions &IRGenOpts, + const FrontendOptions &FrontendOpts) { + // Set the OutputKind for the given Action. + IRGenOpts.OutputKind = [](FrontendOptions::ActionType Action) { + switch (Action) { + case FrontendOptions::ActionType::EmitIR: + return IRGenOutputKind::LLVMAssembly; + case FrontendOptions::ActionType::EmitBC: + return IRGenOutputKind::LLVMBitcode; + case FrontendOptions::ActionType::EmitAssembly: + return IRGenOutputKind::NativeAssembly; + case FrontendOptions::ActionType::Immediate: + return IRGenOutputKind::Module; + case FrontendOptions::ActionType::EmitObject: + default: + // Just fall back to emitting an object file. If we aren't going to run + // IRGen, it doesn't really matter what we put here anyways. + return IRGenOutputKind::ObjectFile; + } + }(FrontendOpts.RequestedAction); + + // If we're in JIT mode, set the requisite flags. + if (FrontendOpts.RequestedAction == FrontendOptions::ActionType::Immediate) { + IRGenOpts.UseJIT = true; + IRGenOpts.DebugInfoLevel = IRGenDebugInfoLevel::Normal; + IRGenOpts.DebugInfoFormat = IRGenDebugInfoFormat::DWARF; + } +} + +static void setBridgingHeaderFromFrontendOptions(ClangImporterOptions &ImporterOpts, + const FrontendOptions &FrontendOpts) { + // If there aren't any inputs, there's nothing to do. + if (!FrontendOpts.InputsAndOutputs.hasInputs()) + return; + + // If we aren't asked to output a bridging header, we don't need to set this. + if (ImporterOpts.PrecompiledHeaderOutputDir.empty()) + return; + + ImporterOpts.BridgingHeader = + FrontendOpts.InputsAndOutputs.getFilenameOfFirstInput(); +} + void CompilerInvocation::setRuntimeResourcePath(StringRef Path) { SearchPathOpts.RuntimeResourcePath = Path; updateRuntimeLibraryPaths(SearchPathOpts, LangOpts.Target); @@ -1309,6 +1352,7 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args, Opts.AutolinkRuntimeCompatibilityDynamicReplacementLibraryVersion = getRuntimeCompatVersion(); } + return false; } @@ -1486,6 +1530,10 @@ bool CompilerInvocation::parseArgs( setDefaultPrebuiltCacheIfNecessary(FrontendOpts, SearchPathOpts, LangOpts.Target); + // Now that we've parsed everything, setup some inter-option-dependent state. + setIRGenOutputOptsFromFrontendOptions(IRGenOpts, FrontendOpts); + setBridgingHeaderFromFrontendOptions(ClangImporterOpts, FrontendOpts); + return false; } diff --git a/lib/FrontendTool/FrontendTool.cpp b/lib/FrontendTool/FrontendTool.cpp index 27e60c952ec..bfcb2ac9199 100644 --- a/lib/FrontendTool/FrontendTool.cpp +++ b/lib/FrontendTool/FrontendTool.cpp @@ -569,25 +569,6 @@ printModuleInterfaceIfNeeded(StringRef outputPath, }); } -/// Returns the OutputKind for the given Action. -static IRGenOutputKind getOutputKind(FrontendOptions::ActionType Action) { - switch (Action) { - case FrontendOptions::ActionType::EmitIR: - return IRGenOutputKind::LLVMAssembly; - case FrontendOptions::ActionType::EmitBC: - return IRGenOutputKind::LLVMBitcode; - case FrontendOptions::ActionType::EmitAssembly: - return IRGenOutputKind::NativeAssembly; - case FrontendOptions::ActionType::EmitObject: - return IRGenOutputKind::ObjectFile; - case FrontendOptions::ActionType::Immediate: - return IRGenOutputKind::Module; - default: - llvm_unreachable("Unknown ActionType which requires IRGen"); - return IRGenOutputKind::ObjectFile; - } -} - namespace { /// If there is an error with fixits it writes the fixits as edits in json @@ -750,9 +731,6 @@ static bool precompileBridgingHeader(CompilerInvocation &Invocation, auto &ImporterOpts = Invocation.getClangImporterOptions(); auto &PCHOutDir = ImporterOpts.PrecompiledHeaderOutputDir; if (!PCHOutDir.empty()) { - ImporterOpts.BridgingHeader = - Invocation.getFrontendOptions() - .InputsAndOutputs.getFilenameOfFirstInput(); // Create or validate a persistent PCH. auto SwiftPCHHash = Invocation.getPCHHash(); auto PCH = clangImporter->getOrCreatePCH(ImporterOpts, SwiftPCHHash); @@ -840,12 +818,8 @@ static bool compileLLVMIR(CompilerInvocation &Invocation, Err.getMessage()); return true; } - IRGenOptions &IRGenOpts = Invocation.getIRGenOptions(); - // TODO: remove once the frontend understands what action it should perform - IRGenOpts.OutputKind = - getOutputKind(Invocation.getFrontendOptions().RequestedAction); - - return performLLVM(IRGenOpts, Instance.getASTContext(), Module.get(), + return performLLVM(Invocation.getIRGenOptions(), + Instance.getASTContext(), Module.get(), Invocation.getFrontendOptions() .InputsAndOutputs.getSingleOutputFilename(), Stats); @@ -1414,12 +1388,9 @@ static bool processCommandLineAndRunImmediately(CompilerInvocation &Invocation, ModuleOrSourceFile MSF, FrontendObserver *observer, int &ReturnValue) { - FrontendOptions &opts = Invocation.getFrontendOptions(); + const FrontendOptions &opts = Invocation.getFrontendOptions(); assert(!MSF.is() && "-i doesn't work in -primary-file mode"); - IRGenOptions &IRGenOpts = Invocation.getIRGenOptions(); - IRGenOpts.UseJIT = true; - IRGenOpts.DebugInfoLevel = IRGenDebugInfoLevel::Normal; - IRGenOpts.DebugInfoFormat = IRGenDebugInfoFormat::DWARF; + const IRGenOptions &IRGenOpts = Invocation.getIRGenOptions(); const ProcessCmdLine &CmdLine = ProcessCmdLine(opts.ImmediateArgv.begin(), opts.ImmediateArgv.end()); Instance.setSILModule(std::move(SM)); From d63053d64e7f8e51f6c5439e4bb26c8b802825b5 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Fri, 10 Jan 2020 11:21:11 -0800 Subject: [PATCH 10/27] [Gardening] Remove more unused parameters --- lib/FrontendTool/FrontendTool.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/FrontendTool/FrontendTool.cpp b/lib/FrontendTool/FrontendTool.cpp index bfcb2ac9199..772eebf5e60 100644 --- a/lib/FrontendTool/FrontendTool.cpp +++ b/lib/FrontendTool/FrontendTool.cpp @@ -482,8 +482,7 @@ getFileOutputStream(StringRef OutputFilename, ASTContext &Ctx) { } /// Writes the Syntax tree to the given file -static bool emitSyntax(SourceFile *SF, LangOptions &LangOpts, - SourceManager &SM, StringRef OutputFilename) { +static bool emitSyntax(SourceFile *SF, StringRef OutputFilename) { auto bufferID = SF->getBufferID(); assert(bufferID && "frontend should have a buffer ID " "for the main source file"); @@ -920,7 +919,6 @@ static Optional dumpASTIfNeeded(CompilerInvocation &Invocation, case FrontendOptions::ActionType::EmitSyntax: emitSyntax(getPrimaryOrMainSourceFile(Invocation, Instance), - Invocation.getLangOptions(), Instance.getSourceMgr(), opts.InputsAndOutputs.getSingleOutputFilename()); break; From bd57f14661baba26678dc86f0a32e0d35fd51e7f Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Fri, 10 Jan 2020 11:22:31 -0800 Subject: [PATCH 11/27] [NFC] Push const IRGenOptions and SILOptions everywhere --- include/swift/Immediate/Immediate.h | 2 +- include/swift/SIL/SILModule.h | 10 ++-- include/swift/Subsystems.h | 18 ++++---- lib/FrontendTool/FrontendTool.cpp | 71 ++++++++++++++--------------- lib/IRGen/IRGen.cpp | 21 +++++---- lib/IRGen/IRGenModule.cpp | 2 +- lib/IRGen/IRGenModule.h | 4 +- lib/IRGen/TypeLayoutDumper.cpp | 2 +- lib/Immediate/Immediate.cpp | 8 ++-- lib/Immediate/ImmediateImpl.h | 2 +- lib/RemoteAST/RemoteAST.cpp | 2 +- lib/SIL/SILModule.cpp | 4 +- lib/SILGen/SILGen.cpp | 6 +-- 13 files changed, 77 insertions(+), 75 deletions(-) diff --git a/include/swift/Immediate/Immediate.h b/include/swift/Immediate/Immediate.h index 3a54005aeed..0f7181cae94 100644 --- a/include/swift/Immediate/Immediate.h +++ b/include/swift/Immediate/Immediate.h @@ -37,7 +37,7 @@ namespace swift { /// /// \return the result returned from main(), if execution succeeded int RunImmediately(CompilerInstance &CI, const ProcessCmdLine &CmdLine, - IRGenOptions &IRGenOpts, const SILOptions &SILOpts); + const IRGenOptions &IRGenOpts, const SILOptions &SILOpts); void runREPL(CompilerInstance &CI, const ProcessCmdLine &CmdLine, bool ParseStdlib); diff --git a/include/swift/SIL/SILModule.h b/include/swift/SIL/SILModule.h index 1e81ecb91d2..d72b69a29e2 100644 --- a/include/swift/SIL/SILModule.h +++ b/include/swift/SIL/SILModule.h @@ -254,7 +254,7 @@ private: bool wholeModule; /// The options passed into this SILModule. - SILOptions &Options; + const SILOptions &Options; /// Set if the SILModule was serialized already. It is used /// to ensure that the module is serialized only once. @@ -270,7 +270,7 @@ private: // Intentionally marked private so that we need to use 'constructSIL()' // to construct a SILModule. SILModule(ModuleDecl *M, Lowering::TypeConverter &TC, - SILOptions &Options, const DeclContext *associatedDC, + const SILOptions &Options, const DeclContext *associatedDC, bool wholeModule); SILModule(const SILModule&) = delete; @@ -351,13 +351,13 @@ public: /// source file. static std::unique_ptr constructSIL(ModuleDecl *M, Lowering::TypeConverter &TC, - SILOptions &Options, FileUnit *sf = nullptr); + const SILOptions &Options, FileUnit *sf = nullptr); /// Create and return an empty SIL module that we can /// later parse SIL bodies directly into, without converting from an AST. static std::unique_ptr createEmptyModule(ModuleDecl *M, Lowering::TypeConverter &TC, - SILOptions &Options, + const SILOptions &Options, bool WholeModule = false); /// Get the Swift module associated with this SIL module. @@ -390,7 +390,7 @@ public: /// Returns true if it is the optimized OnoneSupport module. bool isOptimizedOnoneSupportModule() const; - SILOptions &getOptions() const { return Options; } + const SILOptions &getOptions() const { return Options; } using iterator = FunctionListType::iterator; using const_iterator = FunctionListType::const_iterator; diff --git a/include/swift/Subsystems.h b/include/swift/Subsystems.h index cfd5c0ead68..f96cf488994 100644 --- a/include/swift/Subsystems.h +++ b/include/swift/Subsystems.h @@ -234,12 +234,12 @@ namespace swift { /// SIL of all files in the module is present in the SILModule. std::unique_ptr performSILGeneration(ModuleDecl *M, Lowering::TypeConverter &TC, - SILOptions &options); + const SILOptions &options); /// Turn a source file into SIL IR. std::unique_ptr performSILGeneration(FileUnit &SF, Lowering::TypeConverter &TC, - SILOptions &options); + const SILOptions &options); using ModuleOrSourceFile = PointerUnion; @@ -269,7 +269,7 @@ namespace swift { /// and return the generated LLVM IR module. /// If you set an outModuleHash, then you need to call performLLVM. std::unique_ptr - performIRGeneration(IRGenOptions &Opts, ModuleDecl *M, + performIRGeneration(const IRGenOptions &Opts, ModuleDecl *M, std::unique_ptr SILMod, StringRef ModuleName, const PrimarySpecificPaths &PSPs, llvm::LLVMContext &LLVMContext, @@ -281,7 +281,7 @@ namespace swift { /// and return the generated LLVM IR module. /// If you set an outModuleHash, then you need to call performLLVM. std::unique_ptr - performIRGeneration(IRGenOptions &Opts, SourceFile &SF, + performIRGeneration(const IRGenOptions &Opts, SourceFile &SF, std::unique_ptr SILMod, StringRef ModuleName, const PrimarySpecificPaths &PSPs, StringRef PrivateDiscriminator, @@ -292,7 +292,7 @@ namespace swift { /// Given an already created LLVM module, construct a pass pipeline and run /// the Swift LLVM Pipeline upon it. This does not cause the module to be /// printed, only to be optimized. - void performLLVMOptimizations(IRGenOptions &Opts, llvm::Module *Module, + void performLLVMOptimizations(const IRGenOptions &Opts, llvm::Module *Module, llvm::TargetMachine *TargetMachine); /// Wrap a serialized module inside a swift AST section in an object file. @@ -300,7 +300,7 @@ namespace swift { StringRef OutputPath); /// Turn the given LLVM module into native code and return true on error. - bool performLLVM(IRGenOptions &Opts, ASTContext &Ctx, llvm::Module *Module, + bool performLLVM(const IRGenOptions &Opts, ASTContext &Ctx, llvm::Module *Module, StringRef OutputFilename, UnifiedStatsReporter *Stats=nullptr); @@ -315,7 +315,7 @@ namespace swift { /// \param TargetMachine target of code gen, required. /// \param effectiveLanguageVersion version of the language, effectively. /// \param OutputFilename Filename for output. - bool performLLVM(IRGenOptions &Opts, DiagnosticEngine *Diags, + bool performLLVM(const IRGenOptions &Opts, DiagnosticEngine *Diags, llvm::sys::Mutex *DiagMutex, llvm::GlobalVariable *HashGlobal, llvm::Module *Module, @@ -325,13 +325,13 @@ namespace swift { UnifiedStatsReporter *Stats=nullptr); /// Dump YAML describing all fixed-size types imported from the given module. - bool performDumpTypeInfo(IRGenOptions &Opts, + bool performDumpTypeInfo(const IRGenOptions &Opts, SILModule &SILMod, llvm::LLVMContext &LLVMContext); /// Creates a TargetMachine from the IRGen opts and AST Context. std::unique_ptr - createTargetMachine(IRGenOptions &Opts, ASTContext &Ctx); + createTargetMachine(const IRGenOptions &Opts, ASTContext &Ctx); /// A convenience wrapper for Parser functionality. class ParserUnit { diff --git a/lib/FrontendTool/FrontendTool.cpp b/lib/FrontendTool/FrontendTool.cpp index 772eebf5e60..8c2aadb0fc1 100644 --- a/lib/FrontendTool/FrontendTool.cpp +++ b/lib/FrontendTool/FrontendTool.cpp @@ -510,7 +510,7 @@ static bool writeSIL(SILModule &SM, ModuleDecl *M, bool EmitVerboseSIL, static bool writeSIL(SILModule &SM, const PrimarySpecificPaths &PSPs, CompilerInstance &Instance, - CompilerInvocation &Invocation) { + const CompilerInvocation &Invocation) { const FrontendOptions &opts = Invocation.getFrontendOptions(); return writeSIL(SM, Instance.getMainModule(), opts.EmitVerboseSIL, PSPs.OutputFilename, opts.EmitSortedSIL); @@ -723,7 +723,7 @@ createOptRecordFile(StringRef Filename, DiagnosticEngine &DE) { return File; } -static bool precompileBridgingHeader(CompilerInvocation &Invocation, +static bool precompileBridgingHeader(const CompilerInvocation &Invocation, CompilerInstance &Instance) { auto clangImporter = static_cast( Instance.getASTContext().getClangModuleLoader()); @@ -742,7 +742,7 @@ static bool precompileBridgingHeader(CompilerInvocation &Invocation, .InputsAndOutputs.getSingleOutputFilename()); } -static bool precompileClangModule(CompilerInvocation &Invocation, +static bool precompileClangModule(const CompilerInvocation &Invocation, CompilerInstance &Instance) { auto clangImporter = static_cast( Instance.getASTContext().getClangModuleLoader()); @@ -754,7 +754,7 @@ static bool precompileClangModule(CompilerInvocation &Invocation, .InputsAndOutputs.getSingleOutputFilename()); } -static bool dumpPrecompiledClangModule(CompilerInvocation &Invocation, +static bool dumpPrecompiledClangModule(const CompilerInvocation &Invocation, CompilerInstance &Instance) { auto clangImporter = static_cast( Instance.getASTContext().getClangModuleLoader()); @@ -765,7 +765,7 @@ static bool dumpPrecompiledClangModule(CompilerInvocation &Invocation, .InputsAndOutputs.getSingleOutputFilename()); } -static bool buildModuleFromInterface(CompilerInvocation &Invocation, +static bool buildModuleFromInterface(const CompilerInvocation &Invocation, CompilerInstance &Instance) { const FrontendOptions &FEOpts = Invocation.getFrontendOptions(); assert(FEOpts.InputsAndOutputs.hasSingleInput()); @@ -781,7 +781,7 @@ static bool buildModuleFromInterface(CompilerInvocation &Invocation, FEOpts.TrackSystemDeps, FEOpts.RemarkOnRebuildFromModuleInterface); } -static bool compileLLVMIR(CompilerInvocation &Invocation, +static bool compileLLVMIR(const CompilerInvocation &Invocation, CompilerInstance &Instance, UnifiedStatsReporter *Stats) { auto &LLVMContext = getGlobalLLVMContext(); @@ -824,7 +824,7 @@ static bool compileLLVMIR(CompilerInvocation &Invocation, Stats); } -static void verifyGenericSignaturesIfNeeded(CompilerInvocation &Invocation, +static void verifyGenericSignaturesIfNeeded(const CompilerInvocation &Invocation, ASTContext &Context) { auto verifyGenericSignaturesInModule = Invocation.getFrontendOptions().VerifyGenericSignaturesInModule; @@ -834,7 +834,7 @@ static void verifyGenericSignaturesIfNeeded(CompilerInvocation &Invocation, GenericSignatureBuilder::verifyGenericSignaturesInModule(module); } -static void dumpAndPrintScopeMap(CompilerInvocation &Invocation, +static void dumpAndPrintScopeMap(const CompilerInvocation &Invocation, CompilerInstance &Instance, SourceFile *SF) { // Not const because may require reexpansion ASTScope &scope = SF->getScope(); @@ -853,7 +853,7 @@ static void dumpAndPrintScopeMap(CompilerInvocation &Invocation, } } -static SourceFile *getPrimaryOrMainSourceFile(CompilerInvocation &Invocation, +static SourceFile *getPrimaryOrMainSourceFile(const CompilerInvocation &Invocation, CompilerInstance &Instance) { SourceFile *SF = Instance.getPrimarySourceFile(); if (!SF) { @@ -865,7 +865,7 @@ static SourceFile *getPrimaryOrMainSourceFile(CompilerInvocation &Invocation, /// Dumps the AST of all available primary source files. If corresponding output /// files were specified, use them; otherwise, dump the AST to stdout. -static void dumpAST(CompilerInvocation &Invocation, +static void dumpAST(const CompilerInvocation &Invocation, CompilerInstance &Instance) { auto primaryFiles = Instance.getPrimarySourceFiles(); if (!primaryFiles.empty()) { @@ -887,10 +887,10 @@ static void dumpAST(CompilerInvocation &Invocation, /// CompilerInstance::performSema()), so dump or print the main source file and /// return. -static Optional dumpASTIfNeeded(CompilerInvocation &Invocation, +static Optional dumpASTIfNeeded(const CompilerInvocation &Invocation, CompilerInstance &Instance) { - FrontendOptions &opts = Invocation.getFrontendOptions(); - FrontendOptions::ActionType Action = opts.RequestedAction; + const FrontendOptions &opts = Invocation.getFrontendOptions(); + const FrontendOptions::ActionType Action = opts.RequestedAction; ASTContext &Context = Instance.getASTContext(); switch (Action) { default: @@ -935,7 +935,7 @@ static Optional dumpASTIfNeeded(CompilerInvocation &Invocation, } static void emitReferenceDependenciesForAllPrimaryInputsIfNeeded( - CompilerInvocation &Invocation, CompilerInstance &Instance) { + const CompilerInvocation &Invocation, CompilerInstance &Instance) { if (Invocation.getFrontendOptions() .InputsAndOutputs.hasReferenceDependenciesPath() && Instance.getPrimarySourceFiles().empty()) { @@ -962,7 +962,7 @@ static void emitReferenceDependenciesForAllPrimaryInputsIfNeeded( } } static void -emitSwiftRangesForAllPrimaryInputsIfNeeded(CompilerInvocation &Invocation, +emitSwiftRangesForAllPrimaryInputsIfNeeded(const CompilerInvocation &Invocation, CompilerInstance &Instance) { if (Invocation.getFrontendOptions().InputsAndOutputs.hasSwiftRangesPath() && Instance.getPrimarySourceFiles().empty()) { @@ -980,7 +980,7 @@ emitSwiftRangesForAllPrimaryInputsIfNeeded(CompilerInvocation &Invocation, } } static void -emitCompiledSourceForAllPrimaryInputsIfNeeded(CompilerInvocation &Invocation, +emitCompiledSourceForAllPrimaryInputsIfNeeded(const CompilerInvocation &Invocation, CompilerInstance &Instance) { if (Invocation.getFrontendOptions() .InputsAndOutputs.hasCompiledSourcePath() && @@ -999,7 +999,7 @@ emitCompiledSourceForAllPrimaryInputsIfNeeded(CompilerInvocation &Invocation, } } -static bool writeTBDIfNeeded(CompilerInvocation &Invocation, +static bool writeTBDIfNeeded(const CompilerInvocation &Invocation, CompilerInstance &Instance) { const auto &frontendOpts = Invocation.getFrontendOptions(); const auto &tbdOpts = Invocation.getTBDGenOptions(); @@ -1027,7 +1027,7 @@ static std::string changeToLdAdd(StringRef ldHide) { return OS.str().str(); } -static bool writeLdAddCFileIfNeeded(CompilerInvocation &Invocation, +static bool writeLdAddCFileIfNeeded(const CompilerInvocation &Invocation, CompilerInstance &Instance) { auto frontendOpts = Invocation.getFrontendOptions(); if (!frontendOpts.InputsAndOutputs.isWholeModule()) @@ -1076,14 +1076,14 @@ static bool writeLdAddCFileIfNeeded(CompilerInvocation &Invocation, } static bool performCompileStepsPostSILGen( - CompilerInstance &Instance, CompilerInvocation &Invocation, + CompilerInstance &Instance, const CompilerInvocation &Invocation, std::unique_ptr SM, bool astGuaranteedToCorrespondToSIL, ModuleOrSourceFile MSF, const PrimarySpecificPaths &PSPs, bool moduleIsPublic, int &ReturnValue, FrontendObserver *observer, UnifiedStatsReporter *Stats); static bool -performCompileStepsPostSema(CompilerInvocation &Invocation, +performCompileStepsPostSema(const CompilerInvocation &Invocation, CompilerInstance &Instance, bool moduleIsPublic, int &ReturnValue, FrontendObserver *observer, @@ -1098,8 +1098,8 @@ performCompileStepsPostSema(CompilerInvocation &Invocation, ReturnValue, observer, Stats); } - SILOptions &SILOpts = Invocation.getSILOptions(); - FrontendOptions &opts = Invocation.getFrontendOptions(); + const SILOptions &SILOpts = Invocation.getSILOptions(); + const FrontendOptions &opts = Invocation.getFrontendOptions(); auto fileIsSIB = [](const FileUnit *File) -> bool { auto SASTF = dyn_cast(File); return SASTF && SASTF->isSIB(); @@ -1158,7 +1158,7 @@ performCompileStepsPostSema(CompilerInvocation &Invocation, /// Emits index data for all primary inputs, or the main module. static bool -emitIndexData(CompilerInvocation &Invocation, CompilerInstance &Instance) { +emitIndexData(const CompilerInvocation &Invocation, CompilerInstance &Instance) { bool hadEmitIndexDataError = false; if (Instance.getPrimarySourceFiles().empty()) return emitIndexDataIfNeeded(nullptr, Invocation, Instance); @@ -1175,7 +1175,7 @@ emitIndexData(CompilerInvocation &Invocation, CompilerInstance &Instance) { /// `-typecheck`, but skipped for any mode that runs SIL diagnostics if there's /// an error found there (to get those diagnostics back to the user faster). static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs( - CompilerInstance &Instance, CompilerInvocation &Invocation, + CompilerInstance &Instance, const CompilerInvocation &Invocation, bool moduleIsPublic) { const FrontendOptions &opts = Invocation.getFrontendOptions(); @@ -1212,7 +1212,7 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs( /// mode is NoVerify and there were no errors. /// \returns true on error static bool performCompile(CompilerInstance &Instance, - CompilerInvocation &Invocation, + const CompilerInvocation &Invocation, ArrayRef Args, int &ReturnValue, FrontendObserver *observer, @@ -1358,7 +1358,8 @@ static bool serializeSIB(SILModule *SM, const PrimarySpecificPaths &PSPs, return Context.hadError(); } -static void generateIR(IRGenOptions &IRGenOpts, std::unique_ptr SM, +static void generateIR(const IRGenOptions &IRGenOpts, + std::unique_ptr SM, const PrimarySpecificPaths &PSPs, StringRef OutputFilename, ModuleOrSourceFile MSF, std::unique_ptr &IRModule, @@ -1380,7 +1381,7 @@ static void generateIR(IRGenOptions &IRGenOpts, std::unique_ptr SM, &HashGlobal, &LinkerDirectives); } -static bool processCommandLineAndRunImmediately(CompilerInvocation &Invocation, +static bool processCommandLineAndRunImmediately(const CompilerInvocation &Invocation, CompilerInstance &Instance, std::unique_ptr SM, ModuleOrSourceFile MSF, @@ -1404,7 +1405,7 @@ static bool processCommandLineAndRunImmediately(CompilerInvocation &Invocation, return Instance.getASTContext().hadError(); } -static bool validateTBDIfNeeded(CompilerInvocation &Invocation, +static bool validateTBDIfNeeded(const CompilerInvocation &Invocation, ModuleOrSourceFile MSF, bool astGuaranteedToCorrespondToSIL, llvm::Module &IRModule) { @@ -1443,7 +1444,7 @@ static bool validateTBDIfNeeded(CompilerInvocation &Invocation, Invocation.getTBDGenOptions(), allSymbols); } -static bool generateCode(CompilerInvocation &Invocation, +static bool generateCode(const CompilerInvocation &Invocation, CompilerInstance &Instance, StringRef OutputFilename, llvm::Module *IRModule, llvm::GlobalVariable *HashGlobal, @@ -1473,7 +1474,7 @@ static bool generateCode(CompilerInvocation &Invocation, EffectiveLanguageVersion, OutputFilename, Stats); } -static void collectLinkerDirectives(CompilerInvocation &Invocation, +static void collectLinkerDirectives(const CompilerInvocation &Invocation, ModuleOrSourceFile MSF, llvm::StringSet<> &Symbols) { auto tbdOpts = Invocation.getTBDGenOptions(); @@ -1485,7 +1486,7 @@ static void collectLinkerDirectives(CompilerInvocation &Invocation, } static bool performCompileStepsPostSILGen( - CompilerInstance &Instance, CompilerInvocation &Invocation, + CompilerInstance &Instance, const CompilerInvocation &Invocation, std::unique_ptr SM, bool astGuaranteedToCorrespondToSIL, ModuleOrSourceFile MSF, const PrimarySpecificPaths &PSPs, bool moduleIsPublic, int &ReturnValue, FrontendObserver *observer, @@ -1494,8 +1495,8 @@ static bool performCompileStepsPostSILGen( FrontendOptions opts = Invocation.getFrontendOptions(); FrontendOptions::ActionType Action = opts.RequestedAction; ASTContext &Context = Instance.getASTContext(); - SILOptions &SILOpts = Invocation.getSILOptions(); - IRGenOptions &IRGenOpts = Invocation.getIRGenOptions(); + const SILOptions &SILOpts = Invocation.getSILOptions(); + const IRGenOptions &IRGenOpts = Invocation.getIRGenOptions(); Optional ricd; if (auto *SF = MSF.dyn_cast()) @@ -1604,8 +1605,6 @@ static bool performCompileStepsPostSILGen( if (Action == FrontendOptions::ActionType::DumpTypeInfo) return performDumpTypeInfo(IRGenOpts, *SM, getGlobalLLVMContext()); - // TODO: remove once the frontend understands what action it should perform - IRGenOpts.OutputKind = getOutputKind(Action); if (Action == FrontendOptions::ActionType::Immediate) return processCommandLineAndRunImmediately( Invocation, Instance, std::move(SM), MSF, observer, ReturnValue); @@ -1895,7 +1894,7 @@ createJSONFixItDiagnosticConsumerIfNeeded( } /// Print information about the selected target in JSON. -static void printTargetInfo(CompilerInvocation &invocation, +static void printTargetInfo(const CompilerInvocation &invocation, llvm::raw_ostream &out) { out << "{\n"; diff --git a/lib/IRGen/IRGen.cpp b/lib/IRGen/IRGen.cpp index c24cc912366..c0021ddb330 100644 --- a/lib/IRGen/IRGen.cpp +++ b/lib/IRGen/IRGen.cpp @@ -179,7 +179,8 @@ void setModuleFlags(IRGenModule &IGM) { IRGenModule::swiftVersion); } -void swift::performLLVMOptimizations(IRGenOptions &Opts, llvm::Module *Module, +void swift::performLLVMOptimizations(const IRGenOptions &Opts, + llvm::Module *Module, llvm::TargetMachine *TargetMachine) { // Set up a pipeline. PassManagerBuilderWrapper PMBuilder(Opts); @@ -345,7 +346,7 @@ public: /// Computes the MD5 hash of the llvm \p Module including the compiler version /// and options which influence the compilation. -static void getHashOfModule(MD5::MD5Result &Result, IRGenOptions &Opts, +static void getHashOfModule(MD5::MD5Result &Result, const IRGenOptions &Opts, llvm::Module *Module, llvm::TargetMachine *TargetMachine, version::Version const& effectiveLanguageVersion) { @@ -457,7 +458,7 @@ diagnoseSync(DiagnosticEngine *Diags, llvm::sys::Mutex *DiagMutex, /// Run the LLVM passes. In multi-threaded compilation this will be done for /// multiple LLVM modules in parallel. -bool swift::performLLVM(IRGenOptions &Opts, DiagnosticEngine *Diags, +bool swift::performLLVM(const IRGenOptions &Opts, DiagnosticEngine *Diags, llvm::sys::Mutex *DiagMutex, llvm::GlobalVariable *HashGlobal, llvm::Module *Module, @@ -645,7 +646,7 @@ bool swift::performLLVM(IRGenOptions &Opts, DiagnosticEngine *Diags, } std::unique_ptr -swift::createTargetMachine(IRGenOptions &Opts, ASTContext &Ctx) { +swift::createTargetMachine(const IRGenOptions &Opts, ASTContext &Ctx) { CodeGenOpt::Level OptLevel = Opts.shouldOptimize() ? CodeGenOpt::Default // -Os : CodeGenOpt::None; @@ -697,7 +698,7 @@ swift::createTargetMachine(IRGenOptions &Opts, ASTContext &Ctx) { return std::unique_ptr(TargetMachine); } -IRGenerator::IRGenerator(IRGenOptions &options, SILModule &module) +IRGenerator::IRGenerator(const IRGenOptions &options, SILModule &module) : Opts(options), SIL(module), QueueIndex(0) { } @@ -857,7 +858,7 @@ static void runIRGenPreparePasses(SILModule &Module, /// Generates LLVM IR, runs the LLVM passes and produces the output file. /// All this is done in a single thread. static std::unique_ptr -performIRGeneration(IRGenOptions &Opts, ModuleDecl *M, +performIRGeneration(const IRGenOptions &Opts, ModuleDecl *M, std::unique_ptr SILMod, StringRef ModuleName, const PrimarySpecificPaths &PSPs, StringRef PrivateDiscriminator, @@ -1073,7 +1074,7 @@ struct LLVMCodeGenThreads { /// Generates LLVM IR, runs the LLVM passes and produces the output files. /// All this is done in multiple threads. static void performParallelIRGeneration( - IRGenOptions &Opts, swift::ModuleDecl *M, std::unique_ptr SILMod, + const IRGenOptions &Opts, swift::ModuleDecl *M, std::unique_ptr SILMod, StringRef ModuleName, int numThreads, ArrayRef outputFilenames, llvm::StringSet<> *linkerDirectives) { @@ -1267,7 +1268,7 @@ static void performParallelIRGeneration( } std::unique_ptr swift::performIRGeneration( - IRGenOptions &Opts, swift::ModuleDecl *M, std::unique_ptr SILMod, + const IRGenOptions &Opts, swift::ModuleDecl *M, std::unique_ptr SILMod, StringRef ModuleName, const PrimarySpecificPaths &PSPs, llvm::LLVMContext &LLVMContext, ArrayRef parallelOutputFilenames, @@ -1289,7 +1290,7 @@ std::unique_ptr swift::performIRGeneration( } std::unique_ptr swift:: -performIRGeneration(IRGenOptions &Opts, SourceFile &SF, +performIRGeneration(const IRGenOptions &Opts, SourceFile &SF, std::unique_ptr SILMod, StringRef ModuleName, const PrimarySpecificPaths &PSPs, StringRef PrivateDiscriminator, @@ -1353,7 +1354,7 @@ swift::createSwiftModuleObjectFile(SILModule &SILMod, StringRef Buffer, OutputPath); } -bool swift::performLLVM(IRGenOptions &Opts, ASTContext &Ctx, +bool swift::performLLVM(const IRGenOptions &Opts, ASTContext &Ctx, llvm::Module *Module, StringRef OutputFilename, UnifiedStatsReporter *Stats) { // Build TargetMachine. diff --git a/lib/IRGen/IRGenModule.cpp b/lib/IRGen/IRGenModule.cpp index 768284dde78..3ed07808b41 100644 --- a/lib/IRGen/IRGenModule.cpp +++ b/lib/IRGen/IRGenModule.cpp @@ -87,7 +87,7 @@ static llvm::PointerType *createStructPointerType(IRGenModule &IGM, static clang::CodeGenerator *createClangCodeGenerator(ASTContext &Context, llvm::LLVMContext &LLVMContext, - IRGenOptions &Opts, + const IRGenOptions &Opts, StringRef ModuleName, StringRef PD) { auto Loader = Context.getClangModuleLoader(); diff --git a/lib/IRGen/IRGenModule.h b/lib/IRGen/IRGenModule.h index 37590ba3602..2e88aee79eb 100644 --- a/lib/IRGen/IRGenModule.h +++ b/lib/IRGen/IRGenModule.h @@ -194,7 +194,7 @@ enum RequireMetadata_t : bool { /// IRGenModules - one for each LLVM module (= one for each input/output file). class IRGenerator { public: - IRGenOptions &Opts; + const IRGenOptions &Opts; SILModule &SIL; @@ -298,7 +298,7 @@ private: friend class CurrentIGMPtr; public: - explicit IRGenerator(IRGenOptions &opts, SILModule &module); + explicit IRGenerator(const IRGenOptions &opts, SILModule &module); /// Attempt to create an llvm::TargetMachine for the current target. std::unique_ptr createTargetMachine(); diff --git a/lib/IRGen/TypeLayoutDumper.cpp b/lib/IRGen/TypeLayoutDumper.cpp index 49b8e52f4aa..614416956eb 100644 --- a/lib/IRGen/TypeLayoutDumper.cpp +++ b/lib/IRGen/TypeLayoutDumper.cpp @@ -152,7 +152,7 @@ void TypeLayoutDumper::write(ArrayRef AllModules, } } -bool swift::performDumpTypeInfo(IRGenOptions &Opts, +bool swift::performDumpTypeInfo(const IRGenOptions &Opts, SILModule &SILMod, llvm::LLVMContext &LLVMContext) { auto &Ctx = SILMod.getASTContext(); diff --git a/lib/Immediate/Immediate.cpp b/lib/Immediate/Immediate.cpp index 3f9357fafe9..5d77a3ffc73 100644 --- a/lib/Immediate/Immediate.cpp +++ b/lib/Immediate/Immediate.cpp @@ -220,7 +220,7 @@ bool swift::immediate::linkLLVMModules(llvm::Module *Module, } bool swift::immediate::autolinkImportedModules(ModuleDecl *M, - IRGenOptions &IRGenOpts) { + const IRGenOptions &IRGenOpts) { // Perform autolinking. SmallVector AllLinkLibraries(IRGenOpts.LinkLibraries); auto addLinkLibrary = [&](LinkLibrary linkLib) { @@ -234,8 +234,10 @@ bool swift::immediate::autolinkImportedModules(ModuleDecl *M, return false; } -int swift::RunImmediately(CompilerInstance &CI, const ProcessCmdLine &CmdLine, - IRGenOptions &IRGenOpts, const SILOptions &SILOpts) { +int swift::RunImmediately(CompilerInstance &CI, + const ProcessCmdLine &CmdLine, + const IRGenOptions &IRGenOpts, + const SILOptions &SILOpts) { ASTContext &Context = CI.getASTContext(); // IRGen the main module. diff --git a/lib/Immediate/ImmediateImpl.h b/lib/Immediate/ImmediateImpl.h index a309385910b..904e09691a4 100644 --- a/lib/Immediate/ImmediateImpl.h +++ b/lib/Immediate/ImmediateImpl.h @@ -44,7 +44,7 @@ bool tryLoadLibraries(ArrayRef LinkLibraries, DiagnosticEngine &Diags); bool linkLLVMModules(llvm::Module *Module, std::unique_ptr SubModule); -bool autolinkImportedModules(ModuleDecl *M, IRGenOptions &IRGenOpts); +bool autolinkImportedModules(ModuleDecl *M, const IRGenOptions &IRGenOpts); } // end namespace immediate } // end namespace swift diff --git a/lib/RemoteAST/RemoteAST.cpp b/lib/RemoteAST/RemoteAST.cpp index 9b264e8665e..943a1dad7ba 100644 --- a/lib/RemoteAST/RemoteAST.cpp +++ b/lib/RemoteAST/RemoteAST.cpp @@ -59,7 +59,7 @@ namespace { /// A "minimal" class for querying IRGen. struct IRGenContext { - IRGenOptions IROpts; + const IRGenOptions IROpts; SILOptions SILOpts; Lowering::TypeConverter TC; std::unique_ptr SILMod; diff --git a/lib/SIL/SILModule.cpp b/lib/SIL/SILModule.cpp index 6b2f749aeb5..6b022676ca2 100644 --- a/lib/SIL/SILModule.cpp +++ b/lib/SIL/SILModule.cpp @@ -90,7 +90,7 @@ class SILModule::SerializationCallback final }; SILModule::SILModule(ModuleDecl *SwiftModule, TypeConverter &TC, - SILOptions &Options, const DeclContext *associatedDC, + const SILOptions &Options, const DeclContext *associatedDC, bool wholeModule) : TheSwiftModule(SwiftModule), AssociatedDeclContext(associatedDC), @@ -120,7 +120,7 @@ SILModule::~SILModule() { } std::unique_ptr -SILModule::createEmptyModule(ModuleDecl *M, TypeConverter &TC, SILOptions &Options, +SILModule::createEmptyModule(ModuleDecl *M, TypeConverter &TC, const SILOptions &Options, bool WholeModule) { return std::unique_ptr( new SILModule(M, TC, Options, M, WholeModule)); diff --git a/lib/SILGen/SILGen.cpp b/lib/SILGen/SILGen.cpp index 0e261cca10c..888aadc02cf 100644 --- a/lib/SILGen/SILGen.cpp +++ b/lib/SILGen/SILGen.cpp @@ -1691,7 +1691,7 @@ void SILGenModule::emitSourceFile(SourceFile *sf) { std::unique_ptr SILModule::constructSIL(ModuleDecl *mod, TypeConverter &tc, - SILOptions &options, FileUnit *SF) { + const SILOptions &options, FileUnit *SF) { FrontendStatsTracer tracer(mod->getASTContext().Stats, "SILGen"); const DeclContext *DC; if (SF) { @@ -1751,12 +1751,12 @@ SILModule::constructSIL(ModuleDecl *mod, TypeConverter &tc, std::unique_ptr swift::performSILGeneration(ModuleDecl *mod, Lowering::TypeConverter &tc, - SILOptions &options) { + const SILOptions &options) { return SILModule::constructSIL(mod, tc, options, nullptr); } std::unique_ptr swift::performSILGeneration(FileUnit &sf, Lowering::TypeConverter &tc, - SILOptions &options) { + const SILOptions &options) { return SILModule::constructSIL(sf.getParentModule(), tc, options, &sf); } From 8fe25f7530a76ee165b6d7772e003838dc5969b9 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Sat, 11 Jan 2020 22:00:48 -0800 Subject: [PATCH 12/27] [NFC] Remove CompilerInstance::setSILModule The REPL was using the CompilerInstance to stash this parameter, then it would immediately move it into IRGen. Drop the setter and pass this data directly. --- include/swift/Frontend/Frontend.h | 5 ----- include/swift/Immediate/Immediate.h | 5 ++++- lib/Frontend/Frontend.cpp | 6 +----- lib/FrontendTool/FrontendTool.cpp | 4 +--- lib/Immediate/Immediate.cpp | 5 +++-- 5 files changed, 9 insertions(+), 16 deletions(-) diff --git a/include/swift/Frontend/Frontend.h b/include/swift/Frontend/Frontend.h index 4e690628a08..f54e73b3db0 100644 --- a/include/swift/Frontend/Frontend.h +++ b/include/swift/Frontend/Frontend.h @@ -484,11 +484,6 @@ public: } DependencyTracker *getDependencyTracker() { return DepTracker.get(); } - /// Set the SIL module for this compilation instance. - /// - /// The CompilerInstance takes ownership of the given SILModule object. - void setSILModule(std::unique_ptr M); - SILModule *getSILModule() { return TheSILModule.get(); } diff --git a/include/swift/Immediate/Immediate.h b/include/swift/Immediate/Immediate.h index 0f7181cae94..e4f78f50ba5 100644 --- a/include/swift/Immediate/Immediate.h +++ b/include/swift/Immediate/Immediate.h @@ -18,6 +18,7 @@ #ifndef SWIFT_IMMEDIATE_IMMEDIATE_H #define SWIFT_IMMEDIATE_IMMEDIATE_H +#include #include #include @@ -25,6 +26,7 @@ namespace swift { class CompilerInstance; class IRGenOptions; class SILOptions; + class SILModule; // Using LLVM containers to store command-line arguments turns out // to be a lose, because LLVM's execution engine demands this vector @@ -37,7 +39,8 @@ namespace swift { /// /// \return the result returned from main(), if execution succeeded int RunImmediately(CompilerInstance &CI, const ProcessCmdLine &CmdLine, - const IRGenOptions &IRGenOpts, const SILOptions &SILOpts); + const IRGenOptions &IRGenOpts, const SILOptions &SILOpts, + std::unique_ptr &&SM); void runREPL(CompilerInstance &CI, const ProcessCmdLine &CmdLine, bool ParseStdlib); diff --git a/lib/Frontend/Frontend.cpp b/lib/Frontend/Frontend.cpp index fedf409519e..48271d9a3ec 100644 --- a/lib/Frontend/Frontend.cpp +++ b/lib/Frontend/Frontend.cpp @@ -185,10 +185,6 @@ void CompilerInstance::createSILModule() { Invocation.getFrontendOptions().InputsAndOutputs.isWholeModule()); } -void CompilerInstance::setSILModule(std::unique_ptr M) { - TheSILModule = std::move(M); -} - void CompilerInstance::recordPrimaryInputBuffer(unsigned BufID) { PrimaryBufferIDs.insert(BufID); } @@ -618,7 +614,7 @@ std::unique_ptr CompilerInstance::takeSILModule() { return std::move(TheSILModule); } -ModuleDecl *CompilerInstance::getMainModule() { +ModuleDecl *CompilerInstance::getMainModule() const { if (!MainModule) { Identifier ID = Context->getIdentifier(Invocation.getModuleName()); MainModule = ModuleDecl::create(ID, *Context); diff --git a/lib/FrontendTool/FrontendTool.cpp b/lib/FrontendTool/FrontendTool.cpp index 8c2aadb0fc1..7b20c69339e 100644 --- a/lib/FrontendTool/FrontendTool.cpp +++ b/lib/FrontendTool/FrontendTool.cpp @@ -1383,7 +1383,7 @@ static void generateIR(const IRGenOptions &IRGenOpts, static bool processCommandLineAndRunImmediately(const CompilerInvocation &Invocation, CompilerInstance &Instance, - std::unique_ptr SM, + std::unique_ptr &&SM, ModuleOrSourceFile MSF, FrontendObserver *observer, int &ReturnValue) { @@ -1392,8 +1392,6 @@ static bool processCommandLineAndRunImmediately(const CompilerInvocation &Invoca const IRGenOptions &IRGenOpts = Invocation.getIRGenOptions(); const ProcessCmdLine &CmdLine = ProcessCmdLine(opts.ImmediateArgv.begin(), opts.ImmediateArgv.end()); - Instance.setSILModule(std::move(SM)); - PrettyStackTraceStringAction trace( "running user code", diff --git a/lib/Immediate/Immediate.cpp b/lib/Immediate/Immediate.cpp index 5d77a3ffc73..2adf9479df5 100644 --- a/lib/Immediate/Immediate.cpp +++ b/lib/Immediate/Immediate.cpp @@ -237,7 +237,8 @@ bool swift::immediate::autolinkImportedModules(ModuleDecl *M, int swift::RunImmediately(CompilerInstance &CI, const ProcessCmdLine &CmdLine, const IRGenOptions &IRGenOpts, - const SILOptions &SILOpts) { + const SILOptions &SILOpts, + std::unique_ptr &&SM) { ASTContext &Context = CI.getASTContext(); // IRGen the main module. @@ -246,7 +247,7 @@ int swift::RunImmediately(CompilerInstance &CI, // FIXME: We shouldn't need to use the global context here, but // something is persisting across calls to performIRGeneration. auto ModuleOwner = performIRGeneration( - IRGenOpts, swiftModule, CI.takeSILModule(), swiftModule->getName().str(), + IRGenOpts, swiftModule, std::move(SM), swiftModule->getName().str(), PSPs, getGlobalLLVMContext(), ArrayRef()); auto *Module = ModuleOwner.get(); From 2af598fb528af0dfb112eabf9cb74f86238be615 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Sat, 11 Jan 2020 22:01:50 -0800 Subject: [PATCH 13/27] [Gardening] Const-qualify Many Usages of CompilerInstance For those operations that do not need to emit diagnostics or manipulate modules, there's no reason to mutate the passed instance. --- include/swift/Frontend/Frontend.h | 19 +++++++++------- include/swift/Subsystems.h | 2 +- lib/Frontend/CompilerInvocation.cpp | 14 +++++++----- lib/FrontendTool/FrontendTool.cpp | 35 +++++++++++++++-------------- lib/IRGen/IRGen.cpp | 4 ++-- lib/Immediate/Immediate.cpp | 2 +- lib/Immediate/REPL.cpp | 2 +- 7 files changed, 43 insertions(+), 35 deletions(-) diff --git a/include/swift/Frontend/Frontend.h b/include/swift/Frontend/Frontend.h index f54e73b3db0..5c6c833a4e6 100644 --- a/include/swift/Frontend/Frontend.h +++ b/include/swift/Frontend/Frontend.h @@ -328,7 +328,7 @@ public: /// in generating a cached PCH file for the bridging header. std::string getPCHHash() const; - SourceFile::ImplicitModuleImportKind getImplicitModuleImportKind() { + SourceFile::ImplicitModuleImportKind getImplicitModuleImportKind() const { if (getInputKind() == InputFileKind::SIL) { return SourceFile::ImplicitModuleImportKind::None; } @@ -404,7 +404,7 @@ class CompilerInstance { /// Null if no tracker. std::unique_ptr DepTracker; - ModuleDecl *MainModule = nullptr; + mutable ModuleDecl *MainModule = nullptr; SerializedModuleLoader *SML = nullptr; MemoryBufferSerializedModuleLoader *MemoryBufferLoader = nullptr; @@ -453,14 +453,16 @@ public: void operator=(CompilerInstance &&) = delete; SourceManager &getSourceMgr() { return SourceMgr; } + const SourceManager &getSourceMgr() const { return SourceMgr; } DiagnosticEngine &getDiags() { return Diagnostics; } + const DiagnosticEngine &getDiags() const { return Diagnostics; } llvm::vfs::FileSystem &getFileSystem() { return *SourceMgr.getFileSystem(); } - ASTContext &getASTContext() { - return *Context; - } + ASTContext &getASTContext() { return *Context; } + const ASTContext &getASTContext() const { return *Context; } + bool hasASTContext() const { return Context != nullptr; } SILOptions &getSILOptions() { return Invocation.getSILOptions(); } @@ -483,6 +485,7 @@ public: DepTracker = llvm::make_unique(TrackSystemDeps); } DependencyTracker *getDependencyTracker() { return DepTracker.get(); } + const DependencyTracker *getDependencyTracker() const { return DepTracker.get(); } SILModule *getSILModule() { return TheSILModule.get(); @@ -494,7 +497,7 @@ public: return static_cast(TheSILModule); } - ModuleDecl *getMainModule(); + ModuleDecl *getMainModule() const; MemoryBufferSerializedModuleLoader * getMemoryBufferSerializedModuleLoader() const { @@ -515,7 +518,7 @@ public: /// Gets the set of SourceFiles which are the primary inputs for this /// CompilerInstance. - ArrayRef getPrimarySourceFiles() { + ArrayRef getPrimarySourceFiles() const { return PrimarySourceFiles; } @@ -525,7 +528,7 @@ public: /// /// FIXME: This should be removed eventually, once there are no longer any /// codepaths that rely on a single primary file. - SourceFile *getPrimarySourceFile() { + SourceFile *getPrimarySourceFile() const { if (PrimarySourceFiles.empty()) { return nullptr; } else { diff --git a/include/swift/Subsystems.h b/include/swift/Subsystems.h index f96cf488994..2d577e7c7f3 100644 --- a/include/swift/Subsystems.h +++ b/include/swift/Subsystems.h @@ -263,7 +263,7 @@ namespace swift { /// Get the CPU, subtarget feature options, and triple to use when emitting code. std::tuple, std::string> - getIRTargetOptions(ASTContext &Ctx); + getIRTargetOptions(const IRGenOptions &Opts, ASTContext &Ctx); /// Turn the given Swift module into either LLVM IR or native code /// and return the generated LLVM IR module. diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 6243771b8ae..9d861e5b126 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -111,8 +111,9 @@ static void updateRuntimeLibraryPaths(SearchPathOptions &SearchPathOpts, } } -static void setIRGenOutputOptsFromFrontendOptions(IRGenOptions &IRGenOpts, - const FrontendOptions &FrontendOpts) { +static void +setIRGenOutputOptsFromFrontendOptions(IRGenOptions &IRGenOpts, + const FrontendOptions &FrontendOpts) { // Set the OutputKind for the given Action. IRGenOpts.OutputKind = [](FrontendOptions::ActionType Action) { switch (Action) { @@ -140,8 +141,12 @@ static void setIRGenOutputOptsFromFrontendOptions(IRGenOptions &IRGenOpts, } } -static void setBridgingHeaderFromFrontendOptions(ClangImporterOptions &ImporterOpts, - const FrontendOptions &FrontendOpts) { +static void +setBridgingHeaderFromFrontendOptions(ClangImporterOptions &ImporterOpts, + const FrontendOptions &FrontendOpts) { + if (FrontendOpts.RequestedAction != FrontendOptions::ActionType::EmitPCH) + return; + // If there aren't any inputs, there's nothing to do. if (!FrontendOpts.InputsAndOutputs.hasInputs()) return; @@ -1352,7 +1357,6 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args, Opts.AutolinkRuntimeCompatibilityDynamicReplacementLibraryVersion = getRuntimeCompatVersion(); } - return false; } diff --git a/lib/FrontendTool/FrontendTool.cpp b/lib/FrontendTool/FrontendTool.cpp index 7b20c69339e..98ec4b7dabf 100644 --- a/lib/FrontendTool/FrontendTool.cpp +++ b/lib/FrontendTool/FrontendTool.cpp @@ -509,7 +509,7 @@ static bool writeSIL(SILModule &SM, ModuleDecl *M, bool EmitVerboseSIL, } static bool writeSIL(SILModule &SM, const PrimarySpecificPaths &PSPs, - CompilerInstance &Instance, + const CompilerInstance &Instance, const CompilerInvocation &Invocation) { const FrontendOptions &opts = Invocation.getFrontendOptions(); return writeSIL(SM, Instance.getMainModule(), opts.EmitVerboseSIL, @@ -640,10 +640,10 @@ static void debugFailWithCrash() { /// \return true on error. static bool emitIndexDataIfNeeded(SourceFile *PrimarySourceFile, const CompilerInvocation &Invocation, - CompilerInstance &Instance); + const CompilerInstance &Instance); static void countStatsOfSourceFile(UnifiedStatsReporter &Stats, - CompilerInstance &Instance, + const CompilerInstance &Instance, SourceFile *SF) { auto &C = Stats.getFrontendCounters(); auto &SM = Instance.getSourceMgr(); @@ -724,7 +724,7 @@ createOptRecordFile(StringRef Filename, DiagnosticEngine &DE) { } static bool precompileBridgingHeader(const CompilerInvocation &Invocation, - CompilerInstance &Instance) { + const CompilerInstance &Instance) { auto clangImporter = static_cast( Instance.getASTContext().getClangModuleLoader()); auto &ImporterOpts = Invocation.getClangImporterOptions(); @@ -743,7 +743,7 @@ static bool precompileBridgingHeader(const CompilerInvocation &Invocation, } static bool precompileClangModule(const CompilerInvocation &Invocation, - CompilerInstance &Instance) { + const CompilerInstance &Instance) { auto clangImporter = static_cast( Instance.getASTContext().getClangModuleLoader()); return clangImporter->emitPrecompiledModule( @@ -755,7 +755,7 @@ static bool precompileClangModule(const CompilerInvocation &Invocation, } static bool dumpPrecompiledClangModule(const CompilerInvocation &Invocation, - CompilerInstance &Instance) { + const CompilerInstance &Instance) { auto clangImporter = static_cast( Instance.getASTContext().getClangModuleLoader()); return clangImporter->dumpPrecompiledModule( @@ -835,7 +835,7 @@ static void verifyGenericSignaturesIfNeeded(const CompilerInvocation &Invocation } static void dumpAndPrintScopeMap(const CompilerInvocation &Invocation, - CompilerInstance &Instance, SourceFile *SF) { + const CompilerInstance &Instance, SourceFile *SF) { // Not const because may require reexpansion ASTScope &scope = SF->getScope(); @@ -854,7 +854,7 @@ static void dumpAndPrintScopeMap(const CompilerInvocation &Invocation, } static SourceFile *getPrimaryOrMainSourceFile(const CompilerInvocation &Invocation, - CompilerInstance &Instance) { + const CompilerInstance &Instance) { SourceFile *SF = Instance.getPrimarySourceFile(); if (!SF) { SourceFileKind Kind = Invocation.getSourceFileKind(); @@ -963,7 +963,7 @@ static void emitReferenceDependenciesForAllPrimaryInputsIfNeeded( } static void emitSwiftRangesForAllPrimaryInputsIfNeeded(const CompilerInvocation &Invocation, - CompilerInstance &Instance) { + const CompilerInstance &Instance) { if (Invocation.getFrontendOptions().InputsAndOutputs.hasSwiftRangesPath() && Instance.getPrimarySourceFiles().empty()) { Instance.getASTContext().Diags.diagnose( @@ -981,7 +981,7 @@ emitSwiftRangesForAllPrimaryInputsIfNeeded(const CompilerInvocation &Invocation, } static void emitCompiledSourceForAllPrimaryInputsIfNeeded(const CompilerInvocation &Invocation, - CompilerInstance &Instance) { + const CompilerInstance &Instance) { if (Invocation.getFrontendOptions() .InputsAndOutputs.hasCompiledSourcePath() && Instance.getPrimarySourceFiles().empty()) { @@ -1158,7 +1158,7 @@ performCompileStepsPostSema(const CompilerInvocation &Invocation, /// Emits index data for all primary inputs, or the main module. static bool -emitIndexData(const CompilerInvocation &Invocation, CompilerInstance &Instance) { +emitIndexData(const CompilerInvocation &Invocation, const CompilerInstance &Instance) { bool hadEmitIndexDataError = false; if (Instance.getPrimarySourceFiles().empty()) return emitIndexDataIfNeeded(nullptr, Invocation, Instance); @@ -1344,7 +1344,7 @@ static bool performCompile(CompilerInstance &Instance, } static bool serializeSIB(SILModule *SM, const PrimarySpecificPaths &PSPs, - ASTContext &Context, ModuleOrSourceFile MSF) { + const ASTContext &Context, ModuleOrSourceFile MSF) { const std::string &moduleOutputPath = PSPs.SupplementaryOutputs.ModuleOutputPath; assert(!moduleOutputPath.empty() && "must have an output path"); @@ -1399,7 +1399,8 @@ static bool processCommandLineAndRunImmediately(const CompilerInvocation &Invoca : MSF.get()->getModuleFilename()); ReturnValue = - RunImmediately(Instance, CmdLine, IRGenOpts, Invocation.getSILOptions()); + RunImmediately(Instance, CmdLine, IRGenOpts, Invocation.getSILOptions(), + std::move(SM)); return Instance.getASTContext().hadError(); } @@ -1492,7 +1493,7 @@ static bool performCompileStepsPostSILGen( FrontendOptions opts = Invocation.getFrontendOptions(); FrontendOptions::ActionType Action = opts.RequestedAction; - ASTContext &Context = Instance.getASTContext(); + const ASTContext &Context = Instance.getASTContext(); const SILOptions &SILOpts = Invocation.getSILOptions(); const IRGenOptions &IRGenOpts = Invocation.getIRGenOptions(); @@ -1512,7 +1513,7 @@ static bool performCompileStepsPostSILGen( } if (Action == FrontendOptions::ActionType::EmitSIBGen) { - serializeSIB(SM.get(), PSPs, Instance.getASTContext(), MSF); + serializeSIB(SM.get(), PSPs, Context, MSF); return Context.hadError(); } @@ -1556,7 +1557,7 @@ static bool performCompileStepsPostSILGen( moduleIsPublic); if (Action == FrontendOptions::ActionType::EmitSIB) - return serializeSIB(SM.get(), PSPs, Instance.getASTContext(), MSF); + return serializeSIB(SM.get(), PSPs, Context, MSF); { if (PSPs.haveModuleOrModuleDocOutputPaths()) { @@ -1643,7 +1644,7 @@ static bool performCompileStepsPostSILGen( static bool emitIndexDataIfNeeded(SourceFile *PrimarySourceFile, const CompilerInvocation &Invocation, - CompilerInstance &Instance) { + const CompilerInstance &Instance) { const FrontendOptions &opts = Invocation.getFrontendOptions(); if (opts.IndexStorePath.empty()) diff --git a/lib/IRGen/IRGen.cpp b/lib/IRGen/IRGen.cpp index c0021ddb330..fac4c166f93 100644 --- a/lib/IRGen/IRGen.cpp +++ b/lib/IRGen/IRGen.cpp @@ -152,7 +152,7 @@ static void addSanitizerCoveragePass(const PassManagerBuilder &Builder, std::tuple, std::string> -swift::getIRTargetOptions(ASTContext &Ctx) { +swift::getIRTargetOptions(const IRGenOptions &Opts, ASTContext &Ctx) { // Things that maybe we should collect from the command line: // - relocation model // - code model @@ -657,7 +657,7 @@ swift::createTargetMachine(const IRGenOptions &Opts, ASTContext &Ctx) { std::string EffectiveClangTriple; std::vector targetFeaturesArray; std::tie(TargetOpts, CPU, targetFeaturesArray, EffectiveClangTriple) - = getIRTargetOptions(Ctx); + = getIRTargetOptions(Opts, Ctx); const llvm::Triple &EffectiveTriple = llvm::Triple(EffectiveClangTriple); std::string targetFeatures; if (!targetFeaturesArray.empty()) { diff --git a/lib/Immediate/Immediate.cpp b/lib/Immediate/Immediate.cpp index 2adf9479df5..4037c9efabf 100644 --- a/lib/Immediate/Immediate.cpp +++ b/lib/Immediate/Immediate.cpp @@ -304,7 +304,7 @@ int swift::RunImmediately(CompilerInstance &CI, std::string Triple; std::vector Features; std::tie(TargetOpt, CPU, Features, Triple) - = getIRTargetOptions(swiftModule->getASTContext()); + = getIRTargetOptions(IRGenOpts, swiftModule->getASTContext()); builder.setRelocationModel(llvm::Reloc::PIC_); builder.setTargetOptions(TargetOpt); builder.setMCPU(CPU); diff --git a/lib/Immediate/REPL.cpp b/lib/Immediate/REPL.cpp index 3db966820c4..67c26f1c7d2 100644 --- a/lib/Immediate/REPL.cpp +++ b/lib/Immediate/REPL.cpp @@ -984,7 +984,7 @@ public: std::string Triple; std::vector Features; std::tie(TargetOpt, CPU, Features, Triple) - = getIRTargetOptions(CI.getASTContext()); + = getIRTargetOptions(IRGenOpts, CI.getASTContext()); builder.setRelocationModel(llvm::Reloc::PIC_); builder.setTargetOptions(TargetOpt); From e0ccadd3c2d226ce8540afa874f820507ee13c4d Mon Sep 17 00:00:00 2001 From: Nathan Hawes Date: Tue, 14 Jan 2020 09:12:41 -0800 Subject: [PATCH 14/27] [NFC] Small formatting fix in TypeMatcher.h --- include/swift/AST/TypeMatcher.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/swift/AST/TypeMatcher.h b/include/swift/AST/TypeMatcher.h index a81232d1d6b..05fdd68f26c 100644 --- a/include/swift/AST/TypeMatcher.h +++ b/include/swift/AST/TypeMatcher.h @@ -114,8 +114,7 @@ class TypeMatcher { bool visitUnresolvedType(CanUnresolvedType firstType, Type secondType, Type sugaredFirstType) { // Unresolved types never match. - return mismatch(firstType.getPointer(), secondType, \ - sugaredFirstType); \ + return mismatch(firstType.getPointer(), secondType, sugaredFirstType); } bool visitTupleType(CanTupleType firstTuple, Type secondType, From 0aa3125b624f6479378bd157bb9b7b63f5492921 Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Tue, 14 Jan 2020 10:21:49 -0800 Subject: [PATCH 15/27] [Testing] Eliminate REQUIRES-ANY usage REQUIRES-ANY is deprecated and being removed. Use boolean expressions. rdar://problem/58549266 --- test/Driver/autolink-force-load-no-comdat.swift | 2 +- test/SourceKit/CursorInfo/cursor_rename.swift | 2 +- test/SourceKit/DocSupport/doc_clang_module.swift | 2 +- test/SourceKit/InterfaceGen/gen_clang_module.swift | 2 +- test/SourceKit/InterfaceGen/gen_mixed_module.swift | 2 +- test/SourceKit/Refactoring/basic.swift | 2 +- test/SourceKit/Refactoring/rename-objc.swift | 2 +- .../Refactoring/semantic-refactoring/expand-default.swift | 2 +- .../Refactoring/semantic-refactoring/extract-func-default.swift | 2 +- .../semantic-refactoring/extract-func-with-args.swift | 2 +- .../Refactoring/semantic-refactoring/extract-func.swift | 2 +- .../semantic-refactoring/extract-repeated-expression.swift | 2 +- test/SourceKit/Refactoring/semantic-refactoring/fill-stub.swift | 2 +- .../Refactoring/semantic-refactoring/local-rename.swift | 2 +- .../Refactoring/semantic-refactoring/localize-string.swift | 2 +- validation-test/stdlib/Glibc.swift | 2 +- validation-test/stdlib/POSIXErrorCode.swift | 2 +- validation-test/stdlib/StringLowercasedUppercased.swift | 2 +- 18 files changed, 18 insertions(+), 18 deletions(-) diff --git a/test/Driver/autolink-force-load-no-comdat.swift b/test/Driver/autolink-force-load-no-comdat.swift index c4dc53a4734..f87d27a0337 100644 --- a/test/Driver/autolink-force-load-no-comdat.swift +++ b/test/Driver/autolink-force-load-no-comdat.swift @@ -2,7 +2,7 @@ // RUN: not %swiftc_driver -autolink-force-load -incremental %s 2>&1 | %FileCheck -check-prefix=AUTOLINK_FORCE_LOAD %s // MACHO targets do not support COMDAT -// REQUIRES-ANY: OS=macosx, OS=tvos, OS=watchos, OS=ios +// REQUIRES: OS=macosx || OS=tvos || OS=watchos || OS=ios // AUTOLINK_FORCE_LOAD: error: '-autolink-force-load' is not supported with '-incremental' diff --git a/test/SourceKit/CursorInfo/cursor_rename.swift b/test/SourceKit/CursorInfo/cursor_rename.swift index 32344a0734e..9dc350a2f42 100644 --- a/test/SourceKit/CursorInfo/cursor_rename.swift +++ b/test/SourceKit/CursorInfo/cursor_rename.swift @@ -18,4 +18,4 @@ _ = Foo.init(2) // CHECK1: Rename // CHECK2-NOT: Rename -// REQUIRES-ANY: OS=macosx, OS=linux-gnu \ No newline at end of file +// REQUIRES: OS=macosx || OS=linux-gnu diff --git a/test/SourceKit/DocSupport/doc_clang_module.swift b/test/SourceKit/DocSupport/doc_clang_module.swift index d40aac8ac4a..22be45cc641 100644 --- a/test/SourceKit/DocSupport/doc_clang_module.swift +++ b/test/SourceKit/DocSupport/doc_clang_module.swift @@ -1,7 +1,7 @@ // REQUIRES: objc_interop // FIXME: the test output we're comparing to is specific to macOS. -// REQUIRES-ANY: OS=macosx +// REQUIRES: OS=macosx // RUN: %empty-directory(%t) // RUN: %build-clang-importer-objc-overlays diff --git a/test/SourceKit/InterfaceGen/gen_clang_module.swift b/test/SourceKit/InterfaceGen/gen_clang_module.swift index b9cef439699..e6e6bfb89e3 100644 --- a/test/SourceKit/InterfaceGen/gen_clang_module.swift +++ b/test/SourceKit/InterfaceGen/gen_clang_module.swift @@ -5,7 +5,7 @@ var x: FooClassBase // REQUIRES: objc_interop // FIXME: the test output we're comparing to is specific to macOS. -// REQUIRES-ANY: OS=macosx +// REQUIRES: OS=macosx // RUN: %empty-directory(%t.overlays) // RUN: %empty-directory(%t) diff --git a/test/SourceKit/InterfaceGen/gen_mixed_module.swift b/test/SourceKit/InterfaceGen/gen_mixed_module.swift index 0bfd7119ebb..c6c9fe276c1 100644 --- a/test/SourceKit/InterfaceGen/gen_mixed_module.swift +++ b/test/SourceKit/InterfaceGen/gen_mixed_module.swift @@ -3,7 +3,7 @@ var x = 10 // REQUIRES: objc_interop // FIXME: the test output we're comparing to is specific to macOS. -// REQUIRES-ANY: OS=macosx +// REQUIRES: OS=macosx // RUN: %empty-directory(%t.overlays) // RUN: %empty-directory(%t) diff --git a/test/SourceKit/Refactoring/basic.swift b/test/SourceKit/Refactoring/basic.swift index b20f674b48a..2a0f0d439a3 100644 --- a/test/SourceKit/Refactoring/basic.swift +++ b/test/SourceKit/Refactoring/basic.swift @@ -152,4 +152,4 @@ func foo7() -> String { // CHECK-LOCALIZE-STRING: source.refactoring.kind.localize.string -// REQUIRES-ANY: OS=macosx, OS=linux-gnu \ No newline at end of file +// REQUIRES: OS=macosx || OS=linux-gnu diff --git a/test/SourceKit/Refactoring/rename-objc.swift b/test/SourceKit/Refactoring/rename-objc.swift index ac95dc4351f..6cb45bd71e3 100644 --- a/test/SourceKit/Refactoring/rename-objc.swift +++ b/test/SourceKit/Refactoring/rename-objc.swift @@ -18,4 +18,4 @@ func foo1() { // CHECK2: ACTIONS BEGIN // CHECK2-NEXT: ACTIONS END -// REQUIRES-ANY: OS=macosx, OS=linux-gnu \ No newline at end of file +// REQUIRES: OS=macosx || OS=linux-gnu diff --git a/test/SourceKit/Refactoring/semantic-refactoring/expand-default.swift b/test/SourceKit/Refactoring/semantic-refactoring/expand-default.swift index 92d35368f99..688df4ed9ae 100644 --- a/test/SourceKit/Refactoring/semantic-refactoring/expand-default.swift +++ b/test/SourceKit/Refactoring/semantic-refactoring/expand-default.swift @@ -13,4 +13,4 @@ func foo(e : E) { // RUN: %sourcekitd-test -req=expand-default -pos=7:7 %s -- %s > %t.result/expand-default.swift.expected // RUN: diff -u %S/expand-default.swift.expected %t.result/expand-default.swift.expected -// REQUIRES-ANY: OS=macosx, OS=linux-gnu +// REQUIRES: OS=macosx || OS=linux-gnu diff --git a/test/SourceKit/Refactoring/semantic-refactoring/extract-func-default.swift b/test/SourceKit/Refactoring/semantic-refactoring/extract-func-default.swift index f547b87edab..80fc52ff520 100644 --- a/test/SourceKit/Refactoring/semantic-refactoring/extract-func-default.swift +++ b/test/SourceKit/Refactoring/semantic-refactoring/extract-func-default.swift @@ -9,4 +9,4 @@ func foo() -> Int { // RUN: diff -u %S/extract-func-default.swift.expected %t.result/extract-func-default.swift.expected // FIXME: Fails on linux with assertion: "!GlibcModuleMapPath.empty()"" failed -// REQUIRES-ANY: OS=macosx +// REQUIRES: OS=macosx diff --git a/test/SourceKit/Refactoring/semantic-refactoring/extract-func-with-args.swift b/test/SourceKit/Refactoring/semantic-refactoring/extract-func-with-args.swift index 458690823ce..76a349655f0 100644 --- a/test/SourceKit/Refactoring/semantic-refactoring/extract-func-with-args.swift +++ b/test/SourceKit/Refactoring/semantic-refactoring/extract-func-with-args.swift @@ -9,4 +9,4 @@ func foo() -> Int { // RUN: diff -u %S/extract-func-with-args.swift.expected %t.result/extract-func-with-args.swift.expected // FIXME: Fails on linux with assertion: "!GlibcModuleMapPath.empty()"" failed -// REQUIRES-ANY: OS=macosx +// REQUIRES: OS=macosx diff --git a/test/SourceKit/Refactoring/semantic-refactoring/extract-func.swift b/test/SourceKit/Refactoring/semantic-refactoring/extract-func.swift index c4426191725..c8bbdb82b14 100644 --- a/test/SourceKit/Refactoring/semantic-refactoring/extract-func.swift +++ b/test/SourceKit/Refactoring/semantic-refactoring/extract-func.swift @@ -9,4 +9,4 @@ func foo() -> Int { // RUN: diff -u %S/extract-func.swift.expected %t.result/extract-func.swift.expected // FIXME: Fails on linux with assertion: "!GlibcModuleMapPath.empty()"" failed -// REQUIRES-ANY: OS=macosx +// REQUIRES: OS=macosx diff --git a/test/SourceKit/Refactoring/semantic-refactoring/extract-repeated-expression.swift b/test/SourceKit/Refactoring/semantic-refactoring/extract-repeated-expression.swift index 143c855647e..02ebf45aeb2 100644 --- a/test/SourceKit/Refactoring/semantic-refactoring/extract-repeated-expression.swift +++ b/test/SourceKit/Refactoring/semantic-refactoring/extract-repeated-expression.swift @@ -8,4 +8,4 @@ func foo() -> Int { // RUN: %sourcekitd-test -req=extract-repeated -pos=3:11 -end-pos 3:12 -name new_name %s -- %s > %t.result/extract-repeated-expression.swift.expected // RUN: diff -u %S/extract-repeated-expression.swift.expected %t.result/extract-repeated-expression.swift.expected -// REQUIRES-ANY: OS=macosx, OS=linux-gnu +// REQUIRES: OS=macosx || OS=linux-gnu diff --git a/test/SourceKit/Refactoring/semantic-refactoring/fill-stub.swift b/test/SourceKit/Refactoring/semantic-refactoring/fill-stub.swift index f972d14bc38..87bd053fa6c 100644 --- a/test/SourceKit/Refactoring/semantic-refactoring/fill-stub.swift +++ b/test/SourceKit/Refactoring/semantic-refactoring/fill-stub.swift @@ -8,4 +8,4 @@ class C1 : P {} // RUN: %sourcekitd-test -req=fill-stub -pos=5:8 %s -- %s > %t.result/fill-stub.swift.expected // RUN: diff -u %S/fill-stub.swift.expected %t.result/fill-stub.swift.expected -// REQUIRES-ANY: OS=macosx, OS=linux-gnu +// REQUIRES: OS=macosx || OS=linux-gnu diff --git a/test/SourceKit/Refactoring/semantic-refactoring/local-rename.swift b/test/SourceKit/Refactoring/semantic-refactoring/local-rename.swift index a6664eb151a..587ebcd0b26 100644 --- a/test/SourceKit/Refactoring/semantic-refactoring/local-rename.swift +++ b/test/SourceKit/Refactoring/semantic-refactoring/local-rename.swift @@ -19,4 +19,4 @@ func foo() { // RUN: %sourcekitd-test -req=find-local-rename-ranges -pos=7:11 %s -- %s > %t.result/local-rename-lazy.swift.expected // RUN: diff -u %S/local-rename-lazy.swift.expected %t.result/local-rename-lazy.swift.expected -// REQUIRES-ANY: OS=macosx, OS=linux-gnu +// REQUIRES: OS=macosx || OS=linux-gnu diff --git a/test/SourceKit/Refactoring/semantic-refactoring/localize-string.swift b/test/SourceKit/Refactoring/semantic-refactoring/localize-string.swift index ab53261d7cd..ec207d35438 100644 --- a/test/SourceKit/Refactoring/semantic-refactoring/localize-string.swift +++ b/test/SourceKit/Refactoring/semantic-refactoring/localize-string.swift @@ -6,4 +6,4 @@ func foo() -> String { // RUN: %sourcekitd-test -req=localize-string -pos=2:10 %s -- %s > %t.result/localize-string.swift.expected // RUN: diff -u %S/localize-string.swift.expected %t.result/localize-string.swift.expected -// REQUIRES-ANY: OS=macosx, OS=linux-gnu +// REQUIRES: OS=macosx || OS=linux-gnu diff --git a/validation-test/stdlib/Glibc.swift b/validation-test/stdlib/Glibc.swift index 4b1a9351641..70276d29e0b 100644 --- a/validation-test/stdlib/Glibc.swift +++ b/validation-test/stdlib/Glibc.swift @@ -6,7 +6,7 @@ // UNSUPPORTED: OS=tvos // UNSUPPORTED: OS=watchos -// REQUIRES-ANY: OS=linux-gnu, OS=linux-androideabi, OS=linux-android +// REQUIRES: OS=linux-gnu || OS=linux-androideabi || OS=linux-android import Swift import StdlibUnittest diff --git a/validation-test/stdlib/POSIXErrorCode.swift b/validation-test/stdlib/POSIXErrorCode.swift index 794425a1e6f..fe60b0c33cf 100644 --- a/validation-test/stdlib/POSIXErrorCode.swift +++ b/validation-test/stdlib/POSIXErrorCode.swift @@ -1,7 +1,7 @@ // RUN: %target-run-simple-swift // REQUIRES: executable_test // -// REQUIRES-ANY: OS=macosx, OS=ios, OS=tvos, OS=watchos, OS=linux-androideabi, OS=linux-android, OS=linux-gnu +// REQUIRES: OS=macosx || OS=ios || OS=tvos || OS=watchos || OS=linux-androideabi || OS=linux-android || OS=linux-gnu import Swift import StdlibUnittest diff --git a/validation-test/stdlib/StringLowercasedUppercased.swift b/validation-test/stdlib/StringLowercasedUppercased.swift index 60f92a552e2..7ac789cc922 100644 --- a/validation-test/stdlib/StringLowercasedUppercased.swift +++ b/validation-test/stdlib/StringLowercasedUppercased.swift @@ -5,7 +5,7 @@ // directly. It is not specific to Linux, it is just that on // Apple platforms we are using the NSString bridge right now. -// REQUIRES-ANY: OS=linux-gnu, OS=linux-android, OS=linux-androideabi +// REQUIRES: OS=linux-gnu || OS=linux-android || OS=linux-androideabi import StdlibUnittest From f7d610d2e933f29b9428161c60bd9f2bd51f2b79 Mon Sep 17 00:00:00 2001 From: Erik Eckstein Date: Tue, 14 Jan 2020 10:57:10 +0100 Subject: [PATCH 16/27] IRGen: don't create ObjC methods with the unnamed_addr attribute In some places, Foundation is comparing ObjC method pointers. Therefore LLVM's function merging pass must not create aliases for identica; functions, but instead create thunks. This can be ensured by not creating ObjC methods with the unnamed_addr attribute. rdar://problem/58483698 --- lib/IRGen/GenObjC.cpp | 7 ++- test/IRGen/abitypes.swift | 70 ++++++++++++++-------------- test/IRGen/objc_bridge.swift | 30 ++++++------ test/IRGen/objc_class_export.swift | 6 +-- test/IRGen/objc_dealloc.sil | 2 +- test/IRGen/objc_function_merge.swift | 56 ++++++++++++++++++++++ test/IRGen/objc_subscripts.swift | 2 +- 7 files changed, 116 insertions(+), 57 deletions(-) create mode 100644 test/IRGen/objc_function_merge.swift diff --git a/lib/IRGen/GenObjC.cpp b/lib/IRGen/GenObjC.cpp index e7aee4142c7..77ce2bedaed 100644 --- a/lib/IRGen/GenObjC.cpp +++ b/lib/IRGen/GenObjC.cpp @@ -919,8 +919,11 @@ static llvm::Constant *findSwiftAsObjCThunk(IRGenModule &IGM, SILDeclRef ref, assert(SILFn && "no IR function for swift-as-objc thunk"); auto fn = IGM.getAddrOfSILFunction(SILFn, NotForDefinition); ApplyIRLinkage(IRLinkage::Internal).to(fn); - fn->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global); - + // Don't add the unnamed_addr attribute: in some places Foundation is + // comparing ObjC method pointers. Therefore LLVM's function merging pass must + // not create aliases for identical functions, but create thunks. + // This can be ensured if ObjC methods are not created with the unnamed_addr + // attribute. return llvm::ConstantExpr::getBitCast(fn, IGM.Int8PtrTy); } diff --git a/test/IRGen/abitypes.swift b/test/IRGen/abitypes.swift index f6263302c74..9c27c7d4674 100644 --- a/test/IRGen/abitypes.swift +++ b/test/IRGen/abitypes.swift @@ -19,50 +19,50 @@ import Foundation class Foo { // x86_64-macosx: define hidden swiftcc { float, float, float, float } @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}F"(%T8abitypes3FooC* swiftself) {{.*}} { - // x86_64-macosx: define hidden { <2 x float>, <2 x float> } @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*) unnamed_addr {{.*}} { + // x86_64-macosx: define hidden { <2 x float>, <2 x float> } @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*) {{[#0-9]*}} { // x86_64-ios: define hidden swiftcc { float, float, float, float } @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}F"(%T8abitypes3FooC* swiftself) {{.*}} { - // x86_64-ios: define hidden { <2 x float>, <2 x float> } @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*) unnamed_addr {{.*}} { + // x86_64-ios: define hidden { <2 x float>, <2 x float> } @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*) {{[#0-9]*}} { // i386-ios: define hidden swiftcc void @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}F"(%TSo6MyRectV* noalias nocapture sret, %T8abitypes3FooC* swiftself) {{.*}} { - // i386-ios: define hidden void @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(%TSo6MyRectV* noalias nocapture sret, i8*, i8*) unnamed_addr {{.*}} { + // i386-ios: define hidden void @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(%TSo6MyRectV* noalias nocapture sret, i8*, i8*) {{[#0-9]*}} { // armv7-ios: define hidden swiftcc { float, float, float, float } @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}F"(%T8abitypes3FooC* swiftself) {{.*}} { - // armv7-ios: define hidden void @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(%TSo6MyRectV* noalias nocapture sret, i8*, i8*) unnamed_addr {{.*}} { + // armv7-ios: define hidden void @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(%TSo6MyRectV* noalias nocapture sret, i8*, i8*) {{[#0-9]*}} { // armv7s-ios: define hidden swiftcc { float, float, float, float } @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}F"(%T8abitypes3FooC* swiftself) {{.*}} { - // armv7s-ios: define hidden void @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(%TSo6MyRectV* noalias nocapture sret, i8*, i8*) unnamed_addr {{.*}} { + // armv7s-ios: define hidden void @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(%TSo6MyRectV* noalias nocapture sret, i8*, i8*) {{[#0-9]*}} { // arm64-ios: define hidden swiftcc { float, float, float, float } @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}F"(%T8abitypes3FooC* swiftself) {{.*}} { - // arm64-ios: define hidden [[ARM64_MYRECT]] @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*) unnamed_addr {{.*}} { + // arm64-ios: define hidden [[ARM64_MYRECT]] @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*) {{[#0-9]*}} { // x86_64-tvos: define hidden swiftcc { float, float, float, float } @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}F"(%T8abitypes3FooC* swiftself) {{.*}} { - // x86_64-tvos: define hidden { <2 x float>, <2 x float> } @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*) unnamed_addr {{.*}} { + // x86_64-tvos: define hidden { <2 x float>, <2 x float> } @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*) {{[#0-9]*}} { // arm64-tvos: define hidden swiftcc { float, float, float, float } @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}F"(%T8abitypes3FooC* swiftself) {{.*}} { - // arm64-tvos: define hidden [[ARM64_MYRECT]] @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*) unnamed_addr {{.*}} { + // arm64-tvos: define hidden [[ARM64_MYRECT]] @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*) {{[#0-9]*}} { // i386-watchos: define hidden swiftcc void @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}F"(%TSo6MyRectV* noalias nocapture sret, %T8abitypes3FooC* swiftself) {{.*}} { - // i386-watchos: define hidden void @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(%TSo6MyRectV* noalias nocapture sret, i8*, i8*) unnamed_addr {{.*}} { + // i386-watchos: define hidden void @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(%TSo6MyRectV* noalias nocapture sret, i8*, i8*) {{[#0-9]*}} { // armv7k-watchos: define hidden swiftcc { float, float, float, float } @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}F"(%T8abitypes3FooC* swiftself) {{.*}} { - // armv7k-watchos: define hidden [[ARMV7K_MYRECT]] @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*) unnamed_addr {{.*}} { + // armv7k-watchos: define hidden [[ARMV7K_MYRECT]] @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*) {{[#0-9]*}} { @objc dynamic func bar() -> MyRect { return MyRect(x: 1, y: 2, width: 3, height: 4) } // x86_64-macosx: define hidden swiftcc double @"$s8abitypes3FooC14getXFromNSRect{{[_0-9a-zA-Z]*}}F"(double, double, double, double, %T8abitypes3FooC* swiftself) {{.*}} { - // x86_64-macosx: define hidden double @"$s8abitypes3FooC14getXFromNSRect{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, %TSo6CGRectV* byval align 8) unnamed_addr {{.*}} { + // x86_64-macosx: define hidden double @"$s8abitypes3FooC14getXFromNSRect{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, %TSo6CGRectV* byval align 8) {{[#0-9]*}} { // armv7-ios: define hidden swiftcc double @"$s8abitypes3FooC14getXFromNSRect{{[_0-9a-zA-Z]*}}F"(float, float, float, float, %T8abitypes3FooC* swiftself) {{.*}} { - // armv7-ios: define hidden double @"$s8abitypes3FooC14getXFromNSRect{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, [4 x i32]) unnamed_addr {{.*}} { + // armv7-ios: define hidden double @"$s8abitypes3FooC14getXFromNSRect{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, [4 x i32]) {{[#0-9]*}} { // armv7s-ios: define hidden swiftcc double @"$s8abitypes3FooC14getXFromNSRect{{[_0-9a-zA-Z]*}}F"(float, float, float, float, %T8abitypes3FooC* swiftself) {{.*}} { - // armv7s-ios: define hidden double @"$s8abitypes3FooC14getXFromNSRect{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, [4 x i32]) unnamed_addr {{.*}} { + // armv7s-ios: define hidden double @"$s8abitypes3FooC14getXFromNSRect{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, [4 x i32]) {{[#0-9]*}} { // armv7k-watchos: define hidden swiftcc double @"$s8abitypes3FooC14getXFromNSRect{{[_0-9a-zA-Z]*}}F"(float, float, float, float, %T8abitypes3FooC* swiftself) {{.*}} { - // armv7k-watchos: define hidden double @"$s8abitypes3FooC14getXFromNSRect{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, [4 x float]) unnamed_addr {{.*}} { + // armv7k-watchos: define hidden double @"$s8abitypes3FooC14getXFromNSRect{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, [4 x float]) {{[#0-9]*}} { @objc dynamic func getXFromNSRect(_ r: NSRect) -> Double { return Double(r.origin.x) } // x86_64-macosx: define hidden swiftcc float @"$s8abitypes3FooC12getXFromRect{{[_0-9a-zA-Z]*}}F"(float, float, float, float, %T8abitypes3FooC* swiftself) {{.*}} { - // x86_64-macosx: define hidden float @"$s8abitypes3FooC12getXFromRect{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, <2 x float>, <2 x float>) unnamed_addr {{.*}} { + // x86_64-macosx: define hidden float @"$s8abitypes3FooC12getXFromRect{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, <2 x float>, <2 x float>) {{[#0-9]*}} { // armv7-ios: define hidden swiftcc float @"$s8abitypes3FooC12getXFromRect{{[_0-9a-zA-Z]*}}F"(float, float, float, float, %T8abitypes3FooC* swiftself) {{.*}} { - // armv7-ios: define hidden float @"$s8abitypes3FooC12getXFromRect{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, [4 x i32]) unnamed_addr {{.*}} { + // armv7-ios: define hidden float @"$s8abitypes3FooC12getXFromRect{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, [4 x i32]) {{[#0-9]*}} { // armv7s-ios: define hidden swiftcc float @"$s8abitypes3FooC12getXFromRect{{[_0-9a-zA-Z]*}}F"(float, float, float, float, %T8abitypes3FooC* swiftself) {{.*}} { - // armv7s-ios: define hidden float @"$s8abitypes3FooC12getXFromRect{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, [4 x i32]) unnamed_addr {{.*}} { + // armv7s-ios: define hidden float @"$s8abitypes3FooC12getXFromRect{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, [4 x i32]) {{[#0-9]*}} { // armv7k-watchos: define hidden swiftcc float @"$s8abitypes3FooC12getXFromRect{{[_0-9a-zA-Z]*}}F"(float, float, float, float, %T8abitypes3FooC* swiftself) {{.*}} { - // armv7k-watchos: define hidden float @"$s8abitypes3FooC12getXFromRect{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, [4 x float]) unnamed_addr {{.*}} { + // armv7k-watchos: define hidden float @"$s8abitypes3FooC12getXFromRect{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, [4 x float]) {{[#0-9]*}} { @objc dynamic func getXFromRect(_ r: MyRect) -> Float { return r.x } @@ -110,7 +110,7 @@ class Foo { } // Ensure that MyRect is passed as an indirect-byval on x86_64 because we run out of registers for direct arguments - // x86_64-macosx: define hidden float @"$s8abitypes3FooC25getXFromRectIndirectByVal{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, float, float, float, float, float, float, float, %TSo6MyRectV* byval align 8) unnamed_addr {{.*}} { + // x86_64-macosx: define hidden float @"$s8abitypes3FooC25getXFromRectIndirectByVal{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, float, float, float, float, float, float, float, %TSo6MyRectV* byval align 8) {{[#0-9]*}} { @objc dynamic func getXFromRectIndirectByVal(_: Float, second _: Float, third _: Float, fourth _: Float, fifth _: Float, sixth _: Float, @@ -173,7 +173,7 @@ class Foo { } // x86_64-macosx: define hidden swiftcc { double, double, double } @"$s8abitypes3FooC3baz{{[_0-9a-zA-Z]*}}F"(%T8abitypes3FooC* swiftself) {{.*}} { - // x86_64-macosx: define hidden void @"$s8abitypes3FooC3baz{{[_0-9a-zA-Z]*}}FTo"(%TSo4TrioV* noalias nocapture sret, i8*, i8*) unnamed_addr {{.*}} { + // x86_64-macosx: define hidden void @"$s8abitypes3FooC3baz{{[_0-9a-zA-Z]*}}FTo"(%TSo4TrioV* noalias nocapture sret, i8*, i8*) {{[#0-9]*}} { @objc dynamic func baz() -> Trio { return Trio(i: 1.0, j: 2.0, k: 3.0) } @@ -197,7 +197,7 @@ class Foo { return p.newPair() } - // x86_64-macosx: define hidden i64 @"$s8abitypes3FooC8takepair{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, i64) unnamed_addr {{.*}} { + // x86_64-macosx: define hidden i64 @"$s8abitypes3FooC8takepair{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, i64) {{[#0-9]*}} { @objc dynamic func takepair(_ p: IntPair) -> IntPair { return p } @@ -217,7 +217,7 @@ class Foo { return p.newNestedInts() } - // x86_64-macosx: define hidden i8* @"$s8abitypes3FooC9copyClass{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, i8*) unnamed_addr {{.*}} { + // x86_64-macosx: define hidden i8* @"$s8abitypes3FooC9copyClass{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, i8*) {{[#0-9]*}} { // x86_64-macosx: [[VALUE:%[0-9]+]] = call swiftcc [[TYPE:%.*]]* @"$s8abitypes3FooC9copyClass{{[_0-9a-zA-Z]*}}F" // x86_64-macosx: [[T0:%.*]] = call [[OBJC:%objc_class]]* @swift_getObjCClassFromMetadata([[TYPE]]* [[VALUE]]) // x86_64-macosx: [[RESULT:%[0-9]+]] = bitcast [[OBJC]]* [[T0]] to i8* @@ -226,7 +226,7 @@ class Foo { return a } - // x86_64-macosx: define hidden i8* @"$s8abitypes3FooC9copyProto{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, i8*) unnamed_addr {{.*}} { + // x86_64-macosx: define hidden i8* @"$s8abitypes3FooC9copyProto{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, i8*) {{[#0-9]*}} { // x86_64-macosx: [[VALUE:%[0-9]+]] = call swiftcc [[TYPE:%.*]] @"$s8abitypes3FooC9copyProto{{[_0-9a-zA-Z]*}}F" // x86_64-macosx: [[RESULT:%[0-9]+]] = bitcast [[TYPE]] [[VALUE]] to i8* // x86_64-macosx: ret i8* [[RESULT]] @@ -234,7 +234,7 @@ class Foo { return a } - // x86_64-macosx: define hidden i8* @"$s8abitypes3FooC13copyProtoComp{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, i8*) unnamed_addr {{.*}} { + // x86_64-macosx: define hidden i8* @"$s8abitypes3FooC13copyProtoComp{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, i8*) {{[#0-9]*}} { // x86_64-macosx: [[VALUE:%[0-9]+]] = call swiftcc [[TYPE:%.*]] @"$s8abitypes3FooC13copyProtoComp{{[_0-9a-zA-Z]*}}F" // x86_64-macosx: [[RESULT:%[0-9]+]] = bitcast [[TYPE]] [[VALUE]] to i8* // x86_64-macosx: ret i8* [[RESULT]] @@ -243,7 +243,7 @@ class Foo { } // x86_64-macosx: define hidden swiftcc i1 @"$s8abitypes3FooC6negate{{[_0-9a-zA-Z]*}}F"(i1, %T8abitypes3FooC* swiftself) {{.*}} { - // x86_64-macosx: define hidden signext i8 @"$s8abitypes3FooC6negate{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, i8 signext) unnamed_addr {{.*}} { + // x86_64-macosx: define hidden signext i8 @"$s8abitypes3FooC6negate{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, i8 signext) {{[#0-9]*}} { // x86_64-macosx: [[R1:%[0-9]+]] = call swiftcc i1 @"$s10ObjectiveC22_convertObjCBoolToBool{{[_0-9a-zA-Z]*}}F" // x86_64-macosx: [[R2:%[0-9]+]] = call swiftcc i1 @"$s8abitypes3FooC6negate{{[_0-9a-zA-Z]*}}F" // x86_64-macosx: [[R3:%[0-9]+]] = call swiftcc i8 @"$s10ObjectiveC22_convertBoolToObjCBool{{[_0-9a-zA-Z]*}}F"(i1 [[R2]] @@ -257,14 +257,14 @@ class Foo { // x86_64-ios-fixme: ret i1 [[R3]] // // armv7-ios-fixme: define hidden i1 @"$s8abitypes3FooC6negate{{[_0-9a-zA-Z]*}}F"(i1, %T8abitypes3FooC*) {{.*}} { - // armv7-ios-fixme: define internal signext i8 @"$s8abitypes3FooC6negate{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, i8 signext) unnamed_addr {{.*}} { + // armv7-ios-fixme: define internal signext i8 @"$s8abitypes3FooC6negate{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, i8 signext) {{[#0-9]*}} { // armv7-ios-fixme: [[R1:%[0-9]+]] = call i1 @"$s10ObjectiveC22_convertObjCBoolToBool1xSbAA0cD0V_tF" // armv7-ios-fixme: [[R2:%[0-9]+]] = call i1 @"$s8abitypes3FooC6negate{{[_0-9a-zA-Z]*}}F"(i1 [[R1]] // armv7-ios-fixme: [[R3:%[0-9]+]] = call i8 @"$s10ObjectiveC22_convertBoolToObjCBoolAA0eF0VSb1x_tF"(i1 [[R2]] // armv7-ios-fixme: ret i8 [[R3]] // // armv7s-ios-fixme: define hidden i1 @"$s8abitypes3FooC6negate{{[_0-9a-zA-Z]*}}F"(i1, %T8abitypes3FooC*) {{.*}} { - // armv7s-ios-fixme: define internal signext i8 @"$s8abitypes3FooC6negate{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, i8 signext) unnamed_addr {{.*}} { + // armv7s-ios-fixme: define internal signext i8 @"$s8abitypes3FooC6negate{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, i8 signext) {{[#0-9]*}} { // armv7s-ios-fixme: [[R1:%[0-9]+]] = call i1 @"$s10ObjectiveC22_convertObjCBoolToBool1xSbAA0cD0V_tF" // armv7s-ios-fixme: [[R2:%[0-9]+]] = call i1 @"$s8abitypes3FooC6negate{{[_0-9a-zA-Z]*}}F"(i1 [[R1]] // armv7s-ios-fixme: [[R3:%[0-9]+]] = call i8 @"$s10ObjectiveC22_convertBoolToObjCBoolAA0eF0VSb1x_tF"(i1 [[R2]] @@ -276,7 +276,7 @@ class Foo { // arm64-ios-fixme: ret i1 [[R2]] // // i386-ios-fixme: define hidden i1 @"$s8abitypes3FooC6negate{{[_0-9a-zA-Z]*}}F"(i1, %T8abitypes3FooC*) {{.*}} { - // i386-ios-fixme: define internal signext i8 @"$s8abitypes3FooC6negate{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, i8 signext) unnamed_addr {{.*}} { + // i386-ios-fixme: define internal signext i8 @"$s8abitypes3FooC6negate{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, i8 signext) {{[#0-9]*}} { // i386-ios-fixme: [[R1:%[0-9]+]] = call i1 @"$s10ObjectiveC22_convertObjCBoolToBool{{[_0-9a-zA-Z]*}}F" // i386-ios-fixme: [[R2:%[0-9]+]] = call i1 @"$s8abitypes3FooC6negate{{[_0-9a-zA-Z]*}}F"(i1 [[R1]] // i386-ios-fixme: [[R3:%[0-9]+]] = call i8 @"$s10ObjectiveC22_convertBoolToObjCBool{{[_0-9a-zA-Z]*}}F"(i1 [[R2]] @@ -464,17 +464,17 @@ class Foo { try g.negateThrowing(b) } - // x86_64-macosx: define hidden i32* @"$s8abitypes3FooC24copyUnsafeMutablePointer{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, i32*) unnamed_addr {{.*}} { + // x86_64-macosx: define hidden i32* @"$s8abitypes3FooC24copyUnsafeMutablePointer{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, i32*) {{[#0-9]*}} { @objc dynamic func copyUnsafeMutablePointer(_ p: UnsafeMutablePointer) -> UnsafeMutablePointer { return p } - // x86_64-macosx: define hidden i64 @"$s8abitypes3FooC17returnNSEnumValue{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*) unnamed_addr {{.*}} { + // x86_64-macosx: define hidden i64 @"$s8abitypes3FooC17returnNSEnumValue{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*) {{[#0-9]*}} { @objc dynamic func returnNSEnumValue() -> ByteCountFormatter.CountStyle { return .file } - // x86_64-macosx: define hidden zeroext i16 @"$s8abitypes3FooC20returnOtherEnumValue{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, i16 zeroext) unnamed_addr {{.*}} { + // x86_64-macosx: define hidden zeroext i16 @"$s8abitypes3FooC20returnOtherEnumValue{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, i16 zeroext) {{[#0-9]*}} { @objc dynamic func returnOtherEnumValue(_ choice: ChooseTo) -> ChooseTo { switch choice { case .takeIt: return .leaveIt @@ -483,7 +483,7 @@ class Foo { } // x86_64-macosx: define hidden swiftcc i32 @"$s8abitypes3FooC10getRawEnum{{[_0-9a-zA-Z]*}}F"(%T8abitypes3FooC* swiftself) {{.*}} { - // x86_64-macosx: define hidden i32 @"$s8abitypes3FooC10getRawEnum{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*) unnamed_addr {{.*}} { + // x86_64-macosx: define hidden i32 @"$s8abitypes3FooC10getRawEnum{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*) {{[#0-9]*}} { @objc dynamic func getRawEnum() -> RawEnum { return Intergalactic } @@ -493,7 +493,7 @@ class Foo { self.work = work } - // x86_64-macosx: define hidden void @"$s8abitypes3FooC13testArchetype{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, i8*) unnamed_addr {{.*}} { + // x86_64-macosx: define hidden void @"$s8abitypes3FooC13testArchetype{{[_0-9a-zA-Z]*}}FTo"(i8*, i8*, i8*) {{[#0-9]*}} { @objc dynamic func testArchetype(_ work: Work) { work.doStuff(1) // x86_64-macosx: [[OBJCPTR:%.*]] = bitcast i8* %2 to %objc_object* @@ -514,10 +514,10 @@ class Foo { } // arm64-ios: define hidden swiftcc { i64, i64, i64, i64 } @"$s8abitypes3FooC14callJustReturn{{[_0-9a-zA-Z]*}}F"(%TSo13StructReturnsC*, i64, i64, i64, i64, %T8abitypes3FooC* swiftself) {{.*}} { - // arm64-ios: define hidden void @"$s8abitypes3FooC14callJustReturn{{[_0-9a-zA-Z]*}}FTo"(%TSo9BigStructV* noalias nocapture sret, i8*, i8*, [[OPAQUE:.*]]*, %TSo9BigStructV*) unnamed_addr {{.*}} { + // arm64-ios: define hidden void @"$s8abitypes3FooC14callJustReturn{{[_0-9a-zA-Z]*}}FTo"(%TSo9BigStructV* noalias nocapture sret, i8*, i8*, [[OPAQUE:.*]]*, %TSo9BigStructV*) {{[#0-9]*}} { // // arm64-tvos: define hidden swiftcc { i64, i64, i64, i64 } @"$s8abitypes3FooC14callJustReturn{{[_0-9a-zA-Z]*}}F"(%TSo13StructReturnsC*, i64, i64, i64, i64, %T8abitypes3FooC* swiftself) {{.*}} { - // arm64-tvos: define hidden void @"$s8abitypes3FooC14callJustReturn{{[_0-9a-zA-Z]*}}FTo"(%TSo9BigStructV* noalias nocapture sret, i8*, i8*, [[OPAQUE:.*]]*, %TSo9BigStructV*) unnamed_addr {{.*}} { + // arm64-tvos: define hidden void @"$s8abitypes3FooC14callJustReturn{{[_0-9a-zA-Z]*}}FTo"(%TSo9BigStructV* noalias nocapture sret, i8*, i8*, [[OPAQUE:.*]]*, %TSo9BigStructV*) {{[#0-9]*}} { @objc dynamic func callJustReturn(_ r: StructReturns, with v: BigStruct) -> BigStruct { return r.justReturn(v) } diff --git a/test/IRGen/objc_bridge.swift b/test/IRGen/objc_bridge.swift index 6425f31b92c..eef063e5c76 100644 --- a/test/IRGen/objc_bridge.swift +++ b/test/IRGen/objc_bridge.swift @@ -130,8 +130,8 @@ var NSS : NSString = NSString() // -- NSString methods don't convert 'self' extension NSString { - // CHECK: define internal [[OPAQUE:.*]]* @"$sSo8NSStringC11objc_bridgeE13nsstrFakePropABvgTo"([[OPAQUE:.*]]*, i8*) unnamed_addr - // CHECK: define internal void @"$sSo8NSStringC11objc_bridgeE13nsstrFakePropABvsTo"([[OPAQUE:.*]]*, i8*, [[OPAQUE:.*]]*) unnamed_addr + // CHECK: define internal [[OPAQUE:.*]]* @"$sSo8NSStringC11objc_bridgeE13nsstrFakePropABvgTo"([[OPAQUE:.*]]*, i8*) {{[#0-9]*}} { + // CHECK: define internal void @"$sSo8NSStringC11objc_bridgeE13nsstrFakePropABvsTo"([[OPAQUE:.*]]*, i8*, [[OPAQUE:.*]]*) {{[#0-9]*}} { @objc var nsstrFakeProp : NSString { get { return NSS @@ -139,20 +139,20 @@ extension NSString { set {} } - // CHECK: define internal [[OPAQUE:.*]]* @"$sSo8NSStringC11objc_bridgeE11nsstrResultAByFTo"([[OPAQUE:.*]]*, i8*) unnamed_addr + // CHECK: define internal [[OPAQUE:.*]]* @"$sSo8NSStringC11objc_bridgeE11nsstrResultAByFTo"([[OPAQUE:.*]]*, i8*) {{[#0-9]*}} { @objc func nsstrResult() -> NSString { return NSS } - // CHECK: define internal void @"$sSo8NSStringC11objc_bridgeE8nsstrArg1syAB_tFTo"([[OPAQUE:.*]]*, i8*, [[OPAQUE:.*]]*) unnamed_addr + // CHECK: define internal void @"$sSo8NSStringC11objc_bridgeE8nsstrArg1syAB_tFTo"([[OPAQUE:.*]]*, i8*, [[OPAQUE:.*]]*) {{[#0-9]*}} { @objc func nsstrArg(s s: NSString) { } } class Bas : NSObject { - // CHECK: define internal [[OPAQUE:.*]]* @"$s11objc_bridge3BasC11strRealPropSSvgTo"([[OPAQUE:.*]]*, i8*) unnamed_addr {{.*}} { - // CHECK: define internal void @"$s11objc_bridge3BasC11strRealPropSSvsTo"([[OPAQUE:.*]]*, i8*, [[OPAQUE:.*]]*) unnamed_addr {{.*}} { + // CHECK: define internal [[OPAQUE:.*]]* @"$s11objc_bridge3BasC11strRealPropSSvgTo"([[OPAQUE:.*]]*, i8*) {{[#0-9]*}} { + // CHECK: define internal void @"$s11objc_bridge3BasC11strRealPropSSvsTo"([[OPAQUE:.*]]*, i8*, [[OPAQUE:.*]]*) {{[#0-9]*}} { @objc var strRealProp : String - // CHECK: define internal [[OPAQUE:.*]]* @"$s11objc_bridge3BasC11strFakePropSSvgTo"([[OPAQUE:.*]]*, i8*) unnamed_addr {{.*}} { - // CHECK: define internal void @"$s11objc_bridge3BasC11strFakePropSSvsTo"([[OPAQUE:.*]]*, i8*, [[OPAQUE:.*]]*) unnamed_addr {{.*}} { + // CHECK: define internal [[OPAQUE:.*]]* @"$s11objc_bridge3BasC11strFakePropSSvgTo"([[OPAQUE:.*]]*, i8*) {{[#0-9]*}} { + // CHECK: define internal void @"$s11objc_bridge3BasC11strFakePropSSvsTo"([[OPAQUE:.*]]*, i8*, [[OPAQUE:.*]]*) {{[#0-9]*}} { @objc var strFakeProp : String { get { return "" @@ -160,12 +160,12 @@ class Bas : NSObject { set {} } - // CHECK: define internal [[OPAQUE:.*]]* @"$s11objc_bridge3BasC13nsstrRealPropSo8NSStringCvgTo"([[OPAQUE:.*]]*, i8*) unnamed_addr {{.*}} { - // CHECK: define internal void @"$s11objc_bridge3BasC13nsstrRealPropSo8NSStringCvsTo"([[OPAQUE:.*]]*, i8*, [[OPAQUE:.*]]*) unnamed_addr {{.*}} { + // CHECK: define internal [[OPAQUE:.*]]* @"$s11objc_bridge3BasC13nsstrRealPropSo8NSStringCvgTo"([[OPAQUE:.*]]*, i8*) {{[#0-9]*}} { + // CHECK: define internal void @"$s11objc_bridge3BasC13nsstrRealPropSo8NSStringCvsTo"([[OPAQUE:.*]]*, i8*, [[OPAQUE:.*]]*) {{[#0-9]*}} { @objc var nsstrRealProp : NSString // CHECK: define hidden swiftcc %TSo8NSStringC* @"$s11objc_bridge3BasC13nsstrFakePropSo8NSStringCvg"(%T11objc_bridge3BasC* swiftself) {{.*}} { - // CHECK: define internal void @"$s11objc_bridge3BasC13nsstrFakePropSo8NSStringCvsTo"([[OPAQUE:.*]]*, i8*, [[OPAQUE:.*]]*) unnamed_addr {{.*}} { + // CHECK: define internal void @"$s11objc_bridge3BasC13nsstrFakePropSo8NSStringCvsTo"([[OPAQUE:.*]]*, i8*, [[OPAQUE:.*]]*) {{[#0-9]*}} { @objc var nsstrFakeProp : NSString { get { return NSS @@ -173,14 +173,14 @@ class Bas : NSObject { set {} } - // CHECK: define internal [[OPAQUE:.*]]* @"$s11objc_bridge3BasC9strResultSSyFTo"([[OPAQUE:.*]]*, i8*) unnamed_addr {{.*}} { + // CHECK: define internal [[OPAQUE:.*]]* @"$s11objc_bridge3BasC9strResultSSyFTo"([[OPAQUE:.*]]*, i8*) {{[#0-9]*}} { @objc func strResult() -> String { return "" } - // CHECK: define internal void @"$s11objc_bridge3BasC6strArg1sySS_tFTo"([[OPAQUE:.*]]*, i8*, [[OPAQUE:.*]]*) unnamed_addr {{.*}} { + // CHECK: define internal void @"$s11objc_bridge3BasC6strArg1sySS_tFTo"([[OPAQUE:.*]]*, i8*, [[OPAQUE:.*]]*) {{[#0-9]*}} { @objc func strArg(s s: String) { } - // CHECK: define internal [[OPAQUE:.*]]* @"$s11objc_bridge3BasC11nsstrResultSo8NSStringCyFTo"([[OPAQUE:.*]]*, i8*) unnamed_addr {{.*}} { + // CHECK: define internal [[OPAQUE:.*]]* @"$s11objc_bridge3BasC11nsstrResultSo8NSStringCyFTo"([[OPAQUE:.*]]*, i8*) {{[#0-9]*}} { @objc func nsstrResult() -> NSString { return NSS } - // CHECK: define internal void @"$s11objc_bridge3BasC8nsstrArg1sySo8NSStringC_tFTo"([[OPAQUE:.*]]*, i8*, [[OPAQUE:.*]]*) unnamed_addr {{.*}} { + // CHECK: define internal void @"$s11objc_bridge3BasC8nsstrArg1sySo8NSStringC_tFTo"([[OPAQUE:.*]]*, i8*, [[OPAQUE:.*]]*) {{[#0-9]*}} { @objc func nsstrArg(s s: NSString) { } override init() { diff --git a/test/IRGen/objc_class_export.swift b/test/IRGen/objc_class_export.swift index ccb5adc47c5..2c5b42125c4 100644 --- a/test/IRGen/objc_class_export.swift +++ b/test/IRGen/objc_class_export.swift @@ -81,7 +81,7 @@ struct BigStructWithNativeObjects { @objc func drawInRect(dirty dirty: NSRect) { } - // CHECK: define internal void @"$s17objc_class_export3FooC10drawInRect5dirtyySo6NSRectV_tFTo"([[OPAQUE:%.*]]*, i8*, [[NSRECT]]* byval align 8) unnamed_addr {{.*}} { + // CHECK: define internal void @"$s17objc_class_export3FooC10drawInRect5dirtyySo6NSRectV_tFTo"([[OPAQUE:%.*]]*, i8*, [[NSRECT]]* byval align 8) {{[#0-9]*}} { // CHECK: [[CAST:%[a-zA-Z0-9]+]] = bitcast [[OPAQUE]]* %0 to [[FOO]]* // CHECK: call swiftcc void @"$s17objc_class_export3FooC10drawInRect5dirtyySo6NSRectV_tF"(double {{.*}}, double {{.*}}, double {{.*}}, double {{.*}}, [[FOO]]* swiftself [[CAST]]) // CHECK: } @@ -90,14 +90,14 @@ struct BigStructWithNativeObjects { return NSRect(origin: NSPoint(x: 0, y: 0), size: NSSize(width: 0, height: 0)) } - // CHECK: define internal void @"$s17objc_class_export3FooC6boundsSo6NSRectVyFTo"([[NSRECT]]* noalias nocapture sret, [[OPAQUE4:%.*]]*, i8*) unnamed_addr {{.*}} { + // CHECK: define internal void @"$s17objc_class_export3FooC6boundsSo6NSRectVyFTo"([[NSRECT]]* noalias nocapture sret, [[OPAQUE4:%.*]]*, i8*) {{[#0-9]*}} { // CHECK: [[CAST:%[a-zA-Z0-9]+]] = bitcast [[OPAQUE4]]* %1 to [[FOO]]* // CHECK: call swiftcc { double, double, double, double } @"$s17objc_class_export3FooC6boundsSo6NSRectVyF"([[FOO]]* swiftself [[CAST]]) @objc func convertRectToBacking(r r: NSRect) -> NSRect { return r } - // CHECK: define internal void @"$s17objc_class_export3FooC20convertRectToBacking1rSo6NSRectVAG_tFTo"([[NSRECT]]* noalias nocapture sret, [[OPAQUE5:%.*]]*, i8*, [[NSRECT]]* byval align 8) unnamed_addr {{.*}} { + // CHECK: define internal void @"$s17objc_class_export3FooC20convertRectToBacking1rSo6NSRectVAG_tFTo"([[NSRECT]]* noalias nocapture sret, [[OPAQUE5:%.*]]*, i8*, [[NSRECT]]* byval align 8) {{[#0-9]*}} { // CHECK: [[CAST:%[a-zA-Z0-9]+]] = bitcast [[OPAQUE5]]* %1 to [[FOO]]* // CHECK: call swiftcc { double, double, double, double } @"$s17objc_class_export3FooC20convertRectToBacking1rSo6NSRectVAG_tF"(double {{.*}}, double {{.*}}, double {{.*}}, double {{.*}}, [[FOO]]* swiftself [[CAST]]) diff --git a/test/IRGen/objc_dealloc.sil b/test/IRGen/objc_dealloc.sil index 59899abc696..2c9a0624b62 100644 --- a/test/IRGen/objc_dealloc.sil +++ b/test/IRGen/objc_dealloc.sil @@ -70,7 +70,7 @@ bb0(%0 : @unowned $X, %1 : @unowned $SwiftGizmo): return %7 : $() // id: %8 } -// CHECK: define internal void @"$s12objc_dealloc10SwiftGizmoCfDTo"([[OPAQUE:%.*]]*, i8*) unnamed_addr +// CHECK: define internal void @"$s12objc_dealloc10SwiftGizmoCfDTo"([[OPAQUE:%.*]]*, i8*) {{[#0-9]*}} { sil [ossa] @$s12objc_dealloc10SwiftGizmoCfDTo : $@convention(objc_method) (SwiftGizmo) -> () { bb0(%0 : @unowned $SwiftGizmo): // CHECK-NEXT: entry diff --git a/test/IRGen/objc_function_merge.swift b/test/IRGen/objc_function_merge.swift new file mode 100644 index 00000000000..c2e07effb02 --- /dev/null +++ b/test/IRGen/objc_function_merge.swift @@ -0,0 +1,56 @@ +// RUN: %empty-directory(%t) +// RUN: %target-build-swift -O %s -module-name=test -o %t/a.out +// RUN: %target-build-swift -O %s -module-name=test -emit-ir | %FileCheck --check-prefix=CHECK-IR %s +// RUN: %target-codesign %t/a.out +// RUN: %target-run %t/a.out | %FileCheck %s +// REQUIRES: executable_test +// REQUIRES: objc_interop + +// In some places Foundation is comparing ObjC method pointers. +// Therefore LLVM's function merging pass must not create aliases for identical +// functions, but create thunks. This can be ensured if ObjC methods are not +// created with the unnamed_addr attribute. + +import Foundation + +class Base: NSObject, NSSecureCoding { + @objc public class var supportsSecureCoding: Bool { + return true + } + + @objc let s: String + + func encode(with coder: NSCoder) { + coder.encode(s, forKey: #keyPath(s)) + } + + init(s: String) { + self.s = s + } + + required init?(coder: NSCoder) { + self.s = coder.value(forKey: #keyPath(s)) as! String + } +} + +class Derived : Base { + // Make sure the overridden method is not merged with the base method (without + // creating a thunk), so that the method pointers remain distinct. + @objc public class override var supportsSecureCoding: Bool { + return true + } +} + + +// Check if the objc methods are not generated with the unnamed_addr attribute. +// CHECK-IR-DAG: define {{.*}} @"$s4test4BaseC20supportsSecureCodingSbvgZTo"({{[^\)]*}}) #{{[0-9]+}} { +// CHECK-IR-DAG: define {{.*}} @"$s4test4BaseC6encode4withySo7NSCoderC_tFTo"({{[^\)]*}}) #{{[0-9]+}} { +// CHECK-IR-DAG: define {{.*}} @"$s4test7DerivedC20supportsSecureCodingSbvgZTo"({{[^\)]*}}) #{{[0-9]+}} { + +let d = Derived(s: "") +if #available(macOS 10.13, iOS 11, tvOS 11, watchOS 4, *) { + // Check that we don't crash here. + _ = try NSKeyedArchiver.archivedData(withRootObject: d, requiringSecureCoding: true) +} +// CHECK: okay +print("okay") diff --git a/test/IRGen/objc_subscripts.swift b/test/IRGen/objc_subscripts.swift index 6beda46f8b3..3113c823aa8 100644 --- a/test/IRGen/objc_subscripts.swift +++ b/test/IRGen/objc_subscripts.swift @@ -42,7 +42,7 @@ @objc class SomeObject { @objc subscript (i : Int) -> SomeObject { - // CHECK: define internal [[OPAQUE0:%.*]]* @"$s15objc_subscripts10SomeObjectCyACSicigTo"([[OPAQUE1]]*, i8*, i64) unnamed_addr + // CHECK: define internal [[OPAQUE0:%.*]]* @"$s15objc_subscripts10SomeObjectCyACSicigTo"([[OPAQUE1]]*, i8*, i64) {{[#0-9]*}} { get { // CHECK: call swiftcc %T15objc_subscripts10SomeObjectC* @"$s15objc_subscripts10SomeObjectCyACSicig" return self From 47df8a12579de728c76f0205a45df1145b267a59 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Tue, 14 Jan 2020 15:31:01 -0500 Subject: [PATCH 17/27] SILGen: Fix assert when bridging no-payload enum case to Any It's possible for a value of a non-trivial type to have no cleanup, if the value was constructed from a no-payload enum case. Tweak the assert to check the value's ownership instead of checking the type. Fixes , . --- lib/SILGen/SILGenBridging.cpp | 2 +- test/SILGen/objc_bridging_any.swift | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/SILGen/SILGenBridging.cpp b/lib/SILGen/SILGenBridging.cpp index 873ef443695..9ecb35559c5 100644 --- a/lib/SILGen/SILGenBridging.cpp +++ b/lib/SILGen/SILGenBridging.cpp @@ -730,7 +730,7 @@ static ManagedValue emitNativeToCBridgedNonoptionalValue(SILGenFunction &SGF, nativeType); // Put the value into memory if necessary. - assert(v.getType().isTrivial(SGF.F) || v.hasCleanup()); + assert(v.getOwnershipKind() == ValueOwnershipKind::None || v.hasCleanup()); SILModuleConventions silConv(SGF.SGM.M); // bridgeAnything always takes an indirect argument as @in. // Since we don't have the SIL type here, check the current SIL stage/mode diff --git a/test/SILGen/objc_bridging_any.swift b/test/SILGen/objc_bridging_any.swift index 3a3f9f53f4a..1e1b6a0d04c 100644 --- a/test/SILGen/objc_bridging_any.swift +++ b/test/SILGen/objc_bridging_any.swift @@ -690,7 +690,15 @@ class SwiftAnyEnjoyer: NSIdLover, NSIdLoving { func takesId(viaProtocol x: Any) { } } +enum SillyOptional { + case nothing + case something(NSObject) +} +func bridgeNoPayloadEnumCase(_ receiver: NSIdLover) { + let value = SillyOptional.nothing + receiver.takesId(value) +} // CHECK-LABEL: sil_witness_table shared [serialized] GenericOption: Hashable module objc_generics { // CHECK-NEXT: base_protocol Equatable: GenericOption: Equatable module objc_generics From 7619c63f9168ee28a29046c47aa274c41be983b5 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Tue, 14 Jan 2020 15:32:55 -0500 Subject: [PATCH 18/27] SILGen: Simplify a check in SILGenBuilder::createStore() --- lib/SILGen/SILGenBuilder.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/SILGen/SILGenBuilder.cpp b/lib/SILGen/SILGenBuilder.cpp index 7815383d495..503e6d6d9b5 100644 --- a/lib/SILGen/SILGenBuilder.cpp +++ b/lib/SILGen/SILGenBuilder.cpp @@ -669,8 +669,7 @@ ManagedValue SILGenBuilder::createStore(SILLocation loc, ManagedValue value, SILValue address, StoreOwnershipQualifier qualifier) { CleanupCloner cloner(*this, value); - if (value.getType().isTrivial(SGF.F) || - value.getOwnershipKind() == ValueOwnershipKind::None) + if (value.getOwnershipKind() == ValueOwnershipKind::None) qualifier = StoreOwnershipQualifier::Trivial; createStore(loc, value.forward(SGF), address, qualifier); return cloner.clone(address); From 0aadb7c6a57af3f615bcc36e9654a78a0cacf6d4 Mon Sep 17 00:00:00 2001 From: Pavel Yaskevich Date: Tue, 14 Jan 2020 12:51:48 -0800 Subject: [PATCH 19/27] [CSDiag] NFC: Move `findResolvedMemberRef` to ConstraintSystem.cpp This method is used by diagnostics and CSApply at this point. --- lib/Sema/CSDiag.cpp | 16 ---------------- lib/Sema/ConstraintSystem.cpp | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/Sema/CSDiag.cpp b/lib/Sema/CSDiag.cpp index c100cc30c0a..acb50536c10 100644 --- a/lib/Sema/CSDiag.cpp +++ b/lib/Sema/CSDiag.cpp @@ -2303,19 +2303,3 @@ void FailureDiagnosis::diagnoseAmbiguity(Expr *E) { diagnose(E->getLoc(), diag::type_of_expression_is_ambiguous) .highlight(E->getSourceRange()); } - -/// If an UnresolvedDotExpr, SubscriptMember, etc has been resolved by the -/// constraint system, return the decl that it references. -ValueDecl *ConstraintSystem::findResolvedMemberRef(ConstraintLocator *locator) { - // See if we have a resolution for this member. - auto overload = findSelectedOverloadFor(locator); - if (!overload) - return nullptr; - - // We only want to handle the simplest decl binding. - auto choice = overload->choice; - if (choice.getKind() != OverloadChoiceKind::Decl) - return nullptr; - - return choice.getDecl(); -} diff --git a/lib/Sema/ConstraintSystem.cpp b/lib/Sema/ConstraintSystem.cpp index aefad4f372b..904a9222a9e 100644 --- a/lib/Sema/ConstraintSystem.cpp +++ b/lib/Sema/ConstraintSystem.cpp @@ -3940,3 +3940,19 @@ Expr *ConstraintSystem::buildAutoClosureExpr(Expr *expr, cacheExprTypes(result); return result; } + +/// If an UnresolvedDotExpr, SubscriptMember, etc has been resolved by the +/// constraint system, return the decl that it references. +ValueDecl *ConstraintSystem::findResolvedMemberRef(ConstraintLocator *locator) { + // See if we have a resolution for this member. + auto overload = findSelectedOverloadFor(locator); + if (!overload) + return nullptr; + + // We only want to handle the simplest decl binding. + auto choice = overload->choice; + if (choice.getKind() != OverloadChoiceKind::Decl) + return nullptr; + + return choice.getDecl(); +} From 951b85359a8b4781bae9e0735a893aee07b3dd1e Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Tue, 14 Jan 2020 13:06:57 -0800 Subject: [PATCH 20/27] [SourceKit] Disable module system headers validation in all SourceKit requests. This validation may call many stat(2). Since we don't expect system files are edited. Disable it for SourceKit requests. Even if they are edited, manual builds can validates and updates them. rdar://problem/58550697 --- lib/IDE/CompletionInstance.cpp | 5 ----- tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp | 5 +++++ tools/swift-ide-test/swift-ide-test.cpp | 2 ++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/IDE/CompletionInstance.cpp b/lib/IDE/CompletionInstance.cpp index 44dbf98a3fa..632a3b5f654 100644 --- a/lib/IDE/CompletionInstance.cpp +++ b/lib/IDE/CompletionInstance.cpp @@ -324,11 +324,6 @@ bool swift::ide::CompletionInstance::performOperation( // source text. That breaks an invariant of syntax tree building. Invocation.getLangOptions().BuildSyntaxTree = false; - // This validation may call stat(2) many times. Disable it to prevent - // performance regression. - Invocation.getSearchPathOptions().DisableModulesValidateSystemDependencies = - true; - // FIXME: ASTScopeLookup doesn't support code completion yet. Invocation.disableASTScopeLookup(); diff --git a/tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp b/tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp index 1e2b1fd10a2..1ebbcfeb254 100644 --- a/tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp +++ b/tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp @@ -539,6 +539,11 @@ bool SwiftASTManager::initCompilerInvocation( // We don't care about LLVMArgs FrontendOpts.LLVMArgs.clear(); + // This validation may call stat(2) many times. Disable it to prevent + // performance issues. + Invocation.getSearchPathOptions().DisableModulesValidateSystemDependencies = + true; + // SwiftSourceInfo files provide source location information for decls coming // from loaded modules. For most IDE use cases it either has an undesirable // impact on performance with no benefit (code completion), results in stale diff --git a/tools/swift-ide-test/swift-ide-test.cpp b/tools/swift-ide-test/swift-ide-test.cpp index 995eaaaab5e..fb2b67b7225 100644 --- a/tools/swift-ide-test/swift-ide-test.cpp +++ b/tools/swift-ide-test/swift-ide-test.cpp @@ -3436,6 +3436,8 @@ int main(int argc, char *argv[]) { options::DebugForbidTypecheckPrefix; InitInvok.getTypeCheckerOptions().DebugConstraintSolver = options::DebugConstraintSolver; + InitInvok.getSearchPathOptions().DisableModulesValidateSystemDependencies = + true; for (auto ConfigName : options::BuildConfigs) InitInvok.getLangOptions().addCustomConditionalCompilationFlag(ConfigName); From 546c5b79abf60166bf8c5744b1caa9cd831f2737 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Tue, 14 Jan 2020 08:50:47 -0800 Subject: [PATCH 21/27] tests: fix accidental `not env` usage Manually expand out the few places where we had a `not ...` substitution where the substituted value was invoking `env` to alter the environment. This pattern is not portable and causes problems when using the integrated shell, such as on Windows. This was identified during the LLVM update. This additionally corrects the use of `not` to indicate that it is expecting a crashing failure. This was resulting in the Windows tests failing as `not` was not expecting a crashing failure. --- .../swift_build_sdk_interfaces/early-exits.test-sh | 6 +++--- .../ignore-non-stdlib-failures.test-sh | 8 ++++---- .../swift_build_sdk_interfaces/xfail-logs.test-sh | 6 +++--- .../swift_build_sdk_interfaces/xfails.test-sh | 8 ++++---- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/test/ModuleInterface/swift_build_sdk_interfaces/early-exits.test-sh b/test/ModuleInterface/swift_build_sdk_interfaces/early-exits.test-sh index bf9f8ced03b..d6e53a0135c 100644 --- a/test/ModuleInterface/swift_build_sdk_interfaces/early-exits.test-sh +++ b/test/ModuleInterface/swift_build_sdk_interfaces/early-exits.test-sh @@ -1,8 +1,8 @@ -RUN: not %swift_build_sdk_interfaces 2>&1 | %FileCheck -check-prefix NO-OUTPUT %s +RUN: env SWIFT_EXEC=%swiftc_driver_plain not %{python} %utils/swift_build_sdk_interfaces.py %mcp_opt 2>&1 | %FileCheck -check-prefix NO-OUTPUT %s NO-OUTPUT: argument -o is required -RUN: not env -u SDKROOT %swift_build_sdk_interfaces -o %t 2>&1 | %FileCheck -check-prefix NO-SDK %s +RUN: env -u SDKROOT SWIFT_EXEC=%swiftc_driver_plain not %{python} %utils/swift_build_sdk_interfaces.py %mcp_opt -o %t 2>&1 | %FileCheck -check-prefix NO-SDK %s NO-SDK: SDKROOT must be set -RUN: not %swift_build_sdk_interfaces -o %t -sdk %S/nonexistent 2>&1 | %FileCheck -check-prefix BAD-SDK %s +RUN: env SWIFT_EXEC=%swiftc_driver_plain not %{python} %utils/swift_build_sdk_interfaces.py %mcp_opt -o %t -sdk %S/nonexistent 2>&1 | %FileCheck -check-prefix BAD-SDK %s BAD-SDK: invalid SDK: {{.+[/\\]nonexistent$}} diff --git a/test/ModuleInterface/swift_build_sdk_interfaces/ignore-non-stdlib-failures.test-sh b/test/ModuleInterface/swift_build_sdk_interfaces/ignore-non-stdlib-failures.test-sh index 2e2c6e925f5..5747b3cfe0d 100644 --- a/test/ModuleInterface/swift_build_sdk_interfaces/ignore-non-stdlib-failures.test-sh +++ b/test/ModuleInterface/swift_build_sdk_interfaces/ignore-non-stdlib-failures.test-sh @@ -1,4 +1,4 @@ -RUN: not %swift_build_sdk_interfaces -sdk %S/Inputs/xfails-sdk/ -v -o %t/output | %FileCheck %s +RUN: env SWIFT_EXEC=%swiftc_driver_plain not %{python} %utils/swift_build_sdk_interfaces.py %mcp_opt -sdk %S/Inputs/xfails-sdk/ -v -o %t/output | %FileCheck %s CHECK-DAG: # (FAIL) {{.+}}{{\\|/}}Bad.swiftinterface CHECK-DAG: # (PASS) {{.+}}{{\\|/}}Good.swiftinterface @@ -8,11 +8,11 @@ RUN: %swift_build_sdk_interfaces -sdk %S/Inputs/xfails-sdk/ -v -o %t/output -ign CHECK-IGNORING-FAILURES-DAG: # (XFAIL) {{.+}}{{\\|/}}Bad.swiftinterface CHECK-IGNORING-FAILURES-DAG: # (UPASS) {{.+}}{{\\|/}}Good.swiftinterface -RUN: not %swift_build_sdk_interfaces -sdk %S/Inputs/broken-stdlib-sdk/ -v -o %t/output | %FileCheck -check-prefix CHECK-BROKEN-STDLIB %s -RUN: not %swift_build_sdk_interfaces -sdk %S/Inputs/broken-stdlib-sdk/ -v -o %t/output -ignore-non-stdlib-failures | %FileCheck -check-prefix CHECK-BROKEN-STDLIB %s +RUN: env SWIFT_EXEC=%swiftc_driver_plain not %{python} %utils/swift_build_sdk_interfaces.py %mcp_opt -sdk %S/Inputs/broken-stdlib-sdk/ -v -o %t/output | %FileCheck -check-prefix CHECK-BROKEN-STDLIB %s +RUN: env SWIFT_EXEC=%swiftc_driver_plain not %{python} %utils/swift_build_sdk_interfaces.py %mcp_opt -sdk %S/Inputs/broken-stdlib-sdk/ -v -o %t/output -ignore-non-stdlib-failures | %FileCheck -check-prefix CHECK-BROKEN-STDLIB %s CHECK-BROKEN-STDLIB: # (FAIL) {{.+}}{{\\|/}}Swift.swiftinterface CHECK-BROKEN-STDLIB-NOT: {{^}}# -RUN: not %swift_build_sdk_interfaces -sdk %S/Inputs/broken-stdlib-sdk/ -v -o %t/output -skip-stdlib | %FileCheck %s +RUN: env SWIFT_EXEC=%swiftc_driver_plain not %{python} %utils/swift_build_sdk_interfaces.py %mcp_opt -sdk %S/Inputs/broken-stdlib-sdk/ -v -o %t/output -skip-stdlib | %FileCheck %s RUN: %swift_build_sdk_interfaces -sdk %S/Inputs/broken-stdlib-sdk/ -v -o %t/output -skip-stdlib -ignore-non-stdlib-failures | %FileCheck -check-prefix=CHECK-IGNORING-FAILURES %s diff --git a/test/ModuleInterface/swift_build_sdk_interfaces/xfail-logs.test-sh b/test/ModuleInterface/swift_build_sdk_interfaces/xfail-logs.test-sh index d6e9aabae4b..d9c8457df68 100644 --- a/test/ModuleInterface/swift_build_sdk_interfaces/xfail-logs.test-sh +++ b/test/ModuleInterface/swift_build_sdk_interfaces/xfail-logs.test-sh @@ -1,5 +1,5 @@ RUN: %empty-directory(%t) -RUN: not %swift_build_sdk_interfaces -sdk %S/Inputs/xfails-sdk/ -o %t/output -log-path %t/logs | %FileCheck %s +RUN: env SWIFT_EXEC=%swiftc_driver_plain not %{python} %utils/swift_build_sdk_interfaces.py %mcp_opt -sdk %S/Inputs/xfails-sdk/ -o %t/output -log-path %t/logs | %FileCheck %s RUN: %FileCheck -check-prefix PRINTS-ERROR %s < %t/logs/Bad-Bad-err.txt CHECK: # (FAIL) {{.+}}{{\\|/}}Bad.swiftinterface @@ -8,7 +8,7 @@ PRINTS-ERROR: unresolved identifier 'garbage' RUN: %empty-directory(%t) RUN: echo '["Good"]' > %t/xfails-good.json -RUN: not %swift_build_sdk_interfaces -sdk %S/Inputs/xfails-sdk/ -o %t/output -log-path %t/logs -xfails %t/xfails-good.json | %FileCheck -check-prefix=CHECK-XFAIL-GOOD %s +RUN: env SWIFT_EXEC=%swiftc_driver_plain not %{python} %utils/swift_build_sdk_interfaces.py %mcp_opt -sdk %S/Inputs/xfails-sdk/ -o %t/output -log-path %t/logs -xfails %t/xfails-good.json | %FileCheck -check-prefix=CHECK-XFAIL-GOOD %s RUN: %FileCheck -check-prefix PRINTS-ERROR %s < %t/logs/Bad-Bad-err.txt CHECK-XFAIL-GOOD-DAG: # (FAIL) {{.+}}{{\\|/}}Bad.swiftinterface @@ -30,7 +30,7 @@ RUN: %FileCheck -check-prefix PRINTS-ERROR %s < %t/logs/Bad-Bad-err.txt CHECK-XFAIL-BAD: # (XFAIL) {{.+}}{{\\|/}}Bad.swiftinterface RUN: %empty-directory(%t) -RUN: not %swift_build_sdk_interfaces -sdk %t -o %t/output -log-path %t/logs %S/Inputs/xfail-logs-framework/ | %FileCheck -check-prefix=CHECK-FRAMEWORK %s +RUN: env SWIFT_EXEC=%swiftc_driver_plain not %{python} %utils/swift_build_sdk_interfaces.py %mcp_opt -sdk %t -o %t/output -log-path %t/logs %S/Inputs/xfail-logs-framework/ | %FileCheck -check-prefix=CHECK-FRAMEWORK %s RUN: %FileCheck -check-prefix PRINTS-ERROR %s < %t/logs/BadFMWK-x86_64-apple-macos-err.txt CHECK-FRAMEWORK: # (FAIL) {{.+}}{{\\|/}}BadFMWK.swiftmodule{{\\|/}}x86_64-apple-macos.swiftinterface diff --git a/test/ModuleInterface/swift_build_sdk_interfaces/xfails.test-sh b/test/ModuleInterface/swift_build_sdk_interfaces/xfails.test-sh index 6e8f19a2371..b85baf7cd02 100644 --- a/test/ModuleInterface/swift_build_sdk_interfaces/xfails.test-sh +++ b/test/ModuleInterface/swift_build_sdk_interfaces/xfails.test-sh @@ -1,7 +1,7 @@ RUN: %empty-directory(%t) -RUN: not %swift_build_sdk_interfaces -sdk %S/Inputs/xfails-sdk/ -o %t/output 2> %t/stderr.txt | %FileCheck %s +RUN: env SWIFT_EXEC=%swiftc_driver_plain not %{python} %utils/swift_build_sdk_interfaces.py %mcp_opt -sdk %S/Inputs/xfails-sdk/ -o %t/output 2> %t/stderr.txt | %FileCheck %s RUN: %FileCheck -check-prefix PRINTS-ERROR %s < %t/stderr.txt -RUN: not %swift_build_sdk_interfaces -sdk %S/Inputs/xfails-sdk/ -v -o %t/output 2> %t/stderr.txt | %FileCheck -check-prefix CHECK-VERBOSE %s +RUN: env SWIFT_EXEC=%swiftc_driver_plain not %{python} %utils/swift_build_sdk_interfaces.py %mcp_opt -sdk %S/Inputs/xfails-sdk/ -v -o %t/output 2> %t/stderr.txt | %FileCheck -check-prefix CHECK-VERBOSE %s RUN: %FileCheck -check-prefix PRINTS-ERROR %s < %t/stderr.txt CHECK: # (FAIL) {{.+}}{{\\|/}}Bad.swiftinterface @@ -13,9 +13,9 @@ HIDES-ERROR-NOT: unresolved identifier 'garbage' RUN: %empty-directory(%t) RUN: echo '["Good"]' > %t/xfails-good.json -RUN: not %swift_build_sdk_interfaces -sdk %S/Inputs/xfails-sdk/ -o %t/output -xfails %t/xfails-good.json 2> %t/stderr.txt | %FileCheck -check-prefix=CHECK-XFAIL-GOOD %s +RUN: env SWIFT_EXEC=%swiftc_driver_plain not %{python} %utils/swift_build_sdk_interfaces.py %mcp_opt -sdk %S/Inputs/xfails-sdk/ -o %t/output -xfails %t/xfails-good.json 2> %t/stderr.txt | %FileCheck -check-prefix=CHECK-XFAIL-GOOD %s RUN: %FileCheck -check-prefix PRINTS-ERROR %s < %t/stderr.txt -RUN: not %swift_build_sdk_interfaces -sdk %S/Inputs/xfails-sdk/ -v -o %t/output -xfails %t/xfails-good.json 2> %t/stderr.txt | %FileCheck -check-prefix=CHECK-XFAIL-GOOD %s +RUN: env SWIFT_EXEC=%swiftc_driver_plain not %{python} %utils/swift_build_sdk_interfaces.py %mcp_opt -sdk %S/Inputs/xfails-sdk/ -v -o %t/output -xfails %t/xfails-good.json 2> %t/stderr.txt | %FileCheck -check-prefix=CHECK-XFAIL-GOOD %s RUN: %FileCheck -check-prefix PRINTS-ERROR %s < %t/stderr.txt CHECK-XFAIL-GOOD-DAG: # (FAIL) {{.+}}{{\\|/}}Bad.swiftinterface From b9f4e12365a4e08e6a9d4ed083eb1d90067d1995 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Tue, 14 Jan 2020 17:08:21 -0500 Subject: [PATCH 22/27] SIL: Fix visibility of final method symbols in resilient classes For resilient classes, we hide method symbols if possible, to enforce that only resilient access patterns are used to call and override methods. Final methods can be referenced directly, however, but we were incorrectly hiding them anyway if they were overrides. To consider overrides differently here only makes sense in the non-resilient case; in fact this was a regression from , which fixed a bug with non-resilient classes by adding this check. I tried to add comments and clean up the logic here a bit to be less confusing in the future. Fixes . --- lib/SIL/SILDeclRef.cpp | 77 ++++++++++++++++++++++----------- test/IRGen/method_linkage.swift | 4 ++ 2 files changed, 56 insertions(+), 25 deletions(-) diff --git a/lib/SIL/SILDeclRef.cpp b/lib/SIL/SILDeclRef.cpp index c78e6674b15..b5244327851 100644 --- a/lib/SIL/SILDeclRef.cpp +++ b/lib/SIL/SILDeclRef.cpp @@ -958,31 +958,52 @@ SubclassScope SILDeclRef::getSubclassScope() const { if (!isa(decl)) return SubclassScope::NotApplicable; - // If this declaration is a function which goes into a vtable, then it's - // symbol must be as visible as its class, because derived classes have to put - // all less visible methods of the base class into their vtables. + DeclContext *context = decl->getDeclContext(); + + // Only methods in non-final classes go in the vtable. + auto *classType = dyn_cast(context); + if (!classType || classType->isFinal()) + return SubclassScope::NotApplicable; + + // If a method appears in the vtable of a class, we must give it's symbol + // special consideration when computing visibility because the SIL-level + // linkage does not map to the symbol's visibility in a straightforward + // way. + // + // In particular, the rules are: + // - If the class metadata is not resilient, then all method symbols must + // be visible from any translation unit where a subclass might be defined, + // because the subclass metadata will re-emit all vtable entries. + // + // - For resilient classes, we do the opposite: generally, a method's symbol + // can be hidden from other translation units, because we want to enforce + // that resilient access patterns are used for method calls and overrides. + // + // Constructors and final methods are the exception here, because they can + // be called directly. + + // FIXME: This is too narrow. Any class with resilient metadata should + // probably have this, at least for method overrides that don't add new + // vtable entries. + bool isResilientClass = classType->isResilient(); if (auto *CD = dyn_cast(decl)) { + if (isResilientClass) + return SubclassScope::NotApplicable; // Initializing entry points do not appear in the vtable. if (kind == SILDeclRef::Kind::Initializer) return SubclassScope::NotApplicable; - // Non-required convenience inits do not apper in the vtable. + // Non-required convenience inits do not appear in the vtable. if (!CD->isRequired() && !CD->isDesignatedInit()) return SubclassScope::NotApplicable; } else if (isa(decl)) { - // Detructors do not appear in the vtable. + // Destructors do not appear in the vtable. return SubclassScope::NotApplicable; } else { assert(isa(decl)); } - DeclContext *context = decl->getDeclContext(); - - // Methods from extensions don't go in the vtable. - if (isa(context)) - return SubclassScope::NotApplicable; - - // Various forms of thunks don't either. + // Various forms of thunks don't go in the vtable. if (isThunk() || isForeign) return SubclassScope::NotApplicable; @@ -990,35 +1011,41 @@ SubclassScope SILDeclRef::getSubclassScope() const { if (isDefaultArgGenerator()) return SubclassScope::NotApplicable; - // Only methods in non-final classes go in the vtable. - auto *classType = context->getSelfClassDecl(); - if (!classType || classType->isFinal()) - return SubclassScope::NotApplicable; + if (decl->isFinal()) { + // Final methods only go in the vtable if they override something. + if (!decl->getOverriddenDecl()) + return SubclassScope::NotApplicable; - // Final methods only go in the vtable if they override something. - if (decl->isFinal() && !decl->getOverriddenDecl()) - return SubclassScope::NotApplicable; + // In the resilient case, we're going to be making symbols _less_ + // visible, so make sure we stop now; final methods can always be + // called directly. + if (isResilientClass) + return SubclassScope::Internal; + } assert(decl->getEffectiveAccess() <= classType->getEffectiveAccess() && "class must be as visible as its members"); - // FIXME: This is too narrow. Any class with resilient metadata should - // probably have this, at least for method overrides that don't add new - // vtable entries. - if (classType->isResilient()) { - if (isa(decl)) - return SubclassScope::NotApplicable; + if (isResilientClass) { + // The symbol should _only_ be reached via the vtable, so we're + // going to make it hidden. return SubclassScope::Resilient; } switch (classType->getEffectiveAccess()) { case AccessLevel::Private: case AccessLevel::FilePrivate: + // If the class is private, it can only be subclassed from the same + // SILModule, so we don't need to do anything. return SubclassScope::NotApplicable; case AccessLevel::Internal: case AccessLevel::Public: + // If the class is internal or public, it can only be subclassed from + // the same AST Module, but possibly a different SILModule. return SubclassScope::Internal; case AccessLevel::Open: + // If the class is open, it can be subclassed from a different + // AST Module. All method symbols are public. return SubclassScope::External; } diff --git a/test/IRGen/method_linkage.swift b/test/IRGen/method_linkage.swift index 1598200d4fe..886191eac93 100644 --- a/test/IRGen/method_linkage.swift +++ b/test/IRGen/method_linkage.swift @@ -118,6 +118,10 @@ open class OpenSubclass : OpenClass { fileprivate final override var prop: () { return () } + + // CHECK: define{{( dllexport)?}}{{( protected)?}} swiftcc void @"$s14method_linkage12OpenSubclassC4pbazyyF" + // RESILIENT: define{{( dllexport)?}}{{( protected)?}} swiftcc void @"$s14method_linkage12OpenSubclassC4pbazyyF" + public final override func pbaz() {} } // Just in case anyone wants to delete unused methods... From 64263ed3104d3718fadac5f7d4d22e870221f6b7 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Tue, 14 Jan 2020 15:59:38 -0800 Subject: [PATCH 23/27] test: loosen path pattern matching for Windows The temporary directory may be `Temp` on Windows. Permit both upper and lower case `t` in the path. --- test/Driver/multi-threaded.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Driver/multi-threaded.swift b/test/Driver/multi-threaded.swift index 76e33545bbb..84a15e5c6d5 100644 --- a/test/Driver/multi-threaded.swift +++ b/test/Driver/multi-threaded.swift @@ -55,9 +55,9 @@ // EXEC: -frontend // EXEC-DAG: -num-threads 4 // EXEC-DAG: {{[^ ]*[/\\]}}Inputs{{/|\\\\}}main.swift{{"?}} {{[^ ]*[/\\]}}multi-threaded.swift -// EXEC-DAG: -o {{.*te?mp.*[/\\]}}main{{[^ ]*}}.o{{"?}} -o {{.*te?mp.*[/\\]}}multi-threaded{{[^ ]*}}.o +// EXEC-DAG: -o {{.*[tT]e?mp.*[/\\]}}main{{[^ ]*}}.o{{"?}} -o {{.*[tT]e?mp.*[/\\]}}multi-threaded{{[^ ]*}}.o // EXEC: {{ld|clang}} -// EXEC: {{.*te?mp.*[/\\]}}main{{[^ ]*}}.o{{"?}} {{.*te?mp.*[/\\]}}multi-threaded{{[^ ]*}}.o +// EXEC: {{.*[tT]e?mp.*[/\\]}}main{{[^ ]*}}.o{{"?}} {{.*[tT]e?mp.*[/\\]}}multi-threaded{{[^ ]*}}.o // DEPENDENCIES-DAG: {{.*}}multi-threaded.o : {{.*[/\\]}}multi-threaded.swift {{.*[/\\]}}Inputs{{[/\\]}}main.swift // DEPENDENCIES-DAG: {{.*}}main.o : {{.*[/\\]}}multi-threaded.swift {{.*[/\\]}}Inputs{{[/\\]}}main.swift From 4f10b1937cd89db0a62e013a13d116d864c51e9b Mon Sep 17 00:00:00 2001 From: Varun Gandhi Date: Tue, 14 Jan 2020 16:39:13 -0800 Subject: [PATCH 24/27] [NFC] Adjust SILFunctionType layout to use TrailingObjects methods. (#29124) This makes the implementation cleaner, as well as fixes a bug in the numTrailingObjects method (which was unused). --- include/swift/AST/Types.h | 46 +++++++++++++++------------------------ lib/AST/ASTContext.cpp | 16 ++++++++------ 2 files changed, 27 insertions(+), 35 deletions(-) diff --git a/include/swift/AST/Types.h b/include/swift/AST/Types.h index e27eab4896e..c0cee8dab04 100644 --- a/include/swift/AST/Types.h +++ b/include/swift/AST/Types.h @@ -3859,7 +3859,7 @@ namespace Lowering { /// function parameter and result types. class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode, private llvm::TrailingObjects { + SILResultInfo, SILYieldInfo, CanType> { friend TrailingObjects; size_t numTrailingObjects(OverloadToken) const { @@ -3867,7 +3867,15 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode, } size_t numTrailingObjects(OverloadToken) const { - return hasErrorResult() ? 1 : 0; + return getNumResults() + (hasErrorResult() ? 1 : 0); + } + + size_t numTrailingObjects(OverloadToken) const { + return getNumYields(); + } + + size_t numTrailingObjects(OverloadToken) const { + return hasResultCache() ? 2 : 0; } public: @@ -4040,12 +4048,13 @@ private: unsigned NumAnyResults : 16; // Not including the ErrorResult. unsigned NumAnyIndirectFormalResults : 16; // Subset of NumAnyResults. + // [SILFunctionType-layout] // The layout of a SILFunctionType in memory is: // SILFunctionType // SILParameterInfo[NumParameters] // SILResultInfo[isCoroutine() ? 0 : NumAnyResults] - // SILYieldInfo[isCoroutine() ? NumAnyResults : 0] // SILResultInfo? // if hasErrorResult() + // SILYieldInfo[isCoroutine() ? NumAnyResults : 0] // CanType? // if !isCoro && NumAnyResults > 1, formal result cache // CanType? // if !isCoro && NumAnyResults > 1, all result cache @@ -4058,34 +4067,16 @@ private: } MutableArrayRef getMutableResults() { - auto *ptr = reinterpret_cast(getMutableParameters().end()); - return {ptr, getNumResults()}; + return {getTrailingObjects(), getNumResults()}; } MutableArrayRef getMutableYields() { - auto *ptr = reinterpret_cast(getMutableParameters().end()); - return {ptr, getNumYields()}; - } - - /// Return a pointer past the end of the formal results, whether they - /// are yield-results or normal results. - void *getEndOfFormalResults() { - return isCoroutine() ? static_cast(getMutableYields().end()) - : static_cast(getMutableResults().end()); + return {getTrailingObjects(), getNumYields()}; } SILResultInfo &getMutableErrorResult() { assert(hasErrorResult()); - return *reinterpret_cast(getEndOfFormalResults()); - } - - /// Return a pointer past the end of all of the results, including the - /// error result if one is present. - void *getEndOfAllResults() { - void *end = getEndOfFormalResults(); - if (hasErrorResult()) - end = reinterpret_cast(end) + sizeof(SILResultInfo); - return end; + return *(getTrailingObjects() + getNumResults()); } /// Do we have slots for caches of the normal-result tuple type? @@ -4095,14 +4086,13 @@ private: CanType &getMutableFormalResultsCache() const { assert(hasResultCache()); - auto *ptr = const_cast(this)->getEndOfAllResults(); - return *reinterpret_cast(ptr); + return *const_cast(this)->getTrailingObjects(); } CanType &getMutableAllResultsCache() const { assert(hasResultCache()); - auto *ptr = const_cast(this)->getEndOfAllResults(); - return *(reinterpret_cast(ptr) + 1); + return *(const_cast(this)->getTrailingObjects() + + 1); } SILFunctionType(GenericSignature genericSig, ExtInfo ext, diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 1704cd0f533..b335fa07111 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -3374,13 +3374,13 @@ CanSILFunctionType SILFunctionType::get( // All SILFunctionTypes are canonical. - // Allocate storage for the object. - size_t bytes = sizeof(SILFunctionType) - + sizeof(SILParameterInfo) * params.size() - + sizeof(SILYieldInfo) * yields.size() - + sizeof(SILResultInfo) * normalResults.size() - + (errorResult ? sizeof(SILResultInfo) : 0) - + (normalResults.size() > 1 ? sizeof(CanType) * 2 : 0); + // See [SILFunctionType-layout] + bool hasResultCache = normalResults.size() > 1; + size_t bytes = + totalSizeToAlloc( + params.size(), normalResults.size() + (errorResult ? 1 : 0), + yields.size(), hasResultCache ? 2 : 0); + void *mem = ctx.Allocate(bytes, alignof(SILFunctionType)); RecursiveTypeProperties properties; @@ -3411,6 +3411,8 @@ CanSILFunctionType SILFunctionType::get( params, yields, normalResults, errorResult, substitutions, genericSigIsImplied, ctx, properties, witnessMethodConformance); + assert(fnType->hasResultCache() == hasResultCache); + ctx.getImpl().SILFunctionTypes.InsertNode(fnType, insertPos); return CanSILFunctionType(fnType); } From 97d747002c1c27cd5569319abe00cdf199645570 Mon Sep 17 00:00:00 2001 From: Pavel Yaskevich Date: Tue, 14 Jan 2020 16:47:52 -0800 Subject: [PATCH 25/27] [CSBindings] Avoid inferring duplicate bindings from supertypes If there is `subtype` relationship between two type variables binding inference algorithm attempts to infer supertype bindings transitively, but it doesn't check whether some of the new types are already included in the set, which leads to duplicate solutions. --- lib/Sema/CSBindings.cpp | 100 ++++++++++++++++++++++-------------- lib/Sema/ConstraintSystem.h | 16 ++++++ 2 files changed, 77 insertions(+), 39 deletions(-) diff --git a/lib/Sema/CSBindings.cpp b/lib/Sema/CSBindings.cpp index b7b5cbf4b09..acd726261f6 100644 --- a/lib/Sema/CSBindings.cpp +++ b/lib/Sema/CSBindings.cpp @@ -21,6 +21,66 @@ using namespace swift; using namespace constraints; +void ConstraintSystem::inferTransitiveSupertypeBindings( + const llvm::SmallDenseMap + &inferredBindings, + PotentialBindings &bindings) { + auto *typeVar = bindings.TypeVar; + + llvm::SmallVector subtypeOf; + // First, let's collect all of the `subtype` constraints associated + // with this type variable. + llvm::copy_if(bindings.Sources, std::back_inserter(subtypeOf), + [&](const Constraint *constraint) -> bool { + if (constraint->getKind() != ConstraintKind::Subtype) + return false; + + auto rhs = simplifyType(constraint->getSecondType()); + return rhs->getAs() == typeVar; + }); + + if (subtypeOf.empty()) + return; + + // We need to make sure that there are no duplicate bindings in the + // set, other we'll produce multiple identical solutions. + llvm::SmallPtrSet existingTypes; + for (const auto &binding : bindings.Bindings) + existingTypes.insert(binding.BindingType->getCanonicalType()); + + for (auto *constraint : subtypeOf) { + auto *tv = + simplifyType(constraint->getFirstType())->getAs(); + if (!tv) + continue; + + auto relatedBindings = inferredBindings.find(tv); + if (relatedBindings == inferredBindings.end()) + continue; + + for (auto &binding : relatedBindings->getSecond().Bindings) { + // We need the binding kind for the potential binding to + // either be Exact or Supertypes in order for it to make sense + // to add Supertype bindings based on the relationship between + // our type variables. + if (binding.Kind != AllowedBindingKind::Exact && + binding.Kind != AllowedBindingKind::Supertypes) + continue; + + auto type = binding.BindingType; + + if (!existingTypes.insert(type->getCanonicalType()).second) + continue; + + if (ConstraintSystem::typeVarOccursInType(typeVar, type)) + continue; + + bindings.addPotentialBinding( + binding.withSameSource(type, AllowedBindingKind::Supertypes)); + } + } +} + Optional ConstraintSystem::determineBestBindings() { // Look for potential type variable bindings. @@ -44,46 +104,8 @@ ConstraintSystem::determineBestBindings() { continue; auto &bindings = cachedBindings->getSecond(); - // All of the relevant relational constraints associated with - // current type variable should be recored by its potential bindings. - for (auto *constraint : bindings.Sources) { - if (constraint->getKind() != ConstraintKind::Subtype) - continue; - auto lhs = simplifyType(constraint->getFirstType()); - auto rhs = simplifyType(constraint->getSecondType()); - - // We are only interested in 'subtype' constraints which have - // type variable on the left-hand side. - if (rhs->getAs() != typeVar) - continue; - - auto *tv = lhs->getAs(); - if (!tv) - continue; - - auto relatedBindings = cache.find(tv); - if (relatedBindings == cache.end()) - continue; - - for (auto &binding : relatedBindings->getSecond().Bindings) { - // We need the binding kind for the potential binding to - // either be Exact or Supertypes in order for it to make sense - // to add Supertype bindings based on the relationship between - // our type variables. - if (binding.Kind != AllowedBindingKind::Exact && - binding.Kind != AllowedBindingKind::Supertypes) - continue; - - auto type = binding.BindingType; - - if (ConstraintSystem::typeVarOccursInType(typeVar, type)) - continue; - - bindings.addPotentialBinding( - binding.withSameSource(type, AllowedBindingKind::Supertypes)); - } - } + inferTransitiveSupertypeBindings(cache, bindings); if (getASTContext().TypeCheckerOpts.DebugConstraintSolver) { auto &log = getASTContext().TypeCheckerDebug->getStream(); diff --git a/lib/Sema/ConstraintSystem.h b/lib/Sema/ConstraintSystem.h index 4e4610ea32f..75d1aad3ca7 100644 --- a/lib/Sema/ConstraintSystem.h +++ b/lib/Sema/ConstraintSystem.h @@ -3761,6 +3761,22 @@ private: bool &addOptionalSupertypeBindings) const; PotentialBindings getPotentialBindings(TypeVariableType *typeVar) const; + /// Detect `subtype` relationship between two type variables and + /// attempt to infer supertype bindings transitively e.g. + /// + /// Given A <: T1 <: T2 transitively A <: T2 + /// + /// Which gives us a new (superclass A) binding for T2 as well as T1. + /// + /// \param inferredBindings The set of all bindings inferred for type + /// variables in the workset. + /// \param bindings The type variable we aim to infer new supertype + /// bindings for. + void inferTransitiveSupertypeBindings( + const llvm::SmallDenseMap + &inferredBindings, + PotentialBindings &bindings); + private: /// Add a constraint to the constraint system. SolutionKind addConstraintImpl(ConstraintKind kind, Type first, Type second, From 3a520e674e2057818eff3a136147b6e3c0cf57f2 Mon Sep 17 00:00:00 2001 From: Arnold Schwaighofer Date: Tue, 14 Jan 2020 13:04:44 -0800 Subject: [PATCH 26/27] Disable test that fails spuriously This test fails sometimes with something like: SOURCE_DIR/test/ModuleInterface/ModuleCache/prebuilt-module-cache-forwarding.swift:47:8: error: malformed compiled module: BUILD_DIR/test-macosx-x86_64/ModuleInterface/ModuleCache/Output/prebuilt-module-cache-forwarding.swift.tmp/MCP/Lib-2XZQCTV44N470.swiftmodule rdar://58578342 --- .../ModuleCache/prebuilt-module-cache-forwarding.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/ModuleInterface/ModuleCache/prebuilt-module-cache-forwarding.swift b/test/ModuleInterface/ModuleCache/prebuilt-module-cache-forwarding.swift index a882d8843b6..67be554ade6 100644 --- a/test/ModuleInterface/ModuleCache/prebuilt-module-cache-forwarding.swift +++ b/test/ModuleInterface/ModuleCache/prebuilt-module-cache-forwarding.swift @@ -50,3 +50,5 @@ struct X {} let _: X = Lib.testValue // FROM-INTERFACE: [[@LINE-1]]:16: error: cannot convert value of type 'FromInterface' to specified type 'X' // FROM-PREBUILT: [[@LINE-2]]:16: error: cannot convert value of type 'FromPrebuilt' to specified type 'X' + +// REQUIRES: rdar58578342 From 49d89faad680b3db6343c6c4f70647fd2dfd66e3 Mon Sep 17 00:00:00 2001 From: Arnold Schwaighofer Date: Wed, 15 Jan 2020 07:00:01 -0800 Subject: [PATCH 27/27] Disable test that fails on the ASAN bot rdar://58569201 --- test/TBD/previous-install-name-map.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/TBD/previous-install-name-map.swift b/test/TBD/previous-install-name-map.swift index 25bfff72ebb..9099ce5a2f2 100644 --- a/test/TBD/previous-install-name-map.swift +++ b/test/TBD/previous-install-name-map.swift @@ -11,3 +11,5 @@ // CHECK: remark: previous install name for Foo in iOS is /System/Others // CHECK: remark: previous install name for Foo in tvOS is /System/Others // CHECK: remark: previous install name for Foo in watchOS is /System/Others + +// REQUIRES: rdar58569201