From ef8825bfe6bf9e78a20f266ad049b8f9e44ec901 Mon Sep 17 00:00:00 2001 From: Ben Barham Date: Fri, 2 Feb 2024 22:19:39 -0800 Subject: [PATCH] Migrate llvm::Optional to std::optional LLVM has removed llvm::Optional, move over to std::optional. Also clang-format to fix up all the renamed #includes. --- include/swift/ABI/ObjectFile.h | 12 +- include/swift/ABI/TypeIdentity.h | 3 +- .../swift/APIDigester/ModuleAnalyzerNodes.h | 16 +- include/swift/AST/ASTContext.h | 8 +- include/swift/AST/ASTDemangler.h | 10 +- include/swift/AST/ASTMangler.h | 6 +- include/swift/AST/ASTPrinter.h | 13 +- include/swift/AST/ASTScope.h | 8 +- include/swift/AST/ASTTypeIDZone.def | 4 +- include/swift/AST/ASTTypeIDs.h | 2 +- include/swift/AST/ASTWalker.h | 21 +- .../AST/AbstractSourceFileDepGraphFactory.h | 14 +- include/swift/AST/AccessNotes.h | 14 +- include/swift/AST/AccessRequests.h | 6 +- include/swift/AST/AccessScope.h | 7 +- include/swift/AST/AnyFunctionRef.h | 7 +- include/swift/AST/ArgumentList.h | 27 +- include/swift/AST/Attr.h | 91 ++- include/swift/AST/AutoDiff.h | 10 +- include/swift/AST/Availability.h | 11 +- include/swift/AST/CaptureInfo.h | 2 +- include/swift/AST/CatchNode.h | 10 +- include/swift/AST/ClangModuleLoader.h | 2 +- include/swift/AST/Comment.h | 10 +- include/swift/AST/ConstTypeInfo.h | 30 +- include/swift/AST/Decl.h | 149 +++-- include/swift/AST/DeclContext.h | 4 +- include/swift/AST/DiagnosticConsumer.h | 11 +- include/swift/AST/DiagnosticEngine.h | 8 +- include/swift/AST/Expr.h | 27 +- include/swift/AST/ExtInfo.h | 11 +- include/swift/AST/FileUnit.h | 28 +- include/swift/AST/FineGrainedDependencies.h | 42 +- include/swift/AST/ForeignAsyncConvention.h | 20 +- include/swift/AST/ForeignInfo.h | 4 +- include/swift/AST/GenericEnvironment.h | 2 +- include/swift/AST/IRGenOptions.h | 6 +- include/swift/AST/IRGenRequests.h | 6 +- include/swift/AST/Identifier.h | 2 +- include/swift/AST/Import.h | 27 +- include/swift/AST/KnownProtocols.h | 4 +- include/swift/AST/LifetimeDependence.h | 8 +- include/swift/AST/Module.h | 6 +- include/swift/AST/ModuleDependencies.h | 43 +- include/swift/AST/ModuleLoader.h | 6 +- include/swift/AST/NameLookupRequests.h | 14 +- include/swift/AST/PackConformance.h | 4 +- include/swift/AST/ParameterList.h | 2 +- include/swift/AST/ParseRequests.h | 10 +- include/swift/AST/PlatformKind.h | 8 +- include/swift/AST/PluginLoader.h | 4 +- include/swift/AST/PrettyStackTrace.h | 9 +- include/swift/AST/PrintOptions.h | 10 +- include/swift/AST/ProtocolConformance.h | 40 +- include/swift/AST/ProtocolConformanceRef.h | 6 +- include/swift/AST/Requirement.h | 7 +- include/swift/AST/RequirementMatch.h | 19 +- include/swift/AST/SILGenRequests.h | 6 +- include/swift/AST/SearchPathOptions.h | 19 +- include/swift/AST/SourceFile.h | 24 +- include/swift/AST/Stmt.h | 69 ++- include/swift/AST/SubstitutionMap.h | 6 +- include/swift/AST/SwiftNameTranslation.h | 2 +- include/swift/AST/ThrownErrorDestination.h | 8 +- include/swift/AST/Type.h | 17 +- include/swift/AST/TypeCheckRequests.h | 170 +++--- include/swift/AST/TypeCheckerTypeIDZone.def | 4 +- include/swift/AST/TypeRepr.h | 8 +- include/swift/AST/Types.h | 81 ++- include/swift/AST/Witness.h | 13 +- include/swift/Basic/AnyValue.h | 4 +- include/swift/Basic/BlotMapVector.h | 10 +- include/swift/Basic/BlotSetVector.h | 20 +- include/swift/Basic/CTypeIDZone.def | 2 +- include/swift/Basic/Cache.h | 7 +- include/swift/Basic/ClusteredBitVector.h | 12 +- include/swift/Basic/EditorPlaceholder.h | 4 +- include/swift/Basic/Feature.h | 8 +- include/swift/Basic/Fingerprint.h | 4 +- include/swift/Basic/FrozenMultiMap.h | 60 +- include/swift/Basic/JSONSerialization.h | 10 +- include/swift/Basic/LangOptions.h | 18 +- include/swift/Basic/Lazy.h | 5 +- include/swift/Basic/MultiMapCache.h | 15 +- include/swift/Basic/OptionSet.h | 7 +- include/swift/Basic/OptionalEnum.h | 2 +- include/swift/Basic/ParseableOutput.h | 2 +- include/swift/Basic/Platform.h | 6 +- include/swift/Basic/PlaygroundOption.h | 4 +- include/swift/Basic/PointerIntEnum.h | 6 +- include/swift/Basic/Program.h | 5 +- include/swift/Basic/STLExtras.h | 18 +- include/swift/Basic/SourceManager.h | 23 +- include/swift/Basic/Statistic.h | 12 +- include/swift/Basic/StringExtras.h | 12 +- include/swift/Basic/SuccessorMap.h | 8 +- include/swift/Basic/TargetInfo.h | 4 +- include/swift/Basic/TaskQueue.h | 16 +- include/swift/Basic/TypeID.h | 2 +- include/swift/Basic/UUID.h | 4 +- include/swift/Basic/Version.h | 5 +- include/swift/ClangImporter/ClangImporter.h | 12 +- .../ClangImporter/ClangImporterRequests.h | 2 +- include/swift/ClangImporter/ClangModule.h | 4 +- include/swift/Demangling/ManglingUtils.h | 8 +- include/swift/Demangling/TypeDecoder.h | 65 ++- .../DependencyScan/ModuleDependencyScanner.h | 6 +- include/swift/Driver/Action.h | 8 +- include/swift/Driver/Compilation.h | 14 +- include/swift/Driver/Driver.h | 4 +- include/swift/Driver/Job.h | 8 +- include/swift/Driver/ToolChain.h | 2 +- include/swift/Frontend/CASOutputBackends.h | 2 +- include/swift/Frontend/Frontend.h | 23 +- include/swift/Frontend/FrontendOptions.h | 10 +- .../swift/Frontend/ModuleInterfaceLoader.h | 29 +- include/swift/IDE/APIDigesterData.h | 13 +- include/swift/IDE/AfterPoundExprCompletion.h | 4 +- include/swift/IDE/ArgumentCompletion.h | 4 +- include/swift/IDE/CodeCompletionCache.h | 6 +- include/swift/IDE/CodeCompletionString.h | 5 +- .../swift/IDE/CodeCompletionStringPrinter.h | 4 +- include/swift/IDE/CompletionLookup.h | 23 +- include/swift/IDE/IDEBridging.h | 8 +- include/swift/IDE/ImportDepth.h | 4 +- include/swift/IDE/ModuleInterfacePrinting.h | 4 +- include/swift/IDE/REPLCodeCompletion.h | 2 +- include/swift/IDE/Utils.h | 14 +- include/swift/IDETool/IDEInspectionInstance.h | 2 +- include/swift/IRGen/IRABIDetailsProvider.h | 20 +- .../swift/Localization/LocalizationFormat.h | 2 +- include/swift/Markup/AST.h | 22 +- include/swift/Parse/IDEInspectionCallbacks.h | 6 +- include/swift/Parse/Lexer.h | 6 +- include/swift/Parse/LexerState.h | 2 +- include/swift/Parse/ParseVersion.h | 4 +- include/swift/Parse/Parser.h | 32 +- include/swift/Parse/PatternBindingState.h | 10 +- include/swift/Refactoring/Refactoring.h | 4 +- include/swift/Remote/ExternalTypeRefCache.h | 4 +- include/swift/Remote/MemoryReader.h | 17 +- include/swift/Remote/MetadataReader.h | 181 +++--- .../swift/RemoteInspection/MetadataSource.h | 2 +- .../RemoteInspection/ReflectionContext.h | 102 ++-- include/swift/RemoteInspection/TypeRef.h | 4 +- .../swift/RemoteInspection/TypeRefBuilder.h | 126 ++--- include/swift/SIL/AbstractionPattern.h | 31 +- include/swift/SIL/ApplySite.h | 16 +- include/swift/SIL/BasicBlockUtils.h | 4 +- include/swift/SIL/DebugUtils.h | 2 +- include/swift/SIL/DynamicCasts.h | 20 +- .../swift/SIL/FieldSensitivePrunedLiveness.h | 34 +- include/swift/SIL/InstWrappers.h | 4 +- include/swift/SIL/LinearLifetimeChecker.h | 4 +- include/swift/SIL/MemAccessUtils.h | 2 +- include/swift/SIL/PostOrder.h | 8 +- include/swift/SIL/Projection.h | 16 +- include/swift/SIL/SILArgument.h | 4 +- include/swift/SIL/SILBasicBlock.h | 2 +- include/swift/SIL/SILBridging.h | 4 +- include/swift/SIL/SILBridgingImpl.h | 2 +- include/swift/SIL/SILBuilder.h | 51 +- include/swift/SIL/SILCloner.h | 16 +- include/swift/SIL/SILConstants.h | 4 +- include/swift/SIL/SILDebugInfoExpression.h | 4 +- include/swift/SIL/SILDebugVariable.h | 11 +- include/swift/SIL/SILDeclRef.h | 4 +- include/swift/SIL/SILFunction.h | 4 +- include/swift/SIL/SILFunctionBuilder.h | 2 +- include/swift/SIL/SILGlobalVariable.h | 12 +- include/swift/SIL/SILInstruction.h | 153 +++--- include/swift/SIL/SILInstructionWorklist.h | 4 +- include/swift/SIL/SILModule.h | 8 +- include/swift/SIL/SILProfiler.h | 2 +- include/swift/SIL/SILProperty.h | 8 +- include/swift/SIL/SILRemarkStreamer.h | 4 +- include/swift/SIL/SILType.h | 8 +- include/swift/SIL/SILVTable.h | 4 +- include/swift/SIL/SILValue.h | 6 +- include/swift/SIL/TypeLowering.h | 35 +- .../swift/SILOptimizer/Analysis/ARCAnalysis.h | 26 +- .../Analysis/AccessStorageAnalysis.h | 6 +- .../SILOptimizer/Analysis/ArraySemantic.h | 2 +- .../SILOptimizer/Analysis/CallerAnalysis.h | 4 +- .../Analysis/ClassHierarchyAnalysis.h | 2 +- .../Analysis/EpilogueARCAnalysis.h | 4 +- .../Analysis/LoopRegionAnalysis.h | 36 +- .../Analysis/ProtocolConformanceAnalysis.h | 2 +- .../SILOptimizer/Analysis/ValueTracking.h | 2 +- .../Analysis/VisitBarrierAccessScopes.h | 2 +- .../SILOptimizer/Differentiation/ADContext.h | 14 +- .../Differentiation/AdjointValue.h | 20 +- .../SILOptimizer/Differentiation/Common.h | 4 +- .../Utils/CompileTimeInterpolationUtils.h | 3 +- include/swift/SILOptimizer/Utils/ConstExpr.h | 14 +- .../SILOptimizer/Utils/ConstantFolding.h | 2 +- .../SILOptimizer/Utils/DistributedActor.h | 12 +- .../swift/SILOptimizer/Utils/Existential.h | 2 +- include/swift/SILOptimizer/Utils/Generics.h | 4 +- .../swift/SILOptimizer/Utils/InstOptUtils.h | 4 +- .../SILOptimizer/Utils/OwnershipOptUtils.h | 2 +- .../swift/SILOptimizer/Utils/ScopeOptUtils.h | 10 +- .../swift/SILOptimizer/Utils/StackNesting.h | 2 +- include/swift/Sema/CSBindings.h | 4 +- include/swift/Sema/CSFix.h | 8 +- include/swift/Sema/CompletionContextFinder.h | 2 +- include/swift/Sema/Constraint.h | 8 +- include/swift/Sema/ConstraintGraph.h | 2 +- include/swift/Sema/ConstraintLocator.h | 32 +- include/swift/Sema/ConstraintSystem.h | 194 +++---- include/swift/Sema/IDETypeChecking.h | 4 +- include/swift/Sema/OverloadChoice.h | 2 +- include/swift/Sema/SolutionResult.h | 8 +- include/swift/Sema/SyntacticElementTarget.h | 14 +- include/swift/Serialization/ScanningLoaders.h | 8 +- .../Serialization/SerializedModuleLoader.h | 24 +- .../swift/Serialization/SerializedSILLoader.h | 4 +- .../SymbolGraphGen/DocumentationCategory.h | 6 +- include/swift/Threading/Impl/C11.h | 4 +- include/swift/Threading/Impl/Darwin.h | 4 +- include/swift/Threading/Impl/Linux.h | 4 +- include/swift/Threading/Impl/Nothreads.h | 4 +- include/swift/Threading/Impl/Pthreads.h | 4 +- include/swift/Threading/Impl/Win32.h | 4 +- include/swift/Threading/Thread.h | 4 +- lib/APIDigester/ModuleAnalyzerNodes.cpp | 58 +- lib/AST/ASTBridging.cpp | 10 +- lib/AST/ASTContext.cpp | 98 ++-- lib/AST/ASTDemangler.cpp | 24 +- lib/AST/ASTDumper.cpp | 2 +- lib/AST/ASTMangler.cpp | 38 +- lib/AST/ASTPrinter.cpp | 6 +- lib/AST/ASTScopeCreation.cpp | 16 +- lib/AST/AbstractSourceFileDepGraphFactory.cpp | 7 +- lib/AST/AccessNotes.cpp | 8 +- lib/AST/AccessRequests.cpp | 14 +- lib/AST/ArgumentList.cpp | 17 +- lib/AST/Attr.cpp | 38 +- lib/AST/AutoDiff.cpp | 24 +- lib/AST/Availability.cpp | 32 +- lib/AST/Builtins.cpp | 4 +- lib/AST/ClangTypeConverter.cpp | 6 +- lib/AST/ClangTypeConverter.h | 2 +- lib/AST/Decl.cpp | 179 +++--- lib/AST/DeclContext.cpp | 6 +- lib/AST/DiagnosticConsumer.cpp | 20 +- lib/AST/DiagnosticEngine.cpp | 6 +- lib/AST/DocComment.cpp | 56 +- lib/AST/ExistentialGeneralization.cpp | 4 +- lib/AST/Expr.cpp | 10 +- lib/AST/ExtInfo.cpp | 14 +- lib/AST/FineGrainedDependencies.cpp | 23 +- lib/AST/FineGrainedDependencyFormat.cpp | 14 +- lib/AST/FrontendSourceFileDepGraphFactory.cpp | 11 +- lib/AST/GenericEnvironment.cpp | 8 +- lib/AST/Identifier.cpp | 10 +- lib/AST/Module.cpp | 31 +- lib/AST/ModuleDependencies.cpp | 47 +- lib/AST/ModuleLoader.cpp | 2 +- lib/AST/NameLookupRequests.cpp | 26 +- lib/AST/ParameterPack.cpp | 80 ++- lib/AST/Pattern.cpp | 4 +- lib/AST/PlatformKind.cpp | 16 +- lib/AST/ProtocolConformance.cpp | 18 +- lib/AST/RawComment.cpp | 18 +- .../ConcreteContraction.cpp | 17 +- lib/AST/RequirementMachine/Diagnostics.h | 8 +- .../GenericSignatureQueries.cpp | 10 +- .../RequirementMachine/HomotopyReduction.cpp | 6 +- lib/AST/RequirementMachine/InterfaceType.cpp | 160 +++--- lib/AST/RequirementMachine/PropertyMap.h | 8 +- .../PropertyUnification.cpp | 10 +- .../RequirementMachine/RequirementBuilder.cpp | 4 +- .../RequirementMachineRequests.cpp | 2 +- lib/AST/RequirementMachine/RewriteContext.cpp | 4 +- lib/AST/RequirementMachine/RewriteSystem.cpp | 2 +- lib/AST/RequirementMachine/RewriteSystem.h | 12 +- lib/AST/RequirementMachine/Rule.cpp | 23 +- lib/AST/RequirementMachine/Rule.h | 9 +- lib/AST/RequirementMachine/RuleBuilder.cpp | 4 +- lib/AST/RequirementMachine/RuleBuilder.h | 5 +- .../SimplifySubstitutions.cpp | 6 +- lib/AST/RequirementMachine/Symbol.cpp | 6 +- lib/AST/RequirementMachine/Symbol.h | 4 +- lib/AST/RequirementMachine/Term.cpp | 18 +- lib/AST/RequirementMachine/Term.h | 8 +- lib/AST/RequirementMachine/Trie.h | 8 +- lib/AST/RequirementMachine/TypeDifference.cpp | 18 +- lib/AST/RequirementMachine/TypeDifference.h | 8 +- lib/AST/Stmt.cpp | 28 +- lib/AST/SubstitutionMap.cpp | 6 +- lib/AST/SwiftNameTranslation.cpp | 2 +- lib/AST/Type.cpp | 47 +- lib/AST/TypeCheckRequests.cpp | 195 ++++--- lib/AST/TypeJoinMeet.cpp | 14 +- lib/AST/TypeRefinementContext.cpp | 4 +- lib/AST/TypeRepr.cpp | 2 +- lib/AST/TypeSubstitution.cpp | 23 +- lib/Basic/Default/Task.inc | 12 +- lib/Basic/EditorPlaceholder.cpp | 7 +- lib/Basic/FileSystem.cpp | 13 +- lib/Basic/Fingerprint.cpp | 4 +- lib/Basic/LangOptions.cpp | 29 +- lib/Basic/ParseableOutput.cpp | 6 +- lib/Basic/Platform.cpp | 20 +- lib/Basic/Program.cpp | 8 +- lib/Basic/SourceLoc.cpp | 62 +-- lib/Basic/Statistic.cpp | 2 +- lib/Basic/StringExtras.cpp | 18 +- lib/Basic/TargetInfo.cpp | 6 +- lib/Basic/UUID.cpp | 7 +- lib/Basic/Unix/TaskQueue.inc | 16 +- lib/Basic/Version.cpp | 11 +- lib/ClangImporter/ClangAdapter.cpp | 18 +- lib/ClangImporter/ClangAdapter.h | 8 +- lib/ClangImporter/ClangImporter.cpp | 36 +- lib/ClangImporter/ClangImporterRequests.cpp | 4 +- lib/ClangImporter/ClangIncludePaths.cpp | 18 +- lib/ClangImporter/ClangIncludePaths.h | 2 +- .../ClangModuleDependencyScanner.cpp | 6 +- lib/ClangImporter/DWARFImporter.cpp | 2 +- lib/ClangImporter/ImportDecl.cpp | 184 ++++--- lib/ClangImporter/ImportMacro.cpp | 22 +- lib/ClangImporter/ImportName.cpp | 125 ++--- lib/ClangImporter/ImportName.h | 26 +- lib/ClangImporter/ImportType.cpp | 68 ++- lib/ClangImporter/ImporterImpl.h | 31 +- lib/ClangImporter/Serializability.cpp | 2 +- lib/ClangImporter/SwiftLookupTable.cpp | 37 +- lib/ClangImporter/SwiftLookupTable.h | 16 +- lib/ConstExtract/ConstExtract.cpp | 35 +- lib/Demangling/ManglingUtils.cpp | 11 +- lib/Demangling/OldDemangler.cpp | 24 +- .../ModuleDependencyCacheSerialization.cpp | 34 +- .../ModuleDependencyScanner.cpp | 26 +- lib/DependencyScan/ScanDependencies.cpp | 10 +- lib/Driver/Compilation.cpp | 9 +- lib/Driver/DarwinToolChains.cpp | 10 +- lib/Driver/Driver.cpp | 42 +- lib/Driver/Job.cpp | 2 +- lib/Driver/ToolChain.cpp | 4 +- lib/Driver/ToolChains.h | 12 +- lib/DriverTool/sil_opt_main.cpp | 31 +- lib/DriverTool/swift_api_digester_main.cpp | 20 +- lib/DriverTool/swift_cache_tool_main.cpp | 4 +- lib/DriverTool/swift_llvm_opt_main.cpp | 3 +- .../ArgsToFrontendInputsConverter.cpp | 18 +- lib/Frontend/ArgsToFrontendInputsConverter.h | 4 +- .../ArgsToFrontendOptionsConverter.cpp | 8 +- lib/Frontend/ArgsToFrontendOptionsConverter.h | 2 +- .../ArgsToFrontendOutputsConverter.cpp | 72 +-- lib/Frontend/ArgsToFrontendOutputsConverter.h | 26 +- lib/Frontend/CASOutputBackends.cpp | 10 +- lib/Frontend/CachingUtils.cpp | 2 +- lib/Frontend/CompileJobCacheKey.cpp | 4 +- lib/Frontend/CompilerInvocation.cpp | 81 ++- lib/Frontend/DiagnosticVerifier.cpp | 24 +- lib/Frontend/Frontend.cpp | 36 +- lib/Frontend/ModuleInterfaceBuilder.cpp | 12 +- lib/Frontend/ModuleInterfaceLoader.cpp | 22 +- lib/Frontend/ModuleInterfaceSupport.cpp | 5 +- lib/FrontendTool/FrontendTool.cpp | 6 +- lib/IDE/APIDigesterData.cpp | 12 +- lib/IDE/ArgumentCompletion.cpp | 4 +- lib/IDE/CodeCompletion.cpp | 36 +- lib/IDE/CodeCompletionCache.cpp | 18 +- lib/IDE/CodeCompletionContext.cpp | 2 +- lib/IDE/CodeCompletionResultBuilder.h | 2 +- lib/IDE/CodeCompletionString.cpp | 6 +- lib/IDE/CodeCompletionStringPrinter.cpp | 14 +- lib/IDE/CompletionLookup.cpp | 46 +- lib/IDE/CompletionOverrideLookup.cpp | 2 +- lib/IDE/CursorInfo.cpp | 4 +- lib/IDE/ExprContextAnalysis.h | 2 +- lib/IDE/Formatting.cpp | 281 +++++----- lib/IDE/IDEBridging.cpp | 6 +- lib/IDE/IDERequests.cpp | 10 +- lib/IDE/ModuleInterfacePrinting.cpp | 25 +- lib/IDE/SourceEntityWalker.cpp | 40 +- lib/IDE/SwiftSourceDocInfo.cpp | 14 +- lib/IDE/SyntaxModel.cpp | 52 +- lib/IDE/TypeContextInfo.cpp | 4 +- lib/IDETool/CompileInstance.cpp | 4 +- lib/IDETool/DependencyChecking.cpp | 15 +- lib/IDETool/DependencyChecking.h | 6 +- lib/IDETool/IDEInspectionInstance.cpp | 2 +- lib/IDETool/SyntacticMacroExpansion.cpp | 8 +- lib/IRGen/APIGen.h | 4 +- lib/IRGen/AllocStackHoisting.cpp | 6 +- lib/IRGen/BitPatternBuilder.h | 6 +- lib/IRGen/BitPatternReader.h | 2 +- lib/IRGen/Callee.h | 6 +- lib/IRGen/ClassTypeInfo.h | 4 +- lib/IRGen/DebugTypeInfo.cpp | 4 +- lib/IRGen/DebugTypeInfo.h | 14 +- lib/IRGen/Fulfillment.cpp | 8 +- lib/IRGen/GenCall.cpp | 44 +- lib/IRGen/GenCall.h | 2 +- lib/IRGen/GenCast.cpp | 12 +- lib/IRGen/GenCast.h | 2 +- lib/IRGen/GenClass.cpp | 39 +- lib/IRGen/GenConstant.cpp | 2 +- lib/IRGen/GenDecl.cpp | 21 +- lib/IRGen/GenDecl.h | 2 +- lib/IRGen/GenDiffFunc.cpp | 20 +- lib/IRGen/GenFunc.cpp | 46 +- lib/IRGen/GenFunc.h | 2 +- lib/IRGen/GenHeap.cpp | 10 +- lib/IRGen/GenKeyPath.cpp | 8 +- lib/IRGen/GenKeyPath.h | 9 +- lib/IRGen/GenMeta.cpp | 33 +- lib/IRGen/GenObjC.cpp | 4 +- lib/IRGen/GenPack.cpp | 11 +- lib/IRGen/GenPack.h | 8 +- lib/IRGen/GenProto.cpp | 8 +- lib/IRGen/GenRecord.h | 4 +- lib/IRGen/GenReflection.cpp | 16 +- lib/IRGen/GenStruct.cpp | 68 ++- lib/IRGen/GenStruct.h | 8 +- lib/IRGen/GenThunk.cpp | 2 +- lib/IRGen/GenTuple.cpp | 38 +- lib/IRGen/GenTuple.h | 12 +- lib/IRGen/GenType.cpp | 4 +- lib/IRGen/GenType.h | 2 +- lib/IRGen/GenValueWitness.cpp | 18 +- lib/IRGen/IRABIDetailsProvider.cpp | 38 +- lib/IRGen/IRGen.cpp | 16 +- lib/IRGen/IRGenDebugInfo.cpp | 36 +- lib/IRGen/IRGenDebugInfo.h | 4 +- lib/IRGen/IRGenFunction.cpp | 2 +- lib/IRGen/IRGenFunction.h | 2 +- lib/IRGen/IRGenModule.h | 8 +- lib/IRGen/IRGenSIL.cpp | 24 +- lib/IRGen/LocalTypeData.cpp | 6 +- lib/IRGen/MetadataLayout.cpp | 6 +- lib/IRGen/MetadataRequest.cpp | 8 +- lib/IRGen/ScalarPairTypeInfo.h | 8 +- lib/IRGen/Signature.h | 8 +- lib/IRGen/StructLayout.cpp | 6 +- lib/IRGen/StructLayout.h | 7 +- lib/IRGen/SwiftTargetInfo.h | 2 +- lib/IRGen/TBDGen.cpp | 20 +- lib/IRGen/TBDGenVisitor.h | 2 +- lib/IRGen/TypeLayout.cpp | 100 ++-- lib/IRGen/TypeLayout.h | 81 +-- lib/IRGen/TypeLayoutDumper.cpp | 6 +- lib/Index/Index.cpp | 22 +- lib/Localization/LocalizationFormat.cpp | 2 +- lib/Markup/AST.cpp | 11 +- lib/Markup/Markup.cpp | 7 +- lib/Migrator/APIDiffMigratorPass.cpp | 4 +- lib/Option/SanitizerOptions.cpp | 16 +- lib/Parse/ParseDecl.cpp | 135 +++-- lib/Parse/ParseExpr.cpp | 26 +- lib/Parse/ParseIfConfig.cpp | 31 +- lib/Parse/ParsePattern.cpp | 8 +- lib/Parse/ParseRequests.cpp | 8 +- lib/Parse/ParseStmt.cpp | 14 +- lib/Parse/ParseType.cpp | 6 +- lib/Parse/ParseVersion.cpp | 10 +- lib/Parse/Parser.cpp | 16 +- lib/PrintAsClang/ClangSyntaxPrinter.cpp | 2 +- lib/PrintAsClang/ClangSyntaxPrinter.h | 2 +- lib/PrintAsClang/DeclAndTypePrinter.cpp | 121 ++-- lib/PrintAsClang/PrimitiveTypeMapping.cpp | 36 +- lib/PrintAsClang/PrimitiveTypeMapping.h | 10 +- lib/PrintAsClang/PrintAsClang.cpp | 6 +- lib/PrintAsClang/PrintClangFunction.cpp | 86 +-- lib/PrintAsClang/PrintClangFunction.h | 14 +- lib/PrintAsClang/PrintClangValueType.cpp | 2 +- lib/PrintAsClang/SwiftToClangInteropContext.h | 2 +- lib/Refactoring/Async/AsyncConverter.cpp | 4 +- lib/Refactoring/Async/AsyncHandlerDesc.cpp | 10 +- lib/Refactoring/Async/AsyncRefactoring.h | 20 +- lib/Refactoring/Async/CallbackClassifier.cpp | 24 +- lib/Refactoring/ExpandMacro.cpp | 6 +- lib/Refactoring/ExtractExprBase.cpp | 4 +- lib/Refactoring/LocalRename.cpp | 40 +- lib/Refactoring/SyntacticRename.cpp | 2 +- .../SyntacticRenameRangeDetails.cpp | 14 +- lib/RemoteAST/RemoteAST.cpp | 6 +- lib/SIL/IR/AbstractionPattern.cpp | 44 +- lib/SIL/IR/SILBasicBlock.cpp | 2 +- lib/SIL/IR/SILBuilder.cpp | 10 +- lib/SIL/IR/SILConstants.cpp | 2 +- lib/SIL/IR/SILDeclRef.cpp | 10 +- lib/SIL/IR/SILFunction.cpp | 26 +- lib/SIL/IR/SILFunctionBuilder.cpp | 6 +- lib/SIL/IR/SILFunctionType.cpp | 76 ++- lib/SIL/IR/SILGlobalVariable.cpp | 4 +- lib/SIL/IR/SILInstruction.cpp | 4 +- lib/SIL/IR/SILInstructions.cpp | 42 +- lib/SIL/IR/SILModule.cpp | 4 +- lib/SIL/IR/SILPrinter.cpp | 6 +- lib/SIL/IR/SILProfiler.cpp | 46 +- lib/SIL/IR/SILSymbolVisitor.cpp | 4 +- lib/SIL/IR/SILType.cpp | 2 +- lib/SIL/IR/SILTypeSubstitution.cpp | 15 +- lib/SIL/IR/SILVTable.cpp | 6 +- lib/SIL/IR/SILValue.cpp | 8 +- lib/SIL/IR/TypeLowering.cpp | 32 +- lib/SIL/IR/ValueOwnership.cpp | 4 +- lib/SIL/Parser/ParseSIL.cpp | 125 +++-- lib/SIL/Parser/ParseTestSpecification.cpp | 58 +- lib/SIL/Parser/SILParser.h | 14 +- .../Utils/FieldSensitivePrunedLiveness.cpp | 16 +- lib/SIL/Utils/MemAccessUtils.cpp | 22 +- lib/SIL/Utils/Projection.cpp | 17 +- lib/SIL/Utils/PrunedLiveness.cpp | 4 +- lib/SIL/Verifier/LinearLifetimeChecker.cpp | 42 +- .../Verifier/LinearLifetimeCheckerPrivate.h | 4 +- lib/SIL/Verifier/SILOwnershipVerifier.cpp | 6 +- lib/SIL/Verifier/SILVerifier.cpp | 4 +- lib/SILGen/Callee.h | 23 +- lib/SILGen/Cleanup.cpp | 8 +- lib/SILGen/Cleanup.h | 4 +- lib/SILGen/Condition.h | 2 +- lib/SILGen/Conversion.h | 8 +- lib/SILGen/FormalEvaluation.h | 4 +- lib/SILGen/Initialization.h | 4 +- lib/SILGen/JumpDest.h | 13 +- lib/SILGen/LValue.h | 24 +- lib/SILGen/RValue.cpp | 2 +- lib/SILGen/ResultPlan.cpp | 12 +- lib/SILGen/ResultPlan.h | 6 +- lib/SILGen/SGFContext.h | 4 +- lib/SILGen/SILGen.cpp | 13 +- lib/SILGen/SILGen.h | 50 +- lib/SILGen/SILGenApply.cpp | 93 ++-- lib/SILGen/SILGenBridging.cpp | 38 +- lib/SILGen/SILGenBuilder.cpp | 2 +- lib/SILGen/SILGenBuilder.h | 2 +- lib/SILGen/SILGenBuiltin.cpp | 12 +- lib/SILGen/SILGenConcurrency.cpp | 16 +- lib/SILGen/SILGenConstructor.cpp | 20 +- lib/SILGen/SILGenConvert.cpp | 30 +- lib/SILGen/SILGenDecl.cpp | 8 +- lib/SILGen/SILGenDestructor.cpp | 14 +- lib/SILGen/SILGenDynamicCast.cpp | 20 +- lib/SILGen/SILGenEpilog.cpp | 23 +- lib/SILGen/SILGenExpr.cpp | 128 ++--- lib/SILGen/SILGenForeignError.cpp | 23 +- lib/SILGen/SILGenFunction.cpp | 33 +- lib/SILGen/SILGenFunction.h | 79 ++- lib/SILGen/SILGenGlobalVariable.cpp | 9 +- lib/SILGen/SILGenLValue.cpp | 166 +++--- lib/SILGen/SILGenPattern.cpp | 33 +- lib/SILGen/SILGenPoly.cpp | 16 +- lib/SILGen/SILGenProlog.cpp | 19 +- lib/SILGen/SILGenThunk.cpp | 11 +- lib/SILGen/SILGenTopLevel.cpp | 13 +- lib/SILGen/SILGenType.cpp | 10 +- lib/SILGen/SpecializedEmitter.h | 4 +- lib/SILGen/SwitchEnumBuilder.h | 4 +- lib/SILOptimizer/ARC/ARCBBState.cpp | 12 +- lib/SILOptimizer/ARC/ARCBBState.h | 6 +- lib/SILOptimizer/ARC/ARCMatchingSet.cpp | 16 +- lib/SILOptimizer/ARC/ARCMatchingSet.h | 4 +- .../ARC/GlobalARCSequenceDataflow.cpp | 4 +- .../ARC/GlobalARCSequenceDataflow.h | 10 +- .../ARC/GlobalLoopARCSequenceDataflow.h | 8 +- lib/SILOptimizer/Analysis/ARCAnalysis.cpp | 24 +- .../Analysis/AccessStorageAnalysis.cpp | 14 +- lib/SILOptimizer/Analysis/ArraySemantic.cpp | 10 +- .../DifferentiableActivityAnalysis.cpp | 6 +- lib/SILOptimizer/Analysis/MemoryBehavior.cpp | 4 +- .../Analysis/RCIdentityAnalysis.cpp | 12 +- lib/SILOptimizer/Analysis/ValueTracking.cpp | 16 +- .../Differentiation/ADContext.cpp | 4 +- lib/SILOptimizer/Differentiation/Common.cpp | 8 +- .../Differentiation/JVPCloner.cpp | 4 +- .../Differentiation/PullbackCloner.cpp | 8 +- .../Differentiation/VJPCloner.cpp | 4 +- .../ExistentialTransform.cpp | 2 +- .../FunctionSignatureOpts.cpp | 4 +- .../FunctionSignatureOpts.h | 11 +- .../LoopTransforms/COWArrayOpt.cpp | 6 +- lib/SILOptimizer/LoopTransforms/LICM.cpp | 2 +- .../LoopTransforms/LoopUnroll.cpp | 38 +- lib/SILOptimizer/Mandatory/AddressLowering.h | 2 +- .../Mandatory/DefiniteInitialization.cpp | 38 +- .../DiagnoseInvalidEscapingCaptures.cpp | 2 +- .../Mandatory/DiagnoseStaticExclusivity.cpp | 28 +- .../Mandatory/Differentiation.cpp | 30 +- lib/SILOptimizer/Mandatory/FlowIsolation.cpp | 4 +- .../Mandatory/MandatoryInlining.cpp | 2 +- .../Mandatory/MoveOnlyAddressCheckerUtils.cpp | 12 +- .../MoveOnlyBorrowToDestructureUtils.cpp | 16 +- .../MoveOnlyBorrowToDestructureUtils.h | 2 +- .../Mandatory/MoveOnlyDiagnostics.cpp | 2 +- .../Mandatory/MoveOnlyDiagnostics.h | 2 +- .../Mandatory/MoveOnlyTypeUtils.cpp | 4 +- .../Mandatory/MoveOnlyTypeUtils.h | 4 +- .../MoveOnlyWrappedTypeEliminator.cpp | 5 +- .../Mandatory/OSLogOptimization.cpp | 22 +- .../Mandatory/OwnershipModelEliminator.cpp | 2 +- .../Mandatory/PredictableMemOpt.cpp | 28 +- lib/SILOptimizer/Mandatory/YieldOnceCheck.cpp | 18 +- lib/SILOptimizer/PassManager/PassManager.cpp | 2 +- lib/SILOptimizer/SILCombiner/SILCombiner.h | 4 +- .../SILCombiner/SILCombinerApplyVisitors.cpp | 26 +- .../SILCombinerBuiltinVisitors.cpp | 4 +- .../SILCombiner/SILCombinerCastVisitors.cpp | 4 +- .../SILCombiner/SILCombinerMiscVisitors.cpp | 14 +- .../SemanticARC/LoadCopyToLoadBorrowOpt.cpp | 2 +- .../SemanticARC/OwnershipLiveRange.cpp | 2 +- .../SemanticARC/OwnershipPhiOperand.h | 4 +- .../SemanticARC/SemanticARCOptVisitor.h | 2 +- lib/SILOptimizer/Transforms/ARCCodeMotion.cpp | 2 +- .../Transforms/AllocBoxToStack.cpp | 2 +- .../ArrayElementValuePropagation.cpp | 2 +- .../Transforms/DestroyAddrHoisting.cpp | 2 +- lib/SILOptimizer/Transforms/Outliner.cpp | 6 +- .../Transforms/PartialApplySimplification.cpp | 2 +- .../Transforms/PerformanceInliner.cpp | 8 +- .../Transforms/PhiArgumentOptimizations.cpp | 2 +- .../RedundantOverflowCheckRemoval.cpp | 6 +- lib/SILOptimizer/Transforms/SILCodeMotion.cpp | 16 +- lib/SILOptimizer/Transforms/SILMem2Reg.cpp | 22 +- lib/SILOptimizer/Transforms/SILSROA.cpp | 2 +- lib/SILOptimizer/Transforms/SimplifyCFG.cpp | 2 +- .../Transforms/StringOptimization.cpp | 12 +- .../UtilityPasses/BugReducerTester.cpp | 2 +- .../ConstantEvaluableSubsetChecker.cpp | 4 +- .../UtilityPasses/ConstantEvaluatorTester.cpp | 4 +- .../Utils/CanonicalizeBorrowScope.cpp | 6 +- .../Utils/CanonicalizeInstruction.cpp | 12 +- lib/SILOptimizer/Utils/CastOptimizer.cpp | 14 +- .../Utils/CompileTimeInterpolationUtils.cpp | 3 +- lib/SILOptimizer/Utils/ConstExpr.cpp | 184 +++---- lib/SILOptimizer/Utils/ConstantFolding.cpp | 44 +- lib/SILOptimizer/Utils/DistributedActor.cpp | 10 +- lib/SILOptimizer/Utils/Generics.cpp | 2 +- lib/SILOptimizer/Utils/InstOptUtils.cpp | 12 +- lib/SILOptimizer/Utils/KeyPathProjector.cpp | 8 +- .../Utils/LexicalDestroyFolding.cpp | 8 +- lib/SILOptimizer/Utils/SILInliner.cpp | 8 +- lib/SILOptimizer/Utils/StackNesting.cpp | 4 +- lib/Sema/AssociatedTypeInference.cpp | 101 ++-- lib/Sema/BuilderTransform.cpp | 42 +- lib/Sema/CSApply.cpp | 114 ++-- lib/Sema/CSBindings.cpp | 60 +- lib/Sema/CSDiagnostics.cpp | 56 +- lib/Sema/CSDiagnostics.h | 20 +- lib/Sema/CSFix.cpp | 16 +- lib/Sema/CSGen.cpp | 40 +- lib/Sema/CSRanking.cpp | 28 +- lib/Sema/CSSimplify.cpp | 229 ++++---- lib/Sema/CSSolver.cpp | 24 +- lib/Sema/CSStep.cpp | 4 +- lib/Sema/CSStep.h | 26 +- lib/Sema/CSSyntacticElement.cpp | 12 +- lib/Sema/CodeSynthesis.cpp | 4 +- lib/Sema/CodeSynthesis.h | 2 +- lib/Sema/CodeSynthesisDistributedActor.cpp | 2 +- lib/Sema/CompletionContextFinder.cpp | 10 +- lib/Sema/Constraint.cpp | 6 +- lib/Sema/ConstraintSystem.cpp | 326 ++++++----- lib/Sema/DerivedConformanceCodable.cpp | 19 +- lib/Sema/DerivedConformanceCodingKey.cpp | 6 +- lib/Sema/DerivedConformanceComparable.cpp | 4 +- .../DerivedConformanceEquatableHashable.cpp | 6 +- .../DerivedConformanceRawRepresentable.cpp | 10 +- lib/Sema/DerivedConformances.cpp | 2 +- lib/Sema/IDETypeCheckingRequests.cpp | 2 +- lib/Sema/ImportResolution.cpp | 4 +- lib/Sema/InstrumenterSupport.cpp | 2 +- lib/Sema/InstrumenterSupport.h | 6 +- lib/Sema/LifetimeDependence.cpp | 32 +- lib/Sema/MiscDiagnostics.cpp | 48 +- lib/Sema/MiscDiagnostics.h | 206 ++++--- lib/Sema/PreCheckExpr.cpp | 4 +- lib/Sema/SyntacticElementTarget.cpp | 20 +- lib/Sema/TypeAccessScopeChecker.h | 7 +- lib/Sema/TypeCheckAccess.cpp | 27 +- lib/Sema/TypeCheckAttr.cpp | 84 +-- lib/Sema/TypeCheckAvailability.cpp | 105 ++-- lib/Sema/TypeCheckAvailability.h | 22 +- lib/Sema/TypeCheckBitwise.cpp | 4 +- lib/Sema/TypeCheckCaptures.cpp | 4 +- lib/Sema/TypeCheckCodeCompletion.cpp | 12 +- lib/Sema/TypeCheckConcurrency.cpp | 339 ++++++------ lib/Sema/TypeCheckConcurrency.h | 52 +- lib/Sema/TypeCheckConstraints.cpp | 22 +- lib/Sema/TypeCheckDecl.cpp | 17 +- lib/Sema/TypeCheckDecl.h | 4 +- lib/Sema/TypeCheckDeclObjC.cpp | 90 +-- lib/Sema/TypeCheckDeclOverride.cpp | 8 +- lib/Sema/TypeCheckDeclPrimary.cpp | 44 +- lib/Sema/TypeCheckEffects.cpp | 64 +-- lib/Sema/TypeCheckExprObjC.cpp | 12 +- lib/Sema/TypeCheckGeneric.cpp | 2 +- lib/Sema/TypeCheckMacros.cpp | 80 +-- lib/Sema/TypeCheckMacros.h | 27 +- lib/Sema/TypeCheckNameLookup.cpp | 8 +- lib/Sema/TypeCheckObjC.h | 10 +- lib/Sema/TypeCheckPattern.cpp | 12 +- lib/Sema/TypeCheckPropertyWrapper.cpp | 2 +- lib/Sema/TypeCheckProtocol.cpp | 112 ++-- lib/Sema/TypeCheckProtocol.h | 8 +- lib/Sema/TypeCheckRegex.cpp | 4 +- lib/Sema/TypeCheckRequestFunctions.cpp | 2 +- lib/Sema/TypeCheckStmt.cpp | 4 +- lib/Sema/TypeCheckStorage.cpp | 46 +- lib/Sema/TypeCheckSwitchStmt.cpp | 20 +- lib/Sema/TypeCheckType.cpp | 39 +- lib/Sema/TypeCheckType.h | 10 +- lib/Sema/TypeChecker.cpp | 10 +- lib/Sema/TypeChecker.h | 52 +- lib/Sema/TypoCorrection.h | 10 +- lib/Serialization/Deserialization.cpp | 187 +++---- lib/Serialization/DeserializeSIL.cpp | 41 +- lib/Serialization/DeserializeSIL.h | 4 +- lib/Serialization/ModuleFile.cpp | 71 ++- lib/Serialization/ModuleFile.h | 32 +- lib/Serialization/ModuleFileSharedCore.cpp | 10 +- lib/Serialization/ModuleFormat.h | 8 +- lib/Serialization/ScanningLoaders.cpp | 4 +- lib/Serialization/Serialization.cpp | 12 +- lib/Serialization/Serialization.h | 8 +- lib/Serialization/SerializeDoc.cpp | 8 +- lib/Serialization/SerializeSIL.cpp | 2 +- lib/Serialization/SerializedModuleLoader.cpp | 45 +- lib/Serialization/SerializedSILLoader.cpp | 4 +- lib/StaticMirror/BinaryScanningTool.cpp | 14 +- lib/SymbolGraphGen/AvailabilityMixin.h | 6 +- .../DeclarationFragmentPrinter.h | 2 +- lib/SymbolGraphGen/SymbolGraph.cpp | 4 +- lib/SymbolGraphGen/SymbolGraph.h | 10 +- lib/SymbolGraphGen/SymbolGraphASTWalker.cpp | 4 +- lib/SymbolGraphGen/SymbolGraphGen.cpp | 2 +- lib/Threading/Linux.cpp | 2 +- lib/Threading/Pthreads.cpp | 4 +- lib/Threading/Win32.cpp | 2 +- stdlib/include/llvm/ADT/ArrayRef.h | 12 +- stdlib/include/llvm/ADT/None.h | 28 - stdlib/include/llvm/ADT/Optional.h | 516 ------------------ stdlib/include/llvm/ADT/STLExtras.h | 11 +- stdlib/include/llvm/ADT/StringRef.h | 2 +- stdlib/include/llvm/ADT/StringSwitch.h | 2 +- stdlib/include/llvm/Support/Alignment.h | 20 +- stdlib/include/llvm/Support/Allocator.h | 8 +- stdlib/public/Concurrency/VoucherSupport.h | 10 +- stdlib/public/RemoteInspection/TypeRef.cpp | 14 +- .../RemoteInspection/TypeRefBuilder.cpp | 26 +- .../SwiftRemoteMirror/SwiftRemoteMirror.cpp | 2 +- stdlib/public/runtime/AccessibleFunction.cpp | 2 +- stdlib/public/runtime/MetadataLookup.cpp | 48 +- stdlib/public/runtime/Private.h | 8 +- stdlib/public/runtime/ProtocolConformance.cpp | 50 +- stdlib/public/runtime/SymbolInfo.cpp | 4 +- stdlib/public/runtime/SymbolInfo.h | 6 +- stdlib/public/stubs/Stubs.cpp | 4 +- .../include/Concurrency/VoucherSupport.h | 8 +- test/TypeRoundTrip/round-trip.swift | 2 +- test/stdlib/symbol-visibility-linux.test-sh | 7 + .../include/SourceKit/Core/Context.h | 7 +- tools/SourceKit/include/SourceKit/Core/LLVM.h | 3 - .../include/SourceKit/Core/LangSupport.h | 62 +-- .../include/SourceKit/Support/Tracing.h | 6 +- tools/SourceKit/lib/Core/Context.cpp | 4 +- .../lib/Support/Concurrency-libdispatch.cpp | 6 +- .../SourceKit/lib/SwiftLang/CodeCompletion.h | 10 +- .../lib/SwiftLang/SwiftASTManager.cpp | 2 +- .../SourceKit/lib/SwiftLang/SwiftASTManager.h | 8 +- .../SourceKit/lib/SwiftLang/SwiftCompile.cpp | 4 +- .../lib/SwiftLang/SwiftCompletion.cpp | 8 +- .../SwiftLang/SwiftConformingMethodList.cpp | 4 +- .../lib/SwiftLang/SwiftDocSupport.cpp | 23 +- tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp | 63 ++- .../lib/SwiftLang/SwiftEditorDiagConsumer.h | 2 +- .../lib/SwiftLang/SwiftEditorInterfaceGen.cpp | 33 +- .../SourceKit/lib/SwiftLang/SwiftIndexing.cpp | 2 +- .../lib/SwiftLang/SwiftInterfaceGenContext.h | 7 +- .../lib/SwiftLang/SwiftLangSupport.cpp | 10 +- .../lib/SwiftLang/SwiftLangSupport.h | 39 +- .../lib/SwiftLang/SwiftSourceDocInfo.cpp | 76 ++- .../lib/SwiftLang/SwiftTypeContextInfo.cpp | 4 +- .../tools/complete-test/complete-test.cpp | 47 +- .../tools/sourcekitd-test/TestOptions.cpp | 2 +- .../tools/sourcekitd-test/TestOptions.h | 16 +- .../tools/sourcekitd-test/sourcekitd-test.cpp | 27 +- .../sourcekitd/CodeCompletionResultsArray.h | 20 +- .../include/sourcekitd/CompactArray.h | 2 +- .../sourcekitd/include/sourcekitd/Internal.h | 14 +- .../lib/API/CodeCompletionResultsArray.cpp | 35 +- .../tools/sourcekitd/lib/API/CompactArray.cpp | 2 +- .../sourcekitd/lib/API/DocStructureArray.cpp | 44 +- .../lib/API/DocSupportAnnotationArray.cpp | 12 +- .../lib/API/sourcekitdAPI-InProc.cpp | 27 +- .../sourcekitd/lib/API/sourcekitdAPI-XPC.cpp | 18 +- .../tools/sourcekitd/lib/Service/Requests.cpp | 369 +++++++------ tools/swift-ast-script/ASTScriptParser.cpp | 8 +- tools/swift-ide-test/ModuleAPIDiff.cpp | 30 +- tools/swift-ide-test/swift-ide-test.cpp | 27 +- unittests/AST/ArithmeticEvaluator.cpp | 6 +- unittests/AST/DiagnosticConsumerTests.cpp | 4 +- unittests/AST/TestContext.cpp | 6 +- unittests/Basic/BlotMapVectorTest.cpp | 8 +- unittests/Basic/EditorPlaceholderTest.cpp | 4 +- unittests/Basic/FrozenMultiMapTest.cpp | 2 +- unittests/Parse/BuildConfigTests.cpp | 6 +- unittests/Reflection/TypeRef.cpp | 6 +- unittests/Sema/ConstraintGenerationTests.cpp | 4 +- .../Sema/ConstraintSimplificationTests.cpp | 2 +- .../Sema/KeypathFunctionConversionTests.cpp | 2 +- unittests/Sema/SemaFixture.cpp | 2 +- .../SourceKit/SwiftLang/CursorInfoTest.cpp | 10 +- unittests/SourceKit/SwiftLang/EditingTest.cpp | 2 +- unittests/runtime/Actor.cpp | 8 +- 810 files changed, 8035 insertions(+), 8718 deletions(-) delete mode 100644 stdlib/include/llvm/ADT/None.h delete mode 100644 stdlib/include/llvm/ADT/Optional.h diff --git a/include/swift/ABI/ObjectFile.h b/include/swift/ABI/ObjectFile.h index 3164eaf5c82..3f60a12954f 100644 --- a/include/swift/ABI/ObjectFile.h +++ b/include/swift/ABI/ObjectFile.h @@ -7,9 +7,9 @@ #ifndef SWIFT_ABI_OBJECTFILE_H #define SWIFT_ABI_OBJECTFILE_H -#include "llvm/ADT/Optional.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/ErrorHandling.h" +#include namespace swift { @@ -27,12 +27,10 @@ class SwiftObjectFileFormat { public: virtual ~SwiftObjectFileFormat() {} virtual llvm::StringRef getSectionName(ReflectionSectionKind section) = 0; - virtual llvm::Optional getSegmentName() { - return {}; - } + virtual std::optional getSegmentName() { return {}; } /// Get the name of the segment in the symbol rich binary that may contain /// Swift metadata. - virtual llvm::Optional getSymbolRichSegmentName() { + virtual std::optional getSymbolRichSegmentName() { return {}; } /// Predicate to identify if the named section can contain reflection data. @@ -53,11 +51,11 @@ public: llvm_unreachable("Section type not found."); } - llvm::Optional getSegmentName() override { + std::optional getSegmentName() override { return {"__TEXT"}; } - llvm::Optional getSymbolRichSegmentName() override { + std::optional getSymbolRichSegmentName() override { return {"__DWARF"}; } diff --git a/include/swift/ABI/TypeIdentity.h b/include/swift/ABI/TypeIdentity.h index 5373add7efa..b369a19fb4e 100644 --- a/include/swift/ABI/TypeIdentity.h +++ b/include/swift/ABI/TypeIdentity.h @@ -20,7 +20,6 @@ #include "swift/Basic/LLVM.h" #include "swift/Runtime/Config.h" -#include #include namespace swift { @@ -188,7 +187,7 @@ public: llvm::StringRef FullIdentity; /// Any extended information that type might have. - llvm::Optional> ImportInfo; + std::optional> ImportInfo; /// The ABI name of the type. llvm::StringRef getABIName() const { diff --git a/include/swift/APIDigester/ModuleAnalyzerNodes.h b/include/swift/APIDigester/ModuleAnalyzerNodes.h index af0d64dd272..c5b63f5cd23 100644 --- a/include/swift/APIDigester/ModuleAnalyzerNodes.h +++ b/include/swift/APIDigester/ModuleAnalyzerNodes.h @@ -179,7 +179,7 @@ class SDKContext { CheckerOptions Opts; std::vector BreakingAttrs; // The common version of two ABI/API descriptors under comparison. - llvm::Optional CommonVersion; + std::optional CommonVersion; public: // Define the set of known identifiers. @@ -232,7 +232,7 @@ public: const CheckerOptions &getOpts() const { return Opts; } bool shouldIgnore(Decl *D, const Decl* Parent = nullptr) const; ArrayRef getBreakingAttributeInfo() const { return BreakingAttrs; } - llvm::Optional getFixedBinaryOrder(ValueDecl *VD) const; + std::optional getFixedBinaryOrder(ValueDecl *VD) const; CompilerInstance &newCompilerInstance() { CIs.emplace_back(new CompilerInstance()); @@ -364,7 +364,7 @@ class SDKNodeDecl: public SDKNode { // In ABI mode, this field is populated as a user-friendly version of GenericSig. // Diagnostic preferes the sugared versions if they differ as well. StringRef SugaredGenericSig; - llvm::Optional FixedBinaryOrder; + std::optional FixedBinaryOrder; PlatformIntroVersion introVersions; StringRef ObjCName; @@ -446,7 +446,7 @@ public: ArrayRef getDescendantsByUsr(StringRef Usr) { return DescendantDeclTable[Usr].getArrayRef(); } - llvm::Optional getSingleModuleName() const; + std::optional getSingleModuleName() const; }; class SDKNodeType: public SDKNode { @@ -588,11 +588,11 @@ public: return InheritsConvenienceInitializers; }; - llvm::Optional getSuperclass() const; + std::optional getSuperclass() const; /// Finding the node through all children, including the inherited ones, /// whose printed name matches with the given name. - llvm::Optional lookupChildByPrintedName(StringRef Name) const; + std::optional lookupChildByPrintedName(StringRef Name) const; SDKNodeType *getRawValueType() const; bool isConformingTo(KnownProtocolKind Kind) const; void jsonize(json::Output &out) override; @@ -686,7 +686,7 @@ public: class SDKNodeDeclAbstractFunc : public SDKNodeDecl { bool IsThrowing; bool ReqNewWitnessTableEntry; - llvm::Optional SelfIndex; + std::optional SelfIndex; protected: SDKNodeDeclAbstractFunc(SDKNodeInitInfo Info, SDKNodeKind Kind); @@ -695,7 +695,7 @@ public: bool isThrowing() const { return IsThrowing; } bool reqNewWitnessTableEntry() const { return ReqNewWitnessTableEntry; } uint8_t getSelfIndex() const { return SelfIndex.value(); } - llvm::Optional getSelfIndexOptional() const { return SelfIndex; } + std::optional getSelfIndexOptional() const { return SelfIndex; } bool hasSelfIndex() const { return SelfIndex.has_value(); } static bool classof(const SDKNode *N); virtual void jsonize(json::Output &out) override; diff --git a/include/swift/AST/ASTContext.h b/include/swift/AST/ASTContext.h index c136634716a..3cb712b2424 100644 --- a/include/swift/AST/ASTContext.h +++ b/include/swift/AST/ASTContext.h @@ -172,7 +172,7 @@ enum class KnownFoundationEntity { /// Retrieve the Foundation entity kind for the given Objective-C /// entity name. -llvm::Optional getKnownFoundationEntity(StringRef name); +std::optional getKnownFoundationEntity(StringRef name); /// Retrieve the Swift name for the given Foundation entity, where /// "NS" prefix stripping will apply under omit-needless-words. @@ -362,7 +362,7 @@ public: unsigned NumTypoCorrections = 0; /// Cached mapping from types to their associated tangent spaces. - llvm::DenseMap> AutoDiffTangentSpaces; + llvm::DenseMap> AutoDiffTangentSpaces; /// A cache of derivative function types per configuration. llvm::DenseMap @@ -845,7 +845,7 @@ public: /// SIL analog of \c ASTContext::getClangFunctionType . const clang::Type * getCanonicalClangFunctionType(ArrayRef params, - llvm::Optional result, + std::optional result, SILFunctionType::Representation trueRep); /// Instantiates "Impl.Converter" if needed, then translate Swift generic @@ -1572,7 +1572,7 @@ public: private: friend Decl; - llvm::Optional getExternalSourceLocs(const Decl *D); + std::optional getExternalSourceLocs(const Decl *D); void setExternalSourceLocs(const Decl *D, ExternalSourceLocs *Locs); friend TypeBase; diff --git a/include/swift/AST/ASTDemangler.h b/include/swift/AST/ASTDemangler.h index 9acea180a9a..572a0d91569 100644 --- a/include/swift/AST/ASTDemangler.h +++ b/include/swift/AST/ASTDemangler.h @@ -27,8 +27,8 @@ #include "swift/Demangling/NamespaceMacros.h" #include "swift/Demangling/TypeDecoder.h" #include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/StringRef.h" +#include namespace swift { @@ -151,7 +151,7 @@ public: Demangle::ImplParameterConvention calleeConvention, ArrayRef> params, ArrayRef> results, - llvm::Optional> errorResult, + std::optional> errorResult, ImplFunctionTypeFlags flags); Type createProtocolCompositionType(ArrayRef protocols, @@ -169,11 +169,11 @@ public: Type createExistentialMetatypeType( Type instance, - llvm::Optional repr = llvm::None); + std::optional repr = std::nullopt); Type createMetatypeType( Type instance, - llvm::Optional repr = llvm::None); + std::optional repr = std::nullopt); void pushGenericParams(ArrayRef> parameterPacks); void popGenericParams(); @@ -252,7 +252,7 @@ private: SynthesizedByImporter }; - llvm::Optional getForeignModuleKind(NodePointer node); + std::optional getForeignModuleKind(NodePointer node); GenericTypeDecl *findTypeDecl(DeclContext *dc, Identifier name, diff --git a/include/swift/AST/ASTMangler.h b/include/swift/AST/ASTMangler.h index abe600f9494..5d3f41bb51a 100644 --- a/include/swift/AST/ASTMangler.h +++ b/include/swift/AST/ASTMangler.h @@ -18,7 +18,7 @@ #include "swift/AST/Types.h" #include "swift/Basic/Mangler.h" #include "swift/Basic/TaggedUnion.h" -#include "llvm/ADT/Optional.h" +#include namespace clang { class NamedDecl; @@ -255,7 +255,7 @@ public: /// predefined in the Swift runtime for the given type signature. std::string mangleObjCAsyncCompletionHandlerImpl( CanSILFunctionType BlockType, CanType ResultType, CanGenericSignature Sig, - llvm::Optional FlagParamIsZeroOnError, bool predefined); + std::optional FlagParamIsZeroOnError, bool predefined); /// Mangle the derivative function (JVP/VJP), or optionally its vtable entry /// thunk, for the given: @@ -377,7 +377,7 @@ public: ClangImporterContext, }; - static llvm::Optional + static std::optional getSpecialManglingContext(const ValueDecl *decl, bool useObjCProtocolNames); static bool isCXXCFOptionsDefinition(const ValueDecl *decl); diff --git a/include/swift/AST/ASTPrinter.h b/include/swift/AST/ASTPrinter.h index c62d1a4807b..53bf3266958 100644 --- a/include/swift/AST/ASTPrinter.h +++ b/include/swift/AST/ASTPrinter.h @@ -131,7 +131,7 @@ public: /// /// Callers should use callPrintDeclPre(). virtual void printDeclPre(const Decl *D, - llvm::Optional Bracket) {} + std::optional Bracket) {} /// Called before printing at the point which would be considered the location /// of the declaration (normally the name of the declaration). /// @@ -146,7 +146,7 @@ public: /// /// Callers should use callPrintDeclPost(). virtual void printDeclPost(const Decl *D, - llvm::Optional Bracket) {} + std::optional Bracket) {} /// Called before printing the result type of the declaration. Printer can /// replace \p TL to customize the input. @@ -175,13 +175,13 @@ public: /// Called before printing a synthesized extension. virtual void printSynthesizedExtensionPre(const ExtensionDecl *ED, TypeOrExtensionDecl NTD, - llvm::Optional Bracket) {} + std::optional Bracket) {} /// Called after printing a synthesized extension. virtual void printSynthesizedExtensionPost(const ExtensionDecl *ED, TypeOrExtensionDecl TargetDecl, - llvm::Optional Bracket) {} + std::optional Bracket) {} /// Called before printing a structured entity. /// @@ -303,11 +303,10 @@ public: // MARK: Callback interface wrappers that perform ASTPrinter bookkeeping. /// Make a callback to printDeclPre(), performing any necessary bookkeeping. - void callPrintDeclPre(const Decl *D, llvm::Optional Bracket); + void callPrintDeclPre(const Decl *D, std::optional Bracket); /// Make a callback to printDeclPost(), performing any necessary bookkeeping. - void callPrintDeclPost(const Decl *D, - llvm::Optional Bracket) { + void callPrintDeclPost(const Decl *D, std::optional Bracket) { printDeclPost(D, Bracket); } diff --git a/include/swift/AST/ASTScope.h b/include/swift/AST/ASTScope.h index 27ce6206ee0..ac67f9d5016 100644 --- a/include/swift/AST/ASTScope.h +++ b/include/swift/AST/ASTScope.h @@ -37,10 +37,10 @@ #include "swift/Basic/LLVM.h" #include "swift/Basic/NullablePtr.h" #include "swift/Basic/SourceManager.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" +#include /// In case there's a bug in the ASTScope lookup system, suggest that the user /// try disabling it. @@ -164,7 +164,7 @@ private: /// Child scopes, sorted by source range. Children storedChildren; - mutable llvm::Optional cachedCharSourceRange; + mutable std::optional cachedCharSourceRange; #pragma mark - constructor / destructor public: @@ -995,11 +995,11 @@ public: class PatternEntryDeclScope final : public AbstractPatternEntryScope { const bool isLocalBinding; - llvm::Optional endLoc; + std::optional endLoc; public: PatternEntryDeclScope(PatternBindingDecl *pbDecl, unsigned entryIndex, - bool isLocalBinding, llvm::Optional endLoc) + bool isLocalBinding, std::optional endLoc) : AbstractPatternEntryScope(ScopeKind::PatternEntryDecl, pbDecl, entryIndex), isLocalBinding(isLocalBinding), endLoc(endLoc) {} diff --git a/include/swift/AST/ASTTypeIDZone.def b/include/swift/AST/ASTTypeIDZone.def index e1bc902a3d1..e8ffa9af047 100644 --- a/include/swift/AST/ASTTypeIDZone.def +++ b/include/swift/AST/ASTTypeIDZone.def @@ -61,9 +61,9 @@ SWIFT_TYPEID_NAMED(NamedPattern *, NamedPattern) SWIFT_TYPEID_NAMED(NominalTypeDecl *, NominalTypeDecl) SWIFT_TYPEID_NAMED(OpaqueTypeDecl *, OpaqueTypeDecl) SWIFT_TYPEID_NAMED(OperatorDecl *, OperatorDecl) -SWIFT_TYPEID_NAMED(llvm::Optional, +SWIFT_TYPEID_NAMED(std::optional, PropertyWrapperLValueness) -SWIFT_TYPEID_NAMED(llvm::Optional, +SWIFT_TYPEID_NAMED(std::optional, PropertyWrapperMutability) SWIFT_TYPEID_NAMED(ParamDecl *, ParamDecl) SWIFT_TYPEID_NAMED(PatternBindingEntry *, PatternBindingEntry) diff --git a/include/swift/AST/ASTTypeIDs.h b/include/swift/AST/ASTTypeIDs.h index ea97c297a64..56ab024b122 100644 --- a/include/swift/AST/ASTTypeIDs.h +++ b/include/swift/AST/ASTTypeIDs.h @@ -19,7 +19,7 @@ #include "swift/Basic/LLVM.h" #include "swift/Basic/TypeID.h" -#include "llvm/ADT/Optional.h" +#include namespace swift { diff --git a/include/swift/AST/ASTWalker.h b/include/swift/AST/ASTWalker.h index 2a31bdf4e46..1bfb1ecebac 100644 --- a/include/swift/AST/ASTWalker.h +++ b/include/swift/AST/ASTWalker.h @@ -14,9 +14,8 @@ #define SWIFT_AST_ASTWALKER_H #include "swift/Basic/LLVM.h" -#include "llvm/ADT/Optional.h" -#include "llvm/ADT/None.h" #include "llvm/ADT/PointerUnion.h" +#include #include namespace swift { @@ -48,17 +47,17 @@ enum class SemaReferenceKind : uint8_t { struct ReferenceMetaData { SemaReferenceKind Kind; - llvm::Optional AccKind; + std::optional AccKind; bool isImplicit = false; bool isImplicitCtorType = false; /// When non-none, this is a custom attribute reference. - llvm::Optional> CustomAttrRef; + std::optional> CustomAttrRef; - ReferenceMetaData(SemaReferenceKind Kind, llvm::Optional AccKind, + ReferenceMetaData(SemaReferenceKind Kind, std::optional AccKind, bool isImplicit = false, - llvm::Optional> - customAttrRef = llvm::None) + std::optional> + customAttrRef = std::nullopt) : Kind(Kind), AccKind(AccKind), isImplicit(isImplicit), CustomAttrRef(customAttrRef) {} }; @@ -397,7 +396,7 @@ public: template struct PreWalkResult { PreWalkAction Action; - llvm::Optional Value; + std::optional Value; template ::value>::type @@ -428,7 +427,7 @@ public: : Action(Result.Action), Value(std::move(Result.Value)) {} PreWalkResult(_Detail::StopWalkAction Action) - : Action(Action), Value(llvm::None) {} + : Action(Action), Value(std::nullopt) {} }; /// Do not construct directly, use \c Action:: instead. @@ -439,7 +438,7 @@ public: template struct PostWalkResult { PostWalkAction Action; - llvm::Optional Value; + std::optional Value; template ::value>::type @@ -466,7 +465,7 @@ public: : Action(Result.Action), Value(std::move(Result.Value)) {} PostWalkResult(_Detail::StopWalkAction Action) - : Action(Action), Value(llvm::None) {} + : Action(Action), Value(std::nullopt) {} }; /// This method is called when first visiting an expression diff --git a/include/swift/AST/AbstractSourceFileDepGraphFactory.h b/include/swift/AST/AbstractSourceFileDepGraphFactory.h index 8668093b558..1a4dd896cbf 100644 --- a/include/swift/AST/AbstractSourceFileDepGraphFactory.h +++ b/include/swift/AST/AbstractSourceFileDepGraphFactory.h @@ -16,8 +16,8 @@ #include "swift/AST/Decl.h" #include "swift/AST/DeclContext.h" #include "swift/AST/FineGrainedDependencies.h" -#include "llvm/ADT/Optional.h" #include "llvm/Support/VirtualOutputBackend.h" +#include namespace swift { class DiagnosticEngine; @@ -91,7 +91,7 @@ protected: /// represent some \c Decl defined in this source file. \param key the /// interface key of the pair void addADefinedDecl(const DependencyKey &key, - llvm::Optional fingerprint); + std::optional fingerprint); void addAUsedDecl(const DependencyKey &def, const DependencyKey &use); @@ -99,18 +99,18 @@ protected: /// is not \c None, it is added to the def key. void addAnExternalDependency(const DependencyKey &def, const DependencyKey &use, - llvm::Optional dependencyFingerprint); + std::optional dependencyFingerprint); - static llvm::Optional + static std::optional getFingerprintIfAny(std::pair) { - return llvm::None; + return std::nullopt; } - static llvm::Optional getFingerprintIfAny(const Decl *d) { + static std::optional getFingerprintIfAny(const Decl *d) { if (const auto *idc = dyn_cast(d)) { return idc->getBodyFingerprint(); } - return llvm::None; + return std::nullopt; } }; diff --git a/include/swift/AST/AccessNotes.h b/include/swift/AST/AccessNotes.h index 853d200cd3d..535eeeebea1 100644 --- a/include/swift/AST/AccessNotes.h +++ b/include/swift/AST/AccessNotes.h @@ -21,10 +21,10 @@ #include "swift/AST/Identifier.h" #include "swift/AST/StorageImpl.h" #include "swift/Basic/NullablePtr.h" -#include "llvm/ADT/Optional.h" #include "llvm/Support/Error.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" +#include #include #include #include @@ -48,7 +48,7 @@ public: DeclName name; /// For accessors, the kind of accessor; for non-accessors, \c None. - llvm::Optional accessorKind; + std::optional accessorKind; AccessNoteDeclName(ASTContext &ctx, StringRef str); AccessNoteDeclName(); @@ -71,15 +71,15 @@ public: /// If \c true, add an @objc attribute; if \c false, delete an @objc /// attribute; if \c None, do nothing. - llvm::Optional ObjC; + std::optional ObjC; /// If \c true, add a dynamic modifier; if \c false, delete a dynamic /// modifier; if \c None, do nothing. - llvm::Optional Dynamic; + std::optional Dynamic; /// If set, modify an @objc attribute to give it the specified \c ObjCName. /// If \c ObjC would otherwise be \c None, it will be set to \c true. - llvm::Optional ObjCName; + std::optional ObjCName; void dump(llvm::raw_ostream &os, int indent = 0) const; SWIFT_DEBUG_DUMP; @@ -97,8 +97,8 @@ public: /// Load the access notes from \p buffer, or \c None if they cannot be loaded. /// Diagnoses any parsing issues with the access notes file. - static llvm::Optional - load(ASTContext &ctx, const llvm::MemoryBuffer *buffer); + static std::optional load(ASTContext &ctx, + const llvm::MemoryBuffer *buffer); /// Look up the access note in this file, if any, which applies to \p VD. NullablePtr lookup(ValueDecl *VD) const; diff --git a/include/swift/AST/AccessRequests.h b/include/swift/AST/AccessRequests.h index 7ca72772027..bf1e5025bf5 100644 --- a/include/swift/AST/AccessRequests.h +++ b/include/swift/AST/AccessRequests.h @@ -46,7 +46,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(AccessLevel value) const; }; @@ -69,7 +69,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(AccessLevel value) const; }; @@ -91,7 +91,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(DefaultAndMax value) const; }; diff --git a/include/swift/AST/AccessScope.h b/include/swift/AST/AccessScope.h index 8909f0f385e..892df6fff6d 100644 --- a/include/swift/AST/AccessScope.h +++ b/include/swift/AST/AccessScope.h @@ -16,9 +16,8 @@ #include "swift/AST/AttrKind.h" #include "swift/AST/DeclContext.h" #include "swift/Basic/Debug.h" -#include "llvm/ADT/None.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/PointerIntPair.h" +#include namespace swift { @@ -135,7 +134,7 @@ public: /// Returns the narrowest access scope if this and the specified access scope /// have common intersection, or None if scopes don't intersect. - const llvm::Optional + const std::optional intersectWith(AccessScope accessScope) const { if (hasEqualDeclContextWith(accessScope)) { if (isPrivate()) @@ -147,7 +146,7 @@ public: if (accessScope.isChildOf(*this)) return accessScope; - return llvm::None; + return std::nullopt; } SWIFT_DEBUG_DUMP; diff --git a/include/swift/AST/AnyFunctionRef.h b/include/swift/AST/AnyFunctionRef.h index 371b0ecfd2f..c979eff1014 100644 --- a/include/swift/AST/AnyFunctionRef.h +++ b/include/swift/AST/AnyFunctionRef.h @@ -21,9 +21,8 @@ #include "swift/Basic/Debug.h" #include "swift/Basic/LLVM.h" #include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/None.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/PointerUnion.h" +#include namespace swift { class CaptureInfo; @@ -58,7 +57,7 @@ public: /// Construct an AnyFunctionRef from a decl context that might be /// some sort of function. - static llvm::Optional fromDeclContext(DeclContext *dc) { + static std::optional fromDeclContext(DeclContext *dc) { if (auto fn = dyn_cast(dc)) { return AnyFunctionRef(fn); } @@ -67,7 +66,7 @@ public: return AnyFunctionRef(ace); } - return llvm::None; + return std::nullopt; } CaptureInfo getCaptureInfo() const { diff --git a/include/swift/AST/ArgumentList.h b/include/swift/AST/ArgumentList.h index 3ec0b637046..5228fd5cf11 100644 --- a/include/swift/AST/ArgumentList.h +++ b/include/swift/AST/ArgumentList.h @@ -20,9 +20,9 @@ #include "swift/AST/ASTAllocated.h" #include "swift/AST/Types.h" #include "swift/Basic/Debug.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/TrailingObjects.h" +#include namespace swift { /// Forward declared trampoline for Expr::getType. @@ -140,7 +140,7 @@ class alignas(Argument) ArgumentList final bool HasLabelLocs : 1; ArgumentList(SourceLoc lParenLoc, SourceLoc rParenLoc, unsigned numArgs, - llvm::Optional firstTrailingClosureIndex, + std::optional firstTrailingClosureIndex, ArgumentList *originalArgs, bool isImplicit, bool hasLabels, bool hasLabelLocs) : LParenLoc(lParenLoc), RParenLoc(rParenLoc), NumArgs(numArgs), @@ -221,9 +221,8 @@ public: /// \param arena The arena to allocate the ArgumentList in. static ArgumentList * create(ASTContext &ctx, SourceLoc lParenLoc, ArrayRef args, - SourceLoc rParenLoc, - llvm::Optional firstTrailingClosureIndex, bool isImplicit, - ArgumentList *originalArgs = nullptr, + SourceLoc rParenLoc, std::optional firstTrailingClosureIndex, + bool isImplicit, ArgumentList *originalArgs = nullptr, AllocationArena arena = AllocationArena::Permanent); /// Create a new explicit parsed ArgumentList. @@ -237,7 +236,7 @@ public: static ArgumentList * createParsed(ASTContext &ctx, SourceLoc lParenLoc, ArrayRef args, SourceLoc rParenLoc, - llvm::Optional firstTrailingClosureIndex); + std::optional firstTrailingClosureIndex); /// Create a new type-checked ArgumentList from an original set of arguments. /// @@ -259,13 +258,13 @@ public: static ArgumentList *createImplicit( ASTContext &ctx, SourceLoc lParenLoc, ArrayRef args, SourceLoc rParenLoc, - llvm::Optional firstTrailingClosureIndex = llvm::None, + std::optional firstTrailingClosureIndex = std::nullopt, AllocationArena arena = AllocationArena::Permanent); /// Create a new implicit ArgumentList with a set of \p args. static ArgumentList *createImplicit( ASTContext &ctx, ArrayRef args, - llvm::Optional firstTrailingClosureIndex = llvm::None, + std::optional firstTrailingClosureIndex = std::nullopt, AllocationArena arena = AllocationArena::Permanent); /// Create a new implicit ArgumentList with a single labeled argument @@ -382,10 +381,10 @@ public: /// /// Note for a type-checked argument list, this must be queried on /// \c getOriginalArgs instead. - llvm::Optional getFirstTrailingClosureIndex() const { + std::optional getFirstTrailingClosureIndex() const { assert(!HasOriginalArgs && "Query original args instead"); if (RawFirstTrailingClosureIndex == NumArgs) - return llvm::None; + return std::nullopt; return RawFirstTrailingClosureIndex; } @@ -469,11 +468,11 @@ public: /// /// Note for a type-checked argument list, this must be queried on /// \c getOriginalArgs instead. - llvm::Optional getFirstTrailingClosure() const { + std::optional getFirstTrailingClosure() const { assert(!HasOriginalArgs && "Query original args instead"); auto idx = getFirstTrailingClosureIndex(); if (!idx.has_value()) - return llvm::None; + return std::nullopt; return get(*idx); } @@ -527,8 +526,8 @@ public: /// arguments, returns its index. Otherwise returns \c None. By default this /// will match against semantic sub-expressions, but that may be disabled by /// passing \c false for \c allowSemantic. - llvm::Optional findArgumentExpr(Expr *expr, - bool allowSemantic = true) const; + std::optional findArgumentExpr(Expr *expr, + bool allowSemantic = true) const; /// Creates a TupleExpr or ParenExpr that holds the argument exprs. A /// ParenExpr will be returned for a single argument, otherwise a TupleExpr. diff --git a/include/swift/AST/Attr.h b/include/swift/AST/Attr.h index d415e38a1e7..e714d5c7293 100644 --- a/include/swift/AST/Attr.h +++ b/include/swift/AST/Attr.h @@ -38,7 +38,6 @@ #include "swift/Basic/SourceLoc.h" #include "swift/Basic/UUID.h" #include "swift/Basic/Version.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/DenseMapInfo.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" @@ -46,6 +45,7 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/TrailingObjects.h" #include "llvm/Support/VersionTuple.h" +#include namespace swift { class ArgumentList; @@ -472,7 +472,7 @@ public: /// Also note that this recognizes both attributes like '@inline' (with no @) /// and decl modifiers like 'final'. /// - static llvm::Optional getAttrKindFromString(StringRef Str); + static std::optional getAttrKindFromString(StringRef Str); static DeclAttribute *createSimple(const ASTContext &context, DeclAttrKind kind, SourceLoc atLoc, @@ -664,8 +664,7 @@ enum class PlatformAgnosticAvailabilityKind { /// Defines the @available attribute. class AvailableAttr : public DeclAttribute { public: -#define INIT_VER_TUPLE(X) \ - X(X.empty() ? llvm::Optional() : X) +#define INIT_VER_TUPLE(X) X(X.empty() ? std::optional() : X) AvailableAttr(SourceLoc AtLoc, SourceRange Range, PlatformKind Platform, StringRef Message, StringRef Rename, ValueDecl *RenameDecl, @@ -703,19 +702,19 @@ public: ValueDecl *RenameDecl; /// Indicates when the symbol was introduced. - const llvm::Optional Introduced; + const std::optional Introduced; /// Indicates where the Introduced version was specified. const SourceRange IntroducedRange; /// Indicates when the symbol was deprecated. - const llvm::Optional Deprecated; + const std::optional Deprecated; /// Indicates where the Deprecated version was specified. const SourceRange DeprecatedRange; /// Indicates when the symbol was obsoleted. - const llvm::Optional Obsoleted; + const std::optional Obsoleted; /// Indicates where the Obsoleted version was specified. const SourceRange ObsoletedRange; @@ -816,7 +815,7 @@ class ObjCAttr final : public DeclAttribute, void *NameData; /// Create an implicit @objc attribute with the given (optional) name. - explicit ObjCAttr(llvm::Optional name, bool implicitName) + explicit ObjCAttr(std::optional name, bool implicitName) : DeclAttribute(DeclAttrKind::ObjC, SourceLoc(), SourceRange(), /*Implicit=*/true), NameData(nullptr) { @@ -830,7 +829,7 @@ class ObjCAttr final : public DeclAttribute, /// Create an @objc attribute written in the source. ObjCAttr(SourceLoc atLoc, SourceRange baseRange, - llvm::Optional name, SourceRange parenRange, + std::optional name, SourceRange parenRange, ArrayRef nameLocs); /// Determine whether this attribute has trailing location information. @@ -858,7 +857,7 @@ class ObjCAttr final : public DeclAttribute, public: /// Create implicit ObjC attribute with a given (optional) name. - static ObjCAttr *create(ASTContext &Ctx, llvm::Optional name, + static ObjCAttr *create(ASTContext &Ctx, std::optional name, bool implicitName); /// Create an unnamed Objective-C attribute, i.e., @objc. @@ -904,9 +903,9 @@ public: bool hasName() const { return NameData != nullptr; } /// Retrieve the name of this entity, if specified. - llvm::Optional getName() const { + std::optional getName() const { if (!hasName()) - return llvm::None; + return std::nullopt; return ObjCSelector::getFromOpaqueValue(NameData); } @@ -1864,7 +1863,7 @@ public: /// Returns non-optional if this attribute is active given the current platform. /// The value provides more details about the active platform. - llvm::Optional isActivePlatform(const ASTContext &ctx) const; + std::optional isActivePlatform(const ASTContext &ctx) const; static bool classof(const DeclAttribute *DA) { return DA->getKind() == DeclAttrKind::OriginallyDefinedIn; } @@ -2024,7 +2023,7 @@ struct DeclNameRefWithLoc { /// The declaration name location. DeclNameLoc Loc; /// An optional accessor kind. - llvm::Optional AccessorKind; + std::optional AccessorKind; void print(ASTPrinter &Printer) const; }; @@ -2088,7 +2087,7 @@ class DerivativeAttr final /// The differentiability parameter indices, resolved by the type checker. IndexSubset *ParameterIndices = nullptr; /// The derivative function kind (JVP or VJP), resolved by the type checker. - llvm::Optional Kind = llvm::None; + std::optional Kind = std::nullopt; explicit DerivativeAttr(bool implicit, SourceLoc atLoc, SourceRange baseRange, TypeRepr *baseTypeRepr, DeclNameRefWithLoc original, @@ -2348,28 +2347,27 @@ class ExternAttr : public DeclAttribute { SourceLoc LParenLoc, RParenLoc; public: - ExternAttr(llvm::Optional ModuleName, - llvm::Optional Name, SourceLoc AtLoc, - SourceLoc LParenLoc, SourceLoc RParenLoc, SourceRange Range, - ExternKind Kind, bool Implicit) + ExternAttr(std::optional ModuleName, std::optional Name, + SourceLoc AtLoc, SourceLoc LParenLoc, SourceLoc RParenLoc, + SourceRange Range, ExternKind Kind, bool Implicit) : DeclAttribute(DeclAttrKind::Extern, AtLoc, Range, Implicit), LParenLoc(LParenLoc), RParenLoc(RParenLoc), ModuleName(ModuleName), Name(Name) { Bits.ExternAttr.kind = static_cast(Kind); } - ExternAttr(llvm::Optional ModuleName, - llvm::Optional Name, ExternKind Kind, bool Implicit) + ExternAttr(std::optional ModuleName, std::optional Name, + ExternKind Kind, bool Implicit) : ExternAttr(ModuleName, Name, SourceLoc(), SourceLoc(), SourceLoc(), SourceRange(), Kind, Implicit) {} /// The module name to import the named declaration in it /// Used for Wasm import declaration. - const llvm::Optional ModuleName; + const std::optional ModuleName; /// The declaration name to import /// std::nullopt if the declaration name is not specified with @_extern(c) - const llvm::Optional Name; + const std::optional Name; SourceLoc getLParenLoc() const { return LParenLoc; } SourceLoc getRParenLoc() const { return RParenLoc; } @@ -2396,17 +2394,17 @@ public: class DocumentationAttr: public DeclAttribute { public: DocumentationAttr(SourceLoc AtLoc, SourceRange Range, StringRef Metadata, - llvm::Optional Visibility, bool Implicit) + std::optional Visibility, bool Implicit) : DeclAttribute(DeclAttrKind::Documentation, AtLoc, Range, Implicit), Metadata(Metadata), Visibility(Visibility) {} - DocumentationAttr(StringRef Metadata, llvm::Optional Visibility, + DocumentationAttr(StringRef Metadata, std::optional Visibility, bool Implicit) : DocumentationAttr(SourceLoc(), SourceRange(), Metadata, Visibility, Implicit) {} const StringRef Metadata; - const llvm::Optional Visibility; + const std::optional Visibility; static bool classof(const DeclAttribute *DA) { return DA->getKind() == DeclAttrKind::Documentation; @@ -2558,47 +2556,48 @@ public: /// Return the type whose array layout the attribute type should get its /// layout from, along with the size of that array. Returns None if the /// attribute specifies scalar or manual layout. - llvm::Optional> getArrayLikeTypeAndCount() const { + std::optional> + getArrayLikeTypeAndCount() const { if (!LikeType) - return llvm::None; + return std::nullopt; if (Alignment == ~0u) - return llvm::None; + return std::nullopt; return std::make_pair(LikeType, SizeOrCount); } - + /// Return the size and alignment of the attributed type. Returns /// None if the attribute specifies layout like some other type. - llvm::Optional> getSizeAndAlignment() const { + std::optional> getSizeAndAlignment() const { if (LikeType) - return llvm::None; + return std::nullopt; return std::make_pair(SizeOrCount, Alignment); } - + Type getResolvedLikeType(StructDecl *sd) const; /// Return the type whose single-element layout the attribute type should get /// its layout from. Returns None if the attribute specifies an array or manual /// layout. - llvm::Optional getResolvedScalarLikeType(StructDecl *sd) const { + std::optional getResolvedScalarLikeType(StructDecl *sd) const { if (!LikeType) - return llvm::None; + return std::nullopt; if (Alignment != ~0u) - return llvm::None; + return std::nullopt; return getResolvedLikeType(sd); } - + /// Return the type whose array layout the attribute type should get its /// layout from, along with the size of that array. Returns None if the /// attribute specifies scalar or manual layout. - llvm::Optional> + std::optional> getResolvedArrayLikeTypeAndCount(StructDecl *sd) const { if (!LikeType) - return llvm::None; + return std::nullopt; if (Alignment == ~0u) - return llvm::None; + return std::nullopt; return std::make_pair(getResolvedLikeType(sd), SizeOrCount); } - + static bool classof(const DeclAttribute *DA) { return DA->getKind() == DeclAttrKind::RawLayout; } @@ -2630,10 +2629,10 @@ public: template struct ToAttributeKind { ToAttributeKind() {} - llvm::Optional operator()(const DeclAttribute *Attr) const { + std::optional operator()(const DeclAttribute *Attr) const { if (isa(Attr) && (Attr->isValid() || AllowInvalid)) return cast(Attr); - return llvm::None; + return std::nullopt; } }; @@ -2878,7 +2877,7 @@ public: ParsedDeclAttrFilter(const Decl *decl) : decl(decl) {} - llvm::Optional + std::optional operator()(const DeclAttribute *Attr) const; }; @@ -3011,7 +3010,7 @@ public: /// Given a name like "autoclosure", return the type attribute ID that /// corresponds to it. - static llvm::Optional getAttrKindFromString(StringRef Str); + static std::optional getAttrKindFromString(StringRef Str); /// Return the name (like "autoclosure") for an attribute ID. static const char *getAttrName(TypeAttrKind kind); @@ -3088,7 +3087,7 @@ public: StringRef getConventionName() const { return Name.Item; } SourceLoc getConventionLoc() const { return Name.Loc; } - llvm::Optional getClangType() const { + std::optional getClangType() const { if (!ClangType.Item.empty()) return ClangType.Item; return {}; } diff --git a/include/swift/AST/AutoDiff.h b/include/swift/AST/AutoDiff.h index 56c37a1661f..d4d2574882b 100644 --- a/include/swift/AST/AutoDiff.h +++ b/include/swift/AST/AutoDiff.h @@ -109,7 +109,7 @@ struct NormalDifferentiableFunctionTypeComponent { /// Returns the derivative function kind, if the component is a derivative /// function. - llvm::Optional + std::optional getAsDerivativeFunctionKind() const; }; @@ -180,7 +180,7 @@ struct DifferentiabilityWitnessFunctionKind { explicit DifferentiabilityWitnessFunctionKind(StringRef name); operator innerty() const { return rawValue; } - llvm::Optional + std::optional getAsDerivativeFunctionKind() const; }; @@ -522,15 +522,15 @@ struct TangentPropertyInfo { VarDecl *tangentProperty = nullptr; /// An optional error. - llvm::Optional error = llvm::None; + std::optional error = std::nullopt; private: - TangentPropertyInfo(VarDecl *tangentProperty, llvm::Optional error) + TangentPropertyInfo(VarDecl *tangentProperty, std::optional error) : tangentProperty(tangentProperty), error(error) {} public: TangentPropertyInfo(VarDecl *tangentProperty) - : TangentPropertyInfo(tangentProperty, llvm::None) {} + : TangentPropertyInfo(tangentProperty, std::nullopt) {} TangentPropertyInfo(Error::Kind errorKind) : TangentPropertyInfo(nullptr, Error(errorKind)) {} diff --git a/include/swift/AST/Availability.h b/include/swift/AST/Availability.h index d865cf7e341..f1a4ce04759 100644 --- a/include/swift/AST/Availability.h +++ b/include/swift/AST/Availability.h @@ -19,8 +19,8 @@ #include "swift/AST/Type.h" #include "swift/Basic/LLVM.h" -#include "llvm/ADT/Optional.h" #include "llvm/Support/VersionTuple.h" +#include namespace swift { class ASTContext; @@ -229,12 +229,13 @@ public: /// to create an \c AvailabilityContext, rather than creating one directly. class AvailabilityContext { VersionRange OSVersion; - llvm::Optional SPI; + std::optional SPI; + public: /// Creates a context that requires certain versions of the target OS. explicit AvailabilityContext(VersionRange OSVersion, - llvm::Optional SPI = llvm::None) - : OSVersion(OSVersion), SPI(SPI) {} + std::optional SPI = std::nullopt) + : OSVersion(OSVersion), SPI(SPI) {} /// Creates a context that imposes the constraints of the ASTContext's /// deployment target. @@ -374,7 +375,7 @@ public: /// Returns the context for which the declaration /// is annotated as available, or None if the declaration /// has no availability annotation. - static llvm::Optional + static std::optional annotatedAvailableRange(const Decl *D, ASTContext &C); static AvailabilityContext diff --git a/include/swift/AST/CaptureInfo.h b/include/swift/AST/CaptureInfo.h index dcab728fdd0..cd2ac296a19 100644 --- a/include/swift/AST/CaptureInfo.h +++ b/include/swift/AST/CaptureInfo.h @@ -188,7 +188,7 @@ public: // FIXME: Ideally, everywhere that synthesizes a function should include // its capture info. if (!hasBeenComputed()) - return llvm::None; + return std::nullopt; return StorageAndFlags.getPointer()->getCaptures(); } diff --git a/include/swift/AST/CatchNode.h b/include/swift/AST/CatchNode.h index f564d8e03ac..6265fc963a1 100644 --- a/include/swift/AST/CatchNode.h +++ b/include/swift/AST/CatchNode.h @@ -13,12 +13,12 @@ #ifndef SWIFT_AST_CATCHNODE_H #define SWIFT_AST_CATCHNODE_H -#include "llvm/ADT/Hashing.h" -#include "llvm/ADT/Optional.h" -#include "llvm/ADT/PointerUnion.h" #include "swift/AST/Decl.h" #include "swift/AST/Expr.h" #include "swift/AST/Stmt.h" +#include "llvm/ADT/Hashing.h" +#include "llvm/ADT/PointerUnion.h" +#include namespace swift { @@ -34,9 +34,9 @@ public: /// where it will catch (and possibly rethrow) errors. All of the errors /// thrown from within that region will be converted to this error type. /// - /// Returns the thrown error type for a throwing context, or \c llvm::None + /// Returns the thrown error type for a throwing context, or \c std::nullopt /// if this is a non-throwing context. - llvm::Optional getThrownErrorTypeInContext(ASTContext &ctx) const; + std::optional getThrownErrorTypeInContext(ASTContext &ctx) const; /// Determines the explicitly-specified type error that will be caught by /// this catch node. diff --git a/include/swift/AST/ClangModuleLoader.h b/include/swift/AST/ClangModuleLoader.h index 8dc571779b7..aad28c82ec7 100644 --- a/include/swift/AST/ClangModuleLoader.h +++ b/include/swift/AST/ClangModuleLoader.h @@ -285,7 +285,7 @@ public: virtual FuncDecl *getDefaultArgGenerator(const clang::ParmVarDecl *param) = 0; - virtual llvm::Optional + virtual std::optional importFunctionReturnType(const clang::FunctionDecl *clangDecl, DeclContext *dc) = 0; diff --git a/include/swift/AST/Comment.h b/include/swift/AST/Comment.h index 51272db63f7..f1f4453e61b 100644 --- a/include/swift/AST/Comment.h +++ b/include/swift/AST/Comment.h @@ -14,7 +14,7 @@ #define SWIFT_AST_COMMENT_H #include "swift/Markup/Markup.h" -#include "llvm/ADT/Optional.h" +#include namespace swift { class Decl; @@ -49,15 +49,15 @@ public: return llvm::makeArrayRef(Parts.Tags.begin(), Parts.Tags.end()); } - llvm::Optional getBrief() const { + std::optional getBrief() const { return Parts.Brief; } - llvm::Optional getReturnsField() const { + std::optional getReturnsField() const { return Parts.ReturnsField; } - llvm::Optional getThrowsField() const { + std::optional getThrowsField() const { return Parts.ThrowsField; } @@ -69,7 +69,7 @@ public: return Parts.BodyNodes; } - llvm::Optional + std::optional getLocalizationKeyField() const { return Parts.LocalizationKeyField; } diff --git a/include/swift/AST/ConstTypeInfo.h b/include/swift/AST/ConstTypeInfo.h index 869b188c65d..59e58dae6ad 100644 --- a/include/swift/AST/ConstTypeInfo.h +++ b/include/swift/AST/ConstTypeInfo.h @@ -106,7 +106,7 @@ private: }; struct TupleElement { - llvm::Optional Label; + std::optional Label; swift::Type Type; std::shared_ptr Value; }; @@ -166,12 +166,12 @@ private: class EnumValue : public CompileTimeValue { public: EnumValue(std::string Identifier, - llvm::Optional> Parameters) + std::optional> Parameters) : CompileTimeValue(ValueKind::Enum), Identifier(Identifier), Parameters(Parameters) {} std::string getIdentifier() const { return Identifier; } - llvm::Optional> getParameters() const { + std::optional> getParameters() const { return Parameters; } @@ -181,7 +181,7 @@ public: private: std::string Identifier; - llvm::Optional> Parameters; + std::optional> Parameters; }; /// An type value representation @@ -217,40 +217,38 @@ struct CustomAttrValue { /// A representation of a single associated value for an enumeration case. struct EnumElementParameterValue { - llvm::Optional Label; + std::optional Label; swift::Type Type; }; /// A representation of a single enumeration case. struct EnumElementDeclValue { std::string Name; - llvm::Optional RawValue; - llvm::Optional> Parameters; + std::optional RawValue; + std::optional> Parameters; }; using AttrValueVector = llvm::SmallVector; struct ConstValueTypePropertyInfo { swift::VarDecl *VarDecl; std::shared_ptr Value; - llvm::Optional PropertyWrappers; + std::optional PropertyWrappers; - ConstValueTypePropertyInfo( - swift::VarDecl *VarDecl, std::shared_ptr Value, - llvm::Optional PropertyWrappers) - : VarDecl(VarDecl), Value(Value), PropertyWrappers(PropertyWrappers) - {} + ConstValueTypePropertyInfo(swift::VarDecl *VarDecl, + std::shared_ptr Value, + std::optional PropertyWrappers) + : VarDecl(VarDecl), Value(Value), PropertyWrappers(PropertyWrappers) {} ConstValueTypePropertyInfo(swift::VarDecl *VarDecl, std::shared_ptr Value) : VarDecl(VarDecl), Value(Value), - PropertyWrappers(llvm::Optional()) - {} + PropertyWrappers(std::optional()) {} }; struct ConstValueTypeInfo { swift::NominalTypeDecl *TypeDecl; std::vector Properties; - llvm::Optional> EnumElements; + std::optional> EnumElements; }; } // namespace swift #endif diff --git a/include/swift/AST/Decl.h b/include/swift/AST/Decl.h index 378c3b2fb2a..11661814adb 100644 --- a/include/swift/AST/Decl.h +++ b/include/swift/AST/Decl.h @@ -988,12 +988,12 @@ public: /// Returns the introduced OS version in the given platform kind specified /// by @available attribute. /// This function won't consider the parent context to get the information. - llvm::Optional + std::optional getIntroducedOSVersion(PlatformKind Kind) const; /// Returns the OS version in which the decl became ABI as specified by the /// `@backDeployed` attribute. - llvm::Optional + std::optional getBackDeployedBeforeOSVersion(ASTContext &Ctx) const; /// Returns true if the decl has an active `@backDeployed` attribute for the @@ -1016,13 +1016,13 @@ public: /// Returns the source range of the declaration including its attributes. SourceRange getSourceRangeIncludingAttrs() const; - using ImportAccessLevel = llvm::Optional>; + using ImportAccessLevel = std::optional>; /// Returns the import that may restrict the access to this decl /// from \p useDC. /// /// If this decl and \p useDC are from the same module it returns - /// \c llvm::None. If there are many imports, it returns the most + /// \c std::nullopt. If there are many imports, it returns the most /// permissive one. ImportAccessLevel getImportAccessFrom(const DeclContext *useDC) const; @@ -1118,11 +1118,11 @@ public: /// \returns the unparsed comment attached to this declaration. RawComment getRawComment() const; - llvm::Optional getGroupName() const; + std::optional getGroupName() const; - llvm::Optional getSourceFileName() const; + std::optional getSourceFileName() const; - llvm::Optional getSourceOrder() const; + std::optional getSourceOrder() const; /// \returns The brief comment attached to this declaration, or the brief /// comment attached to the comment providing decl. @@ -1263,7 +1263,7 @@ public: /// This is the "raw" global actor attribute as written directly on the /// declaration, along with the nominal type declaration to which it refers, /// without any inference rules applied. - llvm::Optional> + std::optional> getGlobalActorAttr() const; /// If an alternative module name is specified for this decl, e.g. using @@ -1286,7 +1286,7 @@ public: /// This attribute may come from an enclosing decl since availability is /// inherited. The second member of the returned pair is the decl that owns /// the attribute. - llvm::Optional> + std::optional> getSemanticAvailableRangeAttr() const; /// Retrieve the @available attribute that makes this declaration unavailable, @@ -1299,7 +1299,7 @@ public: /// /// Note that this notion of unavailability is broader than that which is /// checked by \c AvailableAttr::isUnavailable. - llvm::Optional> + std::optional> getSemanticUnavailableAttr(bool ignoreAppExtensions = false) const; /// Returns true if this declaration should be considered available during @@ -1363,10 +1363,10 @@ void *allocateMemoryForDecl(AllocatorTy &allocator, size_t baseSize, /// during lowering. template struct AvailableDuringLoweringDeclFilter { - llvm::Optional operator()(T *decl) const { + std::optional operator()(T *decl) const { if (decl->isAvailableDuringLowering()) return decl; - return llvm::None; + return std::nullopt; } }; @@ -1504,7 +1504,7 @@ public: /// /// If the list is non-homogeneous, or if there is more than one decl that /// cannot be overloaded, returns None. - static llvm::Optional + static std::optional findBestImportKind(ArrayRef Decls); ImportKind getImportKind() const { @@ -1859,7 +1859,7 @@ public: /// Returns the name of the category specified by the \c \@_objcImplementation /// attribute, or \c None if the name is invalid or /// \c isObjCImplementation() is false. - llvm::Optional getCategoryNameForObjCImplementation() const; + std::optional getCategoryNameForObjCImplementation() const; /// If this extension represents an imported Objective-C category, returns the /// category's name. Otherwise returns the empty identifier. @@ -2025,7 +2025,7 @@ public: PatternBindingInitializer *InitContext) : PatternAndFlags(P, {}), InitExpr({E, {E, InitializerStatus::NotChecked}, EqualLoc}), - InitContextAndFlags({InitContext, llvm::None}) {} + InitContextAndFlags({InitContext, std::nullopt}) {} private: Pattern *getPattern() const { return PatternAndFlags.getPointer(); } @@ -2622,18 +2622,18 @@ public: /// A reference to 'Self'. static GenericParameterReferenceInfo forSelfRef(TypePosition position) { - return GenericParameterReferenceInfo(false, position, llvm::None); + return GenericParameterReferenceInfo(false, position, std::nullopt); } /// A reference to the generic parameter in covariant result position. static GenericParameterReferenceInfo forCovariantResult() { return GenericParameterReferenceInfo(true, TypePosition::Covariant, - llvm::None); + std::nullopt); } /// A reference to 'Self' through an associated type. static GenericParameterReferenceInfo forAssocTypeRef(TypePosition position) { - return GenericParameterReferenceInfo(false, llvm::None, position); + return GenericParameterReferenceInfo(false, std::nullopt, position); } GenericParameterReferenceInfo &operator|=(const GenericParameterReferenceInfo &other); @@ -2643,8 +2643,8 @@ public: } GenericParameterReferenceInfo() - : hasCovariantSelfResult(false), selfRef(llvm::None), - assocTypeRef(llvm::None) {} + : hasCovariantSelfResult(false), selfRef(std::nullopt), + assocTypeRef(std::nullopt) {} private: GenericParameterReferenceInfo(bool hasCovariantSelfResult, OptionalTypePosition selfRef, @@ -2746,7 +2746,7 @@ protected: public: /// Find the import that makes the given declaration available. - llvm::Optional> + std::optional> findImport(const DeclContext *fromDC); /// Return true if this protocol member is a protocol requirement. @@ -2812,7 +2812,7 @@ public: /// entities (classes, protocols, properties), this operation will /// return a zero-parameter selector with the appropriate name in its /// first slot. - llvm::Optional + std::optional getObjCRuntimeName(bool skipIsObjCResolution = false) const; /// Determine whether the given declaration can infer @objc, or the @@ -3307,7 +3307,7 @@ private: /// expressed as a SubstitutionMap for the opaque interface generic signature. /// This maps types in the interface generic signature to the outer generic /// signature of the original declaration. - llvm::Optional UniqueUnderlyingType; + std::optional UniqueUnderlyingType; /// A set of substitutions which are used based on the availability /// checks performed at runtime. This set of only populated if there @@ -3315,8 +3315,8 @@ private: /// /// It always contains one or more conditionally available substitutions /// followed by a universally available type used as a fallback. - llvm::Optional> - ConditionallyAvailableTypes = llvm::None; + std::optional> + ConditionallyAvailableTypes = std::nullopt; mutable Identifier OpaqueReturnTypeIdentifier; @@ -3364,7 +3364,7 @@ public: /// Get the ordinal of the anonymous opaque parameter of this decl with type /// repr `repr`, as introduce implicitly by an occurrence of "some" in return /// position e.g. `func f() -> some P`. Returns -1 if `repr` is not found. - llvm::Optional getAnonymousOpaqueParamOrdinal(TypeRepr *repr) const; + std::optional getAnonymousOpaqueParamOrdinal(TypeRepr *repr) const; GenericSignature getOpaqueInterfaceGenericSignature() const { return OpaqueInterfaceGenericSignature; @@ -3400,7 +3400,7 @@ public: /// The substitutions that map the generic parameters of the opaque type to /// the unique underlying types, when that information is known. - llvm::Optional getUniqueUnderlyingTypeSubstitutions() const; + std::optional getUniqueUnderlyingTypeSubstitutions() const; void setUniqueUnderlyingTypeSubstitutions(SubstitutionMap subs) { assert(!UniqueUnderlyingType.has_value() && "resetting underlying type?!"); @@ -3877,7 +3877,7 @@ public: /// Retrieve the default definition type if computed, `None` otherwise. /// /// \Note Should only be used for dumping. - llvm::Optional getCachedDefaultDefinitionType() const; + std::optional getCachedDefaultDefinitionType() const; private: /// Set the computed default definition type. @@ -4227,7 +4227,7 @@ public: bool isOptionalDecl() const; /// Is this a key path type? - llvm::Optional getKeyPathTypeKind() const; + std::optional getKeyPathTypeKind() const; /// Retrieve information about this type as a property wrapper. PropertyWrapperTypeInfo getPropertyWrapperTypeInfo() const; @@ -4738,14 +4738,14 @@ class ClassDecl final : public NominalTypeDecl { llvm::PointerIntPair SuperclassType; } LazySemanticInfo; - llvm::Optional getCachedInheritsSuperclassInitializers() const { + std::optional getCachedInheritsSuperclassInitializers() const { if (Bits.ClassDecl.ComputedInheritsSuperclassInits) return Bits.ClassDecl.InheritsSuperclassInits; - return llvm::None; + return std::nullopt; } - llvm::Optional getCachedHasMissingDesignatedInitializers() const { + std::optional getCachedHasMissingDesignatedInitializers() const { if (!Bits.ClassDecl.ComputedHasMissingDesignatedInitializers) { // Force loading all the members, which will add this attribute if any of // members are determined to be missing while loading. @@ -4757,7 +4757,7 @@ class ClassDecl final : public NominalTypeDecl { if (Bits.ClassDecl.ComputedHasMissingDesignatedInitializers) return Bits.ClassDecl.HasMissingDesignatedInitializers; - return llvm::None; + return std::nullopt; } void setHasMissingDesignatedInitializers(bool value) { @@ -5092,15 +5092,15 @@ class ProtocolDecl final : public NominalTypeDecl { /// The generic signature representing exactly the new requirements introduced /// by this protocol. - llvm::Optional RequirementSig; + std::optional RequirementSig; /// Returns the cached result of \c requiresClass or \c None if it hasn't yet /// been computed. - llvm::Optional getCachedRequiresClass() const { + std::optional getCachedRequiresClass() const { if (Bits.ProtocolDecl.RequiresClassValid) return Bits.ProtocolDecl.RequiresClass; - return llvm::None; + return std::nullopt; } /// Caches the result of \c requiresClass @@ -5111,11 +5111,11 @@ class ProtocolDecl final : public NominalTypeDecl { /// Returns the cached result of \c existentialConformsToSelf or \c None if it /// hasn't yet been computed. - llvm::Optional getCachedExistentialConformsToSelf() const { + std::optional getCachedExistentialConformsToSelf() const { if (Bits.ProtocolDecl.ExistentialConformsToSelfValid) return Bits.ProtocolDecl.ExistentialConformsToSelf; - return llvm::None; + return std::nullopt; } /// Caches the result of \c existentialConformsToSelf @@ -5126,11 +5126,11 @@ class ProtocolDecl final : public NominalTypeDecl { /// Returns the cached result of \c hasSelfOrAssociatedTypeRequirements or /// \c None if it hasn't yet been computed. - llvm::Optional getCachedHasSelfOrAssociatedTypeRequirements() { + std::optional getCachedHasSelfOrAssociatedTypeRequirements() { if (Bits.ProtocolDecl.HasSelfOrAssociatedTypeRequirementsValid) return static_cast(Bits.ProtocolDecl.HasSelfOrAssociatedTypeRequirements); - return llvm::None; + return std::nullopt; } /// Caches the result of \c hasSelfOrAssociatedTypeRequirements @@ -5290,7 +5290,7 @@ public: /// Determine if this is an invertible protocol and return its kind, /// i.e., for a protocol P, returns the kind if inverse constraint ~P exists. - llvm::Optional getInvertibleProtocolKind() const; + std::optional getInvertibleProtocolKind() const; private: void computeKnownProtocolKind() const; @@ -5312,17 +5312,17 @@ private: public: /// If this is known to be a compiler-known protocol, returns the kind. /// Otherwise returns None. - llvm::Optional getKnownProtocolKind() const { + std::optional getKnownProtocolKind() const { if (Bits.ProtocolDecl.KnownProtocol == 0) computeKnownProtocolKind(); if (Bits.ProtocolDecl.KnownProtocol == 1) - return llvm::None; + return std::nullopt; return static_cast(Bits.ProtocolDecl.KnownProtocol - 2); } - llvm::Optional + std::optional getKnownDerivableProtocolKind() const; /// Check whether this protocol is of a specific, known protocol kind. @@ -6339,13 +6339,12 @@ public: /// Retrieve information about the mutability of the composed /// property wrappers. - llvm::Optional - getPropertyWrapperMutability() const; + std::optional getPropertyWrapperMutability() const; /// Returns whether this property is the backing storage property or a storage /// wrapper for wrapper instance's projectedValue. If this property is /// neither, then it returns `None`. - llvm::Optional + std::optional getPropertyWrapperSynthesizedPropertyKind() const; /// Retrieve the backing storage property for a property that has an @@ -6397,8 +6396,8 @@ public: /// \param kind If not \c None, only returns the original property when /// \c this property is the specified synthesized property. VarDecl *getOriginalWrappedProperty( - llvm::Optional kind = - llvm::None) const; + std::optional kind = + std::nullopt) const; /// Set the property that wraps to this property as it's backing /// property. @@ -6498,7 +6497,7 @@ class ParamDecl : public VarDecl { /// Retrieve the cached initializer context for the parameter's default /// argument without triggering a request. - llvm::Optional getCachedDefaultArgumentInitContext() const; + std::optional getCachedDefaultArgumentInitContext() const; /// NOTE: This is stored using bits from TyReprAndFlags and /// DefaultValueAndFlags. @@ -6830,11 +6829,11 @@ public: using Specifier = ParamSpecifier; - llvm::Optional getCachedSpecifier() const { + std::optional getCachedSpecifier() const { if (Bits.ParamDecl.OwnershipSpecifier != 0) return Specifier(Bits.ParamDecl.OwnershipSpecifier - 1); - return llvm::None; + return std::nullopt; } /// Return the raw specifier value for this parameter. @@ -7104,21 +7103,21 @@ class BodyAndFingerprint { Fingerprint Fp; public: - BodyAndFingerprint(BraceStmt *body, llvm::Optional fp) + BodyAndFingerprint(BraceStmt *body, std::optional fp) : BodyAndHasFp(body, fp.has_value()), Fp(fp.has_value() ? *fp : Fingerprint::ZERO()) {} - BodyAndFingerprint() : BodyAndFingerprint(nullptr, llvm::None) {} + BodyAndFingerprint() : BodyAndFingerprint(nullptr, std::nullopt) {} BraceStmt *getBody() const { return BodyAndHasFp.getPointer(); } - llvm::Optional getFingerprint() const { + std::optional getFingerprint() const { if (BodyAndHasFp.getInt()) return Fp; else - return llvm::None; + return std::nullopt; } - void setFingerprint(llvm::Optional fp) { + void setFingerprint(std::optional fp) { if (fp.has_value()) { Fp = *fp; BodyAndHasFp.setInt(true); @@ -7387,12 +7386,12 @@ public: /// Retrieves the thrown interface type. Type getThrownInterfaceType() const; - /// Retrieve the "effective" thrown interface type, or llvm::None if + /// Retrieve the "effective" thrown interface type, or std::nullopt if /// this function cannot throw. /// /// Functions with untyped throws will produce "any Error", functions that - /// cannot throw or are specified to throw "Never" will return llvm::None. - llvm::Optional getEffectiveThrownErrorType() const; + /// cannot throw or are specified to throw "Never" will return std::nullopt. + std::optional getEffectiveThrownErrorType() const; /// Returns if the function throws or is async. bool hasEffect(EffectKind kind) const; @@ -7464,7 +7463,7 @@ public: /// Provide the parsed body for the function. void setBodyParsed(BraceStmt *S, - llvm::Optional fp = llvm::None) { + std::optional fp = std::nullopt) { setBody(S, BodyKind::Parsed); BodyAndFP.setFingerprint(fp); } @@ -7628,11 +7627,11 @@ public: /// Retrieve the fingerprint of the body. Note that this is not affected by /// the body of the local functions or the members of the local types in this /// function. - llvm::Optional getBodyFingerprint() const; + std::optional getBodyFingerprint() const; /// Retrieve the fingerprint of the body including the local type members and /// the local function bodies. - llvm::Optional + std::optional getBodyFingerprintIncludingLocalTypeMembers() const; /// Retrieve the source range of the *original* function body. @@ -7706,14 +7705,14 @@ public: /// Get information about the foreign error convention used by this /// declaration, given that it is @objc and 'throws'. - llvm::Optional getForeignErrorConvention() const; + std::optional getForeignErrorConvention() const; /// If this is a foreign C function imported as a method, get the index of /// the foreign parameter imported as `self`. If the function is imported /// as a static method, `-1` is returned to represent the `self` parameter /// being dropped altogether. `None` is returned for a normal function /// or method. - llvm::Optional getForeignFunctionAsMethodSelfParameterIndex() const; + std::optional getForeignFunctionAsMethodSelfParameterIndex() const; /// Set information about the foreign async convention used by this /// declaration. @@ -7721,7 +7720,7 @@ public: /// Get information about the foreign async convention used by this /// declaration, given that it is @objc and 'async'. - llvm::Optional getForeignAsyncConvention() const; + std::optional getForeignAsyncConvention() const; static bool classof(const Decl *D) { return D->getKind() >= DeclKind::First_AbstractFunctionDecl && @@ -7758,7 +7757,7 @@ public: /// Returns the last index of the parameter that looks like a completion /// handler if \p asyncAlternative is not set (with the same conditions on /// its type as above). - llvm::Optional findPotentialCompletionHandlerParam( + std::optional findPotentialCompletionHandlerParam( const AbstractFunctionDecl *asyncAlternative = nullptr) const; using DeclContext::operator new; @@ -7824,18 +7823,18 @@ private: DeclContext *Parent, ClangNode ClangN); - llvm::Optional getCachedSelfAccessKind() const { + std::optional getCachedSelfAccessKind() const { if (Bits.FuncDecl.SelfAccessComputed) return static_cast(Bits.FuncDecl.SelfAccess); - return llvm::None; + return std::nullopt; } - llvm::Optional getCachedIsStatic() const { + std::optional getCachedIsStatic() const { if (Bits.FuncDecl.IsStaticComputed) return Bits.FuncDecl.IsStatic; - return llvm::None; + return std::nullopt; } public: @@ -8029,10 +8028,10 @@ class AccessorDecl final : public FuncDecl { bool async, SourceLoc asyncLoc, bool throws, SourceLoc throwsLoc, TypeLoc thrownTy, DeclContext *parent, ClangNode clangNode); - llvm::Optional getCachedIsTransparent() const { + std::optional getCachedIsTransparent() const { if (Bits.AccessorDecl.IsTransparentComputed) return Bits.AccessorDecl.IsTransparent; - return llvm::None; + return std::nullopt; } friend class IsAccessorTransparentRequest; @@ -9158,7 +9157,7 @@ public: /// Retrieve the builtin macro kind for this macro, or \c None if it is a /// user-defined macro with no special semantics. - llvm::Optional getBuiltinKind() const; + std::optional getBuiltinKind() const; static bool classof(const DeclContext *C) { if (auto D = C->getAsDecl()) @@ -9214,7 +9213,7 @@ GenericParameterReferenceInfo findGenericParameterReferences(const ValueDecl *value, CanGenericSignature sig, GenericTypeParamType *genericParam, bool treatNonResultCovarianceAsInvariant, - llvm::Optional skipParamIndex); + std::optional skipParamIndex); inline bool AbstractStorageDecl::isSettable(const DeclContext *UseDC, const DeclRefExpr *base) const { diff --git a/include/swift/AST/DeclContext.h b/include/swift/AST/DeclContext.h index 51ca997e9ad..a6b55b8bf67 100644 --- a/include/swift/AST/DeclContext.h +++ b/include/swift/AST/DeclContext.h @@ -29,11 +29,11 @@ #include "swift/Basic/LLVM.h" #include "swift/Basic/STLExtras.h" #include "swift/Basic/SourceLoc.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/PointerEmbeddedInt.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/PointerUnion.h" #include "llvm/Support/raw_ostream.h" +#include #include @@ -949,7 +949,7 @@ public: /// Return a hash of all tokens in the body for dependency analysis, if /// available. - llvm::Optional getBodyFingerprint() const; + std::optional getBodyFingerprint() const; private: /// Add a member to the list for iteration purposes, but do not notify the diff --git a/include/swift/AST/DiagnosticConsumer.h b/include/swift/AST/DiagnosticConsumer.h index 1d8a61e2694..ec4e48b9a3d 100644 --- a/include/swift/AST/DiagnosticConsumer.h +++ b/include/swift/AST/DiagnosticConsumer.h @@ -21,9 +21,8 @@ #include "swift/Basic/LLVM.h" #include "swift/Basic/SourceLoc.h" -#include "llvm/ADT/None.h" -#include "llvm/ADT/Optional.h" #include "llvm/Support/SourceMgr.h" +#include namespace swift { class DiagnosticArgument; @@ -299,7 +298,7 @@ private: /// /// If None, Note diagnostics are sent to every consumer. /// If null, diagnostics are suppressed. - llvm::Optional SubconsumerForSubsequentNotes = llvm::None; + std::optional SubconsumerForSubsequentNotes = std::nullopt; bool HasAnErrorBeenConsumed = false; @@ -327,13 +326,13 @@ private: /// Returns nullptr if diagnostic is to be suppressed, /// None if diagnostic is to be distributed to every consumer, /// a particular consumer if diagnostic goes there. - llvm::Optional + std::optional subconsumerForLocation(SourceManager &SM, SourceLoc loc); - llvm::Optional + std::optional findSubconsumer(SourceManager &SM, const DiagnosticInfo &Info); - llvm::Optional + std::optional findSubconsumerForNonNote(SourceManager &SM, const DiagnosticInfo &Info); }; diff --git a/include/swift/AST/DiagnosticEngine.h b/include/swift/AST/DiagnosticEngine.h index a58c4a188f7..6151f0dc8f4 100644 --- a/include/swift/AST/DiagnosticEngine.h +++ b/include/swift/AST/DiagnosticEngine.h @@ -596,8 +596,8 @@ namespace swift { /// Conditionally limit the diagnostic behavior if the given \c limit /// is not \c None. - InFlightDiagnostic &limitBehaviorIf( - llvm::Optional limit) { + InFlightDiagnostic & + limitBehaviorIf(std::optional limit) { if (!limit) { return *this; } @@ -883,7 +883,7 @@ namespace swift { DiagnosticState state; /// The currently active diagnostic, if there is one. - llvm::Optional ActiveDiagnostic; + std::optional ActiveDiagnostic; /// Diagnostics wrapped by ActiveDiagnostic, if any. SmallVector WrappedDiagnostics; @@ -1233,7 +1233,7 @@ namespace swift { Diagnostic &getActiveDiagnostic() { return *ActiveDiagnostic; } /// Generate DiagnosticInfo for a Diagnostic to be passed to consumers. - llvm::Optional + std::optional diagnosticInfoForDiagnostic(const Diagnostic &diagnostic); /// Send \c diag to all diagnostic consumers. diff --git a/include/swift/AST/Expr.h b/include/swift/AST/Expr.h index bdef4b0034a..876919e1825 100644 --- a/include/swift/AST/Expr.h +++ b/include/swift/AST/Expr.h @@ -32,9 +32,8 @@ #include "swift/AST/TypeAlignments.h" #include "swift/Basic/Debug.h" #include "swift/Basic/InlineBitfield.h" -#include "llvm/ADT/None.h" -#include "llvm/ADT/Optional.h" #include "llvm/Support/TrailingObjects.h" +#include #include namespace llvm { @@ -1211,9 +1210,9 @@ public: /// Determine whether this reference needs to happen asynchronously, i.e., /// guarded by hop_to_executor, and if so describe the target. - llvm::Optional isImplicitlyAsync() const { + std::optional isImplicitlyAsync() const { if (!Bits.DeclRefExpr.IsImplicitlyAsync) - return llvm::None; + return std::nullopt; return implicitActorHopTarget; } @@ -1607,9 +1606,9 @@ public: /// Determine whether this reference needs to happen asynchronously, i.e., /// guarded by hop_to_executor, and if so describe the target. - llvm::Optional isImplicitlyAsync() const { + std::optional isImplicitlyAsync() const { if (!Bits.LookupExpr.IsImplicitlyAsync) - return llvm::None; + return std::nullopt; return implicitActorHopTarget; } @@ -3939,12 +3938,12 @@ public: /// Return whether this closure is throwing when fully applied. bool isBodyThrowing() const; - /// Retrieve the "effective" thrown interface type, or llvm::None if + /// Retrieve the "effective" thrown interface type, or std::nullopt if /// this closure cannot throw. /// /// Closures with untyped throws will produce "any Error", functions that - /// cannot throw or are specified to throw "Never" will return llvm::None. - llvm::Optional getEffectiveThrownType() const; + /// cannot throw or are specified to throw "Never" will return std::nullopt. + std::optional getEffectiveThrownType() const; /// \brief Return whether this closure is async when fully applied. bool isBodyAsync() const; @@ -4680,7 +4679,7 @@ class ApplyExpr : public Expr { // If this apply crosses isolation boundaries, record the callee and caller // isolations in this struct. - llvm::Optional IsolationCrossing; + std::optional IsolationCrossing; /// Destination information for a thrown error, which includes any /// necessary conversions from the actual type thrown to the type that @@ -4741,7 +4740,7 @@ public: // Return the optionally stored ApplyIsolationCrossing instance - set iff this // ApplyExpr crosses isolation domains - const llvm::Optional getIsolationCrossing() const { + const std::optional getIsolationCrossing() const { return IsolationCrossing; } @@ -4773,9 +4772,9 @@ public: /// /// When the application is implicitly async, the result describes /// the actor to which we need to need to hop. - llvm::Optional isImplicitlyAsync() const { + std::optional isImplicitlyAsync() const { if (!Bits.ApplyExpr.ImplicitlyAsync) - return llvm::None; + return std::nullopt; auto isolationCrossing = getIsolationCrossing(); assert(isolationCrossing.has_value() @@ -6064,7 +6063,7 @@ public: /// If the provided expression appears as an argument to a subscript component /// of the key path, returns the index of that component. Otherwise, returns /// \c None. - llvm::Optional findComponentWithSubscriptArg(Expr *arg); + std::optional findComponentWithSubscriptArg(Expr *arg); /// Retrieve the string literal expression, which will be \c NULL prior to /// type checking and a string literal after type checking for an diff --git a/include/swift/AST/ExtInfo.h b/include/swift/AST/ExtInfo.h index b60b701e110..b6d64067b22 100644 --- a/include/swift/AST/ExtInfo.h +++ b/include/swift/AST/ExtInfo.h @@ -23,9 +23,8 @@ #include "swift/AST/AutoDiff.h" #include "swift/AST/LifetimeDependence.h" -#include "llvm/ADT/None.h" -#include "llvm/ADT/Optional.h" #include "llvm/Support/raw_ostream.h" +#include #include @@ -185,7 +184,7 @@ struct UnexpectedClangTypeError { const Kind errorKind; const clang::Type *type; - static llvm::Optional + static std::optional checkClangType(SILFunctionTypeRepresentation fnRep, const clang::Type *type, bool expectNonnullForCOrBlock, bool expectCanonical); @@ -355,7 +354,7 @@ convertRepresentation(FunctionTypeRepresentation rep) { llvm_unreachable("Unhandled FunctionTypeRepresentation!"); } -inline llvm::Optional +inline std::optional convertRepresentation(SILFunctionTypeRepresentation rep) { switch (rep) { case SILFunctionTypeRepresentation::Thick: @@ -375,7 +374,7 @@ convertRepresentation(SILFunctionTypeRepresentation rep) { case SILFunctionTypeRepresentation::KeyPathAccessorSetter: case SILFunctionTypeRepresentation::KeyPathAccessorEquals: case SILFunctionTypeRepresentation::KeyPathAccessorHash: - return llvm::None; + return std::nullopt; } llvm_unreachable("Unhandled SILFunctionTypeRepresentation!"); } @@ -1342,7 +1341,7 @@ public: return builder.isEqualTo(other.builder, useClangTypes); } - llvm::Optional checkClangType() const; + std::optional checkClangType() const; }; /// Helper function to obtain the useClangTypes parameter for checking equality diff --git a/include/swift/AST/FileUnit.h b/include/swift/AST/FileUnit.h index 656a3dfa28b..448e255cead 100644 --- a/include/swift/AST/FileUnit.h +++ b/include/swift/AST/FileUnit.h @@ -136,9 +136,9 @@ public: return false; } - virtual llvm::Optional + virtual std::optional loadFingerprint(const IterableDeclContext *IDC) const { - return llvm::None; + return std::nullopt; } protected: @@ -165,34 +165,34 @@ public: /// This function is an implementation detail for comment serialization. /// If you just want to get a comment attached to a decl, use /// \c Decl::getRawComment() or \c Decl::getSemanticBriefComment(). - virtual llvm::Optional getCommentForDecl(const Decl *D) const { - return llvm::None; + virtual std::optional getCommentForDecl(const Decl *D) const { + return std::nullopt; } /// For a serialized AST file, returns \c true if an adjacent swiftdoc has been /// loaded. Otherwise, returns \c false. virtual bool hasLoadedSwiftDoc() const { return false; } - virtual llvm::Optional getGroupNameForDecl(const Decl *D) const { - return llvm::None; + virtual std::optional getGroupNameForDecl(const Decl *D) const { + return std::nullopt; } - virtual llvm::Optional + virtual std::optional getSourceFileNameForDecl(const Decl *D) const { - return llvm::None; + return std::nullopt; } - virtual llvm::Optional getSourceOrderForDecl(const Decl *D) const { - return llvm::None; + virtual std::optional getSourceOrderForDecl(const Decl *D) const { + return std::nullopt; } - virtual llvm::Optional getGroupNameByUSR(StringRef USR) const { - return llvm::None; + virtual std::optional getGroupNameByUSR(StringRef USR) const { + return std::nullopt; } - virtual llvm::Optional + virtual std::optional getExternalRawLocsForDecl(const Decl *D) const { - return llvm::None; + return std::nullopt; } virtual void collectAllGroups(SmallVectorImpl &Names) const {} diff --git a/include/swift/AST/FineGrainedDependencies.h b/include/swift/AST/FineGrainedDependencies.h index e49ceffe933..fd354427380 100644 --- a/include/swift/AST/FineGrainedDependencies.h +++ b/include/swift/AST/FineGrainedDependencies.h @@ -21,8 +21,6 @@ #include "swift/Basic/Range.h" #include "swift/Basic/ReferenceDependencyKeys.h" #include "llvm/ADT/Hashing.h" -#include "llvm/ADT/None.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/SetVector.h" #include "llvm/Support/MD5.h" #include "llvm/Support/MemoryBuffer.h" @@ -30,6 +28,7 @@ #include "llvm/Support/YAMLParser.h" #include "llvm/Support/YAMLTraits.h" #include "llvm/Support/raw_ostream.h" +#include #include #include #include @@ -106,11 +105,11 @@ template class Memoizer { public: Memoizer() = default; - llvm::Optional findExisting(KeyT key) { + std::optional findExisting(KeyT key) { auto iter = memos.find(key); if (iter != memos.end()) return iter->second; - return llvm::None; + return std::nullopt; } /// \p createFn must create a \ref ValueT that corresponds to the \ref KeyT @@ -151,13 +150,13 @@ private: Map map; public: - llvm::Optional find(const Key1 &k1, const Key2 &k2) const { + std::optional find(const Key1 &k1, const Key2 &k2) const { auto iter = map.find(k1); if (iter == map.end()) - return llvm::None; + return std::nullopt; auto iter2 = iter->second.find(k2); - return iter2 == iter->second.end() ? llvm::None - : llvm::Optional(iter2->second); + return iter2 == iter->second.end() ? std::nullopt + : std::optional(iter2->second); } NullablePtr find(const Key1 &k1) const { @@ -256,12 +255,12 @@ public: bool insert(const Key2 &k2, const Key1 &k1, Value &v) { return insert(k1, k2, v); } - llvm::Optional find(const Key1 &k1, const Key2 &k2) const { + std::optional find(const Key1 &k1, const Key2 &k2) const { auto v = map1.find(k1, k2); assert(assertConsistent(v, map2.find(k2, k1))); return v; } - llvm::Optional find(const Key2 &k2, Key1 &k1) const { + std::optional find(const Key2 &k2, Key1 &k1) const { return find(k1, k2); } @@ -603,7 +602,7 @@ struct std::hash { namespace swift { namespace fine_grained_dependencies { using ContextNameFingerprint = - std::tuple>; + std::tuple>; } } // namespace swift @@ -649,7 +648,7 @@ class DepGraphNode { /// frontend creates an interface node, // it adds a dependency to it from the implementation source file node (which // has the interfaceHash as its fingerprint). - llvm::Optional fingerprint; + std::optional fingerprint; friend ::llvm::yaml::MappingTraits; @@ -657,7 +656,7 @@ public: /// See \ref SourceFileDepGraphNode::SourceFileDepGraphNode(). DepGraphNode() : key(), fingerprint() {} - DepGraphNode(DependencyKey key, llvm::Optional fingerprint) + DepGraphNode(DependencyKey key, std::optional fingerprint) : key(key), fingerprint(fingerprint) {} DepGraphNode(const DepGraphNode &other) = default; @@ -673,7 +672,7 @@ public: this->key = key; } - const llvm::Optional getFingerprint() const { + const std::optional getFingerprint() const { return fingerprint; } /// When driver reads a SourceFileDepGraphNode, it may be a node that was @@ -684,7 +683,7 @@ public: /// (someday) have a fingerprint. In order to preserve the /// ModuleDepGraphNode's identity but bring its fingerprint up to date, it /// needs to set the fingerprint *after* the node has been created. - void setFingerprint(llvm::Optional fp) { fingerprint = fp; } + void setFingerprint(std::optional fp) { fingerprint = fp; } SWIFT_DEBUG_DUMP; void dump(llvm::raw_ostream &os) const; @@ -732,7 +731,7 @@ public: /// Used by the frontend to build nodes. SourceFileDepGraphNode(DependencyKey key, - llvm::Optional fingerprint, + std::optional fingerprint, bool isProvides) : DepGraphNode(key, fingerprint), isProvides(isProvides) { assert(key.verify()); @@ -867,14 +866,14 @@ public: InterfaceAndImplementationPair findExistingNodePairOrCreateAndAddIfNew( const DependencyKey &interfaceKey, - llvm::Optional fingerprint); + std::optional fingerprint); NullablePtr findExistingNode(const DependencyKey &key); SourceFileDepGraphNode * findExistingNodeOrCreateIfNew(const DependencyKey &key, - const llvm::Optional fingerprint, + const std::optional fingerprint, bool isProvides); /// \p Use is the Node that must be rebuilt when \p def changes. @@ -887,14 +886,13 @@ public: /// Read a swiftdeps file at \p path and return a SourceFileDepGraph if /// successful. If \p allowSwiftModule is true, try to load the information /// from a swiftmodule file if appropriate. - llvm::Optional static loadFromPath( + std::optional static loadFromPath( StringRef, bool allowSwiftModule = false); /// Read a swiftdeps file from \p buffer and return a SourceFileDepGraph if /// successful. - llvm::Optional static loadFromBuffer( - llvm::MemoryBuffer &); - llvm::Optional static loadFromSwiftModuleBuffer( + std::optional static loadFromBuffer(llvm::MemoryBuffer &); + std::optional static loadFromSwiftModuleBuffer( llvm::MemoryBuffer &); void verifySame(const SourceFileDepGraph &other) const; diff --git a/include/swift/AST/ForeignAsyncConvention.h b/include/swift/AST/ForeignAsyncConvention.h index 89d1a88d4cb..6f2bef5413c 100644 --- a/include/swift/AST/ForeignAsyncConvention.h +++ b/include/swift/AST/ForeignAsyncConvention.h @@ -45,8 +45,8 @@ public: CompletionHandlerErrorParamIndexPlusOneOrZero(0) { } Info(unsigned completionHandlerParamIndex, - llvm::Optional completionHandlerErrorParamIndex, - llvm::Optional completionHandlerFlagParamIndex, + std::optional completionHandlerErrorParamIndex, + std::optional completionHandlerFlagParamIndex, bool completionHandlerFlagIsErrorOnZero) : CompletionHandlerParamIndex(completionHandlerParamIndex), CompletionHandlerErrorParamIndexPlusOneOrZero( @@ -73,9 +73,9 @@ public: /// provided error will be thrown by the async function. If a /// \c completionHandlerFlagParamIndex is also specified, the /// value of that flag instead indicates whether an error should be raised. - llvm::Optional completionHandlerErrorParamIndex() const { + std::optional completionHandlerErrorParamIndex() const { if (CompletionHandlerErrorParamIndexPlusOneOrZero == 0) - return llvm::None; + return std::nullopt; return CompletionHandlerErrorParamIndexPlusOneOrZero - 1; } @@ -87,9 +87,9 @@ public: /// operation completed with an error. The \c completionHandlerFlagIsErrorOnZero /// value indicates whether this argument being zero indicates an error, or /// whether being nonzero indicates an error. - llvm::Optional completionHandlerFlagParamIndex() const { + std::optional completionHandlerFlagParamIndex() const { if (CompletionHandlerFlagParamIndexPlusOneWithPolarityOrZero == 0) - return llvm::None; + return std::nullopt; return (CompletionHandlerFlagParamIndexPlusOneWithPolarityOrZero - 1) & 0x7FFFFFFFu; @@ -128,8 +128,8 @@ public: ForeignAsyncConvention( CanType completionHandlerType, unsigned completionHandlerParamIndex, - llvm::Optional completionHandlerErrorParamIndex, - llvm::Optional completionHandlerFlagParamIndex, + std::optional completionHandlerErrorParamIndex, + std::optional completionHandlerFlagParamIndex, bool completionHandlerFlagIsErrorOnZero) : CompletionHandlerType(completionHandlerType), TheInfo(completionHandlerParamIndex, completionHandlerErrorParamIndex, @@ -152,7 +152,7 @@ public: /// provided error will be thrown by the async function. If a /// \c completionHandlerFlagParamIndex is also specified, the /// value of that flag instead indicates whether an error should be raised. - llvm::Optional completionHandlerErrorParamIndex() const { + std::optional completionHandlerErrorParamIndex() const { return TheInfo.completionHandlerErrorParamIndex(); } @@ -163,7 +163,7 @@ public: /// operation completed with an error. The \c completionHandlerFlagIsErrorOnZero /// value indicates whether this argument being zero indicates an error, or /// whether being nonzero indicates an error. - llvm::Optional completionHandlerFlagParamIndex() const { + std::optional completionHandlerFlagParamIndex() const { return TheInfo.completionHandlerFlagParamIndex(); } diff --git a/include/swift/AST/ForeignInfo.h b/include/swift/AST/ForeignInfo.h index 10cb80133fc..897d81be218 100644 --- a/include/swift/AST/ForeignInfo.h +++ b/include/swift/AST/ForeignInfo.h @@ -27,8 +27,8 @@ namespace swift { struct ForeignInfo { ImportAsMemberStatus self; - llvm::Optional error; - llvm::Optional async; + std::optional error; + std::optional async; }; } // end namespace swift diff --git a/include/swift/AST/GenericEnvironment.h b/include/swift/AST/GenericEnvironment.h index 810103630b4..46ba4dd7e4b 100644 --- a/include/swift/AST/GenericEnvironment.h +++ b/include/swift/AST/GenericEnvironment.h @@ -168,7 +168,7 @@ private: /// Retrieve the mapping for the given generic parameter, if present. /// /// This is only useful when lazily populating a generic environment. - llvm::Optional getMappingIfPresent(GenericParamKey key) const; + std::optional getMappingIfPresent(GenericParamKey key) const; public: GenericSignature getGenericSignature() const { diff --git a/include/swift/AST/IRGenOptions.h b/include/swift/AST/IRGenOptions.h index 89681ccc18d..f68d9e7cd1e 100644 --- a/include/swift/AST/IRGenOptions.h +++ b/include/swift/AST/IRGenOptions.h @@ -492,10 +492,10 @@ public: TypeInfoDumpFilter TypeInfoFilter; /// Pull in runtime compatibility shim libraries by autolinking. - llvm::Optional AutolinkRuntimeCompatibilityLibraryVersion; - llvm::Optional + std::optional AutolinkRuntimeCompatibilityLibraryVersion; + std::optional AutolinkRuntimeCompatibilityDynamicReplacementLibraryVersion; - llvm::Optional + std::optional AutolinkRuntimeCompatibilityConcurrencyLibraryVersion; bool AutolinkRuntimeCompatibilityBytecodeLayoutsLibrary; diff --git a/include/swift/AST/IRGenRequests.h b/include/swift/AST/IRGenRequests.h index 95d8ad0b383..a9819b27261 100644 --- a/include/swift/AST/IRGenRequests.h +++ b/include/swift/AST/IRGenRequests.h @@ -132,7 +132,7 @@ public: struct IRGenDescriptor { llvm::PointerUnion Ctx; - using SymsToEmit = llvm::Optional>; + using SymsToEmit = std::optional>; SymsToEmit SymbolsToEmit; const IRGenOptions &Opts; @@ -173,7 +173,7 @@ public: const TBDGenOptions &TBDOpts, const SILOptions &SILOpts, Lowering::TypeConverter &Conv, std::unique_ptr &&SILMod, StringRef ModuleName, const PrimarySpecificPaths &PSPs, - StringRef PrivateDiscriminator, SymsToEmit symsToEmit = llvm::None, + StringRef PrivateDiscriminator, SymsToEmit symsToEmit = std::nullopt, llvm::GlobalVariable **outModuleHash = nullptr) { return IRGenDescriptor{file, symsToEmit, @@ -193,7 +193,7 @@ public: ModuleDecl *M, const IRGenOptions &Opts, const TBDGenOptions &TBDOpts, const SILOptions &SILOpts, Lowering::TypeConverter &Conv, std::unique_ptr &&SILMod, StringRef ModuleName, - const PrimarySpecificPaths &PSPs, SymsToEmit symsToEmit = llvm::None, + const PrimarySpecificPaths &PSPs, SymsToEmit symsToEmit = std::nullopt, ArrayRef parallelOutputFilenames = {}, llvm::GlobalVariable **outModuleHash = nullptr) { return IRGenDescriptor{M, diff --git a/include/swift/AST/Identifier.h b/include/swift/AST/Identifier.h index 1d78bbd5558..5560cffaf21 100644 --- a/include/swift/AST/Identifier.h +++ b/include/swift/AST/Identifier.h @@ -846,7 +846,7 @@ public: /// This should not be used to parse selectors written directly in Swift /// source code (e.g. the argument of an @objc attribute). Use the /// parser for that. - static llvm::Optional parse(ASTContext &ctx, StringRef string); + static std::optional parse(ASTContext &ctx, StringRef string); /// Convert to true if the decl name is valid. explicit operator bool() const { return (bool)Storage; } diff --git a/include/swift/AST/Import.h b/include/swift/AST/Import.h index e274a7cf183..47228f692c2 100644 --- a/include/swift/AST/Import.h +++ b/include/swift/AST/Import.h @@ -25,14 +25,13 @@ #include "swift/Basic/OptionSet.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMapInfo.h" -#include "llvm/ADT/None.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/raw_ostream.h" #include +#include namespace swift { class ASTContext; @@ -584,7 +583,7 @@ struct AttributedImport { /// If the import declaration has a `@_documentation(visibility: )` /// attribute, this is the given access level. - llvm::Optional docVisibility; + std::optional docVisibility; /// Access level limiting how imported types can be exported. AccessLevel accessLevel; @@ -597,7 +596,7 @@ struct AttributedImport { ImportOptions options = ImportOptions(), StringRef filename = {}, ArrayRef spiGroups = {}, SourceRange preconcurrencyRange = {}, - llvm::Optional docVisibility = llvm::None, + std::optional docVisibility = std::nullopt, AccessLevel accessLevel = AccessLevel::Public, SourceRange accessLevelRange = SourceRange()) : module(module), importLoc(importLoc), options(options), @@ -772,20 +771,16 @@ struct DenseMapInfo> { // DenseMapInfo-able, but we do check that the spiGroups match in isEqual(). static inline AttributedImport getEmptyKey() { - return AttributedImport(ModuleInfoDMI::getEmptyKey(), - SourceLocDMI::getEmptyKey(), - ImportOptionsDMI::getEmptyKey(), - StringRefDMI::getEmptyKey(), - {}, {}, llvm::None, - swift::AccessLevel::Public, {}); + return AttributedImport( + ModuleInfoDMI::getEmptyKey(), SourceLocDMI::getEmptyKey(), + ImportOptionsDMI::getEmptyKey(), StringRefDMI::getEmptyKey(), {}, {}, + std::nullopt, swift::AccessLevel::Public, {}); } static inline AttributedImport getTombstoneKey() { - return AttributedImport(ModuleInfoDMI::getTombstoneKey(), - SourceLocDMI::getEmptyKey(), - ImportOptionsDMI::getTombstoneKey(), - StringRefDMI::getTombstoneKey(), - {}, {}, llvm::None, - swift::AccessLevel::Public, {}); + return AttributedImport( + ModuleInfoDMI::getTombstoneKey(), SourceLocDMI::getEmptyKey(), + ImportOptionsDMI::getTombstoneKey(), StringRefDMI::getTombstoneKey(), + {}, {}, std::nullopt, swift::AccessLevel::Public, {}); } static inline unsigned getHashValue(const AttributedImport &import) { return detail::combineHashValue( diff --git a/include/swift/AST/KnownProtocols.h b/include/swift/AST/KnownProtocols.h index e18c7c6745b..1df80bb218f 100644 --- a/include/swift/AST/KnownProtocols.h +++ b/include/swift/AST/KnownProtocols.h @@ -67,8 +67,8 @@ using InvertibleProtocolSet = FixedBitSet - getInvertibleProtocolKind(KnownProtocolKind kp); +std::optional +getInvertibleProtocolKind(KnownProtocolKind kp); /// Returns the KnownProtocolKind corresponding to an InvertibleProtocolKind. KnownProtocolKind getKnownProtocolKind(InvertibleProtocolKind ip); diff --git a/include/swift/AST/LifetimeDependence.h b/include/swift/AST/LifetimeDependence.h index c8c5a29fc90..d1789a1f34d 100644 --- a/include/swift/AST/LifetimeDependence.h +++ b/include/swift/AST/LifetimeDependence.h @@ -137,11 +137,11 @@ class LifetimeDependenceInfo { unsigned index, ValueOwnership ownership); - static llvm::Optional + static std::optional fromTypeRepr(AbstractFunctionDecl *afd, Type resultType, bool allowIndex); - static llvm::Optional infer(AbstractFunctionDecl *afd, - Type resultType); + static std::optional infer(AbstractFunctionDecl *afd, + Type resultType); public: LifetimeDependenceInfo() @@ -183,7 +183,7 @@ public: std::optional getLifetimeDependenceOnParam(unsigned paramIndex); - static llvm::Optional + static std::optional get(AbstractFunctionDecl *decl, Type resultType, bool allowIndex = false); static LifetimeDependenceInfo diff --git a/include/swift/AST/Module.h b/include/swift/AST/Module.h index e1a7e9a0387..8dccdf6c447 100644 --- a/include/swift/AST/Module.h +++ b/include/swift/AST/Module.h @@ -31,13 +31,13 @@ #include "swift/Basic/STLExtras.h" #include "swift/Basic/SourceLoc.h" #include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MD5.h" +#include #include namespace clang { @@ -533,7 +533,7 @@ private: /// A cache of this module's underlying module and required bystander if it's /// an underscored cross-import overlay. - llvm::Optional> + std::optional> declaringModuleAndBystander; /// If this module is an underscored cross import overlay, gets the underlying @@ -1095,7 +1095,7 @@ public: /// /// \returns true if there was a problem adding this file. bool registerEntryPointFile(FileUnit *file, SourceLoc diagLoc, - llvm::Optional kind); + std::optional kind); /// \returns true if this module has a main entry point. bool hasEntryPoint() const { diff --git a/include/swift/AST/ModuleDependencies.h b/include/swift/AST/ModuleDependencies.h index 6a6d0dd9257..0ebf7f6d59d 100644 --- a/include/swift/AST/ModuleDependencies.h +++ b/include/swift/AST/ModuleDependencies.h @@ -26,10 +26,9 @@ #include "clang/Tooling/DependencyScanning/DependencyScanningTool.h" #include "clang/Tooling/DependencyScanning/ModuleDepCollector.h" #include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/IntrusiveRefCntPtr.h" -#include "llvm/ADT/Optional.h" -#include "llvm/ADT/StringSet.h" #include "llvm/ADT/DenseSet.h" +#include "llvm/ADT/IntrusiveRefCntPtr.h" +#include "llvm/ADT/StringSet.h" #include "llvm/CAS/CASProvidingFileSystem.h" #include "llvm/CAS/CASReference.h" #include "llvm/CAS/CachingOnDiskFileSystem.h" @@ -38,6 +37,7 @@ #include "llvm/Support/Mutex.h" #include "llvm/Support/PrefixMapper.h" #include "llvm/Support/VirtualFileSystem.h" +#include #include #include #include @@ -193,7 +193,7 @@ struct CommonSwiftTextualModuleDependencyDetails { const std::vector extraPCMArgs; /// Bridging header file, if there is one. - llvm::Optional bridgingHeaderFile; + std::optional bridgingHeaderFile; /// Source files on which the bridging header depends. std::vector bridgingSourceFiles; @@ -727,16 +727,16 @@ public: void addModuleDependency(ModuleDependencyID dependencyID); /// Get the bridging header. - llvm::Optional getBridgingHeader() const; + std::optional getBridgingHeader() const; /// Get CAS Filesystem RootID. - llvm::Optional getCASFSRootID() const; + std::optional getCASFSRootID() const; /// Get Clang Include Tree ID. - llvm::Optional getClangIncludeTree() const; + std::optional getClangIncludeTree() const; /// Get bridging header Include Tree ID. - llvm::Optional getBridgingHeaderIncludeTree() const; + std::optional getBridgingHeaderIncludeTree() const; /// Get module output path. std::string getModuleOutputPath() const; @@ -812,10 +812,10 @@ class SwiftDependencyScanningService { }; /// The CASOption created the Scanning Service if used. - llvm::Optional CASOpts; + std::optional CASOpts; /// The persistent Clang dependency scanner service - llvm::Optional + std::optional ClangScanningService; /// CachingOnDiskFileSystem for dependency tracking. @@ -834,7 +834,7 @@ class SwiftDependencyScanningService { std::unique_ptr Mapper; /// The global file system cache. - llvm::Optional< + std::optional< clang::tooling::dependencies::DependencyScanningFilesystemSharedCache> SharedFilesystemCache; @@ -887,9 +887,9 @@ public: return *CacheFS; } - llvm::Optional createSwiftDependencyTracker() { + std::optional createSwiftDependencyTracker() { if (!CacheFS) - return llvm::None; + return std::nullopt; return SwiftDependencyTracker(*CacheFS, Mapper.get()); } @@ -938,7 +938,7 @@ private: /// Whether we have cached dependency information for the given module. bool hasDependency(StringRef moduleName, - llvm::Optional kind, + std::optional kind, StringRef scanContextHash) const; /// Return a pointer to the cache state of the specified context hash. @@ -948,9 +948,8 @@ private: /// Look for module dependencies for a module with the given name /// /// \returns the cached result, or \c None if there is no cached entry. - llvm::Optional - findDependency(StringRef moduleName, - llvm::Optional kind, + std::optional + findDependency(StringRef moduleName, std::optional kind, StringRef scanContextHash) const; /// Record dependencies for the given module. @@ -1012,7 +1011,7 @@ public: bool hasDependency(const ModuleDependencyID &moduleID) const; /// Whether we have cached dependency information for the given module. bool hasDependency(StringRef moduleName, - llvm::Optional kind) const; + std::optional kind) const; /// Whether we have cached dependency information for the given module Name. bool hasDependency(StringRef moduleName) const; @@ -1047,20 +1046,20 @@ public: /// Look for module dependencies for a module with the given ID /// /// \returns the cached result, or \c None if there is no cached entry. - llvm::Optional + std::optional findDependency(const ModuleDependencyID moduleID) const; /// Look for module dependencies for a module with the given name /// /// \returns the cached result, or \c None if there is no cached entry. - llvm::Optional + std::optional findDependency(StringRef moduleName, - llvm::Optional kind) const; + std::optional kind) const; /// Look for module dependencies for a module with the given name /// /// \returns the cached result, or \c None if there is no cached entry. - llvm::Optional + std::optional findDependency(StringRef moduleName) const; /// Record dependencies for the given module. diff --git a/include/swift/AST/ModuleLoader.h b/include/swift/AST/ModuleLoader.h index 21a00b8a85f..1e4f234abeb 100644 --- a/include/swift/AST/ModuleLoader.h +++ b/include/swift/AST/ModuleLoader.h @@ -25,12 +25,12 @@ #include "swift/Basic/Located.h" #include "swift/Basic/SourceLoc.h" #include "clang/Basic/FileManager.h" -#include "llvm/ADT/Optional.h" +#include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/ADT/SetVector.h" #include "llvm/ADT/StringSet.h" #include "llvm/ADT/TinyPtrVector.h" -#include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/Support/VersionTuple.h" +#include #include namespace llvm { @@ -257,7 +257,7 @@ public: /// Represents a module version and the source it was parsed from. class ModuleVersionInfo { llvm::VersionTuple Version; - llvm::Optional SourceKind; + std::optional SourceKind; public: /// Returns true if the version has a valid source kind. diff --git a/include/swift/AST/NameLookupRequests.h b/include/swift/AST/NameLookupRequests.h index db54835a392..cff92d750a6 100644 --- a/include/swift/AST/NameLookupRequests.h +++ b/include/swift/AST/NameLookupRequests.h @@ -168,7 +168,7 @@ public: // Caching bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(ClassDecl *value) const; }; @@ -189,7 +189,7 @@ private: public: // Caching bool isCached() const { return true; } - llvm::Optional> getCachedResult() const; + std::optional> getCachedResult() const; void cacheResult(ArrayRef value) const; public: @@ -214,7 +214,7 @@ private: public: // Caching bool isCached() const { return true; } - llvm::Optional> getCachedResult() const; + std::optional> getCachedResult() const; void cacheResult(ArrayRef value) const; }; @@ -237,7 +237,7 @@ private: public: // Caching bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(bool) const; }; @@ -259,7 +259,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(NominalTypeDecl *value) const; public: @@ -363,7 +363,7 @@ private: public: // Caching bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(DestructorDecl *value) const; }; @@ -384,7 +384,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(GenericParamList *value) const; }; diff --git a/include/swift/AST/PackConformance.h b/include/swift/AST/PackConformance.h index 62411d7094c..c8299337b12 100644 --- a/include/swift/AST/PackConformance.h +++ b/include/swift/AST/PackConformance.h @@ -82,13 +82,13 @@ public: /// The ProtocolConformanceRef either stores a pack conformance, or /// it is invalid in the case of substitution failure. ProtocolConformanceRef subst(SubstitutionMap subMap, - SubstOptions options = llvm::None) const; + SubstOptions options = std::nullopt) const; /// The ProtocolConformanceRef either stores a pack conformance, or /// it is invalid in the case of substitution failure. ProtocolConformanceRef subst(TypeSubstitutionFn subs, LookupConformanceFn conformances, - SubstOptions options = llvm::None) const; + SubstOptions options = std::nullopt) const; /// Apply an in-flight substitution to the conformances in this /// protocol conformance ref. diff --git a/include/swift/AST/ParameterList.h b/include/swift/AST/ParameterList.h index d189e86109a..344db0c3f04 100644 --- a/include/swift/AST/ParameterList.h +++ b/include/swift/AST/ParameterList.h @@ -130,7 +130,7 @@ public: /// Make a duplicate copy of this parameter list. This allocates copies of /// the ParamDecls, so they can be reparented into a new DeclContext. ParameterList *clone(const ASTContext &C, - OptionSet options = llvm::None) const; + OptionSet options = std::nullopt) const; /// Return a list of function parameters for this parameter list, /// based on the interface types of the parameters in this list. diff --git a/include/swift/AST/ParseRequests.h b/include/swift/AST/ParseRequests.h index cd0eb13c7f6..ae35aa871c1 100644 --- a/include/swift/AST/ParseRequests.h +++ b/include/swift/AST/ParseRequests.h @@ -33,7 +33,7 @@ void reportEvaluatedRequest(UnifiedStatsReporter &stats, const Request &request); struct FingerprintAndMembers { - llvm::Optional fingerprint = llvm::None; + std::optional fingerprint = std::nullopt; ArrayRef members = {}; bool operator==(const FingerprintAndMembers &x) const { return fingerprint == x.fingerprint && members == x.members; @@ -81,14 +81,14 @@ private: public: // Caching bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(BodyAndFingerprint value) const; }; struct SourceFileParsingResult { ArrayRef TopLevelItems; - llvm::Optional> CollectedTokens; - llvm::Optional InterfaceHasher; + std::optional> CollectedTokens; + std::optional InterfaceHasher; }; /// Parse the top-level items of a SourceFile. @@ -108,7 +108,7 @@ private: public: // Caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(SourceFileParsingResult result) const; public: diff --git a/include/swift/AST/PlatformKind.h b/include/swift/AST/PlatformKind.h index 6b1973e96e4..75c998f5249 100644 --- a/include/swift/AST/PlatformKind.h +++ b/include/swift/AST/PlatformKind.h @@ -19,9 +19,9 @@ #include "swift/Basic/LLVM.h" #include "swift/Config.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/VersionTuple.h" +#include namespace swift { @@ -40,12 +40,12 @@ StringRef platformString(PlatformKind platform); /// Returns the platform kind corresponding to the passed-in short platform name /// or None if such a platform kind does not exist. -llvm::Optional platformFromString(StringRef Name); +std::optional platformFromString(StringRef Name); /// Returns a valid platform string that is closest to the candidate string /// based on edit distance. Returns \c None if the closest valid platform /// distance is not within a minimum threshold. -llvm::Optional closestCorrectedPlatformString(StringRef candidate); +std::optional closestCorrectedPlatformString(StringRef candidate); /// Returns a human-readable version of the platform name as a string, suitable /// for emission in diagnostics (e.g., "macOS"). @@ -54,7 +54,7 @@ StringRef prettyPlatformString(PlatformKind platform); /// Returns the base platform for an application-extension platform. For example /// `iOS` would be returned for `iOSApplicationExtension`. Returns `None` for /// platforms which are not application extension platforms. -llvm::Optional +std::optional basePlatformForExtensionPlatform(PlatformKind Platform); /// Returns true if \p Platform represents and application extension platform, diff --git a/include/swift/AST/PluginLoader.h b/include/swift/AST/PluginLoader.h index a12128f581a..f35d5adea7f 100644 --- a/include/swift/AST/PluginLoader.h +++ b/include/swift/AST/PluginLoader.h @@ -15,9 +15,9 @@ #include "swift/AST/ModuleLoader.h" #include "swift/AST/PluginRegistry.h" #include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" +#include namespace swift { @@ -47,7 +47,7 @@ private: const bool disableSandbox; /// Map a module name to an plugin entry that provides the module. - llvm::Optional> PluginMap; + std::optional> PluginMap; /// Get or lazily create and populate 'PluginMap'. llvm::DenseMap &getPluginMap(); diff --git a/include/swift/AST/PrettyStackTrace.h b/include/swift/AST/PrettyStackTrace.h index c1830125b71..d5b80070e2a 100644 --- a/include/swift/AST/PrettyStackTrace.h +++ b/include/swift/AST/PrettyStackTrace.h @@ -23,9 +23,8 @@ #include "swift/AST/Identifier.h" #include "swift/AST/Type.h" #include "swift/Basic/SourceLoc.h" -#include "llvm/ADT/None.h" -#include "llvm/ADT/Optional.h" #include "llvm/Support/PrettyStackTrace.h" +#include namespace clang { class Type; @@ -214,15 +213,15 @@ void printConformanceDescription(llvm::raw_ostream &out, class PrettyStackTraceGenericSignature : public llvm::PrettyStackTraceEntry { const char *Action; GenericSignature GenericSig; - llvm::Optional Requirement; + std::optional Requirement; public: PrettyStackTraceGenericSignature( const char *action, GenericSignature genericSig, - llvm::Optional requirement = llvm::None) + std::optional requirement = std::nullopt) : Action(action), GenericSig(genericSig), Requirement(requirement) {} - void setRequirement(llvm::Optional requirement) { + void setRequirement(std::optional requirement) { Requirement = requirement; } diff --git a/include/swift/AST/PrintOptions.h b/include/swift/AST/PrintOptions.h index 9d52b34ad2b..93839d865fa 100644 --- a/include/swift/AST/PrintOptions.h +++ b/include/swift/AST/PrintOptions.h @@ -13,14 +13,14 @@ #ifndef SWIFT_AST_PRINTOPTIONS_H #define SWIFT_AST_PRINTOPTIONS_H -#include "swift/Basic/STLExtras.h" #include "swift/AST/AttrKind.h" #include "swift/AST/Identifier.h" #include "swift/AST/TypeOrExtensionDecl.h" -#include "llvm/ADT/Optional.h" +#include "swift/Basic/STLExtras.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallSet.h" #include +#include #include namespace swift { @@ -98,12 +98,12 @@ public: AnyAttrKind() : kind(NumTypeAttrKinds), isType(1) {} /// Returns the TypeAttrKind. - llvm::Optional type() const { + std::optional type() const { if (!isType || kind == NumTypeAttrKinds) return {}; return static_cast(kind); } /// Returns the DeclAttrKind. - llvm::Optional decl() const { + std::optional decl() const { if (isType || kind == NumDeclAttrKinds) return {}; return static_cast(kind); @@ -536,7 +536,7 @@ struct PrintOptions { ModuleDecl *CurrentModule = nullptr; /// The information for converting archetypes to specialized types. - llvm::Optional TransformContext; + std::optional TransformContext; /// Whether to display (Clang-)imported module names; bool QualifyImportedTypes = false; diff --git a/include/swift/AST/ProtocolConformance.h b/include/swift/AST/ProtocolConformance.h index 9516a483522..d92d0f38f85 100644 --- a/include/swift/AST/ProtocolConformance.h +++ b/include/swift/AST/ProtocolConformance.h @@ -240,13 +240,13 @@ public: /// Retrieve the type witness for the given associated type. Type getTypeWitness(AssociatedTypeDecl *assocType, - SubstOptions options = llvm::None) const; + SubstOptions options = std::nullopt) const; /// Retrieve the type witness and type decl (if one exists) /// for the given associated type. TypeWitnessAndDecl getTypeWitnessAndDecl(AssociatedTypeDecl *assocType, - SubstOptions options = llvm::None) const; + SubstOptions options = std::nullopt) const; /// Apply the given function object to each type witness within this /// protocol conformance. @@ -403,7 +403,7 @@ public: /// Get any additional requirements that are required for this conformance to /// be satisfied, if it is possible for them to be computed. - llvm::Optional> + std::optional> getConditionalRequirementsIfAvailable() const; /// Get any additional requirements that are required for this conformance to @@ -413,13 +413,13 @@ public: /// Substitute the conforming type and produce a ProtocolConformanceRef that /// applies to the substituted type. ProtocolConformanceRef subst(SubstitutionMap subMap, - SubstOptions options = llvm::None) const; + SubstOptions options = std::nullopt) const; /// Substitute the conforming type and produce a ProtocolConformanceRef that /// applies to the substituted type. ProtocolConformanceRef subst(TypeSubstitutionFn subs, LookupConformanceFn conformances, - SubstOptions options = llvm::None) const; + SubstOptions options = std::nullopt) const; /// Substitute the conforming type and produce a ProtocolConformanceRef that /// applies to the substituted type. @@ -545,7 +545,7 @@ class NormalProtocolConformance : public RootProtocolConformance, /// Conformances that satisfy each of conformance requirements of the /// requirement signature of the protocol. - MutableArrayRef> AssociatedConformances; + MutableArrayRef> AssociatedConformances; /// The lazy member loader provides callbacks for populating imported and /// deserialized conformances. @@ -592,7 +592,7 @@ public: /// to be satisfied. ArrayRef getConditionalRequirements() const; - llvm::Optional> + std::optional> getConditionalRequirementsIfAvailable() const; /// Retrieve the state of this conformance. @@ -698,7 +698,7 @@ public: /// for the given associated type. TypeWitnessAndDecl getTypeWitnessAndDecl(AssociatedTypeDecl *assocType, - SubstOptions options = llvm::None) const; + SubstOptions options = std::nullopt) const; TypeWitnessAndDecl getTypeWitnessUncached(AssociatedTypeDecl *requirement) const; @@ -722,7 +722,7 @@ public: ///protocol's requirement signature. void createAssociatedConformanceArray(); - llvm::Optional + std::optional getAssociatedConformance(unsigned index) const; void @@ -828,12 +828,12 @@ public: TypeWitnessAndDecl getTypeWitnessAndDecl(AssociatedTypeDecl *assocType, - SubstOptions options = llvm::None) const { + SubstOptions options = std::nullopt) const { llvm_unreachable("self-conformances never have associated types"); } Type getTypeWitness(AssociatedTypeDecl *assocType, - SubstOptions options = llvm::None) const { + SubstOptions options = std::nullopt) const { llvm_unreachable("self-conformances never have associated types"); } @@ -851,7 +851,7 @@ public: } Witness getWitness(ValueDecl *requirement) const; - llvm::Optional> + std::optional> getConditionalRequirementsIfAvailable() const { return ArrayRef(); } @@ -898,7 +898,7 @@ class SpecializedProtocolConformance : public ProtocolConformance, /// Any conditional requirements, in substituted form. (E.g. given Foo: Bar /// where T: Bar, Foo> will include Baz: Bar.) - mutable llvm::Optional> ConditionalRequirements; + mutable std::optional> ConditionalRequirements; friend class ASTContext; @@ -927,13 +927,13 @@ public: /// getConditionalRequirementsIfAvailable (these are separate because /// CONFORMANCE_SUBCLASS_DISPATCH does some type checks and a defaulted /// parameter gets in the way of that). - llvm::Optional> + std::optional> getConditionalRequirementsIfAvailableOrCached(bool computeIfPossible) const { if (computeIfPossible) computeConditionalRequirements(); return ConditionalRequirements; } - llvm::Optional> + std::optional> getConditionalRequirementsIfAvailable() const { return getConditionalRequirementsIfAvailableOrCached( /*computeIfPossible=*/true); @@ -975,7 +975,7 @@ public: /// for the given associated type. TypeWitnessAndDecl getTypeWitnessAndDecl(AssociatedTypeDecl *assocType, - SubstOptions options = llvm::None) const; + SubstOptions options = std::nullopt) const; /// Given that the requirement signature of the protocol directly states /// that the given dependent type must conform to the given protocol, @@ -1052,7 +1052,7 @@ public: } /// Get any requirements that must be satisfied for this conformance to apply. - llvm::Optional> + std::optional> getConditionalRequirementsIfAvailable() const { return InheritedConformance->getConditionalRequirementsIfAvailable(); } @@ -1092,7 +1092,7 @@ public: /// for the given associated type. TypeWitnessAndDecl getTypeWitnessAndDecl(AssociatedTypeDecl *assocType, - SubstOptions options = llvm::None) const { + SubstOptions options = std::nullopt) const { return InheritedConformance->getTypeWitnessAndDecl(assocType, options); } @@ -1171,7 +1171,7 @@ public: } /// Get any requirements that must be satisfied for this conformance to apply. - llvm::Optional> + std::optional> getConditionalRequirementsIfAvailable() const { return ArrayRef(); } @@ -1212,7 +1212,7 @@ public: /// for the given associated type. TypeWitnessAndDecl getTypeWitnessAndDecl(AssociatedTypeDecl *assocType, - SubstOptions options = llvm::None) const { + SubstOptions options = std::nullopt) const { llvm_unreachable("builtin-conformances never have associated types"); } diff --git a/include/swift/AST/ProtocolConformanceRef.h b/include/swift/AST/ProtocolConformanceRef.h index c94d37410f4..4b10050942c 100644 --- a/include/swift/AST/ProtocolConformanceRef.h +++ b/include/swift/AST/ProtocolConformanceRef.h @@ -21,9 +21,9 @@ #include "swift/AST/TypeAlignments.h" #include "swift/Basic/Debug.h" #include "llvm/ADT/Hashing.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/PointerUnion.h" #include "llvm/ADT/STLExtras.h" +#include namespace llvm { class raw_ostream; @@ -153,12 +153,12 @@ public: /// Apply a substitution to the conforming type. ProtocolConformanceRef subst(Type origType, SubstitutionMap subMap, - SubstOptions options = llvm::None) const; + SubstOptions options = std::nullopt) const; /// Apply a substitution to the conforming type. ProtocolConformanceRef subst(Type origType, TypeSubstitutionFn subs, LookupConformanceFn conformances, - SubstOptions options = llvm::None) const; + SubstOptions options = std::nullopt) const; /// Apply a substitution to the conforming type. /// diff --git a/include/swift/AST/Requirement.h b/include/swift/AST/Requirement.h index c61901b6ae9..a0c41ab9858 100644 --- a/include/swift/AST/Requirement.h +++ b/include/swift/AST/Requirement.h @@ -226,9 +226,10 @@ CheckRequirementsResult checkRequirements(ArrayRef requirements); /// Check if each requirement is satisfied after applying the given /// substitutions. The substitutions must replace all type parameters that /// appear in the requirement with concrete types or archetypes. -CheckRequirementsResult checkRequirements( - ModuleDecl *module, ArrayRef requirements, - TypeSubstitutionFn substitutions, SubstOptions options=llvm::None); +CheckRequirementsResult checkRequirements(ModuleDecl *module, + ArrayRef requirements, + TypeSubstitutionFn substitutions, + SubstOptions options = std::nullopt); /// A requirement as written in source, together with a source location. See /// ProtocolDecl::getStructuralRequirements(). diff --git a/include/swift/AST/RequirementMatch.h b/include/swift/AST/RequirementMatch.h index 59d712d0a8c..128fd746511 100644 --- a/include/swift/AST/RequirementMatch.h +++ b/include/swift/AST/RequirementMatch.h @@ -270,7 +270,7 @@ struct RequirementCheck { /// Describes a match between a requirement and a witness. struct RequirementMatch { RequirementMatch(ValueDecl *witness, MatchKind kind, - llvm::Optional env = llvm::None) + std::optional env = std::nullopt) : Witness(witness), Kind(kind), WitnessType(), ReqEnv(std::move(env)) { assert(!hasWitnessType() && "Should have witness type"); } @@ -278,13 +278,13 @@ struct RequirementMatch { RequirementMatch(ValueDecl *witness, MatchKind kind, const DeclAttribute *attr) : Witness(witness), Kind(kind), WitnessType(), UnmetAttribute(attr), - ReqEnv(llvm::None) { + ReqEnv(std::nullopt) { assert(!hasWitnessType() && "Should have witness type"); assert(hasUnmetAttribute() && "Should have unmet attribute"); } RequirementMatch(ValueDecl *witness, MatchKind kind, Type witnessType, - llvm::Optional env = llvm::None, + std::optional env = std::nullopt, ArrayRef optionalAdjustments = {}, GenericSignature derivativeGenSig = GenericSignature()) : Witness(witness), Kind(kind), WitnessType(witnessType), @@ -296,7 +296,7 @@ struct RequirementMatch { } RequirementMatch(ValueDecl *witness, MatchKind kind, Requirement requirement, - llvm::Optional env = llvm::None, + std::optional env = std::nullopt, ArrayRef optionalAdjustments = {}, GenericSignature derivativeGenSig = GenericSignature()) : Witness(witness), Kind(kind), WitnessType(requirement.getFirstType()), @@ -318,13 +318,13 @@ struct RequirementMatch { Type WitnessType; /// Requirement not met. - llvm::Optional MissingRequirement; + std::optional MissingRequirement; /// Unmet attribute from the requirement. const DeclAttribute *UnmetAttribute = nullptr; /// The requirement environment to use for the witness thunk. - llvm::Optional ReqEnv; + std::optional ReqEnv; /// The set of optional adjustments performed on the witness. SmallVector OptionalAdjustments; @@ -455,9 +455,10 @@ struct RequirementMatch { } swift::Witness getWitness(ASTContext &ctx) const { - return swift::Witness( - this->Witness, WitnessSubstitutions, ReqEnv->getWitnessThunkSignature(), - ReqEnv->getRequirementToWitnessThunkSubs(), DerivativeGenSig, llvm::None); + return swift::Witness(this->Witness, WitnessSubstitutions, + ReqEnv->getWitnessThunkSignature(), + ReqEnv->getRequirementToWitnessThunkSubs(), + DerivativeGenSig, std::nullopt); } }; diff --git a/include/swift/AST/SILGenRequests.h b/include/swift/AST/SILGenRequests.h index dcee0150f96..c6a6924182b 100644 --- a/include/swift/AST/SILGenRequests.h +++ b/include/swift/AST/SILGenRequests.h @@ -55,7 +55,7 @@ struct ASTLoweringDescriptor { /// A specific set of SILDeclRefs to emit. If set, only these refs will be /// emitted. Otherwise the entire \c context will be emitted. - llvm::Optional SourcesToEmit; + std::optional SourcesToEmit; friend llvm::hash_code hash_value(const ASTLoweringDescriptor &owner) { return llvm::hash_combine(owner.context, (void *)&owner.conv, @@ -76,7 +76,7 @@ struct ASTLoweringDescriptor { public: static ASTLoweringDescriptor forFile(FileUnit &sf, Lowering::TypeConverter &conv, const SILOptions &opts, - llvm::Optional SourcesToEmit = llvm::None, + std::optional SourcesToEmit = std::nullopt, const IRGenOptions *irgenOptions = nullptr) { return ASTLoweringDescriptor{&sf, conv, opts, irgenOptions, std::move(SourcesToEmit)}; @@ -85,7 +85,7 @@ public: static ASTLoweringDescriptor forWholeModule(ModuleDecl *mod, Lowering::TypeConverter &conv, const SILOptions &opts, - llvm::Optional SourcesToEmit = llvm::None, + std::optional SourcesToEmit = std::nullopt, const IRGenOptions *irgenOptions = nullptr) { return ASTLoweringDescriptor{mod, conv, opts, irgenOptions, std::move(SourcesToEmit)}; diff --git a/include/swift/AST/SearchPathOptions.h b/include/swift/AST/SearchPathOptions.h index 8da1773bee9..bdd6706fb07 100644 --- a/include/swift/AST/SearchPathOptions.h +++ b/include/swift/AST/SearchPathOptions.h @@ -19,10 +19,9 @@ #include "llvm/ADT/Hashing.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/ADT/StringMap.h" -#include "llvm/ADT/Optional.h" -#include "llvm/ADT/None.h" #include "llvm/Support/Error.h" #include "llvm/Support/VirtualFileSystem.h" +#include #include #include @@ -364,10 +363,10 @@ private: FrameworkSearchPaths.size() - 1); } - llvm::Optional WinSDKRoot = llvm::None; - llvm::Optional WinSDKVersion = llvm::None; - llvm::Optional VCToolsRoot = llvm::None; - llvm::Optional VCToolsVersion = llvm::None; + std::optional WinSDKRoot = std::nullopt; + std::optional WinSDKVersion = std::nullopt; + std::optional VCToolsRoot = std::nullopt; + std::optional VCToolsVersion = std::nullopt; public: StringRef getSDKPath() const { return SDKPath; } @@ -387,22 +386,22 @@ public: Lookup.searchPathsDidChange(); } - llvm::Optional getWinSDKRoot() const { return WinSDKRoot; } + std::optional getWinSDKRoot() const { return WinSDKRoot; } void setWinSDKRoot(StringRef root) { WinSDKRoot = root; } - llvm::Optional getWinSDKVersion() const { return WinSDKVersion; } + std::optional getWinSDKVersion() const { return WinSDKVersion; } void setWinSDKVersion(StringRef version) { WinSDKVersion = version; } - llvm::Optional getVCToolsRoot() const { return VCToolsRoot; } + std::optional getVCToolsRoot() const { return VCToolsRoot; } void setVCToolsRoot(StringRef root) { VCToolsRoot = root; } - llvm::Optional getVCToolsVersion() const { return VCToolsVersion; } + std::optional getVCToolsVersion() const { return VCToolsVersion; } void setVCToolsVersion(StringRef version) { VCToolsVersion = version; } diff --git a/include/swift/AST/SourceFile.h b/include/swift/AST/SourceFile.h index 4d95bf7315f..16777eb405a 100644 --- a/include/swift/AST/SourceFile.h +++ b/include/swift/AST/SourceFile.h @@ -46,7 +46,7 @@ enum class RestrictedImportKind { }; /// Import that limits the access level of imported entities. -using ImportAccessLevel = llvm::Optional>; +using ImportAccessLevel = std::optional>; /// Stores range information for a \c #if block in a SourceFile. class IfConfigRangeInfo final { @@ -142,7 +142,7 @@ private: /// This is the list of modules that are imported by this module. /// /// This is \c None until it is filled in by the import resolution phase. - llvm::Optional>> Imports; + std::optional>> Imports; /// The underlying clang module, if imported in this file. ModuleDecl *ImportedUnderlyingModule = nullptr; @@ -175,7 +175,7 @@ private: /// this source file. /// /// We only collect interface hash for primary input files. - llvm::Optional InterfaceHasher; + std::optional InterfaceHasher; /// The ID for the memory buffer containing this file's source. /// @@ -217,7 +217,7 @@ private: /// they have not yet been parsed. /// FIXME: Once addTopLevelDecl/prependTopLevelDecl /// have been removed, this can become an optional ArrayRef. - llvm::Optional> Items; + std::optional> Items; /// The list of hoisted declarations. See Decl::isHoisted(). /// This is only used by lldb. @@ -299,9 +299,9 @@ public: /// Retrieves an immutable view of the top-level items if they have already /// been parsed, or \c None if they haven't. Should only be used for dumping. - llvm::Optional> getCachedTopLevelItems() const { + std::optional> getCachedTopLevelItems() const { if (!Items) - return llvm::None; + return std::nullopt; return llvm::makeArrayRef(*Items); } @@ -388,7 +388,7 @@ public: /// \c #sourceLocation(file:) declarations. llvm::StringMap getInfoForUsedFilePaths() const; - SourceFile(ModuleDecl &M, SourceFileKind K, llvm::Optional bufferID, + SourceFile(ModuleDecl &M, SourceFileKind K, std::optional bufferID, ParsingOptions parsingOpts = {}, bool isPrimary = false); ~SourceFile(); @@ -565,16 +565,16 @@ public: Identifier getDiscriminatorForPrivateDecl(const Decl *D) const override; Identifier getPrivateDiscriminator(bool createIfMissing = false) const; - llvm::Optional + std::optional getExternalRawLocsForDecl(const Decl *D) const override; virtual bool walk(ASTWalker &walker) override; /// The buffer ID for the file that was imported, or None if there /// is no associated buffer. - llvm::Optional getBufferID() const { + std::optional getBufferID() const { if (BufferID == -1) - return llvm::None; + return std::nullopt; return BufferID; } @@ -608,7 +608,7 @@ public: /// /// \Returns the fulfilled macro role, or \c None if this source file is not /// for a macro expansion. - llvm::Optional getFulfilledMacroRole() const; + std::optional getFulfilledMacroRole() const; /// When this source file is enclosed within another source file, for example /// because it describes a macro expansion, return the source file it was @@ -787,7 +787,7 @@ private: /// If not \c None, the underlying vector contains the parsed tokens of this /// source file. - llvm::Optional> AllCollectedTokens; + std::optional> AllCollectedTokens; }; inline SourceFile::ParsingOptions operator|(SourceFile::ParsingFlags lhs, diff --git a/include/swift/AST/Stmt.h b/include/swift/AST/Stmt.h index 20f5bfd1bdc..b5275bde04f 100644 --- a/include/swift/AST/Stmt.h +++ b/include/swift/AST/Stmt.h @@ -23,14 +23,13 @@ #include "swift/AST/AvailabilitySpec.h" #include "swift/AST/ConcreteDeclRef.h" #include "swift/AST/IfConfigClause.h" +#include "swift/AST/ThrownErrorDestination.h" #include "swift/AST/TypeAlignments.h" #include "swift/AST/TypeLoc.h" -#include "swift/AST/ThrownErrorDestination.h" #include "swift/Basic/Debug.h" #include "swift/Basic/NullablePtr.h" -#include "llvm/ADT/None.h" -#include "llvm/ADT/Optional.h" #include "llvm/Support/TrailingObjects.h" +#include namespace swift { @@ -116,7 +115,7 @@ protected: /// Return the given value for the 'implicit' flag if present, or if None, /// return true if the location is invalid. - static bool getDefaultImplicitFlag(llvm::Optional implicit, + static bool getDefaultImplicitFlag(std::optional implicit, SourceLoc keyLoc) { return implicit.has_value() ? *implicit : keyLoc.isInvalid(); } @@ -176,12 +175,12 @@ class BraceStmt final : public Stmt, SourceLoc RBLoc; BraceStmt(SourceLoc lbloc, ArrayRef elements, SourceLoc rbloc, - llvm::Optional implicit); + std::optional implicit); public: static BraceStmt *create(ASTContext &ctx, SourceLoc lbloc, ArrayRef elements, SourceLoc rbloc, - llvm::Optional implicit = llvm::None); + std::optional implicit = std::nullopt); static BraceStmt *createImplicit(ASTContext &ctx, ArrayRef elements) { @@ -310,7 +309,7 @@ class YieldStmt final SourceLoc RPLoc; YieldStmt(SourceLoc yieldLoc, SourceLoc lpLoc, ArrayRef yields, - SourceLoc rpLoc, llvm::Optional implicit = llvm::None) + SourceLoc rpLoc, std::optional implicit = std::nullopt) : Stmt(StmtKind::Yield, getDefaultImplicitFlag(implicit, yieldLoc)), YieldLoc(yieldLoc), LPLoc(lpLoc), RPLoc(rpLoc) { Bits.YieldStmt.NumYields = yields.size(); @@ -321,7 +320,7 @@ class YieldStmt final public: static YieldStmt *create(const ASTContext &ctx, SourceLoc yieldLoc, SourceLoc lp, ArrayRef yields, SourceLoc rp, - llvm::Optional implicit = llvm::None); + std::optional implicit = std::nullopt); SourceLoc getYieldLoc() const { return YieldLoc; } SourceLoc getLParenLoc() const { return LPLoc; } @@ -777,7 +776,7 @@ class DoStmt : public LabeledStmt { public: DoStmt(LabeledStmtInfo labelInfo, SourceLoc doLoc, BraceStmt *body, - llvm::Optional implicit = llvm::None) + std::optional implicit = std::nullopt) : LabeledStmt(StmtKind::Do, getDefaultImplicitFlag(implicit, doLoc), labelInfo), DoLoc(doLoc), Body(body) {} @@ -842,7 +841,7 @@ class IfStmt : public LabeledConditionalStmt { public: IfStmt(LabeledStmtInfo LabelInfo, SourceLoc IfLoc, StmtCondition Cond, BraceStmt *Then, SourceLoc ElseLoc, Stmt *Else, - llvm::Optional implicit = llvm::None) + std::optional implicit = std::nullopt) : LabeledConditionalStmt(StmtKind::If, getDefaultImplicitFlag(implicit, IfLoc), LabelInfo, Cond), @@ -854,7 +853,7 @@ public: } IfStmt(SourceLoc IfLoc, Expr *Cond, BraceStmt *Then, SourceLoc ElseLoc, - Stmt *Else, llvm::Optional implicit, ASTContext &Ctx); + Stmt *Else, std::optional implicit, ASTContext &Ctx); SourceLoc getIfLoc() const { return IfLoc; } SourceLoc getElseLoc() const { return ElseLoc; } @@ -893,14 +892,14 @@ class GuardStmt : public LabeledConditionalStmt { public: GuardStmt(SourceLoc GuardLoc, StmtCondition Cond, BraceStmt *Body, - llvm::Optional implicit = llvm::None) + std::optional implicit = std::nullopt) : LabeledConditionalStmt(StmtKind::Guard, getDefaultImplicitFlag(implicit, GuardLoc), LabeledStmtInfo(), Cond), GuardLoc(GuardLoc), Body(Body) {} GuardStmt(SourceLoc GuardLoc, Expr *Cond, BraceStmt *Body, - llvm::Optional implicit, ASTContext &Ctx); + std::optional implicit, ASTContext &Ctx); SourceLoc getGuardLoc() const { return GuardLoc; } @@ -927,7 +926,7 @@ class WhileStmt : public LabeledConditionalStmt { public: WhileStmt(LabeledStmtInfo LabelInfo, SourceLoc WhileLoc, StmtCondition Cond, - Stmt *Body, llvm::Optional implicit = llvm::None) + Stmt *Body, std::optional implicit = std::nullopt) : LabeledConditionalStmt(StmtKind::While, getDefaultImplicitFlag(implicit, WhileLoc), LabelInfo, Cond), @@ -953,7 +952,7 @@ class RepeatWhileStmt : public LabeledStmt { public: RepeatWhileStmt(LabeledStmtInfo LabelInfo, SourceLoc RepeatLoc, Expr *Cond, SourceLoc WhileLoc, Stmt *Body, - llvm::Optional implicit = llvm::None) + std::optional implicit = std::nullopt) : LabeledStmt(StmtKind::RepeatWhile, getDefaultImplicitFlag(implicit, RepeatLoc), LabelInfo), RepeatLoc(RepeatLoc), WhileLoc(WhileLoc), Body(Body), Cond(Cond) {} @@ -1003,7 +1002,7 @@ public: ForEachStmt(LabeledStmtInfo LabelInfo, SourceLoc ForLoc, SourceLoc TryLoc, SourceLoc AwaitLoc, Pattern *Pat, SourceLoc InLoc, Expr *Sequence, SourceLoc WhereLoc, Expr *WhereExpr, BraceStmt *Body, - llvm::Optional implicit = llvm::None) + std::optional implicit = std::nullopt) : LabeledStmt(StmtKind::ForEach, getDefaultImplicitFlag(implicit, ForLoc), LabelInfo), ForLoc(ForLoc), TryLoc(TryLoc), AwaitLoc(AwaitLoc), Pat(nullptr), @@ -1157,7 +1156,7 @@ class FallthroughStmt : public Stmt { CaseStmt *FallthroughDest; public: - FallthroughStmt(SourceLoc Loc, llvm::Optional implicit = llvm::None) + FallthroughStmt(SourceLoc Loc, std::optional implicit = std::nullopt) : Stmt(StmtKind::Fallthrough, getDefaultImplicitFlag(implicit, Loc)), Loc(Loc), FallthroughSource(nullptr), FallthroughDest(nullptr) {} @@ -1219,13 +1218,13 @@ class CaseStmt final llvm::PointerIntPair BodyAndHasFallthrough; - llvm::Optional> CaseBodyVariables; + std::optional> CaseBodyVariables; CaseStmt(CaseParentKind ParentKind, SourceLoc ItemIntroducerLoc, ArrayRef CaseLabelItems, SourceLoc UnknownAttrLoc, SourceLoc ItemTerminatorLoc, BraceStmt *Body, - llvm::Optional> CaseBodyVariables, - llvm::Optional Implicit, + std::optional> CaseBodyVariables, + std::optional Implicit, NullablePtr fallthroughStmt); public: @@ -1245,8 +1244,8 @@ public: create(ASTContext &C, CaseParentKind ParentKind, SourceLoc ItemIntroducerLoc, ArrayRef CaseLabelItems, SourceLoc UnknownAttrLoc, SourceLoc ItemTerminatorLoc, BraceStmt *Body, - llvm::Optional> CaseBodyVariables, - llvm::Optional Implicit = llvm::None, + std::optional> CaseBodyVariables, + std::optional Implicit = std::nullopt, NullablePtr fallthroughStmt = nullptr); CaseParentKind getParentKind() const { return ParentKind; } @@ -1403,7 +1402,7 @@ class SwitchStmt final : public LabeledStmt, SwitchStmt(LabeledStmtInfo LabelInfo, SourceLoc SwitchLoc, Expr *SubjectExpr, SourceLoc LBraceLoc, unsigned CaseCount, SourceLoc RBraceLoc, - SourceLoc EndLoc, llvm::Optional implicit = llvm::None) + SourceLoc EndLoc, std::optional implicit = std::nullopt) : LabeledStmt(StmtKind::Switch, getDefaultImplicitFlag(implicit, SwitchLoc), LabelInfo), SwitchLoc(SwitchLoc), LBraceLoc(LBraceLoc), RBraceLoc(RBraceLoc), @@ -1453,10 +1452,10 @@ public: private: struct AsCaseStmtWithSkippingNonCaseStmts { AsCaseStmtWithSkippingNonCaseStmts() {} - llvm::Optional operator()(const ASTNode &N) const { + std::optional operator()(const ASTNode &N) const { if (auto *CS = llvm::dyn_cast_or_null(N.dyn_cast())) return CS; - return llvm::None; + return std::nullopt; } }; @@ -1497,9 +1496,9 @@ class DoCatchStmt final Stmt *Body; ThrownErrorDestination RethrowDest; - DoCatchStmt(DeclContext *dc,LabeledStmtInfo labelInfo, SourceLoc doLoc, + DoCatchStmt(DeclContext *dc, LabeledStmtInfo labelInfo, SourceLoc doLoc, SourceLoc throwsLoc, TypeLoc thrownType, Stmt *body, - ArrayRef catches, llvm::Optional implicit) + ArrayRef catches, std::optional implicit) : LabeledStmt(StmtKind::DoCatch, getDefaultImplicitFlag(implicit, doLoc), labelInfo), DC(dc), DoLoc(doLoc), ThrowsLoc(throwsLoc), ThrownType(thrownType), @@ -1512,13 +1511,11 @@ class DoCatchStmt final } public: - static DoCatchStmt *create(DeclContext *dc, - LabeledStmtInfo labelInfo, - SourceLoc doLoc, - SourceLoc throwsLoc, TypeLoc thrownType, - Stmt *body, + static DoCatchStmt *create(DeclContext *dc, LabeledStmtInfo labelInfo, + SourceLoc doLoc, SourceLoc throwsLoc, + TypeLoc thrownType, Stmt *body, ArrayRef catches, - llvm::Optional implicit = llvm::None); + std::optional implicit = std::nullopt); DeclContext *getDeclContext() const { return DC; } @@ -1587,7 +1584,7 @@ class BreakStmt : public Stmt { public: BreakStmt(SourceLoc Loc, Identifier TargetName, SourceLoc TargetLoc, - DeclContext *DC, llvm::Optional implicit = llvm::None) + DeclContext *DC, std::optional implicit = std::nullopt) : Stmt(StmtKind::Break, getDefaultImplicitFlag(implicit, Loc)), Loc(Loc), TargetName(TargetName), TargetLoc(TargetLoc), DC(DC) {} @@ -1622,7 +1619,7 @@ class ContinueStmt : public Stmt { public: ContinueStmt(SourceLoc Loc, Identifier TargetName, SourceLoc TargetLoc, - DeclContext *DC, llvm::Optional implicit = llvm::None) + DeclContext *DC, std::optional implicit = std::nullopt) : Stmt(StmtKind::Continue, getDefaultImplicitFlag(implicit, Loc)), Loc(Loc), TargetName(TargetName), TargetLoc(TargetLoc), DC(DC) {} @@ -1656,7 +1653,7 @@ class FailStmt : public Stmt { public: FailStmt(SourceLoc returnLoc, SourceLoc nilLoc, - llvm::Optional implicit = llvm::None) + std::optional implicit = std::nullopt) : Stmt(StmtKind::Fail, getDefaultImplicitFlag(implicit, returnLoc)), ReturnLoc(returnLoc), NilLoc(nilLoc) {} diff --git a/include/swift/AST/SubstitutionMap.h b/include/swift/AST/SubstitutionMap.h index c70e1cee9f5..5ede7fe11bc 100644 --- a/include/swift/AST/SubstitutionMap.h +++ b/include/swift/AST/SubstitutionMap.h @@ -24,7 +24,7 @@ #include "swift/Basic/Debug.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMapInfo.h" -#include "llvm/ADT/Optional.h" +#include namespace llvm { class FoldingSetNodeID; @@ -185,13 +185,13 @@ public: /// Apply a substitution to all replacement types in the map. Does not /// change keys. SubstitutionMap subst(SubstitutionMap subMap, - SubstOptions options = llvm::None) const; + SubstOptions options = std::nullopt) const; /// Apply a substitution to all replacement types in the map. Does not /// change keys. SubstitutionMap subst(TypeSubstitutionFn subs, LookupConformanceFn conformances, - SubstOptions options = llvm::None) const; + SubstOptions options = std::nullopt) const; /// Apply an in-flight substitution to all replacement types in the map. /// Does not change keys. diff --git a/include/swift/AST/SwiftNameTranslation.h b/include/swift/AST/SwiftNameTranslation.h index 12e533cd317..7c77ff71423 100644 --- a/include/swift/AST/SwiftNameTranslation.h +++ b/include/swift/AST/SwiftNameTranslation.h @@ -87,7 +87,7 @@ Diagnostic diagnoseRepresenationError(RepresentationError error, ValueDecl *vd); struct DeclRepresentation { RepresentationKind kind; - llvm::Optional error; + std::optional error; /// Returns true if the given Swift node is unsupported in Clang in any /// language mode. diff --git a/include/swift/AST/ThrownErrorDestination.h b/include/swift/AST/ThrownErrorDestination.h index f69c130d5ac..3d84af1d81c 100644 --- a/include/swift/AST/ThrownErrorDestination.h +++ b/include/swift/AST/ThrownErrorDestination.h @@ -17,10 +17,10 @@ #ifndef SWIFT_AST_THROWNERRORDESTINATION #define SWIFT_AST_THROWNERRORDESTINATION -#include "llvm/ADT/Optional.h" -#include "llvm/ADT/PointerUnion.h" #include "swift/AST/Type.h" #include "swift/AST/TypeAlignments.h" +#include "llvm/ADT/PointerUnion.h" +#include namespace swift { class Expr; @@ -73,12 +73,12 @@ public: /// Retrieve the conversion as a pair of (opaque thrown error value, /// conversion expression), when a conversion from the thrown error type /// to the context error type is required. - llvm::Optional> getConversion() const { + std::optional> getConversion() const { if (auto conversion = storage.dyn_cast()) { return std::make_pair(conversion->thrownError, conversion->conversion); } - return llvm::None; + return std::nullopt; } }; diff --git a/include/swift/AST/Type.h b/include/swift/AST/Type.h index 18720847855..8ea1b476763 100644 --- a/include/swift/AST/Type.h +++ b/include/swift/AST/Type.h @@ -31,9 +31,9 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseMapInfo.h" #include "llvm/ADT/Hashing.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/STLExtras.h" #include +#include #include namespace swift { @@ -172,7 +172,7 @@ struct SubstOptions : public OptionSet { /// conformance with the state \c CheckingTypeWitnesses. GetTentativeTypeWitness getTentativeTypeWitness; - SubstOptions(llvm::NoneType) : OptionSet(llvm::None) {} + SubstOptions(std::nullopt_t) : OptionSet(std::nullopt) {} SubstOptions(SubstFlags flags) : OptionSet(flags) { } @@ -297,7 +297,7 @@ public: /// /// \returns the result of transforming the type. Type - transformRec(llvm::function_ref(TypeBase *)> fn) const; + transformRec(llvm::function_ref(TypeBase *)> fn) const; /// Transform the given type by recursively applying the user-provided /// function to each node. @@ -314,7 +314,7 @@ public: /// \returns the result of transforming the type. Type transformWithPosition( TypePosition pos, - llvm::function_ref(TypeBase *, TypePosition)> fn) + llvm::function_ref(TypeBase *, TypePosition)> fn) const; /// Transform free pack element references, that is, those not captured by a @@ -322,8 +322,7 @@ public: /// /// This is the 'map' counterpart to TypeBase::getTypeParameterPacks(). Type transformTypeParameterPacks( - llvm::function_ref(SubstitutableType *)> fn) - const; + llvm::function_ref(SubstitutableType *)> fn) const; /// Look through the given type and its children and apply fn to them. void visit(llvm::function_ref fn) const { @@ -343,7 +342,7 @@ public: /// /// \returns the substituted type, or a null type if an error occurred. Type subst(SubstitutionMap substitutions, - SubstOptions options = llvm::None) const; + SubstOptions options = std::nullopt) const; /// Replace references to substitutable types with new, concrete types and /// return the substituted result. @@ -357,7 +356,7 @@ public: /// /// \returns the substituted type, or a null type if an error occurred. Type subst(TypeSubstitutionFn substitutions, LookupConformanceFn conformances, - SubstOptions options = llvm::None) const; + SubstOptions options = std::nullopt) const; /// Apply an in-flight substitution to this type. /// @@ -410,7 +409,7 @@ public: /// that can express the join, or Any if the only join would be a /// more-general existential type, or None if we cannot yet compute a /// correct join but one better than Any may exist. - static llvm::Optional join(Type first, Type second); + static std::optional join(Type first, Type second); friend llvm::hash_code hash_value(Type T) { return llvm::hash_value(T.getPointer()); diff --git a/include/swift/AST/TypeCheckRequests.h b/include/swift/AST/TypeCheckRequests.h index 4373e390808..2931285eda1 100644 --- a/include/swift/AST/TypeCheckRequests.h +++ b/include/swift/AST/TypeCheckRequests.h @@ -106,7 +106,7 @@ public: // Caching bool isCached() const; - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(Type value) const; }; @@ -133,7 +133,7 @@ public: public: // Separate caching. bool isCached() const; - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(Type value) const; public: @@ -182,7 +182,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional> getCachedResult() const; + std::optional> getCachedResult() const; void cacheResult(llvm::TinyPtrVector value) const; }; @@ -203,7 +203,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(bool value) const; }; @@ -293,7 +293,7 @@ public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(bool value) const; }; @@ -319,7 +319,7 @@ public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(bool value) const; }; @@ -345,7 +345,7 @@ public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(bool value) const; }; @@ -425,7 +425,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(bool value) const; }; @@ -446,7 +446,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(bool value) const; }; @@ -525,7 +525,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(RequirementSignature value) const; }; @@ -546,7 +546,7 @@ private: public: // Caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(Type value) const; }; @@ -705,7 +705,7 @@ private: public: // Caching bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(Type value) const; }; @@ -795,7 +795,7 @@ public: /// Request information about the mutability of composed property wrappers. class PropertyWrapperMutabilityRequest : public SimpleRequest(VarDecl *), + std::optional(VarDecl *), RequestFlags::Cached> { public: using SimpleRequest::SimpleRequest; @@ -804,8 +804,8 @@ private: friend SimpleRequest; // Evaluation. - llvm::Optional evaluate(Evaluator &evaluator, - VarDecl *var) const; + std::optional evaluate(Evaluator &evaluator, + VarDecl *var) const; public: // Caching @@ -815,7 +815,7 @@ public: /// Request information about the l-valueness of composed property wrappers. class PropertyWrapperLValuenessRequest : public SimpleRequest(VarDecl *), + std::optional(VarDecl *), RequestFlags::Cached> { public: using SimpleRequest::SimpleRequest; @@ -824,8 +824,8 @@ private: friend SimpleRequest; // Evaluation. - llvm::Optional evaluate(Evaluator &evaluator, - VarDecl *var) const; + std::optional evaluate(Evaluator &evaluator, + VarDecl *var) const; public: // Caching @@ -995,7 +995,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(SelfAccessKind value) const; }; @@ -1402,7 +1402,7 @@ using CustomAttrNominalPair = std::pair; /// declaration, with any inference rules applied. class GlobalActorAttributeRequest : public SimpleRequest( + std::optional( llvm::PointerUnion), RequestFlags::Cached> { public: @@ -1412,7 +1412,7 @@ private: friend SimpleRequest; // Evaluation. - llvm::Optional> + std::optional> evaluate(Evaluator &evaluator, llvm::PointerUnion) const; @@ -1471,7 +1471,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(bool value) const; }; @@ -1493,7 +1493,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(bool value) const; }; @@ -1515,7 +1515,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(OpaqueReadOwnership value) const; }; @@ -1555,7 +1555,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(BraceStmt *body) const; public: @@ -1757,7 +1757,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(bool hasStorage) const; }; @@ -1778,7 +1778,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(StorageImplInfo value) const; }; @@ -1799,7 +1799,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(bool value) const; }; @@ -1820,7 +1820,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(bool value) const; }; @@ -1841,7 +1841,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(bool value) const; }; @@ -1864,7 +1864,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(AccessorDecl *value) const; }; @@ -1921,7 +1921,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(bool value) const; }; @@ -2067,7 +2067,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(GenericSignature value) const; void diagnoseCycle(DiagnosticEngine &diags) const; @@ -2090,7 +2090,7 @@ private: public: // Caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(Type value) const; void diagnoseCycle(DiagnosticEngine &diags) const; }; @@ -2137,7 +2137,7 @@ public: // Separate caching. bool isCached() const; - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(evaluator::SideEffect value) const; }; @@ -2196,7 +2196,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(bool value) const; }; @@ -2219,7 +2219,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(bool value) const; }; @@ -2242,7 +2242,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(ParamSpecifier value) const; }; @@ -2269,7 +2269,7 @@ private: public: // Separate caching. bool isCached() const; - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(Type value) const; }; @@ -2290,7 +2290,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(Type value) const; }; @@ -2312,7 +2312,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(const PatternBindingEntry *value) const; }; @@ -2333,7 +2333,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(Expr *expr) const; }; @@ -2352,7 +2352,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(NamedPattern *P) const; }; @@ -2364,7 +2364,7 @@ class ExprPatternMatchResult { // Should only be used as the default value for the request, as the caching // logic assumes the request always produces a non-null result. - ExprPatternMatchResult(llvm::NoneType) + ExprPatternMatchResult(std::nullopt_t) : MatchVar(nullptr), MatchExpr(nullptr) {} public: @@ -2398,7 +2398,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(ExprPatternMatchResult result) const; }; @@ -2441,7 +2441,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(Type value) const; }; @@ -2454,7 +2454,7 @@ struct PrecedenceGroupDescriptor { Identifier ident; SourceLoc nameLoc; // Exists for diagnostics. Does not contribute to the descriptor otherwise. - llvm::Optional pathDirection; + std::optional pathDirection; SourceLoc getLoc() const; @@ -2705,7 +2705,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(bool value) const; }; @@ -2784,7 +2784,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(TypeWitnessAndDecl value) const; }; @@ -2843,7 +2843,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(Witness value) const; }; @@ -2885,7 +2885,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(ProtocolConformanceRef value) const; }; @@ -3041,7 +3041,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(Initializer *init) const; }; @@ -3062,7 +3062,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(Expr *expr) const; }; @@ -3082,7 +3082,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(Type type) const; }; @@ -3125,7 +3125,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(Expr *expr) const; }; @@ -3200,7 +3200,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(evaluator::SideEffect) const; public: @@ -3279,7 +3279,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(IndexSubset *value) const; }; @@ -3450,7 +3450,7 @@ public: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(evaluator::SideEffect) const; public: @@ -3572,7 +3572,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(Type value) const; }; @@ -3594,7 +3594,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(Type value) const; }; @@ -3654,7 +3654,7 @@ private: public: // Cached. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(bool value) const; }; @@ -3886,7 +3886,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(Type value) const; }; @@ -3967,7 +3967,7 @@ using AvailableAttrDeclPair = std::pair; class SemanticAvailableRangeAttrRequest : public SimpleRequest(const Decl *), + std::optional(const Decl *), RequestFlags::Cached> { public: using SimpleRequest::SimpleRequest; @@ -3975,8 +3975,8 @@ public: private: friend SimpleRequest; - llvm::Optional evaluate(Evaluator &evaluator, - const Decl *decl) const; + std::optional evaluate(Evaluator &evaluator, + const Decl *decl) const; public: bool isCached() const { return true; } @@ -3984,7 +3984,7 @@ public: class SemanticUnavailableAttrRequest : public SimpleRequest( + std::optional( const Decl *decl, bool ignoreAppExtensions), RequestFlags::Cached> { public: @@ -3993,7 +3993,7 @@ public: private: friend SimpleRequest; - llvm::Optional + std::optional evaluate(Evaluator &evaluator, const Decl *decl, bool ignoreAppExtensions) const; @@ -4285,7 +4285,7 @@ public: /// Find the definition of a given macro. class ExpandMacroExpansionDeclRequest : public SimpleRequest(MacroExpansionDecl *), + std::optional(MacroExpansionDecl *), RequestFlags::Cached> { public: using SimpleRequest::SimpleRequest; @@ -4293,8 +4293,8 @@ public: private: friend SimpleRequest; - llvm::Optional evaluate(Evaluator &evaluator, - MacroExpansionDecl *med) const; + std::optional evaluate(Evaluator &evaluator, + MacroExpansionDecl *med) const; public: bool isCached() const { return true; } @@ -4305,7 +4305,7 @@ public: /// Expand a 'MacroExpansionExpr', class ExpandMacroExpansionExprRequest : public SimpleRequest(MacroExpansionExpr *), + std::optional(MacroExpansionExpr *), RequestFlags::Cached> { public: using SimpleRequest::SimpleRequest; @@ -4313,8 +4313,8 @@ public: private: friend SimpleRequest; - llvm::Optional evaluate(Evaluator &evaluator, - MacroExpansionExpr *mee) const; + std::optional evaluate(Evaluator &evaluator, + MacroExpansionExpr *mee) const; public: bool isCached() const { return true; } @@ -4509,7 +4509,7 @@ public: class ExpandBodyMacroRequest : public SimpleRequest(AbstractFunctionDecl *), + std::optional(AbstractFunctionDecl *), RequestFlags::Cached> { public: using SimpleRequest::SimpleRequest; @@ -4517,8 +4517,8 @@ public: private: friend SimpleRequest; - llvm::Optional evaluate( - Evaluator &evaluator, AbstractFunctionDecl *fn) const; + std::optional evaluate(Evaluator &evaluator, + AbstractFunctionDecl *fn) const; public: bool isCached() const { return true; } @@ -4708,7 +4708,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional> getCachedResult() const; + std::optional> getCachedResult() const; void cacheResult(std::vector children) const; }; @@ -4730,7 +4730,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(GenericSignature signature) const; }; @@ -4749,7 +4749,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(bool isSkipped) const; }; @@ -4768,13 +4768,13 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(DeclAttributes) const; }; class UniqueUnderlyingTypeSubstitutionsRequest : public SimpleRequest( + std::optional( const OpaqueTypeDecl *), RequestFlags::SeparatelyCached> { public: @@ -4783,14 +4783,14 @@ public: private: friend SimpleRequest; - llvm::Optional evaluate(Evaluator &evaluator, - const OpaqueTypeDecl *) const; + std::optional evaluate(Evaluator &evaluator, + const OpaqueTypeDecl *) const; public: // Separate caching. bool isCached() const { return true; } - llvm::Optional> getCachedResult() const; - void cacheResult(llvm::Optional) const; + std::optional> getCachedResult() const; + void cacheResult(std::optional) const; }; /// Collect all local type declarations in the SourceFile. diff --git a/include/swift/AST/TypeCheckerTypeIDZone.def b/include/swift/AST/TypeCheckerTypeIDZone.def index aa809747c4b..f9e3c4e0c7c 100644 --- a/include/swift/AST/TypeCheckerTypeIDZone.def +++ b/include/swift/AST/TypeCheckerTypeIDZone.def @@ -511,7 +511,7 @@ SWIFT_REQUEST(TypeChecker, ExpandPreambleMacroRequest, ArrayRef(AbstractFunctionDecl *), Cached, NoLocationInfo) SWIFT_REQUEST(TypeChecker, ExpandBodyMacroRequest, - llvm::Optional(AbstractFunctionDecl *), + std::optional(AbstractFunctionDecl *), Cached, NoLocationInfo) SWIFT_REQUEST(TypeChecker, LocalDiscriminatorsRequest, unsigned(DeclContext *), @@ -551,7 +551,7 @@ SWIFT_REQUEST(TypeChecker, SemanticDeclAttrsRequest, DeclAttributes(const Decl *), Cached, NoLocationInfo) SWIFT_REQUEST(TypeChecker, UniqueUnderlyingTypeSubstitutionsRequest, - llvm::Optional(const Decl *), + std::optional(const Decl *), SeparatelyCached, NoLocationInfo) SWIFT_REQUEST(TypeChecker, LocalTypeDeclsRequest, ArrayRef(SourceFile *), diff --git a/include/swift/AST/TypeRepr.h b/include/swift/AST/TypeRepr.h index b8ef358fb14..8a58b6e4367 100644 --- a/include/swift/AST/TypeRepr.h +++ b/include/swift/AST/TypeRepr.h @@ -220,22 +220,22 @@ public: /// All uses of this type should be ignored and not re-diagnosed. class ErrorTypeRepr : public TypeRepr { SourceRange Range; - llvm::Optional DelayedDiag; + std::optional DelayedDiag; - ErrorTypeRepr(SourceRange Range, llvm::Optional Diag) + ErrorTypeRepr(SourceRange Range, std::optional Diag) : TypeRepr(TypeReprKind::Error), Range(Range), DelayedDiag(Diag) {} public: static ErrorTypeRepr * create(ASTContext &Context, SourceRange Range, - llvm::Optional DelayedDiag = llvm::None) { + std::optional DelayedDiag = std::nullopt) { assert((!DelayedDiag || Range) && "diagnostic needs a location"); return new (Context) ErrorTypeRepr(Range, DelayedDiag); } static ErrorTypeRepr * create(ASTContext &Context, SourceLoc Loc = SourceLoc(), - llvm::Optional DelayedDiag = llvm::None) { + std::optional DelayedDiag = std::nullopt) { return create(Context, SourceRange(Loc), DelayedDiag); } diff --git a/include/swift/AST/Types.h b/include/swift/AST/Types.h index 36c33ae64bb..0b46e1263d6 100644 --- a/include/swift/AST/Types.h +++ b/include/swift/AST/Types.h @@ -39,14 +39,13 @@ #include "llvm/ADT/DenseMapInfo.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/FoldingSet.h" -#include "llvm/ADT/None.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/PointerEmbeddedInt.h" #include "llvm/ADT/PointerUnion.h" #include "llvm/ADT/SmallBitVector.h" #include "llvm/Support/Error.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/TrailingObjects.h" +#include namespace llvm { struct fltSemantics; @@ -955,7 +954,7 @@ public: } /// If this type is a known protocol, return its kind. - llvm::Optional getKnownProtocol(); + std::optional getKnownProtocol(); /// Determine whether the given type is "specialized", meaning that /// it involves generic types for which generic arguments have been provided. @@ -1467,7 +1466,7 @@ public: /// Return the tangent space of the given type, if it exists. Otherwise, /// return `None`. - llvm::Optional + std::optional getAutoDiffTangentSpace(LookupConformanceFn lookupConformance); }; @@ -2911,7 +2910,7 @@ class AnyMetatypeType : public TypeBase { protected: AnyMetatypeType(TypeKind kind, const ASTContext *C, RecursiveTypeProperties properties, Type instanceType, - llvm::Optional repr); + std::optional repr); public: Type getInstanceType() const { return InstanceType; } @@ -2956,7 +2955,7 @@ END_CAN_TYPE_WRAPPER(AnyMetatypeType, Type) /// type, in which case the ordinary metatype is spelled X.Protocol /// and X.Type connotes the ExistentialMetatypeType. class MetatypeType : public AnyMetatypeType { - static MetatypeType *get(Type T, llvm::Optional Repr, + static MetatypeType *get(Type T, std::optional Repr, const ASTContext &C); public: @@ -2964,7 +2963,7 @@ public: /// /// This leaves the 'representation' property unavailable. static MetatypeType *get(Type T, const ASTContext &C) { - return get(T, llvm::None, C); + return get(T, std::nullopt, C); } /// Return the MetatypeType for the specified type declaration with @@ -2973,7 +2972,7 @@ public: /// Metatype representation is a SIL-only property. Thin metatypes /// can be lowered away to empty types in IR. static MetatypeType * - get(Type T, llvm::Optional repr = llvm::None) { + get(Type T, std::optional repr = std::nullopt) { return get(T, repr, T->getASTContext()); } @@ -2984,7 +2983,7 @@ public: private: MetatypeType(Type T, const ASTContext *C, RecursiveTypeProperties properties, - llvm::Optional repr); + std::optional repr); friend class TypeDecl; }; BEGIN_CAN_TYPE_WRAPPER(MetatypeType, AnyMetatypeType) @@ -3010,7 +3009,7 @@ END_CAN_TYPE_WRAPPER(MetatypeType, AnyMetatypeType) class ExistentialMetatypeType : public AnyMetatypeType { public: static ExistentialMetatypeType * - get(Type T, llvm::Optional Repr, const ASTContext &C); + get(Type T, std::optional Repr, const ASTContext &C); /// Return the ExistentialMetatypeType for the specified type /// with the given representation. @@ -3018,7 +3017,7 @@ public: /// Metatype representation is a SIL-only property. Existential /// metatypes cannot be thin. static ExistentialMetatypeType * - get(Type T, llvm::Optional repr = llvm::None) { + get(Type T, std::optional repr = std::nullopt) { return get(T, repr, T->getASTContext()); } @@ -3032,7 +3031,7 @@ public: private: ExistentialMetatypeType(Type T, const ASTContext *C, RecursiveTypeProperties properties, - llvm::Optional repr); + std::optional repr); friend class TypeDecl; }; BEGIN_CAN_TYPE_WRAPPER(ExistentialMetatypeType, AnyMetatypeType) @@ -3318,7 +3317,8 @@ public: return Param(getType(), Identifier(), getFlags().asParamFlags()); } - Yield subst(SubstitutionMap subs, SubstOptions options = llvm::None) const { + Yield subst(SubstitutionMap subs, + SubstOptions options = std::nullopt) const { return Yield(getType().subst(subs, options), getFlags()); } @@ -3340,7 +3340,7 @@ public: CanParam asParam() const { return CanParam::getFromParam(Yield::asParam());} CanYield subst(SubstitutionMap subs, - SubstOptions options = llvm::None) const { + SubstOptions options = std::nullopt) const { return CanYield(getType().subst(subs, options)->getCanonicalType(), getFlags()); } @@ -3353,7 +3353,7 @@ protected: /// ClangTypeInfo value if one is present. AnyFunctionType(TypeKind Kind, const ASTContext *CanTypeContext, Type Output, RecursiveTypeProperties properties, unsigned NumParams, - llvm::Optional Info) + std::optional Info) : TypeBase(Kind, CanTypeContext, properties), Output(Output) { if (Info.has_value()) { Bits.AnyFunctionType.HasExtInfo = true; @@ -3441,12 +3441,12 @@ public: return FunctionTypeIsolation::forNonIsolated(); } - /// Retrieve the "effective" thrown interface type, or llvm::None if + /// Retrieve the "effective" thrown interface type, or std::nullopt if /// this function cannot throw. /// /// Functions with untyped throws will produce "any Error", functions that - /// cannot throw or are specified to throw "Never" will return llvm::None. - llvm::Optional getEffectiveThrownErrorType() const; + /// cannot throw or are specified to throw "Never" will return std::nullopt. + std::optional getEffectiveThrownErrorType() const; /// Retrieve the "effective" thrown interface type, or `Never` if /// this function cannot throw. @@ -3677,7 +3677,7 @@ BEGIN_CAN_TYPE_WRAPPER(AnyFunctionType, Type) static CanAnyFunctionType get(CanGenericSignature signature, CanParamArrayRef params, CanType result, - llvm::Optional info = llvm::None); + std::optional info = std::nullopt); CanGenericSignature getOptGenericSignature() const; @@ -3737,7 +3737,7 @@ class FunctionType final public: /// 'Constructor' Factory Function static FunctionType *get(ArrayRef params, Type result, - llvm::Optional info = llvm::None); + std::optional info = std::nullopt); // Retrieve the input parameters of this function type. ArrayRef getParams() const { @@ -3776,13 +3776,13 @@ public: } void Profile(llvm::FoldingSetNodeID &ID) { - llvm::Optional info = llvm::None; + std::optional info = std::nullopt; if (hasExtInfo()) info = getExtInfo(); Profile(ID, getParams(), getResult(), info); } static void Profile(llvm::FoldingSetNodeID &ID, ArrayRef params, - Type result, llvm::Optional info); + Type result, std::optional info); // Implement isa/cast/dyncast/etc. static bool classof(const TypeBase *T) { @@ -3790,13 +3790,12 @@ public: } private: - FunctionType(ArrayRef params, Type result, - llvm::Optional info, const ASTContext *ctx, - RecursiveTypeProperties properties); + FunctionType(ArrayRef params, Type result, std::optional info, + const ASTContext *ctx, RecursiveTypeProperties properties); }; BEGIN_CAN_TYPE_WRAPPER(FunctionType, AnyFunctionType) static CanFunctionType get(CanParamArrayRef params, CanType result, - llvm::Optional info = llvm::None) { + std::optional info = std::nullopt) { auto fnType = FunctionType::get(params.getOriginalArray(), result, info); return cast(fnType->getCanonicalType()); } @@ -3889,14 +3888,14 @@ class GenericFunctionType final /// Construct a new generic function type. GenericFunctionType(GenericSignature sig, ArrayRef params, Type result, - llvm::Optional info, const ASTContext *ctx, + std::optional info, const ASTContext *ctx, RecursiveTypeProperties properties); public: /// Create a new generic function type. static GenericFunctionType *get(GenericSignature sig, ArrayRef params, Type result, - llvm::Optional info = llvm::None); + std::optional info = std::nullopt); // Retrieve the input parameters of this function type. ArrayRef getParams() const { @@ -3939,18 +3938,18 @@ public: /// Substitute the given generic arguments into this generic /// function type and return the resulting non-generic type. FunctionType *substGenericArgs(SubstitutionMap subs, - SubstOptions options = llvm::None); + SubstOptions options = std::nullopt); FunctionType *substGenericArgs(llvm::function_ref substFn) const; void Profile(llvm::FoldingSetNodeID &ID) { - llvm::Optional info = llvm::None; + std::optional info = std::nullopt; if (hasExtInfo()) info = getExtInfo(); Profile(ID, getGenericSignature(), getParams(), getResult(), info); } static void Profile(llvm::FoldingSetNodeID &ID, GenericSignature sig, ArrayRef params, Type result, - llvm::Optional info); + std::optional info); // Implement isa/cast/dyncast/etc. static bool classof(const TypeBase *T) { @@ -3962,7 +3961,7 @@ BEGIN_CAN_TYPE_WRAPPER(GenericFunctionType, AnyFunctionType) /// Create a new generic function type. static CanGenericFunctionType get(CanGenericSignature sig, CanParamArrayRef params, CanType result, - llvm::Optional info = llvm::None) { + std::optional info = std::nullopt) { // Knowing that the argument types are independently canonical is // not sufficient to guarantee that the function type will be canonical. auto fnType = @@ -3988,7 +3987,7 @@ END_CAN_TYPE_WRAPPER(GenericFunctionType, AnyFunctionType) inline CanAnyFunctionType CanAnyFunctionType::get(CanGenericSignature signature, CanParamArrayRef params, - CanType result, llvm::Optional extInfo) { + CanType result, std::optional extInfo) { if (signature) { return CanGenericFunctionType::get(signature, params, result, extInfo); } else { @@ -4817,7 +4816,7 @@ private: ArrayRef params, ArrayRef yieldResults, ArrayRef normalResults, - llvm::Optional errorResult, + std::optional errorResult, SubstitutionMap patternSubs, SubstitutionMap invocationSubs, const ASTContext &ctx, RecursiveTypeProperties properties, ProtocolConformanceRef witnessMethodConformance); @@ -4829,7 +4828,7 @@ public: ArrayRef interfaceParams, ArrayRef interfaceYields, ArrayRef interfaceResults, - llvm::Optional interfaceErrorResult, + std::optional interfaceErrorResult, SubstitutionMap patternSubs, SubstitutionMap invocationSubs, const ASTContext &ctx, ProtocolConformanceRef witnessMethodConformance = @@ -5047,11 +5046,11 @@ public: SILResultInfo getErrorResult() const { return const_cast(this)->getMutableErrorResult(); } - llvm::Optional getOptionalErrorResult() const { + std::optional getOptionalErrorResult() const { if (hasErrorResult()) { return getErrorResult(); } else { - return llvm::None; + return std::nullopt; } } @@ -5483,7 +5482,7 @@ public: DifferingParameterConvention, ABIIncompatibleParameterType, } kind; - llvm::Optional payload; + std::optional payload; ABICompatibilityCheckResult(innerty kind) : kind(kind) {} ABICompatibilityCheckResult(innerty kind, uintptr_t payload) @@ -5544,7 +5543,7 @@ public: SILCoroutineKind coroutineKind, ParameterConvention calleeConvention, ArrayRef params, ArrayRef yields, ArrayRef results, - llvm::Optional errorResult, + std::optional errorResult, ProtocolConformanceRef conformance, SubstitutionMap patternSub, SubstitutionMap invocationSubs); @@ -6676,7 +6675,7 @@ public: /// a fresh archetype with a unique ID will be opened. static CanTypeWrapper get(CanType existential, GenericSignature parentSig, - llvm::Optional knownID = llvm::None); + std::optional knownID = std::nullopt); /// Get or create an archetype that represents the opened type /// of an existential value. @@ -6690,7 +6689,7 @@ public: /// a fresh archetype with a unique ID will be opened. static CanTypeWrapper get(CanType existential, Type interfaceType, GenericSignature parentSig, - llvm::Optional knownID = llvm::None); + std::optional knownID = std::nullopt); /// Create a new archetype that represents the opened type /// of an existential value. diff --git a/include/swift/AST/Witness.h b/include/swift/AST/Witness.h index b470b64989a..75bec74d72f 100644 --- a/include/swift/AST/Witness.h +++ b/include/swift/AST/Witness.h @@ -97,7 +97,7 @@ class Witness { /// The derivative generic signature, when the requirement is a derivative /// function. GenericSignature derivativeGenSig; - llvm::Optional enterIsolation; + std::optional enterIsolation; }; llvm::PointerUnion storage; @@ -125,9 +125,8 @@ public: /// Create a witness for the given requirement. /// /// Deserialized witnesses do not have a witness thunk signature. - static Witness - forDeserialized(ValueDecl *decl, SubstitutionMap substitutions, - llvm::Optional enterIsolation) { + static Witness forDeserialized(ValueDecl *decl, SubstitutionMap substitutions, + std::optional enterIsolation) { // TODO: It's probably a good idea to have a separate 'deserialized' bit. return Witness( decl, substitutions, nullptr, SubstitutionMap(), CanGenericSignature(), @@ -155,7 +154,7 @@ public: GenericSignature witnessThunkSig, SubstitutionMap reqToWitnessThunkSigSubs, GenericSignature derivativeGenSig, - llvm::Optional enterIsolation); + std::optional enterIsolation); /// Retrieve the witness declaration reference, which includes the /// substitutions needed to use the witness from the witness thunk signature @@ -201,11 +200,11 @@ public: return GenericSignature(); } - llvm::Optional getEnterIsolation() const { + std::optional getEnterIsolation() const { if (auto *storedWitness = storage.dyn_cast()) return storedWitness->enterIsolation; - return llvm::None; + return std::nullopt; } /// Retrieve a copy of the witness with an actor isolation that the diff --git a/include/swift/Basic/AnyValue.h b/include/swift/Basic/AnyValue.h index a265e14b2ba..897fd0d03a3 100644 --- a/include/swift/Basic/AnyValue.h +++ b/include/swift/Basic/AnyValue.h @@ -48,8 +48,8 @@ namespace llvm { return !(lhs == rhs); } - template - void simple_display(raw_ostream &out, const Optional &opt) { + template + void simple_display(raw_ostream &out, const std::optional &opt) { if (opt) { simple_display(out, *opt); } else { diff --git a/include/swift/Basic/BlotMapVector.h b/include/swift/Basic/BlotMapVector.h index 16657370c3f..2e8fa262fb3 100644 --- a/include/swift/Basic/BlotMapVector.h +++ b/include/swift/Basic/BlotMapVector.h @@ -13,10 +13,10 @@ #ifndef SWIFT_BASIC_BLOTMAPVECTOR_H #define SWIFT_BASIC_BLOTMAPVECTOR_H -#include "llvm/ADT/DenseMap.h" #include "swift/Basic/LLVM.h" #include "swift/Basic/Range.h" -#include "llvm/ADT/Optional.h" +#include "llvm/ADT/DenseMap.h" +#include #include namespace swift { @@ -31,7 +31,7 @@ bool compareKeyAgainstDefaultKey(const std::pair &Pair) { template , typename VectorT = - std::vector>>> + std::vector>>> class BlotMapVector { /// Map keys to indices in Vector. MapT Map; @@ -127,7 +127,7 @@ public: typename MapT::iterator It = Map.find(Key); if (It == Map.end()) return false; - Vector[It->second] = llvm::None; + Vector[It->second] = std::nullopt; Map.erase(It); return true; } @@ -163,7 +163,7 @@ public: template , typename VectorT = - llvm::SmallVector>, N>> + llvm::SmallVector>, N>> class SmallBlotMapVector : public BlotMapVector { public: SmallBlotMapVector() {} diff --git a/include/swift/Basic/BlotSetVector.h b/include/swift/Basic/BlotSetVector.h index a9e061bc6af..d00488707d1 100644 --- a/include/swift/Basic/BlotSetVector.h +++ b/include/swift/Basic/BlotSetVector.h @@ -15,8 +15,8 @@ #include "swift/Basic/LLVM.h" #include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallVector.h" +#include #include namespace swift { @@ -46,7 +46,7 @@ namespace swift { /// (a) The `blot operation' is leaving the value in the set vector, but marking /// the value as being dead. template >, + typename VectorT = std::vector>, typename MapT = llvm::DenseMap> class BlotSetVector { VectorT vector; @@ -67,7 +67,7 @@ public: const_iterator begin() const { return vector.begin(); } const_iterator end() const { return vector.end(); } - ArrayRef> getArray() const { return vector; } + ArrayRef> getArray() const { return vector; } iterator_range getRange() const { return {begin(), end()}; @@ -80,7 +80,7 @@ public: return {rbegin(), rend()}; } - const llvm::Optional &operator[](unsigned n) const { + const std::optional &operator[](unsigned n) const { assert(n < vector.size() && "Out of range!"); return vector[n]; } @@ -127,7 +127,7 @@ public: auto iterator2 = map.find(value2); if (iterator2 != map.end()) { - vector[index1] = llvm::None; + vector[index1] = std::nullopt; return; } @@ -143,12 +143,12 @@ public: return false; unsigned index = iterator->second; map.erase(iterator); - vector[index] = llvm::None; + vector[index] = std::nullopt; return true; } /// Return the last element of the blot map vector. Will be None if blotted. - llvm::Optional pop_back_val() { + std::optional pop_back_val() { auto result = vector.pop_back_val(); if (!result) return result; @@ -158,10 +158,10 @@ public: /// Attempt to lookup the index of \p value. Returns None upon failure and the /// value on success. - llvm::Optional getIndex(const ValueT &value) { + std::optional getIndex(const ValueT &value) { auto iterator = map.find(value); if (iterator == map.end()) - return llvm::None; + return std::nullopt; return iterator->second; } @@ -174,7 +174,7 @@ public: template class SmallBlotSetVector - : public BlotSetVector, N>, + : public BlotSetVector, N>, llvm::SmallDenseMap> { public: SmallBlotSetVector() {} diff --git a/include/swift/Basic/CTypeIDZone.def b/include/swift/Basic/CTypeIDZone.def index 51aa9bd8ceb..9469fa3a20d 100644 --- a/include/swift/Basic/CTypeIDZone.def +++ b/include/swift/Basic/CTypeIDZone.def @@ -43,4 +43,4 @@ SWIFT_TYPEID_TEMPLATE2_NAMED(std::pair, Pair, typename T1, T1, typename T2, T2) // LLVM ADT types. SWIFT_TYPEID_TEMPLATE1_NAMED(llvm::TinyPtrVector, TinyPtrVector, typename T, T) SWIFT_TYPEID_TEMPLATE1_NAMED(llvm::ArrayRef, ArrayRef, typename T, T) -SWIFT_TYPEID_TEMPLATE1_NAMED(llvm::Optional, Optional, typename T, T) +SWIFT_TYPEID_TEMPLATE1_NAMED(std::optional, Optional, typename T, T) diff --git a/include/swift/Basic/Cache.h b/include/swift/Basic/Cache.h index 580a9dcc05c..b1c6c2ed430 100644 --- a/include/swift/Basic/Cache.h +++ b/include/swift/Basic/Cache.h @@ -15,9 +15,8 @@ #include "llvm/ADT/DenseMapInfo.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" -#include "llvm/ADT/None.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/StringRef.h" +#include namespace swift { namespace sys { @@ -171,12 +170,12 @@ public: releaseValue(CacheValuePtr); } - llvm::Optional get(const KeyT &Key) { + std::optional get(const KeyT &Key) { const void *CacheKeyPtr = KeyInfoT::getLookupKey(&Key); void *CacheValuePtr; bool Found = getAndRetain(CacheKeyPtr, &CacheValuePtr); if (!Found) - return llvm::None; + return std::nullopt; ValueT Val(ValueInfoT::getFromCache(CacheValuePtr)); releaseValue(CacheValuePtr); diff --git a/include/swift/Basic/ClusteredBitVector.h b/include/swift/Basic/ClusteredBitVector.h index 1db3b461afc..d4926d9de50 100644 --- a/include/swift/Basic/ClusteredBitVector.h +++ b/include/swift/Basic/ClusteredBitVector.h @@ -29,10 +29,10 @@ #ifndef SWIFT_BASIC_CLUSTEREDBITVECTOR_H #define SWIFT_BASIC_CLUSTEREDBITVECTOR_H -#include "llvm/ADT/APInt.h" -#include "llvm/ADT/Optional.h" #include "swift/Basic/Debug.h" +#include "llvm/ADT/APInt.h" #include +#include namespace swift { @@ -44,7 +44,7 @@ class ClusteredBitVector { /// The least-significant bit of the integer corresponds to the bit /// at index 0. If the optional does not have a value then the bit /// vector has a length of 0 bits. - llvm::Optional Bits; + std::optional Bits; /// Copy constructor from APInt. ClusteredBitVector(const APInt &bits) : Bits(bits) {} @@ -64,13 +64,11 @@ public: /// Create a new ClusteredBitVector from the provided APInt, /// with a size of 0 if the optional does not have a value. - ClusteredBitVector(const llvm::Optional &bits) - : Bits(bits) {} + ClusteredBitVector(const std::optional &bits) : Bits(bits) {} /// Create a new ClusteredBitVector from the provided APInt, /// with a size of 0 if the optional does not have a value. - ClusteredBitVector(llvm::Optional &&bits) - : Bits(std::move(bits)) {} + ClusteredBitVector(std::optional &&bits) : Bits(std::move(bits)) {} ClusteredBitVector &operator=(const ClusteredBitVector &other) { this->Bits = other.Bits; diff --git a/include/swift/Basic/EditorPlaceholder.h b/include/swift/Basic/EditorPlaceholder.h index c4b5d17745f..64fd0964fa7 100644 --- a/include/swift/Basic/EditorPlaceholder.h +++ b/include/swift/Basic/EditorPlaceholder.h @@ -18,8 +18,8 @@ #ifndef SWIFT_BASIC_EDITORPLACEHOLDER_H #define SWIFT_BASIC_EDITORPLACEHOLDER_H -#include "llvm/ADT/Optional.h" #include "llvm/ADT/StringRef.h" +#include namespace swift { @@ -43,7 +43,7 @@ struct EditorPlaceholderData { /// Deconstructs a placeholder string and returns info about it. /// \returns None if the \c PlaceholderText is not a valid placeholder string. -llvm::Optional +std::optional parseEditorPlaceholder(llvm::StringRef PlaceholderText); /// Checks if an identifier with the given text is an editor placeholder diff --git a/include/swift/Basic/Feature.h b/include/swift/Basic/Feature.h index 7964f938dcd..0b2af2b9693 100644 --- a/include/swift/Basic/Feature.h +++ b/include/swift/Basic/Feature.h @@ -13,8 +13,8 @@ #ifndef SWIFT_BASIC_FEATURES_H #define SWIFT_BASIC_FEATURES_H -#include "llvm/ADT/Optional.h" #include "llvm/ADT/StringRef.h" +#include namespace swift { @@ -54,15 +54,15 @@ inline bool featureImpliesFeature(Feature feature, Feature implied) { } /// Get the feature corresponding to this "future" feature, if there is one. -llvm::Optional getUpcomingFeature(llvm::StringRef name); +std::optional getUpcomingFeature(llvm::StringRef name); /// Get the feature corresponding to this "experimental" feature, if there is /// one. -llvm::Optional getExperimentalFeature(llvm::StringRef name); +std::optional getExperimentalFeature(llvm::StringRef name); /// Get the major language version in which this feature was introduced, or /// \c None if it does not have such a version. -llvm::Optional getFeatureLanguageVersion(Feature feature); +std::optional getFeatureLanguageVersion(Feature feature); /// Determine whether this feature should be included in the /// module interface diff --git a/include/swift/Basic/Fingerprint.h b/include/swift/Basic/Fingerprint.h index a731b8af1da..9d05a945df5 100644 --- a/include/swift/Basic/Fingerprint.h +++ b/include/swift/Basic/Fingerprint.h @@ -15,10 +15,10 @@ #include "swift/Basic/StableHasher.h" #include "llvm/ADT/Hashing.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/raw_ostream.h" +#include #include @@ -73,7 +73,7 @@ public: /// be a 32-byte hash value, i.e. that represent a valid 32-bit hex integer. /// /// Strings that violate this invariant will return a null optional. - static llvm::Optional fromString(llvm::StringRef value); + static std::optional fromString(llvm::StringRef value); /// Creates a fingerprint value by consuming the given \c StableHasher. explicit Fingerprint(StableHasher &&stableHasher) diff --git a/include/swift/Basic/FrozenMultiMap.h b/include/swift/Basic/FrozenMultiMap.h index 93ca8eba8bb..805e898744f 100644 --- a/include/swift/Basic/FrozenMultiMap.h +++ b/include/swift/Basic/FrozenMultiMap.h @@ -45,7 +45,7 @@ namespace swift { template >>> + std::vector>>> class FrozenMultiMap { VectorStorage storage; bool frozen = false; @@ -56,7 +56,7 @@ private: public: using PairToSecondEltRange = - TransformRange>>, + TransformRange>>, PairToSecondElt>; FrozenMultiMap() = default; @@ -66,15 +66,15 @@ public: storage.emplace_back(key, value); } - llvm::Optional find(const Key &key) const { + std::optional find(const Key &key) const { assert(isFrozen() && "Can not perform a find operation until the map is frozen"); // Since our array is sorted, we need to first find the first pair with our // inst as the first element. auto start = std::lower_bound( - storage.begin(), storage.end(), std::make_pair(key, llvm::None), - [&](const std::pair> &p1, - const std::pair> &p2) { + storage.begin(), storage.end(), std::make_pair(key, std::nullopt), + [&](const std::pair> &p1, + const std::pair> &p2) { return p1.first < p2.first; }); @@ -82,18 +82,18 @@ public: // (signaling that we erased it), return None. if (start == storage.end() || start->first != key || !start->second.has_value()) { - return llvm::None; + return std::nullopt; } // Ok, we found our first element. Now scan forward until we find a pair // whose instruction is not our own instruction. auto end = find_if_not(start, storage.end(), - [&](const std::pair> &pair) { + [&](const std::pair> &pair) { return pair.first == key; }); unsigned count = std::distance(start, end); - ArrayRef>> slice(&*start, count); + ArrayRef>> slice(&*start, count); return PairToSecondEltRange(slice, PairToSecondElt()); } @@ -104,8 +104,8 @@ public: // inst as the first element. auto start = std::lower_bound( storage.begin(), storage.end(), std::make_pair(key, Value()), - [&](const std::pair> &p1, - const std::pair> &p2) { + [&](const std::pair> &p1, + const std::pair> &p2) { return p1.first < p2.first; }); @@ -118,7 +118,7 @@ public: // Ok, we found our element. Just set its value to .none to signal it was // destroyed and then return true. - start->second = llvm::None; + start->second = std::nullopt; return true; } @@ -131,8 +131,8 @@ public: /// operations instead of full mutable/non-mutable vector operations. void setFrozen() { std::stable_sort(storage.begin(), storage.end(), - [&](const std::pair> &lhs, - const std::pair> &rhs) { + [&](const std::pair> &lhs, + const std::pair> &rhs) { // Only compare the first entry so that we preserve // insertion order. return lhs.first < rhs.first; @@ -158,7 +158,7 @@ public: struct iterator { using iterator_category = std::forward_iterator_tag; - using value_type = std::pair>; + using value_type = std::pair>; using difference_type = std::ptrdiff_t; using pointer = value_type*; using reference = value_type&; @@ -166,7 +166,7 @@ public: FrozenMultiMap ↦ base_iterator baseIter; - llvm::Optional>> + std::optional>> currentValue; iterator(FrozenMultiMap &map, base_iterator iter) @@ -179,22 +179,21 @@ public: // If we are end, set currentValue to be None. if (baseIter == end) { - currentValue = llvm::None; + currentValue = std::nullopt; return; } // Otherwise, determine the next range that we are visiting. auto rangeEnd = std::find_if_not( std::next(baseIter), end, - [&](const std::pair> &elt) { + [&](const std::pair> &elt) { return elt.first == baseIter->first; }); - llvm::Optional resultRange; + std::optional resultRange; if (baseIter->second.has_value()) { unsigned count = std::distance(baseIter, rangeEnd); - ArrayRef>> slice(&*baseIter, - count); + ArrayRef>> slice(&*baseIter, count); resultRange.emplace(slice, PairToSecondElt()); } currentValue = {baseIter->first, resultRange}; @@ -203,7 +202,7 @@ public: iterator &operator++() { baseIter = std::find_if_not( std::next(baseIter), map.storage.end(), - [&](const std::pair> &elt) { + [&](const std::pair> &elt) { return elt.first == baseIter->first; }); updateCurrentValue(); @@ -220,7 +219,7 @@ public: return tmp; } - std::pair> operator*() const { + std::pair> operator*() const { return *currentValue; } @@ -234,11 +233,10 @@ public: }; struct ToNonErasedValues { - llvm::Optional>> - operator()( - std::pair> pair) const { + std::optional>> + operator()(std::pair> pair) const { if (!pair.second.has_value()) - return llvm::None; + return std::nullopt; return pair; } }; @@ -272,7 +270,7 @@ public: /// this operation with getRange() in a nice way. bool allValuesHaveBeenDeleted() const { return llvm::all_of(storage, - [](const std::pair> &pair) { + [](const std::pair> &pair) { return !pair.second.hasValue(); }); } @@ -302,7 +300,7 @@ template struct FrozenMultiMap::PairToSecondElt { PairToSecondElt() {} - Value operator()(const std::pair> &pair) const { + Value operator()(const std::pair> &pair) const { return *pair.second; } }; @@ -313,14 +311,14 @@ struct FrozenMultiMap operator()( - const std::pair> &pair) const { + const std::pair> &pair) const { return std::make_pair(pair.first, *pair.second); } }; template using SmallFrozenMultiMap = FrozenMultiMap< - Key, Value, SmallVector>, SmallSize>>; + Key, Value, SmallVector>, SmallSize>>; } // namespace swift diff --git a/include/swift/Basic/JSONSerialization.h b/include/swift/Basic/JSONSerialization.h index b3b4e05ce72..490d883e509 100644 --- a/include/swift/Basic/JSONSerialization.h +++ b/include/swift/Basic/JSONSerialization.h @@ -21,13 +21,13 @@ #define SWIFT_BASIC_JSONSERIALIZATION_H /* #include "swift/Basic/LLVM.h" */ -#include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Regex.h" #include "llvm/Support/raw_ostream.h" +#include #include #include @@ -475,8 +475,8 @@ public: } template - void mapOptional(llvm::StringRef Key, llvm::Optional &Val) { - processKeyWithDefault(Key, Val, llvm::Optional(), /*Required=*/false); + void mapOptional(llvm::StringRef Key, std::optional &Val) { + processKeyWithDefault(Key, Val, std::optional(), /*Required=*/false); } template @@ -492,8 +492,8 @@ public: private: template - void processKeyWithDefault(llvm::StringRef Key, llvm::Optional &Val, - const llvm::Optional &DefaultValue, + void processKeyWithDefault(llvm::StringRef Key, std::optional &Val, + const std::optional &DefaultValue, bool Required) { assert(!DefaultValue.has_value() && "Optional shouldn't have a value!"); diff --git a/include/swift/Basic/LangOptions.h b/include/swift/Basic/LangOptions.h index c53f622988d..a5a63bc5be2 100644 --- a/include/swift/Basic/LangOptions.h +++ b/include/swift/Basic/LangOptions.h @@ -28,16 +28,15 @@ #include "clang/CAS/CASOptions.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/Hashing.h" -#include "llvm/ADT/None.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" -#include "llvm/TargetParser/Triple.h" #include "llvm/Support/Regex.h" #include "llvm/Support/VersionTuple.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/TargetParser/Triple.h" #include +#include #include #include @@ -136,7 +135,7 @@ namespace swift { /// a zippered binary that can be loaded into both macCatalyst and /// macOS processes. A value of 'None' means no zippering will be /// performed. - llvm::Optional TargetVariant; + std::optional TargetVariant; /// The target triple to instantiate the internal clang instance. /// When not specified, the compiler will use the value of -target to @@ -146,13 +145,13 @@ namespace swift { /// the loading module. /// The lowering triple may result in multiple versions of the same Clang /// modules being built. - llvm::Optional ClangTarget; + std::optional ClangTarget; /// The SDK version, if known. - llvm::Optional SDKVersion; + std::optional SDKVersion; /// The target variant SDK version, if known. - llvm::Optional VariantSDKVersion; + std::optional VariantSDKVersion; /// The SDK canonical name, if known. std::string SDKName; @@ -190,7 +189,7 @@ namespace swift { bool EnableBypassResilienceInPackage = false; /// Optimization mode for unavailable declarations. - llvm::Optional UnavailableDeclOptimizationMode; + std::optional UnavailableDeclOptimizationMode; /// Causes the compiler to use weak linkage for symbols belonging to /// declarations introduced at the deployment target. @@ -218,7 +217,8 @@ namespace swift { /// Diagnostic level to report when a public declarations doesn't declare /// an introduction OS version. - llvm::Optional RequireExplicitAvailability = llvm::None; + std::optional RequireExplicitAvailability = + std::nullopt; /// Introduction platform and version to suggest as fix-it /// when using RequireExplicitAvailability. diff --git a/include/swift/Basic/Lazy.h b/include/swift/Basic/Lazy.h index eb3cc04e694..e52483c872b 100644 --- a/include/swift/Basic/Lazy.h +++ b/include/swift/Basic/Lazy.h @@ -13,8 +13,9 @@ #ifndef SWIFT_BASIC_LAZY_H #define SWIFT_BASIC_LAZY_H -#include #include +#include +#include #include "swift/Basic/Malloc.h" #include "swift/Basic/type_traits.h" @@ -33,7 +34,7 @@ namespace swift { template > class LazyValue { Initializer Init; - llvm::Optional Value; + std::optional Value; public: LazyValue(Initializer Init) : Init(Init){}; diff --git a/include/swift/Basic/MultiMapCache.h b/include/swift/Basic/MultiMapCache.h index e72d61050fa..98ea59ccf35 100644 --- a/include/swift/Basic/MultiMapCache.h +++ b/include/swift/Basic/MultiMapCache.h @@ -14,11 +14,10 @@ #define SWIFT_BASIC_MULTIMAPCACHE_H #include "swift/Basic/LLVM.h" +#include "swift/Basic/STLExtras.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/Optional.h" -#include "llvm/ADT/None.h" -#include "swift/Basic/STLExtras.h" +#include namespace swift { @@ -37,7 +36,7 @@ namespace swift { template < typename KeyTy, typename ValueTy, typename MapTy = - llvm::DenseMap>>, + llvm::DenseMap>>, typename VectorTy = std::vector, typename VectorTyImpl = VectorTy> class MultiMapCache { std::function function; @@ -59,8 +58,8 @@ public: bool empty() const { return valueToDataOffsetIndexMap.empty(); } unsigned size() const { return valueToDataOffsetIndexMap.size(); } - llvm::Optional> get(const KeyTy &key) { - auto iter = valueToDataOffsetIndexMap.try_emplace(key, llvm::None); + std::optional> get(const KeyTy &key) { + auto iter = valueToDataOffsetIndexMap.try_emplace(key, std::nullopt); // If we already have a cached value, just return the cached value. if (!iter.second) { @@ -82,7 +81,7 @@ public: // We assume that constructValuesForKey /only/ inserts to the end of data // and does not inspect any other values in the data array. if (!function(key, data)) { - return llvm::None; + return std::nullopt; } // Otherwise, compute our length, compute our initial ArrayRef, @@ -98,7 +97,7 @@ template using SmallMultiMapCache = MultiMapCache>, 8>, + KeyTy, std::optional>, 8>, SmallVector, SmallVectorImpl>; } // namespace swift diff --git a/include/swift/Basic/OptionSet.h b/include/swift/Basic/OptionSet.h index 57f228846f1..b113dd260df 100644 --- a/include/swift/Basic/OptionSet.h +++ b/include/swift/Basic/OptionSet.h @@ -17,11 +17,10 @@ #ifndef SWIFT_BASIC_OPTIONSET_H #define SWIFT_BASIC_OPTIONSET_H -#include "llvm/ADT/None.h" - -#include #include #include +#include +#include namespace swift { /// The Swift standard library also has an `OptionSet` type that is imported @@ -59,7 +58,7 @@ public: constexpr OptionSet() : Storage() {} /// Create an empty option set. - constexpr OptionSet(llvm::NoneType) : Storage() {} + constexpr OptionSet(std::nullopt_t) : Storage() {} /// Create an option set with only the given option set. constexpr OptionSet(Flags flag) : Storage(static_cast(flag)) {} diff --git a/include/swift/Basic/OptionalEnum.h b/include/swift/Basic/OptionalEnum.h index fe5c963a64c..ac52039bad1 100644 --- a/include/swift/Basic/OptionalEnum.h +++ b/include/swift/Basic/OptionalEnum.h @@ -35,7 +35,7 @@ namespace swift { OptionalEnum() : Storage(0) { } /// Construct an empty instance. - /*implicit*/ OptionalEnum(llvm::NoneType) : OptionalEnum() {} + /*implicit*/ OptionalEnum(std::nullopt_t) : OptionalEnum() {} /// Construct an instance containing a value of type \c T constructed with /// the given argument. diff --git a/include/swift/Basic/ParseableOutput.h b/include/swift/Basic/ParseableOutput.h index 86825c54130..4247b1b0972 100644 --- a/include/swift/Basic/ParseableOutput.h +++ b/include/swift/Basic/ParseableOutput.h @@ -65,7 +65,7 @@ void emitFinishedMessage(raw_ostream &os, StringRef Name, /// Emits a "signalled" message to the given stream. void emitSignalledMessage(raw_ostream &os, StringRef Name, StringRef ErrorMsg, - StringRef Output, llvm::Optional Signal, + StringRef Output, std::optional Signal, int64_t Pid, sys::TaskProcessInformation ProcInfo); /// Emits a "skipped" message to the given stream. diff --git a/include/swift/Basic/Platform.h b/include/swift/Basic/Platform.h index 96bbab4dbff..6eff7622ea2 100644 --- a/include/swift/Basic/Platform.h +++ b/include/swift/Basic/Platform.h @@ -16,8 +16,8 @@ #include "swift/Basic/LLVM.h" #include "swift/Config.h" #include "clang/Basic/DarwinSDKInfo.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/StringRef.h" +#include namespace llvm { class Triple; @@ -58,7 +58,7 @@ namespace swift { /// Returns the VersionTuple at which Swift first became available for the OS /// represented by `triple`. - const llvm::Optional + const std::optional minimumAvailableOSVersionForTriple(const llvm::Triple &triple); /// Returns true if the given triple represents an OS that has all the @@ -107,7 +107,7 @@ namespace swift { /// Get the Swift runtime version to deploy back to, given a deployment target expressed as an /// LLVM target triple. - llvm::Optional + std::optional getSwiftRuntimeCompatibilityVersionForTarget(const llvm::Triple &Triple); /// Retrieve the target SDK version for the given SDKInfo and target triple. diff --git a/include/swift/Basic/PlaygroundOption.h b/include/swift/Basic/PlaygroundOption.h index 720739f3d1c..33a71afce5e 100644 --- a/include/swift/Basic/PlaygroundOption.h +++ b/include/swift/Basic/PlaygroundOption.h @@ -13,9 +13,9 @@ #ifndef SWIFT_BASIC_PLAYGROUND_OPTIONS_H #define SWIFT_BASIC_PLAYGROUND_OPTIONS_H -#include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/StringRef.h" +#include namespace swift { @@ -40,7 +40,7 @@ constexpr unsigned numPlaygroundOptions() { llvm::StringRef getPlaygroundOptionName(PlaygroundOption option); /// Get the playground option that corresponds to a given name, if there is one. -llvm::Optional getPlaygroundOption(llvm::StringRef name); +std::optional getPlaygroundOption(llvm::StringRef name); /// Set of enabled playground options. typedef llvm::SmallSet PlaygroundOptionSet; diff --git a/include/swift/Basic/PointerIntEnum.h b/include/swift/Basic/PointerIntEnum.h index cebca9f00db..b785e73fca2 100644 --- a/include/swift/Basic/PointerIntEnum.h +++ b/include/swift/Basic/PointerIntEnum.h @@ -14,12 +14,12 @@ #define SWIFT_BASIC_POINTERINTENUM_H #include "swift/Basic/LLVM.h" -#include "llvm/ADT/Optional.h" #include "llvm/Support/PointerLikeTypeTraits.h" #include #include #include #include +#include #include #include @@ -185,9 +185,9 @@ public: /// \returns the kind of the enum if the enum is valid. Returns None if the /// enum is invalid. - llvm::Optional getKind() const { + std::optional getKind() const { if (!isValid()) - return llvm::None; + return std::nullopt; // Check if the bottom pointer bits are all not set. If that is true then we // know that we have a pointer kind. diff --git a/include/swift/Basic/Program.h b/include/swift/Basic/Program.h index 3571cd5c94a..bfe2f93ee87 100644 --- a/include/swift/Basic/Program.h +++ b/include/swift/Basic/Program.h @@ -14,11 +14,10 @@ #define SWIFT_BASIC_PROGRAM_H #include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/None.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/ErrorOr.h" #include "llvm/Support/Program.h" +#include namespace swift { @@ -61,7 +60,7 @@ struct ChildProcessInfo { /// environment. llvm::ErrorOr ExecuteWithPipe( llvm::StringRef program, llvm::ArrayRef args, - llvm::Optional> env = llvm::None); + std::optional> env = std::nullopt); } // end namespace swift diff --git a/include/swift/Basic/STLExtras.h b/include/swift/Basic/STLExtras.h index a5d05f6775e..28a721317d0 100644 --- a/include/swift/Basic/STLExtras.h +++ b/include/swift/Basic/STLExtras.h @@ -17,8 +17,6 @@ #ifndef SWIFT_BASIC_STLEXTRAS_H #define SWIFT_BASIC_STLEXTRAS_H -#include "llvm/ADT/None.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/Casting.h" #include @@ -26,9 +24,9 @@ #include #include #include +#include #include #include -#include namespace swift { @@ -528,20 +526,20 @@ template struct DowncastAsOptional { template auto operator()(Superclass &value) const - -> llvm::Optional(value))> { + -> std::optional(value))> { if (auto result = llvm::dyn_cast(value)) return result; - return llvm::None; + return std::nullopt; } template auto operator()(const Superclass &value) const - -> llvm::Optional(value))> { + -> std::optional(value))> { if (auto result = llvm::dyn_cast(value)) return result; - return llvm::None; + return std::nullopt; } }; @@ -786,14 +784,14 @@ void emplace_back_all(VectorType &vector) {} /// Apply a function to the value if present; otherwise return None. template -auto transform(const llvm::Optional &value, +auto transform(const std::optional &value, const Function &operation) - -> llvm::Optional { + -> std::optional { if (value) { return operation(*value); } - return llvm::None; + return std::nullopt; } } // end namespace swift diff --git a/include/swift/Basic/SourceManager.h b/include/swift/Basic/SourceManager.h index 9c906f6cb47..fec88a8ef52 100644 --- a/include/swift/Basic/SourceManager.h +++ b/include/swift/Basic/SourceManager.h @@ -18,10 +18,9 @@ #include "clang/Basic/FileManager.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseSet.h" -#include "llvm/ADT/None.h" -#include "llvm/ADT/Optional.h" #include "llvm/Support/SourceMgr.h" #include +#include #include namespace swift { @@ -137,14 +136,14 @@ private: /// The last buffer we looked in. This acts as a one-element MRU cache for /// lookups based on source locations. - llvm::Optional lastBufferID; + std::optional lastBufferID; }; /// The cache that's used to quickly map a source location to a particular /// buffer ID. mutable BufferLocCache LocCache; - llvm::Optional findBufferContainingLocInternal(SourceLoc Loc) const; + std::optional findBufferContainingLocInternal(SourceLoc Loc) const; public: SourceManager(llvm::IntrusiveRefCntPtr FS = @@ -210,7 +209,7 @@ public: bool hasGeneratedSourceInfo(unsigned bufferID); /// Retrieve the generated source information for the given buffer. - llvm::Optional + std::optional getGeneratedSourceInfo(unsigned bufferID) const; /// Retrieve the list of ancestors of the given source buffer, starting with @@ -344,7 +343,7 @@ public: /// Returns a buffer ID for a previously added buffer with the given /// buffer identifier, or None if there is no such buffer. - llvm::Optional + std::optional getIDForBufferIdentifier(StringRef BufIdentifier) const; /// Returns the identifier for the buffer with the given ID. @@ -436,7 +435,7 @@ public: StringRef getEntireTextForBuffer(unsigned BufferID) const; StringRef extractText(CharSourceRange Range, - llvm::Optional BufferID = llvm::None) const; + std::optional BufferID = std::nullopt) const; llvm::SMDiagnostic GetMessage(SourceLoc Loc, llvm::SourceMgr::DiagKind Kind, const Twine &Msg, @@ -449,15 +448,15 @@ public: /// Translate line and column pair to the offset. /// If the column number is the maximum unsinged int, return the offset of the end of the line. - llvm::Optional resolveFromLineCol(unsigned BufferId, unsigned Line, - unsigned Col) const; + std::optional resolveFromLineCol(unsigned BufferId, unsigned Line, + unsigned Col) const; /// Translate the end position of the given line to the offset. - llvm::Optional resolveOffsetForEndOfLine(unsigned BufferId, - unsigned Line) const; + std::optional resolveOffsetForEndOfLine(unsigned BufferId, + unsigned Line) const; /// Get the length of the line - llvm::Optional getLineLength(unsigned BufferId, unsigned Line) const; + std::optional getLineLength(unsigned BufferId, unsigned Line) const; SourceLoc getLocForLineCol(unsigned BufferId, unsigned Line, unsigned Col) const { auto Offset = resolveFromLineCol(BufferId, Line, Col); diff --git a/include/swift/Basic/Statistic.h b/include/swift/Basic/Statistic.h index 20d9ac9bf16..83711f76be4 100644 --- a/include/swift/Basic/Statistic.h +++ b/include/swift/Basic/Statistic.h @@ -13,11 +13,11 @@ #ifndef SWIFT_BASIC_STATISTIC_H #define SWIFT_BASIC_STATISTIC_H -#include "llvm/ADT/Optional.h" +#include "swift/Basic/LLVM.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/Statistic.h" #include "llvm/Support/Timer.h" -#include "swift/Basic/LLVM.h" +#include #include #include @@ -157,10 +157,10 @@ private: SourceManager *SourceMgr; clang::SourceManager *ClangSourceMgr; - llvm::Optional DriverCounters; - llvm::Optional FrontendCounters; - llvm::Optional LastTracedFrontendCounters; - llvm::Optional> FrontendStatsEvents; + std::optional DriverCounters; + std::optional FrontendCounters; + std::optional LastTracedFrontendCounters; + std::optional> FrontendStatsEvents; // These are unique_ptr so we can use incomplete types here. std::unique_ptr RecursiveTimers; diff --git a/include/swift/Basic/StringExtras.h b/include/swift/Basic/StringExtras.h index affe162b9e0..2d0e8e4eb75 100644 --- a/include/swift/Basic/StringExtras.h +++ b/include/swift/Basic/StringExtras.h @@ -20,7 +20,6 @@ #include "swift/Basic/LLVM.h" #include "swift/Basic/OptionSet.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" @@ -28,6 +27,7 @@ #include "llvm/ADT/Twine.h" #include "llvm/Support/Allocator.h" #include +#include #include namespace swift { @@ -351,12 +351,12 @@ struct OmissionTypeName { /// Construct a type name. OmissionTypeName(StringRef name = StringRef(), - OmissionTypeOptions options = llvm::None, + OmissionTypeOptions options = std::nullopt, StringRef collectionElement = StringRef()) : Name(name), CollectionElement(collectionElement), Options(options) {} /// Construct a type name. - OmissionTypeName(const char *name, OmissionTypeOptions options = llvm::None, + OmissionTypeName(const char *name, OmissionTypeOptions options = std::nullopt, StringRef collectionElement = StringRef()) : Name(name), CollectionElement(collectionElement), Options(options) {} @@ -466,12 +466,12 @@ bool omitNeedlessWords(StringRef &baseName, MutableArrayRef argNames, ArrayRef paramTypes, bool returnsSelf, bool isProperty, const InheritedNameSet *allPropertyNames, - llvm::Optional completionHandlerIndex, - llvm::Optional completionHandlerName, + std::optional completionHandlerIndex, + std::optional completionHandlerName, StringScratchSpace &scratch); /// If the name has a completion-handler suffix, strip off that suffix. -llvm::Optional stripWithCompletionHandlerSuffix(StringRef name); +std::optional stripWithCompletionHandlerSuffix(StringRef name); /// Represents a string that can be efficiently retrieved either as a StringRef /// or as a null-terminated C string. diff --git a/include/swift/Basic/SuccessorMap.h b/include/swift/Basic/SuccessorMap.h index bead53ba4dd..dee98df3ecf 100644 --- a/include/swift/Basic/SuccessorMap.h +++ b/include/swift/Basic/SuccessorMap.h @@ -25,9 +25,9 @@ #include "swift/Basic/Debug.h" #include "swift/Basic/LLVM.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/raw_ostream.h" +#include namespace swift { @@ -159,7 +159,7 @@ public: void validate() const { #ifndef NDEBUG if (Root) - validateNode(Root, llvm::None, llvm::None); + validateNode(Root, std::nullopt, std::nullopt); #endif } @@ -369,8 +369,8 @@ private: /// Validate that the node is well-formed and that all of its keys /// (and those of its children) fall (non-inclusively) between /// lowerBound and upperBound-1. - static void validateNode(Node *node, llvm::Optional lowerBound, - llvm::Optional upperBound) { + static void validateNode(Node *node, std::optional lowerBound, + std::optional upperBound) { // The node cannot have an empty key range. assert(Traits::precedes(node->Begin, node->End)); diff --git a/include/swift/Basic/TargetInfo.h b/include/swift/Basic/TargetInfo.h index c43fabe96e5..7344f92ae0d 100644 --- a/include/swift/Basic/TargetInfo.h +++ b/include/swift/Basic/TargetInfo.h @@ -19,7 +19,7 @@ #include "swift/Basic/LLVM.h" -#include "llvm/ADT/Optional.h" +#include namespace llvm { class Triple; @@ -34,7 +34,7 @@ void printTargetInfo(const CompilerInvocation &invocation, llvm::raw_ostream &out); void printTripleInfo(const llvm::Triple &triple, - llvm::Optional runtimeVersion, + std::optional runtimeVersion, llvm::raw_ostream &out); } // namespace targetinfo } // namespace swift diff --git a/include/swift/Basic/TaskQueue.h b/include/swift/Basic/TaskQueue.h index 9c813e01f3e..758815601be 100644 --- a/include/swift/Basic/TaskQueue.h +++ b/include/swift/Basic/TaskQueue.h @@ -84,7 +84,7 @@ private: // the process identifier of the operating system ProcessId OSPid; // usage information about the process, if available - llvm::Optional ProcessUsage; + std::optional ProcessUsage; public: TaskProcessInformation(ProcessId Pid, uint64_t utime, uint64_t stime, @@ -92,12 +92,12 @@ public: : OSPid(Pid), ProcessUsage(ResourceUsage(utime, stime, maxrss)) {} TaskProcessInformation(ProcessId Pid) - : OSPid(Pid), ProcessUsage(llvm::None) {} + : OSPid(Pid), ProcessUsage(std::nullopt) {} #if defined(HAVE_GETRUSAGE) && !defined(__HAIKU__) TaskProcessInformation(ProcessId Pid, struct rusage Usage); #endif // defined(HAVE_GETRUSAGE) && !defined(__HAIKU__) - llvm::Optional getResourceUsage() { return ProcessUsage; } + std::optional getResourceUsage() { return ProcessUsage; } virtual ~TaskProcessInformation() = default; virtual void provideMapping(json::Output &out); }; @@ -176,7 +176,7 @@ public: /// should proceed using TaskSignalledCallback = std::function Signal, + void *Context, std::optional Signal, TaskProcessInformation ProcInfo)>; #pragma clang diagnostic pop @@ -205,7 +205,7 @@ public: /// \param Context an optional context which will be associated with the task /// \param SeparateErrors Controls whether error output is reported separately virtual void addTask(const char *ExecPath, ArrayRef Args, - ArrayRef Env = llvm::None, + ArrayRef Env = std::nullopt, void *Context = nullptr, bool SeparateErrors = false); /// Synchronously executes the tasks in the TaskQueue. @@ -240,8 +240,8 @@ class DummyTaskQueue : public TaskQueue { bool SeparateErrors; DummyTask(const char *ExecPath, ArrayRef Args, - ArrayRef Env = llvm::None, void *Context = nullptr, - bool SeparateErrors = false) + ArrayRef Env = std::nullopt, + void *Context = nullptr, bool SeparateErrors = false) : ExecPath(ExecPath), Args(Args), Env(Env), Context(Context), SeparateErrors(SeparateErrors) {} }; @@ -254,7 +254,7 @@ public: virtual ~DummyTaskQueue(); void addTask(const char *ExecPath, ArrayRef Args, - ArrayRef Env = llvm::None, + ArrayRef Env = std::nullopt, void *Context = nullptr, bool SeparateErrors = false) override; bool diff --git a/include/swift/Basic/TypeID.h b/include/swift/Basic/TypeID.h index 35b9104f790..30fbfbd6137 100644 --- a/include/swift/Basic/TypeID.h +++ b/include/swift/Basic/TypeID.h @@ -21,11 +21,11 @@ // NOTE: Most of these includes are for CTypeIDZone.def and DefineTypeIDZone.h. #include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/TinyPtrVector.h" #include #include +#include #include #include diff --git a/include/swift/Basic/UUID.h b/include/swift/Basic/UUID.h index d52d613d4c1..e10888b72e4 100644 --- a/include/swift/Basic/UUID.h +++ b/include/swift/Basic/UUID.h @@ -20,9 +20,9 @@ #include "swift/Basic/LLVM.h" #include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/Optional.h" #include "llvm/Support/raw_ostream.h" #include +#include namespace swift { @@ -65,7 +65,7 @@ public: static UUID fromTime() { return UUID(FromTime); } /// Parse a UUID from a C string. - static llvm::Optional fromString(const char *s); + static std::optional fromString(const char *s); /// Convert a UUID to its string representation. void toString(llvm::SmallVectorImpl &out) const; diff --git a/include/swift/Basic/Version.h b/include/swift/Basic/Version.h index 46e98b64621..c26fd2a17a6 100644 --- a/include/swift/Basic/Version.h +++ b/include/swift/Basic/Version.h @@ -19,13 +19,12 @@ #ifndef SWIFT_BASIC_VERSION_H #define SWIFT_BASIC_VERSION_H - #include "swift/Basic/LLVM.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/VersionTuple.h" #include +#include #include namespace swift { @@ -105,7 +104,7 @@ public: /// support for. It's also common for valid versions to produce a different /// result; for example "-swift-version 3" at one point instructed the /// compiler to act as if it is version 3.1. - llvm::Optional getEffectiveLanguageVersion() const; + std::optional getEffectiveLanguageVersion() const; /// Whether this version is greater than or equal to the given major version /// number. diff --git a/include/swift/ClangImporter/ClangImporter.h b/include/swift/ClangImporter/ClangImporter.h index 6eeeee3946e..df75a57657f 100644 --- a/include/swift/ClangImporter/ClangImporter.h +++ b/include/swift/ClangImporter/ClangImporter.h @@ -112,7 +112,7 @@ public: /// Perform a qualified lookup of a Clang type with this name. /// \param kind Only return results with this type kind. /// \param inModule only return results from this module. - virtual void lookupValue(StringRef name, llvm::Optional kind, + virtual void lookupValue(StringRef name, std::optional kind, StringRef inModule, SmallVectorImpl &results) {} /// vtable anchor. @@ -514,7 +514,7 @@ public: /// to import said decl then return nullptr. /// Otherwise, if we have never encountered this decl previously then return /// None. - llvm::Optional importDeclCached(const clang::NamedDecl *ClangDecl); + std::optional importDeclCached(const clang::NamedDecl *ClangDecl); // Returns true if it is expected that the macro is ignored. bool shouldIgnoreMacro(StringRef Name, const clang::MacroInfo *Macro); @@ -550,7 +550,7 @@ public: const clang::NamedDecl *D, clang::DeclarationName givenName = clang::DeclarationName()) override; - llvm::Optional + std::optional importFunctionReturnType(const clang::FunctionDecl *clangDecl, DeclContext *dc) override; @@ -558,10 +558,10 @@ public: VarDecl *swiftDecl, DeclContext *dc) override; - llvm::Optional + std::optional getOrCreatePCH(const ClangImporterOptions &ImporterOptions, StringRef SwiftPCHHash, bool Cached); - llvm::Optional + std::optional /// \param isExplicit true if the PCH filename was passed directly /// with -import-objc-header option. getPCHFilename(const ClangImporterOptions &ImporterOptions, @@ -657,7 +657,7 @@ bool isCxxStdModule(const clang::Module *module); /// Returns the pointee type if the given type is a C++ `const` /// reference type, `None` otherwise. -llvm::Optional +std::optional getCxxReferencePointeeTypeOrNone(const clang::Type *type); /// Returns true if the given type is a C++ `const` reference type. diff --git a/include/swift/ClangImporter/ClangImporterRequests.h b/include/swift/ClangImporter/ClangImporterRequests.h index 8e3a3c67201..cbed6dd3a70 100644 --- a/include/swift/ClangImporter/ClangImporterRequests.h +++ b/include/swift/ClangImporter/ClangImporterRequests.h @@ -306,7 +306,7 @@ private: public: // Separate caching. bool isCached() const { return true; } - llvm::Optional getCachedResult() const; + std::optional getCachedResult() const; void cacheResult(ObjCInterfaceAndImplementation value) const; }; diff --git a/include/swift/ClangImporter/ClangModule.h b/include/swift/ClangImporter/ClangModule.h index ccbb1588a11..470c7b481f4 100644 --- a/include/swift/ClangImporter/ClangModule.h +++ b/include/swift/ClangImporter/ClangModule.h @@ -37,7 +37,7 @@ class ClangModuleUnit final : public LoadedFile { ClangImporter::Implementation &owner; const clang::Module *clangModule; llvm::PointerIntPair overlayModule; - mutable llvm::Optional> importedModulesForLookup; + mutable std::optional> importedModulesForLookup; /// The metadata of the underlying Clang module. clang::ASTSourceDescriptor ASTSourceDescriptor; @@ -126,7 +126,7 @@ public: /// Returns the ASTSourceDescriptor of the associated Clang module if one /// exists. - llvm::Optional getASTSourceDescriptor() const; + std::optional getASTSourceDescriptor() const; virtual StringRef getModuleDefiningPath() const override; diff --git a/include/swift/Demangling/ManglingUtils.h b/include/swift/Demangling/ManglingUtils.h index dd4d5362ff0..7c20ccd00d8 100644 --- a/include/swift/Demangling/ManglingUtils.h +++ b/include/swift/Demangling/ManglingUtils.h @@ -13,10 +13,10 @@ #ifndef SWIFT_DEMANGLING_MANGLINGUTILS_H #define SWIFT_DEMANGLING_MANGLINGUTILS_H -#include "llvm/ADT/Optional.h" -#include "llvm/ADT/StringRef.h" #include "swift/Demangling/NamespaceMacros.h" #include "swift/Demangling/Punycode.h" +#include "llvm/ADT/StringRef.h" +#include namespace swift { namespace Mangle { @@ -104,8 +104,8 @@ std::string translateOperator(StringRef Op); /// \param allowConcurrencyManglings When true, allows the standard /// substitutions for types in the _Concurrency module that were introduced in /// Swift 5.5. -llvm::Optional getStandardTypeSubst( - StringRef TypeName, bool allowConcurrencyManglings); +std::optional getStandardTypeSubst(StringRef TypeName, + bool allowConcurrencyManglings); /// Mangles an identifier using a generic Mangler class. /// diff --git a/include/swift/Demangling/TypeDecoder.h b/include/swift/Demangling/TypeDecoder.h index 7c5bc8e5b98..339faaec0e1 100644 --- a/include/swift/Demangling/TypeDecoder.h +++ b/include/swift/Demangling/TypeDecoder.h @@ -32,10 +32,9 @@ #include "swift/Strings.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/None.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/StringSwitch.h" +#include #include namespace swift { @@ -133,7 +132,7 @@ public: using ConventionType = ImplParameterConvention; using OptionsType = ImplParameterInfoOptions; - static llvm::Optional + static std::optional getConventionFromString(StringRef conventionString) { if (conventionString == "@in") return ConventionType::Indirect_In; @@ -158,10 +157,10 @@ public: if (conventionString == "@pack_inout") return ConventionType::Pack_Inout; - return llvm::None; + return std::nullopt; } - static llvm::Optional + static std::optional getDifferentiabilityFromString(StringRef string) { OptionsType result; @@ -213,7 +212,7 @@ public: using ConventionType = ImplResultConvention; using OptionsType = ImplResultInfoOptions; - static llvm::Optional + static std::optional getConventionFromString(StringRef conventionString) { if (conventionString == "@out") return ConventionType::Indirect; @@ -228,10 +227,10 @@ public: if (conventionString == "@pack_out") return ConventionType::Pack; - return llvm::None; + return std::nullopt; } - static llvm::Optional + static std::optional getDifferentiabilityFromString(StringRef string) { OptionsType result; @@ -397,25 +396,25 @@ public: #if SWIFT_OBJC_INTEROP /// For a mangled node that refers to an Objective-C class or protocol, /// return the class or protocol name. -static inline llvm::Optional +static inline std::optional getObjCClassOrProtocolName(NodePointer node) { if (node->getKind() != Demangle::Node::Kind::Class && node->getKind() != Demangle::Node::Kind::Protocol) - return llvm::None; + return std::nullopt; if (node->getNumChildren() != 2) - return llvm::None; + return std::nullopt; // Check whether we have the __ObjC module. auto moduleNode = node->getChild(0); if (moduleNode->getKind() != Demangle::Node::Kind::Module || moduleNode->getText() != MANGLING_MODULE_OBJC) - return llvm::None; + return std::nullopt; // Check whether we have an identifier. auto nameNode = node->getChild(1); if (nameNode->getKind() != Demangle::Node::Kind::Identifier) - return llvm::None; + return std::nullopt; return nameNode->getText(); } @@ -470,7 +469,7 @@ void decodeRequirement(NodePointer node, return; auto kind = - llvm::StringSwitch>( + llvm::StringSwitch>( kindChild->getText()) .Case("U", LayoutConstraintKind::UnknownLayout) .Case("R", LayoutConstraintKind::RefCountedObject) @@ -482,7 +481,7 @@ void decodeRequirement(NodePointer node, .Cases("E", "e", LayoutConstraintKind::TrivialOfExactSize) .Cases("M", "m", LayoutConstraintKind::TrivialOfAtMostSize) .Case("S", LayoutConstraintKind::TrivialStride) - .Default(llvm::None); + .Default(std::nullopt); if (!kind) return; @@ -689,7 +688,7 @@ protected: case NodeKind::Metatype: case NodeKind::ExistentialMetatype: { unsigned i = 0; - llvm::Optional repr; + std::optional repr; // Handle lowered metatypes in a hackish way. If the representation // was not thin, force the resulting typeref to have a non-empty @@ -1079,7 +1078,7 @@ protected: } } - llvm::Optional> errorResult; + std::optional> errorResult; switch (errorResults.size()) { case 0: break; @@ -1464,8 +1463,8 @@ protected: } private: - template - llvm::Optional + template + std::optional decodeTypeSequenceElement(Demangle::NodePointer node, unsigned depth, Fn resultCallback) { if (node->getKind() == NodeKind::Type) @@ -1513,7 +1512,7 @@ private: resultCallback(elementType.getType()); } - return llvm::None; + return std::nullopt; } template @@ -1530,7 +1529,7 @@ private: return true; StringRef conventionString = node->getChild(0)->getText(); - llvm::Optional convention = + std::optional convention = T::getConventionFromString(conventionString); if (!convention) return true; @@ -1584,7 +1583,7 @@ private: return false; } - llvm::Optional + std::optional decodeGenericArgs(Demangle::NodePointer node, unsigned depth, llvm::SmallVectorImpl &args) { if (node->getKind() != NodeKind::TypeList) @@ -1597,10 +1596,10 @@ private: return *paramType.getError(); args.push_back(paramType.getType()); } - return llvm::None; + return std::nullopt; } - llvm::Optional + std::optional decodeMangledTypeDecl(Demangle::NodePointer node, unsigned depth, BuiltTypeDecl &typeDecl, BuiltType &parent, bool &typeAlias) { @@ -1657,7 +1656,7 @@ private: if (!typeDecl) return TypeLookupError("Failed to create type decl"); - return llvm::None; + return std::nullopt; } BuiltProtocolDecl decodeMangledProtocolType(Demangle::NodePointer node, @@ -1681,12 +1680,12 @@ private: return Builder.createProtocolDecl(node); } - llvm::Optional decodeMangledFunctionInputType( + std::optional decodeMangledFunctionInputType( Demangle::NodePointer node, unsigned depth, llvm::SmallVectorImpl> ¶ms, bool &hasParamFlags) { if (depth > TypeDecoder::MaxDepth) - return llvm::None; + return std::nullopt; // Look through a couple of sugar nodes. if (node->getKind() == NodeKind::Type || @@ -1697,7 +1696,7 @@ private: auto decodeParamTypeAndFlags = [&](Demangle::NodePointer typeNode, - FunctionParam ¶m) -> llvm::Optional { + FunctionParam ¶m) -> std::optional { Demangle::NodePointer node = typeNode; bool recurse = true; @@ -1760,9 +1759,9 @@ private: }; auto decodeParam = - [&](NodePointer paramNode) -> llvm::Optional { + [&](NodePointer paramNode) -> std::optional { if (paramNode->getKind() != NodeKind::TupleElement) - return llvm::None; + return std::nullopt; FunctionParam param; for (const auto &child : *paramNode) { @@ -1789,7 +1788,7 @@ private: } } - return llvm::None; + return std::nullopt; }; // Expand a single level of tuple. @@ -1801,7 +1800,7 @@ private: return *optError; } - return llvm::None; + return std::nullopt; } // Otherwise, handle the type as a single argument. @@ -1810,7 +1809,7 @@ private: if (optError) return *optError; - return llvm::None; + return std::nullopt; } }; diff --git a/include/swift/DependencyScan/ModuleDependencyScanner.h b/include/swift/DependencyScan/ModuleDependencyScanner.h index 9d5e1c8e1bd..887feaebc84 100644 --- a/include/swift/DependencyScan/ModuleDependencyScanner.h +++ b/include/swift/DependencyScan/ModuleDependencyScanner.h @@ -74,7 +74,7 @@ public: /// Identify the scanner invocation's main module's dependencies llvm::ErrorOr getMainModuleDependencyInfo( ModuleDecl *mainModule, - llvm::Optional tracker = llvm::None); + std::optional tracker = std::nullopt); /// Resolve module dependencies of the given module, computing a full /// transitive closure dependency graph. @@ -84,13 +84,13 @@ public: /// Query the module dependency info for the Clang module with the given name. /// Explicit by-name lookups are useful for batch mode scanning. - llvm::Optional + std::optional getNamedClangModuleDependencyInfo(StringRef moduleName, ModuleDependenciesCache &cache); /// Query the module dependency info for the Swift module with the given name. /// Explicit by-name lookups are useful for batch mode scanning. - llvm::Optional + std::optional getNamedSwiftModuleDependencyInfo(StringRef moduleName, ModuleDependenciesCache &cache); diff --git a/include/swift/Driver/Action.h b/include/swift/Driver/Action.h index eb141b9d6c3..16795530100 100644 --- a/include/swift/Driver/Action.h +++ b/include/swift/Driver/Action.h @@ -17,7 +17,6 @@ #include "swift/Basic/LLVM.h" #include "swift/Driver/Util.h" #include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/None.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/ADT/TinyPtrVector.h" #include "llvm/Support/Chrono.h" @@ -135,7 +134,7 @@ private: public: CompileJobAction(file_types::ID OutputType) - : JobAction(Action::Kind::CompileJob, llvm::None, OutputType) {} + : JobAction(Action::Kind::CompileJob, std::nullopt, OutputType) {} CompileJobAction(Action *Input, file_types::ID OutputType) : JobAction(Action::Kind::CompileJob, Input, OutputType) {} @@ -170,7 +169,7 @@ private: public: explicit InterpretJobAction() - : JobAction(Action::Kind::InterpretJob, llvm::None, + : JobAction(Action::Kind::InterpretJob, std::nullopt, file_types::TY_Nothing) {} static bool classof(const Action *A) { @@ -210,8 +209,7 @@ private: Mode RequestedMode; public: REPLJobAction(Mode mode) - : JobAction(Action::Kind::REPLJob, llvm::None, - file_types::TY_Nothing), + : JobAction(Action::Kind::REPLJob, std::nullopt, file_types::TY_Nothing), RequestedMode(mode) {} Mode getRequestedMode() const { return RequestedMode; } diff --git a/include/swift/Driver/Compilation.h b/include/swift/Driver/Compilation.h index 8a169e9cdd6..2ab1ba12cd1 100644 --- a/include/swift/Driver/Compilation.h +++ b/include/swift/Driver/Compilation.h @@ -177,11 +177,11 @@ private: /// Overrides parallelism level and \c BatchSizeLimit, sets exact /// count of batches, if in batch-mode. - const llvm::Optional BatchCount; + const std::optional BatchCount; /// Overrides maximum batch size, if in batch-mode and not overridden /// by \c BatchCount. - const llvm::Optional BatchSizeLimit; + const std::optional BatchSizeLimit; /// True if temporary files should not be deleted. const bool SaveTemps; @@ -246,8 +246,8 @@ public: size_t FilelistThreshold, bool EnableBatchMode = false, unsigned BatchSeed = 0, - llvm::Optional BatchCount = llvm::None, - llvm::Optional BatchSizeLimit = llvm::None, + std::optional BatchCount = std::nullopt, + std::optional BatchSizeLimit = std::nullopt, bool SaveTemps = false, bool ShowDriverTimeCompilation = false, std::unique_ptr Stats = nullptr, @@ -358,11 +358,9 @@ public: return BatchSeed; } - llvm::Optional getBatchCount() const { - return BatchCount; - } + std::optional getBatchCount() const { return BatchCount; } - llvm::Optional getBatchSizeLimit() const { return BatchSizeLimit; } + std::optional getBatchSizeLimit() const { return BatchSizeLimit; } /// Requests the path to a file containing all input source files. This can /// be shared across jobs. diff --git a/include/swift/Driver/Driver.h b/include/swift/Driver/Driver.h index a74d486e963..eb8843becda 100644 --- a/include/swift/Driver/Driver.h +++ b/include/swift/Driver/Driver.h @@ -97,7 +97,7 @@ public: /// The mode in which the driver should invoke the frontend. Mode CompilerMode = Mode::StandardCompile; - llvm::Optional RuntimeVariant = llvm::None; + std::optional RuntimeVariant = std::nullopt; /// The output type which should be used for compile actions. file_types::ID CompilerOutputType = file_types::ID::TY_INVALID; @@ -336,7 +336,7 @@ public: Compilation &C) const; /// Construct the OutputFileMap for the driver from the given arguments. - llvm::Optional + std::optional buildOutputFileMap(const llvm::opt::DerivedArgList &Args, StringRef workingDirectory) const; diff --git a/include/swift/Driver/Job.h b/include/swift/Driver/Job.h index 01598e2aeda..3a2c2851673 100644 --- a/include/swift/Driver/Job.h +++ b/include/swift/Driver/Job.h @@ -20,7 +20,6 @@ #include "swift/Driver/Action.h" #include "swift/Driver/Util.h" #include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/SmallVector.h" @@ -29,6 +28,7 @@ #include "llvm/Support/Chrono.h" #include "llvm/Support/Program.h" #include "llvm/Support/raw_ostream.h" +#include #include @@ -312,7 +312,7 @@ private: /// The path and argument string to use for the response file if the job's /// arguments should be passed using one. - llvm::Optional ResponseFile; + std::optional ResponseFile; /// The modification time of the main input file, if any. llvm::sys::TimePoint<> InputModTime = llvm::sys::TimePoint<>::max(); @@ -324,7 +324,7 @@ public: llvm::opt::ArgStringList Arguments, EnvironmentVector ExtraEnvironment = {}, std::vector Infos = {}, - llvm::Optional ResponseFile = llvm::None) + std::optional ResponseFile = std::nullopt) : SourceAndCondition(&Source, Condition::Always), Inputs(std::move(Inputs)), Output(std::move(Output)), Executable(Executable), Arguments(std::move(Arguments)), @@ -436,7 +436,7 @@ public: llvm::opt::ArgStringList Arguments, EnvironmentVector ExtraEnvironment, std::vector Infos, ArrayRef Combined, Job::PID &NextQuasiPID, - llvm::Optional ResponseFile = llvm::None); + std::optional ResponseFile = std::nullopt); ArrayRef getCombinedJobs() const { return CombinedJobs; diff --git a/include/swift/Driver/ToolChain.h b/include/swift/Driver/ToolChain.h index e13906142d8..16631c703b8 100644 --- a/include/swift/Driver/ToolChain.h +++ b/include/swift/Driver/ToolChain.h @@ -248,7 +248,7 @@ protected: /// Gets the response file path and command line argument for an invocation /// if the tool supports response files and if the command line length would /// exceed system limits. - llvm::Optional + std::optional getResponseFileInfo(const Compilation &C, const char *executablePath, const InvocationInfo &invocationInfo, const JobContext &context) const; diff --git a/include/swift/Frontend/CASOutputBackends.h b/include/swift/Frontend/CASOutputBackends.h index fa21a7ec275..0ffba2624f4 100644 --- a/include/swift/Frontend/CASOutputBackends.h +++ b/include/swift/Frontend/CASOutputBackends.h @@ -30,7 +30,7 @@ protected: llvm::Expected> createFileImpl(llvm::StringRef ResolvedPath, - llvm::Optional Config) override; + std::optional Config) override; virtual llvm::Error storeImpl(llvm::StringRef Path, llvm::StringRef Bytes, unsigned InputIndex, file_types::ID OutputKind); diff --git a/include/swift/Frontend/Frontend.h b/include/swift/Frontend/Frontend.h index 58f76a9a06b..227efa203f3 100644 --- a/include/swift/Frontend/Frontend.h +++ b/include/swift/Frontend/Frontend.h @@ -237,7 +237,7 @@ public: /// and SDK version. This function is also used by LLDB. static std::string computePrebuiltCachePath(StringRef RuntimeResourcePath, llvm::Triple target, - llvm::Optional sdkVer); + std::optional sdkVer); /// If we haven't explicitly passed -prebuilt-module-cache-path, set it to /// the default value of //prebuilt-modules. @@ -472,7 +472,7 @@ class CompilerInstance { /// the file buffer provided by CAS needs to outlive the SourceMgr. std::shared_ptr CAS; std::shared_ptr ResultCache; - llvm::Optional CompileJobBaseKey; + std::optional CompileJobBaseKey; SourceManager SourceMgr; DiagnosticEngine Diagnostics{SourceMgr}; @@ -571,7 +571,7 @@ public: std::shared_ptr getSharedCASInstance() const { return CAS; } - llvm::Optional getCompilerBaseKey() const { + std::optional getCompilerBaseKey() const { return CompileJobBaseKey; } CachingDiagnosticsProcessor *getCachingDiagnosticsProcessor() const { @@ -719,34 +719,33 @@ private: /// \return false if successful, true on error. bool setupDiagnosticVerifierIfNeeded(); - llvm::Optional setUpIDEInspectionTargetBuffer(); + std::optional setUpIDEInspectionTargetBuffer(); /// Find a buffer for a given input file and ensure it is recorded in /// SourceMgr, PartialModules, or InputSourceCodeBufferIDs as appropriate. /// Return the buffer ID if it is not already compiled, or None if so. /// Set failed on failure. - llvm::Optional getRecordedBufferID(const InputFile &input, - const bool shouldRecover, - bool &failed); + std::optional getRecordedBufferID(const InputFile &input, + const bool shouldRecover, + bool &failed); /// Given an input file, return a buffer to use for its contents, /// and a buffer for the corresponding module doc file if one exists. /// On failure, return a null pointer for the first element of the returned /// pair. - llvm::Optional - getInputBuffersIfPresent(const InputFile &input); + std::optional getInputBuffersIfPresent(const InputFile &input); /// Try to open the module doc file corresponding to the input parameter. /// Return None for error, nullptr if no such file exists, or the buffer if /// one was found. - llvm::Optional> + std::optional> openModuleDoc(const InputFile &input); /// Try to open the module source info file corresponding to the input parameter. /// Return None for error, nullptr if no such file exists, or the buffer if /// one was found. - llvm::Optional> + std::optional> openModuleSourceInfo(const InputFile &input); public: @@ -768,7 +767,7 @@ private: /// Creates a new source file for the main module. SourceFile *createSourceFileForMainModule(ModuleDecl *mod, SourceFileKind FileKind, - llvm::Optional BufferID, + std::optional BufferID, bool isMainBuffer = false) const; /// Creates all the files to be added to the main module, appending them to diff --git a/include/swift/Frontend/FrontendOptions.h b/include/swift/Frontend/FrontendOptions.h index 33e82c0632f..ea1cef2e377 100644 --- a/include/swift/Frontend/FrontendOptions.h +++ b/include/swift/Frontend/FrontendOptions.h @@ -20,9 +20,9 @@ #include "swift/Frontend/InputFile.h" #include "clang/CAS/CASOptions.h" #include "llvm/ADT/Hashing.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/StringMap.h" #include "llvm/MC/MCTargetOptions.h" +#include #include #include @@ -211,7 +211,7 @@ public: /// When true, emitted module files will always contain options for the /// debugger to use. When unset, the options will only be present if the /// module appears to not be a public module. - llvm::Optional SerializeOptionsForDebugging; + std::optional SerializeOptionsForDebugging; /// When true the debug prefix map entries will be applied to debugging /// options before serialization. These can be reconstructed at debug time by @@ -299,7 +299,7 @@ public: /// Specifies the collection mode for the intermodule dependency tracker. /// Note that if set, the dependency tracker will be enabled even if no /// output path is configured. - llvm::Optional IntermoduleDependencyTracking; + std::optional IntermoduleDependencyTracking; /// Should we emit the cType when printing @convention(c) or no? bool PrintFullConvention = false; @@ -326,7 +326,7 @@ public: /// The directory path we should use when print #include for the bridging header. /// By default, we include ImplicitObjCHeaderPath directly. - llvm::Optional BridgingHeaderDirForPrint; + std::optional BridgingHeaderDirForPrint; /// Disable implicitly-built Swift modules because they are explicitly /// built and provided to the compiler invocation. @@ -436,7 +436,7 @@ public: /// Indicates which declarations should be exposed in the generated clang /// header. - llvm::Optional ClangHeaderExposedDecls; + std::optional ClangHeaderExposedDecls; struct ClangHeaderExposedImportedModule { std::string moduleName; diff --git a/include/swift/Frontend/ModuleInterfaceLoader.h b/include/swift/Frontend/ModuleInterfaceLoader.h index f1f7b1beb15..b1dab630c14 100644 --- a/include/swift/Frontend/ModuleInterfaceLoader.h +++ b/include/swift/Frontend/ModuleInterfaceLoader.h @@ -239,11 +239,11 @@ public: // Explicitly-specified Swift module inputs struct ExplicitSwiftModuleInputInfo { ExplicitSwiftModuleInputInfo( - std::string modulePath, llvm::Optional moduleDocPath, - llvm::Optional moduleSourceInfoPath, - llvm::Optional> headerDependencyPaths, + std::string modulePath, std::optional moduleDocPath, + std::optional moduleSourceInfoPath, + std::optional> headerDependencyPaths, bool isFramework = false, bool isSystem = false, - llvm::Optional moduleCacheKey = llvm::None) + std::optional moduleCacheKey = std::nullopt) : modulePath(modulePath), moduleDocPath(moduleDocPath), moduleSourceInfoPath(moduleSourceInfoPath), headerDependencyPaths(headerDependencyPaths), isFramework(isFramework), @@ -251,17 +251,17 @@ struct ExplicitSwiftModuleInputInfo { // Path of the .swiftmodule file. std::string modulePath; // Path of the .swiftmoduledoc file. - llvm::Optional moduleDocPath; + std::optional moduleDocPath; // Path of the .swiftsourceinfo file. - llvm::Optional moduleSourceInfoPath; + std::optional moduleSourceInfoPath; // Paths of the precompiled header dependencies of this module. - llvm::Optional> headerDependencyPaths; + std::optional> headerDependencyPaths; // A flag that indicates whether this module is a framework bool isFramework = false; // A flag that indicates whether this module is a system module bool isSystem = false; // The cache key for clang module. - llvm::Optional moduleCacheKey; + std::optional moduleCacheKey; }; // Explicitly-specified Clang module inputs @@ -269,7 +269,7 @@ struct ExplicitClangModuleInputInfo { ExplicitClangModuleInputInfo( std::string moduleMapPath, std::string modulePath, bool isFramework = false, bool isSystem = false, - llvm::Optional moduleCacheKey = llvm::None) + std::optional moduleCacheKey = std::nullopt) : moduleMapPath(moduleMapPath), modulePath(modulePath), isFramework(isFramework), isSystem(isSystem), moduleCacheKey(moduleCacheKey) {} @@ -282,7 +282,7 @@ struct ExplicitClangModuleInputInfo { // A flag that indicates whether this module is a system module bool isSystem = false; // The cache key for clang module. - llvm::Optional moduleCacheKey; + std::optional moduleCacheKey; }; /// Parser of explicit module maps passed into the compiler. @@ -363,10 +363,9 @@ private: if (!mapNode) return true; StringRef moduleName; - llvm::Optional swiftModulePath, swiftModuleDocPath, - swiftModuleSourceInfoPath, swiftModuleCacheKey, - clangModuleCacheKey; - llvm::Optional> headerDependencyPaths; + std::optional swiftModulePath, swiftModuleDocPath, + swiftModuleSourceInfoPath, swiftModuleCacheKey, clangModuleCacheKey; + std::optional> headerDependencyPaths; std::string clangModuleMapPath = "", clangModulePath = ""; bool isFramework = false, isSystem = false; for (auto &entry : *mapNode) { @@ -631,7 +630,7 @@ struct SwiftInterfaceInfo { /// The tools version of the compiler (e.g. 5.8) that emitted the /// swiftinterface. This is extracted from the `CompilerVersion` string. - llvm::Optional CompilerToolsVersion; + std::optional CompilerToolsVersion; }; struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate { diff --git a/include/swift/IDE/APIDigesterData.h b/include/swift/IDE/APIDigesterData.h index 9b9ad0ed452..52427af6c8b 100644 --- a/include/swift/IDE/APIDigesterData.h +++ b/include/swift/IDE/APIDigesterData.h @@ -38,7 +38,7 @@ enum class SDKNodeKind: uint8_t { #include "DigesterEnums.def" }; -llvm::Optional parseSDKNodeKind(StringRef Content); +std::optional parseSDKNodeKind(StringRef Content); enum class NodeAnnotation: uint8_t{ #define NODE_ANNOTATION(NAME) NAME, @@ -265,8 +265,8 @@ struct TypeMemberDiffItem: public APIDiffItem { StringRef usr; StringRef newTypeName; StringRef newPrintedName; - llvm::Optional selfIndex; - llvm::Optional removedIndex; + std::optional selfIndex; + std::optional removedIndex; StringRef oldTypeName; StringRef oldPrintedName; private: @@ -278,10 +278,9 @@ public: public: TypeMemberDiffItem(StringRef usr, StringRef newTypeName, - StringRef newPrintedName, - llvm::Optional selfIndex, - llvm::Optional removedIndex, - StringRef oldTypeName, StringRef oldPrintedName) + StringRef newPrintedName, std::optional selfIndex, + std::optional removedIndex, StringRef oldTypeName, + StringRef oldPrintedName) : usr(usr), newTypeName(newTypeName), newPrintedName(newPrintedName), selfIndex(selfIndex), removedIndex(removedIndex), oldTypeName(oldTypeName), oldPrintedName(oldPrintedName), diff --git a/include/swift/IDE/AfterPoundExprCompletion.h b/include/swift/IDE/AfterPoundExprCompletion.h index c757244b085..93309390a6c 100644 --- a/include/swift/IDE/AfterPoundExprCompletion.h +++ b/include/swift/IDE/AfterPoundExprCompletion.h @@ -35,7 +35,7 @@ class AfterPoundExprCompletion : public TypeCheckCompletionCallback { CodeCompletionExpr *CompletionExpr; DeclContext *DC; - llvm::Optional ParentStmtKind; + std::optional ParentStmtKind; SmallVector Results; @@ -43,7 +43,7 @@ class AfterPoundExprCompletion : public TypeCheckCompletionCallback { public: AfterPoundExprCompletion(CodeCompletionExpr *CompletionExpr, DeclContext *DC, - llvm::Optional ParentStmtKind) + std::optional ParentStmtKind) : CompletionExpr(CompletionExpr), DC(DC), ParentStmtKind(ParentStmtKind) { } diff --git a/include/swift/IDE/ArgumentCompletion.h b/include/swift/IDE/ArgumentCompletion.h index 55656a728c1..cc1150d3723 100644 --- a/include/swift/IDE/ArgumentCompletion.h +++ b/include/swift/IDE/ArgumentCompletion.h @@ -42,7 +42,7 @@ class ArgumentTypeCheckCompletionCallback : public TypeCheckCompletionCallback { unsigned ArgIdx; /// The index of the parameter corresponding to the completion argument. - llvm::Optional ParamIdx; + std::optional ParamIdx; /// The indices of all params that were bound to non-synthesized /// arguments. Used so we don't suggest them even when the args are out of @@ -69,7 +69,7 @@ class ArgumentTypeCheckCompletionCallback : public TypeCheckCompletionCallback { /// The argument index of the first trailing closure. /// /// \c None if the call doesn't have a trailing closure. - llvm::Optional FirstTrailingClosureIndex; + std::optional FirstTrailingClosureIndex; /// Whether the surrounding context is async and thus calling async /// functions is supported. diff --git a/include/swift/IDE/CodeCompletionCache.h b/include/swift/IDE/CodeCompletionCache.h index 9a90a3f34cb..58fa5b6dbd5 100644 --- a/include/swift/IDE/CodeCompletionCache.h +++ b/include/swift/IDE/CodeCompletionCache.h @@ -85,7 +85,7 @@ public: ~CodeCompletionCache(); static ValueRefCntPtr createValue(); - llvm::Optional get(const Key &K); + std::optional get(const Key &K); void set(const Key &K, ValueRefCntPtr V) { setImpl(K, V, /*setChain*/ true); } private: @@ -107,10 +107,10 @@ public: OnDiskCodeCompletionCache(Twine cacheDirectory); ~OnDiskCodeCompletionCache(); - llvm::Optional get(const Key &K); + std::optional get(const Key &K); std::error_code set(const Key &K, ValueRefCntPtr V); - static llvm::Optional getFromFile(StringRef filename); + static std::optional getFromFile(StringRef filename); }; struct RequestedCachedModule { diff --git a/include/swift/IDE/CodeCompletionString.h b/include/swift/IDE/CodeCompletionString.h index 2ef1b7a03b9..bfb9e4fa087 100644 --- a/include/swift/IDE/CodeCompletionString.h +++ b/include/swift/IDE/CodeCompletionString.h @@ -16,12 +16,11 @@ #include "swift/Basic/Debug.h" #include "swift/Basic/LLVM.h" #include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/None.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/Error.h" #include "llvm/Support/TrailingObjects.h" +#include namespace swift { namespace ide { @@ -354,7 +353,7 @@ public: } StringRef getFirstTextChunk(bool includeLeadingPunctuation = false) const; - llvm::Optional + std::optional getFirstTextChunkIndex(bool includeLeadingPunctuation = false) const; /// Print a debug representation of the code completion string to \p OS. diff --git a/include/swift/IDE/CodeCompletionStringPrinter.h b/include/swift/IDE/CodeCompletionStringPrinter.h index cb8e6d5bb17..c5928861107 100644 --- a/include/swift/IDE/CodeCompletionStringPrinter.h +++ b/include/swift/IDE/CodeCompletionStringPrinter.h @@ -40,10 +40,10 @@ private: bool isInType() const { return TypeDepth > 0; } - llvm::Optional + std::optional getChunkKindForPrintNameContext(PrintNameContext context) const; - llvm::Optional + std::optional getChunkKindForStructureKind(PrintStructureKind Kind) const; void startNestedGroup(ChunkKind Kind); diff --git a/include/swift/IDE/CompletionLookup.h b/include/swift/IDE/CompletionLookup.h index 30d8e45ee93..f61df202dfe 100644 --- a/include/swift/IDE/CompletionLookup.h +++ b/include/swift/IDE/CompletionLookup.h @@ -166,7 +166,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer { /// Innermost method that the code completion point is in. const AbstractFunctionDecl *CurrentMethod = nullptr; - llvm::Optional ForcedSemanticContext = llvm::None; + std::optional ForcedSemanticContext = std::nullopt; bool IsUnresolvedMember = false; public: @@ -316,7 +316,7 @@ public: void addModuleName(ModuleDecl *MD, - llvm::Optional R = llvm::None); + std::optional R = std::nullopt); void addImportModuleNames(); @@ -360,7 +360,7 @@ public: void analyzeActorIsolation( const ValueDecl *VD, Type T, bool &implicitlyAsync, - llvm::Optional &NotRecommended); + std::optional &NotRecommended); void addVarDeclRef(const VarDecl *VD, DeclVisibilityKind Reason, DynamicLookupInfo dynamicLookupInfo); @@ -391,7 +391,7 @@ public: const AbstractFunctionDecl *AFD, bool forceAsync = false); - void addPoundAvailable(llvm::Optional ParentKind); + void addPoundAvailable(std::optional ParentKind); void addPoundSelector(bool needPound); @@ -401,11 +401,11 @@ public: void addSubscriptCallPattern( const AnyFunctionType *AFT, const SubscriptDecl *SD, - const llvm::Optional SemanticContext = llvm::None); + const std::optional SemanticContext = std::nullopt); void addFunctionCallPattern( const AnyFunctionType *AFT, const AbstractFunctionDecl *AFD = nullptr, - const llvm::Optional SemanticContext = llvm::None); + const std::optional SemanticContext = std::nullopt); bool isImplicitlyCurriedInstanceMethod(const AbstractFunctionDecl *FD); @@ -414,8 +414,8 @@ public: void addConstructorCall(const ConstructorDecl *CD, DeclVisibilityKind Reason, DynamicLookupInfo dynamicLookupInfo, - llvm::Optional BaseType, - llvm::Optional Result, bool IsOnType = true, + std::optional BaseType, + std::optional Result, bool IsOnType = true, Identifier addName = Identifier()); void addConstructorCallsForType(Type type, Identifier name, @@ -508,7 +508,7 @@ public: bool tryFunctionCallCompletions( Type ExprType, const ValueDecl *VD, - llvm::Optional SemanticContext = llvm::None); + std::optional SemanticContext = std::nullopt); bool tryModuleCompletions(Type ExprType, CodeCompletionFilter Filter); @@ -591,10 +591,9 @@ public: static bool canUseAttributeOnDecl(DeclAttrKind DAK, bool IsInSil, bool IsConcurrencyEnabled, - llvm::Optional DK, - StringRef Name); + std::optional DK, StringRef Name); - void getAttributeDeclCompletions(bool IsInSil, llvm::Optional DK); + void getAttributeDeclCompletions(bool IsInSil, std::optional DK); void getAttributeDeclParamCompletions(CustomSyntaxAttributeKind AttrKind, int ParamIndex, bool HasLabel); diff --git a/include/swift/IDE/IDEBridging.h b/include/swift/IDE/IDEBridging.h index 3b262937a6a..379783f82ec 100644 --- a/include/swift/IDE/IDEBridging.h +++ b/include/swift/IDE/IDEBridging.h @@ -17,8 +17,8 @@ #ifdef USED_IN_CPP_SOURCE #include "swift/Basic/SourceLoc.h" -#include "llvm/ADT/Optional.h" #include "llvm/CAS/CASReference.h" +#include #include #endif @@ -79,8 +79,8 @@ struct ResolvedLoc { std::vector labelRanges; /// The in index in `labelRanges` that belongs to the first trailing closure - /// or `llvm::None` if there is no trailing closure. - llvm::Optional firstTrailingLabel; + /// or `std::nullopt` if there is no trailing closure. + std::optional firstTrailingLabel; LabelRangeType labelType; @@ -91,7 +91,7 @@ struct ResolvedLoc { ResolvedLoc(swift::CharSourceRange range, std::vector labelRanges, - llvm::Optional firstTrailingLabel, + std::optional firstTrailingLabel, LabelRangeType labelType, bool isActive, ResolvedLocContext context); diff --git a/include/swift/IDE/ImportDepth.h b/include/swift/IDE/ImportDepth.h index c28a105660a..17e79598888 100644 --- a/include/swift/IDE/ImportDepth.h +++ b/include/swift/IDE/ImportDepth.h @@ -33,10 +33,10 @@ public: ImportDepth() = default; ImportDepth(ASTContext &context, const FrontendOptions &frontendOptions); - llvm::Optional lookup(StringRef module) { + std::optional lookup(StringRef module) { auto I = depths.find(module); if (I == depths.end()) - return llvm::None; + return std::nullopt; return I->getValue(); } }; diff --git a/include/swift/IDE/ModuleInterfacePrinting.h b/include/swift/IDE/ModuleInterfacePrinting.h index a8ce488bfab..fc51d5e287d 100644 --- a/include/swift/IDE/ModuleInterfacePrinting.h +++ b/include/swift/IDE/ModuleInterfacePrinting.h @@ -16,7 +16,7 @@ #include "swift/Basic/LLVM.h" #include "swift/Basic/OptionSet.h" -#include "llvm/ADT/Optional.h" +#include #include #include @@ -50,7 +50,7 @@ using ModuleTraversalOptions = OptionSet; void collectModuleGroups(ModuleDecl *M, SmallVectorImpl &Into); -llvm::Optional findGroupNameForUSR(ModuleDecl *M, StringRef USR); +std::optional findGroupNameForUSR(ModuleDecl *M, StringRef USR); bool printTypeInterface(ModuleDecl *M, Type Ty, ASTPrinter &Printer, std::string &TypeName, std::string &Error); diff --git a/include/swift/IDE/REPLCodeCompletion.h b/include/swift/IDE/REPLCodeCompletion.h index 8689fd45c41..083cbe8f154 100644 --- a/include/swift/IDE/REPLCodeCompletion.h +++ b/include/swift/IDE/REPLCodeCompletion.h @@ -69,7 +69,7 @@ private: std::vector CookedResults; std::string Prefix; - mutable llvm::Optional Root; + mutable std::optional Root; size_t CurrentCompletionIdx; public: diff --git a/include/swift/IDE/Utils.h b/include/swift/IDE/Utils.h index a823af60a30..e4714fccd74 100644 --- a/include/swift/IDE/Utils.h +++ b/include/swift/IDE/Utils.h @@ -113,7 +113,7 @@ std::unique_ptr replacePlaceholders(std::unique_ptr InputBuf, bool *HadPlaceholder = nullptr); -llvm::Optional> parseLineCol(StringRef LineCol); +std::optional> parseLineCol(StringRef LineCol); class XMLEscapingPrinter : public StreamPrinter { public: @@ -173,8 +173,8 @@ private: bool IsRef = true; Type Ty; Type ContainerType; - llvm::Optional> CustomAttrRef = - llvm::None; + std::optional> CustomAttrRef = + std::nullopt; bool IsKeywordArgument = false; /// It this is a ref, whether it is "dynamic". See \c ide::isDynamicRef. @@ -197,7 +197,7 @@ public: explicit ResolvedValueRefCursorInfo( SourceFile *SF, SourceLoc Loc, ValueDecl *ValueD, TypeDecl *CtorTyRef, ExtensionDecl *ExtTyRef, bool IsRef, Type Ty, Type ContainerType, - llvm::Optional> CustomAttrRef, + std::optional> CustomAttrRef, bool IsKeywordArgument, bool IsDynamic, SmallVector ReceiverTypes, SmallVector ShorthandShadowedDecls) @@ -241,7 +241,7 @@ public: ValueDecl *typeOrValue() { return CtorTyRef ? CtorTyRef : ValueD; } - llvm::Optional> + std::optional> getCustomAttrRef() const { return CustomAttrRef; } @@ -466,7 +466,7 @@ struct NoteRegion { unsigned StartColumn; unsigned EndLine; unsigned EndColumn; - llvm::Optional ArgIndex; + std::optional ArgIndex; }; struct Replacement { @@ -599,7 +599,7 @@ getCallArgInfo(SourceManager &SM, ArgumentList *Args, LabelRangeEndAt EndKind); // Get the ranges of argument labels from an Arg, either tuple or paren, and // the index of the first trailing closure argument, if any. This includes empty // ranges for any unlabelled arguments, including the first trailing closure. -std::pair, llvm::Optional> +std::pair, std::optional> getCallArgLabelRanges(SourceManager &SM, ArgumentList *Args, LabelRangeEndAt EndKind); diff --git a/include/swift/IDETool/IDEInspectionInstance.h b/include/swift/IDETool/IDEInspectionInstance.h index 00fae7514fc..0f3ab25f7f0 100644 --- a/include/swift/IDETool/IDEInspectionInstance.h +++ b/include/swift/IDETool/IDEInspectionInstance.h @@ -133,7 +133,7 @@ class IDEInspectionInstance { /// the first pass. /// Returns \c false if it fails to setup the \c CompilerInstance. void performNewOperation( - llvm::Optional ArgsHash, + std::optional ArgsHash, swift::CompilerInvocation &Invocation, llvm::IntrusiveRefCntPtr FileSystem, llvm::MemoryBuffer *ideInspectionTargetBuffer, unsigned int Offset, diff --git a/include/swift/IRGen/IRABIDetailsProvider.h b/include/swift/IRGen/IRABIDetailsProvider.h index b3edd7fc9a1..dc140577a91 100644 --- a/include/swift/IRGen/IRABIDetailsProvider.h +++ b/include/swift/IRGen/IRABIDetailsProvider.h @@ -19,11 +19,11 @@ #include "swift/IRGen/GenericRequirement.h" #include "clang/AST/CharUnits.h" #include "llvm/ADT/MapVector.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" #include #include +#include #include namespace swift { @@ -156,7 +156,7 @@ public: /// Returns lowered direct result details, or \c None if direct result is /// void. - llvm::Optional getDirectResultType() const; + std::optional getDirectResultType() const; /// Returns the number of indirect result values in this function signature. size_t getNumIndirectResultValues() const; @@ -206,12 +206,12 @@ public: /// Returns the function signature lowered to its C / LLVM - like /// representation, or \c None if such representation could not be computed. - llvm::Optional + std::optional getFunctionLoweredSignature(AbstractFunctionDecl *fd); /// Returns the size and alignment for the given type, or \c None if the type /// is not a fixed layout type. - llvm::Optional + std::optional getTypeSizeAlignment(const NominalTypeDecl *TD); /// An representation of a single type, or a C struct with multiple members @@ -278,14 +278,14 @@ public: } static MethodDispatchInfo indirectVTableStaticOffset( - size_t offset, llvm::Optional discriminator) { + size_t offset, std::optional discriminator) { return MethodDispatchInfo(Kind::IndirectVTableStaticOffset, offset, "", discriminator); } static MethodDispatchInfo indirectVTableRelativeOffset( size_t offset, std::string symbolName, - llvm::Optional discriminator) { + std::optional discriminator) { return MethodDispatchInfo(Kind::IndirectVTableRelativeOffset, offset, symbolName, discriminator); } @@ -302,7 +302,7 @@ public: assert(kind == Kind::IndirectVTableStaticOffset); return offset; } - llvm::Optional + std::optional getPointerAuthDiscriminator() const { assert(kind == Kind::IndirectVTableStaticOffset || kind == Kind::IndirectVTableRelativeOffset); @@ -330,17 +330,17 @@ public: private: MethodDispatchInfo( Kind kind, size_t offset, std::string symbolName = "", - llvm::Optional discriminator = llvm::None) + std::optional discriminator = std::nullopt) : kind(kind), offset(offset), symbolName(symbolName), discriminator(discriminator) {} Kind kind; size_t offset; std::string symbolName; - llvm::Optional discriminator; + std::optional discriminator; }; - llvm::Optional + std::optional getMethodDispatchInfo(const AbstractFunctionDecl *funcDecl); /// Returns the type of the base offset value located at the specific class diff --git a/include/swift/Localization/LocalizationFormat.h b/include/swift/Localization/LocalizationFormat.h index 6c276dc9251..78c6937e03e 100644 --- a/include/swift/Localization/LocalizationFormat.h +++ b/include/swift/Localization/LocalizationFormat.h @@ -19,7 +19,6 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/Hashing.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/Bitstream/BitstreamReader.h" @@ -30,6 +29,7 @@ #include "llvm/Support/raw_ostream.h" #include #include +#include #include #include #include diff --git a/include/swift/Markup/AST.h b/include/swift/Markup/AST.h index a0b2a5a70f1..c48e8fa6249 100644 --- a/include/swift/Markup/AST.h +++ b/include/swift/Markup/AST.h @@ -14,10 +14,10 @@ #define SWIFT_MARKUP_AST_H #include "swift/Markup/LineList.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/SetVector.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/TrailingObjects.h" +#include namespace swift { namespace markup { @@ -34,13 +34,13 @@ class LocalizationKeyField; /// The basic structure of a doc comment attached to a Swift /// declaration. struct CommentParts { - llvm::Optional Brief; + std::optional Brief; ArrayRef BodyNodes; ArrayRef ParamFields; - llvm::Optional ReturnsField; - llvm::Optional ThrowsField; + std::optional ReturnsField; + std::optional ThrowsField; llvm::SmallSetVector Tags; - llvm::Optional + std::optional LocalizationKeyField; bool isEmpty() const { @@ -556,14 +556,14 @@ class Image final : public InlineContent, // FIXME: Hyperlink destinations can't be wrapped - use a Line StringRef Destination; - llvm::Optional Title; + std::optional Title; - Image(StringRef Destination, llvm::Optional Title, + Image(StringRef Destination, std::optional Title, ArrayRef Children); public: static Image *create(MarkupContext &MC, StringRef Destination, - llvm::Optional Title, + std::optional Title, ArrayRef Children); StringRef getDestination() const { return Destination; } @@ -651,7 +651,7 @@ class ParamField final : public PrivateExtension, // Parameter fields can contain a substructure describing a // function or closure parameter. - llvm::Optional Parts; + std::optional Parts; ParamField(StringRef Name, ArrayRef Children); @@ -664,9 +664,7 @@ public: return Name; } - llvm::Optional getParts() const { - return Parts; - } + std::optional getParts() const { return Parts; } void setParts(CommentParts P) { Parts = P; diff --git a/include/swift/Parse/IDEInspectionCallbacks.h b/include/swift/Parse/IDEInspectionCallbacks.h index c9005a5dcdb..879e0763064 100644 --- a/include/swift/Parse/IDEInspectionCallbacks.h +++ b/include/swift/Parse/IDEInspectionCallbacks.h @@ -142,7 +142,7 @@ public: }; /// Set target decl for attribute if the CC token is in attribute of the decl. - virtual void setAttrTargetDeclKind(llvm::Optional DK) {} + virtual void setAttrTargetDeclKind(std::optional DK) {} /// Set that the code completion token occurred in a custom attribute. This /// allows us to type check the custom attribute even if it is not attached to @@ -262,10 +262,10 @@ public: /// index means that the completion is within the parentheses and is /// for a specific yield value. virtual void completeYieldStmt(CodeCompletionExpr *E, - llvm::Optional yieldIndex){}; + std::optional yieldIndex){}; virtual void completeAfterPoundExpr(CodeCompletionExpr *E, - llvm::Optional ParentKind){}; + std::optional ParentKind){}; virtual void completeAfterPoundDirective() {}; diff --git a/include/swift/Parse/Lexer.h b/include/swift/Parse/Lexer.h index 894d4d84a0b..998ebb39481 100644 --- a/include/swift/Parse/Lexer.h +++ b/include/swift/Parse/Lexer.h @@ -82,7 +82,7 @@ class Lexer { /// A queue of diagnostics to emit when a token is consumed. We want to queue /// them, as the parser may backtrack and re-lex a token. - llvm::Optional DiagQueue; + std::optional DiagQueue; using State = LexerState; @@ -249,11 +249,11 @@ public: /// If a lexer cut off point has been set returns the offset in the buffer at /// which lexing is being cut off. - llvm::Optional lexingCutOffOffset() const { + std::optional lexingCutOffOffset() const { if (LexerCutOffPoint) { return LexerCutOffPoint - BufferStart; } else { - return llvm::None; + return std::nullopt; } } diff --git a/include/swift/Parse/LexerState.h b/include/swift/Parse/LexerState.h index 31b7e272acd..049146c75ca 100644 --- a/include/swift/Parse/LexerState.h +++ b/include/swift/Parse/LexerState.h @@ -17,8 +17,8 @@ #ifndef SWIFT_LEXERSTATE_H #define SWIFT_LEXERSTATE_H -#include "llvm/ADT/Optional.h" #include "swift/Basic/SourceLoc.h" +#include namespace swift { class Lexer; diff --git a/include/swift/Parse/ParseVersion.h b/include/swift/Parse/ParseVersion.h index f366fe3ea76..477ac4c0ecb 100644 --- a/include/swift/Parse/ParseVersion.h +++ b/include/swift/Parse/ParseVersion.h @@ -34,14 +34,14 @@ public: /// \note This is \em only used for the string literal version, so it includes /// backwards-compatibility logic to convert it to something that can be /// compared with a modern SWIFT_COMPILER_VERSION. - static llvm::Optional + static std::optional parseCompilerVersionString(StringRef VersionString, SourceLoc Loc, DiagnosticEngine *Diags); /// Parse a generic version string of the format [0-9]+(.[0-9]+)* /// /// Version components can be any unsigned 64-bit number. - static llvm::Optional + static std::optional parseVersionString(StringRef VersionString, SourceLoc Loc, DiagnosticEngine *Diags); }; diff --git a/include/swift/Parse/Parser.h b/include/swift/Parse/Parser.h index 7b4067d4674..19dc5f5abdc 100644 --- a/include/swift/Parse/Parser.h +++ b/include/swift/Parse/Parser.h @@ -97,7 +97,7 @@ public: /// This is called when a source file is fully parsed. It returns the /// finalized vector of tokens, or \c None if the receiver isn't configured to /// record them. - virtual llvm::Optional> finalize() { return llvm::None; } + virtual std::optional> finalize() { return std::nullopt; } virtual ~ConsumeTokenReceiver() = default; }; @@ -139,7 +139,7 @@ public: /// The current token hash, or \c None if the parser isn't computing a hash /// for the token stream. - llvm::Optional CurrentTokenHash; + std::optional CurrentTokenHash; void recordTokenHash(const Token Tok) { if (!Tok.getText().empty()) @@ -311,7 +311,7 @@ public: /// The leading whitespace for this marker, if it has already been /// computed. - llvm::Optional LeadingWhitespace; + std::optional LeadingWhitespace; }; /// An RAII object that notes when we have seen a structure marker. @@ -434,7 +434,7 @@ public: DelayedTokenReceiver(ConsumeTokenReceiver *&receiver): savedConsumer(receiver, this) {} void receive(const Token &tok) override { delayedTokens.push_back(tok); } - llvm::Optional> finalize() override { + std::optional> finalize() override { llvm_unreachable("Cannot finalize a DelayedTokenReceiver"); } ~DelayedTokenReceiver() { @@ -720,7 +720,7 @@ public: /// \param DiagText name for the string literal in the diagnostic. /// \param AllowMultiline Whether the string literal can be a multiline string /// literal. - llvm::Optional + std::optional getStringLiteralIfNotInterpolated(SourceLoc Loc, StringRef DiagText, bool AllowMultiline); @@ -948,7 +948,7 @@ public: /// Parse the source file via the Swift Parser using the ASTGen library. void parseSourceFileViaASTGen(SmallVectorImpl &items, - llvm::Optional &transaction, + std::optional &transaction, bool suppressDiagnostics = false); /// Parse the top-level SIL decls into the SIL module. @@ -981,7 +981,7 @@ public: llvm::function_ref Handler, bool fromASTGen = false); - std::pair, llvm::Optional> + std::pair, std::optional> parseDeclListDelayed(IterableDeclContext *IDC); bool parseMemberDeclList(SourceLoc &LBLoc, SourceLoc &RBLoc, @@ -1089,8 +1089,8 @@ public: /// Parse the arguments inside the @_specialize attribute bool parseSpecializeAttributeArguments( swift::tok ClosingBrace, bool &DiscardAttribute, - llvm::Optional &Exported, - llvm::Optional &Kind, + std::optional &Exported, + std::optional &Kind, TrailingWhereClause *&TrailingWhereClause, DeclNameRef &targetFunction, AvailabilityContext *SILAvailability, SmallVectorImpl &spiGroups, @@ -1151,8 +1151,8 @@ public: /// Parse a single argument from a @_documentation attribute. bool - parseDocumentationAttributeArgument(llvm::Optional &Metadata, - llvm::Optional &Visibility); + parseDocumentationAttributeArgument(std::optional &Metadata, + std::optional &Visibility); /// Parse the @attached or @freestanding attribute that specifies a macro /// role. @@ -1296,7 +1296,7 @@ public: SourceLoc *parseTildeCopyable = nullptr); ParserStatus parseDeclItem(bool &PreviousHadSemi, llvm::function_ref handler); - std::pair, llvm::Optional> + std::pair, std::optional> parseDeclList(SourceLoc LBLoc, SourceLoc &RBLoc, Diag<> ErrorDiag, bool &hadError); ParserResult parseDeclExtension(ParseDeclOptions Flags, @@ -1683,7 +1683,7 @@ public: /// \endcode /// /// \returns The tuple pattern element, if successful. - std::pair> + std::pair> parsePatternTupleElement(); ParserResult parsePatternTuple(); @@ -1940,9 +1940,9 @@ public: ParserResult parseExprMacroExpansion(bool isExprBasic); ParserResult parseExprCollection(); ParserResult - parseExprCollectionElement(llvm::Optional &isDictionary); + parseExprCollectionElement(std::optional &isDictionary); ParserResult - parseExprPoundCodeCompletion(llvm::Optional ParentKind); + parseExprPoundCodeCompletion(std::optional ParentKind); UnresolvedDeclRefExpr *parseExprOperator(); @@ -2130,7 +2130,7 @@ struct ParsedDeclName { /// For a declaration name that makes the declaration into an /// instance member, the index of the "Self" parameter. - llvm::Optional SelfIndex; + std::optional SelfIndex; /// Determine whether this is a valid name. explicit operator bool() const { return !BaseName.empty(); } diff --git a/include/swift/Parse/PatternBindingState.h b/include/swift/Parse/PatternBindingState.h index 33598433bec..f3f0b04c307 100644 --- a/include/swift/Parse/PatternBindingState.h +++ b/include/swift/Parse/PatternBindingState.h @@ -59,7 +59,7 @@ struct PatternBindingState { operator Kind() const { return kind; } - static llvm::Optional get(StringRef str) { + static std::optional get(StringRef str) { auto kind = llvm::StringSwitch(str) .Case("let", Kind::InLet) .Case("var", Kind::InVar) @@ -104,12 +104,12 @@ struct PatternBindingState { /// If there is a direct introducer associated with this pattern binding /// state, return that. Return none otherwise. - llvm::Optional getIntroducer() const { + std::optional getIntroducer() const { switch (kind) { case Kind::NotInBinding: case Kind::InMatchingPattern: case Kind::ImplicitlyImmutable: - return llvm::None; + return std::nullopt; case Kind::InVar: return VarDecl::Introducer::Var; case Kind::InLet: @@ -124,7 +124,7 @@ struct PatternBindingState { return PatternBindingState(getIntroducer().value_or(defaultValue)); } - llvm::Optional getSelectIndexForIntroducer() const { + std::optional getSelectIndexForIntroducer() const { switch (kind) { case Kind::InLet: return 0; @@ -133,7 +133,7 @@ struct PatternBindingState { case Kind::InVar: return 2; default: - return llvm::None; + return std::nullopt; } } diff --git a/include/swift/Refactoring/Refactoring.h b/include/swift/Refactoring/Refactoring.h index 48c2cf9d08f..3a12f64fb82 100644 --- a/include/swift/Refactoring/Refactoring.h +++ b/include/swift/Refactoring/Refactoring.h @@ -60,7 +60,7 @@ struct RenameInfo { RefactorAvailabilityInfo Availability; }; -llvm::Optional getRenameInfo(ResolvedCursorInfoPtr cursorInfo); +std::optional getRenameInfo(ResolvedCursorInfoPtr cursorInfo); /// An array of \c RenameLoc that also keeps the underlying string storage of /// the \c StringRef inside the \c RenameLoc alive. @@ -126,7 +126,7 @@ struct RefactoringOptions { struct RenameRangeDetail { CharSourceRange Range; RefactoringRangeKind RangeKind; - llvm::Optional Index; + std::optional Index; }; StringRef getDescriptiveRefactoringKindName(RefactoringKind Kind); diff --git a/include/swift/Remote/ExternalTypeRefCache.h b/include/swift/Remote/ExternalTypeRefCache.h index 8ac79f136a3..2f3a461b2f1 100644 --- a/include/swift/Remote/ExternalTypeRefCache.h +++ b/include/swift/Remote/ExternalTypeRefCache.h @@ -22,7 +22,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" -#include "llvm/ADT/Optional.h" +#include #include @@ -62,7 +62,7 @@ struct ExternalTypeRefCache { /// Retrieve a pair representing the reflection info id and the offset of a /// field descriptor in the field section buffer, if available. - virtual llvm::Optional + virtual std::optional getFieldDescriptorLocator(const std::string &Name) = 0; /// Returns whether the reflection info with the corresponding ID has been diff --git a/include/swift/Remote/MemoryReader.h b/include/swift/Remote/MemoryReader.h index 64fd6e0292d..caefa2599f9 100644 --- a/include/swift/Remote/MemoryReader.h +++ b/include/swift/Remote/MemoryReader.h @@ -20,8 +20,7 @@ #include "swift/Remote/RemoteAddress.h" #include "swift/SwiftRemoteMirror/MemoryReaderInterface.h" -#include "llvm/ADT/None.h" -#include "llvm/ADT/Optional.h" +#include #include #include @@ -150,9 +149,9 @@ public: return RemoteAbsolutePointer("", readValue); } - virtual llvm::Optional + virtual std::optional resolvePointerAsSymbol(RemoteAddress address) { - return llvm::None; + return std::nullopt; } /// Lookup a symbol for the given remote address. @@ -170,8 +169,8 @@ public: } /// Attempt to read and resolve a pointer value at the given remote address. - llvm::Optional readPointer(RemoteAddress address, - unsigned pointerSize) { + std::optional readPointer(RemoteAddress address, + unsigned pointerSize) { // First, try to lookup the pointer as a dynamic symbol (binding), as // reading memory may potentially be expensive. if (auto dynamicSymbol = getDynamicSymbol(address)) @@ -179,8 +178,8 @@ public: auto result = readBytes(address, pointerSize); if (!result) - return llvm::None; - + return std::nullopt; + uint64_t pointerData; if (pointerSize == 4) { uint32_t theData; @@ -189,7 +188,7 @@ public: } else if (pointerSize == 8) { memcpy(&pointerData, result.get(), 8); } else { - return llvm::None; + return std::nullopt; } return resolvePointer(address, pointerData); diff --git a/include/swift/Remote/MetadataReader.h b/include/swift/Remote/MetadataReader.h index e7af8979773..1518fec9cb9 100644 --- a/include/swift/Remote/MetadataReader.h +++ b/include/swift/Remote/MetadataReader.h @@ -609,25 +609,25 @@ public: } /// Get the remote process's swift_isaMask. - llvm::Optional readIsaMask() { + std::optional readIsaMask() { auto encoding = getIsaEncoding(); if (encoding != IsaEncodingKind::Masked) { // Still return success if there's no isa encoding at all. if (encoding == IsaEncodingKind::None) return 0; else - return llvm::None; + return std::nullopt; } return IsaMask; } /// Given a remote pointer to metadata, attempt to discover its MetadataKind. - llvm::Optional + std::optional readKindFromMetadata(StoredPointer MetadataAddress) { auto meta = readMetadata(MetadataAddress); if (!meta) - return llvm::None; + return std::nullopt; return meta->getKind(); } @@ -645,11 +645,11 @@ public: /// Given a remote pointer to class metadata, attempt to discover its class /// instance size and whether fields should use the resilient layout strategy. - llvm::Optional readInstanceStartFromClassMetadata( - StoredPointer MetadataAddress) { + std::optional + readInstanceStartFromClassMetadata(StoredPointer MetadataAddress) { auto meta = readMetadata(MetadataAddress); if (!meta || meta->getKind() != MetadataKind::Class) - return llvm::None; + return std::nullopt; if (Runtime::ObjCInterop) { // The following algorithm only works on the non-fragile Apple runtime. @@ -657,14 +657,14 @@ public: // Grab the RO-data pointer. This part is not ABI. StoredPointer roDataPtr = readObjCRODataPtr(MetadataAddress); if (!roDataPtr) - return llvm::None; + return std::nullopt; // Get the address of the InstanceStart field. auto address = roDataPtr + sizeof(uint32_t) * 1; unsigned start; if (!Reader->readInteger(RemoteAddress(address), &start)) - return llvm::None; + return std::nullopt; return start; } else { @@ -677,7 +677,7 @@ public: while (stripSignedPointer(classMeta->Superclass)) { meta = readMetadata(stripSignedPointer(classMeta->Superclass)); if (!meta || meta->getKind() != MetadataKind::Class) - return llvm::None; + return std::nullopt; classMeta = cast(meta); @@ -692,7 +692,7 @@ public: /// Given a pointer to the metadata, attempt to read the value /// witness table. Note that it's not safe to access any non-mandatory /// members of the value witness table, like extra inhabitants or enum members. - llvm::Optional> + std::optional> readValueWitnessTable(StoredPointer MetadataAddress) { // The value witness table pointer is at offset -1 from the metadata // pointer, that is, the pointer-sized word immediately before the @@ -702,10 +702,10 @@ public: StoredPointer ValueWitnessTableAddr; if (!Reader->readInteger(RemoteAddress(ValueWitnessTableAddrAddr), &ValueWitnessTableAddr)) - return llvm::None; + return std::nullopt; if (!Reader->readBytes(RemoteAddress(ValueWitnessTableAddr), (uint8_t *)&VWT, sizeof(VWT))) - return llvm::None; + return std::nullopt; return VWT; } @@ -713,20 +713,20 @@ public: /// pointer to its metadata address, its value address, and whether this /// is a toll-free-bridged NSError or an actual Error existential wrapper /// around a native Swift value. - llvm::Optional + std::optional readMetadataAndValueErrorExistential(RemoteAddress ExistentialAddress) { // An pointer to an error existential is always an heap object. auto MetadataAddress = readMetadataFromInstance(ExistentialAddress.getAddressData()); if (!MetadataAddress) - return llvm::None; + return std::nullopt; bool isObjC = false; bool isBridged = false; auto Meta = readMetadata(*MetadataAddress); if (!Meta) - return llvm::None; + return std::nullopt; if (auto ClassMeta = dyn_cast(Meta)) { if (ClassMeta->isPureObjC()) { @@ -764,12 +764,12 @@ public: auto InstanceMetadataAddress = readMetadataFromInstance(InstanceMetadataAddressAddress); if (!InstanceMetadataAddress) - return llvm::None; + return std::nullopt; // Read the value witness table. auto VWT = readValueWitnessTable(*InstanceMetadataAddress); if (!VWT) - return llvm::None; + return std::nullopt; // Now we need to skip over the instance metadata pointer and instance's // conformance pointer for Swift.Error. @@ -794,22 +794,22 @@ public: /// Given a known-opaque existential, attempt to discover the pointer to its /// metadata address and its value. - llvm::Optional + std::optional readMetadataAndValueOpaqueExistential(RemoteAddress ExistentialAddress) { // OpaqueExistentialContainer is the layout of an opaque existential. // `Type` is the pointer to the metadata. TargetOpaqueExistentialContainer Container; if (!Reader->readBytes(RemoteAddress(ExistentialAddress), (uint8_t *)&Container, sizeof(Container))) - return llvm::None; + return std::nullopt; auto MetadataAddress = static_cast(Container.Type); auto Metadata = readMetadata(MetadataAddress); if (!Metadata) - return llvm::None; + return std::nullopt; auto VWT = readValueWitnessTable(MetadataAddress); if (!VWT) - return llvm::None; + return std::nullopt; // Inline representation (the value fits in the existential container). // So, the value starts at the first word of the container. @@ -821,7 +821,7 @@ public: // The first word of the container stores the address to the box. StoredPointer BoxAddress; if (!Reader->readInteger(ExistentialAddress, &BoxAddress)) - return llvm::None; + return std::nullopt; auto AlignmentMask = VWT->getAlignmentMask(); auto Offset = (sizeof(HeapObject) + AlignmentMask) & ~AlignmentMask; @@ -832,22 +832,22 @@ public: /// Given a known-opaque existential, discover if its value is inlined in /// the existential container. - llvm::Optional + std::optional isValueInlinedInExistentialContainer(RemoteAddress ExistentialAddress) { // OpaqueExistentialContainer is the layout of an opaque existential. // `Type` is the pointer to the metadata. TargetOpaqueExistentialContainer Container; if (!Reader->readBytes(RemoteAddress(ExistentialAddress), (uint8_t *)&Container, sizeof(Container))) - return llvm::None; + return std::nullopt; auto MetadataAddress = static_cast(Container.Type); auto Metadata = readMetadata(MetadataAddress); if (!Metadata) - return llvm::None; + return std::nullopt; auto VWT = readValueWitnessTable(MetadataAddress); if (!VWT) - return llvm::None; + return std::nullopt; return VWT->isValueInline(); } @@ -1700,15 +1700,15 @@ public: } /// Read the isa pointer of an Object-C tagged pointer value. - llvm::Optional + std::optional readMetadataFromTaggedPointer(StoredPointer objectAddress) { auto readArrayElement = [&](StoredPointer base, - StoredPointer tag) -> llvm::Optional { + StoredPointer tag) -> std::optional { StoredPointer addr = base + tag * sizeof(StoredPointer); StoredPointer isa; if (!Reader->readInteger(RemoteAddress(addr), &isa)) - return llvm::None; + return std::nullopt; return isa; }; @@ -1730,19 +1730,19 @@ public: /// Read the isa pointer of a class or closure context instance and apply /// the isa mask. - llvm::Optional + std::optional readMetadataFromInstance(StoredPointer objectAddress) { if (isTaggedPointer(objectAddress)) return readMetadataFromTaggedPointer(objectAddress); StoredPointer isa; if (!Reader->readInteger(RemoteAddress(objectAddress), &isa)) - return llvm::None; + return std::nullopt; switch (getIsaEncoding()) { case IsaEncodingKind::Unknown: case IsaEncodingKind::Error: - return llvm::None; + return std::nullopt; case IsaEncodingKind::None: return isa; @@ -1761,7 +1761,7 @@ public: // 0 is never a valid index. if (classIndex == 0) { - return llvm::None; + return std::nullopt; // If the index is out of range, it's an error; but check for an // update first. (This will also trigger the first time because @@ -1770,12 +1770,12 @@ public: StoredPointer count; if (!Reader->readInteger(RemoteAddress(IndexedClassesCountPointer), &count)) { - return llvm::None; + return std::nullopt; } LastIndexedClassesCount = count; if (classIndex >= count) { - return llvm::None; + return std::nullopt; } } @@ -1785,7 +1785,7 @@ public: + classIndex * sizeof(StoredPointer)); StoredPointer metadataPointer; if (!Reader->readInteger(eltPointer, &metadataPointer)) { - return llvm::None; + return std::nullopt; } return metadataPointer; @@ -1801,7 +1801,7 @@ public: /// /// The offset is in units of words, from the start of the class's /// metadata. - llvm::Optional + std::optional readGenericArgsOffset(MetadataRef metadata, ContextDescriptorRef descriptor) { switch (descriptor->getKind()) { case ContextDescriptorKind::Class: { @@ -1812,7 +1812,7 @@ public: auto bounds = readMetadataBoundsOfSuperclass(descriptor); if (!bounds) - return llvm::None; + return std::nullopt; bounds->adjustForSubclass(type->areImmediateMembersNegative(), type->NumImmediateMembers); @@ -1831,14 +1831,14 @@ public: } default: - return llvm::None; + return std::nullopt; } } using ClassMetadataBounds = TargetClassMetadataBounds; // This follows computeMetadataBoundsForSuperclass. - llvm::Optional + std::optional readMetadataBoundsOfSuperclass(ContextDescriptorRef subclassRef) { auto subclass = cast>(subclassRef); if (!subclass->hasResilientSuperclass()) @@ -1853,37 +1853,37 @@ public: return forTypeReference( subclass->getResilientSuperclassReferenceKind(), rawSuperclass, [&](ContextDescriptorRef superclass) - -> llvm::Optional { + -> std::optional { if (!isa>(superclass)) - return llvm::None; + return std::nullopt; return readMetadataBoundsOfSuperclass(superclass); }, - [&](MetadataRef metadata) -> llvm::Optional { + [&](MetadataRef metadata) -> std::optional { auto cls = dyn_cast(metadata); if (!cls) - return llvm::None; + return std::nullopt; return cls->getClassBoundsAsSwiftSuperclass(); }, - [](StoredPointer objcClassName) -> llvm::Optional { + [](StoredPointer objcClassName) -> std::optional { // We have no ability to look up an ObjC class by name. // FIXME: add a query for this; clients may have a way to do it. - return llvm::None; + return std::nullopt; }); } template - llvm::Optional forTypeReference(TypeReferenceKind refKind, - StoredPointer ref, - const DescriptorFn &descriptorFn, - const MetadataFn &metadataFn, - const ClassNameFn &classNameFn) { + std::optional forTypeReference(TypeReferenceKind refKind, + StoredPointer ref, + const DescriptorFn &descriptorFn, + const MetadataFn &metadataFn, + const ClassNameFn &classNameFn) { switch (refKind) { case TypeReferenceKind::IndirectTypeDescriptor: { StoredPointer descriptorAddress = 0; if (!Reader->readInteger(RemoteAddress(ref), &descriptorAddress)) - return llvm::None; + return std::nullopt; ref = descriptorAddress; LLVM_FALLTHROUGH; @@ -1892,7 +1892,7 @@ public: case TypeReferenceKind::DirectTypeDescriptor: { auto descriptor = readContextDescriptor(ref); if (!descriptor) - return llvm::None; + return std::nullopt; return descriptorFn(descriptor); } @@ -1903,43 +1903,43 @@ public: case TypeReferenceKind::IndirectObjCClass: { StoredPointer classRef = 0; if (!Reader->readInteger(RemoteAddress(ref), &classRef)) - return llvm::None; + return std::nullopt; auto metadata = readMetadata(classRef); if (!metadata) - return llvm::None; + return std::nullopt; return metadataFn(metadata); } } - return llvm::None; + return std::nullopt; } /// Read a single generic type argument from a bound generic type /// metadata. - llvm::Optional + std::optional readGenericArgFromMetadata(StoredPointer metadata, unsigned index) { auto Meta = readMetadata(metadata); if (!Meta) - return llvm::None; + return std::nullopt; auto descriptorAddress = readAddressOfNominalTypeDescriptor(Meta); if (!descriptorAddress) - return llvm::None; + return std::nullopt; // Read the nominal type descriptor. auto descriptor = readContextDescriptor(descriptorAddress); if (!descriptor) - return llvm::None; + return std::nullopt; auto generics = descriptor->getGenericContext(); if (!generics) - return llvm::None; + return std::nullopt; auto offsetToGenericArgs = readGenericArgsOffset(Meta, descriptor); if (!offsetToGenericArgs) - return llvm::None; + return std::nullopt; auto addressOfGenericArgAddress = (getAddress(Meta) + @@ -1947,12 +1947,12 @@ public: index * sizeof(StoredPointer)); if (index >= generics->getGenericContextHeader().getNumArguments()) - return llvm::None; + return std::nullopt; StoredPointer genericArgAddress; if (!Reader->readInteger(RemoteAddress(addressOfGenericArgAddress), &genericArgAddress)) - return llvm::None; + return std::nullopt; return genericArgAddress; } @@ -1991,28 +1991,27 @@ public: } /// Given a remote pointer to class metadata, attempt to read its superclass. - llvm::Optional + std::optional readOffsetToFirstCaptureFromMetadata(StoredPointer MetadataAddress) { auto meta = readMetadata(MetadataAddress); if (!meta || meta->getKind() != MetadataKind::HeapLocalVariable) - return llvm::None; + return std::nullopt; auto heapMeta = cast>(meta); return heapMeta->OffsetToFirstCapture; } - llvm::Optional readPointer(StoredPointer address) { + std::optional readPointer(StoredPointer address) { return Reader->readPointer(RemoteAddress(address), sizeof(StoredPointer)); } - llvm::Optional - readResolvedPointerValue(StoredPointer address) { + std::optional readResolvedPointerValue(StoredPointer address) { if (auto pointer = readPointer(address)) { if (!pointer->isResolved()) - return llvm::None; + return std::nullopt; return (StoredPointer)pointer->getResolvedAddress().getAddressData(); } - return llvm::None; + return std::nullopt; } template @@ -2024,11 +2023,11 @@ public: } /// Given a remote pointer to class metadata, attempt to read its superclass. - llvm::Optional + std::optional readCaptureDescriptorFromMetadata(StoredPointer MetadataAddress) { auto meta = readMetadata(MetadataAddress); if (!meta || meta->getKind() != MetadataKind::HeapLocalVariable) - return llvm::None; + return std::nullopt; auto heapMeta = cast>(meta); return resolvePointerField(meta, heapMeta->CaptureDescription); @@ -2047,14 +2046,14 @@ protected: } template - llvm::Optional + std::optional resolveRelativeIndirectableField(RemoteRef base, const Field &field) { auto fieldRef = base.getField(field); int32_t offset; memcpy(&offset, fieldRef.getLocalBuffer(), sizeof(int32_t)); if (offset == 0) - return llvm::Optional(nullptr); + return std::optional(nullptr); bool indirect = offset & 1; offset &= ~1u; @@ -2068,7 +2067,7 @@ protected: if (auto ptr = readPointer(resultAddress)) { return stripSignedPointer(*ptr); } - return llvm::None; + return std::nullopt; } return RemoteAbsolutePointer("", resultAddress); @@ -2322,16 +2321,16 @@ private: /// Returns Optional(ParentContextDescriptorRef()) if there's no parent descriptor. /// Returns None if there was an error reading the parent descriptor. - llvm::Optional + std::optional readParentContextDescriptor(ContextDescriptorRef base) { auto parentAddress = resolveRelativeIndirectableField(base, base->Parent); if (!parentAddress) - return llvm::None; + return std::nullopt; if (!parentAddress->isResolved()) { // Currently we can only handle references directly to a symbol without // an offset. if (parentAddress->getOffset() != 0) { - return llvm::None; + return std::nullopt; } return ParentContextDescriptorRef(parentAddress->getSymbol()); } @@ -2340,7 +2339,7 @@ private: return ParentContextDescriptorRef(); if (auto parentDescriptor = readContextDescriptor(addr.getAddressData())) return ParentContextDescriptorRef(parentDescriptor); - return llvm::None; + return std::nullopt; } static bool isCImportedContext(Demangle::NodePointer node) { @@ -2356,9 +2355,9 @@ private: } /// Read the name from a module, type, or protocol context descriptor. - llvm::Optional readContextDescriptorName( + std::optional readContextDescriptorName( ContextDescriptorRef descriptor, - llvm::Optional> &importInfo) { + std::optional> &importInfo) { std::string name; auto context = descriptor.getLocalBuffer(); @@ -2369,7 +2368,7 @@ private: if (Reader->readString(RemoteAddress(nameAddress), name)) return name; - return llvm::None; + return std::nullopt; } // Read the name of a module. @@ -2379,17 +2378,17 @@ private: if (Reader->readString(RemoteAddress(nameAddress), name)) return name; - return llvm::None; + return std::nullopt; } // Only type contexts remain. auto typeBuffer = dyn_cast>(context); if (!typeBuffer) - return llvm::None; + return std::nullopt; auto nameAddress = resolveRelativeField(descriptor, typeBuffer->Name); if (!Reader->readString(RemoteAddress(nameAddress), name)) - return llvm::None; + return std::nullopt; // Read the TypeImportInfo if present. if (typeBuffer->getTypeContextDescriptorFlags().hasImportInfo()) { @@ -2400,7 +2399,7 @@ private: // Read the next string. std::string temp; if (!Reader->readString(RemoteAddress(nameAddress), temp)) - return llvm::None; + return std::nullopt; // If we read an empty string, we're done. if (temp.empty()) @@ -2521,7 +2520,7 @@ private: /// produce a mangled node describing the name of \c context. Demangle::NodePointer adoptAnonymousContextName( ContextDescriptorRef contextRef, - llvm::Optional &parentContextRef, + std::optional &parentContextRef, Demangler &dem, Demangle::NodePointer &outerNode) { outerNode = nullptr; @@ -2570,7 +2569,7 @@ private: return nullptr; // Read the name of the current context. - llvm::Optional> importInfo; + std::optional> importInfo; auto contextName = readContextDescriptorName(contextRef, importInfo); if (!contextName) return nullptr; @@ -2696,7 +2695,7 @@ private: } Demangle::Node::Kind nodeKind; - llvm::Optional> importInfo; + std::optional> importInfo; auto getContextName = [&]() -> bool { if (nameNode) diff --git a/include/swift/RemoteInspection/MetadataSource.h b/include/swift/RemoteInspection/MetadataSource.h index bccbab00bc6..85f8e1975b3 100644 --- a/include/swift/RemoteInspection/MetadataSource.h +++ b/include/swift/RemoteInspection/MetadataSource.h @@ -22,8 +22,8 @@ #ifndef SWIFT_REFLECTION_METADATASOURCE_H #define SWIFT_REFLECTION_METADATASOURCE_H -#include "llvm/ADT/Optional.h" #include "llvm/Support/Casting.h" +#include using llvm::cast; diff --git a/include/swift/RemoteInspection/ReflectionContext.h b/include/swift/RemoteInspection/ReflectionContext.h index c71187834c8..7d7ef9f6511 100644 --- a/include/swift/RemoteInspection/ReflectionContext.h +++ b/include/swift/RemoteInspection/ReflectionContext.h @@ -236,8 +236,7 @@ public: /// On success returns the ID of the newly registered Reflection Info. template - llvm::Optional - readMachOSections( + std::optional readMachOSections( RemoteAddress ImageStart, llvm::SmallVector PotentialModuleNames = {}) { auto Buf = @@ -393,7 +392,7 @@ public: } /// On success returns the ID of the newly registered Reflection Info. - llvm::Optional readPECOFFSections( + std::optional readPECOFFSections( RemoteAddress ImageStart, llvm::SmallVector PotentialModuleNames = {}) { auto DOSHdrBuf = this->getReader().readBytes( @@ -497,8 +496,9 @@ public: } /// On success returns the ID of the newly registered Reflection Info. - llvm::Optional readPECOFF(RemoteAddress ImageStart, - llvm::SmallVector PotentialModuleNames = {}) { + std::optional + readPECOFF(RemoteAddress ImageStart, + llvm::SmallVector PotentialModuleNames = {}) { auto Buf = this->getReader().readBytes(ImageStart, sizeof(llvm::object::dos_header)); if (!Buf) @@ -522,9 +522,9 @@ public: /// On success returns the ID of the newly registered Reflection Info. template - llvm::Optional readELFSections( + std::optional readELFSections( RemoteAddress ImageStart, - llvm::Optional FileBuffer, + std::optional FileBuffer, llvm::SmallVector PotentialModuleNames = {}) { // When reading from the FileBuffer we can simply return a pointer to // the underlying data. @@ -710,21 +710,21 @@ public: /// /// \return /// \b The newly added reflection info ID if successful, - /// \b llvm::None otherwise. - llvm::Optional + /// \b std::nullopt otherwise. + std::optional readELF(RemoteAddress ImageStart, - llvm::Optional FileBuffer, + std::optional FileBuffer, llvm::SmallVector PotentialModuleNames = {}) { auto Buf = this->getReader().readBytes(ImageStart, sizeof(llvm::ELF::Elf64_Ehdr)); if (!Buf) - return llvm::None; + return std::nullopt; // Read the header. auto Hdr = reinterpret_cast(Buf.get()); if (!Hdr->checkMagic()) - return llvm::None; + return std::nullopt; // Check if we have a ELFCLASS32 or ELFCLASS64 unsigned char FileClass = Hdr->getFileClass(); @@ -735,12 +735,12 @@ public: return readELFSections>( ImageStart, FileBuffer, PotentialModuleNames); } else { - return llvm::None; + return std::nullopt; } } /// On success returns the ID of the newly registered Reflection Info. - llvm::Optional + std::optional addImage(RemoteAddress ImageStart, llvm::SmallVector PotentialModuleNames = {}) { // Read the first few bytes to look for a magic header. @@ -773,12 +773,12 @@ public: && MagicBytes[1] == llvm::ELF::ElfMagic[1] && MagicBytes[2] == llvm::ELF::ElfMagic[2] && MagicBytes[3] == llvm::ELF::ElfMagic[3]) { - return readELF(ImageStart, llvm::Optional(), + return readELF(ImageStart, std::optional(), PotentialModuleNames); } // We don't recognize the format. - return llvm::None; + return std::nullopt; } /// Adds an image using the FindSection closure to find the swift metadata @@ -788,8 +788,8 @@ public: /// process. /// \return /// \b The newly added reflection info ID if successful, - /// \b llvm::None otherwise. - llvm::Optional + /// \b std::nullopt otherwise. + std::optional addImage(llvm::function_ref< std::pair, uint64_t>(ReflectionSectionKind)> FindSection, @@ -991,7 +991,7 @@ public: } } - llvm::Optional> + std::optional> getDynamicTypeAndAddressClassExistential(RemoteAddress ExistentialAddress) { auto PointerValue = readResolvedPointerValue(ExistentialAddress.getAddressData()); @@ -1006,7 +1006,7 @@ public: return {{std::move(TypeResult), RemoteAddress(*PointerValue)}}; } - llvm::Optional> + std::optional> getDynamicTypeAndAddressErrorExistential(RemoteAddress ExistentialAddress, bool *IsBridgedError = nullptr) { auto Result = readMetadataAndValueErrorExistential(ExistentialAddress); @@ -1024,7 +1024,7 @@ public: return {{TypeResult, Result->PayloadAddress}}; } - llvm::Optional> + std::optional> getDynamicTypeAndAddressOpaqueExistential(RemoteAddress ExistentialAddress) { auto Result = readMetadataAndValueOpaqueExistential(ExistentialAddress); if (!Result) @@ -1103,7 +1103,7 @@ public: /// a class type, it also dereferences the input `ExistentialAddress` before /// attempting to find its dynamic type and address when dealing with error /// existentials. - llvm::Optional> + std::optional> projectExistentialAndUnwrapClass(RemoteAddress ExistentialAddress, const TypeRef &ExistentialTR) { auto IsClass = [](const TypeRef *TypeResult) { @@ -1213,8 +1213,7 @@ public: /// the superclass's fields. For a version of this function that performs the /// same job but starting out with an instance pointer check /// MetadataReader::readInstanceStartFromClassMetadata. - llvm::Optional - computeUnalignedFieldStartOffset(const TypeRef *TR) { + std::optional computeUnalignedFieldStartOffset(const TypeRef *TR) { size_t isaAndRetainCountSize = sizeof(StoredSize) + sizeof(long long); const TypeRef *superclass = getBuilder().lookupSuperclass(TR); @@ -1226,12 +1225,12 @@ public: auto superclassStart = computeUnalignedFieldStartOffset(superclass); if (!superclassStart) - return llvm::None; + return std::nullopt; auto *superTI = getBuilder().getTypeConverter().getClassInstanceTypeInfo( superclass, *superclassStart, nullptr); if (!superTI) - return llvm::None; + return std::nullopt; // The start of the subclass's fields is right after the super class's ones. size_t start = superTI->getSize(); @@ -1319,8 +1318,8 @@ public: /// Iterate the protocol conformance cache in the target process, calling Call /// with the type and protocol of each conformance. Returns None on success, /// and a string describing the error on failure. - llvm::Optional iterateConformances( - std::function Call) { + std::optional iterateConformances( + std::function Call) { std::string ConformancesPointerName = "_swift_debug_protocolConformanceStatePointer"; auto ConformancesAddrAddr = @@ -1334,7 +1333,7 @@ public: return "unable to read value of " + ConformancesPointerName; IterateConformanceTable(ConformancesAddr->getResolvedAddress(), Call); - return llvm::None; + return std::nullopt; } /// Fetch the metadata pointer from a metadata allocation, or 0 if this @@ -1356,18 +1355,18 @@ public: } /// Get the name of a metadata tag, if known. - llvm::Optional metadataAllocationTagName(int Tag) { + std::optional metadataAllocationTagName(int Tag) { switch (Tag) { #define TAG(name, value) \ case value: \ return std::string(#name); #include "../../../stdlib/public/runtime/MetadataAllocatorTags.def" default: - return llvm::None; + return std::nullopt; } } - llvm::Optional> + std::optional> metadataAllocationCacheNode(MetadataAllocation Allocation) { switch (Allocation.Tag) { case BoxesTag: @@ -1389,21 +1388,21 @@ public: auto NodeBytes = getReader().readBytes( RemoteAddress(Allocation.Ptr), sizeof(MetadataCacheNode)); if (!NodeBytes) - return llvm::None; + return std::nullopt; auto Node = reinterpret_cast *>(NodeBytes.get()); return *Node; } default: - return llvm::None; + return std::nullopt; } } /// Iterate the metadata allocations in the target process, calling Call with /// each allocation found. Returns None on success, and a string describing /// the error on failure. - llvm::Optional iterateMetadataAllocations( - std::function)> Call) { + std::optional iterateMetadataAllocations( + std::function)> Call) { std::string IterationEnabledName = "_swift_debug_metadataAllocationIterationEnabled"; std::string AllocationPoolPointerName = @@ -1487,10 +1486,10 @@ public: TrailerPtr = Trailer->PrevTrailer; } - return llvm::None; + return std::nullopt; } - llvm::Optional iterateMetadataAllocationBacktraces( + std::optional iterateMetadataAllocationBacktraces( std::function Call) { std::string BacktraceListName = @@ -1502,7 +1501,7 @@ public: auto BacktraceListNextPtr = getReader().readPointer(BacktraceListAddr, sizeof(StoredPointer)); if (!BacktraceListNextPtr) - return llvm::None; + return std::nullopt; // Limit how many iterations of this loop we'll do, to avoid potential // infinite loops when reading bad data. Limit to 1 billion iterations. In @@ -1541,10 +1540,10 @@ public: BacktraceListNext = RemoteAddress(HeaderPtr->Next); } - return llvm::None; + return std::nullopt; } - std::pair, AsyncTaskSlabInfo> + std::pair, AsyncTaskSlabInfo> asyncTaskSlabAllocations(StoredPointer SlabPtr) { using StackAllocator = StackAllocator; auto SlabBytes = getReader().readBytes( @@ -1575,11 +1574,11 @@ public: // Total slab size is the slab's capacity plus the header. StoredPointer SlabSize = Slab->Capacity + HeaderSize; - return {llvm::None, + return {std::nullopt, {Slab->Next, SlabSize, {NextPtrChunk, AllocatedSpaceChunk}}}; } - std::pair, AsyncTaskInfo> + std::pair, AsyncTaskInfo> asyncTaskInfo(StoredPointer AsyncTaskPtr, unsigned ChildTaskLimit, unsigned AsyncBacktraceLimit) { loadTargetPointers(); @@ -1594,7 +1593,7 @@ public: AsyncTaskPtr, ChildTaskLimit, AsyncBacktraceLimit); } - std::pair, ActorInfo> + std::pair, ActorInfo> actorInfo(StoredPointer ActorPtr) { if (supportsPriorityEscalation) return actorInfo< @@ -1682,7 +1681,7 @@ private: } template - std::pair, AsyncTaskInfo> + std::pair, AsyncTaskInfo> asyncTaskInfo(StoredPointer AsyncTaskPtr, unsigned ChildTaskLimit, unsigned AsyncBacktraceLimit) { auto AsyncTaskObj = readObj(AsyncTaskPtr); @@ -1769,11 +1768,11 @@ private: } } - return {llvm::None, Info}; + return {std::nullopt, Info}; } template - std::pair, ActorInfo> + std::pair, ActorInfo> actorInfo(StoredPointer ActorPtr) { auto ActorObj = readObj(ActorPtr); if (!ActorObj) @@ -1799,7 +1798,7 @@ private: std::tie(Info.HasThreadPort, Info.ThreadPort) = getThreadPort(ActorObj.get()); - return {llvm::None, Info}; + return {std::nullopt, Info}; } // Get the most human meaningful "run job" function pointer from the task, @@ -2021,9 +2020,8 @@ private: /// above. /// /// \param Builder Used to obtain offsets of elements known so far. - llvm::Optional - readMetadataSource(StoredPointer Context, - const MetadataSource *MS, + std::optional + readMetadataSource(StoredPointer Context, const MetadataSource *MS, const RecordTypeInfoBuilder &Builder) { switch (MS->getKind()) { case MetadataSourceKind::ClosureBinding: { @@ -2093,7 +2091,7 @@ private: break; } - return llvm::None; + return std::nullopt; } template diff --git a/include/swift/RemoteInspection/TypeRef.h b/include/swift/RemoteInspection/TypeRef.h index bafaa2918ad..5a393b320fb 100644 --- a/include/swift/RemoteInspection/TypeRef.h +++ b/include/swift/RemoteInspection/TypeRef.h @@ -211,7 +211,7 @@ public: Demangle::NodePointer getDemangling(Demangle::Demangler &Dem) const; /// Build the mangled name from this TypeRef. - llvm::Optional mangle(Demangle::Demangler &Dem) const; + std::optional mangle(Demangle::Demangler &Dem) const; bool isConcrete() const; bool isConcreteAfterSubstitutions(const GenericArgumentMap &Subs) const; @@ -223,7 +223,7 @@ public: const GenericArgumentMap &Subs, bool &DidSubstitute) const; - llvm::Optional getSubstMap() const; + std::optional getSubstMap() const; virtual ~TypeRef() = default; diff --git a/include/swift/RemoteInspection/TypeRefBuilder.h b/include/swift/RemoteInspection/TypeRefBuilder.h index 9e0a8d93996..bc2b6f9221e 100644 --- a/include/swift/RemoteInspection/TypeRefBuilder.h +++ b/include/swift/RemoteInspection/TypeRefBuilder.h @@ -25,10 +25,10 @@ #include "swift/RemoteInspection/Records.h" #include "swift/RemoteInspection/TypeLowering.h" #include "swift/RemoteInspection/TypeRef.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallVector.h" #include #include +#include #include #include #include @@ -361,7 +361,7 @@ struct TypeRefDecl { // Only used when building a bound generic typeref, and when the // generic params for all the levels are stored as a flat array. - llvm::Optional> genericParamsPerLevel; + std::optional> genericParamsPerLevel; TypeRefDecl(std::string mangledName, std::vector genericParamsPerLevel) @@ -369,7 +369,7 @@ struct TypeRefDecl { } TypeRefDecl(std::string mangledName) - : mangledName(mangledName), genericParamsPerLevel(llvm::None) {} + : mangledName(mangledName), genericParamsPerLevel(std::nullopt) {} }; /// An implementation of MetadataReader's BuilderType concept for @@ -384,9 +384,9 @@ class TypeRefBuilder { public: using BuiltType = const TypeRef *; - using BuiltTypeDecl = llvm::Optional; + using BuiltTypeDecl = std::optional; using BuiltProtocolDecl = - llvm::Optional>; + std::optional>; using BuiltSubstitution = std::pair; using BuiltRequirement = TypeRefRequirement; using BuiltLayoutConstraint = TypeRefLayoutConstraint; @@ -506,7 +506,7 @@ public: return readTypeRef(remoteAddr); } - llvm::Optional normalizeReflectionName(RemoteRef name); + std::optional normalizeReflectionName(RemoteRef name); private: /// Get the primitive type lowering for a builtin type. @@ -519,10 +519,10 @@ public: void populateFieldTypeInfoCacheWithReflectionAtIndex(size_t Index); - llvm::Optional> + std::optional> findFieldDescriptorAtIndex(size_t Index, const std::string &MangledName); - llvm::Optional> + std::optional> getFieldDescriptorFromExternalCache(const std::string &MangledName); bool reflectionNameMatches(RemoteRef reflectionName, @@ -539,7 +539,7 @@ public: /// Cache for normalized reflection name lookups. std::unordered_map> + std::optional> NormalizedReflectionNameCache; /// Cache for built-in type descriptor lookups. @@ -572,7 +572,7 @@ public: void dumpTypeRef(RemoteRef MangledName, std::ostream &stream, bool printTypeName = false); FieldTypeCollectionResult - collectFieldTypes(llvm::Optional forMangledTypeName); + collectFieldTypes(std::optional forMangledTypeName); void dumpFieldSection(std::ostream &stream); void dumpBuiltinTypeSection(std::ostream &stream); void dumpCaptureSection(std::ostream &stream); @@ -581,13 +581,13 @@ public: template