Skip to content

Conversation

@jkoritzinsky
Copy link
Member

This PR changes our codegen to match the same shape of code as in https://github.com/AaronRobinsonMSFT/ComObjectRedux/pull/7

For each interface with [GeneratedComInterface], one file will be generated with the following:

  • An InterfaceInformation file-scoped type that defines the implementation of IIUnknownInterfaceType for the interface
  • An InterfaceImplementation file-scoped type, defined in the following 3 partial definitions for simplicity (we can combine these if we so wish):
    • A DIM-based implementation of the user-defined interface for "managed->unmanaged" scenarios.
    • The stubs for the "unmanaged->managed" scenarios
    • ,A method that allocates the vtable for the type (called by the InterfaceInformation type)
  • A partial definition of the user-defined interface with the IUnknownDerivedAttribute applied, using the above two file-scoped types.

As part of getting this PR working, the following general improvements to the ComInterfaceGenerator project and the tests were applied:

  • The implementation code for generating stubs and the vtable allocation was refactored out of VtableIndexStubGenerator and generalized to fit the two (now quite different) shapes of the wrapping code.
  • The NativeInterfaceUsage portion of our code snippets has now been moved into a specific test in the "shape validation" suite for the VtableIndexStubGenerator as the validation it does is no longer valid for the ComInterfaceGenerator and providing a separate single test does a better job at validating the intention of the check.

…erator based on the approach we agreed upon.
…interface and use file-scoped types to provide all of the interface information and implementation based on the design we discussed last week.
…e VirtualMethodIndexAttribute generator in the shape tests for that generator specifically.
@jkoritzinsky jkoritzinsky added area-System.Runtime.InteropServices source-generator Indicates an issue with a source generator feature labels Mar 7, 2023
@jkoritzinsky jkoritzinsky added this to the 8.0.0 milestone Mar 7, 2023
@jkoritzinsky jkoritzinsky requested a review from jtschuster March 7, 2023 00:37
@ghost ghost assigned jkoritzinsky Mar 7, 2023
@ghost
Copy link

ghost commented Mar 7, 2023

Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.

Issue Details

This PR changes our codegen to match the same shape of code as in https://github.com/AaronRobinsonMSFT/ComObjectRedux/pull/7

For each interface with [GeneratedComInterface], one file will be generated with the following:

  • An InterfaceInformation file-scoped type that defines the implementation of IIUnknownInterfaceType for the interface
  • An InterfaceImplementation file-scoped type, defined in the following 3 partial definitions for simplicity (we can combine these if we so wish):
    • A DIM-based implementation of the user-defined interface for "managed->unmanaged" scenarios.
    • The stubs for the "unmanaged->managed" scenarios
    • ,A method that allocates the vtable for the type (called by the InterfaceInformation type)
  • A partial definition of the user-defined interface with the IUnknownDerivedAttribute applied, using the above two file-scoped types.

As part of getting this PR working, the following general improvements to the ComInterfaceGenerator project and the tests were applied:

  • The implementation code for generating stubs and the vtable allocation was refactored out of VtableIndexStubGenerator and generalized to fit the two (now quite different) shapes of the wrapping code.
  • The NativeInterfaceUsage portion of our code snippets has now been moved into a specific test in the "shape validation" suite for the VtableIndexStubGenerator as the validation it does is no longer valid for the ComInterfaceGenerator and providing a separate single test does a better job at validating the intention of the check.
Author: jkoritzinsky
Assignees: -
Labels:

area-System.Runtime.InteropServices, source-generator

Milestone: 8.0.0

…ic we use to efficiently reassociate methods with their types and they're much simpler anyway as we don't need to even try to do any marshalling.
}

context.RegisterConcatenatedSyntaxOutputs(generateNativeInterface, "NativeInterfaces.g.cs");
private static string GenerateMarkerInterfaceSource(ComInterfaceContext iface) => $$"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something we'll want to switch to using the SyntaxFactory methods, or should it stay as an interpolated string?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a lot cleaner as an interpolated string and making it typed with SyntaxFactory doesn't get us the benefits of syntax nodes that we get in the rest of the project (more structure around wrapping syntax and knowing what type of syntax we're working with at various API boundaries). I'd be curious what @AaronRobinsonMSFT and @elinor-fung think for this case.

{
public bool Equals(SyntaxEquivalentNode<T> other)
{
return SyntaxEquivalentComparer.Instance.Equals(Node, other.Node);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know the singleton is usually named Instance, but in this case I first thought this would compare the SyntaxNodes by reference/instance equality. I'm fine leaving it, but if you think it might be confusing too, it could be worth renaming.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can rename it, but I'd rather wait until after this PR is merged in.

Copy link
Member

@jtschuster jtschuster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a couple nits/questions. Thank you!

@jkoritzinsky jkoritzinsky merged commit 49da0bd into dotnet:main Mar 7, 2023
@jkoritzinsky jkoritzinsky deleted the file-per-interface branch March 7, 2023 21:04
@ghost ghost locked as resolved and limited conversation to collaborators Apr 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Runtime.InteropServices source-generator Indicates an issue with a source generator feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants