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 support for externally declared records #9104

Merged
merged 5 commits into from
Oct 1, 2024

Commits on Aug 28, 2024

  1. Fix support for externally declared records

    FIxes improper codec codegen for records declared in referenced projects/assemblies. Roslyn does not guarantee the symbols contain the backing fields for generated properties (see dotnet/roslyn#72374 (comment)) and it also doesn't even report `record struct` symbols as records at all (see dotnet/roslyn#69326).
    
    This makes for a very inconsistent experience when dealing with types defined in external assemblies that don't use the Orleans SDK themselves.
    
    We implement a heuristics here to determine primary constructors that can be relied upon to detect them consistently:
    1. A ctor with non-zero parameters
    2. All parameters match by name exactly with corresponding properties
    3. All matching properties have getter AND setter annotated with [CompilerGenerated].
    
    In addition, since the backing field isn't available at all in these records, and the corresponding property isn't settable (it's generated as `init set`), we leverage unsafe accessors (see https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.unsafeaccessorattribute?view=net-8.0) instead. The code checks whether the `FieldAccessorDescription` has an initializer syntax or not to determine whether to generate the original code or the new accessor version.
    
    The signature of the accessor matches the delegate that is generated for the regular backing field case, so there is no need to modify other call sites.
    
    Fixes dotnet#9092
    kzu committed Aug 28, 2024
    Configuration menu
    Copy the full SHA
    6357654 View commit details
    Browse the repository at this point in the history
  2. Skip compiler-generated ctors in records

    In externally defined symbols, we need to also check for `[CompilerGenerated]`.
    kzu committed Aug 28, 2024
    Configuration menu
    Copy the full SHA
    9e64309 View commit details
    Browse the repository at this point in the history
  3. Ignore design-time build value when debugging generator

    This allows running F5 on the generator project and troubleshoot issues. By checking for an already attached debugger, we can debug also scenarios of code generation where the roslyn component starts it with DTB=true.
    kzu committed Aug 28, 2024
    Configuration menu
    Copy the full SHA
    7b48cc2 View commit details
    Browse the repository at this point in the history

Commits on Sep 30, 2024

  1. Configuration menu
    Copy the full SHA
    050c1c9 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    e919b73 View commit details
    Browse the repository at this point in the history