Skip to content

Commit 7729a6b

Browse files
authored
Merge pull request github#12509 from geoffw0/typealiasimpl
Swift: Extract type aliases
2 parents 62bc807 + fcefd03 commit 7729a6b

File tree

21 files changed

+10510
-25
lines changed

21 files changed

+10510
-25
lines changed

swift/downgrades/e646f9e0308ec7135c83c0fdf96896d2737a8013/old.dbscheme

Lines changed: 2602 additions & 0 deletions
Large diffs are not rendered by default.

swift/downgrades/e646f9e0308ec7135c83c0fdf96896d2737a8013/swift.dbscheme

Lines changed: 2601 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class TypeAliasDecl extends @type_alias_decl {
2+
string toString() { result = "TypeAliasDecl" }
3+
}
4+
5+
from TypeAliasDecl id
6+
select id
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
description: Revert adding TypeAliasDecl.getAliasedType()
2+
compatibility: full
3+
type_alias_decls.rel: run type_alias_decls.qlo

swift/extractor/translators/DeclTranslator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ std::optional<codeql::AssociatedTypeDecl> DeclTranslator::translateAssociatedTyp
206206
std::optional<codeql::TypeAliasDecl> DeclTranslator::translateTypeAliasDecl(
207207
const swift::TypeAliasDecl& decl) {
208208
if (auto entry = createNamedEntry(decl)) {
209+
entry->aliased_type = dispatcher.fetchLabel(decl.getUnderlyingType());
209210
fillTypeDecl(decl, *entry);
210211
return entry;
211212
}

swift/integration-tests/posix-only/deduplication/BuiltinTypes.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
| Builtin.NativeObject | BuiltinNativeObjectType |
1414
| Builtin.RawPointer | BuiltinRawPointerType |
1515
| Builtin.RawUnsafeContinuation | BuiltinRawUnsafeContinuationType |
16+
| Builtin.UnsafeValueBuffer | BuiltinUnsafeValueBufferType |
1617
| Builtin.Vec2xFPIEEE32 | BuiltinVectorType |
1718
| Builtin.Vec2xFPIEEE64 | BuiltinVectorType |
1819
| Builtin.Vec2xInt8 | BuiltinVectorType |

swift/ql/.generated.list

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,10 @@ ql/lib/codeql/swift/generated/File.qll f88c485883dd9b2b4a366080e098372912e03fb31
381381
ql/lib/codeql/swift/generated/Locatable.qll bdc98b9fb7788f44a4bf7e487ee5bd329473409950a8e9f116d61995615ad849 0b36b4fe45e2aa195e4bb70c50ea95f32f141b8e01e5f23466c6427dd9ab88fb
382382
ql/lib/codeql/swift/generated/Location.qll 851766e474cdfdfa67da42e0031fc42dd60196ff5edd39d82f08d3e32deb84c1 b29b2c37672f5acff15f1d3c5727d902f193e51122327b31bd27ec5f877bca3b
383383
ql/lib/codeql/swift/generated/OtherAvailabilitySpec.qll 0e26a203b26ff0581b7396b0c6d1606feec5cc32477f676585cdec4911af91c5 0e26a203b26ff0581b7396b0c6d1606feec5cc32477f676585cdec4911af91c5
384-
ql/lib/codeql/swift/generated/ParentChild.qll 0ac2139b8b2e172858262d80950a0212b21fe46bf6af7259d9058fb7193f8242 6f7464ecd8ca04b6aa261139b36a162e5b0636237d514b8431ef4f97a1c603dc
384+
ql/lib/codeql/swift/generated/ParentChild.qll 7d45d4e872e769f37a5b157ba422c48afe482552e44d94ff5f6a5a6449d672e7 6f7464ecd8ca04b6aa261139b36a162e5b0636237d514b8431ef4f97a1c603dc
385385
ql/lib/codeql/swift/generated/PlatformVersionAvailabilitySpec.qll f82d9ca416fe8bd59b5531b65b1c74c9f317b3297a6101544a11339a1cffce38 7f5c6d3309e66c134107afe55bae76dfc9a72cb7cdd6d4c3706b6b34cee09fa0
386386
ql/lib/codeql/swift/generated/PureSynthConstructors.qll 173c0dd59396a1de26fe870e3bc2766c46de689da2a4d8807cb62023bbce1a98 173c0dd59396a1de26fe870e3bc2766c46de689da2a4d8807cb62023bbce1a98
387-
ql/lib/codeql/swift/generated/Raw.qll efe60f045f8a4aecedd7bfe8110c0c10539bcdcb9f17f342cf560c8d065e6aff 261825907250bb4ddeba8ccce0df29b45f13c6fb338eb41a06ea6b43e7aa9788
387+
ql/lib/codeql/swift/generated/Raw.qll b1ad09374cf2d5556e0a409a59eea723a7280882ae144f68fd2dae362cb147b7 587433583a7e93c9a8534cb59409fd802e4b6587faf1367df9447d06be191c73
388388
ql/lib/codeql/swift/generated/Synth.qll af02e0b49fe7b488592687996cc74d9525d4e3fbc9d324820b310b356f4d2612 5c740a660721173e9e4e45eb701d373ca19ff14d61cdaea309b65871e0deea90
389389
ql/lib/codeql/swift/generated/SynthConstructors.qll a1b3ca33017f82124286ccad317a05484fee144fb9c3cdd2e500ce38e5efcec4 a1b3ca33017f82124286ccad317a05484fee144fb9c3cdd2e500ce38e5efcec4
390390
ql/lib/codeql/swift/generated/UnknownFile.qll 0fcf9beb8de79440bcdfff4bb6ab3dd139bd273e6c32754e05e6a632651e85f6 0fcf9beb8de79440bcdfff4bb6ab3dd139bd273e6c32754e05e6a632651e85f6
@@ -428,7 +428,7 @@ ql/lib/codeql/swift/generated/decl/ProtocolDecl.qll 4b03e3c2a7af66e66e8abc40bd2e
428428
ql/lib/codeql/swift/generated/decl/StructDecl.qll 9343b001dfeec83a6b41e88dc1ec75744d39c397e8e48441aa4d01493f10026a 9343b001dfeec83a6b41e88dc1ec75744d39c397e8e48441aa4d01493f10026a
429429
ql/lib/codeql/swift/generated/decl/SubscriptDecl.qll 31cb1f90d4c60060f64c432850821969953f1a46e36ce772456c67dfff375ff5 1d0098518c56aed96039b0b660b2cce5ea0db7ac4c9a550af07d758e282d4f61
430430
ql/lib/codeql/swift/generated/decl/TopLevelCodeDecl.qll aececf62fda517bd90b1c56bb112bb3ee2eecac3bb2358a889dc8c4de898346e d8c69935ac88f0343a03f17ea155653b97e9b9feff40586cfa8452ac5232700d
431-
ql/lib/codeql/swift/generated/decl/TypeAliasDecl.qll 15cb5bdbe9d722c403874f744bfb3da85f532e33638a64a593acbbdee2f6095e 15cb5bdbe9d722c403874f744bfb3da85f532e33638a64a593acbbdee2f6095e
431+
ql/lib/codeql/swift/generated/decl/TypeAliasDecl.qll 640912badc9d2278b6d14a746d85ed71b17c52cd1f2006aef46d5a4aeaa544f2 a6cbe000ea9d5d1ccd37eb50c23072e19ee0234d53dcb943fef20e3f553fcf4e
432432
ql/lib/codeql/swift/generated/decl/TypeDecl.qll 74bb5f0fe2648d95c84fdce804740f2bba5c7671e15cbea671d8509456bf5c2b 32bc7154c8585c25f27a3587bb4ba039c8d69f09d945725e45d730de44f7a5ae
433433
ql/lib/codeql/swift/generated/decl/ValueDecl.qll 7b4e4c9334be676f242857c77099306d8a0a4357b253f8bc68f71328cedf1f58 f18938c47f670f2e0c27ffd7e31e55f291f88fb50d8e576fcea116d5f9e5c66d
434434
ql/lib/codeql/swift/generated/decl/VarDecl.qll bdea76fe6c8f721bae52bbc26a2fc1cbd665a19a6920b36097822839158d9d3b 9c91d8159fd7a53cba479d8c8f31f49ad2b1e2617b8cd9e7d1a2cb4796dfa2da

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class TypeAliasType extends Generated::TypeAliasType {
1010
* typealias MyInt = Int
1111
* ```
1212
*/
13-
Type getAliasedType() { none() } // TODO: not yet implemented.
13+
Type getAliasedType() { result = this.getDecl().getAliasedType() }
1414

15-
override Type getUnderlyingType() { result = this } // TODO: not yet implemented.
15+
override Type getUnderlyingType() { result = this.getAliasedType().getUnderlyingType() }
1616
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,16 @@ module Raw {
660660

661661
class TypeAliasDecl extends @type_alias_decl, GenericTypeDecl {
662662
override string toString() { result = "TypeAliasDecl" }
663+
664+
/**
665+
* Gets the aliased type on the right-hand side of this type alias declaration.
666+
*
667+
* For example the aliased type of `MyInt` in the following code is `Int`:
668+
* ```
669+
* typealias MyInt = Int
670+
* ```
671+
*/
672+
Type getAliasedType() { type_alias_decls(this, result) }
663673
}
664674

665675
class ClassDecl extends @class_decl, NominalTypeDecl {

swift/ql/lib/codeql/swift/generated/decl/TypeAliasDecl.qll

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,39 @@
22
private import codeql.swift.generated.Synth
33
private import codeql.swift.generated.Raw
44
import codeql.swift.elements.decl.GenericTypeDecl
5+
import codeql.swift.elements.type.Type
56

67
module Generated {
8+
/**
9+
* A declaration of a type alias to another type. For example:
10+
* ```
11+
* typealias MyInt = Int
12+
* ```
13+
*/
714
class TypeAliasDecl extends Synth::TTypeAliasDecl, GenericTypeDecl {
815
override string getAPrimaryQlClass() { result = "TypeAliasDecl" }
16+
17+
/**
18+
* Gets the aliased type on the right-hand side of this type alias declaration.
19+
*
20+
* This includes nodes from the "hidden" AST. It can be overridden in subclasses to change the
21+
* behavior of both the `Immediate` and non-`Immediate` versions.
22+
*/
23+
Type getImmediateAliasedType() {
24+
result =
25+
Synth::convertTypeFromRaw(Synth::convertTypeAliasDeclToRaw(this)
26+
.(Raw::TypeAliasDecl)
27+
.getAliasedType())
28+
}
29+
30+
/**
31+
* Gets the aliased type on the right-hand side of this type alias declaration.
32+
*
33+
* For example the aliased type of `MyInt` in the following code is `Int`:
34+
* ```
35+
* typealias MyInt = Int
36+
* ```
37+
*/
38+
final Type getAliasedType() { result = getImmediateAliasedType().resolve() }
939
}
1040
}

0 commit comments

Comments
 (0)