Skip to content

swift-public-api: merge declarations that share a path into one valid entity - #291

Merged
agorischek merged 3 commits into
mainfrom
fix-swift-duplicate-properties
Dec 3, 2026
Merged

agorischek merged 3 commits into
mainfrom
fix-swift-duplicate-properties

Conversation

@agorischek

@agorischek agorischek commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 5944562435fc7b82dfd0f889f58942eb32419f89

Dimension Assessment Rationale
Change confidence 8.5/10 ↑ New fixture (the #290 package plus subscripts, typealiases, methods, static + instance properties, overloads and Array extensions) 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.declarations and per-declaration evidence, and members of conformance-constrained extensions gain native.where entries: intended, but changes existing extractions.
↑ Copilot review's one finding (a generic method's own where clause got a second where) 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.
Diagnosis confidence 9.5/10 ↑ The new schema test reproduced the issue's exact error (/entities/N/data/contract/signatures: Expected an array) before the fix.
↑ Cause traced to serde_json IndexMut inserting null for the missing signatures key in Builder::symbol.
Evidence fit 9.5/10 ↑ The issue's repro, verbatim, is the fixture's Repro.swift and failed the same way.

What changed

Refs #290, reported by @kerrmarin-lvmh.

Cause. When a symbol's ID was already taken, Builder::symbol merged it with existing["data"]["contract"]["signatures"].as_array_mut(). serde_json's IndexMut inserts the key as null when it's missing, so two non-callables sharing an ID (static let required in two constrained extensions) produced "signatures": null, which the Engine rejects. projections show then 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 its where clause (joining a generic declaration's own clause, before any { get }), so the API renderer tells them apart:
    static let required: Validation<Bool> where Value == Bool
    static let required: Validation<Int> where Value == Int
    
  • contract: the facts every declaration shares (with the first one's declaration, term and visibility) and every declaration's signatures; each declaration's own contract, with its type and where, is in native.declarations.
  • evidence: one entry per declaration.
  • native.where also lists the declaring extension's conformance constraints (Value: Hashable), so declarations in where Value: Equatable and where Value: Hashable extensions 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 where clauses), 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 gains where 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>.md describes what
    users will notice, or the PR has the no changelog label (see
    changelog.d/README.md).

  • No credentials, private source or machine-specific paths are included.

agorischek and others added 2 commits December 3, 2026 07:37
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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the change that merges Swift declarations sharing a path.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@agorischek
agorischek merged commit a0cd42e into main Dec 3, 2026
37 checks passed
@agorischek
agorischek deleted the fix-swift-duplicate-properties branch December 3, 2026 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants