Skip to content

Commit 5b9e89a

Browse files
committed
Swift: implement ignoring of removed classes
1 parent e26e0ec commit 5b9e89a

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

swift/extractor/infra/SwiftTagTraits.h

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,39 @@
99

1010
namespace codeql {
1111

12-
// codegen goes with QL acronym convention (Sil instead of SIL), we need to remap it to Swift's
13-
// convention
14-
using SILBlockStorageTypeTag = SilBlockStorageTypeTag;
15-
using SILBoxTypeTag = SilBoxTypeTag;
16-
using SILFunctionTypeTag = SilFunctionTypeTag;
17-
using SILTokenTypeTag = SilTokenTypeTag;
18-
1912
// OverloadSetRefExpr is collapsed with its only derived class OverloadedDeclRefExpr
2013
using OverloadSetRefExprTag = OverloadedDeclRefExprTag;
2114

15+
// We don't really expect to see the following in extraction. Mapping these tags to void effectively
16+
// ignores all elements of that class (with a message).
17+
18+
// only generated for code editing
19+
using CodeCompletionExprTag = void;
20+
using EditorPlaceholderExprTag = void;
21+
// not present after the Sema phase
22+
using ArrowExprTag = void;
23+
// experimental variadic generics, implemented only in the frontend for now, thus not compilable
24+
using PackExprTag = void;
25+
using PackTypeTag = void;
26+
using ReifyPackExprTag = void;
27+
using PackExpansionTypeTag = void;
28+
// Placeholder types appear in ambiguous types but are anyway transformed to UnresolvedType
29+
using PlaceholderTypeTag = void;
30+
// SIL types that cannot really appear in the frontend run
31+
using SILBlockStorageTypeTag = void;
32+
using SILBoxTypeTag = void;
33+
using SILFunctionTypeTag = void;
34+
using SILTokenTypeTag = void;
35+
2236
#define MAP_TYPE_TO_TAG(TYPE, TAG) \
2337
template <> \
2438
struct detail::ToTagFunctor<TYPE> { \
2539
using type = TAG; \
2640
}
2741
#define MAP_TAG(TYPE) MAP_TYPE_TO_TAG(swift::TYPE, TYPE##Tag)
28-
#define MAP_SUBTAG(TYPE, PARENT) \
29-
MAP_TAG(TYPE); \
30-
static_assert(std::is_base_of_v<PARENT##Tag, TYPE##Tag>, \
42+
#define MAP_SUBTAG(TYPE, PARENT) \
43+
MAP_TAG(TYPE); \
44+
static_assert(std::is_same_v<TYPE##Tag, void> || std::is_base_of_v<PARENT##Tag, TYPE##Tag>, \
3145
#PARENT "Tag must be a base of " #TYPE "Tag");
3246

3347
#define OVERRIDE_TAG(TYPE, TAG) \

swift/extractor/translators/ExprTranslator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ static int translatePropertyWrapperValueKind(swift::AppliedPropertyWrapperExpr::
584584
return 0;
585585
}
586586
}
587+
587588
codeql::AppliedPropertyWrapperExpr ExprTranslator::translateAppliedPropertyWrapperExpr(
588589
const swift::AppliedPropertyWrapperExpr& expr) {
589590
auto entry = createExprEntry(expr);

swift/extractor/translators/TranslatorBase.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,15 @@ DEFINE_TRANSLATE_CHECKER(TypeRepr, , )
6262
// superclasses by default and instead provide our own TBD default (using the exact type).
6363
// Moreover, if the implementation class has translate##CLASS##KIND (that uses generated C++
6464
// classes), for the class of for a parent thereof, we want to use that. We detect that by using the
65-
// type traits HasTranslate##CLASS##KIND defined above
65+
// type traits HasTranslate##CLASS##KIND defined above.
66+
// A special case is for explicitly ignored classes marked with void, which we should never
67+
// encounter.
6668
#define DEFINE_VISIT(KIND, CLASS, PARENT) \
6769
void visit##CLASS##KIND(swift::CLASS##KIND* e) { \
68-
if constexpr (detail::HasTranslate##CLASS##KIND<CrtpSubclass>::value) { \
70+
if constexpr (std::is_same_v<CLASS##KIND##Tag, void>) { \
71+
std::cerr << "Unexpected " #CLASS #KIND "\n"; \
72+
return; \
73+
} else if constexpr (detail::HasTranslate##CLASS##KIND<CrtpSubclass>::value) { \
6974
dispatcher.emit(static_cast<CrtpSubclass*>(this)->translate##CLASS##KIND(*e)); \
7075
} else if constexpr (detail::HasTranslate##PARENT<CrtpSubclass>::value) { \
7176
dispatcher.emit(static_cast<CrtpSubclass*>(this)->translate##PARENT(*e)); \
@@ -105,9 +110,6 @@ class AstTranslatorBase : private swift::ASTVisitor<CrtpSubclass>,
105110

106111
#define PATTERN(CLASS, PARENT) DEFINE_VISIT(Pattern, CLASS, PARENT)
107112
#include "swift/AST/PatternNodes.def"
108-
109-
#define TYPEREPR(CLASS, PARENT) DEFINE_VISIT(TypeRepr, CLASS, PARENT)
110-
#include "swift/AST/TypeReprNodes.def"
111113
};
112114

113115
// base class for our type visitor, getting a SwiftDispatcher member and define_visit emission for

0 commit comments

Comments
 (0)