Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
object.GetType is no longer an internalcall. This means we no longer
mark the ctor of the return type, System.Type, so the type check
removal optimization is kicking in where it didn't before.
  • Loading branch information
sbomer committed Dec 6, 2024
1 parent 497ed57 commit 06cab35
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public static void Main ()
GetUnderlyingTypeOnNonNullableKnownType.Test ();
MakeGenericTypeWithUnknownValue (new object[2] { 1, 2 });
MakeGenericTypeWithKnowAndUnknownArray ();

// Prevents optimizing away 'as Type' conversion.
PreserveSystemType ();
}

[Kept]
Expand Down Expand Up @@ -331,5 +334,11 @@ static void MakeGenericTypeWithKnowAndUnknownArray (Type[] unknownTypes = null,
nullable.GetProperties (); // This works - we still know it's Nullable<>, so we can get its properties
Nullable.GetUnderlyingType (nullable).GetFields (); // This must warn - since we have no idea what the underlying type is for the unknownTypes case
}

[Kept]
static void PreserveSystemType ()
{
typeof (Type).RequiresNonPublicConstructors ();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Reflection.Emit;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Helpers;
using Mono.Linker.Tests.Cases.Expectations.Metadata;

namespace Mono.Linker.Tests.Cases.UnreachableBlock
Expand All @@ -14,6 +15,9 @@ public static void Main ()
{
Test_1 (null);
Test_2 (9);

// Prevents optimizing away 'is Type' check.
PreserveSystemType ();
}

[Kept]
Expand Down Expand Up @@ -100,5 +104,11 @@ static bool IsDynamicCodeSupported {
static void Reached_1 ()
{
}

[Kept]
static void PreserveSystemType ()
{
typeof (Type).RequiresNonPublicConstructors ();
}
}
}

0 comments on commit 06cab35

Please sign in to comment.