Skip to content

Unified: Mark static members in legacy MaD models - #23296

Merged
asgerf merged 7 commits into
mainfrom
asgerf-swift-mad-static-members
Dec 3, 2026
Merged

asgerf merged 7 commits into
mainfrom
asgerf-swift-mad-static-members

Conversation

@asgerf

@asgerf asgerf commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: b46f54171867176c05ec8b84fbbfebd58f88332a

Dimension Assessment Rationale
Change confidence 9/10 ↑ Focused MaD test passes: the Base.Type Parameter[0] model matches the static method in a subtype, while the same-named instance method emits no source.
↑ The test exercises callable declarations rather than call-site matching.
↓ Existing call-site cases remain marked SPURIOUS, and static-property access remains marked MISSING in this PR.

Smaller change split out from this PR.

Previously the MaD models did not indicate if a member was a static or instance member. Static members as now considered members of the "meta-type". The meta-types is written as E.Type for some class E, and describes "the class itself" as opposed to instances of the class.

For example, the model for Process.run must now be described as an method on the Process.Type receiver:

["", "Process.Type", true, "run(_:arguments:)", "", "", "Argument[0,arguments:]", "command-injection", "manual"],

The larger PR above takes meta-types a step further, after which it starts to make more sense to represent it this way. For example, having a representative for the meta type means all member accesses can be assigned a "base type", which can simplify handling of calls in some contexts. But to avoid a huge PR I've just done the MaD refactoring in this PR.

@asgerf asgerf added the no-change-note-required This PR does not need a change note label Nov 30, 2026
@asgerf
asgerf marked this pull request as ready for review December 2, 2026 11:00
@asgerf
asgerf requested a review from a team as a code owner December 2, 2026 11:00
Copilot AI adaptive review requested due to automatic review settings December 2, 2026 11:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The added tests only exercise matchesCall, leaving the new receiver-type distinction in matchesCallable without regression coverage.

1 open issue
What changed in this PR

Updates Unified’s legacy Swift Models-as-Data to represent static members on meta-types such as Process.Type, preparing for broader name-binding changes.

Changes:

  • Migrate static-member models to .Type receivers.
  • Add meta-type selectors and static-aware callable matching.
  • Add static/instance fixtures that record current matching limitations.
File Description
unified/​ql/​test/​library-tests/​mad/​test.swift Add static/instance method and property cases.
unified/​ql/​test/​library-tests/​mad/​test.ext.json Add models for the new fixtures.
unified/​ql/​test/​library-tests/​mad/​test.expected Update expected source and sink results.
unified/​ql/​lib/​ext/​legacy-swift.model.json Mark static Swift model receivers with .Type.
unified/​ql/​lib/​ext/​format-string.model.yml Update static format-string sink receivers.
unified/​ql/​lib/​ext/​database.model.json Update static database API receivers.
unified/​ql/​lib/​codeql/​unified/​internal/​typeinference/​Type.qll Exclude meta-types from ordinary model types.
unified/​ql/​lib/​codeql/​unified/​internal/​mad/​LegacyMaD.qll Add meta-type selectors and static callable selection.

Review effort: Max (adaptive)

@geoffw0 geoffw0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. As discussed on Slack, there are some new models on main now that may still need updating.

asgerf and others added 6 commits December 3, 2026 10:01
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>
@asgerf
asgerf force-pushed the asgerf-swift-mad-static-members branch from b46f541 to 450ca8a Compare December 3, 2026 09:11
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

@hvitved hvitved left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should use another keyword which is not potentially in conflict with actual types?

class C {
  class Type {
  }
}

@asgerf

asgerf commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

@hvitved Sorry perhaps I should have mentioned in the PR description.

C.Type is the reserved way to reference the meta-type of C in Swift. It is not valid to declare a type named Type.

The Protocol name is also reserved, as it used to reference the meta-type of a protocol, but in MaD we always use Type. Both names are restricted in both contexts, however, so it cannot clash.

@asgerf

asgerf commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

Conflicts have been resolved.

@geoffw0 could you check the changes to the RNCryptor model?

@geoffw0

geoffw0 commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

@geoffw0 could you check the changes to the RNCryptor model?

Yes - this is a bit of a confusing area, because we're modelling the Objective C RNCryptor library (this, I think), but a direct Swift RNCryptor port also exists. I believe the former was more popular when the original models were made (which may or may not still be true); it may also be that the latter is build on top of the former. Anyway...

  • the changes in the HardcodedCryptographicValue test (to class func and RNEncryptor.self) appears to fix an inaccuracy in the original test stubs.
  • the corresponding changes to the RNCryptor and RNEncryptor appear to be accurate.
  • the new RNCryptor test cases in mad/test.swift seem reasonable, though they are much less accurate to the library itself than those in the HardcodedCryptographicValue test. I assume this kind of accuracy is not a priority in the MaD test.

@asgerf
asgerf merged commit ef93fa5 into main Dec 3, 2026
17 checks passed
@asgerf
asgerf deleted the asgerf-swift-mad-static-members branch December 3, 2026 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-change-note-required This PR does not need a change note Unified

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants