Skip to content

Swift: make extractor compile again after 6.1 upgrade #19315

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 16 commits into from
Apr 25, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Swift: make extractor compile again after 6.1 upgrade
  • Loading branch information
redsun82 authored and Paolo Tranquilli committed Apr 23, 2025
commit 1ac47a892b6ef5f70d858df4531f663f509ec68f
2 changes: 1 addition & 1 deletion swift/extractor/SwiftExtractor.cpp
Original file line number Diff line number Diff line change
@@ -155,7 +155,7 @@ static std::unordered_set<swift::ModuleDecl*> extractDeclarations(
if (primaryFile && primaryFile->getBufferID()) {
auto& sourceManager = compiler.getSourceMgr();
auto tokens = swift::tokenize(compiler.getInvocation().getLangOptions(), sourceManager,
*primaryFile->getBufferID());
primaryFile->getBufferID());
for (auto& token : tokens) {
if (token.getKind() == swift::tok::comment) {
comments.push_back(token);
1 change: 1 addition & 0 deletions swift/extractor/infra/SwiftLocationExtractor.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <swift/AST/ASTAllocated.h>
#include <llvm/ADT/DenseMap.h> // needed (but not included) by the following header
#include <swift/AST/AvailabilitySpec.h>
#include <swift/AST/Expr.h>
#include <swift/AST/SourceFile.h>
7 changes: 5 additions & 2 deletions swift/extractor/infra/SwiftTagTraits.h
Original file line number Diff line number Diff line change
@@ -177,6 +177,7 @@ MAP(swift::Expr, ExprTag)
MAP(swift::ABISafeConversionExpr, AbiSafeConversionExprTag) // different acronym convention
MAP(swift::ActorIsolationErasureExpr, ActorIsolationErasureExprTag)
MAP(swift::UnreachableExpr, UnreachableExprTag)
MAP(swift::UnsafeCastExpr, void) // TODO swift 6.1
MAP(swift::ExplicitCastExpr, ExplicitCastExprTag)
MAP(swift::CheckedCastExpr, CheckedCastExprTag)
MAP(swift::ForcedCheckedCastExpr, ForcedCheckedCastExprTag)
@@ -204,6 +205,7 @@ MAP(swift::Expr, ExprTag)
MAP(swift::SingleValueStmtExpr, SingleValueStmtExprTag)
MAP(swift::ExtractFunctionIsolationExpr, ExtractFunctionIsolationExprTag)
MAP(swift::CurrentContextIsolationExpr, CurrentContextIsolationExprTag)
MAP(swift::TypeValueExpr, void) // TODO swift 6.1
MAP(swift::Decl, DeclTag)
MAP(swift::ValueDecl, ValueDeclTag)
MAP(swift::TypeDecl, TypeDeclTag)
@@ -235,7 +237,6 @@ MAP(swift::Decl, DeclTag)
MAP(swift::ExtensionDecl, ExtensionDeclTag)
MAP(swift::TopLevelCodeDecl, TopLevelCodeDeclTag)
MAP(swift::ImportDecl, ImportDeclTag)
MAP(swift::IfConfigDecl, IfConfigDeclTag)
MAP(swift::PoundDiagnosticDecl, PoundDiagnosticDeclTag)
MAP(swift::PrecedenceGroupDecl, PrecedenceGroupDeclTag)
MAP(swift::MissingMemberDecl, MissingMemberDeclTag)
@@ -284,6 +285,8 @@ MAP(swift::TypeBase, TypeTag)
MAP(swift::BuiltinVectorType, BuiltinVectorTypeTag)
MAP(swift::BuiltinPackIndexType, void) // SIL type, cannot really appear in the frontend run
MAP(swift::BuiltinNonDefaultDistributedActorStorageType, void) // Does not appear in AST/SIL, only used during IRGen
MAP(swift::BuiltinFixedArrayType, void) // TODO swift 6.1
MAP(swift::BuiltinUnboundGenericType, void) // TODO swift 6.1
MAP(swift::TupleType, TupleTypeTag)
MAP(swift::ReferenceStorageType, ReferenceStorageTypeTag)
MAP(swift::WeakStorageType, WeakStorageTypeTag)
@@ -336,8 +339,8 @@ MAP(swift::TypeBase, TypeTag)
MAP(swift::PackElementType, PackElementTypeTag)
MAP(swift::TypeVariableType, void) // created during type checking and only used for constraint checking
MAP(swift::ErrorUnionType, void) // created during type checking and only used for constraint checking
MAP(swift::IntegerType, void) // TODO swift 6.1
MAP(swift::SugarType, SugarTypeTag)
MAP(swift::ParenType, ParenTypeTag)
MAP(swift::TypeAliasType, TypeAliasTypeTag)
MAP(swift::SyntaxSugarType, SyntaxSugarTypeTag)
MAP(swift::UnarySyntaxSugarType, UnarySyntaxSugarTypeTag)
11 changes: 4 additions & 7 deletions swift/extractor/mangler/SwiftMangler.cpp
Original file line number Diff line number Diff line change
@@ -353,9 +353,10 @@ SwiftMangledName SwiftMangler::visitOpaqueTypeArchetypeType(
}

SwiftMangledName SwiftMangler::visitOpenedArchetypeType(const swift::OpenedArchetypeType* type) {
llvm::SmallVector<char> uuid;
type->getOpenedExistentialID().toString(uuid);
return visitArchetypeType(type) << std::string_view(uuid.data(), uuid.size());
// llvm::SmallVector<char> uuid;
// type->getOpenedExistentialID().toString(uuid); // <- doesn't compile any more
// return visitArchetypeType(type) << std::string_view(uuid.data(), uuid.size());
return visitArchetypeType(type);
}

SwiftMangledName SwiftMangler::visitProtocolCompositionType(
@@ -370,10 +371,6 @@ SwiftMangledName SwiftMangler::visitProtocolCompositionType(
return ret;
}

SwiftMangledName SwiftMangler::visitParenType(const swift::ParenType* type) {
return initMangled(type) << fetch(type->getUnderlyingType());
}

SwiftMangledName SwiftMangler::visitLValueType(const swift::LValueType* type) {
return initMangled(type) << fetch(type->getObjectType());
}
1 change: 0 additions & 1 deletion swift/extractor/mangler/SwiftMangler.h
Original file line number Diff line number Diff line change
@@ -94,7 +94,6 @@ class SwiftMangler : private swift::TypeVisitor<SwiftMangler, SwiftMangledName>,
SwiftMangledName visitOpaqueTypeArchetypeType(const swift::OpaqueTypeArchetypeType* type);
SwiftMangledName visitOpenedArchetypeType(const swift::OpenedArchetypeType* type);
SwiftMangledName visitProtocolCompositionType(const swift::ProtocolCompositionType* type);
SwiftMangledName visitParenType(const swift::ParenType* type);
SwiftMangledName visitLValueType(const swift::LValueType* type);
SwiftMangledName visitDynamicSelfType(const swift::DynamicSelfType* type);
SwiftMangledName visitUnboundGenericType(const swift::UnboundGenericType* type);
8 changes: 0 additions & 8 deletions swift/extractor/translators/DeclTranslator.cpp
Original file line number Diff line number Diff line change
@@ -334,14 +334,6 @@ void DeclTranslator::fillAbstractStorageDecl(const swift::AbstractStorageDecl& d
fillValueDecl(decl, entry);
}

codeql::IfConfigDecl DeclTranslator::translateIfConfigDecl(const swift::IfConfigDecl& decl) {
auto entry = createEntry(decl);
if (auto activeClause = decl.getActiveClause()) {
entry.active_elements = dispatcher.fetchRepeatedLabels(activeClause->Elements);
}
return entry;
}

codeql::OpaqueTypeDecl DeclTranslator::translateOpaqueTypeDecl(const swift::OpaqueTypeDecl& decl) {
auto entry = createEntry(decl);
fillTypeDecl(decl, entry);
1 change: 0 additions & 1 deletion swift/extractor/translators/DeclTranslator.h
Original file line number Diff line number Diff line change
@@ -44,7 +44,6 @@ class DeclTranslator : public AstTranslatorBase<DeclTranslator> {
codeql::ExtensionDecl translateExtensionDecl(const swift::ExtensionDecl& decl);
codeql::ImportDecl translateImportDecl(const swift::ImportDecl& decl);
codeql::ModuleDecl translateModuleDecl(const swift::ModuleDecl& decl);
codeql::IfConfigDecl translateIfConfigDecl(const swift::IfConfigDecl& decl);
codeql::OpaqueTypeDecl translateOpaqueTypeDecl(const swift::OpaqueTypeDecl& decl);
codeql::PoundDiagnosticDecl translatePoundDiagnosticDecl(const swift::PoundDiagnosticDecl& decl);
codeql::MissingMemberDecl translateMissingMemberDecl(const swift::MissingMemberDecl& decl);
2 changes: 1 addition & 1 deletion swift/extractor/translators/ExprTranslator.cpp
Original file line number Diff line number Diff line change
@@ -624,7 +624,7 @@ codeql::AppliedPropertyWrapperExpr ExprTranslator::translateAppliedPropertyWrapp
codeql::RegexLiteralExpr ExprTranslator::translateRegexLiteralExpr(
const swift::RegexLiteralExpr& expr) {
auto entry = createExprEntry(expr);
auto pattern = expr.getRegexText();
auto pattern = expr.getParsedRegexText(); // TODO: there is now this and getRegexToEmit
// the pattern has enclosing '/' delimiters, we'd rather get it without
entry.pattern = pattern.substr(1, pattern.size() - 2);
entry.version = expr.getVersion();
6 changes: 0 additions & 6 deletions swift/extractor/translators/TypeTranslator.cpp
Original file line number Diff line number Diff line change
@@ -76,12 +76,6 @@ codeql::DependentMemberType TypeTranslator::translateDependentMemberType(
return entry;
}

codeql::ParenType TypeTranslator::translateParenType(const swift::ParenType& type) {
auto entry = createTypeEntry(type);
entry.type = dispatcher.fetchLabel(type.getUnderlyingType());
return entry;
}

codeql::OptionalType TypeTranslator::translateOptionalType(const swift::OptionalType& type) {
auto entry = createTypeEntry(type);
fillUnarySyntaxSugarType(type, entry);
1 change: 0 additions & 1 deletion swift/extractor/translators/TypeTranslator.h
Original file line number Diff line number Diff line change
@@ -24,7 +24,6 @@ class TypeTranslator : public TypeTranslatorBase<TypeTranslator> {
const swift::ExistentialMetatypeType& type);
codeql::TypeAliasType translateTypeAliasType(const swift::TypeAliasType& type);
codeql::DependentMemberType translateDependentMemberType(const swift::DependentMemberType& type);
codeql::ParenType translateParenType(const swift::ParenType& type);
codeql::UnarySyntaxSugarType translateUnarySyntaxSugarType(
const swift::UnarySyntaxSugarType& type);
codeql::OptionalType translateOptionalType(const swift::OptionalType& type);
6 changes: 3 additions & 3 deletions swift/ql/.generated.list

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion swift/ql/lib/codeql/swift/elements/MacroRole.qll

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions swift/ql/lib/codeql/swift/generated/MacroRole.qll

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion swift/ql/lib/codeql/swift/generated/Raw.qll

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions swift/ql/lib/swift.dbscheme

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion swift/schema.py
Original file line number Diff line number Diff line change
@@ -1394,7 +1394,7 @@ class MacroRole(AstNode):
"""
kind: int | doc("kind of this macro role (declaration, expression, member, etc.)") | ql.internal
macro_syntax: int | doc("#freestanding or @attached") | ql.internal
conformances: list[TypeExpr] | doc("conformances of this macro role")
conformances: list[Expr] | doc("conformances of this macro role")
names: list[string] | doc("names of this macro role")

class MacroDecl(GenericContext, ValueDecl):
4 changes: 4 additions & 0 deletions swift/third_party/load.bzl
Original file line number Diff line number Diff line change
@@ -5,6 +5,10 @@ load("//misc/bazel:lfs.bzl", "lfs_archive", "lfs_files")

_override = {
# these are used to test new artifacts. Must be empty before merging to main
"swift-prebuilt-macOS-swift-6.1-RELEASE-78.tar.zst": "4dcfe858b5519327c9b0c99735b47fe75c7a5090793d917de1ba6e42795aa86d",
"swift-prebuilt-Linux-swift-6.1-RELEASE-78.tar.zst": "d01b90bccfec46995bdf98a59339bd94e64257da99b4963148869c4a108bc2a9",
"resource-dir-macOS-swift-6.1-RELEASE-91.zip": "12bef89163486ac24d9ca00a5cc6ef3851b633e6fa63b7493c518e4d426e036c",
"resource-dir-Linux-swift-6.1-RELEASE-91.zip": "874932f93c4ca6269ae3a9e9c841916b3fd88f65f5018eec8777a52dde56901d",
}

_staging_url = "https://github.com/dsp-testing/codeql-swift-artifacts/releases/download/staging-{}/{}"