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 16 commits into
base: master
Choose a base branch
from

Commits on Jul 23, 2024

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

    …tion
    
    (review this with whitespace changes ignored)
    Mingun committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    7b57fb4 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 23, 2024
    Configuration menu
    Copy the full SHA
    35df5ee 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 23, 2024
    Configuration menu
    Copy the full SHA
    bdf3793 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 23, 2024
    Configuration menu
    Copy the full SHA
    918c1a2 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 23, 2024
    Configuration menu
    Copy the full SHA
    22f4221 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 23, 2024
    Configuration menu
    Copy the full SHA
    9598ba1 View commit details
    Browse the repository at this point in the history
  7. 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 23, 2024
    Configuration menu
    Copy the full SHA
    228f9cc View commit details
    Browse the repository at this point in the history
  8. Correctly process skipped fields in tuple variants of internally tagg…

    …ed enums
    
    Add methods to calculate effective style of variant
    Mingun committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    f7ecf33 View commit details
    Browse the repository at this point in the history
  9. Correctly serialize tuple variants with permanently skipped fields

    Does not change anything in the generated code, but the new code will correctly
    process tuple variants when serialization style would compute correctly
    Mingun committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    d7cf4db View commit details
    Browse the repository at this point in the history
  10. 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 23, 2024
    Configuration menu
    Copy the full SHA
    d6b1cc2 View commit details
    Browse the repository at this point in the history
  11. 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 23, 2024
    Configuration menu
    Copy the full SHA
    64357d3 View commit details
    Browse the repository at this point in the history
  12. 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 23, 2024
    Configuration menu
    Copy the full SHA
    600ded8 View commit details
    Browse the repository at this point in the history
  13. 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 23, 2024
    Configuration menu
    Copy the full SHA
    5f7d386 View commit details
    Browse the repository at this point in the history
  14. 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 23, 2024
    Configuration menu
    Copy the full SHA
    61121b9 View commit details
    Browse the repository at this point in the history
  15. Configuration menu
    Copy the full SHA
    badba24 View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    20a391d View commit details
    Browse the repository at this point in the history