swift-testing
swift-testing copied to clipboard
[Experimental] Implement JSON coding without using Foundation or `Codable`.
This PR replaces most of our uses of JSONEncoder with a home-grown implementation. Types conform to the internal JSON.Serializable protocol and emit strings, numbers, dictionaries, arrays, etc. Unlike with Codable, there is no synthesized implementation here.
Pros:
- Less reliance on Foundation (ideally we drop the dependency entirely at some point);
- No need to use existentials to encode a value (allowing us to eventually support Embedded Swift); and
- The potential for more inlining as all the encoding work is done in-module.
Cons:
- Don't Repeat Yourself;
- This implementation doesn't come with a decoder (which is harder to write);
- The implementation of
JSON.Serializablecannot be supplied by the compiler; - More code means more technical debt and a higher maintenance burden;
- The implementation is less configurable/customizable than Foundation's; and
- The implementation is not a full
Encoderconformance, so it cannot be used to reimplementCustomTestArgumentEncodable.
Resolves rdar://146964016.
Checklist:
- [ ] Code and documentation should follow the style of the Style Guide.
- [ ] If public symbols are renamed or modified, DocC references should be updated.
I'm going to redo this as an enum now that I have a better idea of the constraints we need to solve for.
@swift-ci test