Skip to content

Unified: Synthesize implicit Swift initializers - #22721

Merged
hvitved merged 2 commits into
github:mainfrom
hvitved:hvitved-swift-implicit-init
Oct 1, 2026
Merged

hvitved merged 2 commits into
github:mainfrom
hvitved:hvitved-swift-implicit-init

Conversation

@hvitved

@hvitved hvitved commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

This PR synthesizes parameterless init constructors for classes and structs without an explicit constructor. Follow-up work will synthesize (in QL) parameters for struct constructors, and perhaps also filter away dead synthesized constructors when there is a base class.

DCA is great; we increase call resolution percentage from 23.8 % to 28.0 %. Surprisingly, percentage of statically resolvable names decreases, but I think I know why, and will do a follow-up fix.

@hvitved
hvitved force-pushed the hvitved-swift-implicit-init branch from 81e9b8b to 46da672 Compare October 1, 2026 11:44
@hvitved
hvitved force-pushed the hvitved-swift-implicit-init branch 3 times, most recently from 95a8302 to 262e923 Compare October 1, 2026 12:24
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Oct 1, 2026
@hvitved
hvitved requested a balanced review from Copilot October 1, 2026 12:34

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

Descendants of generated constructors are still incorrectly reported as ordinary source nodes.

Review effort: Balanced
Findings: 1 High severity

Open (1)
What changed in this PR

Synthesizes implicit Swift initializers so constructor calls and downstream type inference can resolve classes and structs without explicit initializers.

Changes:

  • Adds generated parameterless constructors during Swift AST translation.
  • Excludes generated declarations from source CFG handling.
  • Adds constructor tests and regenerates affected expectations.
File Description
unified/​extractor/​src/​languages/​swift/​swift.rs Synthesizes implicit constructors.
unified/​extractor/​tests/​location_tests.rs Tests constructor synthesis.
unified/​ql/​lib/​codeql/​unified/​internal/​FacadeAst.qll Updates generated-node source classification.
unified/​ql/​lib/​codeql/​unified/​internal/​ControlFlowGraph.qll Skips non-source CFG nodes.
unified/​ql/​test/​library-tests/​constructors/​constructors.swift Adds constructor scenarios.
unified/​ql/​test/​library-tests/​constructors/​test.ql Queries generated constructors.
unified/​ql/​test/​library-tests/​constructors/​test.expected Records constructor expectations.
unified/​ql/​test/​library-tests/​type-inference/​classes.swift Tests inferred constructors.
unified/​ql/​test/​library-tests/​type-inference/​fields.swift Enables field-constructor expectations.
unified/​ql/​test/​library-tests/​type-inference/​generics.swift Adds generic constructor targets.
unified/​ql/​test/​library-tests/​type-inference/​lub.swift Enables subclass constructor target.
unified/​ql/​test/​library-tests/​type-inference/​overload_resolution.swift Uses synthesized constructors.
unified/​ql/​test/​library-tests/​type-inference/​type_constraints.swift Uses synthesized constructor.
unified/​ql/​test/​library-tests/​type-inference/​type-inference.expected Regenerates inference results.
unified/​ql/​test/​library-tests/​BasicTest/​test.expected Regenerates identifier results.
unified/​extractor/​tests/​corpus/​swift/​variables/​property-with-willset-and-didset-observers.output Records synthesized constructor.
unified/​extractor/​tests/​corpus/​swift/​types/​struct.output Records struct constructor.
unified/​extractor/​tests/​corpus/​swift/​types/​static-function.output Records synthesized constructor.
unified/​extractor/​tests/​corpus/​swift/​types/​qualified-type.output Records nested constructors.
unified/​extractor/​tests/​corpus/​swift/​types/​property-with-getter-and-setter.output Records synthesized constructor.
unified/​extractor/​tests/​corpus/​swift/​types/​noncopyable-type.output Records synthesized constructor.
unified/​extractor/​tests/​corpus/​swift/​types/​generic-class-parameters-and-constraints.output Records generic constructor.
unified/​extractor/​tests/​corpus/​swift/​types/​empty-class.output Records empty-class constructor.
unified/​extractor/​tests/​corpus/​swift/​types/​conditional-compilation-in-class-body.output Records synthesized constructor.
unified/​extractor/​tests/​corpus/​swift/​types/​computed-property.output Records synthesized constructor.
unified/​extractor/​tests/​corpus/​swift/​types/​class-with-stored-properties.output Records synthesized constructor.
unified/​extractor/​tests/​corpus/​swift/​types/​class-with-multiple-base-types.output Records inherited-class constructor.
unified/​extractor/​tests/​corpus/​swift/​types/​class-with-method.output Records synthesized constructor.
unified/​extractor/​tests/​corpus/​swift/​types/​class-inheritance.output Records subclass constructor.
unified/​extractor/​tests/​corpus/​swift/​types/​class-function.output Records synthesized constructor.
unified/​extractor/​tests/​corpus/​swift/​functions/​constructor-call-with-type-arguments.output Records generic call constructors.
unified/​extractor/​tests/​corpus/​swift/​expressions/​super-expression.output Records base and derived constructors.
unified/​extractor/​tests/​corpus/​swift/​control-flow/​discard-statement.output Records synthesized constructor.

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

Comment thread unified/ql/lib/codeql/unified/internal/FacadeAst.qll Outdated
Comment thread unified/extractor/tests/location_tests.rs Outdated
@hvitved
hvitved force-pushed the hvitved-swift-implicit-init branch from 5444064 to 2069f4c Compare October 1, 2026 12:48
hvitved and others added 2 commits October 1, 2026 14:50
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@hvitved
hvitved force-pushed the hvitved-swift-implicit-init branch from 2069f4c to 6f9afe3 Compare October 1, 2026 12:51
@hvitved
hvitved marked this pull request as ready for review October 1, 2026 12:55
@hvitved
hvitved requested review from a team as code owners October 1, 2026 12:55
@hvitved
hvitved requested a review from asgerf October 1, 2026 13:36
@hvitved
hvitved merged commit 1912c4a into github:main Oct 1, 2026
16 checks passed
@hvitved
hvitved deleted the hvitved-swift-implicit-init branch October 1, 2026 19:14
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.

3 participants