Unified: Synthesize implicit Swift initializers - #22721
Merged
Merged
Conversation
hvitved
force-pushed
the
hvitved-swift-implicit-init
branch
from
October 1, 2026 11:44
81e9b8b to
46da672
Compare
hvitved
force-pushed
the
hvitved-swift-implicit-init
branch
3 times, most recently
from
October 1, 2026 12:24
95a8302 to
262e923
Compare
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Descendants of generated constructors are still incorrectly reported as ordinary source nodes.
Review effort: Balanced
Findings: 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.
asgerf
reviewed
Oct 1, 2026
hvitved
force-pushed
the
hvitved-swift-implicit-init
branch
from
October 1, 2026 12:48
5444064 to
2069f4c
Compare
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
hvitved
force-pushed
the
hvitved-swift-implicit-init
branch
from
October 1, 2026 12:51
2069f4c to
6f9afe3
Compare
hvitved
marked this pull request as ready for review
October 1, 2026 12:55
asgerf
approved these changes
Oct 1, 2026
This was referenced Oct 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

This PR synthesizes parameterless
initconstructors for classes and structs without an explicit constructor. Follow-up work will synthesize (in QL) parameters forstructconstructors, 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.