Skip to content

unified: Add ClassLikeElement - #23297

Open
asgerf wants to merge 9 commits into
mainfrom
asgerf-class-like-element-refactor
Open

asgerf wants to merge 9 commits into
mainfrom
asgerf-class-like-element-refactor

Conversation

@asgerf

@asgerf asgerf commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Smaller change split out from this PR.

Introduces ClassLikeElement as a representative for a class/type. This serves two purposes:

  • Extensions and the main declaration of class now map to ClassLikeElement. Predicates like getAMemberIncludingExtensions are refactored to go through ClassLikeElement.
  • Types only mentioned in a model, i.e. not declared in the database, also get a ClassLikeElement, making it possible to write code that handles both situations under one pipeline.

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

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

Name-resolution and selector issues can omit valid extensions and members, suppress model-only types, and create spurious or duplicate class-like elements.

4 open issues
What changed in this PR

Introduces ClassLikeElement as a shared representation for declared types, their extensions, and types known only from models.

Changes:

  • Adds and exports the canonical class/type API.
  • Migrates type inference, model matching, and member lookup to use it.
File Description
unified/​ql/​src/​queries/​security/​CWE-312/​CleartextLogging.ql Uses canonical elements for logging-member detection.
unified/​ql/​lib/​utils/​test/​TestUtils.qll Updates member-name qualification.
unified/​ql/​lib/​unified.qll Exports the new API.
unified/​ql/​lib/​codeql/​unified/​internal/​typeinference/​TypeMention.qll Updates type-mention and model-selector handling.
unified/​ql/​lib/​codeql/​unified/​internal/​typeinference/​TypeInferencePluginSwift.qll Migrates Swift type classifiers.
unified/​ql/​lib/​codeql/​unified/​internal/​typeinference/​TypeInference.qll Updates inference to use canonical types.
unified/​ql/​lib/​codeql/​unified/​internal/​typeinference/​TypeAbstraction.qll Updates a type name in documentation only.
unified/​ql/​lib/​codeql/​unified/​internal/​typeinference/​Type.qll Unifies declaration-backed and model-only types.
unified/​ql/​lib/​codeql/​unified/​internal/​StaticNameBinding.qll Exposes cached extension-target resolution.
unified/​ql/​lib/​codeql/​unified/​internal/​mad/​LegacyMaD.qll Connects model selectors to canonical elements.
unified/​ql/​lib/​codeql/​unified/​internal/​FacadeAst.qll Adds element access and refactors extension handling.
unified/​ql/​lib/​codeql/​unified/​internal/​ClassLikeElement.qll Defines canonical elements and their declaration/member relationships.

Review effort: Max (adaptive)

cached
private newtype TClassLikeElement =
TClassLikeDeclarationElement(ClassLikeDeclaration decl) { not exists(decl.getExtensionTarget()) } or
TTypeSelectorElement(MaD::TypeSelector selector) { not exists(selector.getDeclaration()) }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is blocked on getting models to refer to types by their module-qualified names, e.g. Foundation.URL instead of URL. There is just no way to tell which class is the intended target right now.

asgerf and others added 6 commits December 3, 2026 14:38
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>
Constructor calls and subtype declarations referring to a modeled type
via a type alias were not matched by models. Make TypeSelector.getAStaticRef
follow type aliases, and keep an unexpanded variant for type mentions,
which must resolve alias references to the alias type itself.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@asgerf
asgerf force-pushed the asgerf-class-like-element-refactor branch from 61f2d13 to 40c327e Compare December 3, 2026 13:53
@asgerf
asgerf requested an adaptive review from Copilot December 3, 2026 13:54

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

Alias extension prefixes are not expanded, causing nested types to miss matching declarations and create separate model-only elements; alias expansion and regression coverage are needed.

2 open issues
3 resolved since last review

Review effort: Balanced (adaptive)

asgerf and others added 3 commits December 3, 2026 15:16
Expand extension target type aliases when deriving nested declaration
names, so a nested declaration in an aliased model-only extension shares
the modeled type's qualified name.

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>

This branch has not been deployed

No deployments
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.

2 participants