Skip to content
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

Abstract out System.Reflection.Emit.ILGenerator #86594

Merged
merged 5 commits into from
May 23, 2023
Merged

Conversation

buyaa-n
Copy link
Contributor

@buyaa-n buyaa-n commented May 22, 2023

Contributes to #62956
Fixes #86110

  • Abstract out ILGenerator, move into shared library
    • Kept some APIs virtual (when implementations in Mono and CLR are same or close, we can add more)
    • Made some public APIs abstract (mostly when the Mono and CLR implementations are different)

@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost ghost assigned buyaa-n May 22, 2023
@ghost
Copy link

ghost commented May 22, 2023

Tagging subscribers to this area: @dotnet/area-system-reflection
See info in area-owners.md if you want to be subscribed.

Issue Details

Contributes to #62956
Fixes #86110

  • Abstract out ILGenerator, move into shared library
    • Kept some APIs virtual (when implementations in Mono and CLR are same or close, we can add more)
    • Made some public APIs abstract (mostly when the Mono and CLR implementations are different)
Author: buyaa-n
Assignees: -
Labels:

area-System.Reflection, new-api-needs-documentation

Milestone: -

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM otherwise (once the CI is green).

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM otherwise (once the CI is green).

@buyaa-n
Copy link
Contributor Author

buyaa-n commented May 22, 2023

LGTM otherwise (once the CI is green).

Hm, strangely there are tests that accesses private/internal fields/methods of ILGenerator outside of the CoreLib, not sure how to workaround ...

private static readonly FieldInfo s_fiLen = typeof(ILGenerator).GetFieldAssert("m_length");
private static readonly FieldInfo s_fiStream = typeof(ILGenerator).GetFieldAssert("m_ILStream");
private static readonly FieldInfo s_fiExceptions = typeof(ILGenerator).GetFieldAssert("m_exceptions");
private static readonly FieldInfo s_fiExceptionCount = typeof(ILGenerator).GetFieldAssert("m_exceptionCount");
private static readonly FieldInfo s_fiLocalSignature = typeof(ILGenerator).GetFieldAssert("m_localSignature");
private static readonly MethodInfo s_miBakeByteArray = typeof(ILGenerator).GetMethodAssert("BakeByteArray");
private static readonly MethodInfo s_miMaxStackSize = typeof(ILGenerator).GetMethodAssert("GetMaxStackSize");

@jkotas
Copy link
Member

jkotas commented May 22, 2023

Change it to access fields of RuntimeILGenerator:

private static readonly Type s_runtimeILGenerator = Type.GetType("System.Reflection.Emit.RuntimeILGenerator");
private static readonly FieldInfo s_fiLen = s_runtimeILGenerator.GetFieldAssert("m_length");
...

@buyaa-n
Copy link
Contributor Author

buyaa-n commented May 22, 2023

Change it to access fields of RuntimeILGenerator:

Thank you 🙏!

@buyaa-n buyaa-n merged commit 6f97718 into main May 23, 2023
@buyaa-n buyaa-n deleted the abstract-ilgenerator branch May 23, 2023 02:36
@ghost ghost locked as resolved and limited conversation to collaborators Jun 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[API Proposal] Make System.Reflection.Emit.ILGenerator constructor protected
2 participants