This PR is required to allow SwiftDocC to restructure the Symbol Graph Format after decoding the Symbol Graph Files. This is necessary to implement extensions to external types (fix apple/swift-docc#210).
Summary
This PR contains four major changes:
- change Symbol.KindIdentifier to use a struct-type with static properties for known values
- allow for registering new Symbol.KindIdentifiers to ensure identifiers get parsed correctly
- change Codable conformance of Symbol and Relationship to allow for encoding and decoding unknown Mixins
- change Hashable conformance of Relationship so unknown Mixins can be taken into account while hashing
Please refer to SymbolKit.docc/GraphFormatExtensions.md to see how the new APIs are to be used.
The most critical part of this implementation is how to handle decoding (and encoding) of custom Symbol.KindIdentifier
s and Mixin
s. Symbol
(and Relationship
's) Codable implementations must know how to encode/decode the custom types. This PR solves this problem by having the instance defining the custom extensions register the extensions to the Encoder/Decoder. This is realized via Encoder
/Decoder
's userInfo
. This choice has two key advantages over registering the extensions to the static context:
- no need for synchronization
- different extension views on the symbol graph format can coexist within one executable without influencing each other
Next to the user info based approach, this PR also offers the option to register Symbol.KindIdentifier
to the static
context for convenience.
#7 only provided a solution for Symbol.KindIdentifier
which did not register custom identifiers in a global context, but stored the raw value in the Symbol.KindIdentifier
locally. This, however, has one disadvantage: Custom identifiers are parsed differently than those defined by SymbolKit. The language prefix cannot be removed, since the initializer cannot know, if the first section of the identifier is a language, or already important for the language-agnostic identifier.
Dependencies
This PR should be merged after #45 as this PR is based on that branch.
Furthermore, this PR incorporates similar changes as #7 which seems to be stale.
Testing
I added test cases that:
- check encoding/decoding works with custom mixins
- Symbol.KindIdentifiers registered on the static context are parsed as expected and appear in allCases
- Symbol.KindIdentifiers registered on a decoder are decoded as expected and do not appear in allCases
- Hashable conformance of Relationships works as intended with unknown Mixins which do or do not conform to Hashable
Benchmark
Benchmarked this PR (e6478fd383a01e4f79421d9bbac5610bbffdc9dc) against main (cfa80d701f7d8699d64237c7bcc760d6c9616529) using Swift-DocC's bin/benchmark.swift
. Swift-DocC was on main (ed1770f974c3a1c6d2d1437cc07bc90a8f220c89). I used a bundle generated using swift run make-test-bundle --sizeFactor 50
.
There is no significant change in runtime:
+-----------------------------------------------------------------------------------------------------+
| Metric | Change | Before | After |
+-----------------------------------------------------------------------------------------------------+
| Duration for 'bundle-registration' (sec) | +0.54% | 12.01 | 12.08 |
| Duration for 'convert-total-time' (sec) | +0.28% | 19.92 | 19.98 |
| Duration for 'documentation-processing' | -0.15% | 7.38 | 7.37 |
| Duration for 'finalize-navigation-index' | no change | 0.24 | 0.24 |
| Peak memory footprint (MB) | -0.21% | 1966.29 | 1962.25 |
| Data subdirectory size (MB) | no change | 538.01 | 538.01 |
| Index subdirectory size (MB) | no change | 4.84 | 4.84 |
| Total DocC archive size (MB) | no change | 566.93 | 566.93 |
| Topic Anchor Checksum | no change | 08d0a84bec913460905f | 08d0a84bec913460905f |
| Topic Graph Checksum | no change | 74d25c4f1ee185ad5676 | 74d25c4f1ee185ad5676 |
+-----------------------------------------------------------------------------------------------------+
Checklist
Make sure you check off the following items. If they cannot be completed, provide a reason.
- [x] Added tests
- [x] Ran the
./bin/test
script and it succeeded
- [x] Updated documentation if necessary
- [x] Ran Benchmarks