-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Unify Default Comparer logic #88006
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
Unify Default Comparer logic #88006
Changes from all commits
7f617e2
2536992
5605e0e
72e548a
9d9fc84
f229039
70cb1c0
e095936
d591efe
7088336
0c0c84d
c516e7f
d8195e6
f8249c7
4d1d88f
5ab501a
6c45b7e
40eab70
ff59591
1f2b4aa
d0627bf
ba2e5cb
6bdbee2
1d14835
f4009d7
6fdb5c9
b085174
7659053
8ec024f
f5a9c18
c33e1de
588d884
a64df29
fa682a2
859a25d
45ec76d
1c79052
d0ad2dd
8471b21
1999819
0772c85
35ee0a2
7c902b4
fc21b4f
fff6180
1b1c1e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8792,55 +8792,31 @@ CORINFO_CLASS_HANDLE CEEInfo::getDefaultComparerClassHelper(CORINFO_CLASS_HANDLE | |
// We need to find the appropriate instantiation | ||
Instantiation inst(&elemTypeHnd, 1); | ||
|
||
// If T implements IComparable<T> | ||
if (elemTypeHnd.CanCastTo(TypeHandle(CoreLibBinder::GetClass(CLASS__ICOMPARABLEGENERIC)).Instantiate(inst))) | ||
{ | ||
TypeHandle resultTh = ((TypeHandle)CoreLibBinder::GetClass(CLASS__GENERIC_COMPARER)).Instantiate(inst); | ||
return CORINFO_CLASS_HANDLE(resultTh.GetMethodTable()); | ||
} | ||
|
||
// Nullable<T> | ||
if (Nullable::IsNullableType(elemTypeHnd)) | ||
{ | ||
Instantiation nullableInst = elemTypeHnd.AsMethodTable()->GetInstantiation(); | ||
TypeHandle iequatable = TypeHandle(CoreLibBinder::GetClass(CLASS__IEQUATABLEGENERIC)).Instantiate(nullableInst); | ||
if (nullableInst[0].CanCastTo(iequatable)) | ||
{ | ||
TypeHandle resultTh = ((TypeHandle)CoreLibBinder::GetClass(CLASS__NULLABLE_COMPARER)).Instantiate(nullableInst); | ||
return CORINFO_CLASS_HANDLE(resultTh.GetMethodTable()); | ||
} | ||
TypeHandle resultTh = ((TypeHandle)CoreLibBinder::GetClass(CLASS__NULLABLE_COMPARER)).Instantiate(nullableInst); | ||
return CORINFO_CLASS_HANDLE(resultTh.GetMethodTable()); | ||
} | ||
|
||
// We need to special case the Enum comparers based on their underlying type to avoid boxing | ||
if (elemTypeHnd.IsEnum()) | ||
{ | ||
MethodTable* targetClass = NULL; | ||
CorElementType normType = elemTypeHnd.GetVerifierCorElementType(); | ||
|
||
switch(normType) | ||
{ | ||
case ELEMENT_TYPE_I1: | ||
case ELEMENT_TYPE_I2: | ||
case ELEMENT_TYPE_U1: | ||
case ELEMENT_TYPE_U2: | ||
case ELEMENT_TYPE_I4: | ||
case ELEMENT_TYPE_U4: | ||
case ELEMENT_TYPE_I8: | ||
case ELEMENT_TYPE_U8: | ||
{ | ||
targetClass = CoreLibBinder::GetClass(CLASS__ENUM_COMPARER); | ||
break; | ||
} | ||
TypeHandle resultTh = ((TypeHandle)CoreLibBinder::GetClass(CLASS__ENUM_COMPARER)).Instantiate(inst); | ||
return CORINFO_CLASS_HANDLE(resultTh.GetMethodTable()); | ||
jkotas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
default: | ||
break; | ||
} | ||
if (elemTypeHnd.IsCanonicalSubtype()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Or the Or the Here is example of a bug that would be hit by the code as written:
It will start printing true correctly, and then flips to printing false as the incorrect Tier1 optimization kicks in. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It wouldn't, it'd then block There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, it won't mirror the bugs. Notice that the bug demonstrated by my
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This links to my comment. Did you meant to link to some diffs somewhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah, seems like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There diffs look odd. Are you able to reproduce the behavior locally? It can be that the bot picked up stale bits from somewhere. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new diffs look good to me, but I do not think the difference can be explained by the one commit that you have pushed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The bot seems to be having some issues with picking up VM changes, after a fix CoreLib changes look good but frameworks ones still have the weird diff, not sure if it's still an issue with the bot. |
||
{ | ||
return NULL; | ||
} | ||
|
||
if (targetClass != NULL) | ||
{ | ||
TypeHandle resultTh = ((TypeHandle)targetClass->GetCanonicalMethodTable()).Instantiate(inst); | ||
return CORINFO_CLASS_HANDLE(resultTh.GetMethodTable()); | ||
} | ||
// If T implements IComparable<T> | ||
if (elemTypeHnd.CanCastTo(TypeHandle(CoreLibBinder::GetClass(CLASS__ICOMPARABLEGENERIC)).Instantiate(inst))) | ||
{ | ||
TypeHandle resultTh = ((TypeHandle)CoreLibBinder::GetClass(CLASS__GENERIC_COMPARER)).Instantiate(inst); | ||
return CORINFO_CLASS_HANDLE(resultTh.GetMethodTable()); | ||
} | ||
|
||
// Default case | ||
|
@@ -8881,25 +8857,12 @@ CORINFO_CLASS_HANDLE CEEInfo::getDefaultEqualityComparerClassHelper(CORINFO_CLAS | |
// And in compile.cpp's SpecializeEqualityComparer | ||
TypeHandle elemTypeHnd(elemType); | ||
|
||
// Special case for byte | ||
if (elemTypeHnd.AsMethodTable()->HasSameTypeDefAs(CoreLibBinder::GetClass(CLASS__ELEMENT_TYPE_U1))) | ||
{ | ||
return CORINFO_CLASS_HANDLE(CoreLibBinder::GetClass(CLASS__BYTE_EQUALITYCOMPARER)); | ||
} | ||
|
||
// Mirrors the logic in BCL's CompareHelpers.CreateDefaultComparer | ||
// And in compile.cpp's SpecializeComparer | ||
// | ||
// We need to find the appropriate instantiation | ||
Instantiation inst(&elemTypeHnd, 1); | ||
|
||
// If T implements IEquatable<T> | ||
if (elemTypeHnd.CanCastTo(TypeHandle(CoreLibBinder::GetClass(CLASS__IEQUATABLEGENERIC)).Instantiate(inst))) | ||
{ | ||
TypeHandle resultTh = ((TypeHandle)CoreLibBinder::GetClass(CLASS__GENERIC_EQUALITYCOMPARER)).Instantiate(inst); | ||
return CORINFO_CLASS_HANDLE(resultTh.GetMethodTable()); | ||
} | ||
|
||
// Nullable<T> | ||
if (Nullable::IsNullableType(elemTypeHnd)) | ||
{ | ||
|
@@ -8914,33 +8877,20 @@ CORINFO_CLASS_HANDLE CEEInfo::getDefaultEqualityComparerClassHelper(CORINFO_CLAS | |
// to avoid boxing and call the correct versions of GetHashCode. | ||
if (elemTypeHnd.IsEnum()) | ||
{ | ||
MethodTable* targetClass = NULL; | ||
CorElementType normType = elemTypeHnd.GetVerifierCorElementType(); | ||
|
||
switch(normType) | ||
{ | ||
case ELEMENT_TYPE_I1: | ||
case ELEMENT_TYPE_I2: | ||
case ELEMENT_TYPE_U1: | ||
case ELEMENT_TYPE_U2: | ||
case ELEMENT_TYPE_I4: | ||
case ELEMENT_TYPE_U4: | ||
case ELEMENT_TYPE_I8: | ||
case ELEMENT_TYPE_U8: | ||
{ | ||
targetClass = CoreLibBinder::GetClass(CLASS__ENUM_EQUALITYCOMPARER); | ||
break; | ||
} | ||
TypeHandle resultTh = ((TypeHandle)CoreLibBinder::GetClass(CLASS__ENUM_EQUALITYCOMPARER)).Instantiate(inst); | ||
return CORINFO_CLASS_HANDLE(resultTh.GetMethodTable()); | ||
} | ||
|
||
default: | ||
break; | ||
} | ||
if (elemTypeHnd.IsCanonicalSubtype()) | ||
{ | ||
return NULL; | ||
} | ||
|
||
if (targetClass != NULL) | ||
{ | ||
TypeHandle resultTh = ((TypeHandle)targetClass->GetCanonicalMethodTable()).Instantiate(inst); | ||
return CORINFO_CLASS_HANDLE(resultTh.GetMethodTable()); | ||
} | ||
// If T implements IEquatable<T> | ||
if (elemTypeHnd.CanCastTo(TypeHandle(CoreLibBinder::GetClass(CLASS__IEQUATABLEGENERIC)).Instantiate(inst))) | ||
{ | ||
TypeHandle resultTh = ((TypeHandle)CoreLibBinder::GetClass(CLASS__GENERIC_EQUALITYCOMPARER)).Instantiate(inst); | ||
return CORINFO_CLASS_HANDLE(resultTh.GetMethodTable()); | ||
} | ||
|
||
// Default case | ||
|
Uh oh!
There was an error while loading. Please reload this page.