diff --git a/docs/Branches.md b/docs/Branches.md index edd871fe00b..e533c3af5e3 100644 --- a/docs/Branches.md +++ b/docs/Branches.md @@ -56,9 +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: new commits go to `swift/master-next` +- LLVM Project: the destination branch depends on the kind of change that must be made: -...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.)* + 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. + + 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.)* ## Automerging diff --git a/include/swift/AST/IRGenOptions.h b/include/swift/AST/IRGenOptions.h index dc6cb89d402..699385ad271 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. @@ -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/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, 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/include/swift/Frontend/Frontend.h b/include/swift/Frontend/Frontend.h index e58c2c61c98..183892bce3e 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; } @@ -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. @@ -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,11 +485,7 @@ public: DepTracker = std::make_unique(TrackSystemDeps); } 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); + const DependencyTracker *getDependencyTracker() const { return DepTracker.get(); } SILModule *getSILModule() { return TheSILModule.get(); @@ -499,7 +497,7 @@ public: return static_cast(TheSILModule); } - ModuleDecl *getMainModule(); + ModuleDecl *getMainModule() const; MemoryBufferSerializedModuleLoader * getMemoryBufferSerializedModuleLoader() const { @@ -520,7 +518,7 @@ public: /// Gets the set of SourceFiles which are the primary inputs for this /// CompilerInstance. - ArrayRef getPrimarySourceFiles() { + ArrayRef getPrimarySourceFiles() const { return PrimarySourceFiles; } @@ -530,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/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/Immediate/Immediate.h b/include/swift/Immediate/Immediate.h index 3a54005aeed..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, - 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/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 57b4fd6e318..2d577e7c7f3 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; @@ -263,13 +263,13 @@ 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(const IRGenOptions &Opts, ASTContext &Ctx); /// Turn the given Swift module into either LLVM IR or native code /// 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,9 +281,10 @@ 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, llvm::LLVMContext &LLVMContext, llvm::GlobalVariable **outModuleHash = nullptr, llvm::StringSet<> *LinkerDirectives = nullptr); @@ -291,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. @@ -299,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); @@ -314,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, @@ -324,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/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 4e42c94749f..e41d830becd 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -3376,13 +3376,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; @@ -3413,6 +3413,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); } diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 3d36dbe0a7f..9d861e5b126 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -111,6 +111,54 @@ 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 (FrontendOpts.RequestedAction != FrontendOptions::ActionType::EmitPCH) + return; + + // 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); @@ -1486,6 +1534,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/Frontend/Frontend.cpp b/lib/Frontend/Frontend.cpp index a043b7353e5..5c0daf0020d 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; @@ -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 8ece4bb67cb..a1bef6a198a 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"); @@ -510,8 +509,8 @@ static bool writeSIL(SILModule &SM, ModuleDecl *M, bool EmitVerboseSIL, } static bool writeSIL(SILModule &SM, const PrimarySpecificPaths &PSPs, - CompilerInstance &Instance, - CompilerInvocation &Invocation) { + const CompilerInstance &Instance, + const CompilerInvocation &Invocation) { const FrontendOptions &opts = Invocation.getFrontendOptions(); return writeSIL(SM, Instance.getMainModule(), opts.EmitVerboseSIL, PSPs.OutputFilename, opts.EmitSortedSIL); @@ -569,25 +568,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 @@ -660,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(); @@ -743,16 +723,13 @@ createOptRecordFile(StringRef Filename, DiagnosticEngine &DE) { return File; } -static bool precompileBridgingHeader(CompilerInvocation &Invocation, - CompilerInstance &Instance) { +static bool precompileBridgingHeader(const CompilerInvocation &Invocation, + const CompilerInstance &Instance) { auto clangImporter = static_cast( Instance.getASTContext().getClangModuleLoader()); 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); @@ -765,8 +742,8 @@ static bool precompileBridgingHeader(CompilerInvocation &Invocation, .InputsAndOutputs.getSingleOutputFilename()); } -static bool precompileClangModule(CompilerInvocation &Invocation, - CompilerInstance &Instance) { +static bool precompileClangModule(const CompilerInvocation &Invocation, + const CompilerInstance &Instance) { auto clangImporter = static_cast( Instance.getASTContext().getClangModuleLoader()); return clangImporter->emitPrecompiledModule( @@ -777,8 +754,8 @@ static bool precompileClangModule(CompilerInvocation &Invocation, .InputsAndOutputs.getSingleOutputFilename()); } -static bool dumpPrecompiledClangModule(CompilerInvocation &Invocation, - CompilerInstance &Instance) { +static bool dumpPrecompiledClangModule(const CompilerInvocation &Invocation, + const CompilerInstance &Instance) { auto clangImporter = static_cast( Instance.getASTContext().getClangModuleLoader()); return clangImporter->dumpPrecompiledModule( @@ -788,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()); @@ -804,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(); @@ -840,18 +817,14 @@ 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); } -static void verifyGenericSignaturesIfNeeded(CompilerInvocation &Invocation, +static void verifyGenericSignaturesIfNeeded(const CompilerInvocation &Invocation, ASTContext &Context) { auto verifyGenericSignaturesInModule = Invocation.getFrontendOptions().VerifyGenericSignaturesInModule; @@ -861,8 +834,8 @@ static void verifyGenericSignaturesIfNeeded(CompilerInvocation &Invocation, GenericSignatureBuilder::verifyGenericSignaturesInModule(module); } -static void dumpAndPrintScopeMap(CompilerInvocation &Invocation, - CompilerInstance &Instance, SourceFile *SF) { +static void dumpAndPrintScopeMap(const CompilerInvocation &Invocation, + const CompilerInstance &Instance, SourceFile *SF) { // Not const because may require reexpansion ASTScope &scope = SF->getScope(); @@ -880,8 +853,8 @@ static void dumpAndPrintScopeMap(CompilerInvocation &Invocation, } } -static SourceFile *getPrimaryOrMainSourceFile(CompilerInvocation &Invocation, - CompilerInstance &Instance) { +static SourceFile *getPrimaryOrMainSourceFile(const CompilerInvocation &Invocation, + const CompilerInstance &Instance) { SourceFile *SF = Instance.getPrimarySourceFile(); if (!SF) { SourceFileKind Kind = Invocation.getSourceFileKind(); @@ -892,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()) { @@ -914,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: @@ -946,7 +919,6 @@ static Optional dumpASTIfNeeded(CompilerInvocation &Invocation, case FrontendOptions::ActionType::EmitSyntax: emitSyntax(getPrimaryOrMainSourceFile(Invocation, Instance), - Invocation.getLangOptions(), Instance.getSourceMgr(), opts.InputsAndOutputs.getSingleOutputFilename()); break; @@ -963,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()) { @@ -990,8 +962,8 @@ static void emitReferenceDependenciesForAllPrimaryInputsIfNeeded( } } static void -emitSwiftRangesForAllPrimaryInputsIfNeeded(CompilerInvocation &Invocation, - CompilerInstance &Instance) { +emitSwiftRangesForAllPrimaryInputsIfNeeded(const CompilerInvocation &Invocation, + const CompilerInstance &Instance) { if (Invocation.getFrontendOptions().InputsAndOutputs.hasSwiftRangesPath() && Instance.getPrimarySourceFiles().empty()) { Instance.getASTContext().Diags.diagnose( @@ -1008,8 +980,8 @@ emitSwiftRangesForAllPrimaryInputsIfNeeded(CompilerInvocation &Invocation, } } static void -emitCompiledSourceForAllPrimaryInputsIfNeeded(CompilerInvocation &Invocation, - CompilerInstance &Instance) { +emitCompiledSourceForAllPrimaryInputsIfNeeded(const CompilerInvocation &Invocation, + const CompilerInstance &Instance) { if (Invocation.getFrontendOptions() .InputsAndOutputs.hasCompiledSourcePath() && Instance.getPrimarySourceFiles().empty()) { @@ -1027,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(); @@ -1055,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()) @@ -1104,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, @@ -1126,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(); @@ -1186,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, const CompilerInstance &Instance) { bool hadEmitIndexDataError = false; if (Instance.getPrimarySourceFiles().empty()) return emitIndexDataIfNeeded(nullptr, Invocation, Instance); @@ -1203,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(); @@ -1240,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, @@ -1371,23 +1343,8 @@ 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 ASTContext &Context, ModuleOrSourceFile MSF) { const std::string &moduleOutputPath = PSPs.SupplementaryOutputs.ModuleOutputPath; assert(!moduleOutputPath.empty() && "must have an output path"); @@ -1401,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, @@ -1414,6 +1372,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(), @@ -1422,22 +1381,17 @@ 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, + std::unique_ptr &&SM, 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)); - PrettyStackTraceStringAction trace( "running user code", @@ -1445,11 +1399,12 @@ static bool processCommandLineAndRunImmediately(CompilerInvocation &Invocation, : MSF.get()->getModuleFilename()); ReturnValue = - RunImmediately(Instance, CmdLine, IRGenOpts, Invocation.getSILOptions()); + RunImmediately(Instance, CmdLine, IRGenOpts, Invocation.getSILOptions(), + std::move(SM)); return Instance.getASTContext().hadError(); } -static bool validateTBDIfNeeded(CompilerInvocation &Invocation, +static bool validateTBDIfNeeded(const CompilerInvocation &Invocation, ModuleOrSourceFile MSF, bool astGuaranteedToCorrespondToSIL, llvm::Module &IRModule) { @@ -1488,7 +1443,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, @@ -1518,7 +1473,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(); @@ -1530,7 +1485,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, @@ -1538,9 +1493,9 @@ 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 ASTContext &Context = Instance.getASTContext(); + const SILOptions &SILOpts = Invocation.getSILOptions(); + const IRGenOptions &IRGenOpts = Invocation.getIRGenOptions(); Optional ricd; if (auto *SF = MSF.dyn_cast()) @@ -1558,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(); } @@ -1601,10 +1556,8 @@ static bool performCompileStepsPostSILGen( emitAnyWholeModulePostTypeCheckSupplementaryOutputs(Instance, Invocation, moduleIsPublic); - setPrivateDiscriminatorIfNeeded(IRGenOpts, MSF); - if (Action == FrontendOptions::ActionType::EmitSIB) - return serializeSIB(SM.get(), PSPs, Instance.getASTContext(), MSF); + return serializeSIB(SM.get(), PSPs, Context, MSF); { if (PSPs.haveModuleOrModuleDocOutputPaths()) { @@ -1651,8 +1604,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); @@ -1693,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()) @@ -1942,7 +1893,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/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/lib/IRGen/IRGen.cpp b/lib/IRGen/IRGen.cpp index e672678fa50..e9c0c9235a9 100644 --- a/lib/IRGen/IRGen.cpp +++ b/lib/IRGen/IRGen.cpp @@ -153,7 +153,7 @@ static void addSanitizerCoveragePass(const PassManagerBuilder &Builder, std::tuple, std::string> -swift::getIRTargetOptions(IRGenOptions &Opts, ASTContext &Ctx) { +swift::getIRTargetOptions(const IRGenOptions &Opts, ASTContext &Ctx) { // Things that maybe we should collect from the command line: // - relocation model // - code model @@ -180,7 +180,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); @@ -346,7 +347,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) { @@ -463,7 +464,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, @@ -651,7 +652,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; @@ -703,7 +704,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) { } @@ -814,6 +815,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; @@ -825,7 +827,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()); @@ -861,9 +864,10 @@ 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, llvm::LLVMContext &LLVMContext, SourceFile *SF = nullptr, llvm::GlobalVariable **outModuleHash = nullptr, llvm::StringSet<> *linkerDirectives = nullptr) { @@ -878,7 +882,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()); @@ -1075,7 +1080,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) { @@ -1125,7 +1130,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()); @@ -1268,7 +1274,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, @@ -1285,19 +1291,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, +performIRGeneration(const 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); } @@ -1317,7 +1325,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 = @@ -1352,7 +1360,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/IRGenDebugInfo.cpp b/lib/IRGen/IRGenDebugInfo.cpp index 59a3b75da93..1e047b2060f 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); @@ -2356,9 +2358,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 std::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..3ed07808b41 100644 --- a/lib/IRGen/IRGenModule.cpp +++ b/lib/IRGen/IRGenModule.cpp @@ -87,8 +87,9 @@ static llvm::PointerType *createStructPointerType(IRGenModule &IGM, static clang::CodeGenerator *createClangCodeGenerator(ASTContext &Context, llvm::LLVMContext &LLVMContext, - IRGenOptions &Opts, - StringRef ModuleName) { + const IRGenOptions &Opts, + 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..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(); @@ -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/lib/IRGen/MetadataRequest.cpp b/lib/IRGen/MetadataRequest.cpp index 88e2fc4033f..5b9f33dbb2c 100644 --- a/lib/IRGen/MetadataRequest.cpp +++ b/lib/IRGen/MetadataRequest.cpp @@ -2138,10 +2138,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/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 b6554d9ea45..4037c9efabf 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,11 @@ 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, + std::unique_ptr &&SM) { ASTContext &Context = CI.getASTContext(); // IRGen the main module. @@ -244,7 +247,7 @@ int swift::RunImmediately(CompilerInstance &CI, const ProcessCmdLine &CmdLine, // 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(); 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/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/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 b87b9521dbf..888aadc02cf 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())); } } @@ -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); } 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/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); 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() { 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/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(); +} 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, 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/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 diff --git a/test/IRGen/abitypes.swift b/test/IRGen/abitypes.swift index 44e3db6869e..fd9b0eafabd 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 %0) {{.*}} { - // x86_64-macosx: define hidden { <2 x float>, <2 x float> } @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1) unnamed_addr {{.*}} { + // x86_64-macosx: define hidden { <2 x float>, <2 x float> } @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1) {{.*}} { // x86_64-ios: define hidden swiftcc { float, float, float, float } @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}F"(%T8abitypes3FooC* swiftself %0) {{.*}} { - // x86_64-ios: define hidden { <2 x float>, <2 x float> } @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1) unnamed_addr {{.*}} { + // x86_64-ios: define hidden { <2 x float>, <2 x float> } @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1) {{.*}} { // i386-ios: define hidden swiftcc void @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}F"(%TSo6MyRectV* noalias nocapture sret %0, %T8abitypes3FooC* swiftself %1) {{.*}} { - // i386-ios: define hidden void @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(%TSo6MyRectV* noalias nocapture sret %0, i8* %1, i8* %2) unnamed_addr {{.*}} { + // i386-ios: define hidden void @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(%TSo6MyRectV* noalias nocapture sret %0, i8* %1, i8* %2) {{.*}} { // armv7-ios: define hidden swiftcc { float, float, float, float } @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}F"(%T8abitypes3FooC* swiftself %0) {{.*}} { - // armv7-ios: define hidden void @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(%TSo6MyRectV* noalias nocapture sret %0, i8* %1, i8* %2) unnamed_addr {{.*}} { + // armv7-ios: define hidden void @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(%TSo6MyRectV* noalias nocapture sret %0, i8* %1, i8* %2) {{.*}} { // armv7s-ios: define hidden swiftcc { float, float, float, float } @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}F"(%T8abitypes3FooC* swiftself %0) {{.*}} { - // armv7s-ios: define hidden void @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(%TSo6MyRectV* noalias nocapture sret %0, i8* %1, i8* %2) unnamed_addr {{.*}} { + // armv7s-ios: define hidden void @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(%TSo6MyRectV* noalias nocapture sret %0, i8* %1, i8* %2) {{.*}} { // arm64-ios: define hidden swiftcc { float, float, float, float } @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}F"(%T8abitypes3FooC* swiftself %0) {{.*}} { - // arm64-ios: define hidden [[ARM64_MYRECT]] @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1) unnamed_addr {{.*}} { + // arm64-ios: define hidden [[ARM64_MYRECT]] @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1) {{.*}} { // x86_64-tvos: define hidden swiftcc { float, float, float, float } @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}F"(%T8abitypes3FooC* swiftself %0) {{.*}} { - // x86_64-tvos: define hidden { <2 x float>, <2 x float> } @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %0) unnamed_addr {{.*}} { + // x86_64-tvos: define hidden { <2 x float>, <2 x float> } @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %0) {{.*}} { // arm64-tvos: define hidden swiftcc { float, float, float, float } @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}F"(%T8abitypes3FooC* swiftself %0) {{.*}} { - // arm64-tvos: define hidden [[ARM64_MYRECT]] @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1) unnamed_addr {{.*}} { + // arm64-tvos: define hidden [[ARM64_MYRECT]] @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1) {{.*}} { // i386-watchos: define hidden swiftcc void @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}F"(%TSo6MyRectV* noalias nocapture sret %0, %T8abitypes3FooC* swiftself %1) {{.*}} { - // i386-watchos: define hidden void @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(%TSo6MyRectV* noalias nocapture sret %0, i8* %1, i8* %2) unnamed_addr {{.*}} { + // i386-watchos: define hidden void @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(%TSo6MyRectV* noalias nocapture sret %0, i8* %1, i8* %2) {{.*}} { // armv7k-watchos: define hidden swiftcc { float, float, float, float } @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}F"(%T8abitypes3FooC* swiftself %0) {{.*}} { - // armv7k-watchos: define hidden [[ARMV7K_MYRECT]] @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1) unnamed_addr {{.*}} { + // armv7k-watchos: define hidden [[ARMV7K_MYRECT]] @"$s8abitypes3FooC3bar{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1) {{.*}} { @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 %0, double %1, double %2, double %3, %T8abitypes3FooC* swiftself %4) {{.*}} { - // x86_64-macosx: define hidden double @"$s8abitypes3FooC14getXFromNSRect{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1, %TSo6CGRectV* byval align 8 %2) unnamed_addr {{.*}} { + // x86_64-macosx: define hidden double @"$s8abitypes3FooC14getXFromNSRect{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1, %TSo6CGRectV* byval align 8 %2) {{.*}} { // armv7-ios: define hidden swiftcc double @"$s8abitypes3FooC14getXFromNSRect{{[_0-9a-zA-Z]*}}F"(float %0, float %1, float %2, float %3, %T8abitypes3FooC* swiftself %4) {{.*}} { - // armv7-ios: define hidden double @"$s8abitypes3FooC14getXFromNSRect{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1, [4 x i32] %2) unnamed_addr {{.*}} { + // armv7-ios: define hidden double @"$s8abitypes3FooC14getXFromNSRect{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1, [4 x i32] %2) {{.*}} { // armv7s-ios: define hidden swiftcc double @"$s8abitypes3FooC14getXFromNSRect{{[_0-9a-zA-Z]*}}F"(float %0, float %1, float %2, float %3, %T8abitypes3FooC* swiftself %3) {{.*}} { - // armv7s-ios: define hidden double @"$s8abitypes3FooC14getXFromNSRect{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1, [4 x i32] %3) unnamed_addr {{.*}} { + // armv7s-ios: define hidden double @"$s8abitypes3FooC14getXFromNSRect{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1, [4 x i32] %3) {{.*}} { // armv7k-watchos: define hidden swiftcc double @"$s8abitypes3FooC14getXFromNSRect{{[_0-9a-zA-Z]*}}F"(float %0, float %1, float %2, float %3, %T8abitypes3FooC* swiftself %4) {{.*}} { - // armv7k-watchos: define hidden double @"$s8abitypes3FooC14getXFromNSRect{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1, [4 x float] %2) unnamed_addr {{.*}} { + // armv7k-watchos: define hidden double @"$s8abitypes3FooC14getXFromNSRect{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1, [4 x float] %2) {{.*}} { @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 %0, float %1, float %2, float %3, %T8abitypes3FooC* swiftself %4) {{.*}} { - // x86_64-macosx: define hidden float @"$s8abitypes3FooC12getXFromRect{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1, <2 x float> %2, <2 x float> %3) unnamed_addr {{.*}} { + // x86_64-macosx: define hidden float @"$s8abitypes3FooC12getXFromRect{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1, <2 x float> %2, <2 x float> %3) {{.*}} { // armv7-ios: define hidden swiftcc float @"$s8abitypes3FooC12getXFromRect{{[_0-9a-zA-Z]*}}F"(float %0, float %1, float %2, float %3, %T8abitypes3FooC* swiftself %4) {{.*}} { - // armv7-ios: define hidden float @"$s8abitypes3FooC12getXFromRect{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1, [4 x i32] %2) unnamed_addr {{.*}} { + // armv7-ios: define hidden float @"$s8abitypes3FooC12getXFromRect{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1, [4 x i32] %2) {{.*}} { // armv7s-ios: define hidden swiftcc float @"$s8abitypes3FooC12getXFromRect{{[_0-9a-zA-Z]*}}F"(float %0, float %1, float %2, float %3, %T8abitypes3FooC* swiftself %4) {{.*}} { - // armv7s-ios: define hidden float @"$s8abitypes3FooC12getXFromRect{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1, [4 x i32] %2) unnamed_addr {{.*}} { + // armv7s-ios: define hidden float @"$s8abitypes3FooC12getXFromRect{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1, [4 x i32] %2) {{.*}} { // armv7k-watchos: define hidden swiftcc float @"$s8abitypes3FooC12getXFromRect{{[_0-9a-zA-Z]*}}F"(float %0, float %1, float %2, float %3, %T8abitypes3FooC* swiftself %4) {{.*}} { - // armv7k-watchos: define hidden float @"$s8abitypes3FooC12getXFromRect{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1, [4 x float] %3) unnamed_addr {{.*}} { + // armv7k-watchos: define hidden float @"$s8abitypes3FooC12getXFromRect{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1, [4 x float] %3) {{.*}} { @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* %0, i8* %1, float %2, float %3, float %4, float %5, float %6, float %7, float %8, %TSo6MyRectV* byval align 8 %9) unnamed_addr {{.*}} { + // x86_64-macosx: define hidden float @"$s8abitypes3FooC25getXFromRectIndirectByVal{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1, float %2, float %3, float %4, float %5, float %6, float %7, float %8, %TSo6MyRectV* byval align 8 %9) {{[#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 %0) {{.*}} { - // x86_64-macosx: define hidden void @"$s8abitypes3FooC3baz{{[_0-9a-zA-Z]*}}FTo"(%TSo4TrioV* noalias nocapture sret %0, i8* %1, i8* %2) unnamed_addr {{.*}} { + // x86_64-macosx: define hidden void @"$s8abitypes3FooC3baz{{[_0-9a-zA-Z]*}}FTo"(%TSo4TrioV* noalias nocapture sret %0, i8* %1, i8* %2) {{.*}} { @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* %0, i8* %1, i64 %2) unnamed_addr {{.*}} { + // x86_64-macosx: define hidden i64 @"$s8abitypes3FooC8takepair{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1, i64 %2) {{.*}} { @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* %0, i8* %1, i8* %2) unnamed_addr {{.*}} { + // x86_64-macosx: define hidden i8* @"$s8abitypes3FooC9copyClass{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1, i8* %2) {{.*}} { // 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* %0, i8* %1, i8* %2) unnamed_addr {{.*}} { + // x86_64-macosx: define hidden i8* @"$s8abitypes3FooC9copyProto{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1, i8* %2) {{.*}} { // 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* %0, i8* %1, i8* %2) unnamed_addr {{.*}} { + // x86_64-macosx: define hidden i8* @"$s8abitypes3FooC13copyProtoComp{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1, i8* %2) {{.*}} { // 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 %0, %T8abitypes3FooC* swiftself %1) {{.*}} { - // x86_64-macosx: define hidden signext i8 @"$s8abitypes3FooC6negate{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1, i8 signext %2) unnamed_addr {{.*}} { + // x86_64-macosx: define hidden signext i8 @"$s8abitypes3FooC6negate{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1, i8 signext %2) {{.*}} { // 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 %0, %T8abitypes3FooC* %1) {{.*}} { - // armv7-ios-fixme: define internal signext i8 @"$s8abitypes3FooC6negate{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1, i8 signext %2) unnamed_addr {{.*}} { + // armv7-ios-fixme: define internal signext i8 @"$s8abitypes3FooC6negate{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1, i8 signext %2) {{.*}} { // 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* %0, i8* %1, i32* %2) unnamed_addr {{.*}} { + // x86_64-macosx: define hidden i32* @"$s8abitypes3FooC24copyUnsafeMutablePointer{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1, i32* %2) {{.*}} { @objc dynamic func copyUnsafeMutablePointer(_ p: UnsafeMutablePointer) -> UnsafeMutablePointer { return p } - // x86_64-macosx: define hidden i64 @"$s8abitypes3FooC17returnNSEnumValue{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1) unnamed_addr {{.*}} { + // x86_64-macosx: define hidden i64 @"$s8abitypes3FooC17returnNSEnumValue{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1) {{.*}} { @objc dynamic func returnNSEnumValue() -> ByteCountFormatter.CountStyle { return .file } - // x86_64-macosx: define hidden zeroext i16 @"$s8abitypes3FooC20returnOtherEnumValue{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1, i16 zeroext %2) unnamed_addr {{.*}} { + // x86_64-macosx: define hidden zeroext i16 @"$s8abitypes3FooC20returnOtherEnumValue{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1, i16 zeroext %2) {{.*}} { @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 %0) {{.*}} { - // x86_64-macosx: define hidden i32 @"$s8abitypes3FooC10getRawEnum{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1) unnamed_addr {{.*}} { + // x86_64-macosx: define hidden i32 @"$s8abitypes3FooC10getRawEnum{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1) {{.*}} { @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* %0, i8* %1, i8* %2) unnamed_addr {{.*}} { + // x86_64-macosx: define hidden void @"$s8abitypes3FooC13testArchetype{{[_0-9a-zA-Z]*}}FTo"(i8* %0, i8* %1, i8* %2) {{.*}} { @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* %0, i64 %1, i64 %2, i64 %3, i64 %4, %T8abitypes3FooC* swiftself %5) {{.*}} { - // 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*) {{.*}} { // // arm64-tvos: define hidden swiftcc { i64, i64, i64, i64 } @"$s8abitypes3FooC14callJustReturn{{[_0-9a-zA-Z]*}}F"(%TSo13StructReturnsC* %0, i64 %1, i64 %2, i64 %3, i64 %4, %T8abitypes3FooC* swiftself %5) {{.*}} { - // 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*) {{.*}} { @objc dynamic func callJustReturn(_ r: StructReturns, with v: BigStruct) -> BigStruct { return r.justReturn(v) } 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/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... diff --git a/test/IRGen/objc_bridge.swift b/test/IRGen/objc_bridge.swift index 340f4a577c7..20147403ce4 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:.*]]* %0, i8* %1) unnamed_addr - // CHECK: define internal void @"$sSo8NSStringC11objc_bridgeE13nsstrFakePropABvsTo"([[OPAQUE:.*]]* %0, i8* %1, [[OPAQUE:.*]]* %2) unnamed_addr + // CHECK: define internal [[OPAQUE:.*]]* @"$sSo8NSStringC11objc_bridgeE13nsstrFakePropABvgTo"([[OPAQUE:.*]]* %0, i8* %1) + // CHECK: define internal void @"$sSo8NSStringC11objc_bridgeE13nsstrFakePropABvsTo"([[OPAQUE:.*]]* %0, i8* %1, [[OPAQUE:.*]]* %2) @objc var nsstrFakeProp : NSString { get { return NSS @@ -139,20 +139,20 @@ extension NSString { set {} } - // CHECK: define internal [[OPAQUE:.*]]* @"$sSo8NSStringC11objc_bridgeE11nsstrResultAByFTo"([[OPAQUE:.*]]* %0, i8* %1) unnamed_addr + // CHECK: define internal [[OPAQUE:.*]]* @"$sSo8NSStringC11objc_bridgeE11nsstrResultAByFTo"([[OPAQUE:.*]]* %0, i8* %1) @objc func nsstrResult() -> NSString { return NSS } - // CHECK: define internal void @"$sSo8NSStringC11objc_bridgeE8nsstrArg1syAB_tFTo"([[OPAQUE:.*]]* %0, i8* %1, [[OPAQUE:.*]]* %2) unnamed_addr + // CHECK: define internal void @"$sSo8NSStringC11objc_bridgeE8nsstrArg1syAB_tFTo"([[OPAQUE:.*]]* %0, i8* %1, [[OPAQUE:.*]]* %2) @objc func nsstrArg(s s: NSString) { } } class Bas : NSObject { - // CHECK: define internal [[OPAQUE:.*]]* @"$s11objc_bridge3BasC11strRealPropSSvgTo"([[OPAQUE:.*]]* %0, i8* %1) unnamed_addr {{.*}} { - // CHECK: define internal void @"$s11objc_bridge3BasC11strRealPropSSvsTo"([[OPAQUE:.*]]* %0, i8* %1, [[OPAQUE:.*]]* %2) unnamed_addr {{.*}} { + // CHECK: define internal [[OPAQUE:.*]]* @"$s11objc_bridge3BasC11strRealPropSSvgTo"([[OPAQUE:.*]]* %0, i8* %1) {{.*}} { + // CHECK: define internal void @"$s11objc_bridge3BasC11strRealPropSSvsTo"([[OPAQUE:.*]]* %0, i8* %1, [[OPAQUE:.*]]* %2) {{.*}} { @objc var strRealProp : String - // CHECK: define internal [[OPAQUE:.*]]* @"$s11objc_bridge3BasC11strFakePropSSvgTo"([[OPAQUE:.*]]* %0, i8* %1) unnamed_addr {{.*}} { - // CHECK: define internal void @"$s11objc_bridge3BasC11strFakePropSSvsTo"([[OPAQUE:.*]]* %0, i8* %1, [[OPAQUE:.*]]* %2) unnamed_addr {{.*}} { + // CHECK: define internal [[OPAQUE:.*]]* @"$s11objc_bridge3BasC11strFakePropSSvgTo"([[OPAQUE:.*]]* %0, i8* %1) {{.*}} { + // CHECK: define internal void @"$s11objc_bridge3BasC11strFakePropSSvsTo"([[OPAQUE:.*]]* %0, i8* %1, [[OPAQUE:.*]]* %2) {{.*}} { @objc var strFakeProp : String { get { return "" @@ -160,12 +160,12 @@ class Bas : NSObject { set {} } - // CHECK: define internal [[OPAQUE:.*]]* @"$s11objc_bridge3BasC13nsstrRealPropSo8NSStringCvgTo"([[OPAQUE:.*]]* %0, i8* %1) unnamed_addr {{.*}} { - // CHECK: define internal void @"$s11objc_bridge3BasC13nsstrRealPropSo8NSStringCvsTo"([[OPAQUE:.*]]* %0, i8* %1, [[OPAQUE:.*]]* %2) unnamed_addr {{.*}} { + // CHECK: define internal [[OPAQUE:.*]]* @"$s11objc_bridge3BasC13nsstrRealPropSo8NSStringCvgTo"([[OPAQUE:.*]]* %0, i8* %1) {{.*}} { + // CHECK: define internal void @"$s11objc_bridge3BasC13nsstrRealPropSo8NSStringCvsTo"([[OPAQUE:.*]]* %0, i8* %1, [[OPAQUE:.*]]* %2) {{.*}} { @objc var nsstrRealProp : NSString // CHECK: define hidden swiftcc %TSo8NSStringC* @"$s11objc_bridge3BasC13nsstrFakePropSo8NSStringCvg"(%T11objc_bridge3BasC* swiftself %0) {{.*}} { - // CHECK: define internal void @"$s11objc_bridge3BasC13nsstrFakePropSo8NSStringCvsTo"([[OPAQUE:.*]]* %0, i8* %1, [[OPAQUE:.*]]* %2) unnamed_addr {{.*}} { + // CHECK: define internal void @"$s11objc_bridge3BasC13nsstrFakePropSo8NSStringCvsTo"([[OPAQUE:.*]]* %0, i8* %1, [[OPAQUE:.*]]* %2) {{.*}} { @objc var nsstrFakeProp : NSString { get { return NSS @@ -173,14 +173,14 @@ class Bas : NSObject { set {} } - // CHECK: define internal [[OPAQUE:.*]]* @"$s11objc_bridge3BasC9strResultSSyFTo"([[OPAQUE:.*]]* %0, i8* %1) unnamed_addr {{.*}} { + // CHECK: define internal [[OPAQUE:.*]]* @"$s11objc_bridge3BasC9strResultSSyFTo"([[OPAQUE:.*]]* %0, i8* %1) {{.*}} { @objc func strResult() -> String { return "" } - // CHECK: define internal void @"$s11objc_bridge3BasC6strArg1sySS_tFTo"([[OPAQUE:.*]]* %0, i8* %1, [[OPAQUE:.*]]* %2) unnamed_addr {{.*}} { + // CHECK: define internal void @"$s11objc_bridge3BasC6strArg1sySS_tFTo"([[OPAQUE:.*]]* %0, i8* %1, [[OPAQUE:.*]]* %2) {{.*}} { @objc func strArg(s s: String) { } - // CHECK: define internal [[OPAQUE:.*]]* @"$s11objc_bridge3BasC11nsstrResultSo8NSStringCyFTo"([[OPAQUE:.*]]* %0, i8* %1) unnamed_addr {{.*}} { + // CHECK: define internal [[OPAQUE:.*]]* @"$s11objc_bridge3BasC11nsstrResultSo8NSStringCyFTo"([[OPAQUE:.*]]* %0, i8* %1) {{.*}} { @objc func nsstrResult() -> NSString { return NSS } - // CHECK: define internal void @"$s11objc_bridge3BasC8nsstrArg1sySo8NSStringC_tFTo"([[OPAQUE:.*]]* %0, i8* %1, [[OPAQUE:.*]]* %2) unnamed_addr {{.*}} { + // CHECK: define internal void @"$s11objc_bridge3BasC8nsstrArg1sySo8NSStringC_tFTo"([[OPAQUE:.*]]* %0, i8* %1, [[OPAQUE:.*]]* %2) {{.*}} { @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 d627da20b8d..f181fb6f442 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:%.*]]* %0, i8* %1, [[NSRECT]]* byval align 8 %2) unnamed_addr {{.*}} { + // CHECK: define internal void @"$s17objc_class_export3FooC10drawInRect5dirtyySo6NSRectV_tFTo"([[OPAQUE:%.*]]* %0, i8* %1, [[NSRECT]]* byval align 8 %2) {{[#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 %0, [[OPAQUE4:%.*]]* %1, i8* %2) unnamed_addr {{.*}} { + // CHECK: define internal void @"$s17objc_class_export3FooC6boundsSo6NSRectVyFTo"([[NSRECT]]* noalias nocapture sret %0, [[OPAQUE4:%.*]]* %1, i8* %2) {{.*}} { // 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 %0, [[OPAQUE5:%.*]]* %1, i8* %2, [[NSRECT]]* byval align 8 %3) unnamed_addr {{.*}} { + // CHECK: define internal void @"$s17objc_class_export3FooC20convertRectToBacking1rSo6NSRectVAG_tFTo"([[NSRECT]]* noalias nocapture sret %0, [[OPAQUE5:%.*]]* %1, i8* %2, [[NSRECT]]* byval align 8 %3) {{.*}} { // 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 ef6609225a7..15a33f7f184 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:%.*]]* %0, i8* %1) unnamed_addr +// CHECK: define internal void @"$s12objc_dealloc10SwiftGizmoCfDTo"([[OPAQUE:%.*]]* %0, i8* %1) {{[#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 498d7941a02..2399743a743 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]]* %0, i8* %1, i64 %2) unnamed_addr + // CHECK: define internal [[OPAQUE0:%.*]]* @"$s15objc_subscripts10SomeObjectCyACSicigTo"([[OPAQUE1]]* %0, i8* %1, i64 %2) {{[#0-9]*}} { get { // CHECK: call swiftcc %T15objc_subscripts10SomeObjectC* @"$s15objc_subscripts10SomeObjectCyACSicig" return self diff --git a/test/IRGen/objc_types_as_member.sil b/test/IRGen/objc_types_as_member.sil index b996fe96c2e..381b3528e41 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 %0, %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())) 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 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 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 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/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 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/sil-opt/SILOpt.cpp b/tools/sil-opt/SILOpt.cpp index 410604741a0..d157810f096 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); } diff --git a/tools/swift-ide-test/swift-ide-test.cpp b/tools/swift-ide-test/swift-ide-test.cpp index f09d37aa625..e49842609c5 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); 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