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

Conversation

Mingun
Copy link
Contributor

@Mingun Mingun commented Jul 31, 2023

This is continuation of #2520 expanded for enums. Create a draft PR just to see how it could look. It implements suggestions from #2520.

It is still unfinished, I want to check more situations

Mingun and others added 16 commits July 23, 2024 22:19
…tion

(review this with whitespace changes ignored)
…n_place`

Those functions too small and used only once

(review this with whitespace changes ignored)
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
Enums out of scope for now, because they have too many problems

failures (1):
    tuple_struct::tuple2as1

compilation error (commented):
    tuple_struct::tuple1as0
…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
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
…ed enums

Add methods to calculate effective style of variant
Does not change anything in the generated code, but the new code will correctly
process tuple variants when serialization style would compute correctly
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 }
Does not change anything in the generated code, but the new code will correctly
process tuples, when serialization style would compute correctly
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
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
…djacently tagged and untagged enums

serde-rs#2465 maked such deserialization possible
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant