Skip to content

Commit 7b6cb70

Browse files
authored
Merge pull request github#11213 from github/redsun82/swift-types
Swift: extract or ignore last remaining types
2 parents d567ab3 + 3816361 commit 7b6cb70

26 files changed

+132
-148
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
@@ -3990,21 +3990,6 @@ private module Impl {
39903990
)
39913991
}
39923992

3993-
private Element getImmediateChildOfTypeVariableType(
3994-
TypeVariableType e, int index, string partialPredicateCall
3995-
) {
3996-
exists(int b, int bType, int n |
3997-
b = 0 and
3998-
bType = b + 1 + max(int i | i = -1 or exists(getImmediateChildOfType(e, i, _)) | i) and
3999-
n = bType and
4000-
(
4001-
none()
4002-
or
4003-
result = getImmediateChildOfType(e, index - b, partialPredicateCall)
4004-
)
4005-
)
4006-
}
4007-
40083993
private Element getImmediateChildOfUnresolvedType(
40093994
UnresolvedType e, int index, string partialPredicateCall
40103995
) {
@@ -4559,22 +4544,6 @@ private module Impl {
45594544
)
45604545
}
45614546

4562-
private Element getImmediateChildOfSequenceArchetypeType(
4563-
SequenceArchetypeType e, int index, string partialPredicateCall
4564-
) {
4565-
exists(int b, int bArchetypeType, int n |
4566-
b = 0 and
4567-
bArchetypeType =
4568-
b + 1 + max(int i | i = -1 or exists(getImmediateChildOfArchetypeType(e, i, _)) | i) and
4569-
n = bArchetypeType and
4570-
(
4571-
none()
4572-
or
4573-
result = getImmediateChildOfArchetypeType(e, index - b, partialPredicateCall)
4574-
)
4575-
)
4576-
}
4577-
45784547
private Element getImmediateChildOfUnarySyntaxSugarType(
45794548
UnarySyntaxSugarType e, int index, string partialPredicateCall
45804549
) {
@@ -5125,8 +5094,6 @@ private module Impl {
51255094
or
51265095
result = getImmediateChildOfTupleType(e, index, partialAccessor)
51275096
or
5128-
result = getImmediateChildOfTypeVariableType(e, index, partialAccessor)
5129-
or
51305097
result = getImmediateChildOfUnresolvedType(e, index, partialAccessor)
51315098
or
51325099
result = getImmediateChildOfBuiltinBridgeObjectType(e, index, partialAccessor)
@@ -5183,8 +5150,6 @@ private module Impl {
51835150
or
51845151
result = getImmediateChildOfPrimaryArchetypeType(e, index, partialAccessor)
51855152
or
5186-
result = getImmediateChildOfSequenceArchetypeType(e, index, partialAccessor)
5187-
or
51885153
result = getImmediateChildOfArraySliceType(e, index, partialAccessor)
51895154
or
51905155
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
@@ -1324,6 +1324,10 @@ module Raw {
13241324

13251325
class ParameterizedProtocolType extends @parameterized_protocol_type, Type {
13261326
override string toString() { result = "ParameterizedProtocolType" }
1327+
1328+
ProtocolType getBase() { parameterized_protocol_types(this, result) }
1329+
1330+
Type getArg(int index) { parameterized_protocol_type_args(this, index, result) }
13271331
}
13281332

13291333
class ProtocolCompositionType extends @protocol_composition_type, Type {
@@ -1348,10 +1352,6 @@ module Raw {
13481352
string getName(int index) { tuple_type_names(this, index, result) }
13491353
}
13501354

1351-
class TypeVariableType extends @type_variable_type, Type {
1352-
override string toString() { result = "TypeVariableType" }
1353-
}
1354-
13551355
class UnresolvedType extends @unresolved_type, Type, UnresolvedElement {
13561356
override string toString() { result = "UnresolvedType" }
13571357
}
@@ -1501,10 +1501,6 @@ module Raw {
15011501
override string toString() { result = "PrimaryArchetypeType" }
15021502
}
15031503

1504-
class SequenceArchetypeType extends @sequence_archetype_type, ArchetypeType {
1505-
override string toString() { result = "SequenceArchetypeType" }
1506-
}
1507-
15081504
class UnarySyntaxSugarType extends @unary_syntax_sugar_type, SyntaxSugarType {
15091505
Type getBaseType() { unary_syntax_sugar_types(this, result) }
15101506
}

0 commit comments

Comments
 (0)