-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
[API Proposal]: Make OpCode.StackChange() public #93419
Comments
Tagging subscribers to this area: @dotnet/area-system-reflection-emit Issue DetailsBackground and motivationOpCodes represents MS IL instructions that used for emitting IL with ILGenerator. An runtime/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/Opcode.cs Lines 48 to 49 in 946c524
Making this public will be useful for calculating MaxStack fasterRelated to https://github.com/dotnet/runtime/pull/93244/files#r1353013060 API Proposalnamespace System.Reflection.Emit
public readonly partial struct OpCode : System.IEquatable<System.Reflection.Emit.OpCode>
{
...
public StackBehaviour StackBehaviourPop { get }
public StackBehaviour StackBehaviourPush { get }
...
+ public int StackDifference()
} API Usage private void UpdateStackSize(OpCode opCode)
{
_currentStack += opCode.StackDifference();
_maxStackSize = Math.Max(_maxStackSize, _currentStack);
} Alternative DesignsIt can be a property too namespace System.Reflection.Emit
public readonly partial struct OpCode : System.IEquatable<System.Reflection.Emit.OpCode>
{
...
public StackBehaviour StackBehaviourPop { get }
public StackBehaviour StackBehaviourPush { get }
...
+ public int StackDifference { get }
} RisksNo response
|
Seems like this should be a property? |
Yes, can be a property and that is mentioned in the |
How expensive is the computation? I assume it's just a switch over the op code as the values are static? In that case I'd be in favor of a property. I also assume a positive value means the op code net-ads to the evaluation stack (pushing), a negative value means net consumption (popping), and zero means no change or equal amounts of pushing and popping. If so, I think I'd prefer @dotnet/fxdc? |
The OpCode has this info in the upper 4 bits of runtime/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/Opcode.cs Line 34 in d18295e
So the computation is just shifting those bits: runtime/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/Opcode.cs Lines 48 to 49 in d18295e
Yep, that is right |
Oh wow. I didn't realize the op code value encoded the stack change. In other metadata readers I've always seen people doing switches facepalm Also, I didn't realize we already have properties called Anyone else on @dotnet/fxdc? namespace System.Reflection.Emit;
public partial struct OpCode
{
// Existing:
// public StackBehaviour StackBehaviourPop { get; }
// public StackBehaviour StackBehaviourPush { get; }
public int StackDelta { get; }
} |
Slightly more verbose, but I think |
Another option could be |
Either of those names work for me :-) |
Looks good as proposed. namespace System.Reflection.Emit
public readonly partial struct OpCode : System.IEquatable<System.Reflection.Emit.OpCode>
{
public int EvaluationStackDelta { get }
} |
Background and motivation
OpCodes represents MS IL instructions that used for emitting IL with ILGenerator. An
OpCode
instruction may pop value(s) from stack as an operand of the instruction and also may push value(s) into the stack as a result. This stack change is needed for calculating MaxStack value that is essential for populating method body. I could use theStackBehaviourPop
andStackBehaviourPush
properties ofOpCode
to calculate this, but there is an internal method that gives this info directly:runtime/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/Opcode.cs
Lines 48 to 49 in 946c524
Making this public will be useful for calculating
MaxStack
fasterRelated to https://github.com/dotnet/runtime/pull/93244/files#r1353013060
API Proposal
namespace System.Reflection.Emit public readonly partial struct OpCode : System.IEquatable<System.Reflection.Emit.OpCode> { ... public StackBehaviour StackBehaviourPop { get } public StackBehaviour StackBehaviourPush { get } ... + public int EvaluationStackDelta { get } }
Alternative Designs
Other naming options:
EvaluationStackDelta
,StackSizeDelta
,StackTransitionDelta
orStackDepthDelta
as it is showing the difference of evaluation stack transition.API Usage
The text was updated successfully, but these errors were encountered: