Repository navigation
swift-public-api: merge declarations that share a path into one valid entity - #291
Merged
Merged
Conversation
Builder::symbol merged a duplicate-ID symbol by indexing existing["data"]["contract"]["signatures"] mutably, and serde_json's IndexMut inserts null for a missing key, so non-callables sharing an ID (a property in several constrained extensions) got "signatures": null, which the Engine rejects. Declarations sharing an ID now merge into one entity: a signature line each, in source order, ending with the extension constraints that tell it apart; a contract of the shared facts and every signature, with each declaration's own contract in native.declarations; evidence for each. native.where also lists the declaring extension's conformance constraints. Tests validate every fixture extraction with the Engine. Fixes #290 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Generic methods with existing where clauses can receive a second where clause from extension constraints, producing invalid signatures and requiring a fix with regression coverage.
1 open issue
What changed in this PR
Fixes #290 by merging Swift declarations that share a path into one valid API entity, preventing duplicate properties from causing Engine validation failures.
Changes:
- Preserve per-declaration contracts, evidence, and distinguishing extension constraints.
- Add regression fixtures, Engine validation, and native Swift coverage.
- Document the merged representation and user-visible fix.
| File | Description |
|---|---|
packages/extractors/swift-public-api/tests/fixtures/constrained-extensions/package/Sources/Repro/Repro.swift |
Reproduces #290. |
packages/extractors/swift-public-api/tests/fixtures/constrained-extensions/package/Sources/Repro/Box.swift |
Exercises duplicate-path declaration varieties. |
packages/extractors/swift-public-api/tests/fixtures/constrained-extensions/package/Sources/Repro/Array.swift |
Covers external-type extensions. |
packages/extractors/swift-public-api/tests/fixtures/constrained-extensions/package/Package.swift |
Defines the regression package. |
packages/extractors/swift-public-api/tests/fixtures/constrained-extensions/package.symbols/Repro@Swift.symbols.json |
Captures external-extension symbol graphs. |
packages/extractors/swift-public-api/tests/fixtures/constrained-extensions/package.symbols/Repro.symbols.json |
Captures package symbol graphs. |
packages/extractors/swift-public-api/tests/fixtures/constrained-extensions/package.expected.json |
Records expected merged entities. |
packages/extractors/swift-public-api/src/tests.rs |
Validates merged output and Engine acceptance. |
packages/extractors/swift-public-api/src/model/contract.rs |
Preserves extension constraints. |
packages/extractors/swift-public-api/src/model.rs |
Collects and merges same-path declarations. |
packages/extractors/swift-public-api/README.md |
Documents merging and fixture coverage. |
packages/cli/tests/native_tools/swift.rs |
Extends native-toolchain coverage. |
docs/builtins/extractors/swift-public-api.md |
Explains merged entities and constraints. |
changelog.d/291.md |
Describes the user-visible fix. |
Review effort: Balanced
… where clause A generic method or subscript already prints its own where clause, so add the distinguishing extension constraints to it, before any accessor block, rather than appending a second where. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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.

Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
5944562435fc7b82dfd0f889f58942eb32419f89Arrayextensions) has a golden extraction and is validated by the Engine.↑ Native test builds it with Swift 6.4.2 and matches the captured graphs; existing compatibility golden unchanged.
↑ Rendered a before/after comparison in the viewer: one modified entity, new lines highlighted.
↓ Ordinary overloads now also carry
native.declarationsand per-declaration evidence, and members of conformance-constrained extensions gainnative.whereentries: intended, but changes existing extractions.↑ Copilot review's one finding (a generic method's own
whereclause got a secondwhere) fixed with fixture cases.↑ CI green on this revision (27 passed, 9 skipped); a second Copilot review raised nothing.
↓ Ordinary overload output changes are not exercised by any downstream consumer test.
/entities/N/data/contract/signatures: Expected an array) before the fix.↑ Cause traced to serde_json
IndexMutinsertingnullfor the missingsignatureskey inBuilder::symbol.Repro.swiftand failed the same way.What changed
Refs #290, reported by @kerrmarin-lvmh.
Cause. When a symbol's ID was already taken,
Builder::symbolmerged it withexisting["data"]["contract"]["signatures"].as_array_mut(). serde_json'sIndexMutinserts the key asnullwhen it's missing, so two non-callables sharing an ID (static let requiredin two constrained extensions) produced"signatures": null, which the Engine rejects.projections showthen failed for the whole module.Fix. Declarations that share an ID are collected and merged once at the end into one valid entity, the way overloads already were:
data.signature: a line per declaration, in source order, with its extension's constraints that the others don't share added to itswhereclause (joining a generic declaration's own clause, before any{ get }), so the API renderer tells them apart:contract: the facts every declaration shares (with the first one'sdeclaration,termandvisibility) and every declaration'ssignatures; each declaration's own contract, with its type andwhere, is innative.declarations.evidence: one entry per declaration.native.wherealso lists the declaring extension's conformance constraints (Value: Hashable), so declarations inwhere Value: Equatableandwhere Value: Hashableextensions differ in the contract too.Other duplicate-ID paths. Checked with Swift 6.4.2: same-named subscripts, typealiases and methods in constrained extensions (including generic ones with their own
whereclauses), static + instance properties, ordinary overloads, and members of constrained extensions of another module's type all share IDs and are covered by the fixture. Same-named nested types, a typealias and a struct, a property and a typealias, or an enum case and a static property in constrained extensions are rejected by the compiler ("invalid redeclaration"); enum cases can't be declared in extensions.Evidence
cargo test -p projections-extractor-swift-public-api: new test validates every fixture extraction with the Engine (normalize_extraction) and asserts each merged entity; it failed with the issue's error before the fix.PROJECTIONS_NATIVE_SWIFT=1 cargo test -p projections-cli --test native_tools native_swift: builds the new fixture with the real toolchain too.tools check --fast,tools check --affected,tools changelog: pass.Viewer screenshot of the issue's package before (one
required) and after (three): the entity is Modified, the two new lines are added, and the first gainswhere Value == Bool.Documentation that this change affects is updated, and generated reference
pages are regenerated (
npm run docs:generate).Fixes include a regression test.
A changelog fragment at
changelog.d/<this PR's number>.mddescribes whatusers will notice, or the PR has the
no changeloglabel (seechangelog.d/README.md).
No credentials, private source or machine-specific paths are included.