From 3a727a504b1ea1e224ca36c4a8297f8724024ba3 Mon Sep 17 00:00:00 2001 From: Alex Denisov Date: Wed, 5 Jul 2023 17:04:38 +0200 Subject: [PATCH] Swift: minimal 5.9 support --- swift/extractor/SwiftExtractor.cpp | 4 +-- swift/extractor/infra/SwiftTagTraits.h | 13 +++++++- swift/third_party/load.bzl | 1 - .../patches/remove-result-of.patch | 30 ------------------- 4 files changed, 14 insertions(+), 34 deletions(-) delete mode 100644 swift/third_party/swift-llvm-support/patches/remove-result-of.patch diff --git a/swift/extractor/SwiftExtractor.cpp b/swift/extractor/SwiftExtractor.cpp index 77e27c00f418..fac53c2854f9 100644 --- a/swift/extractor/SwiftExtractor.cpp +++ b/swift/extractor/SwiftExtractor.cpp @@ -170,10 +170,10 @@ static std::unordered_set extractDeclarations( } std::vector comments; - if (primaryFile && primaryFile->getBufferID().hasValue()) { + if (primaryFile && primaryFile->getBufferID().has_value()) { auto& sourceManager = compiler.getSourceMgr(); auto tokens = swift::tokenize(compiler.getInvocation().getLangOptions(), sourceManager, - primaryFile->getBufferID().getValue()); + primaryFile->getBufferID().value()); for (auto& token : tokens) { if (token.getKind() == swift::tok::comment) { comments.push_back(token); diff --git a/swift/extractor/infra/SwiftTagTraits.h b/swift/extractor/infra/SwiftTagTraits.h index 0371a783bb79..6559bf9eff0c 100644 --- a/swift/extractor/infra/SwiftTagTraits.h +++ b/swift/extractor/infra/SwiftTagTraits.h @@ -56,6 +56,7 @@ MAP(swift::Stmt, StmtTag) MAP(swift::FailStmt, FailStmtTag) MAP(swift::ThrowStmt, ThrowStmtTag) MAP(swift::PoundAssertStmt, PoundAssertStmtTag) + MAP(swift::DiscardStmt, void) // TODO (introduced in 5.9) MAP(swift::Argument, ArgumentTag) MAP(swift::KeyPathExpr::Component, KeyPathComponentTag) @@ -95,7 +96,7 @@ MAP(swift::Expr, ExprTag) MAP(swift::IdentityExpr, IdentityExprTag) MAP(swift::ParenExpr, ParenExprTag) MAP(swift::DotSelfExpr, DotSelfExprTag) - MAP(swift::MoveExpr, void) // TODO (introduced in 5.8) + MAP(swift::BorrowExpr, void) // TODO (introduced in 5.9) MAP(swift::AwaitExpr, AwaitExprTag) MAP(swift::UnresolvedMemberChainResultExpr, UnresolvedMemberChainResultExprTag) MAP(swift::AnyTryExpr, AnyTryExprTag) @@ -189,6 +190,11 @@ MAP(swift::Expr, ExprTag) MAP(swift::TapExpr, TapExprTag) MAP(swift::TypeJoinExpr, void) // TODO (introduced in 5.8) MAP(swift::MacroExpansionExpr, void) // TODO (introduced in 5.8) + MAP(swift::CopyExpr, void) // TODO (introduced in 5.9) + MAP(swift::ConsumeExpr, void) // TODO (introduced in 5.9) + MAP(swift::MaterializePackExpr, void) // TODO (introduced in 5.9) + MAP(swift::SingleValueStmtExpr, void) // TODO (introduced in 5.9) + MAP(swift::Decl, DeclTag) MAP(swift::ValueDecl, ValueDeclTag) MAP(swift::TypeDecl, TypeDeclTag) @@ -231,6 +237,7 @@ MAP(swift::Decl, DeclTag) MAP(swift::PrefixOperatorDecl, PrefixOperatorDeclTag) MAP(swift::PostfixOperatorDecl, PostfixOperatorDeclTag) MAP(swift::MacroExpansionDecl, void) // TODO (introduced in 5.8) + MAP(swift::MissingDecl, void) // TODO (introduced in 5.9) MAP(swift::Pattern, PatternTag) MAP(swift::ParenPattern, ParenPatternTag) @@ -266,6 +273,8 @@ MAP(swift::TypeBase, TypeTag) MAP(swift::BuiltinUnsafeValueBufferType, BuiltinUnsafeValueBufferTypeTag) MAP(swift::BuiltinDefaultActorStorageType, BuiltinDefaultActorStorageTypeTag) MAP(swift::BuiltinVectorType, BuiltinVectorTypeTag) + MAP(swift::BuiltinPackIndexType, void) // TODO: (introduced in 5.9) + MAP(swift::BuiltinNonDefaultDistributedActorStorageType, void) // TODO: (introduced in 5.9) MAP(swift::TupleType, TupleTypeTag) MAP(swift::ReferenceStorageType, ReferenceStorageTypeTag) MAP(swift::WeakStorageType, WeakStorageTypeTag) @@ -307,6 +316,7 @@ MAP(swift::TypeBase, TypeTag) MAP(swift::SILBoxType, void) // SIL types cannot really appear in the frontend run) MAP(swift::SILMoveOnlyWrappedType, void) // SIL types cannot really appear in the frontend run) MAP(swift::SILTokenType, void) // SIL types cannot really appear in the frontend run) + MAP(swift::SILPackType, void) // TODO: (introduced in 5.9) MAP(swift::ProtocolCompositionType, ProtocolCompositionTypeTag) MAP(swift::ParameterizedProtocolType, ParameterizedProtocolTypeTag) MAP(swift::ExistentialType, ExistentialTypeTag) @@ -314,6 +324,7 @@ MAP(swift::TypeBase, TypeTag) MAP(swift::InOutType, InOutTypeTag) MAP(swift::PackType, void) // experimental variadic generics MAP(swift::PackExpansionType, void) // experimental variadic generics + MAP(swift::PackElementType, void) // TODO: (introduced in 5.9) MAP(swift::TypeVariableType, void) // created during type checking and only used for constraint checking MAP(swift::SugarType, SugarTypeTag) MAP(swift::ParenType, ParenTypeTag) diff --git a/swift/third_party/load.bzl b/swift/third_party/load.bzl index 9cefc77948d1..cfeb9ef7a9d8 100644 --- a/swift/third_party/load.bzl +++ b/swift/third_party/load.bzl @@ -46,7 +46,6 @@ def load_dependencies(workspace_name): patches = [ "@%s//swift/third_party/swift-llvm-support:patches/%s.patch" % (workspace_name, patch_name) for patch_name in ( - "remove-result-of", "remove-redundant-operators", "add-constructor-to-Compilation", ) diff --git a/swift/third_party/swift-llvm-support/patches/remove-result-of.patch b/swift/third_party/swift-llvm-support/patches/remove-result-of.patch deleted file mode 100644 index ab3f2155b678..000000000000 --- a/swift/third_party/swift-llvm-support/patches/remove-result-of.patch +++ /dev/null @@ -1,30 +0,0 @@ -`std::result_of` was removed in C++20, but is still used in the Swift headers. We can't -remove it from there before prebuilding, as that is still done with C++14, but we can -replace it with `std::invoke_result` for compiling the extractor. - -diff --git a/include/swift/Basic/RelativePointer.h b/include/swift/Basic/RelativePointer.h -index 73f91262afa..bdaa304c804 100644 ---- a/include/swift/Basic/RelativePointer.h -+++ b/include/swift/Basic/RelativePointer.h -@@ -551,7 +551,7 @@ public: - } - - template -- typename std::result_of::type operator()(ArgTy... arg) const { -+ typename std::invoke_result::type operator()(ArgTy... arg) const { - #if SWIFT_PTRAUTH - void *ptr = this->super::getWithoutCast(); - return reinterpret_cast(ptrauth_sign_unauthenticated( -diff --git a/include/swift/Basic/STLExtras.h b/include/swift/Basic/STLExtras.h -index 7fa3d0c8890..6bc891a9b63 100644 ---- a/include/swift/Basic/STLExtras.h -+++ b/include/swift/Basic/STLExtras.h -@@ -405,7 +405,7 @@ class OptionalTransformIterator { - typename std::iterator_traits::reference; - - using ResultReference = -- typename std::result_of::type; -+ typename std::invoke_result::type; - - public: - /// Used to indicate when the current iterator has already been