SE-0425: 128-bit Integer Types

It is binary-breaking (and source-breaking) to add to a protocol's requirements, because existing code will not be compliant (which is, I think, basically undefined behaviour in Swift - claiming to conform to a protocol yet not actually implementing all its methods could result in who knows what when something tries to call one of the missing methods).

Adding a new method with a default implementation is a way around that, because the default implementation allows existing code to technically still conform (even if the default implementation does nothing, or throws an exception).

Having the default implementation just throw an error is somewhat appealing:

  • It side-steps debate over how it should encode the 128-bit integer…
    • …and eliminates the need to forever-after support reading that hacky "temporary" representation.
  • Makes it much more likely that custom coders will actually support 128-bit integers properly (rather than just ignoring them and continuing to use the default encoding, which is always going to be suboptimal and is not the intent of having a default encoding).

Would it ever not be able to throw an error, though? i.e. can the default implementation one day be removed? Because permanently having a protocol method that unexpectedly throws exceptions if you forget to override it - which the compiler & IDE won't encourage you to do to, so easy to overlook - will likely be a recurring pain point for not just coder implementors but also codable users.

4 Likes