GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Source generate formatters as nested under the types they format for private member access · Issue #1745 · MessagePack-CSharp/MessagePack-CSharp

Source generate formatters as nested under the types they format for private member access #1745

New issue
Copy link
New issue
Copy link
Closed
#1802
Closed
Source generate formatters as nested under the types they format for private member access#1745
#1802
Copy link
Assignees
AArnott
Labels
enhancement
Milestone
v3.0

Description

@AArnott
AArnott
opened on Jan 25, 2024
Issue body actions

AOT formatters cannot access private members of the types they format today.
This is a blocker for "always on" AOT source generation of MessagePack serializable types.

As a solution, I propose that we generate formatters as nested types within the types that they format. This would be a substantial breaking change for existing users because they have to change their type declarations to be partial. To minimize this, we should only generate the formatters as nested when they need to access private or protected members. For all-public formatters, they can remain as nested types under the source generated resolver.

@pCYSl5EDgo shared some code to help us get this right, since nesting formatters under the type to be formatted may require multiple levels of nesting, for a variety of types all the way up to the namespace (which may or may not be there itself).

Activity

  1. AArnott
    added
    enhancement
    on Jan 25, 2024
  2. AArnott
    added this to the v3.0 milestone on Jan 25, 2024
  3. AArnott
    self-assigned this
    on Jan 25, 2024
  4. neuecc commented on Jan 26, 2024

    @neuecc
    neuecc
    on Jan 26, 2024
    Member
    More actions

    Making it partial and allows private sounds good.
    MemoryPack also adopts this design.
    Moreover, in MessagePack, the current necessity of passing AllowPrivate doesn't make for a great experience.
    Compared to this, enabling specific private classes to be partial seems like a step forward and makes things easier.

    In line with this, the Analyzer should also be modified.
    Currently, writing a Key on a private member seems to be ignored without any warnings.
    At this point, an error message suggesting to make the class partial would be more user-friendly and easier to understand.

    Reacted by Andrew Arnott
  5. pikpok-lihhern commented on Mar 8, 2024

    @pikpok-lihhern
    pikpok-lihhern
    on Mar 8, 2024
    More actions

    As a mid-way solution that doesn't break existing users, it would be great to allow formatter to also work with internal types and accessors. I think this makes sense for many projects that decouple their codebase via multiple assemblies.

  6. AArnott commented on Mar 14, 2024

    @AArnott
    AArnott
    on Mar 14, 2024
    CollaboratorAuthor
    More actions

    @pikpok-lihhern you're right. But we're not going to support both modes. It's hard enough to support one.

  7. pikpok-lihhern commented on Mar 14, 2024

    @pikpok-lihhern
    pikpok-lihhern
    on Mar 14, 2024
    More actions

    Yes, that's also fair. 🙂 Besides, it doesn't take a lot of work to upgrade the classes to partial for this to work anyway. 👍🏼

    I'm looking forward to this as it will be very useful for how we setup our immutable data models. Much better than managing a constructor with a long list of parameters.

    We've been avoiding the constructors approach and marking the properties with internal accessors, then before running MPC, we replace internals to public to trick MPC to generate the formatters. 😅 It's really gross, this is going to be a much better solution.

  8. AndriySvyryd commented on Apr 3, 2024

    @AndriySvyryd
    AndriySvyryd
    on Apr 3, 2024
    More actions

    Alternatively, you could use UnsafeAccessorAttribute for non-public members.
    It was specifically introduced to make serializers AOT-compatible and is almost as fast as accessing the member directly.

  9. AArnott commented on Apr 3, 2024

    @AArnott
    AArnott
    on Apr 3, 2024
    CollaboratorAuthor
    More actions

    That would be cool. But it requires .NET 8+, which leaves most existing .NET code unsupported. In a few years maybe that approach will make sense.

    Reacted by Andriy Svyryd
  10. AArnott commented on Apr 20, 2024

    @AArnott
    AArnott
    on Apr 20, 2024
    CollaboratorAuthor
    More actions

    I've begun work on this.

  11. AArnott
    added 2 commits that reference this issue on Apr 22, 2024

    Add private member serialization support for source generated formatters

    This issue will close once commit 69a3911 is merged into the 'master' branch.
    69a3911

    Add private member serialization support for source generated formatters

    This issue will close once commit 01d6388 is merged into the 'master' branch.
    01d6388
  12. AArnott
    closed this as completedon May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @AArnott
    AArnott

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    • v3.0

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.