[Experimental] WIP newtype redefinition of ProtocolNumber#469
[Experimental] WIP newtype redefinition of ProtocolNumber#469archaephyrryx wants to merge 3 commits intohaskell:masterfrom
Conversation
redefines ProtocolNumber as newtype around CInt (formerly type alias for CInt) that re-derives all instance methods for CInt that are defined in Foreign.C.Types defines and exports pattern synonyms for commonly used protocol-number constants (defined in "netinet/in.h") (IPPROTO_(IP|IPV4|IPV6|TCP|UDP|ICMP|ICMPV6|RAW)) as well as UnsupportedProtocol and GeneralProtocol patterns refactored function definitions previously relying on (ProtocolNumber ~ CInt) to use unwrapper function implements bijective read/show instances for ProtocolNumber whose default behavior is to directly read and show integer values with no constructor syntax
|
This patch constitutes an API change that would potentially break network-dependent packages depending on how reliant they are on the reflection |
Unbreaks doctest by substituting new `show` value of defaultProtocol where it appears in haddock examples Clarifies behavior of show for ProtocolNumber to highlight that pattern synonym names and their corresponding show values are based on assumption of IP protocol families even though the type itself remains general over all protocol families.
|
I also noticed that an incomplete pattern warning for Network/Socket/Types.hsc can be fixed by replacing isSupportedFamily :: Family -> Bool
isSupportedFamily f = case f of
UnsupportedFamily -> False
GeneralFamily _ -> Truewith isSupportedFamily :: Family -> Bool
isSupportedFamily f = case f of
UnsupportedFamily -> False
_ -> Truewithout otherwise changing the behavior of the function. This change is trivial and safe enough that it would probably be better to directly fix it on master than tie a commit to this PR. |
Redefines ProtocolNumber synonyms in terms of canonical "magic" numbers from IANA reference (https://www.iana.org/assignments/protocol-numbers) rather than CPP-constants from C header file. Removes UnsupportedProtocol as all definitions are unconditional instead of relying on C header-file macro definitions; redefines test case to ensure that the value 'ProtocolNumber (-1)' is represented shown as "-1" rather than "UnsupportedProtocol" Renames IPPROTO_IP (dummy for '0') as DefaultProtocol, both as a pattern synonym and in read/show boilerplate bijection (as well as in haddock examples and tests/Network/SocketSpec.hs)
|
I am currently trying to assess how big an impact this API change would have on existing libraries, and have also requested an external reviewer independently. For now, I don't think this is ready to merge yet, but there is not much more to be done for it besides a few minor tweaks assuming everything looks good. |
|
@archaephyrryx Since v3.1.2.0 was released, I think it's time to tackle this PR. Do you think that this PR is ready for merging? |
redefines ProtocolNumber as newtype around CInt (formerly type alias for CInt)
that re-derives all instance methods for CInt that are defined in Foreign.C.Types
defines and exports pattern synonyms for commonly used protocol-number constants (defined in "netinet/in.h")
(IPPROTO_(IP|IPV4|IPV6|TCP|UDP|ICMP|ICMPV6|RAW)) as well as UnsupportedProtocol and GeneralProtocol patterns
refactored function definitions previously relying on (ProtocolNumber ~ CInt) to use unwrapper function
implements bijective read/show instances for ProtocolNumber whose default behavior is to directly read and show integer values with no constructor syntax