-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Minimal ILGenerator implementation for new AssemblyBuilder.Save #92846
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
Conversation
Tagging subscribers to this area: @dotnet/area-system-reflection-emit Issue DetailsMore tests will be added Contributes to #83988
|
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/ILGeneratorImpl.cs
Show resolved
Hide resolved
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/ModuleBuilderImpl.cs
Show resolved
Hide resolved
private static int AddMethodBody(MethodBuilderImpl method, ILGeneratorImpl il, MethodBodyStreamEncoder methodBodyEncoder) => | ||
methodBodyEncoder.AddMethodBody( | ||
instructionEncoder: il.Instructions, | ||
maxStack: 8, // TODO |
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.
What happens if 8 is exceeded? If there is an exception or some other issue, we should probably try to fix this for this PR.
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.
If we can set maxstack == the number of opcodes
for now that should protect us against any InvalidProgramException
thrown by the JIT etc.
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.
I can do that until I have got a better handling
|
||
if ((_methodImplFlags & MethodImplAttributes.CodeTypeMask) != MethodImplAttributes.IL || | ||
(_methodImplFlags & MethodImplAttributes.Unmanaged) != 0 || | ||
(_attributes & MethodAttributes.PinvokeImpl) != 0) |
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.
The CoreLib implementation also has a check for DllImport here. Is it intentionally omitted?
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.
We are setting the _attributes
with MethodAttributes.PinvokeImpl
when DllImportAttribute
is set, no need to keep another boolean flag for this
runtime/src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/MethodBuilderImpl.cs
Lines 111 to 114 in 42a6776
case "System.Runtime.InteropServices.DllImportAttribute": | |
{ | |
_dllImportData = DllImportData.CreateDllImportData(CustomAttributeInfo.DecodeCustomAttribute(con, binaryAttribute), out var preserveSig); | |
_attributes |= MethodAttributes.PinvokeImpl; |
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.
LGTM pending the discussion on a value for maxstack
that shouldn't result in an exception if exceeded.
The failures not related and known |
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/ILGeneratorImpl.cs
Outdated
Show resolved
Hide resolved
…t/ILGeneratorImpl.cs
Basically, replacing the ILGenerator.Emit overloads implementaiton with
InstructionEncoder
which will be written into the file when saving the methods in a type using MethodBodyStreamEncoderContributes to #83988