-
Notifications
You must be signed in to change notification settings - Fork 2k
Swift: Update to Swift 6.3 #21667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Swift: Update to Swift 6.3 #21667
Changes from 8 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2fbfcb9
Swift: Use Swift 6.3 artifacts
jketema fd83515
Swift: Make extractor compile
jketema d473c71
Swift: Update schema
jketema 6b2494c
Swift: Update generated files
jketema 5eb8db0
Swift: Update expected QL test results after 6.3 update
jketema f7de0ab
Swift: Fix `BuiltinFixedArrayType` mangling
jketema 7bf78de
Swift: Fix `AnyFunctionType` name mangling
jketema d09e2f6
Swift: Assign indexes to `fileprivate` `ValueDecl`s
jketema 34b626e
Swift: Update expected integration test results
jketema 7879d0a
Swift: Fix `OpaqueTypeArchetypeType` name mangling
jketema 21937c2
Swift: Add dbscheme upgrade and downgrade scripts
jketema 94fb011
Swift: Add change note
jketema 85c42ae
Swift: Update supported versions
jketema 4ada727
Swift: Add staged archives to LFS
jketema 43f4800
Swift: Clear override
jketema 07b0294
Merge remote-tracking branch 'upstream/main' into jketema/swift-6.3
jketema 7d1c62d
Swift: Address review comment
jketema File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,8 +40,8 @@ std::string_view getTypeKindStr(const swift::TypeBase* type) { | |
|
|
||
| } // namespace | ||
|
|
||
| std::unordered_map<const swift::Decl*, SwiftMangler::ExtensionIndex> | ||
| SwiftMangler::preloadedExtensionIndexes; | ||
| std::unordered_map<const swift::Decl*, SwiftMangler::ExtensionOrFilePrivateValueIndex> | ||
| SwiftMangler::preloadedExtensionOrFilePrivateValueIndexes; | ||
|
|
||
| SwiftMangledName SwiftMangler::initMangled(const swift::TypeBase* type) { | ||
| return {getTypeKindStr(type), '_'}; | ||
|
|
@@ -75,6 +75,12 @@ SwiftMangledName SwiftMangler::visitValueDecl(const swift::ValueDecl* decl, bool | |
| if (decl->isStatic()) { | ||
| ret << "|static"; | ||
| } | ||
| if (decl->getFormalAccess() == swift::AccessLevel::FilePrivate) { | ||
| auto parent = getParent(decl); | ||
| auto index = getExtensionOrFilePrivateValueIndex(decl, parent); | ||
| ret << "|fileprivate" << index.index | ||
| << (index.kind == ExtensionOrFilePrivateValueKind::clang ? "_clang" : ""); | ||
| } | ||
| return ret; | ||
| } | ||
|
|
||
|
|
@@ -105,51 +111,63 @@ SwiftMangledName SwiftMangler::visitExtensionDecl(const swift::ExtensionDecl* de | |
|
|
||
| auto parent = getParent(decl); | ||
| auto target = decl->getExtendedType(); | ||
| auto index = getExtensionIndex(decl, parent); | ||
| auto index = getExtensionOrFilePrivateValueIndex(decl, parent); | ||
| return initMangled(decl) << fetch(target) << index.index | ||
| << (index.kind == ExtensionKind::clang ? "_clang" : ""); | ||
| << (index.kind == ExtensionOrFilePrivateValueKind::clang ? "_clang" | ||
| : ""); | ||
| } | ||
|
|
||
| SwiftMangler::ExtensionIndex SwiftMangler::getExtensionIndex(const swift::ExtensionDecl* decl, | ||
| const swift::Decl* parent) { | ||
| // to avoid iterating multiple times on the parent of multiple extensions, we preload extension | ||
| // indexes once for each encountered parent into the `preloadedExtensionIndexes` mapping. | ||
| if (auto found = SwiftMangler::preloadedExtensionIndexes.find(decl); | ||
| found != SwiftMangler::preloadedExtensionIndexes.end()) { | ||
| SwiftMangler::ExtensionOrFilePrivateValueIndex SwiftMangler::getExtensionOrFilePrivateValueIndex( | ||
| const swift::Decl* decl, | ||
| const swift::Decl* parent) { | ||
| // to avoid iterating multiple times on the parent, we preload the indexes once for each | ||
| // encountered parent. | ||
| if (auto found = SwiftMangler::preloadedExtensionOrFilePrivateValueIndexes.find(decl); | ||
| found != SwiftMangler::preloadedExtensionOrFilePrivateValueIndexes.end()) { | ||
| return found->second; | ||
| } | ||
| if (auto parentModule = llvm::dyn_cast<swift::ModuleDecl>(parent)) { | ||
| llvm::SmallVector<swift::Decl*> siblings; | ||
| parentModule->getTopLevelDecls(siblings); | ||
| indexExtensions(siblings); | ||
| indexExtensionsAndFilePrivateValues(siblings); | ||
| if (auto clangModule = parentModule->findUnderlyingClangModule()) { | ||
| indexClangExtensions(clangModule, decl->getASTContext().getClangModuleLoader()); | ||
| indexClangExtensionsAndFilePrivateValues(clangModule, | ||
| decl->getASTContext().getClangModuleLoader()); | ||
| } | ||
| } else if (auto iterableParent = llvm::dyn_cast<swift::IterableDeclContext>(parent)) { | ||
| indexExtensions(iterableParent->getAllMembers()); | ||
| indexExtensionsAndFilePrivateValues(iterableParent->getAllMembers()); | ||
| } else { | ||
| // TODO use a generic logging handle for Swift entities here, once it's available | ||
| CODEQL_ASSERT(false, "non-local context must be module or iterable decl context"); | ||
| } | ||
| auto found = SwiftMangler::preloadedExtensionIndexes.find(decl); | ||
| auto found = SwiftMangler::preloadedExtensionOrFilePrivateValueIndexes.find(decl); | ||
| // TODO use a generic logging handle for Swift entities here, once it's available | ||
| CODEQL_ASSERT(found != SwiftMangler::preloadedExtensionIndexes.end(), | ||
| "extension not found within parent"); | ||
| CODEQL_ASSERT(found != SwiftMangler::preloadedExtensionOrFilePrivateValueIndexes.end(), | ||
| "declaration not found within parent"); | ||
| return found->second; | ||
| } | ||
|
|
||
| void SwiftMangler::indexExtensions(llvm::ArrayRef<swift::Decl*> siblings) { | ||
| bool SwiftMangler::isExtensionOrFilePrivateValue(const swift::Decl* decl) { | ||
| return decl->getKind() == swift::DeclKind::Extension || | ||
| (swift::isa<swift::ValueDecl>(decl) && | ||
|
IdrissRio marked this conversation as resolved.
Outdated
|
||
| swift::dyn_cast<swift::ValueDecl>(decl)->getFormalAccess() == | ||
| swift::AccessLevel::FilePrivate); | ||
| } | ||
|
|
||
| void SwiftMangler::indexExtensionsAndFilePrivateValues(llvm::ArrayRef<swift::Decl*> siblings) { | ||
| auto index = 0u; | ||
| for (auto sibling : siblings) { | ||
| if (sibling->getKind() == swift::DeclKind::Extension) { | ||
| SwiftMangler::preloadedExtensionIndexes.try_emplace(sibling, ExtensionKind::swift, index); | ||
| if (isExtensionOrFilePrivateValue(sibling)) { | ||
| SwiftMangler::preloadedExtensionOrFilePrivateValueIndexes.try_emplace( | ||
| sibling, ExtensionOrFilePrivateValueKind::swift, index); | ||
| index++; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void SwiftMangler::indexClangExtensions(const clang::Module* clangModule, | ||
| swift::ClangModuleLoader* moduleLoader) { | ||
| void SwiftMangler::indexClangExtensionsAndFilePrivateValues( | ||
| const clang::Module* clangModule, | ||
| swift::ClangModuleLoader* moduleLoader) { | ||
| if (!moduleLoader) { | ||
| return; | ||
| } | ||
|
|
@@ -160,8 +178,9 @@ void SwiftMangler::indexClangExtensions(const clang::Module* clangModule, | |
| llvm::SmallVector<swift::Decl*> children; | ||
| swiftSubmodule->getTopLevelDecls(children); | ||
| for (const auto child : children) { | ||
| if (child->getKind() == swift::DeclKind::Extension) { | ||
| SwiftMangler::preloadedExtensionIndexes.try_emplace(child, ExtensionKind::clang, index); | ||
| if (isExtensionOrFilePrivateValue(child)) { | ||
| SwiftMangler::preloadedExtensionOrFilePrivateValueIndexes.try_emplace( | ||
| child, ExtensionOrFilePrivateValueKind::clang, index); | ||
| index++; | ||
| } | ||
| } | ||
|
|
@@ -202,6 +221,14 @@ SwiftMangledName SwiftMangler::visitBuiltinType(const swift::BuiltinType* type) | |
| return initMangled(type) << type->getTypeName(buffer, /* prependBuiltinNamespace= */ false); | ||
| } | ||
|
|
||
| SwiftMangledName SwiftMangler::visitBuiltinFixedArrayType( | ||
| const swift::BuiltinFixedArrayType* type) { | ||
| auto ret = visitBuiltinType(type); | ||
| ret << fetch(type->getSize()); | ||
| ret << fetch(type->getElementType()); | ||
| return ret; | ||
| } | ||
|
|
||
| SwiftMangledName SwiftMangler::visitAnyGenericType(const swift::AnyGenericType* type) { | ||
| auto ret = initMangled(type); | ||
| auto decl = type->getDecl(); | ||
|
|
@@ -240,9 +267,6 @@ SwiftMangledName SwiftMangler::visitAnyFunctionType(const swift::AnyFunctionType | |
| if (flags.isNonEphemeral()) { | ||
| ret << "_nonephermeral"; | ||
| } | ||
| if (flags.isIsolated()) { | ||
|
jketema marked this conversation as resolved.
|
||
| ret << "_isolated"; | ||
| } | ||
|
Comment on lines
-243
to
-245
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that this was duplicating the first |
||
| if (flags.isSending()) { | ||
| ret << "_sending"; | ||
| } | ||
|
|
@@ -309,9 +333,13 @@ SwiftMangledName SwiftMangler::visitAnyFunctionType(const swift::AnyFunctionType | |
| if (type->hasGlobalActor()) { | ||
| ret << "_actor" << fetch(type->getGlobalActor()); | ||
| } | ||
| if (type->getIsolation().isErased()) { | ||
| const auto& isolation = type->getIsolation(); | ||
| if (isolation.isErased()) { | ||
| ret << "_isolated"; | ||
| } | ||
| if (isolation.isNonIsolatedCaller()) { | ||
| ret << "_nonisolatednonsending"; | ||
|
jketema marked this conversation as resolved.
IdrissRio marked this conversation as resolved.
|
||
| } | ||
| // TODO: see if this needs to be used in identifying types, if not it needs to be removed from | ||
| // type printing in the Swift compiler code | ||
| assert(type->hasExtInfo() && "type must have ext info"); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.