-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Emit/Call member references in new ILGenerator #94116
Conversation
Tagging subscribers to this area: @dotnet/area-system-reflection-emit Issue DetailsAdd implementation for Contributes to #92975
|
{ | ||
ArgumentNullException.ThrowIfNull(con); | ||
|
||
if (!(opcode.Equals(OpCodes.Call) || opcode.Equals(OpCodes.Callvirt) || opcode.Equals(OpCodes.Newobj))) |
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.
Runtime implementation Asserts this instead of throwing:
runtime/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeILGenerator.cs
Lines 680 to 694 in 5f0fe49
if (opcode.StackBehaviourPush == StackBehaviour.Varpush) | |
{ | |
// Instruction must be one of call or callvirt. | |
Debug.Assert(opcode.Equals(OpCodes.Call) || | |
opcode.Equals(OpCodes.Callvirt), | |
"Unexpected opcode encountered for StackBehaviour of VarPush."); | |
stackchange++; | |
} | |
if (opcode.StackBehaviourPop == StackBehaviour.Varpop) | |
{ | |
// Instruction must be one of call, callvirt or newobj. | |
Debug.Assert(opcode.Equals(OpCodes.Call) || | |
opcode.Equals(OpCodes.Callvirt) || | |
opcode.Equals(OpCodes.Newobj), | |
"Unexpected opcode encountered for StackBehaviour of VarPop."); |
I think this should throw instead, same as in the
EmitCall(OpCode opcode, MethodInfo methodInfo, Type[]? optionalParameterTypes)
:runtime/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeILGenerator.cs
Lines 603 to 604 in 5f0fe49
if (!(opcode.Equals(OpCodes.Call) || opcode.Equals(OpCodes.Callvirt) || opcode.Equals(OpCodes.Newobj))) | |
throw new ArgumentException(SR.Argument_NotMethodCallOpcode, nameof(opcode)); |
src/libraries/System.Reflection.Emit/src/Resources/Strings.resx
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/ILGeneratorImpl.cs
Outdated
Show resolved
Hide resolved
|
||
int stackchange = 0; | ||
// Push the return value if there is one. | ||
stackchange++; |
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.
Are we just assuming there is a return value then?
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.
Yes, as it is a constructor
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/ILGeneratorImpl.cs
Outdated
Show resolved
Hide resolved
WriteCustomAttributes(method._customAttributes, methodHandle); | ||
_nextMethodDefRowId++; | ||
MethodDefinitionHandle handle = AddMethodDefinition(method, method.GetMethodSignatureBlob(), offset, _nextParameterRowId); | ||
Debug.Assert(method._handle == handle); |
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.
Why was this Assert added? Can it be added to AddMethodDefinition() instead?
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.
Why was this Assert added?
To make sure the method handle populated with AddMethodDefinition is in sync with prepopulated one.
Can it be added to AddMethodDefinition() instead?
It could, but AddMethodDefinition
is a one liner that just calls MetadataBuilder.AddMethodDefinition
, if you are OK with, don't really want to add another row.
Add implementation for
Emit(OpCode opcode, ConstructorInfo con)
,Emit(OpCode opcode, FieldInfo field)
,Emit(OpCode opcode, MethodInfo meth)
,Emit(OpCode opcode, Type cls)
andEmitCall(OpCode opcode, MethodInfo methodInfo, Type[]? optionalParameterTypes)
Contributes to #92975