Skip to content

Expose specific members of System.[U]IntPtr from native integer types#43766

Merged
cston merged 16 commits intodotnet:masterfrom
cston:new-members
May 5, 2020
Merged

Expose specific members of System.[U]IntPtr from native integer types#43766
cston merged 16 commits intodotnet:masterfrom
cston:new-members

Conversation

@cston
Copy link
Contributor

@cston cston commented Apr 28, 2020

Only exclude a few specific members from the underlying types from native integer types. (Previously, only a few specific members were included.) Include all interfaces implemented by the underlying types.

Fixes #42453
Fixes #42957
Fixes #43657

Test plan #38821

@cston cston added this to the 16.7 milestone Apr 28, 2020
@cston cston marked this pull request as ready for review April 29, 2020 19:57
@cston cston requested a review from a team as a code owner April 29, 2020 19:57
@AlekseyTs
Copy link
Contributor

AlekseyTs commented Apr 30, 2020

@cston I think the title of the PR is confusing. It doesn't exclude members it includes them, but not all of them. Consider renaming the PR before people start commenting on it and adjusting PR's description to accurately reflect the nature of the changes. #Closed

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Apr 30, 2020

Also, if I remember correctly, a number of issues were raised on a previous PR that tried to expose members. Were they taken into consideration in this PR? #Closed

@cston
Copy link
Contributor Author

cston commented Apr 30, 2020

I think the title of the PR is confusing. It doesn't exclude members it includes them, but not all of them. Consider renaming the PR

I wanted the title to reflect the resulting behavior, that a few specific members are excluded, rather than the previous behavior where specific members were included. I agree it's not completely clear though.

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Apr 30, 2020

rather than the previous behavior where specific members were included.

I believe that the previous behavior (before this PR) is that none of the members were included. What am I missing? #Closed

@cston
Copy link
Contributor Author

cston commented Apr 30, 2020

I believe that the previous behavior (before this PR) is that none of the members were included.

Sorry, you are correct. I was thinking of virtual members defined on System.Object, but the native integer types did not expose any members directly.

@cston cston changed the title Exclude specific members of System.[U]IntPtr from native integer types Expose specific members of System.[U]IntPtr from native integer types Apr 30, 2020
@cston
Copy link
Contributor Author

cston commented Apr 30, 2020

Also, if I remember correctly, a number of issues were raised on a previous PR that tried to expose members. Were they taken into consideration in this PR?

The previous PR was #41728. I've updated this PR based on that feedback, thanks.


return methodRef;
}
else if (methodSymbol is NativeIntegerMethodSymbol { UnderlyingMethod: MethodSymbol underlyingMethod })
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 30, 2020

Choose a reason for hiding this comment

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

else if (methodSymbol is NativeIntegerMethodSymbol { UnderlyingMethod: MethodSymbol underlyingMethod }) [](start = 16, length = 103)

Please make sure we have a test for an expression lambda using the method, including the case when the method is generic. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

NativeIntegerTests.ReadOnlyField_VirtualMethods


In reply to: 418299612 [](ancestors = 418299612)

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Apr 30, 2020

            return methodSymbol;

It feels like we might need to do something here for a constructed generic method. Please add a test like that. #Closed


Refers to: src/Compilers/CSharp/Portable/Emitter/Model/PEModuleBuilder.cs:1182 in 08c6617. [](commit_id = 08c6617, deletion_comment = False)

considerCallingConvention: false, //ignore static-ness
considerRefKindDifferences: false,
typeComparison: TypeCompareKind.IgnoreCustomModifiersAndArraySizesAndLowerBounds | TypeCompareKind.IgnoreNullableModifiersForReferenceTypes | TypeCompareKind.IgnoreDynamic);
typeComparison: TypeCompareKind.IgnoreCustomModifiersAndArraySizesAndLowerBounds | TypeCompareKind.IgnoreNullableModifiersForReferenceTypes | TypeCompareKind.IgnoreDynamic | TypeCompareKind.IgnoreNativeIntegers);
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 30, 2020

Choose a reason for hiding this comment

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

TypeCompareKind.IgnoreCustomModifiersAndArraySizesAndLowerBounds | TypeCompareKind.IgnoreNullableModifiersForReferenceTypes | TypeCompareKind.IgnoreDynamic | TypeCompareKind.IgnoreNativeIntegers [](start = 28, length = 194)

TypeCompareKind.AllIgnoreOptions & ~TypeCompareKind.IgnoreTupleNames? #Closed

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Apr 30, 2020

    public static readonly MemberSignatureComparer CSharpWithoutTupleNamesComparer = new MemberSignatureComparer(

AllIgnoreComparer? #Closed


Refers to: src/Compilers/CSharp/Portable/Symbols/MemberSignatureComparer.cs:146 in 08c6617. [](commit_id = 08c6617, deletion_comment = False)

considerCallingConvention: false, //ignore static-ness
considerRefKindDifferences: false,
typeComparison: TypeCompareKind.IgnoreCustomModifiersAndArraySizesAndLowerBounds | TypeCompareKind.IgnoreNullableModifiersForReferenceTypes | TypeCompareKind.IgnoreDynamicAndTupleNames);
typeComparison: TypeCompareKind.IgnoreCustomModifiersAndArraySizesAndLowerBounds | TypeCompareKind.IgnoreNullableModifiersForReferenceTypes | TypeCompareKind.IgnoreDynamicAndTupleNames | TypeCompareKind.IgnoreNativeIntegers);
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 30, 2020

Choose a reason for hiding this comment

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

TypeCompareKind.IgnoreCustomModifiersAndArraySizesAndLowerBounds | TypeCompareKind.IgnoreNullableModifiersForReferenceTypes | TypeCompareKind.IgnoreDynamicAndTupleNames | TypeCompareKind.IgnoreNativeIntegers [](start = 28, length = 207)

TypeCompareKind.AllIgnoreOptions? It looks like other comparers could also use the same simplification. #Closed

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Apr 30, 2020

    public static readonly MemberSignatureComparer CSharpWithTupleNamesComparer = new MemberSignatureComparer(

The name of this comparer (and the next one) is somewhat misleading consider renaming. For example, this could be name IgnoreAllButTupleNamesComparer #Closed


Refers to: src/Compilers/CSharp/Portable/Symbols/MemberSignatureComparer.cs:133 in 08c6617. [](commit_id = 08c6617, deletion_comment = False)

@AlekseyTs
Copy link
Contributor

            return methodSymbol;

I see that we do not expose generic methods at the moment, consider adding an assert here that methodSymbol.OriginalDefinition and methodSymbol.ConstructedFrom are not NativeIntegerMethodSymbol


In reply to: 622124666 [](ancestors = 622124666)


Refers to: src/Compilers/CSharp/Portable/Emitter/Model/PEModuleBuilder.cs:1182 in 08c6617. [](commit_id = 08c6617, deletion_comment = False)

}
}
break;
case MethodKind.ExplicitInterfaceImplementation:
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 30, 2020

Choose a reason for hiding this comment

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

MethodKind.ExplicitInterfaceImplementation [](start = 37, length = 42)

I do not think we can trust this completely. I.e. I think it is possible to have a different kind and still be explicit interface implementation. What exactly are we trying to accomplish here? Perhaps we should simply add everything that is MetadataVirtual, that would take care of all overrides and interface implementations. #Closed

@cston
Copy link
Contributor Author

cston commented Apr 30, 2020

    public static readonly MemberSignatureComparer CSharpWithoutTupleNamesComparer = new MemberSignatureComparer(

It does not include TypeCompareKind.ObliviousNullableModifierMatchesAny which is part of TypeCompareKind.AllIgnoreOptions.


In reply to: 622132199 [](ancestors = 622132199)


Refers to: src/Compilers/CSharp/Portable/Symbols/MemberSignatureComparer.cs:146 in 08c6617. [](commit_id = 08c6617, deletion_comment = False)

{
var builder = ArrayBuilder<Symbol>.GetInstance();
builder.Add(new SynthesizedInstanceConstructor(this));
foreach (var underlyingMember in underlyingMembers)
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 30, 2020

Choose a reason for hiding this comment

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

foreach (var underlyingMember in underlyingMembers) [](start = 16, length = 51)

Are we interested in cloning static members? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.


In reply to: 418320751 [](ancestors = 418320751)

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Apr 30, 2020

    public static readonly MemberSignatureComparer CSharpWithoutTupleNamesComparer = new MemberSignatureComparer(

It does not include TypeCompareKind.ObliviousNullableModifierMatchesAny which is part of TypeCompareKind.AllIgnoreOptions.

When we use TypeCompareKind.IgnoreNullableModifiersForReferenceTypes, presence or absence of TypeCompareKind.ObliviousNullableModifierMatchesAny makes no difference and we should include it anyway for completeness.


In reply to: 622145910 [](ancestors = 622145910,622132199)


Refers to: src/Compilers/CSharp/Portable/Symbols/MemberSignatureComparer.cs:146 in 08c6617. [](commit_id = 08c6617, deletion_comment = False)

{
var builder = ArrayBuilder<Symbol>.GetInstance();
builder.Add(new SynthesizedInstanceConstructor(this));
foreach (var underlyingMember in underlyingMembers)
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 30, 2020

Choose a reason for hiding this comment

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

foreach (var underlyingMember in underlyingMembers) [](start = 16, length = 51)

Are we interested in cloning members inaccessible outside the type? #Closed

Copy link
Member

@gafter gafter left a comment

Choose a reason for hiding this comment

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

:shipit:

internal sealed override NamedTypeSymbol NativeIntegerUnderlyingType => _underlyingType;

internal override bool Equals(TypeSymbol t2, TypeCompareKind comparison, IReadOnlyDictionary<TypeParameterSymbol, bool>? isValueTypeOverrideOpt = null) => _underlyingType.Equals(t2, comparison, isValueTypeOverrideOpt);
internal override bool Equals(TypeSymbol? other, TypeCompareKind comparison, IReadOnlyDictionary<TypeParameterSymbol, bool>? isValueTypeOverrideOpt = null)
Copy link
Contributor

@AlekseyTs AlekseyTs May 4, 2020

Choose a reason for hiding this comment

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

Equals [](start = 31, length = 6)

I would expect us to also override equality for error types representing native/regular ints. #Closed

@AlekseyTs
Copy link
Contributor

AlekseyTs commented May 4, 2020

                            return includeUnderlyingMember(method.AssociatedSymbol);

Is this check useful? #Closed


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NativeIntegerTests.cs:400 in cb1ed0e. [](commit_id = cb1ed0e, deletion_comment = False)

@AlekseyTs
Copy link
Contributor

AlekseyTs commented May 4, 2020

    private sealed class SymbolComparer : IEqualityComparer<Symbol>

Can we use symbol comparer that we have in the compiler? #Closed


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NativeIntegerTests.cs:618 in cb1ed0e. [](commit_id = cb1ed0e, deletion_comment = False)

@AlekseyTs
Copy link
Contributor

AlekseyTs commented May 4, 2020

            if (includesIEquatable)

Does it make sense to add some verification for the else case? #Closed


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NativeIntegerTests.cs:1470 in cb1ed0e. [](commit_id = cb1ed0e, deletion_comment = False)

@cston
Copy link
Contributor Author

cston commented May 4, 2020

    private sealed class SymbolComparer : IEqualityComparer<Symbol>

Do we have a symbol comparer that compares Symbol instances rather than ISymbol?


In reply to: 623747048 [](ancestors = 623747048)


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NativeIntegerTests.cs:618 in cb1ed0e. [](commit_id = cb1ed0e, deletion_comment = False)

@AlekseyTs
Copy link
Contributor

AlekseyTs commented May 4, 2020

    IntPtr I<IntPtr>.F() => this;

These are going to be private and will be filtered out. It is not clear how exactly we are testing ExplicitImplementations if none of the members we are going to cone have them. Spcifically, I am referring to the comment on the test: "ExplicitImplementations properties are empty on native integer types." #Closed


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NativeIntegerTests.cs:2160 in cb1ed0e. [](commit_id = cb1ed0e, deletion_comment = False)

@AlekseyTs
Copy link
Contributor

    private sealed class SymbolComparer : IEqualityComparer<Symbol>

I am not sure how should I interpret closing the thread "By Design" with a question. If there is question, should the thread be kept active?

Do we have a symbol comparer that compares Symbol instances rather than ISymbol?

Would Microsoft.CodeAnalysis.CSharp.Symbols.SymbolEqualityComparer work?


In reply to: 623749896 [](ancestors = 623749896,623747048)


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NativeIntegerTests.cs:618 in cb1ed0e. [](commit_id = cb1ed0e, deletion_comment = False)

@AlekseyTs
Copy link
Contributor

AlekseyTs commented May 4, 2020

Done with review pass (iteration 13) #Closed

@cston
Copy link
Contributor Author

cston commented May 5, 2020

                            return includeUnderlyingMember(method.AssociatedSymbol);

We should ignore accessors for properties that are ignored.


In reply to: 623744738 [](ancestors = 623744738)


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NativeIntegerTests.cs:400 in cb1ed0e. [](commit_id = cb1ed0e, deletion_comment = False)

@cston
Copy link
Contributor Author

cston commented May 5, 2020

    private sealed class SymbolComparer : IEqualityComparer<Symbol>

The comparer wasn't used after all.


In reply to: 623753405 [](ancestors = 623753405,623749896,623747048)


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NativeIntegerTests.cs:618 in cb1ed0e. [](commit_id = cb1ed0e, deletion_comment = False)

@cston
Copy link
Contributor Author

cston commented May 5, 2020

    IntPtr I<IntPtr>.F() => this;

Updated comment.


In reply to: 623750062 [](ancestors = 623750062)


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NativeIntegerTests.cs:2160 in cb1ed0e. [](commit_id = cb1ed0e, deletion_comment = False)

@AlekseyTs
Copy link
Contributor

            if (includesIEquatable)

Does it make sense to add some verification for the else case?

This thread is marked as resolved without any response or obviously related code change. Could you please elaborate?


In reply to: 623748417 [](ancestors = 623748417)


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NativeIntegerTests.cs:1470 in cb1ed0e. [](commit_id = cb1ed0e, deletion_comment = False)

@AlekseyTs
Copy link
Contributor

AlekseyTs commented May 5, 2020

    // Explicit implementations of methods and properties are not included in native integer types.

Are we actually testing what the original comment "ExplicitImplementations properties are empty on native integer types." used to imply? Methods and properties with ExplicitImplementations do not have to be private. #Closed


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NativeIntegerTests.cs:2110 in cb1ed0e. [](commit_id = cb1ed0e, deletion_comment = False)

@cston
Copy link
Contributor Author

cston commented May 5, 2020

            if (includesIEquatable)

Added a call to VerifyInterfaces() above.


In reply to: 624148862 [](ancestors = 624148862,623748417)


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NativeIntegerTests.cs:1470 in cb1ed0e. [](commit_id = cb1ed0e, deletion_comment = False)

@cston
Copy link
Contributor Author

cston commented May 5, 2020

    // Explicit implementations of methods and properties are not included in native integer types.

Line 537 checks ExplicitImplementations for all members.


In reply to: 624149990 [](ancestors = 624149990)


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NativeIntegerTests.cs:2110 in cb7b6ac. [](commit_id = cb7b6ac, deletion_comment = False)

@AlekseyTs
Copy link
Contributor

    // Explicit implementations of methods and properties are not included in native integer types.

Line 537 checks ExplicitImplementations for all members.

But do we test a scenario where the original method/property that we clone has non empty ExplicitImplementations?


In reply to: 624151322 [](ancestors = 624151322,624149990)


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NativeIntegerTests.cs:2110 in cb1ed0e. [](commit_id = cb1ed0e, deletion_comment = False)

@AlekseyTs
Copy link
Contributor

AlekseyTs commented May 5, 2020

Done with review pass (iteration 15) #Closed

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (iteration 16)

@cston cston merged commit 26222e1 into dotnet:master May 5, 2020
@ghost ghost modified the milestones: 16.7, Next May 5, 2020
@cston cston deleted the new-members branch May 5, 2020 20:58
333fred added a commit to 333fred/roslyn that referenced this pull request May 6, 2020
* upstream/master: (495 commits)
  Simplify PEPropertySymbol constructor (dotnet#43990)
  Remove duplicate calls to ThrowIfCancellationRequested
  Allow msbuild to pass properties and metadata as analyzerconfig: (dotnet#43617)
  Use a private exception type for error types encountered instead of ArgumentException.
  Remove unnecessary check
  Code review feedback
  Adding tests and expanding side effect cases
  Expose specific members of System.[U]IntPtr from native integer types (dotnet#43766)
  Remove trailing space from BoundDecisionDagNode
  Don't cache FileInfo instances.
  Add 16.7 Preview 1 to the publish data config
  Bump prerelease version for 16.7 preview 2
  Only run code style analyzers when nullable warnings are enabled
  Remove
  Code review feedback
  Lint
  Undo
  Fix regression in global:: qualified constant in a switch case. Fixes dotnet#43960
  Undo
  Simplify
  ...
@JoeRobich JoeRobich modified the milestones: Next, 16.7.P2 May 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

4 participants