-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Add support for statics access from shared generic code, as well as precise-init static class construction #117110
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
Open
davidwrighton
wants to merge
1
commit into
dotnet:main
Choose a base branch
from
davidwrighton:add_support_for_generic_and_preciseinit_statics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+212
−19
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -885,6 +885,10 @@ public static void RunInterpreterTests() | |
if (!TestStaticVirtualGeneric_CodePointerCase()) | ||
Environment.FailFast(null); | ||
|
||
Console.WriteLine("TestPreciseInitCctors"); | ||
if (!TestPreciseInitCctors()) | ||
Environment.FailFast(null); | ||
|
||
Console.WriteLine("Empty string length: {0}", string.Empty.Length); | ||
|
||
Console.WriteLine("BitConverter.IsLittleEndian: {0}", BitConverter.IsLittleEndian); | ||
|
@@ -1938,8 +1942,26 @@ struct GenericStruct<T> | |
public T Value; | ||
} | ||
|
||
public static int preciseInitCctorsRun = 0; | ||
|
||
class MyPreciseInitClass<T> | ||
{ | ||
static MyPreciseInitClass() | ||
{ | ||
preciseInitCctorsRun++; | ||
} | ||
|
||
public static void TriggerCctorClass() | ||
{ | ||
} | ||
|
||
public static void TriggerCctorMethod<U>() | ||
{} | ||
} | ||
|
||
class MyClass<T> | ||
{ | ||
static Type staticVarType = typeof(MyClass<T>); | ||
public Type GetTypeOf() | ||
{ | ||
return typeof(MyClass<T>); | ||
|
@@ -1948,6 +1970,61 @@ public static Type GetTypeOfStatic() | |
{ | ||
return typeof(MyClass<T>); | ||
} | ||
|
||
public static Type GetTypeThroughStaticVar() | ||
{ | ||
return staticVarType; | ||
} | ||
} | ||
|
||
public static bool TestPreciseInitCctors() | ||
{ | ||
if (preciseInitCctorsRun != 0) | ||
{ | ||
Console.WriteLine("preciseInitCctorsRun should be 0, but is {0}", preciseInitCctorsRun); | ||
return false; | ||
} | ||
MyPreciseInitClass<int>.TriggerCctorClass(); | ||
if (preciseInitCctorsRun != 1) | ||
{ | ||
Console.WriteLine("preciseInitCctorsRun should be 1, but is {0}", preciseInitCctorsRun); | ||
return false; | ||
} | ||
MyPreciseInitClass<short>.TriggerCctorMethod<int>(); | ||
if (preciseInitCctorsRun != 2) | ||
{ | ||
Console.WriteLine("TriggerCctorClass should return 2, but did not"); | ||
return false; | ||
} | ||
|
||
object o = new MyPreciseInitClass<double>(); | ||
if (preciseInitCctorsRun != 3) | ||
{ | ||
Console.WriteLine("TriggerCctorClass should return 3, but did not"); | ||
return false; | ||
} | ||
Comment on lines
+1995
to
+2005
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. These two writelines are wrong |
||
|
||
MyPreciseInitClass<object>.TriggerCctorClass(); | ||
if (preciseInitCctorsRun != 4) | ||
{ | ||
Console.WriteLine("preciseInitCctorsRun should be 4 but is {0}", preciseInitCctorsRun); | ||
return false; | ||
} | ||
MyPreciseInitClass<string>.TriggerCctorMethod<object>(); | ||
if (preciseInitCctorsRun != 5) | ||
{ | ||
Console.WriteLine("TriggerCctorClass should return 5, but did not"); | ||
return false; | ||
} | ||
|
||
o = new MyPreciseInitClass<Type>(); | ||
if (preciseInitCctorsRun != 6) | ||
{ | ||
Console.WriteLine("TriggerCctorClass should return 6, but did not"); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public static bool TestSharedGenerics() | ||
|
@@ -2101,7 +2178,7 @@ public static bool TestSharedGenerics() | |
return false; | ||
} | ||
|
||
MyClass<string > mcString = new MyClass<string>(); | ||
MyClass<string> mcString = new MyClass<string>(); | ||
if (mcString.GetTypeOf() != typeof(MyClass<string>)) | ||
{ | ||
return false; | ||
|
@@ -2110,6 +2187,10 @@ public static bool TestSharedGenerics() | |
{ | ||
return false; | ||
} | ||
if (MyClass<object>.GetTypeThroughStaticVar() != typeof(MyClass<object>)) | ||
{ | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This uses
|=
(assignment) instead of&
to test theCORINFO_FLG_FIELD_INITCLASS
flag, which both mutatesfieldFlags
and always evaluates true. Change it toif ((pFieldInfo->fieldFlags & CORINFO_FLG_FIELD_INITCLASS) != 0)
.Copilot uses AI. Check for mistakes.