Skip to content

Unified: Declare exposed fields on supertypes (v2) - #22693

Open
asgerf wants to merge 8 commits into
github:mainfrom
asgerf:unified/supertype-fields-clean
Open

asgerf wants to merge 8 commits into
github:mainfrom
asgerf:unified/supertype-fields-clean

Conversation

@asgerf

@asgerf asgerf commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Supertypes in ast_nodes.yml can now have a list of fields to expose in the generated QL class.

This replaces the previous rule from #22507 where fields that were common among all subtypes were automatically hoisted to supertypes. The first couple of commits revert the changes from that PR, mainly to make things easier to review and avoid leaving behind weird bits of legacy code.

Compared to automatic hoisting, manually-declared supertype fields work better in a few scenarios:

  • There are some subtypes where the field has a more precise type thus failing an exact signature match
  • Adding a new subtype that lacks a previously-common field can cause a breaking AST change.
  • Sometimes it's just nice to have getters for fields that are present in the common case, but some subtypes are lacking it.

This PR uses the feature for the callable supertype:

  callable:
    subtypes:
      - top_level
      - function_expr
      - function_declaration
      - constructor_declaration
      - destructor_declaration
      - accessor_declaration
      - initializer_declaration
    fields:
      parameter*: parameter
      body?: block

Previously the body field was hoisted automatically, but not parameter, because some callables can't have parameters (like top-level).

asgerf and others added 8 commits September 29, 2026 10:31
Will un-revert once the new mechanism is in place.

This reverts commit 04865cb.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@asgerf asgerf added the no-change-note-required This PR does not need a change note label Sep 29, 2026
@asgerf
asgerf requested a balanced review from Copilot September 29, 2026 09:44

/** Gets the node corresponding to the field `parameter`. */
final F::Parameter getParameter(int i) {
final override F::Parameter getParameter(int i) {
F::Block getBody() { none() }

/** Gets the node corresponding to the field `parameter`. */
F::Parameter getParameter(int i) { none() }

/** Gets the node corresponding to the field `parameter`. */
final F::Parameter getParameter(int i) {
final override F::Parameter getParameter(int i) {

/** Gets the node corresponding to the field `parameter`. */
final F::Parameter getParameter(int i) {
final override F::Parameter getParameter(int i) {

/** Gets the node corresponding to the field `parameter`. */
final F::Parameter getParameter(int i) { unified_function_expr_parameter(this, i, result) }
final override F::Parameter getParameter(int i) {

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.

Copilot review overview

🟡 Changes recommended

Tests do not cover omitted fields or covariant getter types, despite these being core supported scenarios.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds explicitly declared fields to AST supertypes and generates callable getter APIs.

Changes:

  • Supports detailed supertype declarations with fields.
  • Generates default supertype getters and concrete overrides.
  • Adds schema conversion and generator tests.
File Description
unified/​ql/​lib/​codeql/​unified/​internal/​Ast.qll Updates generated callable getters.
unified/​extractor/​ast_types.yml Declares callable fields.
shared/​yeast-schema/​src/​node_types_yaml.rs Parses and serializes supertype fields.
shared/​tree-sitter-extractor/​src/​node_types.rs Preserves fields on union entries.
shared/​tree-sitter-extractor/​src/​generator/​ql.rs Removes abstract predicate-body representation.
shared/​tree-sitter-extractor/​src/​generator/​ql_gen.rs Generates supertype getters and overrides.
shared/​tree-sitter-extractor/​src/​generator/​mod.rs Handles expanded union entries.
shared/​tree-sitter-extractor/​src/​extractor/​mod.rs Handles expanded union entries during matching.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

let yaml = r#"
supertypes:
callable:
subtypes: [function]

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.

I think we can live with this

@asgerf

asgerf commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor Author

@asgerf
asgerf marked this pull request as ready for review September 29, 2026 12:08
@asgerf
asgerf requested review from a team as code owners September 29, 2026 12:08

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.

4 participants