Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect representation of tuple variants with skipped fields #2549

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from

Commits on Jul 31, 2023

  1. Move code that generates reading from a SeqAccess to a dedicated func…

    …tion
    
    (review this with whitespace changes ignored)
    Mingun committed Jul 31, 2023
    Configuration menu
    Copy the full SHA
    bbc2bf8 View commit details
    Browse the repository at this point in the history
  2. Make deserialize_seq generic, parameterize it with data reading fun…

    …ction and rename it
    Mingun committed Jul 31, 2023
    Configuration menu
    Copy the full SHA
    f7b6944 View commit details
    Browse the repository at this point in the history
  3. Inline deserialize_newtype_struct and `deserialize_newtype_struct_i…

    …n_place`
    
    Those functions too small and used only once
    
    (review this with whitespace changes ignored)
    Mingun committed Jul 31, 2023
    Configuration menu
    Copy the full SHA
    2a975fd View commit details
    Browse the repository at this point in the history
  4. Correctly process skipped fields in visit_newtype_struct

    Changes in generated code (see the file attached to PR):
      Tuple1as0:
      Tuple1as0Default:
      Tuple1as0With:
        fixed visit_newtype_struct: use default value instead of deserializing it
    
    This fixes compilation error for Deserialize side of Tuple1as0(Skipped) tuple
    Mingun committed Jul 31, 2023
    Configuration menu
    Copy the full SHA
    b812de8 View commit details
    Browse the repository at this point in the history
  5. Add tests for skipped fields in different kinds of structs

    Enums out of scope for now, because they have too many problems
    
    failures (1):
        tuple_struct::tuple2as1
    
    compilation error (commented):
        tuple_struct::tuple1as0
    Mingun committed Jul 31, 2023
    Configuration menu
    Copy the full SHA
    a6a2c82 View commit details
    Browse the repository at this point in the history
  6. Change Tuple1as0(Skipped) representation: newtype -> tuple(0), simila…

    …r to Tuple0() struct
    
    A side-effect: Tuple2as1(Skipped, x) now also can be deserialized using visit_newtype_struct
    
    Changes in generated code (see the file attached to PR):
      Tuple1as0:
      Tuple1as0Default:
      Tuple1as0With:
        removed visit_newtype_struct, *_newtype_struct -> *_tuple_struct(0)
    
      Tuple2as1:
      Tuple2as1Default:
      Tuple2as1With:
        added visit_newtype_struct
    
    This commit fixes compilation error and actually fixes the issue as it was reported in serde-rs#2105
    Mingun committed Jul 31, 2023
    Configuration menu
    Copy the full SHA
    654ea6d View commit details
    Browse the repository at this point in the history
  7. Change Tuple2as1(Skipped, x) representation: tuple(1) -> newtype

    This matches the Tuple1(x) behavior which should be used
    
    Fixed (1):
        tuple_struct::tuple2as1
    
    Changes in generated code (see the file attached to PR):
      Tuple2as1:
      Tuple2as1Default:
      Tuple2as1With:
        *_tuple_struct(1) -> *_newtype_struct
    Mingun committed Jul 31, 2023
    Configuration menu
    Copy the full SHA
    1eac41c View commit details
    Browse the repository at this point in the history
  8. Add tests for skipped fields in different kinds of enums

    failures (15):
        enum_::adjacently_tagged::tuple_struct::tuple0
        enum_::adjacently_tagged::tuple_struct::tuple1
        enum_::adjacently_tagged::tuple_struct::tuple2as0
        enum_::adjacently_tagged::tuple_struct::tuple2as1
        enum_::adjacently_tagged::unit
        enum_::externally_tagged::tuple_struct::tuple0
        enum_::externally_tagged::tuple_struct::tuple1
        enum_::externally_tagged::tuple_struct::tuple1as0
        enum_::externally_tagged::tuple_struct::tuple2as0
        enum_::externally_tagged::tuple_struct::tuple2as1
        enum_::internally_tagged::tuple_struct::tuple1
        enum_::untagged::tuple_struct::tuple0
        enum_::untagged::tuple_struct::tuple1as0
        enum_::untagged::tuple_struct::tuple2as0
        enum_::untagged::tuple_struct::tuple2as1
    
    compilation error (commented):
        enum_::adjacently_tagged::tuple_struct::tuple1as0
        enum_::internally_tagged::tuple_struct::tuple0
        enum_::internally_tagged::tuple_struct::tuple2as0
        enum_::internally_tagged::tuple_struct::tuple2as1
    Mingun committed Jul 31, 2023
    Configuration menu
    Copy the full SHA
    b3e8da3 View commit details
    Browse the repository at this point in the history
  9. Correctly process skipped fields in tuple variants of internally tagg…

    …ed enums
    
    Add methods to calculate effective style of variant
    Mingun committed Jul 31, 2023
    Configuration menu
    Copy the full SHA
    f92623c View commit details
    Browse the repository at this point in the history
  10. Correctly serialize tuples with permanently skipped fields

    Does not change anything in the generated code, but the new code will correctly
    process tuples, when serialization style would compute correctly
    Mingun committed Jul 31, 2023
    Configuration menu
    Copy the full SHA
    47e031c View commit details
    Browse the repository at this point in the history
  11. Correctly calculate serialized enum style for serialization

    Changes in serialization (see the file attached to PR):
      ExternallyTagged, Untagged, Mixed:
        Tuple0: tuple(0) -> unit
    
        Tuple2as0: tuple(0) -> unit
        Tuple2as1: tuple(1) -> newtype
    
        Tuple2as0Default: tuple(0) -> unit
        Tuple2as1Default: tuple(1) -> newtype
    
        Tuple2as0With: tuple(0) -> unit
        Tuple2as1With: tuple(1) -> newtype
    
      AdjacentlyTagged:
        Tuple0: { tag, content: tuple(0) } -> { tag }
    
        Tuple2as0: { tag, content: tuple(0) } -> { tag }
        Tuple2as1: { tag, content: tuple(1) } -> { tag, content: newtype }
    
        Tuple2as0Default: { tag, content: tuple(0) } -> { tag }
        Tuple2as1Default: { tag, content: tuple(1) } -> { tag, content: newtype }
    
        Tuple2as0With: { tag, content: tuple(0) } -> { tag }
        Tuple2as1With: { tag, content: tuple(1) } -> { tag, content: newtype }
    Mingun committed Jul 31, 2023
    Configuration menu
    Copy the full SHA
    ff1e64b View commit details
    Browse the repository at this point in the history
  12. Correctly construct tuples with permanently skipped fields

    Does not change anything in the generated code, but the new code will correctly
    process tuples, when serialization style would compute correctly
    Mingun committed Jul 31, 2023
    Configuration menu
    Copy the full SHA
    09366b3 View commit details
    Browse the repository at this point in the history
  13. Correctly construct newtypes with permanently skipped fields

    Changes in deserialization of all enums, except externally tagged (see the file attached to PR):
      no changes in logic, only some additional type hints that would required by the next commit
    Mingun committed Jul 31, 2023
    Configuration menu
    Copy the full SHA
    93fb53a View commit details
    Browse the repository at this point in the history
  14. Correctly calculate serialized enum style for deserialization

    Changes in generated code (see the file attached to PR):
      AdjacentlyTagged, Untagged, Mixed:
        Tuple0: tuple(0) -> unit
    
        Tuple2as0: tuple(0) -> unit
        Tuple2as1: tuple(1) -> newtype
    
        Tuple2as0Default: tuple(0) -> unit
        Tuple2as1Default: tuple(1) -> newtype
    
        Tuple2as0With: tuple(0) -> unit
        Tuple2as1With: tuple(1) -> newtype
    Mingun committed Jul 31, 2023
    Configuration menu
    Copy the full SHA
    32f2c49 View commit details
    Browse the repository at this point in the history
  15. Add tests for using visit_seq for deserialzation struct variants of a…

    …djacently tagged and untagged enums
    
    serde-rs#2465 maked such deserialization possible
    Mingun committed Jul 31, 2023
    Configuration menu
    Copy the full SHA
    4647c19 View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    0c8fa03 View commit details
    Browse the repository at this point in the history
  17. Configuration menu
    Copy the full SHA
    77b3293 View commit details
    Browse the repository at this point in the history