Skip to content

Commit 617f81f

Browse files
authored
Drop generic type constraints from Unsafe.BitCast (#100842)
* Drop generic type constraints from Unsafe.BitCast * Add isNullableType to JIT interface * superpmi * Comment formatting * Check IsGenericParameter instead of Canon * Replace IsGenericParameter check with assert * Just kidding, remove it completely :D
1 parent 3c10707 commit 617f81f

File tree

25 files changed

+451
-289
lines changed

25 files changed

+451
-289
lines changed

src/coreclr/inc/corinfo.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2709,6 +2709,11 @@ class ICorStaticInfo
27092709
CORINFO_CLASS_HANDLE cls
27102710
) = 0;
27112711

2712+
// Returns whether a class handle represents a Nullable type, if that can be statically determined.
2713+
virtual TypeCompareState isNullableType(
2714+
CORINFO_CLASS_HANDLE cls
2715+
) = 0;
2716+
27122717
// Returns TypeCompareState::Must if cls is known to be an enum.
27132718
// For enums with known exact type returns the underlying
27142719
// type in underlyingType when the provided pointer is

src/coreclr/inc/icorjitinfoimpl_generated.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@ bool isMoreSpecificType(
344344
bool isExactType(
345345
CORINFO_CLASS_HANDLE cls) override;
346346

347+
TypeCompareState isNullableType(
348+
CORINFO_CLASS_HANDLE cls) override;
349+
347350
TypeCompareState isEnum(
348351
CORINFO_CLASS_HANDLE cls,
349352
CORINFO_CLASS_HANDLE* underlyingType) override;

src/coreclr/inc/jiteeversionguid.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ typedef const GUID *LPCGUID;
4343
#define GUID_DEFINED
4444
#endif // !GUID_DEFINED
4545

46-
constexpr GUID JITEEVersionIdentifier = { /* 3c216494-65f8-49e2-b69a-7f272193bcc6 */
47-
0x3c216494,
48-
0x65f8,
49-
0x49e2,
50-
{0xb6, 0x9a, 0x7f, 0x27, 0x21, 0x93, 0xbc, 0xc6}
46+
constexpr GUID JITEEVersionIdentifier = { /* 8f046bcb-ca5f-4692-9277-898b71cb7938 */
47+
0x8f046bcb,
48+
0xca5f,
49+
0x4692,
50+
{0x92, 0x77, 0x89, 0x8b, 0x71, 0xcb, 0x79, 0x38}
5151
};
5252

5353
//////////////////////////////////////////////////////////////////////////////////////////////////////////

src/coreclr/jit/ICorJitInfo_names_generated.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ DEF_CLR_API(compareTypesForCast)
8585
DEF_CLR_API(compareTypesForEquality)
8686
DEF_CLR_API(isMoreSpecificType)
8787
DEF_CLR_API(isExactType)
88+
DEF_CLR_API(isNullableType)
8889
DEF_CLR_API(isEnum)
8990
DEF_CLR_API(getParentType)
9091
DEF_CLR_API(getChildType)

src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,15 @@ bool WrapICorJitInfo::isExactType(
804804
return temp;
805805
}
806806

807+
TypeCompareState WrapICorJitInfo::isNullableType(
808+
CORINFO_CLASS_HANDLE cls)
809+
{
810+
API_ENTER(isNullableType);
811+
TypeCompareState temp = wrapHnd->isNullableType(cls);
812+
API_LEAVE(isNullableType);
813+
return temp;
814+
}
815+
807816
TypeCompareState WrapICorJitInfo::isEnum(
808817
CORINFO_CLASS_HANDLE cls,
809818
CORINFO_CLASS_HANDLE* underlyingType)

src/coreclr/jit/importercalls.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4717,6 +4717,14 @@ GenTree* Compiler::impSRCSUnsafeIntrinsic(NamedIntrinsic intrinsic,
47174717
ClassLayout* toLayout = nullptr;
47184718
var_types toType = TypeHandleToVarType(toTypeHnd, &toLayout);
47194719

4720+
if (fromType == TYP_REF || info.compCompHnd->isNullableType(fromTypeHnd) != TypeCompareState::MustNot ||
4721+
toType == TYP_REF || info.compCompHnd->isNullableType(toTypeHnd) != TypeCompareState::MustNot)
4722+
{
4723+
// Fallback to the software implementation to throw when the types fail a "default(T) is not null"
4724+
// check.
4725+
return nullptr;
4726+
}
4727+
47204728
unsigned fromSize = fromLayout != nullptr ? fromLayout->GetSize() : genTypeSize(fromType);
47214729
unsigned toSize = toLayout != nullptr ? toLayout->GetSize() : genTypeSize(toType);
47224730

@@ -4729,8 +4737,6 @@ GenTree* Compiler::impSRCSUnsafeIntrinsic(NamedIntrinsic intrinsic,
47294737
return nullptr;
47304738
}
47314739

4732-
assert((fromType != TYP_REF) && (toType != TYP_REF));
4733-
47344740
GenTree* op1 = impPopStack().val;
47354741

47364742
op1 = impImplicitR4orR8Cast(op1, fromType);

src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2941,6 +2941,13 @@ private bool isExactType(CORINFO_CLASS_STRUCT_* cls)
29412941
return _compilation.IsEffectivelySealed(type);
29422942
}
29432943

2944+
private TypeCompareState isNullableType(CORINFO_CLASS_STRUCT_* cls)
2945+
{
2946+
TypeDesc type = HandleToObject(cls);
2947+
2948+
return type.IsNullable ? TypeCompareState.Must : TypeCompareState.MustNot;
2949+
}
2950+
29442951
private TypeCompareState isEnum(CORINFO_CLASS_STRUCT_* cls, CORINFO_CLASS_STRUCT_** underlyingType)
29452952
{
29462953
Debug.Assert(cls != null);

src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs

Lines changed: 110 additions & 94 deletions
Large diffs are not rendered by default.

src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ FUNCTIONS
244244
TypeCompareState compareTypesForEquality(CORINFO_CLASS_HANDLE cls1, CORINFO_CLASS_HANDLE cls2)
245245
bool isMoreSpecificType(CORINFO_CLASS_HANDLE cls1, CORINFO_CLASS_HANDLE cls2)
246246
bool isExactType(CORINFO_CLASS_HANDLE cls)
247+
TypeCompareState isNullableType(CORINFO_CLASS_HANDLE cls)
247248
TypeCompareState isEnum(CORINFO_CLASS_HANDLE cls, CORINFO_CLASS_HANDLE* underlyingType)
248249
CORINFO_CLASS_HANDLE getParentType(CORINFO_CLASS_HANDLE cls)
249250
CorInfoType getChildType(CORINFO_CLASS_HANDLE clsHnd, CORINFO_CLASS_HANDLE* clsRet)

src/coreclr/tools/aot/jitinterface/jitinterface_generated.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ struct JitInterfaceCallbacks
9292
TypeCompareState (* compareTypesForEquality)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE cls1, CORINFO_CLASS_HANDLE cls2);
9393
bool (* isMoreSpecificType)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE cls1, CORINFO_CLASS_HANDLE cls2);
9494
bool (* isExactType)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE cls);
95+
TypeCompareState (* isNullableType)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE cls);
9596
TypeCompareState (* isEnum)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE cls, CORINFO_CLASS_HANDLE* underlyingType);
9697
CORINFO_CLASS_HANDLE (* getParentType)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE cls);
9798
CorInfoType (* getChildType)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE clsHnd, CORINFO_CLASS_HANDLE* clsRet);
@@ -992,6 +993,15 @@ class JitInterfaceWrapper : public ICorJitInfo
992993
return temp;
993994
}
994995

996+
virtual TypeCompareState isNullableType(
997+
CORINFO_CLASS_HANDLE cls)
998+
{
999+
CorInfoExceptionClass* pException = nullptr;
1000+
TypeCompareState temp = _callbacks->isNullableType(_thisHandle, &pException, cls);
1001+
if (pException != nullptr) throw pException;
1002+
return temp;
1003+
}
1004+
9951005
virtual TypeCompareState isEnum(
9961006
CORINFO_CLASS_HANDLE cls,
9971007
CORINFO_CLASS_HANDLE* underlyingType)

0 commit comments

Comments
 (0)