-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Proposal: implement limited CHA in RyuJit and take into account 'sealed' keyword #16187
Comments
Changing the IL opcode emitted by Roslyn from Internal inter = null;
string value = inter.ToStaticString(); // not only succeeds, also returns "abc" |
It's a breaking change: friend assemblies exist. |
An analyzer could suggest |
So: inline the null check in IL? |
@0xd4d It looks to me that Friend Assemblies have to be specially marked as InternalsVisibleToAttribute . So in fact it can be done this automatic sealing of classes, just that it has a bit more limited scope. Instead of: "internal classes which are not overriden inside the assembly could be considered sealed", it could be read as: "internal classes which are not overriden inside the assembly could be considered sealed, excluding that the assembly is exported as a friend assembly, when this optimization would be disabled in the scope of the assembly". |
The Roslyn compilers do not have control over what sequence of machine instructions are executed. The C# language specification binds the invocation of |
Devirtualize more aggressively sealed classes:
Steps to Reproduce:
Most of times calling ToString(). GetHashCode() and co is converted to a virtual call. But by specification sealed methods and classes cannot have overriden methods, so if in context the virtual method cannot be overriden, it should be enforced to be devirtualized safely. There is one difference between calling a virtual method and a non-virtual method (the null pointer check) which should be still checked on this devirtualization.
Expected Behavior:
It should be expected that calling .ToString() to a provable sealed class (like against an Array classes, as byte[], should call a non-virtual method).
This snippet of code is inside a class which is not overriden anywhere:
The output of this program is:
(the code does a lambda capture,
Not only that static calls could be optimized, but RyuJit could have bigger devirtualization opportunities.
As a phase two of this proposal, it is that RyuJit to identify sealed classes which are in context of assemblies:
internal classes which are not overriden inside the assembly could be considered sealed
private classes (classes defined inside another classes) which are not overriden, could be considered sealed
This optimization step could add extra startup cost when loading new assemblies to check the Class Hierarchy Analysis, so maybe the marking of internal classes/priva classes as sealed, could be done on Roslyn side
I added a reverse link to RyuJIT repository
The text was updated successfully, but these errors were encountered: