Skip to content

Commit

Permalink
Run TypeIntrinsics tests with native AOT (dotnet#112477)
Browse files Browse the repository at this point in the history
I don't think the `CreateDynamic` flavors test anything interesting from codegen perspective. The `IsValueType` and `IsValueTypeObj` methods are going to be called using reflection, but nothing interesting will happen in the method body (it's a very regular method body). All the `dynamic` keyword is doing there is that a ton of reflection is going to happen before we execute the regular method body.
  • Loading branch information
MichalStrehovsky authored Feb 14, 2025
1 parent 87959c6 commit 42423ef
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 28 deletions.
30 changes: 18 additions & 12 deletions src/tests/JIT/Intrinsics/TypeIntrinsics.GetEnumUnderlyingType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ public static void TestGetEnumUnderlyingType()
AssertEquals(typeof(long), typeof(LongEnum).GetEnumUnderlyingType());
AssertEquals(typeof(ulong), typeof(ULongEnum).GetEnumUnderlyingType());

AssertEquals(typeof(char), typeof(CharEnum).GetEnumUnderlyingType());
AssertEquals(typeof(bool), typeof(BoolEnum).GetEnumUnderlyingType());
AssertEquals(typeof(float), typeof(FloatEnum).GetEnumUnderlyingType());
AssertEquals(typeof(double), typeof(DoubleEnum).GetEnumUnderlyingType());
AssertEquals(typeof(nint), typeof(IntPtrEnum).GetEnumUnderlyingType());
AssertEquals(typeof(nuint), typeof(UIntPtrEnum).GetEnumUnderlyingType());
if (TestLibrary.PlatformDetection.IsRareEnumsSupported)
{
AssertEquals(typeof(char), typeof(CharEnum).GetEnumUnderlyingType());
AssertEquals(typeof(bool), typeof(BoolEnum).GetEnumUnderlyingType());
AssertEquals(typeof(float), typeof(FloatEnum).GetEnumUnderlyingType());
AssertEquals(typeof(double), typeof(DoubleEnum).GetEnumUnderlyingType());
AssertEquals(typeof(nint), typeof(IntPtrEnum).GetEnumUnderlyingType());
AssertEquals(typeof(nuint), typeof(UIntPtrEnum).GetEnumUnderlyingType());
}

AssertThrowsArgumentException(() => typeof(int).GetEnumUnderlyingType());
AssertThrowsArgumentException(() => typeof(nint).GetEnumUnderlyingType());
Expand All @@ -43,12 +46,15 @@ public static void TestGetEnumUnderlyingType()
AssertEquals(typeof(long), NoInline(typeof(LongEnum).GetEnumUnderlyingType()));
AssertEquals(typeof(ulong), NoInline(typeof(ULongEnum).GetEnumUnderlyingType()));

AssertEquals(typeof(char), NoInline(typeof(CharEnum).GetEnumUnderlyingType()));
AssertEquals(typeof(bool), NoInline(typeof(BoolEnum).GetEnumUnderlyingType()));
AssertEquals(typeof(float), NoInline(typeof(FloatEnum).GetEnumUnderlyingType()));
AssertEquals(typeof(double), NoInline(typeof(DoubleEnum).GetEnumUnderlyingType()));
AssertEquals(typeof(nint), NoInline(typeof(IntPtrEnum).GetEnumUnderlyingType()));
AssertEquals(typeof(nuint), NoInline(typeof(UIntPtrEnum).GetEnumUnderlyingType()));
if (TestLibrary.PlatformDetection.IsRareEnumsSupported)
{
AssertEquals(typeof(char), NoInline(typeof(CharEnum).GetEnumUnderlyingType()));
AssertEquals(typeof(bool), NoInline(typeof(BoolEnum).GetEnumUnderlyingType()));
AssertEquals(typeof(float), NoInline(typeof(FloatEnum).GetEnumUnderlyingType()));
AssertEquals(typeof(double), NoInline(typeof(DoubleEnum).GetEnumUnderlyingType()));
AssertEquals(typeof(nint), NoInline(typeof(IntPtrEnum).GetEnumUnderlyingType()));
AssertEquals(typeof(nuint), NoInline(typeof(UIntPtrEnum).GetEnumUnderlyingType()));
}

AssertThrowsArgumentException(() => NoInline(typeof(int).GetEnumUnderlyingType()));
AssertThrowsArgumentException(() => NoInline(typeof(nint).GetEnumUnderlyingType()));
Expand Down
10 changes: 0 additions & 10 deletions src/tests/JIT/Intrinsics/TypeIntrinsics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ public static int TestEntryPoint()
IsTrue (IsValueType<GenericStruct<int>>(default));
IsTrue (IsValueType<GenericStruct<string>>(default));
IsTrue (IsValueType(SimpleEnum.B));
IsTrue (IsValueType(CreateDynamic1()));
IsFalse(IsValueType(CreateDynamic2()));

IsTrue (IsValueTypeObj(42));
IsTrue (IsValueTypeObj(new Nullable<int>(42)));
Expand All @@ -80,8 +78,6 @@ public static int TestEntryPoint()
IsTrue (IsValueTypeObj(new GenericStruct<int>()));
IsTrue (IsValueTypeObj(new GenericStruct<string>()));
IsTrue (IsValueTypeObj(SimpleEnum.B));
IsTrue (IsValueTypeObj(CreateDynamic1()));
IsFalse(IsValueTypeObj(CreateDynamic2()));

IsTrue (IsValueTypeRef(ref _varInt));
IsTrue (IsValueTypeRef(ref _varNullableInt));
Expand Down Expand Up @@ -342,12 +338,6 @@ private static void GetGenericTypeDefinitionTests()
[MethodImpl(MethodImplOptions.NoInlining)]
private static bool IsValueTypeObj(object val) => val.GetType().IsValueType;

[MethodImpl(MethodImplOptions.NoInlining)]
private static dynamic CreateDynamic1() => 42;

[MethodImpl(MethodImplOptions.NoInlining)]
private static dynamic CreateDynamic2() => new { Name = "Test" };

[MethodImpl(MethodImplOptions.NoInlining)]
private static Type GetGenericTypeDefinition<T>() => typeof(T).GetGenericTypeDefinition();

Expand Down
3 changes: 3 additions & 0 deletions src/tests/JIT/Intrinsics/TypeIntrinsics_r.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
<Compile Include="TypeIntrinsics.IsAssignableTo.cs" />
<Compile Include="TypeIntrinsics.GetEnumUnderlyingType.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions src/tests/JIT/Intrinsics/TypeIntrinsics_ro.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
<Compile Include="TypeIntrinsics.IsAssignableTo.cs" />
<Compile Include="TypeIntrinsics.GetEnumUnderlyingType.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
</ItemGroup>
</Project>
6 changes: 0 additions & 6 deletions src/tests/issues.targets
Original file line number Diff line number Diff line change
Expand Up @@ -680,12 +680,6 @@
<ExcludeList Include="$(XunitTestBinBase)/JIT/Directed/debugging/debuginfo/tester/*">
<Issue>Just-in-time compilation test</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/JIT/Intrinsics/TypeIntrinsics_r/*">
<Issue>Not compatible with multifile testing.</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/JIT/Intrinsics/TypeIntrinsics_ro/*">
<Issue>Not compatible with multifile testing.</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/baseservices/compilerservices/RuntimeWrappedException/RuntimeWrappedException/*">
<Issue>https://github.com/dotnet/runtimelab/issues/155: Wrapping non-exception throws</Issue>
</ExcludeList>
Expand Down

0 comments on commit 42423ef

Please sign in to comment.