Repository navigation
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…cesses Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
… type Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
asgerf
force-pushed
the
asgerf-swift-mad-static-ext
branch
from
November 23, 2026 14:35
7bbb39a to
07b4f7b
Compare
asgerf
force-pushed
the
asgerf-swift-mad-static-ext
branch
3 times, most recently
from
November 24, 2026 11:15
1946ff8 to
213c70d
Compare
…n meta-type values Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved name-binding and receiver-typing defects miss modeled accesses or incorrectly match instance-only models, while generated expectations still contain test-failure entries.
5 open issues
What changed in this PR
This PR extends Unified’s Swift analysis with a canonical representation for declared types, extensions, and model-only types. It improves modeled member resolution and adds lightweight metatype support for static access.
Changes:
- Introduce and export
ClassLikeElement, and refactor member lookup around it. - Include modeled members in name binding and distinguish static access through metatypes.
- Migrate static Swift models to
.Typeselectors and expand extractor and library regression fixtures.
| File | Description |
|---|---|
| unified/ql/test/library-tests/type-inference/type-inference.expected | Update metatype inference expectations. |
| unified/ql/test/library-tests/type-inference/metatypes.swift | Test metatype values and member calls. |
| unified/ql/test/library-tests/static-name-binding/test.ql | Adapt unqualified-access checks to target nodes. |
| unified/ql/test/library-tests/mad/test.swift | Test static, instance, and implicit modeled access. |
| unified/ql/test/library-tests/mad/test.ext.json | Define static and instance test models. |
| unified/ql/test/library-tests/mad/test.expected | Record modeled-member matching results. |
| unified/ql/test/library-tests/mad-static-members/test.swift | Test modeled member namespaces and inheritance. |
| unified/ql/test/library-tests/mad-static-members/test.qlref | Enable inline-expectation postprocessing. |
| unified/ql/test/library-tests/mad-static-members/test.ql | Check model bindings and metatype bases. |
| unified/ql/test/library-tests/mad-static-members/test.ext.json | Supply static and instance member models. |
| unified/ql/test/library-tests/mad-static-members/test.expected | Record binding and base-type expectations. |
| unified/ql/test/library-tests/mad-builtins/test.swift | Update implicit Process-property sink expectations. |
| unified/ql/test/library-tests/mad-builtins/test.expected | Record newly resolved implicit sinks. |
| unified/ql/test/library-tests/dataflow/test.expected | Record metatype call data-flow results. |
| unified/ql/test/library-tests/dataflow/metatypes.swift | Test metatype calls and class overrides. |
| unified/ql/lib/utils/test/TestUtils.qll | Name extension members through canonical elements. |
| unified/ql/lib/unified.qll | Export ClassLikeElement. |
| unified/ql/lib/ext/legacy-swift.model.json | Mark static Swift APIs with .Type. |
| unified/ql/lib/ext/format-string.model.yml | Move static format-string models to .Type. |
| unified/ql/lib/ext/database.model.json | Move static database models to .Type. |
| unified/ql/lib/codeql/unified/internal/typeinference/TypeMention.qll | Resolve class-like and metatype mentions. |
| unified/ql/lib/codeql/unified/internal/typeinference/TypeInferencePluginSwift.qll | Infer X.self and recognize X.Type. |
| unified/ql/lib/codeql/unified/internal/typeinference/TypeInferencePlugin.qll | Add a metatype-operand plugin hook. |
| unified/ql/lib/codeql/unified/internal/typeinference/TypeInference.qll | Resolve static members and infer metatype bases. |
| unified/ql/lib/codeql/unified/internal/typeinference/TypeAbstraction.qll | Update documentation for the ClassLikeType rename. |
| unified/ql/lib/codeql/unified/internal/typeinference/Type.qll | Unify class-like types and introduce MetaType. |
| unified/ql/lib/codeql/unified/internal/StaticNameBinding.qll | Track modeled members and extension targets. |
| unified/ql/lib/codeql/unified/internal/mad/LegacyMaD.qll | Distinguish static and instance model selectors. |
| unified/ql/lib/codeql/unified/internal/FacadeAst.qll | Map declarations and extensions to canonical elements. |
| unified/ql/lib/codeql/unified/internal/dataflow/FlowSummary.qll | Use the renamed MemberSelector abstraction. |
| unified/ql/lib/codeql/unified/internal/ClassLikeElement.qll | Introduce canonical declared/model-only type representatives. |
| unified/ql/lib/codeql/unified/internal/AnalysisQuality.qll | Include modeled unqualified-access targets in statistics. |
| unified/extractor/tests/corpus/swift/types/metatype.swift | Add metatype syntax corpus coverage. |
| unified/extractor/tests/corpus/swift/types/metatype.output | Record parsed and translated metatype trees. |
| unified/extractor/src/languages/swift/swift.rs | Translate metatype syntax into member accesses. |
Review effort: Max
| pragma[nomagic] | ||
| private MaD::TypeSelector getExtendedTypeSelector(ClassLikeDeclaration ext) { | ||
| not exists(N::getExtendedDeclaration(ext)) and | ||
| N::trackTypeSelector(result) = N::getNodeFromRef(ext.getExtensionTarget()) |
| exists(MaD::MemberSelector member | | ||
| node1.isMemberSelector(member) and | ||
| name = member.getName() and | ||
| node2.isTypeSelector(member.getTypeString()) |
| Type inferBaseType(MemberAccess access) { | ||
| result = inferType(access.(MemberAccessExpr).getBase()) | ||
| or | ||
| result.(MetaType).getInstanceType() = access.(MemberAccessExpr).getBase().(TypeMention).getType() |
| or | ||
| result.(MetaType).getInstanceType() = access.(MemberAccessExpr).getBase().(TypeMention).getType() | ||
| or | ||
| result = inferVariableType(access.(UnqualifiedMemberAccess).getImplicitQualifierVariable()) |
| | implicit-self.swift:80:14:80:19 | ... .x | implicit-self.swift:78:24:78:38 | source(...) | implicit-self.swift:80:14:80:19 | ... .x | $@ | implicit-self.swift:78:24:78:38 | source(...) | source(...) | | ||
| | implicit-self.swift:86:14:86:14 | x | implicit-self.swift:85:29:85:43 | source(...) | implicit-self.swift:86:14:86:14 | x | $@ | implicit-self.swift:85:29:85:43 | source(...) | source(...) | | ||
| | implicit-self.swift:87:14:87:19 | ... .x | implicit-self.swift:85:29:85:43 | source(...) | implicit-self.swift:87:14:87:19 | ... .x | $@ | implicit-self.swift:85:29:85:43 | source(...) | source(...) | | ||
| | metatypes.swift:7:14:7:14 | x | metatypes.swift:20:18:20:43 | source(...) | metatypes.swift:7:14:7:14 | x | $@ | metatypes.swift:20:18:20:43 | source(...) | source(...) | |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

ClassLikeElement
Introduces
ClassLikeElementas a representative for a class/type. This serves two purposes:ClassLikeElement. Predicates likegetAMemberIncludingExtensionsare refactored to go throughClassLikeElement.ClassLikeElement, making it possible to write code that handles both situations under one pipeline.Unqualified access to members from models
Members from models are now also present in static name binding. The direct benefit of this is that we can detect unqualified member accesses properly. For example, take the following locally-ambiguous situation:
If we have a model for
E.bar()then thebaraccess is now classified asUnqualifiedMemberAccessand a correspondingselfaccess is generated, with the usual post-update nodes etc.Static members and meta-types
For the above to work properly, we also start distinguishing between static and non-static members in the MaD models. We do this by seeing static members as members of the meta-type, i.e. the type describing "the class itself" as opposed to instances of the class. A static member of
Eis written as a member ofE.Type. We don't add full meta-type support to type inference, but add a representative for the meta type, so all member accesses can be assigned a "base type", where static accesses get the meta-type as its base.