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

Make constructors private for parts of the ComInterfaceGenerator that should only be created from their static methods #101740

Merged
merged 11 commits into from
May 29, 2024

Conversation

jtschuster
Copy link
Member

@jtschuster jtschuster commented Apr 30, 2024

Part of #101615

Moves ComClassInfo to its own file and moves the Func that produces them in the ComClassGenerator pipeline to a static method on ComClassInfo.

Makes the constructors for ComClassInfo, ComInterfaceContext, ComInterfaceInfo, and `ComMethoInfo private to enforce that they are only created from the static creation methods.

Creates more static SpecialTypeInfo types for sbyte, uint, short, and ushort.

Changes pattern matching on records to use property pattern matching rather than the deconstruction notation for records. Since the constructors are not accessible, neither are the deconstruct methods.

Copy link
Contributor

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

@jkoritzinsky
Copy link
Member

Personally, I do prefer using records here as the constraints around record usage (and the with expressions) make it obvious that state isn't mutable by default.

I also see changing to manual equality as a bug farm. We introduced a few bugs in LibraryImport when we had a few custom equality implementations because we forgot to update them.

I think if we want to limit the constructor scope, we can manually define the record properties and define the more-scoped constructor in the body of the record, and just not use the "primary constructor" feature of records (while still getting the rest of the features of records).

@jtschuster jtschuster changed the title Use classes rather than records for parts of the incremental pipeline in interop generators and hide constructors Make constructors private for parts of the ComInterfaceGenerator that should only be created from their static methods May 9, 2024
@jtschuster jtschuster merged commit e36b937 into dotnet:main May 29, 2024
91 of 93 checks passed
Ruihan-Yin pushed a commit to Ruihan-Yin/runtime that referenced this pull request May 30, 2024
… should only be created from their static methods (dotnet#101740)

Moves ComClassInfo to its own file and moves the Func that produces them in the ComClassGenerator pipeline to a static method on ComClassInfo.

Makes the constructors for ComClassInfo, ComInterfaceContext, ComInterfaceInfo, and `ComMethoInfo private to enforce that they are only created from the static creation methods.

Creates more static SpecialTypeInfo types for sbyte, uint, short, and ushort.

Changes pattern matching on records to use property pattern matching rather than the deconstruction notation for records. Since the constructors are not accessible, neither are the deconstruct methods.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants