Skip to content

Commit 346110e

Browse files
committed
Swift: extract DynamicSelfType
1 parent 4281605 commit 346110e

File tree

9 files changed

+36
-5
lines changed

9 files changed

+36
-5
lines changed

swift/codegen/schema.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ DependentMemberType:
9393

9494
DynamicSelfType:
9595
_extends: Type
96+
static_self_type: Type
9697

9798
ErrorType:
9899
_extends: Type

swift/extractor/visitors/TypeVisitor.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,18 @@ void TypeVisitor::fillArchetypeType(const swift::ArchetypeType& type, ArchetypeT
253253
entry.superclass = dispatcher_.fetchOptionalLabel(type.getSuperclass());
254254
fillType(type, entry);
255255
}
256+
256257
codeql::ExistentialType TypeVisitor::translateExistentialType(const swift::ExistentialType& type) {
257258
codeql::ExistentialType entry{dispatcher_.assignNewLabel(type)};
258259
entry.constraint = dispatcher_.fetchLabel(type.getConstraintType());
259260
fillType(type, entry);
260261
return entry;
261262
}
263+
codeql::DynamicSelfType TypeVisitor::translateDynamicSelfType(const swift::DynamicSelfType& type) {
264+
codeql::DynamicSelfType entry{dispatcher_.assignNewLabel(type)};
265+
entry.static_self_type = dispatcher_.fetchLabel(type.getSelfType());
266+
fillType(type, entry);
267+
return entry;
268+
}
262269

263270
} // namespace codeql

swift/extractor/visitors/TypeVisitor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class TypeVisitor : public TypeVisitorBase<TypeVisitor> {
3939
const swift::PrimaryArchetypeType& type);
4040
codeql::NestedArchetypeType translateNestedArchetypeType(const swift::NestedArchetypeType& type);
4141
codeql::ExistentialType translateExistentialType(const swift::ExistentialType& type);
42+
codeql::DynamicSelfType translateDynamicSelfType(const swift::DynamicSelfType& type);
4243

4344
private:
4445
void fillType(const swift::TypeBase& type, codeql::Type& entry);

swift/ql/lib/codeql/swift/generated/type/DynamicSelfType.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,11 @@ import codeql.swift.elements.type.Type
33

44
class DynamicSelfTypeBase extends @dynamic_self_type, Type {
55
override string getAPrimaryQlClass() { result = "DynamicSelfType" }
6+
7+
Type getStaticSelfType() {
8+
exists(Type x |
9+
dynamic_self_types(this, x) and
10+
result = x.resolve()
11+
)
12+
}
613
}

swift/ql/lib/swift.dbscheme

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ dependent_member_types( //dir=type
244244
);
245245

246246
dynamic_self_types( //dir=type
247-
unique int id: @dynamic_self_type
247+
unique int id: @dynamic_self_type,
248+
int static_self_type: @type ref
248249
);
249250

250251
error_types( //dir=type
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| Self | getDiagnosticsName: | Self | getCanonicalType: | Self | getStaticSelfType: | X |
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// generated by codegen/codegen.py
2+
import codeql.swift.elements
3+
import TestUtils
4+
5+
from DynamicSelfType x, string getDiagnosticsName, Type getCanonicalType, Type getStaticSelfType
6+
where
7+
toBeTested(x) and
8+
not x.isUnknown() and
9+
getDiagnosticsName = x.getDiagnosticsName() and
10+
getCanonicalType = x.getCanonicalType() and
11+
getStaticSelfType = x.getStaticSelfType()
12+
select x, "getDiagnosticsName:", getDiagnosticsName, "getCanonicalType:", getCanonicalType,
13+
"getStaticSelfType:", getStaticSelfType

swift/ql/test/extractor-tests/generated/type/DynamicSelfType/MISSING_SOURCE.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class X {
2+
class func create() -> Self { return Self() }
3+
required init() {}
4+
}

0 commit comments

Comments
 (0)