Commit Graph

88616 Commits

Author SHA1 Message Date
Taus
2de1549f52 unified: Port control-flow and pattern rules to swift-syntax
Retarget `if`/`guard`/`switch`/ternary and the case/binding patterns to
the swift-syntax AST, output unchanged. swift-syntax distinguishes a
binding pattern (`valueBindingPattern`, `let x`) from a match pattern
(`expressionPattern`, `someConstant`) by node kind, so the tree-sitter
path's context-based `in_binding_pattern` disambiguation is removed:

- `ifExpr`/`guardStmt`/`ternaryExpr` ->
  `if_expr`/`guard_if_stmt`/`if_expr`;
  `switchExpr` + `switchCase` -> `switch_expr` + `switch_case` (comma
  cases become an `or_pattern`); `conditionElement`/`switchCaseItem`
  unwrap; a statement-position `if`/`switch`/`do` is unwrapped from its
  `expressionStmt`.
- `optionalBindingCondition` (`if let`) and `matchingPatternCondition`
  (`if case`) -> `pattern_guard_expr`.
- An `expressionPattern` wrapping a leading-dot or qualified call ->
  `constructor_pattern` (setting `ctx.in_pattern`);
  `valueBindingPattern` unwraps; a bare `expressionPattern` ->
  `expr_equality_pattern`; a wildcard
  (`discardAssignmentExpr`) -> `ignore_pattern`; a `tupleExpr` match
  pattern -> `tuple_pattern`; `isTypePattern` (`case is T`) ->
  `unsupported_node`.
- The `labeledExpr` argument rules gain `in_pattern`-aware pattern
  variants so an enum-case pattern's arguments (`case .foo(let x, _)`)
  become `pattern_element`s.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-07-24 16:08:14 +00:00
Taus
6ad1facee1 unified: Port closure rules to swift-syntax
Retarget closures to the swift-syntax AST, output unchanged.
swift-syntax nests the whole closure header under an optional
`closureSignature`, so a single `closureExpr` rule (with optional
attributes, capture list, parameter clause, and return clause) replaces
the tree-sitter `lambda_literal` rule.
The parameter clause is a union of the parenthesised form
(`closureParameterClause`, unwrapped to its `closureParameter` children)
and the shorthand form (`closureShorthandParameter`, a bare name); one
rule each replaces the four `lambda_parameter` variants.
`closureCapture` -> `variable_declaration` (an optional ownership
specifier becomes a modifier; an explicit capture initializer becomes
the bound value).

The trailing-closure call form is already handled by the
`functionCallExpr`
`trailingClosure` variant, so the tree-sitter trailing-closure call rule
is
dropped.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-07-24 16:08:14 +00:00
Taus
52cdf59f27 unified: Port function, call, and member-access rules to swift-syntax
Retarget function declarations, calls, member access, and control
transfer to the swift-syntax AST, output unchanged:

- `functionDecl` -> `function_declaration` (parameters and return type
  nest under `signature`; the body is a `codeBlock`). A bodyless
  function (a protocol requirement) still emits an empty `block`.
- `functionParameter` -> `parameter`: two names give the external label
  and internal name, one name just the internal name; the default value
  is handled inline, so the `ctx.default_value` threading (and its
  `SwiftContext` field) is removed. The declared type is dropped: in the
  tree-sitter path the untyped-parameter rule was ordered first and
  shadowed the typed one, so the baseline emits no parameter type.
- A function reference spelled with argument labels (`f(x:y:z:)`) is a
  `declReferenceExpr` with `argumentNames`; it is mapped to
  `unsupported_node` (matched before the bare-name rule) so downstream
  QL isn't handed a malformed reference, as in the tree-sitter path.
- `functionCallExpr` -> `call_expr` (a trailing closure becomes a final
  unlabelled argument); `labeledExpr` -> `argument`;
  `memberAccessExpr` -> `member_access_expr` (base-ful matched before
  leading-dot).
- `returnStmt`/`breakStmt`/`continueStmt`/`throwStmt` ->
  `return_expr`/`break_expr`/`continue_expr`/`throw_expr`, collapsing
  the labelled/unlabelled variants via optional captures.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-07-24 16:08:14 +00:00
Taus
191fc542ba unified: Port type-expression rules to swift-syntax
Retarget type expressions to the swift-syntax AST, output unchanged:

- `user_type` -> `identifierType` (its `name` is the type-name token).
- The sugared types keep desugaring to `generic_type_expr`:
  `optionalType` -> Optional<T>, `arrayType` -> Array<T>,
  `dictionaryType` -> Dictionary<K, V>.
- A generic type with explicit arguments (`Set<Int>`) stays opaque (its
  whole source text as the name), matched before the plain
  `identifierType` rule.
  This matches the tree-sitter `user_type` rule, which was also opaque.
- Tuple types (`(Int, String)`) -> `tuple_type_expr` and function types
  (`(Int) -> Bool`) -> `function_type_expr`. swift-syntax holds both as
  `tupleTypeElement`s but a tuple element maps to `tuple_type_element`
   while a function parameter maps to `parameter`; the containers set
  `SwiftContext::in_function_type` for their direct children so the
  shared `tupleTypeElement` rule emits the right kind (and nested types
  stay correct).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-07-24 16:08:14 +00:00
Taus
437e48239b unified: Port variable-binding rules to swift-syntax
Retarget `let`/`var` bindings to the swift-syntax AST, preserving the
output:

- A `variableDecl` publishes its `bindingSpecifier` (`let`/`var`) as the
  binding modifier, followed by its attributes and modifiers (`@objc`,
  `public`, `static`, …), and flattens each `patternBinding` into its
  own `variable_declaration`, tagging non-first ones
  `chained_declaration`. - One `patternBinding` rule with optional
  `typeAnnotation`/`initializer` covers `let x`, `let x = e`,
  `let x: T`,  and `let x: T = e`.
- `identifierPattern` -> `name_pattern`; `tuplePattern` /
  `tuplePatternElement` -> `tuple_pattern` / `pattern_element` (tuple
  destructuring), carrying an optional element label through as the
  `pattern_element` key.
- `codeBlockItem` now captures `_*` / annotates `stmt*` so a
  multi-binding declaration splices as several statements.
- Add a `declModifier` -> `modifier` rule (swift-syntax unifies the
  visibility/function/member/mutation/ownership modifiers into one
  kind).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-07-24 16:08:14 +00:00
Taus
8328fba68a unified: Port operator rules to swift-syntax
Retarget operator handling to the swift-syntax AST. Because Swift's
grammar has no operator precedence, the parser front-end folds operator
chains into nested `infixOperatorExpr`s (see swift-syntax-rs), so a
single rule replaces the tree-sitter grammar's per-precedence binary
rules (additive, multiplicative, comparison, equality, conjunction,
disjunction, bitwise, range, nil-coalescing). The output is unchanged;
only the input matching differs:

- `binaryOperatorExpr` unwraps to the `infix_operator` leaf.
- A `binaryOperator`-based `infixOperatorExpr` becomes `binary_expr`, or
  `compound_assign_expr` when the operator's spelling is a compound
  assignment — merging the tree-sitter grammar's separate binary and
  compound-assignment rules (the operator kinds are structurally
  identical, distinguishable only by spelling).
- An `assignmentExpr`-based `infixOperatorExpr` becomes `assign_expr`.
- An unresolved chain stays a flat `sequenceExpr` ->
  `unresolved_operator_sequence`.
- `prefixOperatorExpr` -> prefix `unary_expr`; `tupleExpr` -> opaque
  `tuple_expr`; `codeBlock` -> `block`.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-07-24 16:08:14 +00:00
Taus
ad2ce9315f unified: Port top-level, literal, and name rules to swift-syntax
Retarget the top-level, literal, and name mapping rules from the
tree-sitter grammar to the swift-syntax AST. The output each rule builds
is unchanged; only the input pattern differs, reflecting the different
AST shape:

- `source_file` -> `sourceFile` (statements live in an elided
  `statements` collection of `codeBlockItem` wrappers); the tree-sitter
  `global_declaration` / `local_declaration` wrappers have no
  swift-syntax counterpart.
- The lexical integer/string variants (`hex_literal`, `oct_literal`,
  `multi_line_string_literal`, ...) collapse into single
  `integerLiteralExpr` / `stringLiteralExpr` kinds.
- `simple_identifier` and `referenceable_operator` both become
  `declReferenceExpr` (its `baseName` is the referenced name or
  operator).

This is the first step of an in-place, rule-by-rule migration;
intermediate commits do not pass the corpus test (the runtime front-end
is still tree-sitter) — the corpus is regenerated once at the end.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-07-24 16:08:14 +00:00
Taus
79954ce19e unified: Add the swift-syntax parser and unresolved operator sequence (dormant)
Adds the plumbing for the swift-syntax front-end, without yet switching
the runtime over to it (the Swift front-end still parses with
tree-sitter):

- `languages/swift/parse.rs` shells out to the separate
  `swift-syntax-parse` binary and adapts its JSON into a `yeast::Ast`
  (plus side-channel `extra` tokens) via `swift_adapter`. Running the
  parser out-of-process keeps the Swift toolchain out of the extractor's
  own build. It is wired in as a module but left `allow(dead_code)`
  until the runtime uses it.

- `swift_node_types.yml` is the authoritative swift-syntax input schema
  (generated from swift-syntax by a one-off tool). The adapter seeds
  every parse with it, pre-registering every input kind and field so
  that rule matching never references a name absent from a given file's
  tree. The adapter now emits `ExtraToken`s directly during its single
  traversal, so `parse.rs` hands the parsed tree straight through with
  no second pass.

- `ast_types.yml` gains an `unresolved_operator_sequence` type (with an
  `expr_or_operator` union) for flat operator chains the parser can't
  resolve — e.g. a chain using an operator imported from another module,
  whose precedence is unknown. Nothing produces it yet; the mapping
  rules that do are added when the rules are ported. The dbscheme and QL
  library are regenerated to match.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-07-24 16:08:14 +00:00
Taus
bbf52ce7a7 tree-sitter-extractor: Split direct and desugaring extractors
Previously the `simple` multi-language extractor carried an optional
desugarer, so every language (including plain tree-sitter ones such as
ql, dbscheme, json and blame) went through the same desugaring-aware
extraction path.

This commit splits it into two front-ends that share a private driver:

  - `simple`: pure tree-sitter extraction with no desugaring. Comments
    and other `extra` nodes are emitted inline as tokens. (The extractor
    then extracts these as usual.)
  - `desugaring`: parses source into a `ParsedTree` (a yeast AST plus
    side-channel `extra` tokens) and rewrites the AST through a
    `yeast::Desugarer` before extraction. The parser is a closure, so
    both tree-sitter grammars (via `tree_sitter_parser`) and custom
    parsers plug in the same way.

The shared multi-file plumbing (threading, glob matching, source-archive
copying, TRAP writing) lives in a new private `driver` module behind a
`LanguageExtractor` trait, so neither front-end duplicates it.

`extract` no longer takes an optional desugarer (it always walks the
parse tree directly); `extract_parsed` takes a required desugarer. ql
and ruby use the direct path; the unified Swift extractor uses the
desugaring path.

Also rename the new side-channel identifiers from "trivia" to "extra"
(ExtraToken, ParsedTree.extras, emit_extra, ...) to match tree-sitter's
own `is_extra()` terminology. The pre-existing `*_trivia_tokeninfo`
relation is left unchanged for a separate change.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-07-24 16:08:13 +00:00
Taus
2e74c1d83f yeast: Desugar an externally-built AST, and validate by field name
Prepare yeast for front-ends that do not parse with tree-sitter (e.g.
the swift-syntax front-end, whose parser hands us a ready-built
`yeast::Ast`):

- `Runner`/`ConcreteDesugarer` now hold `Option<tree_sitter::Language>`.
  New constructors `Runner::with_schema_no_language`,
  `ConcreteDesugarer::without_language`, and
  `DesugaringConfig::build_schema_no_language` build the schema from the
  output node-types YAML alone. The parsing entry points
  (`run`/`run_from_tree`) error when no language is present;
  `run_from_ast` needs none.

- `BuildCtx::source_text` is a small convenience for Rust-block rules
  that read a captured token's source text.

- AST-dump type validation now resolves field constraints and required
  fields by field NAME rather than by field id. A field id is local to
  the schema that assigned it, so an AST built by one schema (e.g. an
  external parser's adapter) could not be validated against another (the
  output node-types schema) without re-keying. Looking up by name keeps
  the two schemas full independent: they share field names, not ids.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-07-24 16:08:13 +00:00
Taus
8206f6fa97 swift-syntax-rs: Fold local and stdlib operators
In our swift-syntax wrapper, we now attempt to fold all operator
sequences (i.e. `sequenceExpr` nodes) into appropriate
`infixOperatorExpr` nodes, assuming the requisite operator definitions
are present.

Currently, we only consider operators that are defined in the standard
library, and operators that are defined in the current file, leaving
operators defined in separate modules as future work.

The folding is done maximally -- if an argument of an unknown operator
can be folded in isolation, then this is done. Each top-level sequence
is folded independently, so a single unknown operator leaves only its
own sequence flat rather than aborting folding elsewhere.
2026-07-24 16:08:13 +00:00
Taus
7a573c4619 yeast: Order AST dump fields by schema-declared order
The AST dump previously emitted named fields in field-id order, which
made it dependant on registration order and so it could differ between
front-ends. We now emit them in the order declared in the node-types
YAML instead, so that the order is kept stable.
2026-07-24 16:08:13 +00:00
Kristen Newbury
d1fed84daf Merge pull request #22154 from knewbury01/knewbury01/adjust-environmentcheck
Actions Query Fix: UntrustedCheckoutTOCTOU[High|Critical] ControlCheck model fix
2026-07-23 09:30:34 -04:00
Taus
a39eab3e8c Merge pull request #22195 from github/tausbn/swift-syntax-rs
unified: Add Swift parser based on `swift-syntax`
2026-07-23 14:11:54 +02:00
Óscar San José
9836c1de57 Merge pull request #22152 from github/post-release-prep/codeql-cli-2.26.1
Post-release preparation for codeql-cli-2.26.1
2026-07-23 12:55:50 +02:00
Jeroen Ketema
38c9c84dcb Use 22.04 Swift toolchain 2026-07-21 11:08:46 +02:00
Jeroen Ketema
cf8eeb8e44 Only depend on the runtime libraries from the Swift toolchain 2026-07-21 11:01:37 +02:00
Jeroen Ketema
bf575868bc Simplify Xcode transition per review comments 2026-07-21 10:53:03 +02:00
Jeroen Ketema
0a1139c230 Fix Bazel formatting 2026-07-21 10:49:18 +02:00
Kristen Newbury
c5844ad6bd Merge branch 'main' into knewbury01/adjust-environmentcheck 2026-07-20 16:20:15 -04:00
Jeroen Ketema
5690ec71b0 Merge pull request #22111 from jketema/jketema/swift-more-autobuild
Swift: Turn off caching and integrated driver in autobuild
2026-07-20 13:54:46 +02:00
Taus
f384e291d7 unified: Clean up build
Co-authored-by: Jeroen Ketema <93738568+jketema@users.noreply.github.com>
2026-07-20 13:10:02 +02:00
Jeroen Ketema
14450f5bf3 Merge pull request #22211 from jketema/jketema/qldoc
Shared: Add missing QLdoc
2026-07-17 19:13:52 +02:00
Jeroen Ketema
a3eee6204b Shared: Add missing QLdoc 2026-07-17 17:22:11 +02:00
Óscar San José
87835f7f3d Merge pull request #22207 from github/codeql-spark-run-29493713448
Update changelog documentation site for codeql-cli-2.26.1
2026-07-17 12:10:28 +02:00
github-actions[bot]
e9e360ae44 update codeql documentation 2026-07-16 11:18:13 +00:00
Michael Nebel
2eb0158b09 Merge pull request #22193 from michaelnebel/csharp/diableuselessassignment
C#: Remove the query `cs/useless-assignment-to-local` from the `code-quality` suite.
2026-07-16 08:07:29 +02:00
Taus
da1bbb7fac Bazel: regenerate vendored cargo dependencies
Registers the `unified/swift-syntax-rs` workspace member (added in
"unified:
Add swift-syntax-rs") in the tree-sitter extractors crate universe. It
has no
external Rust dependencies, so its dependency entries are empty.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-07-15 13:15:06 +00:00
Taus
7474a33132 unified: Hardcode swift_version
It seems that using swift_version_file has some issues when `codeql` is
consumed as a dependency module. I'm hoping hardcoding the version
instead will fix this, but ideally we should find a more robust
solution.
2026-07-15 12:47:26 +00:00
Taus
205c9a9346 swift-syntax-rs: Fix bazel formatting
aCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-07-15 12:20:24 +00:00
Taus
46d6a118f4 yeast: Clarify Ast::with_schema registration doc
The doc claimed the schema passed to `Ast::with_schema` must already
have
every node kind and field name registered, contradicting the
registration
methods just below and the swift-syntax adapter, which starts from
`Schema::new()` and registers names on demand during construction.
Document
that up-front registration is optional.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-07-15 12:15:14 +00:00
Taus
3eb353ecf7 swift-syntax-rs: Address PR review feedback
- BUILD.bazel: require x86_64 on the Linux branch of the compatibility
  select. The only registered standalone Linux Swift toolchain is
  x86_64-only, so without the CPU constraint Linux/aarch64 targets
stayed
  "compatible" and then failed toolchain resolution instead of being
  skipped cleanly.
- build.rs: emitting `rerun-if-changed` disables Cargo's default
  whole-package scan, so list every input to `swift build` — the package
  manifests, `Package.resolved`, `.swift-version`, and the whole Sources
  tree — so stale shim/toolchain output can't linger. (`.build/` is left
  unwatched, as it is this build's own output.)
- src/lib.rs: a null result from the shim is not a parse failure —
  SwiftParser recovers from invalid syntax and always yields a tree — so
it
  means the shim failed to serialize/allocate the JSON. Fix the error
  message and the variant doc accordingly.
- README.md: `.swift-version` is not honored by the macOS Bazel build
  (which uses the host Xcode toolchain); document that it pins the Linux
  and local builds only.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-07-15 12:14:56 +00:00
Jeroen Ketema
64df10409a Merge pull request #22191 from jketema/jketema/swift-6.3.3
Swift: Update to Swift 6.3.3
2026-07-15 14:09:47 +02:00
Jeroen Ketema
a701922dbd Swift: Update to Swift 6.3.3 2026-07-15 13:28:15 +02:00
copilot-swe-agent[bot]
1577d82ebd Upgrade swift-syntax-rs to swift-syntax 603.0.2 / Swift 6.3.2 2026-07-15 12:23:18 +02:00
Jeroen Ketema
303f81ee14 Merge pull request #22194 from github/jketema/kotlin-2.4.10
Kotlin: Support Kotlin 2.4.10
2026-07-15 11:46:21 +02:00
Michael Nebel
2c161e6b8f Merge pull request #22180 from michaelnebel/csharp/rawurl
C#: Remove the RawUrl sanitizer.
2026-07-15 11:38:28 +02:00
Jeroen Ketema
574ef4d1ac Kotlin: Support Kotlin 2.4.10 2026-07-15 10:17:58 +02:00
Michael Nebel
cb3f8a8394 C#: Add change-note. 2026-07-15 09:16:01 +02:00
Michael Nebel
2395053ed6 C#: Update integration test expected output. 2026-07-15 09:12:52 +02:00
Michael Nebel
b15c243eca C#: Exclude cs/useless-assignment-to-local from the code-quality suite. 2026-07-15 09:12:49 +02:00
copilot-swe-agent[bot]
3e2daf2258 Support building swift-syntax-rs on macOS 2026-07-14 16:28:13 +02:00
Owen Mansel-Chan
05734dcc38 Merge pull request #22175 from owen-mc/java/fix-path-sanitizer
Java: Fix `File.getName()` path sanitizer
2026-07-14 13:12:56 +01:00
Jeroen Ketema
8b477059fe Merge pull request #22178 from jketema/jketema/go-recv
Go: Track whether a type parameter type was declared as part of a receiver
2026-07-14 10:49:52 +02:00
Jeroen Ketema
09da46d8bd Go: Address review comments 2026-07-14 10:23:43 +02:00
Owen Mansel-Chan
2d0095826b Address review comment 2026-07-13 19:40:31 +01:00
Michael Nebel
42843f155e Merge pull request #22159 from aschackmull/java/join-order-effnonvirt
Java: Improve join order.
2026-07-13 16:45:54 +02:00
Jeroen Ketema
2656b5d87d Merge pull request #22179 from jketema/jketema.new-free
C++: Update the CWE tag of `cpp/new-free-mismatch`
2026-07-13 16:25:58 +02:00
Michael Nebel
ae06b778e5 C#: Add change-note. 2026-07-13 15:29:18 +02:00
Michael Nebel
03e44f548f C#: Update test and expected output. 2026-07-13 15:19:04 +02:00