Skip to content

Substituted symbol equality#38408

Closed
chsienki wants to merge 2 commits intodotnet:masterfrom
chsienki:substituted_symbol_equality
Closed

Substituted symbol equality#38408
chsienki wants to merge 2 commits intodotnet:masterfrom
chsienki:substituted_symbol_equality

Conversation

@chsienki
Copy link
Copy Markdown
Member

No description provided.

@chsienki chsienki added the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label Aug 29, 2019

return ReferenceEquals(this.OriginalDefinition, other.OriginalDefinition) &&
TypeSymbol.Equals(ContainingType, other.ContainingType, compareKind) &&
TypeSymbol.Equals(Type, other.Type, compareKind);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

TypeSymbol.Equals(Type, other.Type, compareKind) [](start = 19, length = 48)

This condition feels unnecessary.

// PERF: VSadov specifically replaced the short-circuited operators in changeset #24717.
if (selfIsDeclaration | otherIsDeclaration)
{
return selfIsDeclaration & otherIsDeclaration;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

return selfIsDeclaration & otherIsDeclaration; [](start = 16, length = 46)

This doesn't look right. The methods could be equal even when only one of them IsConstructedFrom

// substituted in the same way.
if (!TypeSymbol.Equals(this.ContainingType, other.ContainingType, compareKind)) return false;

// If both are declarations, then we don't need to check type arguments
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

declarations [](start = 27, length = 12)

The term "declaration" is somewhat confusing here. Consider using "not constructed" instead. Same for variable names.

int arity = this.Arity;
for (int i = 0; i < arity; i++)
{
if (!this.TypeArgumentsWithAnnotations[i].Equals(other.TypeArgumentsWithAnnotations[i], compareKind))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this.TypeArgumentsWithAnnotations [](start = 21, length = 33)

Consider caching this value in a local.

return visitor.VisitField(this);
}

public override bool Equals(Symbol obj, TypeCompareKind compareKind)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

override [](start = 15, length = 8)

sealed?

Assert.Equal(type1.GetHashCode(), type2.GetHashCode());
Assert.Equal(SymbolEqualityComparer.Default.GetHashCode(type1), SymbolEqualityComparer.Default.GetHashCode(type2));
Assert.Equal(SymbolEqualityComparer.IncludeNullability.GetHashCode(type1), SymbolEqualityComparer.IncludeNullability.GetHashCode(type2));
if (expectHashCodeMatch)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

expectHashCodeMatch [](start = 16, length = 19)

Why is this conditional on a separate flag? If Object.Equals(Object) returns true, the hash code must match, so this should be conditioned on expectedDefault.

var methodDecl = root.DescendantNodes().OfType<MethodDeclarationSyntax>().Single();
var methodBlockOperation = model.GetOperation(methodDecl);
var fieldReferenceOperation = methodBlockOperation.Descendants().OfType<IFieldReferenceOperation>().Single();
Assert.True(fieldSym.Equals(fieldReferenceOperation.Field));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Assert.True(fieldSym.Equals(fieldReferenceOperation.Field)); [](start = 16, length = 60)

Please Assert that hash code is equal as well

);
}

private void VerifyEquality(ISymbol type1, ISymbol type2, bool expectedDefault, bool expectedIncludeNullability, bool expectHashCodeMatch = true)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

type1 [](start = 44, length = 5)

Please rename to symbol1 and the other to symbol2.

expectedDefault: true,
expectedIncludeNullability: false
);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

} [](start = 8, length = 1)

It looks like we are lacking tests for generic methods, matrix [(not constructed, constructed) method] * [(not constructed, constructed) containing type].

return visitor.VisitField(this);
}

public override bool Equals(Symbol obj, TypeCompareKind compareKind)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

What about events and properties?

@AlekseyTs
Copy link
Copy Markdown
Contributor

Done with review pass (iteration 2)

@chsienki
Copy link
Copy Markdown
Member Author

chsienki commented Sep 3, 2019

Thanks @AlekseyTs. this isn't ready for review yet, but i'll keep the comments in mind as I update it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants