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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion swift/extractor/SwiftExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
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>
Expand Down
7 changes: 5 additions & 2 deletions swift/extractor/infra/SwiftTagTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 9 additions & 6 deletions swift/extractor/mangler/SwiftMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <swift/AST/Module.h>
#include <swift/AST/ParameterList.h>
#include <swift/AST/ASTContext.h>
#include <swift/AST/GenericEnvironment.h>
#include <swift/AST/GenericParamList.h>
#include <sstream>

using namespace codeql;

Expand Down Expand Up @@ -298,6 +298,12 @@ SwiftMangledName SwiftMangler::visitAnyMetatypeType(const swift::AnyMetatypeType
return initMangled(type) << fetch(type->getInstanceType());
}

SwiftMangledName SwiftMangler::visitExistentialMetatypeType(
const swift::ExistentialMetatypeType* type) {
return visitAnyMetatypeType(type)
<< fetch(const_cast<swift::ExistentialMetatypeType*>(type)->getExistentialInstanceType());
}

SwiftMangledName SwiftMangler::visitDependentMemberType(const swift::DependentMemberType* type) {
return initMangled(type) << fetch(type->getBase()) << fetch(type->getAssocType());
}
Expand Down Expand Up @@ -353,8 +359,9 @@ SwiftMangledName SwiftMangler::visitOpaqueTypeArchetypeType(
}

SwiftMangledName SwiftMangler::visitOpenedArchetypeType(const swift::OpenedArchetypeType* type) {
auto* env = type->getGenericEnvironment();
llvm::SmallVector<char> uuid;
type->getOpenedExistentialID().toString(uuid);
env->getOpenedExistentialUUID().toString(uuid);
return visitArchetypeType(type) << std::string_view(uuid.data(), uuid.size());
}

Expand All @@ -370,10 +377,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());
}
Expand Down
2 changes: 1 addition & 1 deletion swift/extractor/mangler/SwiftMangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class SwiftMangler : private swift::TypeVisitor<SwiftMangler, SwiftMangledName>,
SwiftMangledName visitGenericFunctionType(const swift::GenericFunctionType* type);
SwiftMangledName visitGenericTypeParamType(const swift::GenericTypeParamType* type);
SwiftMangledName visitAnyMetatypeType(const swift::AnyMetatypeType* type);
SwiftMangledName visitExistentialMetatypeType(const swift::ExistentialMetatypeType* type);
SwiftMangledName visitDependentMemberType(const swift::DependentMemberType* type);
SwiftMangledName visitInOutType(const swift::InOutType* type);
SwiftMangledName visitExistentialType(const swift::ExistentialType* type);
Expand All @@ -94,7 +95,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);
Expand Down
8 changes: 0 additions & 8 deletions swift/extractor/translators/DeclTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion swift/extractor/translators/DeclTranslator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion swift/extractor/translators/ExprTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
// the pattern has enclosing '/' delimiters, we'd rather get it without
entry.pattern = pattern.substr(1, pattern.size() - 2);
entry.version = expr.getVersion();
Expand Down
6 changes: 0 additions & 6 deletions swift/extractor/translators/TypeTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion swift/extractor/translators/TypeTranslator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
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
Expand Up @@ -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):
Expand Down
4 changes: 4 additions & 0 deletions swift/third_party/load.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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-{}/{}"
Expand Down
Loading