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

Emission and reading of custom modifiers #85504

Merged
merged 4 commits into from
May 1, 2023

Conversation

MichalStrehovsky
Copy link
Member

Fixes #71883.

  • Emit custom modifiers to the native metadata format
  • Read custom modifiers at runtime
  • Bugfix in the type loader

Fixes dotnet#71883.

* Emit custom modifiers to the native metadata format
* Read custom modifiers at runtime
* Bugfix in the type loader
@ghost
Copy link

ghost commented Apr 28, 2023

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Issue Details

Fixes #71883.

  • Emit custom modifiers to the native metadata format
  • Read custom modifiers at runtime
  • Bugfix in the type loader
Author: MichalStrehovsky
Assignees: -
Labels:

area-NativeAOT-coreclr

Milestone: -

Comment on lines +112 to +115
// We call Reverse for compat with CoreCLR that also reverses these.
// ILDasm also reverses these but don't be fooled: you can go to
// View -> MetaInfo -> Show to see the file format order in ILDasm.
Array.Reverse(result);
Copy link
Member Author

Choose a reason for hiding this comment

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

This is weird.

@@ -47,18 +47,21 @@ private Field HandleFieldDefinition(Cts.FieldDesc field)
private void InitializeFieldDefinition(Cts.FieldDesc entity, Field record)
{
record.Name = HandleString(entity.Name);
Copy link
Member

Choose a reason for hiding this comment

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

Keep this for non-Ecma fields?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add an else branch that throws on non-ecma. This is never reached for non-ecma.

@@ -61,7 +61,6 @@ private Method HandleMethodDefinition(Cts.MethodDesc method)
private void InitializeMethodDefinition(Cts.MethodDesc entity, Method record)
{
record.Name = HandleString(entity.Name);
record.Signature = HandleMethodSignature(entity.Signature);
Copy link
Member

Choose a reason for hiding this comment

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

Dtto

Copy link
Member Author

Choose a reason for hiding this comment

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

This is never reached for non-ecma methods. There is an else branch that throws NotImplemented. There's no scenario for non-ECMA metadata generation.

All of this should be eventually rewritten to work on top of S.R.Metadata instead of the type system.

@@ -98,7 +101,11 @@ private TypeDesc InitializeFieldType()
BlobReader signatureReader = metadataReader.GetBlobReader(metadataReader.GetFieldDefinition(_handle).Signature);

EcmaSignatureParser parser = new EcmaSignatureParser(Module, signatureReader, NotFoundBehavior.Throw);
var fieldType = parser.ParseFieldSignature();
var fieldType = parser.ParseFieldSignature(out EmbeddedSignatureData[] data);
Copy link
Member

Choose a reason for hiding this comment

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

It looks wasteful to use the expensive parsing method that creates Stack, etc. Can we have bool on the parser that tracks whether we have encountered any modifiers?

Copy link
Member

Choose a reason for hiding this comment

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

(Or make the expensive parsing method cheaper, e.g. use inline storage for stack of limited depth.)

Copy link
Member Author

Choose a reason for hiding this comment

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

The modifiers handling within the type system is utter garbage. The Stack should be rewritten to use a stack-based linked list once C# can express that (I haven't been keeping track with all the unscoped ref stuff - maybe it can already express it). I don't think it makes sense to add extra complexity to the already incomprehensible modifiers handling if we know we'll be able to get rid of this cost.

We already pay this cost when parsing method signatures. I've never seen it in profiles.

_embeddedSignatureDataList = new List<EmbeddedSignatureData>();
return ParsePropertySignatureInternal();
}
finally
Copy link
Member

Choose a reason for hiding this comment

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

EcmaSignatureParser is a struct that is not meant to be reused for multiple parsing operatins. This cleanup should not be needed.

(I know that pattern is used in existing methods, but it looks unnecessary.)

Copy link
Member Author

Choose a reason for hiding this comment

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

This is part of the "the modifiers stuff in the managed type system is incomprehensible". I just cargo cult my way through it.

I'll delete this part of the copy paste.

Copy link
Member

Choose a reason for hiding this comment

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

Delete the cargo cult from the two other places in this file as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll do this in a separate PR. I don't like deleting unrelated mystery code in a 500-line PR because the mystery can unravel itself.

@MichalStrehovsky
Copy link
Member Author

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@MichalStrehovsky
Copy link
Member Author

The failures in extra-platforms are going to be fixed with #85579. Hopefully I didn't miss anything. This failed every single leg.

@MichalStrehovsky MichalStrehovsky merged commit e56ff52 into dotnet:main May 1, 2023
@MichalStrehovsky MichalStrehovsky deleted the fnptrsig branch May 1, 2023 10:16
@ghost ghost locked as resolved and limited conversation to collaborators May 31, 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.

Add Function Pointer support to Native AOT Reflection
2 participants