Skip to content

Commit 88dc65c

Browse files
committed
Swift: extract or ignore last remaining types
1 parent bda4b52 commit 88dc65c

26 files changed

+132
-144
lines changed

swift/extractor/infra/SwiftTagTraits.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@ using PackExprTag = void;
2525
using PackTypeTag = void;
2626
using ReifyPackExprTag = void;
2727
using PackExpansionTypeTag = void;
28+
using SequenceArchetypeTypeTag = void;
2829
// Placeholder types appear in ambiguous types but are anyway transformed to UnresolvedType
2930
using PlaceholderTypeTag = void;
3031
// SIL types that cannot really appear in the frontend run
3132
using SILBlockStorageTypeTag = void;
3233
using SILBoxTypeTag = void;
3334
using SILFunctionTypeTag = void;
3435
using SILTokenTypeTag = void;
36+
// This is created during type checking and is only used for constraint checking
37+
using TypeVariableTypeTag = void;
3538

3639
#define MAP_TYPE_TO_TAG(TYPE, TAG) \
3740
template <> \

swift/extractor/translators/TypeTranslator.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,20 @@ codeql::OpaqueTypeArchetypeType TypeTranslator::translateOpaqueTypeArchetypeType
258258
entry.declaration = dispatcher.fetchLabel(type.getDecl());
259259
return entry;
260260
}
261+
262+
codeql::ErrorType TypeTranslator::translateErrorType(const swift::ErrorType& type) {
263+
return createTypeEntry(type);
264+
}
265+
266+
codeql::UnresolvedType TypeTranslator::translateUnresolvedType(const swift::UnresolvedType& type) {
267+
return createTypeEntry(type);
268+
}
269+
270+
codeql::ParameterizedProtocolType TypeTranslator::translateParameterizedProtocolType(
271+
const swift::ParameterizedProtocolType& type) {
272+
auto entry = createTypeEntry(type);
273+
entry.base = dispatcher.fetchLabel(type.getBaseType());
274+
entry.args = dispatcher.fetchRepeatedLabels(type.getArgs());
275+
return entry;
276+
}
261277
} // namespace codeql

swift/extractor/translators/TypeTranslator.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ class TypeTranslator : public TypeTranslatorBase<TypeTranslator> {
7171
codeql::ModuleType translateModuleType(const swift::ModuleType& type);
7272
codeql::OpaqueTypeArchetypeType translateOpaqueTypeArchetypeType(
7373
const swift::OpaqueTypeArchetypeType& type);
74+
codeql::ErrorType translateErrorType(const swift::ErrorType& type);
75+
codeql::UnresolvedType translateUnresolvedType(const swift::UnresolvedType& type);
76+
codeql::ParameterizedProtocolType translateParameterizedProtocolType(
77+
const swift::ParameterizedProtocolType& type);
7478

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

swift/ql/lib/codeql/swift/elements.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,6 @@ import codeql.swift.elements.type.PrimaryArchetypeType
263263
import codeql.swift.elements.type.ProtocolCompositionType
264264
import codeql.swift.elements.type.ProtocolType
265265
import codeql.swift.elements.type.ReferenceStorageType
266-
import codeql.swift.elements.type.SequenceArchetypeType
267266
import codeql.swift.elements.type.StructType
268267
import codeql.swift.elements.type.SubstitutableType
269268
import codeql.swift.elements.type.SugarType
@@ -272,7 +271,6 @@ import codeql.swift.elements.type.TupleType
272271
import codeql.swift.elements.type.Type
273272
import codeql.swift.elements.type.TypeAliasType
274273
import codeql.swift.elements.type.TypeRepr
275-
import codeql.swift.elements.type.TypeVariableType
276274
import codeql.swift.elements.type.UnarySyntaxSugarType
277275
import codeql.swift.elements.type.UnboundGenericType
278276
import codeql.swift.elements.type.UnmanagedStorageType

swift/ql/lib/codeql/swift/elements/type/SequenceArchetypeType.qll

Lines changed: 0 additions & 4 deletions
This file was deleted.

swift/ql/lib/codeql/swift/elements/type/SequenceArchetypeTypeConstructor.qll

Lines changed: 0 additions & 4 deletions
This file was deleted.

swift/ql/lib/codeql/swift/elements/type/TypeVariableType.qll

Lines changed: 0 additions & 4 deletions
This file was deleted.

swift/ql/lib/codeql/swift/elements/type/TypeVariableTypeConstructor.qll

Lines changed: 0 additions & 4 deletions
This file was deleted.

swift/ql/lib/codeql/swift/generated/ParentChild.qll

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3953,21 +3953,6 @@ private module Impl {
39533953
)
39543954
}
39553955

3956-
private Element getImmediateChildOfTypeVariableType(
3957-
TypeVariableType e, int index, string partialPredicateCall
3958-
) {
3959-
exists(int b, int bType, int n |
3960-
b = 0 and
3961-
bType = b + 1 + max(int i | i = -1 or exists(getImmediateChildOfType(e, i, _)) | i) and
3962-
n = bType and
3963-
(
3964-
none()
3965-
or
3966-
result = getImmediateChildOfType(e, index - b, partialPredicateCall)
3967-
)
3968-
)
3969-
}
3970-
39713956
private Element getImmediateChildOfUnresolvedType(
39723957
UnresolvedType e, int index, string partialPredicateCall
39733958
) {
@@ -4522,22 +4507,6 @@ private module Impl {
45224507
)
45234508
}
45244509

4525-
private Element getImmediateChildOfSequenceArchetypeType(
4526-
SequenceArchetypeType e, int index, string partialPredicateCall
4527-
) {
4528-
exists(int b, int bArchetypeType, int n |
4529-
b = 0 and
4530-
bArchetypeType =
4531-
b + 1 + max(int i | i = -1 or exists(getImmediateChildOfArchetypeType(e, i, _)) | i) and
4532-
n = bArchetypeType and
4533-
(
4534-
none()
4535-
or
4536-
result = getImmediateChildOfArchetypeType(e, index - b, partialPredicateCall)
4537-
)
4538-
)
4539-
}
4540-
45414510
private Element getImmediateChildOfUnarySyntaxSugarType(
45424511
UnarySyntaxSugarType e, int index, string partialPredicateCall
45434512
) {
@@ -5088,8 +5057,6 @@ private module Impl {
50885057
or
50895058
result = getImmediateChildOfTupleType(e, index, partialAccessor)
50905059
or
5091-
result = getImmediateChildOfTypeVariableType(e, index, partialAccessor)
5092-
or
50935060
result = getImmediateChildOfUnresolvedType(e, index, partialAccessor)
50945061
or
50955062
result = getImmediateChildOfBuiltinBridgeObjectType(e, index, partialAccessor)
@@ -5146,8 +5113,6 @@ private module Impl {
51465113
or
51475114
result = getImmediateChildOfPrimaryArchetypeType(e, index, partialAccessor)
51485115
or
5149-
result = getImmediateChildOfSequenceArchetypeType(e, index, partialAccessor)
5150-
or
51515116
result = getImmediateChildOfArraySliceType(e, index, partialAccessor)
51525117
or
51535118
result = getImmediateChildOfBoundGenericClassType(e, index, partialAccessor)

swift/ql/lib/codeql/swift/generated/Raw.qll

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,10 @@ module Raw {
13021302

13031303
class ParameterizedProtocolType extends @parameterized_protocol_type, Type {
13041304
override string toString() { result = "ParameterizedProtocolType" }
1305+
1306+
ProtocolType getBase() { parameterized_protocol_types(this, result) }
1307+
1308+
Type getArg(int index) { parameterized_protocol_type_args(this, index, result) }
13051309
}
13061310

13071311
class ProtocolCompositionType extends @protocol_composition_type, Type {
@@ -1326,10 +1330,6 @@ module Raw {
13261330
string getName(int index) { tuple_type_names(this, index, result) }
13271331
}
13281332

1329-
class TypeVariableType extends @type_variable_type, Type {
1330-
override string toString() { result = "TypeVariableType" }
1331-
}
1332-
13331333
class UnresolvedType extends @unresolved_type, Type, UnresolvedElement {
13341334
override string toString() { result = "UnresolvedType" }
13351335
}
@@ -1479,10 +1479,6 @@ module Raw {
14791479
override string toString() { result = "PrimaryArchetypeType" }
14801480
}
14811481

1482-
class SequenceArchetypeType extends @sequence_archetype_type, ArchetypeType {
1483-
override string toString() { result = "SequenceArchetypeType" }
1484-
}
1485-
14861482
class UnarySyntaxSugarType extends @unary_syntax_sugar_type, SyntaxSugarType {
14871483
Type getBaseType() { unary_syntax_sugar_types(this, result) }
14881484
}

0 commit comments

Comments
 (0)